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__
30 #include <boost/shared_ptr.hpp>
31 #include <boost/weak_ptr.hpp>
32 #include <boost/dynamic_bitset.hpp>
34 #include <glibmm/thread.h>
35 #include "pbd/fastlog.h"
36 #include "pbd/xml++.h"
38 #include "pbd/stateful.h"
39 #include "pbd/controllable.h"
40 #include "pbd/destructible.h"
42 #include "ardour/ardour.h"
43 #include "ardour/io.h"
44 #include "ardour/types.h"
45 #include "ardour/mute_master.h"
46 #include "ardour/route_group_member.h"
47 #include "ardour/graphnode.h"
48 #include "ardour/automatable.h"
60 class MonitorProcessor;
62 class Route : public SessionObject, public Automatable, public RouteGroupMember, public GraphNode
66 typedef std::list<boost::shared_ptr<Processor> > ProcessorList;
74 Route (Session&, std::string name, Flag flags = Flag(0), DataType default_type = DataType::AUDIO);
79 boost::shared_ptr<IO> input() const { return _input; }
80 boost::shared_ptr<IO> output() const { return _output; }
82 ChanCount n_inputs() const { return _input->n_ports(); }
83 ChanCount n_outputs() const { return _output->n_ports(); }
85 bool active() const { return _active; }
86 void set_active (bool yn);
88 static std::string ensure_track_or_route_name(std::string, Session &);
90 std::string comment() { return _comment; }
91 void set_comment (std::string str, void *src);
93 bool set_name (const std::string& str);
95 int32_t order_key (std::string const &) const;
96 void set_order_key (std::string const &, int32_t);
98 bool is_hidden() const { return _flags & Hidden; }
99 bool is_master() const { return _flags & MasterOut; }
100 bool is_monitor() const { return _flags & MonitorOut; }
102 /* these are the core of the API of a Route. see the protected sections as well */
104 virtual int roll (nframes_t nframes, framepos_t start_frame, framepos_t end_frame,
105 int declick, bool can_record, bool rec_monitors_input, bool& need_butler);
107 virtual int no_roll (nframes_t nframes, framepos_t start_frame, framepos_t end_frame,
108 bool state_changing, bool can_record, bool rec_monitors_input);
110 virtual int silent_roll (nframes_t nframes, framepos_t start_frame, framepos_t end_frame,
111 bool can_record, bool rec_monitors_input, bool& need_butler);
113 virtual void toggle_monitor_input ();
114 virtual bool can_record() { return false; }
116 virtual void set_record_enabled (bool /*yn*/, void * /*src*/) {}
117 virtual bool record_enabled() const { return false; }
118 virtual void handle_transport_stopped (bool abort, bool did_locate, bool flush_processors);
119 virtual void set_pending_declick (int);
121 /* end of vfunc-based API */
123 void shift (framepos_t, framepos_t);
125 void set_gain (gain_t val, void *src);
126 void inc_gain (gain_t delta, void *src);
128 void set_mute_points (MuteMaster::MutePoint);
129 MuteMaster::MutePoint mute_points () const;
132 void set_mute (bool yn, void* src);
134 /* controls use set_solo() to modify this route's solo state
137 void set_solo (bool yn, void *src);
138 bool soloed () const { return self_soloed () || soloed_by_others (); }
140 bool soloed_by_others () const { return _soloed_by_others_upstream||_soloed_by_others_downstream; }
141 bool soloed_by_others_upstream () const { return _soloed_by_others_upstream; }
142 bool soloed_by_others_downstream () const { return _soloed_by_others_downstream; }
143 bool self_soloed () const { return _self_solo; }
145 void set_solo_isolated (bool yn, void *src);
146 bool solo_isolated() const;
148 void set_solo_safe (bool yn, void *src);
149 bool solo_safe() const;
151 void set_listen (bool yn, void* src);
152 bool listening () const;
154 void set_phase_invert (uint32_t, bool yn);
155 void set_phase_invert (boost::dynamic_bitset<>);
156 bool phase_invert (uint32_t) const;
157 boost::dynamic_bitset<> phase_invert () const;
159 void set_denormal_protection (bool yn);
160 bool denormal_protection() const;
162 void set_meter_point (MeterPoint);
163 void infer_meter_point () const;
164 MeterPoint meter_point() const { return _meter_point; }
169 boost::shared_ptr<Amp> amp() const { return _amp; }
170 PeakMeter& peak_meter() { return *_meter.get(); }
171 const PeakMeter& peak_meter() const { return *_meter.get(); }
172 boost::shared_ptr<PeakMeter> shared_peak_meter() const { return _meter; }
174 void flush_processors ();
176 void foreach_processor (boost::function<void(boost::weak_ptr<Processor>)> method) {
177 Glib::RWLock::ReaderLock lm (_processor_lock);
178 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
179 method (boost::weak_ptr<Processor> (*i));
183 boost::shared_ptr<Processor> nth_processor (uint32_t n) {
184 Glib::RWLock::ReaderLock lm (_processor_lock);
185 ProcessorList::iterator i;
186 for (i = _processors.begin(); i != _processors.end() && n; ++i, --n) {}
187 if (i == _processors.end()) {
188 return boost::shared_ptr<Processor> ();
194 boost::shared_ptr<Processor> nth_plugin (uint32_t n);
195 boost::shared_ptr<Processor> nth_send (uint32_t n);
197 bool processor_is_prefader (boost::shared_ptr<Processor> p);
199 bool has_io_processor_named (const std::string&);
200 ChanCount max_processor_streams () const { return processor_max_streams; }
202 /* special processors */
204 boost::shared_ptr<Delivery> monitor_send() const { return _monitor_send; }
205 boost::shared_ptr<Delivery> main_outs() const { return _main_outs; }
206 boost::shared_ptr<InternalReturn> internal_return() const { return _intreturn; }
207 boost::shared_ptr<MonitorProcessor> monitor_control() const { return _monitor_control; }
208 boost::shared_ptr<Send> internal_send_for (boost::shared_ptr<const Route> target) const;
209 void add_internal_return ();
210 BufferSet* get_return_buffer () const;
211 void release_return_buffer () const;
212 void put_monitor_send_at (Placement);
214 /** A record of the stream configuration at some point in the processor list.
215 * Used to return where and why an processor list configuration request failed.
217 struct ProcessorStreams {
218 ProcessorStreams(size_t i=0, ChanCount c=ChanCount()) : index(i), count(c) {}
220 uint32_t index; ///< Index of processor where configuration failed
221 ChanCount count; ///< Input requested of processor
224 int add_processor (boost::shared_ptr<Processor>, Placement placement, ProcessorStreams* err = 0);
225 int add_processor (boost::shared_ptr<Processor>, ProcessorList::iterator iter, ProcessorStreams* err = 0, bool activation_allowed = true);
226 int add_processors (const ProcessorList&, boost::shared_ptr<Processor> before, ProcessorStreams* err = 0);
227 int add_processors (const ProcessorList&, ProcessorList::iterator iter, ProcessorStreams* err = 0);
228 int remove_processor (boost::shared_ptr<Processor>, ProcessorStreams* err = 0);
229 int remove_processors (const ProcessorList&, ProcessorStreams* err = 0);
230 int reorder_processors (const ProcessorList& new_order, ProcessorStreams* err = 0);
231 void disable_processors (Placement);
232 void disable_processors ();
233 void disable_plugins (Placement);
234 void disable_plugins ();
235 void ab_plugins (bool forward);
236 void clear_processors (Placement);
237 void all_processors_flip();
238 void all_processors_active (Placement, bool state);
240 virtual nframes_t update_total_latency();
241 void set_latency_delay (nframes_t);
242 void set_user_latency (nframes_t);
243 nframes_t initial_delay() const { return _initial_delay; }
245 PBD::Signal0<void> active_changed;
246 PBD::Signal0<void> phase_invert_changed;
247 PBD::Signal0<void> denormal_protection_changed;
248 PBD::Signal1<void,void*> listen_changed;
249 PBD::Signal2<void,bool,void*> solo_changed;
250 PBD::Signal1<void,void*> solo_safe_changed;
251 PBD::Signal1<void,void*> solo_isolated_changed;
252 PBD::Signal1<void,void*> comment_changed;
253 PBD::Signal1<void,void*> mute_changed;
254 PBD::Signal0<void> mute_points_changed;
256 /** the processors have changed; the parameter indicates what changed */
257 PBD::Signal1<void,RouteProcessorChange> processors_changed;
258 PBD::Signal1<void,void*> record_enable_changed;
259 /** the metering point has changed */
260 PBD::Signal0<void> meter_change;
261 PBD::Signal0<void> signal_latency_changed;
262 PBD::Signal0<void> initial_delay_changed;
263 PBD::Signal0<void> order_key_changed;
264 PBD::Signal0<void> io_changed;
266 /* gui's call this for their own purposes. */
268 PBD::Signal2<void,std::string,void*> gui_changed;
272 XMLNode& get_state();
273 int set_state (const XMLNode&, int version);
274 virtual XMLNode& get_template();
276 XMLNode& get_processor_state ();
277 virtual void set_processor_state (const XMLNode&);
279 int save_as_template (const std::string& path, const std::string& name);
281 PBD::Signal1<void,void*> SelectedChanged;
283 int listen_via (boost::shared_ptr<Route>, Placement p, bool active, bool aux);
284 void drop_listen (boost::shared_ptr<Route>);
287 * return true if this route feeds the first argument via at least one
288 * (arbitrarily long) signal pathway.
290 bool feeds (boost::shared_ptr<Route>, bool* via_send_only = 0);
293 * return true if this route feeds the first argument directly, via
294 * either its main outs or a send.
296 bool direct_feeds (boost::shared_ptr<Route>, bool* via_send_only = 0);
299 boost::weak_ptr<Route> r;
302 FeedRecord (boost::shared_ptr<Route> rp, bool sendsonly)
304 , sends_only (sendsonly) {}
307 struct FeedRecordCompare {
308 bool operator() (const FeedRecord& a, const FeedRecord& b) const {
313 typedef std::set<FeedRecord,FeedRecordCompare> FedBy;
315 const FedBy& fed_by() const { return _fed_by; }
316 void clear_fed_by ();
317 bool add_fed_by (boost::shared_ptr<Route>, bool sends_only);
318 bool not_fed() const { return _fed_by.empty(); }
320 /* Controls (not all directly owned by the Route */
322 boost::shared_ptr<AutomationControl> get_control (const Evoral::Parameter& param);
324 struct SoloControllable : public AutomationControl {
325 SoloControllable (std::string name, Route&);
326 void set_value (double);
327 double get_value (void) const;
332 struct MuteControllable : public AutomationControl {
333 MuteControllable (std::string name, Route&);
334 void set_value (double);
335 double get_value (void) const;
340 boost::shared_ptr<AutomationControl> solo_control() const {
341 return _solo_control;
344 boost::shared_ptr<AutomationControl> mute_control() const {
345 return _mute_control;
348 boost::shared_ptr<MuteMaster> mute_master() const {
352 /* Route doesn't own these items, but sub-objects that it does own have them
353 and to make UI code a bit simpler, we provide direct access to them
357 boost::shared_ptr<Panner> panner() const;
358 boost::shared_ptr<AutomationControl> gain_control() const;
360 void automation_snapshot (nframes_t now, bool force=false);
361 void protect_automation ();
363 void set_remote_control_id (uint32_t id, bool notify_class_listeners = true);
364 uint32_t remote_control_id () const;
366 /* for things concerned about *this* route's RID */
368 PBD::Signal0<void> RemoteControlIDChanged;
370 /* for things concerned about any route's RID changes */
372 static PBD::Signal0<void> RemoteControlIDChange;
374 void sync_order_keys (std::string const &);
375 static PBD::Signal1<void,std::string const &> SyncOrderKeys;
378 friend class Session;
380 void catch_up_on_solo_mute_override ();
381 void mod_solo_by_others_upstream (int32_t);
382 void mod_solo_by_others_downstream (int32_t);
383 bool has_external_redirects() const;
384 void curve_reallocate ();
385 void just_meter_input (framepos_t start_frame, framepos_t end_frame, nframes_t nframes);
386 virtual void set_block_size (nframes_t nframes);
389 nframes_t check_initial_delay (nframes_t, nframes_t&);
391 void passthru (framepos_t start_frame, framepos_t end_frame,
392 nframes_t nframes, int declick);
394 virtual void write_out_of_band_data (BufferSet& /* bufs */, framepos_t /* start_frame */, framepos_t /* end_frame */,
395 nframes_t /* nframes */) {}
397 virtual void process_output_buffers (BufferSet& bufs,
398 framepos_t start_frame, framepos_t end_frame,
399 nframes_t nframes, bool with_processors, int declick);
401 boost::shared_ptr<IO> _input;
402 boost::shared_ptr<IO> _output;
405 nframes_t _initial_delay;
406 nframes_t _roll_delay;
408 ProcessorList _processors;
409 mutable Glib::RWLock _processor_lock;
410 boost::shared_ptr<Delivery> _main_outs;
411 boost::shared_ptr<Delivery> _monitor_send;
412 boost::shared_ptr<InternalReturn> _intreturn;
413 boost::shared_ptr<MonitorProcessor> _monitor_control;
416 int _pending_declick;
417 MeterPoint _meter_point;
418 boost::dynamic_bitset<> _phase_invert;
420 uint32_t _soloed_by_others_upstream;
421 uint32_t _soloed_by_others_downstream;
422 uint32_t _solo_isolated;
424 bool _denormal_protection;
426 bool _recordable : 1;
428 bool _declickable : 1;
430 boost::shared_ptr<SoloControllable> _solo_control;
431 boost::shared_ptr<MuteControllable> _mute_control;
432 boost::shared_ptr<MuteMaster> _mute_master;
434 std::string _comment;
435 bool _have_internal_generator;
437 DataType _default_type;
440 virtual ChanCount input_streams () const;
443 virtual XMLNode& state(bool);
445 int configure_processors (ProcessorStreams*);
447 void passthru_silence (framepos_t start_frame, framepos_t end_frame,
448 nframes_t nframes, int declick);
450 void silence (nframes_t);
451 void silence_unlocked (nframes_t);
453 ChanCount processor_max_streams;
454 uint32_t _remote_control_id;
456 uint32_t pans_required() const;
457 ChanCount n_process_buffers ();
459 virtual int _set_state (const XMLNode&, int, bool call_base);
461 boost::shared_ptr<Amp> _amp;
462 boost::shared_ptr<PeakMeter> _meter;
465 int _set_state_2X (const XMLNode&, int);
466 void set_processor_state_2X (XMLNodeList const &, int);
468 static uint32_t order_key_cnt;
470 typedef std::map<std::string, long> OrderKeys;
471 OrderKeys order_keys;
473 void input_change_handler (IOChange, void *src);
474 void output_change_handler (IOChange, void *src);
476 bool _in_configure_processors;
478 int configure_processors_unlocked (ProcessorStreams*);
480 bool add_processor_from_xml_2X (const XMLNode&, int);
482 void placement_range (Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end);
484 void set_self_solo (bool yn);
485 void set_mute_master_solo ();
487 void set_processor_positions ();
490 } // namespace ARDOUR
492 #endif /* __ardour_route_h__ */