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>
48 class StreamPanner : public sigc::trackable, public PBD::Stateful
51 StreamPanner (Panner& p, Evoral::Parameter param);
54 void set_muted (bool yn);
55 bool muted() const { return _muted; }
57 void set_position (float x, bool link_call = false);
58 void set_position (float x, float y, bool link_call = false);
59 void set_position (float x, float y, float z, bool link_call = false);
61 void get_position (float& xpos) const { xpos = x; }
62 void get_position (float& xpos, float& ypos) const { xpos = x; ypos = y; }
63 void get_position (float& xpos, float& ypos, float& zpos) const { xpos = x; ypos = y; zpos = z; }
65 void get_effective_position (float& xpos) const { xpos = effective_x; }
66 void get_effective_position (float& xpos, float& ypos) const { xpos = effective_x; ypos = effective_y; }
67 void get_effective_position (float& xpos, float& ypos, float& zpos) const { xpos = effective_x; ypos = effective_y; zpos = effective_z; }
69 /* the basic StreamPanner API */
71 virtual void distribute (AudioBuffer& src, BufferSet& obufs, gain_t gain_coeff, nframes_t nframes) = 0;
72 virtual void distribute_automated (AudioBuffer& src, BufferSet& obufs,
73 nframes_t start, nframes_t end, nframes_t nframes, pan_t** buffers) = 0;
75 boost::shared_ptr<AutomationControl> pan_control() { return _control; }
77 sigc::signal<void> Changed; /* for position */
78 sigc::signal<void> StateChanged; /* for mute */
80 int set_state (const XMLNode&);
81 virtual XMLNode& state (bool full_state) = 0;
83 Panner & get_parent() { return parent; }
85 /* old school automation loading */
87 virtual int load (istream&, string path, uint32_t&) = 0;
97 /* these are for automation. they store the last value
98 used by the most recent process() cycle.
107 boost::shared_ptr<AutomationControl> _control;
109 void add_state (XMLNode&);
110 virtual void update () = 0;
113 class BaseStereoPanner : public StreamPanner
116 BaseStereoPanner (Panner&, Evoral::Parameter param);
117 ~BaseStereoPanner ();
119 /* this class just leaves the pan law itself to be defined
120 by the update(), distribute_automated()
121 methods. derived classes also need a factory method
122 and a type name. See EqualPowerStereoPanner as an example.
125 void distribute (AudioBuffer& src, BufferSet& obufs, gain_t gain_coeff, nframes_t nframes);
127 /* old school automation loading */
129 int load (istream&, string path, uint32_t&);
140 class EqualPowerStereoPanner : public BaseStereoPanner
143 EqualPowerStereoPanner (Panner&, Evoral::Parameter param);
144 ~EqualPowerStereoPanner ();
146 void distribute_automated (AudioBuffer& src, BufferSet& obufs,
147 nframes_t start, nframes_t end, nframes_t nframes, pan_t** buffers);
149 void get_current_coefficients (pan_t*) const;
150 void get_desired_coefficients (pan_t*) const;
152 static StreamPanner* factory (Panner&, Evoral::Parameter param);
155 XMLNode& state (bool full_state);
156 XMLNode& get_state (void);
157 int set_state (const XMLNode&);
163 class Multi2dPanner : public StreamPanner
166 Multi2dPanner (Panner& parent, Evoral::Parameter);
169 void distribute (AudioBuffer& src, BufferSet& obufs, gain_t gain_coeff, nframes_t nframes);
170 void distribute_automated (AudioBuffer& src, BufferSet& obufs,
171 nframes_t start, nframes_t end, nframes_t nframes, pan_t** buffers);
173 static StreamPanner* factory (Panner&, Evoral::Parameter);
176 XMLNode& state (bool full_state);
177 XMLNode& get_state (void);
178 int set_state (const XMLNode&);
180 /* old school automation loading */
182 int load (istream&, string path, uint32_t&);
189 class Panner : public Processor
198 Output (float xp, float yp)
199 : x (xp), y (yp), current_pan (0.0f), desired_pan (0.f) {}
203 //Panner (std::string name, Session&, int _num_bufs);
204 Panner (string name, Session&);
207 void clear_panners ();
210 /// The fundamental Panner function
211 void set_automation_state (AutoState);
212 AutoState automation_state() const;
213 void set_automation_style (AutoStyle);
214 AutoStyle automation_style() const;
215 bool touching() const;
217 bool is_in_place () const { return false; }
218 bool is_out_of_place () const { return true; }
219 bool can_support_io_configuration (const ChanCount& in, ChanCount& out) const { return true; };
221 void run_out_of_place(BufferSet& src, BufferSet& dest, nframes_t start_frame, nframes_t end_frames, nframes_t nframes, nframes_t offset);
223 //void* get_inline_gui() const = 0;
224 //void* get_full_gui() const = 0;
226 bool bypassed() const { return _bypassed; }
227 void set_bypassed (bool yn);
229 StreamPanner* add ();
230 void remove (uint32_t which);
231 void reset (uint32_t noutputs, uint32_t npans);
236 XMLNode& get_state (void);
237 XMLNode& state (bool full);
238 int set_state (const XMLNode&);
240 static bool equivalent (pan_t a, pan_t b) {
241 return fabsf (a - b) < 0.002; // about 1 degree of arc for a stereo panner
244 void move_output (uint32_t, float x, float y);
245 uint32_t nouts() const { return outputs.size(); }
246 Output& output (uint32_t n) { return outputs[n]; }
248 std::vector<Output> outputs;
255 LinkDirection link_direction() const { return _link_direction; }
256 void set_link_direction (LinkDirection);
258 bool linked() const { return _linked; }
259 void set_linked (bool yn);
261 StreamPanner &streampanner( uint32_t n ) const { assert( n < _streampanners.size() ); return *_streampanners[n]; }
262 uint32_t npanners() const { return _streampanners.size(); }
264 sigc::signal<void> Changed;
265 sigc::signal<void> LinkStateChanged;
266 sigc::signal<void> StateChanged; /* for bypass */
268 /* only StreamPanner should call these */
270 void set_position (float x, StreamPanner& orig);
271 void set_position (float x, float y, StreamPanner& orig);
272 void set_position (float x, float y, float z, StreamPanner& orig);
274 /* old school automation */
278 struct PanControllable : public AutomationControl {
279 PanControllable (Session& s, std::string name, Panner& p, Evoral::Parameter param)
280 : AutomationControl (s, param,
281 boost::shared_ptr<AutomationList>(new AutomationList(param)), name)
283 { assert(param.type() != NullAutomation); }
285 AutomationList* alist() { return (AutomationList*)_list.get(); }
288 void set_value (float);
289 float get_value (void) const;
292 boost::shared_ptr<AutomationControl> pan_control (int id, int chan=0) {
293 return automation_control(Evoral::Parameter (PanAutomation, chan, id));
296 boost::shared_ptr<const AutomationControl> pan_control (int id, int chan=0) const {
297 return automation_control(Evoral::Parameter (PanAutomation, chan, id));
301 /* disallow copy construction */
302 Panner (Panner const &);
304 void distribute_no_automation(BufferSet& src, BufferSet& dest, nframes_t nframes, nframes_t offset, gain_t gain_coeff);
305 std::vector<StreamPanner*> _streampanners;
306 uint32_t current_outs;
309 LinkDirection _link_direction;
311 static float current_automation_version_number;
313 /* old school automation handling */
315 std::string automation_path;
318 } // namespace ARDOUR
320 #endif /*__ardour_panner_h__ */