From 636f1331e8d14dfdb20569b5f4378ef6a1e7036b Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 2 Jun 2021 16:34:13 -0600 Subject: [PATCH] stop using ripple callback API, add Editor::should_ripple() and Editor::do_ripple() to manage rippling --- gtk2_ardour/editor.h | 5 +- gtk2_ardour/editor_audio_import.cc | 8 +- gtk2_ardour/editor_drag.cc | 12 +-- gtk2_ardour/editor_mouse.cc | 2 +- gtk2_ardour/editor_ops.cc | 140 +++++++++++++++++++---------- gtk2_ardour/public_editor.h | 2 +- gtk2_ardour/route_time_axis.cc | 16 ++-- 7 files changed, 119 insertions(+), 66 deletions(-) diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index 2999afd90e..152af1807e 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -583,7 +583,9 @@ public: void edit_tempo_section (ARDOUR::TempoSection*); void edit_meter_section (ARDOUR::MeterSection*); - ARDOUR::Playlist::RippleCallback ripple_callback (bool run_rdiff); + bool should_ripple () const; + void do_ripple (boost::shared_ptr, samplepos_t, samplecnt_t, ARDOUR::RegionList* exclude, bool add_to_command); + void do_ripple (boost::shared_ptr, samplepos_t, samplecnt_t, boost::shared_ptr exclude, bool add_to_command); void add_region_marker (); void clear_region_markers (); @@ -2386,7 +2388,6 @@ private: void radio_reg_sens (Glib::RefPtr action_group, Gtk::RadioAction::Group& radio_group, char const* name, char const* label, sigc::slot slot); void remove_gap_marker_callback (samplepos_t at, samplecnt_t distance); - void _ripple_callback (ARDOUR::Playlist& playlist, samplepos_t, samplecnt_t, bool run_rdiff); friend class Drag; friend class RegionCutDrag; diff --git a/gtk2_ardour/editor_audio_import.cc b/gtk2_ardour/editor_audio_import.cc index 05dbab7203..43588500de 100644 --- a/gtk2_ardour/editor_audio_import.cc +++ b/gtk2_ardour/editor_audio_import.cc @@ -1059,11 +1059,13 @@ Editor::finish_bringing_in_material (boost::shared_ptr region, playlist->clear_changes (); playlist->clear_owned_changes (); playlist->add_region (copy, pos); - if (Config->get_edit_mode() == Ripple) { - playlist->ripple (pos, copy->length(), copy, ripple_callback (true)); + + if (should_ripple()) { + do_ripple (playlist, pos, copy->length(), copy, true); + } else { + playlist->rdiff_and_add_command (_session); } - playlist->rdiff_and_add_command (_session); break; } diff --git a/gtk2_ardour/editor_drag.cc b/gtk2_ardour/editor_drag.cc index a37761fc53..cb0bcd7f4b 100644 --- a/gtk2_ardour/editor_drag.cc +++ b/gtk2_ardour/editor_drag.cc @@ -2184,12 +2184,12 @@ RegionInsertDrag::finished (GdkEvent * event, bool) playlist->add_region (_primary->region (), _last_position.sample, 1.0, false, _last_position.division); - if (Config->get_edit_mode() == Ripple) { - playlist->ripple (_last_position.sample, _primary->region()->length(), _primary->region(), _editor->ripple_callback (true)); + if (_editor->should_ripple()) { + _editor->do_ripple (playlist,_last_position.sample, _primary->region()->length(), _primary->region(), true); + } else { + playlist->rdiff_and_add_command (_editor->session()); } - playlist->rdiff_and_add_command (_editor->session()); - _editor->commit_reversible_command (); delete _primary; @@ -2486,7 +2486,7 @@ RegionRippleDrag::motion (GdkEvent* event, bool first_move) remove_unselected_from_views (prev_amount, false); // ripple previous playlist according to the regions that have been removed onto the new playlist - prev_tav->playlist()->ripple(prev_position, -selection_length, exclude, _editor->ripple_callback (false)); + prev_tav->playlist()->ripple(prev_position, -selection_length, exclude); prev_amount = 0; // move just the selected regions @@ -2495,7 +2495,7 @@ RegionRippleDrag::motion (GdkEvent* event, bool first_move) // ensure that the ripple operation on the new playlist inserts selection_length time adjust = selection_length; // ripple the new current playlist - tv->playlist()->ripple (where, amount+adjust, exclude, _editor->ripple_callback (false)); + tv->playlist()->ripple (where, amount+adjust, exclude); // add regions after point where drag entered this track to subsequent ripples add_all_after_to_views (tv, where, _editor->selection->regions, true); diff --git a/gtk2_ardour/editor_mouse.cc b/gtk2_ardour/editor_mouse.cc index ad9ec54807..a964d2bcec 100644 --- a/gtk2_ardour/editor_mouse.cc +++ b/gtk2_ardour/editor_mouse.cc @@ -2614,7 +2614,7 @@ Editor::add_region_brush_drag (ArdourCanvas::Item* item, GdkEvent*, RegionView* return; } - if (Config->get_edit_mode() == Splice || Config->get_edit_mode() == Ripple) { + if (Config->get_edit_mode() == Splice || should_ripple()) { return; } diff --git a/gtk2_ardour/editor_ops.cc b/gtk2_ardour/editor_ops.cc index 5f07f248ae..2bf5fb8645 100644 --- a/gtk2_ardour/editor_ops.cc +++ b/gtk2_ardour/editor_ops.cc @@ -2625,12 +2625,17 @@ Editor::insert_source_list_selection (float times) begin_reversible_command (_("insert region")); playlist->clear_changes (); playlist->clear_owned_changes (); - playlist->add_region ((RegionFactory::create (region, true)), get_preferred_edit_position(), times); + + playlist->add_region ((RegionFactory::create (region, true)), get_preferred_edit_position(), times, _session->config.get_layered_record_mode()); //ToDo: insert_mode ? if (Config->get_edit_mode() == Ripple) { playlist->ripple (get_preferred_edit_position(), region->length() * times, boost::shared_ptr(), ripple_callback (true)); } - playlist->rdiff_and_add_command (_session); + if (should_ripple()) { + do_ripple (playlist, get_preferred_edit_position(), region->length() * times, boost::shared_ptr(), true); + } else { + playlist->rdiff_and_add_command (_session); + } commit_reversible_command (); } @@ -4581,11 +4586,12 @@ Editor::remove_clicked_region () playlist->clear_owned_changes (); playlist->remove_region (region); - if (Config->get_edit_mode() == Ripple) { - playlist->ripple (region->position(), - region->length(), boost::shared_ptr(), ripple_callback (true)); + if (should_ripple()) { + do_ripple (playlist, region->position(), - region->length(), boost::shared_ptr(), true); + } else { + playlist->rdiff_and_add_command (_session); } - playlist->rdiff_and_add_command (_session); commit_reversible_command (); } @@ -4663,8 +4669,9 @@ Editor::remove_selected_regions () playlist->clear_owned_changes (); playlist->freeze (); playlist->remove_region (*rl); - if (Config->get_edit_mode() == Ripple) { - playlist->ripple ((*rl)->position(), -(*rl)->length(), boost::shared_ptr(), ripple_callback (false)); + + if (should_ripple()) { + do_ripple (playlist, (*rl)->position(), -(*rl)->length(), boost::shared_ptr(), false); } } @@ -4804,8 +4811,8 @@ Editor::cut_copy_regions (CutCopyOp op, RegionSelection& rs) switch (op) { case Delete: pl->remove_region (r); - if (Config->get_edit_mode() == Ripple) { - pl->ripple (r->position(), -r->length(), boost::shared_ptr(), ripple_callback (false)); + if (should_ripple()) { + do_ripple (pl, r->position(), -r->length(), boost::shared_ptr(), false); } break; @@ -4813,8 +4820,8 @@ Editor::cut_copy_regions (CutCopyOp op, RegionSelection& rs) _xx = RegionFactory::create (r, false); npl->add_region (_xx, r->position() - first_position); pl->remove_region (r); - if (Config->get_edit_mode() == Ripple) { - pl->ripple (r->position(), -r->length(), boost::shared_ptr(), ripple_callback (false)); + if (should_ripple()) { + do_ripple (pl, r->position(), -r->length(), boost::shared_ptr(), false); } break; @@ -4825,8 +4832,8 @@ Editor::cut_copy_regions (CutCopyOp op, RegionSelection& rs) case Clear: pl->remove_region (r); - if (Config->get_edit_mode() == Ripple) { - pl->ripple (r->position(), -r->length(), boost::shared_ptr(), ripple_callback (false)); + if (should_ripple()) { + do_ripple (pl, r->position(), -r->length(), boost::shared_ptr(), false); } break; } @@ -5052,7 +5059,7 @@ Editor::duplicate_some_regions (RegionSelection& regions, float times) /* ripple first so that we don't move the duplicates that will be added */ - if (Config->get_edit_mode() == Ripple) { + if (should_ripple()) { /* convert RegionSelection into RegionList so that we can pass it to ripple and exclude the regions we will duplicate */ @@ -5069,7 +5076,7 @@ Editor::duplicate_some_regions (RegionSelection& regions, float times) } for (set >::iterator p = playlists.begin(); p != playlists.end(); ++p) { - (*p)->ripple (start_sample, span * times, &exclude, ripple_callback (false)); + do_ripple ((*p), start_sample, span * times, &exclude, false); } } @@ -5085,7 +5092,7 @@ Editor::duplicate_some_regions (RegionSelection& regions, float times) samplepos_t const position = end_sample + (r->first_sample() - start_sample + 1); playlist = (*i)->region()->playlist(); - if (Config->get_edit_mode() != Ripple) { + if (!should_ripple()) { if (playlists.insert (playlist).second) { playlist->clear_changes (); playlist->clear_owned_changes (); @@ -5100,10 +5107,7 @@ Editor::duplicate_some_regions (RegionSelection& regions, float times) } for (set >::iterator p = playlists.begin(); p != playlists.end(); ++p) { - _session->add_command (new StatefulDiffCommand (*p)); - vector cmds; - (*p)->rdiff (cmds); - _session->add_commands (cmds); + (*p)->rdiff_and_add_command (_session); } if (!foo.empty()) { @@ -9168,10 +9172,7 @@ Editor::remove_gaps (samplecnt_t gap_threshold, samplecnt_t leave_gap, bool mark (*i)->remove_gaps (gap_threshold, leave_gap, callback); } - vector cmds; - (*i)->rdiff (cmds); - _session->add_commands (cmds); - _session->add_command (new StatefulDiffCommand (*i)); + (*i)->rdiff_and_add_command (_session); } if (in_command) { @@ -9185,41 +9186,90 @@ Editor::remove_gaps (samplecnt_t gap_threshold, samplecnt_t leave_gap, bool mark delete locations_before; } } + + cerr << "--- rc\n"; } -ARDOUR::Playlist::RippleCallback -Editor::ripple_callback (bool run_rdiff) +bool +Editor::should_ripple () const { - return boost::bind (&Editor::_ripple_callback, this, _1, _2, _3, run_rdiff); + return (Config->get_edit_mode() == Ripple || + Config->get_edit_mode() == RippleAll); } void -Editor::_ripple_callback (Playlist& playlist, samplepos_t at, samplecnt_t distance, bool run_rdiff) +Editor::do_ripple (boost::shared_ptr target_playlist, samplepos_t at, samplecnt_t distance, boost::shared_ptr exclude, bool add_to_command) { - if (!_session) { - return; + RegionList el; + if (exclude) { + el.push_back (exclude); + } + do_ripple (target_playlist, at, distance, &el, add_to_command); +} + +void +Editor::do_ripple (boost::shared_ptr target_playlist, samplepos_t at, samplecnt_t distance, RegionList* exclude, bool add_to_command) +{ + typedef std::set > UniquePlaylists; + UniquePlaylists playlists; + + playlists.insert (target_playlist); + + if (Config->get_edit_mode() == RippleAll) { + + TrackViewList ts = track_views.filter_to_unique_playlists (); + boost::shared_ptr pl; + + for (TrackSelection::iterator x = ts.begin(); x != ts.end(); ++x) { + if ((pl = (*x)->playlist()) == 0) { + continue; + } + playlists.insert (pl); + } } - /* XXX if ripple-all, figure out what else to ripple, and do it here, - * calling rdiff_and_add_command() for each affected playlist if - * run_rdiff is true - */ + if (add_to_command) { + for (UniquePlaylists::iterator p = playlists.begin(); p != playlists.end(); ++p) { - TrackViewList ts = track_views.filter_to_unique_playlists (); - boost::shared_ptr pl; - Playlist::RippleCallback null_callback; + (*p)->clear_changes (); + (*p)->clear_owned_changes (); + } + } + for (UniquePlaylists::iterator p = playlists.begin(); p != playlists.end(); ++p) { + (*p)->freeze (); + } - for (TrackSelection::iterator x = ts.begin(); x != ts.end(); ++x) { - if ((pl = (*x)->playlist()) == 0) { - continue; + for (UniquePlaylists::iterator p = playlists.begin(); p != playlists.end(); ++p) { + + /* exclude list is only for the target */ + + if ((*p) == target_playlist) { + + (*p)->clear_changes (); + (*p)->clear_owned_changes (); + + (*p)->ripple (at, distance, exclude); + + /* caller may put the target playlist into the undo + * history, so only do this if asked + */ + + if (add_to_command) { + (*p)->rdiff_and_add_command (_session); + } + } else { + /* all other playlists: do the ripple, and save to undo/redo */ + + (*p)->clear_changes (); + (*p)->clear_owned_changes (); + (*p)->ripple (at, distance, 0); + (*p)->rdiff_and_add_command (_session); } - if (pl.get() == &playlist) { - continue; - } + } - pl->ripple (at, distance, 0, null_callback); - pl->rdiff_and_add_command (_session); + for (UniquePlaylists::iterator p = playlists.begin(); p != playlists.end(); ++p) { + (*p)->thaw (); } } diff --git a/gtk2_ardour/public_editor.h b/gtk2_ardour/public_editor.h index 168ffd7f32..a6027b953b 100644 --- a/gtk2_ardour/public_editor.h +++ b/gtk2_ardour/public_editor.h @@ -517,7 +517,7 @@ public: virtual void edit_tempo_section (ARDOUR::TempoSection*) = 0; virtual void edit_meter_section (ARDOUR::MeterSection*) = 0; - virtual ARDOUR::Playlist::RippleCallback ripple_callback (bool run_rdiff) = 0; + virtual bool should_ripple () const = 0; /// Singleton instance, set up by Editor::Editor() diff --git a/gtk2_ardour/route_time_axis.cc b/gtk2_ardour/route_time_axis.cc index 511285d906..1935df90c1 100644 --- a/gtk2_ardour/route_time_axis.cc +++ b/gtk2_ardour/route_time_axis.cc @@ -1288,8 +1288,8 @@ RouteTimeAxisView::cut_copy_clear (Selection& selection, CutCopyOp op) switch (op) { case Delete: if (playlist->cut (time) != 0) { - if (Config->get_edit_mode() == Ripple) { - playlist->ripple (time.start(), -time.length(), 0, _editor.ripple_callback (true)); + if (_editor.should_ripple()) { + playlist->ripple (time.start(), -time.length(), 0); } playlist->rdiff_and_add_command (_session); } @@ -1298,8 +1298,8 @@ RouteTimeAxisView::cut_copy_clear (Selection& selection, CutCopyOp op) case Cut: if ((what_we_got = playlist->cut (time)) != 0) { _editor.get_cut_buffer().add (what_we_got); - if (Config->get_edit_mode() == Ripple) { - playlist->ripple (time.start(), -time.length(), 0, _editor.ripple_callback (true)); + if (_editor.should_ripple()) { + playlist->ripple (time.start(), -time.length(), 0); } playlist->rdiff_and_add_command (_session); } @@ -1312,8 +1312,8 @@ RouteTimeAxisView::cut_copy_clear (Selection& selection, CutCopyOp op) case Clear: if ((what_we_got = playlist->cut (time)) != 0) { - if (Config->get_edit_mode() == Ripple) { - playlist->ripple (time.start(), -time.length(), 0, _editor.ripple_callback (true)); + if (_editor.should_ripple()) { + playlist->ripple (time.start(), -time.length(), 0); } playlist->rdiff_and_add_command (_session); what_we_got->release (); @@ -1347,10 +1347,10 @@ RouteTimeAxisView::paste (samplepos_t pos, const Selection& selection, PasteCont pl->clear_changes (); pl->clear_owned_changes (); - if (Config->get_edit_mode() == Ripple) { + if (_editor.should_ripple()) { std::pair extent = (*p)->get_extent_with_endspace(); samplecnt_t amount = extent.second - extent.first; - pl->ripple(pos, amount * ctx.times, boost::shared_ptr(), _editor.ripple_callback (false)); + pl->ripple(pos, amount * ctx.times, boost::shared_ptr()); } pl->paste (*p, pos, ctx.times, sub_num);