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__
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>
35 #include <ardour/automation_control.h>
47 class StreamPanner : public sigc::trackable, public PBD::Stateful
50 StreamPanner (Panner& p, Parameter param);
53 void set_muted (bool yn);
54 bool muted() const { return _muted; }
56 void set_position (float x, bool link_call = false);
57 void set_position (float x, float y, bool link_call = false);
58 void set_position (float x, float y, float z, bool link_call = false);
60 void get_position (float& xpos) const { xpos = x; }
61 void get_position (float& xpos, float& ypos) const { xpos = x; ypos = y; }
62 void get_position (float& xpos, float& ypos, float& zpos) const { xpos = x; ypos = y; zpos = z; }
64 void get_effective_position (float& xpos) const { xpos = effective_x; }
65 void get_effective_position (float& xpos, float& ypos) const { xpos = effective_x; ypos = effective_y; }
66 void get_effective_position (float& xpos, float& ypos, float& zpos) const { xpos = effective_x; ypos = effective_y; zpos = effective_z; }
68 /* the basic StreamPanner API */
70 virtual void distribute (AudioBuffer& src, BufferSet& obufs, gain_t gain_coeff, nframes_t nframes) = 0;
71 virtual void distribute_automated (AudioBuffer& src, BufferSet& obufs,
72 nframes_t start, nframes_t end, nframes_t nframes, pan_t** buffers) = 0;
74 boost::shared_ptr<AutomationControl> pan_control() { return _control; }
76 sigc::signal<void> Changed; /* for position */
77 sigc::signal<void> StateChanged; /* for mute */
79 int set_state (const XMLNode&);
80 virtual XMLNode& state (bool full_state) = 0;
82 Panner & get_parent() { return parent; }
84 /* old school automation loading */
86 virtual int load (istream&, string path, uint32_t&) = 0;
96 /* these are for automation. they store the last value
97 used by the most recent process() cycle.
106 struct PanControllable : public AutomationControl {
107 PanControllable (Session& s, std::string name, StreamPanner& p, Parameter param)
108 : AutomationControl (s,
109 boost::shared_ptr<AutomationList>(new AutomationList(param)), name)
111 { assert(param.type() != NullAutomation); }
113 AutomationList* alist() { return (AutomationList*)_list.get(); }
114 StreamPanner& panner;
116 void set_value (float);
117 float get_value (void) const;
118 bool can_send_feedback() const;
121 boost::shared_ptr<PanControllable> _control;
123 void add_state (XMLNode&);
124 virtual void update () = 0;
127 class BaseStereoPanner : public StreamPanner
130 BaseStereoPanner (Panner&, Parameter param);
131 ~BaseStereoPanner ();
133 /* this class just leaves the pan law itself to be defined
134 by the update(), distribute_automated()
135 methods. derived classes also need a factory method
136 and a type name. See EqualPowerStereoPanner as an example.
139 void distribute (AudioBuffer& src, BufferSet& obufs, gain_t gain_coeff, nframes_t nframes);
141 /* old school automation loading */
143 int load (istream&, string path, uint32_t&);
154 class EqualPowerStereoPanner : public BaseStereoPanner
157 EqualPowerStereoPanner (Panner&, Parameter param);
158 ~EqualPowerStereoPanner ();
160 void distribute_automated (AudioBuffer& src, BufferSet& obufs,
161 nframes_t start, nframes_t end, nframes_t nframes, pan_t** buffers);
163 void get_current_coefficients (pan_t*) const;
164 void get_desired_coefficients (pan_t*) const;
166 static StreamPanner* factory (Panner&, Parameter param);
169 XMLNode& state (bool full_state);
170 XMLNode& get_state (void);
171 int set_state (const XMLNode&);
177 class Multi2dPanner : public StreamPanner
180 Multi2dPanner (Panner& parent, Parameter);
183 void distribute (AudioBuffer& src, BufferSet& obufs, gain_t gain_coeff, nframes_t nframes);
184 void distribute_automated (AudioBuffer& src, BufferSet& obufs,
185 nframes_t start, nframes_t end, nframes_t nframes, pan_t** buffers);
187 static StreamPanner* factory (Panner&, Parameter);
190 XMLNode& state (bool full_state);
191 XMLNode& get_state (void);
192 int set_state (const XMLNode&);
194 /* old school automation loading */
196 int load (istream&, string path, uint32_t&);
202 class Panner : public std::vector<StreamPanner*>, public PBD::Stateful, public sigc::trackable
211 Output (float xp, float yp)
212 : x (xp), y (yp), current_pan (0.0f), desired_pan (0.f) {}
216 Panner (string name, Session&);
219 /// The fundamental Panner function
220 void distribute(BufferSet& src, BufferSet& dest, nframes_t start_frame, nframes_t end_frames, nframes_t nframes, nframes_t offset);
222 bool bypassed() const { return _bypassed; }
223 void set_bypassed (bool yn);
225 StreamPanner* add ();
226 void remove (uint32_t which);
228 void reset (uint32_t noutputs, uint32_t npans);
230 void snapshot (nframes_t now);
231 void transport_stopped (nframes_t frame);
233 void clear_automation ();
235 void set_automation_state (AutoState);
236 AutoState automation_state() const;
237 void set_automation_style (AutoStyle);
238 AutoStyle automation_style() const;
239 bool touching() const;
241 XMLNode& get_state (void);
242 XMLNode& state (bool full);
243 int set_state (const XMLNode&);
245 sigc::signal<void> Changed;
247 static bool equivalent (pan_t a, pan_t b) {
248 return fabsf (a - b) < 0.002; // about 1 degree of arc for a stereo panner
251 void move_output (uint32_t, float x, float y);
252 uint32_t nouts() const { return outputs.size(); }
253 Output& output (uint32_t n) { return outputs[n]; }
255 std::vector<Output> outputs;
256 Session& session() const { return _session; }
263 LinkDirection link_direction() const { return _link_direction; }
264 void set_link_direction (LinkDirection);
266 bool linked() const { return _linked; }
267 void set_linked (bool yn);
269 sigc::signal<void> LinkStateChanged;
270 sigc::signal<void> StateChanged; /* for bypass */
272 /* only StreamPanner should call these */
274 void set_position (float x, StreamPanner& orig);
275 void set_position (float x, float y, StreamPanner& orig);
276 void set_position (float x, float y, float z, StreamPanner& orig);
278 /* old school automation */
283 void distribute_no_automation(BufferSet& src, BufferSet& dest, nframes_t nframes, nframes_t offset, gain_t gain_coeff);
286 uint32_t current_outs;
289 LinkDirection _link_direction;
291 static float current_automation_version_number;
293 /* old school automation handling */
295 std::string automation_path;
296 void set_name (std::string);
299 } // namespace ARDOUR
301 #endif /*__ardour_panner_h__ */