2 Copyright (C) 2009 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "gtk2ardour-config.h"
27 #include "pbd/memento_command.h"
28 #include "pbd/basename.h"
29 #include "pbd/stateful_diff_command.h"
31 #include "gtkmm2ext/utils.h"
33 #include "ardour/audioengine.h"
34 #include "ardour/audioregion.h"
35 #include "ardour/dB.h"
36 #include "ardour/midi_region.h"
37 #include "ardour/operations.h"
38 #include "ardour/region_factory.h"
39 #include "ardour/session.h"
44 #include "audio_region_view.h"
45 #include "midi_region_view.h"
46 #include "ardour_ui.h"
47 #include "gui_thread.h"
48 #include "control_point.h"
50 #include "region_gain_line.h"
51 #include "editor_drag.h"
52 #include "audio_time_axis.h"
53 #include "midi_time_axis.h"
54 #include "canvas-note.h"
55 #include "selection.h"
56 #include "midi_selection.h"
57 #include "automation_time_axis.h"
59 #include "editor_cursors.h"
60 #include "mouse_cursors.h"
61 #include "verbose_cursor.h"
64 using namespace ARDOUR;
67 using namespace Gtkmm2ext;
68 using namespace Editing;
69 using namespace ArdourCanvas;
71 using Gtkmm2ext::Keyboard;
73 double ControlPointDrag::_zero_gain_fraction = -1.0;
75 DragManager::DragManager (Editor* e)
78 , _current_pointer_frame (0)
82 DragManager::~DragManager ()
87 /** Call abort for each active drag */
93 for (list<Drag*>::const_iterator i = _drags.begin(); i != _drags.end(); ++i) {
98 if (!_drags.empty ()) {
99 _editor->set_follow_playhead (_old_follow_playhead, false);
108 DragManager::add (Drag* d)
110 d->set_manager (this);
111 _drags.push_back (d);
115 DragManager::set (Drag* d, GdkEvent* e, Gdk::Cursor* c)
117 d->set_manager (this);
118 _drags.push_back (d);
123 DragManager::start_grab (GdkEvent* e, Gdk::Cursor* c)
125 /* Prevent follow playhead during the drag to be nice to the user */
126 _old_follow_playhead = _editor->follow_playhead ();
127 _editor->set_follow_playhead (false);
129 _current_pointer_frame = _editor->event_frame (e, &_current_pointer_x, &_current_pointer_y);
131 for (list<Drag*>::const_iterator i = _drags.begin(); i != _drags.end(); ++i) {
132 (*i)->start_grab (e, c);
136 /** Call end_grab for each active drag.
137 * @return true if any drag reported movement having occurred.
140 DragManager::end_grab (GdkEvent* e)
145 for (list<Drag*>::iterator i = _drags.begin(); i != _drags.end(); ++i) {
146 bool const t = (*i)->end_grab (e);
157 _editor->set_follow_playhead (_old_follow_playhead, false);
163 DragManager::motion_handler (GdkEvent* e, bool from_autoscroll)
167 _current_pointer_frame = _editor->event_frame (e, &_current_pointer_x, &_current_pointer_y);
169 for (list<Drag*>::iterator i = _drags.begin(); i != _drags.end(); ++i) {
170 bool const t = (*i)->motion_handler (e, from_autoscroll);
181 DragManager::have_item (ArdourCanvas::Item* i) const
183 list<Drag*>::const_iterator j = _drags.begin ();
184 while (j != _drags.end() && (*j)->item () != i) {
188 return j != _drags.end ();
191 Drag::Drag (Editor* e, ArdourCanvas::Item* i)
194 , _pointer_frame_offset (0)
195 , _move_threshold_passed (false)
196 , _raw_grab_frame (0)
198 , _last_pointer_frame (0)
204 Drag::swap_grab (ArdourCanvas::Item* new_item, Gdk::Cursor* cursor, uint32_t time)
210 _item->grab (Gdk::POINTER_MOTION_MASK | Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK, time);
212 _item->grab (Gdk::POINTER_MOTION_MASK | Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK, *cursor, time);
217 Drag::start_grab (GdkEvent* event, Gdk::Cursor *cursor)
219 // if dragging with button2, the motion is x constrained, with Alt-button2 it is y constrained
221 if (Keyboard::is_button2_event (&event->button)) {
222 if (Keyboard::modifier_state_equals (event->button.state, Keyboard::SecondaryModifier)) {
223 _y_constrained = true;
224 _x_constrained = false;
226 _y_constrained = false;
227 _x_constrained = true;
230 _x_constrained = false;
231 _y_constrained = false;
234 _raw_grab_frame = _editor->event_frame (event, &_grab_x, &_grab_y);
235 setup_pointer_frame_offset ();
236 _grab_frame = adjusted_frame (_raw_grab_frame, event);
237 _last_pointer_frame = _grab_frame;
238 _last_pointer_x = _grab_x;
239 _last_pointer_y = _grab_y;
242 _item->grab (Gdk::POINTER_MOTION_MASK|Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK,
245 _item->grab (Gdk::POINTER_MOTION_MASK|Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK,
250 if (_editor->session() && _editor->session()->transport_rolling()) {
253 _was_rolling = false;
256 switch (_editor->snap_type()) {
257 case SnapToRegionStart:
258 case SnapToRegionEnd:
259 case SnapToRegionSync:
260 case SnapToRegionBoundary:
261 _editor->build_region_boundary_cache ();
268 /** Call to end a drag `successfully'. Ungrabs item and calls
269 * subclass' finished() method.
271 * @param event GDK event, or 0.
272 * @return true if some movement occurred, otherwise false.
275 Drag::end_grab (GdkEvent* event)
277 _editor->stop_canvas_autoscroll ();
279 _item->ungrab (event ? event->button.time : 0);
281 finished (event, _move_threshold_passed);
283 _editor->verbose_cursor()->hide ();
285 return _move_threshold_passed;
289 Drag::adjusted_frame (framepos_t f, GdkEvent const * event, bool snap) const
293 if (f > _pointer_frame_offset) {
294 pos = f - _pointer_frame_offset;
298 _editor->snap_to_with_modifier (pos, event);
305 Drag::adjusted_current_frame (GdkEvent const * event, bool snap) const
307 return adjusted_frame (_drags->current_pointer_frame (), event, snap);
311 Drag::motion_handler (GdkEvent* event, bool from_autoscroll)
313 /* check to see if we have moved in any way that matters since the last motion event */
314 if (_move_threshold_passed &&
315 (!x_movement_matters() || _last_pointer_frame == adjusted_current_frame (event)) &&
316 (!y_movement_matters() || _last_pointer_y == _drags->current_pointer_y ()) ) {
320 pair<framecnt_t, int> const threshold = move_threshold ();
322 bool const old_move_threshold_passed = _move_threshold_passed;
324 if (!from_autoscroll && !_move_threshold_passed) {
326 bool const xp = (::llabs (_drags->current_pointer_frame () - _raw_grab_frame) >= threshold.first);
327 bool const yp = (::fabs ((_drags->current_pointer_y () - _grab_y)) >= threshold.second);
329 _move_threshold_passed = ((xp && x_movement_matters()) || (yp && y_movement_matters()));
332 if (active (_editor->mouse_mode) && _move_threshold_passed) {
334 if (event->motion.state & Gdk::BUTTON1_MASK || event->motion.state & Gdk::BUTTON2_MASK) {
335 if (!from_autoscroll) {
336 bool const moving_left = _drags->current_pointer_x() < _last_pointer_x;
337 bool const moving_up = _drags->current_pointer_y() < _last_pointer_y;
338 _editor->maybe_autoscroll (true, allow_vertical_autoscroll (), moving_left, moving_up);
341 motion (event, _move_threshold_passed != old_move_threshold_passed);
343 _last_pointer_x = _drags->current_pointer_x ();
344 _last_pointer_y = _drags->current_pointer_y ();
345 _last_pointer_frame = adjusted_current_frame (event);
353 /** Call to abort a drag. Ungrabs item and calls subclass's aborted () */
361 aborted (_move_threshold_passed);
363 _editor->stop_canvas_autoscroll ();
364 _editor->verbose_cursor()->hide ();
368 Drag::show_verbose_cursor_time (framepos_t frame)
370 _editor->verbose_cursor()->set_time (
372 _drags->current_pointer_x() + 10 - _editor->horizontal_position(),
373 _drags->current_pointer_y() + 10 - _editor->vertical_adjustment.get_value() + _editor->canvas_timebars_vsize
376 _editor->verbose_cursor()->show ();
380 Drag::show_verbose_cursor_duration (framepos_t start, framepos_t end, double xoffset)
382 _editor->verbose_cursor()->show (xoffset);
384 _editor->verbose_cursor()->set_duration (
386 _drags->current_pointer_x() + 10 - _editor->horizontal_position(),
387 _drags->current_pointer_y() + 10 - _editor->vertical_adjustment.get_value() + _editor->canvas_timebars_vsize
392 Drag::show_verbose_cursor_text (string const & text)
394 _editor->verbose_cursor()->show ();
396 _editor->verbose_cursor()->set (
398 _drags->current_pointer_x() + 10 - _editor->horizontal_position(),
399 _drags->current_pointer_y() + 10 - _editor->vertical_adjustment.get_value() + _editor->canvas_timebars_vsize
403 boost::shared_ptr<Region>
404 Drag::add_midi_region (MidiTimeAxisView* view)
406 if (_editor->session()) {
407 const TempoMap& map (_editor->session()->tempo_map());
408 framecnt_t pos = grab_frame();
409 const Meter& m = map.meter_at (pos);
410 /* not that the frame rate used here can be affected by pull up/down which
413 framecnt_t len = m.frames_per_bar (map.tempo_at (pos), _editor->session()->frame_rate());
414 return view->add_region (grab_frame(), len, true);
417 return boost::shared_ptr<Region>();
420 struct EditorOrderTimeAxisViewSorter {
421 bool operator() (TimeAxisView* a, TimeAxisView* b) {
422 RouteTimeAxisView* ra = dynamic_cast<RouteTimeAxisView*> (a);
423 RouteTimeAxisView* rb = dynamic_cast<RouteTimeAxisView*> (b);
425 return ra->route()->order_key () < rb->route()->order_key ();
429 RegionDrag::RegionDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, list<RegionView*> const & v)
433 _editor->visible_order_range (&_visible_y_low, &_visible_y_high);
435 /* Make a list of tracks to refer to during the drag; we include hidden tracks,
436 as some of the regions we are dragging may be on such tracks.
439 TrackViewList track_views = _editor->track_views;
440 track_views.sort (EditorOrderTimeAxisViewSorter ());
442 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
443 _time_axis_views.push_back (*i);
445 TimeAxisView::Children children_list = (*i)->get_child_list ();
446 for (TimeAxisView::Children::iterator j = children_list.begin(); j != children_list.end(); ++j) {
447 _time_axis_views.push_back (j->get());
451 /* the list of views can be empty at this point if this is a region list-insert drag
454 for (list<RegionView*>::const_iterator i = v.begin(); i != v.end(); ++i) {
455 _views.push_back (DraggingView (*i, this));
458 RegionView::RegionViewGoingAway.connect (death_connection, invalidator (*this), boost::bind (&RegionDrag::region_going_away, this, _1), gui_context());
462 RegionDrag::region_going_away (RegionView* v)
464 list<DraggingView>::iterator i = _views.begin ();
465 while (i != _views.end() && i->view != v) {
469 if (i != _views.end()) {
474 /** Given a TimeAxisView, return the index of it into the _time_axis_views vector,
475 * or -1 if it is not found.
478 RegionDrag::find_time_axis_view (TimeAxisView* t) const
481 int const N = _time_axis_views.size ();
482 while (i < N && _time_axis_views[i] != t) {
493 RegionMotionDrag::RegionMotionDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, list<RegionView*> const & v, bool b)
494 : RegionDrag (e, i, p, v),
503 RegionMotionDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
505 Drag::start_grab (event, cursor);
507 show_verbose_cursor_time (_last_frame_position);
509 pair<TimeAxisView*, double> const tv = _editor->trackview_by_y_position (_drags->current_pointer_y ());
510 _last_pointer_time_axis_view = find_time_axis_view (tv.first);
511 _last_pointer_layer = tv.first->layer_display() == Overlaid ? 0 : tv.second;
515 RegionMotionDrag::compute_x_delta (GdkEvent const * event, framepos_t* pending_region_position)
517 /* compute the amount of pointer motion in frames, and where
518 the region would be if we moved it by that much.
520 *pending_region_position = adjusted_current_frame (event);
522 framepos_t sync_frame;
523 framecnt_t sync_offset;
526 sync_offset = _primary->region()->sync_offset (sync_dir);
528 /* we don't handle a sync point that lies before zero.
530 if (sync_dir >= 0 || (sync_dir < 0 && *pending_region_position >= sync_offset)) {
532 sync_frame = *pending_region_position + (sync_dir*sync_offset);
534 _editor->snap_to_with_modifier (sync_frame, event);
536 *pending_region_position = _primary->region()->adjust_to_sync (sync_frame);
539 *pending_region_position = _last_frame_position;
542 if (*pending_region_position > max_framepos - _primary->region()->length()) {
543 *pending_region_position = _last_frame_position;
548 /* in locked edit mode, reverse the usual meaning of _x_constrained */
549 bool const x_move_allowed = Config->get_edit_mode() == Lock ? _x_constrained : !_x_constrained;
551 if ((*pending_region_position != _last_frame_position) && x_move_allowed) {
553 /* x movement since last time (in pixels) */
554 dx = (static_cast<double> (*pending_region_position) - _last_frame_position) / _editor->frames_per_unit;
556 /* total x movement */
557 framecnt_t total_dx = *pending_region_position;
558 if (regions_came_from_canvas()) {
559 total_dx = total_dx - grab_frame ();
562 /* check that no regions have gone off the start of the session */
563 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
564 if ((i->view->region()->position() + total_dx) < 0) {
566 *pending_region_position = _last_frame_position;
571 _last_frame_position = *pending_region_position;
578 RegionMotionDrag::y_movement_allowed (int delta_track, double delta_layer) const
580 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
581 int const n = i->time_axis_view + delta_track;
582 if (n < 0 || n >= int (_time_axis_views.size())) {
583 /* off the top or bottom track */
587 RouteTimeAxisView const * to = dynamic_cast<RouteTimeAxisView const *> (_time_axis_views[n]);
588 if (to == 0 || !to->is_track() || to->track()->data_type() != i->view->region()->data_type()) {
589 /* not a track, or the wrong type */
593 double const l = i->layer + delta_layer;
595 /* Note that we allow layer to be up to 0.5 below zero, as this is used by `Expanded'
596 mode to allow the user to place a region below another on layer 0.
598 if (delta_track == 0 && (l < -0.5 || l >= int (to->view()->layers()))) {
599 /* Off the top or bottom layer; note that we only refuse if the track hasn't changed.
600 If it has, the layers will be munged later anyway, so it's ok.
606 /* all regions being dragged are ok with this change */
611 RegionMotionDrag::motion (GdkEvent* event, bool first_move)
613 assert (!_views.empty ());
615 /* Find the TimeAxisView that the pointer is now over */
616 pair<TimeAxisView*, double> const tv = _editor->trackview_by_y_position (_drags->current_pointer_y ());
618 if (first_move && tv.first->view()->layer_display() == Stacked) {
619 tv.first->view()->set_layer_display (Expanded);
622 /* Bail early if we're not over a track */
623 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (tv.first);
624 if (!rtv || !rtv->is_track()) {
625 _editor->verbose_cursor()->hide ();
629 /* Note: time axis views in this method are often expressed as an index into the _time_axis_views vector */
631 /* Here's the current pointer position in terms of time axis view and layer */
632 int const current_pointer_time_axis_view = find_time_axis_view (tv.first);
633 double const current_pointer_layer = tv.first->layer_display() == Overlaid ? 0 : tv.second;
635 /* Work out the change in x */
636 framepos_t pending_region_position;
637 double const x_delta = compute_x_delta (event, &pending_region_position);
639 /* Work out the change in y */
640 int delta_time_axis_view = current_pointer_time_axis_view - _last_pointer_time_axis_view;
641 double delta_layer = current_pointer_layer - _last_pointer_layer;
643 if (!y_movement_allowed (delta_time_axis_view, delta_layer)) {
644 /* this y movement is not allowed, so do no y movement this time */
645 delta_time_axis_view = 0;
649 if (x_delta == 0 && delta_time_axis_view == 0 && delta_layer == 0 && !first_move) {
650 /* haven't reached next snap point, and we're not switching
651 trackviews nor layers. nothing to do.
656 pair<set<boost::shared_ptr<Playlist> >::iterator,bool> insert_result;
658 for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
660 RegionView* rv = i->view;
662 if (rv->region()->locked() || rv->region()->video_locked()) {
670 /* Absolutely no idea why this is necessary, but it is; without
671 it, the region view disappears after the reparent.
673 _editor->update_canvas_now ();
675 /* Reparent to a non scrolling group so that we can keep the
676 region selection above all time axis views.
677 Reparenting means that we will have to move the region view
678 later, as the two parent groups have different coordinates.
681 rv->get_canvas_group()->reparent (*(_editor->_region_motion_group));
683 rv->fake_set_opaque (true);
686 /* If we have moved tracks, we'll fudge the layer delta so that the
687 region gets moved back onto layer 0 on its new track; this avoids
688 confusion when dragging regions from non-zero layers onto different
691 double this_delta_layer = delta_layer;
692 if (delta_time_axis_view != 0) {
693 this_delta_layer = - i->layer;
696 /* The TimeAxisView that this region is now on */
697 TimeAxisView* tv = _time_axis_views[i->time_axis_view + delta_time_axis_view];
699 /* Ensure it is moved from stacked -> expanded if appropriate */
700 if (tv->view()->layer_display() == Stacked) {
701 tv->view()->set_layer_display (Expanded);
704 /* We're only allowed to go -ve in layer on Expanded views */
705 if (tv->view()->layer_display() != Expanded && (i->layer + this_delta_layer) < 0) {
706 this_delta_layer = - i->layer;
710 rv->set_height (tv->view()->child_height ());
712 /* Update show/hidden status as the region view may have come from a hidden track,
713 or have moved to one.
716 rv->get_canvas_group()->hide ();
718 rv->get_canvas_group()->show ();
721 /* Update the DraggingView */
722 i->time_axis_view += delta_time_axis_view;
723 i->layer += this_delta_layer;
726 _editor->mouse_brush_insert_region (rv, pending_region_position);
731 /* Get the y coordinate of the top of the track that this region is now on */
732 tv->canvas_display()->i2w (x, y);
733 y += _editor->get_trackview_group_vertical_offset();
735 /* And adjust for the layer that it should be on */
736 StreamView* cv = tv->view ();
737 switch (cv->layer_display ()) {
741 y += (cv->layers() - i->layer - 1) * cv->child_height ();
744 y += (cv->layers() - i->layer - 0.5) * 2 * cv->child_height ();
748 /* Now move the region view */
749 rv->move (x_delta, y - rv->get_canvas_group()->property_y());
752 } /* foreach region */
754 _total_x_delta += x_delta;
757 _editor->cursor_group->raise_to_top();
760 if (x_delta != 0 && !_brushing) {
761 show_verbose_cursor_time (_last_frame_position);
764 _last_pointer_time_axis_view += delta_time_axis_view;
765 _last_pointer_layer += delta_layer;
769 RegionMoveDrag::motion (GdkEvent* event, bool first_move)
771 if (_copy && first_move) {
773 /* duplicate the regionview(s) and region(s) */
775 list<DraggingView> new_regionviews;
777 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
779 RegionView* rv = i->view;
780 AudioRegionView* arv = dynamic_cast<AudioRegionView*>(rv);
781 MidiRegionView* mrv = dynamic_cast<MidiRegionView*>(rv);
783 const boost::shared_ptr<const Region> original = rv->region();
784 boost::shared_ptr<Region> region_copy = RegionFactory::create (original, true);
785 region_copy->set_position (original->position());
789 boost::shared_ptr<AudioRegion> audioregion_copy
790 = boost::dynamic_pointer_cast<AudioRegion>(region_copy);
792 nrv = new AudioRegionView (*arv, audioregion_copy);
794 boost::shared_ptr<MidiRegion> midiregion_copy
795 = boost::dynamic_pointer_cast<MidiRegion>(region_copy);
796 nrv = new MidiRegionView (*mrv, midiregion_copy);
801 nrv->get_canvas_group()->show ();
802 new_regionviews.push_back (DraggingView (nrv, this));
804 /* swap _primary to the copy */
806 if (rv == _primary) {
810 /* ..and deselect the one we copied */
812 rv->set_selected (false);
815 if (!new_regionviews.empty()) {
817 /* reflect the fact that we are dragging the copies */
819 _views = new_regionviews;
821 swap_grab (new_regionviews.front().view->get_canvas_group (), 0, event ? event->motion.time : 0);
824 sync the canvas to what we think is its current state
825 without it, the canvas seems to
826 "forget" to update properly after the upcoming reparent()
827 ..only if the mouse is in rapid motion at the time of the grab.
828 something to do with regionview creation taking so long?
830 _editor->update_canvas_now();
834 RegionMotionDrag::motion (event, first_move);
838 RegionMotionDrag::finished (GdkEvent *, bool)
840 for (vector<TimeAxisView*>::iterator i = _time_axis_views.begin(); i != _time_axis_views.end(); ++i) {
845 if ((*i)->view()->layer_display() == Expanded) {
846 (*i)->view()->set_layer_display (Stacked);
852 RegionMoveDrag::finished (GdkEvent* ev, bool movement_occurred)
854 RegionMotionDrag::finished (ev, movement_occurred);
856 if (!movement_occurred) {
861 /* reverse this here so that we have the correct logic to finalize
865 if (Config->get_edit_mode() == Lock) {
866 _x_constrained = !_x_constrained;
869 assert (!_views.empty ());
871 /* We might have hidden region views so that they weren't visible during the drag
872 (when they have been reparented). Now everything can be shown again, as region
873 views are back in their track parent groups.
875 for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
876 i->view->get_canvas_group()->show ();
879 bool const changed_position = (_last_frame_position != _primary->region()->position());
880 bool const changed_tracks = (_time_axis_views[_views.front().time_axis_view] != &_views.front().view->get_time_axis_view());
881 framecnt_t const drag_delta = _primary->region()->position() - _last_frame_position;
883 _editor->update_canvas_now ();
903 _editor->maybe_locate_with_edit_preroll (_editor->get_selection().regions.start());
907 RegionMoveDrag::finished_copy (bool const changed_position, bool const /*changed_tracks*/, framecnt_t const drag_delta)
909 RegionSelection new_views;
910 PlaylistSet modified_playlists;
911 list<RegionView*> views_to_delete;
914 /* all changes were made during motion event handlers */
916 for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
920 _editor->commit_reversible_command ();
924 if (_x_constrained) {
925 _editor->begin_reversible_command (Operations::fixed_time_region_copy);
927 _editor->begin_reversible_command (Operations::region_copy);
930 /* insert the regions into their new playlists */
931 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
933 if (i->view->region()->locked() || i->view->region()->video_locked()) {
939 if (changed_position && !_x_constrained) {
940 where = i->view->region()->position() - drag_delta;
942 where = i->view->region()->position();
945 RegionView* new_view = insert_region_into_playlist (
946 i->view->region(), dynamic_cast<RouteTimeAxisView*> (_time_axis_views[i->time_axis_view]), i->layer, where, modified_playlists
953 new_views.push_back (new_view);
955 /* we don't need the copied RegionView any more */
956 views_to_delete.push_back (i->view);
959 /* Delete views that are no longer needed; we can't do this directly in the iteration over _views
960 because when views are deleted they are automagically removed from _views, which messes
963 for (list<RegionView*>::iterator i = views_to_delete.begin(); i != views_to_delete.end(); ++i) {
967 /* If we've created new regions either by copying or moving
968 to a new track, we want to replace the old selection with the new ones
971 if (new_views.size() > 0) {
972 _editor->selection->set (new_views);
975 /* write commands for the accumulated diffs for all our modified playlists */
976 add_stateful_diff_commands_for_playlists (modified_playlists);
978 _editor->commit_reversible_command ();
982 RegionMoveDrag::finished_no_copy (
983 bool const changed_position,
984 bool const changed_tracks,
985 framecnt_t const drag_delta
988 RegionSelection new_views;
989 PlaylistSet modified_playlists;
990 PlaylistSet frozen_playlists;
991 set<RouteTimeAxisView*> views_to_update;
994 /* all changes were made during motion event handlers */
995 _editor->commit_reversible_command ();
999 if (_x_constrained) {
1000 _editor->begin_reversible_command (_("fixed time region drag"));
1002 _editor->begin_reversible_command (Operations::region_drag);
1005 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ) {
1007 RegionView* rv = i->view;
1009 RouteTimeAxisView* const dest_rtv = dynamic_cast<RouteTimeAxisView*> (_time_axis_views[i->time_axis_view]);
1010 double const dest_layer = i->layer;
1012 if (rv->region()->locked() || rv->region()->video_locked()) {
1017 views_to_update.insert (dest_rtv);
1021 if (changed_position && !_x_constrained) {
1022 where = rv->region()->position() - drag_delta;
1024 where = rv->region()->position();
1027 if (changed_tracks) {
1029 /* insert into new playlist */
1031 RegionView* new_view = insert_region_into_playlist (
1032 RegionFactory::create (rv->region (), true), dest_rtv, dest_layer, where, modified_playlists
1035 if (new_view == 0) {
1040 new_views.push_back (new_view);
1042 /* remove from old playlist */
1044 /* the region that used to be in the old playlist is not
1045 moved to the new one - we use a copy of it. as a result,
1046 any existing editor for the region should no longer be
1049 rv->hide_region_editor();
1050 rv->fake_set_opaque (false);
1052 remove_region_from_playlist (rv->region(), i->initial_playlist, modified_playlists);
1056 rv->region()->clear_changes ();
1059 motion on the same track. plonk the previously reparented region
1060 back to its original canvas group (its streamview).
1061 No need to do anything for copies as they are fake regions which will be deleted.
1064 rv->get_canvas_group()->reparent (*dest_rtv->view()->canvas_item());
1065 rv->get_canvas_group()->property_y() = i->initial_y;
1068 /* just change the model */
1070 boost::shared_ptr<Playlist> playlist = dest_rtv->playlist();
1072 if (dest_rtv->view()->layer_display() == Stacked || dest_rtv->view()->layer_display() == Expanded) {
1073 playlist->set_layer (rv->region(), dest_layer);
1076 /* freeze playlist to avoid lots of relayering in the case of a multi-region drag */
1078 pair<PlaylistSet::iterator, bool> r = frozen_playlists.insert (playlist);
1081 playlist->freeze ();
1084 /* this movement may result in a crossfade being modified, so we need to get undo
1085 data from the playlist as well as the region.
1088 r = modified_playlists.insert (playlist);
1090 playlist->clear_changes ();
1093 rv->region()->set_position (where);
1095 _editor->session()->add_command (new StatefulDiffCommand (rv->region()));
1098 if (changed_tracks) {
1100 /* OK, this is where it gets tricky. If the playlist was being used by >1 tracks, and the region
1101 was selected in all of them, then removing it from a playlist will have removed all
1102 trace of it from _views (i.e. there were N regions selected, we removed 1,
1103 but since its the same playlist for N tracks, all N tracks updated themselves, removed the
1104 corresponding regionview, and _views is now empty).
1106 This could have invalidated any and all iterators into _views.
1108 The heuristic we use here is: if the region selection is empty, break out of the loop
1109 here. if the region selection is not empty, then restart the loop because we know that
1110 we must have removed at least the region(view) we've just been working on as well as any
1111 that we processed on previous iterations.
1113 EXCEPT .... if we are doing a copy drag, then _views hasn't been modified and
1114 we can just iterate.
1118 if (_views.empty()) {
1129 /* If we've created new regions either by copying or moving
1130 to a new track, we want to replace the old selection with the new ones
1133 if (new_views.size() > 0) {
1134 _editor->selection->set (new_views);
1137 for (set<boost::shared_ptr<Playlist> >::iterator p = frozen_playlists.begin(); p != frozen_playlists.end(); ++p) {
1141 /* write commands for the accumulated diffs for all our modified playlists */
1142 add_stateful_diff_commands_for_playlists (modified_playlists);
1144 _editor->commit_reversible_command ();
1146 /* We have futzed with the layering of canvas items on our streamviews.
1147 If any region changed layer, this will have resulted in the stream
1148 views being asked to set up their region views, and all will be well.
1149 If not, we might now have badly-ordered region views. Ask the StreamViews
1150 involved to sort themselves out, just in case.
1153 for (set<RouteTimeAxisView*>::iterator i = views_to_update.begin(); i != views_to_update.end(); ++i) {
1154 (*i)->view()->playlist_layered ((*i)->track ());
1158 /** Remove a region from a playlist, clearing the diff history of the playlist first if necessary.
1159 * @param region Region to remove.
1160 * @param playlist playlist To remove from.
1161 * @param modified_playlists The playlist will be added to this if it is not there already; used to ensure
1162 * that clear_changes () is only called once per playlist.
1165 RegionMoveDrag::remove_region_from_playlist (
1166 boost::shared_ptr<Region> region,
1167 boost::shared_ptr<Playlist> playlist,
1168 PlaylistSet& modified_playlists
1171 pair<set<boost::shared_ptr<Playlist> >::iterator, bool> r = modified_playlists.insert (playlist);
1174 playlist->clear_changes ();
1177 playlist->remove_region (region);
1181 /** Insert a region into a playlist, handling the recovery of the resulting new RegionView, and
1182 * clearing the playlist's diff history first if necessary.
1183 * @param region Region to insert.
1184 * @param dest_rtv Destination RouteTimeAxisView.
1185 * @param dest_layer Destination layer.
1186 * @param where Destination position.
1187 * @param modified_playlists The playlist will be added to this if it is not there already; used to ensure
1188 * that clear_changes () is only called once per playlist.
1189 * @return New RegionView, or 0 if no insert was performed.
1192 RegionMoveDrag::insert_region_into_playlist (
1193 boost::shared_ptr<Region> region,
1194 RouteTimeAxisView* dest_rtv,
1197 PlaylistSet& modified_playlists
1200 boost::shared_ptr<Playlist> dest_playlist = dest_rtv->playlist ();
1201 if (!dest_playlist) {
1205 /* arrange to collect the new region view that will be created as a result of our playlist insertion */
1206 _new_region_view = 0;
1207 sigc::connection c = dest_rtv->view()->RegionViewAdded.connect (sigc::mem_fun (*this, &RegionMoveDrag::collect_new_region_view));
1209 /* clear history for the playlist we are about to insert to, provided we haven't already done so */
1210 pair<PlaylistSet::iterator, bool> r = modified_playlists.insert (dest_playlist);
1212 dest_playlist->clear_changes ();
1215 dest_playlist->add_region (region, where);
1217 if (dest_rtv->view()->layer_display() == Stacked || dest_rtv->view()->layer_display() == Expanded) {
1218 dest_playlist->set_layer (region, dest_layer);
1223 assert (_new_region_view);
1225 return _new_region_view;
1229 RegionMoveDrag::collect_new_region_view (RegionView* rv)
1231 _new_region_view = rv;
1235 RegionMoveDrag::add_stateful_diff_commands_for_playlists (PlaylistSet const & playlists)
1237 for (PlaylistSet::const_iterator i = playlists.begin(); i != playlists.end(); ++i) {
1238 StatefulDiffCommand* c = new StatefulDiffCommand (*i);
1240 _editor->session()->add_command (c);
1249 RegionMoveDrag::aborted (bool movement_occurred)
1253 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
1260 RegionMotionDrag::aborted (movement_occurred);
1265 RegionMotionDrag::aborted (bool)
1267 for (vector<TimeAxisView*>::iterator i = _time_axis_views.begin(); i != _time_axis_views.end(); ++i) {
1268 if ((*i)->view()->layer_display() == Expanded) {
1269 (*i)->view()->set_layer_display (Stacked);
1273 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
1274 RegionView* rv = i->view;
1275 TimeAxisView* tv = &(rv->get_time_axis_view ());
1276 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (tv);
1278 rv->get_canvas_group()->reparent (*rtv->view()->canvas_item());
1279 rv->get_canvas_group()->property_y() = 0;
1281 rv->fake_set_opaque (false);
1282 rv->move (-_total_x_delta, 0);
1283 rv->set_height (rtv->view()->child_height ());
1286 _editor->update_canvas_now ();
1289 /** @param b true to brush, otherwise false.
1290 * @param c true to make copies of the regions being moved, otherwise false.
1292 RegionMoveDrag::RegionMoveDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, list<RegionView*> const & v, bool b, bool c)
1293 : RegionMotionDrag (e, i, p, v, b),
1296 DEBUG_TRACE (DEBUG::Drags, "New RegionMoveDrag\n");
1299 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (&_primary->get_time_axis_view ());
1300 if (rtv && rtv->is_track()) {
1301 speed = rtv->track()->speed ();
1304 _last_frame_position = static_cast<framepos_t> (_primary->region()->position() / speed);
1308 RegionMoveDrag::setup_pointer_frame_offset ()
1310 _pointer_frame_offset = raw_grab_frame() - _last_frame_position;
1313 RegionInsertDrag::RegionInsertDrag (Editor* e, boost::shared_ptr<Region> r, RouteTimeAxisView* v, framepos_t pos)
1314 : RegionMotionDrag (e, 0, 0, list<RegionView*> (), false)
1316 DEBUG_TRACE (DEBUG::Drags, "New RegionInsertDrag\n");
1318 assert ((boost::dynamic_pointer_cast<AudioRegion> (r) && dynamic_cast<AudioTimeAxisView*> (v)) ||
1319 (boost::dynamic_pointer_cast<MidiRegion> (r) && dynamic_cast<MidiTimeAxisView*> (v)));
1321 _primary = v->view()->create_region_view (r, false, false);
1323 _primary->get_canvas_group()->show ();
1324 _primary->set_position (pos, 0);
1325 _views.push_back (DraggingView (_primary, this));
1327 _last_frame_position = pos;
1329 _item = _primary->get_canvas_group ();
1333 RegionInsertDrag::finished (GdkEvent *, bool)
1335 _editor->update_canvas_now ();
1337 RouteTimeAxisView* dest_rtv = dynamic_cast<RouteTimeAxisView*> (_time_axis_views[_views.front().time_axis_view]);
1339 _primary->get_canvas_group()->reparent (*dest_rtv->view()->canvas_item());
1340 _primary->get_canvas_group()->property_y() = 0;
1342 boost::shared_ptr<Playlist> playlist = dest_rtv->playlist();
1344 _editor->begin_reversible_command (Operations::insert_region);
1345 playlist->clear_changes ();
1346 playlist->add_region (_primary->region (), _last_frame_position);
1347 _editor->session()->add_command (new StatefulDiffCommand (playlist));
1348 _editor->commit_reversible_command ();
1356 RegionInsertDrag::aborted (bool)
1363 RegionSpliceDrag::RegionSpliceDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, list<RegionView*> const & v)
1364 : RegionMoveDrag (e, i, p, v, false, false)
1366 DEBUG_TRACE (DEBUG::Drags, "New RegionSpliceDrag\n");
1369 struct RegionSelectionByPosition {
1370 bool operator() (RegionView*a, RegionView* b) {
1371 return a->region()->position () < b->region()->position();
1376 RegionSpliceDrag::motion (GdkEvent* event, bool)
1378 /* Which trackview is this ? */
1380 pair<TimeAxisView*, double> const tvp = _editor->trackview_by_y_position (_drags->current_pointer_y ());
1381 RouteTimeAxisView* tv = dynamic_cast<RouteTimeAxisView*> (tvp.first);
1383 /* The region motion is only processed if the pointer is over
1387 if (!tv || !tv->is_track()) {
1388 /* To make sure we hide the verbose canvas cursor when the mouse is
1389 not held over and audiotrack.
1391 _editor->verbose_cursor()->hide ();
1397 if ((_drags->current_pointer_x() - last_pointer_x()) > 0) {
1403 RegionSelection copy (_editor->selection->regions);
1405 RegionSelectionByPosition cmp;
1408 framepos_t const pf = adjusted_current_frame (event);
1410 for (RegionSelection::iterator i = copy.begin(); i != copy.end(); ++i) {
1412 RouteTimeAxisView* atv = dynamic_cast<RouteTimeAxisView*> (&(*i)->get_time_axis_view());
1418 boost::shared_ptr<Playlist> playlist;
1420 if ((playlist = atv->playlist()) == 0) {
1424 if (!playlist->region_is_shuffle_constrained ((*i)->region())) {
1429 if (pf < (*i)->region()->last_frame() + 1) {
1433 if (pf > (*i)->region()->first_frame()) {
1439 playlist->shuffle ((*i)->region(), dir);
1444 RegionSpliceDrag::finished (GdkEvent* event, bool movement_occurred)
1446 RegionMoveDrag::finished (event, movement_occurred);
1450 RegionSpliceDrag::aborted (bool)
1455 RegionCreateDrag::RegionCreateDrag (Editor* e, ArdourCanvas::Item* i, TimeAxisView* v)
1457 _view (dynamic_cast<MidiTimeAxisView*> (v))
1459 DEBUG_TRACE (DEBUG::Drags, "New RegionCreateDrag\n");
1465 RegionCreateDrag::motion (GdkEvent* event, bool first_move)
1468 _region = add_midi_region (_view);
1469 _view->playlist()->freeze ();
1472 framepos_t const f = adjusted_current_frame (event);
1473 if (f < grab_frame()) {
1474 _region->set_position (f);
1477 /* Don't use a zero-length region, and subtract 1 frame from the snapped length
1478 so that if this region is duplicated, its duplicate starts on
1479 a snap point rather than 1 frame after a snap point. Otherwise things get
1480 a bit confusing as if a region starts 1 frame after a snap point, one cannot
1481 place snapped notes at the start of the region.
1484 framecnt_t const len = (framecnt_t) fabs (f - grab_frame () - 1);
1485 _region->set_length (len < 1 ? 1 : len);
1491 RegionCreateDrag::finished (GdkEvent*, bool movement_occurred)
1493 if (!movement_occurred) {
1494 add_midi_region (_view);
1496 _view->playlist()->thaw ();
1501 RegionCreateDrag::aborted (bool)
1504 _view->playlist()->thaw ();
1510 NoteResizeDrag::NoteResizeDrag (Editor* e, ArdourCanvas::Item* i)
1514 DEBUG_TRACE (DEBUG::Drags, "New NoteResizeDrag\n");
1518 NoteResizeDrag::start_grab (GdkEvent* event, Gdk::Cursor* /*ignored*/)
1520 Gdk::Cursor* cursor;
1521 ArdourCanvas::CanvasNoteEvent* cnote = dynamic_cast<ArdourCanvas::CanvasNoteEvent*>(_item);
1522 float x_fraction = cnote->mouse_x_fraction ();
1524 if (x_fraction > 0.0 && x_fraction < 0.25) {
1525 cursor = _editor->cursors()->left_side_trim;
1527 cursor = _editor->cursors()->right_side_trim;
1530 Drag::start_grab (event, cursor);
1532 region = &cnote->region_view();
1534 double const region_start = region->get_position_pixels();
1535 double const middle_point = region_start + cnote->x1() + (cnote->x2() - cnote->x1()) / 2.0L;
1537 if (grab_x() <= middle_point) {
1538 cursor = _editor->cursors()->left_side_trim;
1541 cursor = _editor->cursors()->right_side_trim;
1545 _item->grab(GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK, *cursor, event->motion.time);
1547 if (event->motion.state & Keyboard::PrimaryModifier) {
1553 MidiRegionSelection& ms (_editor->get_selection().midi_regions);
1555 if (ms.size() > 1) {
1556 /* has to be relative, may make no sense otherwise */
1560 /* select this note; if it is already selected, preserve the existing selection,
1561 otherwise make this note the only one selected.
1563 region->note_selected (cnote, cnote->selected ());
1565 for (MidiRegionSelection::iterator r = ms.begin(); r != ms.end(); ) {
1566 MidiRegionSelection::iterator next;
1569 (*r)->begin_resizing (at_front);
1575 NoteResizeDrag::motion (GdkEvent* /*event*/, bool /*first_move*/)
1577 MidiRegionSelection& ms (_editor->get_selection().midi_regions);
1578 for (MidiRegionSelection::iterator r = ms.begin(); r != ms.end(); ++r) {
1579 (*r)->update_resizing (dynamic_cast<ArdourCanvas::CanvasNoteEvent*>(_item), at_front, _drags->current_pointer_x() - grab_x(), relative);
1584 NoteResizeDrag::finished (GdkEvent*, bool /*movement_occurred*/)
1586 MidiRegionSelection& ms (_editor->get_selection().midi_regions);
1587 for (MidiRegionSelection::iterator r = ms.begin(); r != ms.end(); ++r) {
1588 (*r)->commit_resizing (dynamic_cast<ArdourCanvas::CanvasNoteEvent*>(_item), at_front, _drags->current_pointer_x() - grab_x(), relative);
1593 NoteResizeDrag::aborted (bool)
1595 MidiRegionSelection& ms (_editor->get_selection().midi_regions);
1596 for (MidiRegionSelection::iterator r = ms.begin(); r != ms.end(); ++r) {
1597 (*r)->abort_resizing ();
1601 AVDraggingView::AVDraggingView (RegionView* v)
1604 initial_position = v->region()->position ();
1607 VideoTimeLineDrag::VideoTimeLineDrag (Editor* e, ArdourCanvas::Item* i)
1610 DEBUG_TRACE (DEBUG::Drags, "New VideoTimeLineDrag\n");
1613 TrackViewList empty;
1615 _editor->get_regions_after(rs, (framepos_t) 0, empty);
1616 std::list<RegionView*> views = rs.by_layer();
1618 for (list<RegionView*>::iterator i = views.begin(); i != views.end(); ++i) {
1619 RegionView* rv = (*i);
1620 if (!rv->region()->video_locked()) {
1623 _views.push_back (AVDraggingView (rv));
1628 VideoTimeLineDrag::start_grab (GdkEvent* event, Gdk::Cursor*)
1630 Drag::start_grab (event);
1631 if (_editor->session() == 0) {
1635 _startdrag_video_offset=ARDOUR_UI::instance()->video_timeline->get_offset();
1636 _max_backwards_drag = (
1637 ARDOUR_UI::instance()->video_timeline->get_duration()
1638 + ARDOUR_UI::instance()->video_timeline->get_offset()
1639 - ceil(ARDOUR_UI::instance()->video_timeline->get_apv())
1642 for (list<AVDraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
1643 if (i->initial_position < _max_backwards_drag || _max_backwards_drag < 0) {
1644 _max_backwards_drag = ARDOUR_UI::instance()->video_timeline->quantify_frames_to_apv (i->initial_position);
1647 DEBUG_TRACE (DEBUG::Drags, string_compose("VideoTimeLineDrag: max backwards-drag: %1\n", _max_backwards_drag));
1650 Timecode::Time timecode;
1651 _editor->session()->sample_to_timecode(abs(_startdrag_video_offset), timecode, true /* use_offset */, false /* use_subframes */ );
1652 snprintf (buf, sizeof (buf), "Video Start:\n%c%02" PRId32 ":%02" PRId32 ":%02" PRId32 ":%02" PRId32, (_startdrag_video_offset<0?'-':' '), timecode.hours, timecode.minutes, timecode.seconds, timecode.frames);
1653 _editor->verbose_cursor()->set(buf, event->button.x + 10, event->button.y + 10);
1654 _editor->verbose_cursor()->show ();
1658 VideoTimeLineDrag::motion (GdkEvent* event, bool first_move)
1660 if (_editor->session() == 0) {
1663 if (ARDOUR_UI::instance()->video_timeline->is_offset_locked()) {
1667 framecnt_t dt = adjusted_current_frame (event) - raw_grab_frame() + _pointer_frame_offset;
1668 dt = ARDOUR_UI::instance()->video_timeline->quantify_frames_to_apv(_startdrag_video_offset+dt) - _startdrag_video_offset;
1670 if (_max_backwards_drag >= 0 && dt <= - _max_backwards_drag) {
1671 dt = - _max_backwards_drag;
1674 ARDOUR_UI::instance()->video_timeline->set_offset(_startdrag_video_offset+dt);
1675 ARDOUR_UI::instance()->flush_videotimeline_cache(true);
1677 for (list<AVDraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
1678 RegionView* rv = i->view;
1679 DEBUG_TRACE (DEBUG::Drags, string_compose("SHIFT REGION at %1 by %2\n", i->initial_position, dt));
1682 _editor->update_canvas_now ();
1683 rv->fake_set_opaque (true);
1684 rv->region()->clear_changes ();
1685 rv->region()->suspend_property_changes();
1687 rv->region()->set_position(i->initial_position + dt);
1688 rv->region_changed(ARDOUR::Properties::position);
1691 const framepos_t offset = ARDOUR_UI::instance()->video_timeline->get_offset();
1692 Timecode::Time timecode;
1693 Timecode::Time timediff;
1695 _editor->session()->sample_to_timecode(abs(offset), timecode, true /* use_offset */, false /* use_subframes */ );
1696 _editor->session()->sample_to_timecode(abs(dt), timediff, false /* use_offset */, false /* use_subframes */ );
1697 snprintf (buf, sizeof (buf),
1698 "%s\n%c%02" PRId32 ":%02" PRId32 ":%02" PRId32 ":%02" PRId32
1699 "\n%s\n%c%02" PRId32 ":%02" PRId32 ":%02" PRId32 ":%02" PRId32
1700 , _("Video Start:"),
1701 (offset<0?'-':' '), timecode.hours, timecode.minutes, timecode.seconds, timecode.frames
1703 (dt<0?'-':' '), timediff.hours, timediff.minutes, timediff.seconds, timediff.frames
1705 _editor->verbose_cursor()->set(buf, event->button.x + 10, event->button.y + 10);
1706 _editor->verbose_cursor()->show ();
1710 VideoTimeLineDrag::finished (GdkEvent * /*event*/, bool movement_occurred)
1712 if (ARDOUR_UI::instance()->video_timeline->is_offset_locked()) {
1716 if (!movement_occurred || ! _editor->session()) {
1720 ARDOUR_UI::instance()->flush_videotimeline_cache(true);
1722 _editor->begin_reversible_command (_("Move Video"));
1724 XMLNode &before = ARDOUR_UI::instance()->video_timeline->get_state();
1725 ARDOUR_UI::instance()->video_timeline->save_undo();
1726 XMLNode &after = ARDOUR_UI::instance()->video_timeline->get_state();
1727 _editor->session()->add_command(new MementoCommand<VideoTimeLine>(*(ARDOUR_UI::instance()->video_timeline), &before, &after));
1729 for (list<AVDraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
1730 i->view->drag_end();
1731 i->view->fake_set_opaque (false);
1732 i->view->region()->resume_property_changes ();
1734 _editor->session()->add_command (new StatefulDiffCommand (i->view->region()));
1737 _editor->session()->maybe_update_session_range(
1738 std::max(ARDOUR_UI::instance()->video_timeline->get_offset(), (ARDOUR::frameoffset_t) 0),
1739 std::max(ARDOUR_UI::instance()->video_timeline->get_offset() + ARDOUR_UI::instance()->video_timeline->get_duration(), (ARDOUR::frameoffset_t) 0)
1743 _editor->commit_reversible_command ();
1744 _editor->update_canvas_now ();
1748 VideoTimeLineDrag::aborted (bool)
1750 if (ARDOUR_UI::instance()->video_timeline->is_offset_locked()) {
1753 ARDOUR_UI::instance()->video_timeline->set_offset(_startdrag_video_offset);
1754 ARDOUR_UI::instance()->flush_videotimeline_cache(true);
1756 for (list<AVDraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
1757 i->view->region()->resume_property_changes ();
1758 i->view->region()->set_position(i->initial_position);
1762 TrimDrag::TrimDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, list<RegionView*> const & v, bool preserve_fade_anchor)
1763 : RegionDrag (e, i, p, v)
1765 DEBUG_TRACE (DEBUG::Drags, "New TrimDrag\n");
1766 _preserve_fade_anchor = preserve_fade_anchor;
1770 TrimDrag::start_grab (GdkEvent* event, Gdk::Cursor*)
1773 TimeAxisView* tvp = &_primary->get_time_axis_view ();
1774 RouteTimeAxisView* tv = dynamic_cast<RouteTimeAxisView*>(tvp);
1776 if (tv && tv->is_track()) {
1777 speed = tv->track()->speed();
1780 framepos_t const region_start = (framepos_t) (_primary->region()->position() / speed);
1781 framepos_t const region_end = (framepos_t) (_primary->region()->last_frame() / speed);
1782 framecnt_t const region_length = (framecnt_t) (_primary->region()->length() / speed);
1784 framepos_t const pf = adjusted_current_frame (event);
1786 if (Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) {
1787 /* Move the contents of the region around without changing the region bounds */
1788 _operation = ContentsTrim;
1789 Drag::start_grab (event, _editor->cursors()->trimmer);
1791 /* These will get overridden for a point trim.*/
1792 if (pf < (region_start + region_length/2)) {
1793 /* closer to front */
1794 _operation = StartTrim;
1795 Drag::start_grab (event, _editor->cursors()->left_side_trim);
1798 _operation = EndTrim;
1799 Drag::start_grab (event, _editor->cursors()->right_side_trim);
1803 switch (_operation) {
1805 show_verbose_cursor_time (region_start);
1806 for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
1807 i->view->trim_front_starting ();
1811 show_verbose_cursor_time (region_end);
1814 show_verbose_cursor_time (pf);
1818 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
1819 i->view->region()->suspend_property_changes ();
1824 TrimDrag::motion (GdkEvent* event, bool first_move)
1826 RegionView* rv = _primary;
1829 TimeAxisView* tvp = &_primary->get_time_axis_view ();
1830 RouteTimeAxisView* tv = dynamic_cast<RouteTimeAxisView*>(tvp);
1831 pair<set<boost::shared_ptr<Playlist> >::iterator,bool> insert_result;
1833 if (tv && tv->is_track()) {
1834 speed = tv->track()->speed();
1837 framecnt_t const dt = adjusted_current_frame (event) - raw_grab_frame () + _pointer_frame_offset;
1843 switch (_operation) {
1845 trim_type = "Region start trim";
1848 trim_type = "Region end trim";
1851 trim_type = "Region content trim";
1855 _editor->begin_reversible_command (trim_type);
1857 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
1858 RegionView* rv = i->view;
1859 rv->fake_set_opaque (false);
1860 rv->enable_display (false);
1861 rv->region()->playlist()->clear_owned_changes ();
1863 AudioRegionView* const arv = dynamic_cast<AudioRegionView*> (rv);
1866 arv->temporarily_hide_envelope ();
1870 boost::shared_ptr<Playlist> pl = rv->region()->playlist();
1871 insert_result = _editor->motion_frozen_playlists.insert (pl);
1873 if (insert_result.second) {
1879 bool non_overlap_trim = false;
1881 if (event && Keyboard::modifier_state_equals (event->button.state, Keyboard::TertiaryModifier)) {
1882 non_overlap_trim = true;
1885 switch (_operation) {
1887 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
1888 bool changed = i->view->trim_front (i->initial_position + dt, non_overlap_trim);
1889 if (changed && _preserve_fade_anchor) {
1890 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (i->view);
1895 boost::shared_ptr<AudioRegion> ar (arv->audio_region());
1896 distance = _drags->current_pointer_x() - grab_x();
1897 len = ar->fade_in()->back()->when;
1898 new_length = len - _editor->unit_to_frame (distance);
1899 new_length = ar->verify_xfade_bounds (new_length, true /*START*/ );
1900 arv->reset_fade_in_shape_width (ar, new_length); //the grey shape
1907 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
1908 bool changed = i->view->trim_end (i->initial_end + dt, non_overlap_trim);
1909 if (changed && _preserve_fade_anchor) {
1910 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (i->view);
1915 boost::shared_ptr<AudioRegion> ar (arv->audio_region());
1916 distance = grab_x() - _drags->current_pointer_x();
1917 len = ar->fade_out()->back()->when;
1918 new_length = len - _editor->unit_to_frame (distance);
1919 new_length = ar->verify_xfade_bounds (new_length, false /*END*/ );
1920 arv->reset_fade_out_shape_width (ar, new_length); //the grey shape
1928 bool swap_direction = false;
1930 if (event && Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) {
1931 swap_direction = true;
1934 framecnt_t frame_delta = 0;
1936 bool left_direction = false;
1937 if (last_pointer_frame() > adjusted_current_frame(event)) {
1938 left_direction = true;
1941 if (left_direction) {
1942 frame_delta = (last_pointer_frame() - adjusted_current_frame(event));
1944 frame_delta = (adjusted_current_frame(event) - last_pointer_frame());
1947 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
1948 i->view->trim_contents (frame_delta, left_direction, swap_direction);
1954 switch (_operation) {
1956 show_verbose_cursor_time ((framepos_t) (rv->region()->position() / speed));
1959 show_verbose_cursor_time ((framepos_t) (rv->region()->last_frame() / speed));
1962 show_verbose_cursor_time (adjusted_current_frame (event));
1969 TrimDrag::finished (GdkEvent* event, bool movement_occurred)
1971 if (movement_occurred) {
1972 motion (event, false);
1974 if (_operation == StartTrim) {
1975 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
1977 /* This must happen before the region's StatefulDiffCommand is created, as it may
1978 `correct' (ahem) the region's _start from being negative to being zero. It
1979 needs to be zero in the undo record.
1981 i->view->trim_front_ending ();
1983 if (_preserve_fade_anchor) {
1984 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (i->view);
1989 boost::shared_ptr<AudioRegion> ar (arv->audio_region());
1990 distance = _drags->current_pointer_x() - grab_x();
1991 len = ar->fade_in()->back()->when;
1992 new_length = len - _editor->unit_to_frame (distance);
1993 new_length = ar->verify_xfade_bounds (new_length, true /*START*/ );
1994 ar->set_fade_in_length(new_length);
1998 } else if (_operation == EndTrim) {
1999 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
2000 if (_preserve_fade_anchor) {
2001 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (i->view);
2006 boost::shared_ptr<AudioRegion> ar (arv->audio_region());
2007 distance = _drags->current_pointer_x() - grab_x();
2008 len = ar->fade_out()->back()->when;
2009 new_length = len - _editor->unit_to_frame (distance);
2010 new_length = ar->verify_xfade_bounds (new_length, false /*END*/ );
2011 ar->set_fade_out_length(new_length);
2017 if (!_views.empty()) {
2018 if (_operation == StartTrim) {
2019 _editor->maybe_locate_with_edit_preroll(
2020 _views.begin()->view->region()->position());
2022 if (_operation == EndTrim) {
2023 _editor->maybe_locate_with_edit_preroll(
2024 _views.begin()->view->region()->position() +
2025 _views.begin()->view->region()->length());
2029 if (!_editor->selection->selected (_primary)) {
2030 _primary->thaw_after_trim ();
2033 set<boost::shared_ptr<Playlist> > diffed_playlists;
2035 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
2036 i->view->thaw_after_trim ();
2037 i->view->enable_display (true);
2038 i->view->fake_set_opaque (true);
2040 /* Trimming one region may affect others on the playlist, so we need
2041 to get undo Commands from the whole playlist rather than just the
2042 region. Use diffed_playlists to make sure we don't diff a given
2043 playlist more than once.
2045 boost::shared_ptr<Playlist> p = i->view->region()->playlist ();
2046 if (diffed_playlists.find (p) == diffed_playlists.end()) {
2047 vector<Command*> cmds;
2049 _editor->session()->add_commands (cmds);
2050 diffed_playlists.insert (p);
2055 for (set<boost::shared_ptr<Playlist> >::iterator p = _editor->motion_frozen_playlists.begin(); p != _editor->motion_frozen_playlists.end(); ++p) {
2059 _editor->motion_frozen_playlists.clear ();
2060 _editor->commit_reversible_command();
2063 /* no mouse movement */
2064 _editor->point_trim (event, adjusted_current_frame (event));
2067 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
2068 if (_operation == StartTrim) {
2069 i->view->trim_front_ending ();
2072 i->view->region()->resume_property_changes ();
2077 TrimDrag::aborted (bool movement_occurred)
2079 /* Our motion method is changing model state, so use the Undo system
2080 to cancel. Perhaps not ideal, as this will leave an Undo point
2081 behind which may be slightly odd from the user's point of view.
2086 if (movement_occurred) {
2090 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
2091 i->view->region()->resume_property_changes ();
2096 TrimDrag::setup_pointer_frame_offset ()
2098 list<DraggingView>::iterator i = _views.begin ();
2099 while (i != _views.end() && i->view != _primary) {
2103 if (i == _views.end()) {
2107 switch (_operation) {
2109 _pointer_frame_offset = raw_grab_frame() - i->initial_position;
2112 _pointer_frame_offset = raw_grab_frame() - i->initial_end;
2119 MeterMarkerDrag::MeterMarkerDrag (Editor* e, ArdourCanvas::Item* i, bool c)
2123 DEBUG_TRACE (DEBUG::Drags, "New MeterMarkerDrag\n");
2124 _marker = reinterpret_cast<MeterMarker*> (_item->get_data ("marker"));
2129 MeterMarkerDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
2131 Drag::start_grab (event, cursor);
2132 show_verbose_cursor_time (adjusted_current_frame(event));
2136 MeterMarkerDrag::setup_pointer_frame_offset ()
2138 _pointer_frame_offset = raw_grab_frame() - _marker->meter().frame();
2142 MeterMarkerDrag::motion (GdkEvent* event, bool first_move)
2146 // create a dummy marker for visual representation of moving the
2147 // section, because whether its a copy or not, we're going to
2148 // leave or lose the original marker (leave if its a copy; lose if its
2149 // not, because we'll remove it from the map).
2151 MeterSection section (_marker->meter());
2153 if (!section.movable()) {
2158 snprintf (name, sizeof(name), "%g/%g", _marker->meter().divisions_per_bar(), _marker->meter().note_divisor ());
2160 _marker = new MeterMarker (
2162 *_editor->meter_group,
2163 ARDOUR_UI::config()->canvasvar_MeterMarker.get(),
2165 *new MeterSection (_marker->meter())
2168 /* use the new marker for the grab */
2169 swap_grab (&_marker->the_item(), 0, GDK_CURRENT_TIME);
2172 TempoMap& map (_editor->session()->tempo_map());
2173 /* get current state */
2174 before_state = &map.get_state();
2175 /* remove the section while we drag it */
2176 map.remove_meter (section, true);
2180 framepos_t const pf = adjusted_current_frame (event);
2181 _marker->set_position (pf);
2182 show_verbose_cursor_time (pf);
2186 MeterMarkerDrag::finished (GdkEvent* event, bool movement_occurred)
2188 if (!movement_occurred) {
2192 motion (event, false);
2194 Timecode::BBT_Time when;
2196 TempoMap& map (_editor->session()->tempo_map());
2197 map.bbt_time (last_pointer_frame(), when);
2199 if (_copy == true) {
2200 _editor->begin_reversible_command (_("copy meter mark"));
2201 XMLNode &before = map.get_state();
2202 map.add_meter (_marker->meter(), when);
2203 XMLNode &after = map.get_state();
2204 _editor->session()->add_command(new MementoCommand<TempoMap>(map, &before, &after));
2205 _editor->commit_reversible_command ();
2208 _editor->begin_reversible_command (_("move meter mark"));
2210 /* we removed it before, so add it back now */
2212 map.add_meter (_marker->meter(), when);
2213 XMLNode &after = map.get_state();
2214 _editor->session()->add_command(new MementoCommand<TempoMap>(map, before_state, &after));
2215 _editor->commit_reversible_command ();
2218 // delete the dummy marker we used for visual representation while moving.
2219 // a new visual marker will show up automatically.
2224 MeterMarkerDrag::aborted (bool moved)
2226 _marker->set_position (_marker->meter().frame ());
2229 TempoMap& map (_editor->session()->tempo_map());
2230 /* we removed it before, so add it back now */
2231 map.add_meter (_marker->meter(), _marker->meter().frame());
2232 // delete the dummy marker we used for visual representation while moving.
2233 // a new visual marker will show up automatically.
2238 TempoMarkerDrag::TempoMarkerDrag (Editor* e, ArdourCanvas::Item* i, bool c)
2242 DEBUG_TRACE (DEBUG::Drags, "New TempoMarkerDrag\n");
2244 _marker = reinterpret_cast<TempoMarker*> (_item->get_data ("marker"));
2249 TempoMarkerDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
2251 Drag::start_grab (event, cursor);
2252 show_verbose_cursor_time (adjusted_current_frame (event));
2256 TempoMarkerDrag::setup_pointer_frame_offset ()
2258 _pointer_frame_offset = raw_grab_frame() - _marker->tempo().frame();
2262 TempoMarkerDrag::motion (GdkEvent* event, bool first_move)
2266 // create a dummy marker for visual representation of moving the
2267 // section, because whether its a copy or not, we're going to
2268 // leave or lose the original marker (leave if its a copy; lose if its
2269 // not, because we'll remove it from the map).
2271 // create a dummy marker for visual representation of moving the copy.
2272 // The actual copying is not done before we reach the finish callback.
2275 snprintf (name, sizeof (name), "%.2f", _marker->tempo().beats_per_minute());
2277 TempoSection section (_marker->tempo());
2279 _marker = new TempoMarker (
2281 *_editor->tempo_group,
2282 ARDOUR_UI::config()->canvasvar_TempoMarker.get(),
2284 *new TempoSection (_marker->tempo())
2287 /* use the new marker for the grab */
2288 swap_grab (&_marker->the_item(), 0, GDK_CURRENT_TIME);
2291 TempoMap& map (_editor->session()->tempo_map());
2292 /* get current state */
2293 before_state = &map.get_state();
2294 /* remove the section while we drag it */
2295 map.remove_tempo (section, true);
2299 framepos_t const pf = adjusted_current_frame (event);
2300 _marker->set_position (pf);
2301 show_verbose_cursor_time (pf);
2305 TempoMarkerDrag::finished (GdkEvent* event, bool movement_occurred)
2307 if (!movement_occurred) {
2311 motion (event, false);
2313 TempoMap& map (_editor->session()->tempo_map());
2314 framepos_t beat_time = map.round_to_beat (last_pointer_frame(), 0);
2315 Timecode::BBT_Time when;
2317 map.bbt_time (beat_time, when);
2319 if (_copy == true) {
2320 _editor->begin_reversible_command (_("copy tempo mark"));
2321 XMLNode &before = map.get_state();
2322 map.add_tempo (_marker->tempo(), when);
2323 XMLNode &after = map.get_state();
2324 _editor->session()->add_command (new MementoCommand<TempoMap>(map, &before, &after));
2325 _editor->commit_reversible_command ();
2328 _editor->begin_reversible_command (_("move tempo mark"));
2329 /* we removed it before, so add it back now */
2330 map.add_tempo (_marker->tempo(), when);
2331 XMLNode &after = map.get_state();
2332 _editor->session()->add_command (new MementoCommand<TempoMap>(map, before_state, &after));
2333 _editor->commit_reversible_command ();
2336 // delete the dummy marker we used for visual representation while moving.
2337 // a new visual marker will show up automatically.
2342 TempoMarkerDrag::aborted (bool moved)
2344 _marker->set_position (_marker->tempo().frame());
2346 TempoMap& map (_editor->session()->tempo_map());
2347 /* we removed it before, so add it back now */
2348 map.add_tempo (_marker->tempo(), _marker->tempo().start());
2349 // delete the dummy marker we used for visual representation while moving.
2350 // a new visual marker will show up automatically.
2355 CursorDrag::CursorDrag (Editor* e, ArdourCanvas::Item* i, bool s)
2359 DEBUG_TRACE (DEBUG::Drags, "New CursorDrag\n");
2362 /** Do all the things we do when dragging the playhead to make it look as though
2363 * we have located, without actually doing the locate (because that would cause
2364 * the diskstream buffers to be refilled, which is too slow).
2367 CursorDrag::fake_locate (framepos_t t)
2369 _editor->playhead_cursor->set_position (t);
2371 Session* s = _editor->session ();
2372 if (s->timecode_transmission_suspended ()) {
2373 framepos_t const f = _editor->playhead_cursor->current_frame;
2374 /* This is asynchronous so it will be sent "now"
2376 s->send_mmc_locate (f);
2377 /* These are synchronous and will be sent during the next
2380 s->queue_full_time_code ();
2381 s->queue_song_position_pointer ();
2384 show_verbose_cursor_time (t);
2385 _editor->UpdateAllTransportClocks (t);
2389 CursorDrag::start_grab (GdkEvent* event, Gdk::Cursor* c)
2391 Drag::start_grab (event, c);
2393 _grab_zoom = _editor->frames_per_unit;
2395 framepos_t where = _editor->event_frame (event, 0, 0);
2396 _editor->snap_to_with_modifier (where, event);
2398 _editor->_dragging_playhead = true;
2400 Session* s = _editor->session ();
2403 if (_was_rolling && _stop) {
2407 if (s->is_auditioning()) {
2408 s->cancel_audition ();
2412 if (AudioEngine::instance()->connected()) {
2414 /* do this only if we're the engine is connected
2415 * because otherwise this request will never be
2416 * serviced and we'll busy wait forever. likewise,
2417 * notice if we are disconnected while waiting for the
2418 * request to be serviced.
2421 s->request_suspend_timecode_transmission ();
2422 while (AudioEngine::instance()->connected() && !s->timecode_transmission_suspended ()) {
2423 /* twiddle our thumbs */
2428 fake_locate (where);
2432 CursorDrag::motion (GdkEvent* event, bool)
2434 framepos_t const adjusted_frame = adjusted_current_frame (event);
2435 if (adjusted_frame != last_pointer_frame()) {
2436 fake_locate (adjusted_frame);
2438 _editor->update_canvas_now ();
2444 CursorDrag::finished (GdkEvent* event, bool movement_occurred)
2446 _editor->_dragging_playhead = false;
2448 if (!movement_occurred && _stop) {
2452 motion (event, false);
2454 Session* s = _editor->session ();
2456 s->request_locate (_editor->playhead_cursor->current_frame, _was_rolling);
2457 _editor->_pending_locate_request = true;
2458 s->request_resume_timecode_transmission ();
2463 CursorDrag::aborted (bool)
2465 if (_editor->_dragging_playhead) {
2466 _editor->session()->request_resume_timecode_transmission ();
2467 _editor->_dragging_playhead = false;
2470 _editor->playhead_cursor->set_position (adjusted_frame (grab_frame (), 0, false));
2473 FadeInDrag::FadeInDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, list<RegionView*> const & v)
2474 : RegionDrag (e, i, p, v)
2476 DEBUG_TRACE (DEBUG::Drags, "New FadeInDrag\n");
2480 FadeInDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
2482 Drag::start_grab (event, cursor);
2484 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (_primary);
2485 boost::shared_ptr<AudioRegion> const r = arv->audio_region ();
2487 show_verbose_cursor_duration (r->position(), r->position() + r->fade_in()->back()->when, 32);
2491 FadeInDrag::setup_pointer_frame_offset ()
2493 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (_primary);
2494 boost::shared_ptr<AudioRegion> const r = arv->audio_region ();
2495 _pointer_frame_offset = raw_grab_frame() - ((framecnt_t) r->fade_in()->back()->when + r->position());
2499 FadeInDrag::motion (GdkEvent* event, bool)
2501 framecnt_t fade_length;
2503 framepos_t const pos = adjusted_current_frame (event);
2505 boost::shared_ptr<Region> region = _primary->region ();
2507 if (pos < (region->position() + 64)) {
2508 fade_length = 64; // this should be a minimum defined somewhere
2509 } else if (pos > region->last_frame()) {
2510 fade_length = region->length();
2512 fade_length = pos - region->position();
2515 for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
2517 AudioRegionView* tmp = dynamic_cast<AudioRegionView*> (i->view);
2523 tmp->reset_fade_in_shape_width (tmp->audio_region(), fade_length);
2526 show_verbose_cursor_duration (region->position(), region->position() + fade_length, 32);
2530 FadeInDrag::finished (GdkEvent* event, bool movement_occurred)
2532 if (!movement_occurred) {
2536 framecnt_t fade_length;
2538 framepos_t const pos = adjusted_current_frame (event);
2540 boost::shared_ptr<Region> region = _primary->region ();
2542 if (pos < (region->position() + 64)) {
2543 fade_length = 64; // this should be a minimum defined somewhere
2544 } else if (pos > region->last_frame()) {
2545 fade_length = region->length();
2547 fade_length = pos - region->position();
2550 _editor->begin_reversible_command (_("change fade in length"));
2552 for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
2554 AudioRegionView* tmp = dynamic_cast<AudioRegionView*> (i->view);
2560 boost::shared_ptr<AutomationList> alist = tmp->audio_region()->fade_in();
2561 XMLNode &before = alist->get_state();
2563 tmp->audio_region()->set_fade_in_length (fade_length);
2564 tmp->audio_region()->set_fade_in_active (true);
2566 XMLNode &after = alist->get_state();
2567 _editor->session()->add_command(new MementoCommand<AutomationList>(*alist.get(), &before, &after));
2570 _editor->commit_reversible_command ();
2574 FadeInDrag::aborted (bool)
2576 for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
2577 AudioRegionView* tmp = dynamic_cast<AudioRegionView*> (i->view);
2583 tmp->reset_fade_in_shape_width (tmp->audio_region(), tmp->audio_region()->fade_in()->back()->when);
2587 FadeOutDrag::FadeOutDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, list<RegionView*> const & v)
2588 : RegionDrag (e, i, p, v)
2590 DEBUG_TRACE (DEBUG::Drags, "New FadeOutDrag\n");
2594 FadeOutDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
2596 Drag::start_grab (event, cursor);
2598 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (_primary);
2599 boost::shared_ptr<AudioRegion> r = arv->audio_region ();
2601 show_verbose_cursor_duration (r->last_frame() - r->fade_out()->back()->when, r->last_frame());
2605 FadeOutDrag::setup_pointer_frame_offset ()
2607 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (_primary);
2608 boost::shared_ptr<AudioRegion> r = arv->audio_region ();
2609 _pointer_frame_offset = raw_grab_frame() - (r->length() - (framecnt_t) r->fade_out()->back()->when + r->position());
2613 FadeOutDrag::motion (GdkEvent* event, bool)
2615 framecnt_t fade_length;
2617 framepos_t const pos = adjusted_current_frame (event);
2619 boost::shared_ptr<Region> region = _primary->region ();
2621 if (pos > (region->last_frame() - 64)) {
2622 fade_length = 64; // this should really be a minimum fade defined somewhere
2624 else if (pos < region->position()) {
2625 fade_length = region->length();
2628 fade_length = region->last_frame() - pos;
2631 for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
2633 AudioRegionView* tmp = dynamic_cast<AudioRegionView*> (i->view);
2639 tmp->reset_fade_out_shape_width (tmp->audio_region(), fade_length);
2642 show_verbose_cursor_duration (region->last_frame() - fade_length, region->last_frame());
2646 FadeOutDrag::finished (GdkEvent* event, bool movement_occurred)
2648 if (!movement_occurred) {
2652 framecnt_t fade_length;
2654 framepos_t const pos = adjusted_current_frame (event);
2656 boost::shared_ptr<Region> region = _primary->region ();
2658 if (pos > (region->last_frame() - 64)) {
2659 fade_length = 64; // this should really be a minimum fade defined somewhere
2661 else if (pos < region->position()) {
2662 fade_length = region->length();
2665 fade_length = region->last_frame() - pos;
2668 _editor->begin_reversible_command (_("change fade out length"));
2670 for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
2672 AudioRegionView* tmp = dynamic_cast<AudioRegionView*> (i->view);
2678 boost::shared_ptr<AutomationList> alist = tmp->audio_region()->fade_out();
2679 XMLNode &before = alist->get_state();
2681 tmp->audio_region()->set_fade_out_length (fade_length);
2682 tmp->audio_region()->set_fade_out_active (true);
2684 XMLNode &after = alist->get_state();
2685 _editor->session()->add_command(new MementoCommand<AutomationList>(*alist.get(), &before, &after));
2688 _editor->commit_reversible_command ();
2692 FadeOutDrag::aborted (bool)
2694 for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
2695 AudioRegionView* tmp = dynamic_cast<AudioRegionView*> (i->view);
2701 tmp->reset_fade_out_shape_width (tmp->audio_region(), tmp->audio_region()->fade_out()->back()->when);
2705 MarkerDrag::MarkerDrag (Editor* e, ArdourCanvas::Item* i)
2708 DEBUG_TRACE (DEBUG::Drags, "New MarkerDrag\n");
2710 _marker = reinterpret_cast<Marker*> (_item->get_data ("marker"));
2713 _points.push_back (Gnome::Art::Point (0, 0));
2714 _points.push_back (Gnome::Art::Point (0, physical_screen_height (_editor->get_window())));
2717 MarkerDrag::~MarkerDrag ()
2719 for (CopiedLocationInfo::iterator i = _copied_locations.begin(); i != _copied_locations.end(); ++i) {
2724 MarkerDrag::CopiedLocationMarkerInfo::CopiedLocationMarkerInfo (Location* l, Marker* m)
2726 location = new Location (*l);
2727 markers.push_back (m);
2732 MarkerDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
2734 Drag::start_grab (event, cursor);
2738 Location *location = _editor->find_location_from_marker (_marker, is_start);
2739 _editor->_dragging_edit_point = true;
2741 update_item (location);
2743 // _drag_line->show();
2744 // _line->raise_to_top();
2747 show_verbose_cursor_time (location->start());
2749 show_verbose_cursor_time (location->end());
2752 Selection::Operation op = ArdourKeyboard::selection_type (event->button.state);
2755 case Selection::Toggle:
2756 /* we toggle on the button release */
2758 case Selection::Set:
2759 if (!_editor->selection->selected (_marker)) {
2760 _editor->selection->set (_marker);
2763 case Selection::Extend:
2765 Locations::LocationList ll;
2766 list<Marker*> to_add;
2768 _editor->selection->markers.range (s, e);
2769 s = min (_marker->position(), s);
2770 e = max (_marker->position(), e);
2773 if (e < max_framepos) {
2776 _editor->session()->locations()->find_all_between (s, e, ll, Location::Flags (0));
2777 for (Locations::LocationList::iterator i = ll.begin(); i != ll.end(); ++i) {
2778 Editor::LocationMarkers* lm = _editor->find_location_markers (*i);
2781 to_add.push_back (lm->start);
2784 to_add.push_back (lm->end);
2788 if (!to_add.empty()) {
2789 _editor->selection->add (to_add);
2793 case Selection::Add:
2794 _editor->selection->add (_marker);
2798 /* Set up copies for us to manipulate during the drag
2801 for (MarkerSelection::iterator i = _editor->selection->markers.begin(); i != _editor->selection->markers.end(); ++i) {
2803 Location* l = _editor->find_location_from_marker (*i, is_start);
2810 _copied_locations.push_back (CopiedLocationMarkerInfo (l, *i));
2812 /* range: check that the other end of the range isn't
2815 CopiedLocationInfo::iterator x;
2816 for (x = _copied_locations.begin(); x != _copied_locations.end(); ++x) {
2817 if (*(*x).location == *l) {
2821 if (x == _copied_locations.end()) {
2822 _copied_locations.push_back (CopiedLocationMarkerInfo (l, *i));
2824 (*x).markers.push_back (*i);
2825 (*x).move_both = true;
2833 MarkerDrag::setup_pointer_frame_offset ()
2836 Location *location = _editor->find_location_from_marker (_marker, is_start);
2837 _pointer_frame_offset = raw_grab_frame() - (is_start ? location->start() : location->end());
2841 MarkerDrag::motion (GdkEvent* event, bool)
2843 framecnt_t f_delta = 0;
2845 bool move_both = false;
2846 Location *real_location;
2847 Location *copy_location = 0;
2849 framepos_t const newframe = adjusted_current_frame (event);
2850 framepos_t next = newframe;
2852 if (Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) {
2856 CopiedLocationInfo::iterator x;
2858 /* find the marker we're dragging, and compute the delta */
2860 for (x = _copied_locations.begin(); x != _copied_locations.end(); ++x) {
2862 copy_location = (*x).location;
2864 if (find (x->markers.begin(), x->markers.end(), _marker) != x->markers.end()) {
2866 /* this marker is represented by this
2867 * CopiedLocationMarkerInfo
2870 if ((real_location = _editor->find_location_from_marker (_marker, is_start)) == 0) {
2875 if (real_location->is_mark()) {
2876 f_delta = newframe - copy_location->start();
2880 switch (_marker->type()) {
2881 case Marker::SessionStart:
2882 case Marker::RangeStart:
2883 case Marker::LoopStart:
2884 case Marker::PunchIn:
2885 f_delta = newframe - copy_location->start();
2888 case Marker::SessionEnd:
2889 case Marker::RangeEnd:
2890 case Marker::LoopEnd:
2891 case Marker::PunchOut:
2892 f_delta = newframe - copy_location->end();
2895 /* what kind of marker is this ? */
2904 if (x == _copied_locations.end()) {
2905 /* hmm, impossible - we didn't find the dragged marker */
2909 /* now move them all */
2911 for (x = _copied_locations.begin(); x != _copied_locations.end(); ++x) {
2913 copy_location = x->location;
2915 /* call this to find out if its the start or end */
2917 if ((real_location = _editor->find_location_from_marker (x->markers.front(), is_start)) == 0) {
2921 if (real_location->locked()) {
2925 if (copy_location->is_mark()) {
2929 copy_location->set_start (copy_location->start() + f_delta);
2933 framepos_t new_start = copy_location->start() + f_delta;
2934 framepos_t new_end = copy_location->end() + f_delta;
2936 if (is_start) { // start-of-range marker
2938 if (move_both || (*x).move_both) {
2939 copy_location->set_start (new_start);
2940 copy_location->set_end (new_end);
2941 } else if (new_start < copy_location->end()) {
2942 copy_location->set_start (new_start);
2943 } else if (newframe > 0) {
2944 _editor->snap_to (next, 1, true);
2945 copy_location->set_end (next);
2946 copy_location->set_start (newframe);
2949 } else { // end marker
2951 if (move_both || (*x).move_both) {
2952 copy_location->set_end (new_end);
2953 copy_location->set_start (new_start);
2954 } else if (new_end > copy_location->start()) {
2955 copy_location->set_end (new_end);
2956 } else if (newframe > 0) {
2957 _editor->snap_to (next, -1, true);
2958 copy_location->set_start (next);
2959 copy_location->set_end (newframe);
2964 update_item (copy_location);
2966 /* now lookup the actual GUI items used to display this
2967 * location and move them to wherever the copy of the location
2968 * is now. This means that the logic in ARDOUR::Location is
2969 * still enforced, even though we are not (yet) modifying
2970 * the real Location itself.
2973 Editor::LocationMarkers* lm = _editor->find_location_markers (real_location);
2976 lm->set_position (copy_location->start(), copy_location->end());
2981 assert (!_copied_locations.empty());
2983 show_verbose_cursor_time (newframe);
2986 _editor->update_canvas_now ();
2991 MarkerDrag::finished (GdkEvent* event, bool movement_occurred)
2993 if (!movement_occurred) {
2995 /* just a click, do nothing but finish
2996 off the selection process
2999 Selection::Operation op = ArdourKeyboard::selection_type (event->button.state);
3002 case Selection::Set:
3003 if (_editor->selection->selected (_marker) && _editor->selection->markers.size() > 1) {
3004 _editor->selection->set (_marker);
3008 case Selection::Toggle:
3009 /* we toggle on the button release, click only */
3010 _editor->selection->toggle (_marker);
3013 case Selection::Extend:
3014 case Selection::Add:
3021 _editor->_dragging_edit_point = false;
3023 _editor->begin_reversible_command ( _("move marker") );
3024 XMLNode &before = _editor->session()->locations()->get_state();
3026 MarkerSelection::iterator i;
3027 CopiedLocationInfo::iterator x;
3030 for (i = _editor->selection->markers.begin(), x = _copied_locations.begin();
3031 x != _copied_locations.end() && i != _editor->selection->markers.end();
3034 Location * location = _editor->find_location_from_marker (*i, is_start);
3038 if (location->locked()) {
3042 if (location->is_mark()) {
3043 location->set_start (((*x).location)->start());
3045 location->set (((*x).location)->start(), ((*x).location)->end());
3050 XMLNode &after = _editor->session()->locations()->get_state();
3051 _editor->session()->add_command(new MementoCommand<Locations>(*(_editor->session()->locations()), &before, &after));
3052 _editor->commit_reversible_command ();
3056 MarkerDrag::aborted (bool)
3062 MarkerDrag::update_item (Location*)
3067 ControlPointDrag::ControlPointDrag (Editor* e, ArdourCanvas::Item* i)
3069 _cumulative_x_drag (0),
3070 _cumulative_y_drag (0)
3072 if (_zero_gain_fraction < 0.0) {
3073 _zero_gain_fraction = gain_to_slider_position_with_max (dB_to_coefficient (0.0), Config->get_max_gain());
3076 DEBUG_TRACE (DEBUG::Drags, "New ControlPointDrag\n");
3078 _point = reinterpret_cast<ControlPoint*> (_item->get_data ("control_point"));
3084 ControlPointDrag::start_grab (GdkEvent* event, Gdk::Cursor* /*cursor*/)
3086 Drag::start_grab (event, _editor->cursors()->fader);
3088 // start the grab at the center of the control point so
3089 // the point doesn't 'jump' to the mouse after the first drag
3090 _fixed_grab_x = _point->get_x();
3091 _fixed_grab_y = _point->get_y();
3093 float const fraction = 1 - (_point->get_y() / _point->line().height());
3095 _point->line().start_drag_single (_point, _fixed_grab_x, fraction);
3097 _editor->verbose_cursor()->set (_point->line().get_verbose_cursor_string (fraction),
3098 event->button.x + 10, event->button.y + 10);
3100 _editor->verbose_cursor()->show ();
3102 _pushing = Keyboard::modifier_state_contains (event->button.state, Keyboard::PrimaryModifier);
3104 if (!_point->can_slide ()) {
3105 _x_constrained = true;
3110 ControlPointDrag::motion (GdkEvent* event, bool)
3112 double dx = _drags->current_pointer_x() - last_pointer_x();
3113 double dy = _drags->current_pointer_y() - last_pointer_y();
3115 if (event->button.state & Keyboard::SecondaryModifier) {
3120 /* coordinate in pixels relative to the start of the region (for region-based automation)
3121 or track (for track-based automation) */
3122 double cx = _fixed_grab_x + _cumulative_x_drag + dx;
3123 double cy = _fixed_grab_y + _cumulative_y_drag + dy;
3125 // calculate zero crossing point. back off by .01 to stay on the
3126 // positive side of zero
3127 double const zero_gain_y = (1.0 - _zero_gain_fraction) * _point->line().height() - .01;
3129 // make sure we hit zero when passing through
3130 if ((cy < zero_gain_y && (cy - dy) > zero_gain_y) || (cy > zero_gain_y && (cy - dy) < zero_gain_y)) {
3134 if (_x_constrained) {
3137 if (_y_constrained) {
3141 _cumulative_x_drag = cx - _fixed_grab_x;
3142 _cumulative_y_drag = cy - _fixed_grab_y;
3146 cy = min ((double) _point->line().height(), cy);
3148 framepos_t cx_frames = _editor->unit_to_frame (cx);
3150 if (!_x_constrained) {
3151 _editor->snap_to_with_modifier (cx_frames, event);
3154 cx_frames = min (cx_frames, _point->line().maximum_time());
3156 float const fraction = 1.0 - (cy / _point->line().height());
3158 _point->line().drag_motion (_editor->frame_to_unit_unrounded (cx_frames), fraction, false, _pushing, _final_index);
3160 _editor->verbose_cursor()->set_text (_point->line().get_verbose_cursor_string (fraction));
3164 ControlPointDrag::finished (GdkEvent* event, bool movement_occurred)
3166 if (!movement_occurred) {
3170 if (Keyboard::modifier_state_equals (event->button.state, Keyboard::TertiaryModifier)) {
3171 _editor->reset_point_selection ();
3175 motion (event, false);
3178 _point->line().end_drag (_pushing, _final_index);
3179 _editor->session()->commit_reversible_command ();
3183 ControlPointDrag::aborted (bool)
3185 _point->line().reset ();
3189 ControlPointDrag::active (Editing::MouseMode m)
3191 if (m == Editing::MouseGain) {
3192 /* always active in mouse gain */
3196 /* otherwise active if the point is on an automation line (ie not if its on a region gain line) */
3197 return dynamic_cast<AutomationLine*> (&(_point->line())) != 0;
3200 LineDrag::LineDrag (Editor* e, ArdourCanvas::Item* i)
3203 _cumulative_y_drag (0)
3205 DEBUG_TRACE (DEBUG::Drags, "New LineDrag\n");
3209 LineDrag::start_grab (GdkEvent* event, Gdk::Cursor* /*cursor*/)
3211 _line = reinterpret_cast<AutomationLine*> (_item->get_data ("line"));
3214 _item = &_line->grab_item ();
3216 /* need to get x coordinate in terms of parent (TimeAxisItemView)
3217 origin, and ditto for y.
3220 double cx = event->button.x;
3221 double cy = event->button.y;
3223 _line->parent_group().w2i (cx, cy);
3225 framecnt_t const frame_within_region = (framecnt_t) floor (cx * _editor->frames_per_unit);
3230 if (!_line->control_points_adjacent (frame_within_region, before, after)) {
3231 /* no adjacent points */
3235 Drag::start_grab (event, _editor->cursors()->fader);
3237 /* store grab start in parent frame */
3242 double fraction = 1.0 - (cy / _line->height());
3244 _line->start_drag_line (before, after, fraction);
3246 _editor->verbose_cursor()->set (_line->get_verbose_cursor_string (fraction),
3247 event->button.x + 10, event->button.y + 10);
3249 _editor->verbose_cursor()->show ();
3253 LineDrag::motion (GdkEvent* event, bool)
3255 double dy = _drags->current_pointer_y() - last_pointer_y();
3257 if (event->button.state & Keyboard::SecondaryModifier) {
3261 double cy = _fixed_grab_y + _cumulative_y_drag + dy;
3263 _cumulative_y_drag = cy - _fixed_grab_y;
3266 cy = min ((double) _line->height(), cy);
3268 double const fraction = 1.0 - (cy / _line->height());
3271 /* we are ignoring x position for this drag, so we can just pass in anything */
3272 _line->drag_motion (0, fraction, true, false, ignored);
3274 _editor->verbose_cursor()->set_text (_line->get_verbose_cursor_string (fraction));
3278 LineDrag::finished (GdkEvent* event, bool movement_occured)
3280 if (movement_occured) {
3281 motion (event, false);
3282 _line->end_drag (false, 0);
3284 /* add a new control point on the line */
3286 AutomationTimeAxisView* atv;
3288 _line->end_drag (false, 0);
3290 if ((atv = dynamic_cast<AutomationTimeAxisView*>(_editor->clicked_axisview)) != 0) {
3291 framepos_t where = _editor->event_frame (event, 0, 0);
3292 atv->add_automation_event (event, where, event->button.y, false);
3296 _editor->session()->commit_reversible_command ();
3300 LineDrag::aborted (bool)
3305 FeatureLineDrag::FeatureLineDrag (Editor* e, ArdourCanvas::Item* i)
3308 _cumulative_x_drag (0)
3310 DEBUG_TRACE (DEBUG::Drags, "New FeatureLineDrag\n");
3314 FeatureLineDrag::start_grab (GdkEvent* event, Gdk::Cursor* /*cursor*/)
3316 Drag::start_grab (event);
3318 _line = reinterpret_cast<Line*> (_item);
3321 /* need to get x coordinate in terms of parent (AudioRegionView) origin. */
3323 double cx = event->button.x;
3324 double cy = event->button.y;
3326 _item->property_parent().get_value()->w2i(cx, cy);
3328 /* store grab start in parent frame */
3329 _region_view_grab_x = cx;
3331 _before = *(float*) _item->get_data ("position");
3333 _arv = reinterpret_cast<AudioRegionView*> (_item->get_data ("regionview"));
3335 _max_x = _editor->frame_to_pixel(_arv->get_duration());
3339 FeatureLineDrag::motion (GdkEvent*, bool)
3341 double dx = _drags->current_pointer_x() - last_pointer_x();
3343 double cx = _region_view_grab_x + _cumulative_x_drag + dx;
3345 _cumulative_x_drag += dx;
3347 /* Clamp the min and max extent of the drag to keep it within the region view bounds */
3356 ArdourCanvas::Points points;
3358 double x1 = 0, x2 = 0, y1 = 0, y2 = 0;
3360 _line->get_bounds(x1, y2, x2, y2);
3362 points.push_back(Gnome::Art::Point(cx, 2.0)); // first x-coord needs to be a non-normal value
3363 points.push_back(Gnome::Art::Point(cx, y2 - y1));
3365 _line->property_points() = points;
3367 float *pos = new float;
3370 _line->set_data ("position", pos);
3376 FeatureLineDrag::finished (GdkEvent*, bool)
3378 _arv = reinterpret_cast<AudioRegionView*> (_item->get_data ("regionview"));
3379 _arv->update_transient(_before, _before);
3383 FeatureLineDrag::aborted (bool)
3388 RubberbandSelectDrag::RubberbandSelectDrag (Editor* e, ArdourCanvas::Item* i)
3390 , _vertical_only (false)
3392 DEBUG_TRACE (DEBUG::Drags, "New RubberbandSelectDrag\n");
3396 RubberbandSelectDrag::start_grab (GdkEvent* event, Gdk::Cursor *)
3398 Drag::start_grab (event);
3399 show_verbose_cursor_time (adjusted_current_frame (event));
3403 RubberbandSelectDrag::motion (GdkEvent* event, bool)
3410 framepos_t const pf = adjusted_current_frame (event, Config->get_rubberbanding_snaps_to_grid ());
3412 framepos_t grab = grab_frame ();
3413 if (Config->get_rubberbanding_snaps_to_grid ()) {
3414 _editor->snap_to_with_modifier (grab, event);
3417 /* base start and end on initial click position */
3427 if (_drags->current_pointer_y() < grab_y()) {
3428 y1 = _drags->current_pointer_y();
3431 y2 = _drags->current_pointer_y();
3436 if (start != end || y1 != y2) {
3438 double x1 = _editor->frame_to_pixel (start);
3439 double x2 = _editor->frame_to_pixel (end);
3441 _editor->rubberband_rect->property_x1() = x1;
3442 if (_vertical_only) {
3443 /* fixed 10 pixel width */
3444 _editor->rubberband_rect->property_x2() = x1 + 10;
3446 _editor->rubberband_rect->property_x2() = x2;
3449 _editor->rubberband_rect->property_y1() = y1;
3450 _editor->rubberband_rect->property_y2() = y2;
3452 _editor->rubberband_rect->show();
3453 _editor->rubberband_rect->raise_to_top();
3455 show_verbose_cursor_time (pf);
3457 do_select_things (event, true);
3462 RubberbandSelectDrag::do_select_things (GdkEvent* event, bool drag_in_progress)
3467 if (grab_frame() < last_pointer_frame()) {
3469 x2 = last_pointer_frame ();
3472 x1 = last_pointer_frame ();
3478 if (_drags->current_pointer_y() < grab_y()) {
3479 y1 = _drags->current_pointer_y();
3482 y2 = _drags->current_pointer_y();
3486 select_things (event->button.state, x1, x2, y1, y2, drag_in_progress);
3490 RubberbandSelectDrag::finished (GdkEvent* event, bool movement_occurred)
3492 if (movement_occurred) {
3494 motion (event, false);
3495 do_select_things (event, false);
3501 bool do_deselect = true;
3502 MidiTimeAxisView* mtv;
3504 if ((mtv = dynamic_cast<MidiTimeAxisView*>(_editor->clicked_axisview)) != 0) {
3506 if (_editor->selection->empty()) {
3507 /* nothing selected */
3508 add_midi_region (mtv);
3509 do_deselect = false;
3513 /* do not deselect if Primary or Tertiary (toggle-select or
3514 * extend-select are pressed.
3517 if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::PrimaryModifier) &&
3518 !Keyboard::modifier_state_contains (event->button.state, Keyboard::TertiaryModifier) &&
3525 _editor->rubberband_rect->hide();
3529 RubberbandSelectDrag::aborted (bool)
3531 _editor->rubberband_rect->hide ();
3534 TimeFXDrag::TimeFXDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, std::list<RegionView*> const & v)
3535 : RegionDrag (e, i, p, v)
3537 DEBUG_TRACE (DEBUG::Drags, "New TimeFXDrag\n");
3541 TimeFXDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
3543 Drag::start_grab (event, cursor);
3545 show_verbose_cursor_time (adjusted_current_frame (event));
3549 TimeFXDrag::motion (GdkEvent* event, bool)
3551 RegionView* rv = _primary;
3552 StreamView* cv = rv->get_time_axis_view().view ();
3554 pair<TimeAxisView*, double> const tv = _editor->trackview_by_y_position (grab_y());
3555 int layer = tv.first->layer_display() == Overlaid ? 0 : tv.second;
3556 int layers = tv.first->layer_display() == Overlaid ? 1 : cv->layers();
3558 framepos_t const pf = adjusted_current_frame (event);
3560 if (pf > rv->region()->position()) {
3561 rv->get_time_axis_view().show_timestretch (rv->region()->position(), pf, layers, layer);
3564 show_verbose_cursor_time (pf);
3568 TimeFXDrag::finished (GdkEvent* /*event*/, bool movement_occurred)
3570 _primary->get_time_axis_view().hide_timestretch ();
3572 if (!movement_occurred) {
3576 if (last_pointer_frame() < _primary->region()->position()) {
3577 /* backwards drag of the left edge - not usable */
3581 framecnt_t newlen = last_pointer_frame() - _primary->region()->position();
3583 float percentage = (double) newlen / (double) _primary->region()->length();
3585 #ifndef USE_RUBBERBAND
3586 // Soundtouch uses percentage / 100 instead of normal (/ 1)
3587 if (_primary->region()->data_type() == DataType::AUDIO) {
3588 percentage = (float) ((double) newlen - (double) _primary->region()->length()) / ((double) newlen) * 100.0f;
3592 if (!_editor->get_selection().regions.empty()) {
3593 /* primary will already be included in the selection, and edit
3594 group shared editing will propagate selection across
3595 equivalent regions, so just use the current region
3599 if (_editor->time_stretch (_editor->get_selection().regions, percentage) == -1) {
3600 error << _("An error occurred while executing time stretch operation") << endmsg;
3606 TimeFXDrag::aborted (bool)
3608 _primary->get_time_axis_view().hide_timestretch ();
3611 ScrubDrag::ScrubDrag (Editor* e, ArdourCanvas::Item* i)
3614 DEBUG_TRACE (DEBUG::Drags, "New ScrubDrag\n");
3618 ScrubDrag::start_grab (GdkEvent* event, Gdk::Cursor *)
3620 Drag::start_grab (event);
3624 ScrubDrag::motion (GdkEvent* /*event*/, bool)
3626 _editor->scrub (adjusted_current_frame (0, false), _drags->current_pointer_x ());
3630 ScrubDrag::finished (GdkEvent* /*event*/, bool movement_occurred)
3632 if (movement_occurred && _editor->session()) {
3633 /* make sure we stop */
3634 _editor->session()->request_transport_speed (0.0);
3639 ScrubDrag::aborted (bool)
3644 SelectionDrag::SelectionDrag (Editor* e, ArdourCanvas::Item* i, Operation o)
3649 , _original_pointer_time_axis (-1)
3650 , _last_pointer_time_axis (-1)
3651 , _time_selection_at_start (!_editor->get_selection().time.empty())
3653 DEBUG_TRACE (DEBUG::Drags, "New SelectionDrag\n");
3655 if (_time_selection_at_start) {
3656 start_at_start = _editor->get_selection().time.start();
3657 end_at_start = _editor->get_selection().time.end_frame();
3662 SelectionDrag::start_grab (GdkEvent* event, Gdk::Cursor*)
3664 if (_editor->session() == 0) {
3668 Gdk::Cursor* cursor = 0;
3670 switch (_operation) {
3671 case CreateSelection:
3672 if (Keyboard::modifier_state_equals (event->button.state, Keyboard::CopyModifier)) {
3677 cursor = _editor->cursors()->selector;
3678 Drag::start_grab (event, cursor);
3681 case SelectionStartTrim:
3682 if (_editor->clicked_axisview) {
3683 _editor->clicked_axisview->order_selection_trims (_item, true);
3685 Drag::start_grab (event, _editor->cursors()->left_side_trim);
3688 case SelectionEndTrim:
3689 if (_editor->clicked_axisview) {
3690 _editor->clicked_axisview->order_selection_trims (_item, false);
3692 Drag::start_grab (event, _editor->cursors()->right_side_trim);
3696 Drag::start_grab (event, cursor);
3699 case SelectionExtend:
3700 Drag::start_grab (event, cursor);
3704 if (_operation == SelectionMove) {
3705 show_verbose_cursor_time (_editor->selection->time[_editor->clicked_selection].start);
3707 show_verbose_cursor_time (adjusted_current_frame (event));
3710 _original_pointer_time_axis = _editor->trackview_by_y_position (_drags->current_pointer_y ()).first->order ();
3714 SelectionDrag::setup_pointer_frame_offset ()
3716 switch (_operation) {
3717 case CreateSelection:
3718 _pointer_frame_offset = 0;
3721 case SelectionStartTrim:
3723 _pointer_frame_offset = raw_grab_frame() - _editor->selection->time[_editor->clicked_selection].start;
3726 case SelectionEndTrim:
3727 _pointer_frame_offset = raw_grab_frame() - _editor->selection->time[_editor->clicked_selection].end;
3730 case SelectionExtend:
3736 SelectionDrag::motion (GdkEvent* event, bool first_move)
3738 framepos_t start = 0;
3740 framecnt_t length = 0;
3741 framecnt_t distance = 0;
3743 pair<TimeAxisView*, int> const pending_time_axis = _editor->trackview_by_y_position (_drags->current_pointer_y ());
3744 if (pending_time_axis.first == 0) {
3748 framepos_t const pending_position = adjusted_current_frame (event);
3750 /* only alter selection if things have changed */
3752 if (pending_time_axis.first->order() == _last_pointer_time_axis && pending_position == last_pointer_frame()) {
3756 switch (_operation) {
3757 case CreateSelection:
3759 framepos_t grab = grab_frame ();
3762 grab = adjusted_current_frame (event, false);
3763 if (grab < pending_position) {
3764 _editor->snap_to (grab, -1);
3766 _editor->snap_to (grab, 1);
3770 if (pending_position < grab) {
3771 start = pending_position;
3774 end = pending_position;
3778 /* first drag: Either add to the selection
3779 or create a new selection
3785 /* adding to the selection */
3786 _editor->set_selected_track_as_side_effect (Selection::Add);
3787 //_editor->selection->add (_editor->clicked_axisview);
3788 _editor->clicked_selection = _editor->selection->add (start, end);
3793 if (_editor->clicked_axisview && !_editor->selection->selected (_editor->clicked_axisview)) {
3794 //_editor->selection->set (_editor->clicked_axisview);
3795 _editor->set_selected_track_as_side_effect (Selection::Set);
3798 _editor->clicked_selection = _editor->selection->set (start, end);
3802 /* select the track that we're in */
3803 if (find (_added_time_axes.begin(), _added_time_axes.end(), pending_time_axis.first) == _added_time_axes.end()) {
3804 // _editor->set_selected_track_as_side_effect (Selection::Add);
3805 _editor->selection->add (pending_time_axis.first);
3806 _added_time_axes.push_back (pending_time_axis.first);
3809 /* deselect any tracks that this drag no longer includes, being careful to only deselect
3810 tracks that we selected in the first place.
3813 int min_order = min (_original_pointer_time_axis, pending_time_axis.first->order());
3814 int max_order = max (_original_pointer_time_axis, pending_time_axis.first->order());
3816 list<TimeAxisView*>::iterator i = _added_time_axes.begin();
3817 while (i != _added_time_axes.end()) {
3819 list<TimeAxisView*>::iterator tmp = i;
3822 if ((*i)->order() < min_order || (*i)->order() > max_order) {
3823 _editor->selection->remove (*i);
3824 _added_time_axes.remove (*i);
3833 case SelectionStartTrim:
3835 start = _editor->selection->time[_editor->clicked_selection].start;
3836 end = _editor->selection->time[_editor->clicked_selection].end;
3838 if (pending_position > end) {
3841 start = pending_position;
3845 case SelectionEndTrim:
3847 start = _editor->selection->time[_editor->clicked_selection].start;
3848 end = _editor->selection->time[_editor->clicked_selection].end;
3850 if (pending_position < start) {
3853 end = pending_position;
3860 start = _editor->selection->time[_editor->clicked_selection].start;
3861 end = _editor->selection->time[_editor->clicked_selection].end;
3863 length = end - start;
3864 distance = pending_position - start;
3865 start = pending_position;
3866 _editor->snap_to (start);
3868 end = start + length;
3872 case SelectionExtend:
3876 if (event->button.x >= _editor->horizontal_position() + _editor->_canvas_width) {
3877 _editor->start_canvas_autoscroll (1, 0);
3881 switch (_operation) {
3883 if (_time_selection_at_start) {
3884 _editor->selection->move_time (distance);
3888 _editor->selection->replace (_editor->clicked_selection, start, end);
3892 if (_operation == SelectionMove) {
3893 show_verbose_cursor_time(start);
3895 show_verbose_cursor_time(pending_position);
3900 SelectionDrag::finished (GdkEvent* event, bool movement_occurred)
3902 Session* s = _editor->session();
3904 if (movement_occurred) {
3905 motion (event, false);
3906 /* XXX this is not object-oriented programming at all. ick */
3907 if (_editor->selection->time.consolidate()) {
3908 _editor->selection->TimeChanged ();
3911 /* XXX what if its a music time selection? */
3913 if ( s->get_play_range() && s->transport_rolling() ) {
3914 s->request_play_range (&_editor->selection->time, true);
3916 if (Config->get_always_play_range() && !s->transport_rolling()) {
3917 s->request_locate (_editor->get_selection().time.start());
3923 /* just a click, no pointer movement.
3926 if (_operation == SelectionExtend) {
3927 if (_time_selection_at_start) {
3928 framepos_t pos = adjusted_current_frame (event, false);
3929 framepos_t start = min (pos, start_at_start);
3930 framepos_t end = max (pos, end_at_start);
3931 _editor->selection->set (start, end);
3934 if (Keyboard::modifier_state_equals (event->button.state, Keyboard::CopyModifier)) {
3935 if (_editor->clicked_selection) {
3936 _editor->selection->remove (_editor->clicked_selection);
3939 if (!_editor->clicked_selection) {
3940 _editor->selection->clear_time();
3945 if (_editor->clicked_axisview && !_editor->selection->selected (_editor->clicked_axisview)) {
3946 _editor->selection->set (_editor->clicked_axisview);
3949 if (s && s->get_play_range () && s->transport_rolling()) {
3950 s->request_stop (false, false);
3955 _editor->stop_canvas_autoscroll ();
3956 _editor->clicked_selection = 0;
3960 SelectionDrag::aborted (bool)
3965 RangeMarkerBarDrag::RangeMarkerBarDrag (Editor* e, ArdourCanvas::Item* i, Operation o)
3970 DEBUG_TRACE (DEBUG::Drags, "New RangeMarkerBarDrag\n");
3972 _drag_rect = new ArdourCanvas::SimpleRect (*_editor->time_line_group, 0.0, 0.0, 0.0,
3973 physical_screen_height (_editor->get_window()));
3974 _drag_rect->hide ();
3976 _drag_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_RangeDragRect.get();
3977 _drag_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_RangeDragRect.get();
3981 RangeMarkerBarDrag::start_grab (GdkEvent* event, Gdk::Cursor *)
3983 if (_editor->session() == 0) {
3987 Gdk::Cursor* cursor = 0;
3989 if (!_editor->temp_location) {
3990 _editor->temp_location = new Location (*_editor->session());
3993 switch (_operation) {
3994 case CreateRangeMarker:
3995 case CreateTransportMarker:
3996 case CreateCDMarker:
3998 if (Keyboard::modifier_state_equals (event->button.state, Keyboard::TertiaryModifier)) {
4003 cursor = _editor->cursors()->selector;
4007 Drag::start_grab (event, cursor);
4009 show_verbose_cursor_time (adjusted_current_frame (event));
4013 RangeMarkerBarDrag::motion (GdkEvent* event, bool first_move)
4015 framepos_t start = 0;
4017 ArdourCanvas::SimpleRect *crect;
4019 switch (_operation) {
4020 case CreateRangeMarker:
4021 crect = _editor->range_bar_drag_rect;
4023 case CreateTransportMarker:
4024 crect = _editor->transport_bar_drag_rect;
4026 case CreateCDMarker:
4027 crect = _editor->cd_marker_bar_drag_rect;
4030 error << string_compose (_("programming_error: %1"), "Error: unknown range marker op passed to Editor::drag_range_markerbar_op ()") << endmsg;
4035 framepos_t const pf = adjusted_current_frame (event);
4037 if (_operation == CreateRangeMarker || _operation == CreateTransportMarker || _operation == CreateCDMarker) {
4038 framepos_t grab = grab_frame ();
4039 _editor->snap_to (grab);
4041 if (pf < grab_frame()) {
4049 /* first drag: Either add to the selection
4050 or create a new selection.
4055 _editor->temp_location->set (start, end);
4059 update_item (_editor->temp_location);
4061 //_drag_rect->raise_to_top();
4066 if (event->button.x >= _editor->horizontal_position() + _editor->_canvas_width) {
4067 _editor->start_canvas_autoscroll (1, 0);
4071 _editor->temp_location->set (start, end);
4073 double x1 = _editor->frame_to_pixel (start);
4074 double x2 = _editor->frame_to_pixel (end);
4075 crect->property_x1() = x1;
4076 crect->property_x2() = x2;
4078 update_item (_editor->temp_location);
4081 show_verbose_cursor_time (pf);
4086 RangeMarkerBarDrag::finished (GdkEvent* event, bool movement_occurred)
4088 Location * newloc = 0;
4092 if (movement_occurred) {
4093 motion (event, false);
4096 switch (_operation) {
4097 case CreateRangeMarker:
4098 case CreateCDMarker:
4100 _editor->begin_reversible_command (_("new range marker"));
4101 XMLNode &before = _editor->session()->locations()->get_state();
4102 _editor->session()->locations()->next_available_name(rangename,"unnamed");
4103 if (_operation == CreateCDMarker) {
4104 flags = Location::IsRangeMarker | Location::IsCDMarker;
4105 _editor->cd_marker_bar_drag_rect->hide();
4108 flags = Location::IsRangeMarker;
4109 _editor->range_bar_drag_rect->hide();
4111 newloc = new Location (
4112 *_editor->session(), _editor->temp_location->start(), _editor->temp_location->end(), rangename, (Location::Flags) flags
4115 _editor->session()->locations()->add (newloc, true);
4116 XMLNode &after = _editor->session()->locations()->get_state();
4117 _editor->session()->add_command(new MementoCommand<Locations>(*(_editor->session()->locations()), &before, &after));
4118 _editor->commit_reversible_command ();
4122 case CreateTransportMarker:
4123 // popup menu to pick loop or punch
4124 _editor->new_transport_marker_context_menu (&event->button, _item);
4128 /* just a click, no pointer movement. remember that context menu stuff was handled elsewhere */
4130 if (Keyboard::no_modifier_keys_pressed (&event->button) && _operation != CreateCDMarker) {
4135 _editor->session()->locations()->marks_either_side (grab_frame(), start, end);
4137 if (end == max_framepos) {
4138 end = _editor->session()->current_end_frame ();
4141 if (start == max_framepos) {
4142 start = _editor->session()->current_start_frame ();
4145 switch (_editor->mouse_mode) {
4147 /* find the two markers on either side and then make the selection from it */
4148 _editor->select_all_within (start, end, 0.0f, FLT_MAX, _editor->track_views, Selection::Set, false);
4152 /* find the two markers on either side of the click and make the range out of it */
4153 _editor->selection->set (start, end);
4162 _editor->stop_canvas_autoscroll ();
4166 RangeMarkerBarDrag::aborted (bool)
4172 RangeMarkerBarDrag::update_item (Location* location)
4174 double const x1 = _editor->frame_to_pixel (location->start());
4175 double const x2 = _editor->frame_to_pixel (location->end());
4177 _drag_rect->property_x1() = x1;
4178 _drag_rect->property_x2() = x2;
4181 MouseZoomDrag::MouseZoomDrag (Editor* e, ArdourCanvas::Item* i)
4185 DEBUG_TRACE (DEBUG::Drags, "New MouseZoomDrag\n");
4189 MouseZoomDrag::start_grab (GdkEvent* event, Gdk::Cursor *)
4191 if (Keyboard::the_keyboard().key_is_down (GDK_Control_L)) {
4192 Drag::start_grab (event, _editor->cursors()->zoom_out);
4195 Drag::start_grab (event, _editor->cursors()->zoom_in);
4199 show_verbose_cursor_time (adjusted_current_frame (event));
4203 MouseZoomDrag::motion (GdkEvent* event, bool first_move)
4208 framepos_t const pf = adjusted_current_frame (event);
4210 framepos_t grab = grab_frame ();
4211 _editor->snap_to_with_modifier (grab, event);
4213 /* base start and end on initial click position */
4225 _editor->zoom_rect->show();
4226 _editor->zoom_rect->raise_to_top();
4229 _editor->reposition_zoom_rect(start, end);
4231 show_verbose_cursor_time (pf);
4236 MouseZoomDrag::finished (GdkEvent* event, bool movement_occurred)
4238 if (movement_occurred) {
4239 motion (event, false);
4241 if (grab_frame() < last_pointer_frame()) {
4242 _editor->temporal_zoom_by_frame (grab_frame(), last_pointer_frame());
4244 _editor->temporal_zoom_by_frame (last_pointer_frame(), grab_frame());
4247 if (Keyboard::the_keyboard().key_is_down (GDK_Shift_L)) {
4248 _editor->tav_zoom_step (_zoom_out);
4250 _editor->temporal_zoom_to_frame (_zoom_out, grab_frame());
4254 _editor->zoom_rect->hide();
4258 MouseZoomDrag::aborted (bool)
4260 _editor->zoom_rect->hide ();
4263 NoteDrag::NoteDrag (Editor* e, ArdourCanvas::Item* i)
4265 , _cumulative_dx (0)
4266 , _cumulative_dy (0)
4268 DEBUG_TRACE (DEBUG::Drags, "New NoteDrag\n");
4270 _primary = dynamic_cast<CanvasNoteEvent*> (_item);
4271 _region = &_primary->region_view ();
4272 _note_height = _region->midi_stream_view()->note_height ();
4276 NoteDrag::start_grab (GdkEvent* event, Gdk::Cursor *)
4278 Drag::start_grab (event);
4280 if (!(_was_selected = _primary->selected())) {
4282 /* tertiary-click means extend selection - we'll do that on button release,
4283 so don't add it here, because otherwise we make it hard to figure
4284 out the "extend-to" range.
4287 bool extend = Keyboard::modifier_state_equals (event->button.state, Keyboard::TertiaryModifier);
4290 bool add = Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier);
4293 _region->note_selected (_primary, true);
4295 _region->unique_select (_primary);
4301 /** @return Current total drag x change in frames */
4303 NoteDrag::total_dx () const
4306 frameoffset_t const dx = _editor->unit_to_frame (_drags->current_pointer_x() - grab_x());
4308 /* primary note time */
4309 frameoffset_t const n = _region->source_beats_to_absolute_frames (_primary->note()->time ());
4311 /* new time of the primary note in session frames */
4312 frameoffset_t st = n + dx;
4314 framepos_t const rp = _region->region()->position ();
4316 /* prevent the note being dragged earlier than the region's position */
4319 /* snap and return corresponding delta */
4320 return _region->snap_frame_to_frame (st - rp) + rp - n;
4323 /** @return Current total drag y change in note number */
4325 NoteDrag::total_dy () const
4327 MidiStreamView* msv = _region->midi_stream_view ();
4328 double const y = _region->midi_view()->y_position ();
4329 /* new current note */
4330 uint8_t n = msv->y_to_note (_drags->current_pointer_y () - y);
4332 n = max (msv->lowest_note(), n);
4333 n = min (msv->highest_note(), n);
4334 /* and work out delta */
4335 return n - msv->y_to_note (grab_y() - y);
4339 NoteDrag::motion (GdkEvent *, bool)
4341 /* Total change in x and y since the start of the drag */
4342 frameoffset_t const dx = total_dx ();
4343 int8_t const dy = total_dy ();
4345 /* Now work out what we have to do to the note canvas items to set this new drag delta */
4346 double const tdx = _editor->frame_to_unit (dx) - _cumulative_dx;
4347 double const tdy = -dy * _note_height - _cumulative_dy;
4350 _cumulative_dx += tdx;
4351 _cumulative_dy += tdy;
4353 int8_t note_delta = total_dy();
4355 _region->move_selection (tdx, tdy, note_delta);
4357 /* the new note value may be the same as the old one, but we
4358 * don't know what that means because the selection may have
4359 * involved more than one note and we might be doing something
4360 * odd with them. so show the note value anyway, always.
4364 uint8_t new_note = min (max (_primary->note()->note() + note_delta, 0), 127);
4366 snprintf (buf, sizeof (buf), "%s (%d)", Evoral::midi_note_name (new_note).c_str(),
4367 (int) floor (new_note));
4369 show_verbose_cursor_text (buf);
4374 NoteDrag::finished (GdkEvent* ev, bool moved)
4377 /* no motion - select note */
4379 if (_editor->current_mouse_mode() == Editing::MouseObject ||
4380 _editor->current_mouse_mode() == Editing::MouseDraw) {
4382 if (_was_selected) {
4383 bool add = Keyboard::modifier_state_equals (ev->button.state, Keyboard::PrimaryModifier);
4385 _region->note_deselected (_primary);
4388 bool extend = Keyboard::modifier_state_equals (ev->button.state, Keyboard::TertiaryModifier);
4389 bool add = Keyboard::modifier_state_equals (ev->button.state, Keyboard::PrimaryModifier);
4391 if (!extend && !add && _region->selection_size() > 1) {
4392 _region->unique_select (_primary);
4393 } else if (extend) {
4394 _region->note_selected (_primary, true, true);
4396 /* it was added during button press */
4401 _region->note_dropped (_primary, total_dx(), total_dy());
4406 NoteDrag::aborted (bool)
4411 /** Make an AutomationRangeDrag for lines in an AutomationTimeAxisView */
4412 AutomationRangeDrag::AutomationRangeDrag (Editor* editor, AutomationTimeAxisView* atv, list<AudioRange> const & r)
4413 : Drag (editor, atv->base_item ())
4415 , _nothing_to_drag (false)
4417 DEBUG_TRACE (DEBUG::Drags, "New AutomationRangeDrag\n");
4418 y_origin = atv->y_position();
4419 setup (atv->lines ());
4422 /** Make an AutomationRangeDrag for region gain lines */
4423 AutomationRangeDrag::AutomationRangeDrag (Editor* editor, AudioRegionView* rv, list<AudioRange> const & r)
4424 : Drag (editor, rv->get_canvas_group ())
4426 , _nothing_to_drag (false)
4428 DEBUG_TRACE (DEBUG::Drags, "New AutomationRangeDrag\n");
4430 list<boost::shared_ptr<AutomationLine> > lines;
4431 lines.push_back (rv->get_gain_line ());
4432 y_origin = rv->get_time_axis_view().y_position();
4436 /** @param lines AutomationLines to drag.
4437 * @param offset Offset from the session start to the points in the AutomationLines.
4440 AutomationRangeDrag::setup (list<boost::shared_ptr<AutomationLine> > const & lines)
4442 /* find the lines that overlap the ranges being dragged */
4443 list<boost::shared_ptr<AutomationLine> >::const_iterator i = lines.begin ();
4444 while (i != lines.end ()) {
4445 list<boost::shared_ptr<AutomationLine> >::const_iterator j = i;
4448 pair<framepos_t, framepos_t> r = (*i)->get_point_x_range ();
4450 /* check this range against all the AudioRanges that we are using */
4451 list<AudioRange>::const_iterator k = _ranges.begin ();
4452 while (k != _ranges.end()) {
4453 if (k->coverage (r.first, r.second) != Evoral::OverlapNone) {
4459 /* add it to our list if it overlaps at all */
4460 if (k != _ranges.end()) {
4465 _lines.push_back (n);
4471 /* Now ::lines contains the AutomationLines that somehow overlap our drag */
4475 AutomationRangeDrag::y_fraction (boost::shared_ptr<AutomationLine> line, double global_y) const
4477 return 1.0 - ((global_y - y_origin) / line->height());
4481 AutomationRangeDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
4483 Drag::start_grab (event, cursor);
4485 /* Get line states before we start changing things */
4486 for (list<Line>::iterator i = _lines.begin(); i != _lines.end(); ++i) {
4487 i->state = &i->line->get_state ();
4488 i->original_fraction = y_fraction (i->line, _drags->current_pointer_y());
4491 if (_ranges.empty()) {
4493 /* No selected time ranges: drag all points */
4494 for (list<Line>::iterator i = _lines.begin(); i != _lines.end(); ++i) {
4495 uint32_t const N = i->line->npoints ();
4496 for (uint32_t j = 0; j < N; ++j) {
4497 i->points.push_back (i->line->nth (j));
4503 for (list<AudioRange>::const_iterator i = _ranges.begin(); i != _ranges.end(); ++i) {
4505 framecnt_t const half = (i->start + i->end) / 2;
4507 /* find the line that this audio range starts in */
4508 list<Line>::iterator j = _lines.begin();
4509 while (j != _lines.end() && (j->range.first > i->start || j->range.second < i->start)) {
4513 if (j != _lines.end()) {
4514 boost::shared_ptr<AutomationList> the_list = j->line->the_list ();
4516 /* j is the line that this audio range starts in; fade into it;
4517 64 samples length plucked out of thin air.
4520 framepos_t a = i->start + 64;
4525 double const p = j->line->time_converter().from (i->start - j->line->time_converter().origin_b ());
4526 double const q = j->line->time_converter().from (a - j->line->time_converter().origin_b ());
4528 the_list->add (p, the_list->eval (p));
4529 the_list->add (q, the_list->eval (q));
4532 /* same thing for the end */
4535 while (j != _lines.end() && (j->range.first > i->end || j->range.second < i->end)) {
4539 if (j != _lines.end()) {
4540 boost::shared_ptr<AutomationList> the_list = j->line->the_list ();
4542 /* j is the line that this audio range starts in; fade out of it;
4543 64 samples length plucked out of thin air.
4546 framepos_t b = i->end - 64;
4551 double const p = j->line->time_converter().from (b - j->line->time_converter().origin_b ());
4552 double const q = j->line->time_converter().from (i->end - j->line->time_converter().origin_b ());
4554 the_list->add (p, the_list->eval (p));
4555 the_list->add (q, the_list->eval (q));
4559 _nothing_to_drag = true;
4561 /* Find all the points that should be dragged and put them in the relevant
4562 points lists in the Line structs.
4565 for (list<Line>::iterator i = _lines.begin(); i != _lines.end(); ++i) {
4567 uint32_t const N = i->line->npoints ();
4568 for (uint32_t j = 0; j < N; ++j) {
4570 /* here's a control point on this line */
4571 ControlPoint* p = i->line->nth (j);
4572 double const w = i->line->time_converter().to ((*p->model())->when) + i->line->time_converter().origin_b ();
4574 /* see if it's inside a range */
4575 list<AudioRange>::const_iterator k = _ranges.begin ();
4576 while (k != _ranges.end() && (k->start >= w || k->end <= w)) {
4580 if (k != _ranges.end()) {
4581 /* dragging this point */
4582 _nothing_to_drag = false;
4583 i->points.push_back (p);
4589 if (_nothing_to_drag) {
4593 for (list<Line>::iterator i = _lines.begin(); i != _lines.end(); ++i) {
4594 i->line->start_drag_multiple (i->points, y_fraction (i->line, _drags->current_pointer_y()), i->state);
4599 AutomationRangeDrag::motion (GdkEvent*, bool /*first_move*/)
4601 if (_nothing_to_drag) {
4605 for (list<Line>::iterator l = _lines.begin(); l != _lines.end(); ++l) {
4606 float const f = y_fraction (l->line, _drags->current_pointer_y());
4607 /* we are ignoring x position for this drag, so we can just pass in anything */
4609 l->line->drag_motion (0, f, true, false, ignored);
4610 show_verbose_cursor_text (l->line->get_verbose_cursor_relative_string (l->original_fraction, f));
4615 AutomationRangeDrag::finished (GdkEvent* event, bool)
4617 if (_nothing_to_drag) {
4621 motion (event, false);
4622 for (list<Line>::iterator i = _lines.begin(); i != _lines.end(); ++i) {
4623 i->line->end_drag (false, 0);
4626 _editor->session()->commit_reversible_command ();
4630 AutomationRangeDrag::aborted (bool)
4632 for (list<Line>::iterator i = _lines.begin(); i != _lines.end(); ++i) {
4637 DraggingView::DraggingView (RegionView* v, RegionDrag* parent)
4640 time_axis_view = parent->find_time_axis_view (&v->get_time_axis_view ());
4641 layer = v->region()->layer ();
4642 initial_y = v->get_canvas_group()->property_y ();
4643 initial_playlist = v->region()->playlist ();
4644 initial_position = v->region()->position ();
4645 initial_end = v->region()->position () + v->region()->length ();
4648 PatchChangeDrag::PatchChangeDrag (Editor* e, CanvasPatchChange* i, MidiRegionView* r)
4652 , _cumulative_dx (0)
4654 DEBUG_TRACE (DEBUG::Drags, string_compose ("New PatchChangeDrag, patch @ %1, grab @ %2\n",
4655 _region_view->source_beats_to_absolute_frames (_patch_change->patch()->time()),
4660 PatchChangeDrag::motion (GdkEvent* ev, bool)
4662 framepos_t f = adjusted_current_frame (ev);
4663 boost::shared_ptr<Region> r = _region_view->region ();
4664 f = max (f, r->position ());
4665 f = min (f, r->last_frame ());
4667 framecnt_t const dxf = f - grab_frame(); // permitted dx in frames
4668 double const dxu = _editor->frame_to_unit (dxf); // permitted fx in units
4669 _patch_change->move (dxu - _cumulative_dx, 0);
4670 _cumulative_dx = dxu;
4674 PatchChangeDrag::finished (GdkEvent* ev, bool movement_occurred)
4676 if (!movement_occurred) {
4680 boost::shared_ptr<Region> r (_region_view->region ());
4681 framepos_t f = adjusted_current_frame (ev);
4682 f = max (f, r->position ());
4683 f = min (f, r->last_frame ());
4685 _region_view->move_patch_change (
4687 _region_view->region_frames_to_region_beats (f - (r->position() - r->start()))
4692 PatchChangeDrag::aborted (bool)
4694 _patch_change->move (-_cumulative_dx, 0);
4698 PatchChangeDrag::setup_pointer_frame_offset ()
4700 boost::shared_ptr<Region> region = _region_view->region ();
4701 _pointer_frame_offset = raw_grab_frame() - _region_view->source_beats_to_absolute_frames (_patch_change->patch()->time());
4704 MidiRubberbandSelectDrag::MidiRubberbandSelectDrag (Editor* e, MidiRegionView* rv)
4705 : RubberbandSelectDrag (e, rv->get_canvas_frame ())
4712 MidiRubberbandSelectDrag::select_things (int button_state, framepos_t x1, framepos_t x2, double y1, double y2, bool /*drag_in_progress*/)
4714 framepos_t const p = _region_view->region()->position ();
4715 double const y = _region_view->midi_view()->y_position ();
4717 x1 = max ((framepos_t) 0, x1 - p);
4718 x2 = max ((framepos_t) 0, x2 - p);
4719 y1 = max (0.0, y1 - y);
4720 y2 = max (0.0, y2 - y);
4722 _region_view->update_drag_selection (
4723 _editor->frame_to_pixel (x1),
4724 _editor->frame_to_pixel (x2),
4727 Keyboard::modifier_state_contains (button_state, Keyboard::TertiaryModifier)
4732 MidiRubberbandSelectDrag::deselect_things ()
4737 MidiVerticalSelectDrag::MidiVerticalSelectDrag (Editor* e, MidiRegionView* rv)
4738 : RubberbandSelectDrag (e, rv->get_canvas_frame ())
4741 _vertical_only = true;
4745 MidiVerticalSelectDrag::select_things (int button_state, framepos_t /*x1*/, framepos_t /*x2*/, double y1, double y2, bool /*drag_in_progress*/)
4747 double const y = _region_view->midi_view()->y_position ();
4749 y1 = max (0.0, y1 - y);
4750 y2 = max (0.0, y2 - y);
4752 _region_view->update_vertical_drag_selection (
4755 Keyboard::modifier_state_contains (button_state, Keyboard::TertiaryModifier)
4760 MidiVerticalSelectDrag::deselect_things ()
4765 EditorRubberbandSelectDrag::EditorRubberbandSelectDrag (Editor* e, ArdourCanvas::Item* i)
4766 : RubberbandSelectDrag (e, i)
4772 EditorRubberbandSelectDrag::select_things (int button_state, framepos_t x1, framepos_t x2, double y1, double y2, bool drag_in_progress)
4774 if (drag_in_progress) {
4775 /* We just want to select things at the end of the drag, not during it */
4779 Selection::Operation op = ArdourKeyboard::selection_type (button_state);
4781 _editor->begin_reversible_command (_("rubberband selection"));
4782 _editor->select_all_within (x1, x2 - 1, y1, y2, _editor->track_views, op, false);
4783 _editor->commit_reversible_command ();
4787 EditorRubberbandSelectDrag::deselect_things ()
4789 if (!getenv("ARDOUR_SAE")) {
4790 _editor->selection->clear_tracks();
4792 _editor->selection->clear_regions();
4793 _editor->selection->clear_points ();
4794 _editor->selection->clear_lines ();
4797 NoteCreateDrag::NoteCreateDrag (Editor* e, ArdourCanvas::Item* i, MidiRegionView* rv)
4805 NoteCreateDrag::~NoteCreateDrag ()
4811 NoteCreateDrag::grid_frames (framepos_t t) const
4814 Evoral::MusicalTime grid_beats = _editor->get_grid_type_as_beats (success, t);
4819 return _region_view->region_beats_to_region_frames (grid_beats);
4823 NoteCreateDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
4825 Drag::start_grab (event, cursor);
4827 _drag_rect = new ArdourCanvas::SimpleRect (*_region_view->get_canvas_group ());
4829 framepos_t pf = _drags->current_pointer_frame ();
4830 framecnt_t const g = grid_frames (pf);
4832 /* Hack so that we always snap to the note that we are over, instead of snapping
4833 to the next one if we're more than halfway through the one we're over.
4835 if (_editor->snap_mode() == SnapNormal && pf > g / 2) {
4839 _note[0] = adjusted_frame (pf, event) - _region_view->region()->position ();
4841 MidiStreamView* sv = _region_view->midi_stream_view ();
4842 double const x = _editor->frame_to_pixel (_note[0]);
4843 double const y = sv->note_to_y (sv->y_to_note (y_to_region (event->button.y)));
4845 _drag_rect->property_x1() = x;
4846 _drag_rect->property_y1() = y;
4847 _drag_rect->property_x2() = x;
4848 _drag_rect->property_y2() = y + floor (_region_view->midi_stream_view()->note_height ());
4850 _drag_rect->property_outline_what() = 0xff;
4851 _drag_rect->property_outline_color_rgba() = 0xffffff99;
4852 _drag_rect->property_fill_color_rgba() = 0xffffff66;
4856 NoteCreateDrag::motion (GdkEvent* event, bool)
4858 _note[1] = max ((framepos_t)0, adjusted_current_frame (event) - _region_view->region()->position ());
4859 double const x = _editor->frame_to_pixel (_note[1]);
4860 if (_note[1] > _note[0]) {
4861 _drag_rect->property_x2() = x;
4863 _drag_rect->property_x1() = x;
4868 NoteCreateDrag::finished (GdkEvent*, bool had_movement)
4870 if (!had_movement) {
4874 framepos_t const start = min (_note[0], _note[1]);
4875 framecnt_t length = (framecnt_t) fabs (_note[0] - _note[1]);
4877 framecnt_t const g = grid_frames (start);
4878 double const one_tick = 1 / Timecode::BBT_Time::ticks_per_beat;
4880 if (_editor->snap_mode() == SnapNormal && length < g) {
4881 length = g - one_tick;
4884 double const length_beats = max (one_tick, _region_view->region_frames_to_region_beats (length));
4886 _region_view->create_note_at (start, _drag_rect->property_y1(), length_beats, false);
4890 NoteCreateDrag::y_to_region (double y) const
4893 _region_view->get_canvas_group()->w2i (x, y);
4898 NoteCreateDrag::aborted (bool)
4903 CrossfadeEdgeDrag::CrossfadeEdgeDrag (Editor* e, AudioRegionView* rv, ArdourCanvas::Item* i, bool start_yn)
4908 std::cout << ("CrossfadeEdgeDrag is DEPRECATED. See TrimDrag::preserve_fade_anchor") << endl;
4912 CrossfadeEdgeDrag::start_grab (GdkEvent* event, Gdk::Cursor *cursor)
4914 Drag::start_grab (event, cursor);
4918 CrossfadeEdgeDrag::motion (GdkEvent*, bool)
4924 boost::shared_ptr<AudioRegion> ar (arv->audio_region());
4927 distance = _drags->current_pointer_x() - grab_x();
4928 len = ar->fade_in()->back()->when;
4930 distance = grab_x() - _drags->current_pointer_x();
4931 len = ar->fade_out()->back()->when;
4934 /* how long should it be ? */
4936 new_length = len + _editor->unit_to_frame (distance);
4938 /* now check with the region that this is legal */
4940 new_length = ar->verify_xfade_bounds (new_length, start);
4943 arv->redraw_start_xfade_to (ar, new_length);
4945 arv->redraw_end_xfade_to (ar, new_length);
4950 CrossfadeEdgeDrag::finished (GdkEvent*, bool)
4956 boost::shared_ptr<AudioRegion> ar (arv->audio_region());
4959 distance = _drags->current_pointer_x() - grab_x();
4960 len = ar->fade_in()->back()->when;
4962 distance = grab_x() - _drags->current_pointer_x();
4963 len = ar->fade_out()->back()->when;
4966 new_length = ar->verify_xfade_bounds (len + _editor->unit_to_frame (distance), start);
4968 _editor->begin_reversible_command ("xfade trim");
4969 ar->playlist()->clear_owned_changes ();
4972 ar->set_fade_in_length (new_length);
4974 ar->set_fade_out_length (new_length);
4977 /* Adjusting the xfade may affect other regions in the playlist, so we need
4978 to get undo Commands from the whole playlist rather than just the
4982 vector<Command*> cmds;
4983 ar->playlist()->rdiff (cmds);
4984 _editor->session()->add_commands (cmds);
4985 _editor->commit_reversible_command ();
4990 CrossfadeEdgeDrag::aborted (bool)
4993 arv->redraw_start_xfade ();
4995 arv->redraw_end_xfade ();