From 27c98adda9c84af4e93c761e25c0e07c30484b10 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Fri, 27 Nov 2020 14:29:00 -0700 Subject: [PATCH] alter API for MementoCommandBinder to allow future flexibility --- .../ardour/midi_automation_list_binder.h | 5 ++- libs/ardour/midi_automation_list_binder.cc | 31 +++++++++++++++++-- libs/pbd/pbd/memento_command.h | 18 +++++------ 3 files changed, 41 insertions(+), 13 deletions(-) diff --git a/libs/ardour/ardour/midi_automation_list_binder.h b/libs/ardour/ardour/midi_automation_list_binder.h index f07247e5b6..8b8cabf4f6 100644 --- a/libs/ardour/ardour/midi_automation_list_binder.h +++ b/libs/ardour/ardour/midi_automation_list_binder.h @@ -35,7 +35,10 @@ public: MidiAutomationListBinder (boost::shared_ptr, Evoral::Parameter); MidiAutomationListBinder (XMLNode *, ARDOUR::Session::SourceMap const &); - ARDOUR::AutomationList* get () const; + void set_state (XMLNode const & node , int version) const; + XMLNode& get_state () const; + std::string type_name() const; + void add_state (XMLNode *); private: diff --git a/libs/ardour/midi_automation_list_binder.cc b/libs/ardour/midi_automation_list_binder.cc index 54487b97f9..75c9251d81 100644 --- a/libs/ardour/midi_automation_list_binder.cc +++ b/libs/ardour/midi_automation_list_binder.cc @@ -49,8 +49,8 @@ MidiAutomationListBinder::MidiAutomationListBinder (XMLNode* node, Session::Sour _parameter = EventTypeMap::instance().from_symbol (parameter_str); } -AutomationList* -MidiAutomationListBinder::get () const +void +MidiAutomationListBinder::set_state (XMLNode const & node, int version) const { boost::shared_ptr model = _source->model (); assert (model); @@ -58,9 +58,34 @@ MidiAutomationListBinder::get () const boost::shared_ptr control = model->automation_control (_parameter); assert (control); - return control->alist().get(); + control->alist().get()->set_state (node, version); } +XMLNode& +MidiAutomationListBinder::get_state () const +{ + boost::shared_ptr model = _source->model (); + assert (model); + + boost::shared_ptr control = model->automation_control (_parameter); + assert (control); + + return control->alist().get()->get_state (); +} + +std::string +MidiAutomationListBinder::type_name() const +{ + boost::shared_ptr model = _source->model (); + assert (model); + + boost::shared_ptr control = model->automation_control (_parameter); + assert (control); + + return PBD::demangled_name (*control->alist().get()); +} + + void MidiAutomationListBinder::add_state (XMLNode* node) { diff --git a/libs/pbd/pbd/memento_command.h b/libs/pbd/pbd/memento_command.h index c452554dd8..7d9cbf18f9 100644 --- a/libs/pbd/pbd/memento_command.h +++ b/libs/pbd/pbd/memento_command.h @@ -55,13 +55,11 @@ template class LIBPBD_TEMPLATE_API MementoCommandBinder : public PBD::Destructible { public: - /** @return Stateful object to operate on */ - virtual obj_T* get () const = 0; + virtual void set_state (XMLNode const &, int version) const = 0; + virtual XMLNode& get_state () const = 0; /** @return Name of our type */ - virtual std::string type_name () const { - return PBD::demangled_name (*get ()); - } + virtual std::string type_name () const = 0; /** Add our own state to an XMLNode */ virtual void add_state (XMLNode *) = 0; @@ -78,8 +76,10 @@ public: _object.Destroyed.connect_same_thread (_object_death_connection, boost::bind (&SimpleMementoCommandBinder::object_died, this)); } - obj_T* get () const { - return &_object; + void set_state (XMLNode const & node , int version) const { _object.set_state (node, version); } + XMLNode& get_state () const { return _object.get_state(); } + std::string type_name() const { + return PBD::demangled_name (_object); } void add_state (XMLNode* node) { @@ -131,13 +131,13 @@ public: void operator() () { if (after) { - _binder->get()->set_state(*after, Stateful::current_state_version); + _binder->set_state(*after, Stateful::current_state_version); } } void undo() { if (before) { - _binder->get()->set_state(*before, Stateful::current_state_version); + _binder->set_state(*before, Stateful::current_state_version); } }