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/state_manager.h>
40 #include <ardour/curve.h>
41 #include <ardour/types.h>
42 #include <ardour/data_type.h>
57 /** A collection of input and output ports with connections.
59 * An IO can contain ports of varying types, making routes/inserts/etc with
60 * varied combinations of types (eg MIDI and audio) possible.
62 class IO : public PBD::StatefulDestructible, public ARDOUR::StateManager
66 static const string state_node_name;
68 IO (Session&, string name,
69 int input_min = -1, int input_max = -1,
70 int output_min = -1, int output_max = -1,
71 DataType default_type = DataType::AUDIO);
75 int input_minimum() const { return _input_minimum; }
76 int input_maximum() const { return _input_maximum; }
77 int output_minimum() const { return _output_minimum; }
78 int output_maximum() const { return _output_maximum; }
80 void set_input_minimum (int n);
81 void set_input_maximum (int n);
82 void set_output_minimum (int n);
83 void set_output_maximum (int n);
85 DataType default_type() const { return _default_type; }
87 const string& name() const { return _name; }
88 virtual int set_name (string str, void *src);
90 virtual void silence (nframes_t, nframes_t offset);
92 // These should be moved in to a separate object that manipulates an IO
94 void pan (vector<Sample*>& bufs, uint32_t nbufs, nframes_t nframes, nframes_t offset, gain_t gain_coeff);
95 void pan_automated (vector<Sample*>& bufs, uint32_t nbufs, nframes_t start_frame, nframes_t end_frame,
96 nframes_t nframes, nframes_t offset);
97 void collect_input (vector<Sample*>&, uint32_t nbufs, nframes_t nframes, nframes_t offset);
98 void deliver_output (vector<Sample*>&, uint32_t nbufs, nframes_t nframes, nframes_t offset);
99 void deliver_output_no_pan (vector<Sample*>&, uint32_t nbufs, nframes_t nframes, nframes_t offset);
100 void just_meter_input (nframes_t start_frame, nframes_t end_frame,
101 nframes_t nframes, nframes_t offset);
103 virtual uint32_t n_process_buffers () { return 0; }
105 virtual void set_gain (gain_t g, void *src);
106 void inc_gain (gain_t delta, void *src);
107 gain_t gain () const { return _desired_gain; }
108 virtual gain_t effective_gain () const;
110 Panner& panner() { return *_panner; }
112 int ensure_io (uint32_t, uint32_t, bool clear, void *src);
114 int use_input_connection (Connection&, void *src);
115 int use_output_connection (Connection&, void *src);
117 Connection *input_connection() const { return _input_connection; }
118 Connection *output_connection() const { return _output_connection; }
120 int add_input_port (string source, void *src, DataType type = DataType::NIL);
121 int add_output_port (string destination, void *src, DataType type = DataType::NIL);
123 int remove_input_port (Port *, void *src);
124 int remove_output_port (Port *, void *src);
126 int set_input (Port *, void *src);
128 int connect_input (Port *our_port, string other_port, void *src);
129 int connect_output (Port *our_port, string other_port, void *src);
131 int disconnect_input (Port *our_port, string other_port, void *src);
132 int disconnect_output (Port *our_port, string other_port, void *src);
134 int disconnect_inputs (void *src);
135 int disconnect_outputs (void *src);
137 nframes_t output_latency() const;
138 nframes_t input_latency() const;
139 void set_port_latency (nframes_t);
141 Port *output (uint32_t n) const {
149 Port *input (uint32_t n) const {
157 uint32_t n_inputs () const { return _ninputs; }
158 uint32_t n_outputs () const { return _noutputs; }
160 sigc::signal<void,IOChange,void*> input_changed;
161 sigc::signal<void,IOChange,void*> output_changed;
163 sigc::signal<void,void*> gain_changed;
164 sigc::signal<void,void*> name_changed;
166 virtual XMLNode& state (bool full);
167 XMLNode& get_state (void);
168 int set_state (const XMLNode&);
170 virtual UndoAction get_memento() const;
173 static int disable_connecting (void);
175 static int enable_connecting (void);
177 static int disable_ports (void);
179 static int enable_ports (void);
181 static int disable_panners (void);
183 static int reset_panners (void);
185 static sigc::signal<int> PortsLegal;
186 static sigc::signal<int> PannersLegal;
187 static sigc::signal<int> ConnectingLegal;
188 static sigc::signal<void,uint32_t> MoreOutputs;
189 static sigc::signal<int> PortsCreated;
191 PBD::Controllable& gain_control() {
192 return _gain_control;
197 float peak_input_power (uint32_t n) {
198 if (n < std::max (_ninputs, _noutputs)) {
199 return _visible_peak_power[n];
201 return minus_infinity();
205 static void update_meters();
209 static sigc::signal<void> Meter;
210 static Glib::StaticMutex m_meter_signal_lock;
211 sigc::connection m_meter_connection;
217 void clear_automation ();
219 bool gain_automation_recording() const {
220 return (_gain_automation_curve.automation_state() & (Write|Touch));
223 bool gain_automation_playback() const {
224 return (_gain_automation_curve.automation_state() & Play) ||
225 ((_gain_automation_curve.automation_state() & Touch) &&
226 !_gain_automation_curve.touching());
229 virtual void set_gain_automation_state (AutoState);
230 AutoState gain_automation_state() const { return _gain_automation_curve.automation_state(); }
231 sigc::signal<void> gain_automation_state_changed;
233 virtual void set_gain_automation_style (AutoStyle);
234 AutoStyle gain_automation_style () const { return _gain_automation_curve.automation_style(); }
235 sigc::signal<void> gain_automation_style_changed;
237 virtual void transport_stopped (nframes_t now);
239 ARDOUR::Curve& gain_automation_curve () { return _gain_automation_curve; }
241 void start_gain_touch ();
242 void end_gain_touch ();
244 void start_pan_touch (uint32_t which);
245 void end_pan_touch (uint32_t which);
247 void defer_pan_reset ();
248 void allow_pan_reset ();
250 /* the session calls this for master outs before
251 anyone else. controls outs too, at some point.
254 XMLNode *pending_state_node;
255 int ports_became_legal ();
258 mutable Glib::Mutex io_lock;
264 gain_t _effective_gain;
265 gain_t _desired_gain;
266 Glib::Mutex declick_lock;
267 vector<Port*> _outputs;
268 vector<Port*> _inputs;
269 vector<float> _peak_power;
270 vector<float> _visible_peak_power;
272 Connection* _input_connection;
273 Connection* _output_connection;
274 bool no_panner_reset;
275 XMLNode* deferred_state;
276 DataType _default_type;
278 virtual void set_deferred_state() {}
280 void reset_peak_meters();
281 void reset_panner ();
283 virtual uint32_t pans_required() const { return _ninputs; }
285 static void apply_declick (vector<Sample*>&, uint32_t nbufs, nframes_t nframes,
286 gain_t initial, gain_t target, bool invert_polarity);
288 struct GainControllable : public PBD::Controllable {
289 GainControllable (std::string name, IO& i) : Controllable (name), io (i) {}
291 void set_value (float val);
292 float get_value (void) const;
297 GainControllable _gain_control;
299 /* state management */
301 Change restore_state (State&);
302 StateManager::State* state_factory (std::string why) const;
304 AutoState _gain_automation_state;
305 AutoStyle _gain_automation_style;
307 bool apply_gain_automation;
308 Curve _gain_automation_curve;
310 int save_automation (const string&);
311 int load_automation (const string&);
313 Glib::Mutex automation_lock;
315 /* AudioTrack::deprecated_use_diskstream_connections() needs these */
317 int set_inputs (const string& str);
318 int set_outputs (const string& str);
320 static bool connecting_legal;
321 static bool ports_legal;
328 /* are these the best variable names ever, or what? */
330 sigc::connection input_connection_configuration_connection;
331 sigc::connection output_connection_configuration_connection;
332 sigc::connection input_connection_connection_connection;
333 sigc::connection output_connection_connection_connection;
335 static bool panners_legal;
337 int connecting_became_legal ();
338 int panners_became_legal ();
339 sigc::connection connection_legal_c;
340 sigc::connection port_legal_c;
341 sigc::connection panner_legal_c;
349 static int parse_io_string (const string&, vector<string>& chns);
351 static int parse_gain_string (const string&, vector<string>& chns);
353 int set_sources (vector<string>&, void *src, bool add);
354 int set_destinations (vector<string>&, void *src, bool add);
356 int ensure_inputs (uint32_t, bool clear, bool lockit, void *src);
357 int ensure_outputs (uint32_t, bool clear, bool lockit, void *src);
359 void drop_input_connection ();
360 void drop_output_connection ();
362 void input_connection_configuration_changed ();
363 void input_connection_connection_changed (int);
364 void output_connection_configuration_changed ();
365 void output_connection_connection_changed (int);
367 int create_ports (const XMLNode&);
368 int make_connections (const XMLNode&);
370 void setup_peak_meters ();
373 bool ensure_inputs_locked (uint32_t, bool clear, void *src);
374 bool ensure_outputs_locked (uint32_t, bool clear, void *src);
376 int32_t find_input_port_hole ();
377 int32_t find_output_port_hole ();
380 } // namespace ARDOUR
382 #endif /*__ardour_io_h__ */