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/statefuldestructible.h>
35 #include <pbd/controllable.h>
37 #include <ardour/ardour.h>
38 #include <ardour/utils.h>
39 #include <ardour/curve.h>
40 #include <ardour/types.h>
41 #include <ardour/data_type.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 PBD::StatefulDestructible
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 = DataType::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 (nframes_t, 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, nframes_t nframes, nframes_t offset, gain_t gain_coeff);
94 void pan_automated (vector<Sample*>& bufs, uint32_t nbufs, nframes_t start_frame, nframes_t end_frame,
95 nframes_t nframes, nframes_t offset);
96 void collect_input (vector<Sample*>&, uint32_t nbufs, nframes_t nframes, nframes_t offset);
97 void deliver_output (vector<Sample*>&, uint32_t nbufs, nframes_t nframes, nframes_t offset);
98 void deliver_output_no_pan (vector<Sample*>&, uint32_t nbufs, nframes_t nframes, nframes_t offset);
99 void just_meter_input (nframes_t start_frame, nframes_t end_frame,
100 nframes_t nframes, 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 = DataType::NIL);
120 int add_output_port (string destination, void *src, DataType type = DataType::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 nframes_t output_latency() const;
137 nframes_t input_latency() const;
138 void set_port_latency (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 static int disable_connecting (void);
170 static int enable_connecting (void);
171 static int disable_ports (void);
172 static int enable_ports (void);
173 static int disable_panners (void);
174 static int reset_panners (void);
176 static sigc::signal<int> PortsLegal;
177 static sigc::signal<int> PannersLegal;
178 static sigc::signal<int> ConnectingLegal;
179 static sigc::signal<void,uint32_t> MoreOutputs;
180 static sigc::signal<int> PortsCreated;
182 PBD::Controllable& gain_control() {
183 return _gain_control;
188 float peak_input_power (uint32_t n) {
189 if (n < std::max (_ninputs, _noutputs)) {
190 return _visible_peak_power[n];
192 return minus_infinity();
196 static void update_meters();
200 static sigc::signal<void> Meter;
201 static Glib::StaticMutex m_meter_signal_lock;
202 sigc::connection m_meter_connection;
208 void clear_automation ();
210 bool gain_automation_recording() const {
211 return (_gain_automation_curve.automation_state() & (Write|Touch));
214 bool gain_automation_playback() const {
215 return (_gain_automation_curve.automation_state() & Play) ||
216 ((_gain_automation_curve.automation_state() & Touch) &&
217 !_gain_automation_curve.touching());
220 virtual void set_gain_automation_state (AutoState);
221 AutoState gain_automation_state() const { return _gain_automation_curve.automation_state(); }
222 sigc::signal<void> gain_automation_state_changed;
224 virtual void set_gain_automation_style (AutoStyle);
225 AutoStyle gain_automation_style () const { return _gain_automation_curve.automation_style(); }
226 sigc::signal<void> gain_automation_style_changed;
228 virtual void transport_stopped (nframes_t now);
230 ARDOUR::Curve& gain_automation_curve () { return _gain_automation_curve; }
232 void start_gain_touch ();
233 void end_gain_touch ();
235 void start_pan_touch (uint32_t which);
236 void end_pan_touch (uint32_t which);
238 void defer_pan_reset ();
239 void allow_pan_reset ();
241 /* the session calls this for master outs before
242 anyone else. controls outs too, at some point.
245 XMLNode *pending_state_node;
246 int ports_became_legal ();
249 mutable Glib::Mutex io_lock;
255 gain_t _effective_gain;
256 gain_t _desired_gain;
257 Glib::Mutex declick_lock;
258 vector<Port*> _outputs;
259 vector<Port*> _inputs;
260 vector<float> _peak_power;
261 vector<float> _visible_peak_power;
263 Connection* _input_connection;
264 Connection* _output_connection;
265 bool no_panner_reset;
266 XMLNode* deferred_state;
267 DataType _default_type;
268 bool _ignore_gain_on_deliver;
271 virtual void set_deferred_state() {}
273 void reset_peak_meters();
274 void reset_panner ();
276 virtual uint32_t pans_required() const { return _ninputs; }
278 static void apply_declick (vector<Sample*>&, uint32_t nbufs, nframes_t nframes,
279 gain_t initial, gain_t target, bool invert_polarity);
281 struct GainControllable : public PBD::Controllable {
282 GainControllable (std::string name, IO& i) : Controllable (name), io (i) {}
284 void set_value (float val);
285 float get_value (void) const;
290 GainControllable _gain_control;
292 AutoState _gain_automation_state;
293 AutoStyle _gain_automation_style;
295 bool apply_gain_automation;
296 Curve _gain_automation_curve;
298 int save_automation (const string&);
299 int load_automation (const string&);
301 Glib::Mutex automation_lock;
303 /* AudioTrack::deprecated_use_diskstream_connections() needs these */
305 int set_inputs (const string& str);
306 int set_outputs (const string& str);
308 static bool connecting_legal;
309 static bool ports_legal;
316 /* are these the best variable names ever, or what? */
318 sigc::connection input_connection_configuration_connection;
319 sigc::connection output_connection_configuration_connection;
320 sigc::connection input_connection_connection_connection;
321 sigc::connection output_connection_connection_connection;
323 static bool panners_legal;
325 int connecting_became_legal ();
326 int panners_became_legal ();
327 sigc::connection connection_legal_c;
328 sigc::connection port_legal_c;
329 sigc::connection panner_legal_c;
337 static int parse_io_string (const string&, vector<string>& chns);
339 static int parse_gain_string (const string&, vector<string>& chns);
341 int set_sources (vector<string>&, void *src, bool add);
342 int set_destinations (vector<string>&, void *src, bool add);
344 int ensure_inputs (uint32_t, bool clear, bool lockit, void *src);
345 int ensure_outputs (uint32_t, bool clear, bool lockit, void *src);
347 void drop_input_connection ();
348 void drop_output_connection ();
350 void input_connection_configuration_changed ();
351 void input_connection_connection_changed (int);
352 void output_connection_configuration_changed ();
353 void output_connection_connection_changed (int);
355 int create_ports (const XMLNode&);
356 int make_connections (const XMLNode&);
358 void setup_peak_meters ();
361 bool ensure_inputs_locked (uint32_t, bool clear, void *src);
362 bool ensure_outputs_locked (uint32_t, bool clear, void *src);
364 int32_t find_input_port_hole ();
365 int32_t find_output_port_hole ();
368 } // namespace ARDOUR
370 #endif /*__ardour_io_h__ */