correctly restore VCA-VCA slave/master relationships at session load time
[ardour.git] / libs / ardour / ardour / gain_control.h
index 7845679220f8fece5f738a1ccd0814c24739d682..2b472dc8e00887d3f46d8f3f20cd0849ae51e0b2 100644 (file)
@@ -20,7 +20,7 @@
 #define __ardour_gain_control_h__
 
 #include <string>
-#include <list>
+#include <map>
 
 #include <boost/shared_ptr.hpp>
 #include <glibmm/threads.h>
@@ -41,6 +41,7 @@ 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);
 
@@ -54,20 +55,52 @@ class LIBARDOUR_API GainControl : public AutomationControl {
        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;
+       bool slaved () const;
+       std::vector<uint32_t> masters () const;
+
+       PBD::Signal0<void> VCAStatusChange;
+
+       int set_state (XMLNode const&, int);
+       XMLNode& get_state();
 
   private:
-       void _set_value (double val, PBD::Controllable::GroupControlDisposition group_override);
+       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; }
 
-       mutable Glib::Threads::Mutex master_lock;
+               PBD::ScopedConnection connection;
 
-       typedef std::list<boost::shared_ptr<GainControl> > Masters;
+         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);
 };
 
 } /* namespace */