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 "selection.h"
55 #include "midi_selection.h"
56 #include "automation_time_axis.h"
58 #include "editor_cursors.h"
59 #include "mouse_cursors.h"
60 #include "note_base.h"
61 #include "patch_change.h"
62 #include "verbose_cursor.h"
65 using namespace ARDOUR;
68 using namespace Gtkmm2ext;
69 using namespace Editing;
70 using namespace ArdourCanvas;
72 using Gtkmm2ext::Keyboard;
74 double ControlPointDrag::_zero_gain_fraction = -1.0;
76 DragManager::DragManager (Editor* e)
79 , _current_pointer_frame (0)
83 DragManager::~DragManager ()
88 /** Call abort for each active drag */
94 for (list<Drag*>::const_iterator i = _drags.begin(); i != _drags.end(); ++i) {
99 if (!_drags.empty ()) {
100 _editor->set_follow_playhead (_old_follow_playhead, false);
109 DragManager::add (Drag* d)
111 d->set_manager (this);
112 _drags.push_back (d);
116 DragManager::set (Drag* d, GdkEvent* e, Gdk::Cursor* c)
118 d->set_manager (this);
119 _drags.push_back (d);
124 DragManager::start_grab (GdkEvent* e, Gdk::Cursor* c)
126 /* Prevent follow playhead during the drag to be nice to the user */
127 _old_follow_playhead = _editor->follow_playhead ();
128 _editor->set_follow_playhead (false);
130 _current_pointer_frame = _editor->canvas_event_frame (e, &_current_pointer_x, &_current_pointer_y);
132 for (list<Drag*>::const_iterator i = _drags.begin(); i != _drags.end(); ++i) {
133 (*i)->start_grab (e, c);
137 /** Call end_grab for each active drag.
138 * @return true if any drag reported movement having occurred.
141 DragManager::end_grab (GdkEvent* e)
146 for (list<Drag*>::iterator i = _drags.begin(); i != _drags.end(); ++i) {
147 bool const t = (*i)->end_grab (e);
158 _editor->set_follow_playhead (_old_follow_playhead, false);
164 DragManager::mark_double_click ()
166 for (list<Drag*>::const_iterator i = _drags.begin(); i != _drags.end(); ++i) {
167 (*i)->set_double_click (true);
172 DragManager::motion_handler (GdkEvent* e, bool from_autoscroll)
176 _current_pointer_frame = _editor->canvas_event_frame (e, &_current_pointer_x, &_current_pointer_y);
178 for (list<Drag*>::iterator i = _drags.begin(); i != _drags.end(); ++i) {
179 bool const t = (*i)->motion_handler (e, from_autoscroll);
190 DragManager::window_motion_handler (GdkEvent* e, bool from_autoscroll)
194 _current_pointer_frame = _editor->window_event_frame (e, &_current_pointer_x, &_current_pointer_y);
196 for (list<Drag*>::iterator i = _drags.begin(); i != _drags.end(); ++i) {
197 bool const t = (*i)->motion_handler (e, from_autoscroll);
208 DragManager::have_item (ArdourCanvas::Item* i) const
210 list<Drag*>::const_iterator j = _drags.begin ();
211 while (j != _drags.end() && (*j)->item () != i) {
215 return j != _drags.end ();
218 Drag::Drag (Editor* e, ArdourCanvas::Item* i)
221 , _pointer_frame_offset (0)
222 , _move_threshold_passed (false)
223 , _was_double_click (false)
224 , _raw_grab_frame (0)
226 , _last_pointer_frame (0)
232 Drag::swap_grab (ArdourCanvas::Item* new_item, Gdk::Cursor* cursor, uint32_t /*time*/)
245 Drag::start_grab (GdkEvent* event, Gdk::Cursor *cursor)
247 // if dragging with button2, the motion is x constrained, with Alt-button2 it is y constrained
249 if (Keyboard::is_button2_event (&event->button)) {
250 if (Keyboard::modifier_state_equals (event->button.state, Keyboard::SecondaryModifier)) {
251 _y_constrained = true;
252 _x_constrained = false;
254 _y_constrained = false;
255 _x_constrained = true;
258 _x_constrained = false;
259 _y_constrained = false;
262 _raw_grab_frame = _editor->canvas_event_frame (event, &_grab_x, &_grab_y);
263 setup_pointer_frame_offset ();
264 _grab_frame = adjusted_frame (_raw_grab_frame, event);
265 _last_pointer_frame = _grab_frame;
266 _last_pointer_x = _grab_x;
267 _last_pointer_y = _grab_y;
273 /* CAIROCANVAS need a variant here that passes *cursor */
278 if (_editor->session() && _editor->session()->transport_rolling()) {
281 _was_rolling = false;
284 switch (_editor->snap_type()) {
285 case SnapToRegionStart:
286 case SnapToRegionEnd:
287 case SnapToRegionSync:
288 case SnapToRegionBoundary:
289 _editor->build_region_boundary_cache ();
296 /** Call to end a drag `successfully'. Ungrabs item and calls
297 * subclass' finished() method.
299 * @param event GDK event, or 0.
300 * @return true if some movement occurred, otherwise false.
303 Drag::end_grab (GdkEvent* event)
305 _editor->stop_canvas_autoscroll ();
309 finished (event, _move_threshold_passed);
311 _editor->verbose_cursor()->hide ();
313 return _move_threshold_passed;
317 Drag::adjusted_frame (framepos_t f, GdkEvent const * event, bool snap) const
321 if (f > _pointer_frame_offset) {
322 pos = f - _pointer_frame_offset;
326 _editor->snap_to_with_modifier (pos, event);
333 Drag::adjusted_current_frame (GdkEvent const * event, bool snap) const
335 return adjusted_frame (_drags->current_pointer_frame (), event, snap);
339 Drag::motion_handler (GdkEvent* event, bool from_autoscroll)
341 /* check to see if we have moved in any way that matters since the last motion event */
342 if (_move_threshold_passed &&
343 (!x_movement_matters() || _last_pointer_frame == adjusted_current_frame (event)) &&
344 (!y_movement_matters() || _last_pointer_y == _drags->current_pointer_y ()) ) {
348 pair<framecnt_t, int> const threshold = move_threshold ();
350 bool const old_move_threshold_passed = _move_threshold_passed;
352 if (!from_autoscroll && !_move_threshold_passed) {
354 bool const xp = (::llabs (_drags->current_pointer_frame () - _raw_grab_frame) >= threshold.first);
355 bool const yp = (::fabs ((_drags->current_pointer_y () - _grab_y)) >= threshold.second);
357 _move_threshold_passed = ((xp && x_movement_matters()) || (yp && y_movement_matters()));
360 if (active (_editor->mouse_mode) && _move_threshold_passed) {
362 if (event->motion.state & Gdk::BUTTON1_MASK || event->motion.state & Gdk::BUTTON2_MASK) {
363 if (!from_autoscroll) {
364 bool const moving_left = _drags->current_pointer_x() < _last_pointer_x;
365 bool const moving_up = _drags->current_pointer_y() < _last_pointer_y;
366 _editor->maybe_autoscroll (true, allow_vertical_autoscroll (), moving_left, moving_up);
369 motion (event, _move_threshold_passed != old_move_threshold_passed);
371 _last_pointer_x = _drags->current_pointer_x ();
372 _last_pointer_y = _drags->current_pointer_y ();
373 _last_pointer_frame = adjusted_current_frame (event);
381 /** Call to abort a drag. Ungrabs item and calls subclass's aborted () */
389 aborted (_move_threshold_passed);
391 _editor->stop_canvas_autoscroll ();
392 _editor->verbose_cursor()->hide ();
396 Drag::show_verbose_cursor_time (framepos_t frame)
398 _editor->verbose_cursor()->set_time (
400 _drags->current_pointer_x() + 10 - _editor->horizontal_position(),
401 _drags->current_pointer_y() + 10 - _editor->vertical_adjustment.get_value()
404 _editor->verbose_cursor()->show ();
408 Drag::show_verbose_cursor_duration (framepos_t start, framepos_t end, double xoffset)
410 _editor->verbose_cursor()->show (xoffset);
412 _editor->verbose_cursor()->set_duration (
414 _drags->current_pointer_x() + 10 - _editor->horizontal_position(),
415 _drags->current_pointer_y() + 10 - _editor->vertical_adjustment.get_value()
420 Drag::show_verbose_cursor_text (string const & text)
422 _editor->verbose_cursor()->show ();
424 _editor->verbose_cursor()->set (
426 _drags->current_pointer_x() + 10 - _editor->horizontal_position(),
427 _drags->current_pointer_y() + 10 - _editor->vertical_adjustment.get_value()
431 boost::shared_ptr<Region>
432 Drag::add_midi_region (MidiTimeAxisView* view)
434 if (_editor->session()) {
435 const TempoMap& map (_editor->session()->tempo_map());
436 framecnt_t pos = grab_frame();
437 const Meter& m = map.meter_at (pos);
438 /* not that the frame rate used here can be affected by pull up/down which
441 framecnt_t len = m.frames_per_bar (map.tempo_at (pos), _editor->session()->frame_rate());
442 return view->add_region (grab_frame(), len, true);
445 return boost::shared_ptr<Region>();
448 struct EditorOrderTimeAxisViewSorter {
449 bool operator() (TimeAxisView* a, TimeAxisView* b) {
450 RouteTimeAxisView* ra = dynamic_cast<RouteTimeAxisView*> (a);
451 RouteTimeAxisView* rb = dynamic_cast<RouteTimeAxisView*> (b);
453 return ra->route()->order_key (EditorSort) < rb->route()->order_key (EditorSort);
457 RegionDrag::RegionDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, list<RegionView*> const & v)
461 _editor->visible_order_range (&_visible_y_low, &_visible_y_high);
463 /* Make a list of tracks to refer to during the drag; we include hidden tracks,
464 as some of the regions we are dragging may be on such tracks.
467 TrackViewList track_views = _editor->track_views;
468 track_views.sort (EditorOrderTimeAxisViewSorter ());
470 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
471 _time_axis_views.push_back (*i);
473 TimeAxisView::Children children_list = (*i)->get_child_list ();
474 for (TimeAxisView::Children::iterator j = children_list.begin(); j != children_list.end(); ++j) {
475 _time_axis_views.push_back (j->get());
479 /* the list of views can be empty at this point if this is a region list-insert drag
482 for (list<RegionView*>::const_iterator i = v.begin(); i != v.end(); ++i) {
483 _views.push_back (DraggingView (*i, this));
486 RegionView::RegionViewGoingAway.connect (death_connection, invalidator (*this), boost::bind (&RegionDrag::region_going_away, this, _1), gui_context());
490 RegionDrag::region_going_away (RegionView* v)
492 list<DraggingView>::iterator i = _views.begin ();
493 while (i != _views.end() && i->view != v) {
497 if (i != _views.end()) {
502 /** Given a TimeAxisView, return the index of it into the _time_axis_views vector,
503 * or -1 if it is not found.
506 RegionDrag::find_time_axis_view (TimeAxisView* t) const
509 int const N = _time_axis_views.size ();
510 while (i < N && _time_axis_views[i] != t) {
521 RegionMotionDrag::RegionMotionDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, list<RegionView*> const & v, bool b)
522 : RegionDrag (e, i, p, v),
526 DEBUG_TRACE (DEBUG::Drags, "New RegionMotionDrag\n");
530 RegionMotionDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
532 Drag::start_grab (event, cursor);
534 show_verbose_cursor_time (_last_frame_position);
536 pair<TimeAxisView*, double> const tv = _editor->trackview_by_y_position (_drags->current_pointer_y ());
537 _last_pointer_time_axis_view = find_time_axis_view (tv.first);
538 _last_pointer_layer = tv.first->layer_display() == Overlaid ? 0 : tv.second;
542 RegionMotionDrag::compute_x_delta (GdkEvent const * event, framepos_t* pending_region_position)
544 /* compute the amount of pointer motion in frames, and where
545 the region would be if we moved it by that much.
547 *pending_region_position = adjusted_current_frame (event);
549 framepos_t sync_frame;
550 framecnt_t sync_offset;
553 sync_offset = _primary->region()->sync_offset (sync_dir);
555 /* we don't handle a sync point that lies before zero.
557 if (sync_dir >= 0 || (sync_dir < 0 && *pending_region_position >= sync_offset)) {
559 sync_frame = *pending_region_position + (sync_dir*sync_offset);
561 _editor->snap_to_with_modifier (sync_frame, event);
563 *pending_region_position = _primary->region()->adjust_to_sync (sync_frame);
566 *pending_region_position = _last_frame_position;
569 if (*pending_region_position > max_framepos - _primary->region()->length()) {
570 *pending_region_position = _last_frame_position;
575 /* in locked edit mode, reverse the usual meaning of _x_constrained */
576 bool const x_move_allowed = Config->get_edit_mode() == Lock ? _x_constrained : !_x_constrained;
578 if ((*pending_region_position != _last_frame_position) && x_move_allowed) {
580 /* x movement since last time (in pixels) */
581 dx = (static_cast<double> (*pending_region_position) - _last_frame_position) / _editor->samples_per_pixel;
583 /* total x movement */
584 framecnt_t total_dx = *pending_region_position;
585 if (regions_came_from_canvas()) {
586 total_dx = total_dx - grab_frame ();
589 /* check that no regions have gone off the start of the session */
590 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
591 if ((i->view->region()->position() + total_dx) < 0) {
593 *pending_region_position = _last_frame_position;
598 _last_frame_position = *pending_region_position;
605 RegionMotionDrag::y_movement_allowed (int delta_track, double delta_layer) const
607 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
608 int const n = i->time_axis_view + delta_track;
609 if (n < 0 || n >= int (_time_axis_views.size())) {
610 /* off the top or bottom track */
614 RouteTimeAxisView const * to = dynamic_cast<RouteTimeAxisView const *> (_time_axis_views[n]);
615 if (to == 0 || !to->is_track() || to->track()->data_type() != i->view->region()->data_type()) {
616 /* not a track, or the wrong type */
620 double const l = i->layer + delta_layer;
622 /* Note that we allow layer to be up to 0.5 below zero, as this is used by `Expanded'
623 mode to allow the user to place a region below another on layer 0.
625 if (delta_track == 0 && (l < -0.5 || l >= int (to->view()->layers()))) {
626 /* Off the top or bottom layer; note that we only refuse if the track hasn't changed.
627 If it has, the layers will be munged later anyway, so it's ok.
633 /* all regions being dragged are ok with this change */
638 RegionMotionDrag::motion (GdkEvent* event, bool first_move)
640 assert (!_views.empty ());
642 /* Find the TimeAxisView that the pointer is now over */
643 pair<TimeAxisView*, double> const tv = _editor->trackview_by_y_position (_drags->current_pointer_y ());
645 if (first_move && tv.first->view()->layer_display() == Stacked) {
646 tv.first->view()->set_layer_display (Expanded);
649 /* Bail early if we're not over a track */
650 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (tv.first);
651 if (!rtv || !rtv->is_track()) {
652 _editor->verbose_cursor()->hide ();
656 /* Note: time axis views in this method are often expressed as an index into the _time_axis_views vector */
658 /* Here's the current pointer position in terms of time axis view and layer */
659 int const current_pointer_time_axis_view = find_time_axis_view (tv.first);
660 double const current_pointer_layer = tv.first->layer_display() == Overlaid ? 0 : tv.second;
662 /* Work out the change in x */
663 framepos_t pending_region_position;
664 double const x_delta = compute_x_delta (event, &pending_region_position);
666 /* Work out the change in y */
668 int delta_time_axis_view = current_pointer_time_axis_view - _last_pointer_time_axis_view;
669 double delta_layer = current_pointer_layer - _last_pointer_layer;
671 if (!y_movement_allowed (delta_time_axis_view, delta_layer)) {
672 /* this y movement is not allowed, so do no y movement this time */
673 delta_time_axis_view = 0;
677 if (x_delta == 0 && delta_time_axis_view == 0 && delta_layer == 0 && !first_move) {
678 /* haven't reached next snap point, and we're not switching
679 trackviews nor layers. nothing to do.
684 pair<set<boost::shared_ptr<Playlist> >::iterator,bool> insert_result;
686 for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
688 RegionView* rv = i->view;
690 if (rv->region()->locked() || rv->region()->video_locked()) {
698 /* Reparent to a non scrolling group so that we can keep the
699 region selection above all time axis views.
700 Reparenting means that we will have to move the region view
701 within its new parent, as the two parent groups have different coordinates.
704 ArdourCanvas::Group* rvg = rv->get_canvas_group();
705 Duple rv_canvas_offset = rvg->item_to_canvas (Duple (0,0));
707 rv->get_canvas_group()->reparent (_editor->_region_motion_group);
709 rv->fake_set_opaque (true);
710 rvg->set_position (rv_canvas_offset);
713 /* If we have moved tracks, we'll fudge the layer delta so that the
714 region gets moved back onto layer 0 on its new track; this avoids
715 confusion when dragging regions from non-zero layers onto different
718 double this_delta_layer = delta_layer;
719 if (delta_time_axis_view != 0) {
720 this_delta_layer = - i->layer;
723 /* The TimeAxisView that this region is now on */
724 TimeAxisView* tv = _time_axis_views[i->time_axis_view + delta_time_axis_view];
726 /* Ensure it is moved from stacked -> expanded if appropriate */
727 if (tv->view()->layer_display() == Stacked) {
728 tv->view()->set_layer_display (Expanded);
731 /* We're only allowed to go -ve in layer on Expanded views */
732 if (tv->view()->layer_display() != Expanded && (i->layer + this_delta_layer) < 0) {
733 this_delta_layer = - i->layer;
737 rv->set_height (tv->view()->child_height ());
739 /* Update show/hidden status as the region view may have come from a hidden track,
740 or have moved to one.
743 rv->get_canvas_group()->hide ();
745 rv->get_canvas_group()->show ();
748 /* Update the DraggingView */
749 i->time_axis_view += delta_time_axis_view;
750 i->layer += this_delta_layer;
753 _editor->mouse_brush_insert_region (rv, pending_region_position);
758 /* Get the y coordinate of the top of the track that this region is now on */
759 tv->canvas_display()->item_to_canvas (x, y);
761 /* And adjust for the layer that it should be on */
762 StreamView* cv = tv->view ();
763 switch (cv->layer_display ()) {
767 y += (cv->layers() - i->layer - 1) * cv->child_height ();
770 y += (cv->layers() - i->layer - 0.5) * 2 * cv->child_height ();
774 /* Now move the region view */
775 rv->move (x_delta, y - rv->get_canvas_group()->position().y);
778 } /* foreach region */
780 _total_x_delta += x_delta;
782 if (x_delta != 0 && !_brushing) {
783 show_verbose_cursor_time (_last_frame_position);
786 _last_pointer_time_axis_view += delta_time_axis_view;
787 _last_pointer_layer += delta_layer;
791 RegionMoveDrag::motion (GdkEvent* event, bool first_move)
793 if (_copy && first_move) {
795 /* duplicate the regionview(s) and region(s) */
797 list<DraggingView> new_regionviews;
799 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
801 RegionView* rv = i->view;
802 AudioRegionView* arv = dynamic_cast<AudioRegionView*>(rv);
803 MidiRegionView* mrv = dynamic_cast<MidiRegionView*>(rv);
805 const boost::shared_ptr<const Region> original = rv->region();
806 boost::shared_ptr<Region> region_copy = RegionFactory::create (original, true);
807 region_copy->set_position (original->position());
811 boost::shared_ptr<AudioRegion> audioregion_copy
812 = boost::dynamic_pointer_cast<AudioRegion>(region_copy);
814 nrv = new AudioRegionView (*arv, audioregion_copy);
816 boost::shared_ptr<MidiRegion> midiregion_copy
817 = boost::dynamic_pointer_cast<MidiRegion>(region_copy);
818 nrv = new MidiRegionView (*mrv, midiregion_copy);
823 nrv->get_canvas_group()->show ();
824 new_regionviews.push_back (DraggingView (nrv, this));
826 /* swap _primary to the copy */
828 if (rv == _primary) {
832 /* ..and deselect the one we copied */
834 rv->set_selected (false);
837 if (!new_regionviews.empty()) {
839 /* reflect the fact that we are dragging the copies */
841 _views = new_regionviews;
843 swap_grab (new_regionviews.front().view->get_canvas_group (), 0, event ? event->motion.time : 0);
847 RegionMotionDrag::motion (event, first_move);
851 RegionMotionDrag::finished (GdkEvent *, bool)
853 for (vector<TimeAxisView*>::iterator i = _time_axis_views.begin(); i != _time_axis_views.end(); ++i) {
858 if ((*i)->view()->layer_display() == Expanded) {
859 (*i)->view()->set_layer_display (Stacked);
865 RegionMoveDrag::finished (GdkEvent* ev, bool movement_occurred)
867 RegionMotionDrag::finished (ev, movement_occurred);
869 if (!movement_occurred) {
874 /* reverse this here so that we have the correct logic to finalize
878 if (Config->get_edit_mode() == Lock) {
879 _x_constrained = !_x_constrained;
882 assert (!_views.empty ());
884 /* We might have hidden region views so that they weren't visible during the drag
885 (when they have been reparented). Now everything can be shown again, as region
886 views are back in their track parent groups.
888 for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
889 i->view->get_canvas_group()->show ();
892 bool const changed_position = (_last_frame_position != _primary->region()->position());
893 bool const changed_tracks = (_time_axis_views[_views.front().time_axis_view] != &_views.front().view->get_time_axis_view());
894 framecnt_t const drag_delta = _primary->region()->position() - _last_frame_position;
914 _editor->maybe_locate_with_edit_preroll (_editor->get_selection().regions.start());
918 RegionMoveDrag::finished_copy (bool const changed_position, bool const /*changed_tracks*/, framecnt_t const drag_delta)
920 RegionSelection new_views;
921 PlaylistSet modified_playlists;
922 list<RegionView*> views_to_delete;
925 /* all changes were made during motion event handlers */
927 for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
931 _editor->commit_reversible_command ();
935 if (_x_constrained) {
936 _editor->begin_reversible_command (Operations::fixed_time_region_copy);
938 _editor->begin_reversible_command (Operations::region_copy);
941 /* insert the regions into their new playlists */
942 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
944 if (i->view->region()->locked() || i->view->region()->video_locked()) {
950 if (changed_position && !_x_constrained) {
951 where = i->view->region()->position() - drag_delta;
953 where = i->view->region()->position();
956 RegionView* new_view = insert_region_into_playlist (
957 i->view->region(), dynamic_cast<RouteTimeAxisView*> (_time_axis_views[i->time_axis_view]), i->layer, where, modified_playlists
964 new_views.push_back (new_view);
966 /* we don't need the copied RegionView any more */
967 views_to_delete.push_back (i->view);
970 /* Delete views that are no longer needed; we can't do this directly in the iteration over _views
971 because when views are deleted they are automagically removed from _views, which messes
974 for (list<RegionView*>::iterator i = views_to_delete.begin(); i != views_to_delete.end(); ++i) {
978 /* If we've created new regions either by copying or moving
979 to a new track, we want to replace the old selection with the new ones
982 if (new_views.size() > 0) {
983 _editor->selection->set (new_views);
986 /* write commands for the accumulated diffs for all our modified playlists */
987 add_stateful_diff_commands_for_playlists (modified_playlists);
989 _editor->commit_reversible_command ();
993 RegionMoveDrag::finished_no_copy (
994 bool const changed_position,
995 bool const changed_tracks,
996 framecnt_t const drag_delta
999 RegionSelection new_views;
1000 PlaylistSet modified_playlists;
1001 PlaylistSet frozen_playlists;
1002 set<RouteTimeAxisView*> views_to_update;
1005 /* all changes were made during motion event handlers */
1006 _editor->commit_reversible_command ();
1010 if (_x_constrained) {
1011 _editor->begin_reversible_command (_("fixed time region drag"));
1013 _editor->begin_reversible_command (Operations::region_drag);
1016 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ) {
1018 RegionView* rv = i->view;
1020 RouteTimeAxisView* const dest_rtv = dynamic_cast<RouteTimeAxisView*> (_time_axis_views[i->time_axis_view]);
1021 double const dest_layer = i->layer;
1023 if (rv->region()->locked() || rv->region()->video_locked()) {
1028 views_to_update.insert (dest_rtv);
1032 if (changed_position && !_x_constrained) {
1033 where = rv->region()->position() - drag_delta;
1035 where = rv->region()->position();
1038 if (changed_tracks) {
1040 /* insert into new playlist */
1042 RegionView* new_view = insert_region_into_playlist (
1043 RegionFactory::create (rv->region (), true), dest_rtv, dest_layer, where, modified_playlists
1046 if (new_view == 0) {
1051 new_views.push_back (new_view);
1053 /* remove from old playlist */
1055 /* the region that used to be in the old playlist is not
1056 moved to the new one - we use a copy of it. as a result,
1057 any existing editor for the region should no longer be
1060 rv->hide_region_editor();
1061 rv->fake_set_opaque (false);
1063 remove_region_from_playlist (rv->region(), i->initial_playlist, modified_playlists);
1067 rv->region()->clear_changes ();
1070 motion on the same track. plonk the previously reparented region
1071 back to its original canvas group (its streamview).
1072 No need to do anything for copies as they are fake regions which will be deleted.
1075 rv->get_canvas_group()->reparent (dest_rtv->view()->canvas_item());
1076 rv->get_canvas_group()->set_y_position (i->initial_y);
1079 /* just change the model */
1081 boost::shared_ptr<Playlist> playlist = dest_rtv->playlist();
1083 if (dest_rtv->view()->layer_display() == Stacked || dest_rtv->view()->layer_display() == Expanded) {
1084 playlist->set_layer (rv->region(), dest_layer);
1087 /* freeze playlist to avoid lots of relayering in the case of a multi-region drag */
1089 pair<PlaylistSet::iterator, bool> r = frozen_playlists.insert (playlist);
1092 playlist->freeze ();
1095 /* this movement may result in a crossfade being modified, so we need to get undo
1096 data from the playlist as well as the region.
1099 r = modified_playlists.insert (playlist);
1101 playlist->clear_changes ();
1104 rv->region()->set_position (where);
1106 _editor->session()->add_command (new StatefulDiffCommand (rv->region()));
1109 if (changed_tracks) {
1111 /* OK, this is where it gets tricky. If the playlist was being used by >1 tracks, and the region
1112 was selected in all of them, then removing it from a playlist will have removed all
1113 trace of it from _views (i.e. there were N regions selected, we removed 1,
1114 but since its the same playlist for N tracks, all N tracks updated themselves, removed the
1115 corresponding regionview, and _views is now empty).
1117 This could have invalidated any and all iterators into _views.
1119 The heuristic we use here is: if the region selection is empty, break out of the loop
1120 here. if the region selection is not empty, then restart the loop because we know that
1121 we must have removed at least the region(view) we've just been working on as well as any
1122 that we processed on previous iterations.
1124 EXCEPT .... if we are doing a copy drag, then _views hasn't been modified and
1125 we can just iterate.
1129 if (_views.empty()) {
1140 /* If we've created new regions either by copying or moving
1141 to a new track, we want to replace the old selection with the new ones
1144 if (new_views.size() > 0) {
1145 _editor->selection->set (new_views);
1148 for (set<boost::shared_ptr<Playlist> >::iterator p = frozen_playlists.begin(); p != frozen_playlists.end(); ++p) {
1152 /* write commands for the accumulated diffs for all our modified playlists */
1153 add_stateful_diff_commands_for_playlists (modified_playlists);
1155 _editor->commit_reversible_command ();
1157 /* We have futzed with the layering of canvas items on our streamviews.
1158 If any region changed layer, this will have resulted in the stream
1159 views being asked to set up their region views, and all will be well.
1160 If not, we might now have badly-ordered region views. Ask the StreamViews
1161 involved to sort themselves out, just in case.
1164 for (set<RouteTimeAxisView*>::iterator i = views_to_update.begin(); i != views_to_update.end(); ++i) {
1165 (*i)->view()->playlist_layered ((*i)->track ());
1169 /** Remove a region from a playlist, clearing the diff history of the playlist first if necessary.
1170 * @param region Region to remove.
1171 * @param playlist playlist To remove from.
1172 * @param modified_playlists The playlist will be added to this if it is not there already; used to ensure
1173 * that clear_changes () is only called once per playlist.
1176 RegionMoveDrag::remove_region_from_playlist (
1177 boost::shared_ptr<Region> region,
1178 boost::shared_ptr<Playlist> playlist,
1179 PlaylistSet& modified_playlists
1182 pair<set<boost::shared_ptr<Playlist> >::iterator, bool> r = modified_playlists.insert (playlist);
1185 playlist->clear_changes ();
1188 playlist->remove_region (region);
1192 /** Insert a region into a playlist, handling the recovery of the resulting new RegionView, and
1193 * clearing the playlist's diff history first if necessary.
1194 * @param region Region to insert.
1195 * @param dest_rtv Destination RouteTimeAxisView.
1196 * @param dest_layer Destination layer.
1197 * @param where Destination position.
1198 * @param modified_playlists The playlist will be added to this if it is not there already; used to ensure
1199 * that clear_changes () is only called once per playlist.
1200 * @return New RegionView, or 0 if no insert was performed.
1203 RegionMoveDrag::insert_region_into_playlist (
1204 boost::shared_ptr<Region> region,
1205 RouteTimeAxisView* dest_rtv,
1208 PlaylistSet& modified_playlists
1211 boost::shared_ptr<Playlist> dest_playlist = dest_rtv->playlist ();
1212 if (!dest_playlist) {
1216 /* arrange to collect the new region view that will be created as a result of our playlist insertion */
1217 _new_region_view = 0;
1218 sigc::connection c = dest_rtv->view()->RegionViewAdded.connect (sigc::mem_fun (*this, &RegionMoveDrag::collect_new_region_view));
1220 /* clear history for the playlist we are about to insert to, provided we haven't already done so */
1221 pair<PlaylistSet::iterator, bool> r = modified_playlists.insert (dest_playlist);
1223 dest_playlist->clear_changes ();
1226 dest_playlist->add_region (region, where);
1228 if (dest_rtv->view()->layer_display() == Stacked || dest_rtv->view()->layer_display() == Expanded) {
1229 dest_playlist->set_layer (region, dest_layer);
1234 assert (_new_region_view);
1236 return _new_region_view;
1240 RegionMoveDrag::collect_new_region_view (RegionView* rv)
1242 _new_region_view = rv;
1246 RegionMoveDrag::add_stateful_diff_commands_for_playlists (PlaylistSet const & playlists)
1248 for (PlaylistSet::const_iterator i = playlists.begin(); i != playlists.end(); ++i) {
1249 StatefulDiffCommand* c = new StatefulDiffCommand (*i);
1251 _editor->session()->add_command (c);
1260 RegionMoveDrag::aborted (bool movement_occurred)
1264 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
1271 RegionMotionDrag::aborted (movement_occurred);
1276 RegionMotionDrag::aborted (bool)
1278 for (vector<TimeAxisView*>::iterator i = _time_axis_views.begin(); i != _time_axis_views.end(); ++i) {
1279 if ((*i)->view()->layer_display() == Expanded) {
1280 (*i)->view()->set_layer_display (Stacked);
1284 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
1285 RegionView* rv = i->view;
1286 TimeAxisView* tv = &(rv->get_time_axis_view ());
1287 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (tv);
1289 rv->get_canvas_group()->reparent (rtv->view()->canvas_item());
1290 rv->get_canvas_group()->set_y_position (0);
1292 rv->fake_set_opaque (false);
1293 rv->move (-_total_x_delta, 0);
1294 rv->set_height (rtv->view()->child_height ());
1298 /** @param b true to brush, otherwise false.
1299 * @param c true to make copies of the regions being moved, otherwise false.
1301 RegionMoveDrag::RegionMoveDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, list<RegionView*> const & v, bool b, bool c)
1302 : RegionMotionDrag (e, i, p, v, b),
1305 DEBUG_TRACE (DEBUG::Drags, "New RegionMoveDrag\n");
1308 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (&_primary->get_time_axis_view ());
1309 if (rtv && rtv->is_track()) {
1310 speed = rtv->track()->speed ();
1313 _last_frame_position = static_cast<framepos_t> (_primary->region()->position() / speed);
1317 RegionMoveDrag::setup_pointer_frame_offset ()
1319 _pointer_frame_offset = raw_grab_frame() - _last_frame_position;
1322 RegionInsertDrag::RegionInsertDrag (Editor* e, boost::shared_ptr<Region> r, RouteTimeAxisView* v, framepos_t pos)
1323 : RegionMotionDrag (e, 0, 0, list<RegionView*> (), false)
1325 DEBUG_TRACE (DEBUG::Drags, "New RegionInsertDrag\n");
1327 assert ((boost::dynamic_pointer_cast<AudioRegion> (r) && dynamic_cast<AudioTimeAxisView*> (v)) ||
1328 (boost::dynamic_pointer_cast<MidiRegion> (r) && dynamic_cast<MidiTimeAxisView*> (v)));
1330 _primary = v->view()->create_region_view (r, false, false);
1332 _primary->get_canvas_group()->show ();
1333 _primary->set_position (pos, 0);
1334 _views.push_back (DraggingView (_primary, this));
1336 _last_frame_position = pos;
1338 _item = _primary->get_canvas_group ();
1342 RegionInsertDrag::finished (GdkEvent *, bool)
1344 RouteTimeAxisView* dest_rtv = dynamic_cast<RouteTimeAxisView*> (_time_axis_views[_views.front().time_axis_view]);
1346 _primary->get_canvas_group()->reparent (dest_rtv->view()->canvas_item());
1347 _primary->get_canvas_group()->set_y_position (0);
1349 boost::shared_ptr<Playlist> playlist = dest_rtv->playlist();
1351 _editor->begin_reversible_command (Operations::insert_region);
1352 playlist->clear_changes ();
1353 playlist->add_region (_primary->region (), _last_frame_position);
1354 _editor->session()->add_command (new StatefulDiffCommand (playlist));
1355 _editor->commit_reversible_command ();
1363 RegionInsertDrag::aborted (bool)
1370 RegionSpliceDrag::RegionSpliceDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, list<RegionView*> const & v)
1371 : RegionMoveDrag (e, i, p, v, false, false)
1373 DEBUG_TRACE (DEBUG::Drags, "New RegionSpliceDrag\n");
1376 struct RegionSelectionByPosition {
1377 bool operator() (RegionView*a, RegionView* b) {
1378 return a->region()->position () < b->region()->position();
1383 RegionSpliceDrag::motion (GdkEvent* event, bool)
1385 /* Which trackview is this ? */
1387 pair<TimeAxisView*, double> const tvp = _editor->trackview_by_y_position (_drags->current_pointer_y ());
1388 RouteTimeAxisView* tv = dynamic_cast<RouteTimeAxisView*> (tvp.first);
1390 /* The region motion is only processed if the pointer is over
1394 if (!tv || !tv->is_track()) {
1395 /* To make sure we hide the verbose canvas cursor when the mouse is
1396 not held over and audiotrack.
1398 _editor->verbose_cursor()->hide ();
1404 if ((_drags->current_pointer_x() - last_pointer_x()) > 0) {
1410 RegionSelection copy (_editor->selection->regions);
1412 RegionSelectionByPosition cmp;
1415 framepos_t const pf = adjusted_current_frame (event);
1417 for (RegionSelection::iterator i = copy.begin(); i != copy.end(); ++i) {
1419 RouteTimeAxisView* atv = dynamic_cast<RouteTimeAxisView*> (&(*i)->get_time_axis_view());
1425 boost::shared_ptr<Playlist> playlist;
1427 if ((playlist = atv->playlist()) == 0) {
1431 if (!playlist->region_is_shuffle_constrained ((*i)->region())) {
1436 if (pf < (*i)->region()->last_frame() + 1) {
1440 if (pf > (*i)->region()->first_frame()) {
1446 playlist->shuffle ((*i)->region(), dir);
1451 RegionSpliceDrag::finished (GdkEvent* event, bool movement_occurred)
1453 RegionMoveDrag::finished (event, movement_occurred);
1457 RegionSpliceDrag::aborted (bool)
1462 RegionCreateDrag::RegionCreateDrag (Editor* e, ArdourCanvas::Item* i, TimeAxisView* v)
1464 _view (dynamic_cast<MidiTimeAxisView*> (v))
1466 DEBUG_TRACE (DEBUG::Drags, "New RegionCreateDrag\n");
1472 RegionCreateDrag::motion (GdkEvent* event, bool first_move)
1475 _region = add_midi_region (_view);
1476 _view->playlist()->freeze ();
1479 framepos_t const f = adjusted_current_frame (event);
1480 if (f < grab_frame()) {
1481 _region->set_position (f);
1484 /* Don't use a zero-length region, and subtract 1 frame from the snapped length
1485 so that if this region is duplicated, its duplicate starts on
1486 a snap point rather than 1 frame after a snap point. Otherwise things get
1487 a bit confusing as if a region starts 1 frame after a snap point, one cannot
1488 place snapped notes at the start of the region.
1491 framecnt_t const len = (framecnt_t) fabs (f - grab_frame () - 1);
1492 _region->set_length (len < 1 ? 1 : len);
1498 RegionCreateDrag::finished (GdkEvent*, bool movement_occurred)
1500 if (!movement_occurred) {
1501 add_midi_region (_view);
1503 _view->playlist()->thaw ();
1508 RegionCreateDrag::aborted (bool)
1511 _view->playlist()->thaw ();
1517 NoteResizeDrag::NoteResizeDrag (Editor* e, ArdourCanvas::Item* i)
1521 DEBUG_TRACE (DEBUG::Drags, "New NoteResizeDrag\n");
1525 NoteResizeDrag::start_grab (GdkEvent* event, Gdk::Cursor* /*ignored*/)
1527 Gdk::Cursor* cursor;
1528 NoteBase* cnote = reinterpret_cast<NoteBase*> (_item->get_data ("notebase"));
1530 float x_fraction = cnote->mouse_x_fraction ();
1532 if (x_fraction > 0.0 && x_fraction < 0.25) {
1533 cursor = _editor->cursors()->left_side_trim;
1535 cursor = _editor->cursors()->right_side_trim;
1538 Drag::start_grab (event, cursor);
1540 region = &cnote->region_view();
1542 double const region_start = region->get_position_pixels();
1543 double const middle_point = region_start + cnote->x0() + (cnote->x1() - cnote->x0()) / 2.0L;
1545 if (grab_x() <= middle_point) {
1546 cursor = _editor->cursors()->left_side_trim;
1549 cursor = _editor->cursors()->right_side_trim;
1555 if (event->motion.state & Keyboard::PrimaryModifier) {
1561 MidiRegionSelection& ms (_editor->get_selection().midi_regions);
1563 if (ms.size() > 1) {
1564 /* has to be relative, may make no sense otherwise */
1568 /* select this note; if it is already selected, preserve the existing selection,
1569 otherwise make this note the only one selected.
1571 region->note_selected (cnote, cnote->selected ());
1573 for (MidiRegionSelection::iterator r = ms.begin(); r != ms.end(); ) {
1574 MidiRegionSelection::iterator next;
1577 (*r)->begin_resizing (at_front);
1583 NoteResizeDrag::motion (GdkEvent* /*event*/, bool /*first_move*/)
1585 MidiRegionSelection& ms (_editor->get_selection().midi_regions);
1586 for (MidiRegionSelection::iterator r = ms.begin(); r != ms.end(); ++r) {
1587 NoteBase* nb = reinterpret_cast<NoteBase*> (_item->get_data ("notebase"));
1589 (*r)->update_resizing (nb, at_front, _drags->current_pointer_x() - grab_x(), relative);
1594 NoteResizeDrag::finished (GdkEvent*, bool /*movement_occurred*/)
1596 MidiRegionSelection& ms (_editor->get_selection().midi_regions);
1597 for (MidiRegionSelection::iterator r = ms.begin(); r != ms.end(); ++r) {
1598 NoteBase* nb = reinterpret_cast<NoteBase*> (_item->get_data ("notebase"));
1600 (*r)->commit_resizing (nb, at_front, _drags->current_pointer_x() - grab_x(), relative);
1605 NoteResizeDrag::aborted (bool)
1607 MidiRegionSelection& ms (_editor->get_selection().midi_regions);
1608 for (MidiRegionSelection::iterator r = ms.begin(); r != ms.end(); ++r) {
1609 (*r)->abort_resizing ();
1613 AVDraggingView::AVDraggingView (RegionView* v)
1616 initial_position = v->region()->position ();
1619 VideoTimeLineDrag::VideoTimeLineDrag (Editor* e, ArdourCanvas::Item* i)
1622 DEBUG_TRACE (DEBUG::Drags, "New VideoTimeLineDrag\n");
1625 TrackViewList empty;
1627 _editor->get_regions_after(rs, (framepos_t) 0, empty);
1628 std::list<RegionView*> views = rs.by_layer();
1630 for (list<RegionView*>::iterator i = views.begin(); i != views.end(); ++i) {
1631 RegionView* rv = (*i);
1632 if (!rv->region()->video_locked()) {
1635 _views.push_back (AVDraggingView (rv));
1640 VideoTimeLineDrag::start_grab (GdkEvent* event, Gdk::Cursor*)
1642 Drag::start_grab (event);
1643 if (_editor->session() == 0) {
1647 _startdrag_video_offset=ARDOUR_UI::instance()->video_timeline->get_offset();
1648 _max_backwards_drag = (
1649 ARDOUR_UI::instance()->video_timeline->get_duration()
1650 + ARDOUR_UI::instance()->video_timeline->get_offset()
1651 - ceil(ARDOUR_UI::instance()->video_timeline->get_apv())
1654 for (list<AVDraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
1655 if (i->initial_position < _max_backwards_drag || _max_backwards_drag < 0) {
1656 _max_backwards_drag = ARDOUR_UI::instance()->video_timeline->quantify_frames_to_apv (i->initial_position);
1659 DEBUG_TRACE (DEBUG::Drags, string_compose("VideoTimeLineDrag: max backwards-drag: %1\n", _max_backwards_drag));
1662 Timecode::Time timecode;
1663 _editor->session()->sample_to_timecode(abs(_startdrag_video_offset), timecode, true /* use_offset */, false /* use_subframes */ );
1664 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);
1665 _editor->verbose_cursor()->set(buf, event->button.x + 10, event->button.y + 10);
1666 _editor->verbose_cursor()->show ();
1670 VideoTimeLineDrag::motion (GdkEvent* event, bool first_move)
1672 if (_editor->session() == 0) {
1675 if (ARDOUR_UI::instance()->video_timeline->is_offset_locked()) {
1679 framecnt_t dt = adjusted_current_frame (event) - raw_grab_frame() + _pointer_frame_offset;
1680 dt = ARDOUR_UI::instance()->video_timeline->quantify_frames_to_apv(dt);
1682 if (_max_backwards_drag >= 0 && dt <= - _max_backwards_drag) {
1683 dt = - _max_backwards_drag;
1686 ARDOUR_UI::instance()->video_timeline->set_offset(_startdrag_video_offset+dt);
1687 ARDOUR_UI::instance()->flush_videotimeline_cache(true);
1689 for (list<AVDraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
1690 RegionView* rv = i->view;
1691 DEBUG_TRACE (DEBUG::Drags, string_compose("SHIFT REGION at %1 by %2\n", i->initial_position, dt));
1694 rv->fake_set_opaque (true);
1695 rv->region()->clear_changes ();
1696 rv->region()->suspend_property_changes();
1698 rv->region()->set_position(i->initial_position + dt);
1699 rv->region_changed(ARDOUR::Properties::position);
1702 const framepos_t offset = ARDOUR_UI::instance()->video_timeline->get_offset();
1703 Timecode::Time timecode;
1704 Timecode::Time timediff;
1706 _editor->session()->sample_to_timecode(abs(offset), timecode, true /* use_offset */, false /* use_subframes */ );
1707 _editor->session()->sample_to_timecode(abs(dt), timediff, false /* use_offset */, false /* use_subframes */ );
1708 snprintf (buf, sizeof (buf),
1709 "%s\n%c%02" PRId32 ":%02" PRId32 ":%02" PRId32 ":%02" PRId32
1710 "\n%s\n%c%02" PRId32 ":%02" PRId32 ":%02" PRId32 ":%02" PRId32
1711 , _("Video Start:"),
1712 (offset<0?'-':' '), timecode.hours, timecode.minutes, timecode.seconds, timecode.frames
1714 (dt<0?'-':' '), timediff.hours, timediff.minutes, timediff.seconds, timediff.frames
1716 _editor->verbose_cursor()->set(buf, event->button.x + 10, event->button.y + 10);
1717 _editor->verbose_cursor()->show ();
1721 VideoTimeLineDrag::finished (GdkEvent * /*event*/, bool movement_occurred)
1723 if (ARDOUR_UI::instance()->video_timeline->is_offset_locked()) {
1727 if (!movement_occurred || ! _editor->session()) {
1731 ARDOUR_UI::instance()->flush_videotimeline_cache(true);
1733 _editor->begin_reversible_command (_("Move Video"));
1735 XMLNode &before = ARDOUR_UI::instance()->video_timeline->get_state();
1736 ARDOUR_UI::instance()->video_timeline->save_undo();
1737 XMLNode &after = ARDOUR_UI::instance()->video_timeline->get_state();
1738 _editor->session()->add_command(new MementoCommand<VideoTimeLine>(*(ARDOUR_UI::instance()->video_timeline), &before, &after));
1740 for (list<AVDraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
1741 i->view->drag_end();
1742 i->view->fake_set_opaque (false);
1743 i->view->region()->resume_property_changes ();
1745 _editor->session()->add_command (new StatefulDiffCommand (i->view->region()));
1748 _editor->session()->maybe_update_session_range(
1749 std::max(ARDOUR_UI::instance()->video_timeline->get_offset(), (ARDOUR::frameoffset_t) 0),
1750 std::max(ARDOUR_UI::instance()->video_timeline->get_offset() + ARDOUR_UI::instance()->video_timeline->get_duration(), (ARDOUR::frameoffset_t) 0)
1754 _editor->commit_reversible_command ();
1758 VideoTimeLineDrag::aborted (bool)
1760 if (ARDOUR_UI::instance()->video_timeline->is_offset_locked()) {
1763 ARDOUR_UI::instance()->video_timeline->set_offset(_startdrag_video_offset);
1764 ARDOUR_UI::instance()->flush_videotimeline_cache(true);
1766 for (list<AVDraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
1767 i->view->region()->resume_property_changes ();
1768 i->view->region()->set_position(i->initial_position);
1772 TrimDrag::TrimDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, list<RegionView*> const & v, bool preserve_fade_anchor)
1773 : RegionDrag (e, i, p, v)
1775 DEBUG_TRACE (DEBUG::Drags, "New TrimDrag\n");
1776 _preserve_fade_anchor = preserve_fade_anchor;
1780 TrimDrag::start_grab (GdkEvent* event, Gdk::Cursor*)
1783 TimeAxisView* tvp = &_primary->get_time_axis_view ();
1784 RouteTimeAxisView* tv = dynamic_cast<RouteTimeAxisView*>(tvp);
1786 if (tv && tv->is_track()) {
1787 speed = tv->track()->speed();
1790 framepos_t const region_start = (framepos_t) (_primary->region()->position() / speed);
1791 framepos_t const region_end = (framepos_t) (_primary->region()->last_frame() / speed);
1792 framecnt_t const region_length = (framecnt_t) (_primary->region()->length() / speed);
1794 framepos_t const pf = adjusted_current_frame (event);
1796 if (Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) {
1797 /* Move the contents of the region around without changing the region bounds */
1798 _operation = ContentsTrim;
1799 Drag::start_grab (event, _editor->cursors()->trimmer);
1801 /* These will get overridden for a point trim.*/
1802 if (pf < (region_start + region_length/2)) {
1803 /* closer to front */
1804 _operation = StartTrim;
1805 Drag::start_grab (event, _editor->cursors()->left_side_trim);
1808 _operation = EndTrim;
1809 Drag::start_grab (event, _editor->cursors()->right_side_trim);
1813 switch (_operation) {
1815 show_verbose_cursor_time (region_start);
1816 for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
1817 i->view->trim_front_starting ();
1821 show_verbose_cursor_time (region_end);
1824 show_verbose_cursor_time (pf);
1828 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
1829 i->view->region()->suspend_property_changes ();
1834 TrimDrag::motion (GdkEvent* event, bool first_move)
1836 RegionView* rv = _primary;
1839 TimeAxisView* tvp = &_primary->get_time_axis_view ();
1840 RouteTimeAxisView* tv = dynamic_cast<RouteTimeAxisView*>(tvp);
1841 pair<set<boost::shared_ptr<Playlist> >::iterator,bool> insert_result;
1842 frameoffset_t frame_delta = 0;
1844 if (tv && tv->is_track()) {
1845 speed = tv->track()->speed();
1848 framecnt_t const dt = adjusted_current_frame (event) - raw_grab_frame () + _pointer_frame_offset;
1854 switch (_operation) {
1856 trim_type = "Region start trim";
1859 trim_type = "Region end trim";
1862 trim_type = "Region content trim";
1866 _editor->begin_reversible_command (trim_type);
1868 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
1869 RegionView* rv = i->view;
1870 rv->fake_set_opaque (false);
1871 rv->enable_display (false);
1872 rv->region()->playlist()->clear_owned_changes ();
1874 AudioRegionView* const arv = dynamic_cast<AudioRegionView*> (rv);
1877 arv->temporarily_hide_envelope ();
1881 boost::shared_ptr<Playlist> pl = rv->region()->playlist();
1882 insert_result = _editor->motion_frozen_playlists.insert (pl);
1884 if (insert_result.second) {
1890 bool non_overlap_trim = false;
1892 if (event && Keyboard::modifier_state_equals (event->button.state, Keyboard::TertiaryModifier)) {
1893 non_overlap_trim = true;
1896 switch (_operation) {
1898 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
1899 bool changed = i->view->trim_front (i->initial_position + dt, non_overlap_trim);
1900 if (changed && _preserve_fade_anchor) {
1901 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (i->view);
1906 boost::shared_ptr<AudioRegion> ar (arv->audio_region());
1907 distance = _drags->current_pointer_x() - grab_x();
1908 len = ar->fade_in()->back()->when;
1909 new_length = len - _editor->pixel_to_sample (distance);
1910 new_length = ar->verify_xfade_bounds (new_length, true /*START*/ );
1911 arv->reset_fade_in_shape_width (ar, new_length); //the grey shape
1918 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
1919 bool changed = i->view->trim_end (i->initial_end + dt, non_overlap_trim);
1920 if (changed && _preserve_fade_anchor) {
1921 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (i->view);
1926 boost::shared_ptr<AudioRegion> ar (arv->audio_region());
1927 distance = grab_x() - _drags->current_pointer_x();
1928 len = ar->fade_out()->back()->when;
1929 new_length = len - _editor->pixel_to_sample (distance);
1930 new_length = ar->verify_xfade_bounds (new_length, false /*END*/ );
1931 arv->reset_fade_out_shape_width (ar, new_length); //the grey shape
1939 frame_delta = (adjusted_current_frame(event) - last_pointer_frame());
1940 // frame_delta = (last_pointer_frame() - adjusted_current_frame(event));
1942 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
1943 i->view->move_contents (frame_delta);
1949 switch (_operation) {
1951 show_verbose_cursor_time ((framepos_t) (rv->region()->position() / speed));
1954 show_verbose_cursor_time ((framepos_t) (rv->region()->last_frame() / speed));
1957 // show_verbose_cursor_time (frame_delta);
1964 TrimDrag::finished (GdkEvent* event, bool movement_occurred)
1966 if (movement_occurred) {
1967 motion (event, false);
1969 if (_operation == StartTrim) {
1970 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
1972 /* This must happen before the region's StatefulDiffCommand is created, as it may
1973 `correct' (ahem) the region's _start from being negative to being zero. It
1974 needs to be zero in the undo record.
1976 i->view->trim_front_ending ();
1978 if (_preserve_fade_anchor) {
1979 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (i->view);
1984 boost::shared_ptr<AudioRegion> ar (arv->audio_region());
1985 distance = _drags->current_pointer_x() - grab_x();
1986 len = ar->fade_in()->back()->when;
1987 new_length = len - _editor->pixel_to_sample (distance);
1988 new_length = ar->verify_xfade_bounds (new_length, true /*START*/ );
1989 ar->set_fade_in_length(new_length);
1993 } else if (_operation == EndTrim) {
1994 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
1995 if (_preserve_fade_anchor) {
1996 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (i->view);
2001 boost::shared_ptr<AudioRegion> ar (arv->audio_region());
2002 distance = _drags->current_pointer_x() - grab_x();
2003 len = ar->fade_out()->back()->when;
2004 new_length = len - _editor->pixel_to_sample (distance);
2005 new_length = ar->verify_xfade_bounds (new_length, false /*END*/ );
2006 ar->set_fade_out_length(new_length);
2012 if (!_views.empty()) {
2013 if (_operation == StartTrim) {
2014 _editor->maybe_locate_with_edit_preroll(
2015 _views.begin()->view->region()->position());
2017 if (_operation == EndTrim) {
2018 _editor->maybe_locate_with_edit_preroll(
2019 _views.begin()->view->region()->position() +
2020 _views.begin()->view->region()->length());
2024 if (!_editor->selection->selected (_primary)) {
2025 _primary->thaw_after_trim ();
2028 set<boost::shared_ptr<Playlist> > diffed_playlists;
2030 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
2031 i->view->thaw_after_trim ();
2032 i->view->enable_display (true);
2033 i->view->fake_set_opaque (true);
2035 /* Trimming one region may affect others on the playlist, so we need
2036 to get undo Commands from the whole playlist rather than just the
2037 region. Use diffed_playlists to make sure we don't diff a given
2038 playlist more than once.
2040 boost::shared_ptr<Playlist> p = i->view->region()->playlist ();
2041 if (diffed_playlists.find (p) == diffed_playlists.end()) {
2042 vector<Command*> cmds;
2044 _editor->session()->add_commands (cmds);
2045 diffed_playlists.insert (p);
2050 for (set<boost::shared_ptr<Playlist> >::iterator p = _editor->motion_frozen_playlists.begin(); p != _editor->motion_frozen_playlists.end(); ++p) {
2054 _editor->motion_frozen_playlists.clear ();
2055 _editor->commit_reversible_command();
2058 /* no mouse movement */
2059 _editor->point_trim (event, adjusted_current_frame (event));
2062 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
2063 if (_operation == StartTrim) {
2064 i->view->trim_front_ending ();
2067 i->view->region()->resume_property_changes ();
2072 TrimDrag::aborted (bool movement_occurred)
2074 /* Our motion method is changing model state, so use the Undo system
2075 to cancel. Perhaps not ideal, as this will leave an Undo point
2076 behind which may be slightly odd from the user's point of view.
2081 if (movement_occurred) {
2085 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
2086 i->view->region()->resume_property_changes ();
2091 TrimDrag::setup_pointer_frame_offset ()
2093 list<DraggingView>::iterator i = _views.begin ();
2094 while (i != _views.end() && i->view != _primary) {
2098 if (i == _views.end()) {
2102 switch (_operation) {
2104 _pointer_frame_offset = raw_grab_frame() - i->initial_position;
2107 _pointer_frame_offset = raw_grab_frame() - i->initial_end;
2114 MeterMarkerDrag::MeterMarkerDrag (Editor* e, ArdourCanvas::Item* i, bool c)
2118 DEBUG_TRACE (DEBUG::Drags, "New MeterMarkerDrag\n");
2119 _marker = reinterpret_cast<MeterMarker*> (_item->get_data ("marker"));
2124 MeterMarkerDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
2126 Drag::start_grab (event, cursor);
2127 show_verbose_cursor_time (adjusted_current_frame(event));
2131 MeterMarkerDrag::setup_pointer_frame_offset ()
2133 _pointer_frame_offset = raw_grab_frame() - _marker->meter().frame();
2137 MeterMarkerDrag::motion (GdkEvent* event, bool first_move)
2141 // create a dummy marker for visual representation of moving the
2142 // section, because whether its a copy or not, we're going to
2143 // leave or lose the original marker (leave if its a copy; lose if its
2144 // not, because we'll remove it from the map).
2146 MeterSection section (_marker->meter());
2148 if (!section.movable()) {
2153 snprintf (name, sizeof(name), "%g/%g", _marker->meter().divisions_per_bar(), _marker->meter().note_divisor ());
2155 _marker = new MeterMarker (
2157 *_editor->meter_group,
2158 ARDOUR_UI::config()->get_canvasvar_MeterMarker(),
2160 *new MeterSection (_marker->meter())
2163 /* use the new marker for the grab */
2164 swap_grab (&_marker->the_item(), 0, GDK_CURRENT_TIME);
2167 TempoMap& map (_editor->session()->tempo_map());
2168 /* get current state */
2169 before_state = &map.get_state();
2170 /* remove the section while we drag it */
2171 map.remove_meter (section, true);
2175 framepos_t const pf = adjusted_current_frame (event);
2176 _marker->set_position (pf);
2177 show_verbose_cursor_time (pf);
2181 MeterMarkerDrag::finished (GdkEvent* event, bool movement_occurred)
2183 if (!movement_occurred) {
2187 motion (event, false);
2189 Timecode::BBT_Time when;
2191 TempoMap& map (_editor->session()->tempo_map());
2192 map.bbt_time (last_pointer_frame(), when);
2194 if (_copy == true) {
2195 _editor->begin_reversible_command (_("copy meter mark"));
2196 XMLNode &before = map.get_state();
2197 map.add_meter (_marker->meter(), when);
2198 XMLNode &after = map.get_state();
2199 _editor->session()->add_command(new MementoCommand<TempoMap>(map, &before, &after));
2200 _editor->commit_reversible_command ();
2203 _editor->begin_reversible_command (_("move meter mark"));
2205 /* we removed it before, so add it back now */
2207 map.add_meter (_marker->meter(), when);
2208 XMLNode &after = map.get_state();
2209 _editor->session()->add_command(new MementoCommand<TempoMap>(map, before_state, &after));
2210 _editor->commit_reversible_command ();
2213 // delete the dummy marker we used for visual representation while moving.
2214 // a new visual marker will show up automatically.
2219 MeterMarkerDrag::aborted (bool moved)
2221 _marker->set_position (_marker->meter().frame ());
2224 TempoMap& map (_editor->session()->tempo_map());
2225 /* we removed it before, so add it back now */
2226 map.add_meter (_marker->meter(), _marker->meter().frame());
2227 // delete the dummy marker we used for visual representation while moving.
2228 // a new visual marker will show up automatically.
2233 TempoMarkerDrag::TempoMarkerDrag (Editor* e, ArdourCanvas::Item* i, bool c)
2237 DEBUG_TRACE (DEBUG::Drags, "New TempoMarkerDrag\n");
2239 _marker = reinterpret_cast<TempoMarker*> (_item->get_data ("marker"));
2244 TempoMarkerDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
2246 Drag::start_grab (event, cursor);
2247 show_verbose_cursor_time (adjusted_current_frame (event));
2251 TempoMarkerDrag::setup_pointer_frame_offset ()
2253 _pointer_frame_offset = raw_grab_frame() - _marker->tempo().frame();
2257 TempoMarkerDrag::motion (GdkEvent* event, bool first_move)
2261 // create a dummy marker for visual representation of moving the
2262 // section, because whether its a copy or not, we're going to
2263 // leave or lose the original marker (leave if its a copy; lose if its
2264 // not, because we'll remove it from the map).
2266 // create a dummy marker for visual representation of moving the copy.
2267 // The actual copying is not done before we reach the finish callback.
2270 snprintf (name, sizeof (name), "%.2f", _marker->tempo().beats_per_minute());
2272 TempoSection section (_marker->tempo());
2274 _marker = new TempoMarker (
2276 *_editor->tempo_group,
2277 ARDOUR_UI::config()->get_canvasvar_TempoMarker(),
2279 *new TempoSection (_marker->tempo())
2282 /* use the new marker for the grab */
2283 swap_grab (&_marker->the_item(), 0, GDK_CURRENT_TIME);
2286 TempoMap& map (_editor->session()->tempo_map());
2287 /* get current state */
2288 before_state = &map.get_state();
2289 /* remove the section while we drag it */
2290 map.remove_tempo (section, true);
2294 framepos_t const pf = adjusted_current_frame (event);
2295 _marker->set_position (pf);
2296 show_verbose_cursor_time (pf);
2300 TempoMarkerDrag::finished (GdkEvent* event, bool movement_occurred)
2302 if (!movement_occurred) {
2306 motion (event, false);
2308 TempoMap& map (_editor->session()->tempo_map());
2309 framepos_t beat_time = map.round_to_beat (last_pointer_frame(), 0);
2310 Timecode::BBT_Time when;
2312 map.bbt_time (beat_time, when);
2314 if (_copy == true) {
2315 _editor->begin_reversible_command (_("copy tempo mark"));
2316 XMLNode &before = map.get_state();
2317 map.add_tempo (_marker->tempo(), when);
2318 XMLNode &after = map.get_state();
2319 _editor->session()->add_command (new MementoCommand<TempoMap>(map, &before, &after));
2320 _editor->commit_reversible_command ();
2323 _editor->begin_reversible_command (_("move tempo mark"));
2324 /* we removed it before, so add it back now */
2325 map.add_tempo (_marker->tempo(), when);
2326 XMLNode &after = map.get_state();
2327 _editor->session()->add_command (new MementoCommand<TempoMap>(map, before_state, &after));
2328 _editor->commit_reversible_command ();
2331 // delete the dummy marker we used for visual representation while moving.
2332 // a new visual marker will show up automatically.
2337 TempoMarkerDrag::aborted (bool moved)
2339 _marker->set_position (_marker->tempo().frame());
2341 TempoMap& map (_editor->session()->tempo_map());
2342 /* we removed it before, so add it back now */
2343 map.add_tempo (_marker->tempo(), _marker->tempo().start());
2344 // delete the dummy marker we used for visual representation while moving.
2345 // a new visual marker will show up automatically.
2350 CursorDrag::CursorDrag (Editor* e, EditorCursor& c, bool s)
2351 : Drag (e, &c.time_bar_canvas_item())
2355 DEBUG_TRACE (DEBUG::Drags, "New CursorDrag\n");
2358 /** Do all the things we do when dragging the playhead to make it look as though
2359 * we have located, without actually doing the locate (because that would cause
2360 * the diskstream buffers to be refilled, which is too slow).
2363 CursorDrag::fake_locate (framepos_t t)
2365 _editor->playhead_cursor->set_position (t);
2367 Session* s = _editor->session ();
2368 if (s->timecode_transmission_suspended ()) {
2369 framepos_t const f = _editor->playhead_cursor->current_frame ();
2370 s->send_mmc_locate (f);
2371 s->send_full_time_code (f);
2374 show_verbose_cursor_time (t);
2375 _editor->UpdateAllTransportClocks (t);
2379 CursorDrag::start_grab (GdkEvent* event, Gdk::Cursor* c)
2381 Drag::start_grab (event, c);
2383 _grab_zoom = _editor->samples_per_pixel;
2385 framepos_t where = _editor->canvas_event_frame (event, 0, 0);
2387 _editor->snap_to_with_modifier (where, event);
2389 _editor->_dragging_playhead = true;
2391 Session* s = _editor->session ();
2393 /* grab the track canvas item as well */
2395 _cursor.track_canvas_item().grab();
2398 if (_was_rolling && _stop) {
2402 if (s->is_auditioning()) {
2403 s->cancel_audition ();
2407 if (AudioEngine::instance()->connected()) {
2409 /* do this only if we're the engine is connected
2410 * because otherwise this request will never be
2411 * serviced and we'll busy wait forever. likewise,
2412 * notice if we are disconnected while waiting for the
2413 * request to be serviced.
2416 s->request_suspend_timecode_transmission ();
2417 while (AudioEngine::instance()->connected() && !s->timecode_transmission_suspended ()) {
2418 /* twiddle our thumbs */
2423 fake_locate (where);
2427 CursorDrag::motion (GdkEvent* event, bool)
2429 framepos_t const adjusted_frame = adjusted_current_frame (event);
2430 if (adjusted_frame != last_pointer_frame()) {
2431 fake_locate (adjusted_frame);
2436 CursorDrag::finished (GdkEvent* event, bool movement_occurred)
2438 _editor->_dragging_playhead = false;
2440 _cursor.track_canvas_item().ungrab();
2442 if (!movement_occurred && _stop) {
2446 motion (event, false);
2448 Session* s = _editor->session ();
2450 s->request_locate (_editor->playhead_cursor->current_frame (), _was_rolling);
2451 _editor->_pending_locate_request = true;
2452 s->request_resume_timecode_transmission ();
2457 CursorDrag::aborted (bool)
2459 _cursor.track_canvas_item().ungrab();
2461 if (_editor->_dragging_playhead) {
2462 _editor->session()->request_resume_timecode_transmission ();
2463 _editor->_dragging_playhead = false;
2466 _editor->playhead_cursor->set_position (adjusted_frame (grab_frame (), 0, false));
2469 FadeInDrag::FadeInDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, list<RegionView*> const & v)
2470 : RegionDrag (e, i, p, v)
2472 DEBUG_TRACE (DEBUG::Drags, "New FadeInDrag\n");
2476 FadeInDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
2478 Drag::start_grab (event, cursor);
2480 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (_primary);
2481 boost::shared_ptr<AudioRegion> const r = arv->audio_region ();
2483 show_verbose_cursor_duration (r->position(), r->position() + r->fade_in()->back()->when, 32);
2487 FadeInDrag::setup_pointer_frame_offset ()
2489 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (_primary);
2490 boost::shared_ptr<AudioRegion> const r = arv->audio_region ();
2491 _pointer_frame_offset = raw_grab_frame() - ((framecnt_t) r->fade_in()->back()->when + r->position());
2495 FadeInDrag::motion (GdkEvent* event, bool)
2497 framecnt_t fade_length;
2499 framepos_t const pos = adjusted_current_frame (event);
2501 boost::shared_ptr<Region> region = _primary->region ();
2503 if (pos < (region->position() + 64)) {
2504 fade_length = 64; // this should be a minimum defined somewhere
2505 } else if (pos > region->last_frame()) {
2506 fade_length = region->length();
2508 fade_length = pos - region->position();
2511 for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
2513 AudioRegionView* tmp = dynamic_cast<AudioRegionView*> (i->view);
2519 tmp->reset_fade_in_shape_width (tmp->audio_region(), fade_length);
2522 show_verbose_cursor_duration (region->position(), region->position() + fade_length, 32);
2526 FadeInDrag::finished (GdkEvent* event, bool movement_occurred)
2528 if (!movement_occurred) {
2532 framecnt_t fade_length;
2534 framepos_t const pos = adjusted_current_frame (event);
2536 boost::shared_ptr<Region> region = _primary->region ();
2538 if (pos < (region->position() + 64)) {
2539 fade_length = 64; // this should be a minimum defined somewhere
2540 } else if (pos > region->last_frame()) {
2541 fade_length = region->length();
2543 fade_length = pos - region->position();
2546 _editor->begin_reversible_command (_("change fade in length"));
2548 for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
2550 AudioRegionView* tmp = dynamic_cast<AudioRegionView*> (i->view);
2556 boost::shared_ptr<AutomationList> alist = tmp->audio_region()->fade_in();
2557 XMLNode &before = alist->get_state();
2559 tmp->audio_region()->set_fade_in_length (fade_length);
2560 tmp->audio_region()->set_fade_in_active (true);
2562 XMLNode &after = alist->get_state();
2563 _editor->session()->add_command(new MementoCommand<AutomationList>(*alist.get(), &before, &after));
2566 _editor->commit_reversible_command ();
2570 FadeInDrag::aborted (bool)
2572 for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
2573 AudioRegionView* tmp = dynamic_cast<AudioRegionView*> (i->view);
2579 tmp->reset_fade_in_shape_width (tmp->audio_region(), tmp->audio_region()->fade_in()->back()->when);
2583 FadeOutDrag::FadeOutDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, list<RegionView*> const & v)
2584 : RegionDrag (e, i, p, v)
2586 DEBUG_TRACE (DEBUG::Drags, "New FadeOutDrag\n");
2590 FadeOutDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
2592 Drag::start_grab (event, cursor);
2594 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (_primary);
2595 boost::shared_ptr<AudioRegion> r = arv->audio_region ();
2597 show_verbose_cursor_duration (r->last_frame() - r->fade_out()->back()->when, r->last_frame());
2601 FadeOutDrag::setup_pointer_frame_offset ()
2603 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (_primary);
2604 boost::shared_ptr<AudioRegion> r = arv->audio_region ();
2605 _pointer_frame_offset = raw_grab_frame() - (r->length() - (framecnt_t) r->fade_out()->back()->when + r->position());
2609 FadeOutDrag::motion (GdkEvent* event, bool)
2611 framecnt_t fade_length;
2613 framepos_t const pos = adjusted_current_frame (event);
2615 boost::shared_ptr<Region> region = _primary->region ();
2617 if (pos > (region->last_frame() - 64)) {
2618 fade_length = 64; // this should really be a minimum fade defined somewhere
2620 else if (pos < region->position()) {
2621 fade_length = region->length();
2624 fade_length = region->last_frame() - pos;
2627 for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
2629 AudioRegionView* tmp = dynamic_cast<AudioRegionView*> (i->view);
2635 tmp->reset_fade_out_shape_width (tmp->audio_region(), fade_length);
2638 show_verbose_cursor_duration (region->last_frame() - fade_length, region->last_frame());
2642 FadeOutDrag::finished (GdkEvent* event, bool movement_occurred)
2644 if (!movement_occurred) {
2648 framecnt_t fade_length;
2650 framepos_t const pos = adjusted_current_frame (event);
2652 boost::shared_ptr<Region> region = _primary->region ();
2654 if (pos > (region->last_frame() - 64)) {
2655 fade_length = 64; // this should really be a minimum fade defined somewhere
2657 else if (pos < region->position()) {
2658 fade_length = region->length();
2661 fade_length = region->last_frame() - pos;
2664 _editor->begin_reversible_command (_("change fade out length"));
2666 for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
2668 AudioRegionView* tmp = dynamic_cast<AudioRegionView*> (i->view);
2674 boost::shared_ptr<AutomationList> alist = tmp->audio_region()->fade_out();
2675 XMLNode &before = alist->get_state();
2677 tmp->audio_region()->set_fade_out_length (fade_length);
2678 tmp->audio_region()->set_fade_out_active (true);
2680 XMLNode &after = alist->get_state();
2681 _editor->session()->add_command(new MementoCommand<AutomationList>(*alist.get(), &before, &after));
2684 _editor->commit_reversible_command ();
2688 FadeOutDrag::aborted (bool)
2690 for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
2691 AudioRegionView* tmp = dynamic_cast<AudioRegionView*> (i->view);
2697 tmp->reset_fade_out_shape_width (tmp->audio_region(), tmp->audio_region()->fade_out()->back()->when);
2701 MarkerDrag::MarkerDrag (Editor* e, ArdourCanvas::Item* i)
2704 DEBUG_TRACE (DEBUG::Drags, "New MarkerDrag\n");
2706 _marker = reinterpret_cast<Marker*> (_item->get_data ("marker"));
2709 _points.push_back (ArdourCanvas::Duple (0, 0));
2710 _points.push_back (ArdourCanvas::Duple (0, physical_screen_height (_editor->get_window())));
2713 MarkerDrag::~MarkerDrag ()
2715 for (CopiedLocationInfo::iterator i = _copied_locations.begin(); i != _copied_locations.end(); ++i) {
2720 MarkerDrag::CopiedLocationMarkerInfo::CopiedLocationMarkerInfo (Location* l, Marker* m)
2722 location = new Location (*l);
2723 markers.push_back (m);
2728 MarkerDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
2730 Drag::start_grab (event, cursor);
2734 Location *location = _editor->find_location_from_marker (_marker, is_start);
2735 _editor->_dragging_edit_point = true;
2737 update_item (location);
2739 // _drag_line->show();
2740 // _line->raise_to_top();
2743 show_verbose_cursor_time (location->start());
2745 show_verbose_cursor_time (location->end());
2748 Selection::Operation op = ArdourKeyboard::selection_type (event->button.state);
2751 case Selection::Toggle:
2752 /* we toggle on the button release */
2754 case Selection::Set:
2755 if (!_editor->selection->selected (_marker)) {
2756 _editor->selection->set (_marker);
2759 case Selection::Extend:
2761 Locations::LocationList ll;
2762 list<Marker*> to_add;
2764 _editor->selection->markers.range (s, e);
2765 s = min (_marker->position(), s);
2766 e = max (_marker->position(), e);
2769 if (e < max_framepos) {
2772 _editor->session()->locations()->find_all_between (s, e, ll, Location::Flags (0));
2773 for (Locations::LocationList::iterator i = ll.begin(); i != ll.end(); ++i) {
2774 Editor::LocationMarkers* lm = _editor->find_location_markers (*i);
2777 to_add.push_back (lm->start);
2780 to_add.push_back (lm->end);
2784 if (!to_add.empty()) {
2785 _editor->selection->add (to_add);
2789 case Selection::Add:
2790 _editor->selection->add (_marker);
2794 /* Set up copies for us to manipulate during the drag
2797 for (MarkerSelection::iterator i = _editor->selection->markers.begin(); i != _editor->selection->markers.end(); ++i) {
2799 Location* l = _editor->find_location_from_marker (*i, is_start);
2806 _copied_locations.push_back (CopiedLocationMarkerInfo (l, *i));
2808 /* range: check that the other end of the range isn't
2811 CopiedLocationInfo::iterator x;
2812 for (x = _copied_locations.begin(); x != _copied_locations.end(); ++x) {
2813 if (*(*x).location == *l) {
2817 if (x == _copied_locations.end()) {
2818 _copied_locations.push_back (CopiedLocationMarkerInfo (l, *i));
2820 (*x).markers.push_back (*i);
2821 (*x).move_both = true;
2829 MarkerDrag::setup_pointer_frame_offset ()
2832 Location *location = _editor->find_location_from_marker (_marker, is_start);
2833 _pointer_frame_offset = raw_grab_frame() - (is_start ? location->start() : location->end());
2837 MarkerDrag::motion (GdkEvent* event, bool)
2839 framecnt_t f_delta = 0;
2841 bool move_both = false;
2842 Location *real_location;
2843 Location *copy_location = 0;
2845 framepos_t const newframe = adjusted_current_frame (event);
2846 framepos_t next = newframe;
2848 if (Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) {
2852 CopiedLocationInfo::iterator x;
2854 /* find the marker we're dragging, and compute the delta */
2856 for (x = _copied_locations.begin(); x != _copied_locations.end(); ++x) {
2858 copy_location = (*x).location;
2860 if (find (x->markers.begin(), x->markers.end(), _marker) != x->markers.end()) {
2862 /* this marker is represented by this
2863 * CopiedLocationMarkerInfo
2866 if ((real_location = _editor->find_location_from_marker (_marker, is_start)) == 0) {
2871 if (real_location->is_mark()) {
2872 f_delta = newframe - copy_location->start();
2876 switch (_marker->type()) {
2877 case Marker::SessionStart:
2878 case Marker::RangeStart:
2879 case Marker::LoopStart:
2880 case Marker::PunchIn:
2881 f_delta = newframe - copy_location->start();
2884 case Marker::SessionEnd:
2885 case Marker::RangeEnd:
2886 case Marker::LoopEnd:
2887 case Marker::PunchOut:
2888 f_delta = newframe - copy_location->end();
2891 /* what kind of marker is this ? */
2900 if (x == _copied_locations.end()) {
2901 /* hmm, impossible - we didn't find the dragged marker */
2905 /* now move them all */
2907 for (x = _copied_locations.begin(); x != _copied_locations.end(); ++x) {
2909 copy_location = x->location;
2911 /* call this to find out if its the start or end */
2913 if ((real_location = _editor->find_location_from_marker (x->markers.front(), is_start)) == 0) {
2917 if (real_location->locked()) {
2921 if (copy_location->is_mark()) {
2925 copy_location->set_start (copy_location->start() + f_delta);
2929 framepos_t new_start = copy_location->start() + f_delta;
2930 framepos_t new_end = copy_location->end() + f_delta;
2932 if (is_start) { // start-of-range marker
2934 if (move_both || (*x).move_both) {
2935 copy_location->set_start (new_start);
2936 copy_location->set_end (new_end);
2937 } else if (new_start < copy_location->end()) {
2938 copy_location->set_start (new_start);
2939 } else if (newframe > 0) {
2940 _editor->snap_to (next, 1, true);
2941 copy_location->set_end (next);
2942 copy_location->set_start (newframe);
2945 } else { // end marker
2947 if (move_both || (*x).move_both) {
2948 copy_location->set_end (new_end);
2949 copy_location->set_start (new_start);
2950 } else if (new_end > copy_location->start()) {
2951 copy_location->set_end (new_end);
2952 } else if (newframe > 0) {
2953 _editor->snap_to (next, -1, true);
2954 copy_location->set_start (next);
2955 copy_location->set_end (newframe);
2960 update_item (copy_location);
2962 /* now lookup the actual GUI items used to display this
2963 * location and move them to wherever the copy of the location
2964 * is now. This means that the logic in ARDOUR::Location is
2965 * still enforced, even though we are not (yet) modifying
2966 * the real Location itself.
2969 Editor::LocationMarkers* lm = _editor->find_location_markers (real_location);
2972 lm->set_position (copy_location->start(), copy_location->end());
2977 assert (!_copied_locations.empty());
2979 show_verbose_cursor_time (newframe);
2983 MarkerDrag::finished (GdkEvent* event, bool movement_occurred)
2985 if (!movement_occurred) {
2987 if (was_double_click()) {
2988 cerr << "End of marker double click\n";
2991 /* just a click, do nothing but finish
2992 off the selection process
2995 Selection::Operation op = ArdourKeyboard::selection_type (event->button.state);
2998 case Selection::Set:
2999 if (_editor->selection->selected (_marker) && _editor->selection->markers.size() > 1) {
3000 _editor->selection->set (_marker);
3004 case Selection::Toggle:
3005 /* we toggle on the button release, click only */
3006 _editor->selection->toggle (_marker);
3009 case Selection::Extend:
3010 case Selection::Add:
3017 _editor->_dragging_edit_point = false;
3019 _editor->begin_reversible_command ( _("move marker") );
3020 XMLNode &before = _editor->session()->locations()->get_state();
3022 MarkerSelection::iterator i;
3023 CopiedLocationInfo::iterator x;
3026 for (i = _editor->selection->markers.begin(), x = _copied_locations.begin();
3027 x != _copied_locations.end() && i != _editor->selection->markers.end();
3030 Location * location = _editor->find_location_from_marker (*i, is_start);
3034 if (location->locked()) {
3038 if (location->is_mark()) {
3039 location->set_start (((*x).location)->start());
3041 location->set (((*x).location)->start(), ((*x).location)->end());
3046 XMLNode &after = _editor->session()->locations()->get_state();
3047 _editor->session()->add_command(new MementoCommand<Locations>(*(_editor->session()->locations()), &before, &after));
3048 _editor->commit_reversible_command ();
3052 MarkerDrag::aborted (bool)
3058 MarkerDrag::update_item (Location*)
3063 ControlPointDrag::ControlPointDrag (Editor* e, ArdourCanvas::Item* i)
3065 _cumulative_x_drag (0),
3066 _cumulative_y_drag (0)
3068 if (_zero_gain_fraction < 0.0) {
3069 _zero_gain_fraction = gain_to_slider_position_with_max (dB_to_coefficient (0.0), Config->get_max_gain());
3072 DEBUG_TRACE (DEBUG::Drags, "New ControlPointDrag\n");
3074 _point = reinterpret_cast<ControlPoint*> (_item->get_data ("control_point"));
3080 ControlPointDrag::start_grab (GdkEvent* event, Gdk::Cursor* /*cursor*/)
3082 Drag::start_grab (event, _editor->cursors()->fader);
3084 // start the grab at the center of the control point so
3085 // the point doesn't 'jump' to the mouse after the first drag
3086 _fixed_grab_x = _point->get_x();
3087 _fixed_grab_y = _point->get_y();
3089 float const fraction = 1 - (_point->get_y() / _point->line().height());
3091 _point->line().start_drag_single (_point, _fixed_grab_x, fraction);
3093 _editor->verbose_cursor()->set (_point->line().get_verbose_cursor_string (fraction),
3094 event->button.x + 10, event->button.y + 10);
3096 _editor->verbose_cursor()->show ();
3098 _pushing = Keyboard::modifier_state_contains (event->button.state, Keyboard::PrimaryModifier);
3100 if (!_point->can_slide ()) {
3101 _x_constrained = true;
3106 ControlPointDrag::motion (GdkEvent* event, bool)
3108 double dx = _drags->current_pointer_x() - last_pointer_x();
3109 double dy = _drags->current_pointer_y() - last_pointer_y();
3111 if (event->button.state & Keyboard::SecondaryModifier) {
3116 /* coordinate in pixels relative to the start of the region (for region-based automation)
3117 or track (for track-based automation) */
3118 double cx = _fixed_grab_x + _cumulative_x_drag + dx;
3119 double cy = _fixed_grab_y + _cumulative_y_drag + dy;
3121 // calculate zero crossing point. back off by .01 to stay on the
3122 // positive side of zero
3123 double const zero_gain_y = (1.0 - _zero_gain_fraction) * _point->line().height() - .01;
3125 // make sure we hit zero when passing through
3126 if ((cy < zero_gain_y && (cy - dy) > zero_gain_y) || (cy > zero_gain_y && (cy - dy) < zero_gain_y)) {
3130 if (_x_constrained) {
3133 if (_y_constrained) {
3137 _cumulative_x_drag = cx - _fixed_grab_x;
3138 _cumulative_y_drag = cy - _fixed_grab_y;
3142 cy = min ((double) _point->line().height(), cy);
3144 framepos_t cx_frames = _editor->pixel_to_sample (cx);
3146 if (!_x_constrained) {
3147 _editor->snap_to_with_modifier (cx_frames, event);
3150 cx_frames = min (cx_frames, _point->line().maximum_time());
3152 float const fraction = 1.0 - (cy / _point->line().height());
3154 _point->line().drag_motion (_editor->sample_to_pixel_unrounded (cx_frames), fraction, false, _pushing, _final_index);
3156 _editor->verbose_cursor()->set_text (_point->line().get_verbose_cursor_string (fraction));
3160 ControlPointDrag::finished (GdkEvent* event, bool movement_occurred)
3162 if (!movement_occurred) {
3166 if (Keyboard::modifier_state_equals (event->button.state, Keyboard::TertiaryModifier)) {
3167 _editor->reset_point_selection ();
3171 motion (event, false);
3174 _point->line().end_drag (_pushing, _final_index);
3175 _editor->session()->commit_reversible_command ();
3179 ControlPointDrag::aborted (bool)
3181 _point->line().reset ();
3185 ControlPointDrag::active (Editing::MouseMode m)
3187 if (m == Editing::MouseGain) {
3188 /* always active in mouse gain */
3192 /* otherwise active if the point is on an automation line (ie not if its on a region gain line) */
3193 return dynamic_cast<AutomationLine*> (&(_point->line())) != 0;
3196 LineDrag::LineDrag (Editor* e, ArdourCanvas::Item* i)
3199 _cumulative_y_drag (0)
3201 DEBUG_TRACE (DEBUG::Drags, "New LineDrag\n");
3205 LineDrag::start_grab (GdkEvent* event, Gdk::Cursor* /*cursor*/)
3207 _line = reinterpret_cast<AutomationLine*> (_item->get_data ("line"));
3210 _item = &_line->grab_item ();
3212 /* need to get x coordinate in terms of parent (TimeAxisItemView)
3213 origin, and ditto for y.
3216 double cx = event->button.x;
3217 double cy = event->button.y;
3219 _line->parent_group().canvas_to_item (cx, cy);
3221 framecnt_t const frame_within_region = (framecnt_t) floor (cx * _editor->samples_per_pixel);
3226 if (!_line->control_points_adjacent (frame_within_region, before, after)) {
3227 /* no adjacent points */
3231 Drag::start_grab (event, _editor->cursors()->fader);
3233 /* store grab start in parent frame */
3238 double fraction = 1.0 - (cy / _line->height());
3240 _line->start_drag_line (before, after, fraction);
3242 _editor->verbose_cursor()->set (_line->get_verbose_cursor_string (fraction),
3243 event->button.x + 10, event->button.y + 10);
3245 _editor->verbose_cursor()->show ();
3249 LineDrag::motion (GdkEvent* event, bool)
3251 double dy = _drags->current_pointer_y() - last_pointer_y();
3253 if (event->button.state & Keyboard::SecondaryModifier) {
3257 double cy = _fixed_grab_y + _cumulative_y_drag + dy;
3259 _cumulative_y_drag = cy - _fixed_grab_y;
3262 cy = min ((double) _line->height(), cy);
3264 double const fraction = 1.0 - (cy / _line->height());
3267 /* we are ignoring x position for this drag, so we can just pass in anything */
3268 _line->drag_motion (0, fraction, true, false, ignored);
3270 _editor->verbose_cursor()->set_text (_line->get_verbose_cursor_string (fraction));
3274 LineDrag::finished (GdkEvent* event, bool)
3276 motion (event, false);
3277 _line->end_drag (false, 0);
3278 _editor->session()->commit_reversible_command ();
3282 LineDrag::aborted (bool)
3287 FeatureLineDrag::FeatureLineDrag (Editor* e, ArdourCanvas::Item* i)
3290 _cumulative_x_drag (0)
3292 DEBUG_TRACE (DEBUG::Drags, "New FeatureLineDrag\n");
3296 FeatureLineDrag::start_grab (GdkEvent* event, Gdk::Cursor* /*cursor*/)
3298 Drag::start_grab (event);
3300 _line = reinterpret_cast<Line*> (_item);
3303 /* need to get x coordinate in terms of parent (AudioRegionView) origin. */
3305 double cx = event->button.x;
3306 double cy = event->button.y;
3308 _item->parent()->canvas_to_item (cx, cy);
3310 /* store grab start in parent frame */
3311 _region_view_grab_x = cx;
3313 _before = *(float*) _item->get_data ("position");
3315 _arv = reinterpret_cast<AudioRegionView*> (_item->get_data ("regionview"));
3317 _max_x = _editor->sample_to_pixel(_arv->get_duration());
3321 FeatureLineDrag::motion (GdkEvent*, bool)
3323 double dx = _drags->current_pointer_x() - last_pointer_x();
3325 double cx = _region_view_grab_x + _cumulative_x_drag + dx;
3327 _cumulative_x_drag += dx;
3329 /* Clamp the min and max extent of the drag to keep it within the region view bounds */
3338 boost::optional<ArdourCanvas::Rect> bbox = _line->bounding_box ();
3340 _line->set (ArdourCanvas::Duple (cx, 2.0), ArdourCanvas::Duple (cx, bbox.get().height ()));
3342 float *pos = new float;
3345 _line->set_data ("position", pos);
3351 FeatureLineDrag::finished (GdkEvent*, bool)
3353 _arv = reinterpret_cast<AudioRegionView*> (_item->get_data ("regionview"));
3354 _arv->update_transient(_before, _before);
3358 FeatureLineDrag::aborted (bool)
3363 RubberbandSelectDrag::RubberbandSelectDrag (Editor* e, ArdourCanvas::Item* i)
3365 , _vertical_only (false)
3367 DEBUG_TRACE (DEBUG::Drags, "New RubberbandSelectDrag\n");
3371 RubberbandSelectDrag::start_grab (GdkEvent* event, Gdk::Cursor *)
3373 Drag::start_grab (event);
3374 show_verbose_cursor_time (adjusted_current_frame (event));
3378 RubberbandSelectDrag::motion (GdkEvent* event, bool)
3385 framepos_t const pf = adjusted_current_frame (event, Config->get_rubberbanding_snaps_to_grid ());
3387 framepos_t grab = grab_frame ();
3388 if (Config->get_rubberbanding_snaps_to_grid ()) {
3389 _editor->snap_to_with_modifier (grab, event);
3392 /* base start and end on initial click position */
3402 if (_drags->current_pointer_y() < grab_y()) {
3403 y1 = _drags->current_pointer_y();
3406 y2 = _drags->current_pointer_y();
3411 if (start != end || y1 != y2) {
3413 double x1 = _editor->sample_to_pixel (start);
3414 double x2 = _editor->sample_to_pixel (end);
3416 _editor->rubberband_rect->set_x0 (x1);
3417 if (_vertical_only) {
3418 /* fixed 10 pixel width */
3419 _editor->rubberband_rect->set_x1 (x1 + 10);
3421 _editor->rubberband_rect->set_x1 (x2);
3424 _editor->rubberband_rect->set_y0 (y1);
3425 _editor->rubberband_rect->set_y1 (y2);
3427 _editor->rubberband_rect->show();
3428 _editor->rubberband_rect->raise_to_top();
3430 show_verbose_cursor_time (pf);
3432 do_select_things (event, true);
3437 RubberbandSelectDrag::do_select_things (GdkEvent* event, bool drag_in_progress)
3442 if (grab_frame() < last_pointer_frame()) {
3444 x2 = last_pointer_frame ();
3447 x1 = last_pointer_frame ();
3453 if (_drags->current_pointer_y() < grab_y()) {
3454 y1 = _drags->current_pointer_y();
3457 y2 = _drags->current_pointer_y();
3461 select_things (event->button.state, x1, x2, y1, y2, drag_in_progress);
3465 RubberbandSelectDrag::finished (GdkEvent* event, bool movement_occurred)
3467 if (movement_occurred) {
3469 motion (event, false);
3470 do_select_things (event, false);
3476 bool do_deselect = true;
3477 MidiTimeAxisView* mtv;
3479 if ((mtv = dynamic_cast<MidiTimeAxisView*>(_editor->clicked_axisview)) != 0) {
3481 if (_editor->selection->empty()) {
3482 /* nothing selected */
3483 add_midi_region (mtv);
3484 do_deselect = false;
3488 /* do not deselect if Primary or Tertiary (toggle-select or
3489 * extend-select are pressed.
3492 if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::PrimaryModifier) &&
3493 !Keyboard::modifier_state_contains (event->button.state, Keyboard::TertiaryModifier) &&
3500 _editor->rubberband_rect->hide();
3504 RubberbandSelectDrag::aborted (bool)
3506 _editor->rubberband_rect->hide ();
3509 TimeFXDrag::TimeFXDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, std::list<RegionView*> const & v)
3510 : RegionDrag (e, i, p, v)
3512 DEBUG_TRACE (DEBUG::Drags, "New TimeFXDrag\n");
3516 TimeFXDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
3518 Drag::start_grab (event, cursor);
3520 show_verbose_cursor_time (adjusted_current_frame (event));
3524 TimeFXDrag::motion (GdkEvent* event, bool)
3526 RegionView* rv = _primary;
3527 StreamView* cv = rv->get_time_axis_view().view ();
3529 pair<TimeAxisView*, double> const tv = _editor->trackview_by_y_position (grab_y());
3530 int layer = tv.first->layer_display() == Overlaid ? 0 : tv.second;
3531 int layers = tv.first->layer_display() == Overlaid ? 1 : cv->layers();
3533 framepos_t const pf = adjusted_current_frame (event);
3535 if (pf > rv->region()->position()) {
3536 rv->get_time_axis_view().show_timestretch (rv->region()->position(), pf, layers, layer);
3539 show_verbose_cursor_time (pf);
3543 TimeFXDrag::finished (GdkEvent* /*event*/, bool movement_occurred)
3545 _primary->get_time_axis_view().hide_timestretch ();
3547 if (!movement_occurred) {
3551 if (last_pointer_frame() < _primary->region()->position()) {
3552 /* backwards drag of the left edge - not usable */
3556 framecnt_t newlen = last_pointer_frame() - _primary->region()->position();
3558 float percentage = (double) newlen / (double) _primary->region()->length();
3560 #ifndef USE_RUBBERBAND
3561 // Soundtouch uses percentage / 100 instead of normal (/ 1)
3562 if (_primary->region()->data_type() == DataType::AUDIO) {
3563 percentage = (float) ((double) newlen - (double) _primary->region()->length()) / ((double) newlen) * 100.0f;
3567 if (!_editor->get_selection().regions.empty()) {
3568 /* primary will already be included in the selection, and edit
3569 group shared editing will propagate selection across
3570 equivalent regions, so just use the current region
3574 if (_editor->time_stretch (_editor->get_selection().regions, percentage) == -1) {
3575 error << _("An error occurred while executing time stretch operation") << endmsg;
3581 TimeFXDrag::aborted (bool)
3583 _primary->get_time_axis_view().hide_timestretch ();
3586 ScrubDrag::ScrubDrag (Editor* e, ArdourCanvas::Item* i)
3589 DEBUG_TRACE (DEBUG::Drags, "New ScrubDrag\n");
3593 ScrubDrag::start_grab (GdkEvent* event, Gdk::Cursor *)
3595 Drag::start_grab (event);
3599 ScrubDrag::motion (GdkEvent* /*event*/, bool)
3601 _editor->scrub (adjusted_current_frame (0, false), _drags->current_pointer_x ());
3605 ScrubDrag::finished (GdkEvent* /*event*/, bool movement_occurred)
3607 if (movement_occurred && _editor->session()) {
3608 /* make sure we stop */
3609 _editor->session()->request_transport_speed (0.0);
3614 ScrubDrag::aborted (bool)
3619 SelectionDrag::SelectionDrag (Editor* e, ArdourCanvas::Item* i, Operation o)
3624 , _original_pointer_time_axis (-1)
3625 , _last_pointer_time_axis (-1)
3626 , _time_selection_at_start (!_editor->get_selection().time.empty())
3628 DEBUG_TRACE (DEBUG::Drags, "New SelectionDrag\n");
3630 if (_time_selection_at_start) {
3631 start_at_start = _editor->get_selection().time.start();
3632 end_at_start = _editor->get_selection().time.end_frame();
3637 SelectionDrag::start_grab (GdkEvent* event, Gdk::Cursor*)
3639 if (_editor->session() == 0) {
3643 Gdk::Cursor* cursor = 0;
3645 switch (_operation) {
3646 case CreateSelection:
3647 if (Keyboard::modifier_state_equals (event->button.state, Keyboard::CopyModifier)) {
3652 cursor = _editor->cursors()->selector;
3653 Drag::start_grab (event, cursor);
3656 case SelectionStartTrim:
3657 if (_editor->clicked_axisview) {
3658 _editor->clicked_axisview->order_selection_trims (_item, true);
3660 Drag::start_grab (event, _editor->cursors()->left_side_trim);
3663 case SelectionEndTrim:
3664 if (_editor->clicked_axisview) {
3665 _editor->clicked_axisview->order_selection_trims (_item, false);
3667 Drag::start_grab (event, _editor->cursors()->right_side_trim);
3671 Drag::start_grab (event, cursor);
3674 case SelectionExtend:
3675 Drag::start_grab (event, cursor);
3679 if (_operation == SelectionMove) {
3680 show_verbose_cursor_time (_editor->selection->time[_editor->clicked_selection].start);
3682 show_verbose_cursor_time (adjusted_current_frame (event));
3685 _original_pointer_time_axis = _editor->trackview_by_y_position (_drags->current_pointer_y ()).first->order ();
3689 SelectionDrag::setup_pointer_frame_offset ()
3691 switch (_operation) {
3692 case CreateSelection:
3693 _pointer_frame_offset = 0;
3696 case SelectionStartTrim:
3698 _pointer_frame_offset = raw_grab_frame() - _editor->selection->time[_editor->clicked_selection].start;
3701 case SelectionEndTrim:
3702 _pointer_frame_offset = raw_grab_frame() - _editor->selection->time[_editor->clicked_selection].end;
3705 case SelectionExtend:
3711 SelectionDrag::motion (GdkEvent* event, bool first_move)
3713 framepos_t start = 0;
3715 framecnt_t length = 0;
3716 framecnt_t distance = 0;
3718 pair<TimeAxisView*, int> const pending_time_axis = _editor->trackview_by_y_position (_drags->current_pointer_y ());
3719 if (pending_time_axis.first == 0) {
3723 framepos_t const pending_position = adjusted_current_frame (event);
3725 /* only alter selection if things have changed */
3727 if (pending_time_axis.first->order() == _last_pointer_time_axis && pending_position == last_pointer_frame()) {
3731 switch (_operation) {
3732 case CreateSelection:
3734 framepos_t grab = grab_frame ();
3737 grab = adjusted_current_frame (event, false);
3738 if (grab < pending_position) {
3739 _editor->snap_to (grab, -1);
3741 _editor->snap_to (grab, 1);
3745 if (pending_position < grab) {
3746 start = pending_position;
3749 end = pending_position;
3753 /* first drag: Either add to the selection
3754 or create a new selection
3760 /* adding to the selection */
3761 _editor->set_selected_track_as_side_effect (Selection::Add);
3762 //_editor->selection->add (_editor->clicked_axisview);
3763 _editor->clicked_selection = _editor->selection->add (start, end);
3768 if (_editor->clicked_axisview && !_editor->selection->selected (_editor->clicked_axisview)) {
3769 //_editor->selection->set (_editor->clicked_axisview);
3770 _editor->set_selected_track_as_side_effect (Selection::Set);
3773 _editor->clicked_selection = _editor->selection->set (start, end);
3777 /* select the track that we're in */
3778 if (find (_added_time_axes.begin(), _added_time_axes.end(), pending_time_axis.first) == _added_time_axes.end()) {
3779 // _editor->set_selected_track_as_side_effect (Selection::Add);
3780 _editor->selection->add (pending_time_axis.first);
3781 _added_time_axes.push_back (pending_time_axis.first);
3784 /* deselect any tracks that this drag no longer includes, being careful to only deselect
3785 tracks that we selected in the first place.
3788 int min_order = min (_original_pointer_time_axis, pending_time_axis.first->order());
3789 int max_order = max (_original_pointer_time_axis, pending_time_axis.first->order());
3791 list<TimeAxisView*>::iterator i = _added_time_axes.begin();
3792 while (i != _added_time_axes.end()) {
3794 list<TimeAxisView*>::iterator tmp = i;
3797 if ((*i)->order() < min_order || (*i)->order() > max_order) {
3798 _editor->selection->remove (*i);
3799 _added_time_axes.remove (*i);
3808 case SelectionStartTrim:
3810 start = _editor->selection->time[_editor->clicked_selection].start;
3811 end = _editor->selection->time[_editor->clicked_selection].end;
3813 if (pending_position > end) {
3816 start = pending_position;
3820 case SelectionEndTrim:
3822 start = _editor->selection->time[_editor->clicked_selection].start;
3823 end = _editor->selection->time[_editor->clicked_selection].end;
3825 if (pending_position < start) {
3828 end = pending_position;
3835 start = _editor->selection->time[_editor->clicked_selection].start;
3836 end = _editor->selection->time[_editor->clicked_selection].end;
3838 length = end - start;
3839 distance = pending_position - start;
3840 start = pending_position;
3841 _editor->snap_to (start);
3843 end = start + length;
3847 case SelectionExtend:
3851 if (event->button.x >= _editor->horizontal_position() + _editor->_visible_canvas_width) {
3852 _editor->start_canvas_autoscroll (1, 0);
3856 switch (_operation) {
3858 if (_time_selection_at_start) {
3859 _editor->selection->move_time (distance);
3863 _editor->selection->replace (_editor->clicked_selection, start, end);
3867 if (_operation == SelectionMove) {
3868 show_verbose_cursor_time(start);
3870 show_verbose_cursor_time(pending_position);
3875 SelectionDrag::finished (GdkEvent* event, bool movement_occurred)
3877 Session* s = _editor->session();
3879 if (movement_occurred) {
3880 motion (event, false);
3881 /* XXX this is not object-oriented programming at all. ick */
3882 if (_editor->selection->time.consolidate()) {
3883 _editor->selection->TimeChanged ();
3886 /* XXX what if its a music time selection? */
3888 if ( s->get_play_range() && s->transport_rolling() ) {
3889 s->request_play_range (&_editor->selection->time, true);
3891 if (Config->get_always_play_range() && !s->transport_rolling()) {
3892 s->request_locate (_editor->get_selection().time.start());
3898 /* just a click, no pointer movement.
3901 if (_operation == SelectionExtend) {
3902 if (_time_selection_at_start) {
3903 framepos_t pos = adjusted_current_frame (event, false);
3904 framepos_t start = min (pos, start_at_start);
3905 framepos_t end = max (pos, end_at_start);
3906 _editor->selection->set (start, end);
3909 if (Keyboard::modifier_state_equals (event->button.state, Keyboard::CopyModifier)) {
3910 if (_editor->clicked_selection) {
3911 _editor->selection->remove (_editor->clicked_selection);
3914 if (!_editor->clicked_selection) {
3915 _editor->selection->clear_time();
3920 if (_editor->clicked_axisview && !_editor->selection->selected (_editor->clicked_axisview)) {
3921 _editor->selection->set (_editor->clicked_axisview);
3924 if (s && s->get_play_range () && s->transport_rolling()) {
3925 s->request_stop (false, false);
3930 _editor->stop_canvas_autoscroll ();
3931 _editor->clicked_selection = 0;
3935 SelectionDrag::aborted (bool)
3940 RangeMarkerBarDrag::RangeMarkerBarDrag (Editor* e, ArdourCanvas::Item* i, Operation o)
3945 DEBUG_TRACE (DEBUG::Drags, "New RangeMarkerBarDrag\n");
3947 _drag_rect = new ArdourCanvas::Rectangle (_editor->time_line_group,
3948 ArdourCanvas::Rect (0.0, 0.0, 0.0,
3949 physical_screen_height (_editor->get_window())));
3950 _drag_rect->hide ();
3952 _drag_rect->set_fill_color (ARDOUR_UI::config()->get_canvasvar_RangeDragRect());
3953 _drag_rect->set_outline_color (ARDOUR_UI::config()->get_canvasvar_RangeDragRect());
3957 RangeMarkerBarDrag::start_grab (GdkEvent* event, Gdk::Cursor *)
3959 if (_editor->session() == 0) {
3963 Gdk::Cursor* cursor = 0;
3965 if (!_editor->temp_location) {
3966 _editor->temp_location = new Location (*_editor->session());
3969 switch (_operation) {
3970 case CreateRangeMarker:
3971 case CreateTransportMarker:
3972 case CreateCDMarker:
3974 if (Keyboard::modifier_state_equals (event->button.state, Keyboard::TertiaryModifier)) {
3979 cursor = _editor->cursors()->selector;
3983 Drag::start_grab (event, cursor);
3985 show_verbose_cursor_time (adjusted_current_frame (event));
3989 RangeMarkerBarDrag::motion (GdkEvent* event, bool first_move)
3991 framepos_t start = 0;
3993 ArdourCanvas::Rectangle *crect;
3995 switch (_operation) {
3996 case CreateRangeMarker:
3997 crect = _editor->range_bar_drag_rect;
3999 case CreateTransportMarker:
4000 crect = _editor->transport_bar_drag_rect;
4002 case CreateCDMarker:
4003 crect = _editor->cd_marker_bar_drag_rect;
4006 error << string_compose (_("programming_error: %1"), "Error: unknown range marker op passed to Editor::drag_range_markerbar_op ()") << endmsg;
4011 framepos_t const pf = adjusted_current_frame (event);
4013 if (_operation == CreateRangeMarker || _operation == CreateTransportMarker || _operation == CreateCDMarker) {
4014 framepos_t grab = grab_frame ();
4015 _editor->snap_to (grab);
4017 if (pf < grab_frame()) {
4025 /* first drag: Either add to the selection
4026 or create a new selection.
4031 _editor->temp_location->set (start, end);
4035 update_item (_editor->temp_location);
4037 //_drag_rect->raise_to_top();
4042 if (event->button.x >= _editor->horizontal_position() + _editor->_visible_canvas_width) {
4043 _editor->start_canvas_autoscroll (1, 0);
4047 _editor->temp_location->set (start, end);
4049 double x1 = _editor->sample_to_pixel (start);
4050 double x2 = _editor->sample_to_pixel (end);
4054 update_item (_editor->temp_location);
4057 show_verbose_cursor_time (pf);
4062 RangeMarkerBarDrag::finished (GdkEvent* event, bool movement_occurred)
4064 Location * newloc = 0;
4068 if (movement_occurred) {
4069 motion (event, false);
4072 switch (_operation) {
4073 case CreateRangeMarker:
4074 case CreateCDMarker:
4076 _editor->begin_reversible_command (_("new range marker"));
4077 XMLNode &before = _editor->session()->locations()->get_state();
4078 _editor->session()->locations()->next_available_name(rangename,"unnamed");
4079 if (_operation == CreateCDMarker) {
4080 flags = Location::IsRangeMarker | Location::IsCDMarker;
4081 _editor->cd_marker_bar_drag_rect->hide();
4084 flags = Location::IsRangeMarker;
4085 _editor->range_bar_drag_rect->hide();
4087 newloc = new Location (
4088 *_editor->session(), _editor->temp_location->start(), _editor->temp_location->end(), rangename, (Location::Flags) flags
4091 _editor->session()->locations()->add (newloc, true);
4092 XMLNode &after = _editor->session()->locations()->get_state();
4093 _editor->session()->add_command(new MementoCommand<Locations>(*(_editor->session()->locations()), &before, &after));
4094 _editor->commit_reversible_command ();
4098 case CreateTransportMarker:
4099 // popup menu to pick loop or punch
4100 _editor->new_transport_marker_context_menu (&event->button, _item);
4104 /* just a click, no pointer movement. remember that context menu stuff was handled elsewhere */
4106 if (Keyboard::no_modifier_keys_pressed (&event->button) && _operation != CreateCDMarker) {
4111 _editor->session()->locations()->marks_either_side (grab_frame(), start, end);
4113 if (end == max_framepos) {
4114 end = _editor->session()->current_end_frame ();
4117 if (start == max_framepos) {
4118 start = _editor->session()->current_start_frame ();
4121 switch (_editor->mouse_mode) {
4123 /* find the two markers on either side and then make the selection from it */
4124 _editor->select_all_within (start, end, 0.0f, FLT_MAX, _editor->track_views, Selection::Set, false);
4128 /* find the two markers on either side of the click and make the range out of it */
4129 _editor->selection->set (start, end);
4138 _editor->stop_canvas_autoscroll ();
4142 RangeMarkerBarDrag::aborted (bool)
4148 RangeMarkerBarDrag::update_item (Location* location)
4150 double const x1 = _editor->sample_to_pixel (location->start());
4151 double const x2 = _editor->sample_to_pixel (location->end());
4153 _drag_rect->set_x0 (x1);
4154 _drag_rect->set_x1 (x2);
4157 MouseZoomDrag::MouseZoomDrag (Editor* e, ArdourCanvas::Item* i)
4161 DEBUG_TRACE (DEBUG::Drags, "New MouseZoomDrag\n");
4165 MouseZoomDrag::start_grab (GdkEvent* event, Gdk::Cursor *)
4167 if (Keyboard::the_keyboard().key_is_down (GDK_Control_L)) {
4168 Drag::start_grab (event, _editor->cursors()->zoom_out);
4171 Drag::start_grab (event, _editor->cursors()->zoom_in);
4175 show_verbose_cursor_time (adjusted_current_frame (event));
4179 MouseZoomDrag::motion (GdkEvent* event, bool first_move)
4184 framepos_t const pf = adjusted_current_frame (event);
4186 framepos_t grab = grab_frame ();
4187 _editor->snap_to_with_modifier (grab, event);
4189 /* base start and end on initial click position */
4201 _editor->zoom_rect->show();
4202 _editor->zoom_rect->raise_to_top();
4205 _editor->reposition_zoom_rect(start, end);
4207 show_verbose_cursor_time (pf);
4212 MouseZoomDrag::finished (GdkEvent* event, bool movement_occurred)
4214 if (movement_occurred) {
4215 motion (event, false);
4217 if (grab_frame() < last_pointer_frame()) {
4218 _editor->temporal_zoom_by_frame (grab_frame(), last_pointer_frame());
4220 _editor->temporal_zoom_by_frame (last_pointer_frame(), grab_frame());
4223 if (Keyboard::the_keyboard().key_is_down (GDK_Shift_L)) {
4224 _editor->tav_zoom_step (_zoom_out);
4226 _editor->temporal_zoom_to_frame (_zoom_out, grab_frame());
4230 _editor->zoom_rect->hide();
4234 MouseZoomDrag::aborted (bool)
4236 _editor->zoom_rect->hide ();
4239 NoteDrag::NoteDrag (Editor* e, ArdourCanvas::Item* i)
4241 , _cumulative_dx (0)
4242 , _cumulative_dy (0)
4244 DEBUG_TRACE (DEBUG::Drags, "New NoteDrag\n");
4246 _primary = reinterpret_cast<NoteBase*> (_item->get_data ("notebase"));
4248 _region = &_primary->region_view ();
4249 _note_height = _region->midi_stream_view()->note_height ();
4253 NoteDrag::start_grab (GdkEvent* event, Gdk::Cursor *)
4255 Drag::start_grab (event);
4257 if (!(_was_selected = _primary->selected())) {
4259 /* tertiary-click means extend selection - we'll do that on button release,
4260 so don't add it here, because otherwise we make it hard to figure
4261 out the "extend-to" range.
4264 bool extend = Keyboard::modifier_state_equals (event->button.state, Keyboard::TertiaryModifier);
4267 bool add = Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier);
4270 _region->note_selected (_primary, true);
4272 _region->unique_select (_primary);
4278 /** @return Current total drag x change in frames */
4280 NoteDrag::total_dx () const
4283 frameoffset_t const dx = _editor->pixel_to_sample (_drags->current_pointer_x() - grab_x());
4285 /* primary note time */
4286 frameoffset_t const n = _region->source_beats_to_absolute_frames (_primary->note()->time ());
4288 /* new time of the primary note in session frames */
4289 frameoffset_t st = n + dx;
4291 framepos_t const rp = _region->region()->position ();
4293 /* prevent the note being dragged earlier than the region's position */
4296 /* snap and return corresponding delta */
4297 return _region->snap_frame_to_frame (st - rp) + rp - n;
4300 /** @return Current total drag y change in note number */
4302 NoteDrag::total_dy () const
4304 MidiStreamView* msv = _region->midi_stream_view ();
4305 double const y = _region->midi_view()->y_position ();
4306 /* new current note */
4307 uint8_t n = msv->y_to_note (_drags->current_pointer_y () - y);
4309 n = max (msv->lowest_note(), n);
4310 n = min (msv->highest_note(), n);
4311 /* and work out delta */
4312 return n - msv->y_to_note (grab_y() - y);
4316 NoteDrag::motion (GdkEvent *, bool)
4318 /* Total change in x and y since the start of the drag */
4319 frameoffset_t const dx = total_dx ();
4320 int8_t const dy = total_dy ();
4322 /* Now work out what we have to do to the note canvas items to set this new drag delta */
4323 double const tdx = _editor->sample_to_pixel (dx) - _cumulative_dx;
4324 double const tdy = -dy * _note_height - _cumulative_dy;
4327 _cumulative_dx += tdx;
4328 _cumulative_dy += tdy;
4330 int8_t note_delta = total_dy();
4332 _region->move_selection (tdx, tdy, note_delta);
4334 /* the new note value may be the same as the old one, but we
4335 * don't know what that means because the selection may have
4336 * involved more than one note and we might be doing something
4337 * odd with them. so show the note value anyway, always.
4341 uint8_t new_note = min (max (_primary->note()->note() + note_delta, 0), 127);
4343 snprintf (buf, sizeof (buf), "%s (%d)", Evoral::midi_note_name (new_note).c_str(),
4344 (int) floor (new_note));
4346 show_verbose_cursor_text (buf);
4351 NoteDrag::finished (GdkEvent* ev, bool moved)
4354 /* no motion - select note */
4356 if (_editor->current_mouse_mode() == Editing::MouseObject ||
4357 _editor->current_mouse_mode() == Editing::MouseDraw) {
4359 if (_was_selected) {
4360 bool add = Keyboard::modifier_state_equals (ev->button.state, Keyboard::PrimaryModifier);
4362 _region->note_deselected (_primary);
4365 bool extend = Keyboard::modifier_state_equals (ev->button.state, Keyboard::TertiaryModifier);
4366 bool add = Keyboard::modifier_state_equals (ev->button.state, Keyboard::PrimaryModifier);
4368 if (!extend && !add && _region->selection_size() > 1) {
4369 _region->unique_select (_primary);
4370 } else if (extend) {
4371 _region->note_selected (_primary, true, true);
4373 /* it was added during button press */
4378 _region->note_dropped (_primary, total_dx(), total_dy());
4383 NoteDrag::aborted (bool)
4388 /** Make an AutomationRangeDrag for lines in an AutomationTimeAxisView */
4389 AutomationRangeDrag::AutomationRangeDrag (Editor* editor, AutomationTimeAxisView* atv, list<AudioRange> const & r)
4390 : Drag (editor, atv->base_item ())
4392 , _nothing_to_drag (false)
4394 DEBUG_TRACE (DEBUG::Drags, "New AutomationRangeDrag\n");
4395 y_origin = atv->y_position();
4396 setup (atv->lines ());
4399 /** Make an AutomationRangeDrag for region gain lines */
4400 AutomationRangeDrag::AutomationRangeDrag (Editor* editor, AudioRegionView* rv, list<AudioRange> const & r)
4401 : Drag (editor, rv->get_canvas_group ())
4403 , _nothing_to_drag (false)
4405 DEBUG_TRACE (DEBUG::Drags, "New AutomationRangeDrag\n");
4407 list<boost::shared_ptr<AutomationLine> > lines;
4408 lines.push_back (rv->get_gain_line ());
4409 y_origin = rv->get_time_axis_view().y_position();
4413 /** @param lines AutomationLines to drag.
4414 * @param offset Offset from the session start to the points in the AutomationLines.
4417 AutomationRangeDrag::setup (list<boost::shared_ptr<AutomationLine> > const & lines)
4419 /* find the lines that overlap the ranges being dragged */
4420 list<boost::shared_ptr<AutomationLine> >::const_iterator i = lines.begin ();
4421 while (i != lines.end ()) {
4422 list<boost::shared_ptr<AutomationLine> >::const_iterator j = i;
4425 pair<framepos_t, framepos_t> r = (*i)->get_point_x_range ();
4427 /* check this range against all the AudioRanges that we are using */
4428 list<AudioRange>::const_iterator k = _ranges.begin ();
4429 while (k != _ranges.end()) {
4430 if (k->coverage (r.first, r.second) != Evoral::OverlapNone) {
4436 /* add it to our list if it overlaps at all */
4437 if (k != _ranges.end()) {
4442 _lines.push_back (n);
4448 /* Now ::lines contains the AutomationLines that somehow overlap our drag */
4452 AutomationRangeDrag::y_fraction (boost::shared_ptr<AutomationLine> line, double global_y) const
4454 return 1.0 - ((global_y - y_origin) / line->height());
4458 AutomationRangeDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
4460 Drag::start_grab (event, cursor);
4462 /* Get line states before we start changing things */
4463 for (list<Line>::iterator i = _lines.begin(); i != _lines.end(); ++i) {
4464 i->state = &i->line->get_state ();
4465 i->original_fraction = y_fraction (i->line, _drags->current_pointer_y());
4468 if (_ranges.empty()) {
4470 /* No selected time ranges: drag all points */
4471 for (list<Line>::iterator i = _lines.begin(); i != _lines.end(); ++i) {
4472 uint32_t const N = i->line->npoints ();
4473 for (uint32_t j = 0; j < N; ++j) {
4474 i->points.push_back (i->line->nth (j));
4480 for (list<AudioRange>::const_iterator i = _ranges.begin(); i != _ranges.end(); ++i) {
4482 framecnt_t const half = (i->start + i->end) / 2;
4484 /* find the line that this audio range starts in */
4485 list<Line>::iterator j = _lines.begin();
4486 while (j != _lines.end() && (j->range.first > i->start || j->range.second < i->start)) {
4490 if (j != _lines.end()) {
4491 boost::shared_ptr<AutomationList> the_list = j->line->the_list ();
4493 /* j is the line that this audio range starts in; fade into it;
4494 64 samples length plucked out of thin air.
4497 framepos_t a = i->start + 64;
4502 double const p = j->line->time_converter().from (i->start - j->line->time_converter().origin_b ());
4503 double const q = j->line->time_converter().from (a - j->line->time_converter().origin_b ());
4505 the_list->add (p, the_list->eval (p));
4506 the_list->add (q, the_list->eval (q));
4509 /* same thing for the end */
4512 while (j != _lines.end() && (j->range.first > i->end || j->range.second < i->end)) {
4516 if (j != _lines.end()) {
4517 boost::shared_ptr<AutomationList> the_list = j->line->the_list ();
4519 /* j is the line that this audio range starts in; fade out of it;
4520 64 samples length plucked out of thin air.
4523 framepos_t b = i->end - 64;
4528 double const p = j->line->time_converter().from (b - j->line->time_converter().origin_b ());
4529 double const q = j->line->time_converter().from (i->end - j->line->time_converter().origin_b ());
4531 the_list->add (p, the_list->eval (p));
4532 the_list->add (q, the_list->eval (q));
4536 _nothing_to_drag = true;
4538 /* Find all the points that should be dragged and put them in the relevant
4539 points lists in the Line structs.
4542 for (list<Line>::iterator i = _lines.begin(); i != _lines.end(); ++i) {
4544 uint32_t const N = i->line->npoints ();
4545 for (uint32_t j = 0; j < N; ++j) {
4547 /* here's a control point on this line */
4548 ControlPoint* p = i->line->nth (j);
4549 double const w = i->line->time_converter().to ((*p->model())->when) + i->line->time_converter().origin_b ();
4551 /* see if it's inside a range */
4552 list<AudioRange>::const_iterator k = _ranges.begin ();
4553 while (k != _ranges.end() && (k->start >= w || k->end <= w)) {
4557 if (k != _ranges.end()) {
4558 /* dragging this point */
4559 _nothing_to_drag = false;
4560 i->points.push_back (p);
4566 if (_nothing_to_drag) {
4570 for (list<Line>::iterator i = _lines.begin(); i != _lines.end(); ++i) {
4571 i->line->start_drag_multiple (i->points, y_fraction (i->line, _drags->current_pointer_y()), i->state);
4576 AutomationRangeDrag::motion (GdkEvent*, bool /*first_move*/)
4578 if (_nothing_to_drag) {
4582 for (list<Line>::iterator l = _lines.begin(); l != _lines.end(); ++l) {
4583 float const f = y_fraction (l->line, _drags->current_pointer_y());
4584 /* we are ignoring x position for this drag, so we can just pass in anything */
4586 l->line->drag_motion (0, f, true, false, ignored);
4587 show_verbose_cursor_text (l->line->get_verbose_cursor_relative_string (l->original_fraction, f));
4592 AutomationRangeDrag::finished (GdkEvent* event, bool)
4594 if (_nothing_to_drag) {
4598 motion (event, false);
4599 for (list<Line>::iterator i = _lines.begin(); i != _lines.end(); ++i) {
4600 i->line->end_drag (false, 0);
4603 _editor->session()->commit_reversible_command ();
4607 AutomationRangeDrag::aborted (bool)
4609 for (list<Line>::iterator i = _lines.begin(); i != _lines.end(); ++i) {
4614 DraggingView::DraggingView (RegionView* v, RegionDrag* parent)
4617 time_axis_view = parent->find_time_axis_view (&v->get_time_axis_view ());
4618 layer = v->region()->layer ();
4619 initial_y = v->get_canvas_group()->position().y;
4620 initial_playlist = v->region()->playlist ();
4621 initial_position = v->region()->position ();
4622 initial_end = v->region()->position () + v->region()->length ();
4625 PatchChangeDrag::PatchChangeDrag (Editor* e, PatchChange* i, MidiRegionView* r)
4626 : Drag (e, i->canvas_item ())
4629 , _cumulative_dx (0)
4631 DEBUG_TRACE (DEBUG::Drags, string_compose ("New PatchChangeDrag, patch @ %1, grab @ %2\n",
4632 _region_view->source_beats_to_absolute_frames (_patch_change->patch()->time()),
4637 PatchChangeDrag::motion (GdkEvent* ev, bool)
4639 framepos_t f = adjusted_current_frame (ev);
4640 boost::shared_ptr<Region> r = _region_view->region ();
4641 f = max (f, r->position ());
4642 f = min (f, r->last_frame ());
4644 framecnt_t const dxf = f - grab_frame(); // permitted dx in frames
4645 double const dxu = _editor->sample_to_pixel (dxf); // permitted fx in units
4646 _patch_change->move (ArdourCanvas::Duple (dxu - _cumulative_dx, 0));
4647 _cumulative_dx = dxu;
4651 PatchChangeDrag::finished (GdkEvent* ev, bool movement_occurred)
4653 if (!movement_occurred) {
4657 boost::shared_ptr<Region> r (_region_view->region ());
4658 framepos_t f = adjusted_current_frame (ev);
4659 f = max (f, r->position ());
4660 f = min (f, r->last_frame ());
4662 _region_view->move_patch_change (
4664 _region_view->region_frames_to_region_beats (f - (r->position() - r->start()))
4669 PatchChangeDrag::aborted (bool)
4671 _patch_change->move (ArdourCanvas::Duple (-_cumulative_dx, 0));
4675 PatchChangeDrag::setup_pointer_frame_offset ()
4677 boost::shared_ptr<Region> region = _region_view->region ();
4678 _pointer_frame_offset = raw_grab_frame() - _region_view->source_beats_to_absolute_frames (_patch_change->patch()->time());
4681 MidiRubberbandSelectDrag::MidiRubberbandSelectDrag (Editor* e, MidiRegionView* rv)
4682 : RubberbandSelectDrag (e, rv->get_canvas_group ())
4689 MidiRubberbandSelectDrag::select_things (int button_state, framepos_t x1, framepos_t x2, double y1, double y2, bool /*drag_in_progress*/)
4691 framepos_t const p = _region_view->region()->position ();
4692 double const y = _region_view->midi_view()->y_position ();
4694 x1 = max ((framepos_t) 0, x1 - p);
4695 x2 = max ((framepos_t) 0, x2 - p);
4696 y1 = max (0.0, y1 - y);
4697 y2 = max (0.0, y2 - y);
4699 _region_view->update_drag_selection (
4700 _editor->sample_to_pixel (x1),
4701 _editor->sample_to_pixel (x2),
4704 Keyboard::modifier_state_contains (button_state, Keyboard::TertiaryModifier)
4709 MidiRubberbandSelectDrag::deselect_things ()
4714 MidiVerticalSelectDrag::MidiVerticalSelectDrag (Editor* e, MidiRegionView* rv)
4715 : RubberbandSelectDrag (e, rv->get_canvas_group ())
4718 _vertical_only = true;
4722 MidiVerticalSelectDrag::select_things (int button_state, framepos_t /*x1*/, framepos_t /*x2*/, double y1, double y2, bool /*drag_in_progress*/)
4724 double const y = _region_view->midi_view()->y_position ();
4726 y1 = max (0.0, y1 - y);
4727 y2 = max (0.0, y2 - y);
4729 _region_view->update_vertical_drag_selection (
4732 Keyboard::modifier_state_contains (button_state, Keyboard::TertiaryModifier)
4737 MidiVerticalSelectDrag::deselect_things ()
4742 EditorRubberbandSelectDrag::EditorRubberbandSelectDrag (Editor* e, ArdourCanvas::Item* i)
4743 : RubberbandSelectDrag (e, i)
4749 EditorRubberbandSelectDrag::select_things (int button_state, framepos_t x1, framepos_t x2, double y1, double y2, bool drag_in_progress)
4751 if (drag_in_progress) {
4752 /* We just want to select things at the end of the drag, not during it */
4756 Selection::Operation op = ArdourKeyboard::selection_type (button_state);
4758 _editor->begin_reversible_command (_("rubberband selection"));
4759 _editor->select_all_within (x1, x2 - 1, y1, y2, _editor->track_views, op, false);
4760 _editor->commit_reversible_command ();
4764 EditorRubberbandSelectDrag::deselect_things ()
4766 if (!getenv("ARDOUR_SAE")) {
4767 _editor->selection->clear_tracks();
4769 _editor->selection->clear_regions();
4770 _editor->selection->clear_points ();
4771 _editor->selection->clear_lines ();
4774 NoteCreateDrag::NoteCreateDrag (Editor* e, ArdourCanvas::Item* i, MidiRegionView* rv)
4782 NoteCreateDrag::~NoteCreateDrag ()
4788 NoteCreateDrag::grid_frames (framepos_t t) const
4791 Evoral::MusicalTime grid_beats = _editor->get_grid_type_as_beats (success, t);
4796 return _region_view->region_beats_to_region_frames (grid_beats);
4800 NoteCreateDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
4802 Drag::start_grab (event, cursor);
4804 _drag_rect = new ArdourCanvas::Rectangle (_region_view->get_canvas_group ());
4806 framepos_t pf = _drags->current_pointer_frame ();
4807 framecnt_t const g = grid_frames (pf);
4809 /* Hack so that we always snap to the note that we are over, instead of snapping
4810 to the next one if we're more than halfway through the one we're over.
4812 if (_editor->snap_mode() == SnapNormal && pf > g / 2) {
4816 _note[0] = adjusted_frame (pf, event) - _region_view->region()->position ();
4818 MidiStreamView* sv = _region_view->midi_stream_view ();
4819 double const x = _editor->sample_to_pixel (_note[0]);
4820 double const y = sv->note_to_y (sv->y_to_note (y_to_region (event->button.y)));
4822 _drag_rect->set (ArdourCanvas::Rect (x, y, x, y + floor (_region_view->midi_stream_view()->note_height ())));
4823 _drag_rect->set_outline_what (0xff);
4824 _drag_rect->set_outline_color (0xffffff99);
4825 _drag_rect->set_fill_color (0xffffff66);
4829 NoteCreateDrag::motion (GdkEvent* event, bool)
4831 _note[1] = max ((framepos_t)0, adjusted_current_frame (event) - _region_view->region()->position ());
4832 double const x = _editor->sample_to_pixel (_note[1]);
4833 if (_note[1] > _note[0]) {
4834 _drag_rect->set_x1 (x);
4836 _drag_rect->set_x0 (x);
4841 NoteCreateDrag::finished (GdkEvent*, bool had_movement)
4843 if (!had_movement) {
4847 framepos_t const start = min (_note[0], _note[1]);
4848 framecnt_t length = (framecnt_t) fabs (_note[0] - _note[1]);
4850 framecnt_t const g = grid_frames (start);
4851 double const one_tick = 1 / Timecode::BBT_Time::ticks_per_beat;
4853 if (_editor->snap_mode() == SnapNormal && length < g) {
4854 length = g - one_tick;
4857 double const length_beats = max (one_tick, _region_view->region_frames_to_region_beats (length));
4859 _region_view->create_note_at (start, _drag_rect->y0(), length_beats, false);
4863 NoteCreateDrag::y_to_region (double y) const
4866 _region_view->get_canvas_group()->canvas_to_item (x, y);
4871 NoteCreateDrag::aborted (bool)
4876 CrossfadeEdgeDrag::CrossfadeEdgeDrag (Editor* e, AudioRegionView* rv, ArdourCanvas::Item* i, bool start_yn)
4881 std::cout << ("CrossfadeEdgeDrag is DEPRECATED. See TrimDrag::preserve_fade_anchor") << endl;
4885 CrossfadeEdgeDrag::start_grab (GdkEvent* event, Gdk::Cursor *cursor)
4887 Drag::start_grab (event, cursor);
4891 CrossfadeEdgeDrag::motion (GdkEvent*, bool)
4897 boost::shared_ptr<AudioRegion> ar (arv->audio_region());
4900 distance = _drags->current_pointer_x() - grab_x();
4901 len = ar->fade_in()->back()->when;
4903 distance = grab_x() - _drags->current_pointer_x();
4904 len = ar->fade_out()->back()->when;
4907 /* how long should it be ? */
4909 new_length = len + _editor->pixel_to_sample (distance);
4911 /* now check with the region that this is legal */
4913 new_length = ar->verify_xfade_bounds (new_length, start);
4916 arv->reset_fade_in_shape_width (ar, new_length);
4918 arv->reset_fade_out_shape_width (ar, new_length);
4923 CrossfadeEdgeDrag::finished (GdkEvent*, bool)
4929 boost::shared_ptr<AudioRegion> ar (arv->audio_region());
4932 distance = _drags->current_pointer_x() - grab_x();
4933 len = ar->fade_in()->back()->when;
4935 distance = grab_x() - _drags->current_pointer_x();
4936 len = ar->fade_out()->back()->when;
4939 new_length = ar->verify_xfade_bounds (len + _editor->pixel_to_sample (distance), start);
4941 _editor->begin_reversible_command ("xfade trim");
4942 ar->playlist()->clear_owned_changes ();
4945 ar->set_fade_in_length (new_length);
4947 ar->set_fade_out_length (new_length);
4950 /* Adjusting the xfade may affect other regions in the playlist, so we need
4951 to get undo Commands from the whole playlist rather than just the
4955 vector<Command*> cmds;
4956 ar->playlist()->rdiff (cmds);
4957 _editor->session()->add_commands (cmds);
4958 _editor->commit_reversible_command ();
4963 CrossfadeEdgeDrag::aborted (bool)
4966 arv->redraw_start_xfade ();
4968 arv->redraw_end_xfade ();