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"
26 #include "pbd/memento_command.h"
27 #include "pbd/basename.h"
28 #include "pbd/stateful_diff_command.h"
30 #include "gtkmm2ext/utils.h"
32 #include "ardour/audioengine.h"
33 #include "ardour/audioregion.h"
34 #include "ardour/dB.h"
35 #include "ardour/midi_region.h"
36 #include "ardour/operations.h"
37 #include "ardour/region_factory.h"
38 #include "ardour/session.h"
43 #include "audio_region_view.h"
44 #include "midi_region_view.h"
45 #include "ardour_ui.h"
46 #include "gui_thread.h"
47 #include "control_point.h"
49 #include "region_gain_line.h"
50 #include "editor_drag.h"
51 #include "audio_time_axis.h"
52 #include "midi_time_axis.h"
53 #include "canvas-note.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 "verbose_cursor.h"
63 using namespace ARDOUR;
66 using namespace Gtkmm2ext;
67 using namespace Editing;
68 using namespace ArdourCanvas;
70 using Gtkmm2ext::Keyboard;
72 double ControlPointDrag::_zero_gain_fraction = -1.0;
74 DragManager::DragManager (Editor* e)
77 , _current_pointer_frame (0)
81 DragManager::~DragManager ()
86 /** Call abort for each active drag */
92 for (list<Drag*>::const_iterator i = _drags.begin(); i != _drags.end(); ++i) {
97 if (!_drags.empty ()) {
98 _editor->set_follow_playhead (_old_follow_playhead, false);
107 DragManager::add (Drag* d)
109 d->set_manager (this);
110 _drags.push_back (d);
114 DragManager::set (Drag* d, GdkEvent* e, Gdk::Cursor* c)
116 d->set_manager (this);
117 _drags.push_back (d);
122 DragManager::start_grab (GdkEvent* e, Gdk::Cursor* c)
124 /* Prevent follow playhead during the drag to be nice to the user */
125 _old_follow_playhead = _editor->follow_playhead ();
126 _editor->set_follow_playhead (false);
128 _current_pointer_frame = _editor->event_frame (e, &_current_pointer_x, &_current_pointer_y);
130 for (list<Drag*>::const_iterator i = _drags.begin(); i != _drags.end(); ++i) {
131 (*i)->start_grab (e, c);
135 /** Call end_grab for each active drag.
136 * @return true if any drag reported movement having occurred.
139 DragManager::end_grab (GdkEvent* e)
144 for (list<Drag*>::iterator i = _drags.begin(); i != _drags.end(); ++i) {
145 bool const t = (*i)->end_grab (e);
156 _editor->set_follow_playhead (_old_follow_playhead, false);
162 DragManager::motion_handler (GdkEvent* e, bool from_autoscroll)
166 _current_pointer_frame = _editor->event_frame (e, &_current_pointer_x, &_current_pointer_y);
168 for (list<Drag*>::iterator i = _drags.begin(); i != _drags.end(); ++i) {
169 bool const t = (*i)->motion_handler (e, from_autoscroll);
180 DragManager::have_item (ArdourCanvas::Item* i) const
182 list<Drag*>::const_iterator j = _drags.begin ();
183 while (j != _drags.end() && (*j)->item () != i) {
187 return j != _drags.end ();
190 Drag::Drag (Editor* e, ArdourCanvas::Item* i)
193 , _pointer_frame_offset (0)
194 , _move_threshold_passed (false)
195 , _raw_grab_frame (0)
197 , _last_pointer_frame (0)
203 Drag::swap_grab (ArdourCanvas::Item* new_item, Gdk::Cursor* cursor, uint32_t time)
209 _item->grab (Gdk::POINTER_MOTION_MASK | Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK, time);
211 _item->grab (Gdk::POINTER_MOTION_MASK | Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK, *cursor, time);
216 Drag::start_grab (GdkEvent* event, Gdk::Cursor *cursor)
218 // if dragging with button2, the motion is x constrained, with Alt-button2 it is y constrained
220 if (Keyboard::is_button2_event (&event->button)) {
221 if (Keyboard::modifier_state_equals (event->button.state, Keyboard::SecondaryModifier)) {
222 _y_constrained = true;
223 _x_constrained = false;
225 _y_constrained = false;
226 _x_constrained = true;
229 _x_constrained = false;
230 _y_constrained = false;
233 _raw_grab_frame = _editor->event_frame (event, &_grab_x, &_grab_y);
234 setup_pointer_frame_offset ();
235 _grab_frame = adjusted_frame (_raw_grab_frame, event);
236 _last_pointer_frame = _grab_frame;
237 _last_pointer_x = _grab_x;
238 _last_pointer_y = _grab_y;
241 _item->grab (Gdk::POINTER_MOTION_MASK|Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK,
244 _item->grab (Gdk::POINTER_MOTION_MASK|Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK,
249 if (_editor->session() && _editor->session()->transport_rolling()) {
252 _was_rolling = false;
255 switch (_editor->snap_type()) {
256 case SnapToRegionStart:
257 case SnapToRegionEnd:
258 case SnapToRegionSync:
259 case SnapToRegionBoundary:
260 _editor->build_region_boundary_cache ();
267 /** Call to end a drag `successfully'. Ungrabs item and calls
268 * subclass' finished() method.
270 * @param event GDK event, or 0.
271 * @return true if some movement occurred, otherwise false.
274 Drag::end_grab (GdkEvent* event)
276 _editor->stop_canvas_autoscroll ();
278 _item->ungrab (event ? event->button.time : 0);
280 finished (event, _move_threshold_passed);
282 _editor->verbose_cursor()->hide ();
284 return _move_threshold_passed;
288 Drag::adjusted_frame (framepos_t f, GdkEvent const * event, bool snap) const
292 if (f > _pointer_frame_offset) {
293 pos = f - _pointer_frame_offset;
297 _editor->snap_to_with_modifier (pos, event);
304 Drag::adjusted_current_frame (GdkEvent const * event, bool snap) const
306 return adjusted_frame (_drags->current_pointer_frame (), event, snap);
310 Drag::motion_handler (GdkEvent* event, bool from_autoscroll)
312 /* check to see if we have moved in any way that matters since the last motion event */
313 if (_move_threshold_passed &&
314 (!x_movement_matters() || _last_pointer_frame == adjusted_current_frame (event)) &&
315 (!y_movement_matters() || _last_pointer_y == _drags->current_pointer_y ()) ) {
319 pair<framecnt_t, int> const threshold = move_threshold ();
321 bool const old_move_threshold_passed = _move_threshold_passed;
323 if (!from_autoscroll && !_move_threshold_passed) {
325 bool const xp = (::llabs (_drags->current_pointer_frame () - _raw_grab_frame) >= threshold.first);
326 bool const yp = (::fabs ((_drags->current_pointer_y () - _grab_y)) >= threshold.second);
328 _move_threshold_passed = ((xp && x_movement_matters()) || (yp && y_movement_matters()));
331 if (active (_editor->mouse_mode) && _move_threshold_passed) {
333 if (event->motion.state & Gdk::BUTTON1_MASK || event->motion.state & Gdk::BUTTON2_MASK) {
334 if (!from_autoscroll) {
335 bool const moving_left = _drags->current_pointer_x() < _last_pointer_x;
336 bool const moving_up = _drags->current_pointer_y() < _last_pointer_y;
337 _editor->maybe_autoscroll (true, allow_vertical_autoscroll (), moving_left, moving_up);
340 motion (event, _move_threshold_passed != old_move_threshold_passed);
342 _last_pointer_x = _drags->current_pointer_x ();
343 _last_pointer_y = _drags->current_pointer_y ();
344 _last_pointer_frame = adjusted_current_frame (event);
352 /** Call to abort a drag. Ungrabs item and calls subclass's aborted () */
360 aborted (_move_threshold_passed);
362 _editor->stop_canvas_autoscroll ();
363 _editor->verbose_cursor()->hide ();
367 Drag::show_verbose_cursor_time (framepos_t frame)
369 _editor->verbose_cursor()->set_time (
371 _drags->current_pointer_x() + 10 - _editor->horizontal_position(),
372 _drags->current_pointer_y() + 10 - _editor->vertical_adjustment.get_value() + _editor->canvas_timebars_vsize
375 _editor->verbose_cursor()->show ();
379 Drag::show_verbose_cursor_duration (framepos_t start, framepos_t end, double xoffset)
381 _editor->verbose_cursor()->show (xoffset);
383 _editor->verbose_cursor()->set_duration (
385 _drags->current_pointer_x() + 10 - _editor->horizontal_position(),
386 _drags->current_pointer_y() + 10 - _editor->vertical_adjustment.get_value() + _editor->canvas_timebars_vsize
391 Drag::show_verbose_cursor_text (string const & text)
393 _editor->verbose_cursor()->show ();
395 _editor->verbose_cursor()->set (
397 _drags->current_pointer_x() + 10 - _editor->horizontal_position(),
398 _drags->current_pointer_y() + 10 - _editor->vertical_adjustment.get_value() + _editor->canvas_timebars_vsize
402 boost::shared_ptr<Region>
403 Drag::add_midi_region (MidiTimeAxisView* view)
405 if (_editor->session()) {
406 const TempoMap& map (_editor->session()->tempo_map());
407 framecnt_t pos = grab_frame();
408 const Meter& m = map.meter_at (pos);
409 /* not that the frame rate used here can be affected by pull up/down which
412 framecnt_t len = m.frames_per_bar (map.tempo_at (pos), _editor->session()->frame_rate());
413 return view->add_region (grab_frame(), len, true);
416 return boost::shared_ptr<Region>();
419 struct EditorOrderTimeAxisViewSorter {
420 bool operator() (TimeAxisView* a, TimeAxisView* b) {
421 RouteTimeAxisView* ra = dynamic_cast<RouteTimeAxisView*> (a);
422 RouteTimeAxisView* rb = dynamic_cast<RouteTimeAxisView*> (b);
424 return ra->route()->order_key (EditorSort) < rb->route()->order_key (EditorSort);
428 RegionDrag::RegionDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, list<RegionView*> const & v)
432 _editor->visible_order_range (&_visible_y_low, &_visible_y_high);
434 /* Make a list of tracks to refer to during the drag; we include hidden tracks,
435 as some of the regions we are dragging may be on such tracks.
438 TrackViewList track_views = _editor->track_views;
439 track_views.sort (EditorOrderTimeAxisViewSorter ());
441 for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) {
442 _time_axis_views.push_back (*i);
444 TimeAxisView::Children children_list = (*i)->get_child_list ();
445 for (TimeAxisView::Children::iterator j = children_list.begin(); j != children_list.end(); ++j) {
446 _time_axis_views.push_back (j->get());
450 /* the list of views can be empty at this point if this is a region list-insert drag
453 for (list<RegionView*>::const_iterator i = v.begin(); i != v.end(); ++i) {
454 _views.push_back (DraggingView (*i, this));
457 RegionView::RegionViewGoingAway.connect (death_connection, invalidator (*this), boost::bind (&RegionDrag::region_going_away, this, _1), gui_context());
461 RegionDrag::region_going_away (RegionView* v)
463 list<DraggingView>::iterator i = _views.begin ();
464 while (i != _views.end() && i->view != v) {
468 if (i != _views.end()) {
473 /** Given a TimeAxisView, return the index of it into the _time_axis_views vector,
474 * or -1 if it is not found.
477 RegionDrag::find_time_axis_view (TimeAxisView* t) const
480 int const N = _time_axis_views.size ();
481 while (i < N && _time_axis_views[i] != t) {
492 RegionMotionDrag::RegionMotionDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, list<RegionView*> const & v, bool b)
493 : RegionDrag (e, i, p, v),
502 RegionMotionDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
504 Drag::start_grab (event, cursor);
506 show_verbose_cursor_time (_last_frame_position);
508 pair<TimeAxisView*, double> const tv = _editor->trackview_by_y_position (_drags->current_pointer_y ());
509 _last_pointer_time_axis_view = find_time_axis_view (tv.first);
510 _last_pointer_layer = tv.first->layer_display() == Overlaid ? 0 : tv.second;
514 RegionMotionDrag::compute_x_delta (GdkEvent const * event, framepos_t* pending_region_position)
516 /* compute the amount of pointer motion in frames, and where
517 the region would be if we moved it by that much.
519 *pending_region_position = adjusted_current_frame (event);
521 framepos_t sync_frame;
522 framecnt_t sync_offset;
525 sync_offset = _primary->region()->sync_offset (sync_dir);
527 /* we don't handle a sync point that lies before zero.
529 if (sync_dir >= 0 || (sync_dir < 0 && *pending_region_position >= sync_offset)) {
531 sync_frame = *pending_region_position + (sync_dir*sync_offset);
533 _editor->snap_to_with_modifier (sync_frame, event);
535 *pending_region_position = _primary->region()->adjust_to_sync (sync_frame);
538 *pending_region_position = _last_frame_position;
541 if (*pending_region_position > max_framepos - _primary->region()->length()) {
542 *pending_region_position = _last_frame_position;
547 /* in locked edit mode, reverse the usual meaning of _x_constrained */
548 bool const x_move_allowed = Config->get_edit_mode() == Lock ? _x_constrained : !_x_constrained;
550 if ((*pending_region_position != _last_frame_position) && x_move_allowed) {
552 /* x movement since last time (in pixels) */
553 dx = (static_cast<double> (*pending_region_position) - _last_frame_position) / _editor->frames_per_unit;
555 /* total x movement */
556 framecnt_t total_dx = *pending_region_position;
557 if (regions_came_from_canvas()) {
558 total_dx = total_dx - grab_frame ();
561 /* check that no regions have gone off the start of the session */
562 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
563 if ((i->view->region()->position() + total_dx) < 0) {
565 *pending_region_position = _last_frame_position;
570 _last_frame_position = *pending_region_position;
577 RegionMotionDrag::y_movement_allowed (int delta_track, double delta_layer) const
579 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
580 int const n = i->time_axis_view + delta_track;
581 if (n < 0 || n >= int (_time_axis_views.size())) {
582 /* off the top or bottom track */
586 RouteTimeAxisView const * to = dynamic_cast<RouteTimeAxisView const *> (_time_axis_views[n]);
587 if (to == 0 || !to->is_track() || to->track()->data_type() != i->view->region()->data_type()) {
588 /* not a track, or the wrong type */
592 double const l = i->layer + delta_layer;
594 /* Note that we allow layer to be up to 0.5 below zero, as this is used by `Expanded'
595 mode to allow the user to place a region below another on layer 0.
597 if (delta_track == 0 && (l < -0.5 || l >= int (to->view()->layers()))) {
598 /* Off the top or bottom layer; note that we only refuse if the track hasn't changed.
599 If it has, the layers will be munged later anyway, so it's ok.
605 /* all regions being dragged are ok with this change */
610 RegionMotionDrag::motion (GdkEvent* event, bool first_move)
612 assert (!_views.empty ());
614 /* Find the TimeAxisView that the pointer is now over */
615 pair<TimeAxisView*, double> const tv = _editor->trackview_by_y_position (_drags->current_pointer_y ());
617 if (first_move && tv.first->view()->layer_display() == Stacked) {
618 tv.first->view()->set_layer_display (Expanded);
621 /* Bail early if we're not over a track */
622 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (tv.first);
623 if (!rtv || !rtv->is_track()) {
624 _editor->verbose_cursor()->hide ();
628 /* Note: time axis views in this method are often expressed as an index into the _time_axis_views vector */
630 /* Here's the current pointer position in terms of time axis view and layer */
631 int const current_pointer_time_axis_view = find_time_axis_view (tv.first);
632 double const current_pointer_layer = tv.first->layer_display() == Overlaid ? 0 : tv.second;
634 /* Work out the change in x */
635 framepos_t pending_region_position;
636 double const x_delta = compute_x_delta (event, &pending_region_position);
638 /* Work out the change in y */
639 int delta_time_axis_view = current_pointer_time_axis_view - _last_pointer_time_axis_view;
640 double delta_layer = current_pointer_layer - _last_pointer_layer;
642 if (!y_movement_allowed (delta_time_axis_view, delta_layer)) {
643 /* this y movement is not allowed, so do no y movement this time */
644 delta_time_axis_view = 0;
648 if (x_delta == 0 && delta_time_axis_view == 0 && delta_layer == 0 && !first_move) {
649 /* haven't reached next snap point, and we're not switching
650 trackviews nor layers. nothing to do.
655 pair<set<boost::shared_ptr<Playlist> >::iterator,bool> insert_result;
657 for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
659 RegionView* rv = i->view;
661 if (rv->region()->locked()) {
669 /* Absolutely no idea why this is necessary, but it is; without
670 it, the region view disappears after the reparent.
672 _editor->update_canvas_now ();
674 /* Reparent to a non scrolling group so that we can keep the
675 region selection above all time axis views.
676 Reparenting means that we will have to move the region view
677 later, as the two parent groups have different coordinates.
680 rv->get_canvas_group()->reparent (*(_editor->_region_motion_group));
682 rv->fake_set_opaque (true);
685 /* If we have moved tracks, we'll fudge the layer delta so that the
686 region gets moved back onto layer 0 on its new track; this avoids
687 confusion when dragging regions from non-zero layers onto different
690 double this_delta_layer = delta_layer;
691 if (delta_time_axis_view != 0) {
692 this_delta_layer = - i->layer;
695 /* The TimeAxisView that this region is now on */
696 TimeAxisView* tv = _time_axis_views[i->time_axis_view + delta_time_axis_view];
698 /* Ensure it is moved from stacked -> expanded if appropriate */
699 if (tv->view()->layer_display() == Stacked) {
700 tv->view()->set_layer_display (Expanded);
703 /* We're only allowed to go -ve in layer on Expanded views */
704 if (tv->view()->layer_display() != Expanded && (i->layer + this_delta_layer) < 0) {
705 this_delta_layer = - i->layer;
709 rv->set_height (tv->view()->child_height ());
711 /* Update show/hidden status as the region view may have come from a hidden track,
712 or have moved to one.
715 rv->get_canvas_group()->hide ();
717 rv->get_canvas_group()->show ();
720 /* Update the DraggingView */
721 i->time_axis_view += delta_time_axis_view;
722 i->layer += this_delta_layer;
725 _editor->mouse_brush_insert_region (rv, pending_region_position);
730 /* Get the y coordinate of the top of the track that this region is now on */
731 tv->canvas_display()->i2w (x, y);
732 y += _editor->get_trackview_group_vertical_offset();
734 /* And adjust for the layer that it should be on */
735 StreamView* cv = tv->view ();
736 switch (cv->layer_display ()) {
740 y += (cv->layers() - i->layer - 1) * cv->child_height ();
743 y += (cv->layers() - i->layer - 0.5) * 2 * cv->child_height ();
747 /* Now move the region view */
748 rv->move (x_delta, y - rv->get_canvas_group()->property_y());
751 } /* foreach region */
753 _total_x_delta += x_delta;
756 _editor->cursor_group->raise_to_top();
759 if (x_delta != 0 && !_brushing) {
760 show_verbose_cursor_time (_last_frame_position);
763 _last_pointer_time_axis_view += delta_time_axis_view;
764 _last_pointer_layer += delta_layer;
768 RegionMoveDrag::motion (GdkEvent* event, bool first_move)
770 if (_copy && first_move) {
772 /* duplicate the regionview(s) and region(s) */
774 list<DraggingView> new_regionviews;
776 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
778 RegionView* rv = i->view;
779 AudioRegionView* arv = dynamic_cast<AudioRegionView*>(rv);
780 MidiRegionView* mrv = dynamic_cast<MidiRegionView*>(rv);
782 const boost::shared_ptr<const Region> original = rv->region();
783 boost::shared_ptr<Region> region_copy = RegionFactory::create (original, true);
784 region_copy->set_position (original->position());
788 boost::shared_ptr<AudioRegion> audioregion_copy
789 = boost::dynamic_pointer_cast<AudioRegion>(region_copy);
791 nrv = new AudioRegionView (*arv, audioregion_copy);
793 boost::shared_ptr<MidiRegion> midiregion_copy
794 = boost::dynamic_pointer_cast<MidiRegion>(region_copy);
795 nrv = new MidiRegionView (*mrv, midiregion_copy);
800 nrv->get_canvas_group()->show ();
801 new_regionviews.push_back (DraggingView (nrv, this));
803 /* swap _primary to the copy */
805 if (rv == _primary) {
809 /* ..and deselect the one we copied */
811 rv->set_selected (false);
814 if (!new_regionviews.empty()) {
816 /* reflect the fact that we are dragging the copies */
818 _views = new_regionviews;
820 swap_grab (new_regionviews.front().view->get_canvas_group (), 0, event ? event->motion.time : 0);
823 sync the canvas to what we think is its current state
824 without it, the canvas seems to
825 "forget" to update properly after the upcoming reparent()
826 ..only if the mouse is in rapid motion at the time of the grab.
827 something to do with regionview creation taking so long?
829 _editor->update_canvas_now();
833 RegionMotionDrag::motion (event, first_move);
837 RegionMotionDrag::finished (GdkEvent *, bool)
839 for (vector<TimeAxisView*>::iterator i = _time_axis_views.begin(); i != _time_axis_views.end(); ++i) {
844 if ((*i)->view()->layer_display() == Expanded) {
845 (*i)->view()->set_layer_display (Stacked);
851 RegionMoveDrag::finished (GdkEvent* ev, bool movement_occurred)
853 RegionMotionDrag::finished (ev, movement_occurred);
855 if (!movement_occurred) {
860 /* reverse this here so that we have the correct logic to finalize
864 if (Config->get_edit_mode() == Lock) {
865 _x_constrained = !_x_constrained;
868 assert (!_views.empty ());
870 /* We might have hidden region views so that they weren't visible during the drag
871 (when they have been reparented). Now everything can be shown again, as region
872 views are back in their track parent groups.
874 for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
875 i->view->get_canvas_group()->show ();
878 bool const changed_position = (_last_frame_position != _primary->region()->position());
879 bool const changed_tracks = (_time_axis_views[_views.front().time_axis_view] != &_views.front().view->get_time_axis_view());
880 framecnt_t const drag_delta = _primary->region()->position() - _last_frame_position;
882 _editor->update_canvas_now ();
902 _editor->maybe_locate_with_edit_preroll (_editor->get_selection().regions.start());
906 RegionMoveDrag::finished_copy (bool const changed_position, bool const /*changed_tracks*/, framecnt_t const drag_delta)
908 RegionSelection new_views;
909 PlaylistSet modified_playlists;
910 list<RegionView*> views_to_delete;
913 /* all changes were made during motion event handlers */
915 for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
919 _editor->commit_reversible_command ();
923 if (_x_constrained) {
924 _editor->begin_reversible_command (Operations::fixed_time_region_copy);
926 _editor->begin_reversible_command (Operations::region_copy);
929 /* insert the regions into their new playlists */
930 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
932 if (i->view->region()->locked()) {
938 if (changed_position && !_x_constrained) {
939 where = i->view->region()->position() - drag_delta;
941 where = i->view->region()->position();
944 RegionView* new_view = insert_region_into_playlist (
945 i->view->region(), dynamic_cast<RouteTimeAxisView*> (_time_axis_views[i->time_axis_view]), i->layer, where, modified_playlists
952 new_views.push_back (new_view);
954 /* we don't need the copied RegionView any more */
955 views_to_delete.push_back (i->view);
958 /* Delete views that are no longer needed; we can't do this directly in the iteration over _views
959 because when views are deleted they are automagically removed from _views, which messes
962 for (list<RegionView*>::iterator i = views_to_delete.begin(); i != views_to_delete.end(); ++i) {
966 /* If we've created new regions either by copying or moving
967 to a new track, we want to replace the old selection with the new ones
970 if (new_views.size() > 0) {
971 _editor->selection->set (new_views);
974 /* write commands for the accumulated diffs for all our modified playlists */
975 add_stateful_diff_commands_for_playlists (modified_playlists);
977 _editor->commit_reversible_command ();
981 RegionMoveDrag::finished_no_copy (
982 bool const changed_position,
983 bool const changed_tracks,
984 framecnt_t const drag_delta
987 RegionSelection new_views;
988 PlaylistSet modified_playlists;
989 PlaylistSet frozen_playlists;
990 set<RouteTimeAxisView*> views_to_update;
993 /* all changes were made during motion event handlers */
994 _editor->commit_reversible_command ();
998 if (_x_constrained) {
999 _editor->begin_reversible_command (_("fixed time region drag"));
1001 _editor->begin_reversible_command (Operations::region_drag);
1004 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ) {
1006 RegionView* rv = i->view;
1008 RouteTimeAxisView* const dest_rtv = dynamic_cast<RouteTimeAxisView*> (_time_axis_views[i->time_axis_view]);
1009 double const dest_layer = i->layer;
1011 if (rv->region()->locked()) {
1016 views_to_update.insert (dest_rtv);
1020 if (changed_position && !_x_constrained) {
1021 where = rv->region()->position() - drag_delta;
1023 where = rv->region()->position();
1026 if (changed_tracks) {
1028 /* insert into new playlist */
1030 RegionView* new_view = insert_region_into_playlist (
1031 RegionFactory::create (rv->region (), true), dest_rtv, dest_layer, where, modified_playlists
1034 if (new_view == 0) {
1039 new_views.push_back (new_view);
1041 /* remove from old playlist */
1043 /* the region that used to be in the old playlist is not
1044 moved to the new one - we use a copy of it. as a result,
1045 any existing editor for the region should no longer be
1048 rv->hide_region_editor();
1049 rv->fake_set_opaque (false);
1051 remove_region_from_playlist (rv->region(), i->initial_playlist, modified_playlists);
1055 rv->region()->clear_changes ();
1058 motion on the same track. plonk the previously reparented region
1059 back to its original canvas group (its streamview).
1060 No need to do anything for copies as they are fake regions which will be deleted.
1063 rv->get_canvas_group()->reparent (*dest_rtv->view()->canvas_item());
1064 rv->get_canvas_group()->property_y() = i->initial_y;
1067 /* just change the model */
1069 boost::shared_ptr<Playlist> playlist = dest_rtv->playlist();
1071 if (dest_rtv->view()->layer_display() == Stacked || dest_rtv->view()->layer_display() == Expanded) {
1072 playlist->set_layer (rv->region(), dest_layer);
1075 /* freeze playlist to avoid lots of relayering in the case of a multi-region drag */
1077 pair<PlaylistSet::iterator, bool> r = frozen_playlists.insert (playlist);
1080 playlist->freeze ();
1083 /* this movement may result in a crossfade being modified, so we need to get undo
1084 data from the playlist as well as the region.
1087 r = modified_playlists.insert (playlist);
1089 playlist->clear_changes ();
1092 rv->region()->set_position (where);
1094 _editor->session()->add_command (new StatefulDiffCommand (rv->region()));
1097 if (changed_tracks) {
1099 /* OK, this is where it gets tricky. If the playlist was being used by >1 tracks, and the region
1100 was selected in all of them, then removing it from a playlist will have removed all
1101 trace of it from _views (i.e. there were N regions selected, we removed 1,
1102 but since its the same playlist for N tracks, all N tracks updated themselves, removed the
1103 corresponding regionview, and _views is now empty).
1105 This could have invalidated any and all iterators into _views.
1107 The heuristic we use here is: if the region selection is empty, break out of the loop
1108 here. if the region selection is not empty, then restart the loop because we know that
1109 we must have removed at least the region(view) we've just been working on as well as any
1110 that we processed on previous iterations.
1112 EXCEPT .... if we are doing a copy drag, then _views hasn't been modified and
1113 we can just iterate.
1117 if (_views.empty()) {
1128 /* If we've created new regions either by copying or moving
1129 to a new track, we want to replace the old selection with the new ones
1132 if (new_views.size() > 0) {
1133 _editor->selection->set (new_views);
1136 for (set<boost::shared_ptr<Playlist> >::iterator p = frozen_playlists.begin(); p != frozen_playlists.end(); ++p) {
1140 /* write commands for the accumulated diffs for all our modified playlists */
1141 add_stateful_diff_commands_for_playlists (modified_playlists);
1143 _editor->commit_reversible_command ();
1145 /* We have futzed with the layering of canvas items on our streamviews.
1146 If any region changed layer, this will have resulted in the stream
1147 views being asked to set up their region views, and all will be well.
1148 If not, we might now have badly-ordered region views. Ask the StreamViews
1149 involved to sort themselves out, just in case.
1152 for (set<RouteTimeAxisView*>::iterator i = views_to_update.begin(); i != views_to_update.end(); ++i) {
1153 (*i)->view()->playlist_layered ((*i)->track ());
1157 /** Remove a region from a playlist, clearing the diff history of the playlist first if necessary.
1158 * @param region Region to remove.
1159 * @param playlist playlist To remove from.
1160 * @param modified_playlists The playlist will be added to this if it is not there already; used to ensure
1161 * that clear_changes () is only called once per playlist.
1164 RegionMoveDrag::remove_region_from_playlist (
1165 boost::shared_ptr<Region> region,
1166 boost::shared_ptr<Playlist> playlist,
1167 PlaylistSet& modified_playlists
1170 pair<set<boost::shared_ptr<Playlist> >::iterator, bool> r = modified_playlists.insert (playlist);
1173 playlist->clear_changes ();
1176 playlist->remove_region (region);
1180 /** Insert a region into a playlist, handling the recovery of the resulting new RegionView, and
1181 * clearing the playlist's diff history first if necessary.
1182 * @param region Region to insert.
1183 * @param dest_rtv Destination RouteTimeAxisView.
1184 * @param dest_layer Destination layer.
1185 * @param where Destination position.
1186 * @param modified_playlists The playlist will be added to this if it is not there already; used to ensure
1187 * that clear_changes () is only called once per playlist.
1188 * @return New RegionView, or 0 if no insert was performed.
1191 RegionMoveDrag::insert_region_into_playlist (
1192 boost::shared_ptr<Region> region,
1193 RouteTimeAxisView* dest_rtv,
1196 PlaylistSet& modified_playlists
1199 boost::shared_ptr<Playlist> dest_playlist = dest_rtv->playlist ();
1200 if (!dest_playlist) {
1204 /* arrange to collect the new region view that will be created as a result of our playlist insertion */
1205 _new_region_view = 0;
1206 sigc::connection c = dest_rtv->view()->RegionViewAdded.connect (sigc::mem_fun (*this, &RegionMoveDrag::collect_new_region_view));
1208 /* clear history for the playlist we are about to insert to, provided we haven't already done so */
1209 pair<PlaylistSet::iterator, bool> r = modified_playlists.insert (dest_playlist);
1211 dest_playlist->clear_changes ();
1214 dest_playlist->add_region (region, where);
1216 if (dest_rtv->view()->layer_display() == Stacked || dest_rtv->view()->layer_display() == Expanded) {
1217 dest_playlist->set_layer (region, dest_layer);
1222 assert (_new_region_view);
1224 return _new_region_view;
1228 RegionMoveDrag::collect_new_region_view (RegionView* rv)
1230 _new_region_view = rv;
1234 RegionMoveDrag::add_stateful_diff_commands_for_playlists (PlaylistSet const & playlists)
1236 for (PlaylistSet::const_iterator i = playlists.begin(); i != playlists.end(); ++i) {
1237 StatefulDiffCommand* c = new StatefulDiffCommand (*i);
1239 _editor->session()->add_command (c);
1248 RegionMoveDrag::aborted (bool movement_occurred)
1252 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
1259 RegionMotionDrag::aborted (movement_occurred);
1264 RegionMotionDrag::aborted (bool)
1266 for (vector<TimeAxisView*>::iterator i = _time_axis_views.begin(); i != _time_axis_views.end(); ++i) {
1267 if ((*i)->view()->layer_display() == Expanded) {
1268 (*i)->view()->set_layer_display (Stacked);
1272 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
1273 RegionView* rv = i->view;
1274 TimeAxisView* tv = &(rv->get_time_axis_view ());
1275 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (tv);
1277 rv->get_canvas_group()->reparent (*rtv->view()->canvas_item());
1278 rv->get_canvas_group()->property_y() = 0;
1280 rv->fake_set_opaque (false);
1281 rv->move (-_total_x_delta, 0);
1282 rv->set_height (rtv->view()->child_height ());
1285 _editor->update_canvas_now ();
1288 /** @param b true to brush, otherwise false.
1289 * @param c true to make copies of the regions being moved, otherwise false.
1291 RegionMoveDrag::RegionMoveDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, list<RegionView*> const & v, bool b, bool c)
1292 : RegionMotionDrag (e, i, p, v, b),
1295 DEBUG_TRACE (DEBUG::Drags, "New RegionMoveDrag\n");
1298 RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (&_primary->get_time_axis_view ());
1299 if (rtv && rtv->is_track()) {
1300 speed = rtv->track()->speed ();
1303 _last_frame_position = static_cast<framepos_t> (_primary->region()->position() / speed);
1307 RegionMoveDrag::setup_pointer_frame_offset ()
1309 _pointer_frame_offset = raw_grab_frame() - _last_frame_position;
1312 RegionInsertDrag::RegionInsertDrag (Editor* e, boost::shared_ptr<Region> r, RouteTimeAxisView* v, framepos_t pos)
1313 : RegionMotionDrag (e, 0, 0, list<RegionView*> (), false)
1315 DEBUG_TRACE (DEBUG::Drags, "New RegionInsertDrag\n");
1317 assert ((boost::dynamic_pointer_cast<AudioRegion> (r) && dynamic_cast<AudioTimeAxisView*> (v)) ||
1318 (boost::dynamic_pointer_cast<MidiRegion> (r) && dynamic_cast<MidiTimeAxisView*> (v)));
1320 _primary = v->view()->create_region_view (r, false, false);
1322 _primary->get_canvas_group()->show ();
1323 _primary->set_position (pos, 0);
1324 _views.push_back (DraggingView (_primary, this));
1326 _last_frame_position = pos;
1328 _item = _primary->get_canvas_group ();
1332 RegionInsertDrag::finished (GdkEvent *, bool)
1334 _editor->update_canvas_now ();
1336 RouteTimeAxisView* dest_rtv = dynamic_cast<RouteTimeAxisView*> (_time_axis_views[_views.front().time_axis_view]);
1338 _primary->get_canvas_group()->reparent (*dest_rtv->view()->canvas_item());
1339 _primary->get_canvas_group()->property_y() = 0;
1341 boost::shared_ptr<Playlist> playlist = dest_rtv->playlist();
1343 _editor->begin_reversible_command (Operations::insert_region);
1344 playlist->clear_changes ();
1345 playlist->add_region (_primary->region (), _last_frame_position);
1346 _editor->session()->add_command (new StatefulDiffCommand (playlist));
1347 _editor->commit_reversible_command ();
1355 RegionInsertDrag::aborted (bool)
1362 RegionSpliceDrag::RegionSpliceDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, list<RegionView*> const & v)
1363 : RegionMoveDrag (e, i, p, v, false, false)
1365 DEBUG_TRACE (DEBUG::Drags, "New RegionSpliceDrag\n");
1368 struct RegionSelectionByPosition {
1369 bool operator() (RegionView*a, RegionView* b) {
1370 return a->region()->position () < b->region()->position();
1375 RegionSpliceDrag::motion (GdkEvent* event, bool)
1377 /* Which trackview is this ? */
1379 pair<TimeAxisView*, double> const tvp = _editor->trackview_by_y_position (_drags->current_pointer_y ());
1380 RouteTimeAxisView* tv = dynamic_cast<RouteTimeAxisView*> (tvp.first);
1382 /* The region motion is only processed if the pointer is over
1386 if (!tv || !tv->is_track()) {
1387 /* To make sure we hide the verbose canvas cursor when the mouse is
1388 not held over and audiotrack.
1390 _editor->verbose_cursor()->hide ();
1396 if ((_drags->current_pointer_x() - last_pointer_x()) > 0) {
1402 RegionSelection copy (_editor->selection->regions);
1404 RegionSelectionByPosition cmp;
1407 framepos_t const pf = adjusted_current_frame (event);
1409 for (RegionSelection::iterator i = copy.begin(); i != copy.end(); ++i) {
1411 RouteTimeAxisView* atv = dynamic_cast<RouteTimeAxisView*> (&(*i)->get_time_axis_view());
1417 boost::shared_ptr<Playlist> playlist;
1419 if ((playlist = atv->playlist()) == 0) {
1423 if (!playlist->region_is_shuffle_constrained ((*i)->region())) {
1428 if (pf < (*i)->region()->last_frame() + 1) {
1432 if (pf > (*i)->region()->first_frame()) {
1438 playlist->shuffle ((*i)->region(), dir);
1443 RegionSpliceDrag::finished (GdkEvent* event, bool movement_occurred)
1445 RegionMoveDrag::finished (event, movement_occurred);
1449 RegionSpliceDrag::aborted (bool)
1454 RegionCreateDrag::RegionCreateDrag (Editor* e, ArdourCanvas::Item* i, TimeAxisView* v)
1456 _view (dynamic_cast<MidiTimeAxisView*> (v))
1458 DEBUG_TRACE (DEBUG::Drags, "New RegionCreateDrag\n");
1464 RegionCreateDrag::motion (GdkEvent* event, bool first_move)
1467 _region = add_midi_region (_view);
1468 _view->playlist()->freeze ();
1471 framepos_t const f = adjusted_current_frame (event);
1472 if (f < grab_frame()) {
1473 _region->set_position (f);
1476 /* Don't use a zero-length region, and subtract 1 frame from the snapped length
1477 so that if this region is duplicated, its duplicate starts on
1478 a snap point rather than 1 frame after a snap point. Otherwise things get
1479 a bit confusing as if a region starts 1 frame after a snap point, one cannot
1480 place snapped notes at the start of the region.
1483 framecnt_t const len = (framecnt_t) fabs (f - grab_frame () - 1);
1484 _region->set_length (len < 1 ? 1 : len);
1490 RegionCreateDrag::finished (GdkEvent*, bool movement_occurred)
1492 if (!movement_occurred) {
1493 add_midi_region (_view);
1495 _view->playlist()->thaw ();
1500 RegionCreateDrag::aborted (bool)
1503 _view->playlist()->thaw ();
1509 NoteResizeDrag::NoteResizeDrag (Editor* e, ArdourCanvas::Item* i)
1513 DEBUG_TRACE (DEBUG::Drags, "New NoteResizeDrag\n");
1517 NoteResizeDrag::start_grab (GdkEvent* event, Gdk::Cursor* /*ignored*/)
1519 Gdk::Cursor* cursor;
1520 ArdourCanvas::CanvasNoteEvent* cnote = dynamic_cast<ArdourCanvas::CanvasNoteEvent*>(_item);
1521 float x_fraction = cnote->mouse_x_fraction ();
1523 if (x_fraction > 0.0 && x_fraction < 0.25) {
1524 cursor = _editor->cursors()->left_side_trim;
1526 cursor = _editor->cursors()->right_side_trim;
1529 Drag::start_grab (event, cursor);
1531 region = &cnote->region_view();
1533 double const region_start = region->get_position_pixels();
1534 double const middle_point = region_start + cnote->x1() + (cnote->x2() - cnote->x1()) / 2.0L;
1536 if (grab_x() <= middle_point) {
1537 cursor = _editor->cursors()->left_side_trim;
1540 cursor = _editor->cursors()->right_side_trim;
1544 _item->grab(GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK, *cursor, event->motion.time);
1546 if (event->motion.state & Keyboard::PrimaryModifier) {
1552 MidiRegionSelection& ms (_editor->get_selection().midi_regions);
1554 if (ms.size() > 1) {
1555 /* has to be relative, may make no sense otherwise */
1559 /* select this note; if it is already selected, preserve the existing selection,
1560 otherwise make this note the only one selected.
1562 region->note_selected (cnote, cnote->selected ());
1564 for (MidiRegionSelection::iterator r = ms.begin(); r != ms.end(); ) {
1565 MidiRegionSelection::iterator next;
1568 (*r)->begin_resizing (at_front);
1574 NoteResizeDrag::motion (GdkEvent* /*event*/, bool /*first_move*/)
1576 MidiRegionSelection& ms (_editor->get_selection().midi_regions);
1577 for (MidiRegionSelection::iterator r = ms.begin(); r != ms.end(); ++r) {
1578 (*r)->update_resizing (dynamic_cast<ArdourCanvas::CanvasNoteEvent*>(_item), at_front, _drags->current_pointer_x() - grab_x(), relative);
1583 NoteResizeDrag::finished (GdkEvent*, bool /*movement_occurred*/)
1585 MidiRegionSelection& ms (_editor->get_selection().midi_regions);
1586 for (MidiRegionSelection::iterator r = ms.begin(); r != ms.end(); ++r) {
1587 (*r)->commit_resizing (dynamic_cast<ArdourCanvas::CanvasNoteEvent*>(_item), at_front, _drags->current_pointer_x() - grab_x(), relative);
1592 NoteResizeDrag::aborted (bool)
1594 MidiRegionSelection& ms (_editor->get_selection().midi_regions);
1595 for (MidiRegionSelection::iterator r = ms.begin(); r != ms.end(); ++r) {
1596 (*r)->abort_resizing ();
1600 TrimDrag::TrimDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, list<RegionView*> const & v, bool preserve_fade_anchor)
1601 : RegionDrag (e, i, p, v)
1603 DEBUG_TRACE (DEBUG::Drags, "New TrimDrag\n");
1604 _preserve_fade_anchor = preserve_fade_anchor;
1608 TrimDrag::start_grab (GdkEvent* event, Gdk::Cursor*)
1611 TimeAxisView* tvp = &_primary->get_time_axis_view ();
1612 RouteTimeAxisView* tv = dynamic_cast<RouteTimeAxisView*>(tvp);
1614 if (tv && tv->is_track()) {
1615 speed = tv->track()->speed();
1618 framepos_t const region_start = (framepos_t) (_primary->region()->position() / speed);
1619 framepos_t const region_end = (framepos_t) (_primary->region()->last_frame() / speed);
1620 framecnt_t const region_length = (framecnt_t) (_primary->region()->length() / speed);
1622 framepos_t const pf = adjusted_current_frame (event);
1624 if (Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) {
1625 /* Move the contents of the region around without changing the region bounds */
1626 _operation = ContentsTrim;
1627 Drag::start_grab (event, _editor->cursors()->trimmer);
1629 /* These will get overridden for a point trim.*/
1630 if (pf < (region_start + region_length/2)) {
1631 /* closer to front */
1632 _operation = StartTrim;
1633 Drag::start_grab (event, _editor->cursors()->left_side_trim);
1636 _operation = EndTrim;
1637 Drag::start_grab (event, _editor->cursors()->right_side_trim);
1641 switch (_operation) {
1643 show_verbose_cursor_time (region_start);
1644 for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
1645 i->view->trim_front_starting ();
1649 show_verbose_cursor_time (region_end);
1652 show_verbose_cursor_time (pf);
1656 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
1657 i->view->region()->suspend_property_changes ();
1662 TrimDrag::motion (GdkEvent* event, bool first_move)
1664 RegionView* rv = _primary;
1667 TimeAxisView* tvp = &_primary->get_time_axis_view ();
1668 RouteTimeAxisView* tv = dynamic_cast<RouteTimeAxisView*>(tvp);
1669 pair<set<boost::shared_ptr<Playlist> >::iterator,bool> insert_result;
1671 if (tv && tv->is_track()) {
1672 speed = tv->track()->speed();
1675 framecnt_t const dt = adjusted_current_frame (event) - raw_grab_frame () + _pointer_frame_offset;
1681 switch (_operation) {
1683 trim_type = "Region start trim";
1686 trim_type = "Region end trim";
1689 trim_type = "Region content trim";
1693 _editor->begin_reversible_command (trim_type);
1695 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
1696 RegionView* rv = i->view;
1697 rv->fake_set_opaque (false);
1698 rv->enable_display (false);
1699 rv->region()->playlist()->clear_owned_changes ();
1701 AudioRegionView* const arv = dynamic_cast<AudioRegionView*> (rv);
1704 arv->temporarily_hide_envelope ();
1708 boost::shared_ptr<Playlist> pl = rv->region()->playlist();
1709 insert_result = _editor->motion_frozen_playlists.insert (pl);
1711 if (insert_result.second) {
1717 bool non_overlap_trim = false;
1719 if (event && Keyboard::modifier_state_equals (event->button.state, Keyboard::TertiaryModifier)) {
1720 non_overlap_trim = true;
1723 switch (_operation) {
1725 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
1726 bool changed = i->view->trim_front (i->initial_position + dt, non_overlap_trim);
1727 if (changed && _preserve_fade_anchor) {
1728 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (i->view);
1733 boost::shared_ptr<AudioRegion> ar (arv->audio_region());
1734 distance = _drags->current_pointer_x() - grab_x();
1735 len = ar->fade_in()->back()->when;
1736 new_length = len - _editor->unit_to_frame (distance);
1737 new_length = ar->verify_xfade_bounds (new_length, true /*START*/ );
1738 arv->reset_fade_in_shape_width (ar, new_length); //the grey shape
1745 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
1746 bool changed = i->view->trim_end (i->initial_end + dt, non_overlap_trim);
1747 if (changed && _preserve_fade_anchor) {
1748 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (i->view);
1753 boost::shared_ptr<AudioRegion> ar (arv->audio_region());
1754 distance = grab_x() - _drags->current_pointer_x();
1755 len = ar->fade_out()->back()->when;
1756 new_length = len - _editor->unit_to_frame (distance);
1757 new_length = ar->verify_xfade_bounds (new_length, false /*END*/ );
1758 arv->reset_fade_out_shape_width (ar, new_length); //the grey shape
1766 bool swap_direction = false;
1768 if (event && Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) {
1769 swap_direction = true;
1772 framecnt_t frame_delta = 0;
1774 bool left_direction = false;
1775 if (last_pointer_frame() > adjusted_current_frame(event)) {
1776 left_direction = true;
1779 if (left_direction) {
1780 frame_delta = (last_pointer_frame() - adjusted_current_frame(event));
1782 frame_delta = (adjusted_current_frame(event) - last_pointer_frame());
1785 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
1786 i->view->trim_contents (frame_delta, left_direction, swap_direction);
1792 switch (_operation) {
1794 show_verbose_cursor_time ((framepos_t) (rv->region()->position() / speed));
1797 show_verbose_cursor_time ((framepos_t) (rv->region()->last_frame() / speed));
1800 show_verbose_cursor_time (adjusted_current_frame (event));
1807 TrimDrag::finished (GdkEvent* event, bool movement_occurred)
1809 if (movement_occurred) {
1810 motion (event, false);
1812 if (_operation == StartTrim) {
1813 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
1815 /* This must happen before the region's StatefulDiffCommand is created, as it may
1816 `correct' (ahem) the region's _start from being negative to being zero. It
1817 needs to be zero in the undo record.
1819 i->view->trim_front_ending ();
1821 if (_preserve_fade_anchor) {
1822 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (i->view);
1827 boost::shared_ptr<AudioRegion> ar (arv->audio_region());
1828 distance = _drags->current_pointer_x() - grab_x();
1829 len = ar->fade_in()->back()->when;
1830 new_length = len - _editor->unit_to_frame (distance);
1831 new_length = ar->verify_xfade_bounds (new_length, true /*START*/ );
1832 ar->set_fade_in_length(new_length);
1836 } else if (_operation == EndTrim) {
1837 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
1838 if (_preserve_fade_anchor) {
1839 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (i->view);
1844 boost::shared_ptr<AudioRegion> ar (arv->audio_region());
1845 distance = _drags->current_pointer_x() - grab_x();
1846 len = ar->fade_out()->back()->when;
1847 new_length = len - _editor->unit_to_frame (distance);
1848 new_length = ar->verify_xfade_bounds (new_length, false /*END*/ );
1849 ar->set_fade_out_length(new_length);
1855 if (!_views.empty()) {
1856 if (_operation == StartTrim) {
1857 _editor->maybe_locate_with_edit_preroll(
1858 _views.begin()->view->region()->position());
1860 if (_operation == EndTrim) {
1861 _editor->maybe_locate_with_edit_preroll(
1862 _views.begin()->view->region()->position() +
1863 _views.begin()->view->region()->length());
1867 if (!_editor->selection->selected (_primary)) {
1868 _primary->thaw_after_trim ();
1871 set<boost::shared_ptr<Playlist> > diffed_playlists;
1873 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
1874 i->view->thaw_after_trim ();
1875 i->view->enable_display (true);
1876 i->view->fake_set_opaque (true);
1878 /* Trimming one region may affect others on the playlist, so we need
1879 to get undo Commands from the whole playlist rather than just the
1880 region. Use diffed_playlists to make sure we don't diff a given
1881 playlist more than once.
1883 boost::shared_ptr<Playlist> p = i->view->region()->playlist ();
1884 if (diffed_playlists.find (p) == diffed_playlists.end()) {
1885 vector<Command*> cmds;
1887 _editor->session()->add_commands (cmds);
1888 diffed_playlists.insert (p);
1893 for (set<boost::shared_ptr<Playlist> >::iterator p = _editor->motion_frozen_playlists.begin(); p != _editor->motion_frozen_playlists.end(); ++p) {
1897 _editor->motion_frozen_playlists.clear ();
1898 _editor->commit_reversible_command();
1901 /* no mouse movement */
1902 _editor->point_trim (event, adjusted_current_frame (event));
1905 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
1906 if (_operation == StartTrim) {
1907 i->view->trim_front_ending ();
1910 i->view->region()->resume_property_changes ();
1915 TrimDrag::aborted (bool movement_occurred)
1917 /* Our motion method is changing model state, so use the Undo system
1918 to cancel. Perhaps not ideal, as this will leave an Undo point
1919 behind which may be slightly odd from the user's point of view.
1924 if (movement_occurred) {
1928 for (list<DraggingView>::const_iterator i = _views.begin(); i != _views.end(); ++i) {
1929 i->view->region()->resume_property_changes ();
1934 TrimDrag::setup_pointer_frame_offset ()
1936 list<DraggingView>::iterator i = _views.begin ();
1937 while (i != _views.end() && i->view != _primary) {
1941 if (i == _views.end()) {
1945 switch (_operation) {
1947 _pointer_frame_offset = raw_grab_frame() - i->initial_position;
1950 _pointer_frame_offset = raw_grab_frame() - i->initial_end;
1957 MeterMarkerDrag::MeterMarkerDrag (Editor* e, ArdourCanvas::Item* i, bool c)
1961 DEBUG_TRACE (DEBUG::Drags, "New MeterMarkerDrag\n");
1962 _marker = reinterpret_cast<MeterMarker*> (_item->get_data ("marker"));
1967 MeterMarkerDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
1969 Drag::start_grab (event, cursor);
1970 show_verbose_cursor_time (adjusted_current_frame(event));
1974 MeterMarkerDrag::setup_pointer_frame_offset ()
1976 _pointer_frame_offset = raw_grab_frame() - _marker->meter().frame();
1980 MeterMarkerDrag::motion (GdkEvent* event, bool first_move)
1984 // create a dummy marker for visual representation of moving the
1985 // section, because whether its a copy or not, we're going to
1986 // leave or lose the original marker (leave if its a copy; lose if its
1987 // not, because we'll remove it from the map).
1989 MeterSection section (_marker->meter());
1991 if (!section.movable()) {
1996 snprintf (name, sizeof(name), "%g/%g", _marker->meter().divisions_per_bar(), _marker->meter().note_divisor ());
1998 _marker = new MeterMarker (
2000 *_editor->meter_group,
2001 ARDOUR_UI::config()->canvasvar_MeterMarker.get(),
2003 *new MeterSection (_marker->meter())
2006 /* use the new marker for the grab */
2007 swap_grab (&_marker->the_item(), 0, GDK_CURRENT_TIME);
2010 TempoMap& map (_editor->session()->tempo_map());
2011 /* get current state */
2012 before_state = &map.get_state();
2013 /* remove the section while we drag it */
2014 map.remove_meter (section, true);
2018 framepos_t const pf = adjusted_current_frame (event);
2019 _marker->set_position (pf);
2020 show_verbose_cursor_time (pf);
2024 MeterMarkerDrag::finished (GdkEvent* event, bool movement_occurred)
2026 if (!movement_occurred) {
2030 motion (event, false);
2032 Timecode::BBT_Time when;
2034 TempoMap& map (_editor->session()->tempo_map());
2035 map.bbt_time (last_pointer_frame(), when);
2037 if (_copy == true) {
2038 _editor->begin_reversible_command (_("copy meter mark"));
2039 XMLNode &before = map.get_state();
2040 map.add_meter (_marker->meter(), when);
2041 XMLNode &after = map.get_state();
2042 _editor->session()->add_command(new MementoCommand<TempoMap>(map, &before, &after));
2043 _editor->commit_reversible_command ();
2046 _editor->begin_reversible_command (_("move meter mark"));
2048 /* we removed it before, so add it back now */
2050 map.add_meter (_marker->meter(), when);
2051 XMLNode &after = map.get_state();
2052 _editor->session()->add_command(new MementoCommand<TempoMap>(map, before_state, &after));
2053 _editor->commit_reversible_command ();
2056 // delete the dummy marker we used for visual representation while moving.
2057 // a new visual marker will show up automatically.
2062 MeterMarkerDrag::aborted (bool moved)
2064 _marker->set_position (_marker->meter().frame ());
2067 TempoMap& map (_editor->session()->tempo_map());
2068 /* we removed it before, so add it back now */
2069 map.add_meter (_marker->meter(), _marker->meter().frame());
2070 // delete the dummy marker we used for visual representation while moving.
2071 // a new visual marker will show up automatically.
2076 TempoMarkerDrag::TempoMarkerDrag (Editor* e, ArdourCanvas::Item* i, bool c)
2080 DEBUG_TRACE (DEBUG::Drags, "New TempoMarkerDrag\n");
2082 _marker = reinterpret_cast<TempoMarker*> (_item->get_data ("marker"));
2087 TempoMarkerDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
2089 Drag::start_grab (event, cursor);
2090 show_verbose_cursor_time (adjusted_current_frame (event));
2094 TempoMarkerDrag::setup_pointer_frame_offset ()
2096 _pointer_frame_offset = raw_grab_frame() - _marker->tempo().frame();
2100 TempoMarkerDrag::motion (GdkEvent* event, bool first_move)
2104 // create a dummy marker for visual representation of moving the
2105 // section, because whether its a copy or not, we're going to
2106 // leave or lose the original marker (leave if its a copy; lose if its
2107 // not, because we'll remove it from the map).
2109 // create a dummy marker for visual representation of moving the copy.
2110 // The actual copying is not done before we reach the finish callback.
2113 snprintf (name, sizeof (name), "%.2f", _marker->tempo().beats_per_minute());
2115 TempoSection section (_marker->tempo());
2117 _marker = new TempoMarker (
2119 *_editor->tempo_group,
2120 ARDOUR_UI::config()->canvasvar_TempoMarker.get(),
2122 *new TempoSection (_marker->tempo())
2125 /* use the new marker for the grab */
2126 swap_grab (&_marker->the_item(), 0, GDK_CURRENT_TIME);
2129 TempoMap& map (_editor->session()->tempo_map());
2130 /* get current state */
2131 before_state = &map.get_state();
2132 /* remove the section while we drag it */
2133 map.remove_tempo (section, true);
2137 framepos_t const pf = adjusted_current_frame (event);
2138 _marker->set_position (pf);
2139 show_verbose_cursor_time (pf);
2143 TempoMarkerDrag::finished (GdkEvent* event, bool movement_occurred)
2145 if (!movement_occurred) {
2149 motion (event, false);
2151 TempoMap& map (_editor->session()->tempo_map());
2152 framepos_t beat_time = map.round_to_beat (last_pointer_frame(), 0);
2153 Timecode::BBT_Time when;
2155 map.bbt_time (beat_time, when);
2157 if (_copy == true) {
2158 _editor->begin_reversible_command (_("copy tempo mark"));
2159 XMLNode &before = map.get_state();
2160 map.add_tempo (_marker->tempo(), when);
2161 XMLNode &after = map.get_state();
2162 _editor->session()->add_command (new MementoCommand<TempoMap>(map, &before, &after));
2163 _editor->commit_reversible_command ();
2166 _editor->begin_reversible_command (_("move tempo mark"));
2167 /* we removed it before, so add it back now */
2168 map.add_tempo (_marker->tempo(), when);
2169 XMLNode &after = map.get_state();
2170 _editor->session()->add_command (new MementoCommand<TempoMap>(map, before_state, &after));
2171 _editor->commit_reversible_command ();
2174 // delete the dummy marker we used for visual representation while moving.
2175 // a new visual marker will show up automatically.
2180 TempoMarkerDrag::aborted (bool moved)
2182 _marker->set_position (_marker->tempo().frame());
2184 TempoMap& map (_editor->session()->tempo_map());
2185 /* we removed it before, so add it back now */
2186 map.add_tempo (_marker->tempo(), _marker->tempo().start());
2187 // delete the dummy marker we used for visual representation while moving.
2188 // a new visual marker will show up automatically.
2193 CursorDrag::CursorDrag (Editor* e, ArdourCanvas::Item* i, bool s)
2197 DEBUG_TRACE (DEBUG::Drags, "New CursorDrag\n");
2200 /** Do all the things we do when dragging the playhead to make it look as though
2201 * we have located, without actually doing the locate (because that would cause
2202 * the diskstream buffers to be refilled, which is too slow).
2205 CursorDrag::fake_locate (framepos_t t)
2207 _editor->playhead_cursor->set_position (t);
2209 Session* s = _editor->session ();
2210 if (s->timecode_transmission_suspended ()) {
2211 framepos_t const f = _editor->playhead_cursor->current_frame;
2212 s->send_mmc_locate (f);
2213 s->send_full_time_code (f);
2216 show_verbose_cursor_time (t);
2217 _editor->UpdateAllTransportClocks (t);
2221 CursorDrag::start_grab (GdkEvent* event, Gdk::Cursor* c)
2223 Drag::start_grab (event, c);
2225 _grab_zoom = _editor->frames_per_unit;
2227 framepos_t where = _editor->event_frame (event, 0, 0);
2228 _editor->snap_to_with_modifier (where, event);
2230 _editor->_dragging_playhead = true;
2232 Session* s = _editor->session ();
2235 if (_was_rolling && _stop) {
2239 if (s->is_auditioning()) {
2240 s->cancel_audition ();
2244 if (AudioEngine::instance()->connected()) {
2246 /* do this only if we're the engine is connected
2247 * because otherwise this request will never be
2248 * serviced and we'll busy wait forever. likewise,
2249 * notice if we are disconnected while waiting for the
2250 * request to be serviced.
2253 s->request_suspend_timecode_transmission ();
2254 while (AudioEngine::instance()->connected() && !s->timecode_transmission_suspended ()) {
2255 /* twiddle our thumbs */
2260 fake_locate (where);
2264 CursorDrag::motion (GdkEvent* event, bool)
2266 framepos_t const adjusted_frame = adjusted_current_frame (event);
2267 if (adjusted_frame != last_pointer_frame()) {
2268 fake_locate (adjusted_frame);
2270 _editor->update_canvas_now ();
2276 CursorDrag::finished (GdkEvent* event, bool movement_occurred)
2278 _editor->_dragging_playhead = false;
2280 if (!movement_occurred && _stop) {
2284 motion (event, false);
2286 Session* s = _editor->session ();
2288 s->request_locate (_editor->playhead_cursor->current_frame, _was_rolling);
2289 _editor->_pending_locate_request = true;
2290 s->request_resume_timecode_transmission ();
2295 CursorDrag::aborted (bool)
2297 if (_editor->_dragging_playhead) {
2298 _editor->session()->request_resume_timecode_transmission ();
2299 _editor->_dragging_playhead = false;
2302 _editor->playhead_cursor->set_position (adjusted_frame (grab_frame (), 0, false));
2305 FadeInDrag::FadeInDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, list<RegionView*> const & v)
2306 : RegionDrag (e, i, p, v)
2308 DEBUG_TRACE (DEBUG::Drags, "New FadeInDrag\n");
2312 FadeInDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
2314 Drag::start_grab (event, cursor);
2316 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (_primary);
2317 boost::shared_ptr<AudioRegion> const r = arv->audio_region ();
2319 show_verbose_cursor_duration (r->position(), r->position() + r->fade_in()->back()->when, 32);
2323 FadeInDrag::setup_pointer_frame_offset ()
2325 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (_primary);
2326 boost::shared_ptr<AudioRegion> const r = arv->audio_region ();
2327 _pointer_frame_offset = raw_grab_frame() - ((framecnt_t) r->fade_in()->back()->when + r->position());
2331 FadeInDrag::motion (GdkEvent* event, bool)
2333 framecnt_t fade_length;
2335 framepos_t const pos = adjusted_current_frame (event);
2337 boost::shared_ptr<Region> region = _primary->region ();
2339 if (pos < (region->position() + 64)) {
2340 fade_length = 64; // this should be a minimum defined somewhere
2341 } else if (pos > region->last_frame()) {
2342 fade_length = region->length();
2344 fade_length = pos - region->position();
2347 for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
2349 AudioRegionView* tmp = dynamic_cast<AudioRegionView*> (i->view);
2355 tmp->reset_fade_in_shape_width (tmp->audio_region(), fade_length);
2358 show_verbose_cursor_duration (region->position(), region->position() + fade_length, 32);
2362 FadeInDrag::finished (GdkEvent* event, bool movement_occurred)
2364 if (!movement_occurred) {
2368 framecnt_t fade_length;
2370 framepos_t const pos = adjusted_current_frame (event);
2372 boost::shared_ptr<Region> region = _primary->region ();
2374 if (pos < (region->position() + 64)) {
2375 fade_length = 64; // this should be a minimum defined somewhere
2376 } else if (pos > region->last_frame()) {
2377 fade_length = region->length();
2379 fade_length = pos - region->position();
2382 _editor->begin_reversible_command (_("change fade in length"));
2384 for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
2386 AudioRegionView* tmp = dynamic_cast<AudioRegionView*> (i->view);
2392 boost::shared_ptr<AutomationList> alist = tmp->audio_region()->fade_in();
2393 XMLNode &before = alist->get_state();
2395 tmp->audio_region()->set_fade_in_length (fade_length);
2396 tmp->audio_region()->set_fade_in_active (true);
2398 XMLNode &after = alist->get_state();
2399 _editor->session()->add_command(new MementoCommand<AutomationList>(*alist.get(), &before, &after));
2402 _editor->commit_reversible_command ();
2406 FadeInDrag::aborted (bool)
2408 for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
2409 AudioRegionView* tmp = dynamic_cast<AudioRegionView*> (i->view);
2415 tmp->reset_fade_in_shape_width (tmp->audio_region(), tmp->audio_region()->fade_in()->back()->when);
2419 FadeOutDrag::FadeOutDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, list<RegionView*> const & v)
2420 : RegionDrag (e, i, p, v)
2422 DEBUG_TRACE (DEBUG::Drags, "New FadeOutDrag\n");
2426 FadeOutDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
2428 Drag::start_grab (event, cursor);
2430 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (_primary);
2431 boost::shared_ptr<AudioRegion> r = arv->audio_region ();
2433 show_verbose_cursor_duration (r->last_frame() - r->fade_out()->back()->when, r->last_frame());
2437 FadeOutDrag::setup_pointer_frame_offset ()
2439 AudioRegionView* arv = dynamic_cast<AudioRegionView*> (_primary);
2440 boost::shared_ptr<AudioRegion> r = arv->audio_region ();
2441 _pointer_frame_offset = raw_grab_frame() - (r->length() - (framecnt_t) r->fade_out()->back()->when + r->position());
2445 FadeOutDrag::motion (GdkEvent* event, bool)
2447 framecnt_t fade_length;
2449 framepos_t const pos = adjusted_current_frame (event);
2451 boost::shared_ptr<Region> region = _primary->region ();
2453 if (pos > (region->last_frame() - 64)) {
2454 fade_length = 64; // this should really be a minimum fade defined somewhere
2456 else if (pos < region->position()) {
2457 fade_length = region->length();
2460 fade_length = region->last_frame() - pos;
2463 for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
2465 AudioRegionView* tmp = dynamic_cast<AudioRegionView*> (i->view);
2471 tmp->reset_fade_out_shape_width (tmp->audio_region(), fade_length);
2474 show_verbose_cursor_duration (region->last_frame() - fade_length, region->last_frame());
2478 FadeOutDrag::finished (GdkEvent* event, bool movement_occurred)
2480 if (!movement_occurred) {
2484 framecnt_t fade_length;
2486 framepos_t const pos = adjusted_current_frame (event);
2488 boost::shared_ptr<Region> region = _primary->region ();
2490 if (pos > (region->last_frame() - 64)) {
2491 fade_length = 64; // this should really be a minimum fade defined somewhere
2493 else if (pos < region->position()) {
2494 fade_length = region->length();
2497 fade_length = region->last_frame() - pos;
2500 _editor->begin_reversible_command (_("change fade out length"));
2502 for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
2504 AudioRegionView* tmp = dynamic_cast<AudioRegionView*> (i->view);
2510 boost::shared_ptr<AutomationList> alist = tmp->audio_region()->fade_out();
2511 XMLNode &before = alist->get_state();
2513 tmp->audio_region()->set_fade_out_length (fade_length);
2514 tmp->audio_region()->set_fade_out_active (true);
2516 XMLNode &after = alist->get_state();
2517 _editor->session()->add_command(new MementoCommand<AutomationList>(*alist.get(), &before, &after));
2520 _editor->commit_reversible_command ();
2524 FadeOutDrag::aborted (bool)
2526 for (list<DraggingView>::iterator i = _views.begin(); i != _views.end(); ++i) {
2527 AudioRegionView* tmp = dynamic_cast<AudioRegionView*> (i->view);
2533 tmp->reset_fade_out_shape_width (tmp->audio_region(), tmp->audio_region()->fade_out()->back()->when);
2537 MarkerDrag::MarkerDrag (Editor* e, ArdourCanvas::Item* i)
2540 DEBUG_TRACE (DEBUG::Drags, "New MarkerDrag\n");
2542 _marker = reinterpret_cast<Marker*> (_item->get_data ("marker"));
2545 _points.push_back (Gnome::Art::Point (0, 0));
2546 _points.push_back (Gnome::Art::Point (0, physical_screen_height (_editor->get_window())));
2549 MarkerDrag::~MarkerDrag ()
2551 for (CopiedLocationInfo::iterator i = _copied_locations.begin(); i != _copied_locations.end(); ++i) {
2556 MarkerDrag::CopiedLocationMarkerInfo::CopiedLocationMarkerInfo (Location* l, Marker* m)
2558 location = new Location (*l);
2559 markers.push_back (m);
2564 MarkerDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
2566 Drag::start_grab (event, cursor);
2570 Location *location = _editor->find_location_from_marker (_marker, is_start);
2571 _editor->_dragging_edit_point = true;
2573 update_item (location);
2575 // _drag_line->show();
2576 // _line->raise_to_top();
2579 show_verbose_cursor_time (location->start());
2581 show_verbose_cursor_time (location->end());
2584 Selection::Operation op = ArdourKeyboard::selection_type (event->button.state);
2587 case Selection::Toggle:
2588 /* we toggle on the button release */
2590 case Selection::Set:
2591 if (!_editor->selection->selected (_marker)) {
2592 _editor->selection->set (_marker);
2595 case Selection::Extend:
2597 Locations::LocationList ll;
2598 list<Marker*> to_add;
2600 _editor->selection->markers.range (s, e);
2601 s = min (_marker->position(), s);
2602 e = max (_marker->position(), e);
2605 if (e < max_framepos) {
2608 _editor->session()->locations()->find_all_between (s, e, ll, Location::Flags (0));
2609 for (Locations::LocationList::iterator i = ll.begin(); i != ll.end(); ++i) {
2610 Editor::LocationMarkers* lm = _editor->find_location_markers (*i);
2613 to_add.push_back (lm->start);
2616 to_add.push_back (lm->end);
2620 if (!to_add.empty()) {
2621 _editor->selection->add (to_add);
2625 case Selection::Add:
2626 _editor->selection->add (_marker);
2630 /* Set up copies for us to manipulate during the drag
2633 for (MarkerSelection::iterator i = _editor->selection->markers.begin(); i != _editor->selection->markers.end(); ++i) {
2635 Location* l = _editor->find_location_from_marker (*i, is_start);
2642 _copied_locations.push_back (CopiedLocationMarkerInfo (l, *i));
2644 /* range: check that the other end of the range isn't
2647 CopiedLocationInfo::iterator x;
2648 for (x = _copied_locations.begin(); x != _copied_locations.end(); ++x) {
2649 if (*(*x).location == *l) {
2653 if (x == _copied_locations.end()) {
2654 _copied_locations.push_back (CopiedLocationMarkerInfo (l, *i));
2656 (*x).markers.push_back (*i);
2657 (*x).move_both = true;
2665 MarkerDrag::setup_pointer_frame_offset ()
2668 Location *location = _editor->find_location_from_marker (_marker, is_start);
2669 _pointer_frame_offset = raw_grab_frame() - (is_start ? location->start() : location->end());
2673 MarkerDrag::motion (GdkEvent* event, bool)
2675 framecnt_t f_delta = 0;
2677 bool move_both = false;
2678 Location *real_location;
2679 Location *copy_location = 0;
2681 framepos_t const newframe = adjusted_current_frame (event);
2682 framepos_t next = newframe;
2684 if (Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier)) {
2688 CopiedLocationInfo::iterator x;
2690 /* find the marker we're dragging, and compute the delta */
2692 for (x = _copied_locations.begin(); x != _copied_locations.end(); ++x) {
2694 copy_location = (*x).location;
2696 if (find (x->markers.begin(), x->markers.end(), _marker) != x->markers.end()) {
2698 /* this marker is represented by this
2699 * CopiedLocationMarkerInfo
2702 if ((real_location = _editor->find_location_from_marker (_marker, is_start)) == 0) {
2707 if (real_location->is_mark()) {
2708 f_delta = newframe - copy_location->start();
2712 switch (_marker->type()) {
2713 case Marker::SessionStart:
2714 case Marker::RangeStart:
2715 case Marker::LoopStart:
2716 case Marker::PunchIn:
2717 f_delta = newframe - copy_location->start();
2720 case Marker::SessionEnd:
2721 case Marker::RangeEnd:
2722 case Marker::LoopEnd:
2723 case Marker::PunchOut:
2724 f_delta = newframe - copy_location->end();
2727 /* what kind of marker is this ? */
2736 if (x == _copied_locations.end()) {
2737 /* hmm, impossible - we didn't find the dragged marker */
2741 /* now move them all */
2743 for (x = _copied_locations.begin(); x != _copied_locations.end(); ++x) {
2745 copy_location = x->location;
2747 /* call this to find out if its the start or end */
2749 if ((real_location = _editor->find_location_from_marker (x->markers.front(), is_start)) == 0) {
2753 if (real_location->locked()) {
2757 if (copy_location->is_mark()) {
2761 copy_location->set_start (copy_location->start() + f_delta);
2765 framepos_t new_start = copy_location->start() + f_delta;
2766 framepos_t new_end = copy_location->end() + f_delta;
2768 if (is_start) { // start-of-range marker
2770 if (move_both || (*x).move_both) {
2771 copy_location->set_start (new_start);
2772 copy_location->set_end (new_end);
2773 } else if (new_start < copy_location->end()) {
2774 copy_location->set_start (new_start);
2775 } else if (newframe > 0) {
2776 _editor->snap_to (next, 1, true);
2777 copy_location->set_end (next);
2778 copy_location->set_start (newframe);
2781 } else { // end marker
2783 if (move_both || (*x).move_both) {
2784 copy_location->set_end (new_end);
2785 copy_location->set_start (new_start);
2786 } else if (new_end > copy_location->start()) {
2787 copy_location->set_end (new_end);
2788 } else if (newframe > 0) {
2789 _editor->snap_to (next, -1, true);
2790 copy_location->set_start (next);
2791 copy_location->set_end (newframe);
2796 update_item (copy_location);
2798 /* now lookup the actual GUI items used to display this
2799 * location and move them to wherever the copy of the location
2800 * is now. This means that the logic in ARDOUR::Location is
2801 * still enforced, even though we are not (yet) modifying
2802 * the real Location itself.
2805 Editor::LocationMarkers* lm = _editor->find_location_markers (real_location);
2808 lm->set_position (copy_location->start(), copy_location->end());
2813 assert (!_copied_locations.empty());
2815 show_verbose_cursor_time (newframe);
2818 _editor->update_canvas_now ();
2823 MarkerDrag::finished (GdkEvent* event, bool movement_occurred)
2825 if (!movement_occurred) {
2827 /* just a click, do nothing but finish
2828 off the selection process
2831 Selection::Operation op = ArdourKeyboard::selection_type (event->button.state);
2834 case Selection::Set:
2835 if (_editor->selection->selected (_marker) && _editor->selection->markers.size() > 1) {
2836 _editor->selection->set (_marker);
2840 case Selection::Toggle:
2841 /* we toggle on the button release, click only */
2842 _editor->selection->toggle (_marker);
2845 case Selection::Extend:
2846 case Selection::Add:
2853 _editor->_dragging_edit_point = false;
2855 _editor->begin_reversible_command ( _("move marker") );
2856 XMLNode &before = _editor->session()->locations()->get_state();
2858 MarkerSelection::iterator i;
2859 CopiedLocationInfo::iterator x;
2862 for (i = _editor->selection->markers.begin(), x = _copied_locations.begin();
2863 x != _copied_locations.end() && i != _editor->selection->markers.end();
2866 Location * location = _editor->find_location_from_marker (*i, is_start);
2870 if (location->locked()) {
2874 if (location->is_mark()) {
2875 location->set_start (((*x).location)->start());
2877 location->set (((*x).location)->start(), ((*x).location)->end());
2882 XMLNode &after = _editor->session()->locations()->get_state();
2883 _editor->session()->add_command(new MementoCommand<Locations>(*(_editor->session()->locations()), &before, &after));
2884 _editor->commit_reversible_command ();
2888 MarkerDrag::aborted (bool)
2894 MarkerDrag::update_item (Location*)
2899 ControlPointDrag::ControlPointDrag (Editor* e, ArdourCanvas::Item* i)
2901 _cumulative_x_drag (0),
2902 _cumulative_y_drag (0)
2904 if (_zero_gain_fraction < 0.0) {
2905 _zero_gain_fraction = gain_to_slider_position_with_max (dB_to_coefficient (0.0), Config->get_max_gain());
2908 DEBUG_TRACE (DEBUG::Drags, "New ControlPointDrag\n");
2910 _point = reinterpret_cast<ControlPoint*> (_item->get_data ("control_point"));
2916 ControlPointDrag::start_grab (GdkEvent* event, Gdk::Cursor* /*cursor*/)
2918 Drag::start_grab (event, _editor->cursors()->fader);
2920 // start the grab at the center of the control point so
2921 // the point doesn't 'jump' to the mouse after the first drag
2922 _fixed_grab_x = _point->get_x();
2923 _fixed_grab_y = _point->get_y();
2925 float const fraction = 1 - (_point->get_y() / _point->line().height());
2927 _point->line().start_drag_single (_point, _fixed_grab_x, fraction);
2929 _editor->verbose_cursor()->set (_point->line().get_verbose_cursor_string (fraction),
2930 event->button.x + 10, event->button.y + 10);
2932 _editor->verbose_cursor()->show ();
2934 _pushing = Keyboard::modifier_state_contains (event->button.state, Keyboard::PrimaryModifier);
2936 if (!_point->can_slide ()) {
2937 _x_constrained = true;
2942 ControlPointDrag::motion (GdkEvent* event, bool)
2944 double dx = _drags->current_pointer_x() - last_pointer_x();
2945 double dy = _drags->current_pointer_y() - last_pointer_y();
2947 if (event->button.state & Keyboard::SecondaryModifier) {
2952 /* coordinate in pixels relative to the start of the region (for region-based automation)
2953 or track (for track-based automation) */
2954 double cx = _fixed_grab_x + _cumulative_x_drag + dx;
2955 double cy = _fixed_grab_y + _cumulative_y_drag + dy;
2957 // calculate zero crossing point. back off by .01 to stay on the
2958 // positive side of zero
2959 double const zero_gain_y = (1.0 - _zero_gain_fraction) * _point->line().height() - .01;
2961 // make sure we hit zero when passing through
2962 if ((cy < zero_gain_y && (cy - dy) > zero_gain_y) || (cy > zero_gain_y && (cy - dy) < zero_gain_y)) {
2966 if (_x_constrained) {
2969 if (_y_constrained) {
2973 _cumulative_x_drag = cx - _fixed_grab_x;
2974 _cumulative_y_drag = cy - _fixed_grab_y;
2978 cy = min ((double) _point->line().height(), cy);
2980 framepos_t cx_frames = _editor->unit_to_frame (cx);
2982 if (!_x_constrained) {
2983 _editor->snap_to_with_modifier (cx_frames, event);
2986 cx_frames = min (cx_frames, _point->line().maximum_time());
2988 float const fraction = 1.0 - (cy / _point->line().height());
2990 _point->line().drag_motion (_editor->frame_to_unit_unrounded (cx_frames), fraction, false, _pushing, _final_index);
2992 _editor->verbose_cursor()->set_text (_point->line().get_verbose_cursor_string (fraction));
2996 ControlPointDrag::finished (GdkEvent* event, bool movement_occurred)
2998 if (!movement_occurred) {
3002 if (Keyboard::modifier_state_equals (event->button.state, Keyboard::TertiaryModifier)) {
3003 _editor->reset_point_selection ();
3007 motion (event, false);
3010 _point->line().end_drag (_pushing, _final_index);
3011 _editor->session()->commit_reversible_command ();
3015 ControlPointDrag::aborted (bool)
3017 _point->line().reset ();
3021 ControlPointDrag::active (Editing::MouseMode m)
3023 if (m == Editing::MouseGain) {
3024 /* always active in mouse gain */
3028 /* otherwise active if the point is on an automation line (ie not if its on a region gain line) */
3029 return dynamic_cast<AutomationLine*> (&(_point->line())) != 0;
3032 LineDrag::LineDrag (Editor* e, ArdourCanvas::Item* i)
3035 _cumulative_y_drag (0)
3037 DEBUG_TRACE (DEBUG::Drags, "New LineDrag\n");
3041 LineDrag::start_grab (GdkEvent* event, Gdk::Cursor* /*cursor*/)
3043 _line = reinterpret_cast<AutomationLine*> (_item->get_data ("line"));
3046 _item = &_line->grab_item ();
3048 /* need to get x coordinate in terms of parent (TimeAxisItemView)
3049 origin, and ditto for y.
3052 double cx = event->button.x;
3053 double cy = event->button.y;
3055 _line->parent_group().w2i (cx, cy);
3057 framecnt_t const frame_within_region = (framecnt_t) floor (cx * _editor->frames_per_unit);
3062 if (!_line->control_points_adjacent (frame_within_region, before, after)) {
3063 /* no adjacent points */
3067 Drag::start_grab (event, _editor->cursors()->fader);
3069 /* store grab start in parent frame */
3074 double fraction = 1.0 - (cy / _line->height());
3076 _line->start_drag_line (before, after, fraction);
3078 _editor->verbose_cursor()->set (_line->get_verbose_cursor_string (fraction),
3079 event->button.x + 10, event->button.y + 10);
3081 _editor->verbose_cursor()->show ();
3085 LineDrag::motion (GdkEvent* event, bool)
3087 double dy = _drags->current_pointer_y() - last_pointer_y();
3089 if (event->button.state & Keyboard::SecondaryModifier) {
3093 double cy = _fixed_grab_y + _cumulative_y_drag + dy;
3095 _cumulative_y_drag = cy - _fixed_grab_y;
3098 cy = min ((double) _line->height(), cy);
3100 double const fraction = 1.0 - (cy / _line->height());
3103 /* we are ignoring x position for this drag, so we can just pass in anything */
3104 _line->drag_motion (0, fraction, true, false, ignored);
3106 _editor->verbose_cursor()->set_text (_line->get_verbose_cursor_string (fraction));
3110 LineDrag::finished (GdkEvent* event, bool)
3112 motion (event, false);
3113 _line->end_drag (false, 0);
3114 _editor->session()->commit_reversible_command ();
3118 LineDrag::aborted (bool)
3123 FeatureLineDrag::FeatureLineDrag (Editor* e, ArdourCanvas::Item* i)
3126 _cumulative_x_drag (0)
3128 DEBUG_TRACE (DEBUG::Drags, "New FeatureLineDrag\n");
3132 FeatureLineDrag::start_grab (GdkEvent* event, Gdk::Cursor* /*cursor*/)
3134 Drag::start_grab (event);
3136 _line = reinterpret_cast<Line*> (_item);
3139 /* need to get x coordinate in terms of parent (AudioRegionView) origin. */
3141 double cx = event->button.x;
3142 double cy = event->button.y;
3144 _item->property_parent().get_value()->w2i(cx, cy);
3146 /* store grab start in parent frame */
3147 _region_view_grab_x = cx;
3149 _before = *(float*) _item->get_data ("position");
3151 _arv = reinterpret_cast<AudioRegionView*> (_item->get_data ("regionview"));
3153 _max_x = _editor->frame_to_pixel(_arv->get_duration());
3157 FeatureLineDrag::motion (GdkEvent*, bool)
3159 double dx = _drags->current_pointer_x() - last_pointer_x();
3161 double cx = _region_view_grab_x + _cumulative_x_drag + dx;
3163 _cumulative_x_drag += dx;
3165 /* Clamp the min and max extent of the drag to keep it within the region view bounds */
3174 ArdourCanvas::Points points;
3176 double x1 = 0, x2 = 0, y1 = 0, y2 = 0;
3178 _line->get_bounds(x1, y2, x2, y2);
3180 points.push_back(Gnome::Art::Point(cx, 2.0)); // first x-coord needs to be a non-normal value
3181 points.push_back(Gnome::Art::Point(cx, y2 - y1));
3183 _line->property_points() = points;
3185 float *pos = new float;
3188 _line->set_data ("position", pos);
3194 FeatureLineDrag::finished (GdkEvent*, bool)
3196 _arv = reinterpret_cast<AudioRegionView*> (_item->get_data ("regionview"));
3197 _arv->update_transient(_before, _before);
3201 FeatureLineDrag::aborted (bool)
3206 RubberbandSelectDrag::RubberbandSelectDrag (Editor* e, ArdourCanvas::Item* i)
3208 , _vertical_only (false)
3210 DEBUG_TRACE (DEBUG::Drags, "New RubberbandSelectDrag\n");
3214 RubberbandSelectDrag::start_grab (GdkEvent* event, Gdk::Cursor *)
3216 Drag::start_grab (event);
3217 show_verbose_cursor_time (adjusted_current_frame (event));
3221 RubberbandSelectDrag::motion (GdkEvent* event, bool)
3228 framepos_t const pf = adjusted_current_frame (event, Config->get_rubberbanding_snaps_to_grid ());
3230 framepos_t grab = grab_frame ();
3231 if (Config->get_rubberbanding_snaps_to_grid ()) {
3232 _editor->snap_to_with_modifier (grab, event);
3235 /* base start and end on initial click position */
3245 if (_drags->current_pointer_y() < grab_y()) {
3246 y1 = _drags->current_pointer_y();
3249 y2 = _drags->current_pointer_y();
3254 if (start != end || y1 != y2) {
3256 double x1 = _editor->frame_to_pixel (start);
3257 double x2 = _editor->frame_to_pixel (end);
3259 _editor->rubberband_rect->property_x1() = x1;
3260 if (_vertical_only) {
3261 /* fixed 10 pixel width */
3262 _editor->rubberband_rect->property_x2() = x1 + 10;
3264 _editor->rubberband_rect->property_x2() = x2;
3267 _editor->rubberband_rect->property_y1() = y1;
3268 _editor->rubberband_rect->property_y2() = y2;
3270 _editor->rubberband_rect->show();
3271 _editor->rubberband_rect->raise_to_top();
3273 show_verbose_cursor_time (pf);
3275 do_select_things (event, true);
3280 RubberbandSelectDrag::do_select_things (GdkEvent* event, bool drag_in_progress)
3285 if (grab_frame() < last_pointer_frame()) {
3287 x2 = last_pointer_frame ();
3290 x1 = last_pointer_frame ();
3296 if (_drags->current_pointer_y() < grab_y()) {
3297 y1 = _drags->current_pointer_y();
3300 y2 = _drags->current_pointer_y();
3304 select_things (event->button.state, x1, x2, y1, y2, drag_in_progress);
3308 RubberbandSelectDrag::finished (GdkEvent* event, bool movement_occurred)
3310 if (movement_occurred) {
3312 motion (event, false);
3313 do_select_things (event, false);
3319 bool do_deselect = true;
3320 MidiTimeAxisView* mtv;
3322 if ((mtv = dynamic_cast<MidiTimeAxisView*>(_editor->clicked_axisview)) != 0) {
3324 if (_editor->selection->empty()) {
3325 /* nothing selected */
3326 add_midi_region (mtv);
3327 do_deselect = false;
3331 /* do not deselect if Primary or Tertiary (toggle-select or
3332 * extend-select are pressed.
3335 if (!Keyboard::modifier_state_contains (event->button.state, Keyboard::PrimaryModifier) &&
3336 !Keyboard::modifier_state_contains (event->button.state, Keyboard::TertiaryModifier) &&
3343 _editor->rubberband_rect->hide();
3347 RubberbandSelectDrag::aborted (bool)
3349 _editor->rubberband_rect->hide ();
3352 TimeFXDrag::TimeFXDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, std::list<RegionView*> const & v)
3353 : RegionDrag (e, i, p, v)
3355 DEBUG_TRACE (DEBUG::Drags, "New TimeFXDrag\n");
3359 TimeFXDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
3361 Drag::start_grab (event, cursor);
3363 show_verbose_cursor_time (adjusted_current_frame (event));
3367 TimeFXDrag::motion (GdkEvent* event, bool)
3369 RegionView* rv = _primary;
3370 StreamView* cv = rv->get_time_axis_view().view ();
3372 pair<TimeAxisView*, double> const tv = _editor->trackview_by_y_position (grab_y());
3373 int layer = tv.first->layer_display() == Overlaid ? 0 : tv.second;
3374 int layers = tv.first->layer_display() == Overlaid ? 1 : cv->layers();
3376 framepos_t const pf = adjusted_current_frame (event);
3378 if (pf > rv->region()->position()) {
3379 rv->get_time_axis_view().show_timestretch (rv->region()->position(), pf, layers, layer);
3382 show_verbose_cursor_time (pf);
3386 TimeFXDrag::finished (GdkEvent* /*event*/, bool movement_occurred)
3388 _primary->get_time_axis_view().hide_timestretch ();
3390 if (!movement_occurred) {
3394 if (last_pointer_frame() < _primary->region()->position()) {
3395 /* backwards drag of the left edge - not usable */
3399 framecnt_t newlen = last_pointer_frame() - _primary->region()->position();
3401 float percentage = (double) newlen / (double) _primary->region()->length();
3403 #ifndef USE_RUBBERBAND
3404 // Soundtouch uses percentage / 100 instead of normal (/ 1)
3405 if (_primary->region()->data_type() == DataType::AUDIO) {
3406 percentage = (float) ((double) newlen - (double) _primary->region()->length()) / ((double) newlen) * 100.0f;
3410 if (!_editor->get_selection().regions.empty()) {
3411 /* primary will already be included in the selection, and edit
3412 group shared editing will propagate selection across
3413 equivalent regions, so just use the current region
3417 if (_editor->time_stretch (_editor->get_selection().regions, percentage) == -1) {
3418 error << _("An error occurred while executing time stretch operation") << endmsg;
3424 TimeFXDrag::aborted (bool)
3426 _primary->get_time_axis_view().hide_timestretch ();
3429 ScrubDrag::ScrubDrag (Editor* e, ArdourCanvas::Item* i)
3432 DEBUG_TRACE (DEBUG::Drags, "New ScrubDrag\n");
3436 ScrubDrag::start_grab (GdkEvent* event, Gdk::Cursor *)
3438 Drag::start_grab (event);
3442 ScrubDrag::motion (GdkEvent* /*event*/, bool)
3444 _editor->scrub (adjusted_current_frame (0, false), _drags->current_pointer_x ());
3448 ScrubDrag::finished (GdkEvent* /*event*/, bool movement_occurred)
3450 if (movement_occurred && _editor->session()) {
3451 /* make sure we stop */
3452 _editor->session()->request_transport_speed (0.0);
3457 ScrubDrag::aborted (bool)
3462 SelectionDrag::SelectionDrag (Editor* e, ArdourCanvas::Item* i, Operation o)
3467 , _original_pointer_time_axis (-1)
3468 , _last_pointer_time_axis (-1)
3469 , _time_selection_at_start (!_editor->get_selection().time.empty())
3471 DEBUG_TRACE (DEBUG::Drags, "New SelectionDrag\n");
3473 if (_time_selection_at_start) {
3474 start_at_start = _editor->get_selection().time.start();
3475 end_at_start = _editor->get_selection().time.end_frame();
3480 SelectionDrag::start_grab (GdkEvent* event, Gdk::Cursor*)
3482 if (_editor->session() == 0) {
3486 Gdk::Cursor* cursor = 0;
3488 switch (_operation) {
3489 case CreateSelection:
3490 if (Keyboard::modifier_state_equals (event->button.state, Keyboard::CopyModifier)) {
3495 cursor = _editor->cursors()->selector;
3496 Drag::start_grab (event, cursor);
3499 case SelectionStartTrim:
3500 if (_editor->clicked_axisview) {
3501 _editor->clicked_axisview->order_selection_trims (_item, true);
3503 Drag::start_grab (event, _editor->cursors()->left_side_trim);
3506 case SelectionEndTrim:
3507 if (_editor->clicked_axisview) {
3508 _editor->clicked_axisview->order_selection_trims (_item, false);
3510 Drag::start_grab (event, _editor->cursors()->right_side_trim);
3514 Drag::start_grab (event, cursor);
3517 case SelectionExtend:
3518 Drag::start_grab (event, cursor);
3522 if (_operation == SelectionMove) {
3523 show_verbose_cursor_time (_editor->selection->time[_editor->clicked_selection].start);
3525 show_verbose_cursor_time (adjusted_current_frame (event));
3528 _original_pointer_time_axis = _editor->trackview_by_y_position (_drags->current_pointer_y ()).first->order ();
3532 SelectionDrag::setup_pointer_frame_offset ()
3534 switch (_operation) {
3535 case CreateSelection:
3536 _pointer_frame_offset = 0;
3539 case SelectionStartTrim:
3541 _pointer_frame_offset = raw_grab_frame() - _editor->selection->time[_editor->clicked_selection].start;
3544 case SelectionEndTrim:
3545 _pointer_frame_offset = raw_grab_frame() - _editor->selection->time[_editor->clicked_selection].end;
3548 case SelectionExtend:
3554 SelectionDrag::motion (GdkEvent* event, bool first_move)
3556 framepos_t start = 0;
3558 framecnt_t length = 0;
3559 framecnt_t distance = 0;
3561 pair<TimeAxisView*, int> const pending_time_axis = _editor->trackview_by_y_position (_drags->current_pointer_y ());
3562 if (pending_time_axis.first == 0) {
3566 framepos_t const pending_position = adjusted_current_frame (event);
3568 /* only alter selection if things have changed */
3570 if (pending_time_axis.first->order() == _last_pointer_time_axis && pending_position == last_pointer_frame()) {
3574 switch (_operation) {
3575 case CreateSelection:
3577 framepos_t grab = grab_frame ();
3580 grab = adjusted_current_frame (event, false);
3581 if (grab < pending_position) {
3582 _editor->snap_to (grab, -1);
3584 _editor->snap_to (grab, 1);
3588 if (pending_position < grab) {
3589 start = pending_position;
3592 end = pending_position;
3596 /* first drag: Either add to the selection
3597 or create a new selection
3603 /* adding to the selection */
3604 _editor->set_selected_track_as_side_effect (Selection::Add);
3605 //_editor->selection->add (_editor->clicked_axisview);
3606 _editor->clicked_selection = _editor->selection->add (start, end);
3611 if (_editor->clicked_axisview && !_editor->selection->selected (_editor->clicked_axisview)) {
3612 //_editor->selection->set (_editor->clicked_axisview);
3613 _editor->set_selected_track_as_side_effect (Selection::Set);
3616 _editor->clicked_selection = _editor->selection->set (start, end);
3620 /* select the track that we're in */
3621 if (find (_added_time_axes.begin(), _added_time_axes.end(), pending_time_axis.first) == _added_time_axes.end()) {
3622 // _editor->set_selected_track_as_side_effect (Selection::Add);
3623 _editor->selection->add (pending_time_axis.first);
3624 _added_time_axes.push_back (pending_time_axis.first);
3627 /* deselect any tracks that this drag no longer includes, being careful to only deselect
3628 tracks that we selected in the first place.
3631 int min_order = min (_original_pointer_time_axis, pending_time_axis.first->order());
3632 int max_order = max (_original_pointer_time_axis, pending_time_axis.first->order());
3634 list<TimeAxisView*>::iterator i = _added_time_axes.begin();
3635 while (i != _added_time_axes.end()) {
3637 list<TimeAxisView*>::iterator tmp = i;
3640 if ((*i)->order() < min_order || (*i)->order() > max_order) {
3641 _editor->selection->remove (*i);
3642 _added_time_axes.remove (*i);
3651 case SelectionStartTrim:
3653 start = _editor->selection->time[_editor->clicked_selection].start;
3654 end = _editor->selection->time[_editor->clicked_selection].end;
3656 if (pending_position > end) {
3659 start = pending_position;
3663 case SelectionEndTrim:
3665 start = _editor->selection->time[_editor->clicked_selection].start;
3666 end = _editor->selection->time[_editor->clicked_selection].end;
3668 if (pending_position < start) {
3671 end = pending_position;
3678 start = _editor->selection->time[_editor->clicked_selection].start;
3679 end = _editor->selection->time[_editor->clicked_selection].end;
3681 length = end - start;
3682 distance = pending_position - start;
3683 start = pending_position;
3684 _editor->snap_to (start);
3686 end = start + length;
3690 case SelectionExtend:
3694 if (event->button.x >= _editor->horizontal_position() + _editor->_canvas_width) {
3695 _editor->start_canvas_autoscroll (1, 0);
3699 switch (_operation) {
3701 if (_time_selection_at_start) {
3702 _editor->selection->move_time (distance);
3706 _editor->selection->replace (_editor->clicked_selection, start, end);
3710 if (_operation == SelectionMove) {
3711 show_verbose_cursor_time(start);
3713 show_verbose_cursor_time(pending_position);
3718 SelectionDrag::finished (GdkEvent* event, bool movement_occurred)
3720 Session* s = _editor->session();
3722 if (movement_occurred) {
3723 motion (event, false);
3724 /* XXX this is not object-oriented programming at all. ick */
3725 if (_editor->selection->time.consolidate()) {
3726 _editor->selection->TimeChanged ();
3729 /* XXX what if its a music time selection? */
3731 if ( s->get_play_range() && s->transport_rolling() ) {
3732 s->request_play_range (&_editor->selection->time, true);
3734 if (Config->get_always_play_range() && !s->transport_rolling()) {
3735 s->request_locate (_editor->get_selection().time.start());
3741 /* just a click, no pointer movement.
3744 if (_operation == SelectionExtend) {
3745 if (_time_selection_at_start) {
3746 framepos_t pos = adjusted_current_frame (event, false);
3747 framepos_t start = min (pos, start_at_start);
3748 framepos_t end = max (pos, end_at_start);
3749 _editor->selection->set (start, end);
3752 if (Keyboard::modifier_state_equals (event->button.state, Keyboard::CopyModifier)) {
3753 if (_editor->clicked_selection) {
3754 _editor->selection->remove (_editor->clicked_selection);
3757 if (!_editor->clicked_selection) {
3758 _editor->selection->clear_time();
3763 if (_editor->clicked_axisview && !_editor->selection->selected (_editor->clicked_axisview)) {
3764 _editor->selection->set (_editor->clicked_axisview);
3767 if (s && s->get_play_range () && s->transport_rolling()) {
3768 s->request_stop (false, false);
3773 _editor->stop_canvas_autoscroll ();
3774 _editor->clicked_selection = 0;
3778 SelectionDrag::aborted (bool)
3783 RangeMarkerBarDrag::RangeMarkerBarDrag (Editor* e, ArdourCanvas::Item* i, Operation o)
3788 DEBUG_TRACE (DEBUG::Drags, "New RangeMarkerBarDrag\n");
3790 _drag_rect = new ArdourCanvas::SimpleRect (*_editor->time_line_group, 0.0, 0.0, 0.0,
3791 physical_screen_height (_editor->get_window()));
3792 _drag_rect->hide ();
3794 _drag_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_RangeDragRect.get();
3795 _drag_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_RangeDragRect.get();
3799 RangeMarkerBarDrag::start_grab (GdkEvent* event, Gdk::Cursor *)
3801 if (_editor->session() == 0) {
3805 Gdk::Cursor* cursor = 0;
3807 if (!_editor->temp_location) {
3808 _editor->temp_location = new Location (*_editor->session());
3811 switch (_operation) {
3812 case CreateRangeMarker:
3813 case CreateTransportMarker:
3814 case CreateCDMarker:
3816 if (Keyboard::modifier_state_equals (event->button.state, Keyboard::TertiaryModifier)) {
3821 cursor = _editor->cursors()->selector;
3825 Drag::start_grab (event, cursor);
3827 show_verbose_cursor_time (adjusted_current_frame (event));
3831 RangeMarkerBarDrag::motion (GdkEvent* event, bool first_move)
3833 framepos_t start = 0;
3835 ArdourCanvas::SimpleRect *crect;
3837 switch (_operation) {
3838 case CreateRangeMarker:
3839 crect = _editor->range_bar_drag_rect;
3841 case CreateTransportMarker:
3842 crect = _editor->transport_bar_drag_rect;
3844 case CreateCDMarker:
3845 crect = _editor->cd_marker_bar_drag_rect;
3848 error << string_compose (_("programming_error: %1"), "Error: unknown range marker op passed to Editor::drag_range_markerbar_op ()") << endmsg;
3853 framepos_t const pf = adjusted_current_frame (event);
3855 if (_operation == CreateRangeMarker || _operation == CreateTransportMarker || _operation == CreateCDMarker) {
3856 framepos_t grab = grab_frame ();
3857 _editor->snap_to (grab);
3859 if (pf < grab_frame()) {
3867 /* first drag: Either add to the selection
3868 or create a new selection.
3873 _editor->temp_location->set (start, end);
3877 update_item (_editor->temp_location);
3879 //_drag_rect->raise_to_top();
3884 if (event->button.x >= _editor->horizontal_position() + _editor->_canvas_width) {
3885 _editor->start_canvas_autoscroll (1, 0);
3889 _editor->temp_location->set (start, end);
3891 double x1 = _editor->frame_to_pixel (start);
3892 double x2 = _editor->frame_to_pixel (end);
3893 crect->property_x1() = x1;
3894 crect->property_x2() = x2;
3896 update_item (_editor->temp_location);
3899 show_verbose_cursor_time (pf);
3904 RangeMarkerBarDrag::finished (GdkEvent* event, bool movement_occurred)
3906 Location * newloc = 0;
3910 if (movement_occurred) {
3911 motion (event, false);
3914 switch (_operation) {
3915 case CreateRangeMarker:
3916 case CreateCDMarker:
3918 _editor->begin_reversible_command (_("new range marker"));
3919 XMLNode &before = _editor->session()->locations()->get_state();
3920 _editor->session()->locations()->next_available_name(rangename,"unnamed");
3921 if (_operation == CreateCDMarker) {
3922 flags = Location::IsRangeMarker | Location::IsCDMarker;
3923 _editor->cd_marker_bar_drag_rect->hide();
3926 flags = Location::IsRangeMarker;
3927 _editor->range_bar_drag_rect->hide();
3929 newloc = new Location (
3930 *_editor->session(), _editor->temp_location->start(), _editor->temp_location->end(), rangename, (Location::Flags) flags
3933 _editor->session()->locations()->add (newloc, true);
3934 XMLNode &after = _editor->session()->locations()->get_state();
3935 _editor->session()->add_command(new MementoCommand<Locations>(*(_editor->session()->locations()), &before, &after));
3936 _editor->commit_reversible_command ();
3940 case CreateTransportMarker:
3941 // popup menu to pick loop or punch
3942 _editor->new_transport_marker_context_menu (&event->button, _item);
3946 /* just a click, no pointer movement. remember that context menu stuff was handled elsewhere */
3948 if (Keyboard::no_modifier_keys_pressed (&event->button) && _operation != CreateCDMarker) {
3953 _editor->session()->locations()->marks_either_side (grab_frame(), start, end);
3955 if (end == max_framepos) {
3956 end = _editor->session()->current_end_frame ();
3959 if (start == max_framepos) {
3960 start = _editor->session()->current_start_frame ();
3963 switch (_editor->mouse_mode) {
3965 /* find the two markers on either side and then make the selection from it */
3966 _editor->select_all_within (start, end, 0.0f, FLT_MAX, _editor->track_views, Selection::Set, false);
3970 /* find the two markers on either side of the click and make the range out of it */
3971 _editor->selection->set (start, end);
3980 _editor->stop_canvas_autoscroll ();
3984 RangeMarkerBarDrag::aborted (bool)
3990 RangeMarkerBarDrag::update_item (Location* location)
3992 double const x1 = _editor->frame_to_pixel (location->start());
3993 double const x2 = _editor->frame_to_pixel (location->end());
3995 _drag_rect->property_x1() = x1;
3996 _drag_rect->property_x2() = x2;
3999 MouseZoomDrag::MouseZoomDrag (Editor* e, ArdourCanvas::Item* i)
4003 DEBUG_TRACE (DEBUG::Drags, "New MouseZoomDrag\n");
4007 MouseZoomDrag::start_grab (GdkEvent* event, Gdk::Cursor *)
4009 if (Keyboard::the_keyboard().key_is_down (GDK_Control_L)) {
4010 Drag::start_grab (event, _editor->cursors()->zoom_out);
4013 Drag::start_grab (event, _editor->cursors()->zoom_in);
4017 show_verbose_cursor_time (adjusted_current_frame (event));
4021 MouseZoomDrag::motion (GdkEvent* event, bool first_move)
4026 framepos_t const pf = adjusted_current_frame (event);
4028 framepos_t grab = grab_frame ();
4029 _editor->snap_to_with_modifier (grab, event);
4031 /* base start and end on initial click position */
4043 _editor->zoom_rect->show();
4044 _editor->zoom_rect->raise_to_top();
4047 _editor->reposition_zoom_rect(start, end);
4049 show_verbose_cursor_time (pf);
4054 MouseZoomDrag::finished (GdkEvent* event, bool movement_occurred)
4056 if (movement_occurred) {
4057 motion (event, false);
4059 if (grab_frame() < last_pointer_frame()) {
4060 _editor->temporal_zoom_by_frame (grab_frame(), last_pointer_frame());
4062 _editor->temporal_zoom_by_frame (last_pointer_frame(), grab_frame());
4065 if (Keyboard::the_keyboard().key_is_down (GDK_Shift_L)) {
4066 _editor->tav_zoom_step (_zoom_out);
4068 _editor->temporal_zoom_to_frame (_zoom_out, grab_frame());
4072 _editor->zoom_rect->hide();
4076 MouseZoomDrag::aborted (bool)
4078 _editor->zoom_rect->hide ();
4081 NoteDrag::NoteDrag (Editor* e, ArdourCanvas::Item* i)
4083 , _cumulative_dx (0)
4084 , _cumulative_dy (0)
4086 DEBUG_TRACE (DEBUG::Drags, "New NoteDrag\n");
4088 _primary = dynamic_cast<CanvasNoteEvent*> (_item);
4089 _region = &_primary->region_view ();
4090 _note_height = _region->midi_stream_view()->note_height ();
4094 NoteDrag::start_grab (GdkEvent* event, Gdk::Cursor *)
4096 Drag::start_grab (event);
4098 if (!(_was_selected = _primary->selected())) {
4100 /* tertiary-click means extend selection - we'll do that on button release,
4101 so don't add it here, because otherwise we make it hard to figure
4102 out the "extend-to" range.
4105 bool extend = Keyboard::modifier_state_equals (event->button.state, Keyboard::TertiaryModifier);
4108 bool add = Keyboard::modifier_state_equals (event->button.state, Keyboard::PrimaryModifier);
4111 _region->note_selected (_primary, true);
4113 _region->unique_select (_primary);
4119 /** @return Current total drag x change in frames */
4121 NoteDrag::total_dx () const
4124 frameoffset_t const dx = _editor->unit_to_frame (_drags->current_pointer_x() - grab_x());
4126 /* primary note time */
4127 frameoffset_t const n = _region->source_beats_to_absolute_frames (_primary->note()->time ());
4129 /* new time of the primary note in session frames */
4130 frameoffset_t st = n + dx;
4132 framepos_t const rp = _region->region()->position ();
4134 /* prevent the note being dragged earlier than the region's position */
4137 /* snap and return corresponding delta */
4138 return _region->snap_frame_to_frame (st - rp) + rp - n;
4141 /** @return Current total drag y change in note number */
4143 NoteDrag::total_dy () const
4145 MidiStreamView* msv = _region->midi_stream_view ();
4146 double const y = _region->midi_view()->y_position ();
4147 /* new current note */
4148 uint8_t n = msv->y_to_note (_drags->current_pointer_y () - y);
4150 n = max (msv->lowest_note(), n);
4151 n = min (msv->highest_note(), n);
4152 /* and work out delta */
4153 return n - msv->y_to_note (grab_y() - y);
4157 NoteDrag::motion (GdkEvent *, bool)
4159 /* Total change in x and y since the start of the drag */
4160 frameoffset_t const dx = total_dx ();
4161 int8_t const dy = total_dy ();
4163 /* Now work out what we have to do to the note canvas items to set this new drag delta */
4164 double const tdx = _editor->frame_to_unit (dx) - _cumulative_dx;
4165 double const tdy = -dy * _note_height - _cumulative_dy;
4168 _cumulative_dx += tdx;
4169 _cumulative_dy += tdy;
4171 int8_t note_delta = total_dy();
4173 _region->move_selection (tdx, tdy, note_delta);
4175 /* the new note value may be the same as the old one, but we
4176 * don't know what that means because the selection may have
4177 * involved more than one note and we might be doing something
4178 * odd with them. so show the note value anyway, always.
4182 uint8_t new_note = min (max (_primary->note()->note() + note_delta, 0), 127);
4184 snprintf (buf, sizeof (buf), "%s (%d)", Evoral::midi_note_name (new_note).c_str(),
4185 (int) floor (new_note));
4187 show_verbose_cursor_text (buf);
4192 NoteDrag::finished (GdkEvent* ev, bool moved)
4195 /* no motion - select note */
4197 if (_editor->current_mouse_mode() == Editing::MouseObject ||
4198 _editor->current_mouse_mode() == Editing::MouseDraw) {
4200 if (_was_selected) {
4201 bool add = Keyboard::modifier_state_equals (ev->button.state, Keyboard::PrimaryModifier);
4203 _region->note_deselected (_primary);
4206 bool extend = Keyboard::modifier_state_equals (ev->button.state, Keyboard::TertiaryModifier);
4207 bool add = Keyboard::modifier_state_equals (ev->button.state, Keyboard::PrimaryModifier);
4209 if (!extend && !add && _region->selection_size() > 1) {
4210 _region->unique_select (_primary);
4211 } else if (extend) {
4212 _region->note_selected (_primary, true, true);
4214 /* it was added during button press */
4219 _region->note_dropped (_primary, total_dx(), total_dy());
4224 NoteDrag::aborted (bool)
4229 /** Make an AutomationRangeDrag for lines in an AutomationTimeAxisView */
4230 AutomationRangeDrag::AutomationRangeDrag (Editor* editor, AutomationTimeAxisView* atv, list<AudioRange> const & r)
4231 : Drag (editor, atv->base_item ())
4233 , _nothing_to_drag (false)
4235 DEBUG_TRACE (DEBUG::Drags, "New AutomationRangeDrag\n");
4236 y_origin = atv->y_position();
4237 setup (atv->lines ());
4240 /** Make an AutomationRangeDrag for region gain lines */
4241 AutomationRangeDrag::AutomationRangeDrag (Editor* editor, AudioRegionView* rv, list<AudioRange> const & r)
4242 : Drag (editor, rv->get_canvas_group ())
4244 , _nothing_to_drag (false)
4246 DEBUG_TRACE (DEBUG::Drags, "New AutomationRangeDrag\n");
4248 list<boost::shared_ptr<AutomationLine> > lines;
4249 lines.push_back (rv->get_gain_line ());
4250 y_origin = rv->get_time_axis_view().y_position();
4254 /** @param lines AutomationLines to drag.
4255 * @param offset Offset from the session start to the points in the AutomationLines.
4258 AutomationRangeDrag::setup (list<boost::shared_ptr<AutomationLine> > const & lines)
4260 /* find the lines that overlap the ranges being dragged */
4261 list<boost::shared_ptr<AutomationLine> >::const_iterator i = lines.begin ();
4262 while (i != lines.end ()) {
4263 list<boost::shared_ptr<AutomationLine> >::const_iterator j = i;
4266 pair<framepos_t, framepos_t> r = (*i)->get_point_x_range ();
4268 /* check this range against all the AudioRanges that we are using */
4269 list<AudioRange>::const_iterator k = _ranges.begin ();
4270 while (k != _ranges.end()) {
4271 if (k->coverage (r.first, r.second) != Evoral::OverlapNone) {
4277 /* add it to our list if it overlaps at all */
4278 if (k != _ranges.end()) {
4283 _lines.push_back (n);
4289 /* Now ::lines contains the AutomationLines that somehow overlap our drag */
4293 AutomationRangeDrag::y_fraction (boost::shared_ptr<AutomationLine> line, double global_y) const
4295 return 1.0 - ((global_y - y_origin) / line->height());
4299 AutomationRangeDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
4301 Drag::start_grab (event, cursor);
4303 /* Get line states before we start changing things */
4304 for (list<Line>::iterator i = _lines.begin(); i != _lines.end(); ++i) {
4305 i->state = &i->line->get_state ();
4306 i->original_fraction = y_fraction (i->line, _drags->current_pointer_y());
4309 if (_ranges.empty()) {
4311 /* No selected time ranges: drag all points */
4312 for (list<Line>::iterator i = _lines.begin(); i != _lines.end(); ++i) {
4313 uint32_t const N = i->line->npoints ();
4314 for (uint32_t j = 0; j < N; ++j) {
4315 i->points.push_back (i->line->nth (j));
4321 for (list<AudioRange>::const_iterator i = _ranges.begin(); i != _ranges.end(); ++i) {
4323 framecnt_t const half = (i->start + i->end) / 2;
4325 /* find the line that this audio range starts in */
4326 list<Line>::iterator j = _lines.begin();
4327 while (j != _lines.end() && (j->range.first > i->start || j->range.second < i->start)) {
4331 if (j != _lines.end()) {
4332 boost::shared_ptr<AutomationList> the_list = j->line->the_list ();
4334 /* j is the line that this audio range starts in; fade into it;
4335 64 samples length plucked out of thin air.
4338 framepos_t a = i->start + 64;
4343 double const p = j->line->time_converter().from (i->start - j->line->time_converter().origin_b ());
4344 double const q = j->line->time_converter().from (a - j->line->time_converter().origin_b ());
4346 the_list->add (p, the_list->eval (p));
4347 the_list->add (q, the_list->eval (q));
4350 /* same thing for the end */
4353 while (j != _lines.end() && (j->range.first > i->end || j->range.second < i->end)) {
4357 if (j != _lines.end()) {
4358 boost::shared_ptr<AutomationList> the_list = j->line->the_list ();
4360 /* j is the line that this audio range starts in; fade out of it;
4361 64 samples length plucked out of thin air.
4364 framepos_t b = i->end - 64;
4369 double const p = j->line->time_converter().from (b - j->line->time_converter().origin_b ());
4370 double const q = j->line->time_converter().from (i->end - j->line->time_converter().origin_b ());
4372 the_list->add (p, the_list->eval (p));
4373 the_list->add (q, the_list->eval (q));
4377 _nothing_to_drag = true;
4379 /* Find all the points that should be dragged and put them in the relevant
4380 points lists in the Line structs.
4383 for (list<Line>::iterator i = _lines.begin(); i != _lines.end(); ++i) {
4385 uint32_t const N = i->line->npoints ();
4386 for (uint32_t j = 0; j < N; ++j) {
4388 /* here's a control point on this line */
4389 ControlPoint* p = i->line->nth (j);
4390 double const w = i->line->time_converter().to ((*p->model())->when) + i->line->time_converter().origin_b ();
4392 /* see if it's inside a range */
4393 list<AudioRange>::const_iterator k = _ranges.begin ();
4394 while (k != _ranges.end() && (k->start >= w || k->end <= w)) {
4398 if (k != _ranges.end()) {
4399 /* dragging this point */
4400 _nothing_to_drag = false;
4401 i->points.push_back (p);
4407 if (_nothing_to_drag) {
4411 for (list<Line>::iterator i = _lines.begin(); i != _lines.end(); ++i) {
4412 i->line->start_drag_multiple (i->points, y_fraction (i->line, _drags->current_pointer_y()), i->state);
4417 AutomationRangeDrag::motion (GdkEvent*, bool /*first_move*/)
4419 if (_nothing_to_drag) {
4423 for (list<Line>::iterator l = _lines.begin(); l != _lines.end(); ++l) {
4424 float const f = y_fraction (l->line, _drags->current_pointer_y());
4425 /* we are ignoring x position for this drag, so we can just pass in anything */
4427 l->line->drag_motion (0, f, true, false, ignored);
4428 show_verbose_cursor_text (l->line->get_verbose_cursor_relative_string (l->original_fraction, f));
4433 AutomationRangeDrag::finished (GdkEvent* event, bool)
4435 if (_nothing_to_drag) {
4439 motion (event, false);
4440 for (list<Line>::iterator i = _lines.begin(); i != _lines.end(); ++i) {
4441 i->line->end_drag (false, 0);
4444 _editor->session()->commit_reversible_command ();
4448 AutomationRangeDrag::aborted (bool)
4450 for (list<Line>::iterator i = _lines.begin(); i != _lines.end(); ++i) {
4455 DraggingView::DraggingView (RegionView* v, RegionDrag* parent)
4458 time_axis_view = parent->find_time_axis_view (&v->get_time_axis_view ());
4459 layer = v->region()->layer ();
4460 initial_y = v->get_canvas_group()->property_y ();
4461 initial_playlist = v->region()->playlist ();
4462 initial_position = v->region()->position ();
4463 initial_end = v->region()->position () + v->region()->length ();
4466 PatchChangeDrag::PatchChangeDrag (Editor* e, CanvasPatchChange* i, MidiRegionView* r)
4470 , _cumulative_dx (0)
4472 DEBUG_TRACE (DEBUG::Drags, string_compose ("New PatchChangeDrag, patch @ %1, grab @ %2\n",
4473 _region_view->source_beats_to_absolute_frames (_patch_change->patch()->time()),
4478 PatchChangeDrag::motion (GdkEvent* ev, bool)
4480 framepos_t f = adjusted_current_frame (ev);
4481 boost::shared_ptr<Region> r = _region_view->region ();
4482 f = max (f, r->position ());
4483 f = min (f, r->last_frame ());
4485 framecnt_t const dxf = f - grab_frame(); // permitted dx in frames
4486 double const dxu = _editor->frame_to_unit (dxf); // permitted fx in units
4487 _patch_change->move (dxu - _cumulative_dx, 0);
4488 _cumulative_dx = dxu;
4492 PatchChangeDrag::finished (GdkEvent* ev, bool movement_occurred)
4494 if (!movement_occurred) {
4498 boost::shared_ptr<Region> r (_region_view->region ());
4499 framepos_t f = adjusted_current_frame (ev);
4500 f = max (f, r->position ());
4501 f = min (f, r->last_frame ());
4503 _region_view->move_patch_change (
4505 _region_view->region_frames_to_region_beats (f - (r->position() - r->start()))
4510 PatchChangeDrag::aborted (bool)
4512 _patch_change->move (-_cumulative_dx, 0);
4516 PatchChangeDrag::setup_pointer_frame_offset ()
4518 boost::shared_ptr<Region> region = _region_view->region ();
4519 _pointer_frame_offset = raw_grab_frame() - _region_view->source_beats_to_absolute_frames (_patch_change->patch()->time());
4522 MidiRubberbandSelectDrag::MidiRubberbandSelectDrag (Editor* e, MidiRegionView* rv)
4523 : RubberbandSelectDrag (e, rv->get_canvas_frame ())
4530 MidiRubberbandSelectDrag::select_things (int button_state, framepos_t x1, framepos_t x2, double y1, double y2, bool /*drag_in_progress*/)
4532 framepos_t const p = _region_view->region()->position ();
4533 double const y = _region_view->midi_view()->y_position ();
4535 x1 = max ((framepos_t) 0, x1 - p);
4536 x2 = max ((framepos_t) 0, x2 - p);
4537 y1 = max (0.0, y1 - y);
4538 y2 = max (0.0, y2 - y);
4540 _region_view->update_drag_selection (
4541 _editor->frame_to_pixel (x1),
4542 _editor->frame_to_pixel (x2),
4545 Keyboard::modifier_state_contains (button_state, Keyboard::TertiaryModifier)
4550 MidiRubberbandSelectDrag::deselect_things ()
4555 MidiVerticalSelectDrag::MidiVerticalSelectDrag (Editor* e, MidiRegionView* rv)
4556 : RubberbandSelectDrag (e, rv->get_canvas_frame ())
4559 _vertical_only = true;
4563 MidiVerticalSelectDrag::select_things (int button_state, framepos_t /*x1*/, framepos_t /*x2*/, double y1, double y2, bool /*drag_in_progress*/)
4565 double const y = _region_view->midi_view()->y_position ();
4567 y1 = max (0.0, y1 - y);
4568 y2 = max (0.0, y2 - y);
4570 _region_view->update_vertical_drag_selection (
4573 Keyboard::modifier_state_contains (button_state, Keyboard::TertiaryModifier)
4578 MidiVerticalSelectDrag::deselect_things ()
4583 EditorRubberbandSelectDrag::EditorRubberbandSelectDrag (Editor* e, ArdourCanvas::Item* i)
4584 : RubberbandSelectDrag (e, i)
4590 EditorRubberbandSelectDrag::select_things (int button_state, framepos_t x1, framepos_t x2, double y1, double y2, bool drag_in_progress)
4592 if (drag_in_progress) {
4593 /* We just want to select things at the end of the drag, not during it */
4597 Selection::Operation op = ArdourKeyboard::selection_type (button_state);
4599 _editor->begin_reversible_command (_("rubberband selection"));
4600 _editor->select_all_within (x1, x2 - 1, y1, y2, _editor->track_views, op, false);
4601 _editor->commit_reversible_command ();
4605 EditorRubberbandSelectDrag::deselect_things ()
4607 if (!getenv("ARDOUR_SAE")) {
4608 _editor->selection->clear_tracks();
4610 _editor->selection->clear_regions();
4611 _editor->selection->clear_points ();
4612 _editor->selection->clear_lines ();
4615 NoteCreateDrag::NoteCreateDrag (Editor* e, ArdourCanvas::Item* i, MidiRegionView* rv)
4623 NoteCreateDrag::~NoteCreateDrag ()
4629 NoteCreateDrag::grid_frames (framepos_t t) const
4632 Evoral::MusicalTime grid_beats = _editor->get_grid_type_as_beats (success, t);
4637 return _region_view->region_beats_to_region_frames (grid_beats);
4641 NoteCreateDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor)
4643 Drag::start_grab (event, cursor);
4645 _drag_rect = new ArdourCanvas::SimpleRect (*_region_view->get_canvas_group ());
4647 framepos_t pf = _drags->current_pointer_frame ();
4648 framecnt_t const g = grid_frames (pf);
4650 /* Hack so that we always snap to the note that we are over, instead of snapping
4651 to the next one if we're more than halfway through the one we're over.
4653 if (_editor->snap_mode() == SnapNormal && pf > g / 2) {
4657 _note[0] = adjusted_frame (pf, event) - _region_view->region()->position ();
4659 MidiStreamView* sv = _region_view->midi_stream_view ();
4660 double const x = _editor->frame_to_pixel (_note[0]);
4661 double const y = sv->note_to_y (sv->y_to_note (y_to_region (event->button.y)));
4663 _drag_rect->property_x1() = x;
4664 _drag_rect->property_y1() = y;
4665 _drag_rect->property_x2() = x;
4666 _drag_rect->property_y2() = y + floor (_region_view->midi_stream_view()->note_height ());
4668 _drag_rect->property_outline_what() = 0xff;
4669 _drag_rect->property_outline_color_rgba() = 0xffffff99;
4670 _drag_rect->property_fill_color_rgba() = 0xffffff66;
4674 NoteCreateDrag::motion (GdkEvent* event, bool)
4676 _note[1] = max ((framepos_t)0, adjusted_current_frame (event) - _region_view->region()->position ());
4677 double const x = _editor->frame_to_pixel (_note[1]);
4678 if (_note[1] > _note[0]) {
4679 _drag_rect->property_x2() = x;
4681 _drag_rect->property_x1() = x;
4686 NoteCreateDrag::finished (GdkEvent*, bool had_movement)
4688 if (!had_movement) {
4692 framepos_t const start = min (_note[0], _note[1]);
4693 framecnt_t length = (framecnt_t) fabs (_note[0] - _note[1]);
4695 framecnt_t const g = grid_frames (start);
4696 double const one_tick = 1 / Timecode::BBT_Time::ticks_per_beat;
4698 if (_editor->snap_mode() == SnapNormal && length < g) {
4699 length = g - one_tick;
4702 double const length_beats = max (one_tick, _region_view->region_frames_to_region_beats (length));
4704 _region_view->create_note_at (start, _drag_rect->property_y1(), length_beats, false);
4708 NoteCreateDrag::y_to_region (double y) const
4711 _region_view->get_canvas_group()->w2i (x, y);
4716 NoteCreateDrag::aborted (bool)
4721 CrossfadeEdgeDrag::CrossfadeEdgeDrag (Editor* e, AudioRegionView* rv, ArdourCanvas::Item* i, bool start_yn)
4726 std::cout << ("CrossfadeEdgeDrag is DEPRECATED. See TrimDrag::preserve_fade_anchor") << endl;
4730 CrossfadeEdgeDrag::start_grab (GdkEvent* event, Gdk::Cursor *cursor)
4732 Drag::start_grab (event, cursor);
4736 CrossfadeEdgeDrag::motion (GdkEvent*, bool)
4742 boost::shared_ptr<AudioRegion> ar (arv->audio_region());
4745 distance = _drags->current_pointer_x() - grab_x();
4746 len = ar->fade_in()->back()->when;
4748 distance = grab_x() - _drags->current_pointer_x();
4749 len = ar->fade_out()->back()->when;
4752 /* how long should it be ? */
4754 new_length = len + _editor->unit_to_frame (distance);
4756 /* now check with the region that this is legal */
4758 new_length = ar->verify_xfade_bounds (new_length, start);
4761 arv->redraw_start_xfade_to (ar, new_length);
4763 arv->redraw_end_xfade_to (ar, new_length);
4768 CrossfadeEdgeDrag::finished (GdkEvent*, bool)
4774 boost::shared_ptr<AudioRegion> ar (arv->audio_region());
4777 distance = _drags->current_pointer_x() - grab_x();
4778 len = ar->fade_in()->back()->when;
4780 distance = grab_x() - _drags->current_pointer_x();
4781 len = ar->fade_out()->back()->when;
4784 new_length = ar->verify_xfade_bounds (len + _editor->unit_to_frame (distance), start);
4786 _editor->begin_reversible_command ("xfade trim");
4787 ar->playlist()->clear_owned_changes ();
4790 ar->set_fade_in_length (new_length);
4792 ar->set_fade_out_length (new_length);
4795 /* Adjusting the xfade may affect other regions in the playlist, so we need
4796 to get undo Commands from the whole playlist rather than just the
4800 vector<Command*> cmds;
4801 ar->playlist()->rdiff (cmds);
4802 _editor->session()->add_commands (cmds);
4803 _editor->commit_reversible_command ();
4808 CrossfadeEdgeDrag::aborted (bool)
4811 arv->redraw_start_xfade ();
4813 arv->redraw_end_xfade ();