some further debugging, just in case
[ardour.git] / gtk2_ardour / editor_drag.cc
index 1538457f7ebb6347eeab71227ca145b6f90541b5..dfab9f89906cf4ddc382813b4a944243ba98b56b 100644 (file)
@@ -40,6 +40,7 @@
 #include "ardour/profile.h"
 #include "ardour/region_factory.h"
 #include "ardour/session.h"
+#include "ardour/session_playlists.h"
 
 #include "canvas/canvas.h"
 #include "canvas/scroll_group.h"
@@ -628,6 +629,7 @@ RegionMotionDrag::RegionMotionDrag (Editor* e, ArdourCanvas::Item* i, RegionView
        , _pdropzone (0)
        , _ddropzone (0)
 {
+       _last_position = MusicFrame (_primary->region()->position(), 0);
        DEBUG_TRACE (DEBUG::Drags, "New RegionMotionDrag\n");
 }
 
@@ -662,6 +664,11 @@ RegionMotionDrag::compute_x_delta (GdkEvent const * event, MusicFrame* pending_r
        /* compute the amount of pointer motion in frames, and where
           the region would be if we moved it by that much.
        */
+       if (_x_constrained) {
+               *pending_region_position = _last_position;
+               return 0.0;
+       }
+
        *pending_region_position = adjusted_frame (_drags->current_pointer_frame (), event, false);
 
        framecnt_t sync_offset;
@@ -1586,7 +1593,7 @@ RegionMoveDrag::finished_no_copy (
        PlaylistSet frozen_playlists;
        set<RouteTimeAxisView*> views_to_update;
        RouteTimeAxisView* new_time_axis_view = 0;
-       framecnt_t const drag_delta = _primary->region()->position() - _last_position.frame;
+       framecnt_t const drag_delta = _primary->region()->position() - last_position.frame;
 
        typedef map<boost::shared_ptr<Playlist>, RouteTimeAxisView*> PlaylistMapping;
        PlaylistMapping playlist_mapping;
@@ -2988,6 +2995,21 @@ TrimDrag::motion (GdkEvent* event, bool first_move)
                        if (insert_result.second) {
                                pl->freeze();
                        }
+
+                       MidiRegionView* const mrv = dynamic_cast<MidiRegionView*> (rv);
+                       /* a MRV start trim may change the source length. ensure we cover all playlists here */
+                       if (mrv && _operation == StartTrim) {
+                               vector<boost::shared_ptr<Playlist> > all_playlists;
+                               _editor->session()->playlists->get (all_playlists);
+                               for (vector<boost::shared_ptr<Playlist> >::iterator x = all_playlists.begin(); x != all_playlists.end(); ++x) {
+                                       if ((*x)->uses_source (rv->region()->source(0))) {
+                                               insert_result = _editor->motion_frozen_playlists.insert (*x);
+                                               if (insert_result.second) {
+                                                       pl->freeze();
+                                               }
+                                       }
+                               }
+                       }
                }
        }
 
@@ -3136,29 +3158,22 @@ TrimDrag::finished (GdkEvent* event, bool movement_occurred)
                if (!_editor->selection->selected (_primary)) {
                        _primary->thaw_after_trim ();
                } else {
-
-                       set<boost::shared_ptr<Playlist> > diffed_playlists;
-
                        for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
                                i->view->thaw_after_trim ();
                                i->view->enable_display (true);
-
-                               /* Trimming one region may affect others on the playlist, so we need
-                                  to get undo Commands from the whole playlist rather than just the
-                                  region.  Use diffed_playlists to make sure we don't diff a given
-                                  playlist more than once.
-                               */
-                               boost::shared_ptr<Playlist> p = i->view->region()->playlist ();
-                               if (diffed_playlists.find (p) == diffed_playlists.end()) {
-                                       vector<Command*> cmds;
-                                       p->rdiff (cmds);
-                                       _editor->session()->add_commands (cmds);
-                                       diffed_playlists.insert (p);
-                               }
                        }
                }
 
                for (set<boost::shared_ptr<Playlist> >::iterator p = _editor->motion_frozen_playlists.begin(); p != _editor->motion_frozen_playlists.end(); ++p) {
+                       /* Trimming one region may affect others on the playlist, so we need
+                          to get undo Commands from the whole playlist rather than just the
+                          region.  Use motion_frozen_playlists (a set) to make sure we don't
+                          diff a given playlist more than once.
+                       */
+
+                       vector<Command*> cmds;
+                       (*p)->rdiff (cmds);
+                       _editor->session()->add_commands (cmds);
                        (*p)->thaw ();
                }