alter API for MementoCommandBinder to allow future flexibility

This commit is contained in:
Paul Davis 2020-11-27 14:29:00 -07:00
parent 3c00fab75e
commit 27c98adda9
3 changed files with 41 additions and 13 deletions

View File

@ -35,7 +35,10 @@ public:
MidiAutomationListBinder (boost::shared_ptr<ARDOUR::MidiSource>, 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:

View File

@ -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<MidiModel> model = _source->model ();
assert (model);
@ -58,9 +58,34 @@ MidiAutomationListBinder::get () const
boost::shared_ptr<AutomationControl> 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<MidiModel> model = _source->model ();
assert (model);
boost::shared_ptr<AutomationControl> control = model->automation_control (_parameter);
assert (control);
return control->alist().get()->get_state ();
}
std::string
MidiAutomationListBinder::type_name() const
{
boost::shared_ptr<MidiModel> model = _source->model ();
assert (model);
boost::shared_ptr<AutomationControl> control = model->automation_control (_parameter);
assert (control);
return PBD::demangled_name (*control->alist().get());
}
void
MidiAutomationListBinder::add_state (XMLNode* node)
{

View File

@ -55,13 +55,11 @@ template <class obj_T>
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);
}
}