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.
20 #ifndef __ardour_panner_h__
21 #define __ardour_panner_h__
27 #include <sigc++/signal.h>
29 #include <pbd/stateful.h>
30 #include <pbd/controllable.h>
32 #include <ardour/types.h>
33 #include <ardour/curve.h>
43 class StreamPanner : public sigc::trackable, public Stateful
46 StreamPanner (Panner& p);
49 void set_muted (bool yn);
50 bool muted() const { return _muted; }
52 void set_position (float x, bool link_call = false);
53 void set_position (float x, float y, bool link_call = false);
54 void set_position (float x, float y, float z, bool link_call = false);
56 void get_position (float& xpos) const { xpos = x; }
57 void get_position (float& xpos, float& ypos) const { xpos = x; ypos = y; }
58 void get_position (float& xpos, float& ypos, float& zpos) const { xpos = x; ypos = y; zpos = z; }
60 void get_effective_position (float& xpos) const { xpos = effective_x; }
61 void get_effective_position (float& xpos, float& ypos) const { xpos = effective_x; ypos = effective_y; }
62 void get_effective_position (float& xpos, float& ypos, float& zpos) const { xpos = effective_x; ypos = effective_y; zpos = effective_z; }
64 /* the basic panner API */
66 virtual void distribute (Sample* src, Sample** obufs, gain_t gain_coeff, nframes_t nframes) = 0;
67 virtual void distribute_automated (Sample* src, Sample** obufs,
68 nframes_t start, nframes_t end, nframes_t nframes, pan_t** buffers) = 0;
72 virtual void snapshot (nframes_t now) = 0;
73 virtual void transport_stopped (nframes_t frame) = 0;
74 virtual void set_automation_state (AutoState) = 0;
75 virtual void set_automation_style (AutoStyle) = 0;
77 PBD::Controllable& control() { return _control; }
79 /* XXX this is wrong. for multi-dimensional panners, there
80 must surely be more than 1 automation curve.
83 virtual Curve& automation() = 0;
85 sigc::signal<void> Changed; /* for position */
86 sigc::signal<void> StateChanged; /* for mute */
88 int set_state (const XMLNode&);
89 virtual XMLNode& state (bool full_state) = 0;
91 Panner & get_parent() { return parent; }
93 /* old school automation loading */
95 virtual int load (istream&, string path, uint32_t&) = 0;
105 /* these are for automation. they store the last value
106 used by the most recent process() cycle.
115 struct PanControllable : public PBD::Controllable {
116 PanControllable (std::string name, StreamPanner& p) : Controllable (name), panner (p) {}
118 StreamPanner& panner;
120 void set_value (float);
121 float get_value (void) const;
122 bool can_send_feedback() const;
125 PanControllable _control;
127 void add_state (XMLNode&);
128 virtual void update () = 0;
131 class BaseStereoPanner : public StreamPanner
134 BaseStereoPanner (Panner&);
135 ~BaseStereoPanner ();
137 /* this class just leaves the pan law itself to be defined
138 by the update(), distribute_automated()
139 methods. derived classes also need a factory method
140 and a type name. See EqualPowerStereoPanner as an example.
143 void distribute (Sample* src, Sample** obufs, gain_t gain_coeff, nframes_t nframes);
145 void snapshot (nframes_t now);
146 void transport_stopped (nframes_t frame);
147 void set_automation_state (AutoState);
148 void set_automation_style (AutoStyle);
150 Curve& automation() { return _automation; }
152 /* old school automation loading */
154 int load (istream&, string path, uint32_t&);
167 class EqualPowerStereoPanner : public BaseStereoPanner
170 EqualPowerStereoPanner (Panner&);
171 ~EqualPowerStereoPanner ();
173 void distribute_automated (Sample* src, Sample** obufs,
174 nframes_t start, nframes_t end, nframes_t nframes, pan_t** buffers);
176 void get_current_coefficients (pan_t*) const;
177 void get_desired_coefficients (pan_t*) const;
179 static StreamPanner* factory (Panner&);
182 XMLNode& state (bool full_state);
183 XMLNode& get_state (void);
184 int set_state (const XMLNode&);
190 class Multi2dPanner : public StreamPanner
193 Multi2dPanner (Panner& parent);
196 void snapshot (nframes_t now);
197 void transport_stopped (nframes_t frame);
198 void set_automation_state (AutoState);
199 void set_automation_style (AutoStyle);
201 /* XXX this is wrong. for multi-dimensional panners, there
202 must surely be more than 1 automation curve.
205 Curve& automation() { return _automation; }
207 void distribute (Sample* src, Sample** obufs, gain_t gain_coeff, nframes_t nframes);
208 void distribute_automated (Sample* src, Sample** obufs,
209 nframes_t start, nframes_t end, nframes_t nframes, pan_t** buffers);
211 static StreamPanner* factory (Panner&);
214 XMLNode& state (bool full_state);
215 XMLNode& get_state (void);
216 int set_state (const XMLNode&);
218 /* old school automation loading */
220 int load (istream&, string path, uint32_t&);
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 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;
263 XMLNode& get_state (void);
264 XMLNode& state (bool full);
265 int set_state (const XMLNode&);
267 sigc::signal<void> Changed;
269 static bool equivalent (pan_t a, pan_t b) {
270 return fabsf (a - b) < 0.002; // about 1 degree of arc for a stereo panner
273 void move_output (uint32_t, float x, float y);
274 uint32_t nouts() const { return outputs.size(); }
275 Output& output (uint32_t n) { return outputs[n]; }
277 std::vector<Output> outputs;
278 Session& session() const { return _session; }
285 LinkDirection link_direction() const { return _link_direction; }
286 void set_link_direction (LinkDirection);
288 bool linked() const { return _linked; }
289 void set_linked (bool yn);
291 sigc::signal<void> LinkStateChanged;
292 sigc::signal<void> StateChanged; /* for bypass */
294 /* only StreamPanner should call these */
296 void set_position (float x, StreamPanner& orig);
297 void set_position (float x, float y, StreamPanner& orig);
298 void set_position (float x, float y, float z, StreamPanner& orig);
300 /* old school automation */
307 uint32_t current_outs;
310 LinkDirection _link_direction;
312 static float current_automation_version_number;
314 /* old school automation handling */
316 std::string automation_path;
317 void set_name (std::string);
320 } // namespace ARDOUR
322 #endif /*__ardour_panner_h__ */