From 12b9571b8007238a365324238e42721ab994853f Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 9 Feb 2010 22:28:46 +0000 Subject: Save and not-yet-working restore of StatefulDiffCommands. git-svn-id: svn://localhost/ardour2/branches/3.0@6669 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/ardour/ardour/session.h | 1 + libs/ardour/session_command.cc | 19 +++++++++++++++++++ libs/ardour/session_state.cc | 4 ++++ libs/pbd/pbd/stateful_diff_command.h | 3 ++- libs/pbd/stateful_diff_command.cc | 17 ++++++++++++++++- 5 files changed, 42 insertions(+), 2 deletions(-) diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index de2dbaa149..f0b71d8019 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -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 */ diff --git a/libs/ardour/session_command.cc b/libs/ardour/session_command.cc index 19253cc725..897359b274 100644 --- a/libs/ardour/session_command.cc +++ b/libs/ardour/session_command.cc @@ -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; +} diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index fd14094f7f..45e35c91fd 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -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; } diff --git a/libs/pbd/pbd/stateful_diff_command.h b/libs/pbd/pbd/stateful_diff_command.h index b02d7a669e..41c0c70f69 100644 --- a/libs/pbd/pbd/stateful_diff_command.h +++ b/libs/pbd/pbd/stateful_diff_command.h @@ -30,7 +30,8 @@ class Stateful; class StatefulDiffCommand : public Command { public: - StatefulDiffCommand (Stateful* s); + StatefulDiffCommand (Stateful *); + StatefulDiffCommand (Stateful *, XMLNode const &); ~StatefulDiffCommand (); void operator() (); diff --git a/libs/pbd/stateful_diff_command.cc b/libs/pbd/stateful_diff_command.cc index 788a5be034..1332cae4ff 100644 --- a/libs/pbd/stateful_diff_command.cc +++ b/libs/pbd/stateful_diff_command.cc @@ -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; } -- cgit v1.2.3