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/redirect.h>
43 #include <ardour/types.h>
58 class Route : public IO
62 typedef list<boost::shared_ptr<Redirect> > RedirectList;
72 Route (Session&, std::string name, int input_min, int input_max, int output_min, int output_max,
73 Flag flags = Flag(0), DataType default_type = DataType::AUDIO);
74 Route (Session&, const XMLNode&, DataType default_type = DataType::AUDIO);
77 std::string comment() { return _comment; }
78 void set_comment (std::string str, void *src);
80 long order_key (const char* name) const;
81 void set_order_key (const char* name, long n);
83 bool hidden() const { return _flags & Hidden; }
84 bool master() const { return _flags & MasterOut; }
85 bool control() const { return _flags & ControlOut; }
87 /* these are the core of the API of a Route. see the protected sections as well */
90 virtual int roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame,
91 nframes_t offset, int declick, bool can_record, bool rec_monitors_input);
93 virtual int no_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame,
94 nframes_t offset, bool state_changing, bool can_record, bool rec_monitors_input);
96 virtual int silent_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame,
97 nframes_t offset, bool can_record, bool rec_monitors_input);
98 virtual void toggle_monitor_input ();
99 virtual bool can_record() { return false; }
100 virtual void set_record_enable (bool yn, void *src) {}
101 virtual bool record_enabled() const { return false; }
102 virtual void handle_transport_stopped (bool abort, bool did_locate, bool flush_redirects);
103 virtual void set_pending_declick (int);
105 /* end of vfunc-based API */
107 /* override IO::set_gain() to provide group control */
109 void set_gain (gain_t val, void *src);
110 void inc_gain (gain_t delta, void *src);
112 bool active() const { return _active; }
113 void set_active (bool yn);
115 void set_solo (bool yn, void *src);
116 bool soloed() const { return _soloed; }
118 void set_solo_safe (bool yn, void *src);
119 bool solo_safe() const { return _solo_safe; }
121 void set_mute (bool yn, void *src);
122 bool muted() const { return _muted; }
123 bool solo_muted() const { return desired_solo_gain == 0.0; }
125 void set_mute_config (mute_type, bool, void *src);
126 bool get_mute_config (mute_type);
128 void set_edit_group (RouteGroup *, void *);
129 void drop_edit_group (void *);
130 RouteGroup *edit_group () { return _edit_group; }
132 void set_mix_group (RouteGroup *, void *);
133 void drop_mix_group (void *);
134 RouteGroup *mix_group () { return _mix_group; }
136 virtual void set_meter_point (MeterPoint, void *src);
137 MeterPoint meter_point() const { return _meter_point; }
141 void flush_redirects ();
143 template<class T> void foreach_redirect (T *obj, void (T::*func)(boost::shared_ptr<Redirect>)) {
144 Glib::RWLock::ReaderLock lm (redirect_lock);
145 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
150 boost::shared_ptr<Redirect> nth_redirect (uint32_t n) {
151 Glib::RWLock::ReaderLock lm (redirect_lock);
152 RedirectList::iterator i;
153 for (i = _redirects.begin(); i != _redirects.end() && n; ++i, --n);
154 if (i == _redirects.end()) {
155 return boost::shared_ptr<Redirect> ();
161 ChanCount max_redirect_outs () const { return redirect_max_outs; }
163 // FIXME: remove/replace err_streams parameters with something appropriate
164 // they are used by 'wierd_plugin_dialog'(sic) to display the number of input streams
165 // at the insertion point if the insert fails
166 int add_redirect (boost::shared_ptr<Redirect>, void *src, uint32_t* err_streams = 0);
167 int add_redirects (const RedirectList&, void *src, uint32_t* err_streams = 0);
168 int remove_redirect (boost::shared_ptr<Redirect>, void *src, uint32_t* err_streams = 0);
169 int copy_redirects (const Route&, Placement, uint32_t* err_streams = 0);
170 int sort_redirects (uint32_t* err_streams = 0);
171 void disable_redirects (Placement);
172 void disable_redirects ();
173 void disable_plugins (Placement);
174 void disable_plugins ();
175 void ab_plugins (bool forward);
176 void clear_redirects (Placement, void *src);
177 void all_redirects_flip();
178 void all_redirects_active (Placement, bool state);
180 virtual nframes_t update_total_latency();
181 nframes_t signal_latency() const { return _own_latency; }
182 virtual void set_latency_delay (nframes_t);
184 sigc::signal<void,void*> solo_changed;
185 sigc::signal<void,void*> solo_safe_changed;
186 sigc::signal<void,void*> comment_changed;
187 sigc::signal<void,void*> mute_changed;
188 sigc::signal<void,void*> pre_fader_changed;
189 sigc::signal<void,void*> post_fader_changed;
190 sigc::signal<void,void*> control_outs_changed;
191 sigc::signal<void,void*> main_outs_changed;
192 sigc::signal<void,void*> redirects_changed;
193 sigc::signal<void,void*> record_enable_changed;
194 sigc::signal<void,void*> edit_group_changed;
195 sigc::signal<void,void*> mix_group_changed;
196 sigc::signal<void> active_changed;
197 sigc::signal<void,void*> meter_change;
199 /* gui's call this for their own purposes. */
201 sigc::signal<void,std::string,void*> gui_changed;
205 XMLNode& get_state();
206 int set_state(const XMLNode& node);
207 virtual XMLNode& get_template();
209 XMLNode& get_redirect_state ();
210 int set_redirect_state (const XMLNode&);
212 sigc::signal<void,void*> SelectedChanged;
214 int set_control_outs (const vector<std::string>& ports);
215 IO* control_outs() { return _control_outs; }
217 bool feeds (boost::shared_ptr<Route>);
218 set<boost::shared_ptr<Route> > fed_by;
220 struct ToggleControllable : public PBD::Controllable {
226 ToggleControllable (std::string name, Route&, ToggleType);
227 void set_value (float);
228 float get_value (void) const;
234 PBD::Controllable& solo_control() {
235 return _solo_control;
238 PBD::Controllable& mute_control() {
239 return _mute_control;
242 void automation_snapshot (nframes_t now);
243 void protect_automation ();
245 void set_remote_control_id (uint32_t id);
246 uint32_t remote_control_id () const;
247 sigc::signal<void> RemoteControlIDChanged;
250 friend class Session;
252 void set_solo_mute (bool yn);
253 void set_block_size (nframes_t nframes);
254 bool has_external_redirects() const;
255 void curve_reallocate ();
260 /* tight cache-line access here is more important than sheer speed of
267 bool _recordable : 1;
269 bool _mute_affects_pre_fader : 1;
270 bool _mute_affects_post_fader : 1;
271 bool _mute_affects_control_outs : 1;
272 bool _mute_affects_main_outs : 1;
274 bool _declickable : 1;
275 int _pending_declick;
277 MeterPoint _meter_point;
281 gain_t desired_solo_gain;
282 gain_t desired_mute_gain;
284 nframes_t check_initial_delay (nframes_t, nframes_t&, nframes_t&);
286 nframes_t _initial_delay;
287 nframes_t _roll_delay;
288 nframes_t _own_latency;
289 RedirectList _redirects;
290 Glib::RWLock redirect_lock;
292 Glib::Mutex control_outs_lock;
293 RouteGroup *_edit_group;
294 RouteGroup *_mix_group;
295 std::string _comment;
296 bool _have_internal_generator;
298 ToggleControllable _solo_control;
299 ToggleControllable _mute_control;
301 void passthru (nframes_t start_frame, nframes_t end_frame,
302 nframes_t nframes, nframes_t offset, int declick, bool meter_inputs);
304 virtual void process_output_buffers (BufferSet& bufs,
305 nframes_t start_frame, nframes_t end_frame,
306 nframes_t nframes, nframes_t offset, bool with_redirects, int declick,
311 virtual XMLNode& state(bool);
313 void passthru_silence (nframes_t start_frame, nframes_t end_frame,
314 nframes_t nframes, nframes_t offset, int declick,
317 void silence (nframes_t nframes, nframes_t offset);
319 sigc::connection input_signal_connection;
321 ChanCount redirect_max_outs;
322 uint32_t _remote_control_id;
324 uint32_t pans_required() const;
325 ChanCount n_process_buffers ();
327 virtual int _set_state (const XMLNode&, bool call_base);
332 static uint32_t order_key_cnt;
336 bool operator()(const char* s1, const char* s2) const
338 return strcmp(s1, s2) < 0;
342 typedef std::map<const char*,long,ltstr> OrderKeys;
343 OrderKeys order_keys;
345 void input_change_handler (IOChange, void *src);
346 void output_change_handler (IOChange, void *src);
348 bool legal_redirect (Redirect&);
349 int reset_plugin_counts (uint32_t*); /* locked */
350 int _reset_plugin_counts (uint32_t*); /* unlocked */
352 /* plugin count handling */
355 boost::shared_ptr<ARDOUR::Insert> insert;
360 InsertCount (boost::shared_ptr<ARDOUR::Insert> ins) : insert (ins), cnt (-1) {}
363 int32_t apply_some_plugin_counts (std::list<InsertCount>& iclist);
364 int32_t check_some_plugin_counts (std::list<InsertCount>& iclist, int32_t required_inputs, uint32_t* err_streams);
366 void set_deferred_state ();
367 void add_redirect_from_xml (const XMLNode&);
368 void redirect_active_proxy (Redirect*, void*);
371 } // namespace ARDOUR
373 #endif /* __ardour_route_h__ */