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 sigc::signal<void> Changed; /* for position */
87 sigc::signal<void> StateChanged; /* for mute */
89 int set_state (const XMLNode&);
90 virtual XMLNode& state (bool full_state) = 0;
92 Panner & get_parent() { return parent; }
102 /* these are for automation. they store the last value
103 used by the most recent process() cycle.
112 struct PanControllable : public PBD::Controllable {
113 PanControllable (std::string name, StreamPanner& p) : Controllable (name), panner (p) {}
115 StreamPanner& panner;
117 void set_value (float);
118 float get_value (void) const;
119 bool can_send_feedback() const;
122 PanControllable _control;
124 void add_state (XMLNode&);
125 virtual void update () = 0;
128 class BaseStereoPanner : public StreamPanner
131 BaseStereoPanner (Panner&);
132 ~BaseStereoPanner ();
134 /* this class just leaves the pan law itself to be defined
135 by the update(), distribute_automated()
136 methods. derived classes also need a factory method
137 and a type name. See EqualPowerStereoPanner as an example.
140 void distribute (Sample* src, Sample** obufs, gain_t gain_coeff, nframes_t nframes);
142 void snapshot (nframes_t now);
143 void transport_stopped (nframes_t frame);
144 void set_automation_state (AutoState);
145 void set_automation_style (AutoStyle);
147 Curve& automation() { return _automation; }
160 class EqualPowerStereoPanner : public BaseStereoPanner
163 EqualPowerStereoPanner (Panner&);
164 ~EqualPowerStereoPanner ();
166 void distribute_automated (Sample* src, Sample** obufs,
167 nframes_t start, nframes_t end, nframes_t nframes, pan_t** buffers);
169 void get_current_coefficients (pan_t*) const;
170 void get_desired_coefficients (pan_t*) const;
172 static StreamPanner* factory (Panner&);
175 XMLNode& state (bool full_state);
176 XMLNode& get_state (void);
177 int set_state (const XMLNode&);
183 class Multi2dPanner : public StreamPanner
186 Multi2dPanner (Panner& parent);
189 void snapshot (nframes_t now);
190 void transport_stopped (nframes_t frame);
191 void set_automation_state (AutoState);
192 void set_automation_style (AutoStyle);
194 /* XXX this is wrong. for multi-dimensional panners, there
195 must surely be more than 1 automation curve.
198 Curve& automation() { return _automation; }
200 void distribute (Sample* src, Sample** obufs, gain_t gain_coeff, nframes_t nframes);
201 void distribute_automated (Sample* src, Sample** obufs,
202 nframes_t start, nframes_t end, nframes_t nframes, pan_t** buffers);
204 static StreamPanner* factory (Panner&);
207 XMLNode& state (bool full_state);
208 XMLNode& get_state (void);
209 int set_state (const XMLNode&);
216 class Panner : public std::vector<StreamPanner*>, public Stateful, public sigc::trackable
225 Output (float xp, float yp)
226 : x (xp), y (yp), current_pan (0.0f), desired_pan (0.f) {}
230 Panner (string name, Session&);
233 bool bypassed() const { return _bypassed; }
234 void set_bypassed (bool yn);
236 StreamPanner* add ();
237 void remove (uint32_t which);
239 void reset (uint32_t noutputs, uint32_t npans);
241 void snapshot (nframes_t now);
242 void transport_stopped (nframes_t frame);
244 void clear_automation ();
246 void set_automation_state (AutoState);
247 AutoState automation_state() const;
248 void set_automation_style (AutoStyle);
249 AutoStyle automation_style() const;
250 bool touching() const;
252 XMLNode& get_state (void);
253 XMLNode& state (bool full);
254 int set_state (const XMLNode&);
256 sigc::signal<void> Changed;
258 static bool equivalent (pan_t a, pan_t b) {
259 return fabsf (a - b) < 0.002; // about 1 degree of arc for a stereo panner
262 void move_output (uint32_t, float x, float y);
263 uint32_t nouts() const { return outputs.size(); }
264 Output& output (uint32_t n) { return outputs[n]; }
266 std::vector<Output> outputs;
267 Session& session() const { return _session; }
274 LinkDirection link_direction() const { return _link_direction; }
275 void set_link_direction (LinkDirection);
277 bool linked() const { return _linked; }
278 void set_linked (bool yn);
280 sigc::signal<void> LinkStateChanged;
281 sigc::signal<void> StateChanged; /* for bypass */
283 /* only StreamPanner should call these */
285 void set_position (float x, StreamPanner& orig);
286 void set_position (float x, float y, StreamPanner& orig);
287 void set_position (float x, float y, float z, StreamPanner& orig);
292 uint32_t current_outs;
295 LinkDirection _link_direction;
297 static float current_automation_version_number;
300 } // namespace ARDOUR
302 #endif /*__ardour_panner_h__ */