correctly restore VCA-VCA slave/master relationships at session load time
[ardour.git] / libs / ardour / ardour / gain_control.h
index fa43b5d39f5faee24516b309a84640918669972a..2b472dc8e00887d3f46d8f3f20cd0849ae51e0b2 100644 (file)
 #define __ardour_gain_control_h__
 
 #include <string>
+#include <map>
+
 #include <boost/shared_ptr.hpp>
+#include <glibmm/threads.h>
 
 #include "pbd/controllable.h"
 
@@ -38,9 +41,9 @@ class LIBARDOUR_API GainControl : public AutomationControl {
        GainControl (Session& session, const Evoral::Parameter &param,
                     boost::shared_ptr<AutomationList> al = boost::shared_ptr<AutomationList>());
 
+       double get_value () const;
        void set_value (double val, PBD::Controllable::GroupControlDisposition group_override);
        void set_value_unchecked (double);
-       double get_value () const;
 
        double internal_to_interface (double) const;
        double interface_to_internal (double) const;
@@ -51,12 +54,53 @@ class LIBARDOUR_API GainControl : public AutomationControl {
        double lower_db;
        double range_db;
 
-       boost::shared_ptr<GainControl> master() const { return _master; }
-       void set_master (boost::shared_ptr<GainControl>);
+       gain_t get_master_gain () const;
+       void add_master (boost::shared_ptr<VCA>);
+       void remove_master (boost::shared_ptr<VCA>);
+       void clear_masters ();
+       bool slaved_to (boost::shared_ptr<VCA>) const;
+       bool slaved () const;
+       std::vector<uint32_t> masters () const;
+
+       PBD::Signal0<void> VCAStatusChange;
+
+       int set_state (XMLNode const&, int);
+       XMLNode& get_state();
 
   private:
+       class MasterRecord {
+          public:
+               MasterRecord (boost::shared_ptr<GainControl> gc, double r)
+                       : _master (gc)
+                       , _ratio (r)
+               {}
+
+               boost::shared_ptr<GainControl> master() const { return _master; }
+               double ratio () const { return _ratio; }
+               void reset_ratio (double r) { _ratio = r; }
+
+               PBD::ScopedConnection connection;
+
+         private:
+               boost::shared_ptr<GainControl> _master;
+               double _ratio;
+
+       };
+
+       mutable Glib::Threads::RWLock master_lock;
+       typedef std::map<uint32_t,MasterRecord> Masters;
+       Masters _masters;
+       PBD::ScopedConnectionList masters_connections;
+       std::string masters_string;
+       PBD::ScopedConnection vca_loaded_connection;
+
+       gain_t get_value_locked () const;
+       gain_t get_master_gain_locked () const;
+       void master_going_away (boost::weak_ptr<VCA>);
+       void recompute_masters_ratios (double val);
+       void vcas_loaded();
+
        void _set_value (double val, PBD::Controllable::GroupControlDisposition group_override);
-       boost::shared_ptr<GainControl> _master;
 };
 
 } /* namespace */