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

None timeline load #86

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
69 changes: 51 additions & 18 deletions app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include <chrono>
#include <iostream>

#include <opentimelineio/clip.h>

void DrawMenu();
void DrawToolbar(ImVec2 buttonSize);
void DrawDroppedFilesPrompt();
Expand Down Expand Up @@ -238,7 +240,7 @@ std::string otio_error_string(otio::ErrorStatus const& error_status) {
}

void LoadTimeline(otio::Timeline* timeline) {
appState.timeline = timeline;
appState.root = timeline;
DetectPlayheadLimits();
appState.playhead = appState.playhead_limit.start_time();
FitZoomWholeTimeline();
Expand Down Expand Up @@ -275,17 +277,35 @@ void LoadFile(std::string path) {
auto start = std::chrono::high_resolution_clock::now();

otio::ErrorStatus error_status;
auto timeline = dynamic_cast<otio::Timeline*>(
otio::Timeline::from_json_file(path, &error_status));
if (!timeline || otio::is_error(error_status)) {
auto root = otio::Timeline::from_json_file(path, &error_status);
if (!root || otio::is_error(error_status)) {
Message(
"Error loading \"%s\": %s",
path.c_str(),
otio_error_string(error_status).c_str());
return;
}

LoadTimeline(timeline);
std::string file_name;
if (root->schema_name() == "Timeline") {
auto timeline = dynamic_cast<otio::Timeline*>(root);
LoadTimeline(timeline);
file_name = timeline->name();
} else if (root->schema_name() == "Clip") {
auto clip = dynamic_cast<otio::Clip*>(root);
file_name = clip->name();
appState.root = clip;

auto timeline = new otio::Timeline();
SelectObject(clip);
} else{
Message(
"Error loading \"%s\": Unsupported root schema: %s",
path.c_str(),
root->schema_name().c_str()
);
return;
}

appState.file_path = path;

Expand All @@ -294,12 +314,12 @@ void LoadFile(std::string path) {
double elapsed_seconds = elapsed.count();
Message(
"Loaded \"%s\" in %.3f seconds",
timeline->name().c_str(),
file_name.c_str(),
elapsed_seconds);
}

void SaveFile(std::string path) {
auto timeline = appState.timeline;
auto timeline = appState.root;
if (!timeline)
return;

Expand Down Expand Up @@ -390,6 +410,12 @@ bool IconButton(const char* label, const ImVec2 size = ImVec2(0, 0)) {

void AppUpdate() { }

void DrawRoot(){
if (appState.root->schema_name() == "Timeline") {
DrawTimeline(dynamic_cast<otio::Timeline*>(appState.root));
}
}

void MainGui() {
AppUpdate();

Expand Down Expand Up @@ -532,12 +558,14 @@ void MainGui() {
contentSize.y -= ImGui::GetTextLineHeightWithSpacing() + 7;
ImGui::BeginChild("##TimelineContainer", contentSize);

DrawTimeline(appState.timeline);
DrawRoot();

ImGui::EndChild();

if (DrawTransportControls(appState.timeline)) {
appState.scroll_to_playhead = true;
if (appState.root->schema_name() == "Timeline"){
if (DrawTransportControls(dynamic_cast<otio::Timeline*>(appState.root))) {
appState.scroll_to_playhead = true;
}
}
}
ImGui::End();
Expand Down Expand Up @@ -687,8 +715,8 @@ void DrawMenu() {
if (ImGui::MenuItem("Revert")) {
LoadFile(appState.file_path);
}
if (ImGui::MenuItem("Close", NULL, false, appState.timeline)) {
appState.timeline = NULL;
if (ImGui::MenuItem("Close", NULL, false, appState.root)) {
appState.root = NULL;
SelectObject(NULL);
}
#ifndef EMSCRIPTEN
Expand Down Expand Up @@ -889,7 +917,7 @@ void SelectObject(
appState.selected_text = "No selection";
} else {
otio::ErrorStatus error_status;
appState.selected_text = object->to_json_string(&error_status);
//appState.selected_text = object->to_json_string(&error_status);
if (otio::is_error(error_status)) {
appState.selected_text = otio_error_string(error_status);
}
Expand All @@ -914,14 +942,19 @@ void SnapPlayhead() {
}

void DetectPlayheadLimits() {
const auto timeline = appState.timeline;
appState.playhead_limit = otio::TimeRange(
timeline->global_start_time().value_or(otio::RationalTime()),
timeline->duration());
if (appState.root->schema_name() == "Timeline"){
const auto timeline = dynamic_cast<otio::Timeline*>(appState.root);
appState.playhead_limit = otio::TimeRange(
timeline->global_start_time().value_or(otio::RationalTime()),
timeline->duration());
}
}

void FitZoomWholeTimeline() {
appState.scale = appState.timeline_width / appState.timeline->duration().to_seconds();
if (appState.root->schema_name() == "Timeline"){
const auto timeline = dynamic_cast<otio::Timeline*>(appState.root);
appState.scale = appState.timeline_width / timeline->duration().to_seconds();
}
}
// GUI utility to add dynamic height to GUI elements

Expand Down
2 changes: 1 addition & 1 deletion app.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ struct AppState {

// This holds the main timeline object.
// Pretty much everything drills into this one entry point.
otio::SerializableObject::Retainer<otio::Timeline> timeline;
otio::SerializableObjectWithMetadata* root;

// Timeline display settings
float timeline_width = 100.0f; // automatically calculated (pixels)
Expand Down
25 changes: 18 additions & 7 deletions editing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include <stdlib.h>

void DeleteSelectedObject() {
if (appState.selected_object == appState.timeline) {
appState.timeline = NULL;
if (appState.selected_object == appState.root) {
appState.root = NULL;
SelectObject(NULL);
return;
}
Expand Down Expand Up @@ -57,10 +57,16 @@ void DeleteSelectedObject() {

void AddMarkerAtPlayhead(otio::Item* item, std::string name, std::string color) {
auto playhead = appState.playhead;


if (!appState.root)
return;

const auto& timeline = appState.timeline;
if (!timeline)
if (appState.root->schema_name() != "Timeline"){
return;
}

const auto& timeline = dynamic_cast<otio::Timeline*>(appState.root);

// Default to the selected item, or the top-level timeline.
if (item == NULL) {
Expand Down Expand Up @@ -91,10 +97,15 @@ void AddMarkerAtPlayhead(otio::Item* item, std::string name, std::string color)
}

void AddTrack(std::string kind) {
const auto& timeline = appState.timeline;
if (!timeline)
if (!appState.root)
return;

if (appState.root->schema_name() != "Timeline"){
return;
}

const auto& timeline = dynamic_cast<otio::Timeline*>(appState.root);

// Fall back to the top level stack.
int insertion_index = -1;
otio::Stack* stack = timeline->tracks();
Expand Down Expand Up @@ -150,7 +161,7 @@ void AddTrack(std::string kind) {
}

void FlattenTrackDown() {
const auto& timeline = appState.timeline;
const auto& timeline = appState.root;
if (!timeline) {
Message("Cannot flatten: No timeline.");
return;
Expand Down
58 changes: 36 additions & 22 deletions inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,20 +616,27 @@ void DrawMarkersInspector() {
typedef std::pair<otio::SerializableObject::Retainer<otio::Marker>, otio::SerializableObject::Retainer<otio::Item>> marker_parent_pair;
std::vector<marker_parent_pair> pairs;

auto root = appState.timeline->tracks();
auto global_start = appState.timeline->global_start_time().value_or(otio::RationalTime());
auto root = new otio::Stack();
auto global_start = otio::RationalTime(0.0);

for (const auto& marker : root->markers()) {
pairs.push_back(marker_parent_pair(marker, root));
}
if (appState.root->schema_name() == "Timeline"){
const auto& timeline = dynamic_cast<otio::Timeline*>(appState.root);

for (const auto& child :
appState.timeline->tracks()->find_children())
{
if (const auto& item = dynamic_cast<otio::Item*>(&*child))
root = timeline->tracks();
global_start = timeline->global_start_time().value_or(otio::RationalTime());

for (const auto& marker : root->markers()) {
pairs.push_back(marker_parent_pair(marker, root));
}

for (const auto& child :
timeline->tracks()->find_children())
{
for (const auto& marker : item->markers()) {
pairs.push_back(marker_parent_pair(marker, item));
if (const auto& item = dynamic_cast<otio::Item*>(&*child))
{
for (const auto& marker : item->markers()) {
pairs.push_back(marker_parent_pair(marker, item));
}
}
}
}
Expand Down Expand Up @@ -714,20 +721,27 @@ void DrawEffectsInspector() {
typedef std::pair<otio::SerializableObject::Retainer<otio::Effect>, otio::SerializableObject::Retainer<otio::Item>> effect_parent_pair;
std::vector<effect_parent_pair> pairs;

auto root = appState.timeline->tracks();
auto global_start = appState.timeline->global_start_time().value_or(otio::RationalTime());
auto root = new otio::Stack();
auto global_start = otio::RationalTime(0.0);

for (const auto& effect : root->effects()) {
pairs.push_back(effect_parent_pair(effect, root));
}
if (appState.root->schema_name() == "Timeline"){
const auto& timeline = dynamic_cast<otio::Timeline*>(appState.root);

for (const auto& child :
appState.timeline->tracks()->find_children())
{
if (const auto& item = dynamic_cast<otio::Item*>(&*child))
root = timeline->tracks();
global_start = timeline->global_start_time().value_or(otio::RationalTime());

for (const auto& effect : root->effects()) {
pairs.push_back(effect_parent_pair(effect, root));
}

for (const auto& child :
timeline->tracks()->find_children())
{
for (const auto& effect : item->effects()) {
pairs.push_back(effect_parent_pair(effect, item));
if (const auto& item = dynamic_cast<otio::Item*>(&*child))
{
for (const auto& effect : item->effects()) {
pairs.push_back(effect_parent_pair(effect, item));
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion timeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void TopLevelTimeRangeMap(
std::map<otio::Composable*, otio::TimeRange>& range_map,
otio::Item* context) {
auto zero = otio::RationalTime();
auto top = appState.timeline->tracks();
auto top = dynamic_cast<otio::Timeline*>(appState.root)->tracks();
auto offset = context->transformed_time(zero, top);

for (auto& pair : range_map) {
Expand Down