ChangeLog.
[dcpomatic.git] / src / wx / timeline.cc
index d4df6d8b2be2b246005b6c543d3ec8d5eeab3f60..2e368e57d7b6373740efc865e895f0a0538aae79 100644 (file)
@@ -123,6 +123,10 @@ public:
                _track = t;
        }
 
+       void unset_track () {
+               _track = boost::optional<int> ();
+       }
+
        optional<int> track () const {
                return _track;
        }
@@ -362,7 +366,8 @@ Timeline::Timeline (wxWindow* parent, FilmEditor* ed, shared_ptr<Film> film)
 
        SetMinSize (wxSize (640, tracks() * track_height() + 96));
 
-       _playlist_connection = film->playlist()->Changed.connect (bind (&Timeline::playlist_changed, this));
+       _playlist_changed_connection = film->playlist()->Changed.connect (bind (&Timeline::playlist_changed, this));
+       _playlist_content_changed_connection = film->playlist()->ContentChanged.connect (bind (&Timeline::playlist_content_changed, this, _2));
 }
 
 void
@@ -413,19 +418,38 @@ Timeline::playlist_changed ()
        Refresh ();
 }
 
+void
+Timeline::playlist_content_changed (int property)
+{
+       ensure_ui_thread ();
+
+       if (property == ContentProperty::POSITION) {
+               assign_tracks ();
+               setup_pixels_per_time_unit ();
+               Refresh ();
+       }
+}
+
 void
 Timeline::assign_tracks ()
 {
+       for (ViewList::iterator i = _views.begin(); i != _views.end(); ++i) {
+               shared_ptr<ContentView> c = dynamic_pointer_cast<ContentView> (*i);
+               if (c) {
+                       c->unset_track ();
+               }
+       }
+
        for (ViewList::iterator i = _views.begin(); i != _views.end(); ++i) {
                shared_ptr<ContentView> cv = dynamic_pointer_cast<ContentView> (*i);
                if (!cv) {
                        continue;
                }
-       
+
                shared_ptr<Content> content = cv->content();
 
                int t = 0;
-               while (1) {
+               while (true) {
                        ViewList::iterator j = _views.begin();
                        while (j != _views.end()) {
                                shared_ptr<ContentView> test = dynamic_pointer_cast<ContentView> (*j);
@@ -623,7 +647,7 @@ Timeline::set_position_from_event (wxMouseEvent& ev)
                                Time const d = abs (cv->content()->end() - new_position);
                                if (first || d < nearest_distance) {
                                        nearest_distance = d;
-                                       nearest_new_position = cv->content()->end();
+                                       nearest_new_position = cv->content()->end() + 1;
                                }
                        }
                        
@@ -632,7 +656,7 @@ Timeline::set_position_from_event (wxMouseEvent& ev)
                                Time const d = abs (cv->content()->position() - (new_position + _down_view->content()->length_after_trim()));
                                if (d < nearest_distance) {
                                        nearest_distance = d;
-                                       nearest_new_position = cv->content()->position() - _down_view->content()->length_after_trim ();
+                                       nearest_new_position = cv->content()->position() - _down_view->content()->length_after_trim () - 1;
                                }
                        }
                        
@@ -650,7 +674,7 @@ Timeline::set_position_from_event (wxMouseEvent& ev)
        if (new_position < 0) {
                new_position = 0;
        }
-       
+
        _down_view->content()->set_position (new_position);
        
        shared_ptr<Film> film = _film.lock ();