monster commit: transport mgmt changes from 2.X (omnibus edition); make slave use...
[ardour.git] / gtk2_ardour / editor_drag.cc
index 81f210a9019e3497910d9b85a043689e6a101fc5..df12ddf94c0058b9bbda94beb4e605dd96f571d6 100644 (file)
@@ -20,6 +20,7 @@
 #include "pbd/memento_command.h"
 #include "pbd/basename.h"
 #include "ardour/diskstream.h"
+#include "ardour/session.h"
 #include "ardour/dB.h"
 #include "ardour/region_factory.h"
 #include "ardour/midi_diskstream.h"
@@ -49,15 +50,16 @@ using namespace ArdourCanvas;
 
 double const ControlPointDrag::_zero_gain_fraction = gain_to_slider_position (dB_to_coefficient (0.0));
 
-Drag::Drag (Editor* e, ArdourCanvas::Item* i) :
-       _editor (e),
-       _item (i),
-       _pointer_frame_offset (0),
-       _grab_frame (0),
-       _last_pointer_frame (0),
-       _current_pointer_frame (0),
-       _had_movement (false),
-       _move_threshold_passed (false)
+Drag::Drag (Editor* e, ArdourCanvas::Item* i) 
+       : _editor (e)
+       , _item (i)
+       , _pointer_frame_offset (0)
+       , _grab_frame (0)
+       , _last_pointer_frame (0)
+       , _current_pointer_frame (0)
+       , _had_movement (false)
+       , _have_transaction (false)
+       , _move_threshold_passed (false)
 {
 
 }
@@ -119,7 +121,7 @@ Drag::start_grab (GdkEvent* event, Gdk::Cursor *cursor)
                _was_rolling = false;
        }
 
-       switch (_editor->snap_type) {
+       switch (_editor->snap_type()) {
        case SnapToRegionStart:
        case SnapToRegionEnd:
        case SnapToRegionSync:
@@ -777,6 +779,8 @@ RegionMoveDrag::finished (GdkEvent* /*event*/, bool movement_occurred)
                }
        }
 
+       _have_transaction = true;
+
        changed_position = (_last_frame_position != (nframes64_t) (_primary->region()->position()));
        changed_tracks = (_dest_trackview != &_primary->get_time_axis_view());
 
@@ -1550,6 +1554,7 @@ TrimDrag::motion (GdkEvent* event, bool first_move)
                }
 
                _editor->begin_reversible_command (trim_type);
+               _have_transaction = true;
 
                for (list<RegionView*>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
                        (*i)->fake_set_opaque(false);
@@ -1575,6 +1580,9 @@ TrimDrag::motion (GdkEvent* event, bool first_move)
                return;
        }
 
+       /* XXX i hope to god that we can really conclude this ... */
+       _have_transaction = true;
+
        if (left_direction) {
                frame_delta = (_last_pointer_frame - _current_pointer_frame);
        } else {
@@ -1657,15 +1665,19 @@ TrimDrag::finished (GdkEvent* event, bool movement_occurred)
                                (*i)->fake_set_opaque (true);
                        }
                }
-
                for (set<boost::shared_ptr<Playlist> >::iterator p = _editor->motion_frozen_playlists.begin(); p != _editor->motion_frozen_playlists.end(); ++p) {
                        (*p)->thaw ();
-                       _editor->session->add_command (new MementoCommand<Playlist>(*(*p).get(), 0, &(*p)->get_state()));
+                       if (_have_transaction) {
+                               _editor->session->add_command (new MementoCommand<Playlist>(*(*p).get(), 0, &(*p)->get_state()));
+                       }
                }
 
                _editor->motion_frozen_playlists.clear ();
 
-               _editor->commit_reversible_command();
+               if (_have_transaction) {
+                       _editor->commit_reversible_command();
+               }
+
        } else {
                /* no mouse movement */
                _editor->point_trim (event);
@@ -1947,6 +1959,7 @@ FadeInDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
        boost::shared_ptr<AudioRegion> const r = a->audio_region ();
 
        _pointer_frame_offset = _grab_frame - ((nframes64_t) r->fade_in()->back()->when + r->position());
+       _editor->show_verbose_duration_cursor (r->position(), r->position() + r->fade_in()->back()->when, 10);
 }
 
 void
@@ -2039,6 +2052,7 @@ FadeOutDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
        boost::shared_ptr<AudioRegion> r = a->audio_region ();
 
        _pointer_frame_offset = _grab_frame - (r->length() - (nframes64_t) r->fade_out()->back()->when + r->position());
+       _editor->show_verbose_duration_cursor (r->last_frame() - r->fade_out()->back()->when, r->last_frame(), 10);
 }
 
 void
@@ -2850,9 +2864,9 @@ ScrubDrag::finished (GdkEvent* /*event*/, bool movement_occurred)
 }
 
 SelectionDrag::SelectionDrag (Editor* e, ArdourCanvas::Item* i, Operation o)
-       : Drag (e, i),
-         _operation (o),
-         _copy (false)
+       : Drag (e, i)
+       , _operation (o)
+       , _copy (false)
 {
 
 }
@@ -2921,6 +2935,7 @@ SelectionDrag::motion (GdkEvent* event, bool first_move)
        nframes64_t end = 0;
        nframes64_t length;
 
+
        nframes64_t const pending_position = adjusted_current_frame (event);
 
        /* only alter selection if the current frame is
@@ -2953,6 +2968,7 @@ SelectionDrag::motion (GdkEvent* event, bool first_move)
                if (first_move) {
 
                        _editor->begin_reversible_command (_("range selection"));
+                       _have_transaction = true;
 
                        if (_copy) {
                                /* adding to the selection */
@@ -2969,8 +2985,9 @@ SelectionDrag::motion (GdkEvent* event, bool first_move)
 
                if (first_move) {
                        _editor->begin_reversible_command (_("trim selection start"));
+                       _have_transaction = true;
                }
-
+               
                start = _editor->selection->time[_editor->clicked_selection].start;
                end = _editor->selection->time[_editor->clicked_selection].end;
 
@@ -2985,6 +3002,7 @@ SelectionDrag::motion (GdkEvent* event, bool first_move)
 
                if (first_move) {
                        _editor->begin_reversible_command (_("trim selection end"));
+                       _have_transaction = true;
                }
 
                start = _editor->selection->time[_editor->clicked_selection].start;
@@ -3002,6 +3020,7 @@ SelectionDrag::motion (GdkEvent* event, bool first_move)
 
                if (first_move) {
                        _editor->begin_reversible_command (_("move selection"));
+                       _have_transaction = true;
                }
 
                start = _editor->selection->time[_editor->clicked_selection].start;
@@ -3037,13 +3056,25 @@ SelectionDrag::motion (GdkEvent* event, bool first_move)
 void
 SelectionDrag::finished (GdkEvent* event, bool movement_occurred)
 {
+       Session* s = _editor->session;
+
        if (movement_occurred) {
                motion (event, false);
                /* XXX this is not object-oriented programming at all. ick */
                if (_editor->selection->time.consolidate()) {
                        _editor->selection->TimeChanged ();
                }
-               _editor->commit_reversible_command ();
+
+               if (_have_transaction) {
+                       _editor->commit_reversible_command ();
+               }
+
+               /* XXX what if its a music time selection? */
+               if (s && (s->config.get_auto_play() || (s->get_play_range() && s->transport_rolling()))) {
+                       s->request_play_range (&_editor->selection->time, true);
+               }
+
+
        } else {
                /* just a click, no pointer movement.*/
 
@@ -3052,10 +3083,13 @@ SelectionDrag::finished (GdkEvent* event, bool movement_occurred)
                        _editor->selection->clear_time();
 
                }
+               
+               if (s && s->get_play_range () && s->transport_rolling()) {
+                       s->request_stop (false, false);
+               }
+
        }
 
-       /* XXX what happens if its a music selection? */
-       _editor->session->set_audio_range (_editor->selection->time);
        _editor->stop_canvas_autoscroll ();
 }