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.
20 #ifndef __ardour_io_h__
21 #define __ardour_io_h__
26 #include <sigc++/signal.h>
27 #include <jack/jack.h>
29 #include <glibmm/thread.h>
31 #include <pbd/fastlog.h>
33 #include <pbd/statefuldestructible.h>
34 #include <pbd/controllable.h>
36 #include <ardour/ardour.h>
37 #include <ardour/automatable.h>
38 #include <ardour/utils.h>
39 #include <ardour/curve.h>
40 #include <ardour/types.h>
41 #include <ardour/data_type.h>
42 #include <ardour/port_set.h>
43 #include <ardour/chan_count.h>
44 #include <ardour/latent.h>
45 #include <ardour/automation_control.h>
65 /** A collection of input and output ports with connections.
67 * An IO can contain ports of varying types, making routes/inserts/etc with
68 * varied combinations of types (eg MIDI and audio) possible.
71 class IO : public Automatable, public Latent
74 static const string state_node_name;
76 IO (Session&, const string& name,
77 int input_min = -1, int input_max = -1,
78 int output_min = -1, int output_max = -1,
79 DataType default_type = DataType::AUDIO);
81 IO (Session&, const XMLNode&, DataType default_type = DataType::AUDIO);
85 ChanCount input_minimum() const { return _input_minimum; }
86 ChanCount input_maximum() const { return _input_maximum; }
87 ChanCount output_minimum() const { return _output_minimum; }
88 ChanCount output_maximum() const { return _output_maximum; }
90 void set_input_minimum (ChanCount n);
91 void set_input_maximum (ChanCount n);
92 void set_output_minimum (ChanCount n);
93 void set_output_maximum (ChanCount n);
95 DataType default_type() const { return _default_type; }
96 void set_default_type(DataType t) { _default_type = t; }
98 bool set_name (const string& str);
100 virtual void silence (nframes_t, nframes_t offset);
102 void collect_input (BufferSet& bufs, nframes_t nframes, nframes_t offset);
103 void deliver_output (BufferSet& bufs, nframes_t start_frame, nframes_t end_frame,
104 nframes_t nframes, nframes_t offset);
105 void just_meter_input (nframes_t start_frame, nframes_t end_frame,
106 nframes_t nframes, nframes_t offset);
108 gain_t gain () const { return _desired_gain; }
109 virtual gain_t effective_gain () const;
111 void set_denormal_protection (bool yn, void *src);
112 bool denormal_protection() const { return _denormal_protection; }
114 void set_phase_invert (bool yn, void *src);
115 bool phase_invert() const { return _phase_invert; }
117 Panner& panner() { return *_panner; }
118 PeakMeter& peak_meter() { return *_meter; }
119 const Panner& panner() const { return *_panner; }
121 int ensure_io (ChanCount in, ChanCount out, bool clear, void *src);
123 int connect_input_ports_to_bundle (boost::shared_ptr<Bundle>, void *src);
124 int connect_output_ports_to_bundle (boost::shared_ptr<Bundle>, void *src);
126 boost::shared_ptr<Bundle> input_bundle();
127 boost::shared_ptr<Bundle> output_bundle();
129 int add_input_port (string source, void *src, DataType type = DataType::NIL);
130 int add_output_port (string destination, void *src, DataType type = DataType::NIL);
132 int remove_input_port (Port *, void *src);
133 int remove_output_port (Port *, void *src);
135 int set_input (Port *, void *src);
137 int connect_input (Port *our_port, string other_port, void *src);
138 int connect_output (Port *our_port, string other_port, void *src);
140 int disconnect_input (Port *our_port, string other_port, void *src);
141 int disconnect_output (Port *our_port, string other_port, void *src);
143 int disconnect_inputs (void *src);
144 int disconnect_outputs (void *src);
146 nframes_t signal_latency() const { return _own_latency; }
147 nframes_t output_latency() const;
148 nframes_t input_latency() const;
149 void set_port_latency (nframes_t);
151 void update_port_total_latencies ();
153 const PortSet& inputs() const { return _inputs; }
154 const PortSet& outputs() const { return _outputs; }
156 Port *output (uint32_t n) const {
157 if (n < _outputs.num_ports()) {
158 return _outputs.port(n);
164 Port *input (uint32_t n) const {
165 if (n < _inputs.num_ports()) {
166 return _inputs.port(n);
172 AudioPort* audio_input(uint32_t n) const;
173 AudioPort* audio_output(uint32_t n) const;
174 MidiPort* midi_input(uint32_t n) const;
175 MidiPort* midi_output(uint32_t n) const;
177 const ChanCount& n_inputs () const { return _inputs.count(); }
178 const ChanCount& n_outputs () const { return _outputs.count(); }
180 void attach_buffers(ChanCount ignored);
182 boost::shared_ptr<Bundle> bundle_for_inputs () const { return _bundle_for_inputs; }
183 boost::shared_ptr<Bundle> bundle_for_outputs () const { return _bundle_for_outputs; }
185 sigc::signal<void,IOChange,void*> input_changed;
186 sigc::signal<void,IOChange,void*> output_changed;
188 virtual XMLNode& state (bool full);
189 XMLNode& get_state (void);
190 int set_state (const XMLNode&);
192 static int disable_connecting (void);
194 static int enable_connecting (void);
196 static int disable_ports (void);
198 static int enable_ports (void);
200 static int disable_panners (void);
202 static int reset_panners (void);
204 static sigc::signal<int> PortsLegal;
205 static sigc::signal<int> PannersLegal;
206 static sigc::signal<int> ConnectingLegal;
207 /// raised when the number of input or output ports changes
208 static sigc::signal<void,ChanCount> PortCountChanged;
209 static sigc::signal<int> PortsCreated;
211 static void update_meters();
215 static sigc::signal<void> Meter;
216 static Glib::StaticMutex m_meter_signal_lock;
217 sigc::connection m_meter_connection;
223 struct GainControl : public AutomationControl {
224 GainControl (std::string name, IO& i, boost::shared_ptr<AutomationList> al)
225 : AutomationControl (i._session, al, name)
229 void set_value (float val);
230 float get_value (void) const;
235 boost::shared_ptr<GainControl> gain_control() {
236 return _gain_control;
238 boost::shared_ptr<const GainControl> gain_control() const {
239 return _gain_control;
242 void clear_automation ();
244 void set_parameter_automation_state (Parameter, AutoState);
246 virtual void transport_stopped (nframes_t now); // interface: matches Insert
247 void automation_snapshot (nframes_t now); // interface: matches Automatable
249 void start_pan_touch (uint32_t which);
250 void end_pan_touch (uint32_t which);
252 void defer_pan_reset ();
253 void allow_pan_reset ();
255 /* the session calls this for master outs before
256 anyone else. controls outs too, at some point.
259 XMLNode *pending_state_node;
260 int ports_became_legal ();
263 mutable Glib::Mutex io_lock;
267 BufferSet* _output_buffers; //< Set directly to output port buffers
269 gain_t _effective_gain;
270 gain_t _desired_gain;
271 Glib::Mutex declick_lock;
275 boost::shared_ptr<Bundle> _input_bundle; ///< bundle connected to our inputs
276 boost::shared_ptr<Bundle> _output_bundle; ///< bundle connected to our outputs
277 bool no_panner_reset;
279 bool _denormal_protection;
280 XMLNode* deferred_state;
281 DataType _default_type;
283 virtual void set_deferred_state() {}
285 void reset_panner ();
287 virtual uint32_t pans_required() const
288 { return _inputs.count().n_audio(); }
290 boost::shared_ptr<GainControl> _gain_control;
292 virtual void set_gain (gain_t g, void *src);
293 void inc_gain (gain_t delta, void *src);
295 bool apply_gain_automation;
297 virtual int load_automation (std::string path);
299 /* AudioTrack::deprecated_use_diskstream_connections() needs these */
301 int set_inputs (const string& str);
302 int set_outputs (const string& str);
304 static bool connecting_legal;
305 static bool ports_legal;
307 BufferSet& output_buffers() { return *_output_buffers; }
313 /* are these the best variable names ever, or what? */
315 sigc::connection input_bundle_configuration_connection;
316 sigc::connection output_bundle_configuration_connection;
317 sigc::connection input_bundle_connection_connection;
318 sigc::connection output_bundle_connection_connection;
320 static bool panners_legal;
322 int connecting_became_legal ();
323 int panners_became_legal ();
324 sigc::connection connection_legal_c;
325 sigc::connection port_legal_c;
326 sigc::connection panner_legal_c;
328 ChanCount _input_minimum; ///< minimum number of input channels (0 for no minimum)
329 ChanCount _input_maximum; ///< maximum number of input channels (ChanCount::INFINITE for no maximum)
330 ChanCount _output_minimum; ///< minimum number of output channels (0 for no minimum)
331 ChanCount _output_maximum; ///< maximum number of output channels (ChanCount::INFINITE for no maximum)
333 boost::shared_ptr<Bundle> _bundle_for_inputs;
334 boost::shared_ptr<Bundle> _bundle_for_outputs;
336 static int parse_io_string (const string&, vector<string>& chns);
338 static int parse_gain_string (const string&, vector<string>& chns);
340 int set_sources (vector<string>&, void *src, bool add);
341 int set_destinations (vector<string>&, void *src, bool add);
343 int ensure_inputs (ChanCount, bool clear, bool lockit, void *src);
344 int ensure_outputs (ChanCount, bool clear, bool lockit, void *src);
346 void drop_input_bundle ();
347 void drop_output_bundle ();
349 void input_bundle_configuration_changed ();
350 void input_bundle_connection_changed (int);
351 void output_bundle_configuration_changed ();
352 void output_bundle_connection_changed (int);
354 int create_ports (const XMLNode&);
355 int make_connections (const XMLNode&);
357 void setup_peak_meters ();
360 bool ensure_inputs_locked (ChanCount, bool clear, void *src);
361 bool ensure_outputs_locked (ChanCount, bool clear, void *src);
363 int32_t find_input_port_hole ();
364 int32_t find_output_port_hole ();
366 void create_bundles ();
367 void setup_bundles ();
370 } // namespace ARDOUR
372 #endif /*__ardour_io_h__ */