diff --git a/libs/ardour/ardour/slavable.h b/libs/ardour/ardour/slavable.h new file mode 100644 index 0000000000..ae53caef38 --- /dev/null +++ b/libs/ardour/ardour/slavable.h @@ -0,0 +1,61 @@ +/* + Copyright (C) 2016 Paul Davis + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#ifndef __ardour_slavable_h__ +#define __ardour_slavable_h__ + +#include +#include +#include + +#include + +class XMLNode; + +namespace ARDOUR { + +class VCA; +class Session; + +class Slavable +{ + public: + Slavable (); + virtual ~Slavable() {} + + XMLNode& state () const; + int assign (Session& s, XMLNode const&); + + void assign (boost::shared_ptr); + void unassign (boost::shared_ptr); + + static std::string xml_node_name; + + protected: + virtual int assign_controls (boost::shared_ptr) = 0; + virtual int unassign_controls (boost::shared_ptr) = 0; + + private: + mutable Glib::Threads::RWLock master_lock; + std::set _masters; +}; + +} // namespace ARDOUR + +#endif /* __ardour_slavable_h__ */ diff --git a/libs/ardour/slavable.cc b/libs/ardour/slavable.cc new file mode 100644 index 0000000000..989c2ec663 --- /dev/null +++ b/libs/ardour/slavable.cc @@ -0,0 +1,76 @@ +/* + Copyright (C) 2016 Paul Davis + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include + +#include "pbd/convert.h" +#include "pbd/xml++.h" + +#include "ardour/slavable.h" +#include "ardour/vca.h" + +#include "i18n.h" + +using namespace ARDOUR; + +std::string Slavable::xml_node_name = X_("Slavable"); + +Slavable::Slavable () +{ + +} + +XMLNode& +Slavable::state () const +{ + XMLNode* node = new XMLNode (xml_node_name); + XMLNode* child; + + Glib::Threads::RWLock::ReaderLock lm (master_lock); + for (std::set::const_iterator i = _masters.begin(); i != _masters.end(); ++i) { + child = new XMLNode (X_("Master")); + child->add_property (X_("number"), PBD::to_string (*i, std::dec)); + node->add_child_nocopy (*child); + } + + return *node; +} + +int +Slavable::assign (Session& s, XMLNode const& node) +{ + return 0; +} + +void +Slavable::assign (boost::shared_ptr v) +{ + if (assign_controls (v) == 0) { + Glib::Threads::RWLock::WriterLock lm (master_lock); + _masters.insert (v->number()); + } +} + +void +Slavable::unassign (boost::shared_ptr v) +{ + (void) unassign_controls (v); + Glib::Threads::RWLock::WriterLock lm (master_lock); + _masters.erase (v->number()); +}