diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index af0b6161dd..495ef71fc9 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -583,6 +583,8 @@ public: void edit_tempo_section (ARDOUR::TempoSection*); void edit_meter_section (ARDOUR::MeterSection*); + ARDOUR::Playlist::RippleCallback ripple_callback (bool run_rdiff); + void add_region_marker (); void clear_region_markers (); void remove_region_marker (ARDOUR::CueMarker&); @@ -2384,6 +2386,7 @@ 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, 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 9058ec8e2b..05dbab7203 100644 --- a/gtk2_ardour/editor_audio_import.cc +++ b/gtk2_ardour/editor_audio_import.cc @@ -1060,15 +1060,10 @@ Editor::finish_bringing_in_material (boost::shared_ptr region, playlist->clear_owned_changes (); playlist->add_region (copy, pos); if (Config->get_edit_mode() == Ripple) { - playlist->ripple (pos, copy->length(), copy); - - /* recusive diff of rippled regions */ - vector cmds; - playlist->rdiff (cmds); - _session->add_commands (cmds); + playlist->ripple (pos, copy->length(), copy, ripple_callback (true)); } - _session->add_command (new StatefulDiffCommand (playlist)); + playlist->rdiff_and_add_command (_session); break; } diff --git a/gtk2_ardour/editor_drag.cc b/gtk2_ardour/editor_drag.cc index 1e5b1ed8fc..a37761fc53 100644 --- a/gtk2_ardour/editor_drag.cc +++ b/gtk2_ardour/editor_drag.cc @@ -2185,15 +2185,11 @@ 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()); - - /* recusive diff of rippled regions */ - vector cmds; - playlist->rdiff (cmds); - _editor->session()->add_commands (cmds); + playlist->ripple (_last_position.sample, _primary->region()->length(), _primary->region(), _editor->ripple_callback (true)); } - _editor->session()->add_command (new StatefulDiffCommand (playlist)); + playlist->rdiff_and_add_command (_editor->session()); + _editor->commit_reversible_command (); delete _primary; @@ -2490,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); + prev_tav->playlist()->ripple(prev_position, -selection_length, exclude, _editor->ripple_callback (false)); prev_amount = 0; // move just the selected regions @@ -2499,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); + tv->playlist()->ripple (where, amount+adjust, exclude, _editor->ripple_callback (false)); // 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_ops.cc b/gtk2_ardour/editor_ops.cc index b132383aab..81469c1a65 100644 --- a/gtk2_ardour/editor_ops.cc +++ b/gtk2_ardour/editor_ops.cc @@ -2627,14 +2627,11 @@ Editor::insert_source_list_selection (float times) playlist->clear_owned_changes (); playlist->add_region ((RegionFactory::create (region, true)), get_preferred_edit_position(), times); if (Config->get_edit_mode() == Ripple) { - playlist->ripple (get_preferred_edit_position(), region->length() * times, boost::shared_ptr()); - /* recusive diff of rippled regions */ - vector cmds; - playlist->rdiff (cmds); - _session->add_commands (cmds); + playlist->ripple (get_preferred_edit_position(), region->length() * times, boost::shared_ptr(), ripple_callback (true)); } - _session->add_command(new StatefulDiffCommand (playlist)); + playlist->rdiff_and_add_command (_session); + commit_reversible_command (); } @@ -4585,17 +4582,10 @@ Editor::remove_clicked_region () playlist->remove_region (region); if (Config->get_edit_mode() == Ripple) { - playlist->ripple (region->position(), - region->length(), boost::shared_ptr()); + playlist->ripple (region->position(), - region->length(), boost::shared_ptr(), ripple_callback (true)); } - /* We might have removed regions, which alters other regions' layering_index, - so we need to do a recursive diff here. - */ - vector cmds; - playlist->rdiff (cmds); - _session->add_commands (cmds); - - _session->add_command(new StatefulDiffCommand (playlist)); + playlist->rdiff_and_add_command (_session); commit_reversible_command (); } @@ -4674,7 +4664,7 @@ Editor::remove_selected_regions () playlist->freeze (); playlist->remove_region (*rl); if (Config->get_edit_mode() == Ripple) { - playlist->ripple ((*rl)->position(), -(*rl)->length(), boost::shared_ptr()); + playlist->ripple ((*rl)->position(), -(*rl)->length(), boost::shared_ptr(), ripple_callback (false)); } } @@ -4815,7 +4805,7 @@ Editor::cut_copy_regions (CutCopyOp op, RegionSelection& rs) case Delete: pl->remove_region (r); if (Config->get_edit_mode() == Ripple) { - pl->ripple (r->position(), -r->length(), boost::shared_ptr()); + pl->ripple (r->position(), -r->length(), boost::shared_ptr(), ripple_callback (false)); } break; @@ -4824,7 +4814,7 @@ Editor::cut_copy_regions (CutCopyOp op, RegionSelection& rs) 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()); + pl->ripple (r->position(), -r->length(), boost::shared_ptr(), ripple_callback (false)); } break; @@ -4836,7 +4826,7 @@ 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()); + pl->ripple (r->position(), -r->length(), boost::shared_ptr(), ripple_callback (false)); } break; } @@ -4874,11 +4864,8 @@ Editor::cut_copy_regions (CutCopyOp op, RegionSelection& rs) /* 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); - _session->add_commands (cmds); - _session->add_command (new StatefulDiffCommand (*pl)); + (*pl)->rdiff_and_add_command (_session); } } @@ -5082,7 +5069,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); + (*p)->ripple (start_sample, span * times, &exclude, ripple_callback (false)); } } @@ -9199,3 +9186,22 @@ Editor::remove_gaps (samplecnt_t gap_threshold, samplecnt_t leave_gap, bool mark } } } + +ARDOUR::Playlist::RippleCallback +Editor::ripple_callback (bool run_rdiff) +{ + return boost::bind (&Editor::_ripple_callback, this, _1, run_rdiff); +} + +void +Editor::_ripple_callback (Playlist& playlist, bool run_rdiff) +{ + if (!_session) { + return; + } + + /* 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 + */ +} diff --git a/gtk2_ardour/public_editor.h b/gtk2_ardour/public_editor.h index 374c8ab696..168ffd7f32 100644 --- a/gtk2_ardour/public_editor.h +++ b/gtk2_ardour/public_editor.h @@ -517,6 +517,8 @@ 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; + /// Singleton instance, set up by Editor::Editor() static PublicEditor* _instance; diff --git a/gtk2_ardour/route_time_axis.cc b/gtk2_ardour/route_time_axis.cc index f833d9dd02..511285d906 100644 --- a/gtk2_ardour/route_time_axis.cc +++ b/gtk2_ardour/route_time_axis.cc @@ -1289,15 +1289,9 @@ RouteTimeAxisView::cut_copy_clear (Selection& selection, CutCopyOp op) case Delete: if (playlist->cut (time) != 0) { if (Config->get_edit_mode() == Ripple) { - playlist->ripple(time.start(), -time.length(), NULL); + playlist->ripple (time.start(), -time.length(), 0, _editor.ripple_callback (true)); } - // no need to exclude any regions from rippling here - - vector cmds; - playlist->rdiff (cmds); - _session->add_commands (cmds); - - _session->add_command (new StatefulDiffCommand (playlist)); + playlist->rdiff_and_add_command (_session); } break; @@ -1305,15 +1299,9 @@ RouteTimeAxisView::cut_copy_clear (Selection& selection, CutCopyOp op) 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(), NULL); + playlist->ripple (time.start(), -time.length(), 0, _editor.ripple_callback (true)); } - // no need to exclude any regions from rippling here - - vector cmds; - playlist->rdiff (cmds); - _session->add_commands (cmds); - - _session->add_command (new StatefulDiffCommand (playlist)); + playlist->rdiff_and_add_command (_session); } break; case Copy: @@ -1325,14 +1313,9 @@ 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(), NULL); + playlist->ripple (time.start(), -time.length(), 0, _editor.ripple_callback (true)); } - // no need to exclude any regions from rippling here - - vector cmds; - playlist->rdiff (cmds); - _session->add_commands (cmds); - _session->add_command (new StatefulDiffCommand (playlist)); + playlist->rdiff_and_add_command (_session); what_we_got->release (); } break; @@ -1367,7 +1350,7 @@ RouteTimeAxisView::paste (samplepos_t pos, const Selection& selection, PasteCont if (Config->get_edit_mode() == 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()); + pl->ripple(pos, amount * ctx.times, boost::shared_ptr(), _editor.ripple_callback (false)); } pl->paste (*p, pos, ctx.times, sub_num);