Try to make new layering stuff play nicely with undo.
authorCarl Hetherington <carl@carlh.net>
Tue, 27 Dec 2011 20:21:00 +0000 (20:21 +0000)
committerCarl Hetherington <carl@carlh.net>
Tue, 27 Dec 2011 20:21:00 +0000 (20:21 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@11097 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/editor.h
gtk2_ardour/editor_ops.cc
gtk2_ardour/region_selection.cc
gtk2_ardour/region_selection.h
libs/ardour/playlist.cc

index 7f84176d61fd617581157e09afd8bf0345592a4c..2b03e210a9c6a29297ea01c3206996a361a78bc8 100644 (file)
@@ -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);
index a07f16b5c8f393479e4f221916962870953167ed..d387f7c0eb1d70516b843dc828e130ce5bcbc538 100644 (file)
@@ -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<boost::shared_ptr<Playlist> > playlists = selection->regions.playlists ();
+       for (set<boost::shared_ptr<Playlist> >::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<Region> 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<boost::shared_ptr<Playlist> >::iterator i = playlists.begin(); i != playlists.end(); ++i) {
+               vector<Command*> 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 */
index 333e2104ad8f49244affffc5883c939f162ad763..8c3a641941851ca8b0fcfbc3f2675814312d31c8 100644 (file)
@@ -274,3 +274,15 @@ RegionSelection::end_frame () const
 
        return e;
 }
+
+/** @return the playlists that the regions in the selection are on */
+set<boost::shared_ptr<Playlist> >
+RegionSelection::playlists () const
+{
+       set<boost::shared_ptr<Playlist> > pl;
+       for (RegionSelection::const_iterator i = begin(); i != end(); ++i) {
+               pl.insert ((*i)->region()->playlist ());
+       }
+
+       return pl;
+}
index fd43e4626fa648689137a88bcf92b5dd4463d7fb..36e40061c1a6b392166bdaec2f6544fc7ddf8084 100644 (file)
 #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<RegionView*>
        void  by_position (std::list<RegionView*>&) const;
        void  by_track (std::list<RegionView*>&) const;
 
+       std::set<boost::shared_ptr<ARDOUR::Playlist> > playlists () const;
+
   private:
        void remove_it (RegionView*);
 
index 1eebafba5adc9d91e02fd2534efeacabb496f535..e5240747aaf432e74641f7cdaa8013dbf5e506d8 100644 (file)
@@ -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.