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"
31 #include "pbd/cartesian.h"
33 #include "ardour/types.h"
34 #include "ardour/automation_control.h"
35 #include "ardour/processor.h"
45 class StreamPanner : public PBD::Stateful
48 StreamPanner (Panner& p, Evoral::Parameter param);
51 void set_muted (bool yn);
52 bool muted() const { return _muted; }
54 const PBD::AngularVector& get_position() const { return _angles; }
55 const PBD::AngularVector& get_effective_position() const { return _effective_angles; }
56 void set_position (const PBD::AngularVector&, bool link_call = false);
57 void set_diffusion (double);
59 void distribute (AudioBuffer &, BufferSet &, gain_t, pframes_t);
60 void distribute_automated (AudioBuffer &, BufferSet &, framepos_t, framepos_t, pframes_t, pan_t **);
62 /* the basic StreamPanner API */
65 * Pan some input samples to a number of output buffers.
67 * @param src Input buffer.
68 * @param obufs Output buffers (one per panner output).
69 * @param gain_coeff Gain coefficient to apply to output samples.
70 * @param nframes Number of frames in the input.
72 virtual void do_distribute (AudioBuffer& src, BufferSet& obufs, gain_t gain_coeff, pframes_t nframes) = 0;
73 virtual void do_distribute_automated (AudioBuffer& src, BufferSet& obufs,
74 framepos_t start, framepos_t end, pframes_t nframes,
77 boost::shared_ptr<AutomationControl> pan_control() { return _control; }
79 PBD::Signal0<void> Changed; /* for position or diffusion */
80 PBD::Signal0<void> StateChanged; /* for mute, mono */
82 int set_state (const XMLNode&, int version);
83 virtual XMLNode& state (bool full_state) = 0;
85 Panner & get_parent() { return parent; }
87 /* old school automation loading */
88 virtual int load (std::istream&, std::string path, uint32_t&) = 0;
90 struct PanControllable : public AutomationControl {
91 PanControllable (Session& s, std::string name, StreamPanner* p, Evoral::Parameter param)
92 : AutomationControl (s, param,
93 boost::shared_ptr<AutomationList>(new AutomationList(param)), name)
95 { assert (param.type() == PanAutomation); }
97 AutomationList* alist() { return (AutomationList*)_list.get(); }
98 StreamPanner* streampanner;
100 void set_value (double);
101 double get_value (void) const;
102 double lower () const;
109 void set_mono (bool);
111 PBD::AngularVector _angles;
112 PBD::AngularVector _effective_angles;
118 boost::shared_ptr<AutomationControl> _control;
120 XMLNode& get_state ();
122 /* Update internal parameters based on this.angles */
123 virtual void update () = 0;
126 class BaseStereoPanner : public StreamPanner
129 BaseStereoPanner (Panner&, Evoral::Parameter param);
130 ~BaseStereoPanner ();
132 /* this class just leaves the pan law itself to be defined
133 by the update(), do_distribute_automated()
134 methods. derived classes also need a factory method
135 and a type name. See EqualPowerStereoPanner as an example.
138 void do_distribute (AudioBuffer& src, BufferSet& obufs, gain_t gain_coeff, pframes_t nframes);
140 static double azimuth_to_lr_fract (double azi) {
141 /* 180.0 degrees=> left => 0.0 */
142 /* 0.0 degrees => right => 1.0 */
144 /* humans can only distinguish 1 degree of arc between two positions,
145 so force azi back to an integral value before computing
148 return 1.0 - (rint(azi)/180.0);
151 static double lr_fract_to_azimuth (double fract) {
152 /* fract = 0.0 => degrees = 180.0 => left */
153 /* fract = 1.0 => degrees = 0.0 => right */
155 /* humans can only distinguish 1 degree of arc between two positions,
156 so force azi back to an integral value after computing
159 return rint (180.0 - (fract * 180.0));
162 /* old school automation loading */
164 int load (std::istream&, std::string path, uint32_t&);
175 class EqualPowerStereoPanner : public BaseStereoPanner
178 EqualPowerStereoPanner (Panner&, Evoral::Parameter param);
179 ~EqualPowerStereoPanner ();
181 void do_distribute_automated (AudioBuffer& src, BufferSet& obufs,
182 framepos_t start, framepos_t end, pframes_t nframes,
185 void get_current_coefficients (pan_t*) const;
186 void get_desired_coefficients (pan_t*) const;
188 static StreamPanner* factory (Panner&, Evoral::Parameter param, Speakers&);
189 static std::string name;
191 XMLNode& state (bool full_state);
192 XMLNode& get_state (void);
193 int set_state (const XMLNode&, int version);
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
206 PBD::AngularVector position;
210 Output (const PBD::AngularVector& a)
211 : position (a), current_pan (0), desired_pan (0) {}
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 std::string describe_parameter (Evoral::Parameter param);
229 bool can_support_io_configuration (const ChanCount& /*in*/, ChanCount& /*out*/) const { return true; };
231 /// The fundamental Panner function
232 void run (BufferSet& src, BufferSet& dest, framepos_t start_frame, framepos_t end_frames, pframes_t nframes);
234 bool bypassed() const { return _bypassed; }
235 void set_bypassed (bool yn);
236 bool mono () const { return _mono; }
237 void set_mono (bool);
239 StreamPanner* add ();
240 void remove (uint32_t which);
241 void reset (uint32_t noutputs, uint32_t npans);
242 void reset_streampanner (uint32_t which_panner);
243 void reset_to_default ();
245 XMLNode& get_state (void);
246 XMLNode& state (bool full);
247 int set_state (const XMLNode&, int version);
249 static bool equivalent (pan_t a, pan_t b) {
250 return fabsf (a - b) < 0.002; // about 1 degree of arc for a stereo panner
252 static bool equivalent (const PBD::AngularVector& a, const PBD::AngularVector& b) {
253 /* XXX azimuth only, at present */
254 return fabs (a.azi - b.azi) < 1.0;
257 void move_output (uint32_t, float x, float y);
258 uint32_t nouts() const { return outputs.size(); }
259 Output& output (uint32_t n) { return outputs[n]; }
266 LinkDirection link_direction() const { return _link_direction; }
267 void set_link_direction (LinkDirection);
269 bool linked() const { return _linked; }
270 void set_linked (bool yn);
272 StreamPanner &streampanner( uint32_t n ) const { assert( n < _streampanners.size() ); return *_streampanners[n]; }
273 uint32_t npanners() const { return _streampanners.size(); }
275 PBD::Signal0<void> Changed; /* panner and/or outputs count changed */
276 PBD::Signal0<void> LinkStateChanged;
277 PBD::Signal0<void> StateChanged; /* for bypass */
279 /* only StreamPanner should call these */
281 void set_position (const PBD::AngularVector&, StreamPanner& orig);
283 /* old school automation */
287 boost::shared_ptr<AutomationControl> pan_control (int id, uint32_t chan=0) {
288 return automation_control (Evoral::Parameter (PanAutomation, chan, id));
291 boost::shared_ptr<const AutomationControl> pan_control (int id, uint32_t chan=0) const {
292 return automation_control (Evoral::Parameter (PanAutomation, chan, id));
295 boost::shared_ptr<AutomationControl> direction_control () {
296 return automation_control (Evoral::Parameter (PanAutomation, 0, 100));
299 boost::shared_ptr<AutomationControl> width_control () {
300 return automation_control (Evoral::Parameter (PanAutomation, 0, 200));
303 void set_stereo_position (double);
304 void set_stereo_width (double);
305 bool set_stereo_pan (double pos, double width);
307 static std::string value_as_string (double);
310 /* disallow copy construction */
311 Panner (Panner const &);
313 void distribute_no_automation(BufferSet& src, BufferSet& dest, pframes_t nframes, gain_t gain_coeff);
314 std::vector<StreamPanner*> _streampanners; ///< one StreamPanner per input
315 std::vector<Output> outputs;
316 uint32_t current_outs;
320 LinkDirection _link_direction;
322 static float current_automation_version_number;
324 void setup_speakers (uint32_t nouts);
325 void setup_meta_controls ();
327 /* old school automation handling */
329 std::string automation_path;
332 } // namespace ARDOUR
334 #endif /*__ardour_panner_h__ */