2 Copyright (C) 2004 Paul Davis
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.
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.
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.
21 #ifndef __ardour_panner_h__
22 #define __ardour_panner_h__
28 #include <sigc++/signal.h>
30 #include <pbd/stateful.h>
31 #include <pbd/controllable.h>
33 #include <ardour/types.h>
34 #include <ardour/curve.h>
46 class StreamPanner : public sigc::trackable, public Stateful
49 StreamPanner (Panner& p);
52 void set_muted (bool yn);
53 bool muted() const { return _muted; }
55 void set_position (float x, bool link_call = false);
56 void set_position (float x, float y, bool link_call = false);
57 void set_position (float x, float y, float z, bool link_call = false);
59 void get_position (float& xpos) const { xpos = x; }
60 void get_position (float& xpos, float& ypos) const { xpos = x; ypos = y; }
61 void get_position (float& xpos, float& ypos, float& zpos) const { xpos = x; ypos = y; zpos = z; }
63 void get_effective_position (float& xpos) const { xpos = effective_x; }
64 void get_effective_position (float& xpos, float& ypos) const { xpos = effective_x; ypos = effective_y; }
65 void get_effective_position (float& xpos, float& ypos, float& zpos) const { xpos = effective_x; ypos = effective_y; zpos = effective_z; }
67 /* the basic StreamPanner API */
69 virtual void distribute (AudioBuffer& src, BufferSet& obufs, gain_t gain_coeff, nframes_t nframes) = 0;
70 virtual void distribute_automated (AudioBuffer& src, BufferSet& obufs,
71 nframes_t start, nframes_t end, nframes_t nframes, pan_t** buffers) = 0;
75 virtual void snapshot (nframes_t now) = 0;
76 virtual void transport_stopped (nframes_t frame) = 0;
77 virtual void set_automation_state (AutoState) = 0;
78 virtual void set_automation_style (AutoStyle) = 0;
80 PBD::Controllable& control() { return _control; }
82 /* XXX this is wrong. for multi-dimensional panners, there
83 must surely be more than 1 automation curve.
86 virtual Curve& automation() = 0;
88 virtual int load (istream&, string path, uint32_t&) = 0;
90 virtual int save (ostream&) const = 0;
92 sigc::signal<void> Changed; /* for position */
93 sigc::signal<void> StateChanged; /* for mute */
95 int set_state (const XMLNode&);
96 virtual XMLNode& state (bool full_state) = 0;
98 Panner & get_parent() { return parent; }
108 /* these are for automation. they store the last value
109 used by the most recent process() cycle.
118 struct PanControllable : public PBD::Controllable {
119 PanControllable (std::string name, StreamPanner& p) : Controllable (name), panner (p) {}
121 StreamPanner& panner;
123 void set_value (float);
124 float get_value (void) const;
125 bool can_send_feedback() const;
128 PanControllable _control;
130 void add_state (XMLNode&);
131 virtual void update () = 0;
134 class BaseStereoPanner : public StreamPanner
137 BaseStereoPanner (Panner&);
138 ~BaseStereoPanner ();
140 /* this class just leaves the pan law itself to be defined
141 by the update(), distribute_automated()
142 methods. derived classes also need a factory method
143 and a type name. See EqualPowerStereoPanner as an example.
146 void distribute (AudioBuffer& src, BufferSet& obufs, gain_t gain_coeff, nframes_t nframes);
148 int load (istream&, string path, uint32_t&);
149 int save (ostream&) const;
150 void snapshot (nframes_t now);
151 void transport_stopped (nframes_t frame);
152 void set_automation_state (AutoState);
153 void set_automation_style (AutoStyle);
155 Curve& automation() { return _automation; }
168 class EqualPowerStereoPanner : public BaseStereoPanner
171 EqualPowerStereoPanner (Panner&);
172 ~EqualPowerStereoPanner ();
174 void distribute_automated (AudioBuffer& src, BufferSet& obufs,
175 nframes_t start, nframes_t end, nframes_t nframes, pan_t** buffers);
177 void get_current_coefficients (pan_t*) const;
178 void get_desired_coefficients (pan_t*) const;
180 static StreamPanner* factory (Panner&);
183 XMLNode& state (bool full_state);
184 XMLNode& get_state (void);
185 int set_state (const XMLNode&);
191 class Multi2dPanner : public StreamPanner
194 Multi2dPanner (Panner& parent);
197 void snapshot (nframes_t now);
198 void transport_stopped (nframes_t frame);
199 void set_automation_state (AutoState);
200 void set_automation_style (AutoStyle);
202 /* XXX this is wrong. for multi-dimensional panners, there
203 must surely be more than 1 automation curve.
206 Curve& automation() { return _automation; }
208 void distribute (AudioBuffer& src, BufferSet& obufs, gain_t gain_coeff, nframes_t nframes);
209 void distribute_automated (AudioBuffer& src, BufferSet& obufs,
210 nframes_t start, nframes_t end, nframes_t nframes, pan_t** buffers);
212 int load (istream&, string path, uint32_t&);
213 int save (ostream&) const;
215 static StreamPanner* factory (Panner&);
218 XMLNode& state (bool full_state);
219 XMLNode& get_state (void);
220 int set_state (const XMLNode&);
227 class Panner : public std::vector<StreamPanner*>, public Stateful, public sigc::trackable
236 Output (float xp, float yp)
237 : x (xp), y (yp), current_pan (0.0f), desired_pan (0.f) {}
241 Panner (string name, Session&);
244 /// The fundamental Panner function
245 void distribute(BufferSet& src, BufferSet& dest, nframes_t start_frame, nframes_t end_frames, nframes_t nframes, nframes_t offset);
247 void set_name (string);
249 bool bypassed() const { return _bypassed; }
250 void set_bypassed (bool yn);
252 StreamPanner* add ();
253 void remove (uint32_t which);
255 void reset (uint32_t noutputs, uint32_t npans);
257 void snapshot (nframes_t now);
258 void transport_stopped (nframes_t frame);
260 void clear_automation ();
262 void set_automation_state (AutoState);
263 AutoState automation_state() const;
264 void set_automation_style (AutoStyle);
265 AutoStyle automation_style() const;
266 bool touching() const;
271 XMLNode& get_state (void);
272 XMLNode& state (bool full);
273 int set_state (const XMLNode&);
275 sigc::signal<void> Changed;
277 static bool equivalent (pan_t a, pan_t b) {
278 return fabsf (a - b) < 0.002; // about 1 degree of arc for a stereo panner
281 void move_output (uint32_t, float x, float y);
282 uint32_t nouts() const { return outputs.size(); }
283 Output& output (uint32_t n) { return outputs[n]; }
285 std::vector<Output> outputs;
286 Session& session() const { return _session; }
293 LinkDirection link_direction() const { return _link_direction; }
294 void set_link_direction (LinkDirection);
296 bool linked() const { return _linked; }
297 void set_linked (bool yn);
299 sigc::signal<void> LinkStateChanged;
300 sigc::signal<void> StateChanged; /* for bypass */
302 /* only StreamPanner should call these */
304 void set_position (float x, StreamPanner& orig);
305 void set_position (float x, float y, StreamPanner& orig);
306 void set_position (float x, float y, float z, StreamPanner& orig);
309 void distribute_no_automation(BufferSet& src, BufferSet& dest, nframes_t nframes, nframes_t offset, gain_t gain_coeff);
312 string automation_path;
314 uint32_t current_outs;
317 LinkDirection _link_direction;
319 static float current_automation_version_number;
322 } // namespace ARDOUR
324 #endif /*__ardour_panner_h__ */