Pan automation/serialization fixes.
[ardour.git] / libs / ardour / ardour / panner.h
index 3091527e59b78b93884809405a7f6734b0f8b01f..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;
@@ -40,11 +41,13 @@ namespace ARDOUR {
 
 class Session;
 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);
@@ -62,39 +65,26 @@ class StreamPanner : public sigc::trackable, public Stateful
        void get_effective_position (float& xpos, float& ypos) const { xpos = effective_x; ypos = effective_y; }
        void get_effective_position (float& xpos, float& ypos, float& zpos) const { xpos = effective_x; ypos = effective_y; zpos = effective_z; }
 
-       /* the basic panner API */
+       /* the basic StreamPanner API */
 
-       virtual void distribute (Sample* src, Sample** obufs, gain_t gain_coeff, nframes_t nframes) = 0;
-       virtual void distribute_automated (Sample* src, Sample** obufs, 
+       virtual void distribute (AudioBuffer& src, BufferSet& obufs, gain_t gain_coeff, nframes_t nframes) = 0;
+       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;
@@ -113,8 +103,11 @@ class StreamPanner : public sigc::trackable, public Stateful
 
        bool             _muted;
 
-       struct PanControllable : public PBD::Controllable {
-           PanControllable (StreamPanner& p) : 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;
            
@@ -123,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;
@@ -132,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
@@ -141,16 +134,11 @@ class BaseStereoPanner : public StreamPanner
           and a type name. See EqualPowerStereoPanner as an example.
        */
 
-       void distribute (Sample* src, Sample** obufs, gain_t gain_coeff, nframes_t nframes);
+       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;
@@ -159,23 +147,21 @@ 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 (Sample* src, Sample** obufs, 
+       void distribute_automated (AudioBuffer& src, BufferSet& obufs, 
                             nframes_t start, nframes_t end, nframes_t nframes, pan_t** buffers);
 
        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); 
@@ -189,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);
 
-       void distribute (Sample* src, Sample** obufs, gain_t gain_coeff, nframes_t nframes);
-       void distribute_automated (Sample* src, Sample** obufs, 
-                            nframes_t start, nframes_t end, nframes_t nframes, pan_t** buffers);
-
-       int load (istream&, string path, uint32_t&);
-       int save (ostream&) const;
-
-       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 {
@@ -239,7 +214,8 @@ class Panner : public std::vector<StreamPanner*>, public Stateful, public sigc::
        Panner (string name, Session&);
        virtual ~Panner ();
 
-       void set_name (string);
+       /// The fundamental Panner function
+       void distribute(BufferSet& src, BufferSet& dest, nframes_t start_frame, nframes_t end_frames, nframes_t nframes, nframes_t offset);
 
        bool bypassed() const { return _bypassed; }
        void set_bypassed (bool yn);
@@ -260,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&);
@@ -299,10 +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;
@@ -310,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