From f440f91849a807e9026d79c06075bbd15852cbf6 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 27 Dec 2011 20:21:00 +0000 Subject: Try to make new layering stuff play nicely with undo. git-svn-id: svn://localhost/ardour2/branches/3.0@11097 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/editor.h | 9 +++++ gtk2_ardour/editor_ops.cc | 81 +++++++++++++++++++++++++++++++++++++++-- gtk2_ardour/region_selection.cc | 12 ++++++ gtk2_ardour/region_selection.h | 6 +++ libs/ardour/playlist.cc | 12 ++++-- 5 files changed, 113 insertions(+), 7 deletions(-) diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index 7f84176d61..2b03e210a9 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -1099,6 +1099,15 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD void toggle_solo_isolate (); void toggle_mute (); void toggle_region_lock_style (); + + enum LayerOperation { + Raise, + RaiseToTop, + Lower, + LowerToBottom + }; + + void do_layer_operation (LayerOperation); void raise_region (); void raise_region_to_top (); void change_region_layering_order (bool from_context_menu); diff --git a/gtk2_ardour/editor_ops.cc b/gtk2_ardour/editor_ops.cc index a07f16b5c8..d387f7c0eb 100644 --- a/gtk2_ardour/editor_ops.cc +++ b/gtk2_ardour/editor_ops.cc @@ -2133,28 +2133,101 @@ Editor::loop_location (Location& location) } } +void +Editor::do_layer_operation (LayerOperation op) +{ + if (selection->regions.empty ()) { + return; + } + + bool const multiple = selection->regions.size() > 1; + switch (op) { + case Raise: + if (multiple) { + begin_reversible_command (_("raise regions")); + } else { + begin_reversible_command (_("raise region")); + } + break; + + case RaiseToTop: + if (multiple) { + begin_reversible_command (_("raise regions to top")); + } else { + begin_reversible_command (_("raise region to top")); + } + break; + + case Lower: + if (multiple) { + begin_reversible_command (_("lower regions")); + } else { + begin_reversible_command (_("lower region")); + } + break; + + case LowerToBottom: + if (multiple) { + begin_reversible_command (_("lower regions to bottom")); + } else { + begin_reversible_command (_("lower region")); + } + break; + } + + set > playlists = selection->regions.playlists (); + for (set >::iterator i = playlists.begin(); i != playlists.end(); ++i) { + (*i)->clear_owned_changes (); + } + + for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) { + boost::shared_ptr r = (*i)->region (); + switch (op) { + case Raise: + r->raise (); + break; + case RaiseToTop: + r->raise_to_top (); + break; + case Lower: + r->lower (); + break; + case LowerToBottom: + r->lower_to_bottom (); + } + } + + for (set >::iterator i = playlists.begin(); i != playlists.end(); ++i) { + vector cmds; + (*i)->rdiff (cmds); + _session->add_commands (cmds); + } + + commit_reversible_command (); +} + void Editor::raise_region () { - selection->foreach_region (&Region::raise); + do_layer_operation (Raise); } void Editor::raise_region_to_top () { - selection->foreach_region (&Region::raise_to_top); + do_layer_operation (RaiseToTop); } void Editor::lower_region () { - selection->foreach_region (&Region::lower); + do_layer_operation (Lower); } void Editor::lower_region_to_bottom () { - selection->foreach_region (&Region::lower_to_bottom); + do_layer_operation (LowerToBottom); } /** Show the region editor for the selected regions */ diff --git a/gtk2_ardour/region_selection.cc b/gtk2_ardour/region_selection.cc index 333e2104ad..8c3a641941 100644 --- a/gtk2_ardour/region_selection.cc +++ b/gtk2_ardour/region_selection.cc @@ -274,3 +274,15 @@ RegionSelection::end_frame () const return e; } + +/** @return the playlists that the regions in the selection are on */ +set > +RegionSelection::playlists () const +{ + set > pl; + for (RegionSelection::const_iterator i = begin(); i != end(); ++i) { + pl.insert ((*i)->region()->playlist ()); + } + + return pl; +} diff --git a/gtk2_ardour/region_selection.h b/gtk2_ardour/region_selection.h index fd43e4626f..36e40061c1 100644 --- a/gtk2_ardour/region_selection.h +++ b/gtk2_ardour/region_selection.h @@ -25,6 +25,10 @@ #include "pbd/signals.h" #include "ardour/types.h" +namespace ARDOUR { + class Playlist; +} + class RegionView; class TimeAxisView; @@ -57,6 +61,8 @@ class RegionSelection : public std::list void by_position (std::list&) const; void by_track (std::list&) const; + std::set > playlists () const; + private: void remove_it (RegionView*); diff --git a/libs/ardour/playlist.cc b/libs/ardour/playlist.cc index 1eebafba5a..e5240747aa 100644 --- a/libs/ardour/playlist.cc +++ b/libs/ardour/playlist.cc @@ -646,10 +646,14 @@ Playlist::flush_notifications (bool from_undo) RegionsExtended (pending_region_extensions); } - if (!regions_to_relayer.empty ()) { + if (!regions_to_relayer.empty () && !from_undo) { relayer (regions_to_relayer); } + if (pending_layering) { + LayeringChanged (); /* EMIT SIGNAL */ + } + clear_pending (); in_flush = false; @@ -1571,6 +1575,10 @@ Playlist::flush_notifications (bool from_undo) notify_region_start_trimmed (region); } + if (what_changed.contains (Properties::layer)) { + notify_layering_changed (); + } + if (what_changed.contains (our_interests)) { save = true; } @@ -2536,8 +2544,6 @@ Playlist::commit_temporary_layers (TemporaryLayers const & temporary_layers) DEBUG_TRACE (DEBUG::Layering, string_compose ("\t%1 temporary %2 committed %3\n", (*i)->name(), temporary_layers.get (*i), (*i)->layer())); } - - notify_layering_changed (); } /** Relayer a list of regions. -- cgit v1.2.3