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/automation_control.h"
35 #include "ardour/processor.h"
44 class StreamPanner : public sigc::trackable, public PBD::Stateful
47 StreamPanner (Panner& p, Evoral::Parameter param);
50 void set_muted (bool yn);
51 bool muted() const { return _muted; }
54 void set_position (float x, bool link_call = false);
55 void set_position (float x, float y, bool link_call = false);
56 void set_position (float x, float y, float z, bool link_call = false);
58 void get_position (float& xpos) const { xpos = x; }
59 void get_position (float& xpos, float& ypos) const { xpos = x; ypos = y; }
60 void get_position (float& xpos, float& ypos, float& zpos) const { xpos = x; ypos = y; zpos = z; }
62 void get_effective_position (float& xpos) const { xpos = effective_x; }
63 void get_effective_position (float& xpos, float& ypos) const { xpos = effective_x; ypos = effective_y; }
64 void get_effective_position (float& xpos, float& ypos, float& zpos) const { xpos = effective_x; ypos = effective_y; zpos = effective_z; }
66 void distribute (AudioBuffer &, BufferSet &, gain_t, nframes_t);
67 void distribute_automated (AudioBuffer &, BufferSet &, nframes_t, nframes_t, nframes_t, pan_t **);
69 /* the basic StreamPanner API */
72 * Pan some input samples to a number of output buffers.
74 * @param src Input buffer.
75 * @param obufs Output buffers (one per panner output).
76 * @param gain_coeff Gain coefficient to apply to output samples.
77 * @param nframes Numbner of frames in the input.
79 virtual void do_distribute (AudioBuffer& src, BufferSet& obufs, gain_t gain_coeff, nframes_t nframes) = 0;
80 virtual void do_distribute_automated (AudioBuffer& src, BufferSet& obufs,
81 nframes_t start, nframes_t end, nframes_t nframes, pan_t** buffers) = 0;
83 boost::shared_ptr<AutomationControl> pan_control() { return _control; }
85 sigc::signal<void> Changed; /* for position */
86 sigc::signal<void> StateChanged; /* for mute */
88 int set_state (const XMLNode&, int version);
89 virtual XMLNode& state (bool full_state) = 0;
91 Panner & get_parent() { return parent; }
93 /* old school automation loading */
95 virtual int load (std::istream&, std::string path, uint32_t&) = 0;
105 /* these are for automation. they store the last value
106 used by the most recent process() cycle.
116 boost::shared_ptr<AutomationControl> _control;
118 void add_state (XMLNode&);
119 virtual void update () = 0;
122 class BaseStereoPanner : public StreamPanner
125 BaseStereoPanner (Panner&, Evoral::Parameter param);
126 ~BaseStereoPanner ();
128 /* this class just leaves the pan law itself to be defined
129 by the update(), do_distribute_automated()
130 methods. derived classes also need a factory method
131 and a type name. See EqualPowerStereoPanner as an example.
134 void do_distribute (AudioBuffer& src, BufferSet& obufs, gain_t gain_coeff, nframes_t nframes);
136 /* old school automation loading */
138 int load (std::istream&, std::string path, uint32_t&);
149 class EqualPowerStereoPanner : public BaseStereoPanner
152 EqualPowerStereoPanner (Panner&, Evoral::Parameter param);
153 ~EqualPowerStereoPanner ();
155 void do_distribute_automated (AudioBuffer& src, BufferSet& obufs,
156 nframes_t start, nframes_t end, nframes_t nframes, pan_t** buffers);
158 void get_current_coefficients (pan_t*) const;
159 void get_desired_coefficients (pan_t*) const;
161 static StreamPanner* factory (Panner&, Evoral::Parameter param);
162 static std::string name;
164 XMLNode& state (bool full_state);
165 XMLNode& get_state (void);
166 int set_state (const XMLNode&, int version);
172 class Multi2dPanner : public StreamPanner
175 Multi2dPanner (Panner& parent, Evoral::Parameter);
178 void do_distribute (AudioBuffer& src, BufferSet& obufs, gain_t gain_coeff, nframes_t nframes);
179 void do_distribute_automated (AudioBuffer& src, BufferSet& obufs,
180 nframes_t start, nframes_t end, nframes_t nframes, pan_t** buffers);
182 static StreamPanner* factory (Panner&, Evoral::Parameter);
183 static std::string name;
185 XMLNode& state (bool full_state);
186 XMLNode& get_state (void);
187 int set_state (const XMLNode&, int version);
189 /* old school automation loading */
191 int load (std::istream&, std::string path, uint32_t&);
198 ///< Class to pan from some number of inputs to some number of outputs
200 class Panner : public SessionObject, public AutomatableControls
209 Output (float xp, float yp)
210 : x (xp), y (yp), current_pan (0.0f), desired_pan (0.f) {}
214 //Panner (std::string name, Session&, int _num_bufs);
215 Panner (std::string name, Session&);
218 void clear_panners ();
219 bool empty() const { return _streampanners.empty(); }
221 void set_automation_state (AutoState);
222 AutoState automation_state() const;
223 void set_automation_style (AutoStyle);
224 AutoStyle automation_style() const;
225 bool touching() const;
227 bool can_support_io_configuration (const ChanCount& /*in*/, ChanCount& /*out*/) const { return true; };
229 /// The fundamental Panner function
230 void run (BufferSet& src, BufferSet& dest, sframes_t start_frame, sframes_t end_frames, nframes_t nframes);
232 //void* get_inline_gui() const = 0;
233 //void* get_full_gui() const = 0;
235 bool bypassed() const { return _bypassed; }
236 void set_bypassed (bool yn);
237 bool mono () const { return _mono; }
238 void set_mono (bool);
240 StreamPanner* add ();
241 void remove (uint32_t which);
242 void reset (uint32_t noutputs, uint32_t npans);
243 void reset_streampanner (uint32_t which_panner);
244 void reset_to_default ();
246 XMLNode& get_state (void);
247 XMLNode& state (bool full);
248 int set_state (const XMLNode&, int version);
250 static bool equivalent (pan_t a, pan_t b) {
251 return fabsf (a - b) < 0.002; // about 1 degree of arc for a stereo panner
254 void move_output (uint32_t, float x, float y);
255 uint32_t nouts() const { return outputs.size(); }
256 Output& output (uint32_t n) { return outputs[n]; }
258 std::vector<Output> outputs;
265 LinkDirection link_direction() const { return _link_direction; }
266 void set_link_direction (LinkDirection);
268 bool linked() const { return _linked; }
269 void set_linked (bool yn);
271 StreamPanner &streampanner( uint32_t n ) const { assert( n < _streampanners.size() ); return *_streampanners[n]; }
272 uint32_t npanners() const { return _streampanners.size(); }
274 sigc::signal<void> Changed;
275 sigc::signal<void> LinkStateChanged;
276 sigc::signal<void> StateChanged; /* for bypass */
278 /* only StreamPanner should call these */
280 void set_position (float x, StreamPanner& orig);
281 void set_position (float x, float y, StreamPanner& orig);
282 void set_position (float x, float y, float z, StreamPanner& orig);
284 /* old school automation */
288 struct PanControllable : public AutomationControl {
289 PanControllable (Session& s, std::string name, Panner& p, Evoral::Parameter param)
290 : AutomationControl (s, param,
291 boost::shared_ptr<AutomationList>(new AutomationList(param)), name)
293 { assert(param.type() != NullAutomation); }
295 AutomationList* alist() { return (AutomationList*)_list.get(); }
298 void set_value (float);
299 float get_value (void) const;
302 boost::shared_ptr<AutomationControl> pan_control (int id, int chan=0) {
303 return automation_control(Evoral::Parameter (PanAutomation, chan, id));
306 boost::shared_ptr<const AutomationControl> pan_control (int id, int chan=0) const {
307 return automation_control(Evoral::Parameter (PanAutomation, chan, id));
311 /* disallow copy construction */
312 Panner (Panner const &);
314 void distribute_no_automation(BufferSet& src, BufferSet& dest, nframes_t nframes, gain_t gain_coeff);
315 std::vector<StreamPanner*> _streampanners; ///< one StreamPanner per input
316 uint32_t current_outs;
320 LinkDirection _link_direction;
322 static float current_automation_version_number;
324 /* old school automation handling */
326 std::string automation_path;
329 } // namespace ARDOUR
331 #endif /*__ardour_panner_h__ */