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.
21 #ifndef __ardour_panner_h__
22 #define __ardour_panner_h__
28 #include <sigc++/signal.h>
30 #include <midi++/controllable.h>
32 #include <ardour/types.h>
33 #include <ardour/stateful.h>
34 #include <ardour/curve.h>
44 class StreamPanner : public sigc::trackable, public Stateful
47 StreamPanner (Panner& p);
50 void set_muted (bool yn);
51 bool muted() const { return _muted; }
53 void set_position (float x, bool link_call = false);
54 void set_position (float x, float y, bool link_call = false);
55 void set_position (float x, float y, float z, bool link_call = false);
57 void get_position (float& xpos) const { xpos = x; }
58 void get_position (float& xpos, float& ypos) const { xpos = x; ypos = y; }
59 void get_position (float& xpos, float& ypos, float& zpos) const { xpos = x; ypos = y; zpos = z; }
61 void get_effective_position (float& xpos) const { xpos = effective_x; }
62 void get_effective_position (float& xpos, float& ypos) const { xpos = effective_x; ypos = effective_y; }
63 void get_effective_position (float& xpos, float& ypos, float& zpos) const { xpos = effective_x; ypos = effective_y; zpos = effective_z; }
65 /* the basic panner API */
67 virtual void distribute (Sample* src, Sample** obufs, gain_t gain_coeff, jack_nframes_t nframes) = 0;
68 virtual void distribute_automated (Sample* src, Sample** obufs,
69 jack_nframes_t start, jack_nframes_t end, jack_nframes_t nframes, pan_t** buffers) = 0;
73 virtual void snapshot (jack_nframes_t now) = 0;
74 virtual void transport_stopped (jack_nframes_t frame) = 0;
75 virtual void set_automation_state (AutoState) = 0;
76 virtual void set_automation_style (AutoStyle) = 0;
80 struct MIDIControl : public MIDI::Controllable {
81 MIDIControl (StreamPanner&, MIDI::Port *);
82 void set_value (float);
83 void send_feedback (gain_t);
84 MIDI::byte* write_feedback (MIDI::byte* buf, int32_t& bufsize, gain_t val, bool force = false);
86 pan_t (*midi_to_pan)(double val);
87 double (*pan_to_midi)(pan_t p);
94 MIDIControl& midi_control() { return _midi_control; }
95 void reset_midi_control (MIDI::Port *, bool);
97 /* XXX this is wrong. for multi-dimensional panners, there
98 must surely be more than 1 automation curve.
101 virtual Curve& automation() = 0;
104 virtual int load (istream&, string path, uint32_t&) = 0;
106 virtual int save (ostream&) const = 0;
108 sigc::signal<void> Changed; /* for position */
109 sigc::signal<void> StateChanged; /* for mute */
111 int set_state (const XMLNode&);
112 virtual XMLNode& state (bool full_state) = 0;
114 Panner & get_parent() { return parent; }
124 /* these are for automation. they store the last value
125 used by the most recent process() cycle.
133 MIDIControl _midi_control;
135 void add_state (XMLNode&);
136 bool get_midi_node_info (XMLNode * node, MIDI::eventType & ev, MIDI::channel_t & chan, MIDI::byte & additional);
137 bool set_midi_node_info (XMLNode * node, MIDI::eventType ev, MIDI::channel_t chan, MIDI::byte additional);
139 virtual void update () = 0;
142 class BaseStereoPanner : public StreamPanner
145 BaseStereoPanner (Panner&);
146 ~BaseStereoPanner ();
148 /* this class just leaves the pan law itself to be defined
149 by the update(), distribute_automated()
150 methods. derived classes also need a factory method
151 and a type name. See EqualPowerStereoPanner as an example.
154 void distribute (Sample* src, Sample** obufs, gain_t gain_coeff, jack_nframes_t nframes);
156 int load (istream&, string path, uint32_t&);
157 int save (ostream&) const;
158 void snapshot (jack_nframes_t now);
159 void transport_stopped (jack_nframes_t frame);
160 void set_automation_state (AutoState);
161 void set_automation_style (AutoStyle);
163 Curve& automation() { return _automation; }
176 class EqualPowerStereoPanner : public BaseStereoPanner
179 EqualPowerStereoPanner (Panner&);
180 ~EqualPowerStereoPanner ();
182 void distribute_automated (Sample* src, Sample** obufs,
183 jack_nframes_t start, jack_nframes_t end, jack_nframes_t nframes, pan_t** buffers);
185 void get_current_coefficients (pan_t*) const;
186 void get_desired_coefficients (pan_t*) const;
188 static StreamPanner* factory (Panner&);
191 XMLNode& state (bool full_state);
192 XMLNode& get_state (void);
193 int set_state (const XMLNode&);
199 class Multi2dPanner : public StreamPanner
202 Multi2dPanner (Panner& parent);
205 void snapshot (jack_nframes_t now);
206 void transport_stopped (jack_nframes_t frame);
207 void set_automation_state (AutoState);
208 void set_automation_style (AutoStyle);
210 /* XXX this is wrong. for multi-dimensional panners, there
211 must surely be more than 1 automation curve.
214 Curve& automation() { return _automation; }
216 void distribute (Sample* src, Sample** obufs, gain_t gain_coeff, jack_nframes_t nframes);
217 void distribute_automated (Sample* src, Sample** obufs,
218 jack_nframes_t start, jack_nframes_t end, jack_nframes_t nframes, pan_t** buffers);
220 int load (istream&, string path, uint32_t&);
221 int save (ostream&) const;
223 static StreamPanner* factory (Panner&);
226 XMLNode& state (bool full_state);
227 XMLNode& get_state (void);
228 int set_state (const XMLNode&);
235 class Panner : public std::vector<StreamPanner*>, public Stateful, public sigc::trackable
244 Output (float xp, float yp)
245 : x (xp), y (yp), current_pan (0.0f), desired_pan (0.f) {}
249 Panner (string name, Session&);
252 void set_name (string);
254 bool bypassed() const { return _bypassed; }
255 void set_bypassed (bool yn);
257 StreamPanner* add ();
258 void remove (uint32_t which);
260 void reset (uint32_t noutputs, uint32_t npans);
262 void snapshot (jack_nframes_t now);
263 void transport_stopped (jack_nframes_t frame);
265 void clear_automation ();
267 void set_automation_state (AutoState);
268 AutoState automation_state() const;
269 void set_automation_style (AutoStyle);
270 AutoStyle automation_style() const;
271 bool touching() const;
276 XMLNode& get_state (void);
277 XMLNode& state (bool full);
278 int set_state (const XMLNode&);
280 sigc::signal<void> Changed;
282 static bool equivalent (pan_t a, pan_t b) {
283 return fabsf (a - b) < 0.002; // about 1 degree of arc for a stereo panner
286 void move_output (uint32_t, float x, float y);
287 uint32_t nouts() const { return outputs.size(); }
288 Output& output (uint32_t n) { return outputs[n]; }
290 std::vector<Output> outputs;
291 Session& session() const { return _session; }
293 void reset_midi_control (MIDI::Port *, bool);
294 void send_all_midi_feedback ();
295 MIDI::byte* write_midi_feedback (MIDI::byte*, int32_t& bufsize);
302 LinkDirection link_direction() const { return _link_direction; }
303 void set_link_direction (LinkDirection);
305 bool linked() const { return _linked; }
306 void set_linked (bool yn);
308 sigc::signal<void> LinkStateChanged;
309 sigc::signal<void> StateChanged; /* for bypass */
311 /* only StreamPanner should call these */
313 void set_position (float x, StreamPanner& orig);
314 void set_position (float x, float y, StreamPanner& orig);
315 void set_position (float x, float y, float z, StreamPanner& orig);
319 string automation_path;
321 uint32_t current_outs;
324 LinkDirection _link_direction;
326 static float current_automation_version_number;
329 }; /* namespace ARDOUR */
331 #endif /*__ardour_panner_h__ */