From 2d5238d87581bc0ff9dcaaa8aad9e255b5d9c370 Mon Sep 17 00:00:00 2001 From: nick_m Date: Tue, 14 Jun 2016 03:21:52 +1000 Subject: Make some musical operations on music-locked regions operate in beats. - use exact beats to determine frame position. - see comments in tempo.cc for more. - this hasn't been done for split yet, but dragging and trimming are supported. --- gtk2_ardour/editor_drag.cc | 36 ++++++++++++++++++++---------------- gtk2_ardour/editor_drag.h | 8 +++++--- gtk2_ardour/midi_time_axis.cc | 4 ++-- gtk2_ardour/midi_time_axis.h | 2 +- gtk2_ardour/region_view.cc | 4 ++-- gtk2_ardour/region_view.h | 2 +- gtk2_ardour/step_editor.cc | 2 +- 7 files changed, 32 insertions(+), 26 deletions(-) (limited to 'gtk2_ardour') diff --git a/gtk2_ardour/editor_drag.cc b/gtk2_ardour/editor_drag.cc index c5e72fb778..d87388e888 100644 --- a/gtk2_ardour/editor_drag.cc +++ b/gtk2_ardour/editor_drag.cc @@ -510,7 +510,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()); @@ -519,7 +519,7 @@ Drag::add_midi_region (MidiTimeAxisView* view, bool commit) 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); + return view->add_region (grab_frame(), len, commit, sub_num); } return boost::shared_ptr(); @@ -1257,7 +1257,7 @@ RegionMoveDrag::motion (GdkEvent* event, bool first_move) const boost::shared_ptr original = rv->region(); boost::shared_ptr region_copy = RegionFactory::create (original, true); - region_copy->set_position (original->position()); + region_copy->set_position (original->position(), _editor->get_grid_music_divisions (event->button.state)); /* 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. @@ -1364,7 +1364,8 @@ RegionMoveDrag::finished (GdkEvent* ev, bool movement_occurred) finished_copy ( changed_position, changed_tracks, - drag_delta + drag_delta, + ev->button.state ); } else { @@ -1372,7 +1373,8 @@ RegionMoveDrag::finished (GdkEvent* ev, bool movement_occurred) finished_no_copy ( changed_position, changed_tracks, - drag_delta + drag_delta, + ev->button.state ); } @@ -1419,7 +1421,7 @@ RegionMoveDrag::create_destination_time_axis (boost::shared_ptr region, } 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; @@ -1510,7 +1512,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; @@ -1631,7 +1634,7 @@ RegionMoveDrag::finished_no_copy ( playlist->freeze (); } - rv->region()->set_position (where); + rv->region()->set_position (where, _editor->get_grid_music_divisions (ev_state)); _editor->session()->add_command (new StatefulDiffCommand (rv->region())); } @@ -1876,7 +1879,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()); @@ -2303,7 +2306,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) { @@ -2326,10 +2329,10 @@ RegionCreateDrag::motion (GdkEvent* event, bool first_move) } 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(); @@ -2911,7 +2914,9 @@ TrimDrag::motion (GdkEvent* event, bool first_move) 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 + , _editor->get_grid_music_divisions (event->button.state)); + if (changed && _preserve_fade_anchor) { AudioRegionView* arv = dynamic_cast (i->view); if (arv) { @@ -3379,8 +3384,7 @@ 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; } } @@ -4757,7 +4761,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; } } diff --git a/gtk2_ardour/editor_drag.h b/gtk2_ardour/editor_drag.h index 196bd37123..d9ac49cfd4 100644 --- a/gtk2_ardour/editor_drag.h +++ b/gtk2_ardour/editor_drag.h @@ -248,7 +248,7 @@ protected: /* sets snap delta from unsnapped pos */ void setup_snap_delta (framepos_t pos); - boost::shared_ptr add_midi_region (MidiTimeAxisView*, bool commit); + boost::shared_ptr add_midi_region (MidiTimeAxisView*, bool commit, const int32_t& sub_num); void show_verbose_cursor_time (framepos_t); void show_verbose_cursor_duration (framepos_t, framepos_t, double xoffset = 0); @@ -407,13 +407,15 @@ private: void finished_no_copy ( bool const, bool const, - ARDOUR::framecnt_t const + ARDOUR::framecnt_t const, + int32_t const ev_state ); void finished_copy ( bool const, bool const, - ARDOUR::framecnt_t const + ARDOUR::framecnt_t const, + int32_t const ev_state ); RegionView* insert_region_into_playlist ( diff --git a/gtk2_ardour/midi_time_axis.cc b/gtk2_ardour/midi_time_axis.cc index 9f68aa5e55..074f2a115b 100644 --- a/gtk2_ardour/midi_time_axis.cc +++ b/gtk2_ardour/midi_time_axis.cc @@ -1508,7 +1508,7 @@ MidiTimeAxisView::automation_child_menu_item (Evoral::Parameter param) } boost::shared_ptr -MidiTimeAxisView::add_region (framepos_t pos, framecnt_t length, bool commit) +MidiTimeAxisView::add_region (framepos_t pos, framecnt_t length, bool commit, const int32_t& sub_num) { Editor* real_editor = dynamic_cast (&_editor); if (commit) { @@ -1526,7 +1526,7 @@ MidiTimeAxisView::add_region (framepos_t pos, framecnt_t length, bool commit) plist.add (ARDOUR::Properties::name, PBD::basename_nosuffix(src->name())); boost::shared_ptr region = (RegionFactory::create (src, plist)); - + region->set_position (pos, sub_num); playlist()->add_region (region, pos); _session->add_command (new StatefulDiffCommand (playlist())); diff --git a/gtk2_ardour/midi_time_axis.h b/gtk2_ardour/midi_time_axis.h index 6fe77dc8ac..b8e60660b4 100644 --- a/gtk2_ardour/midi_time_axis.h +++ b/gtk2_ardour/midi_time_axis.h @@ -82,7 +82,7 @@ public: void set_height (uint32_t, TrackHeightMode m = OnlySelf); - boost::shared_ptr add_region (ARDOUR::framepos_t, ARDOUR::framecnt_t, bool); + boost::shared_ptr add_region (ARDOUR::framepos_t, ARDOUR::framecnt_t, bool, const int32_t& sub_num); void show_all_automation (bool apply_to_selection = false); void show_existing_automation (bool apply_to_selection = false); diff --git a/gtk2_ardour/region_view.cc b/gtk2_ardour/region_view.cc index a62d000abc..b9648bbbc3 100644 --- a/gtk2_ardour/region_view.cc +++ b/gtk2_ardour/region_view.cc @@ -819,7 +819,7 @@ RegionView::update_coverage_frames (LayerDisplay d) } bool -RegionView::trim_front (framepos_t new_bound, bool no_overlap) +RegionView::trim_front (framepos_t new_bound, bool no_overlap, const int32_t& sub_num) { if (_region->locked()) { return false; @@ -836,7 +836,7 @@ RegionView::trim_front (framepos_t new_bound, bool no_overlap) return false; } - _region->trim_front (speed_bound); + _region->trim_front (speed_bound, sub_num); if (no_overlap) { // Get the next region on the left of this region and shrink/expand it. diff --git a/gtk2_ardour/region_view.h b/gtk2_ardour/region_view.h index f17e37a72d..43608c31d1 100644 --- a/gtk2_ardour/region_view.h +++ b/gtk2_ardour/region_view.h @@ -102,7 +102,7 @@ class RegionView : public TimeAxisViewItem /** Called when a front trim is about to begin */ virtual void trim_front_starting () {} - bool trim_front (framepos_t, bool); + bool trim_front (framepos_t, bool, const int32_t& sub_num); /** Called when a start trim has finished */ virtual void trim_front_ending () {} diff --git a/gtk2_ardour/step_editor.cc b/gtk2_ardour/step_editor.cc index 8afc0ed826..3ea3bb4ccd 100644 --- a/gtk2_ardour/step_editor.cc +++ b/gtk2_ardour/step_editor.cc @@ -122,7 +122,7 @@ StepEditor::prepare_step_edit_region () framecnt_t next_bar_pos = _mtv.session()->tempo_map().frame_at_beat (next_bar_in_beats); framecnt_t len = next_bar_pos - step_edit_insert_position; - step_edit_region = _mtv.add_region (step_edit_insert_position, len, true); + step_edit_region = _mtv.add_region (step_edit_insert_position, len, true, _editor.get_grid_music_divisions (0)); RegionView* rv = _mtv.midi_view()->find_view (step_edit_region); step_edit_region_view = dynamic_cast(rv); -- cgit v1.2.3