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__
29 #include "pbd/stateful.h"
30 #include "pbd/controllable.h"
32 #include "ardour/types.h"
33 #include "ardour/automation_control.h"
34 #include "ardour/processor.h"
43 class StreamPanner : public PBD::Stateful
46 StreamPanner (Panner& p, Evoral::Parameter param);
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 void distribute (AudioBuffer &, BufferSet &, gain_t, nframes_t);
65 void distribute_automated (AudioBuffer &, BufferSet &, nframes_t, nframes_t, nframes_t, pan_t **);
67 /* the basic StreamPanner API */
70 * Pan some input samples to a number of output buffers.
72 * @param src Input buffer.
73 * @param obufs Output buffers (one per panner output).
74 * @param gain_coeff Gain coefficient to apply to output samples.
75 * @param nframes Number of frames in the input.
77 virtual void do_distribute (AudioBuffer& src, BufferSet& obufs, gain_t gain_coeff, nframes_t nframes) = 0;
78 virtual void do_distribute_automated (AudioBuffer& src, BufferSet& obufs,
79 nframes_t start, nframes_t end, nframes_t nframes, pan_t** buffers) = 0;
81 boost::shared_ptr<AutomationControl> pan_control() { return _control; }
83 PBD::Signal0<void> Changed; /* for position */
84 PBD::Signal0<void> StateChanged; /* for mute, mono */
86 int set_state (const XMLNode&, int version);
87 virtual XMLNode& state (bool full_state) = 0;
89 Panner & get_parent() { return parent; }
91 /* old school automation loading */
92 virtual int load (std::istream&, std::string path, uint32_t&) = 0;
104 /* these are for automation. they store the last value
105 used by the most recent process() cycle.
115 boost::shared_ptr<AutomationControl> _control;
117 void add_state (XMLNode&);
119 /* Update internal parameters based on _x, _y and _z */
120 virtual void update () = 0;
123 class BaseStereoPanner : public StreamPanner
126 BaseStereoPanner (Panner&, Evoral::Parameter param);
127 ~BaseStereoPanner ();
129 /* this class just leaves the pan law itself to be defined
130 by the update(), do_distribute_automated()
131 methods. derived classes also need a factory method
132 and a type name. See EqualPowerStereoPanner as an example.
135 void do_distribute (AudioBuffer& src, BufferSet& obufs, gain_t gain_coeff, nframes_t nframes);
137 /* old school automation loading */
139 int load (std::istream&, std::string path, uint32_t&);
150 class EqualPowerStereoPanner : public BaseStereoPanner
153 EqualPowerStereoPanner (Panner&, Evoral::Parameter param);
154 ~EqualPowerStereoPanner ();
156 void do_distribute_automated (AudioBuffer& src, BufferSet& obufs,
157 nframes_t start, nframes_t end, nframes_t nframes, pan_t** buffers);
159 void get_current_coefficients (pan_t*) const;
160 void get_desired_coefficients (pan_t*) const;
162 static StreamPanner* factory (Panner&, Evoral::Parameter param);
163 static std::string name;
165 XMLNode& state (bool full_state);
166 XMLNode& get_state (void);
167 int set_state (const XMLNode&, int version);
173 class Multi2dPanner : public StreamPanner
176 Multi2dPanner (Panner& parent, Evoral::Parameter);
179 void do_distribute (AudioBuffer& src, BufferSet& obufs, gain_t gain_coeff, nframes_t nframes);
180 void do_distribute_automated (AudioBuffer& src, BufferSet& obufs,
181 nframes_t start, nframes_t end, nframes_t nframes, pan_t** buffers);
183 static StreamPanner* factory (Panner&, Evoral::Parameter);
184 static std::string name;
186 XMLNode& state (bool full_state);
187 XMLNode& get_state (void);
188 int set_state (const XMLNode&, int version);
190 /* old school automation loading */
192 int load (std::istream&, std::string path, uint32_t&);
199 /** Class to pan from some number of inputs to some number of outputs.
200 * This class has a number of StreamPanners, one for each input.
202 class Panner : public SessionObject, public Automatable
211 Output (float xp, float yp)
212 : x (xp), y (yp), current_pan (0), desired_pan (0) {}
216 Panner (std::string name, Session&);
219 void clear_panners ();
220 bool empty() const { return _streampanners.empty(); }
222 void set_automation_state (AutoState);
223 AutoState automation_state() const;
224 void set_automation_style (AutoStyle);
225 AutoStyle automation_style() const;
226 bool touching() const;
228 bool can_support_io_configuration (const ChanCount& /*in*/, ChanCount& /*out*/) const { return true; };
230 /// The fundamental Panner function
231 void run (BufferSet& src, BufferSet& dest, framepos_t start_frame, framepos_t end_frames, nframes_t nframes);
233 bool bypassed() const { return _bypassed; }
234 void set_bypassed (bool yn);
235 bool mono () const { return _mono; }
236 void set_mono (bool);
238 StreamPanner* add ();
239 void remove (uint32_t which);
240 void reset (uint32_t noutputs, uint32_t npans);
241 void reset_streampanner (uint32_t which_panner);
242 void reset_to_default ();
244 XMLNode& get_state (void);
245 XMLNode& state (bool full);
246 int set_state (const XMLNode&, int version);
248 static bool equivalent (pan_t a, pan_t b) {
249 return fabsf (a - b) < 0.002; // about 1 degree of arc for a stereo panner
252 void move_output (uint32_t, float x, float y);
253 uint32_t nouts() const { return outputs.size(); }
254 Output& output (uint32_t n) { return outputs[n]; }
261 LinkDirection link_direction() const { return _link_direction; }
262 void set_link_direction (LinkDirection);
264 bool linked() const { return _linked; }
265 void set_linked (bool yn);
267 StreamPanner &streampanner( uint32_t n ) const { assert( n < _streampanners.size() ); return *_streampanners[n]; }
268 uint32_t npanners() const { return _streampanners.size(); }
270 PBD::Signal0<void> Changed; /* panner and/or outputs count changed */
271 PBD::Signal0<void> LinkStateChanged;
272 PBD::Signal0<void> StateChanged; /* for bypass */
274 /* only StreamPanner should call these */
276 void set_position (float x, StreamPanner& orig);
277 void set_position (float x, float y, StreamPanner& orig);
278 void set_position (float x, float y, float z, StreamPanner& orig);
280 /* old school automation */
284 struct PanControllable : public AutomationControl {
285 PanControllable (Session& s, std::string name, Panner& p, Evoral::Parameter param)
286 : AutomationControl (s, param,
287 boost::shared_ptr<AutomationList>(new AutomationList(param)), name)
289 { assert(param.type() != NullAutomation); }
291 AutomationList* alist() { return (AutomationList*)_list.get(); }
294 void set_value (double);
295 double get_value (void) const;
298 boost::shared_ptr<AutomationControl> pan_control (int id, int chan=0) {
299 return automation_control (Evoral::Parameter (PanAutomation, chan, id));
302 boost::shared_ptr<const AutomationControl> pan_control (int id, int chan=0) const {
303 return automation_control (Evoral::Parameter (PanAutomation, chan, id));
306 static std::string value_as_string (double);
309 /* disallow copy construction */
310 Panner (Panner const &);
312 void distribute_no_automation(BufferSet& src, BufferSet& dest, nframes_t nframes, gain_t gain_coeff);
313 std::vector<StreamPanner*> _streampanners; ///< one StreamPanner per input
314 std::vector<Output> outputs;
315 uint32_t current_outs;
319 LinkDirection _link_direction;
321 static float current_automation_version_number;
323 /* old school automation handling */
325 std::string automation_path;
328 } // namespace ARDOUR
330 #endif /*__ardour_panner_h__ */