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_sample (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_sample (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->canvas_event_sample (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_sample (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 _editor->maybe_autoscroll (true, allow_vertical_autoscroll (), false);
367 if (!_editor->autoscroll_active() || from_autoscroll) {
368 motion (event, _move_threshold_passed != old_move_threshold_passed);
370 _last_pointer_x = _drags->current_pointer_x ();
371 _last_pointer_y = _drags->current_pointer_y ();
372 _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,
401 _drags->current_pointer_y() + 10
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,
415 _drags->current_pointer_y() + 10
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,
427 _drags->current_pointer_y() + 10
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 () < rb->route()->order_key ();
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)
525 , _last_pointer_time_axis_view (0)
526 , _last_pointer_layer (0)
528 DEBUG_TRACE (DEBUG::Drags, "New RegionMotionDrag\n");
532 RegionMotionDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
534 Drag::start_grab (event, cursor);
536 show_verbose_cursor_time (_last_frame_position);
538 pair<TimeAxisView*, double> const tv = _editor->trackview_by_y_position (_drags->current_pointer_y ());
540 _last_pointer_time_axis_view = find_time_axis_view (tv.first);
541 _last_pointer_layer = tv.first->layer_display() == Overlaid ? 0 : tv.second;
546 RegionMotionDrag::compute_x_delta (GdkEvent const * event, framepos_t* pending_region_position)
548 /* compute the amount of pointer motion in frames, and where
549 the region would be if we moved it by that much.
551 *pending_region_position = adjusted_current_frame (event);
553 framepos_t sync_frame;
554 framecnt_t sync_offset;
557 sync_offset = _primary->region()->sync_offset (sync_dir);
559 /* we don't handle a sync point that lies before zero.
561 if (sync_dir >= 0 || (sync_dir < 0 && *pending_region_position >= sync_offset)) {
563 sync_frame = *pending_region_position + (sync_dir*sync_offset);
565 _editor->snap_to_with_modifier (sync_frame, event);
567 *pending_region_position = _primary->region()->adjust_to_sync (sync_frame);
570 *pending_region_position = _last_frame_position;
573 if (*pending_region_position > max_framepos - _primary->region()->length()) {
574 *pending_region_position = _last_frame_position;
579 /* in locked edit mode, reverse the usual meaning of _x_constrained */
580 bool const x_move_allowed = Config->get_edit_mode() == Lock ? _x_constrained : !_x_constrained;
582 if ((*pending_region_position != _last_frame_position) && x_move_allowed) {
584 /* x movement since last time (in pixels) */
585 dx = (static_cast<double> (*pending_region_position) - _last_frame_position) / _editor->samples_per_pixel;
587 /* total x movement */
588 framecnt_t total_dx = *pending_region_position;
589 if (regions_came_from_canvas()) {
590 total_dx = total_dx - grab_frame ();
593 /* check that no regions have gone off the start of the session */
594 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
595 if ((i->view->region()->position() + total_dx) < 0) {
597 *pending_region_position = _last_frame_position;
602 _last_frame_position = *pending_region_position;
609 RegionMotionDrag::y_movement_allowed (int delta_track, double delta_layer) const
611 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
612 int const n = i->time_axis_view + delta_track;
613 if (n < 0 || n >= int (_time_axis_views.size())) {
614 /* off the top or bottom track */
618 RouteTimeAxisView const * to = dynamic_cast<RouteTimeAxisView const *> (_time_axis_views[n]);
619 if (to == 0 || !to->is_track() || to->track()->data_type() != i->view->region()->data_type()) {
620 /* not a track, or the wrong type */
624 double const l = i->layer + delta_layer;
626 /* Note that we allow layer to be up to 0.5 below zero, as this is used by `Expanded'
627 mode to allow the user to place a region below another on layer 0.
629 if (delta_track == 0 && (l < -0.5 || l >= int (to->view()->layers()))) {
630 /* Off the top or bottom layer; note that we only refuse if the track hasn't changed.
631 If it has, the layers will be munged later anyway, so it's ok.
637 /* all regions being dragged are ok with this change */
642 RegionMotionDrag::motion (GdkEvent* event, bool first_move)
644 assert (!_views.empty ());
646 /* Find the TimeAxisView that the pointer is now over */
647 pair<TimeAxisView*, double> const tv = _editor->trackview_by_y_position (_drags->current_pointer_y ());
649 /* Bail early if we're not over a track */
650 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (tv.first);
652 if (!rtv || !rtv->is_track()) {
653 _editor->verbose_cursor()->hide ();
657 if (first_move && tv.first->view()->layer_display() == Stacked) {
658 tv.first->view()->set_layer_display (Expanded);
661 /* Note: time axis views in this method are often expressed as an index into the _time_axis_views vector */
663 /* Here's the current pointer position in terms of time axis view and layer */
664 int const current_pointer_time_axis_view = find_time_axis_view (tv.first);
665 double const current_pointer_layer = tv.first->layer_display() == Overlaid ? 0 : tv.second;
667 /* Work out the change in x */
668 framepos_t pending_region_position;
669 double const x_delta = compute_x_delta (event, &pending_region_position);
671 /* Work out the change in y */
673 int delta_time_axis_view = current_pointer_time_axis_view - _last_pointer_time_axis_view;
674 double delta_layer = current_pointer_layer - _last_pointer_layer;
676 if (!y_movement_allowed (delta_time_axis_view, delta_layer)) {
677 /* this y movement is not allowed, so do no y movement this time */
678 delta_time_axis_view = 0;
682 if (x_delta == 0 && delta_time_axis_view == 0 && delta_layer == 0 && !first_move) {
683 /* haven't reached next snap point, and we're not switching
684 trackviews nor layers. nothing to do.
689 pair<set<boost::shared_ptr<Playlist> >::iterator,bool> insert_result;
691 for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
693 RegionView* rv = i->view;
695 if (rv->region()->locked() || rv->region()->video_locked()) {
703 /* Reparent to a non scrolling group so that we can keep the
704 region selection above all time axis views.
705 Reparenting means that we will have to move the region view
706 within its new parent, as the two parent groups have different coordinates.
709 ArdourCanvas::Group* rvg = rv->get_canvas_group();
710 Duple rv_canvas_offset = rvg->item_to_canvas (Duple (0,0));
712 rv->get_canvas_group()->reparent (_editor->_region_motion_group);
714 rv->fake_set_opaque (true);
715 rvg->set_position (rv_canvas_offset);
718 /* If we have moved tracks, we'll fudge the layer delta so that the
719 region gets moved back onto layer 0 on its new track; this avoids
720 confusion when dragging regions from non-zero layers onto different
723 double this_delta_layer = delta_layer;
724 if (delta_time_axis_view != 0) {
725 this_delta_layer = - i->layer;
728 /* The TimeAxisView that this region is now on */
729 TimeAxisView* tv = _time_axis_views[i->time_axis_view + delta_time_axis_view];
731 /* Ensure it is moved from stacked -> expanded if appropriate */
732 if (tv->view()->layer_display() == Stacked) {
733 tv->view()->set_layer_display (Expanded);
736 /* We're only allowed to go -ve in layer on Expanded views */
737 if (tv->view()->layer_display() != Expanded && (i->layer + this_delta_layer) < 0) {
738 this_delta_layer = - i->layer;
742 rv->set_height (tv->view()->child_height ());
744 /* Update show/hidden status as the region view may have come from a hidden track,
745 or have moved to one.
748 rv->get_canvas_group()->hide ();
750 rv->get_canvas_group()->show ();
753 /* Update the DraggingView */
754 i->time_axis_view += delta_time_axis_view;
755 i->layer += this_delta_layer;
758 _editor->mouse_brush_insert_region (rv, pending_region_position);
763 /* Get the y coordinate of the top of the track that this region is now on */
764 tv->canvas_display()->item_to_canvas (x, y);
766 /* And adjust for the layer that it should be on */
767 StreamView* cv = tv->view ();
768 switch (cv->layer_display ()) {
772 y += (cv->layers() - i->layer - 1) * cv->child_height ();
775 y += (cv->layers() - i->layer - 0.5) * 2 * cv->child_height ();
779 /* Now move the region view */
780 rv->move (x_delta, y - rv->get_canvas_group()->position().y);
783 } /* foreach region */
785 _total_x_delta += x_delta;
787 if (x_delta != 0 && !_brushing) {
788 show_verbose_cursor_time (_last_frame_position);
791 _last_pointer_time_axis_view += delta_time_axis_view;
792 _last_pointer_layer += delta_layer;
796 RegionMoveDrag::motion (GdkEvent* event, bool first_move)
798 if (_copy && first_move) {
800 /* duplicate the regionview(s) and region(s) */
802 list<DraggingView> new_regionviews;
804 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
806 RegionView* rv = i->view;
807 AudioRegionView* arv = dynamic_cast<AudioRegionView*>(rv);
808 MidiRegionView* mrv = dynamic_cast<MidiRegionView*>(rv);
810 const boost::shared_ptr<const Region> original = rv->region();
811 boost::shared_ptr<Region> region_copy = RegionFactory::create (original, true);
812 region_copy->set_position (original->position());
816 boost::shared_ptr<AudioRegion> audioregion_copy
817 = boost::dynamic_pointer_cast<AudioRegion>(region_copy);
819 nrv = new AudioRegionView (*arv, audioregion_copy);
821 boost::shared_ptr<MidiRegion> midiregion_copy
822 = boost::dynamic_pointer_cast<MidiRegion>(region_copy);
823 nrv = new MidiRegionView (*mrv, midiregion_copy);
828 nrv->get_canvas_group()->show ();
829 new_regionviews.push_back (DraggingView (nrv, this));
831 /* swap _primary to the copy */
833 if (rv == _primary) {
837 /* ..and deselect the one we copied */
839 rv->set_selected (false);
842 if (!new_regionviews.empty()) {
844 /* reflect the fact that we are dragging the copies */
846 _views = new_regionviews;
848 swap_grab (new_regionviews.front().view->get_canvas_group (), 0, event ? event->motion.time : 0);
852 RegionMotionDrag::motion (event, first_move);
856 RegionMotionDrag::finished (GdkEvent *, bool)
858 for (vector<TimeAxisView*>::iterator i = _time_axis_views.begin(); i != _time_axis_views.end(); ++i) {
863 if ((*i)->view()->layer_display() == Expanded) {
864 (*i)->view()->set_layer_display (Stacked);
870 RegionMoveDrag::finished (GdkEvent* ev, bool movement_occurred)
872 RegionMotionDrag::finished (ev, movement_occurred);
874 if (!movement_occurred) {
878 if (was_double_click() && !_views.empty()) {
879 DraggingView dv = _views.front();
880 dv.view->show_region_editor ();
887 /* reverse this here so that we have the correct logic to finalize
891 if (Config->get_edit_mode() == Lock) {
892 _x_constrained = !_x_constrained;
895 assert (!_views.empty ());
897 /* We might have hidden region views so that they weren't visible during the drag
898 (when they have been reparented). Now everything can be shown again, as region
899 views are back in their track parent groups.
901 for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
902 i->view->get_canvas_group()->show ();
905 bool const changed_position = (_last_frame_position != _primary->region()->position());
906 bool const changed_tracks = (_time_axis_views[_views.front().time_axis_view] != &_views.front().view->get_time_axis_view());
907 framecnt_t const drag_delta = _primary->region()->position() - _last_frame_position;
927 _editor->maybe_locate_with_edit_preroll (_editor->get_selection().regions.start());
931 RegionMoveDrag::finished_copy (bool const changed_position, bool const /*changed_tracks*/, framecnt_t const drag_delta)
933 RegionSelection new_views;
934 PlaylistSet modified_playlists;
935 list<RegionView*> views_to_delete;
938 /* all changes were made during motion event handlers */
940 for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
944 _editor->commit_reversible_command ();
948 if (_x_constrained) {
949 _editor->begin_reversible_command (Operations::fixed_time_region_copy);
951 _editor->begin_reversible_command (Operations::region_copy);
954 /* insert the regions into their new playlists */
955 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
957 if (i->view->region()->locked() || i->view->region()->video_locked()) {
963 if (changed_position && !_x_constrained) {
964 where = i->view->region()->position() - drag_delta;
966 where = i->view->region()->position();
969 RegionView* new_view = insert_region_into_playlist (
970 i->view->region(), dynamic_cast<RouteTimeAxisView*> (_time_axis_views[i->time_axis_view]), i->layer, where, modified_playlists
977 new_views.push_back (new_view);
979 /* we don't need the copied RegionView any more */
980 views_to_delete.push_back (i->view);
983 /* Delete views that are no longer needed; we can't do this directly in the iteration over _views
984 because when views are deleted they are automagically removed from _views, which messes
987 for (list<RegionView*>::iterator i = views_to_delete.begin(); i != views_to_delete.end(); ++i) {
991 /* If we've created new regions either by copying or moving
992 to a new track, we want to replace the old selection with the new ones
995 if (new_views.size() > 0) {
996 _editor->selection->set (new_views);
999 /* write commands for the accumulated diffs for all our modified playlists */
1000 add_stateful_diff_commands_for_playlists (modified_playlists);
1002 _editor->commit_reversible_command ();
1006 RegionMoveDrag::finished_no_copy (
1007 bool const changed_position,
1008 bool const changed_tracks,
1009 framecnt_t const drag_delta
1012 RegionSelection new_views;
1013 PlaylistSet modified_playlists;
1014 PlaylistSet frozen_playlists;
1015 set<RouteTimeAxisView*> views_to_update;
1018 /* all changes were made during motion event handlers */
1019 _editor->commit_reversible_command ();
1023 if (_x_constrained) {
1024 _editor->begin_reversible_command (_("fixed time region drag"));
1026 _editor->begin_reversible_command (Operations::region_drag);
1029 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ) {
1031 RegionView* rv = i->view;
1033 RouteTimeAxisView* const dest_rtv = dynamic_cast<RouteTimeAxisView*> (_time_axis_views[i->time_axis_view]);
1034 double const dest_layer = i->layer;
1036 if (rv->region()->locked() || rv->region()->video_locked()) {
1041 views_to_update.insert (dest_rtv);
1045 if (changed_position && !_x_constrained) {
1046 where = rv->region()->position() - drag_delta;
1048 where = rv->region()->position();
1051 if (changed_tracks) {
1053 /* insert into new playlist */
1055 RegionView* new_view = insert_region_into_playlist (
1056 RegionFactory::create (rv->region (), true), dest_rtv, dest_layer, where, modified_playlists
1059 if (new_view == 0) {
1064 new_views.push_back (new_view);
1066 /* remove from old playlist */
1068 /* the region that used to be in the old playlist is not
1069 moved to the new one - we use a copy of it. as a result,
1070 any existing editor for the region should no longer be
1073 rv->hide_region_editor();
1074 rv->fake_set_opaque (false);
1076 remove_region_from_playlist (rv->region(), i->initial_playlist, modified_playlists);
1080 rv->region()->clear_changes ();
1083 motion on the same track. plonk the previously reparented region
1084 back to its original canvas group (its streamview).
1085 No need to do anything for copies as they are fake regions which will be deleted.
1088 rv->get_canvas_group()->reparent (dest_rtv->view()->canvas_item());
1089 rv->get_canvas_group()->set_y_position (i->initial_y);
1092 /* just change the model */
1094 boost::shared_ptr<Playlist> playlist = dest_rtv->playlist();
1096 if (dest_rtv->view()->layer_display() == Stacked || dest_rtv->view()->layer_display() == Expanded) {
1097 playlist->set_layer (rv->region(), dest_layer);
1100 /* freeze playlist to avoid lots of relayering in the case of a multi-region drag */
1102 pair<PlaylistSet::iterator, bool> r = frozen_playlists.insert (playlist);
1105 playlist->freeze ();
1108 /* this movement may result in a crossfade being modified, so we need to get undo
1109 data from the playlist as well as the region.
1112 r = modified_playlists.insert (playlist);
1114 playlist->clear_changes ();
1117 rv->region()->set_position (where);
1119 _editor->session()->add_command (new StatefulDiffCommand (rv->region()));
1122 if (changed_tracks) {
1124 /* OK, this is where it gets tricky. If the playlist was being used by >1 tracks, and the region
1125 was selected in all of them, then removing it from a playlist will have removed all
1126 trace of it from _views (i.e. there were N regions selected, we removed 1,
1127 but since its the same playlist for N tracks, all N tracks updated themselves, removed the
1128 corresponding regionview, and _views is now empty).
1130 This could have invalidated any and all iterators into _views.
1132 The heuristic we use here is: if the region selection is empty, break out of the loop
1133 here. if the region selection is not empty, then restart the loop because we know that
1134 we must have removed at least the region(view) we've just been working on as well as any
1135 that we processed on previous iterations.
1137 EXCEPT .... if we are doing a copy drag, then _views hasn't been modified and
1138 we can just iterate.
1142 if (_views.empty()) {
1153 /* If we've created new regions either by copying or moving
1154 to a new track, we want to replace the old selection with the new ones
1157 if (new_views.size() > 0) {
1158 _editor->selection->set (new_views);
1161 for (set<boost::shared_ptr<Playlist> >::iterator p = frozen_playlists.begin(); p != frozen_playlists.end(); ++p) {
1165 /* write commands for the accumulated diffs for all our modified playlists */
1166 add_stateful_diff_commands_for_playlists (modified_playlists);
1168 _editor->commit_reversible_command ();
1170 /* We have futzed with the layering of canvas items on our streamviews.
1171 If any region changed layer, this will have resulted in the stream
1172 views being asked to set up their region views, and all will be well.
1173 If not, we might now have badly-ordered region views. Ask the StreamViews
1174 involved to sort themselves out, just in case.
1177 for (set<RouteTimeAxisView*>::iterator i = views_to_update.begin(); i != views_to_update.end(); ++i) {
1178 (*i)->view()->playlist_layered ((*i)->track ());
1182 /** Remove a region from a playlist, clearing the diff history of the playlist first if necessary.
1183 * @param region Region to remove.
1184 * @param playlist playlist To remove from.
1185 * @param modified_playlists The playlist will be added to this if it is not there already; used to ensure
1186 * that clear_changes () is only called once per playlist.
1189 RegionMoveDrag::remove_region_from_playlist (
1190 boost::shared_ptr<Region> region,
1191 boost::shared_ptr<Playlist> playlist,
1192 PlaylistSet& modified_playlists
1195 pair<set<boost::shared_ptr<Playlist> >::iterator, bool> r = modified_playlists.insert (playlist);
1198 playlist->clear_changes ();
1201 playlist->remove_region (region);
1205 /** Insert a region into a playlist, handling the recovery of the resulting new RegionView, and
1206 * clearing the playlist's diff history first if necessary.
1207 * @param region Region to insert.
1208 * @param dest_rtv Destination RouteTimeAxisView.
1209 * @param dest_layer Destination layer.
1210 * @param where Destination position.
1211 * @param modified_playlists The playlist will be added to this if it is not there already; used to ensure
1212 * that clear_changes () is only called once per playlist.
1213 * @return New RegionView, or 0 if no insert was performed.
1216 RegionMoveDrag::insert_region_into_playlist (
1217 boost::shared_ptr<Region> region,
1218 RouteTimeAxisView* dest_rtv,
1221 PlaylistSet& modified_playlists
1224 boost::shared_ptr<Playlist> dest_playlist = dest_rtv->playlist ();
1225 if (!dest_playlist) {
1229 /* arrange to collect the new region view that will be created as a result of our playlist insertion */
1230 _new_region_view = 0;
1231 sigc::connection c = dest_rtv->view()->RegionViewAdded.connect (sigc::mem_fun (*this, &RegionMoveDrag::collect_new_region_view));
1233 /* clear history for the playlist we are about to insert to, provided we haven't already done so */
1234 pair<PlaylistSet::iterator, bool> r = modified_playlists.insert (dest_playlist);
1236 dest_playlist->clear_changes ();
1239 dest_playlist->add_region (region, where);
1241 if (dest_rtv->view()->layer_display() == Stacked || dest_rtv->view()->layer_display() == Expanded) {
1242 dest_playlist->set_layer (region, dest_layer);
1247 assert (_new_region_view);
1249 return _new_region_view;
1253 RegionMoveDrag::collect_new_region_view (RegionView* rv)
1255 _new_region_view = rv;
1259 RegionMoveDrag::add_stateful_diff_commands_for_playlists (PlaylistSet const & playlists)
1261 for (PlaylistSet::const_iterator i = playlists.begin(); i != playlists.end(); ++i) {
1262 StatefulDiffCommand* c = new StatefulDiffCommand (*i);
1264 _editor->session()->add_command (c);
1273 RegionMoveDrag::aborted (bool movement_occurred)
1277 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
1284 RegionMotionDrag::aborted (movement_occurred);
1289 RegionMotionDrag::aborted (bool)
1291 for (vector<TimeAxisView*>::iterator i = _time_axis_views.begin(); i != _time_axis_views.end(); ++i) {
1293 StreamView* sview = (*i)->view();
1296 if (sview->layer_display() == Expanded) {
1297 sview->set_layer_display (Stacked);
1302 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
1303 RegionView* rv = i->view;
1304 TimeAxisView* tv = &(rv->get_time_axis_view ());
1305 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (tv);
1307 rv->get_canvas_group()->reparent (rtv->view()->canvas_item());
1308 rv->get_canvas_group()->set_y_position (0);
1310 rv->fake_set_opaque (false);
1311 rv->move (-_total_x_delta, 0);
1312 rv->set_height (rtv->view()->child_height ());
1316 /** @param b true to brush, otherwise false.
1317 * @param c true to make copies of the regions being moved, otherwise false.
1319 RegionMoveDrag::RegionMoveDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, list<RegionView*> const & v, bool b, bool c)
1320 : RegionMotionDrag (e, i, p, v, b),
1323 DEBUG_TRACE (DEBUG::Drags, "New RegionMoveDrag\n");
1326 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (&_primary->get_time_axis_view ());
1327 if (rtv && rtv->is_track()) {
1328 speed = rtv->track()->speed ();
1331 _last_frame_position = static_cast<framepos_t> (_primary->region()->position() / speed);
1335 RegionMoveDrag::setup_pointer_frame_offset ()
1337 _pointer_frame_offset = raw_grab_frame() - _last_frame_position;
1340 RegionInsertDrag::RegionInsertDrag (Editor* e, boost::shared_ptr<Region> r, RouteTimeAxisView* v, framepos_t pos)
1341 : RegionMotionDrag (e, 0, 0, list<RegionView*> (), false)
1343 DEBUG_TRACE (DEBUG::Drags, "New RegionInsertDrag\n");
1345 assert ((boost::dynamic_pointer_cast<AudioRegion> (r) && dynamic_cast<AudioTimeAxisView*> (v)) ||
1346 (boost::dynamic_pointer_cast<MidiRegion> (r) && dynamic_cast<MidiTimeAxisView*> (v)));
1348 _primary = v->view()->create_region_view (r, false, false);
1350 _primary->get_canvas_group()->show ();
1351 _primary->set_position (pos, 0);
1352 _views.push_back (DraggingView (_primary, this));
1354 _last_frame_position = pos;
1356 _item = _primary->get_canvas_group ();
1360 RegionInsertDrag::finished (GdkEvent *, bool)
1362 RouteTimeAxisView* dest_rtv = dynamic_cast<RouteTimeAxisView*> (_time_axis_views[_views.front().time_axis_view]);
1364 _primary->get_canvas_group()->reparent (dest_rtv->view()->canvas_item());
1365 _primary->get_canvas_group()->set_y_position (0);
1367 boost::shared_ptr<Playlist> playlist = dest_rtv->playlist();
1369 _editor->begin_reversible_command (Operations::insert_region);
1370 playlist->clear_changes ();
1371 playlist->add_region (_primary->region (), _last_frame_position);
1372 _editor->session()->add_command (new StatefulDiffCommand (playlist));
1373 _editor->commit_reversible_command ();
1381 RegionInsertDrag::aborted (bool)
1388 RegionSpliceDrag::RegionSpliceDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, list<RegionView*> const & v)
1389 : RegionMoveDrag (e, i, p, v, false, false)
1391 DEBUG_TRACE (DEBUG::Drags, "New RegionSpliceDrag\n");
1394 struct RegionSelectionByPosition {
1395 bool operator() (RegionView*a, RegionView* b) {
1396 return a->region()->position () < b->region()->position();
1401 RegionSpliceDrag::motion (GdkEvent* event, bool)
1403 /* Which trackview is this ? */
1405 pair<TimeAxisView*, double> const tvp = _editor->trackview_by_y_position (_drags->current_pointer_y ());
1406 RouteTimeAxisView* tv = dynamic_cast<RouteTimeAxisView*> (tvp.first);
1408 /* The region motion is only processed if the pointer is over
1412 if (!tv || !tv->is_track()) {
1413 /* To make sure we hide the verbose canvas cursor when the mouse is
1414 not held over and audiotrack.
1416 _editor->verbose_cursor()->hide ();
1422 if ((_drags->current_pointer_x() - last_pointer_x()) > 0) {
1428 RegionSelection copy (_editor->selection->regions);
1430 RegionSelectionByPosition cmp;
1433 framepos_t const pf = adjusted_current_frame (event);
1435 for (RegionSelection::iterator i = copy.begin(); i != copy.end(); ++i) {
1437 RouteTimeAxisView* atv = dynamic_cast<RouteTimeAxisView*> (&(*i)->get_time_axis_view());
1443 boost::shared_ptr<Playlist> playlist;
1445 if ((playlist = atv->playlist()) == 0) {
1449 if (!playlist->region_is_shuffle_constrained ((*i)->region())) {
1454 if (pf < (*i)->region()->last_frame() + 1) {
1458 if (pf > (*i)->region()->first_frame()) {
1464 playlist->shuffle ((*i)->region(), dir);
1469 RegionSpliceDrag::finished (GdkEvent* event, bool movement_occurred)
1471 RegionMoveDrag::finished (event, movement_occurred);
1475 RegionSpliceDrag::aborted (bool)
1480 RegionCreateDrag::RegionCreateDrag (Editor* e, ArdourCanvas::Item* i, TimeAxisView* v)
1482 _view (dynamic_cast<MidiTimeAxisView*> (v))
1484 DEBUG_TRACE (DEBUG::Drags, "New RegionCreateDrag\n");
1490 RegionCreateDrag::motion (GdkEvent* event, bool first_move)
1493 _region = add_midi_region (_view);
1494 _view->playlist()->freeze ();
1497 framepos_t const f = adjusted_current_frame (event);
1498 if (f < grab_frame()) {
1499 _region->set_position (f);
1502 /* Don't use a zero-length region, and subtract 1 frame from the snapped length
1503 so that if this region is duplicated, its duplicate starts on
1504 a snap point rather than 1 frame after a snap point. Otherwise things get
1505 a bit confusing as if a region starts 1 frame after a snap point, one cannot
1506 place snapped notes at the start of the region.
1509 framecnt_t const len = (framecnt_t) fabs ((double)(f - grab_frame () - 1));
1510 _region->set_length (len < 1 ? 1 : len);
1516 RegionCreateDrag::finished (GdkEvent*, bool movement_occurred)
1518 if (!movement_occurred) {
1519 add_midi_region (_view);
1521 _view->playlist()->thaw ();
1526 RegionCreateDrag::aborted (bool)
1529 _view->playlist()->thaw ();
1535 NoteResizeDrag::NoteResizeDrag (Editor* e, ArdourCanvas::Item* i)
1539 DEBUG_TRACE (DEBUG::Drags, "New NoteResizeDrag\n");
1543 NoteResizeDrag::start_grab (GdkEvent* event, Gdk::Cursor* /*ignored*/)
1545 Gdk::Cursor* cursor;
1546 NoteBase* cnote = reinterpret_cast<NoteBase*> (_item->get_data ("notebase"));
1548 float x_fraction = cnote->mouse_x_fraction ();
1550 if (x_fraction > 0.0 && x_fraction < 0.25) {
1551 cursor = _editor->cursors()->left_side_trim;
1553 cursor = _editor->cursors()->right_side_trim;
1556 Drag::start_grab (event, cursor);
1558 region = &cnote->region_view();
1560 double const region_start = region->get_position_pixels();
1561 double const middle_point = region_start + cnote->x0() + (cnote->x1() - cnote->x0()) / 2.0L;
1563 if (grab_x() <= middle_point) {
1564 cursor = _editor->cursors()->left_side_trim;
1567 cursor = _editor->cursors()->right_side_trim;
1573 if (event->motion.state & Keyboard::PrimaryModifier) {
1579 MidiRegionSelection& ms (_editor->get_selection().midi_regions);
1581 if (ms.size() > 1) {
1582 /* has to be relative, may make no sense otherwise */
1586 /* select this note; if it is already selected, preserve the existing selection,
1587 otherwise make this note the only one selected.
1589 region->note_selected (cnote, cnote->selected ());
1591 for (MidiRegionSelection::iterator r = ms.begin(); r != ms.end(); ) {
1592 MidiRegionSelection::iterator next;
1595 (*r)->begin_resizing (at_front);
1601 NoteResizeDrag::motion (GdkEvent* /*event*/, bool /*first_move*/)
1603 MidiRegionSelection& ms (_editor->get_selection().midi_regions);
1604 for (MidiRegionSelection::iterator r = ms.begin(); r != ms.end(); ++r) {
1605 NoteBase* nb = reinterpret_cast<NoteBase*> (_item->get_data ("notebase"));
1607 (*r)->update_resizing (nb, at_front, _drags->current_pointer_x() - grab_x(), relative);
1612 NoteResizeDrag::finished (GdkEvent*, bool /*movement_occurred*/)
1614 MidiRegionSelection& ms (_editor->get_selection().midi_regions);
1615 for (MidiRegionSelection::iterator r = ms.begin(); r != ms.end(); ++r) {
1616 NoteBase* nb = reinterpret_cast<NoteBase*> (_item->get_data ("notebase"));
1618 (*r)->commit_resizing (nb, at_front, _drags->current_pointer_x() - grab_x(), relative);
1623 NoteResizeDrag::aborted (bool)
1625 MidiRegionSelection& ms (_editor->get_selection().midi_regions);
1626 for (MidiRegionSelection::iterator r = ms.begin(); r != ms.end(); ++r) {
1627 (*r)->abort_resizing ();
1631 AVDraggingView::AVDraggingView (RegionView* v)
1634 initial_position = v->region()->position ();
1637 VideoTimeLineDrag::VideoTimeLineDrag (Editor* e, ArdourCanvas::Item* i)
1640 DEBUG_TRACE (DEBUG::Drags, "New VideoTimeLineDrag\n");
1643 TrackViewList empty;
1645 _editor->get_regions_after(rs, (framepos_t) 0, empty);
1646 std::list<RegionView*> views = rs.by_layer();
1648 for (list<RegionView*>::iterator i = views.begin(); i != views.end(); ++i) {
1649 RegionView* rv = (*i);
1650 if (!rv->region()->video_locked()) {
1653 _views.push_back (AVDraggingView (rv));
1658 VideoTimeLineDrag::start_grab (GdkEvent* event, Gdk::Cursor*)
1660 Drag::start_grab (event);
1661 if (_editor->session() == 0) {
1665 _startdrag_video_offset=ARDOUR_UI::instance()->video_timeline->get_offset();
1666 _max_backwards_drag = (
1667 ARDOUR_UI::instance()->video_timeline->get_duration()
1668 + ARDOUR_UI::instance()->video_timeline->get_offset()
1669 - ceil(ARDOUR_UI::instance()->video_timeline->get_apv())
1672 for (list<AVDraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
1673 if (i->initial_position < _max_backwards_drag || _max_backwards_drag < 0) {
1674 _max_backwards_drag = ARDOUR_UI::instance()->video_timeline->quantify_frames_to_apv (i->initial_position);
1677 DEBUG_TRACE (DEBUG::Drags, string_compose("VideoTimeLineDrag: max backwards-drag: %1\n", _max_backwards_drag));
1680 Timecode::Time timecode;
1681 _editor->session()->sample_to_timecode(abs(_startdrag_video_offset), timecode, true /* use_offset */, false /* use_subframes */ );
1682 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);
1683 _editor->verbose_cursor()->set(buf, event->button.x + 10, event->button.y + 10);
1684 _editor->verbose_cursor()->show ();
1688 VideoTimeLineDrag::motion (GdkEvent* event, bool first_move)
1690 if (_editor->session() == 0) {
1693 if (ARDOUR_UI::instance()->video_timeline->is_offset_locked()) {
1697 framecnt_t dt = adjusted_current_frame (event) - raw_grab_frame() + _pointer_frame_offset;
1698 dt = ARDOUR_UI::instance()->video_timeline->quantify_frames_to_apv(_startdrag_video_offset+dt) - _startdrag_video_offset;
1700 if (_max_backwards_drag >= 0 && dt <= - _max_backwards_drag) {
1701 dt = - _max_backwards_drag;
1704 ARDOUR_UI::instance()->video_timeline->set_offset(_startdrag_video_offset+dt);
1705 ARDOUR_UI::instance()->flush_videotimeline_cache(true);
1707 for (list<AVDraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
1708 RegionView* rv = i->view;
1709 DEBUG_TRACE (DEBUG::Drags, string_compose("SHIFT REGION at %1 by %2\n", i->initial_position, dt));
1712 rv->fake_set_opaque (true);
1713 rv->region()->clear_changes ();
1714 rv->region()->suspend_property_changes();
1716 rv->region()->set_position(i->initial_position + dt);
1717 rv->region_changed(ARDOUR::Properties::position);
1720 const framepos_t offset = ARDOUR_UI::instance()->video_timeline->get_offset();
1721 Timecode::Time timecode;
1722 Timecode::Time timediff;
1724 _editor->session()->sample_to_timecode(abs(offset), timecode, true /* use_offset */, false /* use_subframes */ );
1725 _editor->session()->sample_to_timecode(abs(dt), timediff, false /* use_offset */, false /* use_subframes */ );
1726 snprintf (buf, sizeof (buf),
1727 "%s\n%c%02" PRId32 ":%02" PRId32 ":%02" PRId32 ":%02" PRId32
1728 "\n%s\n%c%02" PRId32 ":%02" PRId32 ":%02" PRId32 ":%02" PRId32
1729 , _("Video Start:"),
1730 (offset<0?'-':' '), timecode.hours, timecode.minutes, timecode.seconds, timecode.frames
1732 (dt<0?'-':' '), timediff.hours, timediff.minutes, timediff.seconds, timediff.frames
1734 _editor->verbose_cursor()->set(buf, event->button.x + 10, event->button.y + 10);
1735 _editor->verbose_cursor()->show ();
1739 VideoTimeLineDrag::finished (GdkEvent * /*event*/, bool movement_occurred)
1741 if (ARDOUR_UI::instance()->video_timeline->is_offset_locked()) {
1745 if (!movement_occurred || ! _editor->session()) {
1749 ARDOUR_UI::instance()->flush_videotimeline_cache(true);
1751 _editor->begin_reversible_command (_("Move Video"));
1753 XMLNode &before = ARDOUR_UI::instance()->video_timeline->get_state();
1754 ARDOUR_UI::instance()->video_timeline->save_undo();
1755 XMLNode &after = ARDOUR_UI::instance()->video_timeline->get_state();
1756 _editor->session()->add_command(new MementoCommand<VideoTimeLine>(*(ARDOUR_UI::instance()->video_timeline), &before, &after));
1758 for (list<AVDraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
1759 i->view->drag_end();
1760 i->view->fake_set_opaque (false);
1761 i->view->region()->resume_property_changes ();
1763 _editor->session()->add_command (new StatefulDiffCommand (i->view->region()));
1766 _editor->session()->maybe_update_session_range(
1767 std::max(ARDOUR_UI::instance()->video_timeline->get_offset(), (ARDOUR::frameoffset_t) 0),
1768 std::max(ARDOUR_UI::instance()->video_timeline->get_offset() + ARDOUR_UI::instance()->video_timeline->get_duration(), (ARDOUR::frameoffset_t) 0)
1772 _editor->commit_reversible_command ();
1776 VideoTimeLineDrag::aborted (bool)
1778 if (ARDOUR_UI::instance()->video_timeline->is_offset_locked()) {
1781 ARDOUR_UI::instance()->video_timeline->set_offset(_startdrag_video_offset);
1782 ARDOUR_UI::instance()->flush_videotimeline_cache(true);
1784 for (list<AVDraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
1785 i->view->region()->resume_property_changes ();
1786 i->view->region()->set_position(i->initial_position);
1790 TrimDrag::TrimDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, list<RegionView*> const & v, bool preserve_fade_anchor)
1791 : RegionDrag (e, i, p, v)
1792 , _preserve_fade_anchor (preserve_fade_anchor)
1793 , _jump_position_when_done (false)
1795 DEBUG_TRACE (DEBUG::Drags, "New TrimDrag\n");
1799 TrimDrag::start_grab (GdkEvent* event, Gdk::Cursor*)
1802 TimeAxisView* tvp = &_primary->get_time_axis_view ();
1803 RouteTimeAxisView* tv = dynamic_cast<RouteTimeAxisView*>(tvp);
1805 if (tv && tv->is_track()) {
1806 speed = tv->track()->speed();
1809 framepos_t const region_start = (framepos_t) (_primary->region()->position() / speed);
1810 framepos_t const region_end = (framepos_t) (_primary->region()->last_frame() / speed);
1811 framecnt_t const region_length = (framecnt_t) (_primary->region()->length() / speed);
1813 framepos_t const pf = adjusted_current_frame (event);
1815 if (Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) {
1816 /* Move the contents of the region around without changing the region bounds */
1817 _operation = ContentsTrim;
1818 Drag::start_grab (event, _editor->cursors()->trimmer);
1820 /* These will get overridden for a point trim.*/
1821 if (pf < (region_start + region_length/2)) {
1822 /* closer to front */
1823 _operation = StartTrim;
1824 Drag::start_grab (event, _editor->cursors()->left_side_trim);
1827 _operation = EndTrim;
1828 Drag::start_grab (event, _editor->cursors()->right_side_trim);
1832 if (Keyboard::modifier_state_equals (event->button.state, Keyboard::TertiaryModifier)) {
1833 _jump_position_when_done = true;
1836 switch (_operation) {
1838 show_verbose_cursor_time (region_start);
1839 for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
1840 i->view->trim_front_starting ();
1844 show_verbose_cursor_time (region_end);
1847 show_verbose_cursor_time (pf);
1851 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
1852 i->view->region()->suspend_property_changes ();
1857 TrimDrag::motion (GdkEvent* event, bool first_move)
1859 RegionView* rv = _primary;
1862 TimeAxisView* tvp = &_primary->get_time_axis_view ();
1863 RouteTimeAxisView* tv = dynamic_cast<RouteTimeAxisView*>(tvp);
1864 pair<set<boost::shared_ptr<Playlist> >::iterator,bool> insert_result;
1865 frameoffset_t frame_delta = 0;
1867 if (tv && tv->is_track()) {
1868 speed = tv->track()->speed();
1871 framecnt_t const dt = adjusted_current_frame (event) - raw_grab_frame () + _pointer_frame_offset;
1877 switch (_operation) {
1879 trim_type = "Region start trim";
1882 trim_type = "Region end trim";
1885 trim_type = "Region content trim";
1889 _editor->begin_reversible_command (trim_type);
1891 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
1892 RegionView* rv = i->view;
1893 rv->fake_set_opaque (false);
1894 rv->enable_display (false);
1895 rv->region()->playlist()->clear_owned_changes ();
1897 AudioRegionView* const arv = dynamic_cast<AudioRegionView*> (rv);
1900 arv->temporarily_hide_envelope ();
1904 boost::shared_ptr<Playlist> pl = rv->region()->playlist();
1905 insert_result = _editor->motion_frozen_playlists.insert (pl);
1907 if (insert_result.second) {
1913 bool non_overlap_trim = false;
1915 if (event && Keyboard::modifier_state_equals (event->button.state, Keyboard::TertiaryModifier)) {
1916 non_overlap_trim = true;
1919 switch (_operation) {
1921 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
1922 bool changed = i->view->trim_front (i->initial_position + dt, non_overlap_trim);
1923 if (changed && _preserve_fade_anchor) {
1924 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (i->view);
1929 boost::shared_ptr<AudioRegion> ar (arv->audio_region());
1930 distance = _drags->current_pointer_x() - grab_x();
1931 len = ar->fade_in()->back()->when;
1932 new_length = len - _editor->pixel_to_sample (distance);
1933 new_length = ar->verify_xfade_bounds (new_length, true /*START*/ );
1934 arv->reset_fade_in_shape_width (ar, new_length); //the grey shape
1941 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
1942 bool changed = i->view->trim_end (i->initial_end + dt, non_overlap_trim);
1943 if (changed && _preserve_fade_anchor) {
1944 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (i->view);
1949 boost::shared_ptr<AudioRegion> ar (arv->audio_region());
1950 distance = grab_x() - _drags->current_pointer_x();
1951 len = ar->fade_out()->back()->when;
1952 new_length = len - _editor->pixel_to_sample (distance);
1953 new_length = ar->verify_xfade_bounds (new_length, false /*END*/ );
1954 arv->reset_fade_out_shape_width (ar, new_length); //the grey shape
1962 frame_delta = (adjusted_current_frame(event) - last_pointer_frame());
1963 // frame_delta = (last_pointer_frame() - adjusted_current_frame(event));
1965 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
1966 i->view->move_contents (frame_delta);
1972 switch (_operation) {
1974 show_verbose_cursor_time ((framepos_t) (rv->region()->position() / speed));
1977 show_verbose_cursor_time ((framepos_t) (rv->region()->last_frame() / speed));
1980 // show_verbose_cursor_time (frame_delta);
1987 TrimDrag::finished (GdkEvent* event, bool movement_occurred)
1989 if (movement_occurred) {
1990 motion (event, false);
1992 if (_operation == StartTrim) {
1993 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
1995 /* This must happen before the region's StatefulDiffCommand is created, as it may
1996 `correct' (ahem) the region's _start from being negative to being zero. It
1997 needs to be zero in the undo record.
1999 i->view->trim_front_ending ();
2001 if (_preserve_fade_anchor) {
2002 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (i->view);
2007 boost::shared_ptr<AudioRegion> ar (arv->audio_region());
2008 distance = _drags->current_pointer_x() - grab_x();
2009 len = ar->fade_in()->back()->when;
2010 new_length = len - _editor->pixel_to_sample (distance);
2011 new_length = ar->verify_xfade_bounds (new_length, true /*START*/ );
2012 ar->set_fade_in_length(new_length);
2015 if (_jump_position_when_done) {
2016 i->view->region()->set_position (i->initial_position);
2019 } else if (_operation == EndTrim) {
2020 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
2021 if (_preserve_fade_anchor) {
2022 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (i->view);
2027 boost::shared_ptr<AudioRegion> ar (arv->audio_region());
2028 distance = _drags->current_pointer_x() - grab_x();
2029 len = ar->fade_out()->back()->when;
2030 new_length = len - _editor->pixel_to_sample (distance);
2031 new_length = ar->verify_xfade_bounds (new_length, false /*END*/ );
2032 ar->set_fade_out_length(new_length);
2035 if (_jump_position_when_done) {
2036 i->view->region()->set_position (i->initial_end - i->view->region()->length());
2041 if (!_views.empty()) {
2042 if (_operation == StartTrim) {
2043 _editor->maybe_locate_with_edit_preroll(
2044 _views.begin()->view->region()->position());
2046 if (_operation == EndTrim) {
2047 _editor->maybe_locate_with_edit_preroll(
2048 _views.begin()->view->region()->position() +
2049 _views.begin()->view->region()->length());
2053 if (!_editor->selection->selected (_primary)) {
2054 _primary->thaw_after_trim ();
2057 set<boost::shared_ptr<Playlist> > diffed_playlists;
2059 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
2060 i->view->thaw_after_trim ();
2061 i->view->enable_display (true);
2062 i->view->fake_set_opaque (true);
2064 /* Trimming one region may affect others on the playlist, so we need
2065 to get undo Commands from the whole playlist rather than just the
2066 region. Use diffed_playlists to make sure we don't diff a given
2067 playlist more than once.
2069 boost::shared_ptr<Playlist> p = i->view->region()->playlist ();
2070 if (diffed_playlists.find (p) == diffed_playlists.end()) {
2071 vector<Command*> cmds;
2073 _editor->session()->add_commands (cmds);
2074 diffed_playlists.insert (p);
2079 for (set<boost::shared_ptr<Playlist> >::iterator p = _editor->motion_frozen_playlists.begin(); p != _editor->motion_frozen_playlists.end(); ++p) {
2083 _editor->motion_frozen_playlists.clear ();
2084 _editor->commit_reversible_command();
2087 /* no mouse movement */
2088 _editor->point_trim (event, adjusted_current_frame (event));
2091 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
2092 if (_operation == StartTrim) {
2093 i->view->trim_front_ending ();
2096 i->view->region()->resume_property_changes ();
2101 TrimDrag::aborted (bool movement_occurred)
2103 /* Our motion method is changing model state, so use the Undo system
2104 to cancel. Perhaps not ideal, as this will leave an Undo point
2105 behind which may be slightly odd from the user's point of view.
2110 if (movement_occurred) {
2114 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
2115 i->view->region()->resume_property_changes ();
2120 TrimDrag::setup_pointer_frame_offset ()
2122 list<DraggingView>::iterator i = _views.begin ();
2123 while (i != _views.end() && i->view != _primary) {
2127 if (i == _views.end()) {
2131 switch (_operation) {
2133 _pointer_frame_offset = raw_grab_frame() - i->initial_position;
2136 _pointer_frame_offset = raw_grab_frame() - i->initial_end;
2143 MeterMarkerDrag::MeterMarkerDrag (Editor* e, ArdourCanvas::Item* i, bool c)
2147 DEBUG_TRACE (DEBUG::Drags, "New MeterMarkerDrag\n");
2148 _marker = reinterpret_cast<MeterMarker*> (_item->get_data ("marker"));
2153 MeterMarkerDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
2155 Drag::start_grab (event, cursor);
2156 show_verbose_cursor_time (adjusted_current_frame(event));
2160 MeterMarkerDrag::setup_pointer_frame_offset ()
2162 _pointer_frame_offset = raw_grab_frame() - _marker->meter().frame();
2166 MeterMarkerDrag::motion (GdkEvent* event, bool first_move)
2168 if (!_marker->meter().movable()) {
2174 // create a dummy marker for visual representation of moving the
2175 // section, because whether its a copy or not, we're going to
2176 // leave or lose the original marker (leave if its a copy; lose if its
2177 // not, because we'll remove it from the map).
2179 MeterSection section (_marker->meter());
2181 if (!section.movable()) {
2186 snprintf (name, sizeof(name), "%g/%g", _marker->meter().divisions_per_bar(), _marker->meter().note_divisor ());
2188 _marker = new MeterMarker (
2190 *_editor->meter_group,
2191 ARDOUR_UI::config()->get_canvasvar_MeterMarker(),
2193 *new MeterSection (_marker->meter())
2196 /* use the new marker for the grab */
2197 swap_grab (&_marker->the_item(), 0, GDK_CURRENT_TIME);
2200 TempoMap& map (_editor->session()->tempo_map());
2201 /* get current state */
2202 before_state = &map.get_state();
2203 /* remove the section while we drag it */
2204 map.remove_meter (section, true);
2208 framepos_t const pf = adjusted_current_frame (event);
2209 _marker->set_position (pf);
2210 show_verbose_cursor_time (pf);
2214 MeterMarkerDrag::finished (GdkEvent* event, bool movement_occurred)
2216 if (!movement_occurred) {
2217 if (was_double_click()) {
2218 _editor->edit_meter_marker (*_marker);
2223 if (!_marker->meter().movable()) {
2227 motion (event, false);
2229 Timecode::BBT_Time when;
2231 TempoMap& map (_editor->session()->tempo_map());
2232 map.bbt_time (last_pointer_frame(), when);
2234 if (_copy == true) {
2235 _editor->begin_reversible_command (_("copy meter mark"));
2236 XMLNode &before = map.get_state();
2237 map.add_meter (_marker->meter(), when);
2238 XMLNode &after = map.get_state();
2239 _editor->session()->add_command(new MementoCommand<TempoMap>(map, &before, &after));
2240 _editor->commit_reversible_command ();
2243 _editor->begin_reversible_command (_("move meter mark"));
2245 /* we removed it before, so add it back now */
2247 map.add_meter (_marker->meter(), when);
2248 XMLNode &after = map.get_state();
2249 _editor->session()->add_command(new MementoCommand<TempoMap>(map, before_state, &after));
2250 _editor->commit_reversible_command ();
2253 // delete the dummy marker we used for visual representation while moving.
2254 // a new visual marker will show up automatically.
2259 MeterMarkerDrag::aborted (bool moved)
2261 _marker->set_position (_marker->meter().frame ());
2264 TempoMap& map (_editor->session()->tempo_map());
2265 /* we removed it before, so add it back now */
2266 map.add_meter (_marker->meter(), _marker->meter().frame());
2267 // delete the dummy marker we used for visual representation while moving.
2268 // a new visual marker will show up automatically.
2273 TempoMarkerDrag::TempoMarkerDrag (Editor* e, ArdourCanvas::Item* i, bool c)
2277 DEBUG_TRACE (DEBUG::Drags, "New TempoMarkerDrag\n");
2279 _marker = reinterpret_cast<TempoMarker*> (_item->get_data ("marker"));
2284 TempoMarkerDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
2286 Drag::start_grab (event, cursor);
2287 show_verbose_cursor_time (adjusted_current_frame (event));
2291 TempoMarkerDrag::setup_pointer_frame_offset ()
2293 _pointer_frame_offset = raw_grab_frame() - _marker->tempo().frame();
2297 TempoMarkerDrag::motion (GdkEvent* event, bool first_move)
2299 if (!_marker->tempo().movable()) {
2305 // create a dummy marker for visual representation of moving the
2306 // section, because whether its a copy or not, we're going to
2307 // leave or lose the original marker (leave if its a copy; lose if its
2308 // not, because we'll remove it from the map).
2310 // create a dummy marker for visual representation of moving the copy.
2311 // The actual copying is not done before we reach the finish callback.
2314 snprintf (name, sizeof (name), "%.2f", _marker->tempo().beats_per_minute());
2316 TempoSection section (_marker->tempo());
2318 _marker = new TempoMarker (
2320 *_editor->tempo_group,
2321 ARDOUR_UI::config()->get_canvasvar_TempoMarker(),
2323 *new TempoSection (_marker->tempo())
2326 /* use the new marker for the grab */
2327 swap_grab (&_marker->the_item(), 0, GDK_CURRENT_TIME);
2330 TempoMap& map (_editor->session()->tempo_map());
2331 /* get current state */
2332 before_state = &map.get_state();
2333 /* remove the section while we drag it */
2334 map.remove_tempo (section, true);
2338 framepos_t const pf = adjusted_current_frame (event);
2339 _marker->set_position (pf);
2340 show_verbose_cursor_time (pf);
2344 TempoMarkerDrag::finished (GdkEvent* event, bool movement_occurred)
2346 if (!movement_occurred) {
2347 if (was_double_click()) {
2348 _editor->edit_tempo_marker (*_marker);
2353 if (!_marker->tempo().movable()) {
2357 motion (event, false);
2359 TempoMap& map (_editor->session()->tempo_map());
2360 framepos_t beat_time = map.round_to_beat (last_pointer_frame(), 0);
2361 Timecode::BBT_Time when;
2363 map.bbt_time (beat_time, when);
2365 if (_copy == true) {
2366 _editor->begin_reversible_command (_("copy tempo mark"));
2367 XMLNode &before = map.get_state();
2368 map.add_tempo (_marker->tempo(), when);
2369 XMLNode &after = map.get_state();
2370 _editor->session()->add_command (new MementoCommand<TempoMap>(map, &before, &after));
2371 _editor->commit_reversible_command ();
2374 _editor->begin_reversible_command (_("move tempo mark"));
2375 /* we removed it before, so add it back now */
2376 map.add_tempo (_marker->tempo(), when);
2377 XMLNode &after = map.get_state();
2378 _editor->session()->add_command (new MementoCommand<TempoMap>(map, before_state, &after));
2379 _editor->commit_reversible_command ();
2382 // delete the dummy marker we used for visual representation while moving.
2383 // a new visual marker will show up automatically.
2388 TempoMarkerDrag::aborted (bool moved)
2390 _marker->set_position (_marker->tempo().frame());
2392 TempoMap& map (_editor->session()->tempo_map());
2393 /* we removed it before, so add it back now */
2394 map.add_tempo (_marker->tempo(), _marker->tempo().start());
2395 // delete the dummy marker we used for visual representation while moving.
2396 // a new visual marker will show up automatically.
2401 CursorDrag::CursorDrag (Editor* e, EditorCursor& c, bool s)
2402 : Drag (e, &c.time_bar_canvas_item())
2406 DEBUG_TRACE (DEBUG::Drags, "New CursorDrag\n");
2409 /** Do all the things we do when dragging the playhead to make it look as though
2410 * we have located, without actually doing the locate (because that would cause
2411 * the diskstream buffers to be refilled, which is too slow).
2414 CursorDrag::fake_locate (framepos_t t)
2416 _editor->playhead_cursor->set_position (t);
2418 Session* s = _editor->session ();
2419 if (s->timecode_transmission_suspended ()) {
2420 framepos_t const f = _editor->playhead_cursor->current_frame ();
2421 /* This is asynchronous so it will be sent "now"
2423 s->send_mmc_locate (f);
2424 /* These are synchronous and will be sent during the next
2427 s->queue_full_time_code ();
2428 s->queue_song_position_pointer ();
2431 show_verbose_cursor_time (t);
2432 _editor->UpdateAllTransportClocks (t);
2436 CursorDrag::start_grab (GdkEvent* event, Gdk::Cursor* c)
2438 Drag::start_grab (event, c);
2440 _grab_zoom = _editor->samples_per_pixel;
2442 framepos_t where = _editor->canvas_event_sample (event);
2444 _editor->snap_to_with_modifier (where, event);
2446 _editor->_dragging_playhead = true;
2448 Session* s = _editor->session ();
2450 /* grab the track canvas item as well */
2452 _cursor.track_canvas_item().grab();
2455 if (_was_rolling && _stop) {
2459 if (s->is_auditioning()) {
2460 s->cancel_audition ();
2464 if (AudioEngine::instance()->connected()) {
2466 /* do this only if we're the engine is connected
2467 * because otherwise this request will never be
2468 * serviced and we'll busy wait forever. likewise,
2469 * notice if we are disconnected while waiting for the
2470 * request to be serviced.
2473 s->request_suspend_timecode_transmission ();
2474 while (AudioEngine::instance()->connected() && !s->timecode_transmission_suspended ()) {
2475 /* twiddle our thumbs */
2480 fake_locate (where);
2484 CursorDrag::motion (GdkEvent* event, bool)
2486 framepos_t const adjusted_frame = adjusted_current_frame (event);
2487 if (adjusted_frame != last_pointer_frame()) {
2488 fake_locate (adjusted_frame);
2493 CursorDrag::finished (GdkEvent* event, bool movement_occurred)
2495 _editor->_dragging_playhead = false;
2497 _cursor.track_canvas_item().ungrab();
2499 if (!movement_occurred && _stop) {
2503 motion (event, false);
2505 Session* s = _editor->session ();
2507 s->request_locate (_editor->playhead_cursor->current_frame (), _was_rolling);
2508 _editor->_pending_locate_request = true;
2509 s->request_resume_timecode_transmission ();
2514 CursorDrag::aborted (bool)
2516 _cursor.track_canvas_item().ungrab();
2518 if (_editor->_dragging_playhead) {
2519 _editor->session()->request_resume_timecode_transmission ();
2520 _editor->_dragging_playhead = false;
2523 _editor->playhead_cursor->set_position (adjusted_frame (grab_frame (), 0, false));
2526 FadeInDrag::FadeInDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, list<RegionView*> const & v)
2527 : RegionDrag (e, i, p, v)
2529 DEBUG_TRACE (DEBUG::Drags, "New FadeInDrag\n");
2533 FadeInDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
2535 Drag::start_grab (event, cursor);
2537 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (_primary);
2538 boost::shared_ptr<AudioRegion> const r = arv->audio_region ();
2540 show_verbose_cursor_duration (r->position(), r->position() + r->fade_in()->back()->when, 32);
2544 FadeInDrag::setup_pointer_frame_offset ()
2546 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (_primary);
2547 boost::shared_ptr<AudioRegion> const r = arv->audio_region ();
2548 _pointer_frame_offset = raw_grab_frame() - ((framecnt_t) r->fade_in()->back()->when + r->position());
2552 FadeInDrag::motion (GdkEvent* event, bool)
2554 framecnt_t fade_length;
2556 framepos_t const pos = adjusted_current_frame (event);
2558 boost::shared_ptr<Region> region = _primary->region ();
2560 if (pos < (region->position() + 64)) {
2561 fade_length = 64; // this should be a minimum defined somewhere
2562 } else if (pos > region->last_frame()) {
2563 fade_length = region->length();
2565 fade_length = pos - region->position();
2568 for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
2570 AudioRegionView* tmp = dynamic_cast<AudioRegionView*> (i->view);
2576 tmp->reset_fade_in_shape_width (tmp->audio_region(), fade_length);
2579 show_verbose_cursor_duration (region->position(), region->position() + fade_length, 32);
2583 FadeInDrag::finished (GdkEvent* event, bool movement_occurred)
2585 if (!movement_occurred) {
2589 framecnt_t fade_length;
2591 framepos_t const pos = adjusted_current_frame (event);
2593 boost::shared_ptr<Region> region = _primary->region ();
2595 if (pos < (region->position() + 64)) {
2596 fade_length = 64; // this should be a minimum defined somewhere
2597 } else if (pos > region->last_frame()) {
2598 fade_length = region->length();
2600 fade_length = pos - region->position();
2603 _editor->begin_reversible_command (_("change fade in length"));
2605 for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
2607 AudioRegionView* tmp = dynamic_cast<AudioRegionView*> (i->view);
2613 boost::shared_ptr<AutomationList> alist = tmp->audio_region()->fade_in();
2614 XMLNode &before = alist->get_state();
2616 tmp->audio_region()->set_fade_in_length (fade_length);
2617 tmp->audio_region()->set_fade_in_active (true);
2619 XMLNode &after = alist->get_state();
2620 _editor->session()->add_command(new MementoCommand<AutomationList>(*alist.get(), &before, &after));
2623 _editor->commit_reversible_command ();
2627 FadeInDrag::aborted (bool)
2629 for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
2630 AudioRegionView* tmp = dynamic_cast<AudioRegionView*> (i->view);
2636 tmp->reset_fade_in_shape_width (tmp->audio_region(), tmp->audio_region()->fade_in()->back()->when);
2640 FadeOutDrag::FadeOutDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, list<RegionView*> const & v)
2641 : RegionDrag (e, i, p, v)
2643 DEBUG_TRACE (DEBUG::Drags, "New FadeOutDrag\n");
2647 FadeOutDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
2649 Drag::start_grab (event, cursor);
2651 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (_primary);
2652 boost::shared_ptr<AudioRegion> r = arv->audio_region ();
2654 show_verbose_cursor_duration (r->last_frame() - r->fade_out()->back()->when, r->last_frame());
2658 FadeOutDrag::setup_pointer_frame_offset ()
2660 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (_primary);
2661 boost::shared_ptr<AudioRegion> r = arv->audio_region ();
2662 _pointer_frame_offset = raw_grab_frame() - (r->length() - (framecnt_t) r->fade_out()->back()->when + r->position());
2666 FadeOutDrag::motion (GdkEvent* event, bool)
2668 framecnt_t fade_length;
2670 framepos_t const pos = adjusted_current_frame (event);
2672 boost::shared_ptr<Region> region = _primary->region ();
2674 if (pos > (region->last_frame() - 64)) {
2675 fade_length = 64; // this should really be a minimum fade defined somewhere
2677 else if (pos < region->position()) {
2678 fade_length = region->length();
2681 fade_length = region->last_frame() - pos;
2684 for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
2686 AudioRegionView* tmp = dynamic_cast<AudioRegionView*> (i->view);
2692 tmp->reset_fade_out_shape_width (tmp->audio_region(), fade_length);
2695 show_verbose_cursor_duration (region->last_frame() - fade_length, region->last_frame());
2699 FadeOutDrag::finished (GdkEvent* event, bool movement_occurred)
2701 if (!movement_occurred) {
2705 framecnt_t fade_length;
2707 framepos_t const pos = adjusted_current_frame (event);
2709 boost::shared_ptr<Region> region = _primary->region ();
2711 if (pos > (region->last_frame() - 64)) {
2712 fade_length = 64; // this should really be a minimum fade defined somewhere
2714 else if (pos < region->position()) {
2715 fade_length = region->length();
2718 fade_length = region->last_frame() - pos;
2721 _editor->begin_reversible_command (_("change fade out length"));
2723 for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
2725 AudioRegionView* tmp = dynamic_cast<AudioRegionView*> (i->view);
2731 boost::shared_ptr<AutomationList> alist = tmp->audio_region()->fade_out();
2732 XMLNode &before = alist->get_state();
2734 tmp->audio_region()->set_fade_out_length (fade_length);
2735 tmp->audio_region()->set_fade_out_active (true);
2737 XMLNode &after = alist->get_state();
2738 _editor->session()->add_command(new MementoCommand<AutomationList>(*alist.get(), &before, &after));
2741 _editor->commit_reversible_command ();
2745 FadeOutDrag::aborted (bool)
2747 for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
2748 AudioRegionView* tmp = dynamic_cast<AudioRegionView*> (i->view);
2754 tmp->reset_fade_out_shape_width (tmp->audio_region(), tmp->audio_region()->fade_out()->back()->when);
2758 MarkerDrag::MarkerDrag (Editor* e, ArdourCanvas::Item* i)
2761 DEBUG_TRACE (DEBUG::Drags, "New MarkerDrag\n");
2763 _marker = reinterpret_cast<Marker*> (_item->get_data ("marker"));
2766 _points.push_back (ArdourCanvas::Duple (0, 0));
2767 _points.push_back (ArdourCanvas::Duple (0, physical_screen_height (_editor->get_window())));
2770 MarkerDrag::~MarkerDrag ()
2772 for (CopiedLocationInfo::iterator i = _copied_locations.begin(); i != _copied_locations.end(); ++i) {
2777 MarkerDrag::CopiedLocationMarkerInfo::CopiedLocationMarkerInfo (Location* l, Marker* m)
2779 location = new Location (*l);
2780 markers.push_back (m);
2785 MarkerDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
2787 Drag::start_grab (event, cursor);
2791 Location *location = _editor->find_location_from_marker (_marker, is_start);
2792 _editor->_dragging_edit_point = true;
2794 update_item (location);
2796 // _drag_line->show();
2797 // _line->raise_to_top();
2800 show_verbose_cursor_time (location->start());
2802 show_verbose_cursor_time (location->end());
2805 Selection::Operation op = ArdourKeyboard::selection_type (event->button.state);
2808 case Selection::Toggle:
2809 /* we toggle on the button release */
2811 case Selection::Set:
2812 if (!_editor->selection->selected (_marker)) {
2813 _editor->selection->set (_marker);
2816 case Selection::Extend:
2818 Locations::LocationList ll;
2819 list<Marker*> to_add;
2821 _editor->selection->markers.range (s, e);
2822 s = min (_marker->position(), s);
2823 e = max (_marker->position(), e);
2826 if (e < max_framepos) {
2829 _editor->session()->locations()->find_all_between (s, e, ll, Location::Flags (0));
2830 for (Locations::LocationList::iterator i = ll.begin(); i != ll.end(); ++i) {
2831 Editor::LocationMarkers* lm = _editor->find_location_markers (*i);
2834 to_add.push_back (lm->start);
2837 to_add.push_back (lm->end);
2841 if (!to_add.empty()) {
2842 _editor->selection->add (to_add);
2846 case Selection::Add:
2847 _editor->selection->add (_marker);
2851 /* Set up copies for us to manipulate during the drag
2854 for (MarkerSelection::iterator i = _editor->selection->markers.begin(); i != _editor->selection->markers.end(); ++i) {
2856 Location* l = _editor->find_location_from_marker (*i, is_start);
2863 _copied_locations.push_back (CopiedLocationMarkerInfo (l, *i));
2865 /* range: check that the other end of the range isn't
2868 CopiedLocationInfo::iterator x;
2869 for (x = _copied_locations.begin(); x != _copied_locations.end(); ++x) {
2870 if (*(*x).location == *l) {
2874 if (x == _copied_locations.end()) {
2875 _copied_locations.push_back (CopiedLocationMarkerInfo (l, *i));
2877 (*x).markers.push_back (*i);
2878 (*x).move_both = true;
2886 MarkerDrag::setup_pointer_frame_offset ()
2889 Location *location = _editor->find_location_from_marker (_marker, is_start);
2890 _pointer_frame_offset = raw_grab_frame() - (is_start ? location->start() : location->end());
2894 MarkerDrag::motion (GdkEvent* event, bool)
2896 framecnt_t f_delta = 0;
2898 bool move_both = false;
2899 Location *real_location;
2900 Location *copy_location = 0;
2902 framepos_t const newframe = adjusted_current_frame (event);
2903 framepos_t next = newframe;
2905 if (Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) {
2909 CopiedLocationInfo::iterator x;
2911 /* find the marker we're dragging, and compute the delta */
2913 for (x = _copied_locations.begin(); x != _copied_locations.end(); ++x) {
2915 copy_location = (*x).location;
2917 if (find (x->markers.begin(), x->markers.end(), _marker) != x->markers.end()) {
2919 /* this marker is represented by this
2920 * CopiedLocationMarkerInfo
2923 if ((real_location = _editor->find_location_from_marker (_marker, is_start)) == 0) {
2928 if (real_location->is_mark()) {
2929 f_delta = newframe - copy_location->start();
2933 switch (_marker->type()) {
2934 case Marker::SessionStart:
2935 case Marker::RangeStart:
2936 case Marker::LoopStart:
2937 case Marker::PunchIn:
2938 f_delta = newframe - copy_location->start();
2941 case Marker::SessionEnd:
2942 case Marker::RangeEnd:
2943 case Marker::LoopEnd:
2944 case Marker::PunchOut:
2945 f_delta = newframe - copy_location->end();
2948 /* what kind of marker is this ? */
2957 if (x == _copied_locations.end()) {
2958 /* hmm, impossible - we didn't find the dragged marker */
2962 /* now move them all */
2964 for (x = _copied_locations.begin(); x != _copied_locations.end(); ++x) {
2966 copy_location = x->location;
2968 /* call this to find out if its the start or end */
2970 if ((real_location = _editor->find_location_from_marker (x->markers.front(), is_start)) == 0) {
2974 if (real_location->locked()) {
2978 if (copy_location->is_mark()) {
2982 copy_location->set_start (copy_location->start() + f_delta);
2986 framepos_t new_start = copy_location->start() + f_delta;
2987 framepos_t new_end = copy_location->end() + f_delta;
2989 if (is_start) { // start-of-range marker
2991 if (move_both || (*x).move_both) {
2992 copy_location->set_start (new_start);
2993 copy_location->set_end (new_end);
2994 } else if (new_start < copy_location->end()) {
2995 copy_location->set_start (new_start);
2996 } else if (newframe > 0) {
2997 _editor->snap_to (next, 1, true);
2998 copy_location->set_end (next);
2999 copy_location->set_start (newframe);
3002 } else { // end marker
3004 if (move_both || (*x).move_both) {
3005 copy_location->set_end (new_end);
3006 copy_location->set_start (new_start);
3007 } else if (new_end > copy_location->start()) {
3008 copy_location->set_end (new_end);
3009 } else if (newframe > 0) {
3010 _editor->snap_to (next, -1, true);
3011 copy_location->set_start (next);
3012 copy_location->set_end (newframe);
3017 update_item (copy_location);
3019 /* now lookup the actual GUI items used to display this
3020 * location and move them to wherever the copy of the location
3021 * is now. This means that the logic in ARDOUR::Location is
3022 * still enforced, even though we are not (yet) modifying
3023 * the real Location itself.
3026 Editor::LocationMarkers* lm = _editor->find_location_markers (real_location);
3029 lm->set_position (copy_location->start(), copy_location->end());
3034 assert (!_copied_locations.empty());
3036 show_verbose_cursor_time (newframe);
3040 MarkerDrag::finished (GdkEvent* event, bool movement_occurred)
3042 if (!movement_occurred) {
3044 if (was_double_click()) {
3045 _editor->rename_marker (_marker);
3049 /* just a click, do nothing but finish
3050 off the selection process
3053 Selection::Operation op = ArdourKeyboard::selection_type (event->button.state);
3056 case Selection::Set:
3057 if (_editor->selection->selected (_marker) && _editor->selection->markers.size() > 1) {
3058 _editor->selection->set (_marker);
3062 case Selection::Toggle:
3063 /* we toggle on the button release, click only */
3064 _editor->selection->toggle (_marker);
3067 case Selection::Extend:
3068 case Selection::Add:
3075 _editor->_dragging_edit_point = false;
3077 _editor->begin_reversible_command ( _("move marker") );
3078 XMLNode &before = _editor->session()->locations()->get_state();
3080 MarkerSelection::iterator i;
3081 CopiedLocationInfo::iterator x;
3084 for (i = _editor->selection->markers.begin(), x = _copied_locations.begin();
3085 x != _copied_locations.end() && i != _editor->selection->markers.end();
3088 Location * location = _editor->find_location_from_marker (*i, is_start);
3092 if (location->locked()) {
3096 if (location->is_mark()) {
3097 location->set_start (((*x).location)->start());
3099 location->set (((*x).location)->start(), ((*x).location)->end());
3104 XMLNode &after = _editor->session()->locations()->get_state();
3105 _editor->session()->add_command(new MementoCommand<Locations>(*(_editor->session()->locations()), &before, &after));
3106 _editor->commit_reversible_command ();
3110 MarkerDrag::aborted (bool)
3116 MarkerDrag::update_item (Location*)
3121 ControlPointDrag::ControlPointDrag (Editor* e, ArdourCanvas::Item* i)
3123 _cumulative_x_drag (0),
3124 _cumulative_y_drag (0)
3126 if (_zero_gain_fraction < 0.0) {
3127 _zero_gain_fraction = gain_to_slider_position_with_max (dB_to_coefficient (0.0), Config->get_max_gain());
3130 DEBUG_TRACE (DEBUG::Drags, "New ControlPointDrag\n");
3132 _point = reinterpret_cast<ControlPoint*> (_item->get_data ("control_point"));
3138 ControlPointDrag::start_grab (GdkEvent* event, Gdk::Cursor* /*cursor*/)
3140 Drag::start_grab (event, _editor->cursors()->fader);
3142 // start the grab at the center of the control point so
3143 // the point doesn't 'jump' to the mouse after the first drag
3144 _fixed_grab_x = _point->get_x();
3145 _fixed_grab_y = _point->get_y();
3147 float const fraction = 1 - (_point->get_y() / _point->line().height());
3149 _point->line().start_drag_single (_point, _fixed_grab_x, fraction);
3151 _editor->verbose_cursor()->set (_point->line().get_verbose_cursor_string (fraction),
3152 event->button.x + 10, event->button.y + 10);
3154 _editor->verbose_cursor()->show ();
3156 _pushing = Keyboard::modifier_state_contains (event->button.state, Keyboard::PrimaryModifier);
3158 if (!_point->can_slide ()) {
3159 _x_constrained = true;
3164 ControlPointDrag::motion (GdkEvent* event, bool)
3166 double dx = _drags->current_pointer_x() - last_pointer_x();
3167 double dy = _drags->current_pointer_y() - last_pointer_y();
3169 if (event->button.state & Keyboard::SecondaryModifier) {
3174 /* coordinate in pixels relative to the start of the region (for region-based automation)
3175 or track (for track-based automation) */
3176 double cx = _fixed_grab_x + _cumulative_x_drag + dx;
3177 double cy = _fixed_grab_y + _cumulative_y_drag + dy;
3179 // calculate zero crossing point. back off by .01 to stay on the
3180 // positive side of zero
3181 double const zero_gain_y = (1.0 - _zero_gain_fraction) * _point->line().height() - .01;
3183 // make sure we hit zero when passing through
3184 if ((cy < zero_gain_y && (cy - dy) > zero_gain_y) || (cy > zero_gain_y && (cy - dy) < zero_gain_y)) {
3188 if (_x_constrained) {
3191 if (_y_constrained) {
3195 _cumulative_x_drag = cx - _fixed_grab_x;
3196 _cumulative_y_drag = cy - _fixed_grab_y;
3200 cy = min ((double) _point->line().height(), cy);
3202 framepos_t cx_frames = _editor->pixel_to_sample (cx);
3204 if (!_x_constrained) {
3205 _editor->snap_to_with_modifier (cx_frames, event);
3208 cx_frames = min (cx_frames, _point->line().maximum_time());
3210 float const fraction = 1.0 - (cy / _point->line().height());
3212 _point->line().drag_motion (_editor->sample_to_pixel_unrounded (cx_frames), fraction, false, _pushing, _final_index);
3214 _editor->verbose_cursor()->set_text (_point->line().get_verbose_cursor_string (fraction));
3218 ControlPointDrag::finished (GdkEvent* event, bool movement_occurred)
3220 if (!movement_occurred) {
3224 if (Keyboard::modifier_state_equals (event->button.state, Keyboard::TertiaryModifier)) {
3225 _editor->reset_point_selection ();
3229 motion (event, false);
3232 _point->line().end_drag (_pushing, _final_index);
3233 _editor->session()->commit_reversible_command ();
3237 ControlPointDrag::aborted (bool)
3239 _point->line().reset ();
3243 ControlPointDrag::active (Editing::MouseMode m)
3245 if (m == Editing::MouseGain) {
3246 /* always active in mouse gain */
3250 /* otherwise active if the point is on an automation line (ie not if its on a region gain line) */
3251 return dynamic_cast<AutomationLine*> (&(_point->line())) != 0;
3254 LineDrag::LineDrag (Editor* e, ArdourCanvas::Item* i)
3257 _cumulative_y_drag (0)
3259 DEBUG_TRACE (DEBUG::Drags, "New LineDrag\n");
3263 LineDrag::start_grab (GdkEvent* event, Gdk::Cursor* /*cursor*/)
3265 _line = reinterpret_cast<AutomationLine*> (_item->get_data ("line"));
3268 _item = &_line->grab_item ();
3270 /* need to get x coordinate in terms of parent (TimeAxisItemView)
3271 origin, and ditto for y.
3274 double cx = event->button.x;
3275 double cy = event->button.y;
3277 _line->parent_group().canvas_to_item (cx, cy);
3279 framecnt_t const frame_within_region = (framecnt_t) floor (cx * _editor->samples_per_pixel);
3284 if (!_line->control_points_adjacent (frame_within_region, before, after)) {
3285 /* no adjacent points */
3289 Drag::start_grab (event, _editor->cursors()->fader);
3291 /* store grab start in parent frame */
3296 double fraction = 1.0 - (cy / _line->height());
3298 _line->start_drag_line (before, after, fraction);
3300 _editor->verbose_cursor()->set (_line->get_verbose_cursor_string (fraction),
3301 event->button.x + 10, event->button.y + 10);
3303 _editor->verbose_cursor()->show ();
3307 LineDrag::motion (GdkEvent* event, bool)
3309 double dy = _drags->current_pointer_y() - last_pointer_y();
3311 if (event->button.state & Keyboard::SecondaryModifier) {
3315 double cy = _fixed_grab_y + _cumulative_y_drag + dy;
3317 _cumulative_y_drag = cy - _fixed_grab_y;
3320 cy = min ((double) _line->height(), cy);
3322 double const fraction = 1.0 - (cy / _line->height());
3325 /* we are ignoring x position for this drag, so we can just pass in anything */
3326 _line->drag_motion (0, fraction, true, false, ignored);
3328 _editor->verbose_cursor()->set_text (_line->get_verbose_cursor_string (fraction));
3332 LineDrag::finished (GdkEvent* event, bool movement_occured)
3334 if (movement_occured) {
3335 motion (event, false);
3336 _line->end_drag (false, 0);
3338 /* add a new control point on the line */
3340 AutomationTimeAxisView* atv;
3342 _line->end_drag (false, 0);
3344 if ((atv = dynamic_cast<AutomationTimeAxisView*>(_editor->clicked_axisview)) != 0) {
3345 framepos_t where = _editor->window_event_sample (event, 0, 0);
3346 atv->add_automation_event (event, where, event->button.y, false);
3350 _editor->session()->commit_reversible_command ();
3354 LineDrag::aborted (bool)
3359 FeatureLineDrag::FeatureLineDrag (Editor* e, ArdourCanvas::Item* i)
3362 _cumulative_x_drag (0)
3364 DEBUG_TRACE (DEBUG::Drags, "New FeatureLineDrag\n");
3368 FeatureLineDrag::start_grab (GdkEvent* event, Gdk::Cursor* /*cursor*/)
3370 Drag::start_grab (event);
3372 _line = reinterpret_cast<Line*> (_item);
3375 /* need to get x coordinate in terms of parent (AudioRegionView) origin. */
3377 double cx = event->button.x;
3378 double cy = event->button.y;
3380 _item->parent()->canvas_to_item (cx, cy);
3382 /* store grab start in parent frame */
3383 _region_view_grab_x = cx;
3385 _before = *(float*) _item->get_data ("position");
3387 _arv = reinterpret_cast<AudioRegionView*> (_item->get_data ("regionview"));
3389 _max_x = _editor->sample_to_pixel(_arv->get_duration());
3393 FeatureLineDrag::motion (GdkEvent*, bool)
3395 double dx = _drags->current_pointer_x() - last_pointer_x();
3397 double cx = _region_view_grab_x + _cumulative_x_drag + dx;
3399 _cumulative_x_drag += dx;
3401 /* Clamp the min and max extent of the drag to keep it within the region view bounds */
3410 boost::optional<ArdourCanvas::Rect> bbox = _line->bounding_box ();
3412 _line->set (ArdourCanvas::Duple (cx, 2.0), ArdourCanvas::Duple (cx, bbox.get().height ()));
3414 float *pos = new float;
3417 _line->set_data ("position", pos);
3423 FeatureLineDrag::finished (GdkEvent*, bool)
3425 _arv = reinterpret_cast<AudioRegionView*> (_item->get_data ("regionview"));
3426 _arv->update_transient(_before, _before);
3430 FeatureLineDrag::aborted (bool)
3435 RubberbandSelectDrag::RubberbandSelectDrag (Editor* e, ArdourCanvas::Item* i)
3437 , _vertical_only (false)
3439 DEBUG_TRACE (DEBUG::Drags, "New RubberbandSelectDrag\n");
3443 RubberbandSelectDrag::start_grab (GdkEvent* event, Gdk::Cursor *)
3445 Drag::start_grab (event);
3446 show_verbose_cursor_time (adjusted_current_frame (event));
3450 RubberbandSelectDrag::motion (GdkEvent* event, bool)
3457 framepos_t const pf = adjusted_current_frame (event, Config->get_rubberbanding_snaps_to_grid ());
3459 framepos_t grab = grab_frame ();
3460 if (Config->get_rubberbanding_snaps_to_grid ()) {
3461 _editor->snap_to_with_modifier (grab, event);
3464 /* base start and end on initial click position */
3474 if (_drags->current_pointer_y() < grab_y()) {
3475 y1 = _drags->current_pointer_y();
3478 y2 = _drags->current_pointer_y();
3483 if (start != end || y1 != y2) {
3485 double x1 = _editor->sample_to_pixel (start);
3486 double x2 = _editor->sample_to_pixel (end);
3487 const double min_dimension = 2.0;
3489 _editor->rubberband_rect->set_x0 (x1);
3490 if (_vertical_only) {
3491 /* fixed 10 pixel width */
3492 _editor->rubberband_rect->set_x1 (x1 + 10);
3495 x2 = min (x1 - min_dimension, x2);
3497 x2 = max (x1 + min_dimension, x2);
3499 _editor->rubberband_rect->set_x1 (x2);
3502 _editor->rubberband_rect->set_y0 (y1);
3504 y2 = min (y1 - min_dimension, y2);
3506 y2 = max (y1 + min_dimension, y2);
3509 _editor->rubberband_rect->set_y1 (y2);
3511 _editor->rubberband_rect->show();
3512 _editor->rubberband_rect->raise_to_top();
3514 show_verbose_cursor_time (pf);
3516 do_select_things (event, true);
3521 RubberbandSelectDrag::do_select_things (GdkEvent* event, bool drag_in_progress)
3526 if (grab_frame() < last_pointer_frame()) {
3528 x2 = last_pointer_frame ();
3531 x1 = last_pointer_frame ();
3537 if (_drags->current_pointer_y() < grab_y()) {
3538 y1 = _drags->current_pointer_y();
3541 y2 = _drags->current_pointer_y();
3545 select_things (event->button.state, x1, x2, y1, y2, drag_in_progress);
3549 RubberbandSelectDrag::finished (GdkEvent* event, bool movement_occurred)
3551 if (movement_occurred) {
3553 motion (event, false);
3554 do_select_things (event, false);
3560 bool do_deselect = true;
3561 MidiTimeAxisView* mtv;
3563 if ((mtv = dynamic_cast<MidiTimeAxisView*>(_editor->clicked_axisview)) != 0) {
3565 if (_editor->selection->empty()) {
3566 /* nothing selected */
3567 add_midi_region (mtv);
3568 do_deselect = false;
3572 /* do not deselect if Primary or Tertiary (toggle-select or
3573 * extend-select are pressed.
3576 if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::PrimaryModifier) &&
3577 !Keyboard::modifier_state_contains (event->button.state, Keyboard::TertiaryModifier) &&
3584 _editor->rubberband_rect->hide();
3588 RubberbandSelectDrag::aborted (bool)
3590 _editor->rubberband_rect->hide ();
3593 TimeFXDrag::TimeFXDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, std::list<RegionView*> const & v)
3594 : RegionDrag (e, i, p, v)
3596 DEBUG_TRACE (DEBUG::Drags, "New TimeFXDrag\n");
3600 TimeFXDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
3602 Drag::start_grab (event, cursor);
3604 show_verbose_cursor_time (adjusted_current_frame (event));
3608 TimeFXDrag::motion (GdkEvent* event, bool)
3610 RegionView* rv = _primary;
3611 StreamView* cv = rv->get_time_axis_view().view ();
3613 pair<TimeAxisView*, double> const tv = _editor->trackview_by_y_position (grab_y());
3614 int layer = tv.first->layer_display() == Overlaid ? 0 : tv.second;
3615 int layers = tv.first->layer_display() == Overlaid ? 1 : cv->layers();
3617 framepos_t const pf = adjusted_current_frame (event);
3619 if (pf > rv->region()->position()) {
3620 rv->get_time_axis_view().show_timestretch (rv->region()->position(), pf, layers, layer);
3623 show_verbose_cursor_time (pf);
3627 TimeFXDrag::finished (GdkEvent* /*event*/, bool movement_occurred)
3629 _primary->get_time_axis_view().hide_timestretch ();
3631 if (!movement_occurred) {
3635 if (last_pointer_frame() < _primary->region()->position()) {
3636 /* backwards drag of the left edge - not usable */
3640 framecnt_t newlen = last_pointer_frame() - _primary->region()->position();
3642 float percentage = (double) newlen / (double) _primary->region()->length();
3644 #ifndef USE_RUBBERBAND
3645 // Soundtouch uses percentage / 100 instead of normal (/ 1)
3646 if (_primary->region()->data_type() == DataType::AUDIO) {
3647 percentage = (float) ((double) newlen - (double) _primary->region()->length()) / ((double) newlen) * 100.0f;
3651 if (!_editor->get_selection().regions.empty()) {
3652 /* primary will already be included in the selection, and edit
3653 group shared editing will propagate selection across
3654 equivalent regions, so just use the current region
3658 if (_editor->time_stretch (_editor->get_selection().regions, percentage) == -1) {
3659 error << _("An error occurred while executing time stretch operation") << endmsg;
3665 TimeFXDrag::aborted (bool)
3667 _primary->get_time_axis_view().hide_timestretch ();
3670 ScrubDrag::ScrubDrag (Editor* e, ArdourCanvas::Item* i)
3673 DEBUG_TRACE (DEBUG::Drags, "New ScrubDrag\n");
3677 ScrubDrag::start_grab (GdkEvent* event, Gdk::Cursor *)
3679 Drag::start_grab (event);
3683 ScrubDrag::motion (GdkEvent* /*event*/, bool)
3685 _editor->scrub (adjusted_current_frame (0, false), _drags->current_pointer_x ());
3689 ScrubDrag::finished (GdkEvent* /*event*/, bool movement_occurred)
3691 if (movement_occurred && _editor->session()) {
3692 /* make sure we stop */
3693 _editor->session()->request_transport_speed (0.0);
3698 ScrubDrag::aborted (bool)
3703 SelectionDrag::SelectionDrag (Editor* e, ArdourCanvas::Item* i, Operation o)
3708 , _original_pointer_time_axis (-1)
3709 , _last_pointer_time_axis (-1)
3710 , _time_selection_at_start (!_editor->get_selection().time.empty())
3712 DEBUG_TRACE (DEBUG::Drags, "New SelectionDrag\n");
3714 if (_time_selection_at_start) {
3715 start_at_start = _editor->get_selection().time.start();
3716 end_at_start = _editor->get_selection().time.end_frame();
3721 SelectionDrag::start_grab (GdkEvent* event, Gdk::Cursor*)
3723 if (_editor->session() == 0) {
3727 Gdk::Cursor* cursor = 0;
3729 switch (_operation) {
3730 case CreateSelection:
3731 if (Keyboard::modifier_state_equals (event->button.state, Keyboard::CopyModifier)) {
3736 cursor = _editor->cursors()->selector;
3737 Drag::start_grab (event, cursor);
3740 case SelectionStartTrim:
3741 if (_editor->clicked_axisview) {
3742 _editor->clicked_axisview->order_selection_trims (_item, true);
3744 Drag::start_grab (event, _editor->cursors()->left_side_trim);
3747 case SelectionEndTrim:
3748 if (_editor->clicked_axisview) {
3749 _editor->clicked_axisview->order_selection_trims (_item, false);
3751 Drag::start_grab (event, _editor->cursors()->right_side_trim);
3755 Drag::start_grab (event, cursor);
3758 case SelectionExtend:
3759 Drag::start_grab (event, cursor);
3763 if (_operation == SelectionMove) {
3764 show_verbose_cursor_time (_editor->selection->time[_editor->clicked_selection].start);
3766 show_verbose_cursor_time (adjusted_current_frame (event));
3769 _original_pointer_time_axis = _editor->trackview_by_y_position (_drags->current_pointer_y ()).first->order ();
3773 SelectionDrag::setup_pointer_frame_offset ()
3775 switch (_operation) {
3776 case CreateSelection:
3777 _pointer_frame_offset = 0;
3780 case SelectionStartTrim:
3782 _pointer_frame_offset = raw_grab_frame() - _editor->selection->time[_editor->clicked_selection].start;
3785 case SelectionEndTrim:
3786 _pointer_frame_offset = raw_grab_frame() - _editor->selection->time[_editor->clicked_selection].end;
3789 case SelectionExtend:
3795 SelectionDrag::motion (GdkEvent* event, bool first_move)
3797 framepos_t start = 0;
3799 framecnt_t length = 0;
3800 framecnt_t distance = 0;
3802 framepos_t const pending_position = adjusted_current_frame (event);
3804 if (_operation != CreateSelection && pending_position == last_pointer_frame()) {
3808 switch (_operation) {
3809 case CreateSelection:
3811 framepos_t grab = grab_frame ();
3814 grab = adjusted_current_frame (event, false);
3815 if (grab < pending_position) {
3816 _editor->snap_to (grab, -1);
3818 _editor->snap_to (grab, 1);
3822 if (pending_position < grab) {
3823 start = pending_position;
3826 end = pending_position;
3830 /* first drag: Either add to the selection
3831 or create a new selection
3838 /* adding to the selection */
3839 _editor->set_selected_track_as_side_effect (Selection::Add);
3840 _editor->clicked_selection = _editor->selection->add (start, end);
3847 if (_editor->clicked_axisview && !_editor->selection->selected (_editor->clicked_axisview)) {
3848 _editor->set_selected_track_as_side_effect (Selection::Set);
3851 _editor->clicked_selection = _editor->selection->set (start, end);
3855 /* select all tracks within the rectangle that we've marked out so far */
3856 TrackViewList to_be_added_to_selection;
3857 TrackViewList to_be_removed_from_selection;
3858 TrackViewList& all_tracks (_editor->track_views);
3860 for (TrackViewList::const_iterator i = all_tracks.begin(); i != all_tracks.end(); ++i) {
3862 if ((*i)->covered_by_y_range (grab_y(), _drags->current_pointer_y())) {
3863 if (!(*i)->get_selected()) {
3864 to_be_added_to_selection.push_back (*i);
3867 if ((*i)->get_selected()) {
3868 to_be_removed_from_selection.push_back (*i);
3873 if (!to_be_added_to_selection.empty()) {
3874 _editor->selection->add (to_be_added_to_selection);
3877 if (!to_be_removed_from_selection.empty()) {
3878 _editor->selection->remove (to_be_removed_from_selection);
3883 case SelectionStartTrim:
3885 start = _editor->selection->time[_editor->clicked_selection].start;
3886 end = _editor->selection->time[_editor->clicked_selection].end;
3888 if (pending_position > end) {
3891 start = pending_position;
3895 case SelectionEndTrim:
3897 start = _editor->selection->time[_editor->clicked_selection].start;
3898 end = _editor->selection->time[_editor->clicked_selection].end;
3900 if (pending_position < start) {
3903 end = pending_position;
3910 start = _editor->selection->time[_editor->clicked_selection].start;
3911 end = _editor->selection->time[_editor->clicked_selection].end;
3913 length = end - start;
3914 distance = pending_position - start;
3915 start = pending_position;
3916 _editor->snap_to (start);
3918 end = start + length;
3922 case SelectionExtend:
3926 _editor->maybe_autoscroll (true, false, false);
3929 switch (_operation) {
3931 if (_time_selection_at_start) {
3932 _editor->selection->move_time (distance);
3936 _editor->selection->replace (_editor->clicked_selection, start, end);
3940 if (_operation == SelectionMove) {
3941 show_verbose_cursor_time(start);
3943 show_verbose_cursor_time(pending_position);
3948 SelectionDrag::finished (GdkEvent* event, bool movement_occurred)
3950 Session* s = _editor->session();
3952 if (movement_occurred) {
3953 motion (event, false);
3954 /* XXX this is not object-oriented programming at all. ick */
3955 if (_editor->selection->time.consolidate()) {
3956 _editor->selection->TimeChanged ();
3959 /* XXX what if its a music time selection? */
3961 if ( s->get_play_range() && s->transport_rolling() ) {
3962 s->request_play_range (&_editor->selection->time, true);
3964 if (Config->get_always_play_range() && !s->transport_rolling()) {
3965 s->request_locate (_editor->get_selection().time.start());
3971 /* just a click, no pointer movement.
3974 if (_operation == SelectionExtend) {
3975 if (_time_selection_at_start) {
3976 framepos_t pos = adjusted_current_frame (event, false);
3977 framepos_t start = min (pos, start_at_start);
3978 framepos_t end = max (pos, end_at_start);
3979 _editor->selection->set (start, end);
3982 if (Keyboard::modifier_state_equals (event->button.state, Keyboard::CopyModifier)) {
3983 if (_editor->clicked_selection) {
3984 _editor->selection->remove (_editor->clicked_selection);
3987 if (!_editor->clicked_selection) {
3988 _editor->selection->clear_time();
3993 if (_editor->clicked_axisview && !_editor->selection->selected (_editor->clicked_axisview)) {
3994 _editor->selection->set (_editor->clicked_axisview);
3997 if (s && s->get_play_range () && s->transport_rolling()) {
3998 s->request_stop (false, false);
4003 _editor->stop_canvas_autoscroll ();
4004 _editor->clicked_selection = 0;
4008 SelectionDrag::aborted (bool)
4013 RangeMarkerBarDrag::RangeMarkerBarDrag (Editor* e, ArdourCanvas::Item* i, Operation o)
4018 DEBUG_TRACE (DEBUG::Drags, "New RangeMarkerBarDrag\n");
4020 _drag_rect = new ArdourCanvas::Rectangle (_editor->time_line_group,
4021 ArdourCanvas::Rect (0.0, 0.0, 0.0,
4022 physical_screen_height (_editor->get_window())));
4023 _drag_rect->hide ();
4025 _drag_rect->set_fill_color (ARDOUR_UI::config()->get_canvasvar_RangeDragRect());
4026 _drag_rect->set_outline_color (ARDOUR_UI::config()->get_canvasvar_RangeDragRect());
4030 RangeMarkerBarDrag::start_grab (GdkEvent* event, Gdk::Cursor *)
4032 if (_editor->session() == 0) {
4036 Gdk::Cursor* cursor = 0;
4038 if (!_editor->temp_location) {
4039 _editor->temp_location = new Location (*_editor->session());
4042 switch (_operation) {
4043 case CreateRangeMarker:
4044 case CreateTransportMarker:
4045 case CreateCDMarker:
4047 if (Keyboard::modifier_state_equals (event->button.state, Keyboard::TertiaryModifier)) {
4052 cursor = _editor->cursors()->selector;
4056 Drag::start_grab (event, cursor);
4058 show_verbose_cursor_time (adjusted_current_frame (event));
4062 RangeMarkerBarDrag::motion (GdkEvent* event, bool first_move)
4064 framepos_t start = 0;
4066 ArdourCanvas::Rectangle *crect;
4068 switch (_operation) {
4069 case CreateRangeMarker:
4070 crect = _editor->range_bar_drag_rect;
4072 case CreateTransportMarker:
4073 crect = _editor->transport_bar_drag_rect;
4075 case CreateCDMarker:
4076 crect = _editor->cd_marker_bar_drag_rect;
4079 error << string_compose (_("programming_error: %1"), "Error: unknown range marker op passed to Editor::drag_range_markerbar_op ()") << endmsg;
4084 framepos_t const pf = adjusted_current_frame (event);
4086 if (_operation == CreateRangeMarker || _operation == CreateTransportMarker || _operation == CreateCDMarker) {
4087 framepos_t grab = grab_frame ();
4088 _editor->snap_to (grab);
4090 if (pf < grab_frame()) {
4098 /* first drag: Either add to the selection
4099 or create a new selection.
4104 _editor->temp_location->set (start, end);
4108 update_item (_editor->temp_location);
4110 //_drag_rect->raise_to_top();
4115 _editor->maybe_autoscroll (true, false, false);
4118 _editor->temp_location->set (start, end);
4120 double x1 = _editor->sample_to_pixel (start);
4121 double x2 = _editor->sample_to_pixel (end);
4125 update_item (_editor->temp_location);
4128 show_verbose_cursor_time (pf);
4133 RangeMarkerBarDrag::finished (GdkEvent* event, bool movement_occurred)
4135 Location * newloc = 0;
4139 if (movement_occurred) {
4140 motion (event, false);
4143 switch (_operation) {
4144 case CreateRangeMarker:
4145 case CreateCDMarker:
4147 _editor->begin_reversible_command (_("new range marker"));
4148 XMLNode &before = _editor->session()->locations()->get_state();
4149 _editor->session()->locations()->next_available_name(rangename,"unnamed");
4150 if (_operation == CreateCDMarker) {
4151 flags = Location::IsRangeMarker | Location::IsCDMarker;
4152 _editor->cd_marker_bar_drag_rect->hide();
4155 flags = Location::IsRangeMarker;
4156 _editor->range_bar_drag_rect->hide();
4158 newloc = new Location (
4159 *_editor->session(), _editor->temp_location->start(), _editor->temp_location->end(), rangename, (Location::Flags) flags
4162 _editor->session()->locations()->add (newloc, true);
4163 XMLNode &after = _editor->session()->locations()->get_state();
4164 _editor->session()->add_command(new MementoCommand<Locations>(*(_editor->session()->locations()), &before, &after));
4165 _editor->commit_reversible_command ();
4169 case CreateTransportMarker:
4170 // popup menu to pick loop or punch
4171 _editor->new_transport_marker_context_menu (&event->button, _item);
4177 /* just a click, no pointer movement. remember that context menu stuff was handled elsewhere */
4179 if (_operation == CreateTransportMarker) {
4181 /* didn't drag, so just locate */
4183 _editor->session()->request_locate (grab_frame(), _editor->session()->transport_rolling());
4185 } else if (_operation == CreateCDMarker) {
4187 /* didn't drag, but mark is already created so do
4190 } else { /* operation == CreateRangeMarker */
4196 _editor->session()->locations()->marks_either_side (grab_frame(), start, end);
4198 if (end == max_framepos) {
4199 end = _editor->session()->current_end_frame ();
4202 if (start == max_framepos) {
4203 start = _editor->session()->current_start_frame ();
4206 switch (_editor->mouse_mode) {
4208 /* find the two markers on either side and then make the selection from it */
4209 _editor->select_all_within (start, end, 0.0f, FLT_MAX, _editor->track_views, Selection::Set, false);
4213 /* find the two markers on either side of the click and make the range out of it */
4214 _editor->selection->set (start, end);
4223 _editor->stop_canvas_autoscroll ();
4227 RangeMarkerBarDrag::aborted (bool)
4233 RangeMarkerBarDrag::update_item (Location* location)
4235 double const x1 = _editor->sample_to_pixel (location->start());
4236 double const x2 = _editor->sample_to_pixel (location->end());
4238 _drag_rect->set_x0 (x1);
4239 _drag_rect->set_x1 (x2);
4242 MouseZoomDrag::MouseZoomDrag (Editor* e, ArdourCanvas::Item* i)
4246 DEBUG_TRACE (DEBUG::Drags, "New MouseZoomDrag\n");
4250 MouseZoomDrag::start_grab (GdkEvent* event, Gdk::Cursor *)
4252 if (Keyboard::the_keyboard().key_is_down (GDK_Control_L)) {
4253 Drag::start_grab (event, _editor->cursors()->zoom_out);
4256 Drag::start_grab (event, _editor->cursors()->zoom_in);
4260 show_verbose_cursor_time (adjusted_current_frame (event));
4264 MouseZoomDrag::motion (GdkEvent* event, bool first_move)
4269 framepos_t const pf = adjusted_current_frame (event);
4271 framepos_t grab = grab_frame ();
4272 _editor->snap_to_with_modifier (grab, event);
4274 /* base start and end on initial click position */
4286 _editor->zoom_rect->show();
4287 _editor->zoom_rect->raise_to_top();
4290 _editor->reposition_zoom_rect(start, end);
4292 show_verbose_cursor_time (pf);
4297 MouseZoomDrag::finished (GdkEvent* event, bool movement_occurred)
4299 if (movement_occurred) {
4300 motion (event, false);
4302 if (grab_frame() < last_pointer_frame()) {
4303 _editor->temporal_zoom_by_frame (grab_frame(), last_pointer_frame());
4305 _editor->temporal_zoom_by_frame (last_pointer_frame(), grab_frame());
4308 if (Keyboard::the_keyboard().key_is_down (GDK_Shift_L)) {
4309 _editor->tav_zoom_step (_zoom_out);
4311 _editor->temporal_zoom_to_frame (_zoom_out, grab_frame());
4315 _editor->zoom_rect->hide();
4319 MouseZoomDrag::aborted (bool)
4321 _editor->zoom_rect->hide ();
4324 NoteDrag::NoteDrag (Editor* e, ArdourCanvas::Item* i)
4326 , _cumulative_dx (0)
4327 , _cumulative_dy (0)
4329 DEBUG_TRACE (DEBUG::Drags, "New NoteDrag\n");
4331 _primary = reinterpret_cast<NoteBase*> (_item->get_data ("notebase"));
4333 _region = &_primary->region_view ();
4334 _note_height = _region->midi_stream_view()->note_height ();
4338 NoteDrag::start_grab (GdkEvent* event, Gdk::Cursor *)
4340 Drag::start_grab (event);
4342 if (!(_was_selected = _primary->selected())) {
4344 /* tertiary-click means extend selection - we'll do that on button release,
4345 so don't add it here, because otherwise we make it hard to figure
4346 out the "extend-to" range.
4349 bool extend = Keyboard::modifier_state_equals (event->button.state, Keyboard::TertiaryModifier);
4352 bool add = Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier);
4355 _region->note_selected (_primary, true);
4357 _region->unique_select (_primary);
4363 /** @return Current total drag x change in frames */
4365 NoteDrag::total_dx () const
4368 frameoffset_t const dx = _editor->pixel_to_sample (_drags->current_pointer_x() - grab_x());
4370 /* primary note time */
4371 frameoffset_t const n = _region->source_beats_to_absolute_frames (_primary->note()->time ());
4373 /* new time of the primary note in session frames */
4374 frameoffset_t st = n + dx;
4376 framepos_t const rp = _region->region()->position ();
4378 /* prevent the note being dragged earlier than the region's position */
4381 /* snap and return corresponding delta */
4382 return _region->snap_frame_to_frame (st - rp) + rp - n;
4385 /** @return Current total drag y change in note number */
4387 NoteDrag::total_dy () const
4389 MidiStreamView* msv = _region->midi_stream_view ();
4390 double const y = _region->midi_view()->y_position ();
4391 /* new current note */
4392 uint8_t n = msv->y_to_note (_drags->current_pointer_y () - y);
4394 n = max (msv->lowest_note(), n);
4395 n = min (msv->highest_note(), n);
4396 /* and work out delta */
4397 return n - msv->y_to_note (grab_y() - y);
4401 NoteDrag::motion (GdkEvent *, bool)
4403 /* Total change in x and y since the start of the drag */
4404 frameoffset_t const dx = total_dx ();
4405 int8_t const dy = total_dy ();
4407 /* Now work out what we have to do to the note canvas items to set this new drag delta */
4408 double const tdx = _editor->sample_to_pixel (dx) - _cumulative_dx;
4409 double const tdy = -dy * _note_height - _cumulative_dy;
4412 _cumulative_dx += tdx;
4413 _cumulative_dy += tdy;
4415 int8_t note_delta = total_dy();
4417 _region->move_selection (tdx, tdy, note_delta);
4419 /* the new note value may be the same as the old one, but we
4420 * don't know what that means because the selection may have
4421 * involved more than one note and we might be doing something
4422 * odd with them. so show the note value anyway, always.
4426 uint8_t new_note = min (max (_primary->note()->note() + note_delta, 0), 127);
4428 snprintf (buf, sizeof (buf), "%s (%d)", Evoral::midi_note_name (new_note).c_str(),
4429 (int) floor ((double)new_note));
4431 show_verbose_cursor_text (buf);
4436 NoteDrag::finished (GdkEvent* ev, bool moved)
4439 /* no motion - select note */
4441 if (_editor->current_mouse_mode() == Editing::MouseObject ||
4442 _editor->current_mouse_mode() == Editing::MouseDraw) {
4444 if (_was_selected) {
4445 bool add = Keyboard::modifier_state_equals (ev->button.state, Keyboard::PrimaryModifier);
4447 _region->note_deselected (_primary);
4450 bool extend = Keyboard::modifier_state_equals (ev->button.state, Keyboard::TertiaryModifier);
4451 bool add = Keyboard::modifier_state_equals (ev->button.state, Keyboard::PrimaryModifier);
4453 if (!extend && !add && _region->selection_size() > 1) {
4454 _region->unique_select (_primary);
4455 } else if (extend) {
4456 _region->note_selected (_primary, true, true);
4458 /* it was added during button press */
4463 _region->note_dropped (_primary, total_dx(), total_dy());
4468 NoteDrag::aborted (bool)
4473 /** Make an AutomationRangeDrag for lines in an AutomationTimeAxisView */
4474 AutomationRangeDrag::AutomationRangeDrag (Editor* editor, AutomationTimeAxisView* atv, list<AudioRange> const & r)
4475 : Drag (editor, atv->base_item ())
4477 , _nothing_to_drag (false)
4479 DEBUG_TRACE (DEBUG::Drags, "New AutomationRangeDrag\n");
4480 y_origin = atv->y_position();
4481 setup (atv->lines ());
4484 /** Make an AutomationRangeDrag for region gain lines */
4485 AutomationRangeDrag::AutomationRangeDrag (Editor* editor, AudioRegionView* rv, list<AudioRange> const & r)
4486 : Drag (editor, rv->get_canvas_group ())
4488 , _nothing_to_drag (false)
4490 DEBUG_TRACE (DEBUG::Drags, "New AutomationRangeDrag\n");
4492 list<boost::shared_ptr<AutomationLine> > lines;
4493 lines.push_back (rv->get_gain_line ());
4494 y_origin = rv->get_time_axis_view().y_position();
4498 /** @param lines AutomationLines to drag.
4499 * @param offset Offset from the session start to the points in the AutomationLines.
4502 AutomationRangeDrag::setup (list<boost::shared_ptr<AutomationLine> > const & lines)
4504 /* find the lines that overlap the ranges being dragged */
4505 list<boost::shared_ptr<AutomationLine> >::const_iterator i = lines.begin ();
4506 while (i != lines.end ()) {
4507 list<boost::shared_ptr<AutomationLine> >::const_iterator j = i;
4510 pair<framepos_t, framepos_t> r = (*i)->get_point_x_range ();
4512 /* check this range against all the AudioRanges that we are using */
4513 list<AudioRange>::const_iterator k = _ranges.begin ();
4514 while (k != _ranges.end()) {
4515 if (k->coverage (r.first, r.second) != Evoral::OverlapNone) {
4521 /* add it to our list if it overlaps at all */
4522 if (k != _ranges.end()) {
4527 _lines.push_back (n);
4533 /* Now ::lines contains the AutomationLines that somehow overlap our drag */
4537 AutomationRangeDrag::y_fraction (boost::shared_ptr<AutomationLine> line, double global_y) const
4539 return 1.0 - ((global_y - y_origin) / line->height());
4543 AutomationRangeDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
4545 Drag::start_grab (event, cursor);
4547 /* Get line states before we start changing things */
4548 for (list<Line>::iterator i = _lines.begin(); i != _lines.end(); ++i) {
4549 i->state = &i->line->get_state ();
4550 i->original_fraction = y_fraction (i->line, _drags->current_pointer_y());
4553 if (_ranges.empty()) {
4555 /* No selected time ranges: drag all points */
4556 for (list<Line>::iterator i = _lines.begin(); i != _lines.end(); ++i) {
4557 uint32_t const N = i->line->npoints ();
4558 for (uint32_t j = 0; j < N; ++j) {
4559 i->points.push_back (i->line->nth (j));
4565 for (list<AudioRange>::const_iterator i = _ranges.begin(); i != _ranges.end(); ++i) {
4567 framecnt_t const half = (i->start + i->end) / 2;
4569 /* find the line that this audio range starts in */
4570 list<Line>::iterator j = _lines.begin();
4571 while (j != _lines.end() && (j->range.first > i->start || j->range.second < i->start)) {
4575 if (j != _lines.end()) {
4576 boost::shared_ptr<AutomationList> the_list = j->line->the_list ();
4578 /* j is the line that this audio range starts in; fade into it;
4579 64 samples length plucked out of thin air.
4582 framepos_t a = i->start + 64;
4587 double const p = j->line->time_converter().from (i->start - j->line->time_converter().origin_b ());
4588 double const q = j->line->time_converter().from (a - j->line->time_converter().origin_b ());
4590 the_list->add (p, the_list->eval (p));
4591 the_list->add (q, the_list->eval (q));
4594 /* same thing for the end */
4597 while (j != _lines.end() && (j->range.first > i->end || j->range.second < i->end)) {
4601 if (j != _lines.end()) {
4602 boost::shared_ptr<AutomationList> the_list = j->line->the_list ();
4604 /* j is the line that this audio range starts in; fade out of it;
4605 64 samples length plucked out of thin air.
4608 framepos_t b = i->end - 64;
4613 double const p = j->line->time_converter().from (b - j->line->time_converter().origin_b ());
4614 double const q = j->line->time_converter().from (i->end - j->line->time_converter().origin_b ());
4616 the_list->add (p, the_list->eval (p));
4617 the_list->add (q, the_list->eval (q));
4621 _nothing_to_drag = true;
4623 /* Find all the points that should be dragged and put them in the relevant
4624 points lists in the Line structs.
4627 for (list<Line>::iterator i = _lines.begin(); i != _lines.end(); ++i) {
4629 uint32_t const N = i->line->npoints ();
4630 for (uint32_t j = 0; j < N; ++j) {
4632 /* here's a control point on this line */
4633 ControlPoint* p = i->line->nth (j);
4634 double const w = i->line->time_converter().to ((*p->model())->when) + i->line->time_converter().origin_b ();
4636 /* see if it's inside a range */
4637 list<AudioRange>::const_iterator k = _ranges.begin ();
4638 while (k != _ranges.end() && (k->start >= w || k->end <= w)) {
4642 if (k != _ranges.end()) {
4643 /* dragging this point */
4644 _nothing_to_drag = false;
4645 i->points.push_back (p);
4651 if (_nothing_to_drag) {
4655 for (list<Line>::iterator i = _lines.begin(); i != _lines.end(); ++i) {
4656 i->line->start_drag_multiple (i->points, y_fraction (i->line, _drags->current_pointer_y()), i->state);
4661 AutomationRangeDrag::motion (GdkEvent*, bool /*first_move*/)
4663 if (_nothing_to_drag) {
4667 for (list<Line>::iterator l = _lines.begin(); l != _lines.end(); ++l) {
4668 float const f = y_fraction (l->line, _drags->current_pointer_y());
4669 /* we are ignoring x position for this drag, so we can just pass in anything */
4671 l->line->drag_motion (0, f, true, false, ignored);
4672 show_verbose_cursor_text (l->line->get_verbose_cursor_relative_string (l->original_fraction, f));
4677 AutomationRangeDrag::finished (GdkEvent* event, bool)
4679 if (_nothing_to_drag) {
4683 motion (event, false);
4684 for (list<Line>::iterator i = _lines.begin(); i != _lines.end(); ++i) {
4685 i->line->end_drag (false, 0);
4688 _editor->session()->commit_reversible_command ();
4692 AutomationRangeDrag::aborted (bool)
4694 for (list<Line>::iterator i = _lines.begin(); i != _lines.end(); ++i) {
4699 DraggingView::DraggingView (RegionView* v, RegionDrag* parent)
4702 time_axis_view = parent->find_time_axis_view (&v->get_time_axis_view ());
4703 layer = v->region()->layer ();
4704 initial_y = v->get_canvas_group()->position().y;
4705 initial_playlist = v->region()->playlist ();
4706 initial_position = v->region()->position ();
4707 initial_end = v->region()->position () + v->region()->length ();
4710 PatchChangeDrag::PatchChangeDrag (Editor* e, PatchChange* i, MidiRegionView* r)
4711 : Drag (e, i->canvas_item ())
4714 , _cumulative_dx (0)
4716 DEBUG_TRACE (DEBUG::Drags, string_compose ("New PatchChangeDrag, patch @ %1, grab @ %2\n",
4717 _region_view->source_beats_to_absolute_frames (_patch_change->patch()->time()),
4722 PatchChangeDrag::motion (GdkEvent* ev, bool)
4724 framepos_t f = adjusted_current_frame (ev);
4725 boost::shared_ptr<Region> r = _region_view->region ();
4726 f = max (f, r->position ());
4727 f = min (f, r->last_frame ());
4729 framecnt_t const dxf = f - grab_frame(); // permitted dx in frames
4730 double const dxu = _editor->sample_to_pixel (dxf); // permitted fx in units
4731 _patch_change->move (ArdourCanvas::Duple (dxu - _cumulative_dx, 0));
4732 _cumulative_dx = dxu;
4736 PatchChangeDrag::finished (GdkEvent* ev, bool movement_occurred)
4738 if (!movement_occurred) {
4742 boost::shared_ptr<Region> r (_region_view->region ());
4743 framepos_t f = adjusted_current_frame (ev);
4744 f = max (f, r->position ());
4745 f = min (f, r->last_frame ());
4747 _region_view->move_patch_change (
4749 _region_view->region_frames_to_region_beats (f - (r->position() - r->start()))
4754 PatchChangeDrag::aborted (bool)
4756 _patch_change->move (ArdourCanvas::Duple (-_cumulative_dx, 0));
4760 PatchChangeDrag::setup_pointer_frame_offset ()
4762 boost::shared_ptr<Region> region = _region_view->region ();
4763 _pointer_frame_offset = raw_grab_frame() - _region_view->source_beats_to_absolute_frames (_patch_change->patch()->time());
4766 MidiRubberbandSelectDrag::MidiRubberbandSelectDrag (Editor* e, MidiRegionView* rv)
4767 : RubberbandSelectDrag (e, rv->get_canvas_group ())
4774 MidiRubberbandSelectDrag::select_things (int button_state, framepos_t x1, framepos_t x2, double y1, double y2, bool /*drag_in_progress*/)
4776 framepos_t const p = _region_view->region()->position ();
4777 double const y = _region_view->midi_view()->y_position ();
4779 x1 = max ((framepos_t) 0, x1 - p);
4780 x2 = max ((framepos_t) 0, x2 - p);
4781 y1 = max (0.0, y1 - y);
4782 y2 = max (0.0, y2 - y);
4784 _region_view->update_drag_selection (
4785 _editor->sample_to_pixel (x1),
4786 _editor->sample_to_pixel (x2),
4789 Keyboard::modifier_state_contains (button_state, Keyboard::TertiaryModifier)
4794 MidiRubberbandSelectDrag::deselect_things ()
4799 MidiVerticalSelectDrag::MidiVerticalSelectDrag (Editor* e, MidiRegionView* rv)
4800 : RubberbandSelectDrag (e, rv->get_canvas_group ())
4803 _vertical_only = true;
4807 MidiVerticalSelectDrag::select_things (int button_state, framepos_t /*x1*/, framepos_t /*x2*/, double y1, double y2, bool /*drag_in_progress*/)
4809 double const y = _region_view->midi_view()->y_position ();
4811 y1 = max (0.0, y1 - y);
4812 y2 = max (0.0, y2 - y);
4814 _region_view->update_vertical_drag_selection (
4817 Keyboard::modifier_state_contains (button_state, Keyboard::TertiaryModifier)
4822 MidiVerticalSelectDrag::deselect_things ()
4827 EditorRubberbandSelectDrag::EditorRubberbandSelectDrag (Editor* e, ArdourCanvas::Item* i)
4828 : RubberbandSelectDrag (e, i)
4834 EditorRubberbandSelectDrag::select_things (int button_state, framepos_t x1, framepos_t x2, double y1, double y2, bool drag_in_progress)
4836 if (drag_in_progress) {
4837 /* We just want to select things at the end of the drag, not during it */
4841 Selection::Operation op = ArdourKeyboard::selection_type (button_state);
4843 _editor->begin_reversible_command (_("rubberband selection"));
4844 _editor->select_all_within (x1, x2 - 1, y1, y2, _editor->track_views, op, false);
4845 _editor->commit_reversible_command ();
4849 EditorRubberbandSelectDrag::deselect_things ()
4851 if (!getenv("ARDOUR_SAE")) {
4852 _editor->selection->clear_tracks();
4854 _editor->selection->clear_regions();
4855 _editor->selection->clear_points ();
4856 _editor->selection->clear_lines ();
4859 NoteCreateDrag::NoteCreateDrag (Editor* e, ArdourCanvas::Item* i, MidiRegionView* rv)
4867 NoteCreateDrag::~NoteCreateDrag ()
4873 NoteCreateDrag::grid_frames (framepos_t t) const
4876 Evoral::MusicalTime grid_beats = _editor->get_grid_type_as_beats (success, t);
4881 return _region_view->region_beats_to_region_frames (grid_beats);
4885 NoteCreateDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
4887 Drag::start_grab (event, cursor);
4889 _drag_rect = new ArdourCanvas::Rectangle (_region_view->get_canvas_group ());
4891 framepos_t pf = _drags->current_pointer_frame ();
4892 framecnt_t const g = grid_frames (pf);
4894 /* Hack so that we always snap to the note that we are over, instead of snapping
4895 to the next one if we're more than halfway through the one we're over.
4897 if (_editor->snap_mode() == SnapNormal && pf > g / 2) {
4901 _note[0] = adjusted_frame (pf, event) - _region_view->region()->position ();
4903 MidiStreamView* sv = _region_view->midi_stream_view ();
4904 double const x = _editor->sample_to_pixel (_note[0]);
4905 double const y = sv->note_to_y (sv->y_to_note (y_to_region (event->button.y)));
4907 _drag_rect->set (ArdourCanvas::Rect (x, y, x, y + floor (_region_view->midi_stream_view()->note_height ())));
4908 _drag_rect->set_outline_all ();
4909 _drag_rect->set_outline_color (0xffffff99);
4910 _drag_rect->set_fill_color (0xffffff66);
4914 NoteCreateDrag::motion (GdkEvent* event, bool)
4916 _note[1] = max ((framepos_t)0, adjusted_current_frame (event) - _region_view->region()->position ());
4917 double const x = _editor->sample_to_pixel (_note[1]);
4918 if (_note[1] > _note[0]) {
4919 _drag_rect->set_x1 (x);
4921 _drag_rect->set_x0 (x);
4926 NoteCreateDrag::finished (GdkEvent*, bool had_movement)
4928 if (!had_movement) {
4932 framepos_t const start = min (_note[0], _note[1]);
4933 framecnt_t length = (framecnt_t) fabs ((double)(_note[0] - _note[1]));
4935 framecnt_t const g = grid_frames (start);
4936 double const one_tick = 1 / Timecode::BBT_Time::ticks_per_beat;
4938 if (_editor->snap_mode() == SnapNormal && length < g) {
4939 length = g - one_tick;
4942 double const length_beats = max (one_tick, _region_view->region_frames_to_region_beats (length));
4944 _region_view->create_note_at (start, _drag_rect->y0(), length_beats, false);
4948 NoteCreateDrag::y_to_region (double y) const
4951 _region_view->get_canvas_group()->canvas_to_item (x, y);
4956 NoteCreateDrag::aborted (bool)
4961 CrossfadeEdgeDrag::CrossfadeEdgeDrag (Editor* e, AudioRegionView* rv, ArdourCanvas::Item* i, bool start_yn)
4966 std::cout << ("CrossfadeEdgeDrag is DEPRECATED. See TrimDrag::preserve_fade_anchor") << endl;
4970 CrossfadeEdgeDrag::start_grab (GdkEvent* event, Gdk::Cursor *cursor)
4972 Drag::start_grab (event, cursor);
4976 CrossfadeEdgeDrag::motion (GdkEvent*, bool)
4982 boost::shared_ptr<AudioRegion> ar (arv->audio_region());
4985 distance = _drags->current_pointer_x() - grab_x();
4986 len = ar->fade_in()->back()->when;
4988 distance = grab_x() - _drags->current_pointer_x();
4989 len = ar->fade_out()->back()->when;
4992 /* how long should it be ? */
4994 new_length = len + _editor->pixel_to_sample (distance);
4996 /* now check with the region that this is legal */
4998 new_length = ar->verify_xfade_bounds (new_length, start);
5001 arv->reset_fade_in_shape_width (ar, new_length);
5003 arv->reset_fade_out_shape_width (ar, new_length);
5008 CrossfadeEdgeDrag::finished (GdkEvent*, bool)
5014 boost::shared_ptr<AudioRegion> ar (arv->audio_region());
5017 distance = _drags->current_pointer_x() - grab_x();
5018 len = ar->fade_in()->back()->when;
5020 distance = grab_x() - _drags->current_pointer_x();
5021 len = ar->fade_out()->back()->when;
5024 new_length = ar->verify_xfade_bounds (len + _editor->pixel_to_sample (distance), start);
5026 _editor->begin_reversible_command ("xfade trim");
5027 ar->playlist()->clear_owned_changes ();
5030 ar->set_fade_in_length (new_length);
5032 ar->set_fade_out_length (new_length);
5035 /* Adjusting the xfade may affect other regions in the playlist, so we need
5036 to get undo Commands from the whole playlist rather than just the
5040 vector<Command*> cmds;
5041 ar->playlist()->rdiff (cmds);
5042 _editor->session()->add_commands (cmds);
5043 _editor->commit_reversible_command ();
5048 CrossfadeEdgeDrag::aborted (bool)
5051 arv->redraw_start_xfade ();
5053 arv->redraw_end_xfade ();