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>
44 class StreamPanner : public sigc::trackable, public Stateful
47 StreamPanner (Panner& p);
50 void set_muted (bool yn);
51 bool muted() const { return _muted; }
53 void set_position (float x, bool link_call = false);
54 void set_position (float x, float y, bool link_call = false);
55 void set_position (float x, float y, float z, bool link_call = false);
57 void get_position (float& xpos) const { xpos = x; }
58 void get_position (float& xpos, float& ypos) const { xpos = x; ypos = y; }
59 void get_position (float& xpos, float& ypos, float& zpos) const { xpos = x; ypos = y; zpos = z; }
61 void get_effective_position (float& xpos) const { xpos = effective_x; }
62 void get_effective_position (float& xpos, float& ypos) const { xpos = effective_x; ypos = effective_y; }
63 void get_effective_position (float& xpos, float& ypos, float& zpos) const { xpos = effective_x; ypos = effective_y; zpos = effective_z; }
65 /* the basic panner API */
67 virtual void distribute (Sample* src, Sample** obufs, gain_t gain_coeff, nframes_t nframes) = 0;
68 virtual void distribute_automated (Sample* src, Sample** obufs,
69 nframes_t start, nframes_t end, nframes_t nframes, pan_t** buffers) = 0;
73 virtual void snapshot (nframes_t now) = 0;
74 virtual void transport_stopped (nframes_t frame) = 0;
75 virtual void set_automation_state (AutoState) = 0;
76 virtual void set_automation_style (AutoStyle) = 0;
78 PBD::Controllable& control() { return _control; }
80 /* XXX this is wrong. for multi-dimensional panners, there
81 must surely be more than 1 automation curve.
84 virtual Curve& automation() = 0;
86 virtual int load (istream&, string path, uint32_t&) = 0;
88 virtual int save (ostream&) const = 0;
90 sigc::signal<void> Changed; /* for position */
91 sigc::signal<void> StateChanged; /* for mute */
93 int set_state (const XMLNode&);
94 virtual XMLNode& state (bool full_state) = 0;
96 Panner & get_parent() { return parent; }
106 /* these are for automation. they store the last value
107 used by the most recent process() cycle.
116 struct PanControllable : public PBD::Controllable {
117 PanControllable (StreamPanner& p) : panner (p) {}
119 StreamPanner& panner;
121 void set_value (float);
122 float get_value (void) const;
123 bool can_send_feedback() const;
126 PanControllable _control;
128 void add_state (XMLNode&);
129 virtual void update () = 0;
132 class BaseStereoPanner : public StreamPanner
135 BaseStereoPanner (Panner&);
136 ~BaseStereoPanner ();
138 /* this class just leaves the pan law itself to be defined
139 by the update(), distribute_automated()
140 methods. derived classes also need a factory method
141 and a type name. See EqualPowerStereoPanner as an example.
144 void distribute (Sample* src, Sample** obufs, gain_t gain_coeff, nframes_t nframes);
146 int load (istream&, string path, uint32_t&);
147 int save (ostream&) const;
148 void snapshot (nframes_t now);
149 void transport_stopped (nframes_t frame);
150 void set_automation_state (AutoState);
151 void set_automation_style (AutoStyle);
153 Curve& automation() { return _automation; }
166 class EqualPowerStereoPanner : public BaseStereoPanner
169 EqualPowerStereoPanner (Panner&);
170 ~EqualPowerStereoPanner ();
172 void distribute_automated (Sample* src, Sample** obufs,
173 nframes_t start, nframes_t end, nframes_t nframes, pan_t** buffers);
175 void get_current_coefficients (pan_t*) const;
176 void get_desired_coefficients (pan_t*) const;
178 static StreamPanner* factory (Panner&);
181 XMLNode& state (bool full_state);
182 XMLNode& get_state (void);
183 int set_state (const XMLNode&);
189 class Multi2dPanner : public StreamPanner
192 Multi2dPanner (Panner& parent);
195 void snapshot (nframes_t now);
196 void transport_stopped (nframes_t frame);
197 void set_automation_state (AutoState);
198 void set_automation_style (AutoStyle);
200 /* XXX this is wrong. for multi-dimensional panners, there
201 must surely be more than 1 automation curve.
204 Curve& automation() { return _automation; }
206 void distribute (Sample* src, Sample** obufs, gain_t gain_coeff, nframes_t nframes);
207 void distribute_automated (Sample* src, Sample** obufs,
208 nframes_t start, nframes_t end, nframes_t nframes, pan_t** buffers);
210 int load (istream&, string path, uint32_t&);
211 int save (ostream&) const;
213 static StreamPanner* factory (Panner&);
216 XMLNode& state (bool full_state);
217 XMLNode& get_state (void);
218 int set_state (const XMLNode&);
225 class Panner : public std::vector<StreamPanner*>, public Stateful, public sigc::trackable
234 Output (float xp, float yp)
235 : x (xp), y (yp), current_pan (0.0f), desired_pan (0.f) {}
239 Panner (string name, Session&);
242 void set_name (string);
244 bool bypassed() const { return _bypassed; }
245 void set_bypassed (bool yn);
247 StreamPanner* add ();
248 void remove (uint32_t which);
250 void reset (uint32_t noutputs, uint32_t npans);
252 void snapshot (nframes_t now);
253 void transport_stopped (nframes_t frame);
255 void clear_automation ();
257 void set_automation_state (AutoState);
258 AutoState automation_state() const;
259 void set_automation_style (AutoStyle);
260 AutoStyle automation_style() const;
261 bool touching() const;
266 XMLNode& get_state (void);
267 XMLNode& state (bool full);
268 int set_state (const XMLNode&);
270 sigc::signal<void> Changed;
272 static bool equivalent (pan_t a, pan_t b) {
273 return fabsf (a - b) < 0.002; // about 1 degree of arc for a stereo panner
276 void move_output (uint32_t, float x, float y);
277 uint32_t nouts() const { return outputs.size(); }
278 Output& output (uint32_t n) { return outputs[n]; }
280 std::vector<Output> outputs;
281 Session& session() const { return _session; }
288 LinkDirection link_direction() const { return _link_direction; }
289 void set_link_direction (LinkDirection);
291 bool linked() const { return _linked; }
292 void set_linked (bool yn);
294 sigc::signal<void> LinkStateChanged;
295 sigc::signal<void> StateChanged; /* for bypass */
297 /* only StreamPanner should call these */
299 void set_position (float x, StreamPanner& orig);
300 void set_position (float x, float y, StreamPanner& orig);
301 void set_position (float x, float y, float z, StreamPanner& orig);
305 string automation_path;
307 uint32_t current_outs;
310 LinkDirection _link_direction;
312 static float current_automation_version_number;
315 } // namespace ARDOUR
317 #endif /*__ardour_panner_h__ */