77#include < opentimelineio/clip.h>
88#include < opentimelineio/stack.h>
99#include < opentimelineio/track.h>
10+ #include < opentimelineio/gap.h>
1011#include < opentimelineio/stackAlgorithm.h>
1112
1213#include < iostream>
@@ -213,6 +214,109 @@ main(int argc, char** argv)
213214 assertEqual (result->duration ().value (), 300 );
214215 });
215216
217+ tests.add_test (
218+ " test_flatten_stack_04" , [] {
219+ using namespace otio ;
220+
221+ otio::RationalTime rt_0_24{0 , 24 };
222+ otio::RationalTime rt_150_24{150 , 24 };
223+ otio::TimeRange tr_AB_150_24{rt_0_24, rt_150_24};
224+
225+ otio::TimeRange tr_C_150_24{rt_0_24, otio::RationalTime (300 , 24 )};
226+
227+ // A and B are Gaps placed over clip C
228+ // C should remain uncut
229+ // 0 150 300
230+ // [ A | B ]
231+ // [ C ]
232+ //
233+ // should flatten to:
234+ // [ C ]
235+
236+ otio::SerializableObject::Retainer<otio::Gap> cl_A =
237+ new otio::Gap (tr_AB_150_24, " track1_A" );
238+ otio::SerializableObject::Retainer<otio::Gap> cl_B =
239+ new otio::Gap (tr_AB_150_24, " track1_B" );
240+ otio::SerializableObject::Retainer<otio::Clip> cl_C =
241+ new otio::Clip (" track2_C" , nullptr , tr_C_150_24);
242+
243+ otio::SerializableObject::Retainer<otio::Track> tr_over =
244+ new otio::Track ();
245+ tr_over->append_child (cl_A);
246+ tr_over->append_child (cl_B);
247+
248+ otio::SerializableObject::Retainer<otio::Track> tr_under =
249+ new otio::Track ();
250+ tr_under->append_child (cl_C);
251+
252+ otio::SerializableObject::Retainer<otio::Stack> st =
253+ new otio::Stack ();
254+ st->append_child (tr_under);
255+ st->append_child (tr_over);
256+
257+ auto result = flatten_stack (st);
258+
259+ assertEqual (result->children ().size (), 1 );
260+ assertEqual (result->children ()[0 ]->name (), std::string (" track2_C" ));
261+ assertEqual (result->duration ().value (), 300 );
262+ assertEqual (st->children ().size (), 2 );
263+ assertEqual (dynamic_cast <otio::Track*>(st->children ()[0 ].value )->children ().size (), 1 );
264+ assertEqual (dynamic_cast <otio::Track*>(st->children ()[1 ].value )->children ().size (), 2 );
265+ });
266+
267+ tests.add_test (
268+ " test_flatten_stack_05" , [] {
269+ using namespace otio ;
270+
271+ otio::RationalTime rt_0_24{0 , 24 };
272+ otio::RationalTime rt_150_24{150 , 24 };
273+ otio::TimeRange tr_150_24{rt_0_24, rt_150_24};
274+
275+ // A and B are Gaps placed over clips C and D
276+ // with a cut at the same location
277+ // 0 150 300
278+ // [ A | B ]
279+ // [ C | D ]
280+ //
281+ // should flatten to:
282+ // [ C | D ]
283+
284+ otio::SerializableObject::Retainer<otio::Gap> cl_A =
285+ new otio::Gap (tr_150_24, " track1_A" );
286+ otio::SerializableObject::Retainer<otio::Gap> cl_B =
287+ new otio::Gap (tr_150_24, " track1_B" );
288+ otio::SerializableObject::Retainer<otio::Clip> cl_C =
289+ new otio::Clip (" track2_C" , nullptr , tr_150_24);
290+ otio::SerializableObject::Retainer<otio::Clip> cl_D =
291+ new otio::Clip (" track2_D" , nullptr , tr_150_24);
292+
293+
294+ otio::SerializableObject::Retainer<otio::Track> tr_over =
295+ new otio::Track ();
296+ tr_over->append_child (cl_A);
297+ tr_over->append_child (cl_B);
298+
299+ otio::SerializableObject::Retainer<otio::Track> tr_under =
300+ new otio::Track ();
301+ tr_under->append_child (cl_C);
302+ tr_under->append_child (cl_D);
303+
304+ otio::SerializableObject::Retainer<otio::Stack> st =
305+ new otio::Stack ();
306+ st->append_child (tr_under);
307+ st->append_child (tr_over);
308+
309+ auto result = flatten_stack (st);
310+
311+ assertEqual (result->children ().size (), 2 );
312+ assertEqual (result->children ()[0 ]->name (), std::string (" track2_C" ));
313+ assertEqual (result->children ()[1 ]->name (), std::string (" track2_D" ));
314+ assertEqual (result->duration ().value (), 300 );
315+ assertEqual (st->children ().size (), 2 );
316+ assertEqual (dynamic_cast <otio::Track*>(st->children ()[0 ].value )->children ().size (), 2 );
317+ assertEqual (dynamic_cast <otio::Track*>(st->children ()[1 ].value )->children ().size (), 2 );
318+ });
319+
216320 tests.run (argc, argv);
217321 return 0 ;
218- }
322+ }
0 commit comments