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.
21 #ifndef __ardour_route_h__
22 #define __ardour_route_h__
30 #include <boost/shared_ptr.hpp>
32 #include <pbd/fastlog.h>
33 #include <glibmm/thread.h>
34 #include <pbd/xml++.h>
36 #include <pbd/stateful.h>
37 #include <pbd/controllable.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);
75 Route (Session&, const XMLNode&);
78 std::string comment() { return _comment; }
79 void set_comment (std::string str, void *src);
81 long order_key(std::string name) const;
82 void set_order_key (std::string name, long n);
84 bool hidden() const { return _flags & Hidden; }
85 bool master() const { return _flags & MasterOut; }
86 bool 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 (jack_nframes_t nframes, jack_nframes_t start_frame, jack_nframes_t end_frame,
92 jack_nframes_t offset, int declick, bool can_record, bool rec_monitors_input);
94 virtual int no_roll (jack_nframes_t nframes, jack_nframes_t start_frame, jack_nframes_t end_frame,
95 jack_nframes_t offset, bool state_changing, bool can_record, bool rec_monitors_input);
97 virtual int silent_roll (jack_nframes_t nframes, jack_nframes_t start_frame, jack_nframes_t end_frame,
98 jack_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_redirects);
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 bool active() const { return _active; }
114 void set_active (bool yn);
116 void set_solo (bool yn, void *src);
117 bool soloed() const { return _soloed; }
119 void set_solo_safe (bool yn, void *src);
120 bool solo_safe() const { return _solo_safe; }
122 void set_mute (bool yn, void *src);
123 bool muted() const { return _muted; }
125 void set_mute_config (mute_type, bool, void *src);
126 bool get_mute_config (mute_type);
128 void set_phase_invert (bool yn, void *src);
129 bool phase_invert() const { return _phase_invert; }
131 void set_edit_group (RouteGroup *, void *);
132 void drop_edit_group (void *);
133 RouteGroup *edit_group () { return _edit_group; }
135 void set_mix_group (RouteGroup *, void *);
136 void drop_mix_group (void *);
137 RouteGroup *mix_group () { return _mix_group; }
139 virtual void set_meter_point (MeterPoint, void *src);
140 MeterPoint meter_point() const { return _meter_point; }
144 void flush_redirects ();
146 template<class T> void foreach_redirect (T *obj, void (T::*func)(boost::shared_ptr<Redirect>)) {
147 Glib::RWLock::ReaderLock lm (redirect_lock);
148 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
153 boost::shared_ptr<Redirect> nth_redirect (uint32_t n) {
154 Glib::RWLock::ReaderLock lm (redirect_lock);
155 RedirectList::iterator i;
156 for (i = _redirects.begin(); i != _redirects.end() && n; ++i, --n);
157 if (i == _redirects.end()) {
158 return boost::shared_ptr<Redirect> ();
164 ChanCount max_redirect_outs () const { return redirect_max_outs; }
166 // FIXME: remove/replace err_streams parameters with something appropriate
167 // they are used by 'wierd_plugin_dialog'(sic) to display the number of input streams
168 // at the insertion point if the insert fails
169 int add_redirect (boost::shared_ptr<Redirect>, void *src, uint32_t* err_streams = 0);
170 int add_redirects (const RedirectList&, void *src, uint32_t* err_streams = 0);
171 int remove_redirect (boost::shared_ptr<Redirect>, void *src, uint32_t* err_streams = 0);
172 int copy_redirects (const Route&, Placement, uint32_t* err_streams = 0);
173 int sort_redirects (uint32_t* err_streams = 0);
175 void clear_redirects (void *src);
176 void all_redirects_flip();
177 void all_redirects_active (bool state);
179 virtual jack_nframes_t update_total_latency();
180 jack_nframes_t signal_latency() const { return _own_latency; }
181 virtual void set_latency_delay (jack_nframes_t);
183 sigc::signal<void,void*> solo_changed;
184 sigc::signal<void,void*> solo_safe_changed;
185 sigc::signal<void,void*> comment_changed;
186 sigc::signal<void,void*> mute_changed;
187 sigc::signal<void,void*> pre_fader_changed;
188 sigc::signal<void,void*> post_fader_changed;
189 sigc::signal<void,void*> control_outs_changed;
190 sigc::signal<void,void*> main_outs_changed;
191 sigc::signal<void,void*> redirects_changed;
192 sigc::signal<void,void*> record_enable_changed;
193 sigc::signal<void,void*> edit_group_changed;
194 sigc::signal<void,void*> mix_group_changed;
195 sigc::signal<void> active_changed;
196 sigc::signal<void,void*> meter_change;
198 sigc::signal<void> GoingAway;
200 /* gui's call this for their own purposes. */
202 sigc::signal<void,std::string,void*> gui_changed;
206 XMLNode& get_state();
207 int set_state(const XMLNode& node);
208 virtual XMLNode& get_template();
210 sigc::signal<void,void*> SelectedChanged;
214 UndoAction get_memento() const;
215 void set_state (state_id_t);
217 int set_control_outs (const vector<std::string>& ports);
218 IO* control_outs() { return _control_outs; }
220 bool feeds (boost::shared_ptr<Route>);
221 set<boost::shared_ptr<Route> > fed_by;
223 struct ToggleControllable : public PBD::Controllable {
229 ToggleControllable (Route&, ToggleType);
230 void set_value (float);
231 float get_value (void) const;
237 PBD::Controllable& solo_control() {
238 return _solo_control;
241 PBD::Controllable& mute_control() {
242 return _mute_control;
245 void automation_snapshot (jack_nframes_t now);
247 void protect_automation ();
249 void set_remote_control_id (uint32_t id);
250 uint32_t remote_control_id () const;
251 sigc::signal<void> RemoteControlIDChanged;
254 friend class Session;
256 void set_solo_mute (bool yn);
257 void set_block_size (jack_nframes_t nframes);
258 bool has_external_redirects() const;
259 void curve_reallocate ();
262 unsigned char _flags;
264 /* tight cache-line access here is more important than sheer speed of
270 bool _solo_muted : 1;
272 bool _phase_invert : 1;
273 bool _recordable : 1;
275 bool _mute_affects_pre_fader : 1;
276 bool _mute_affects_post_fader : 1;
277 bool _mute_affects_control_outs : 1;
278 bool _mute_affects_main_outs : 1;
280 bool _declickable : 1;
281 int _pending_declick;
283 MeterPoint _meter_point;
287 gain_t desired_solo_gain;
288 gain_t desired_mute_gain;
290 jack_nframes_t check_initial_delay (jack_nframes_t, jack_nframes_t&, jack_nframes_t&);
292 jack_nframes_t _initial_delay;
293 jack_nframes_t _roll_delay;
294 jack_nframes_t _own_latency;
295 RedirectList _redirects;
296 Glib::RWLock redirect_lock;
298 Glib::Mutex control_outs_lock;
299 RouteGroup *_edit_group;
300 RouteGroup *_mix_group;
301 std::string _comment;
302 bool _have_internal_generator;
304 ToggleControllable _solo_control;
305 ToggleControllable _mute_control;
307 void passthru (jack_nframes_t start_frame, jack_nframes_t end_frame,
308 jack_nframes_t nframes, jack_nframes_t offset, int declick, bool meter_inputs);
310 virtual void process_output_buffers (BufferSet& bufs,
311 jack_nframes_t start_frame, jack_nframes_t end_frame,
312 jack_nframes_t nframes, jack_nframes_t offset, bool with_redirects, int declick,
316 /* for derived classes */
318 virtual XMLNode& state(bool);
320 void silence (jack_nframes_t nframes, jack_nframes_t offset);
321 sigc::connection input_signal_connection;
323 state_id_t _current_state_id;
324 ChanCount redirect_max_outs;
325 uint32_t _remote_control_id;
327 uint32_t pans_required() const;
328 ChanCount n_process_buffers ();
333 static uint32_t order_key_cnt;
334 typedef std::map<std::string,long> OrderKeys;
335 OrderKeys order_keys;
337 void input_change_handler (IOChange, void *src);
338 void output_change_handler (IOChange, void *src);
340 bool legal_redirect (Redirect&);
341 int reset_plugin_counts (uint32_t*); /* locked */
342 int _reset_plugin_counts (uint32_t*); /* unlocked */
344 /* plugin count handling */
347 boost::shared_ptr<ARDOUR::Insert> insert;
352 InsertCount (boost::shared_ptr<ARDOUR::Insert> ins) : insert (ins), cnt (-1) {}
355 int32_t apply_some_plugin_counts (std::list<InsertCount>& iclist);
356 int32_t check_some_plugin_counts (std::list<InsertCount>& iclist, int32_t required_inputs, uint32_t* err_streams);
358 void set_deferred_state ();
359 void add_redirect_from_xml (const XMLNode&);
360 void redirect_active_proxy (Redirect*, void*);
363 } // namespace ARDOUR
365 #endif /* __ardour_route_h__ */