Some attempts to block referencing of DCPs when it is not possible.
[dcpomatic.git] / src / wx / timeline.cc
index 9a9dfc26d764ec08efb038e1f27427d83b165672..f91d2937f44ed51ac23aa94cff8a0bbe5674914f 100644 (file)
@@ -32,7 +32,9 @@
 #include "lib/subtitle_content.h"
 #include <wx/graphics.h>
 #include <boost/weak_ptr.hpp>
+#include <boost/foreach.hpp>
 #include <list>
+#include <iostream>
 
 using std::list;
 using std::cout;
@@ -111,19 +113,17 @@ Timeline::recreate_views ()
        _views.clear ();
        _views.push_back (_time_axis_view);
 
-       ContentList content = film->content ();
-
-       for (ContentList::iterator i = content.begin(); i != content.end(); ++i) {
-               if (dynamic_pointer_cast<VideoContent> (*i)) {
-                       _views.push_back (shared_ptr<TimelineView> (new TimelineVideoContentView (*this, *i)));
+       BOOST_FOREACH (shared_ptr<Content> i, film->content ()) {
+               if (dynamic_pointer_cast<VideoContent> (i)) {
+                       _views.push_back (shared_ptr<TimelineView> (new TimelineVideoContentView (*this, i)));
                }
 
-               shared_ptr<AudioContent> ac = dynamic_pointer_cast<AudioContent> (*i);
+               shared_ptr<AudioContent> ac = dynamic_pointer_cast<AudioContent> (i);
                if (ac && !ac->audio_mapping().mapped_output_channels().empty ()) {
-                       _views.push_back (shared_ptr<TimelineView> (new TimelineAudioContentView (*this, *i)));
+                       _views.push_back (shared_ptr<TimelineView> (new TimelineAudioContentView (*this, i)));
                }
 
-               shared_ptr<SubtitleContent> sc = dynamic_pointer_cast<SubtitleContent> (*i);
+               shared_ptr<SubtitleContent> sc = dynamic_pointer_cast<SubtitleContent> (i);
                if (sc && sc->has_subtitles ()) {
                        _views.push_back (shared_ptr<TimelineView> (new TimelineSubtitleContentView (*this, sc)));
                }
@@ -168,6 +168,7 @@ Timeline::assign_tracks ()
                }
 
                shared_ptr<Content> content = cv->content();
+               DCPTimePeriod content_period (content->position(), content->end());
 
                int t = 0;
                while (true) {
@@ -182,11 +183,7 @@ Timeline::assign_tracks ()
                                shared_ptr<Content> test_content = test->content();
 
                                if (test && test->track() && test->track().get() == t) {
-                                       bool const no_overlap =
-                                               (content->position() < test_content->position() && content->end() < test_content->position()) ||
-                                               (content->position() > test_content->end()      && content->end() > test_content->end());
-
-                                       if (!no_overlap) {
+                                       if (content_period.overlaps (DCPTimePeriod(test_content->position(), test_content->end()))) {
                                                /* we have an overlap on track `t' */
                                                ++t;
                                                break;
@@ -367,7 +364,7 @@ Timeline::set_position_from_event (wxMouseEvent& ev)
 
        if (_snap) {
 
-               DCPTime const new_end = new_position + _down_view->content()->length_after_trim () - DCPTime (1);
+               DCPTime const new_end = new_position + _down_view->content()->length_after_trim();
                /* Signed `distance' to nearest thing (i.e. negative is left on the timeline,
                   positive is right).
                */
@@ -381,9 +378,9 @@ Timeline::set_position_from_event (wxMouseEvent& ev)
                        }
 
                        maybe_snap (cv->content()->position(), new_position, nearest_distance);
-                       maybe_snap (cv->content()->position(), new_end + DCPTime (1), nearest_distance);
-                       maybe_snap (cv->content()->end() + DCPTime (1), new_position, nearest_distance);
-                       maybe_snap (cv->content()->end() + DCPTime (1), new_end, nearest_distance);
+                       maybe_snap (cv->content()->position(), new_end, nearest_distance);
+                       maybe_snap (cv->content()->end(), new_position, nearest_distance);
+                       maybe_snap (cv->content()->end(), new_end, nearest_distance);
                }
 
                if (nearest_distance) {