Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add media reference to inspector #68

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e57d2c7
Initial setup of the dropdown menu to select media references
Jspada200ilm Sep 26, 2024
0463c85
Use the key on the media ref object to display in the dropdown
Jspada200ilm Sep 26, 2024
8129364
Set the selected media ref index to -1 on clip change, UI updates, Se…
Jspada200ilm Sep 27, 2024
5e58a2b
Remove test file
Jspada200ilm Sep 27, 2024
1f2ce64
remove accidental commit of config file
Jspada200ilm Sep 27, 2024
853d346
Add vscode folder to git ignore
Jspada200ilm Sep 27, 2024
1039d5f
Add method for drawing and modifying the image bounds
Jspada200ilm Sep 27, 2024
05ce4e1
Remove unused import
Jspada200ilm Sep 27, 2024
ef58ace
remove try/catch
Jspada200ilm Sep 27, 2024
89c3ac7
Remove comments
Jspada200ilm Sep 27, 2024
012be20
Fix bug with the wrong pointer being used
Jspada200ilm Sep 27, 2024
c5865a0
Ensure the min value is less then the max
Jspada200ilm Sep 27, 2024
002bf81
Ensure we are checking for the missing reference
Jspada200ilm Sep 27, 2024
0a6edf4
make labels consistent
Jspada200ilm Sep 27, 2024
05d638e
make text consistent
Jspada200ilm Sep 27, 2024
c2d4b20
PR feedback
Jspada200ilm Oct 1, 2024
170dac1
Improve clip and transition color changes on hover and select (#67)
yaash45 Sep 27, 2024
b230c2a
Add drag & drop functionality for opening files (in macOS) (#69)
agetroortega Sep 27, 2024
358ed9f
Add instruction to do a recursive clone before attempting a build (#66)
yaash45 Sep 28, 2024
5ff0f78
Expose methods to load OTIO files in WASM through Javascript (#70)
austinwitherspoon Sep 28, 2024
7963d25
Bump libs/glfw from `dc557ec` to `b35641f` (#48)
dependabot[bot] Sep 28, 2024
2432f70
Bump libs/opentimelineio from `4b3b673` to `5184c36` (#71)
dependabot[bot] Sep 28, 2024
75a333d
Adjust timecode track height dynamically (#75)
TrevorAyl Sep 30, 2024
b730ee0
Merge branch 'main' into Add-Media-Reference-to-inspector
jspada200 Oct 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@


build
.vscode
*.DS_Store
3 changes: 3 additions & 0 deletions app.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ struct AppState {
std::string selected_text; // displayed in the JSON inspector
char message[1024]; // single-line message displayed in main window

// Store the currently selected MediaReference index for the inspector.
int selected_reference_index = -1;

// Toggles for Dear ImGui windows
bool show_main_window = true;
bool show_style_editor = false;
Expand Down
184 changes: 183 additions & 1 deletion inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@
#include <opentimelineio/anyDictionary.h>
#include <opentimelineio/clip.h>
#include <opentimelineio/effect.h>
#include <opentimelineio/externalReference.h>
#include <opentimelineio/gap.h>
#include <opentimelineio/imageSequenceReference.h>
#include <opentimelineio/linearTimeWarp.h>
#include <opentimelineio/marker.h>
#include <opentimelineio/mediaReference.h>
#include <opentimelineio/missingReference.h>
#include <opentimelineio/track.h>
#include <opentimelineio/transition.h>

#include <implot.h>
#include <TextEditor.h>
#include <implot.h>

static const char* marker_color_names[] = {
"PINK", "RED", "ORANGE", "YELLOW",
Expand Down Expand Up @@ -75,6 +79,10 @@ void UpdateJSONInspector() {
jsonEditor.SetReadOnly(true);
jsonEditor.SetLanguageDefinition(otioLangDef);
jsonEditor.SetText(appState.selected_text);

// When the user selects a new clip, we need to update the selected reference index
// this allows the inspector to show the correct reference when the user selects a clip
appState.selected_reference_index = -1;
}

void DrawJSONInspector() {
Expand Down Expand Up @@ -210,6 +218,65 @@ bool DrawTimeRange(
return changed;
}

void DrawAvailableImageBounds(
char const* label,
otio::MediaReference* media_reference) {
/*
* Draw the widgets for viewing and modifying the available image bounds.
*
* @parm label: The label to display above the widgets.
* @parm media_reference: The media reference to get the available image bounds from
* and set the new bounds to.
*/

auto available_image_bounds = media_reference->available_image_bounds();

ImGui::Text("%s", label);
ImGui::Indent();

Imath_3_2::Box2d bounds = available_image_bounds.value();

ImGui::Text("Min:");
ImGui::SameLine();
ImGui::PushItemWidth(100);
float min_x = static_cast<float>(available_image_bounds->min.x);
if (ImGui::InputFloat("##min_x", &min_x)) {
bounds.min.x = static_cast<double>(min_x);
};
ImGui::SameLine();

float min_y = static_cast<float>(available_image_bounds->min.y);
if (ImGui::InputFloat("##min_y", &min_y)) {
bounds.min.y = static_cast<double>(min_y);
};

ImGui::PopItemWidth();

ImGui::Text("Max:");
ImGui::SameLine();
ImGui::PushItemWidth(100);

float max_x = static_cast<float>(available_image_bounds->max.x);
if (ImGui::InputFloat("##max_x", &max_x)) {
bounds.max.x = static_cast<double>(max_x);
};
ImGui::SameLine();

float max_y = static_cast<float>(available_image_bounds->max.y);
if (ImGui::InputFloat("##max_y", &max_y)) {
bounds.max.y = static_cast<double>(max_y);
};
ImGui::PopItemWidth();
ImGui::Unindent();

if (bounds != available_image_bounds.value()) {
// Ensure that the min is less than the max on the x and y
if (bounds.min.x < bounds.max.x && bounds.min.y < bounds.max.y) {
media_reference->set_available_image_bounds(bounds);
}
}
}

void DrawMetadataSubtree(std::string key, otio::AnyDictionary& metadata);

void DrawMetadataArray(std::string key, otio::AnyVector& vector);
Expand Down Expand Up @@ -606,6 +673,121 @@ void DrawInspector() {

DrawMetadataTable(metadata);
}

// Draw Reference Media Information
if (const auto& clip = dynamic_cast<otio::Clip*>(selected_object)) {
ImGui::Dummy(ImVec2(0.0f, 20.0f));
ImGui::Text("Selected media reference:");

const auto& media_references = clip->media_references();

// Array of names and corresponding MediaReference pointers
std::vector<const char*> reference_names;
otio::MediaReference** reference_objects = new otio::MediaReference*[media_references.size()];

size_t i = 0;
for (const auto& media_reference : media_references) {
reference_names.push_back(media_reference.first.c_str());
reference_objects[i] = media_reference.second;
i++;
}
int num_references = static_cast<int>(media_references.size());

std::string current_reference_name = clip->active_media_reference_key();

// Select the active media reference if it is not already set in the appState.
if (appState.selected_reference_index == -1) {
for (int i = 0; i < num_references; i++) {
if (current_reference_name == reference_names[i]) {
appState.selected_reference_index = i;
break;
}
}
}

// Set the active media ref key based on user selection
if (ImGui::Combo("", &appState.selected_reference_index, reference_names.data(), num_references)) {
if (appState.selected_reference_index >= 0 && appState.selected_reference_index < num_references) {
clip->set_active_media_reference_key(reference_names[appState.selected_reference_index]);
}
}

// Retrieve the selected MediaReference object
otio::MediaReference* selected_reference = nullptr;
if (appState.selected_reference_index >= 0 && appState.selected_reference_index < num_references) {
selected_reference = reference_objects[appState.selected_reference_index];
} else {
std::cerr << "Error: Selected reference index is out of range." << std::endl;
}

if (selected_reference) {
ImGui::Indent();
ImGui::Dummy(ImVec2(0.0f, 5.0f));

if (auto external_ref = dynamic_cast<otio::ExternalReference*>(selected_reference)) {
ImGui::Text("Type: External Media");
snprintf(tmp_str, sizeof(tmp_str), "%s", external_ref->target_url().c_str());
if (ImGui::InputText("Target", tmp_str, sizeof(tmp_str))) {
external_ref->set_target_url(tmp_str);
}

auto available_range = external_ref->available_range();
if (available_range && DrawTimeRange("Available range", &(*available_range), false)) {
external_ref->set_available_range(available_range);
}

auto available_image_bounds = external_ref->available_image_bounds();
if (available_image_bounds) {
DrawAvailableImageBounds("Available image bounds", external_ref);
}

ImGui::Text("Metadata:");
DrawMetadataTable(external_ref->metadata());

} else if (auto missing_ref = dynamic_cast<otio::MissingReference*>(selected_reference)) {
ImGui::Text("Type: Missing Media");

auto available_range = missing_ref->available_range();
if (available_range && DrawTimeRange("Available range", &(*available_range), false)) {
missing_ref->set_available_range(available_range);
}

auto available_image_bounds = missing_ref->available_image_bounds();
if (available_image_bounds) {
DrawAvailableImageBounds("Available image bounds", missing_ref);
}

ImGui::Text("Metadata:");
DrawMetadataTable(missing_ref->metadata());
} else if (auto imageSeqRef = dynamic_cast<otio::ImageSequenceReference*>(selected_reference)) {
ImGui::Text("Type: Image Sequence");

auto target_url = imageSeqRef->target_url_base();
if (ImGui::InputText("Target url base", tmp_str, sizeof(tmp_str))) {
imageSeqRef->set_target_url_base(tmp_str);
}

auto available_range = imageSeqRef->available_range();
if (available_range && DrawTimeRange("Available range", &(*available_range), false)) {
imageSeqRef->set_available_range(available_range);
}

auto available_image_bounds = imageSeqRef->available_image_bounds();
if (available_image_bounds) {
DrawAvailableImageBounds("Available image bounds", imageSeqRef);
}

ImGui::Text("Metadata:");
DrawMetadataTable(imageSeqRef->metadata());

} else {
jspada200 marked this conversation as resolved.
Show resolved Hide resolved
ImGui::Text("Type: The selected media type is not yet supported in the inspector.");
}
ImGui::Unindent();
} else {
ImGui::Text("No media reference found.");
}
}
}

void DrawMarkersInspector() {
Expand Down