Optimise timeline view; speed up snapping and only set content panel selection on...
authorCarl Hetherington <cth@carlh.net>
Wed, 17 Feb 2016 09:32:03 +0000 (09:32 +0000)
committerCarl Hetherington <cth@carlh.net>
Wed, 17 Feb 2016 09:32:03 +0000 (09:32 +0000)
src/wx/timeline.cc
src/wx/timeline.h

index 0e6f95d51fe7a0aceec2ce7640043d1f44496f65..1516202bcbb286719ff00e96b4b12fffeeb04386 100644 (file)
@@ -29,6 +29,7 @@
 #include "lib/film.h"
 #include "lib/playlist.h"
 #include "lib/image_content.h"
+#include "lib/timer.h"
 #include "lib/audio_content.h"
 #include "lib/subtitle_content.h"
 #include <wx/graphics.h>
@@ -265,10 +266,6 @@ Timeline::left_down (wxMouseEvent& ev)
                if (!ev.ShiftDown ()) {
                        cv->set_selected (view == *i);
                }
-
-               if (view == *i) {
-                       _content_panel->set_selection (cv->content ());
-               }
        }
 
        if (content_view && ev.ShiftDown ()) {
@@ -280,6 +277,24 @@ Timeline::left_down (wxMouseEvent& ev)
        _first_move = false;
 
        if (_down_view) {
+               /* Pre-compute the points that we might snap to */
+               for (TimelineViewList::iterator i = _views.begin(); i != _views.end(); ++i) {
+                       shared_ptr<TimelineContentView> cv = dynamic_pointer_cast<TimelineContentView> (*i);
+                       if (!cv || cv == _down_view || cv->content() == _down_view->content()) {
+                               continue;
+                       }
+
+                       _start_snaps.push_back (cv->content()->position());
+                       _end_snaps.push_back (cv->content()->position());
+                       _start_snaps.push_back (cv->content()->end());
+                       _end_snaps.push_back (cv->content()->end());
+
+                       BOOST_FOREACH (DCPTime i, cv->content()->reel_split_points()) {
+                               _start_snaps.push_back (i);
+                       }
+               }
+
+               /* Tell everyone that things might change frequently during the drag */
                _down_view->content()->set_change_signals_frequent (true);
        }
 }
@@ -291,6 +306,7 @@ Timeline::left_up (wxMouseEvent& ev)
 
        if (_down_view) {
                _down_view->content()->set_change_signals_frequent (false);
+               _content_panel->set_selection (_down_view->content ());
        }
 
        set_position_from_event (ev);
@@ -300,6 +316,9 @@ Timeline::left_up (wxMouseEvent& ev)
        */
        setup_pixels_per_second ();
        Refresh ();
+
+       _start_snaps.clear ();
+       _end_snaps.clear ();
 }
 
 void
@@ -374,21 +393,14 @@ Timeline::set_position_from_event (wxMouseEvent& ev)
                */
                optional<DCPTime> nearest_distance;
 
-               /* Find the nearest snap point; this is inefficient */
-               for (TimelineViewList::iterator i = _views.begin(); i != _views.end(); ++i) {
-                       shared_ptr<TimelineContentView> cv = dynamic_pointer_cast<TimelineContentView> (*i);
-                       if (!cv || cv == _down_view || cv->content() == _down_view->content()) {
-                               continue;
-                       }
+               /* Find the nearest snap point */
 
-                       maybe_snap (cv->content()->position(), new_position, 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);
+               BOOST_FOREACH (DCPTime i, _start_snaps) {
+                       maybe_snap (i, new_position, nearest_distance);
+               }
 
-                       BOOST_FOREACH (DCPTime i, cv->content()->reel_split_points()) {
-                               maybe_snap (i, new_position, nearest_distance);
-                       }
+               BOOST_FOREACH (DCPTime i, _end_snaps) {
+                       maybe_snap (i, new_end, nearest_distance);
                }
 
                if (nearest_distance) {
index e8ae2120f7ad392f4def9eda9b6fb759df9f1484..e0e4dfb2a416e4b1668a151606d788ea9d1f0eb8 100644 (file)
@@ -109,6 +109,8 @@ private:
        bool _first_move;
        ContentMenu _menu;
        bool _snap;
+       std::list<DCPTime> _start_snaps;
+       std::list<DCPTime> _end_snaps;
 
        boost::signals2::scoped_connection _film_changed_connection;
        boost::signals2::scoped_connection _film_content_changed_connection;