From 2def30bda5e38ead362a9fc7af97a1617e799b0b Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 9 Jul 2025 17:02:11 -0600 Subject: [PATCH] Editor::trim_region_front/end should obey ripple mode --- gtk2_ardour/editor_ops.cc | 70 +++++++++++++++++++++++++++++++++------ 1 file changed, 60 insertions(+), 10 deletions(-) diff --git a/gtk2_ardour/editor_ops.cc b/gtk2_ardour/editor_ops.cc index a7a5e9f53d..06a612b7d8 100644 --- a/gtk2_ardour/editor_ops.cc +++ b/gtk2_ardour/editor_ops.cc @@ -3753,22 +3753,72 @@ Editor::trim_region (bool front) begin_reversible_command (front ? _("trim front") : _("trim back")); - for (list::const_iterator i = rs.by_layer().begin(); i != rs.by_layer().end(); ++i) { - if (!(*i)->region()->locked()) { + list rsl (rs.by_layer()); + vector > playlists; - (*i)->region()->clear_changes (); + for (auto & rv : rsl) { - if (front) { - (*i)->region()->trim_front (where); - } else { - (*i)->region()->trim_end (where); - } + std::shared_ptr region (rv->region()); - _session->add_command (new StatefulDiffCommand ((*i)->region())); + if (region->locked()) { + continue; } + + std::shared_ptr playlist = region->playlist(); + + if (!playlist) { + // is this check necessary? + continue; + } + + if (std::find (playlists.begin(), playlists.end(), playlist) == playlists.end()) { + playlists.push_back (playlist); + + playlist->clear_changes (); + playlist->clear_owned_changes (); + playlist->freeze (); + } + + region->clear_changes (); + timepos_t old_pos = region->position(); + timecnt_t delta; + + if (front) { + delta = where.distance (region->position()); + region->trim_front (where); + } else { + delta = region->end().distance (where); + region->trim_end (where); + } + + if (should_ripple()) { + do_ripple (playlist, old_pos, delta, std::shared_ptr(), false); + } + + add_command (new StatefulDiffCommand (region)); } - commit_reversible_command (); + bool commit_result = false; + + for (auto & pl : playlists) { + commit_result = true; + pl->thaw (); + + /* We might have removed regions, which alters other regions' layering_index, + so we need to do a recursive diff here. + */ + + vector cmds; + pl->rdiff (cmds); + add_commands (cmds); + add_command (new StatefulDiffCommand (pl)); + } + + if (commit_result) { + commit_reversible_command (); + } else { + abort_reversible_command (); + } } /** Trim the end of the selected regions to the position of the edit cursor */