2 Copyright (C) 2000 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_io_h__
22 #define __ardour_io_h__
27 #include <sigc++/signal.h>
28 #include <jack/jack.h>
30 #include <glibmm/thread.h>
32 #include <pbd/fastlog.h>
34 #include <pbd/stateful.h>
35 #include <pbd/controllable.h>
37 #include <ardour/ardour.h>
38 #include <ardour/utils.h>
39 #include <ardour/state_manager.h>
40 #include <ardour/curve.h>
41 #include <ardour/types.h>
56 /** A collection of input and output ports with connections.
58 * An IO can contain ports of varying types, making routes/inserts/etc with
59 * varied combinations of types (eg MIDI and audio) possible.
61 class IO : public Stateful, public ARDOUR::StateManager
65 static const string state_node_name;
67 IO (Session&, string name,
68 int input_min = -1, int input_max = -1,
69 int output_min = -1, int output_max = -1,
70 DataType default_type = AUDIO);
74 int input_minimum() const { return _input_minimum; }
75 int input_maximum() const { return _input_maximum; }
76 int output_minimum() const { return _output_minimum; }
77 int output_maximum() const { return _output_maximum; }
79 void set_input_minimum (int n);
80 void set_input_maximum (int n);
81 void set_output_minimum (int n);
82 void set_output_maximum (int n);
84 DataType default_type() const { return _default_type; }
86 const string& name() const { return _name; }
87 virtual int set_name (string str, void *src);
89 virtual void silence (jack_nframes_t, jack_nframes_t offset);
91 // These should be moved in to a separate object that manipulates an IO
93 void pan (vector<Sample*>& bufs, uint32_t nbufs, jack_nframes_t nframes, jack_nframes_t offset, gain_t gain_coeff);
94 void pan_automated (vector<Sample*>& bufs, uint32_t nbufs, jack_nframes_t start_frame, jack_nframes_t end_frame,
95 jack_nframes_t nframes, jack_nframes_t offset);
96 void collect_input (vector<Sample*>&, uint32_t nbufs, jack_nframes_t nframes, jack_nframes_t offset);
97 void deliver_output (vector<Sample*>&, uint32_t nbufs, jack_nframes_t nframes, jack_nframes_t offset);
98 void deliver_output_no_pan (vector<Sample*>&, uint32_t nbufs, jack_nframes_t nframes, jack_nframes_t offset);
99 void just_meter_input (jack_nframes_t start_frame, jack_nframes_t end_frame,
100 jack_nframes_t nframes, jack_nframes_t offset);
102 virtual uint32_t n_process_buffers () { return 0; }
104 virtual void set_gain (gain_t g, void *src);
105 void inc_gain (gain_t delta, void *src);
106 gain_t gain () const { return _desired_gain; }
107 virtual gain_t effective_gain () const;
109 Panner& panner() { return *_panner; }
111 int ensure_io (uint32_t, uint32_t, bool clear, void *src);
113 int use_input_connection (Connection&, void *src);
114 int use_output_connection (Connection&, void *src);
116 Connection *input_connection() const { return _input_connection; }
117 Connection *output_connection() const { return _output_connection; }
119 int add_input_port (string source, void *src, DataType type = NIL);
120 int add_output_port (string destination, void *src, DataType type = NIL);
122 int remove_input_port (Port *, void *src);
123 int remove_output_port (Port *, void *src);
125 int set_input (Port *, void *src);
127 int connect_input (Port *our_port, string other_port, void *src);
128 int connect_output (Port *our_port, string other_port, void *src);
130 int disconnect_input (Port *our_port, string other_port, void *src);
131 int disconnect_output (Port *our_port, string other_port, void *src);
133 int disconnect_inputs (void *src);
134 int disconnect_outputs (void *src);
136 jack_nframes_t output_latency() const;
137 jack_nframes_t input_latency() const;
138 void set_port_latency (jack_nframes_t);
140 Port *output (uint32_t n) const {
148 Port *input (uint32_t n) const {
156 uint32_t n_inputs () const { return _ninputs; }
157 uint32_t n_outputs () const { return _noutputs; }
159 sigc::signal<void,IOChange,void*> input_changed;
160 sigc::signal<void,IOChange,void*> output_changed;
162 sigc::signal<void,void*> gain_changed;
163 sigc::signal<void,void*> name_changed;
165 virtual XMLNode& state (bool full);
166 XMLNode& get_state (void);
167 int set_state (const XMLNode&);
169 virtual UndoAction get_memento() const;
172 static int disable_connecting (void);
174 static int enable_connecting (void);
176 static int disable_ports (void);
178 static int enable_ports (void);
180 static int disable_panners (void);
182 static int reset_panners (void);
184 static sigc::signal<int> PortsLegal;
185 static sigc::signal<int> PannersLegal;
186 static sigc::signal<int> ConnectingLegal;
187 static sigc::signal<void,uint32_t> MoreOutputs;
188 static sigc::signal<int> PortsCreated;
190 PBD::Controllable& gain_control() {
191 return _gain_control;
196 float peak_input_power (uint32_t n) {
197 if (n < std::max (_ninputs, _noutputs)) {
198 return _visible_peak_power[n];
200 return minus_infinity();
204 static void update_meters();
208 static sigc::signal<void> Meter;
209 static Glib::StaticMutex m_meter_signal_lock;
210 sigc::connection m_meter_connection;
216 void clear_automation ();
218 bool gain_automation_recording() const {
219 return (_gain_automation_curve.automation_state() & (Write|Touch));
222 bool gain_automation_playback() const {
223 return (_gain_automation_curve.automation_state() & Play) ||
224 ((_gain_automation_curve.automation_state() & Touch) &&
225 !_gain_automation_curve.touching());
228 virtual void set_gain_automation_state (AutoState);
229 AutoState gain_automation_state() const { return _gain_automation_curve.automation_state(); }
230 sigc::signal<void> gain_automation_state_changed;
232 virtual void set_gain_automation_style (AutoStyle);
233 AutoStyle gain_automation_style () const { return _gain_automation_curve.automation_style(); }
234 sigc::signal<void> gain_automation_style_changed;
236 static void set_automation_interval (jack_nframes_t frames) {
237 _automation_interval = frames;
240 static jack_nframes_t automation_interval() {
241 return _automation_interval;
244 virtual void transport_stopped (jack_nframes_t now);
245 virtual void automation_snapshot (jack_nframes_t now);
247 ARDOUR::Curve& gain_automation_curve () { return _gain_automation_curve; }
249 void start_gain_touch ();
250 void end_gain_touch ();
252 void start_pan_touch (uint32_t which);
253 void end_pan_touch (uint32_t which);
255 const PBD::ID& id() const { return _id; }
257 void defer_pan_reset ();
258 void allow_pan_reset ();
260 /* the session calls this for master outs before
261 anyone else. controls outs too, at some point.
264 XMLNode *pending_state_node;
265 int ports_became_legal ();
268 mutable Glib::Mutex io_lock;
274 gain_t _effective_gain;
275 gain_t _desired_gain;
276 Glib::Mutex declick_lock;
277 vector<Port*> _outputs;
278 vector<Port*> _inputs;
279 vector<float> _peak_power;
280 vector<float> _visible_peak_power;
282 Connection* _input_connection;
283 Connection* _output_connection;
285 bool no_panner_reset;
286 XMLNode* deferred_state;
287 DataType _default_type;
289 virtual void set_deferred_state() {}
291 void reset_peak_meters();
292 void reset_panner ();
294 virtual uint32_t pans_required() const { return _ninputs; }
296 static void apply_declick (vector<Sample*>&, uint32_t nbufs, jack_nframes_t nframes,
297 gain_t initial, gain_t target, bool invert_polarity);
299 struct GainControllable : public PBD::Controllable {
300 GainControllable (IO& i) : io (i) {}
302 void set_value (float val);
303 float get_value (void) const;
308 GainControllable _gain_control;
310 /* state management */
312 Change restore_state (State&);
313 StateManager::State* state_factory (std::string why) const;
317 jack_nframes_t last_automation_snapshot;
318 static jack_nframes_t _automation_interval;
320 AutoState _gain_automation_state;
321 AutoStyle _gain_automation_style;
323 bool apply_gain_automation;
324 Curve _gain_automation_curve;
326 int save_automation (const string&);
327 int load_automation (const string&);
329 Glib::Mutex automation_lock;
331 /* AudioTrack::deprecated_use_diskstream_connections() needs these */
333 int set_inputs (const string& str);
334 int set_outputs (const string& str);
336 static bool connecting_legal;
337 static bool ports_legal;
344 /* are these the best variable names ever, or what? */
346 sigc::connection input_connection_configuration_connection;
347 sigc::connection output_connection_configuration_connection;
348 sigc::connection input_connection_connection_connection;
349 sigc::connection output_connection_connection_connection;
351 static bool panners_legal;
353 int connecting_became_legal ();
354 int panners_became_legal ();
355 sigc::connection connection_legal_c;
356 sigc::connection port_legal_c;
357 sigc::connection panner_legal_c;
365 static int parse_io_string (const string&, vector<string>& chns);
367 static int parse_gain_string (const string&, vector<string>& chns);
369 int set_sources (vector<string>&, void *src, bool add);
370 int set_destinations (vector<string>&, void *src, bool add);
372 int ensure_inputs (uint32_t, bool clear, bool lockit, void *src);
373 int ensure_outputs (uint32_t, bool clear, bool lockit, void *src);
375 void drop_input_connection ();
376 void drop_output_connection ();
378 void input_connection_configuration_changed ();
379 void input_connection_connection_changed (int);
380 void output_connection_configuration_changed ();
381 void output_connection_connection_changed (int);
383 int create_ports (const XMLNode&);
384 int make_connections (const XMLNode&);
386 void setup_peak_meters ();
389 bool ensure_inputs_locked (uint32_t, bool clear, void *src);
390 bool ensure_outputs_locked (uint32_t, bool clear, void *src);
392 int32_t find_input_port_hole ();
393 int32_t find_output_port_hole ();
396 } // namespace ARDOUR
398 #endif /*__ardour_io_h__ */