2 Copyright (C) 2000 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 #include "libardour-config.h"
29 #include <boost/algorithm/string.hpp>
31 #include "pbd/xml++.h"
32 #include "pbd/enumwriter.h"
33 #include "pbd/locale_guard.h"
34 #include "pbd/memento_command.h"
35 #include "pbd/stacktrace.h"
36 #include "pbd/types_convert.h"
37 #include "pbd/unwind.h"
39 #include "ardour/amp.h"
40 #include "ardour/audio_buffer.h"
41 #include "ardour/audio_track.h"
42 #include "ardour/audio_port.h"
43 #include "ardour/audioengine.h"
44 #include "ardour/boost_debug.h"
45 #include "ardour/buffer.h"
46 #include "ardour/buffer_set.h"
47 #include "ardour/capturing_processor.h"
48 #include "ardour/debug.h"
49 #include "ardour/delivery.h"
50 #include "ardour/disk_reader.h"
51 #include "ardour/disk_writer.h"
52 #include "ardour/event_type_map.h"
53 #include "ardour/gain_control.h"
54 #include "ardour/internal_return.h"
55 #include "ardour/internal_send.h"
56 #include "ardour/meter.h"
57 #include "ardour/delayline.h"
58 #include "ardour/midi_buffer.h"
59 #include "ardour/midi_port.h"
60 #include "ardour/midi_track.h"
61 #include "ardour/monitor_control.h"
62 #include "ardour/monitor_processor.h"
63 #include "ardour/pannable.h"
64 #include "ardour/panner.h"
65 #include "ardour/panner_shell.h"
66 #include "ardour/parameter_descriptor.h"
67 #include "ardour/phase_control.h"
68 #include "ardour/plugin_insert.h"
69 #include "ardour/polarity_processor.h"
70 #include "ardour/port.h"
71 #include "ardour/port_insert.h"
72 #include "ardour/processor.h"
73 #include "ardour/profile.h"
74 #include "ardour/route.h"
75 #include "ardour/route_group.h"
76 #include "ardour/send.h"
77 #include "ardour/session.h"
78 #include "ardour/solo_control.h"
79 #include "ardour/solo_isolate_control.h"
80 #include "ardour/types_convert.h"
81 #include "ardour/unknown_processor.h"
82 #include "ardour/utils.h"
83 #include "ardour/vca.h"
88 using namespace ARDOUR;
91 PBD::Signal3<int,boost::shared_ptr<Route>, boost::shared_ptr<PluginInsert>, Route::PluginSetupOptions > Route::PluginSetup;
93 /** Base class for all routable/mixable objects (tracks and busses) */
94 Route::Route (Session& sess, string name, PresentationInfo::Flag flag, DataType default_type)
95 : Stripable (sess, name, PresentationInfo (flag))
96 , GraphNode (sess._process_graph)
97 , Muteable (sess, name)
100 , _disk_io_point (DiskIOPreFader)
101 , _pending_process_reorder (0)
102 , _pending_signals (0)
103 , _meter_point (MeterPostFader)
104 , _pending_meter_point (MeterPostFader)
105 , _meter_type (MeterPeak)
106 , _denormal_protection (false)
108 , _have_internal_generator (false)
109 , _default_type (default_type)
110 , _loop_location (NULL)
113 , _in_configure_processors (false)
114 , _initial_io_setup (false)
115 , _in_sidechain_setup (false)
116 , _custom_meter_position_noted (false)
118 , _patch_selector_dialog (0)
120 processor_max_streams.reset();
123 boost::weak_ptr<Route>
124 Route::weakroute () {
125 return boost::weak_ptr<Route> (boost::dynamic_pointer_cast<Route> (shared_from_this ()));
131 /* set default meter type */
133 _meter_type = Config->get_meter_type_master ();
135 else if (dynamic_cast<Track*>(this)) {
136 _meter_type = Config->get_meter_type_track ();
138 _meter_type = Config->get_meter_type_bus ();
141 /* add standard controls */
143 _gain_control.reset (new GainControl (_session, GainAutomation));
144 _trim_control.reset (new GainControl (_session, TrimAutomation));
145 /* While the route has-a gain-control for consistency with Stripable and VCA
146 * ownership is handed over to the Amp Processor which manages the
147 * state of the Control and AutomationList as part of its
148 * Automatable API. -- Don't call add_control () here.
151 _solo_control.reset (new SoloControl (_session, X_("solo"), *this, *this));
152 add_control (_solo_control);
153 _solo_control->Changed.connect_same_thread (*this, boost::bind (&Route::solo_control_changed, this, _1, _2));
155 _mute_control.reset (new MuteControl (_session, X_("mute"), *this));
156 add_control (_mute_control);
158 _phase_control.reset (new PhaseControl (_session, X_("phase")));
159 add_control (_phase_control);
161 _solo_isolate_control.reset (new SoloIsolateControl (_session, X_("solo-iso"), *this, *this));
162 add_control (_solo_isolate_control);
164 _solo_safe_control.reset (new SoloSafeControl (_session, X_("solo-safe")));
165 add_control (_solo_safe_control);
169 if (!(_presentation_info.flags() & PresentationInfo::MonitorOut)) {
170 _pannable.reset (new Pannable (_session));
173 /* input and output objects */
175 _input.reset (new IO (_session, _name, IO::Input, _default_type));
176 _output.reset (new IO (_session, _name, IO::Output, _default_type));
178 _input->changed.connect_same_thread (*this, boost::bind (&Route::input_change_handler, this, _1, _2));
179 _input->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::input_port_count_changing, this, _1));
181 _output->changed.connect_same_thread (*this, boost::bind (&Route::output_change_handler, this, _1, _2));
182 _output->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::output_port_count_changing, this, _1));
184 /* add the amp/fader processor.
185 * it should be the first processor to be added on every route.
188 _amp.reset (new Amp (_session, X_("Fader"), _gain_control, true));
189 add_processor (_amp, PostFader);
191 _polarity.reset (new PolarityProcessor (_session, _phase_control));
192 _polarity->activate();
193 _polarity->set_owner (this);
196 _amp->set_display_name (_("Monitor"));
199 if (!is_master() && !is_monitor() && !is_auditioner()) {
200 _delayline.reset (new DelayLine (_session, name ()));
205 _trim.reset (new Amp (_session, X_("Trim"), _trim_control, false));
206 _trim->set_display_to_user (false);
208 if (dynamic_cast<AudioTrack*>(this)) {
209 /* we can't do this in the AudioTrack's constructor
210 * because _trim does not exit then
214 else if (!dynamic_cast<Track*>(this) && ! ( is_monitor() || is_auditioner() )) {
219 /* create standard processors: meter, main outs, monitor out;
220 they will be added to _processors by setup_invisible_processors ()
223 _meter.reset (new PeakMeter (_session, _name));
224 _meter->set_owner (this);
225 _meter->set_display_to_user (false);
228 _main_outs.reset (new Delivery (_session, _output, _pannable, _mute_master, _name, Delivery::Main));
229 _main_outs->activate ();
232 /* where we listen to tracks */
233 _intreturn.reset (new InternalReturn (_session));
234 _intreturn->activate ();
236 /* the thing that provides proper control over a control/monitor/listen bus
237 (such as per-channel cut, dim, solo, invert, etc).
239 _monitor_control.reset (new MonitorProcessor (_session));
240 _monitor_control->activate ();
243 /* now that we have _meter, its safe to connect to this */
246 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
247 configure_processors (0);
255 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
257 /* do this early so that we don't get incoming signals as we are going through destruction
262 /* don't use clear_processors here, as it depends on the session which may
263 be half-destroyed by now
266 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
267 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
268 (*i)->drop_references ();
271 _processors.clear ();
275 Route::ensure_track_or_route_name (string newname) const
277 while (!_session.io_name_is_legal (newname)) {
278 newname = bump_name_once (newname, ' ');
279 if (newname == name()) {
287 Route::set_trim (gain_t val, Controllable::GroupControlDisposition /* group override */)
289 // TODO route group, see set_gain()
290 // _trim_control->route_set_value (val);
293 /** Process this route for one (sub) cycle (process thread)
295 * @param bufs Scratch buffers to use for the signal path
296 * @param start_sample Initial transport sample
297 * @param end_sample Final transport sample
298 * @param nframes Number of samples to output (to ports)
300 * Note that (end_sample - start_sample) may not be equal to nframes when the
301 * transport speed isn't 1.0 (eg varispeed).
304 Route::process_output_buffers (BufferSet& bufs,
305 samplepos_t start_sample, samplepos_t end_sample, pframes_t nframes,
306 bool gain_automation_ok, bool run_disk_reader)
308 /* Caller must hold process lock */
309 assert (!AudioEngine::instance()->process_lock().trylock());
311 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
313 // can this actually happen?
314 // Places that need a WriterLock on (_processor_lock) must also take the process-lock.
315 bufs.silence (nframes, 0);
316 assert (0); // ...one way to find out.
320 /* We should offset the route-owned ctrls by the given latency, however
321 * this only affects Mute. Other route-owned controls (solo, polarity..)
322 * are not automatable.
324 * Mute has its own issues since there's not a single mute-point,
327 automation_run (start_sample, nframes);
330 _pannable->automation_run (start_sample + _signal_latency, nframes);
333 /* figure out if we're going to use gain automation */
334 if (gain_automation_ok) {
335 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
336 _amp->setup_gain_automation (
337 start_sample + _amp->output_latency (),
338 end_sample + _amp->output_latency (),
341 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
342 _trim->setup_gain_automation (
343 start_sample + _trim->output_latency (),
344 end_sample + _trim->output_latency (),
348 /* We align the playhead to output. The user hears what the clock says:
349 * When the playhead/clock says 1:00:00:00 the user will hear the audio sample
350 * at 1:00:00:00. sample_start will be [sample at] 1:00:00:00
352 * e.g. clock says Time T = 0, sample_start = 0
353 * Disk-read(play) -> latent-plugin (+10) -> fader-automation -> output (+5)
354 * -> total playback latency "disk -> out" is 15.
355 * -> at Time T= -15, the disk-reader reads sample T=0.
356 * By the Time T=0 is reached (dt=15 later) that sample is audible.
359 const double speed = (is_auditioner() ? 1.0 : _session.transport_speed ());
361 const sampleoffset_t latency_offset = _signal_latency + _output->latency ();
363 /* when rolling backwards this can become negative */
364 start_sample -= latency_offset;
365 end_sample -= latency_offset;
367 start_sample += latency_offset;
368 end_sample += latency_offset;
371 /* Note: during intial pre-roll 'start_sample' as passed as argument can be negative.
372 * Functions calling process_output_buffers() will set "run_disk_reader"
373 * to false if the pre-roll count-down is larger than playback_latency ().
375 * playback_latency() is guarnteed to be <= _signal_latency + _output->latency ()
377 assert (!_disk_reader || !run_disk_reader || start_sample >= 0 || speed < 0);
379 /* however the disk-writer may need to pick up output from other tracks
380 * during pre-roll (in particular if this route has latent effects after the disk).
382 * e.g. track 1 play -> latency A --port--> track2 capture -> latency B ---> out
383 * total pre-roll = A + B.
385 * Note the disk-writer has built-in overlap detection (it's safe to run it early)
388 bool run_disk_writer = false;
389 if (_disk_writer && speed > 0) {
390 samplecnt_t latency_preroll = _session.remaining_latency_preroll ();
391 run_disk_writer = latency_preroll < nframes + (_signal_latency + _output->latency ());
392 if (end_sample - _disk_writer->input_latency () < _session.transport_sample ()) {
393 run_disk_writer = true;
397 /* Tell main outs what to do about monitoring. We do this so that
398 * on a transition between monitoring states we get a de-clicking gain
399 * change in the _main_outs delivery, if config.get_use_monitor_fades()
402 * We override this in the case where we have an internal generator.
404 * FIXME: when punching in/out this also depends on latency compensated time
405 * for this route. monitoring_state() does not currently handle that correctly,.
407 * Also during remaining_latency_preroll, transport_rolling () is false, but
408 * we may need to monitor disk instead.
410 MonitorState ms = monitoring_state ();
411 bool silence = _have_internal_generator ? false : (ms == MonitoringSilence);
413 _main_outs->no_outs_cuz_we_no_monitor (silence);
415 /* -------------------------------------------------------------------------------------------
417 ----------------------------------------------------------------------------------------- */
418 /* XXX We'll need to protect silent inputs as well as silent disk
419 * (when not monitoring input or monitoring disk and there's no region
420 * for a longer time).
422 * ...or simply drop that feature.
424 if (_denormal_protection || Config->get_denormal_protection()) {
426 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
427 Sample* const sp = i->data();
428 for (pframes_t nx = 0; nx < nframes; ++nx) {
435 /* -------------------------------------------------------------------------------------------
437 ----------------------------------------------------------------------------------------- */
439 samplecnt_t latency = 0;
441 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
443 /* TODO check for split cycles here.
445 * start_frame, end_frame is adjusted by latency and may
450 /* if it has any inputs, make sure they match */
451 if (boost::dynamic_pointer_cast<UnknownProcessor> (*i) == 0 && (*i)->input_streams() != ChanCount::ZERO) {
452 if (bufs.count() != (*i)->input_streams()) {
454 DEBUG::Processors, string_compose (
455 "input port mismatch %1 bufs = %2 input for %3 = %4\n",
456 _name, bufs.count(), (*i)->name(), (*i)->input_streams()
463 bool re_inject_oob_data = false;
464 if ((*i) == _disk_reader) {
465 /* Well now, we've made it past the disk-writer and to the disk-reader.
466 * Time to decide what to do about monitoring.
468 * Even when not doing MonitoringDisk, we need to run the processors,
469 * so that it advances its internal buffers (IFF run_disk_reader is true).
472 if (ms == MonitoringDisk || ms == MonitoringSilence) {
473 /* this will clear out-of-band data, too (e.g. MIDI-PC, Panic etc.
474 * OOB data is written at the end of the cycle (nframes - 1),
475 * and jack does not re-order events, so we push them back later */
476 re_inject_oob_data = true;
477 bufs.silence (nframes, 0);
481 double pspeed = speed;
482 if ((!run_disk_reader && (*i) == _disk_reader) || (!run_disk_writer && (*i) == _disk_writer)) {
483 /* run with speed 0, no-roll */
488 (*i)->run (bufs, start_sample + latency, end_sample + latency, pspeed, nframes, *i != _processors.back());
490 (*i)->run (bufs, start_sample - latency, end_sample - latency, pspeed, nframes, *i != _processors.back());
493 bufs.set_count ((*i)->output_streams());
495 /* Note: plugin latency may change. While the plugin does inform the session via
496 * processor_latency_changed(). But the session may not yet have gotten around to
497 * update the actual worste-case and update this track's _signal_latency.
499 * So there can be cases where adding up all latencies may not equal _signal_latency.
501 if ((*i)->active ()) {
502 latency += (*i)->signal_latency ();
505 if (re_inject_oob_data) {
506 write_out_of_band_data (bufs, nframes);
510 if ((*i) == _delayline) {
511 latency += _delayline->delay ();
518 Route::bounce_process (BufferSet& buffers, samplepos_t start, samplecnt_t nframes,
519 boost::shared_ptr<Processor> endpoint,
520 bool include_endpoint, bool for_export, bool for_freeze)
522 /* If no processing is required, there's no need to go any further. */
523 if (!endpoint && !include_endpoint) {
527 samplecnt_t latency = bounce_get_latency(_amp, false, for_export, for_freeze);
528 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
529 _amp->setup_gain_automation (start - latency, start - latency + nframes, nframes);
531 /* trim is always at the top, for bounce no latency compensation is needed */
532 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
533 _trim->setup_gain_automation (start, start + nframes, nframes);
536 const double speed = _session.transport_speed ();
537 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
539 if (!include_endpoint && (*i) == endpoint) {
543 /* if we're *not* exporting, stop processing if we come across a routing processor. */
544 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
547 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
551 /* special case the panner (export outputs)
552 * Ideally we'd only run the panner, not the delivery itself...
553 * but panners need separate input/output buffers and some context
554 * (panshell, panner type, etc). AFAICT there is no ill side effect
555 * of re-using the main delivery when freewheeling/exporting a region.
557 if ((*i) == _main_outs) {
558 assert ((*i)->does_routing());
559 (*i)->run (buffers, start - latency, start - latency + nframes, speed, nframes, true);
560 buffers.set_count ((*i)->output_streams());
563 /* don't run any processors that do routing.
564 * Also don't bother with metering.
566 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
567 (*i)->run (buffers, start - latency, start - latency + nframes, 1.0, nframes, true);
568 buffers.set_count ((*i)->output_streams());
569 latency += (*i)->signal_latency ();
572 if ((*i) == endpoint) {
579 Route::bounce_get_latency (boost::shared_ptr<Processor> endpoint,
580 bool include_endpoint, bool for_export, bool for_freeze) const
582 samplecnt_t latency = 0;
583 if (!endpoint && !include_endpoint) {
587 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
588 if (!include_endpoint && (*i) == endpoint) {
591 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
594 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
597 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
598 latency += (*i)->signal_latency ();
600 if ((*i) == endpoint) {
608 Route::bounce_get_output_streams (ChanCount &cc, boost::shared_ptr<Processor> endpoint,
609 bool include_endpoint, bool for_export, bool for_freeze) const
611 if (!endpoint && !include_endpoint) {
615 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
616 if (!include_endpoint && (*i) == endpoint) {
619 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
622 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
625 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
626 cc = (*i)->output_streams();
628 if ((*i) == endpoint) {
636 Route::n_process_buffers ()
638 return max (_input->n_ports(), processor_max_streams);
642 Route::monitor_run (samplepos_t start_sample, samplepos_t end_sample, pframes_t nframes)
644 assert (is_monitor());
645 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
646 run_route (start_sample, end_sample, nframes, true, false);
650 Route::run_route (samplepos_t start_sample, samplepos_t end_sample, pframes_t nframes, bool gain_automation_ok, bool run_disk_reader)
652 BufferSet& bufs (_session.get_route_buffers (n_process_buffers()));
654 fill_buffers_with_input (bufs, _input, nframes);
656 /* filter captured data before meter sees it */
659 if (is_monitor() && _session.listening() && !_session.is_auditioning()) {
661 /* control/monitor bus ignores input ports when something is
662 feeding the listen "stream". data will "arrive" into the
663 route from the intreturn processor element.
666 bufs.silence (nframes, 0);
669 snapshot_out_of_band_data (nframes);
670 /* append immediate messages to the first MIDI buffer (thus sending it to the first output port) */
672 write_out_of_band_data (bufs, nframes);
674 /* run processor chain */
676 process_output_buffers (bufs, start_sample, end_sample, nframes, gain_automation_ok, run_disk_reader);
678 /* map events (e.g. MIDI-CC) back to control-parameters */
679 update_controls (bufs);
681 flush_processor_buffers_locked (nframes);
685 Route::set_listen (bool yn)
688 if (_monitor_send->active() == yn) {
692 _monitor_send->activate ();
694 _monitor_send->deactivate ();
700 Route::solo_control_changed (bool, Controllable::GroupControlDisposition)
702 /* nothing to do if we're not using AFL/PFL. But if we are, we need
703 to alter the active state of the monitor send.
706 if (Config->get_solo_control_is_listen_control ()) {
707 set_listen (_solo_control->self_soloed() || _solo_control->get_masters_value());
712 Route::push_solo_isolate_upstream (int32_t delta)
714 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
716 boost::shared_ptr<RouteList> routes = _session.get_routes ();
717 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
719 if ((*i).get() == this || !(*i)->can_solo()) {
724 bool does_feed = feeds (*i, &sends_only);
726 if (does_feed && !sends_only) {
727 (*i)->solo_isolate_control()->mod_solo_isolated_by_upstream (delta);
733 Route::push_solo_upstream (int delta)
735 DEBUG_TRACE (DEBUG::Solo, string_compose("\t ... INVERT push from %1\n", _name));
736 for (FedBy::iterator i = _fed_by.begin(); i != _fed_by.end(); ++i) {
740 boost::shared_ptr<Route> sr (i->r.lock());
742 sr->solo_control()->mod_solo_by_others_downstream (-delta);
749 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
751 cerr << name << " {" << endl;
752 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
753 p != procs.end(); ++p) {
754 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << " @ " << (*p) << endl;
760 /** Supposing that we want to insert a Processor at a given Placement, return
761 * the processor to add the new one before (or 0 to add at the end).
763 boost::shared_ptr<Processor>
764 Route::before_processor_for_placement (Placement p)
766 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
768 ProcessorList::iterator loc;
771 /* generic pre-fader: insert immediately before the amp */
772 loc = find (_processors.begin(), _processors.end(), _amp);
774 /* generic post-fader: insert right before the main outs */
775 loc = find (_processors.begin(), _processors.end(), _main_outs);
778 return loc != _processors.end() ? *loc : boost::shared_ptr<Processor> ();
781 /** Supposing that we want to insert a Processor at a given index, return
782 * the processor to add the new one before (or 0 to add at the end).
784 boost::shared_ptr<Processor>
785 Route::before_processor_for_index (int index)
788 return boost::shared_ptr<Processor> ();
791 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
793 ProcessorList::iterator i = _processors.begin ();
795 while (i != _processors.end() && j < index) {
796 if ((*i)->display_to_user()) {
803 return (i != _processors.end() ? *i : boost::shared_ptr<Processor> ());
806 /** Add a processor either pre- or post-fader
807 * @return 0 on success, non-0 on failure.
810 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err, bool activation_allowed)
812 return add_processor (processor, before_processor_for_placement (placement), err, activation_allowed);
816 /** Add a processor to a route such that it ends up with a given index into the visible processors.
817 * @param index Index to add the processor at, or -1 to add at the end of the list.
818 * @return 0 on success, non-0 on failure.
821 Route::add_processor_by_index (boost::shared_ptr<Processor> processor, int index, ProcessorStreams* err, bool activation_allowed)
823 return add_processor (processor, before_processor_for_index (index), err, activation_allowed);
826 /** Add a processor to the route.
827 * @param before An existing processor in the list, or 0; the new processor will be inserted immediately before it (or at the end).
828 * @return 0 on success, non-0 on failure.
831 Route::add_processor (boost::shared_ptr<Processor> processor, boost::shared_ptr<Processor> before, ProcessorStreams* err, bool activation_allowed)
833 assert (processor != _meter);
834 assert (processor != _main_outs);
836 DEBUG_TRACE (DEBUG::Processors, string_compose (
837 "%1 adding processor %2\n", name(), processor->name()));
841 pl.push_back (processor);
842 int rv = add_processors (pl, before, err);
848 if (activation_allowed && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user ())) {
849 processor->activate ();
856 Route::processor_selfdestruct (boost::weak_ptr<Processor> wp)
858 /* We cannot destruct the processor here (usually RT-thread
859 * with various locks held - in case of sends also io_locks).
860 * Queue for deletion in low-priority thread.
862 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
863 selfdestruct_sequence.push_back (wp);
867 Route::add_processor_from_xml_2X (const XMLNode& node, int version)
869 XMLProperty const * prop;
872 boost::shared_ptr<Processor> processor;
874 /* bit of a hack: get the `placement' property from the <Redirect> tag here
875 so that we can add the processor in the right place (pre/post-fader)
878 XMLNodeList const & children = node.children ();
879 XMLNodeList::const_iterator i = children.begin ();
881 while (i != children.end() && (*i)->name() != X_("Redirect")) {
885 Placement placement = PreFader;
887 if (i != children.end()) {
888 if ((prop = (*i)->property (X_("placement"))) != 0) {
889 placement = Placement (string_2_enum (prop->value(), placement));
893 if (node.name() == "Insert") {
895 if ((prop = node.property ("type")) != 0) {
897 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
898 prop->value() == "lv2" ||
899 prop->value() == "windows-vst" ||
900 prop->value() == "mac-vst" ||
901 prop->value() == "lxvst" ||
902 prop->value() == "audiounit") {
904 if (_session.get_disable_all_loaded_plugins ()) {
905 processor.reset (new UnknownProcessor (_session, node));
907 processor.reset (new PluginInsert (_session));
908 processor->set_owner (this);
913 processor.reset (new PortInsert (_session, _pannable, _mute_master));
918 } else if (node.name() == "Send") {
920 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
921 processor.reset (new Send (_session, sendpan, _mute_master));
925 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
929 if (processor->set_state (node, version)) {
933 //A2 uses the "active" flag in the toplevel redirect node, not in the child plugin/IO
934 if (i != children.end()) {
935 if ((prop = (*i)->property (X_("active"))) != 0) {
936 if ( string_to<bool> (prop->value()) && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user () ) )
937 processor->activate();
939 processor->deactivate();
943 return (add_processor (processor, placement, 0, false) == 0);
946 catch (failed_constructor &err) {
947 warning << _("processor could not be created. Ignored.") << endmsg;
953 inline Route::PluginSetupOptions operator|= (Route::PluginSetupOptions& a, const Route::PluginSetupOptions& b) {
954 return a = static_cast<Route::PluginSetupOptions> (static_cast <int>(a) | static_cast<int> (b));
957 inline Route::PluginSetupOptions operator&= (Route::PluginSetupOptions& a, const Route::PluginSetupOptions& b) {
958 return a = static_cast<Route::PluginSetupOptions> (static_cast <int>(a) & static_cast<int> (b));
962 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
964 ProcessorList::iterator loc;
965 boost::shared_ptr <PluginInsert> fanout;
967 if (g_atomic_int_get (&_pending_process_reorder)) {
968 /* we need to flush any pending re-order changes */
969 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
970 apply_processor_changes_rt ();
974 loc = find(_processors.begin(), _processors.end(), before);
975 if (loc == _processors.end ()) {
979 /* nothing specified - at end */
980 loc = _processors.end ();
983 if (others.empty()) {
987 ProcessorList to_skip;
989 // check if there's an instrument to replace or configure
990 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
991 boost::shared_ptr<PluginInsert> pi;
992 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) == 0) {
995 if (!pi->plugin ()->get_info ()->is_instrument ()) {
998 boost::shared_ptr<Processor> instrument = the_instrument ();
999 ChanCount in (DataType::MIDI, 1);
1000 ChanCount out (DataType::AUDIO, 2); // XXX route's out?!
1002 PluginSetupOptions flags = None;
1004 flags |= CanReplace;
1005 in = instrument->input_streams ();
1006 out = instrument->output_streams ();
1008 if (pi->has_output_presets (in, out)) {
1012 pi->set_strict_io (_strict_io);
1014 PluginSetupOptions mask = None;
1015 if (Config->get_ask_replace_instrument ()) {
1018 if (Config->get_ask_setup_instrument ()) {
1024 if (flags != None) {
1025 boost::optional<int> rv = PluginSetup (boost::dynamic_pointer_cast<Route>(shared_from_this ()), pi, flags); /* EMIT SIGNAL */
1026 int mode = rv.get_value_or (0);
1029 to_skip.push_back (*i); // don't add this one;
1032 replace_processor (instrument, *i, err);
1033 to_skip.push_back (*i);
1038 if ((mode & 5) == 4) {
1045 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1046 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1047 ProcessorState pstate (this);
1049 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1054 ProcessorList::iterator check = find (to_skip.begin(), to_skip.end(), *i);
1055 if (check != to_skip.end()) {
1059 boost::shared_ptr<PluginInsert> pi;
1061 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1062 pi->set_strict_io (_strict_io);
1066 /* Ensure that only one amp is in the list at any time */
1067 ProcessorList::iterator check = find (_processors.begin(), _processors.end(), *i);
1068 if (check != _processors.end()) {
1069 if (before == _amp) {
1070 /* Already in position; all is well */
1073 _processors.erase (check);
1078 assert (find (_processors.begin(), _processors.end(), *i) == _processors.end ());
1080 _processors.insert (loc, *i);
1081 (*i)->set_owner (this);
1084 if (configure_processors_unlocked (err, &lm)) {
1086 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
1091 if (pi && pi->has_sidechain ()) {
1092 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
1095 if ((*i)->active()) {
1096 // emit ActiveChanged() and latency_changed() if needed
1100 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1102 boost::shared_ptr<Send> send;
1103 if ((send = boost::dynamic_pointer_cast<Send> (*i))) {
1104 send->SelfDestruct.connect_same_thread (*this,
1105 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (*i)));
1109 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1110 boost::shared_ptr<PluginInsert> pi;
1112 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1113 if (pi->has_no_inputs ()) {
1114 _have_internal_generator = true;
1120 _output->set_user_latency (0);
1123 reset_instrument_info ();
1124 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1125 set_processor_positions ();
1127 if (fanout && fanout->configured ()
1128 && fanout->output_streams().n_audio() > 2
1129 && boost::dynamic_pointer_cast<PluginInsert> (the_instrument ()) == fanout) {
1130 fan_out (); /* EMIT SIGNAL */
1136 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1138 if (p == PreFader) {
1139 start = _processors.begin();
1140 end = find(_processors.begin(), _processors.end(), _amp);
1142 start = find(_processors.begin(), _processors.end(), _amp);
1144 end = _processors.end();
1148 /** Turn off all processors with a given placement
1149 * @param p Placement of processors to disable
1152 Route::disable_processors (Placement p)
1154 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1156 ProcessorList::iterator start, end;
1157 placement_range(p, start, end);
1159 for (ProcessorList::iterator i = start; i != end; ++i) {
1160 (*i)->enable (false);
1163 _session.set_dirty ();
1166 /** Turn off all redirects
1169 Route::disable_processors ()
1171 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1173 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1174 (*i)->enable (false);
1177 _session.set_dirty ();
1180 /** Turn off all redirects with a given placement
1181 * @param p Placement of redirects to disable
1184 Route::disable_plugins (Placement p)
1186 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1188 ProcessorList::iterator start, end;
1189 placement_range(p, start, end);
1191 for (ProcessorList::iterator i = start; i != end; ++i) {
1192 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1193 (*i)->enable (false);
1197 _session.set_dirty ();
1200 /** Turn off all plugins
1203 Route::disable_plugins ()
1205 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1207 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1208 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1209 (*i)->enable (false);
1213 _session.set_dirty ();
1218 Route::ab_plugins (bool forward)
1220 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1224 /* forward = turn off all active redirects, and mark them so that the next time
1225 we go the other way, we will revert them
1228 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1229 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1232 if (!(*i)->display_to_user ()) {
1236 if (boost::dynamic_pointer_cast<PluginInsert> (*i)->is_channelstrip()) {
1241 if ((*i)->enabled ()) {
1242 (*i)->enable (false);
1243 (*i)->set_next_ab_is_active (true);
1245 (*i)->set_next_ab_is_active (false);
1251 /* backward = if the redirect was marked to go active on the next ab, do so */
1253 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1254 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1257 if (!(*i)->display_to_user ()) {
1261 if (boost::dynamic_pointer_cast<PluginInsert> (*i)->is_channelstrip()) {
1266 (*i)->enable ((*i)->get_next_ab_is_active ());
1270 _session.set_dirty ();
1274 /** Remove processors with a given placement.
1275 * @param p Placement of processors to remove.
1278 Route::clear_processors (Placement p)
1280 if (!_session.engine().connected()) {
1284 bool already_deleting = _session.deletion_in_progress();
1285 if (!already_deleting) {
1286 _session.set_deletion_in_progress();
1289 ProcessorList old_list = _processors;
1291 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1292 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1293 ProcessorList new_list;
1294 ProcessorStreams err;
1295 bool seen_amp = false;
1297 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1303 if (is_internal_processor (*i)) {
1305 /* you can't remove these */
1307 new_list.push_back (*i);
1314 new_list.push_back (*i);
1317 (*i)->drop_references ();
1325 (*i)->drop_references ();
1328 new_list.push_back (*i);
1335 _processors = new_list;
1336 configure_processors_unlocked (&err, &lm); // this can't fail
1338 /* drop references w/o process-lock (I/O procs may re-take it in ~IO() */
1341 processor_max_streams.reset();
1342 _have_internal_generator = false;
1343 reset_instrument_info ();
1344 set_processor_positions ();
1346 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1348 if (!already_deleting) {
1349 _session.clear_deletion_in_progress();
1354 Route::is_internal_processor (boost::shared_ptr<Processor> p) const
1356 if (p == _amp || p == _meter || p == _main_outs || p == _delayline || p == _trim || p == _polarity) {
1363 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err, bool need_process_lock)
1365 // TODO once the export point can be configured properly, do something smarter here
1366 if (processor == _capturing_processor) {
1367 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1368 if (need_process_lock) {
1372 _capturing_processor.reset();
1374 if (need_process_lock) {
1379 /* these can never be removed */
1381 if (is_internal_processor (processor)) {
1385 if (!_session.engine().connected()) {
1389 processor_max_streams.reset();
1392 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1393 if (need_process_lock) {
1397 /* Caller must hold process lock */
1398 assert (!AudioEngine::instance()->process_lock().trylock());
1400 Glib::Threads::RWLock::WriterLock lm (_processor_lock); // XXX deadlock after export
1402 ProcessorState pstate (this);
1404 ProcessorList::iterator i;
1405 bool removed = false;
1407 for (i = _processors.begin(); i != _processors.end(); ) {
1408 if (*i == processor) {
1410 /* move along, see failure case for configure_processors()
1411 where we may need to reconfigure the processor.
1414 /* stop redirects that send signals to JACK ports
1415 from causing noise as a result of no longer being
1419 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor> (*i);
1420 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
1424 iop = pi->sidechain();
1431 i = _processors.erase (i);
1439 _output->set_user_latency (0);
1447 if (configure_processors_unlocked (err, &lm)) {
1449 /* we know this will work, because it worked before :) */
1450 configure_processors_unlocked (0, &lm);
1454 _have_internal_generator = false;
1456 for (i = _processors.begin(); i != _processors.end(); ++i) {
1457 boost::shared_ptr<PluginInsert> pi;
1459 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1460 if (pi->has_no_inputs ()) {
1461 _have_internal_generator = true;
1466 if (need_process_lock) {
1471 reset_instrument_info ();
1472 processor->drop_references ();
1473 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1474 set_processor_positions ();
1480 Route::replace_processor (boost::shared_ptr<Processor> old, boost::shared_ptr<Processor> sub, ProcessorStreams* err)
1482 /* these can never be removed */
1483 if (is_internal_processor (old)) {
1486 /* and can't be used as substitute, either */
1487 if (is_internal_processor (sub)) {
1491 /* I/Os are out, too */
1492 if (boost::dynamic_pointer_cast<IOProcessor> (old) || boost::dynamic_pointer_cast<IOProcessor> (sub)) {
1496 /* this function cannot be used to swap/reorder processors */
1497 if (find (_processors.begin(), _processors.end(), sub) != _processors.end ()) {
1501 if (!AudioEngine::instance()->connected() || !old || !sub) {
1505 /* ensure that sub is not owned by another route */
1506 if (sub->owner ()) {
1511 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1512 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1513 ProcessorState pstate (this);
1515 assert (find (_processors.begin(), _processors.end(), sub) == _processors.end ());
1517 ProcessorList::iterator i;
1518 bool replaced = false;
1519 bool enable = old->enabled ();
1521 for (i = _processors.begin(); i != _processors.end(); ) {
1523 i = _processors.erase (i);
1524 _processors.insert (i, sub);
1525 sub->set_owner (this);
1538 boost::shared_ptr<PluginInsert> pi;
1539 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(sub)) != 0) {
1540 pi->set_strict_io (true);
1544 if (configure_processors_unlocked (err, &lm)) {
1546 configure_processors_unlocked (0, &lm);
1550 _have_internal_generator = false;
1552 for (i = _processors.begin(); i != _processors.end(); ++i) {
1553 boost::shared_ptr<PluginInsert> pi;
1554 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1555 if (pi->has_no_inputs ()) {
1556 _have_internal_generator = true;
1566 sub->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1567 _output->set_user_latency (0);
1570 reset_instrument_info ();
1571 old->drop_references ();
1572 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1573 set_processor_positions ();
1578 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1580 ProcessorList deleted;
1582 if (!_session.engine().connected()) {
1586 processor_max_streams.reset();
1589 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1590 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1591 ProcessorState pstate (this);
1593 ProcessorList::iterator i;
1594 boost::shared_ptr<Processor> processor;
1596 for (i = _processors.begin(); i != _processors.end(); ) {
1600 /* these can never be removed */
1602 if (is_internal_processor (processor)) {
1607 /* see if its in the list of processors to delete */
1609 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1614 /* stop IOProcessors that send to JACK ports
1615 from causing noise as a result of no longer being
1619 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(processor);
1620 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
1623 iop = pi->sidechain();
1630 deleted.push_back (processor);
1631 i = _processors.erase (i);
1634 if (deleted.empty()) {
1635 /* none of those in the requested list were found */
1639 _output->set_user_latency (0);
1641 if (configure_processors_unlocked (err, &lm)) {
1643 /* we know this will work, because it worked before :) */
1644 configure_processors_unlocked (0, &lm);
1649 _have_internal_generator = false;
1651 for (i = _processors.begin(); i != _processors.end(); ++i) {
1652 boost::shared_ptr<PluginInsert> pi;
1654 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1655 if (pi->has_no_inputs ()) {
1656 _have_internal_generator = true;
1663 /* now try to do what we need to so that those that were removed will be deleted */
1665 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1666 (*i)->drop_references ();
1669 reset_instrument_info ();
1670 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1671 set_processor_positions ();
1677 Route::reset_instrument_info ()
1679 boost::shared_ptr<Processor> instr = the_instrument();
1681 _instrument_info.set_internal_instrument (instr);
1685 /** Caller must hold process lock */
1687 Route::configure_processors (ProcessorStreams* err)
1689 #ifndef PLATFORM_WINDOWS
1690 assert (!AudioEngine::instance()->process_lock().trylock());
1693 if (!_in_configure_processors) {
1694 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1695 return configure_processors_unlocked (err, &lm);
1702 Route::input_streams () const
1704 return _input->n_ports ();
1707 list<pair<ChanCount, ChanCount> >
1708 Route::try_configure_processors (ChanCount in, ProcessorStreams* err)
1710 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1712 return try_configure_processors_unlocked (in, err);
1715 list<pair<ChanCount, ChanCount> >
1716 Route::try_configure_processors_unlocked (ChanCount in, ProcessorStreams* err)
1718 // Check each processor in order to see if we can configure as requested
1720 list<pair<ChanCount, ChanCount> > configuration;
1723 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1724 DEBUG_TRACE (DEBUG::Processors, "{\n");
1726 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1728 if ((*p)->can_support_io_configuration(in, out)) {
1730 if (boost::dynamic_pointer_cast<Delivery> (*p)
1731 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main
1733 && (is_monitor() || _strict_io || Profile->get_mixbus ())) {
1734 /* with strict I/O the panner + output are forced to
1735 * follow the last processor's output.
1737 * Delivery::can_support_io_configuration() will only add ports,
1738 * but not remove excess ports.
1740 * This works because the delivery only requires
1741 * as many outputs as there are inputs.
1742 * Delivery::configure_io() will do the actual removal
1743 * by calling _output->ensure_io()
1745 if (!is_master() && _session.master_out () && in.n_audio() > 0) {
1746 /* ..but at least as many as there are master-inputs, if
1747 * the delivery is dealing with audio */
1748 // XXX this may need special-casing for mixbus (master-outputs)
1749 // and should maybe be a preference anyway ?!
1750 out = ChanCount::max (in, _session.master_out ()->n_inputs ());
1756 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID=%2 in=%3 out=%4\n",(*p)->name(), (*p)->id(), in, out));
1757 configuration.push_back(make_pair(in, out));
1760 // restriction for Monitor Section Processors
1761 if (in.n_audio() != out.n_audio() || out.n_midi() > 0) {
1762 /* Note: The Monitor follows the master-bus and has no panner.
1764 * The general idea is to only allow plugins that retain the channel-count
1765 * and plugins with MIDI in (e.g VSTs with control that will remain unconnected).
1766 * Then again 5.1 in, monitor stereo is a valid use-case.
1768 * and worse: we only refuse adding plugins *here*.
1770 * 1) stereo-master, stereo-mon, add a stereo-plugin, OK
1771 * 2) change master-bus, add a channel
1772 * 2a) monitor-secion follows
1773 * 3) monitor processors fail to re-reconfigure (stereo plugin)
1774 * 4) re-load session, monitor-processor remains unconfigured, crash.
1776 DEBUG_TRACE (DEBUG::Processors, "Monitor: Channel configuration change.\n");
1778 if (boost::dynamic_pointer_cast<InternalSend> (*p)) {
1779 // internal sends make no sense, only feedback
1780 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1781 return list<pair<ChanCount, ChanCount> > ();
1783 if (boost::dynamic_pointer_cast<PortInsert> (*p)) {
1784 /* External Sends can be problematic. one can add/remove ports
1785 * there signal leaves the DAW to external monitors anyway, so there's
1786 * no real use for allowing them here anyway.
1788 DEBUG_TRACE (DEBUG::Processors, "Monitor: No External Sends allowed.\n");
1789 return list<pair<ChanCount, ChanCount> > ();
1791 if (boost::dynamic_pointer_cast<Send> (*p)) {
1793 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1794 return list<pair<ChanCount, ChanCount> > ();
1803 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
1804 DEBUG_TRACE (DEBUG::Processors, string_compose ("---- %1 cannot support in=%2 out=%3\n", (*p)->name(), in, out));
1805 DEBUG_TRACE (DEBUG::Processors, "}\n");
1806 return list<pair<ChanCount, ChanCount> > ();
1810 DEBUG_TRACE (DEBUG::Processors, "}\n");
1812 return configuration;
1815 /** Set the input/output configuration of each processor in the processors list.
1816 * Caller must hold process lock.
1817 * Return 0 on success, otherwise configuration is impossible.
1820 Route::configure_processors_unlocked (ProcessorStreams* err, Glib::Threads::RWLock::WriterLock* lm)
1822 #ifndef PLATFORM_WINDOWS
1823 assert (!AudioEngine::instance()->process_lock().trylock());
1826 if (_in_configure_processors) {
1830 /* put invisible processors where they should be */
1831 setup_invisible_processors ();
1833 _in_configure_processors = true;
1835 list<pair<ChanCount, ChanCount> > configuration = try_configure_processors_unlocked (input_streams (), err);
1837 if (configuration.empty ()) {
1838 _in_configure_processors = false;
1843 bool seen_mains_out = false;
1844 processor_out_streams = _input->n_ports();
1845 processor_max_streams.reset();
1847 /* processor configure_io() may result in adding ports
1848 * e.g. Delivery::configure_io -> ARDOUR::IO::ensure_io ()
1850 * with jack2 adding ports results in a graph-order callback,
1851 * which calls Session::resort_routes() and eventually
1852 * Route::direct_feeds_according_to_reality()
1853 * which takes a ReaderLock (_processor_lock).
1855 * so we can't hold a WriterLock here until jack2 threading
1858 * NB. we still hold the process lock
1860 * (ardour's own engines do call graph-order from the
1861 * process-thread and hence do not have this issue; besides
1862 * merely adding ports won't trigger a graph-order, only
1863 * making connections does)
1867 // TODO check for a potential ReaderLock after ReaderLock ??
1868 Glib::Threads::RWLock::ReaderLock lr (_processor_lock);
1870 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1871 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1873 if (!(*p)->configure_io(c->first, c->second)) {
1874 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration failed\n", _name));
1875 _in_configure_processors = false;
1881 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1882 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1884 boost::shared_ptr<IOProcessor> iop;
1885 boost::shared_ptr<PluginInsert> pi;
1886 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
1887 /* plugins connected via Split or Hide Match may have more channels.
1888 * route/scratch buffers are needed for all of them
1889 * The configuration may only be a subset (both input and output)
1891 processor_max_streams = ChanCount::max(processor_max_streams, pi->required_buffers());
1893 else if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*p)) != 0) {
1894 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_input_streams());
1895 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_output_streams());
1899 if (boost::dynamic_pointer_cast<Delivery> (*p)
1900 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main) {
1901 /* main delivery will increase port count to match input.
1902 * the Delivery::Main is usually the last processor - followed only by
1905 seen_mains_out = true;
1907 if (!seen_mains_out) {
1908 processor_out_streams = out;
1917 _meter->set_max_channels (processor_max_streams);
1920 /* make sure we have sufficient scratch buffers to cope with the new processor
1923 _session.ensure_buffers (n_process_buffers ());
1925 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration complete\n", _name));
1927 _in_configure_processors = false;
1931 /** Set all visible processors to a given active state (except Fader, whose state is not changed)
1932 * @param state New active state for those processors.
1935 Route::all_visible_processors_active (bool state)
1937 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1939 if (_processors.empty()) {
1943 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1944 if (!(*i)->display_to_user() || boost::dynamic_pointer_cast<Amp> (*i)) {
1948 boost::shared_ptr<PluginInsert> pi;
1949 if (0 != (pi = boost::dynamic_pointer_cast<PluginInsert>(*i))) {
1950 if (pi->is_channelstrip ()) {
1955 (*i)->enable (state);
1958 _session.set_dirty ();
1962 Route::processors_reorder_needs_configure (const ProcessorList& new_order)
1964 /* check if re-order requires re-configuration of any processors
1965 * -> compare channel configuration for all processors
1967 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1968 ChanCount c = input_streams ();
1970 for (ProcessorList::const_iterator j = new_order.begin(); j != new_order.end(); ++j) {
1972 if (c != (*j)->input_streams()) {
1975 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1978 if ((*i)->input_streams() != c) {
1981 c = (*i)->output_streams();
1993 __attribute__((annotate("realtime")))
1996 Route::apply_processor_order (const ProcessorList& new_order)
1998 /* need to hold processor_lock; either read or write lock
1999 * and the engine process_lock.
2000 * Due to r/w lock ambiguity we can only assert the latter
2002 assert (!AudioEngine::instance()->process_lock().trylock());
2005 /* "new_order" is an ordered list of processors to be positioned according to "placement".
2006 * NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
2007 * processors in the current actual processor list that are hidden. Any visible processors
2008 * in the current list but not in "new_order" will be assumed to be deleted.
2011 /* "as_it_will_be" and "_processors" are lists of shared pointers.
2012 * actual memory usage is small, but insert/erase is not actually rt-safe :(
2013 * (note though that ::processors_reorder_needs_configure() ensured that
2014 * this function will only ever be called from the rt-thread if no processor were removed)
2016 * either way, I can't proove it, but an x-run due to re-order here is less likley
2017 * than an x-run-less 'ardour-silent cycle' both of which effectively "click".
2020 ProcessorList as_it_will_be;
2021 ProcessorList::iterator oiter;
2022 ProcessorList::const_iterator niter;
2024 oiter = _processors.begin();
2025 niter = new_order.begin();
2027 while (niter != new_order.end()) {
2029 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
2030 then append it to the temp list.
2032 Otherwise, see if the next processor in the old list is in the new list. if not,
2033 its been deleted. If its there, append it to the temp list.
2036 if (oiter == _processors.end()) {
2038 /* no more elements in the old list, so just stick the rest of
2039 the new order onto the temp list.
2042 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
2043 while (niter != new_order.end()) {
2050 if (!(*oiter)->display_to_user()) {
2052 as_it_will_be.push_back (*oiter);
2056 /* visible processor: check that its in the new order */
2058 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
2059 /* deleted: do nothing, shared_ptr<> will clean up */
2061 /* ignore this one, and add the next item from the new order instead */
2062 as_it_will_be.push_back (*niter);
2067 /* now remove from old order - its taken care of no matter what */
2068 oiter = _processors.erase (oiter);
2072 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
2074 /* If the meter is in a custom position, find it and make a rough note of its position */
2075 maybe_note_meter_position ();
2079 Route::move_instrument_down (bool postfader)
2081 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2082 ProcessorList new_order;
2083 boost::shared_ptr<Processor> instrument;
2084 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2085 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
2086 if (pi && pi->plugin ()->get_info ()->is_instrument ()) {
2088 } else if (instrument && *i == _amp) {
2090 new_order.push_back (*i);
2091 new_order.push_back (instrument);
2093 new_order.push_back (instrument);
2094 new_order.push_back (*i);
2097 new_order.push_back (*i);
2104 reorder_processors (new_order, 0);
2108 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
2110 // it a change is already queued, wait for it
2111 // (unless engine is stopped. apply immediately and proceed
2112 while (g_atomic_int_get (&_pending_process_reorder)) {
2113 if (!AudioEngine::instance()->running()) {
2114 DEBUG_TRACE (DEBUG::Processors, "offline apply queued processor re-order.\n");
2115 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2117 apply_processor_order(_pending_processor_order);
2118 setup_invisible_processors ();
2120 g_atomic_int_set (&_pending_process_reorder, 0);
2122 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2123 set_processor_positions ();
2125 // TODO rather use a semaphore or something.
2126 // but since ::reorder_processors() is called
2127 // from the GUI thread, this is fine..
2132 if (processors_reorder_needs_configure (new_order) || !AudioEngine::instance()->running()) {
2134 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2135 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2136 ProcessorState pstate (this);
2138 apply_processor_order (new_order);
2140 if (configure_processors_unlocked (err, &lm)) {
2148 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2149 set_processor_positions ();
2152 DEBUG_TRACE (DEBUG::Processors, "Queue clickless processor re-order.\n");
2153 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2155 // _pending_processor_order is protected by _processor_lock
2156 _pending_processor_order = new_order;
2157 g_atomic_int_set (&_pending_process_reorder, 1);
2160 /* update processor input/output latency
2161 * (total signal_latency does not change)
2163 update_signal_latency (true);
2169 Route::add_remove_sidechain (boost::shared_ptr<Processor> proc, bool add)
2171 boost::shared_ptr<PluginInsert> pi;
2172 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2176 if (pi->has_sidechain () == add) {
2177 return true; // ?? call failed, but result is as expected.
2181 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2182 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2183 if (i == _processors.end ()) {
2189 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ()); // take before Writerlock to avoid deadlock
2190 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2191 PBD::Unwinder<bool> uw (_in_sidechain_setup, true);
2193 lx.release (); // IO::add_port() and ~IO takes process lock - XXX check if this is safe
2195 if (!pi->add_sidechain ()) {
2199 if (!pi->del_sidechain ()) {
2205 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2210 pi->del_sidechain ();
2212 pi->add_sidechain ();
2213 // TODO restore side-chain's state.
2218 configure_processors_unlocked (0, &lm);
2221 if (pi->has_sidechain ()) {
2222 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
2225 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2226 _session.set_dirty ();
2231 Route::plugin_preset_output (boost::shared_ptr<Processor> proc, ChanCount outs)
2233 boost::shared_ptr<PluginInsert> pi;
2234 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2239 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2240 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2241 if (i == _processors.end ()) {
2247 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2248 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2250 const ChanCount& old (pi->preset_out ());
2251 if (!pi->set_preset_out (outs)) {
2252 return true; // no change, OK
2255 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2258 pi->set_preset_out (old);
2261 configure_processors_unlocked (0, &lm);
2264 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2265 _session.set_dirty ();
2270 Route::reset_plugin_insert (boost::shared_ptr<Processor> proc)
2273 return customize_plugin_insert (proc, 0, unused, unused);
2277 Route::customize_plugin_insert (boost::shared_ptr<Processor> proc, uint32_t count, ChanCount outs, ChanCount sinks)
2279 boost::shared_ptr<PluginInsert> pi;
2280 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2285 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2286 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2287 if (i == _processors.end ()) {
2293 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2294 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2296 bool old_cust = pi->custom_cfg ();
2297 uint32_t old_cnt = pi->get_count ();
2298 ChanCount old_chan = pi->output_streams ();
2299 ChanCount old_sinks = pi->natural_input_streams ();
2302 pi->set_custom_cfg (false);
2304 pi->set_custom_cfg (true);
2305 pi->set_count (count);
2306 pi->set_outputs (outs);
2307 pi->set_sinks (sinks);
2310 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2314 pi->set_count (old_cnt);
2315 pi->set_sinks (old_sinks);
2316 pi->set_outputs (old_chan);
2317 pi->set_custom_cfg (old_cust);
2321 configure_processors_unlocked (0, &lm);
2324 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2325 _session.set_dirty ();
2330 Route::set_strict_io (const bool enable)
2332 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2334 if (_strict_io != enable) {
2335 _strict_io = enable;
2336 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2337 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2338 boost::shared_ptr<PluginInsert> pi;
2339 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2340 pi->set_strict_io (_strict_io);
2344 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2348 _strict_io = !enable; // restore old value
2349 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2350 boost::shared_ptr<PluginInsert> pi;
2351 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2352 pi->set_strict_io (_strict_io);
2359 configure_processors (0);
2362 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2363 _session.set_dirty ();
2371 return state (false);
2375 Route::get_template()
2377 return state (true);
2381 Route::state (bool save_template)
2383 if (!_session._template_state_dir.empty()) {
2384 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), _session._template_state_dir));
2387 XMLNode *node = new XMLNode("Route");
2388 ProcessorList::iterator i;
2390 node->set_property (X_("id"), id ());
2391 node->set_property (X_("name"), name());
2392 node->set_property (X_("default-type"), _default_type);
2393 node->set_property (X_("strict-io"), _strict_io);
2395 node->add_child_nocopy (_presentation_info.get_state());
2397 node->set_property (X_("active"), _active);
2398 node->set_property (X_("denormal-protection"), _denormal_protection);
2399 node->set_property (X_("meter-point"), _meter_point);
2400 node->set_property (X_("disk-io-point"), _disk_io_point);
2402 node->set_property (X_("meter-type"), _meter_type);
2405 node->set_property (X_("route-group"), _route_group->name());
2408 node->add_child_nocopy (_solo_control->get_state ());
2409 node->add_child_nocopy (_solo_isolate_control->get_state ());
2410 node->add_child_nocopy (_solo_safe_control->get_state ());
2412 node->add_child_nocopy (_input->get_state ());
2413 node->add_child_nocopy (_output->get_state ());
2414 node->add_child_nocopy (_mute_master->get_state ());
2416 node->add_child_nocopy (_mute_control->get_state ());
2417 node->add_child_nocopy (_phase_control->get_state ());
2419 if (!skip_saving_automation) {
2420 node->add_child_nocopy (Automatable::get_automation_xml_state ());
2423 if (_comment.length()) {
2424 XMLNode *cmt = node->add_child ("Comment");
2425 cmt->add_content (_comment);
2429 node->add_child_nocopy (_pannable->get_state ());
2433 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2434 for (i = _processors.begin(); i != _processors.end(); ++i) {
2435 if (*i == _delayline) {
2438 if (save_template) {
2439 /* template save: do not include internal sends functioning as
2440 aux sends because the chance of the target ID
2441 in the session where this template is used
2444 similarly, do not save listen sends which connect to
2445 the monitor section, because these will always be
2448 boost::shared_ptr<InternalSend> is;
2450 if ((is = boost::dynamic_pointer_cast<InternalSend> (*i)) != 0) {
2451 if (is->role() == Delivery::Listen) {
2456 node->add_child_nocopy((*i)->get_state ());
2461 node->add_child_copy (*_extra_xml);
2464 if (_custom_meter_position_noted) {
2465 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
2467 node->set_property (X_("processor-after-last-custom-meter"), after->id());
2471 if (!_session._template_state_dir.empty()) {
2472 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), ""));
2475 node->add_child_copy (Slavable::get_state());
2481 Route::set_state (const XMLNode& node, int version)
2483 if (version < 3000) {
2484 return set_state_2X (node, version);
2488 XMLNodeConstIterator niter;
2491 if (node.name() != "Route"){
2492 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2496 std::string route_name;
2497 if (node.get_property (X_("name"), route_name)) {
2498 Route::set_name (route_name);
2502 _initial_io_setup = true;
2504 Stripable::set_state (node, version);
2506 node.get_property (X_("strict-io"), _strict_io);
2509 /* monitor bus does not get a panner, but if (re)created
2510 via XML, it will already have one by the time we
2511 call ::set_state(). so ... remove it.
2516 /* add all processors (except amp, which is always present) */
2518 nlist = node.children();
2519 XMLNode processor_state (X_("processor_state"));
2521 Stateful::save_extra_xml (node);
2523 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2527 if (child->name() == IO::state_node_name) {
2528 std::string direction;
2529 if (!child->get_property (X_("direction"), direction)) {
2533 if (direction == "Input") {
2534 _input->set_state (*child, version);
2535 } else if (direction == "Output") {
2536 _output->set_state (*child, version);
2539 } else if (child->name() == X_("Processor")) {
2540 processor_state.add_child_copy (*child);
2541 } else if (child->name() == X_("Pannable")) {
2543 _pannable->set_state (*child, version);
2545 warning << string_compose (_("Pannable state found for route (%1) without a panner!"), name()) << endmsg;
2547 } else if (child->name() == Slavable::xml_node_name) {
2548 Slavable::set_state (*child, version);
2553 if (node.get_property (X_("meter-point"), mp)) {
2554 set_meter_point (mp, true);
2556 _meter->set_display_to_user (_meter_point == MeterCustom);
2561 if (node.get_property (X_("disk-io-point"), diop)) {
2563 _disk_writer->set_display_to_user (diop == DiskIOCustom);
2566 _disk_reader->set_display_to_user (diop == DiskIOCustom);
2568 set_disk_io_point (diop);
2571 node.get_property (X_("meter-type"), _meter_type);
2573 _initial_io_setup = false;
2575 set_processor_state (processor_state);
2577 // this looks up the internal instrument in processors
2578 reset_instrument_info();
2580 bool denormal_protection;
2581 if (node.get_property (X_("denormal-protection"), denormal_protection)) {
2582 set_denormal_protection (denormal_protection);
2585 /* convert old 3001 state */
2586 std::string phase_invert_str;
2587 if (node.get_property (X_("phase-invert"), phase_invert_str)) {
2588 _phase_control->set_phase_invert (boost::dynamic_bitset<> (phase_invert_str));
2592 if (node.get_property (X_("active"), is_active)) {
2593 set_active (is_active, this);
2596 std::string id_string;
2597 if (node.get_property (X_("processor-after-last-custom-meter"), id_string)) {
2598 PBD::ID id (id_string);
2599 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2600 ProcessorList::const_iterator i = _processors.begin ();
2601 while (i != _processors.end() && (*i)->id() != id) {
2605 if (i != _processors.end ()) {
2606 _processor_after_last_custom_meter = *i;
2607 _custom_meter_position_noted = true;
2611 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2614 if (child->name() == X_("Comment")) {
2616 /* XXX this is a terrible API design in libxml++ */
2618 XMLNode *cmt = *(child->children().begin());
2619 _comment = cmt->content();
2621 } else if (child->name() == Controllable::xml_node_name) {
2622 std::string control_name;
2623 if (!child->get_property (X_("name"), control_name)) {
2627 if (control_name == _solo_control->name()) {
2628 _solo_control->set_state (*child, version);
2629 } else if (control_name == _solo_safe_control->name()) {
2630 _solo_safe_control->set_state (*child, version);
2631 } else if (control_name == _solo_isolate_control->name()) {
2632 _solo_isolate_control->set_state (*child, version);
2633 } else if (control_name == _mute_control->name()) {
2634 _mute_control->set_state (*child, version);
2635 } else if (control_name == _phase_control->name()) {
2636 _phase_control->set_state (*child, version);
2638 Evoral::Parameter p = EventTypeMap::instance().from_symbol (control_name);
2639 if (p.type () >= MidiCCAutomation && p.type () < MidiSystemExclusiveAutomation) {
2640 boost::shared_ptr<AutomationControl> ac = automation_control (p, true);
2642 ac->set_state (*child, version);
2646 } else if (child->name() == MuteMaster::xml_node_name) {
2647 _mute_master->set_state (*child, version);
2649 } else if (child->name() == Automatable::xml_node_name) {
2650 set_automation_xml_state (*child, Evoral::Parameter(NullAutomation));
2655 _delayline->set_name (name ());
2662 Route::set_state_2X (const XMLNode& node, int version)
2666 XMLNodeConstIterator niter;
2668 XMLProperty const * prop;
2670 /* 2X things which still remain to be handled:
2676 if (node.name() != "Route") {
2677 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2681 Stripable::set_state (node, version);
2683 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2684 set_denormal_protection (string_to<bool> (prop->value()));
2687 if ((prop = node.property (X_("muted"))) != 0) {
2690 bool muted = string_to<bool> (prop->value());
2696 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2698 if (string_to<bool> (prop->value())){
2699 mute_point = mute_point + "PreFader";
2704 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2706 if (string_to<bool> (prop->value())){
2709 mute_point = mute_point + ",";
2712 mute_point = mute_point + "PostFader";
2717 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2719 if (string_to<bool> (prop->value())){
2722 mute_point = mute_point + ",";
2725 mute_point = mute_point + "Listen";
2730 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2732 if (string_to<bool> (prop->value())){
2735 mute_point = mute_point + ",";
2738 mute_point = mute_point + "Main";
2742 _mute_master->set_mute_points (mute_point);
2743 _mute_master->set_muted_by_self (true);
2747 if ((prop = node.property (X_("meter-point"))) != 0) {
2748 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2753 nlist = node.children ();
2754 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2758 if (child->name() == IO::state_node_name) {
2760 /* there is a note in IO::set_state_2X() about why we have to call
2764 _input->set_state_2X (*child, version, true);
2765 _output->set_state_2X (*child, version, false);
2767 if ((prop = child->property (X_("name"))) != 0) {
2768 Route::set_name (prop->value ());
2773 if ((prop = child->property (X_("active"))) != 0) {
2774 bool yn = string_to<bool> (prop->value());
2775 _active = !yn; // force switch
2776 set_active (yn, this);
2779 if ((prop = child->property (X_("gain"))) != 0) {
2782 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
2783 _amp->gain_control()->set_value (val, Controllable::NoGroup);
2787 /* Set up Panners in the IO */
2788 XMLNodeList io_nlist = child->children ();
2790 XMLNodeConstIterator io_niter;
2793 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
2795 io_child = *io_niter;
2797 if (io_child->name() == X_("Panner")) {
2798 _main_outs->panner_shell()->set_state(*io_child, version);
2799 } else if (io_child->name() == X_("Automation")) {
2800 /* IO's automation is for the fader */
2801 _amp->set_automation_xml_state (*io_child, Evoral::Parameter (GainAutomation));
2807 XMLNodeList redirect_nodes;
2809 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2813 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2814 redirect_nodes.push_back(child);
2819 set_processor_state_2X (redirect_nodes, version);
2821 Stateful::save_extra_xml (node);
2823 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2826 if (child->name() == X_("Comment")) {
2828 /* XXX this is a terrible API design in libxml++ */
2830 XMLNode *cmt = *(child->children().begin());
2831 _comment = cmt->content();
2833 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2834 if (prop->value() == X_("solo")) {
2835 _solo_control->set_state (*child, version);
2836 } else if (prop->value() == X_("mute")) {
2837 _mute_control->set_state (*child, version);
2847 Route::get_processor_state ()
2849 XMLNode* root = new XMLNode (X_("redirects"));
2850 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2851 root->add_child_nocopy ((*i)->get_state ());
2858 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2860 /* We don't bother removing existing processors not in nList, as this
2861 method will only be called when creating a Route from scratch, not
2862 for undo purposes. Just put processors in at the appropriate place
2866 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2867 add_processor_from_xml_2X (**i, version);
2872 Route::set_processor_state (const XMLNode& node)
2874 const XMLNodeList &nlist = node.children();
2875 XMLNodeConstIterator niter;
2876 ProcessorList new_order;
2877 bool must_configure = false;
2879 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2881 XMLProperty* prop = (*niter)->property ("type");
2883 if (prop->value() == "amp") {
2884 _amp->set_state (**niter, Stateful::current_state_version);
2885 new_order.push_back (_amp);
2886 } else if (prop->value() == "trim") {
2887 _trim->set_state (**niter, Stateful::current_state_version);
2888 new_order.push_back (_trim);
2889 } else if (prop->value() == "meter") {
2890 _meter->set_state (**niter, Stateful::current_state_version);
2891 new_order.push_back (_meter);
2892 } else if (prop->value() == "polarity") {
2893 _polarity->set_state (**niter, Stateful::current_state_version);
2894 new_order.push_back (_polarity);
2895 } else if (prop->value() == "delay") {
2897 } else if (prop->value() == "main-outs") {
2898 _main_outs->set_state (**niter, Stateful::current_state_version);
2899 } else if (prop->value() == "intreturn") {
2901 _intreturn.reset (new InternalReturn (_session));
2902 must_configure = true;
2904 _intreturn->set_state (**niter, Stateful::current_state_version);
2905 } else if (is_monitor() && prop->value() == "monitor") {
2906 if (!_monitor_control) {
2907 _monitor_control.reset (new MonitorProcessor (_session));
2908 must_configure = true;
2910 _monitor_control->set_state (**niter, Stateful::current_state_version);
2911 } else if (prop->value() == "capture") {
2912 /* CapturingProcessor should never be restored, it's always
2913 added explicitly when needed */
2914 } else if (prop->value() == "diskreader" && _disk_reader) {
2915 _disk_reader->set_state (**niter, Stateful::current_state_version);
2916 new_order.push_back (_disk_reader);
2917 } else if (prop->value() == "diskwriter" && _disk_writer) {
2918 _disk_writer->set_state (**niter, Stateful::current_state_version);
2919 new_order.push_back (_disk_writer);
2921 set_processor_state (**niter, prop, new_order, must_configure);
2925 ProcessorList old_list = _processors; // keep a copy
2927 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2928 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2929 /* re-assign _processors w/o process-lock.
2930 * if there's an IO-processor present in _processors but
2931 * not in new_order, it will be deleted and ~IO takes
2934 _processors = new_order;
2936 if (must_configure) {
2937 configure_processors_unlocked (0, &lm);
2940 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2942 (*i)->set_owner (this);
2943 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
2945 boost::shared_ptr<PluginInsert> pi;
2947 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
2948 if (pi->has_no_inputs ()) {
2949 _have_internal_generator = true;
2955 /* drop references w/o process-lock (I/O procs may re-take it in ~IO() */
2958 reset_instrument_info ();
2959 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2960 set_processor_positions ();
2964 Route::set_processor_state (XMLNode const & node, XMLProperty const* prop, ProcessorList& new_order, bool& must_configure)
2966 ProcessorList::iterator o;
2968 for (o = _processors.begin(); o != _processors.end(); ++o) {
2969 XMLProperty const * id_prop = node.property(X_("id"));
2970 if (id_prop && (*o)->id() == id_prop->value()) {
2971 (*o)->set_state (node, Stateful::current_state_version);
2972 new_order.push_back (*o);
2977 // If the processor (node) is not on the route then create it
2979 if (o == _processors.end()) {
2981 boost::shared_ptr<Processor> processor;
2983 if (prop->value() == "intsend") {
2985 processor.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), boost::shared_ptr<Route>(), Delivery::Aux, true));
2987 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
2988 prop->value() == "lv2" ||
2989 prop->value() == "windows-vst" ||
2990 prop->value() == "mac-vst" ||
2991 prop->value() == "lxvst" ||
2992 prop->value() == "luaproc" ||
2993 prop->value() == "audiounit") {
2995 if (_session.get_disable_all_loaded_plugins ()) {
2996 processor.reset (new UnknownProcessor (_session, node));
2998 processor.reset (new PluginInsert (_session));
2999 processor->set_owner (this);
3001 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
3002 pi->set_strict_io (true);
3006 } else if (prop->value() == "port") {
3008 processor.reset (new PortInsert (_session, _pannable, _mute_master));
3010 } else if (prop->value() == "send") {
3012 processor.reset (new Send (_session, _pannable, _mute_master, Delivery::Send, true));
3013 boost::shared_ptr<Send> send = boost::dynamic_pointer_cast<Send> (processor);
3014 send->SelfDestruct.connect_same_thread (*this,
3015 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (processor)));
3021 if (processor->set_state (node, Stateful::current_state_version) != 0) {
3022 /* This processor could not be configured. Turn it into a UnknownProcessor */
3023 processor.reset (new UnknownProcessor (_session, node));
3026 /* subscribe to Sidechain IO changes */
3027 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
3028 if (pi && pi->has_sidechain ()) {
3029 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
3032 /* we have to note the monitor send here, otherwise a new one will be created
3033 and the state of this one will be lost.
3035 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
3036 if (isend && isend->role() == Delivery::Listen) {
3037 _monitor_send = isend;
3040 /* it doesn't matter if invisible processors are added here, as they
3041 will be sorted out by setup_invisible_processors () shortly.
3044 new_order.push_back (processor);
3045 must_configure = true;
3051 Route::curve_reallocate ()
3053 // _gain_automation_curve.finish_resize ();
3054 // _pan_automation_curve.finish_resize ();
3058 Route::silence (samplecnt_t nframes)
3060 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3065 silence_unlocked (nframes);
3069 Route::silence_unlocked (samplecnt_t nframes)
3071 /* Must be called with the processor lock held */
3073 const samplepos_t now = _session.transport_sample ();
3075 _output->silence (nframes);
3077 // update owned automated controllables
3078 automation_run (now, nframes);
3080 _pannable->automation_run (now, nframes);
3083 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3084 boost::shared_ptr<PluginInsert> pi;
3086 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
3087 /* evaluate automated automation controls */
3088 pi->automation_run (now, nframes);
3089 /* skip plugins, they don't need anything when we're not active */
3093 (*i)->silence (nframes, now);
3098 Route::add_internal_return ()
3101 _intreturn.reset (new InternalReturn (_session));
3102 add_processor (_intreturn, PreFader);
3107 Route::add_send_to_internal_return (InternalSend* send)
3109 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3111 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3112 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3115 return d->add_send (send);
3121 Route::remove_send_from_internal_return (InternalSend* send)
3123 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3125 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3126 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3129 return d->remove_send (send);
3135 Route::enable_monitor_send ()
3137 /* Caller must hold process lock */
3138 assert (!AudioEngine::instance()->process_lock().trylock());
3140 /* master never sends to monitor section via the normal mechanism */
3141 assert (!is_master ());
3142 assert (!is_monitor ());
3144 /* make sure we have one */
3145 if (!_monitor_send) {
3146 _monitor_send.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), _session.monitor_out(), Delivery::Listen));
3147 _monitor_send->set_display_to_user (false);
3151 configure_processors (0);
3154 /** Add an aux send to a route.
3155 * @param route route to send to.
3156 * @param before Processor to insert before, or 0 to insert at the end.
3159 Route::add_aux_send (boost::shared_ptr<Route> route, boost::shared_ptr<Processor> before)
3161 assert (route != _session.monitor_out ());
3164 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3166 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3168 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend> (*x);
3170 if (d && d->target_route() == route) {
3171 /* already listening via the specified IO: do nothing */
3179 boost::shared_ptr<InternalSend> listener;
3182 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
3183 listener.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), route, Delivery::Aux));
3186 add_processor (listener, before);
3188 } catch (failed_constructor& err) {
3196 Route::add_personal_send (boost::shared_ptr<Route> route)
3198 assert (route != _session.monitor_out ());
3199 boost::shared_ptr<Processor> before = before_processor_for_placement (PreFader);
3202 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3204 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3206 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend> (*x);
3208 if (d && d->target_route() == route) {
3209 /* already listening via the specified IO: do nothing */
3217 boost::shared_ptr<InternalSend> listener;
3220 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
3221 listener.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), route, Delivery::Personal));
3224 add_processor (listener, before);
3226 } catch (failed_constructor& err) {
3234 Route::remove_aux_or_listen (boost::shared_ptr<Route> route)
3236 ProcessorStreams err;
3237 ProcessorList::iterator tmp;
3240 Glib::Threads::RWLock::ReaderLock rl(_processor_lock);
3242 /* have to do this early because otherwise processor reconfig
3243 * will put _monitor_send back in the list
3246 if (route == _session.monitor_out()) {
3247 _monitor_send.reset ();
3251 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3253 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
3255 if (d && d->target_route() == route) {
3257 if (remove_processor (*x, &err, false) > 0) {
3263 /* list could have been demolished while we dropped the lock
3266 if (_session.engine().connected()) {
3267 /* i/o processors cannot be removed if the engine is not running
3268 * so don't live-loop in case the engine is N/A or dies
3278 Route::set_comment (string cmt, void *src)
3282 _session.set_dirty ();
3286 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
3288 FeedRecord fr (other, via_sends_only);
3290 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
3292 if (!result.second) {
3294 /* already a record for "other" - make sure sends-only information is correct */
3295 if (!via_sends_only && result.first->sends_only) {
3296 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
3297 frp->sends_only = false;
3301 return result.second;
3305 Route::clear_fed_by ()
3311 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
3313 const FedBy& fed_by (other->fed_by());
3315 for (FedBy::const_iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
3316 boost::shared_ptr<Route> sr = f->r.lock();
3318 if (sr && (sr.get() == this)) {
3320 if (via_sends_only) {
3321 *via_sends_only = f->sends_only;
3332 Route::all_inputs () const
3334 /* TODO, if this works as expected,
3335 * cache the IOVector and maintain it via
3336 * input_change_handler(), sidechain_change_handler() etc
3339 ios.push_back (_input);
3341 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3342 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3344 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3345 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3348 iop = pi->sidechain();
3351 if (iop != 0 && iop->input()) {
3352 ios.push_back (iop->input());
3359 Route::all_outputs () const
3362 // _output is included via Delivery
3363 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3364 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3365 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3366 if (iop != 0 && iop->output()) {
3367 ios.push_back (iop->output());
3374 Route::direct_feeds_according_to_reality (boost::shared_ptr<Route> other, bool* via_send_only)
3376 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
3377 if (other->all_inputs().fed_by (_output)) {
3378 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
3379 if (via_send_only) {
3380 *via_send_only = false;
3386 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3388 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
3390 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3391 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3394 iop = pi->sidechain();
3398 boost::shared_ptr<const IO> iop_out = iop->output();
3399 if (other.get() == this && iop_out && iop->input() && iop_out->connected_to (iop->input())) {
3400 // TODO this needs a delaylines in the Insert to align connections (!)
3401 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed its own return (%2)\n", iop->name(), other->name()));
3404 if ((iop_out && other->all_inputs().fed_by (iop_out)) || iop->feeds (other)) {
3405 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
3406 if (via_send_only) {
3407 *via_send_only = true;
3411 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
3414 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
3419 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
3424 Route::direct_feeds_according_to_graph (boost::shared_ptr<Route> other, bool* via_send_only)
3426 return _session._current_route_graph.has (boost::dynamic_pointer_cast<Route> (shared_from_this ()), other, via_send_only);
3430 Route::feeds_according_to_graph (boost::shared_ptr<Route> other)
3432 return _session._current_route_graph.feeds (boost::dynamic_pointer_cast<Route> (shared_from_this ()), other);
3435 /** Called from the (non-realtime) butler thread when the transport is stopped */
3437 Route::non_realtime_transport_stop (samplepos_t now, bool flush)
3439 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3441 Automatable::non_realtime_transport_stop (now, flush);
3443 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3445 if (!_have_internal_generator && (Config->get_plugins_stop_with_transport() && flush)) {
3449 (*i)->non_realtime_transport_stop (now, flush);
3454 Route::realtime_handle_transport_stopped ()
3456 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3458 /* currently only by Plugin, queue note-off events */
3459 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3460 (*i)->realtime_handle_transport_stopped ();
3466 Route::input_change_handler (IOChange change, void * /*src*/)
3468 if ((change.type & IOChange::ConfigurationChanged)) {
3469 /* This is called with the process lock held if change
3470 contains ConfigurationChanged
3472 configure_processors (0);
3473 io_changed (); /* EMIT SIGNAL */
3476 if (_solo_control->soloed_by_others_upstream() || _solo_isolate_control->solo_isolated_by_upstream()) {
3479 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3480 if (_input->connected()) {
3481 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3482 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3486 bool does_feed = (*i)->direct_feeds_according_to_reality (boost::dynamic_pointer_cast<Route> (shared_from_this()), &sends_only);
3487 if (does_feed && !sends_only) {
3488 if ((*i)->soloed()) {
3491 if ((*i)->solo_isolate_control()->solo_isolated()) {
3498 int delta = sbou - _solo_control->soloed_by_others_upstream();
3499 int idelta = ibou - _solo_isolate_control->solo_isolated_by_upstream();
3502 PBD::warning << string_compose (
3503 _("Invalid Solo-Isolate propagation: from:%1 new:%2 - old:%3 = delta:%4"),
3504 _name, ibou, _solo_isolate_control->solo_isolated_by_upstream(), idelta)
3509 if (_solo_control->soloed_by_others_upstream()) {
3510 // ignore new connections (they're not propagated)
3512 _solo_control->mod_solo_by_others_upstream (delta);
3516 if (_solo_isolate_control->solo_isolated_by_upstream()) {
3517 // solo-isolate currently only propagates downstream
3519 _solo_isolate_control->mod_solo_isolated_by_upstream (1);
3521 //_solo_isolated_by_upstream = ibou;
3524 // Session::route_solo_changed does not propagate indirect solo-changes
3525 // propagate downstream to tracks
3526 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3527 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3531 bool does_feed = feeds (*i, &sends_only);
3532 if (delta <= 0 && does_feed && !sends_only) {
3533 (*i)->solo_control()->mod_solo_by_others_upstream (delta);
3536 if (idelta < 0 && does_feed && !sends_only) {
3537 (*i)->solo_isolate_control()->mod_solo_isolated_by_upstream (-1);
3544 Route::output_change_handler (IOChange change, void * /*src*/)
3546 if (_initial_io_setup) {
3550 if ((change.type & IOChange::ConfigurationChanged)) {
3551 /* This is called with the process lock held if change
3552 contains ConfigurationChanged
3554 configure_processors (0);
3557 _session.reset_monitor_section();
3560 io_changed (); /* EMIT SIGNAL */
3563 if ((change.type & IOChange::ConnectionsChanged)) {
3565 /* do this ONLY if connections have changed. Configuration
3566 * changes do not, by themselves alter solo upstream or
3567 * downstream status.
3570 if (_solo_control->soloed_by_others_downstream()) {
3572 /* checking all all downstream routes for
3573 * explicit of implict solo is a rather drastic measure,
3574 * ideally the input_change_handler() of the other route
3575 * would propagate the change to us.
3577 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3578 if (_output->connected()) {
3579 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3580 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3584 bool does_feed = direct_feeds_according_to_reality (*i, &sends_only);
3585 if (does_feed && !sends_only) {
3586 if ((*i)->soloed()) {
3594 int delta = sbod - _solo_control->soloed_by_others_downstream();
3596 // do not allow new connections to change implicit solo (no propagation)
3597 _solo_control->mod_solo_by_others_downstream (delta);
3598 // Session::route_solo_changed() does not propagate indirect solo-changes
3599 // propagate upstream to tracks
3600 boost::shared_ptr<Route> shared_this = boost::dynamic_pointer_cast<Route> (shared_from_this());
3601 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3602 if ((*i).get() == this || !can_solo()) {
3606 bool does_feed = (*i)->feeds (shared_this, &sends_only);
3607 if (delta != 0 && does_feed && !sends_only) {
3608 (*i)->solo_control()->mod_solo_by_others_downstream (delta);
3618 Route::sidechain_change_handler (IOChange change, void* src)
3620 if (_initial_io_setup || _in_sidechain_setup) {
3624 input_change_handler (change, src);
3628 Route::pans_required () const
3630 if (n_outputs().n_audio() < 2) {
3634 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
3638 Route::flush_processor_buffers_locked (samplecnt_t nframes)
3640 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3641 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery> (*i);
3643 d->flush_buffers (nframes);
3645 boost::shared_ptr<PortInsert> p = boost::dynamic_pointer_cast<PortInsert> (*i);
3647 p->flush_buffers (nframes);
3654 Route::flush_processors ()
3656 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3658 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3664 Route::playback_latency (bool incl_downstream) const
3668 rv = _disk_reader->output_latency ();
3670 rv = _signal_latency;
3672 if (incl_downstream) {
3673 rv += _output->connected_latency (true);
3675 rv += _output->latency ();
3681 Route::latency_preroll (pframes_t nframes, samplepos_t& start_sample, samplepos_t& end_sample)
3683 samplecnt_t latency_preroll = _session.remaining_latency_preroll ();
3684 if (latency_preroll == 0) {
3687 if (!_disk_reader) {
3688 start_sample -= latency_preroll;
3689 end_sample -= latency_preroll;
3693 if (latency_preroll > playback_latency ()) {
3694 no_roll_unlocked (nframes, start_sample - latency_preroll, end_sample - latency_preroll, false);
3698 start_sample -= latency_preroll;
3699 end_sample -= latency_preroll;
3704 Route::roll (pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, bool& need_butler)
3706 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3713 silence_unlocked (nframes);
3718 if ((nframes = latency_preroll (nframes, start_sample, end_sample)) == 0) {
3722 run_route (start_sample, end_sample, nframes, (!_disk_writer || !_disk_writer->record_enabled()) && _session.transport_rolling(), true);
3724 if ((_disk_reader && _disk_reader->need_butler()) || (_disk_writer && _disk_writer->need_butler())) {
3731 Route::no_roll (pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, bool session_state_changing)
3733 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3739 return no_roll_unlocked (nframes, start_sample, end_sample, session_state_changing);
3743 Route::no_roll_unlocked (pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, bool session_state_changing)
3745 /* Must be called with the processor lock held */
3748 silence_unlocked (nframes);
3753 if (session_state_changing) {
3754 if (_session.transport_speed() != 0.0f) {
3755 /* we're rolling but some state is changing (e.g. our diskstream contents)
3756 so we cannot use them. Be silent till this is over.
3758 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
3760 silence_unlocked (nframes);
3764 /* we're really not rolling, so we're either delivery silence or actually
3765 monitoring, both of which are safe to do while session_state_changing is true.
3769 run_route (start_sample, end_sample, nframes, false, false);
3774 Route::silent_roll (pframes_t nframes, samplepos_t /*start_sample*/, samplepos_t /*end_sample*/, bool& /* need_butler */)
3777 flush_processor_buffers_locked (nframes);
3782 __attribute__((annotate("realtime")))
3785 Route::apply_processor_changes_rt ()
3787 int emissions = EmitNone;
3789 if (_pending_meter_point != _meter_point) {
3790 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3792 /* meters always have buffers for 'processor_max_streams'
3793 * they can be re-positioned without re-allocation */
3794 if (set_meter_point_unlocked()) {
3795 emissions |= EmitMeterChanged | EmitMeterVisibilityChange;;
3797 emissions |= EmitMeterChanged;
3802 bool changed = false;
3804 if (g_atomic_int_get (&_pending_process_reorder)) {
3805 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3807 apply_processor_order (_pending_processor_order);
3808 setup_invisible_processors ();
3810 g_atomic_int_set (&_pending_process_reorder, 0);
3811 emissions |= EmitRtProcessorChange;
3815 set_processor_positions ();
3816 /* update processor input/output latency
3817 * (total signal_latency does not change)
3819 update_signal_latency (true);
3821 if (emissions != 0) {
3822 g_atomic_int_set (&_pending_signals, emissions);
3825 return (!selfdestruct_sequence.empty ());
3829 Route::emit_pending_signals ()
3831 int sig = g_atomic_int_and (&_pending_signals, 0);
3832 if (sig & EmitMeterChanged) {
3833 _meter->emit_configuration_changed();
3834 meter_change (); /* EMIT SIGNAL */
3835 if (sig & EmitMeterVisibilityChange) {
3836 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3838 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3841 if (sig & EmitRtProcessorChange) {
3842 processors_changed (RouteProcessorChange (RouteProcessorChange::RealTimeChange)); /* EMIT SIGNAL */
3845 /* this would be a job for the butler.
3846 * Conceptually we should not take processe/processor locks here.
3847 * OTOH its more efficient (less overhead for summoning the butler and
3848 * telling her what do do) and signal emission is called
3849 * directly after the process callback, which decreases the chance
3850 * of x-runs when taking the locks.
3852 while (!selfdestruct_sequence.empty ()) {
3853 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
3854 if (selfdestruct_sequence.empty ()) { break; } // re-check with lock
3855 boost::shared_ptr<Processor> proc = selfdestruct_sequence.back ().lock ();
3856 selfdestruct_sequence.pop_back ();
3859 remove_processor (proc);
3865 Route::set_meter_point (MeterPoint p, bool force)
3867 if (_pending_meter_point == p && !force) {
3871 if (force || !AudioEngine::instance()->running()) {
3872 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3873 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3874 _pending_meter_point = p;
3875 _meter->emit_configuration_changed();
3876 meter_change (); /* EMIT SIGNAL */
3877 if (set_meter_point_unlocked()) {
3878 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3880 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3883 _pending_meter_point = p;
3889 __attribute__((annotate("realtime")))
3892 Route::set_meter_point_unlocked ()
3895 /* Caller must hold process and processor write lock */
3896 assert (!AudioEngine::instance()->process_lock().trylock());
3897 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3898 assert (!lm.locked ());
3901 _meter_point = _pending_meter_point;
3903 bool meter_was_visible_to_user = _meter->display_to_user ();
3905 if (!_custom_meter_position_noted) {
3906 maybe_note_meter_position ();
3909 if (_meter_point != MeterCustom) {
3911 _meter->set_display_to_user (false);
3913 setup_invisible_processors ();
3916 _meter->set_display_to_user (true);
3918 /* If we have a previous position for the custom meter, try to put it there */
3919 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
3921 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), after);
3922 if (i != _processors.end ()) {
3923 _processors.remove (_meter);
3924 _processors.insert (i, _meter);
3926 } else {// at end, right before the mains_out/panner
3927 _processors.remove (_meter);
3928 ProcessorList::iterator main = _processors.end();
3929 _processors.insert (--main, _meter);
3933 /* Set up the meter for its new position */
3935 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
3939 if (loc == _processors.begin()) {
3940 m_in = _input->n_ports();
3942 ProcessorList::iterator before = loc;
3944 m_in = (*before)->output_streams ();
3947 _meter->reflect_inputs (m_in);
3949 /* we do not need to reconfigure the processors, because the meter
3950 (a) is always ready to handle processor_max_streams
3951 (b) is always an N-in/N-out processor, and thus moving
3952 it doesn't require any changes to the other processors.
3955 /* these should really be done after releasing the lock
3956 * but all those signals are subscribed to with gui_thread()
3959 return (_meter->display_to_user() != meter_was_visible_to_user);
3963 Route::listen_position_changed ()
3966 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3967 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3968 ProcessorState pstate (this);
3970 if (configure_processors_unlocked (0, &lm)) {
3971 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
3973 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
3978 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3979 _session.set_dirty ();
3982 boost::shared_ptr<CapturingProcessor>
3983 Route::add_export_point()
3985 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3986 if (!_capturing_processor) {
3988 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3989 Glib::Threads::RWLock::WriterLock lw (_processor_lock);
3991 /* Align all tracks for stem-export w/o processing.
3992 * Compensate for all plugins between the this route's disk-reader
3993 * and the common final downstream output (ie alignment point for playback).
3995 _capturing_processor.reset (new CapturingProcessor (_session, playback_latency (true)));
3996 configure_processors_unlocked (0, &lw);
3997 _capturing_processor->activate ();
4000 return _capturing_processor;
4004 Route::update_signal_latency (bool apply_to_delayline)
4006 // TODO: bail out if !active() and set/assume _signal_latency = 0,
4007 // here or in Session::* ? -> also zero send latencies,
4008 // and make sure that re-enabling a route updates things again...
4010 samplecnt_t capt_lat_in = _input->connected_latency (false);
4011 samplecnt_t play_lat_out = _output->connected_latency (true);
4013 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4015 samplecnt_t l_in = 0;
4016 samplecnt_t l_out = _output->user_latency();
4017 for (ProcessorList::reverse_iterator i = _processors.rbegin(); i != _processors.rend(); ++i) {
4018 if (boost::shared_ptr<Send> snd = boost::dynamic_pointer_cast<Send> (*i)) {
4019 snd->set_delay_in (l_out + _output->latency());
4022 if (boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) {
4023 if (boost::shared_ptr<IO> pio = pi->sidechain_input ()) {
4024 samplecnt_t lat = l_out + _output->latency();
4025 pio->set_private_port_latencies (lat, true);
4026 pio->set_public_port_latencies (lat, true);
4029 (*i)->set_output_latency (l_out);
4030 if ((*i)->active ()) {
4031 l_out += (*i)->signal_latency ();
4035 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal signal latency = %2\n", _name, l_out));
4037 _signal_latency = l_out;
4039 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4041 /* set sidechain, send and insert port latencies */
4042 if (boost::shared_ptr<PortInsert> pi = boost::dynamic_pointer_cast<PortInsert> (*i)) {
4044 /* propagate playback latency from output to input */
4045 pi->input ()->set_private_port_latencies (play_lat_out + l_in, true);
4047 if (pi->output ()) {
4048 /* propagate capture latency from input to output */
4049 pi->output ()->set_private_port_latencies (capt_lat_in + l_in, false);
4052 } else if (boost::shared_ptr<Send> snd = boost::dynamic_pointer_cast<Send> (*i)) {
4053 if (snd->output ()) {
4054 /* set capture latency */
4055 snd->output ()->set_private_port_latencies (capt_lat_in + l_in, false);
4056 /* take send-target's playback latency into account */
4057 snd->set_delay_out (snd->output ()->connected_latency (true));
4061 (*i)->set_input_latency (l_in);
4062 (*i)->set_playback_offset (_signal_latency + _output->latency ());
4063 (*i)->set_capture_offset (_input->latency ());
4064 if ((*i)->active ()) {
4065 l_in += (*i)->signal_latency ();
4071 if (apply_to_delayline) {
4072 /* see also Session::post_playback_latency() */
4073 apply_latency_compensation ();
4076 if (_signal_latency != l_out) {
4077 signal_latency_changed (); /* EMIT SIGNAL */
4080 return _signal_latency;
4084 Route::set_user_latency (samplecnt_t nframes)
4086 _output->set_user_latency (nframes);
4087 _session.update_latency_compensation ();
4091 Route::apply_latency_compensation ()
4094 samplecnt_t old = _delayline->delay ();
4096 samplecnt_t play_lat_in = _input->connected_latency (true);
4097 samplecnt_t play_lat_out = _output->connected_latency (true);
4098 samplecnt_t latcomp = play_lat_in - play_lat_out - _signal_latency;
4101 samplecnt_t capt_lat_in = _input->connected_latency (false);
4102 samplecnt_t capt_lat_out = _output->connected_latency (false);
4103 samplecnt_t latcomp_capt = capt_lat_out - capt_lat_in - _signal_latency;
4105 cout << "ROUTE " << name() << " delay for " << latcomp << " (c: " << latcomp_capt << ")" << endl;
4108 _delayline->set_delay (latcomp > 0 ? latcomp : 0);
4110 if (old != _delayline->delay ()) {
4111 signal_latency_updated (); /* EMIT SIGNAL */
4117 Route::set_block_size (pframes_t nframes)
4119 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4120 (*i)->set_block_size (nframes);
4123 _session.ensure_buffers (n_process_buffers ());
4127 Route::protect_automation ()
4129 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
4130 (*i)->protect_automation();
4133 /** Shift automation forwards from a particular place, thereby inserting time.
4134 * Adds undo commands for any shifts that are performed.
4136 * @param pos Position to start shifting from.
4137 * @param samples Amount to shift forwards by.
4141 Route::shift (samplepos_t pos, samplecnt_t samples)
4143 /* gain automation */
4145 boost::shared_ptr<AutomationControl> gc = _amp->gain_control();
4147 XMLNode &before = gc->alist()->get_state ();
4148 gc->alist()->shift (pos, samples);
4149 XMLNode &after = gc->alist()->get_state ();
4150 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
4153 /* gain automation */
4155 boost::shared_ptr<AutomationControl> gc = _trim->gain_control();
4157 XMLNode &before = gc->alist()->get_state ();
4158 gc->alist()->shift (pos, samples);
4159 XMLNode &after = gc->alist()->get_state ();
4160 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
4163 // TODO mute automation ??
4165 /* pan automation */
4167 ControlSet::Controls& c (_pannable->controls());
4169 for (ControlSet::Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
4170 boost::shared_ptr<AutomationControl> pc = boost::dynamic_pointer_cast<AutomationControl> (ci->second);
4172 boost::shared_ptr<AutomationList> al = pc->alist();
4173 XMLNode& before = al->get_state ();
4174 al->shift (pos, samples);
4175 XMLNode& after = al->get_state ();
4176 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4181 /* redirect automation */
4183 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4184 for (ProcessorList::iterator i = _processors.begin (); i != _processors.end (); ++i) {
4186 set<Evoral::Parameter> parameters = (*i)->what_can_be_automated();
4188 for (set<Evoral::Parameter>::const_iterator p = parameters.begin (); p != parameters.end (); ++p) {
4189 boost::shared_ptr<AutomationControl> ac = (*i)->automation_control (*p);
4191 boost::shared_ptr<AutomationList> al = ac->alist();
4192 XMLNode &before = al->get_state ();
4193 al->shift (pos, samples);
4194 XMLNode &after = al->get_state ();
4195 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4203 Route::set_plugin_state_dir (boost::weak_ptr<Processor> p, const std::string& d)
4205 boost::shared_ptr<Processor> processor (p.lock ());
4206 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
4210 pi->set_state_dir (d);
4214 Route::save_as_template (const string& path, const string& name, const string& description)
4216 std::string state_dir = path.substr (0, path.find_last_of ('.')); // strip template_suffix
4217 PBD::Unwinder<std::string> uw (_session._template_state_dir, state_dir);
4219 XMLNode& node (state (false));
4220 node.set_property (X_("name"), name);
4222 node.remove_nodes (X_("description"));
4223 if (!description.empty()) {
4224 XMLNode* desc = new XMLNode(X_("description"));
4225 XMLNode* desc_cont = new XMLNode(X_("content"), description);
4226 desc->add_child_nocopy (*desc_cont);
4228 node.add_child_nocopy (*desc);
4233 IO::set_name_in_state (*node.children().front(), name);
4235 tree.set_root (&node);
4237 /* return zero on success, non-zero otherwise */
4238 return !tree.write (path.c_str());
4243 Route::set_name (const string& str)
4249 if (str == name()) {
4253 string newname = Route::ensure_track_or_route_name (str);
4255 if (newname == name()) {
4259 SessionObject::set_name (newname);
4261 bool ret = (_input->set_name(newname) && _output->set_name(newname));
4264 /* rename the main outs. Leave other IO processors
4265 * with whatever name they already have, because its
4266 * just fine as it is (it will not contain the route
4267 * name if its a port insert, port send or port return).
4271 if (_main_outs->set_name (newname)) {
4272 /* XXX returning false here is stupid because
4273 we already changed the route name.
4283 /** Set the name of a route in an XML description.
4284 * @param node XML <Route> node to set the name in.
4285 * @param name New name.
4288 Route::set_name_in_state (XMLNode& node, string const & name, bool rename_playlist)
4290 node.set_property (X_("name"), name);
4292 XMLNodeList children = node.children();
4293 for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
4295 if ((*i)->name() == X_("IO")) {
4297 IO::set_name_in_state (**i, name);
4299 } else if ((*i)->name() == X_("Processor")) {
4302 if ((*i)->get_property (X_("role"), str) && str == X_("Main")) {
4303 (*i)->set_property (X_("name"), name);
4306 } else if ((*i)->name() == X_("Diskstream")) {
4308 if (rename_playlist) {
4309 (*i)->set_property (X_("playlist"), name + ".1");
4311 (*i)->set_property (X_("name"), name);
4317 boost::shared_ptr<Send>
4318 Route::internal_send_for (boost::shared_ptr<const Route> target) const
4320 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4322 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4323 boost::shared_ptr<InternalSend> send;
4325 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
4326 if (send->target_route() == target) {
4332 return boost::shared_ptr<Send>();
4336 Route::set_denormal_protection (bool yn)
4338 if (_denormal_protection != yn) {
4339 _denormal_protection = yn;
4340 denormal_protection_changed (); /* EMIT SIGNAL */
4345 Route::denormal_protection () const
4347 return _denormal_protection;
4351 Route::set_active (bool yn, void* src)
4353 if (_session.transport_rolling()) {
4357 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_route_active()) {
4358 _route_group->foreach_route (boost::bind (&Route::set_active, _1, yn, _route_group));
4362 if (_active != yn) {
4364 _input->set_active (yn);
4365 _output->set_active (yn);
4366 flush_processors ();
4367 active_changed (); // EMIT SIGNAL
4368 _session.set_dirty ();
4372 boost::shared_ptr<Pannable>
4373 Route::pannable() const
4378 boost::shared_ptr<Panner>
4379 Route::panner() const
4382 return _main_outs->panner_shell()->panner();
4385 boost::shared_ptr<PannerShell>
4386 Route::panner_shell() const
4388 return _main_outs->panner_shell();
4391 boost::shared_ptr<GainControl>
4392 Route::gain_control() const
4394 return _gain_control;
4397 boost::shared_ptr<GainControl>
4398 Route::trim_control() const
4400 return _trim_control;
4403 boost::shared_ptr<PhaseControl>
4404 Route::phase_control() const
4406 return _phase_control;
4409 boost::shared_ptr<AutomationControl>
4410 Route::get_control (const Evoral::Parameter& param)
4412 /* either we own the control or .... */
4414 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
4418 /* maybe one of our processors does or ... */
4420 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
4421 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4422 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
4430 /* nobody does so we'll make a new one */
4432 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
4439 boost::shared_ptr<Processor>
4440 Route::nth_plugin (uint32_t n) const
4442 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4443 ProcessorList::const_iterator i;
4445 for (i = _processors.begin(); i != _processors.end(); ++i) {
4446 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
4453 return boost::shared_ptr<Processor> ();
4456 boost::shared_ptr<Processor>
4457 Route::nth_send (uint32_t n) const
4459 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4460 ProcessorList::const_iterator i;
4462 for (i = _processors.begin(); i != _processors.end(); ++i) {
4463 if (boost::dynamic_pointer_cast<Send> (*i)) {
4465 if ((*i)->name().find (_("Monitor")) == 0) {
4466 /* send to monitor section is not considered
4467 to be an accessible send.
4478 return boost::shared_ptr<Processor> ();
4482 Route::has_io_processor_named (const string& name)
4484 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4485 ProcessorList::iterator i;
4487 for (i = _processors.begin(); i != _processors.end(); ++i) {
4488 if (boost::dynamic_pointer_cast<Send> (*i) ||
4489 boost::dynamic_pointer_cast<PortInsert> (*i)) {
4490 if ((*i)->name() == name) {
4500 Route::set_processor_positions ()
4502 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4504 bool had_amp = false;
4505 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4506 (*i)->set_pre_fader (!had_amp);
4513 /** Called when there is a proposed change to the input port count */
4515 Route::input_port_count_changing (ChanCount to)
4517 list<pair<ChanCount, ChanCount> > c = try_configure_processors (to, 0);
4519 /* The processors cannot be configured with the new input arrangement, so
4525 /* The change is ok */
4529 /** Called when there is a proposed change to the output port count */
4531 Route::output_port_count_changing (ChanCount to)
4533 if (_strict_io && !_in_configure_processors) {
4536 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
4537 if (processor_out_streams.get(*t) > to.get(*t)) {
4541 /* The change is ok */
4546 Route::unknown_processors () const
4550 if (_session.get_disable_all_loaded_plugins ()) {
4551 // Do not list "missing plugins" if they are explicitly disabled
4555 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4556 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4557 if (boost::dynamic_pointer_cast<UnknownProcessor const> (*i)) {
4558 p.push_back ((*i)->name ());
4567 Route::update_port_latencies (PortSet& from, PortSet& to, bool playback, samplecnt_t our_latency) const
4569 /* we assume that all our input ports feed all our output ports. its not
4570 universally true, but the alternative is way too corner-case to worry about.
4573 LatencyRange all_connections;
4576 all_connections.min = 0;
4577 all_connections.max = 0;
4579 all_connections.min = ~((pframes_t) 0);
4580 all_connections.max = 0;
4582 /* iterate over all "from" ports and determine the latency range for all of their
4583 connections to the "outside" (outside of this Route).
4586 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4590 p->get_connected_latency_range (range, playback);
4592 all_connections.min = min (all_connections.min, range.min);
4593 all_connections.max = max (all_connections.max, range.max);
4597 /* set the "from" port latencies to the max/min range of all their connections */
4599 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4600 p->set_private_latency_range (all_connections, playback);
4603 /* set the ports "in the direction of the flow" to the same value as above plus our own signal latency */
4605 all_connections.min += our_latency;
4606 all_connections.max += our_latency;
4608 for (PortSet::iterator p = to.begin(); p != to.end(); ++p) {
4609 p->set_private_latency_range (all_connections, playback);
4612 return all_connections.max;
4616 Route::set_private_port_latencies (bool playback) const
4618 samplecnt_t own_latency = 0;
4620 /* Processor list not protected by lock: MUST BE CALLED FROM PROCESS THREAD
4621 OR LATENCY CALLBACK.
4623 This is called (early) from the latency callback. It computes the REAL
4624 latency associated with each port and stores the result as the "private"
4625 latency of the port. A later call to Route::set_public_port_latencies()
4626 sets all ports to the same value to reflect the fact that we do latency
4627 compensation and so all signals are delayed by the same amount as they
4628 flow through ardour.
4631 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4633 if ((*i)->active ()) {
4634 own_latency += (*i)->signal_latency ();
4639 /* playback: propagate latency from "outside the route" to outputs to inputs */
4640 return update_port_latencies (_output->ports (), _input->ports (), true, own_latency);
4642 /* capture: propagate latency from "outside the route" to inputs to outputs */
4643 return update_port_latencies (_input->ports (), _output->ports (), false, own_latency);
4648 Route::set_public_port_latencies (samplecnt_t value, bool playback) const
4650 /* publish private latencies */
4651 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4652 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4653 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*i);
4657 if (iop->input ()) {
4658 iop->input ()->set_public_port_latencies (iop->input()->latency(), true);
4660 if (iop->output ()) {
4661 iop->output ()->set_public_port_latencies (iop->output()->latency(), false);
4665 /* this is called to set the JACK-visible port latencies, which take
4666 * latency compensation into account.
4668 _input->set_public_port_latencies (value, playback);
4669 _output->set_public_port_latencies (value, playback);
4672 /** Put the invisible processors in the right place in _processors.
4673 * Must be called with a writer lock on _processor_lock held.
4676 __attribute__((annotate("realtime")))
4679 Route::setup_invisible_processors ()
4682 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4683 assert (!lm.locked ());
4687 /* too early to be doing this stuff */
4691 /* we'll build this new list here and then use it
4693 * TODO put the ProcessorList is on the stack for RT-safety.
4696 ProcessorList new_processors;
4697 ProcessorList personal_sends;
4698 ProcessorList::iterator dr;
4699 ProcessorList::iterator dw;
4701 /* find visible processors */
4703 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4704 boost::shared_ptr<Send> auxsnd = boost::dynamic_pointer_cast<Send> ((*i));
4705 if ((*i)->display_to_user ()) {
4706 new_processors.push_back (*i);
4708 else if (auxsnd && auxsnd->is_personal ()) {
4709 personal_sends.push_back (*i);
4715 ProcessorList::iterator amp = find (new_processors.begin(), new_processors.end(), _amp);
4717 if (amp == new_processors.end ()) {
4718 error << string_compose (_("Amp/Fader on Route '%1' went AWOL. Re-added."), name()) << endmsg;
4719 new_processors.push_front (_amp);
4720 amp = find (new_processors.begin(), new_processors.end(), _amp);
4723 /* and the processor after the amp */
4725 ProcessorList::iterator after_amp = amp;
4728 /* Pre-fader METER */
4730 if (_meter && _meter_point == MeterPreFader) {
4731 /* add meter just before the fader */
4732 assert (!_meter->display_to_user ());
4733 new_processors.insert (amp, _meter);
4738 assert (_main_outs);
4739 assert (!_main_outs->display_to_user ());
4740 new_processors.push_back (_main_outs);
4742 /* iterator for the main outs */
4744 ProcessorList::iterator main = new_processors.end();
4747 /* OUTPUT METERING */
4749 if (_meter && (_meter_point == MeterOutput || _meter_point == MeterPostFader)) {
4750 assert (!_meter->display_to_user ());
4752 /* add the processor just before or just after the main outs */
4754 ProcessorList::iterator meter_point = main;
4756 if (_meter_point == MeterOutput) {
4759 new_processors.insert (meter_point, _meter);
4762 /* Personal Sends */
4764 for (ProcessorList::iterator i = personal_sends.begin(); i != personal_sends.end(); ++i) {
4765 new_processors.insert (amp, (*i));
4770 if (_monitor_send && !is_monitor ()) {
4771 assert (!_monitor_send->display_to_user ());
4772 switch (Config->get_listen_position ()) {
4773 case PreFaderListen:
4774 switch (Config->get_pfl_position ()) {
4775 case PFLFromBeforeProcessors:
4776 new_processors.push_front (_monitor_send);
4778 case PFLFromAfterProcessors:
4779 new_processors.insert (amp, _monitor_send);
4782 _monitor_send->set_can_pan (false);
4784 case AfterFaderListen:
4785 switch (Config->get_afl_position ()) {
4786 case AFLFromBeforeProcessors:
4787 new_processors.insert (after_amp, _monitor_send);
4789 case AFLFromAfterProcessors:
4790 new_processors.insert (new_processors.end(), _monitor_send);
4793 _monitor_send->set_can_pan (true);
4798 /* MONITOR CONTROL */
4800 if (_monitor_control && is_monitor ()) {
4801 assert (!_monitor_control->display_to_user ());
4802 new_processors.insert (amp, _monitor_control);
4807 ProcessorList::iterator trim = new_processors.end();
4809 if (_trim->active()) {
4810 assert (!_trim->display_to_user ());
4811 new_processors.push_front (_trim);
4812 trim = new_processors.begin();
4815 /* INTERNAL RETURN */
4817 /* doing this here means that any monitor control will come after
4818 the return and trim.
4822 assert (!_intreturn->display_to_user ());
4823 new_processors.push_front (_intreturn);
4826 /* DISK READER & WRITER (for Track objects) */
4828 if (_disk_reader || _disk_writer) {
4829 switch (_disk_io_point) {
4830 case DiskIOPreFader:
4831 if (trim != new_processors.end()) {
4832 /* insert BEFORE TRIM */
4834 new_processors.insert (trim, _disk_writer);
4837 new_processors.insert (trim, _disk_reader);
4841 new_processors.push_front (_disk_writer);
4844 new_processors.push_front (_disk_reader);
4848 case DiskIOPostFader:
4849 /* insert BEFORE main outs */
4851 new_processors.insert (main, _disk_writer);
4854 new_processors.insert (main, _disk_reader);
4858 /* reader and writer are visible under this condition, so they
4859 * are not invisible and thus not handled here.
4865 /* ensure dist-writer is before disk-reader */
4866 if (_disk_reader && _disk_writer) {
4867 ProcessorList::iterator reader_pos = find (new_processors.begin(), new_processors.end(), _disk_reader);
4868 ProcessorList::iterator writer_pos = find (new_processors.begin(), new_processors.end(), _disk_writer);
4869 assert (reader_pos != new_processors.end ());
4870 assert (writer_pos != new_processors.end ());
4871 if (std::distance (new_processors.begin(), reader_pos) < std::distance (new_processors.begin(), writer_pos)) {
4872 new_processors.erase (reader_pos);
4873 assert (writer_pos == find (new_processors.begin(), new_processors.end(), _disk_writer));
4874 new_processors.insert (++writer_pos, _disk_reader);
4878 /* EXPORT PROCESSOR */
4879 if (_capturing_processor) {
4880 assert (!_capturing_processor->display_to_user ());
4881 ProcessorList::iterator reader_pos = find (new_processors.begin(), new_processors.end(), _disk_reader);
4882 if (reader_pos != new_processors.end()) {
4883 /* insert after disk-reader */
4884 new_processors.insert (++reader_pos, _capturing_processor);
4886 ProcessorList::iterator return_pos = find (new_processors.begin(), new_processors.end(), _intreturn);
4887 /* insert after return */
4888 if (return_pos != new_processors.end()) {
4889 new_processors.insert (++return_pos, _capturing_processor);
4891 new_processors.push_front (_capturing_processor);
4896 /* Polarity Invert */
4898 ProcessorList::iterator reader_pos = find (new_processors.begin(), new_processors.end(), _disk_reader);
4899 if (reader_pos != new_processors.end()) {
4900 /* insert after disk-reader */
4901 new_processors.insert (++reader_pos, _polarity);
4903 ProcessorList::iterator return_pos = find (new_processors.begin(), new_processors.end(), _intreturn);
4904 /* insert after return */
4905 if (return_pos != new_processors.end()) {
4906 new_processors.insert (++return_pos, _polarity);
4908 new_processors.push_front (_polarity);
4914 if (_meter && _meter_point == MeterInput) {
4915 /* add meter just before the disk-writer (if any)
4916 * otherwise at the top, but after the latency delayline
4917 * (perhaps it should also be after intreturn on busses ??)
4919 assert (!_meter->display_to_user ());
4920 ProcessorList::iterator writer_pos = find (new_processors.begin(), new_processors.end(), _disk_writer);
4921 if (writer_pos != new_processors.end()) {
4922 /* insert before disk-writer */
4923 new_processors.insert (writer_pos, _meter);
4925 ProcessorList::iterator return_pos = find (new_processors.begin(), new_processors.end(), _intreturn);
4926 /* insert after return */
4927 if (return_pos != new_processors.end()) {
4928 new_processors.insert (++return_pos, _meter);
4930 new_processors.push_front (_meter);
4935 if (!is_master() && !is_monitor() && !is_auditioner()) {
4936 ProcessorList::iterator reader_pos = find (new_processors.begin(), new_processors.end(), _disk_reader);
4937 if (reader_pos != new_processors.end()) {
4938 /* insert before disk-reader */
4939 new_processors.insert (reader_pos, _delayline);
4941 new_processors.push_front (_delayline);
4945 _processors = new_processors;
4947 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4948 if (!(*i)->display_to_user () && !(*i)->enabled () && (*i) != _monitor_send) {
4949 (*i)->enable (true);
4953 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: setup_invisible_processors\n", _name));
4954 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4955 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1\n", (*i)->name ()));
4962 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
4963 Glib::Threads::RWLock::ReaderLock lp (_processor_lock);
4967 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4968 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*i);
4975 /** If the meter point is `Custom', make a note of where the meter is.
4976 * This is so that if the meter point is subsequently set to something else,
4977 * and then back to custom, we can put the meter back where it was last time
4978 * custom was enabled.
4980 * Must be called with the _processor_lock held.
4983 Route::maybe_note_meter_position ()
4985 if (_meter_point != MeterCustom) {
4989 _custom_meter_position_noted = true;
4990 /* custom meter points range from after trim to before panner/main_outs
4991 * this is a limitation by the current processor UI
4993 bool seen_trim = false;
4994 _processor_after_last_custom_meter.reset();
4995 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4996 if ((*i) == _trim) {
4999 if ((*i) == _main_outs) {
5000 _processor_after_last_custom_meter = *i;
5003 if (boost::dynamic_pointer_cast<PeakMeter> (*i)) {
5005 _processor_after_last_custom_meter = _trim;
5007 ProcessorList::iterator j = i;
5009 assert(j != _processors.end ()); // main_outs should be before
5010 _processor_after_last_custom_meter = *j;
5015 assert(_processor_after_last_custom_meter.lock());
5018 boost::shared_ptr<Processor>
5019 Route::processor_by_id (PBD::ID id) const
5021 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5022 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5023 if ((*i)->id() == id) {
5028 return boost::shared_ptr<Processor> ();
5031 /** @return what we should be metering; either the data coming from the input
5032 * IO or the data that is flowing through the route.
5035 Route::metering_state () const
5037 return MeteringRoute;
5041 Route::has_external_redirects () const
5043 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5045 /* ignore inactive processors and obviously ignore the main
5046 * outs since everything has them and we don't care.
5049 if ((*i)->active() && (*i) != _main_outs && (*i)->does_routing()) {
5057 boost::shared_ptr<Processor>
5058 Route::the_instrument () const
5060 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5061 return the_instrument_unlocked ();
5064 boost::shared_ptr<Processor>
5065 Route::the_instrument_unlocked () const
5067 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5068 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
5069 if (pi && pi->plugin ()->get_info ()->is_instrument ()) {
5073 return boost::shared_ptr<Processor>();
5079 return dynamic_cast<Track*>(this) != 0;
5083 Route::non_realtime_locate (samplepos_t pos)
5085 Automatable::non_realtime_locate (pos);
5088 _pannable->non_realtime_locate (pos);
5091 #if 0 // XXX mayhaps clear delayline here (and at stop?)
5093 _delayline->flush ();
5098 //Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
5099 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5101 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5102 (*i)->non_realtime_locate (pos);
5108 Route::fill_buffers_with_input (BufferSet& bufs, boost::shared_ptr<IO> io, pframes_t nframes)
5115 * We don't currently mix MIDI input together, so we don't need the
5116 * complex logic of the audio case.
5119 n_buffers = bufs.count().n_midi ();
5121 for (i = 0; i < n_buffers; ++i) {
5123 boost::shared_ptr<MidiPort> source_port = io->midi (i);
5124 MidiBuffer& buf (bufs.get_midi (i));
5127 buf.copy (source_port->get_midi_buffer(nframes));
5129 buf.silence (nframes);
5135 n_buffers = bufs.count().n_audio();
5137 size_t n_ports = io->n_ports().n_audio();
5138 float scaling = 1.0f;
5140 if (n_ports > n_buffers) {
5141 scaling = ((float) n_buffers) / n_ports;
5144 for (i = 0; i < n_ports; ++i) {
5146 /* if there are more ports than buffers, map them onto buffers
5147 * in a round-robin fashion
5150 boost::shared_ptr<AudioPort> source_port = io->audio (i);
5151 AudioBuffer& buf (bufs.get_audio (i%n_buffers));
5153 if (i < n_buffers) {
5155 /* first time through just copy a channel into
5159 buf.read_from (source_port->get_audio_buffer (nframes), nframes);
5161 if (scaling != 1.0f) {
5162 buf.apply_gain (scaling, nframes);
5167 /* on subsequent times around, merge data from
5168 * the port with what is already there
5171 if (scaling != 1.0f) {
5172 buf.accumulate_with_gain_from (source_port->get_audio_buffer (nframes), nframes, 0, scaling);
5174 buf.accumulate_from (source_port->get_audio_buffer (nframes), nframes);
5179 /* silence any remaining buffers */
5181 for (; i < n_buffers; ++i) {
5182 AudioBuffer& buf (bufs.get_audio (i));
5183 buf.silence (nframes);
5186 /* establish the initial setup of the buffer set, reflecting what was
5187 copied into it. unless, of course, we are the auditioner, in which
5188 case nothing was fed into it from the inputs at all.
5191 if (!is_auditioner()) {
5192 bufs.set_count (io->n_ports());
5196 boost::shared_ptr<AutomationControl>
5197 Route::pan_azimuth_control() const
5200 # undef MIXBUS_PORTS_H
5201 # include "../../gtk2_ardour/mixbus_ports.h"
5202 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5204 return boost::shared_ptr<AutomationControl>();
5206 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_pan)));
5208 if (!_pannable || !panner()) {
5209 return boost::shared_ptr<AutomationControl>();
5211 return _pannable->pan_azimuth_control;
5215 boost::shared_ptr<AutomationControl>
5216 Route::pan_elevation_control() const
5218 if (Profile->get_mixbus() || !_pannable || !panner()) {
5219 return boost::shared_ptr<AutomationControl>();
5222 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5224 if (c.find (PanElevationAutomation) != c.end()) {
5225 return _pannable->pan_elevation_control;
5227 return boost::shared_ptr<AutomationControl>();
5230 boost::shared_ptr<AutomationControl>
5231 Route::pan_width_control() const
5234 if (mixbus() && _ch_pre) {
5236 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl>(_ch_pre->control(Evoral::Parameter(PluginAutomation, 0, 5)));
5239 if (Profile->get_mixbus() || !_pannable || !panner()) {
5240 return boost::shared_ptr<AutomationControl>();
5243 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5245 if (c.find (PanWidthAutomation) != c.end()) {
5246 return _pannable->pan_width_control;
5248 return boost::shared_ptr<AutomationControl>();
5251 boost::shared_ptr<AutomationControl>
5252 Route::pan_frontback_control() const
5254 if (Profile->get_mixbus() || !_pannable || !panner()) {
5255 return boost::shared_ptr<AutomationControl>();
5258 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5260 if (c.find (PanFrontBackAutomation) != c.end()) {
5261 return _pannable->pan_frontback_control;
5263 return boost::shared_ptr<AutomationControl>();
5266 boost::shared_ptr<AutomationControl>
5267 Route::pan_lfe_control() const
5269 if (Profile->get_mixbus() || !_pannable || !panner()) {
5270 return boost::shared_ptr<AutomationControl>();
5273 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5275 if (c.find (PanLFEAutomation) != c.end()) {
5276 return _pannable->pan_lfe_control;
5278 return boost::shared_ptr<AutomationControl>();
5283 Route::eq_band_cnt () const
5285 if (Profile->get_mixbus()) {
5287 if (is_master() || mixbus()) {
5296 /* Ardour has no well-known EQ object */
5301 boost::shared_ptr<AutomationControl>
5302 Route::eq_gain_controllable (uint32_t band) const
5305 boost::shared_ptr<PluginInsert> eq = ch_eq();
5308 return boost::shared_ptr<AutomationControl>();
5311 uint32_t port_number;
5312 if (is_master() || mixbus()) {
5314 case 0: port_number = 4; break;
5315 case 1: port_number = 3; break;
5316 case 2: port_number = 2; break;
5318 return boost::shared_ptr<AutomationControl>();
5323 case 0: port_number = 14; break;
5324 case 1: port_number = 12; break;
5325 case 2: port_number = 10; break;
5326 case 3: port_number = 8; break;
5328 return boost::shared_ptr<AutomationControl>();
5332 case 0: port_number = 8; break;
5333 case 1: port_number = 6; break;
5334 case 2: port_number = 4; break;
5336 return boost::shared_ptr<AutomationControl>();
5341 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5343 return boost::shared_ptr<AutomationControl>();
5346 boost::shared_ptr<AutomationControl>
5347 Route::eq_freq_controllable (uint32_t band) const
5350 if (mixbus() || is_master()) {
5351 /* no frequency controls for mixbusses or master */
5352 return boost::shared_ptr<AutomationControl>();
5355 boost::shared_ptr<PluginInsert> eq = ch_eq();
5358 return boost::shared_ptr<AutomationControl>();
5361 uint32_t port_number;
5364 case 0: port_number = 13; break; // lo
5365 case 1: port_number = 11; break; // lo mid
5366 case 2: port_number = 9; break; // hi mid
5367 case 3: port_number = 7; break; // hi
5369 return boost::shared_ptr<AutomationControl>();
5373 case 0: port_number = 7; break;
5374 case 1: port_number = 5; break;
5375 case 2: port_number = 3; break;
5377 return boost::shared_ptr<AutomationControl>();
5381 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5383 return boost::shared_ptr<AutomationControl>();
5387 boost::shared_ptr<AutomationControl>
5388 Route::eq_q_controllable (uint32_t band) const
5390 return boost::shared_ptr<AutomationControl>();
5393 boost::shared_ptr<AutomationControl>
5394 Route::eq_shape_controllable (uint32_t band) const
5397 boost::shared_ptr<PluginInsert> eq = ch_eq();
5398 if (is_master() || mixbus() || !eq) {
5399 return boost::shared_ptr<AutomationControl>();
5403 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4))); // lo bell
5406 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3))); // hi bell
5412 return boost::shared_ptr<AutomationControl>();
5415 boost::shared_ptr<AutomationControl>
5416 Route::eq_enable_controllable () const
5419 boost::shared_ptr<PluginInsert> eq = ch_eq();
5422 return boost::shared_ptr<AutomationControl>();
5425 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5427 return boost::shared_ptr<AutomationControl>();
5431 boost::shared_ptr<AutomationControl>
5432 Route::filter_freq_controllable (bool hpf) const
5435 boost::shared_ptr<PluginInsert> eq = ch_eq();
5437 if (is_master() || mixbus() || !eq) {
5438 return boost::shared_ptr<AutomationControl>();
5442 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5))); // HPF freq
5444 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5448 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 6))); // LPF freq
5450 return boost::shared_ptr<AutomationControl>();
5455 return boost::shared_ptr<AutomationControl>();
5459 boost::shared_ptr<AutomationControl>
5460 Route::filter_slope_controllable (bool) const
5462 return boost::shared_ptr<AutomationControl>();
5465 boost::shared_ptr<AutomationControl>
5466 Route::filter_enable_controllable (bool) const
5469 boost::shared_ptr<PluginInsert> eq = ch_eq();
5471 if (is_master() || mixbus() || !eq) {
5472 return boost::shared_ptr<AutomationControl>();
5475 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5477 return boost::shared_ptr<AutomationControl>();
5481 boost::shared_ptr<AutomationControl>
5482 Route::tape_drive_controllable () const
5485 if (_ch_pre && mixbus()) {
5486 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (_ch_pre->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4)));
5488 if (_ch_pre && is_master()) {
5489 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (_ch_pre->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5493 return boost::shared_ptr<AutomationControl>();
5497 Route::eq_band_name (uint32_t band) const
5500 if (is_master() || mixbus()) {
5502 if (Profile->get_mixbus()) {
5504 case 0: return _("lo");
5505 case 1: return _("mid");
5506 case 2: return _("hi");
5507 default: return string();
5515 case 0: return _("lo");
5516 case 1: return _("lo mid");
5517 case 2: return _("hi mid");
5518 case 3: return _("hi");
5519 default: return string();
5525 boost::shared_ptr<AutomationControl>
5526 Route::comp_enable_controllable () const
5529 boost::shared_ptr<PluginInsert> comp = ch_comp();
5532 return boost::shared_ptr<AutomationControl>();
5535 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5537 return boost::shared_ptr<AutomationControl>();
5540 boost::shared_ptr<AutomationControl>
5541 Route::comp_threshold_controllable () const
5544 boost::shared_ptr<PluginInsert> comp = ch_comp();
5547 return boost::shared_ptr<AutomationControl>();
5550 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5553 return boost::shared_ptr<AutomationControl>();
5556 boost::shared_ptr<AutomationControl>
5557 Route::comp_speed_controllable () const
5560 boost::shared_ptr<PluginInsert> comp = ch_comp();
5563 return boost::shared_ptr<AutomationControl>();
5566 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3)));
5568 return boost::shared_ptr<AutomationControl>();
5571 boost::shared_ptr<AutomationControl>
5572 Route::comp_mode_controllable () const
5575 boost::shared_ptr<PluginInsert> comp = ch_comp();
5578 return boost::shared_ptr<AutomationControl>();
5581 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4)));
5583 return boost::shared_ptr<AutomationControl>();
5586 boost::shared_ptr<AutomationControl>
5587 Route::comp_makeup_controllable () const
5590 boost::shared_ptr<PluginInsert> comp = ch_comp();
5593 return boost::shared_ptr<AutomationControl>();
5596 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5)));
5598 return boost::shared_ptr<AutomationControl>();
5601 boost::shared_ptr<ReadOnlyControl>
5602 Route::comp_redux_controllable () const
5605 boost::shared_ptr<PluginInsert> comp = ch_comp();
5608 return boost::shared_ptr<ReadOnlyControl>();
5611 return comp->control_output (2);
5613 return comp->control_output (6);
5617 return boost::shared_ptr<ReadOnlyControl>();
5622 Route::comp_mode_name (uint32_t mode) const
5627 return _("Leveler");
5629 return _("Compressor");
5631 return _("Limiter");
5633 return mixbus() ? _("Sidechain") : _("Limiter");
5643 Route::comp_speed_name (uint32_t mode) const
5661 boost::shared_ptr<AutomationControl>
5662 Route::send_pan_azi_controllable (uint32_t n) const
5665 # undef MIXBUS_PORTS_H
5666 # include "../../gtk2_ardour/mixbus_ports.h"
5667 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5668 if (plug && !mixbus()) {
5669 uint32_t port_id = 0;
5672 case 0: port_id = port_channel_post_aux0_pan; break; //32c mb "pan" controls use zero-based names, unlike levels. ugh
5673 case 1: port_id = port_channel_post_aux1_pan; break;
5674 case 2: port_id = port_channel_post_aux2_pan; break;
5675 case 3: port_id = port_channel_post_aux3_pan; break;
5676 case 4: port_id = port_channel_post_aux4_pan; break;
5677 case 5: port_id = port_channel_post_aux5_pan; break;
5678 case 6: port_id = port_channel_post_aux6_pan; break;
5679 case 7: port_id = port_channel_post_aux7_pan; break;
5680 case 8: port_id = port_channel_post_aux8_pan; break;
5681 case 9: port_id = port_channel_post_aux9_pan; break;
5682 case 10: port_id = port_channel_post_aux10_pan; break;
5683 case 11: port_id = port_channel_post_aux11_pan; break;
5690 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5695 return boost::shared_ptr<AutomationControl>();
5698 boost::shared_ptr<AutomationControl>
5699 Route::send_level_controllable (uint32_t n) const
5702 # undef MIXBUS_PORTS_H
5703 # include "../../gtk2_ardour/mixbus_ports.h"
5704 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5705 if (plug && !mixbus()) {
5706 uint32_t port_id = 0;
5708 case 0: port_id = port_channel_post_aux1_level; break;
5709 case 1: port_id = port_channel_post_aux2_level; break;
5710 case 2: port_id = port_channel_post_aux3_level; break;
5711 case 3: port_id = port_channel_post_aux4_level; break;
5712 case 4: port_id = port_channel_post_aux5_level; break;
5713 case 5: port_id = port_channel_post_aux6_level; break;
5714 case 6: port_id = port_channel_post_aux7_level; break;
5715 case 7: port_id = port_channel_post_aux8_level; break;
5717 case 8: port_id = port_channel_post_aux9_level; break;
5718 case 9: port_id = port_channel_post_aux10_level; break;
5719 case 10: port_id = port_channel_post_aux11_level; break;
5720 case 11: port_id = port_channel_post_aux12_level; break;
5727 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5738 boost::shared_ptr<Send> s = boost::dynamic_pointer_cast<Send>(nth_send (n));
5740 return boost::shared_ptr<AutomationControl>();
5742 return s->gain_control ();
5745 boost::shared_ptr<AutomationControl>
5746 Route::send_enable_controllable (uint32_t n) const
5749 # undef MIXBUS_PORTS_H
5750 # include "../../gtk2_ardour/mixbus_ports.h"
5751 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5752 if (plug && !mixbus()) {
5753 uint32_t port_id = 0;
5755 case 0: port_id = port_channel_post_aux1_asgn; break;
5756 case 1: port_id = port_channel_post_aux2_asgn; break;
5757 case 2: port_id = port_channel_post_aux3_asgn; break;
5758 case 3: port_id = port_channel_post_aux4_asgn; break;
5759 case 4: port_id = port_channel_post_aux5_asgn; break;
5760 case 5: port_id = port_channel_post_aux6_asgn; break;
5761 case 6: port_id = port_channel_post_aux7_asgn; break;
5762 case 7: port_id = port_channel_post_aux8_asgn; break;
5764 case 8: port_id = port_channel_post_aux9_asgn; break;
5765 case 9: port_id = port_channel_post_aux10_asgn; break;
5766 case 10: port_id = port_channel_post_aux11_asgn; break;
5767 case 11: port_id = port_channel_post_aux12_asgn; break;
5774 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5785 /* although Ardour sends have enable/disable as part of the Processor
5786 * API, it is not exposed as a controllable.
5788 * XXX: we should fix this (make it click-free, automatable enable-control)
5790 return boost::shared_ptr<AutomationControl>();
5794 Route::send_name (uint32_t n) const
5797 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5798 if (plug && !mixbus()) {
5801 return _session.get_mixbus (n)->name();
5806 return _session.get_mixbus (n)->name();
5812 boost::shared_ptr<Processor> p = nth_send (n);
5820 boost::shared_ptr<AutomationControl>
5821 Route::master_send_enable_controllable () const
5824 if (is_master() || is_monitor() || is_auditioner()) {
5825 return boost::shared_ptr<AutomationControl>();
5828 boost::shared_ptr<ARDOUR::PluginInsert> plug = mixbus() ? ch_pre () : ch_post();
5830 return boost::shared_ptr<AutomationControl>();
5832 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, mixbus() ? 3 : 19)));
5834 return boost::shared_ptr<AutomationControl>();
5839 Route::slaved () const
5841 if (!_gain_control) {
5844 /* just test one particular control, not all of them */
5845 return _gain_control->slaved ();
5849 Route::slaved_to (boost::shared_ptr<VCA> vca) const
5851 if (!vca || !_gain_control) {
5855 /* just test one particular control, not all of them */
5857 return _gain_control->slaved_to (vca->gain_control());
5861 Route::muted_by_others_soloing () const
5863 if (!can_be_muted_by_others ()) {
5867 return _session.soloing() && !_solo_control->soloed() && !_solo_isolate_control->solo_isolated();
5871 Route::clear_all_solo_state ()
5873 _solo_control->clear_all_solo_state ();
5876 boost::shared_ptr<AutomationControl>
5877 Route::automation_control_recurse (PBD::ID const & id) const
5879 boost::shared_ptr<AutomationControl> ac = Automatable::automation_control (id);
5885 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5887 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5888 if ((ac = (*i)->automation_control (id))) {
5893 return boost::shared_ptr<AutomationControl> ();
5897 Route::slavables () const
5899 SlavableControlList rv;
5900 rv.push_back (_gain_control);
5901 rv.push_back (_mute_control);
5902 rv.push_back (_solo_control);
5907 Route::set_disk_io_point (DiskIOPoint diop)
5909 bool display = false;
5911 cerr << "set disk io to " << enum_2_string (diop) << endl;
5922 _disk_writer->set_display_to_user (display);
5926 _disk_reader->set_display_to_user (display);
5929 const bool changed = (diop != _disk_io_point);
5931 _disk_io_point = diop;
5934 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
5935 configure_processors (0);
5938 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
5942 Route::set_loop (Location* l)
5945 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5946 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5951 #ifdef USE_TRACKS_CODE_FEATURES
5953 /* This is the Tracks version of Track::monitoring_state().
5955 * Ardour developers: try to flag or fix issues if parts of the libardour API
5956 * change in ways that invalidate this
5960 Route::monitoring_state () const
5962 /* Explicit requests */
5964 if (_monitoring != MonitorInput) {
5965 return MonitoringInput;
5968 if (_monitoring & MonitorDisk) {
5969 return MonitoringDisk;
5972 /* This is an implementation of the truth table in doc/monitor_modes.pdf;
5973 I don't think it's ever going to be too pretty too look at.
5976 // GZ: NOT USED IN TRACKS
5977 //bool const auto_input = _session.config.get_auto_input ();
5978 //bool const software_monitor = Config->get_monitoring_model() == SoftwareMonitoring;
5979 //bool const tape_machine_mode = Config->get_tape_machine_mode ();
5981 bool const roll = _session.transport_rolling ();
5982 bool const track_rec = _diskstream->record_enabled ();
5983 bool session_rec = _session.actively_recording ();
5987 if (!session_rec && roll) {
5988 return MonitoringDisk;
5990 return MonitoringInput;
5996 return MonitoringDisk;
6000 return MonitoringSilence;
6005 /* This is the Ardour/Mixbus version of Track::monitoring_state().
6007 * Tracks developers: do NOT modify this method under any circumstances.
6011 Route::monitoring_state () const
6013 if (!_disk_reader) {
6014 return MonitoringInput;
6017 /* Explicit requests */
6018 MonitorChoice m (_monitoring_control->monitoring_choice());
6020 if (m != MonitorAuto) {
6022 MonitorState ms ((MonitorState) 0);
6024 if (m & MonitorInput) {
6025 ms = MonitoringInput;
6028 if (m & MonitorDisk) {
6029 ms = MonitorState (ms | MonitoringDisk);
6035 switch (_session.config.get_session_monitoring ()) {
6037 return MonitoringDisk;
6040 return MonitoringInput;
6046 return get_auto_monitoring_state();