2 Copyright (C) 2000-2002 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_route_h__
21 #define __ardour_route_h__
29 #include <boost/shared_ptr.hpp>
31 #include <pbd/fastlog.h>
32 #include <glibmm/thread.h>
33 #include <pbd/xml++.h>
35 #include <pbd/stateful.h>
36 #include <pbd/controllable.h>
37 #include <pbd/destructible.h>
39 #include <ardour/ardour.h>
40 #include <ardour/io.h>
41 #include <ardour/session.h>
42 #include <ardour/io_processor.h>
43 #include <ardour/types.h>
58 class Route : public IO
62 typedef list<boost::shared_ptr<Processor> > ProcessorList;
73 Route (Session&, std::string name, int input_min, int input_max, int output_min, int output_max,
74 Flag flags = Flag(0), DataType default_type = DataType::AUDIO);
75 Route (Session&, const XMLNode&, DataType default_type = DataType::AUDIO);
78 std::string comment() { return _comment; }
79 void set_comment (std::string str, void *src);
81 long order_key (const char* name) const;
82 void set_order_key (const char* name, long n);
84 bool is_hidden() const { return _flags & Hidden; }
85 bool is_master() const { return _flags & MasterOut; }
86 bool is_control() const { return _flags & ControlOut; }
88 /* these are the core of the API of a Route. see the protected sections as well */
91 virtual int roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame,
92 nframes_t offset, int declick, bool can_record, bool rec_monitors_input);
94 virtual int no_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame,
95 nframes_t offset, bool state_changing, bool can_record, bool rec_monitors_input);
97 virtual int silent_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame,
98 nframes_t offset, bool can_record, bool rec_monitors_input);
99 virtual void toggle_monitor_input ();
100 virtual bool can_record() { return false; }
101 virtual void set_record_enable (bool yn, void *src) {}
102 virtual bool record_enabled() const { return false; }
103 virtual void handle_transport_stopped (bool abort, bool did_locate, bool flush_processors);
104 virtual void set_pending_declick (int);
106 /* end of vfunc-based API */
108 /* override IO::set_gain() to provide group control */
110 void set_gain (gain_t val, void *src);
111 void inc_gain (gain_t delta, void *src);
113 void set_solo (bool yn, void *src);
114 bool soloed() const { return _soloed; }
116 void set_solo_safe (bool yn, void *src);
117 bool solo_safe() const { return _solo_safe; }
119 void set_mute (bool yn, void *src);
120 bool muted() const { return _muted; }
121 bool solo_muted() const { return desired_solo_gain == 0.0; }
123 void set_mute_config (mute_type, bool, void *src);
124 bool get_mute_config (mute_type);
126 void set_edit_group (RouteGroup *, void *);
127 void drop_edit_group (void *);
128 RouteGroup *edit_group () { return _edit_group; }
130 void set_mix_group (RouteGroup *, void *);
131 void drop_mix_group (void *);
132 RouteGroup *mix_group () { return _mix_group; }
134 virtual void set_meter_point (MeterPoint, void *src);
135 MeterPoint meter_point() const { return _meter_point; }
139 void flush_processors ();
141 template<class T> void foreach_processor (T *obj, void (T::*func)(boost::shared_ptr<Processor>)) {
142 Glib::RWLock::ReaderLock lm (_processor_lock);
143 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
148 boost::shared_ptr<Processor> nth_processor (uint32_t n) {
149 Glib::RWLock::ReaderLock lm (_processor_lock);
150 ProcessorList::iterator i;
151 for (i = _processors.begin(); i != _processors.end() && n; ++i, --n);
152 if (i == _processors.end()) {
153 return boost::shared_ptr<IOProcessor> ();
159 ChanCount max_processor_outs () const { return processor_max_outs; }
160 ChanCount pre_fader_streams() const;
162 /** A record of the stream configuration at some point in the processor list.
163 * Used to return where and why an processor list configuration request failed.
165 struct ProcessorStreams {
166 ProcessorStreams(size_t i=0, ChanCount c=ChanCount()) : index(i), count(c) {}
168 size_t index; ///< Index of processor where configuration failed
169 ChanCount count; ///< Input requested of processor
172 int add_processor (boost::shared_ptr<Processor>, ProcessorStreams* err = 0);
173 int add_processors (const ProcessorList&, ProcessorStreams* err = 0);
174 int remove_processor (boost::shared_ptr<Processor>, ProcessorStreams* err = 0);
175 int copy_processors (const Route&, Placement, ProcessorStreams* err = 0);
176 int sort_processors (ProcessorStreams* err = 0);
177 void disable_processors (Placement);
178 void disable_processors ();
179 void disable_plugins (Placement);
180 void disable_plugins ();
181 void ab_plugins (bool forward);
182 void clear_processors (Placement);
183 void all_processors_flip();
184 void all_processors_active (Placement, bool state);
186 virtual nframes_t update_total_latency();
187 void set_latency_delay (nframes_t);
188 void set_user_latency (nframes_t);
189 nframes_t initial_delay() const { return _initial_delay; }
191 sigc::signal<void,void*> solo_changed;
192 sigc::signal<void,void*> solo_safe_changed;
193 sigc::signal<void,void*> comment_changed;
194 sigc::signal<void,void*> mute_changed;
195 sigc::signal<void,void*> pre_fader_changed;
196 sigc::signal<void,void*> post_fader_changed;
197 sigc::signal<void,void*> control_outs_changed;
198 sigc::signal<void,void*> main_outs_changed;
199 sigc::signal<void> processors_changed;
200 sigc::signal<void,void*> record_enable_changed;
201 sigc::signal<void,void*> edit_group_changed;
202 sigc::signal<void,void*> mix_group_changed;
203 sigc::signal<void,void*> meter_change;
204 sigc::signal<void> signal_latency_changed;
205 sigc::signal<void> initial_delay_changed;
207 /* gui's call this for their own purposes. */
209 sigc::signal<void,std::string,void*> gui_changed;
213 XMLNode& get_state();
214 int set_state(const XMLNode& node);
215 virtual XMLNode& get_template();
217 XMLNode& get_processor_state ();
218 int set_processor_state (const XMLNode&);
220 sigc::signal<void,void*> SelectedChanged;
222 int set_control_outs (const vector<std::string>& ports);
223 IO* control_outs() { return _control_outs; }
225 bool feeds (boost::shared_ptr<Route>);
226 set<boost::shared_ptr<Route> > fed_by;
228 struct ToggleControllable : public PBD::Controllable {
234 ToggleControllable (std::string name, Route&, ToggleType);
235 void set_value (float);
236 float get_value (void) const;
242 boost::shared_ptr<PBD::Controllable> solo_control() {
243 return _solo_control;
246 boost::shared_ptr<PBD::Controllable> mute_control() {
247 return _mute_control;
250 void automation_snapshot (nframes_t now);
251 void protect_automation ();
253 void set_remote_control_id (uint32_t id);
254 uint32_t remote_control_id () const;
255 sigc::signal<void> RemoteControlIDChanged;
257 void sync_order_keys ();
258 static sigc::signal<void> SyncOrderKeys;
261 friend class Session;
263 void set_solo_mute (bool yn);
264 void set_block_size (nframes_t nframes);
265 bool has_external_redirects() const;
266 void curve_reallocate ();
271 /* tight cache-line access here is more important than sheer speed of
278 bool _recordable : 1;
279 bool _mute_affects_pre_fader : 1;
280 bool _mute_affects_post_fader : 1;
281 bool _mute_affects_control_outs : 1;
282 bool _mute_affects_main_outs : 1;
284 bool _declickable : 1;
285 int _pending_declick;
287 MeterPoint _meter_point;
291 gain_t desired_solo_gain;
292 gain_t desired_mute_gain;
296 nframes_t _initial_delay;
297 nframes_t _roll_delay;
298 ProcessorList _processors;
299 Glib::RWLock _processor_lock;
301 Glib::Mutex _control_outs_lock;
302 RouteGroup *_edit_group;
303 RouteGroup *_mix_group;
304 std::string _comment;
305 bool _have_internal_generator;
307 boost::shared_ptr<ToggleControllable> _solo_control;
308 boost::shared_ptr<ToggleControllable> _mute_control;
310 nframes_t check_initial_delay (nframes_t, nframes_t&, nframes_t&);
312 void passthru (nframes_t start_frame, nframes_t end_frame,
313 nframes_t nframes, nframes_t offset, int declick, bool meter_inputs);
315 virtual void process_output_buffers (BufferSet& bufs,
316 nframes_t start_frame, nframes_t end_frame,
317 nframes_t nframes, nframes_t offset, bool with_processors, int declick,
322 virtual XMLNode& state(bool);
324 void passthru_silence (nframes_t start_frame, nframes_t end_frame,
325 nframes_t nframes, nframes_t offset, int declick,
328 void silence (nframes_t nframes, nframes_t offset);
330 sigc::connection input_signal_connection;
332 ChanCount processor_max_outs;
333 uint32_t _remote_control_id;
335 uint32_t pans_required() const;
336 ChanCount n_process_buffers ();
338 virtual int _set_state (const XMLNode&, bool call_base);
339 virtual void _set_processor_states (const XMLNodeList&);
344 static uint32_t order_key_cnt;
348 bool operator()(const char* s1, const char* s2) const
350 return strcmp(s1, s2) < 0;
354 typedef std::map<const char*,long,ltstr> OrderKeys;
355 OrderKeys order_keys;
357 void input_change_handler (IOChange, void *src);
358 void output_change_handler (IOChange, void *src);
360 int reset_plugin_counts (ProcessorStreams*); /* locked */
361 int _reset_plugin_counts (ProcessorStreams*); /* unlocked */
363 /* processor I/O channels and plugin count handling */
365 struct ProcessorCount {
366 boost::shared_ptr<ARDOUR::Processor> processor;
370 ProcessorCount (boost::shared_ptr<ARDOUR::Processor> ins) : processor(ins) {}
373 int32_t apply_some_plugin_counts (std::list<ProcessorCount>& iclist);
374 bool check_some_plugin_counts (std::list<ProcessorCount>& iclist, ChanCount required_inputs, ProcessorStreams* err_streams);
376 void set_deferred_state ();
377 void add_processor_from_xml (const XMLNode&);
380 } // namespace ARDOUR
382 #endif /* __ardour_route_h__ */