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, boost::shared_ptr<AutomationList>(new AutomationList(
109 param, 0.0, 1.0, 0.5)), name)
110 , panner (p) { assert(param.type() != NullAutomation); }
112 StreamPanner& panner;
114 void set_value (float);
115 float get_value (void) const;
116 bool can_send_feedback() const;
119 boost::shared_ptr<PanControllable> _control;
121 void add_state (XMLNode&);
122 virtual void update () = 0;
125 class BaseStereoPanner : public StreamPanner
128 BaseStereoPanner (Panner&, Parameter param);
129 ~BaseStereoPanner ();
131 /* this class just leaves the pan law itself to be defined
132 by the update(), distribute_automated()
133 methods. derived classes also need a factory method
134 and a type name. See EqualPowerStereoPanner as an example.
137 void distribute (AudioBuffer& src, BufferSet& obufs, gain_t gain_coeff, nframes_t nframes);
139 /* old school automation loading */
141 int load (istream&, string path, uint32_t&);
152 class EqualPowerStereoPanner : public BaseStereoPanner
155 EqualPowerStereoPanner (Panner&, Parameter param);
156 ~EqualPowerStereoPanner ();
158 void distribute_automated (AudioBuffer& src, BufferSet& obufs,
159 nframes_t start, nframes_t end, nframes_t nframes, pan_t** buffers);
161 void get_current_coefficients (pan_t*) const;
162 void get_desired_coefficients (pan_t*) const;
164 static StreamPanner* factory (Panner&, Parameter param);
167 XMLNode& state (bool full_state);
168 XMLNode& get_state (void);
169 int set_state (const XMLNode&);
175 class Multi2dPanner : public StreamPanner
178 Multi2dPanner (Panner& parent, Parameter);
181 void distribute (AudioBuffer& src, BufferSet& obufs, gain_t gain_coeff, nframes_t nframes);
182 void distribute_automated (AudioBuffer& src, BufferSet& obufs,
183 nframes_t start, nframes_t end, nframes_t nframes, pan_t** buffers);
185 static StreamPanner* factory (Panner&, Parameter);
188 XMLNode& state (bool full_state);
189 XMLNode& get_state (void);
190 int set_state (const XMLNode&);
192 /* old school automation loading */
194 int load (istream&, string path, uint32_t&);
200 class Panner : public std::vector<StreamPanner*>, public PBD::Stateful, public sigc::trackable
209 Output (float xp, float yp)
210 : x (xp), y (yp), current_pan (0.0f), desired_pan (0.f) {}
214 Panner (string name, Session&);
217 /// The fundamental Panner function
218 void distribute(BufferSet& src, BufferSet& dest, nframes_t start_frame, nframes_t end_frames, nframes_t nframes, nframes_t offset);
220 bool bypassed() const { return _bypassed; }
221 void set_bypassed (bool yn);
223 StreamPanner* add ();
224 void remove (uint32_t which);
226 void reset (uint32_t noutputs, uint32_t npans);
228 void snapshot (nframes_t now);
229 void transport_stopped (nframes_t frame);
231 void clear_automation ();
233 void set_automation_state (AutoState);
234 AutoState automation_state() const;
235 void set_automation_style (AutoStyle);
236 AutoStyle automation_style() const;
237 bool touching() const;
239 XMLNode& get_state (void);
240 XMLNode& state (bool full);
241 int set_state (const XMLNode&);
243 sigc::signal<void> Changed;
245 static bool equivalent (pan_t a, pan_t b) {
246 return fabsf (a - b) < 0.002; // about 1 degree of arc for a stereo panner
249 void move_output (uint32_t, float x, float y);
250 uint32_t nouts() const { return outputs.size(); }
251 Output& output (uint32_t n) { return outputs[n]; }
253 std::vector<Output> outputs;
254 Session& session() const { return _session; }
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 sigc::signal<void> LinkStateChanged;
268 sigc::signal<void> StateChanged; /* for bypass */
270 /* only StreamPanner should call these */
272 void set_position (float x, StreamPanner& orig);
273 void set_position (float x, float y, StreamPanner& orig);
274 void set_position (float x, float y, float z, StreamPanner& orig);
276 /* old school automation */
281 void distribute_no_automation(BufferSet& src, BufferSet& dest, nframes_t nframes, nframes_t offset, gain_t gain_coeff);
284 uint32_t current_outs;
287 LinkDirection _link_direction;
289 static float current_automation_version_number;
291 /* old school automation handling */
293 std::string automation_path;
294 void set_name (std::string);
297 } // namespace ARDOUR
299 #endif /*__ardour_panner_h__ */