1 /*
2  * Copyright (C) 2000-2019 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2006-2014 David Robillard <d@drobilla.net>
4  * Copyright (C) 2008-2012 Carl Hetherington <carl@carlh.net>
5  * Copyright (C) 2013-2019 Robin Gareus <robin@gareus.org>
6  * Copyright (C) 2015-2018 Ben Loftis <ben@harrisonconsoles.com>
7  * Copyright (C) 2015-2018 Len Ovens <len@ovenwerks.net>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23 
24 #ifndef __ardour_route_h__
25 #define __ardour_route_h__
26 
27 #include <cmath>
28 #include <cstring>
29 #include <list>
30 #include <map>
31 #include <set>
32 #include <string>
33 
34 #include <boost/shared_ptr.hpp>
35 #include <boost/weak_ptr.hpp>
36 
37 #include <glibmm/threads.h>
38 #include "pbd/fastlog.h"
39 #include "pbd/xml++.h"
40 #include "pbd/undo.h"
41 #include "pbd/stateful.h"
42 #include "pbd/controllable.h"
43 #include "pbd/destructible.h"
44 #include "pbd/g_atomic_compat.h"
45 
46 #include "ardour/ardour.h"
47 #include "ardour/gain_control.h"
48 #include "ardour/instrument_info.h"
49 #include "ardour/io.h"
50 #include "ardour/io_vector.h"
51 #include "ardour/libardour_visibility.h"
52 #include "ardour/types.h"
53 #include "ardour/monitorable.h"
54 #include "ardour/muteable.h"
55 #include "ardour/mute_master.h"
56 #include "ardour/mute_control.h"
57 #include "ardour/route_group_member.h"
58 #include "ardour/stripable.h"
59 #include "ardour/graphnode.h"
60 #include "ardour/automatable.h"
61 #include "ardour/unknown_processor.h"
62 #include "ardour/soloable.h"
63 #include "ardour/solo_control.h"
64 #include "ardour/solo_safe_control.h"
65 #include "ardour/slavable.h"
66 
67 class RoutePinWindowProxy;
68 class PatchChangeGridDialog;
69 
70 namespace ARDOUR {
71 
72 class Amp;
73 class DelayLine;
74 class Delivery;
75 class DiskReader;
76 class DiskWriter;
77 class IOProcessor;
78 class Panner;
79 class PannerShell;
80 class PolarityProcessor;
81 class PortSet;
82 class Processor;
83 class PluginInsert;
84 class RouteGroup;
85 class Send;
86 class InternalReturn;
87 class Location;
88 class MonitorControl;
89 class MonitorProcessor;
90 class Pannable;
91 class CapturingProcessor;
92 class InternalSend;
93 class VCA;
94 class SoloIsolateControl;
95 class PhaseControl;
96 class MonitorControl;
97 
98 class LIBARDOUR_API Route : public Stripable,
99                             public GraphNode,
100                             public Soloable,
101                             public Muteable,
102                             public Monitorable,
103                             public RouteGroupMember
104 {
105 public:
106 
107 	typedef std::list<boost::shared_ptr<Processor> > ProcessorList;
108 
109 	Route (Session&, std::string name, PresentationInfo::Flag flags = PresentationInfo::Flag(0), DataType default_type = DataType::AUDIO);
110 	virtual ~Route();
111 
112 	virtual int init ();
113 
data_type()114 	DataType data_type () const {
115 		/* XXX ultimately nice to do away with this concept, but it is
116 		   quite useful for coders and for users too.
117 		*/
118 		return _default_type;
119 	}
120 
input()121 	boost::shared_ptr<IO> input() const { return _input; }
output()122 	boost::shared_ptr<IO> output() const { return _output; }
123 	IOVector all_inputs () const;
124 	IOVector all_outputs () const;
125 
n_inputs()126 	ChanCount n_inputs() const { return _input->n_ports(); }
n_outputs()127 	ChanCount n_outputs() const { return _output->n_ports(); }
128 
active()129 	bool active() const { return _active; }
130 	void set_active (bool yn, void *);
131 
132 	std::string ensure_track_or_route_name (std::string) const;
133 
comment()134 	std::string comment() { return _comment; }
135 	void set_comment (std::string str, void *src);
136 
137 	bool set_name (const std::string& str);
138 	static void set_name_in_state (XMLNode &, const std::string &);
139 
monitoring_control()140 	boost::shared_ptr<MonitorControl> monitoring_control() const { return _monitoring_control; }
141 
142 	MonitorState monitoring_state () const;
get_input_monitoring_state(bool recording,bool talkback)143 	virtual MonitorState get_input_monitoring_state (bool recording, bool talkback) const { return MonitoringSilence; }
144 
145 	/* these are the core of the API of a Route. see the protected sections as well */
146 
filter_input(BufferSet &)147 	virtual void filter_input (BufferSet &) {}
148 
149 	int roll (pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, bool& need_butler);
150 
151 	int no_roll (pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, bool state_changing);
152 
153 	int silent_roll (pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, bool& need_butler);
154 
declick_in_progress()155 	virtual bool declick_in_progress () const { return false; }
can_record()156 	virtual bool can_record() { return false; }
157 
158 	void non_realtime_transport_stop (samplepos_t now, bool flush);
159 	virtual void realtime_handle_transport_stopped ();
160 
realtime_locate(bool)161 	virtual void realtime_locate (bool) {}
162 	virtual void non_realtime_locate (samplepos_t);
163 	void set_loop (ARDOUR::Location *);
164 
165 	/* end of vfunc-based API */
166 
167 	void shift (samplepos_t, samplecnt_t);
168 
169 	/* controls use set_solo() to modify this route's solo state */
170 
171 	void clear_all_solo_state ();
172 
soloed_by_others()173 	bool soloed_by_others () const { return _solo_control->soloed_by_others(); }
soloed_by_others_upstream()174 	bool soloed_by_others_upstream () const { return _solo_control->soloed_by_others_upstream(); }
soloed_by_others_downstream()175 	bool soloed_by_others_downstream () const { return _solo_control->soloed_by_others_downstream(); }
self_soloed()176 	bool self_soloed () const { return _solo_control->self_soloed(); }
soloed()177 	bool soloed () const { return self_soloed () || soloed_by_others (); }
178 
179 	void push_solo_upstream (int32_t delta);
180 	void push_solo_isolate_upstream (int32_t delta);
can_solo()181 	bool can_solo () const {
182 		return !(is_master() || is_monitor() || is_auditioner() || is_foldbackbus());
183 	}
is_safe()184 	bool is_safe () const {
185 		return _solo_safe_control->get_value();
186 	}
can_monitor()187 	bool can_monitor () const {
188 		return can_solo() || is_foldbackbus ();
189 	}
190 	void enable_monitor_send ();
191 
192 	void set_denormal_protection (bool yn);
193 	bool denormal_protection() const;
194 
195 	void         set_meter_point (MeterPoint);
196 	bool         apply_processor_changes_rt ();
197 	void         emit_pending_signals ();
meter_point()198 	MeterPoint   meter_point() const { return _pending_meter_point; }
199 
200 	void         set_meter_type (MeterType t);
201 	MeterType    meter_type () const;
202 
203 	void set_disk_io_point (DiskIOPoint);
disk_io_point()204 	DiskIOPoint disk_io_point() const { return _disk_io_point; }
205 
206 	/* Processors */
207 
amp()208 	boost::shared_ptr<Amp> amp() const  { return _amp; }
trim()209 	boost::shared_ptr<Amp> trim() const { return _trim; }
polarity()210 	boost::shared_ptr<PolarityProcessor> polarity() const { return _polarity; }
peak_meter()211 	boost::shared_ptr<PeakMeter>       peak_meter()       { return _meter; }
peak_meter()212 	boost::shared_ptr<const PeakMeter> peak_meter() const { return _meter; }
shared_peak_meter()213 	boost::shared_ptr<PeakMeter> shared_peak_meter() const { return _meter; }
214 
215 	void flush_processors ();
216 
foreach_processor(boost::function<void (boost::weak_ptr<Processor>)> method)217 	void foreach_processor (boost::function<void(boost::weak_ptr<Processor>)> method) {
218 		Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
219 		for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
220 			method (boost::weak_ptr<Processor> (*i));
221 		}
222 	}
223 
nth_processor(uint32_t n)224 	boost::shared_ptr<Processor> nth_processor (uint32_t n) {
225 		Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
226 		ProcessorList::iterator i;
227 		for (i = _processors.begin(); i != _processors.end() && n; ++i, --n) {}
228 		if (i == _processors.end()) {
229 			return boost::shared_ptr<Processor> ();
230 		} else {
231 			return *i;
232 		}
233 	}
234 
235 	boost::shared_ptr<Processor> processor_by_id (PBD::ID) const;
236 
237 	boost::shared_ptr<Processor> nth_plugin (uint32_t n) const;
238 	boost::shared_ptr<Processor> nth_send (uint32_t n) const;
239 
240 	bool has_io_processor_named (const std::string&);
max_processor_streams()241 	ChanCount max_processor_streams () const { return processor_max_streams; }
242 
243 	std::list<std::string> unknown_processors () const;
244 
pinmgr_proxy()245 	RoutePinWindowProxy * pinmgr_proxy () const { return _pinmgr_proxy; }
set_pingmgr_proxy(RoutePinWindowProxy * wp)246 	void set_pingmgr_proxy (RoutePinWindowProxy* wp) { _pinmgr_proxy = wp ; }
247 
patch_selector_dialog()248 	PatchChangeGridDialog* patch_selector_dialog () const { return _patch_selector_dialog; }
set_patch_selector_dialog(PatchChangeGridDialog * d)249 	void set_patch_selector_dialog  (PatchChangeGridDialog* d) { _patch_selector_dialog = d; }
250 
251 	boost::shared_ptr<AutomationControl> automation_control_recurse (PBD::ID const & id) const;
252 
253 	/* special processors */
254 
monitor_send()255 	boost::shared_ptr<InternalSend>     monitor_send() const { return _monitor_send; }
256 	/** the signal processorat at end of the processing chain which produces output */
main_outs()257 	boost::shared_ptr<Delivery>         main_outs() const { return _main_outs; }
internal_return()258 	boost::shared_ptr<InternalReturn>   internal_return() const { return _intreturn; }
monitor_control()259 	boost::shared_ptr<MonitorProcessor> monitor_control() const { return _monitor_control; }
260 	boost::shared_ptr<Send>             internal_send_for (boost::shared_ptr<const Route> target) const;
261 	void add_internal_return ();
262 	void add_send_to_internal_return (InternalSend *);
263 	void remove_send_from_internal_return (InternalSend *);
264 	void listen_position_changed ();
265 	boost::shared_ptr<CapturingProcessor> add_export_point(/* Add some argument for placement later */);
266 
267 	/** A record of the stream configuration at some point in the processor list.
268 	 * Used to return where and why an processor list configuration request failed.
269 	 */
270 	struct ProcessorStreams {
indexProcessorStreams271 		ProcessorStreams(size_t i=0, ChanCount c=ChanCount()) : index(i), count(c) {}
272 
273 		uint32_t  index; ///< Index of processor where configuration failed
274 		ChanCount count; ///< Input requested of processor
275 	};
276 
277 	int add_processor (boost::shared_ptr<Processor>, Placement placement, ProcessorStreams* err = 0, bool activation_allowed = true);
278 	int add_processor_by_index (boost::shared_ptr<Processor>, int, ProcessorStreams* err = 0, bool activation_allowed = true);
279 	int add_processor (boost::shared_ptr<Processor>, boost::shared_ptr<Processor>, ProcessorStreams* err = 0, bool activation_allowed = true);
280 	int add_processors (const ProcessorList&, boost::shared_ptr<Processor>, ProcessorStreams* err = 0);
281 	boost::shared_ptr<Processor> before_processor_for_placement (Placement);
282 	boost::shared_ptr<Processor> before_processor_for_index (int);
283 	bool processors_reorder_needs_configure (const ProcessorList& new_order);
284 	/** remove plugin/processor
285 	 *
286 	 * @param proc processor to remove
287 	 * @param err error report (index where removal vailed, channel-count why it failed) may be nil
288 	 * @param need_process_lock if locking is required (set to true, unless called from RT context with lock)
289 	 * @returns 0 on success
290 	 */
291 	int remove_processor (boost::shared_ptr<Processor> proc, ProcessorStreams* err = 0, bool need_process_lock = true);
292 	/** replace plugin/processor with another
293 	 *
294 	 * @param old processor to remove
295 	 * @param sub processor to substitute the old one with
296 	 * @param err error report (index where removal vailed, channel-count why it failed) may be nil
297 	 * @returns 0 on success
298 	 */
299 	int replace_processor (boost::shared_ptr<Processor> old, boost::shared_ptr<Processor> sub, ProcessorStreams* err = 0);
300 	int remove_processors (const ProcessorList&, ProcessorStreams* err = 0);
301 	int reorder_processors (const ProcessorList& new_order, ProcessorStreams* err = 0);
302 	void disable_processors (Placement);
303 	void disable_processors ();
304 	void disable_plugins (Placement);
305 	void disable_plugins ();
306 	void ab_plugins (bool forward);
307 	void clear_processors (Placement);
308 	void all_visible_processors_active (bool);
309 	void move_instrument_down (bool postfader = false);
310 
strict_io()311 	bool strict_io () const { return _strict_io; }
312 	bool set_strict_io (bool);
313 	/** reset plugin-insert configuration to default, disable customizations.
314 	 *
315 	 * This is equivalent to calling
316 	 * @code
317 	 * customize_plugin_insert (proc, 0, unused)
318 	 * @endcode
319 	 *
320 	 * @param proc Processor to reset
321 	 * @returns true if successful
322 	 */
323 	bool reset_plugin_insert (boost::shared_ptr<Processor> proc);
324 	/** enable custom plugin-insert configuration
325 	 * @param proc Processor to customize
326 	 * @param count number of plugin instances to use (if zero, reset to default)
327 	 * @param outs output port customization
328 	 * @param sinks input pins for variable-I/O plugins
329 	 * @returns true if successful
330 	 */
331 	bool customize_plugin_insert (boost::shared_ptr<Processor> proc, uint32_t count, ChanCount outs, ChanCount sinks);
332 	bool add_remove_sidechain (boost::shared_ptr<Processor> proc, bool);
333 	bool plugin_preset_output (boost::shared_ptr<Processor> proc, ChanCount outs);
334 
335 	/* enable sidechain input for a given processor
336 	 *
337 	 * The sidechain itself is an IO port object with variable number of channels and configured independently.
338 	 * Adding/removing the port itself however requires reconfiguring the route and is hence
339 	 * not a plugin operation itself.
340 	 *
341 	 * @param proc the processor to add sidechain inputs to
342 	 * @returns true on success
343 	 */
add_sidechain(boost::shared_ptr<Processor> proc)344 	bool add_sidechain (boost::shared_ptr<Processor> proc) { return add_remove_sidechain (proc, true); }
345 	/* remove sidechain input from given processor
346 	 * @param proc the processor to remove the sidechain input from
347 	 * @returns true on success
348 	 */
remove_sidechain(boost::shared_ptr<Processor> proc)349 	bool remove_sidechain (boost::shared_ptr<Processor> proc) { return add_remove_sidechain (proc, false); }
350 
351 	samplecnt_t  update_signal_latency (bool apply_to_delayline = false, bool* delayline_update_needed = NULL);
352 	virtual void apply_latency_compensation ();
353 
354 	samplecnt_t  set_private_port_latencies (bool playback) const;
355 	void         set_public_port_latencies (samplecnt_t, bool playback) const;
356 
signal_latency()357 	samplecnt_t signal_latency() const { return _signal_latency; }
358 	samplecnt_t playback_latency (bool incl_downstream = false) const;
359 
output_latency()360 	virtual samplecnt_t output_latency () const { return _output_latency; }
361 
362 	PBD::Signal0<void> active_changed;
363 	PBD::Signal0<void> denormal_protection_changed;
364 	PBD::Signal0<void> comment_changed;
365 
366 	bool is_track();
367 
368 	/** track numbers - assigned by session
369 	 * nubers > 0 indicate tracks (audio+midi)
370 	 * nubers < 0 indicate busses
371 	 * zero is reserved for unnumbered special busses.
372 	 * */
373 	PBD::Signal0<void> track_number_changed;
track_number()374 	int64_t track_number() const { return _track_number; }
375 
set_track_number(int64_t tn)376 	void set_track_number(int64_t tn) {
377 		if (tn == _track_number) { return; }
378 		_track_number = tn;
379 		track_number_changed();
380 		PropertyChanged (ARDOUR::Properties::name);
381 	}
382 
383 	enum PluginSetupOptions {
384 		None = 0x0,
385 		CanReplace = 0x1,
386 		MultiOut = 0x2,
387 	};
388 
389 	/** ask GUI about port-count, fan-out when adding instrument */
390 	static PBD::Signal3<int, boost::shared_ptr<Route>, boost::shared_ptr<PluginInsert>, PluginSetupOptions > PluginSetup;
391 
392 	/** used to signal the GUI to fan-out (track-creation) */
393 	static PBD::Signal1<void, boost::weak_ptr<Route> > FanOut;
394 
395 	/** the processors have changed; the parameter indicates what changed */
396 	PBD::Signal1<void,RouteProcessorChange> processors_changed;
397 	PBD::Signal1<void,void*> record_enable_changed;
398 	/** a processor's latency has changed
399 	 * (emitted from PluginInsert::latency_changed)
400 	 */
401 	PBD::Signal0<void> processor_latency_changed;
402 	/** the metering point has changed */
403 	PBD::Signal0<void> meter_change;
404 
405 	/** Emitted with the process lock held */
406 	PBD::Signal0<void>       io_changed;
407 
408 	/* stateful */
409 	XMLNode& get_state();
410 	XMLNode& get_template();
411 	virtual int set_state (const XMLNode&, int version);
412 
413 	XMLNode& get_processor_state ();
414 	void set_processor_state (const XMLNode&, int version);
415 	virtual bool set_processor_state (XMLNode const & node, int version, XMLProperty const* prop, ProcessorList& new_order, bool& must_configure);
416 
417 	boost::weak_ptr<Route> weakroute ();
418 
419 	int save_as_template (const std::string& path, const std::string& name, const std::string& description );
420 
421 	PBD::Signal1<void,void*> SelectedChanged;
422 
423 	int add_aux_send (boost::shared_ptr<Route>, boost::shared_ptr<Processor>);
424 	int add_foldback_send (boost::shared_ptr<Route>, bool post_fader);
425 	void remove_monitor_send ();
426 
427 	/**
428 	 * return true if this route feeds the first argument via at least one
429 	 * (arbitrarily long) signal pathway.
430 	 */
431 	bool feeds (boost::shared_ptr<Route>, bool* via_send_only = 0);
432 
433 	/**
434 	 * return true if this route feeds the first argument directly, via
435 	 * either its main outs or a send.  This is checked by the actual
436 	 * connections, rather than by what the graph is currently doing.
437 	 */
438 	bool direct_feeds_according_to_reality (boost::shared_ptr<Route>, bool* via_send_only = 0);
439 
440 	/**
441 	 * return true if this route feeds the first argument directly, via
442 	 * either its main outs or a send, according to the graph that
443 	 * is currently being processed.
444 	 */
445 	bool direct_feeds_according_to_graph (boost::shared_ptr<Route>, bool* via_send_only = 0);
446 
447 	bool feeds_according_to_graph (boost::shared_ptr<Route>);
448 
449 	struct FeedRecord {
450 		boost::weak_ptr<Route> r;
451 		bool sends_only;
452 
FeedRecordFeedRecord453 		FeedRecord (boost::shared_ptr<Route> rp, bool sendsonly)
454 		: r (rp)
455 		, sends_only (sendsonly) {}
456 	};
457 
458 	struct FeedRecordCompare {
operatorFeedRecordCompare459 		bool operator() (const FeedRecord& a, const FeedRecord& b) const {
460 			return a.r < b.r;
461 		}
462 	};
463 
464 	typedef std::set<FeedRecord,FeedRecordCompare> FedBy;
465 
fed_by()466 	const FedBy& fed_by() const { return _fed_by; }
467 	void clear_fed_by ();
468 	bool add_fed_by (boost::shared_ptr<Route>, bool sends_only);
469 
470 	/* Controls (not all directly owned by the Route) */
471 
472 	boost::shared_ptr<AutomationControl> get_control (const Evoral::Parameter& param);
473 
solo_control()474 	boost::shared_ptr<SoloControl> solo_control() const {
475 		return _solo_control;
476 	}
477 
mute_control()478 	boost::shared_ptr<MuteControl> mute_control() const {
479 		return _mute_control;
480 	}
481 
can_be_muted_by_others()482 	bool can_be_muted_by_others () const { return can_solo(); }
muted()483 	bool muted () const { return _mute_control->muted(); }
muted_by_masters()484 	bool muted_by_masters () const { return _mute_control->muted_by_masters(); }
muted_by_self()485 	bool muted_by_self () const { return _mute_control->muted_by_self(); }
486 	bool muted_by_others_soloing () const;
487 
solo_isolate_control()488 	boost::shared_ptr<SoloIsolateControl> solo_isolate_control() const {
489 		return _solo_isolate_control;
490 	}
491 
solo_safe_control()492 	boost::shared_ptr<SoloSafeControl> solo_safe_control() const {
493 		return _solo_safe_control;
494 	}
495 
496 	/* Route doesn't own these items, but sub-objects that it does own have them
497 	   and to make UI code a bit simpler, we provide direct access to them
498 	   here.
499 	*/
500 
501 	boost::shared_ptr<Panner> panner() const;  /* may return null */
502 	boost::shared_ptr<PannerShell> panner_shell() const;
503 	boost::shared_ptr<Pannable> pannable() const;
504 
505 	boost::shared_ptr<GainControl> gain_control() const;
506 	boost::shared_ptr<GainControl> trim_control() const;
507 	boost::shared_ptr<GainControl> volume_control() const;
508 	boost::shared_ptr<PhaseControl> phase_control() const;
509 
510 	void set_volume_applies_to_output (bool);
511 
volume_applies_to_output()512 	bool volume_applies_to_output () const {
513 		return _volume_applies_to_output;
514 	}
515 
516 	/**
517 	   Return the first processor that accepts has at least one MIDI input
518 	   and at least one audio output. In the vast majority of cases, this
519 	   will be "the instrument". This does not preclude other MIDI->audio
520 	   processors later in the processing chain, but that would be a
521 	   special case not covered by this utility function.
522 	*/
523 	boost::shared_ptr<Processor> the_instrument() const;
instrument_info()524 	InstrumentInfo& instrument_info() { return _instrument_info; }
instrument_fanned_out()525 	bool instrument_fanned_out () const { return _instrument_fanned_out;}
526 
527 
528 	/* "well-known" controls.
529 	 * Any or all of these may return NULL.
530 	 */
531 
532 	boost::shared_ptr<AutomationControl> pan_azimuth_control() const;
533 	boost::shared_ptr<AutomationControl> pan_elevation_control() const;
534 	boost::shared_ptr<AutomationControl> pan_width_control() const;
535 	boost::shared_ptr<AutomationControl> pan_frontback_control() const;
536 	boost::shared_ptr<AutomationControl> pan_lfe_control() const;
537 
538 	uint32_t eq_band_cnt () const;
539 	std::string eq_band_name (uint32_t) const;
540 	boost::shared_ptr<AutomationControl> eq_enable_controllable () const;
541 	boost::shared_ptr<AutomationControl> eq_gain_controllable (uint32_t band) const;
542 	boost::shared_ptr<AutomationControl> eq_freq_controllable (uint32_t band) const;
543 	boost::shared_ptr<AutomationControl> eq_q_controllable (uint32_t band) const;
544 	boost::shared_ptr<AutomationControl> eq_shape_controllable (uint32_t band) const;
545 
546 	boost::shared_ptr<AutomationControl> filter_freq_controllable (bool hpf) const;
547 	boost::shared_ptr<AutomationControl> filter_slope_controllable (bool) const;
548 	boost::shared_ptr<AutomationControl> filter_enable_controllable (bool) const;
549 
550 	boost::shared_ptr<AutomationControl> tape_drive_controllable () const;
551 	boost::shared_ptr<ReadOnlyControl>   tape_drive_mtr_controllable () const;
552 
553 	boost::shared_ptr<AutomationControl> comp_enable_controllable () const;
554 	boost::shared_ptr<AutomationControl> comp_threshold_controllable () const;
555 	boost::shared_ptr<AutomationControl> comp_speed_controllable () const;
556 	boost::shared_ptr<AutomationControl> comp_mode_controllable () const;
557 	boost::shared_ptr<AutomationControl> comp_makeup_controllable () const;
558 	boost::shared_ptr<ReadOnlyControl>   comp_redux_controllable () const;
559 
560 	std::string comp_mode_name (uint32_t mode) const;
561 	std::string comp_speed_name (uint32_t mode) const;
562 
563 	boost::shared_ptr<AutomationControl> send_level_controllable (uint32_t n) const;
564 	boost::shared_ptr<AutomationControl> send_enable_controllable (uint32_t n) const;
565 	boost::shared_ptr<AutomationControl> send_pan_azimuth_controllable (uint32_t n) const;
566 	boost::shared_ptr<AutomationControl> send_pan_azimuth_enable_controllable (uint32_t n) const;
567 
568 	std::string send_name (uint32_t n) const;
569 
570 	boost::shared_ptr<AutomationControl> master_send_enable_controllable () const;
571 
572 	boost::shared_ptr<ReadOnlyControl> master_correlation_mtr_controllable (bool) const;
573 
574 	boost::shared_ptr<AutomationControl> master_limiter_enable_controllable () const;
575 	boost::shared_ptr<ReadOnlyControl> master_limiter_mtr_controllable () const;
576 	boost::shared_ptr<ReadOnlyControl> master_k_mtr_controllable () const;
577 
578 	void protect_automation ();
579 
580 	bool has_external_redirects() const;
581 
582 	/* can only be executed by a route for which is_monitor() is true
583 	 * (i.e. the monitor out)
584 	 */
585 	void monitor_run (samplepos_t start_sample, samplepos_t end_sample, pframes_t nframes);
586 
587 	bool slaved_to (boost::shared_ptr<VCA>) const;
588 	bool slaved () const;
589 
use_captured_sources(SourceList & srcs,CaptureInfos const &)590 	virtual void use_captured_sources (SourceList& srcs, CaptureInfos const &) {}
591 
592 protected:
593 	friend class Session;
594 
595 	void catch_up_on_solo_mute_override ();
596 	void set_listen (bool);
597 
598 	virtual void set_block_size (pframes_t nframes);
599 
600 	virtual int no_roll_unlocked (pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, bool session_state_changing);
601 
snapshot_out_of_band_data(samplecnt_t)602 	virtual void snapshot_out_of_band_data (samplecnt_t /* nframes */) {}
write_out_of_band_data(BufferSet &,samplecnt_t)603 	virtual void write_out_of_band_data (BufferSet&, samplecnt_t /* nframes */) const {}
update_controls(BufferSet const &)604 	virtual void update_controls (BufferSet const&) {}
605 
606 	void process_output_buffers (BufferSet& bufs,
607 	                             samplepos_t start_sample, samplepos_t end_sample,
608 	                             pframes_t nframes,
609 	                             bool gain_automation_ok,
610 	                             bool run_disk_processors);
611 
612 	void flush_processor_buffers_locked (samplecnt_t nframes);
613 
614 	virtual void bounce_process (BufferSet& bufs,
615 	                             samplepos_t start_sample, samplecnt_t nframes,
616 															 boost::shared_ptr<Processor> endpoint, bool include_endpoint,
617 	                             bool for_export, bool for_freeze);
618 
619 	samplecnt_t  bounce_get_latency (boost::shared_ptr<Processor> endpoint, bool include_endpoint, bool for_export, bool for_freeze) const;
620 	ChanCount    bounce_get_output_streams (ChanCount &cc, boost::shared_ptr<Processor> endpoint, bool include_endpoint, bool for_export, bool for_freeze) const;
621 
622 	bool can_freeze_processor (boost::shared_ptr<Processor>, bool allow_routing = false) const;
623 
624 	bool           _active;
625 	samplecnt_t    _signal_latency;
626 	samplecnt_t    _output_latency;
627 
628 	ProcessorList  _processors;
629 	mutable Glib::Threads::RWLock _processor_lock;
630 
631 	boost::shared_ptr<IO>               _input;
632 	boost::shared_ptr<IO>               _output;
633 
634 	boost::shared_ptr<Delivery>         _main_outs;
635 	boost::shared_ptr<InternalSend>     _monitor_send;
636 	boost::shared_ptr<InternalReturn>   _intreturn;
637 	boost::shared_ptr<MonitorProcessor> _monitor_control;
638 	boost::shared_ptr<Pannable>         _pannable;
639 	boost::shared_ptr<DiskReader>       _disk_reader;
640 	boost::shared_ptr<DiskWriter>       _disk_writer;
641 
642 	boost::shared_ptr<MonitorControl>   _monitoring_control;
643 
644 	DiskIOPoint _disk_io_point;
645 
646 	enum {
647 		EmitNone = 0x00,
648 		EmitMeterChanged = 0x01,
649 		EmitMeterVisibilityChange = 0x02,
650 		EmitRtProcessorChange = 0x04
651 	};
652 
653 	ProcessorList     _pending_processor_order;
654 	GATOMIC_QUAL gint _pending_process_reorder; // atomic
655 	GATOMIC_QUAL gint _pending_listen_change; // atomic
656 	GATOMIC_QUAL gint _pending_signals; // atomic
657 
658 	MeterPoint     _meter_point;
659 	MeterPoint     _pending_meter_point;
660 
661 	bool           _denormal_protection;
662 
663 	bool _recordable : 1;
664 
665 	boost::shared_ptr<SoloControl> _solo_control;
666 	boost::shared_ptr<MuteControl> _mute_control;
667 	boost::shared_ptr<SoloIsolateControl> _solo_isolate_control;
668 	boost::shared_ptr<SoloSafeControl> _solo_safe_control;
669 
670 	std::string    _comment;
671 	bool           _have_internal_generator;
672 	DataType       _default_type;
673 	FedBy          _fed_by;
674 
675 	InstrumentInfo _instrument_info;
676 	bool           _instrument_fanned_out;
677 	Location*      _loop_location;
678 
679 	virtual ChanCount input_streams () const;
680 
681 	virtual XMLNode& state (bool save_template);
682 
683 	int configure_processors (ProcessorStreams*);
684 
685 	void silence (samplecnt_t);
686 	void silence_unlocked (samplecnt_t);
687 
688 	ChanCount processor_max_streams;
689 	ChanCount processor_out_streams;
690 
691 	uint32_t pans_required() const;
692 	ChanCount n_process_buffers ();
693 
694 	boost::shared_ptr<GainControl>  _gain_control;
695 	boost::shared_ptr<GainControl>  _trim_control;
696 	boost::shared_ptr<GainControl>  _volume_control;
697 	boost::shared_ptr<PhaseControl> _phase_control;
698 	boost::shared_ptr<Amp>               _amp;
699 	boost::shared_ptr<Amp>               _trim;
700 	boost::shared_ptr<Amp>               _volume;
701 	boost::shared_ptr<PeakMeter>         _meter;
702 	boost::shared_ptr<PolarityProcessor> _polarity;
703 
704 	bool _volume_applies_to_output;
705 
706 	boost::shared_ptr<DelayLine> _delayline;
707 
708 	bool is_internal_processor (boost::shared_ptr<Processor>) const;
709 
710 	boost::shared_ptr<Processor> the_instrument_unlocked() const;
711 
712 	SlavableControlList slavables () const;
713 
714 private:
715 	/* no copy construction */
716 	Route (Route const &);
717 
718 	int set_state_2X (const XMLNode&, int);
719 	void set_processor_state_2X (XMLNodeList const &, int);
720 
721 	void input_change_handler (IOChange, void *src);
722 	void output_change_handler (IOChange, void *src);
723 	void sidechain_change_handler (IOChange, void *src);
724 
725 	void processor_selfdestruct (boost::weak_ptr<Processor>);
726 	std::vector<boost::weak_ptr<Processor> > selfdestruct_sequence;
727 	Glib::Threads::Mutex  selfdestruct_lock;
728 
729 	bool input_port_count_changing (ChanCount);
730 	bool output_port_count_changing (ChanCount);
731 
732 	int configure_processors_unlocked (ProcessorStreams*, Glib::Threads::RWLock::WriterLock*);
733 	bool set_meter_point_unlocked ();
734 	void apply_processor_order (const ProcessorList& new_order);
735 
736 	std::list<std::pair<ChanCount, ChanCount> > try_configure_processors (ChanCount, ProcessorStreams *);
737 	std::list<std::pair<ChanCount, ChanCount> > try_configure_processors_unlocked (ChanCount, ProcessorStreams *);
738 
739 	bool add_processor_from_xml_2X (const XMLNode&, int);
740 
741 	void placement_range (Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end);
742 
743 	void set_self_solo (bool yn);
744 	void unpan ();
745 
746 	void set_processor_positions ();
747 	samplecnt_t update_port_latencies (PortSet& ports, PortSet& feeders, bool playback, samplecnt_t) const;
748 
749 	void setup_invisible_processors ();
750 
751 	pframes_t latency_preroll (pframes_t nframes, samplepos_t& start_sample, samplepos_t& end_sample);
752 
753 	void run_route (samplepos_t start_sample, samplepos_t end_sample, pframes_t nframes, bool gain_automation_ok, bool run_disk_reader);
754 	void fill_buffers_with_input (BufferSet& bufs, boost::shared_ptr<IO> io, pframes_t nframes);
755 
756 	void reset_instrument_info ();
757 	void solo_control_changed (bool self, PBD::Controllable::GroupControlDisposition);
758 	void maybe_note_meter_position ();
759 
760 	void set_plugin_state_dir (boost::weak_ptr<Processor>, const std::string&);
761 
762 	/** A handy class to keep processor state while we attempt a reconfiguration
763 	 *  that may fail.
764 	 */
765 	class ProcessorState {
766 	public:
ProcessorState(Route * r)767 		ProcessorState (Route* r)
768 			: _route (r)
769 			, _processors (r->_processors)
770 			, _processor_max_streams (r->processor_max_streams)
771 		{ }
772 
restore()773 		void restore () {
774 			_route->_processors = _processors;
775 			_route->processor_max_streams = _processor_max_streams;
776 		}
777 
778 	private:
779 		/* this should perhaps be a shared_ptr, but ProcessorStates will
780 		   not hang around long enough for it to matter.
781 		*/
782 		Route* _route;
783 		ProcessorList _processors;
784 		ChanCount _processor_max_streams;
785 	};
786 
787 	friend class ProcessorState;
788 
789 	boost::shared_ptr<CapturingProcessor> _capturing_processor;
790 
791 	int64_t _track_number;
792 	bool    _strict_io;
793 	bool    _in_configure_processors;
794 	bool    _initial_io_setup;
795 	bool    _in_sidechain_setup;
796 	gain_t  _monitor_gain;
797 
798 	/** true if we've made a note of a custom meter position in these variables */
799 	bool _custom_meter_position_noted;
800 	/** the processor that came after the meter when it was last set to a custom position,
801 	    or 0.
802 	*/
803 	boost::weak_ptr<Processor> _processor_after_last_custom_meter;
804 
805 	RoutePinWindowProxy*   _pinmgr_proxy;
806 	PatchChangeGridDialog* _patch_selector_dialog;
807 };
808 
809 } // namespace ARDOUR
810 
811 #endif /* __ardour_route_h__ */
812