Save and not-yet-working restore of StatefulDiffCommands.
authorCarl Hetherington <carl@carlh.net>
Tue, 9 Feb 2010 22:28:46 +0000 (22:28 +0000)
committerCarl Hetherington <carl@carlh.net>
Tue, 9 Feb 2010 22:28:46 +0000 (22:28 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@6669 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/ardour/session.h
libs/ardour/session_command.cc
libs/ardour/session_state.cc
libs/pbd/pbd/stateful_diff_command.h
libs/pbd/stateful_diff_command.cc

index de2dbaa14969240ae28b827472c3239d2c7dd538..f0b71d8019f2927b3d67b0befdeb43e070a4b264 100644 (file)
@@ -728,6 +728,7 @@ class Session : public PBD::StatefulDestructible, public PBD::ScopedConnectionLi
 
        // these commands are implemented in libs/ardour/session_command.cc
        Command* memento_command_factory(XMLNode* n);
+       Command* stateful_diff_command_factory (XMLNode *);
        void register_with_memento_command_factory(PBD::ID, PBD::StatefulDestructible*);
 
        /* clicking */
index 19253cc725887daa3b6030e31e52857cd9d53102..897359b274cfa5d006bf535254934beb6f3c0bc7 100644 (file)
@@ -36,6 +36,7 @@
 #include "pbd/id.h"
 #include "pbd/statefuldestructible.h"
 #include "pbd/failed_constructor.h"
+#include "pbd/stateful_diff_command.h"
 #include "evoral/Curve.hpp"
 
 using namespace PBD;
@@ -132,3 +133,21 @@ Session::memento_command_factory(XMLNode *n)
     return 0 ;
 }
 
+Command *
+Session::stateful_diff_command_factory (XMLNode* n)
+{
+       PBD::ID const id (n->property("obj-id")->value ());
+
+       string const obj_T = n->property ("type-name")->value ();
+       if ((obj_T == typeid (AudioRegion).name() || obj_T == typeid (MidiRegion).name()) && regions.count(id)) {
+               return new StatefulDiffCommand (regions[id].get(), *n);
+       }
+
+       /* we failed */
+       
+       error << string_compose (
+               _("could not reconstitute StatefulDiffCommand from XMLNode. object type = %1 id = %2"), obj_T, id.to_s())
+             << endmsg;
+       
+       return 0;
+}
index fd14094f7f006213f9096e0077ffc8bbcd5fc814..45e35c91fd75a041d8e64facd5ed2a966fd02787 100644 (file)
@@ -2955,6 +2955,10 @@ Session::restore_history (string snapshot_name)
                                        error << string_compose (_("Region command references an unknown region ID=%1"), id.to_s()) << endmsg;
                                }
 
+                       } else if (n->name() == "StatefulDiffCommand") {
+                               if ((c = stateful_diff_command_factory (n))) {
+                                       ut->add_command (c);
+                               }
                        } else {
                                error << string_compose(_("Couldn't figure out how to make a Command out of a %1 XMLNode."), n->name()) << endmsg;
                        }
index b02d7a669ecd8cd78f5d1a52ba30aeb5330deabf..41c0c70f69d332550386759a1db83779a2dd3947 100644 (file)
@@ -30,7 +30,8 @@ class Stateful;
 class StatefulDiffCommand : public Command
 {
 public:
-       StatefulDiffCommand (Stateful* s);
+       StatefulDiffCommand (Stateful *);
+       StatefulDiffCommand (Stateful *, XMLNode const &);
        ~StatefulDiffCommand ();
 
        void operator() ();
index 788a5be0341776c716f0a9d8fd88e52b212171dc..1332cae4ff9720736f5611eed5bdcad209a60aba 100644 (file)
@@ -18,6 +18,7 @@
 */
 
 #include "pbd/stateful_diff_command.h"
+#include "i18n.h"
 
 using namespace std;
 using namespace PBD;
@@ -35,6 +36,13 @@ StatefulDiffCommand::StatefulDiffCommand (Stateful* s)
        _after = p.second;
 }
 
+StatefulDiffCommand::StatefulDiffCommand (Stateful* s, XMLNode const & n)
+       : _object (s)
+{
+       _before = new XMLNode (*n.children().front());
+       _after = new XMLNode (*n.children().back());
+}
+
 
 StatefulDiffCommand::~StatefulDiffCommand ()
 {
@@ -57,5 +65,12 @@ StatefulDiffCommand::undo ()
 XMLNode&
 StatefulDiffCommand::get_state ()
 {
-       /* XXX */
+       XMLNode* node = new XMLNode (X_("StatefulDiffCommand"));
+
+       node->add_property ("obj-id", _object->id().to_s());
+       node->add_property ("type-name", typeid(*_object).name());
+       node->add_child_copy (*_before);
+       node->add_child_copy (*_after);
+
+       return *node;
 }