Fix wrongly exposed set_parameter methods on PluginInsert.
[ardour.git] / libs / ardour / ardour / panner.h
1 /*
2     Copyright (C) 2004 Paul Davis 
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #ifndef __ardour_panner_h__
21 #define __ardour_panner_h__
22
23 #include <cmath>
24 #include <cassert>
25 #include <vector>
26 #include <string>
27 #include <iostream>
28 #include <sigc++/signal.h>
29
30 #include <pbd/stateful.h> 
31 #include <pbd/controllable.h>
32
33 #include <ardour/types.h>
34 #include <ardour/automation_control.h>
35 #include <ardour/processor.h>
36 #include <ardour/session.h>
37
38 using std::istream;
39 using std::ostream;
40
41 namespace ARDOUR {
42
43 class Route;
44 class Session;
45 class Panner;
46 class BufferSet;
47 class AudioBuffer;
48
49 class StreamPanner : public sigc::trackable, public PBD::Stateful
50 {
51   public:
52         StreamPanner (Panner& p, Evoral::Parameter param);
53         ~StreamPanner ();
54
55         void set_muted (bool yn);
56         bool muted() const { return _muted; }
57
58         void set_position (float x, bool link_call = false);
59         void set_position (float x, float y, bool link_call = false);
60         void set_position (float x, float y, float z, bool link_call = false);
61
62         void get_position (float& xpos) const { xpos = x; }
63         void get_position (float& xpos, float& ypos) const { xpos = x; ypos = y; }
64         void get_position (float& xpos, float& ypos, float& zpos) const { xpos = x; ypos = y; zpos = z; }
65
66         void get_effective_position (float& xpos) const { xpos = effective_x; }
67         void get_effective_position (float& xpos, float& ypos) const { xpos = effective_x; ypos = effective_y; }
68         void get_effective_position (float& xpos, float& ypos, float& zpos) const { xpos = effective_x; ypos = effective_y; zpos = effective_z; }
69
70         /* the basic StreamPanner API */
71
72         virtual void distribute (AudioBuffer& src, BufferSet& obufs, gain_t gain_coeff, nframes_t nframes) = 0;
73         virtual void distribute_automated (AudioBuffer& src, BufferSet& obufs,
74                                      nframes_t start, nframes_t end, nframes_t nframes, pan_t** buffers) = 0;
75
76         boost::shared_ptr<AutomationControl> pan_control()  { return _control; }
77         
78         sigc::signal<void> Changed;      /* for position */
79         sigc::signal<void> StateChanged; /* for mute */
80
81         int set_state (const XMLNode&);
82         virtual XMLNode& state (bool full_state) = 0;
83         
84         Panner & get_parent() { return parent; }
85
86         /* old school automation loading */
87
88         virtual int load (istream&, string path, uint32_t&) = 0;
89
90   protected:
91         friend class Panner;
92         Panner& parent;
93
94         float x;
95         float y;
96         float z;
97         
98         /* these are for automation. they store the last value
99            used by the most recent process() cycle.
100         */
101
102         float effective_x;
103         float effective_y;
104         float effective_z;
105
106         bool _muted;
107
108         boost::shared_ptr<AutomationControl> _control;
109
110         void add_state (XMLNode&);
111         virtual void update () = 0;
112 };
113
114 class BaseStereoPanner : public StreamPanner
115 {
116   public:
117         BaseStereoPanner (Panner&, Evoral::Parameter param);
118         ~BaseStereoPanner ();
119
120         /* this class just leaves the pan law itself to be defined
121            by the update(), distribute_automated() 
122            methods. derived classes also need a factory method
123            and a type name. See EqualPowerStereoPanner as an example.
124         */
125
126         void distribute (AudioBuffer& src, BufferSet& obufs, gain_t gain_coeff, nframes_t nframes);
127
128         /* old school automation loading */
129
130         int load (istream&, string path, uint32_t&);
131
132   protected:
133         float left;
134         float right;
135         float desired_left;
136         float desired_right;
137         float left_interp;
138         float right_interp;
139 };
140
141 class EqualPowerStereoPanner : public BaseStereoPanner
142 {
143   public:
144         EqualPowerStereoPanner (Panner&, Evoral::Parameter param);
145         ~EqualPowerStereoPanner ();
146
147         void distribute_automated (AudioBuffer& src, BufferSet& obufs, 
148                              nframes_t start, nframes_t end, nframes_t nframes, pan_t** buffers);
149
150         void get_current_coefficients (pan_t*) const;
151         void get_desired_coefficients (pan_t*) const;
152
153         static StreamPanner* factory (Panner&, Evoral::Parameter param);
154         static string name;
155
156         XMLNode& state (bool full_state); 
157         XMLNode& get_state (void); 
158         int      set_state (const XMLNode&);
159
160   private:
161         void update ();
162 };
163
164 class Multi2dPanner : public StreamPanner
165 {
166   public:
167         Multi2dPanner (Panner& parent, Evoral::Parameter);
168         ~Multi2dPanner ();
169
170         void distribute (AudioBuffer& src, BufferSet& obufs, gain_t gain_coeff, nframes_t nframes);
171         void distribute_automated (AudioBuffer& src, BufferSet& obufs,
172                                    nframes_t start, nframes_t end, nframes_t nframes, pan_t** buffers);
173
174         static StreamPanner* factory (Panner&, Evoral::Parameter);
175         static string name;
176
177         XMLNode& state (bool full_state); 
178         XMLNode& get_state (void);
179         int set_state (const XMLNode&);
180
181         /* old school automation loading */
182
183         int load (istream&, string path, uint32_t&);
184
185   private:
186         void update ();
187 };
188
189
190 class Panner : public Processor
191 {
192   public:
193         struct Output {
194             float x;
195             float y;
196             pan_t current_pan;
197             pan_t desired_pan;
198
199             Output (float xp, float yp) 
200                     : x (xp), y (yp), current_pan (0.0f), desired_pan (0.f) {}
201                     
202         };
203
204         //Panner (std::string name, Session&, int _num_bufs);
205         Panner (string name, Session&);
206         virtual ~Panner ();
207
208         void clear_panners ();
209
210
211         /// The fundamental Panner function
212         void set_automation_state (AutoState);
213         AutoState automation_state() const;
214         void set_automation_style (AutoStyle);
215         AutoStyle automation_style() const;
216         bool touching() const;
217
218         bool is_in_place () const { return false; }
219         bool is_out_of_place () const { return true; }
220         bool can_support_io_configuration (const ChanCount& in, ChanCount& out) const { return true; };
221
222         void run_out_of_place(BufferSet& src, BufferSet& dest, nframes_t start_frame, nframes_t end_frames, nframes_t nframes, nframes_t offset);
223
224         //void* get_inline_gui() const = 0;
225         //void* get_full_gui() const = 0;
226
227         bool bypassed() const { return _bypassed; }
228         void set_bypassed (bool yn);
229
230         StreamPanner* add ();
231         void remove (uint32_t which);
232         void reset (uint32_t noutputs, uint32_t npans);
233
234         
235
236
237         XMLNode& get_state (void);
238         XMLNode& state (bool full);
239         int      set_state (const XMLNode&);
240
241         static bool equivalent (pan_t a, pan_t b) {
242                 return fabsf (a - b) < 0.002; // about 1 degree of arc for a stereo panner
243         }
244
245         void move_output (uint32_t, float x, float y);
246         uint32_t nouts() const { return outputs.size(); }
247         Output& output (uint32_t n) { return outputs[n]; }
248
249         std::vector<Output> outputs;
250
251         enum LinkDirection {
252                 SameDirection,
253                 OppositeDirection
254         };
255
256         LinkDirection link_direction() const { return _link_direction; }
257         void set_link_direction (LinkDirection);
258         
259         bool linked() const { return _linked; }
260         void set_linked (bool yn);
261
262         StreamPanner &streampanner( uint32_t n ) const { assert( n < _streampanners.size() ); return *_streampanners[n]; }
263         uint32_t npanners() const { return _streampanners.size(); }
264
265         sigc::signal<void> Changed;
266         sigc::signal<void> LinkStateChanged;
267         sigc::signal<void> StateChanged; /* for bypass */
268
269         /* only StreamPanner should call these */
270         
271         void set_position (float x, StreamPanner& orig);
272         void set_position (float x, float y, StreamPanner& orig);
273         void set_position (float x, float y, float z, StreamPanner& orig);
274
275         /* old school automation */
276
277         int load ();
278
279         struct PanControllable : public AutomationControl {
280             PanControllable (Session& s, std::string name, Panner& p, Evoral::Parameter param)
281                         : AutomationControl (s, param,
282                                         boost::shared_ptr<AutomationList>(new AutomationList(param)), name)
283                         , panner (p)
284                 { assert(param.type() != NullAutomation); }
285             
286                 AutomationList* alist() { return (AutomationList*)_list.get(); }
287             Panner& panner;
288             
289             void set_value (float);
290             float get_value (void) const;
291         };
292
293         boost::shared_ptr<AutomationControl> pan_control (int id, int chan=0) {
294             return automation_control(Evoral::Parameter (PanAutomation, chan, id));
295         }
296
297         boost::shared_ptr<const AutomationControl> pan_control (int id, int chan=0) const {
298             return automation_control(Evoral::Parameter (PanAutomation, chan, id));
299         }
300
301   private:
302         void distribute_no_automation(BufferSet& src, BufferSet& dest, nframes_t nframes, nframes_t offset, gain_t gain_coeff);
303         std::vector<StreamPanner*> _streampanners;
304         uint32_t     current_outs;
305         bool             _linked;
306         bool             _bypassed;
307         LinkDirection    _link_direction;
308
309         static float current_automation_version_number;
310
311         /* old school automation handling */
312
313         std::string automation_path;
314 };
315
316 } // namespace ARDOUR
317
318 #endif /*__ardour_panner_h__ */