Fix restoration of MementoCommand<Crossfade>. Fixes #3418.
authorCarl Hetherington <carl@carlh.net>
Tue, 14 Sep 2010 00:41:53 +0000 (00:41 +0000)
committerCarl Hetherington <carl@carlh.net>
Tue, 14 Sep 2010 00:41:53 +0000 (00:41 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@7771 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/ardour/audioplaylist.h
libs/ardour/ardour/playlist.h
libs/ardour/ardour/session_playlists.h
libs/ardour/audio_playlist.cc
libs/ardour/crossfade.cc
libs/ardour/session_command.cc
libs/ardour/session_playlists.cc

index 39a19d8ed1fb3839d13053376e7a17f958a4e93a..edf5008283a74cde03dea012cc8708f3b9201756 100644 (file)
@@ -91,6 +91,8 @@ public:
 
        void update (const CrossfadeListProperty::ChangeRecord &);
 
+       boost::shared_ptr<Crossfade> find_crossfade (const PBD::ID &) const;
+       
     protected:
 
        /* playlist "callbacks" */
index feea056ac3fed1c1eb070c51addda2a5c7a380b8..67638cf15eb9b00d200456240b89fae893448c58 100644 (file)
@@ -50,6 +50,7 @@ namespace ARDOUR  {
 class Session;
 class Region;
 class Playlist;
+class Crossfade;       
 
 namespace Properties {
         /* fake the type, since regions are handled by SequenceProperty which doesn't
@@ -210,6 +211,10 @@ public:
 
        void set_explicit_relayering (bool e);
 
+       virtual boost::shared_ptr<Crossfade> find_crossfade (const PBD::ID &) const {
+               return boost::shared_ptr<Crossfade> ();
+       }
+
   protected:
        friend class Session;
 
index 1c83a312a53782b00d2b6fe140610493f9a9ab91..4ca67bdee8b7b478e13982feef1760e4c7843727 100644 (file)
@@ -41,6 +41,7 @@ class Playlist;
 class Region;
 class Source;
 class Session;
+class Crossfade;       
        
 class SessionPlaylists : public PBD::ScopedConnectionList
 {
@@ -54,6 +55,7 @@ public:
        void get (std::vector<boost::shared_ptr<Playlist> >&);
        void unassigned (std::list<boost::shared_ptr<Playlist> > & list);
         void destroy_region (boost::shared_ptr<Region>);
+       boost::shared_ptr<Crossfade> find_crossfade (const PBD::ID &);
 
 private:
        friend class Session;
index 5019935d5d0802587dae7b4e91c077f2b06855d9..9c3bce4196eb39b9560afa27e343c3a584fb45b3 100644 (file)
@@ -875,3 +875,18 @@ AudioPlaylist::update (const CrossfadeListProperty::ChangeRecord& change)
 
        /* don't remove crossfades here; they will be dealt with by the dependency code */
 }
+
+boost::shared_ptr<Crossfade>
+AudioPlaylist::find_crossfade (const PBD::ID& id) const
+{
+       Crossfades::const_iterator i = _crossfades.begin ();
+       while (i != _crossfades.end() && (*i)->id() != id) {
+               ++i;
+       }
+
+       if (i == _crossfades.end()) {
+               return boost::shared_ptr<Crossfade> ();
+       }
+
+       return *i;
+}
index 67ccea937182d4953fc6017454f554a9a1fc6cd0..6b0c0a9560d3248f38d1893364a6c521b3da88f8 100644 (file)
@@ -717,6 +717,8 @@ Crossfade::get_state ()
        char buf[64];
        LocaleGuard lg (X_("POSIX"));
 
+       id().print (buf, sizeof (buf));
+       node->add_property ("id", buf);
        _out->id().print (buf, sizeof (buf));
        node->add_property ("out", buf);
        _in->id().print (buf, sizeof (buf));
@@ -774,6 +776,10 @@ Crossfade::set_state (const XMLNode& node, int /*version*/)
        PropertyChange what_changed;
        framepos_t val;
 
+       if ((prop = node.property (X_("id")))) {
+               _id = prop->value();
+       }
+
        if ((prop = node.property ("position")) != 0) {
                sscanf (prop->value().c_str(), "%" PRId64, &val);
                if (val != _position) {
index 8d3ce793bcf6eb65c74b0b89144f34bf798b29f1..17c7d559d4795bf25efbf1fc882c90700665318b 100644 (file)
@@ -34,6 +34,7 @@
 #include "ardour/session_playlists.h"
 #include "ardour/region_factory.h"
 #include "ardour/midi_automation_list_binder.h"
+#include "ardour/crossfade.h"
 #include "pbd/error.h"
 #include "pbd/id.h"
 #include "pbd/statefuldestructible.h"
@@ -140,7 +141,15 @@ Session::memento_command_factory(XMLNode *n)
            }
            
            cerr << "Alist not found\n";
-           
+
+    } else if (obj_T == "ARDOUR::Crossfade") {
+           boost::shared_ptr<Crossfade> c = playlists->find_crossfade (id);
+           if (c) {
+                   return new MementoCommand<Crossfade> (*c.get(), before, after);
+           } else {
+                   error << string_compose (X_("Crossfade %1 not found in session"), id) << endmsg;
+           }
+
     } else if (registry.count(id)) { // For Editor and AutomationLine which are off-limits herea
            return new MementoCommand<PBD::StatefulDestructible>(*registry[id], before, after);
     }
index 38c6744d06c2864aef3b59f4ad83f584c009551c..b54faba97ed2f60721590d2e71efe47bb77dedbc 100644 (file)
@@ -390,3 +390,26 @@ SessionPlaylists::XMLPlaylistFactory (Session& session, const XMLNode& node)
        }
 }
 
+boost::shared_ptr<Crossfade>
+SessionPlaylists::find_crossfade (const PBD::ID& id)
+{
+       Glib::Mutex::Lock lm (lock);
+
+       boost::shared_ptr<Crossfade> c;
+       
+       for (List::iterator i = playlists.begin(); i != playlists.end(); ++i) {
+               c = (*i)->find_crossfade (id);
+               if (c) {
+                       return c;
+               }
+       }
+
+       for (List::iterator i = unused_playlists.begin(); i != unused_playlists.end(); ++i) {
+               c = (*i)->find_crossfade (id);
+               if (c) {
+                       return c;
+               }
+       }
+
+       return boost::shared_ptr<Crossfade> ();
+}