#define __ardour_gain_control_h__
#include <string>
-#include <list>
+#include <set>
#include <boost/shared_ptr.hpp>
#include <glibmm/threads.h>
double range_db;
gain_t get_master_gain () const;
- void add_master (boost::shared_ptr<GainControl>);
- void remove_master (boost::shared_ptr<GainControl>);
+ void add_master (boost::shared_ptr<VCA>);
+ void remove_master (boost::shared_ptr<VCA>);
void clear_masters ();
- bool slaved_to (boost::shared_ptr<GainControl>) const;
+ bool slaved_to (boost::shared_ptr<VCA>) const;
+ std::vector<uint32_t> masters () const;
+
+ int set_state (XMLNode const&, int);
+ XMLNode& get_state();
private:
void _set_value (double val, PBD::Controllable::GroupControlDisposition group_override);
mutable Glib::Threads::Mutex master_lock;
- typedef std::list<boost::shared_ptr<GainControl> > Masters;
+ typedef std::set<boost::shared_ptr<GainControl> > Masters;
Masters _masters;
+ PBD::ScopedConnectionList masters_connections;
+ std::set<uint32_t> _masters_numbers;
+ std::string _masters_state_string ();
gain_t get_master_gain_locked () const;
+ void master_going_away (boost::weak_ptr<VCA>);
};
} /* namespace */
675 Mass Ave, Cambridge, MA 02139, USA.
*/
+#include "pbd/convert.h"
+#include "pbd/strsplit.h"
+
#include "ardour/dB.h"
#include "ardour/gain_control.h"
#include "ardour/session.h"
+#include "ardour/vca.h"
+#include "ardour/vca_manager.h"
#include "i18n.h"
}
void
-GainControl::add_master (boost::shared_ptr<GainControl> m)
+GainControl::add_master (boost::shared_ptr<VCA> vca)
{
gain_t old_master_val;
gain_t new_master_val;
{
Glib::Threads::Mutex::Lock lm (master_lock);
old_master_val = get_master_gain_locked ();
- _masters.push_back (m);
+ _masters.insert (vca->control());
+ _masters_numbers.insert (vca->number());
new_master_val = get_master_gain_locked ();
+
+ /* note that we bind @param m as a weak_ptr<GainControl>, thus
+ avoiding holding a reference to the control in the binding
+ itself.
+ */
+
+ vca->DropReferences.connect_same_thread (masters_connections, boost::bind (&GainControl::master_going_away, this, vca));
+
}
if (old_master_val != new_master_val) {
}
void
-GainControl::remove_master (boost::shared_ptr<GainControl> m)
+GainControl::master_going_away (boost::weak_ptr<VCA> wv)
+{
+ boost::shared_ptr<VCA> v = wv.lock();
+ if (v) {
+ remove_master (v);
+ }
+}
+
+void
+GainControl::remove_master (boost::shared_ptr<VCA> vca)
{
gain_t old_master_val;
gain_t new_master_val;
{
Glib::Threads::Mutex::Lock lm (master_lock);
old_master_val = get_master_gain_locked ();
- _masters.remove (m);
+ _masters.erase (vca->control());
+ _masters_numbers.erase (vca->number());
new_master_val = get_master_gain_locked ();
}
Glib::Threads::Mutex::Lock lm (master_lock);
old_master_val = get_master_gain_locked ();
_masters.clear ();
+ _masters_numbers.clear ();
new_master_val = get_master_gain_locked ();
}
}
bool
-GainControl::slaved_to (boost::shared_ptr<GainControl> gc) const
+GainControl::slaved_to (boost::shared_ptr<VCA> vca) const
{
Glib::Threads::Mutex::Lock lm (master_lock);
- return find (_masters.begin(), _masters.end(), gc) != _masters.end();
+ return find (_masters.begin(), _masters.end(), vca->control()) != _masters.end();
+}
+
+XMLNode&
+GainControl::get_state ()
+{
+ XMLNode& node (AutomationControl::get_state());
+
+ /* store VCA master IDs */
+
+ string str;
+
+ {
+ Glib::Threads::Mutex::Lock lm (master_lock);
+ for (set<uint32_t>::const_iterator m = _masters_numbers.begin(); m != _masters_numbers.end(); ++m) {
+ if (!str.empty()) {
+ str += ',';
+ }
+ str += PBD::to_string (*m, std::dec);
+ }
+ }
+
+ if (!str.empty()) {
+ node.add_property (X_("masters"), str);
+ }
+
+ return node;
+}
+
+int
+GainControl::set_state (XMLNode const& node, int version)
+{
+ AutomationControl::set_state (node, version);
+
+ XMLProperty const* prop = node.property (X_("masters"));
+
+ /* XXXProblem here if we allow VCA's to be slaved to other VCA's .. we
+ * have to load all VCAs first, then call ::set_state() so that
+ * vca_by_number() will succeed.
+ */
+
+ if (prop) {
+ vector<string> masters;
+ split (prop->value(), masters, ',');
+
+ for (vector<string>::const_iterator m = masters.begin(); m != masters.end(); ++m) {
+ boost::shared_ptr<VCA> vca = _session.vca_manager().vca_by_number (PBD::atoi (*m));
+ if (vca) {
+ add_master (vca);
+ }
+ }
+ }
+
+ return 0;
}