Pan automation/serialization fixes.
[ardour.git] / libs / ardour / ardour / panner.h
index 52311208408d8f66d0083a2f90213eeda6439860..1852bdd1891ca70cc305f845cdeec5750ea18a3b 100644 (file)
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id$
 */
 
 #ifndef __ardour_panner_h__
 #define __ardour_panner_h__
 
 #include <cmath>
+#include <cassert>
 #include <vector>
 #include <string>
 #include <iostream>
@@ -32,6 +32,7 @@
 
 #include <ardour/types.h>
 #include <ardour/curve.h>
+#include <ardour/automation_control.h>
 
 using std::istream;
 using std::ostream;
@@ -43,10 +44,10 @@ class Panner;
 class BufferSet;
 class AudioBuffer;
 
-class StreamPanner : public sigc::trackable, public Stateful
+class StreamPanner : public sigc::trackable, public PBD::Stateful
 {
   public:
-       StreamPanner (Panner& p);
+       StreamPanner (Panner& p, ParamID param);
        ~StreamPanner ();
 
        void set_muted (bool yn);
@@ -70,33 +71,20 @@ class StreamPanner : public sigc::trackable, public Stateful
        virtual void distribute_automated (AudioBuffer& src, BufferSet& obufs,
                                     nframes_t start, nframes_t end, nframes_t nframes, pan_t** buffers) = 0;
 
-       /* automation */
-
-       virtual void snapshot (nframes_t now) = 0;
-       virtual void transport_stopped (nframes_t frame) = 0;
-       virtual void set_automation_state (AutoState) = 0;
-       virtual void set_automation_style (AutoStyle) = 0;
-       
-       PBD::Controllable& control()  { return _control; }
+       boost::shared_ptr<AutomationControl> pan_control()  { return _control; }
        
-       /* XXX this is wrong. for multi-dimensional panners, there
-          must surely be more than 1 automation curve.
-       */
-
-       virtual Curve& automation() = 0;
-
-       virtual int load (istream&, string path, uint32_t&) = 0;
-
-       virtual int save (ostream&) const = 0;
-
        sigc::signal<void> Changed;      /* for position */
        sigc::signal<void> StateChanged; /* for mute */
 
        int set_state (const XMLNode&);
        virtual XMLNode& state (bool full_state) = 0;
-
-       Panner & get_parent() { return parent; }
        
+       Panner & get_parent() { return parent; }
+
+       /* old school automation loading */
+
+       virtual int load (istream&, string path, uint32_t&) = 0;
+
   protected:
        friend class Panner;
        Panner& parent;
@@ -115,8 +103,11 @@ class StreamPanner : public sigc::trackable, public Stateful
 
        bool             _muted;
 
-       struct PanControllable : public PBD::Controllable {
-           PanControllable (std::string name, StreamPanner& p) : Controllable (name), panner (p) {}
+       struct PanControllable : public AutomationControl {
+           PanControllable (Session& s, std::string name, StreamPanner& p, ParamID param)
+                       : AutomationControl (s, boost::shared_ptr<AutomationList>(new AutomationList(
+                                       param, 0.0, 1.0, 0.5)), name)
+                       , panner (p) { assert(param.type() != NullAutomation); }
            
            StreamPanner& panner;
            
@@ -125,7 +116,7 @@ class StreamPanner : public sigc::trackable, public Stateful
            bool can_send_feedback() const;
        };
 
-       PanControllable  _control;
+       boost::shared_ptr<PanControllable> _control;
 
        void add_state (XMLNode&);
        virtual void update () = 0;
@@ -134,7 +125,7 @@ class StreamPanner : public sigc::trackable, public Stateful
 class BaseStereoPanner : public StreamPanner
 {
   public:
-       BaseStereoPanner (Panner&);
+       BaseStereoPanner (Panner&, ParamID param);
        ~BaseStereoPanner ();
 
        /* this class just leaves the pan law itself to be defined
@@ -145,14 +136,9 @@ class BaseStereoPanner : public StreamPanner
 
        void distribute (AudioBuffer& src, BufferSet& obufs, gain_t gain_coeff, nframes_t nframes);
 
-       int load (istream&, string path, uint32_t&);
-       int save (ostream&) const;
-       void snapshot (nframes_t now);
-       void transport_stopped (nframes_t frame);
-       void set_automation_state (AutoState);
-       void set_automation_style (AutoStyle);
+       /* old school automation loading */
 
-       Curve& automation() { return _automation; }
+       int load (istream&, string path, uint32_t&);
 
   protected:
        float left;
@@ -161,14 +147,12 @@ class BaseStereoPanner : public StreamPanner
        float desired_right;
        float left_interp;
        float right_interp;
-
-       Curve  _automation;
 };
 
 class EqualPowerStereoPanner : public BaseStereoPanner
 {
   public:
-       EqualPowerStereoPanner (Panner&);
+       EqualPowerStereoPanner (Panner&, ParamID param);
        ~EqualPowerStereoPanner ();
 
        void distribute_automated (AudioBuffer& src, BufferSet& obufs, 
@@ -177,7 +161,7 @@ class EqualPowerStereoPanner : public BaseStereoPanner
        void get_current_coefficients (pan_t*) const;
        void get_desired_coefficients (pan_t*) const;
 
-       static StreamPanner* factory (Panner&);
+       static StreamPanner* factory (Panner&, ParamID param);
        static string name;
 
        XMLNode& state (bool full_state); 
@@ -191,40 +175,29 @@ class EqualPowerStereoPanner : public BaseStereoPanner
 class Multi2dPanner : public StreamPanner
 {
   public:
-       Multi2dPanner (Panner& parent);
+       Multi2dPanner (Panner& parent, ParamID);
        ~Multi2dPanner ();
 
-       void snapshot (nframes_t now);
-       void transport_stopped (nframes_t frame);
-       void set_automation_state (AutoState);
-       void set_automation_style (AutoStyle);
-
-       /* XXX this is wrong. for multi-dimensional panners, there
-          must surely be more than 1 automation curve.
-       */
-
-       Curve& automation() { return _automation; }
-
        void distribute (AudioBuffer& src, BufferSet& obufs, gain_t gain_coeff, nframes_t nframes);
        void distribute_automated (AudioBuffer& src, BufferSet& obufs,
-                            nframes_t start, nframes_t end, nframes_t nframes, pan_t** buffers);
-
-       int load (istream&, string path, uint32_t&);
-       int save (ostream&) const;
+                                  nframes_t start, nframes_t end, nframes_t nframes, pan_t** buffers);
 
-       static StreamPanner* factory (Panner&);
+       static StreamPanner* factory (Panner&, ParamID);
        static string name;
 
        XMLNode& state (bool full_state); 
        XMLNode& get_state (void);
        int set_state (const XMLNode&);
 
+       /* old school automation loading */
+
+       int load (istream&, string path, uint32_t&);
+
   private:
-       Curve _automation;
        void update ();
 };
 
-class Panner : public std::vector<StreamPanner*>, public Stateful, public sigc::trackable
+class Panner : public std::vector<StreamPanner*>, public PBD::Stateful, public sigc::trackable
 {
   public:
        struct Output {
@@ -244,8 +217,6 @@ class Panner : public std::vector<StreamPanner*>, public Stateful, public sigc::
        /// The fundamental Panner function
        void distribute(BufferSet& src, BufferSet& dest, nframes_t start_frame, nframes_t end_frames, nframes_t nframes, nframes_t offset);
 
-       void set_name (string);
-
        bool bypassed() const { return _bypassed; }
        void set_bypassed (bool yn);
 
@@ -265,9 +236,6 @@ class Panner : public std::vector<StreamPanner*>, public Stateful, public sigc::
        AutoStyle automation_style() const;
        bool touching() const;
 
-       int load ();
-       int save () const;
-
        XMLNode& get_state (void);
        XMLNode& state (bool full);
        int      set_state (const XMLNode&);
@@ -304,12 +272,14 @@ class Panner : public std::vector<StreamPanner*>, public Stateful, public sigc::
        void set_position (float x, StreamPanner& orig);
        void set_position (float x, float y, StreamPanner& orig);
        void set_position (float x, float y, float z, StreamPanner& orig);
-       
+
+       /* old school automation */
+
+       int load ();
+
   private:
        void distribute_no_automation(BufferSet& src, BufferSet& dest, nframes_t nframes, nframes_t offset, gain_t gain_coeff);
 
-
-       string            automation_path;
        Session&         _session;
        uint32_t     current_outs;
        bool             _linked;
@@ -317,6 +287,11 @@ class Panner : public std::vector<StreamPanner*>, public Stateful, public sigc::
        LinkDirection    _link_direction;
 
        static float current_automation_version_number;
+
+       /* old school automation handling */
+
+       std::string automation_path;
+       void set_name (std::string);
 };
 
 } // namespace ARDOUR