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/buffer.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 Buffer::Type default_type = Buffer::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 const string& name() const { return _name; }
85 virtual int set_name (string str, void *src);
87 virtual void silence (jack_nframes_t, jack_nframes_t offset);
89 // These should be moved in to a separate object that manipulates an IO
91 void pan (vector<Sample*>& bufs, uint32_t nbufs, jack_nframes_t nframes, jack_nframes_t offset, gain_t gain_coeff);
92 void pan_automated (vector<Sample*>& bufs, uint32_t nbufs, jack_nframes_t start_frame, jack_nframes_t end_frame,
93 jack_nframes_t nframes, jack_nframes_t offset);
94 void collect_input (vector<Sample*>&, uint32_t nbufs, jack_nframes_t nframes, jack_nframes_t offset);
95 void deliver_output (vector<Sample*>&, uint32_t nbufs, jack_nframes_t nframes, jack_nframes_t offset);
96 void deliver_output_no_pan (vector<Sample*>&, uint32_t nbufs, jack_nframes_t nframes, jack_nframes_t offset);
97 void just_meter_input (jack_nframes_t start_frame, jack_nframes_t end_frame,
98 jack_nframes_t nframes, jack_nframes_t offset);
100 virtual uint32_t n_process_buffers () { return 0; }
102 virtual void set_gain (gain_t g, void *src);
103 void inc_gain (gain_t delta, void *src);
104 gain_t gain () const { return _desired_gain; }
105 virtual gain_t effective_gain () const;
107 Panner& panner() { return *_panner; }
109 int ensure_io (uint32_t, uint32_t, bool clear, void *src);
111 int use_input_connection (Connection&, void *src);
112 int use_output_connection (Connection&, void *src);
114 Connection *input_connection() const { return _input_connection; }
115 Connection *output_connection() const { return _output_connection; }
117 int add_input_port (string source, void *src, Buffer::Type type = Buffer::NIL);
118 int add_output_port (string destination, void *src, Buffer::Type type = Buffer::NIL);
120 int remove_input_port (Port *, void *src);
121 int remove_output_port (Port *, void *src);
123 int set_input (Port *, void *src);
125 int connect_input (Port *our_port, string other_port, void *src);
126 int connect_output (Port *our_port, string other_port, void *src);
128 int disconnect_input (Port *our_port, string other_port, void *src);
129 int disconnect_output (Port *our_port, string other_port, void *src);
131 int disconnect_inputs (void *src);
132 int disconnect_outputs (void *src);
134 jack_nframes_t output_latency() const;
135 jack_nframes_t input_latency() const;
136 void set_port_latency (jack_nframes_t);
138 Port *output (uint32_t n) const {
146 Port *input (uint32_t n) const {
154 uint32_t n_inputs () const { return _ninputs; }
155 uint32_t n_outputs () const { return _noutputs; }
157 sigc::signal<void,IOChange,void*> input_changed;
158 sigc::signal<void,IOChange,void*> output_changed;
160 sigc::signal<void,void*> gain_changed;
161 sigc::signal<void,void*> name_changed;
163 virtual XMLNode& state (bool full);
164 XMLNode& get_state (void);
165 int set_state (const XMLNode&);
167 virtual UndoAction get_memento() const;
170 static int disable_connecting (void);
172 static int enable_connecting (void);
174 static int disable_ports (void);
176 static int enable_ports (void);
178 static int disable_panners (void);
180 static int reset_panners (void);
182 static sigc::signal<int> PortsLegal;
183 static sigc::signal<int> PannersLegal;
184 static sigc::signal<int> ConnectingLegal;
185 static sigc::signal<void,uint32_t> MoreOutputs;
186 static sigc::signal<int> PortsCreated;
188 PBD::Controllable& gain_control() {
189 return _gain_control;
194 float peak_input_power (uint32_t n) {
195 if (n < std::max (_ninputs, _noutputs)) {
196 return _visible_peak_power[n];
198 return minus_infinity();
202 static void update_meters();
206 static sigc::signal<void> Meter;
207 static Glib::StaticMutex m_meter_signal_lock;
208 sigc::connection m_meter_connection;
214 void clear_automation ();
216 bool gain_automation_recording() const {
217 return (_gain_automation_curve.automation_state() & (Write|Touch));
220 bool gain_automation_playback() const {
221 return (_gain_automation_curve.automation_state() & Play) ||
222 ((_gain_automation_curve.automation_state() & Touch) &&
223 !_gain_automation_curve.touching());
226 virtual void set_gain_automation_state (AutoState);
227 AutoState gain_automation_state() const { return _gain_automation_curve.automation_state(); }
228 sigc::signal<void> gain_automation_state_changed;
230 virtual void set_gain_automation_style (AutoStyle);
231 AutoStyle gain_automation_style () const { return _gain_automation_curve.automation_style(); }
232 sigc::signal<void> gain_automation_style_changed;
234 static void set_automation_interval (jack_nframes_t frames) {
235 _automation_interval = frames;
238 static jack_nframes_t automation_interval() {
239 return _automation_interval;
242 virtual void transport_stopped (jack_nframes_t now);
243 virtual void automation_snapshot (jack_nframes_t now);
245 ARDOUR::Curve& gain_automation_curve () { return _gain_automation_curve; }
247 void start_gain_touch ();
248 void end_gain_touch ();
250 void start_pan_touch (uint32_t which);
251 void end_pan_touch (uint32_t which);
253 const PBD::ID& id() const { return _id; }
255 void defer_pan_reset ();
256 void allow_pan_reset ();
258 /* the session calls this for master outs before
259 anyone else. controls outs too, at some point.
262 XMLNode *pending_state_node;
263 int ports_became_legal ();
266 mutable Glib::Mutex io_lock;
272 gain_t _effective_gain;
273 gain_t _desired_gain;
274 Glib::Mutex declick_lock;
275 vector<Port*> _outputs;
276 vector<Port*> _inputs;
277 vector<float> _peak_power;
278 vector<float> _visible_peak_power;
280 Connection* _input_connection;
281 Connection* _output_connection;
283 bool no_panner_reset;
284 XMLNode* deferred_state;
285 Buffer::Type _default_type;
287 virtual void set_deferred_state() {}
289 void reset_peak_meters();
290 void reset_panner ();
292 virtual uint32_t pans_required() const { return _ninputs; }
294 static void apply_declick (vector<Sample*>&, uint32_t nbufs, jack_nframes_t nframes,
295 gain_t initial, gain_t target, bool invert_polarity);
297 struct GainControllable : public PBD::Controllable {
298 GainControllable (IO& i) : io (i) {}
300 void set_value (float val);
301 float get_value (void) const;
306 GainControllable _gain_control;
308 /* state management */
310 Change restore_state (State&);
311 StateManager::State* state_factory (std::string why) const;
315 jack_nframes_t last_automation_snapshot;
316 static jack_nframes_t _automation_interval;
318 AutoState _gain_automation_state;
319 AutoStyle _gain_automation_style;
321 bool apply_gain_automation;
322 Curve _gain_automation_curve;
324 int save_automation (const string&);
325 int load_automation (const string&);
327 Glib::Mutex automation_lock;
329 /* AudioTrack::deprecated_use_diskstream_connections() needs these */
331 int set_inputs (const string& str);
332 int set_outputs (const string& str);
334 static bool connecting_legal;
335 static bool ports_legal;
342 /* are these the best variable names ever, or what? */
344 sigc::connection input_connection_configuration_connection;
345 sigc::connection output_connection_configuration_connection;
346 sigc::connection input_connection_connection_connection;
347 sigc::connection output_connection_connection_connection;
349 static bool panners_legal;
351 int connecting_became_legal ();
352 int panners_became_legal ();
353 sigc::connection connection_legal_c;
354 sigc::connection port_legal_c;
355 sigc::connection panner_legal_c;
363 static int parse_io_string (const string&, vector<string>& chns);
365 static int parse_gain_string (const string&, vector<string>& chns);
367 int set_sources (vector<string>&, void *src, bool add);
368 int set_destinations (vector<string>&, void *src, bool add);
370 int ensure_inputs (uint32_t, bool clear, bool lockit, void *src);
371 int ensure_outputs (uint32_t, bool clear, bool lockit, void *src);
373 void drop_input_connection ();
374 void drop_output_connection ();
376 void input_connection_configuration_changed ();
377 void input_connection_connection_changed (int);
378 void output_connection_configuration_changed ();
379 void output_connection_connection_changed (int);
381 int create_ports (const XMLNode&);
382 int make_connections (const XMLNode&);
384 void setup_peak_meters ();
387 bool ensure_inputs_locked (uint32_t, bool clear, void *src);
388 bool ensure_outputs_locked (uint32_t, bool clear, void *src);
390 int32_t find_input_port_hole ();
391 int32_t find_output_port_hole ();
394 }; /* namespace ARDOUR */
396 #endif /*__ardour_io_h__ */