X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Feditor_drag.cc;h=9e763ff26494ac0bab3e86a0238db57a941f1a37;hb=c7863289664f0c847f6a5e1c0fa5b4c731c134d3;hp=d60df1c89679d602b796b8194a0c4bf7794b2dc0;hpb=f182235410d3121929c8357cf61bc66f56a2b4a0;p=ardour.git diff --git a/gtk2_ardour/editor_drag.cc b/gtk2_ardour/editor_drag.cc index d60df1c896..9e763ff264 100644 --- a/gtk2_ardour/editor_drag.cc +++ b/gtk2_ardour/editor_drag.cc @@ -37,6 +37,7 @@ #include "ardour/midi_region.h" #include "ardour/midi_track.h" #include "ardour/operations.h" +#include "ardour/profile.h" #include "ardour/region_factory.h" #include "ardour/session.h" @@ -44,7 +45,7 @@ #include "canvas/scroll_group.h" #include "editor.h" -#include "i18n.h" +#include "pbd/i18n.h" #include "keyboard.h" #include "audio_region_view.h" #include "automation_region_view.h" @@ -237,6 +238,7 @@ Drag::Drag (Editor* e, ArdourCanvas::Item* i, bool trackview_only) , _grab_frame (0) , _last_pointer_frame (0) , _snap_delta (0) + , _constraint_pressed (false) { } @@ -261,6 +263,7 @@ Drag::start_grab (GdkEvent* event, Gdk::Cursor *cursor) { /* we set up x/y dragging constraints on first move */ + _constraint_pressed = ArdourKeyboard::indicates_constraint (event->button.state); _raw_grab_frame = _editor->canvas_event_sample (event, &_grab_x, &_grab_y); @@ -420,14 +423,14 @@ Drag::motion_handler (GdkEvent* event, bool from_autoscroll) if (Config->get_edit_mode() != Lock) { if (event->motion.state & Gdk::BUTTON2_MASK) { // if dragging with button2, the motion is x constrained, with constraint modifier it is y constrained - if (Keyboard::modifier_state_equals (event->button.state, ArdourKeyboard::constraint_modifier ())) { + if (_constraint_pressed) { _x_constrained = false; _y_constrained = true; } else { _x_constrained = true; _y_constrained = false; } - } else if (Keyboard::modifier_state_equals (event->button.state, ArdourKeyboard::constraint_modifier ())) { + } else if (_constraint_pressed) { // if dragging normally, the motion is constrained to the first direction of movement. if (_initially_vertical) { _x_constrained = true; @@ -510,7 +513,7 @@ Drag::show_verbose_cursor_text (string const & text) } boost::shared_ptr -Drag::add_midi_region (MidiTimeAxisView* view, bool commit) +Drag::add_midi_region (MidiTimeAxisView* view, bool commit, const int32_t sub_num) { if (_editor->session()) { const TempoMap& map (_editor->session()->tempo_map()); @@ -518,19 +521,16 @@ Drag::add_midi_region (MidiTimeAxisView* view, bool commit) /* not that the frame rate used here can be affected by pull up/down which might be wrong. */ - framecnt_t len = map.frame_at_beat (map.beat_at_frame (pos) + 1.0) - pos; - return view->add_region (grab_frame(), len, commit); + framecnt_t len = map.frame_at_beat (max (0.0, map.beat_at_frame (pos)) + 1.0) - pos; + return view->add_region (grab_frame(), len, commit, sub_num); } return boost::shared_ptr(); } -struct EditorOrderTimeAxisViewSorter { +struct PresentationInfoTimeAxisViewSorter { bool operator() (TimeAxisView* a, TimeAxisView* b) { - RouteTimeAxisView* ra = dynamic_cast (a); - RouteTimeAxisView* rb = dynamic_cast (b); - assert (ra && rb); - return ra->route()->order_key () < rb->route()->order_key (); + return a->stripable()->presentation_info().order() < b->stripable()->presentation_info().order(); } }; @@ -546,7 +546,7 @@ RegionDrag::RegionDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, listtrack_views; - track_views.sort (EditorOrderTimeAxisViewSorter ()); + track_views.sort (PresentationInfoTimeAxisViewSorter ()); for (TrackViewList::iterator i = track_views.begin(); i != track_views.end(); ++i) { _time_axis_views.push_back (*i); @@ -599,6 +599,29 @@ RegionDrag::find_time_axis_view (TimeAxisView* t) const return i; } +/** determines if @pos is the closest frame to an exact musical division when using SnapMagnetic. + * (SnapMagnetic may snap to an exact division or no division at all). + * this is a hotfix for musical region position/trim. we should really + * deliver musical divisors when snapping magnetically to avoid this. +*/ +int32_t +RegionDrag::current_music_divisor (framepos_t pos, int32_t button_state) +{ + int32_t divisions = _editor->get_grid_music_divisions (button_state); + + if (_editor->snap_mode() == Editing::SnapMagnetic && !ArdourKeyboard::indicates_snap (button_state)) { + TempoMap& tmap (_editor->session()->tempo_map()); + const framepos_t exact_qn_pos = tmap.frame_at_quarter_note (tmap.exact_qn_at_frame (pos, divisions)); + + if (pos != exact_qn_pos) { + /* magnetic has not snapped */ + divisions = 0; + } + } + + return divisions; +} + RegionMotionDrag::RegionMotionDrag (Editor* e, ArdourCanvas::Item* i, RegionView* p, list const & v, bool b) : RegionDrag (e, i, p, v) , _brushing (b) @@ -846,7 +869,7 @@ RegionMotionDrag::motion (GdkEvent* event, bool first_move) RouteTimeAxisView* rtv = dynamic_cast (tv); if (!rtv || !rtv->is_track()) { - /* ignore busses early on. we can't move any regions on them */ + /* ignore non-tracks early on. we can't move any regions on them */ } else if (_last_pointer_time_axis_view < 0) { /* Was in the drop-zone, now over a track. * Hence it must be an upward move (from the bottom) @@ -1100,6 +1123,10 @@ RegionMotionDrag::motion (GdkEvent* event, bool first_move) y_delta = yposition - rv->get_canvas_group()->canvas_origin().y; } + MidiRegionView* mrv = dynamic_cast(rv); + if (mrv) { + mrv->apply_note_range (60, 71, true); + } } else { /* The TimeAxisView that this region is now over */ @@ -1161,6 +1188,14 @@ RegionMotionDrag::motion (GdkEvent* event, bool first_move) y_delta = track_origin.y - rv->get_canvas_group()->canvas_origin().y; } + + MidiRegionView* mrv = dynamic_cast(rv); + if (mrv) { + MidiStreamView* msv; + if ((msv = dynamic_cast (current_tv->view())) != 0) { + mrv->apply_note_range (msv->lowest_note(), msv->highest_note(), true); + } + } } /* Now move the region view */ @@ -1259,8 +1294,15 @@ RegionMoveDrag::motion (GdkEvent* event, bool first_move) MidiRegionView* mrv = dynamic_cast(rv); const boost::shared_ptr original = rv->region(); - boost::shared_ptr region_copy = RegionFactory::create (original, true); - region_copy->set_position (original->position()); + boost::shared_ptr region_copy; + + if (rv == _primary) { + region_copy = RegionFactory::create (original, true + , current_music_divisor (original->position(), event->button.state)); + } else { + region_copy = RegionFactory::create (original, true, 0); + } + /* need to set this so that the drop zone code can work. This doesn't actually put the region into the playlist, but just sets a weak pointer to it. @@ -1341,8 +1383,7 @@ RegionMoveDrag::finished (GdkEvent* ev, bool movement_occurred) if (was_double_click() && !_views.empty()) { DraggingView dv = _views.front(); - dv.view->show_region_editor (); - + _editor->edit_region (dv.view); } return; @@ -1367,7 +1408,8 @@ RegionMoveDrag::finished (GdkEvent* ev, bool movement_occurred) finished_copy ( changed_position, changed_tracks, - drag_delta + drag_delta, + ev->button.state ); } else { @@ -1375,12 +1417,11 @@ RegionMoveDrag::finished (GdkEvent* ev, bool movement_occurred) finished_no_copy ( changed_position, changed_tracks, - drag_delta + drag_delta, + ev->button.state ); } - - _editor->maybe_locate_with_edit_preroll (_editor->get_selection().regions.start()); } RouteTimeAxisView* @@ -1389,7 +1430,7 @@ RegionMoveDrag::create_destination_time_axis (boost::shared_ptr region, /* Add a new track of the correct type, and return the RouteTimeAxisView that is created to display the new track. */ - + TimeAxisView* tav = 0; try { if (boost::dynamic_pointer_cast (region)) { list > audio_tracks; @@ -1397,35 +1438,40 @@ RegionMoveDrag::create_destination_time_axis (boost::shared_ptr region, if ((Config->get_output_auto_connect() & AutoConnectMaster) && _editor->session()->master_out()) { output_chan = _editor->session()->master_out()->n_inputs().n_audio(); } - audio_tracks = _editor->session()->new_audio_track (region->n_channels(), output_chan, ARDOUR::Normal, 0, 1, region->name()); - RouteTimeAxisView* rtav = _editor->axis_view_from_route (audio_tracks.front()); - if (rtav) { - rtav->set_height (original->current_height()); - } - return rtav; + audio_tracks = _editor->session()->new_audio_track (region->n_channels(), output_chan, 0, 1, region->name(), PresentationInfo::max_order); + tav =_editor->axis_view_from_stripable (audio_tracks.front()); } else { ChanCount one_midi_port (DataType::MIDI, 1); list > midi_tracks; - midi_tracks = _editor->session()->new_midi_track (one_midi_port, one_midi_port, boost::shared_ptr(), ARDOUR::Normal, 0, 1, region->name()); - RouteTimeAxisView* rtav = _editor->axis_view_from_route (midi_tracks.front()); - if (rtav) { - rtav->set_height (original->current_height()); - } - return rtav; + midi_tracks = _editor->session()->new_midi_track (one_midi_port, one_midi_port, + Config->get_strict_io () || Profile->get_mixbus (), + boost::shared_ptr(), + (ARDOUR::Plugin::PresetRecord*) 0, + (ARDOUR::RouteGroup*) 0, 1, region->name(), PresentationInfo::max_order); + tav = _editor->axis_view_from_stripable (midi_tracks.front()); + } + + if (tav) { + tav->set_height (original->current_height()); } } catch (...) { error << _("Could not create new track after region placed in the drop zone") << endmsg; - return 0; } + + return dynamic_cast (tav); } void -RegionMoveDrag::finished_copy (bool const changed_position, bool const /*changed_tracks*/, framecnt_t const drag_delta) +RegionMoveDrag::finished_copy (bool const changed_position, bool const /*changed_tracks*/, framecnt_t const drag_delta, int32_t const ev_state) { RegionSelection new_views; PlaylistSet modified_playlists; RouteTimeAxisView* new_time_axis_view = 0; + int32_t divisor = current_music_divisor (_primary->region()->position() - drag_delta, ev_state); + TempoMap& tmap (_editor->session()->tempo_map()); + double qn_delta = _primary->region()->quarter_note() - tmap.exact_qn_at_frame (_primary->region()->position() - drag_delta, divisor); + if (_brushing) { /* all changes were made during motion event handlers */ @@ -1465,6 +1511,10 @@ RegionMoveDrag::finished_copy (bool const changed_position, bool const /*changed if ((pm = playlist_mapping.find (i->view->region()->playlist())) == playlist_mapping.end()) { /* first region from this original playlist: create a new track */ new_time_axis_view = create_destination_time_axis (i->view->region(), i->initial_time_axis_view); + if(!new_time_axis_view) { + Drag::abort(); + return; + } playlist_mapping.insert (make_pair (i->view->region()->playlist(), new_time_axis_view)); dest_rtv = new_time_axis_view; } else { @@ -1477,7 +1527,21 @@ RegionMoveDrag::finished_copy (bool const changed_position, bool const /*changed } if (dest_rtv != 0) { - RegionView* new_view = insert_region_into_playlist (i->view->region(), dest_rtv, i->layer, where, modified_playlists); + RegionView* new_view; + if (i->view == _primary) { + new_view = insert_region_into_playlist (i->view->region(), dest_rtv, i->layer, where, + modified_playlists, current_music_divisor (where, ev_state)); + } else { + if (i->view->region()->position_lock_style() == AudioTime) { + new_view = insert_region_into_playlist (i->view->region(), dest_rtv, i->layer, where, + modified_playlists, 0); + } else { + where = tmap.frame_at_quarter_note (i->view->region()->quarter_note() - qn_delta); + new_view = insert_region_into_playlist (i->view->region(), dest_rtv, i->layer, where, + modified_playlists, 0); + } + } + if (new_view != 0) { new_views.push_back (new_view); } @@ -1511,7 +1575,8 @@ void RegionMoveDrag::finished_no_copy ( bool const changed_position, bool const changed_tracks, - framecnt_t const drag_delta + framecnt_t const drag_delta, + int32_t const ev_state ) { RegionSelection new_views; @@ -1523,6 +1588,11 @@ RegionMoveDrag::finished_no_copy ( typedef map, RouteTimeAxisView*> PlaylistMapping; PlaylistMapping playlist_mapping; + int32_t divisor = current_music_divisor (_primary->region()->position() - drag_delta, ev_state); + TempoMap& tmap (_editor->session()->tempo_map()); + double qn_delta = _primary->region()->quarter_note() - tmap.exact_qn_at_frame (_primary->region()->position() - drag_delta, divisor); + + std::set > uniq; for (list::const_iterator i = _views.begin(); i != _views.end(); ) { RegionView* rv = i->view; @@ -1533,6 +1603,13 @@ RegionMoveDrag::finished_no_copy ( continue; } + if (uniq.find (rv->region()) != uniq.end()) { + /* prevent duplicate moves when selecting regions from shared playlists */ + ++i; + continue; + } + uniq.insert(rv->region()); + if (i->time_axis_view < 0 || i->time_axis_view >= (int)_time_axis_views.size()) { /* dragged to drop zone */ @@ -1541,6 +1618,10 @@ RegionMoveDrag::finished_no_copy ( if ((pm = playlist_mapping.find (i->view->region()->playlist())) == playlist_mapping.end()) { /* first region from this original playlist: create a new track */ new_time_axis_view = create_destination_time_axis (i->view->region(), i->initial_time_axis_view); + if(!new_time_axis_view) { // New track creation failed + Drag::abort(); + return; + } playlist_mapping.insert (make_pair (i->view->region()->playlist(), new_time_axis_view)); dest_rtv = new_time_axis_view; } else { @@ -1570,10 +1651,27 @@ RegionMoveDrag::finished_no_copy ( if (changed_tracks) { /* insert into new playlist */ + RegionView* new_view; + if (rv == _primary) { + new_view = insert_region_into_playlist ( + RegionFactory::create (rv->region (), true), dest_rtv, dest_layer, where, + modified_playlists, current_music_divisor (where, ev_state) + ); + } else { + if (rv->region()->position_lock_style() == AudioTime) { - RegionView* new_view = insert_region_into_playlist ( - RegionFactory::create (rv->region (), true), dest_rtv, dest_layer, where, modified_playlists - ); + new_view = insert_region_into_playlist ( + RegionFactory::create (rv->region (), true), dest_rtv, dest_layer, where, + modified_playlists, 0 + ); + } else { + where = tmap.frame_at_quarter_note (rv->region()->quarter_note() - qn_delta); + new_view = insert_region_into_playlist ( + RegionFactory::create (rv->region (), true), dest_rtv, dest_layer, where, + modified_playlists, 0 + ); + } + } if (new_view == 0) { ++i; @@ -1631,8 +1729,16 @@ RegionMoveDrag::finished_no_copy ( if (r.second) { playlist->freeze (); } + if (rv == _primary) { + rv->region()->set_position (where, current_music_divisor (where, ev_state)); + } else { + if (rv->region()->position_lock_style() == AudioTime) { + rv->region()->set_position (where, 0); + } else { + rv->region()->set_position (tmap.frame_at_quarter_note (rv->region()->quarter_note() - qn_delta), 0); - rv->region()->set_position (where); + } + } _editor->session()->add_command (new StatefulDiffCommand (rv->region())); } @@ -1735,7 +1841,8 @@ RegionMoveDrag::insert_region_into_playlist ( RouteTimeAxisView* dest_rtv, layer_t dest_layer, framecnt_t where, - PlaylistSet& modified_playlists + PlaylistSet& modified_playlists, + const int32_t sub_num ) { boost::shared_ptr dest_playlist = dest_rtv->playlist (); @@ -1752,8 +1859,7 @@ RegionMoveDrag::insert_region_into_playlist ( if (r.second) { dest_playlist->clear_changes (); } - - dest_playlist->add_region (region, where); + dest_playlist->add_region (region, where, 1.0, false, sub_num); if (dest_rtv->view()->layer_display() == Stacked || dest_rtv->view()->layer_display() == Expanded) { dest_playlist->set_layer (region, dest_layer); @@ -1877,7 +1983,7 @@ RegionInsertDrag::RegionInsertDrag (Editor* e, boost::shared_ptr r, Rout } void -RegionInsertDrag::finished (GdkEvent *, bool) +RegionInsertDrag::finished (GdkEvent * event, bool) { int pos = _views.front().time_axis_view; assert(pos >= 0 && pos < (int)_time_axis_views.size()); @@ -2234,8 +2340,7 @@ RegionRippleDrag::finished (GdkEvent* event, bool movement_occurred) if (was_double_click() && !_views.empty()) { DraggingView dv = _views.front(); - dv.view->show_region_editor (); - + _editor->edit_region (dv.view); } return; @@ -2304,7 +2409,7 @@ RegionCreateDrag::motion (GdkEvent* event, bool first_move) { if (first_move) { _editor->begin_reversible_command (_("create region")); - _region = add_midi_region (_view, false); + _region = add_midi_region (_view, false, _editor->get_grid_music_divisions (event->button.state)); _view->playlist()->freeze (); } else { if (_region) { @@ -2321,16 +2426,16 @@ RegionCreateDrag::motion (GdkEvent* event, bool first_move) */ framecnt_t const len = (framecnt_t) fabs ((double)(f - grab_frame () - 1)); - _region->set_length (len < 1 ? 1 : len); + _region->set_length (len < 1 ? 1 : len, _editor->get_grid_music_divisions (event->button.state)); } } } void -RegionCreateDrag::finished (GdkEvent*, bool movement_occurred) +RegionCreateDrag::finished (GdkEvent* event, bool movement_occurred) { if (!movement_occurred) { - add_midi_region (_view, true); + add_midi_region (_view, true, _editor->get_grid_music_divisions (event->button.state)); } else { _view->playlist()->thaw (); _editor->commit_reversible_command(); @@ -2851,7 +2956,6 @@ TrimDrag::motion (GdkEvent* event, bool first_move) for (list::const_iterator i = _views.begin(); i != _views.end(); ++i) { RegionView* rv = i->view; - rv->enable_display (false); rv->region()->playlist()->clear_owned_changes (); if (_operation == StartTrim) { @@ -2908,11 +3012,14 @@ TrimDrag::motion (GdkEvent* event, bool first_move) } } + int32_t divisions = current_music_divisor (adj_frame, event->button.state); switch (_operation) { case StartTrim: for (list::iterator i = _views.begin(); i != _views.end(); ++i) { - bool changed = i->view->trim_front (i->initial_position + dt, non_overlap_trim); + bool changed = i->view->trim_front (i->initial_position + dt, non_overlap_trim + , divisions); + if (changed && _preserve_fade_anchor) { AudioRegionView* arv = dynamic_cast (i->view); if (arv) { @@ -2930,7 +3037,7 @@ TrimDrag::motion (GdkEvent* event, bool first_move) case EndTrim: for (list::iterator i = _views.begin(); i != _views.end(); ++i) { - bool changed = i->view->trim_end (i->initial_end + dt, non_overlap_trim); + bool changed = i->view->trim_end (i->initial_end + dt, non_overlap_trim, divisions); if (changed && _preserve_fade_anchor) { AudioRegionView* arv = dynamic_cast (i->view); if (arv) { @@ -3015,18 +3122,6 @@ TrimDrag::finished (GdkEvent* event, bool movement_occurred) } } - if (!_views.empty()) { - if (_operation == StartTrim) { - _editor->maybe_locate_with_edit_preroll( - _views.begin()->view->region()->position()); - } - if (_operation == EndTrim) { - _editor->maybe_locate_with_edit_preroll( - _views.begin()->view->region()->position() + - _views.begin()->view->region()->length()); - } - } - if (!_editor->selection->selected (_primary)) { _primary->thaw_after_trim (); } else { @@ -3079,10 +3174,11 @@ TrimDrag::aborted (bool movement_occurred) behind which may be slightly odd from the user's point of view. */ - finished (0, true); + GdkEvent ev; + finished (&ev, true); if (movement_occurred) { - _editor->undo (); + _editor->session()->undo (1); } for (list::const_iterator i = _views.begin(); i != _views.end(); ++i) { @@ -3115,8 +3211,10 @@ TrimDrag::setup_pointer_frame_offset () } MeterMarkerDrag::MeterMarkerDrag (Editor* e, ArdourCanvas::Item* i, bool c) - : Drag (e, i), - _copy (c) + : Drag (e, i) + , _copy (c) + , _old_snap_type (e->snap_type()) + , _old_snap_mode (e->snap_mode()) , before_state (0) { DEBUG_TRACE (DEBUG::Drags, "New MeterMarkerDrag\n"); @@ -3143,7 +3241,6 @@ void MeterMarkerDrag::motion (GdkEvent* event, bool first_move) { if (first_move) { - // create a dummy marker to catch events, then hide it. char name[64]; @@ -3178,33 +3275,35 @@ MeterMarkerDrag::motion (GdkEvent* event, bool first_move) } else { --bbt.bars; } - const double beat = map.bbt_to_beats (bbt); + const double beat = map.beat_at_bbt (bbt); + const framepos_t frame = map.frame_at_beat (beat); _real_section = map.add_meter (Meter (_marker->meter().divisions_per_bar(), _marker->meter().note_divisor()) - , beat, bbt, map.frame_time (bbt), _real_section->position_lock_style()); + , beat, bbt, frame, _real_section->position_lock_style()); + if (!_real_section) { + aborted (true); + return; + } } + /* only snap to bars. leave snap mode alone for audio locked meters.*/ + if (_real_section->position_lock_style() != AudioTime) { + _editor->set_snap_to (SnapToBar); + _editor->set_snap_mode (SnapNormal); + } } - framepos_t const pf = adjusted_current_frame (event, false); - if (_marker->meter().position_lock_style() == MusicTime) { - TempoMap& map (_editor->session()->tempo_map()); - Timecode::BBT_Time bbt; - map.bbt_time (pf, bbt); - /* round bbt to bars */ - map.round_bbt (bbt, -1, RoundNearest); - - if ((bbt.bars != _real_section->bbt().bars && pf > last_pointer_frame()) - || (bbt.bars < _real_section->bbt().bars && pf < last_pointer_frame())) { + framepos_t pf = adjusted_current_frame (event); - /* move meter beat-based */ - _editor->session()->tempo_map().gui_move_meter_bbt (_real_section, bbt); - } - } else { - /* AudioTime */ - /* move meter frame-based */ - _editor->session()->tempo_map().gui_move_meter_frame (_real_section, pf); + if (_real_section->position_lock_style() == AudioTime && _editor->snap_musical()) { + /* never snap to music for audio locked */ + pf = adjusted_current_frame (event, false); } - _marker->set_position (pf); + + _editor->session()->tempo_map().gui_set_meter_position (_real_section, pf); + + /* fake marker meeds to stay under the mouse, unlike the real one. */ + _marker->set_position (adjusted_current_frame (event, false)); + show_verbose_cursor_time (_real_section->frame()); } @@ -3218,6 +3317,10 @@ MeterMarkerDrag::finished (GdkEvent* event, bool movement_occurred) return; } + /* reinstate old snap setting */ + _editor->set_snap_to (_old_snap_type); + _editor->set_snap_mode (_old_snap_mode); + TempoMap& map (_editor->session()->tempo_map()); XMLNode &after = map.get_state(); @@ -3234,6 +3337,10 @@ MeterMarkerDrag::aborted (bool moved) { _marker->set_position (_marker->meter().frame ()); if (moved) { + /* reinstate old snap setting */ + _editor->set_snap_to (_old_snap_type); + _editor->set_snap_mode (_old_snap_mode); + _editor->session()->tempo_map().set_state (*before_state, Stateful::current_state_version); // delete the dummy marker we used for visual representation while moving. // a new visual marker will show up automatically. @@ -3244,13 +3351,15 @@ MeterMarkerDrag::aborted (bool moved) TempoMarkerDrag::TempoMarkerDrag (Editor* e, ArdourCanvas::Item* i, bool c) : Drag (e, i) , _copy (c) + , _grab_bpm (0.0) , before_state (0) { DEBUG_TRACE (DEBUG::Drags, "New TempoMarkerDrag\n"); _marker = reinterpret_cast (_item->get_data ("marker")); _real_section = &_marker->tempo(); - _movable = _real_section->movable(); + _movable = !_real_section->initial(); + _grab_bpm = _real_section->note_types_per_minute(); assert (_marker); } @@ -3268,7 +3377,7 @@ TempoMarkerDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor) void TempoMarkerDrag::setup_pointer_frame_offset () { - _pointer_frame_offset = raw_grab_frame() - _marker->tempo().frame(); + _pointer_frame_offset = raw_grab_frame() - _real_section->frame(); } void @@ -3283,7 +3392,7 @@ TempoMarkerDrag::motion (GdkEvent* event, bool first_move) // mvc drag - create a dummy marker to catch events, hide it. char name[64]; - snprintf (name, sizeof (name), "%.2f", _marker->tempo().beats_per_minute()); + snprintf (name, sizeof (name), "%.2f", _marker->tempo().note_types_per_minute()); TempoSection section (_marker->tempo()); @@ -3302,127 +3411,62 @@ TempoMarkerDrag::motion (GdkEvent* event, bool first_move) TempoMap& map (_editor->session()->tempo_map()); /* get current state */ before_state = &map.get_state(); + if (!_copy) { _editor->begin_reversible_command (_("move tempo mark")); + } else { + const Tempo tempo (_marker->tempo()); + const framepos_t frame = adjusted_current_frame (event) + 1; + const TempoSection::Type type = _real_section->type(); + _editor->begin_reversible_command (_("copy tempo mark")); - framepos_t frame; - bool use_snap = false; - if (!_editor->snap_musical()) { - frame = adjusted_current_frame (event); + if (_real_section->position_lock_style() == MusicTime) { + const int32_t divisions = _editor->get_grid_music_divisions (event->button.state); + _real_section = map.add_tempo (tempo, map.exact_qn_at_frame (frame, divisions), 0, type, MusicTime); } else { - frame = adjusted_current_frame (event, false); - if (ArdourKeyboard::indicates_snap (event->button.state)) { - if (_editor->snap_mode() == Editing::SnapOff) { - use_snap = true; - } else { - use_snap = false; - } - } else { - if (_editor->snap_mode() == Editing::SnapOff) { - use_snap = false; - } else { - use_snap = true; - } - } + _real_section = map.add_tempo (tempo, 0.0, frame, type, AudioTime); } - Timecode::BBT_Time bbt; - map.bbt_time (frame, bbt); - - /* add new tempo section to map, ensuring we don't refer to existing tempos for snap */ - - if (_real_section->position_lock_style() == MusicTime) { - if (use_snap && _editor->snap_type() == SnapToBar) { - map.round_bbt (bbt, -1, (frame > _real_section->frame()) ? RoundUpMaybe : RoundDownMaybe); - } else if (use_snap) { - map.round_bbt (bbt, _editor->get_grid_beat_divisions (0), RoundNearest); - } - double const pulse = map.predict_tempo (_real_section, bbt).first; - _real_section = map.add_tempo (_marker->tempo(), pulse, 0, _real_section->type(), MusicTime); - } else { - if (use_snap && _editor->snap_type() == SnapToBar) { - map.round_bbt (bbt, -1, (frame > _real_section->frame()) ? RoundUpMaybe : RoundDownMaybe); - } else if (use_snap) { - map.round_bbt (bbt, _editor->get_grid_beat_divisions (0), RoundNearest); - } - if (use_snap) { - frame = map.predict_tempo (_real_section, bbt).second; - } - _real_section = map.add_tempo (_marker->tempo(), 0.0, frame, _real_section->type(), AudioTime); + if (!_real_section) { + aborted (true); + return; } } } - framepos_t pf; - - if (Keyboard::modifier_state_contains (event->button.state, ArdourKeyboard::constraint_modifier ())) { - double new_bpm = _real_section->beats_per_minute() + ((last_pointer_y() - current_pointer_y()) / 5.0); - _editor->session()->tempo_map().gui_change_tempo (_real_section, Tempo (new_bpm, _real_section->note_type())); + if (ArdourKeyboard::indicates_constraint (event->button.state)) { + /* use vertical movement to alter tempo .. should be log */ + double new_bpm = max (1.5, _grab_bpm + ((grab_y() - min (-1.0, current_pointer_y())) / 5.0)); stringstream strs; + _editor->session()->tempo_map().gui_change_tempo (_real_section, Tempo (new_bpm, _real_section->note_type())); strs << new_bpm; show_verbose_cursor_text (strs.str()); + } else if (_movable && !_real_section->locked_to_meter()) { - if (!_editor->snap_musical()) { - /* snap normally (this is not self-referential).*/ - pf = adjusted_current_frame (event); - } else { - /* but this is. - we can't use the map for anything related to tempo, - so we round bbt using meters, which have no dependency - on pulse for this kind of thing. - */ - bool use_snap; - TempoMap& map (_editor->session()->tempo_map()); + framepos_t pf; + if (_editor->snap_musical()) { + /* we can't snap to a grid that we are about to move. + * gui_move_tempo() will sort out snap using the supplied beat divisions. + */ pf = adjusted_current_frame (event, false); - if (ArdourKeyboard::indicates_snap (event->button.state)) { - if (_editor->snap_mode() == Editing::SnapOff) { - use_snap = true; - } else { - use_snap = false; - } - } else { - if (_editor->snap_mode() == Editing::SnapOff) { - use_snap = false; - } else { - use_snap = true; - } - } + } else { + pf = adjusted_current_frame (event); + } - Timecode::BBT_Time when; - map.bbt_time (pf, when); + TempoMap& map (_editor->session()->tempo_map()); - if (_real_section->position_lock_style() == MusicTime) { + /* snap to beat is 1, snap to bar is -1 (sorry) */ + const int sub_num = _editor->get_grid_music_divisions (event->button.state); - const double pulse = map.predict_tempo (_real_section, when).first; - when = map.pulse_to_bbt (pulse); - if (use_snap && _editor->snap_type() == SnapToBar) { - map.round_bbt (when, -1, (pf > _real_section->frame()) ? RoundUpMaybe : RoundDownMaybe); - } else if (use_snap) { - map.round_bbt (when, _editor->get_grid_beat_divisions (0), RoundNearest); - } - - const double beat = map.bbt_to_beats (when); - map.gui_move_tempo_beat (_real_section, beat); - } else { - if (use_snap && _editor->snap_type() == SnapToBar) { - map.round_bbt (when, -1, (pf > _real_section->frame()) ? RoundUpMaybe : RoundDownMaybe); - } else if (use_snap) { - map.round_bbt (when, _editor->get_grid_beat_divisions (0), RoundNearest); - } - if (use_snap) { - pf = map.predict_tempo (_real_section, when).second; - } - map.gui_move_tempo_frame (_real_section, pf); - } - } + map.gui_set_tempo_position (_real_section, pf, sub_num); show_verbose_cursor_time (_real_section->frame()); } - _marker->set_position (pf); + _marker->set_position (adjusted_current_frame (event, false)); } void @@ -3456,16 +3500,14 @@ TempoMarkerDrag::aborted (bool moved) if (moved) { TempoMap& map (_editor->session()->tempo_map()); map.set_state (*before_state, Stateful::current_state_version); - // delete the dummy marker we used for visual representation while moving. - // a new visual marker will show up automatically. + // delete the dummy (hidden) marker we used for events while moving. delete _marker; } } BBTRulerDrag::BBTRulerDrag (Editor* e, ArdourCanvas::Item* i) : Drag (e, i) - , _pulse (0.0) - , _beat (0.0) + , _grab_qn (0.0) , _tempo (0) , before_state (0) { @@ -3477,13 +3519,12 @@ void BBTRulerDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor) { Drag::start_grab (event, cursor); - TempoMap& map (_editor->session()->tempo_map()); + _tempo = const_cast (&map.tempo_section_at_frame (raw_grab_frame())); ostringstream sstr; - _tempo = const_cast (&map.tempo_section_at (raw_grab_frame())); - sstr << "^" << fixed << setprecision(3) << map.tempo_at (adjusted_current_frame (event)).beats_per_minute() << "\n"; - sstr << "<" << fixed << setprecision(3) << _tempo->beats_per_minute(); + sstr << "^" << fixed << setprecision(3) << map.tempo_at_frame (adjusted_current_frame (event)).note_types_per_minute() << "\n"; + sstr << "<" << fixed << setprecision(3) << _tempo->note_types_per_minute(); show_verbose_cursor_text (sstr.str()); finished (event, false); } @@ -3492,19 +3533,24 @@ void BBTRulerDrag::setup_pointer_frame_offset () { TempoMap& map (_editor->session()->tempo_map()); - const double beat_at_frame = map.beat_at_frame (raw_grab_frame()); + const double beat_at_frame = max (0.0, map.beat_at_frame (raw_grab_frame())); const uint32_t divisions = _editor->get_grid_beat_divisions (0); + double beat = 0.0; + if (divisions > 0) { - _beat = floor (beat_at_frame) + (floor (((beat_at_frame - floor (beat_at_frame)) * divisions)) / divisions); + beat = floor (beat_at_frame) + (floor (((beat_at_frame - floor (beat_at_frame)) * divisions)) / divisions); } else { /* while it makes some sense for the user to determine the division to 'grab', grabbing a bar often leads to confusing results wrt the actual tempo section being altered and the result over steep tempo curves. Use sixteenths. */ - _beat = floor (beat_at_frame) + (floor (((beat_at_frame - floor (beat_at_frame)) * 4)) / 4); + beat = floor (beat_at_frame) + (floor (((beat_at_frame - floor (beat_at_frame)) * 4)) / 4); } - _pulse = map.pulse_at_beat (_beat); - _pointer_frame_offset = raw_grab_frame() - map.frame_at_beat (_beat); + + _grab_qn = map.quarter_note_at_beat (beat); + + _pointer_frame_offset = raw_grab_frame() - map.frame_at_quarter_note (_grab_qn); + } void @@ -3515,18 +3561,24 @@ BBTRulerDrag::motion (GdkEvent* event, bool first_move) if (first_move) { /* get current state */ before_state = &map.get_state(); - _editor->begin_reversible_command (_("dilate tempo")); + _editor->begin_reversible_command (_("stretch tempo")); } - framepos_t const pf = adjusted_current_frame (event, false); + framepos_t pf; + + if (_editor->snap_musical()) { + pf = adjusted_current_frame (event, false); + } else { + pf = adjusted_current_frame (event); + } - if (Keyboard::modifier_state_contains (event->button.state, ArdourKeyboard::constraint_modifier())) { + if (ArdourKeyboard::indicates_constraint (event->button.state)) { /* adjust previous tempo to match pointer frame */ - _editor->session()->tempo_map().gui_dilate_tempo (_tempo, map.frame_at_pulse (_pulse), pf, _pulse); + _editor->session()->tempo_map().gui_stretch_tempo (_tempo, map.frame_at_quarter_note (_grab_qn), pf); } ostringstream sstr; - sstr << "^" << fixed << setprecision(3) << map.tempo_at (pf).beats_per_minute() << "\n"; - sstr << "<" << fixed << setprecision(3) << _tempo->beats_per_minute(); + sstr << "^" << fixed << setprecision(3) << map.tempo_at_frame (pf).note_types_per_minute() << "\n"; + sstr << "<" << fixed << setprecision(3) << _tempo->note_types_per_minute(); show_verbose_cursor_text (sstr.str()); } @@ -4147,6 +4199,8 @@ MarkerDrag::motion (GdkEvent* event, bool) return; } + const int32_t divisions = _editor->get_grid_music_divisions (event->button.state); + /* now move them all */ for (x = _copied_locations.begin(); x != _copied_locations.end(); ++x) { @@ -4164,8 +4218,7 @@ MarkerDrag::motion (GdkEvent* event, bool) if (copy_location->is_mark()) { /* now move it */ - - copy_location->set_start (copy_location->start() + f_delta); + copy_location->set_start (copy_location->start() + f_delta, false, true, divisions); } else { @@ -4175,27 +4228,27 @@ MarkerDrag::motion (GdkEvent* event, bool) if (is_start) { // start-of-range marker if (move_both || (*x).move_both) { - copy_location->set_start (new_start); - copy_location->set_end (new_end); + copy_location->set_start (new_start, false, true, divisions); + copy_location->set_end (new_end, false, true, divisions); } else if (new_start < copy_location->end()) { - copy_location->set_start (new_start); + copy_location->set_start (new_start, false, true, divisions); } else if (newframe > 0) { //_editor->snap_to (next, RoundUpAlways, true); - copy_location->set_end (next); - copy_location->set_start (newframe); + copy_location->set_end (next, false, true, divisions); + copy_location->set_start (newframe, false, true, divisions); } } else { // end marker if (move_both || (*x).move_both) { - copy_location->set_end (new_end); - copy_location->set_start (new_start); + copy_location->set_end (new_end, divisions); + copy_location->set_start (new_start, false, true, divisions); } else if (new_end > copy_location->start()) { - copy_location->set_end (new_end); + copy_location->set_end (new_end, false, true, divisions); } else if (newframe > 0) { //_editor->snap_to (next, RoundDownAlways, true); - copy_location->set_start (next); - copy_location->set_end (newframe); + copy_location->set_start (next, false, true, divisions); + copy_location->set_end (newframe, false, true, divisions); } } } @@ -4272,6 +4325,7 @@ MarkerDrag::finished (GdkEvent* event, bool movement_occurred) MarkerSelection::iterator i; CopiedLocationInfo::iterator x; + const int32_t divisions = _editor->get_grid_music_divisions (event->button.state); bool is_start; for (i = _editor->selection->markers.begin(), x = _copied_locations.begin(); @@ -4290,9 +4344,13 @@ MarkerDrag::finished (GdkEvent* event, bool movement_occurred) in_command = true; } if (location->is_mark()) { - location->set_start (((*x).location)->start()); + location->set_start (((*x).location)->start(), false, true, divisions); } else { - location->set (((*x).location)->start(), ((*x).location)->end()); + location->set (((*x).location)->start(), ((*x).location)->end(), true, divisions); + } + + if (location->is_session_range()) { + _editor->session()->set_end_is_free (false); } } } @@ -4361,7 +4419,7 @@ ControlPointDrag::start_grab (GdkEvent* event, Gdk::Cursor* /*cursor*/) // start the grab at the center of the control point so // the point doesn't 'jump' to the mouse after the first drag - _fixed_grab_x = _point->get_x(); + _fixed_grab_x = _point->get_x() + _editor->sample_to_pixel_unrounded (_point->line().offset()); _fixed_grab_y = _point->get_y(); framepos_t pos = _editor->pixel_to_sample (_fixed_grab_x); @@ -4419,13 +4477,12 @@ ControlPointDrag::motion (GdkEvent* event, bool first_motion) } framepos_t cx_frames = _editor->pixel_to_sample (cx) + snap_delta (event->button.state); - if (!_x_constrained && need_snap) { _editor->snap_to_with_modifier (cx_frames, event); } cx_frames -= snap_delta (event->button.state); - cx_frames = min (cx_frames, _point->line().maximum_time()); + cx_frames = min (cx_frames, _point->line().maximum_time() + _point->line().offset()); float const fraction = 1.0 - (cy / _point->line().height()); @@ -4825,7 +4882,7 @@ RubberbandSelectDrag::finished (GdkEvent* event, bool movement_occurred) /* MIDI track */ if (_editor->selection->empty() && _editor->mouse_mode == MouseDraw) { /* nothing selected */ - add_midi_region (mtv, true); + add_midi_region (mtv, true, _editor->get_grid_music_divisions(event->button.state)); do_deselect = false; } } @@ -4981,6 +5038,7 @@ SelectionDrag::SelectionDrag (Editor* e, ArdourCanvas::Item* i, Operation o) : Drag (e, i) , _operation (o) , _add (false) + , _track_selection_at_start (e) , _time_selection_at_start (!_editor->get_selection().time.empty()) { DEBUG_TRACE (DEBUG::Drags, "New SelectionDrag\n"); @@ -5077,6 +5135,10 @@ SelectionDrag::motion (GdkEvent* event, bool first_move) return; } + if (first_move) { + _track_selection_at_start = _editor->selection->tracks; + } + switch (_operation) { case CreateSelection: { @@ -5148,32 +5210,30 @@ SelectionDrag::motion (GdkEvent* event, bool first_move) } } - //now find any tracks that are GROUPED with the tracks we selected - TrackViewList grouped_add = new_selection; - for (TrackViewList::const_iterator i = new_selection.begin(); i != new_selection.end(); ++i) { - RouteTimeAxisView *n = dynamic_cast(*i); - if ( n && n->route()->route_group() && n->route()->route_group()->is_active() && n->route()->route_group()->enabled_property (ARDOUR::Properties::select.property_id) ) { - for (TrackViewList::const_iterator j = all_tracks.begin(); j != all_tracks.end(); ++j) { - RouteTimeAxisView *check = dynamic_cast(*j); - if ( check && (n != check) && (check->route()->route_group() == n->route()->route_group()) ) - grouped_add.push_back (*j); + //now compare our list with the current selection, and add as necessary + //( NOTE: most mouse moves don't change the selection so we can't just SET it for every mouse move; it gets clunky ) + TrackViewList tracks_to_add; + TrackViewList tracks_to_remove; + + if (!first_move) { + for (TrackViewList::const_iterator i = _editor->selection->tracks.begin(); i != _editor->selection->tracks.end(); ++i) { + if (!new_selection.contains (*i) && !_track_selection_at_start.contains (*i)) { + tracks_to_remove.push_back (*i); } } } - //now compare our list with the current selection, and add or remove as necessary - //( NOTE: most mouse moves don't change the selection so we can't just SET it for every mouse move; it gets clunky ) - TrackViewList tracks_to_add; - TrackViewList tracks_to_remove; - for (TrackViewList::const_iterator i = grouped_add.begin(); i != grouped_add.end(); ++i) - if ( !_editor->selection->tracks.contains ( *i ) ) - tracks_to_add.push_back ( *i ); - for (TrackViewList::const_iterator i = _editor->selection->tracks.begin(); i != _editor->selection->tracks.end(); ++i) - if ( !grouped_add.contains ( *i ) ) - tracks_to_remove.push_back ( *i ); - _editor->selection->add(tracks_to_add); - _editor->selection->remove(tracks_to_remove); + for (TrackViewList::const_iterator i = new_selection.begin(); i != new_selection.end(); ++i) { + if (!_editor->selection->tracks.contains (*i)) { + tracks_to_add.push_back (*i); + } + } + _editor->selection->add (tracks_to_add); + + if (!tracks_to_remove.empty()) { + _editor->selection->remove (tracks_to_remove); + } } } break; @@ -5257,10 +5317,7 @@ SelectionDrag::finished (GdkEvent* event, bool movement_occurred) s->request_play_range (&_editor->selection->time, true); } else if (!s->config.get_external_sync()) { if (UIConfiguration::instance().get_follow_edits() && !s->transport_rolling()) { - if (_operation == SelectionEndTrim) - _editor->maybe_locate_with_edit_preroll( _editor->get_selection().time.end_frame()); - else - s->request_locate (_editor->get_selection().time.start()); + s->request_locate (_editor->get_selection().time.start()); } } @@ -5275,6 +5332,13 @@ SelectionDrag::finished (GdkEvent* event, bool movement_occurred) /* just a click, no pointer movement. */ + if (was_double_click()) { + if (UIConfiguration::instance().get_use_double_click_to_zoom_to_selection()) { + _editor->temporal_zoom_selection (Both); + return; + } + } + if (_operation == SelectionExtend) { if (_time_selection_at_start) { framepos_t pos = adjusted_current_frame (event, false); @@ -5480,7 +5544,7 @@ RangeMarkerBarDrag::finished (GdkEvent* event, bool movement_occurred) } newloc = new Location ( *_editor->session(), _editor->temp_location->start(), _editor->temp_location->end(), rangename, (Location::Flags) flags - ); + , _editor->get_grid_music_divisions (event->button.state)); _editor->session()->locations()->add (newloc, true); XMLNode &after = _editor->session()->locations()->get_state(); @@ -5568,6 +5632,7 @@ NoteDrag::NoteDrag (Editor* e, ArdourCanvas::Item* i) , _cumulative_dx (0) , _cumulative_dy (0) , _was_selected (false) + , _copy (false) { DEBUG_TRACE (DEBUG::Drags, "New NoteDrag\n"); @@ -5581,6 +5646,13 @@ void NoteDrag::start_grab (GdkEvent* event, Gdk::Cursor *) { Drag::start_grab (event); + + if (Keyboard::modifier_state_equals (event->button.state, Keyboard::CopyModifier)) { + _copy = true; + } else { + _copy = false; + } + setup_snap_delta (_region->source_beats_to_absolute_frames (_primary->note()->time ())); if (!(_was_selected = _primary->selected())) { @@ -5609,11 +5681,17 @@ NoteDrag::start_grab (GdkEvent* event, Gdk::Cursor *) frameoffset_t NoteDrag::total_dx (const guint state) const { + if (_x_constrained) { + return 0; + } + TempoMap& map (_editor->session()->tempo_map()); + /* dx in frames */ frameoffset_t const dx = _editor->pixel_to_sample (_drags->current_pointer_x() - grab_x()); /* primary note time */ - frameoffset_t const n = _region->source_beats_to_absolute_frames (_primary->note()->time ()); + double const quarter_note_start = _region->region()->quarter_note() - _region->midi_region()->start_beats(); + frameoffset_t const n = map.frame_at_quarter_note (quarter_note_start + _primary->note()->time().to_double()); /* new time of the primary note in session frames */ frameoffset_t st = n + dx + snap_delta (state); @@ -5655,27 +5733,36 @@ NoteDrag::total_dx (const guint state) const int8_t NoteDrag::total_dy () const { - MidiStreamView* msv = _region->midi_stream_view (); + if (_y_constrained) { + return 0; + } + double const y = _region->midi_view()->y_position (); /* new current note */ - uint8_t n = msv->y_to_note (current_pointer_y () - y); + uint8_t n = _region->y_to_note (current_pointer_y () - y); /* clamp */ + MidiStreamView* msv = _region->midi_stream_view (); n = max (msv->lowest_note(), n); n = min (msv->highest_note(), n); /* and work out delta */ - return n - msv->y_to_note (grab_y() - y); + return n - _region->y_to_note (grab_y() - y); } void -NoteDrag::motion (GdkEvent * event, bool) +NoteDrag::motion (GdkEvent * event, bool first_move) { + if (_copy && first_move) { + /* make copies of all the selected notes */ + _primary = _region->copy_selection (); + } + /* Total change in x and y since the start of the drag */ frameoffset_t const dx = total_dx (event->button.state); int8_t const dy = total_dy (); /* Now work out what we have to do to the note canvas items to set this new drag delta */ - double const tdx = _editor->sample_to_pixel (dx) - _cumulative_dx; - double const tdy = -dy * _note_height - _cumulative_dy; + double const tdx = _x_constrained ? 0 : _editor->sample_to_pixel (dx) - _cumulative_dx; + double const tdy = _y_constrained ? 0 : -dy * _note_height - _cumulative_dy; if (tdx || tdy) { _cumulative_dx += tdx; @@ -5683,17 +5770,23 @@ NoteDrag::motion (GdkEvent * event, bool) int8_t note_delta = total_dy(); - _region->move_selection (tdx, tdy, note_delta); + if (tdx || tdy) { + if (_copy) { + _region->move_copies (tdx, tdy, note_delta); + } else { + _region->move_selection (tdx, tdy, note_delta); + } - /* the new note value may be the same as the old one, but we - * don't know what that means because the selection may have - * involved more than one note and we might be doing something - * odd with them. so show the note value anyway, always. - */ + /* the new note value may be the same as the old one, but we + * don't know what that means because the selection may have + * involved more than one note and we might be doing something + * odd with them. so show the note value anyway, always. + */ - uint8_t new_note = min (max (_primary->note()->note() + note_delta, 0), 127); + uint8_t new_note = min (max (_primary->note()->note() + note_delta, 0), 127); - _region->show_verbose_cursor_for_new_note_value (_primary->note(), new_note); + _region->show_verbose_cursor_for_new_note_value (_primary->note(), new_note); + } } } @@ -5742,7 +5835,7 @@ NoteDrag::finished (GdkEvent* ev, bool moved) } } } else { - _region->note_dropped (_primary, total_dx (ev->button.state), total_dy()); + _region->note_dropped (_primary, total_dx (ev->button.state), total_dy(), _copy); } } @@ -6060,6 +6153,9 @@ void PatchChangeDrag::finished (GdkEvent* ev, bool movement_occurred) { if (!movement_occurred) { + if (was_double_click()) { + _region_view->edit_patch_change (_patch_change); + } return; } @@ -6189,13 +6285,12 @@ NoteCreateDrag::~NoteCreateDrag () framecnt_t NoteCreateDrag::grid_frames (framepos_t t) const { - bool success; - Evoral::Beats grid_beats = _editor->get_grid_type_as_beats (success, t); - if (!success) { - grid_beats = Evoral::Beats(1); - } - return _region_view->region_beats_to_region_frames (grid_beats); + const Evoral::Beats grid_beats = _region_view->get_grid_beats (t); + const Evoral::Beats t_beats = _region_view->region_frames_to_region_beats (t); + + return _region_view->region_beats_to_region_frames (t_beats + grid_beats) + - _region_view->region_beats_to_region_frames (t_beats); } void @@ -6204,25 +6299,38 @@ NoteCreateDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor) Drag::start_grab (event, cursor); _drag_rect = new ArdourCanvas::Rectangle (_region_view->get_canvas_group ()); + TempoMap& map (_editor->session()->tempo_map()); - framepos_t pf = _drags->current_pointer_frame (); - framecnt_t const g = grid_frames (pf); + const framepos_t pf = _drags->current_pointer_frame (); + const int32_t divisions = _editor->get_grid_music_divisions (event->button.state); - /* Hack so that we always snap to the note that we are over, instead of snapping - to the next one if we're more than halfway through the one we're over. - */ - if (_editor->snap_mode() == SnapNormal && pf > g / 2) { - pf -= g / 2; + const Evoral::Beats grid_beats = _region_view->get_grid_beats (pf); + + double eqaf = map.exact_qn_at_frame (pf, divisions); + + if (divisions != 0) { + + const double qaf = map.quarter_note_at_frame (pf); + + /* Hack so that we always snap to the note that we are over, instead of snapping + to the next one if we're more than halfway through the one we're over. + */ + + const double rem = eqaf - qaf; + if (rem >= 0.0) { + eqaf -= grid_beats.to_double(); + } } - _note[0] = adjusted_frame (pf, event) - _region_view->region()->position (); - _note[1] = _note[0]; + _note[0] = map.frame_at_quarter_note (eqaf) - _region_view->region()->position(); + /* minimum initial length is grid beats */ + _note[1] = map.frame_at_quarter_note (eqaf + grid_beats.to_double()) - _region_view->region()->position(); - MidiStreamView* sv = _region_view->midi_stream_view (); - double const x = _editor->sample_to_pixel (_note[0]); - double const y = sv->note_to_y (sv->y_to_note (y_to_region (event->button.y))); + double const x0 = _editor->sample_to_pixel (_note[0]); + double const x1 = _editor->sample_to_pixel (_note[1]); + double const y = _region_view->note_to_y (_region_view->y_to_note (y_to_region (event->button.y))); - _drag_rect->set (ArdourCanvas::Rect (x, y, x, y + floor (_region_view->midi_stream_view()->note_height ()))); + _drag_rect->set (ArdourCanvas::Rect (x0, y, x1, y + floor (_region_view->midi_stream_view()->note_height ()))); _drag_rect->set_outline_all (); _drag_rect->set_outline_color (0xffffff99); _drag_rect->set_fill_color (0xffffff66); @@ -6231,7 +6339,29 @@ NoteCreateDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor) void NoteCreateDrag::motion (GdkEvent* event, bool) { - _note[1] = max ((framepos_t)0, adjusted_current_frame (event) - _region_view->region()->position ()); + TempoMap& map (_editor->session()->tempo_map()); + const framepos_t pf = _drags->current_pointer_frame (); + const int32_t divisions = _editor->get_grid_music_divisions (event->button.state); + double eqaf = map.exact_qn_at_frame (pf, divisions); + + if (divisions != 0) { + + const Evoral::Beats grid_beats = _region_view->get_grid_beats (pf); + + const double qaf = map.quarter_note_at_frame (pf); + /* Hack so that we always snap to the note that we are over, instead of snapping + to the next one if we're more than halfway through the one we're over. + */ + + const double rem = eqaf - qaf; + if (rem >= 0.0) { + eqaf -= grid_beats.to_double(); + } + + eqaf += grid_beats.to_double(); + } + _note[1] = max ((framepos_t)0, map.frame_at_quarter_note (eqaf) - _region_view->region()->position ()); + double const x0 = _editor->sample_to_pixel (_note[0]); double const x1 = _editor->sample_to_pixel (_note[1]); _drag_rect->set_x0 (std::min(x0, x1)); @@ -6239,26 +6369,23 @@ NoteCreateDrag::motion (GdkEvent* event, bool) } void -NoteCreateDrag::finished (GdkEvent*, bool had_movement) +NoteCreateDrag::finished (GdkEvent* ev, bool had_movement) { - if (!had_movement) { - return; - } - + /* we create a note even if there was no movement */ framepos_t const start = min (_note[0], _note[1]); - framecnt_t length = (framecnt_t) fabs ((double)(_note[0] - _note[1])); - + framepos_t const start_sess_rel = start + _region_view->region()->position(); + framecnt_t length = max (_editor->pixel_to_sample (1.0), (framecnt_t) fabs ((double)(_note[0] - _note[1]))); framecnt_t const g = grid_frames (start); - Evoral::Beats const one_tick = Evoral::Beats::ticks(1); - if (_editor->snap_mode() == SnapNormal && length < g) { + if (_editor->get_grid_music_divisions (ev->button.state) != 0 && length < g) { length = g; } - Evoral::Beats length_beats = max ( - one_tick, _region_view->region_frames_to_region_beats (length) - one_tick); + TempoMap& map (_editor->session()->tempo_map()); + const double qn_length = map.quarter_notes_between_frames (start_sess_rel, start_sess_rel + length); + Evoral::Beats qn_length_beats = max (Evoral::Beats::ticks(1), Evoral::Beats (qn_length)); - _region_view->create_note_at (start, _drag_rect->y0(), length_beats, false); + _region_view->create_note_at (start, _drag_rect->y0(), qn_length_beats, ev->button.state, false); } double @@ -6275,6 +6402,100 @@ NoteCreateDrag::aborted (bool) } +HitCreateDrag::HitCreateDrag (Editor* e, ArdourCanvas::Item* i, MidiRegionView* rv) + : Drag (e, i) + , _region_view (rv) + , _last_pos (0) + , _last_y (0.0) +{ +} + +HitCreateDrag::~HitCreateDrag () +{ +} + +void +HitCreateDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor) +{ + Drag::start_grab (event, cursor); + + TempoMap& map (_editor->session()->tempo_map()); + + const framepos_t pf = _drags->current_pointer_frame (); + const int32_t divisions = _editor->get_grid_music_divisions (event->button.state); + + const double eqaf = map.exact_qn_at_frame (pf, divisions); + + boost::shared_ptr mr = _region_view->midi_region(); + + if (eqaf >= mr->quarter_note() + mr->length_beats()) { + return; + } + + const framepos_t start = map.frame_at_quarter_note (eqaf) - _region_view->region()->position(); + const double y = _region_view->note_to_y (_region_view->y_to_note (y_to_region (event->button.y))); + + Evoral::Beats length = _region_view->get_grid_beats (pf); + + _region_view->create_note_at (start, y, length, event->button.state, false); + + _last_pos = start; + _last_y = y; +} + +void +HitCreateDrag::motion (GdkEvent* event, bool) +{ + TempoMap& map (_editor->session()->tempo_map()); + + const framepos_t pf = _drags->current_pointer_frame (); + const int32_t divisions = _editor->get_grid_music_divisions (event->button.state); + + if (divisions == 0) { + return; + } + + const double eqaf = map.exact_qn_at_frame (pf, divisions); + const framepos_t start = map.frame_at_quarter_note (eqaf) - _region_view->region()->position (); + const double y = _region_view->note_to_y (_region_view->y_to_note (y_to_region (event->button.y))); + + if (_last_pos == start && y == _last_y) { + return; + } + + Evoral::Beats length = _region_view->get_grid_beats (pf); + + boost::shared_ptr mr = _region_view->midi_region(); + if (eqaf >= mr->quarter_note() + mr->length_beats()) { + return; + } + + _region_view->create_note_at (start, y, length, event->button.state, false); + + _last_pos = start; + _last_y = y; +} + +void +HitCreateDrag::finished (GdkEvent* /* ev */, bool /* had_movement */) +{ + +} + +double +HitCreateDrag::y_to_region (double y) const +{ + double x = 0; + _region_view->get_canvas_group()->canvas_to_item (x, y); + return y; +} + +void +HitCreateDrag::aborted (bool) +{ + // umm.. +} + CrossfadeEdgeDrag::CrossfadeEdgeDrag (Editor* e, AudioRegionView* rv, ArdourCanvas::Item* i, bool start_yn) : Drag (e, i) , arv (rv) @@ -6377,6 +6598,7 @@ RegionCutDrag::RegionCutDrag (Editor* e, ArdourCanvas::Item* item, framepos_t po { line->set_position (pos); line->show (); + line->track_canvas_item().reparent (_editor->_drag_motion_group); } RegionCutDrag::~RegionCutDrag () @@ -6385,20 +6607,28 @@ RegionCutDrag::~RegionCutDrag () } void -RegionCutDrag::motion (GdkEvent*, bool) +RegionCutDrag::start_grab (GdkEvent* event, Gdk::Cursor* c) { - framepos_t where = _drags->current_pointer_frame(); - _editor->snap_to (where); + Drag::start_grab (event, c); + motion (event, false); +} - line->set_position (where); +void +RegionCutDrag::motion (GdkEvent* event, bool) +{ + framepos_t pos = _drags->current_pointer_frame(); + _editor->snap_to_with_modifier (pos, event); + + line->set_position (pos); } void -RegionCutDrag::finished (GdkEvent*, bool) +RegionCutDrag::finished (GdkEvent* event, bool) { _editor->get_track_canvas()->canvas()->re_enter(); framepos_t pos = _drags->current_pointer_frame(); + _editor->snap_to_with_modifier (pos, event); line->hide (); @@ -6408,10 +6638,64 @@ RegionCutDrag::finished (GdkEvent*, bool) return; } - _editor->split_regions_at (pos, rs); + _editor->split_regions_at (pos, rs, _editor->get_grid_music_divisions (event->button.state), + false); } void RegionCutDrag::aborted (bool) { } + +RulerZoomDrag::RulerZoomDrag (Editor* e, ArdourCanvas::Item* item) + : Drag (e, item, true) +{ +} + +void +RulerZoomDrag::start_grab (GdkEvent* event, Gdk::Cursor* c) +{ + Drag::start_grab (event, c); + + framepos_t where = _editor->canvas_event_sample(event); + + _editor->_dragging_playhead = true; + + _editor->playhead_cursor->set_position (where); +} + +void +RulerZoomDrag::motion (GdkEvent* event, bool) +{ + framepos_t where = _editor->canvas_event_sample(event); + + _editor->playhead_cursor->set_position (where); + + const double movement_limit = 20.0; + const double scale = 1.08; + const double y_delta = last_pointer_y() - current_pointer_y(); + + if (y_delta > 0 && y_delta < movement_limit) { + _editor->temporal_zoom_step_mouse_focus_scale (true, scale); + } else if (y_delta < 0 && y_delta > -movement_limit) { + _editor->temporal_zoom_step_mouse_focus_scale (false, scale); + } +} + +void +RulerZoomDrag::finished (GdkEvent*, bool) +{ + _editor->_dragging_playhead = false; + + Session* s = _editor->session (); + if (s) { + s->request_locate (_editor->playhead_cursor->current_frame (), _was_rolling); + _editor->_pending_locate_request = true; + } + +} + +void +RulerZoomDrag::aborted (bool) +{ +}