2 * Copyright (C) 2000-2019 Paul Davis <paul@linuxaudiosystems.com>
3 * Copyright (C) 2006-2007 Sampo Savolainen <v2@iki.fi>
4 * Copyright (C) 2006-2014 David Robillard <d@drobilla.net>
5 * Copyright (C) 2006 Jesse Chappell <jesse@essej.net>
6 * Copyright (C) 2008-2012 Carl Hetherington <carl@carlh.net>
7 * Copyright (C) 2011-2012 Sakari Bergen <sakari.bergen@beatwaves.net>
8 * Copyright (C) 2013-2015 Nick Mainsbridge <mainsbridge@gmail.com>
9 * Copyright (C) 2013-2017 John Emmas <john@creativepost.co.uk>
10 * Copyright (C) 2013-2019 Robin Gareus <robin@gareus.org>
11 * Copyright (C) 2014-2018 Ben Loftis <ben@harrisonconsoles.com>
12 * Copyright (C) 2015-2018 Len Ovens <len@ovenwerks.net>
13 * Copyright (C) 2016 Julien "_FrnchFrgg_" RIVAUD <frnchfrgg@free.fr>
14 * Copyright (C) 2016 Tim Mayberry <mojofunk@gmail.com>
15 * Copyright (C) 2017-2018 Johannes Mueller <github@johannes-mueller.org>
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License along
28 * with this program; if not, write to the Free Software Foundation, Inc.,
29 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
33 #include "libardour-config.h"
41 #include <boost/algorithm/string.hpp>
43 #include "pbd/xml++.h"
44 #include "pbd/enumwriter.h"
45 #include "pbd/locale_guard.h"
46 #include "pbd/memento_command.h"
47 #include "pbd/stacktrace.h"
48 #include "pbd/types_convert.h"
49 #include "pbd/unwind.h"
51 #include "ardour/amp.h"
52 #include "ardour/audio_buffer.h"
53 #include "ardour/audio_track.h"
54 #include "ardour/audio_port.h"
55 #include "ardour/audioengine.h"
56 #include "ardour/boost_debug.h"
57 #include "ardour/buffer.h"
58 #include "ardour/buffer_set.h"
59 #include "ardour/capturing_processor.h"
60 #include "ardour/debug.h"
61 #include "ardour/delivery.h"
62 #include "ardour/disk_reader.h"
63 #include "ardour/disk_writer.h"
64 #include "ardour/event_type_map.h"
65 #include "ardour/gain_control.h"
66 #include "ardour/internal_return.h"
67 #include "ardour/internal_send.h"
68 #include "ardour/meter.h"
69 #include "ardour/delayline.h"
70 #include "ardour/midi_buffer.h"
71 #include "ardour/midi_port.h"
72 #include "ardour/midi_track.h"
73 #include "ardour/monitor_control.h"
74 #include "ardour/monitor_processor.h"
75 #include "ardour/pannable.h"
76 #include "ardour/panner.h"
77 #include "ardour/panner_shell.h"
78 #include "ardour/parameter_descriptor.h"
79 #include "ardour/phase_control.h"
80 #include "ardour/plugin_insert.h"
81 #include "ardour/polarity_processor.h"
82 #include "ardour/port.h"
83 #include "ardour/port_insert.h"
84 #include "ardour/processor.h"
85 #include "ardour/profile.h"
86 #include "ardour/revision.h"
87 #include "ardour/route.h"
88 #include "ardour/route_group.h"
89 #include "ardour/send.h"
90 #include "ardour/session.h"
91 #include "ardour/solo_control.h"
92 #include "ardour/solo_isolate_control.h"
93 #include "ardour/types_convert.h"
94 #include "ardour/unknown_processor.h"
95 #include "ardour/utils.h"
96 #include "ardour/vca.h"
101 using namespace ARDOUR;
104 PBD::Signal3<int,boost::shared_ptr<Route>, boost::shared_ptr<PluginInsert>, Route::PluginSetupOptions > Route::PluginSetup;
106 /** Base class for all routable/mixable objects (tracks and busses) */
107 Route::Route (Session& sess, string name, PresentationInfo::Flag flag, DataType default_type)
108 : Stripable (sess, name, PresentationInfo (flag))
109 , GraphNode (sess._process_graph)
110 , Muteable (sess, name)
112 , _signal_latency (0)
113 , _disk_io_point (DiskIOPreFader)
114 , _pending_process_reorder (0)
115 , _pending_signals (0)
116 , _meter_point (MeterPostFader)
117 , _pending_meter_point (MeterPostFader)
118 , _denormal_protection (false)
120 , _have_internal_generator (false)
121 , _default_type (default_type)
122 , _loop_location (NULL)
125 , _in_configure_processors (false)
126 , _initial_io_setup (false)
127 , _in_sidechain_setup (false)
128 , _custom_meter_position_noted (false)
130 , _patch_selector_dialog (0)
132 processor_max_streams.reset();
135 boost::weak_ptr<Route>
136 Route::weakroute () {
137 return boost::weak_ptr<Route> (boost::dynamic_pointer_cast<Route> (shared_from_this ()));
143 /* add standard controls */
145 _gain_control.reset (new GainControl (_session, GainAutomation));
146 _trim_control.reset (new GainControl (_session, TrimAutomation));
147 /* While the route has-a gain-control for consistency with Stripable and VCA
148 * ownership is handed over to the Amp Processor which manages the
149 * state of the Control and AutomationList as part of its
150 * Automatable API. -- Don't call add_control () here.
153 _solo_control.reset (new SoloControl (_session, X_("solo"), *this, *this));
154 add_control (_solo_control);
155 _solo_control->Changed.connect_same_thread (*this, boost::bind (&Route::solo_control_changed, this, _1, _2));
157 _mute_control.reset (new MuteControl (_session, X_("mute"), *this));
158 add_control (_mute_control);
160 _phase_control.reset (new PhaseControl (_session, X_("phase")));
161 add_control (_phase_control);
163 _solo_isolate_control.reset (new SoloIsolateControl (_session, X_("solo-iso"), *this, *this));
164 add_control (_solo_isolate_control);
166 _solo_safe_control.reset (new SoloSafeControl (_session, X_("solo-safe")));
167 add_control (_solo_safe_control);
171 if (!(_presentation_info.flags() & PresentationInfo::MonitorOut)) {
172 _pannable.reset (new Pannable (_session));
175 /* input and output objects */
177 _input.reset (new IO (_session, _name, IO::Input, _default_type));
178 _output.reset (new IO (_session, _name, IO::Output, _default_type));
180 _input->changed.connect_same_thread (*this, boost::bind (&Route::input_change_handler, this, _1, _2));
181 _input->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::input_port_count_changing, this, _1));
183 _output->changed.connect_same_thread (*this, boost::bind (&Route::output_change_handler, this, _1, _2));
184 _output->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::output_port_count_changing, this, _1));
186 /* add the amp/fader processor.
187 * it should be the first processor to be added on every route.
190 _amp.reset (new Amp (_session, X_("Fader"), _gain_control, true));
192 _amp->set_owner (this);
194 _polarity.reset (new PolarityProcessor (_session, _phase_control));
195 _polarity->activate();
196 _polarity->set_owner (this);
199 _amp->set_display_name (_("Monitor"));
202 if (!is_master() && !is_monitor() && !is_auditioner()) {
203 _delayline.reset (new DelayLine (_session, name ()));
208 _trim.reset (new Amp (_session, X_("Trim"), _trim_control, false));
209 _trim->set_display_to_user (false);
211 if (dynamic_cast<AudioTrack*>(this)) {
212 /* we can't do this in the AudioTrack's constructor
213 * because _trim does not exit then
217 else if (!dynamic_cast<Track*>(this) && ! (is_monitor() || is_auditioner())) {
222 /* create standard processors: meter, main outs, monitor out;
223 they will be added to _processors by setup_invisible_processors ()
226 _meter.reset (new PeakMeter (_session, _name));
227 _meter->set_owner (this);
228 _meter->set_display_to_user (false);
231 /* set default meter type */
234 set_meter_type (MeterK14);
236 set_meter_type (Config->get_meter_type_master ());
238 } else if (dynamic_cast<Track*>(this)) {
239 set_meter_type (Config->get_meter_type_track ());
241 set_meter_type (Config->get_meter_type_bus ());
244 _main_outs.reset (new Delivery (_session, _output, _pannable, _mute_master, _name, Delivery::Main));
245 _main_outs->activate ();
248 /* where we listen to tracks */
249 _intreturn.reset (new InternalReturn (_session));
250 _intreturn->activate ();
252 /* the thing that provides proper control over a control/monitor/listen bus
253 (such as per-channel cut, dim, solo, invert, etc).
255 _monitor_control.reset (new MonitorProcessor (_session));
256 _monitor_control->activate ();
258 if (_presentation_info.flags() & PresentationInfo::FoldbackBus) {
259 panner_shell()->select_panner_by_uri ("http://ardour.org/plugin/panner_balance");
262 /* now set up processor chain and invisible processors */
264 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
266 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
267 _processors.push_back (_amp);
269 if (!_session.loading()) {
270 configure_processors (0);
279 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
281 /* do this early so that we don't get incoming signals as we are going through destruction
286 /* don't use clear_processors here, as it depends on the session which may
287 be half-destroyed by now
290 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
291 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
292 (*i)->drop_references ();
295 _processors.clear ();
299 Route::ensure_track_or_route_name (string newname) const
301 while (!_session.io_name_is_legal (newname)) {
302 newname = bump_name_once (newname, ' ');
303 if (newname == name()) {
311 Route::set_trim (gain_t val, Controllable::GroupControlDisposition /* group override */)
313 // TODO route group, see set_gain()
314 // _trim_control->route_set_value (val);
317 /** Process this route for one (sub) cycle (process thread)
319 * @param bufs Scratch buffers to use for the signal path
320 * @param start_sample Initial transport sample
321 * @param end_sample Final transport sample
322 * @param nframes Number of samples to output (to ports)
324 * Note that (end_sample - start_sample) may not be equal to nframes when the
325 * transport speed isn't 1.0 (eg varispeed).
328 Route::process_output_buffers (BufferSet& bufs,
329 samplepos_t start_sample, samplepos_t end_sample, pframes_t nframes,
330 bool gain_automation_ok, bool run_disk_reader)
332 /* Caller must hold process lock */
333 assert (!AudioEngine::instance()->process_lock().trylock());
335 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
337 // can this actually happen?
338 // Places that need a WriterLock on (_processor_lock) must also take the process-lock.
339 bufs.silence (nframes, 0);
340 assert (0); // ...one way to find out.
344 /* We should offset the route-owned ctrls by the given latency, however
345 * this only affects Mute. Other route-owned controls (solo, polarity..)
346 * are not automatable.
348 * Mute has its own issues since there's not a single mute-point,
351 automation_run (start_sample, nframes);
354 _pannable->automation_run (start_sample + _signal_latency, nframes);
357 /* figure out if we're going to use gain automation */
358 if (gain_automation_ok) {
359 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
360 _amp->setup_gain_automation (
361 start_sample + _amp->output_latency (),
362 end_sample + _amp->output_latency (),
365 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
366 _trim->setup_gain_automation (
367 start_sample + _trim->output_latency (),
368 end_sample + _trim->output_latency (),
372 /* We align the playhead to output. The user hears what the clock says:
373 * When the playhead/clock says 1:00:00:00 the user will hear the audio sample
374 * at 1:00:00:00. sample_start will be [sample at] 1:00:00:00
376 * e.g. clock says Time T = 0, sample_start = 0
377 * Disk-read(play) -> latent-plugin (+10) -> fader-automation -> output (+5)
378 * -> total playback latency "disk -> out" is 15.
379 * -> at Time T= -15, the disk-reader reads sample T=0.
380 * By the Time T=0 is reached (dt=15 later) that sample is audible.
383 const double speed = (is_auditioner() ? 1.0 : _session.transport_speed ());
385 const sampleoffset_t latency_offset = _signal_latency + _output->latency ();
387 /* when rolling backwards this can become negative */
388 start_sample -= latency_offset;
389 end_sample -= latency_offset;
391 start_sample += latency_offset;
392 end_sample += latency_offset;
395 /* Note: during intial pre-roll 'start_sample' as passed as argument can be negative.
396 * Functions calling process_output_buffers() will set "run_disk_reader"
397 * to false if the pre-roll count-down is larger than playback_latency ().
399 * playback_latency() is guarnteed to be <= _signal_latency + _output->latency ()
401 assert (!_disk_reader || !run_disk_reader || start_sample >= 0 || speed < 0);
403 /* however the disk-writer may need to pick up output from other tracks
404 * during pre-roll (in particular if this route has latent effects after the disk).
406 * e.g. track 1 play -> latency A --port--> track2 capture -> latency B ---> out
407 * total pre-roll = A + B.
409 * Note the disk-writer has built-in overlap detection (it's safe to run it early)
412 bool run_disk_writer = false;
413 if (_disk_writer && speed > 0) {
414 samplecnt_t latency_preroll = _session.remaining_latency_preroll ();
415 run_disk_writer = latency_preroll < nframes + (_signal_latency + _output->latency ());
416 if (end_sample - _disk_writer->input_latency () < _session.transport_sample ()) {
417 run_disk_writer = true;
421 /* Tell main outs what to do about monitoring. We do this so that
422 * on a transition between monitoring states we get a de-clicking gain
423 * change in the _main_outs delivery, if config.get_use_monitor_fades()
426 * We override this in the case where we have an internal generator.
428 * FIXME: when punching in/out this also depends on latency compensated time
429 * for this route. monitoring_state() does not currently handle that correctly,.
431 * Also during remaining_latency_preroll, transport_rolling () is false, but
432 * we may need to monitor disk instead.
434 const MonitorState ms = monitoring_state ();
435 const bool silent = _have_internal_generator ? false : (ms == MonitoringSilence);
437 _main_outs->no_outs_cuz_we_no_monitor (silent);
439 /* -------------------------------------------------------------------------------------------
441 ----------------------------------------------------------------------------------------- */
442 /* XXX We'll need to protect silent inputs as well as silent disk
443 * (when not monitoring input or monitoring disk and there's no region
444 * for a longer time).
446 * ...or simply drop that feature.
448 if (_denormal_protection || Config->get_denormal_protection()) {
450 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
451 Sample* const sp = i->data();
452 for (pframes_t nx = 0; nx < nframes; ++nx) {
459 /* -------------------------------------------------------------------------------------------
461 ----------------------------------------------------------------------------------------- */
463 samplecnt_t latency = 0;
465 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
467 /* TODO check for split cycles here.
469 * start_frame, end_frame is adjusted by latency and may
474 /* if it has any inputs, make sure they match */
475 if (boost::dynamic_pointer_cast<UnknownProcessor> (*i) == 0 && (*i)->input_streams() != ChanCount::ZERO) {
476 if (bufs.count() != (*i)->input_streams()) {
478 DEBUG::Processors, string_compose (
479 "input port mismatch %1 bufs = %2 input for %3 = %4\n",
480 _name, bufs.count(), (*i)->name(), (*i)->input_streams()
487 bool re_inject_oob_data = false;
488 if ((*i) == _disk_reader) {
489 /* Well now, we've made it past the disk-writer and to the disk-reader.
490 * Time to decide what to do about monitoring.
492 * Even when not doing MonitoringDisk, we need to run the processors,
493 * so that it advances its internal buffers (IFF run_disk_reader is true).
496 if (ms == MonitoringDisk || ms == MonitoringSilence) {
497 /* this will clear out-of-band data, too (e.g. MIDI-PC, Panic etc.
498 * OOB data is written at the end of the cycle (nframes - 1),
499 * and jack does not re-order events, so we push them back later */
500 re_inject_oob_data = true;
501 bufs.silence (nframes, 0);
505 double pspeed = speed;
506 if ((!run_disk_reader && (*i) == _disk_reader) || (!run_disk_writer && (*i) == _disk_writer)) {
507 /* run with speed 0, no-roll */
512 (*i)->run (bufs, start_sample + latency, end_sample + latency, pspeed, nframes, *i != _processors.back());
514 (*i)->run (bufs, start_sample - latency, end_sample - latency, pspeed, nframes, *i != _processors.back());
517 bufs.set_count ((*i)->output_streams());
519 /* Note: plugin latency may change. While the plugin does inform the session via
520 * processor_latency_changed(). But the session may not yet have gotten around to
521 * update the actual worste-case and update this track's _signal_latency.
523 * So there can be cases where adding up all latencies may not equal _signal_latency.
525 if ((*i)->active ()) {
526 latency += (*i)->effective_latency ();
529 if (re_inject_oob_data) {
530 write_out_of_band_data (bufs, nframes);
534 if ((*i) == _delayline) {
535 latency += _delayline->delay ();
542 Route::bounce_process (BufferSet& buffers, samplepos_t start, samplecnt_t nframes,
543 boost::shared_ptr<Processor> endpoint,
544 bool include_endpoint, bool for_export, bool for_freeze)
546 /* If no processing is required, there's no need to go any further. */
547 if (!endpoint && !include_endpoint) {
551 samplecnt_t latency = bounce_get_latency(_amp, false, for_export, for_freeze);
552 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
553 _amp->setup_gain_automation (start - latency, start - latency + nframes, nframes);
555 /* trim is always at the top, for bounce no latency compensation is needed */
556 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
557 _trim->setup_gain_automation (start, start + nframes, nframes);
560 bool seen_disk_io = false;
561 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
563 if (!include_endpoint && (*i) == endpoint) {
567 if (!for_export && !seen_disk_io) {
568 if (boost::dynamic_pointer_cast<DiskReader> (*i)) {
570 buffers.set_count ((*i)->output_streams());
575 /* if we're *not* exporting, stop processing if we come across a routing processor. */
576 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
579 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
583 /* special case the panner (export outputs)
584 * Ideally we'd only run the panner, not the delivery itself...
585 * but panners need separate input/output buffers and some context
586 * (panshell, panner type, etc). AFAICT there is no ill side effect
587 * of re-using the main delivery when freewheeling/exporting a region.
589 if ((*i) == _main_outs) {
590 assert ((*i)->does_routing());
591 (*i)->run (buffers, start - latency, start - latency + nframes, 1.0, nframes, true);
592 buffers.set_count ((*i)->output_streams());
595 /* don't run any processors that do routing.
596 * Also don't bother with metering.
598 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
599 (*i)->run (buffers, start - latency, start - latency + nframes, 1.0, nframes, true);
600 buffers.set_count ((*i)->output_streams());
601 latency += (*i)->effective_latency ();
604 if ((*i) == endpoint) {
611 Route::bounce_get_latency (boost::shared_ptr<Processor> endpoint,
612 bool include_endpoint, bool for_export, bool for_freeze) const
614 samplecnt_t latency = 0;
615 if (!endpoint && !include_endpoint) {
619 bool seen_disk_io = false;
620 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
621 if (!include_endpoint && (*i) == endpoint) {
624 if (!for_export && !seen_disk_io) {
625 if (boost::dynamic_pointer_cast<DiskReader> (*i)) {
630 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
633 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
636 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
637 latency += (*i)->effective_latency ();
639 if ((*i) == endpoint) {
647 Route::bounce_get_output_streams (ChanCount &cc, boost::shared_ptr<Processor> endpoint,
648 bool include_endpoint, bool for_export, bool for_freeze) const
650 if (!endpoint && !include_endpoint) {
654 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
655 if (!include_endpoint && (*i) == endpoint) {
658 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
661 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
664 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
665 cc = (*i)->output_streams();
667 if ((*i) == endpoint) {
675 Route::n_process_buffers ()
677 return max (_input->n_ports(), processor_max_streams);
681 Route::monitor_run (samplepos_t start_sample, samplepos_t end_sample, pframes_t nframes)
683 assert (is_monitor());
684 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
685 run_route (start_sample, end_sample, nframes, true, false);
689 Route::run_route (samplepos_t start_sample, samplepos_t end_sample, pframes_t nframes, bool gain_automation_ok, bool run_disk_reader)
691 BufferSet& bufs (_session.get_route_buffers (n_process_buffers()));
693 fill_buffers_with_input (bufs, _input, nframes);
695 /* filter captured data before meter sees it */
698 if (is_monitor() && _session.listening() && !_session.is_auditioning()) {
700 /* control/monitor bus ignores input ports when something is
701 feeding the listen "stream". data will "arrive" into the
702 route from the intreturn processor element.
705 bufs.silence (nframes, 0);
708 snapshot_out_of_band_data (nframes);
709 /* append immediate messages to the first MIDI buffer (thus sending it to the first output port) */
711 write_out_of_band_data (bufs, nframes);
713 /* run processor chain */
715 process_output_buffers (bufs, start_sample, end_sample, nframes, gain_automation_ok, run_disk_reader);
717 /* map events (e.g. MIDI-CC) back to control-parameters */
718 update_controls (bufs);
720 flush_processor_buffers_locked (nframes);
724 Route::set_listen (bool yn)
727 if (_monitor_send->active() == yn) {
731 _monitor_send->activate ();
733 _monitor_send->deactivate ();
739 Route::solo_control_changed (bool, Controllable::GroupControlDisposition)
741 /* nothing to do if we're not using AFL/PFL. But if we are, we need
742 to alter the active state of the monitor send.
745 if (Config->get_solo_control_is_listen_control ()) {
746 set_listen (_solo_control->self_soloed() || _solo_control->get_masters_value());
751 Route::push_solo_isolate_upstream (int32_t delta)
753 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
755 boost::shared_ptr<RouteList> routes = _session.get_routes ();
756 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
758 if ((*i).get() == this || !(*i)->can_solo()) {
763 bool does_feed = feeds (*i, &sends_only);
765 if (does_feed && !sends_only) {
766 (*i)->solo_isolate_control()->mod_solo_isolated_by_upstream (delta);
772 Route::push_solo_upstream (int delta)
774 DEBUG_TRACE (DEBUG::Solo, string_compose("\t ... INVERT push from %1\n", _name));
775 for (FedBy::iterator i = _fed_by.begin(); i != _fed_by.end(); ++i) {
779 boost::shared_ptr<Route> sr (i->r.lock());
781 sr->solo_control()->mod_solo_by_others_downstream (-delta);
788 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
790 cerr << name << " {" << endl;
791 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
792 p != procs.end(); ++p) {
793 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << " @ " << (*p) << endl;
799 /** Supposing that we want to insert a Processor at a given Placement, return
800 * the processor to add the new one before (or 0 to add at the end).
802 boost::shared_ptr<Processor>
803 Route::before_processor_for_placement (Placement p)
805 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
807 ProcessorList::iterator loc;
810 /* generic pre-fader: insert immediately before the amp */
811 loc = find (_processors.begin(), _processors.end(), _amp);
813 /* generic post-fader: insert right before the main outs */
814 loc = find (_processors.begin(), _processors.end(), _main_outs);
817 return loc != _processors.end() ? *loc : boost::shared_ptr<Processor> ();
820 /** Supposing that we want to insert a Processor at a given index, return
821 * the processor to add the new one before (or 0 to add at the end).
823 boost::shared_ptr<Processor>
824 Route::before_processor_for_index (int index)
827 return boost::shared_ptr<Processor> ();
830 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
832 ProcessorList::iterator i = _processors.begin ();
834 while (i != _processors.end() && j < index) {
835 if ((*i)->display_to_user()) {
842 return (i != _processors.end() ? *i : boost::shared_ptr<Processor> ());
845 /** Add a processor either pre- or post-fader
846 * @return 0 on success, non-0 on failure.
849 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err, bool activation_allowed)
851 return add_processor (processor, before_processor_for_placement (placement), err, activation_allowed);
855 /** Add a processor to a route such that it ends up with a given index into the visible processors.
856 * @param index Index to add the processor at, or -1 to add at the end of the list.
857 * @return 0 on success, non-0 on failure.
860 Route::add_processor_by_index (boost::shared_ptr<Processor> processor, int index, ProcessorStreams* err, bool activation_allowed)
862 return add_processor (processor, before_processor_for_index (index), err, activation_allowed);
865 /** Add a processor to the route.
866 * @param before An existing processor in the list, or 0; the new processor will be inserted immediately before it (or at the end).
867 * @return 0 on success, non-0 on failure.
870 Route::add_processor (boost::shared_ptr<Processor> processor, boost::shared_ptr<Processor> before, ProcessorStreams* err, bool activation_allowed)
872 assert (processor != _meter);
873 assert (processor != _main_outs);
875 DEBUG_TRACE (DEBUG::Processors, string_compose (
876 "%1 adding processor %2\n", name(), processor->name()));
880 pl.push_back (processor);
881 int rv = add_processors (pl, before, err);
887 if (activation_allowed && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user ())) {
888 processor->activate ();
891 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
893 pi->update_sidechain_name ();
900 Route::processor_selfdestruct (boost::weak_ptr<Processor> wp)
902 /* We cannot destruct the processor here (usually RT-thread
903 * with various locks held - in case of sends also io_locks).
904 * Queue for deletion in low-priority thread.
906 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
907 selfdestruct_sequence.push_back (wp);
911 Route::add_processor_from_xml_2X (const XMLNode& node, int version)
913 XMLProperty const * prop;
916 boost::shared_ptr<Processor> processor;
918 /* bit of a hack: get the `placement' property from the <Redirect> tag here
919 so that we can add the processor in the right place (pre/post-fader)
922 XMLNodeList const & children = node.children ();
923 XMLNodeList::const_iterator i = children.begin ();
925 while (i != children.end() && (*i)->name() != X_("Redirect")) {
929 Placement placement = PreFader;
931 if (i != children.end()) {
932 if ((prop = (*i)->property (X_("placement"))) != 0) {
933 placement = Placement (string_2_enum (prop->value(), placement));
937 if (node.name() == "Insert") {
939 if ((prop = node.property ("type")) != 0) {
941 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
942 prop->value() == "lv2" ||
943 prop->value() == "windows-vst" ||
944 prop->value() == "mac-vst" ||
945 prop->value() == "lxvst" ||
946 prop->value() == "audiounit") {
948 if (_session.get_disable_all_loaded_plugins ()) {
949 processor.reset (new UnknownProcessor (_session, node));
951 processor.reset (new PluginInsert (_session));
952 processor->set_owner (this);
957 processor.reset (new PortInsert (_session, _pannable, _mute_master));
962 } else if (node.name() == "Send") {
964 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
965 processor.reset (new Send (_session, sendpan, _mute_master));
969 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
973 if (processor->set_state (node, version)) {
977 //A2 uses the "active" flag in the toplevel redirect node, not in the child plugin/IO
978 if (i != children.end()) {
979 if ((prop = (*i)->property (X_("active"))) != 0) {
980 if (string_to<bool> (prop->value()) && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user ()))
981 processor->activate();
983 processor->deactivate();
987 return (add_processor (processor, placement, 0, false) == 0);
990 catch (failed_constructor &err) {
991 warning << _("processor could not be created. Ignored.") << endmsg;
997 inline Route::PluginSetupOptions operator|= (Route::PluginSetupOptions& a, const Route::PluginSetupOptions& b) {
998 return a = static_cast<Route::PluginSetupOptions> (static_cast <int>(a) | static_cast<int> (b));
1001 inline Route::PluginSetupOptions operator&= (Route::PluginSetupOptions& a, const Route::PluginSetupOptions& b) {
1002 return a = static_cast<Route::PluginSetupOptions> (static_cast <int>(a) & static_cast<int> (b));
1006 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
1008 ProcessorList::iterator loc;
1009 boost::shared_ptr <PluginInsert> fanout;
1011 if (g_atomic_int_get (&_pending_process_reorder)) {
1012 /* we need to flush any pending re-order changes */
1013 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1014 apply_processor_changes_rt ();
1018 loc = find(_processors.begin(), _processors.end(), before);
1019 if (loc == _processors.end ()) {
1023 /* nothing specified - at end */
1024 loc = _processors.end ();
1027 if (others.empty()) {
1031 ProcessorList to_skip;
1033 // check if there's an instrument to replace or configure
1034 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1035 boost::shared_ptr<PluginInsert> pi;
1036 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) == 0) {
1039 if (!pi->plugin ()->get_info ()->is_instrument ()) {
1042 boost::shared_ptr<Processor> instrument = the_instrument ();
1043 ChanCount in (DataType::MIDI, 1);
1044 ChanCount out (DataType::AUDIO, 2); // XXX route's out?!
1046 PluginSetupOptions flags = None;
1048 flags |= CanReplace;
1049 in = instrument->input_streams ();
1050 out = instrument->output_streams ();
1052 if (pi->has_output_presets (in, out)) {
1056 pi->set_strict_io (_strict_io);
1058 if (is_auditioner()) {
1062 PluginSetupOptions mask = None;
1063 if (Config->get_ask_replace_instrument ()) {
1066 if (Config->get_ask_setup_instrument ()) {
1072 if (flags != None) {
1073 boost::optional<int> rv = PluginSetup (boost::dynamic_pointer_cast<Route>(shared_from_this ()), pi, flags); /* EMIT SIGNAL */
1074 int mode = rv.get_value_or (0);
1077 to_skip.push_back (*i); // don't add this one;
1080 replace_processor (instrument, *i, err);
1081 to_skip.push_back (*i);
1086 if ((mode & 5) == 4) {
1093 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1094 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1095 ProcessorState pstate (this);
1097 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1102 ProcessorList::iterator check = find (to_skip.begin(), to_skip.end(), *i);
1103 if (check != to_skip.end()) {
1107 boost::shared_ptr<PluginInsert> pi;
1109 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1110 pi->set_strict_io (_strict_io);
1114 /* Ensure that only one amp is in the list at any time */
1115 ProcessorList::iterator check = find (_processors.begin(), _processors.end(), *i);
1116 if (check != _processors.end()) {
1117 if (before == _amp) {
1118 /* Already in position; all is well */
1121 _processors.erase (check);
1126 assert (find (_processors.begin(), _processors.end(), *i) == _processors.end ());
1128 _processors.insert (loc, *i);
1129 (*i)->set_owner (this);
1132 if (configure_processors_unlocked (err, &lm)) {
1134 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
1139 if (pi && pi->has_sidechain ()) {
1140 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
1143 if ((*i)->active()) {
1144 // emit ActiveChanged() and latency_changed() if needed
1148 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1150 boost::shared_ptr<Send> send;
1151 if ((send = boost::dynamic_pointer_cast<Send> (*i))) {
1152 send->SelfDestruct.connect_same_thread (*this,
1153 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (*i)));
1157 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1158 boost::shared_ptr<PluginInsert> pi;
1160 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1161 if (pi->has_no_inputs ()) {
1162 _have_internal_generator = true;
1169 reset_instrument_info ();
1170 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1171 set_processor_positions ();
1173 if (fanout && fanout->configured ()
1174 && fanout->output_streams().n_audio() > 2
1175 && boost::dynamic_pointer_cast<PluginInsert> (the_instrument ()) == fanout) {
1176 fan_out (); /* EMIT SIGNAL */
1182 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1184 if (p == PreFader) {
1185 start = _processors.begin();
1186 end = find(_processors.begin(), _processors.end(), _amp);
1188 start = find(_processors.begin(), _processors.end(), _amp);
1190 end = _processors.end();
1194 /** Turn off all processors with a given placement
1195 * @param p Placement of processors to disable
1198 Route::disable_processors (Placement p)
1200 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1202 ProcessorList::iterator start, end;
1203 placement_range(p, start, end);
1205 for (ProcessorList::iterator i = start; i != end; ++i) {
1206 (*i)->enable (false);
1209 _session.set_dirty ();
1212 /** Turn off all redirects
1215 Route::disable_processors ()
1217 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1219 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1220 (*i)->enable (false);
1223 _session.set_dirty ();
1226 /** Turn off all redirects with a given placement
1227 * @param p Placement of redirects to disable
1230 Route::disable_plugins (Placement p)
1232 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1234 ProcessorList::iterator start, end;
1235 placement_range(p, start, end);
1237 for (ProcessorList::iterator i = start; i != end; ++i) {
1238 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1239 (*i)->enable (false);
1243 _session.set_dirty ();
1246 /** Turn off all plugins
1249 Route::disable_plugins ()
1251 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1253 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1254 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1255 (*i)->enable (false);
1259 _session.set_dirty ();
1264 Route::ab_plugins (bool forward)
1266 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1270 /* forward = turn off all active redirects, and mark them so that the next time
1271 we go the other way, we will revert them
1274 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1275 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1278 if (!(*i)->display_to_user ()) {
1282 if (boost::dynamic_pointer_cast<PluginInsert> (*i)->is_channelstrip()) {
1287 if ((*i)->enabled ()) {
1288 (*i)->enable (false);
1289 (*i)->set_next_ab_is_active (true);
1291 (*i)->set_next_ab_is_active (false);
1297 /* backward = if the redirect was marked to go active on the next ab, do so */
1299 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1300 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1303 if (!(*i)->display_to_user ()) {
1307 if (boost::dynamic_pointer_cast<PluginInsert> (*i)->is_channelstrip()) {
1312 (*i)->enable ((*i)->get_next_ab_is_active ());
1316 _session.set_dirty ();
1320 /** Remove processors with a given placement.
1321 * @param p Placement of processors to remove.
1324 Route::clear_processors (Placement p)
1326 if (!_session.engine().running()) {
1330 bool already_deleting = _session.deletion_in_progress();
1331 if (!already_deleting) {
1332 _session.set_deletion_in_progress();
1335 ProcessorList old_list = _processors;
1337 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1338 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1339 ProcessorList new_list;
1340 ProcessorStreams err;
1341 bool seen_amp = false;
1343 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1349 if (is_internal_processor (*i)) {
1351 /* you can't remove these */
1353 new_list.push_back (*i);
1360 new_list.push_back (*i);
1363 (*i)->drop_references ();
1371 (*i)->drop_references ();
1374 new_list.push_back (*i);
1381 _processors = new_list;
1382 configure_processors_unlocked (&err, &lm); // this can't fail
1384 /* drop references w/o process-lock (I/O procs may re-take it in ~IO() */
1387 processor_max_streams.reset();
1388 _have_internal_generator = false;
1389 reset_instrument_info ();
1390 set_processor_positions ();
1392 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1394 if (!already_deleting) {
1395 _session.clear_deletion_in_progress();
1400 Route::is_internal_processor (boost::shared_ptr<Processor> p) const
1402 if (p == _amp || p == _meter || p == _main_outs || p == _delayline || p == _trim || p == _polarity) {
1406 if (p == _ch_pre || p == _ch_post || p == _ch_eq || p == _ch_comp) {
1414 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err, bool need_process_lock)
1416 // TODO once the export point can be configured properly, do something smarter here
1417 if (processor == _capturing_processor) {
1418 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1419 if (need_process_lock) {
1423 _capturing_processor.reset();
1425 if (need_process_lock) {
1430 /* these can never be removed */
1432 if (is_internal_processor (processor)) {
1436 if (!_session.engine().running()) {
1440 processor_max_streams.reset();
1443 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1444 if (need_process_lock) {
1448 /* Caller must hold process lock */
1449 assert (!AudioEngine::instance()->process_lock().trylock());
1451 Glib::Threads::RWLock::WriterLock lm (_processor_lock); // XXX deadlock after export
1453 ProcessorState pstate (this);
1455 ProcessorList::iterator i;
1456 bool removed = false;
1458 for (i = _processors.begin(); i != _processors.end(); ) {
1459 if (*i == processor) {
1461 /* move along, see failure case for configure_processors()
1462 where we may need to reconfigure the processor.
1465 /* stop redirects that send signals to JACK ports
1466 from causing noise as a result of no longer being
1470 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor> (*i);
1471 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
1475 iop = pi->sidechain();
1482 i = _processors.erase (i);
1496 if (configure_processors_unlocked (err, &lm)) {
1498 /* we know this will work, because it worked before :) */
1499 configure_processors_unlocked (0, &lm);
1503 _have_internal_generator = false;
1505 for (i = _processors.begin(); i != _processors.end(); ++i) {
1506 boost::shared_ptr<PluginInsert> pi;
1508 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1509 if (pi->has_no_inputs ()) {
1510 _have_internal_generator = true;
1515 if (need_process_lock) {
1520 reset_instrument_info ();
1521 processor->drop_references ();
1522 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1523 set_processor_positions ();
1529 Route::replace_processor (boost::shared_ptr<Processor> old, boost::shared_ptr<Processor> sub, ProcessorStreams* err)
1531 /* these can never be removed */
1532 if (is_internal_processor (old)) {
1535 /* and can't be used as substitute, either */
1536 if (is_internal_processor (sub)) {
1540 /* I/Os are out, too */
1541 if (boost::dynamic_pointer_cast<IOProcessor> (old) || boost::dynamic_pointer_cast<IOProcessor> (sub)) {
1545 /* this function cannot be used to swap/reorder processors */
1546 if (find (_processors.begin(), _processors.end(), sub) != _processors.end ()) {
1550 if (!AudioEngine::instance()->running() || !old || !sub) {
1554 /* ensure that sub is not owned by another route */
1555 if (sub->owner ()) {
1560 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1561 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1562 ProcessorState pstate (this);
1564 assert (find (_processors.begin(), _processors.end(), sub) == _processors.end ());
1566 ProcessorList::iterator i;
1567 bool replaced = false;
1568 bool enable = old->enabled ();
1570 for (i = _processors.begin(); i != _processors.end(); ) {
1572 i = _processors.erase (i);
1573 _processors.insert (i, sub);
1574 sub->set_owner (this);
1587 boost::shared_ptr<PluginInsert> pi;
1588 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(sub)) != 0) {
1589 pi->set_strict_io (true);
1593 if (configure_processors_unlocked (err, &lm)) {
1595 configure_processors_unlocked (0, &lm);
1599 _have_internal_generator = false;
1601 for (i = _processors.begin(); i != _processors.end(); ++i) {
1602 boost::shared_ptr<PluginInsert> pi;
1603 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1604 if (pi->has_no_inputs ()) {
1605 _have_internal_generator = true;
1615 sub->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1618 reset_instrument_info ();
1619 old->drop_references ();
1620 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1621 set_processor_positions ();
1626 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1628 ProcessorList deleted;
1630 if (!_session.engine().running()) {
1634 processor_max_streams.reset();
1637 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1638 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1639 ProcessorState pstate (this);
1641 ProcessorList::iterator i;
1642 boost::shared_ptr<Processor> processor;
1644 for (i = _processors.begin(); i != _processors.end(); ) {
1648 /* these can never be removed */
1650 if (is_internal_processor (processor)) {
1655 /* see if its in the list of processors to delete */
1657 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1662 /* stop IOProcessors that send to JACK ports
1663 from causing noise as a result of no longer being
1667 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(processor);
1668 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
1671 iop = pi->sidechain();
1678 deleted.push_back (processor);
1679 i = _processors.erase (i);
1682 if (deleted.empty()) {
1683 /* none of those in the requested list were found */
1687 if (configure_processors_unlocked (err, &lm)) {
1689 /* we know this will work, because it worked before :) */
1690 configure_processors_unlocked (0, &lm);
1695 _have_internal_generator = false;
1697 for (i = _processors.begin(); i != _processors.end(); ++i) {
1698 boost::shared_ptr<PluginInsert> pi;
1700 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1701 if (pi->has_no_inputs ()) {
1702 _have_internal_generator = true;
1709 /* now try to do what we need to so that those that were removed will be deleted */
1711 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1712 (*i)->drop_references ();
1715 reset_instrument_info ();
1716 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1717 set_processor_positions ();
1723 Route::reset_instrument_info ()
1725 boost::shared_ptr<Processor> instr = the_instrument();
1727 _instrument_info.set_internal_instrument (instr);
1731 /** Caller must hold process lock */
1733 Route::configure_processors (ProcessorStreams* err)
1735 #ifndef PLATFORM_WINDOWS
1736 assert (!AudioEngine::instance()->process_lock().trylock());
1739 if (!_in_configure_processors) {
1740 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1741 return configure_processors_unlocked (err, &lm);
1748 Route::input_streams () const
1750 return _input->n_ports ();
1753 list<pair<ChanCount, ChanCount> >
1754 Route::try_configure_processors (ChanCount in, ProcessorStreams* err)
1756 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1758 return try_configure_processors_unlocked (in, err);
1761 list<pair<ChanCount, ChanCount> >
1762 Route::try_configure_processors_unlocked (ChanCount in, ProcessorStreams* err)
1764 // Check each processor in order to see if we can configure as requested
1766 list<pair<ChanCount, ChanCount> > configuration;
1769 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1770 DEBUG_TRACE (DEBUG::Processors, "{\n");
1772 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1774 if ((*p)->can_support_io_configuration(in, out)) {
1776 if (boost::dynamic_pointer_cast<Delivery> (*p)
1777 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main
1779 && (is_monitor() || _strict_io || Profile->get_mixbus ())) {
1780 /* with strict I/O the panner + output are forced to
1781 * follow the last processor's output.
1783 * Delivery::can_support_io_configuration() will only add ports,
1784 * but not remove excess ports.
1786 * This works because the delivery only requires
1787 * as many outputs as there are inputs.
1788 * Delivery::configure_io() will do the actual removal
1789 * by calling _output->ensure_io()
1791 if (!is_master() && _session.master_out () && in.n_audio() > 0) {
1792 /* ..but at least as many as there are master-inputs, if
1793 * the delivery is dealing with audio */
1794 // XXX this may need special-casing for mixbus (master-outputs)
1795 // and should maybe be a preference anyway ?!
1796 out = ChanCount::max (in, _session.master_out ()->n_inputs ());
1802 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID=%2 in=%3 out=%4\n",(*p)->name(), (*p)->id(), in, out));
1803 configuration.push_back(make_pair(in, out));
1806 // restriction for Monitor Section Processors
1807 if (in.n_audio() != out.n_audio() || out.n_midi() > 0) {
1808 /* Note: The Monitor follows the master-bus and has no panner.
1810 * The general idea is to only allow plugins that retain the channel-count
1811 * and plugins with MIDI in (e.g VSTs with control that will remain unconnected).
1812 * Then again 5.1 in, monitor stereo is a valid use-case.
1814 * and worse: we only refuse adding plugins *here*.
1816 * 1) stereo-master, stereo-mon, add a stereo-plugin, OK
1817 * 2) change master-bus, add a channel
1818 * 2a) monitor-secion follows
1819 * 3) monitor processors fail to re-reconfigure (stereo plugin)
1820 * 4) re-load session, monitor-processor remains unconfigured, crash.
1822 DEBUG_TRACE (DEBUG::Processors, "Monitor: Channel configuration change.\n");
1824 if (boost::dynamic_pointer_cast<InternalSend> (*p)) {
1825 // internal sends make no sense, only feedback
1826 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1827 return list<pair<ChanCount, ChanCount> > ();
1829 if (boost::dynamic_pointer_cast<PortInsert> (*p)) {
1830 /* External Sends can be problematic. one can add/remove ports
1831 * there signal leaves the DAW to external monitors anyway, so there's
1832 * no real use for allowing them here anyway.
1834 DEBUG_TRACE (DEBUG::Processors, "Monitor: No External Sends allowed.\n");
1835 return list<pair<ChanCount, ChanCount> > ();
1837 if (boost::dynamic_pointer_cast<Send> (*p)) {
1839 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1840 return list<pair<ChanCount, ChanCount> > ();
1849 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
1850 DEBUG_TRACE (DEBUG::Processors, string_compose ("---- %1 cannot support in=%2 out=%3\n", (*p)->name(), in, out));
1851 DEBUG_TRACE (DEBUG::Processors, "}\n");
1852 return list<pair<ChanCount, ChanCount> > ();
1856 DEBUG_TRACE (DEBUG::Processors, "}\n");
1858 return configuration;
1861 /** Set the input/output configuration of each processor in the processors list.
1862 * Caller must hold process lock.
1863 * Return 0 on success, otherwise configuration is impossible.
1866 Route::configure_processors_unlocked (ProcessorStreams* err, Glib::Threads::RWLock::WriterLock* lm)
1868 #ifndef PLATFORM_WINDOWS
1869 assert (!AudioEngine::instance()->process_lock().trylock());
1872 if (_in_configure_processors) {
1876 /* put invisible processors where they should be */
1877 setup_invisible_processors ();
1879 _in_configure_processors = true;
1881 list<pair<ChanCount, ChanCount> > configuration = try_configure_processors_unlocked (input_streams (), err);
1883 if (configuration.empty ()) {
1884 _in_configure_processors = false;
1889 bool seen_mains_out = false;
1890 processor_out_streams = _input->n_ports();
1891 processor_max_streams.reset();
1893 /* processor configure_io() may result in adding ports
1894 * e.g. Delivery::configure_io -> ARDOUR::IO::ensure_io ()
1896 * with jack2 adding ports results in a graph-order callback,
1897 * which calls Session::resort_routes() and eventually
1898 * Route::direct_feeds_according_to_reality()
1899 * which takes a ReaderLock (_processor_lock).
1901 * so we can't hold a WriterLock here until jack2 threading
1904 * NB. we still hold the process lock
1906 * (ardour's own engines do call graph-order from the
1907 * process-thread and hence do not have this issue; besides
1908 * merely adding ports won't trigger a graph-order, only
1909 * making connections does)
1913 // TODO check for a potential ReaderLock after ReaderLock ??
1914 Glib::Threads::RWLock::ReaderLock lr (_processor_lock);
1916 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1917 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1919 if (!(*p)->configure_io(c->first, c->second)) {
1920 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration failed\n", _name));
1921 _in_configure_processors = false;
1927 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1928 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1930 boost::shared_ptr<IOProcessor> iop;
1931 boost::shared_ptr<PluginInsert> pi;
1932 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
1933 /* plugins connected via Split or Hide Match may have more channels.
1934 * route/scratch buffers are needed for all of them
1935 * The configuration may only be a subset (both input and output)
1937 processor_max_streams = ChanCount::max(processor_max_streams, pi->required_buffers());
1939 else if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*p)) != 0) {
1940 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_input_streams());
1941 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_output_streams());
1945 if (boost::dynamic_pointer_cast<Delivery> (*p)
1946 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main) {
1947 /* main delivery will increase port count to match input.
1948 * the Delivery::Main is usually the last processor - followed only by
1951 seen_mains_out = true;
1953 if (!seen_mains_out) {
1954 processor_out_streams = out;
1963 _meter->set_max_channels (processor_max_streams);
1966 /* make sure we have sufficient scratch buffers to cope with the new processor
1969 _session.ensure_buffers (n_process_buffers ());
1971 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration complete\n", _name));
1973 _in_configure_processors = false;
1977 /** Set all visible processors to a given active state (except Fader, whose state is not changed)
1978 * @param state New active state for those processors.
1981 Route::all_visible_processors_active (bool state)
1983 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1985 if (_processors.empty()) {
1989 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1990 if (!(*i)->display_to_user() || boost::dynamic_pointer_cast<Amp> (*i)) {
1994 boost::shared_ptr<PluginInsert> pi;
1995 if (0 != (pi = boost::dynamic_pointer_cast<PluginInsert>(*i))) {
1996 if (pi->is_channelstrip ()) {
2001 (*i)->enable (state);
2004 _session.set_dirty ();
2008 Route::processors_reorder_needs_configure (const ProcessorList& new_order)
2010 /* check if re-order requires re-configuration of any processors
2011 * -> compare channel configuration for all processors
2013 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2014 ChanCount c = input_streams ();
2016 for (ProcessorList::const_iterator j = new_order.begin(); j != new_order.end(); ++j) {
2018 if (c != (*j)->input_streams()) {
2021 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2024 if ((*i)->input_streams() != c) {
2027 c = (*i)->output_streams();
2039 __attribute__((annotate("realtime")))
2042 Route::apply_processor_order (const ProcessorList& new_order)
2044 /* need to hold processor_lock; either read or write lock
2045 * and the engine process_lock.
2046 * Due to r/w lock ambiguity we can only assert the latter
2048 assert (!AudioEngine::instance()->process_lock().trylock());
2051 /* "new_order" is an ordered list of processors to be positioned according to "placement".
2052 * NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
2053 * processors in the current actual processor list that are hidden. Any visible processors
2054 * in the current list but not in "new_order" will be assumed to be deleted.
2057 /* "as_it_will_be" and "_processors" are lists of shared pointers.
2058 * actual memory usage is small, but insert/erase is not actually rt-safe :(
2059 * (note though that ::processors_reorder_needs_configure() ensured that
2060 * this function will only ever be called from the rt-thread if no processor were removed)
2062 * either way, I can't proove it, but an x-run due to re-order here is less likley
2063 * than an x-run-less 'ardour-silent cycle' both of which effectively "click".
2066 ProcessorList as_it_will_be;
2067 ProcessorList::iterator oiter;
2068 ProcessorList::const_iterator niter;
2070 oiter = _processors.begin();
2071 niter = new_order.begin();
2073 while (niter != new_order.end()) {
2075 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
2076 then append it to the temp list.
2078 Otherwise, see if the next processor in the old list is in the new list. if not,
2079 its been deleted. If its there, append it to the temp list.
2082 if (oiter == _processors.end()) {
2084 /* no more elements in the old list, so just stick the rest of
2085 the new order onto the temp list.
2088 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
2089 while (niter != new_order.end()) {
2096 if (!(*oiter)->display_to_user()) {
2098 as_it_will_be.push_back (*oiter);
2102 /* visible processor: check that its in the new order */
2104 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
2105 /* deleted: do nothing, shared_ptr<> will clean up */
2107 /* ignore this one, and add the next item from the new order instead */
2108 as_it_will_be.push_back (*niter);
2113 /* now remove from old order - its taken care of no matter what */
2114 oiter = _processors.erase (oiter);
2118 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
2120 /* If the meter is in a custom position, find it and make a rough note of its position */
2121 maybe_note_meter_position ();
2125 Route::move_instrument_down (bool postfader)
2127 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2128 ProcessorList new_order;
2129 boost::shared_ptr<Processor> instrument;
2130 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2131 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
2132 if (pi && pi->plugin ()->get_info ()->is_instrument ()) {
2134 } else if (instrument && *i == _amp) {
2136 new_order.push_back (*i);
2137 new_order.push_back (instrument);
2139 new_order.push_back (instrument);
2140 new_order.push_back (*i);
2143 new_order.push_back (*i);
2150 reorder_processors (new_order, 0);
2154 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
2156 // it a change is already queued, wait for it
2157 // (unless engine is stopped. apply immediately and proceed
2158 while (g_atomic_int_get (&_pending_process_reorder)) {
2159 if (!AudioEngine::instance()->running()) {
2160 DEBUG_TRACE (DEBUG::Processors, "offline apply queued processor re-order.\n");
2161 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2163 apply_processor_order(_pending_processor_order);
2164 setup_invisible_processors ();
2166 g_atomic_int_set (&_pending_process_reorder, 0);
2168 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2169 set_processor_positions ();
2171 // TODO rather use a semaphore or something.
2172 // but since ::reorder_processors() is called
2173 // from the GUI thread, this is fine..
2178 if (processors_reorder_needs_configure (new_order) || !AudioEngine::instance()->running()) {
2180 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2181 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2182 ProcessorState pstate (this);
2184 apply_processor_order (new_order);
2186 if (configure_processors_unlocked (err, &lm)) {
2194 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2195 set_processor_positions ();
2198 DEBUG_TRACE (DEBUG::Processors, "Queue clickless processor re-order.\n");
2199 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2201 // _pending_processor_order is protected by _processor_lock
2202 _pending_processor_order = new_order;
2203 g_atomic_int_set (&_pending_process_reorder, 1);
2206 /* update processor input/output latency
2207 * (total signal_latency does not change)
2209 update_signal_latency (true);
2215 Route::add_remove_sidechain (boost::shared_ptr<Processor> proc, bool add)
2217 if (_session.actively_recording ()) {
2221 boost::shared_ptr<PluginInsert> pi;
2222 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2226 if (pi->has_sidechain () == add) {
2227 return true; // ?? call failed, but result is as expected.
2231 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2232 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2233 if (i == _processors.end ()) {
2239 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ()); // take before Writerlock to avoid deadlock
2240 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2241 PBD::Unwinder<bool> uw (_in_sidechain_setup, true);
2243 lx.release (); // IO::add_port() and ~IO takes process lock - XXX check if this is safe
2245 if (!pi->add_sidechain ()) {
2249 if (!pi->del_sidechain ()) {
2255 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2260 pi->del_sidechain ();
2262 pi->add_sidechain ();
2263 // TODO restore side-chain's state.
2268 configure_processors_unlocked (0, &lm);
2271 if (pi->has_sidechain ()) {
2272 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
2275 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2276 _session.set_dirty ();
2281 Route::plugin_preset_output (boost::shared_ptr<Processor> proc, ChanCount outs)
2283 if (_session.actively_recording ()) {
2287 boost::shared_ptr<PluginInsert> pi;
2288 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2293 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2294 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2295 if (i == _processors.end ()) {
2301 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2302 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2304 const ChanCount& old (pi->preset_out ());
2305 if (!pi->set_preset_out (outs)) {
2306 return true; // no change, OK
2309 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2312 pi->set_preset_out (old);
2315 configure_processors_unlocked (0, &lm);
2318 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2319 _session.set_dirty ();
2324 Route::reset_plugin_insert (boost::shared_ptr<Processor> proc)
2327 return customize_plugin_insert (proc, 0, unused, unused);
2331 Route::customize_plugin_insert (boost::shared_ptr<Processor> proc, uint32_t count, ChanCount outs, ChanCount sinks)
2333 if (_session.actively_recording ()) {
2336 boost::shared_ptr<PluginInsert> pi;
2337 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2342 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2343 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2344 if (i == _processors.end ()) {
2350 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2351 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2353 bool old_cust = pi->custom_cfg ();
2354 uint32_t old_cnt = pi->get_count ();
2355 ChanCount old_chan = pi->output_streams ();
2356 ChanCount old_sinks = pi->natural_input_streams ();
2359 pi->set_custom_cfg (false);
2361 pi->set_custom_cfg (true);
2362 pi->set_count (count);
2363 pi->set_outputs (outs);
2364 pi->set_sinks (sinks);
2367 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2371 pi->set_count (old_cnt);
2372 pi->set_sinks (old_sinks);
2373 pi->set_outputs (old_chan);
2374 pi->set_custom_cfg (old_cust);
2378 configure_processors_unlocked (0, &lm);
2381 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2382 _session.set_dirty ();
2387 Route::set_strict_io (const bool enable)
2389 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2391 if (_strict_io != enable) {
2392 _strict_io = enable;
2393 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2394 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2395 boost::shared_ptr<PluginInsert> pi;
2396 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2397 pi->set_strict_io (_strict_io);
2401 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2405 _strict_io = !enable; // restore old value
2406 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2407 boost::shared_ptr<PluginInsert> pi;
2408 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2409 pi->set_strict_io (_strict_io);
2416 configure_processors (0);
2419 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2420 _session.set_dirty ();
2428 return state (false);
2432 Route::get_template()
2434 return state (true);
2438 Route::state (bool save_template)
2440 if (!_session._template_state_dir.empty()) {
2441 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), _session._template_state_dir));
2444 XMLNode *node = new XMLNode("Route");
2445 ProcessorList::iterator i;
2448 XMLNode* child = node->add_child("ProgramVersion");
2449 child->set_property("created-with", _session.created_with);
2451 std::string modified_with = string_compose ("%1 %2", PROGRAM_NAME, revision);
2452 child->set_property("modified-with", modified_with);
2455 node->set_property (X_("id"), id ());
2456 node->set_property (X_("name"), name());
2457 node->set_property (X_("default-type"), _default_type);
2458 node->set_property (X_("strict-io"), _strict_io);
2460 node->add_child_nocopy (_presentation_info.get_state());
2462 node->set_property (X_("active"), _active);
2463 node->set_property (X_("denormal-protection"), _denormal_protection);
2464 node->set_property (X_("meter-point"), _meter_point);
2465 node->set_property (X_("disk-io-point"), _disk_io_point);
2467 node->set_property (X_("meter-type"), _meter->meter_type ());
2470 node->set_property (X_("route-group"), _route_group->name());
2473 node->add_child_nocopy (_solo_control->get_state ());
2474 node->add_child_nocopy (_solo_isolate_control->get_state ());
2475 node->add_child_nocopy (_solo_safe_control->get_state ());
2477 node->add_child_nocopy (_input->get_state ());
2478 node->add_child_nocopy (_output->get_state ());
2479 node->add_child_nocopy (_mute_master->get_state ());
2481 node->add_child_nocopy (_mute_control->get_state ());
2482 node->add_child_nocopy (_phase_control->get_state ());
2484 if (!skip_saving_automation) {
2485 node->add_child_nocopy (Automatable::get_automation_xml_state ());
2488 if (_comment.length()) {
2489 XMLNode *cmt = node->add_child ("Comment");
2490 cmt->add_content (_comment);
2494 node->add_child_nocopy (_pannable->get_state ());
2498 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2499 for (i = _processors.begin(); i != _processors.end(); ++i) {
2500 if (*i == _delayline) {
2503 if (save_template) {
2504 /* template save: do not include internal sends functioning as
2505 aux sends because the chance of the target ID
2506 in the session where this template is used
2509 similarly, do not save listen sends which connect to
2510 the monitor section, because these will always be
2513 boost::shared_ptr<InternalSend> is;
2515 if ((is = boost::dynamic_pointer_cast<InternalSend> (*i)) != 0) {
2516 if (is->role() == Delivery::Listen) {
2521 node->add_child_nocopy((*i)->get_state ());
2526 node->add_child_copy (*_extra_xml);
2529 if (_custom_meter_position_noted) {
2530 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
2532 node->set_property (X_("processor-after-last-custom-meter"), after->id());
2536 if (!_session._template_state_dir.empty()) {
2537 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), ""));
2540 node->add_child_copy (Slavable::get_state());
2546 Route::set_state (const XMLNode& node, int version)
2548 if (version < 3000) {
2549 return set_state_2X (node, version);
2553 XMLNodeConstIterator niter;
2556 if (node.name() != "Route"){
2557 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2561 std::string route_name;
2562 if (node.get_property (X_("name"), route_name)) {
2563 Route::set_name (route_name);
2567 _initial_io_setup = true;
2569 Stripable::set_state (node, version);
2571 node.get_property (X_("strict-io"), _strict_io);
2574 /* monitor bus does not get a panner, but if (re)created
2575 via XML, it will already have one by the time we
2576 call ::set_state(). so ... remove it.
2581 /* add all processors (except amp, which is always present) */
2583 nlist = node.children();
2584 XMLNode processor_state (X_("processor_state"));
2586 Stateful::save_extra_xml (node);
2588 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2592 if (child->name() == IO::state_node_name) {
2593 std::string direction;
2594 if (!child->get_property (X_("direction"), direction)) {
2598 if (direction == "Input") {
2599 _input->set_state (*child, version);
2600 } else if (direction == "Output") {
2601 _output->set_state (*child, version);
2604 } else if (child->name() == X_("Processor")) {
2605 processor_state.add_child_copy (*child);
2606 } else if (child->name() == X_("Pannable")) {
2608 _pannable->set_state (*child, version);
2610 warning << string_compose (_("Pannable state found for route (%1) without a panner!"), name()) << endmsg;
2612 } else if (child->name() == Slavable::xml_node_name) {
2613 Slavable::set_state (*child, version);
2618 if (node.get_property (X_("meter-point"), mp)) {
2619 set_meter_point (mp, true);
2621 _meter->set_display_to_user (_meter_point == MeterCustom);
2626 if (node.get_property (X_("disk-io-point"), diop)) {
2628 _disk_writer->set_display_to_user (diop == DiskIOCustom);
2631 _disk_reader->set_display_to_user (diop == DiskIOCustom);
2633 set_disk_io_point (diop);
2636 MeterType meter_type;
2637 if (node.get_property (X_("meter-type"), meter_type)) {
2638 set_meter_type (meter_type);
2641 _initial_io_setup = false;
2643 set_processor_state (processor_state);
2645 // this looks up the internal instrument in processors
2646 reset_instrument_info();
2648 bool denormal_protection;
2649 if (node.get_property (X_("denormal-protection"), denormal_protection)) {
2650 set_denormal_protection (denormal_protection);
2653 /* convert old 3001 state */
2654 std::string phase_invert_str;
2655 if (node.get_property (X_("phase-invert"), phase_invert_str)) {
2656 _phase_control->set_phase_invert (boost::dynamic_bitset<> (phase_invert_str));
2660 if (node.get_property (X_("active"), is_active)) {
2661 set_active (is_active, this);
2664 std::string id_string;
2665 if (node.get_property (X_("processor-after-last-custom-meter"), id_string)) {
2666 PBD::ID id (id_string);
2667 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2668 ProcessorList::const_iterator i = _processors.begin ();
2669 while (i != _processors.end() && (*i)->id() != id) {
2673 if (i != _processors.end ()) {
2674 _processor_after_last_custom_meter = *i;
2675 _custom_meter_position_noted = true;
2679 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2682 if (child->name() == X_("Comment")) {
2684 /* XXX this is a terrible API design in libxml++ */
2686 XMLNode *cmt = *(child->children().begin());
2687 _comment = cmt->content();
2689 } else if (child->name() == Controllable::xml_node_name) {
2690 std::string control_name;
2691 if (!child->get_property (X_("name"), control_name)) {
2695 if (control_name == _solo_control->name()) {
2696 _solo_control->set_state (*child, version);
2697 } else if (control_name == _solo_safe_control->name()) {
2698 _solo_safe_control->set_state (*child, version);
2699 } else if (control_name == _solo_isolate_control->name()) {
2700 _solo_isolate_control->set_state (*child, version);
2701 } else if (control_name == _mute_control->name()) {
2702 _mute_control->set_state (*child, version);
2703 } else if (control_name == _phase_control->name()) {
2704 _phase_control->set_state (*child, version);
2706 Evoral::Parameter p = EventTypeMap::instance().from_symbol (control_name);
2707 if (p.type () >= MidiCCAutomation && p.type () < MidiSystemExclusiveAutomation) {
2708 boost::shared_ptr<AutomationControl> ac = automation_control (p, true);
2710 ac->set_state (*child, version);
2714 } else if (child->name() == MuteMaster::xml_node_name) {
2715 _mute_master->set_state (*child, version);
2717 } else if (child->name() == Automatable::xml_node_name) {
2718 set_automation_xml_state (*child, Evoral::Parameter(NullAutomation));
2723 _delayline->set_name (name ());
2730 Route::set_state_2X (const XMLNode& node, int version)
2734 XMLNodeConstIterator niter;
2736 XMLProperty const * prop;
2738 /* 2X things which still remain to be handled:
2744 if (node.name() != "Route") {
2745 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2749 Stripable::set_state (node, version);
2751 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2752 set_denormal_protection (string_to<bool> (prop->value()));
2755 if ((prop = node.property (X_("muted"))) != 0) {
2758 bool muted = string_to<bool> (prop->value());
2764 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2766 if (string_to<bool> (prop->value())){
2767 mute_point = mute_point + "PreFader";
2772 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2774 if (string_to<bool> (prop->value())){
2777 mute_point = mute_point + ",";
2780 mute_point = mute_point + "PostFader";
2785 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2787 if (string_to<bool> (prop->value())){
2790 mute_point = mute_point + ",";
2793 mute_point = mute_point + "Listen";
2798 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2800 if (string_to<bool> (prop->value())){
2803 mute_point = mute_point + ",";
2806 mute_point = mute_point + "Main";
2810 _mute_master->set_mute_points (mute_point);
2811 _mute_master->set_muted_by_self (true);
2815 if ((prop = node.property (X_("meter-point"))) != 0) {
2816 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2821 nlist = node.children ();
2822 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2826 if (child->name() == IO::state_node_name) {
2828 /* there is a note in IO::set_state_2X() about why we have to call
2832 _input->set_state_2X (*child, version, true);
2833 _output->set_state_2X (*child, version, false);
2835 if ((prop = child->property (X_("name"))) != 0) {
2836 Route::set_name (prop->value ());
2841 if ((prop = child->property (X_("active"))) != 0) {
2842 bool yn = string_to<bool> (prop->value());
2843 _active = !yn; // force switch
2844 set_active (yn, this);
2847 if ((prop = child->property (X_("gain"))) != 0) {
2850 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
2851 _amp->gain_control()->set_value (val, Controllable::NoGroup);
2855 /* Set up Panners in the IO */
2856 XMLNodeList io_nlist = child->children ();
2858 XMLNodeConstIterator io_niter;
2861 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
2863 io_child = *io_niter;
2865 if (io_child->name() == X_("Panner")) {
2866 _main_outs->panner_shell()->set_state(*io_child, version);
2867 } else if (io_child->name() == X_("Automation")) {
2868 /* IO's automation is for the fader */
2869 _amp->set_automation_xml_state (*io_child, Evoral::Parameter (GainAutomation));
2875 XMLNodeList redirect_nodes;
2877 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2881 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2882 redirect_nodes.push_back(child);
2887 set_processor_state_2X (redirect_nodes, version);
2889 Stateful::save_extra_xml (node);
2891 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2894 if (child->name() == X_("Comment")) {
2896 /* XXX this is a terrible API design in libxml++ */
2898 XMLNode *cmt = *(child->children().begin());
2899 _comment = cmt->content();
2901 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2902 if (prop->value() == X_("solo")) {
2903 _solo_control->set_state (*child, version);
2904 } else if (prop->value() == X_("mute")) {
2905 _mute_control->set_state (*child, version);
2915 Route::get_processor_state ()
2917 XMLNode* root = new XMLNode (X_("redirects"));
2918 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2919 root->add_child_nocopy ((*i)->get_state ());
2926 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2928 /* We don't bother removing existing processors not in nList, as this
2929 method will only be called when creating a Route from scratch, not
2930 for undo purposes. Just put processors in at the appropriate place
2934 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2935 add_processor_from_xml_2X (**i, version);
2940 Route::set_processor_state (const XMLNode& node)
2942 const XMLNodeList &nlist = node.children();
2943 XMLNodeConstIterator niter;
2944 ProcessorList new_order;
2945 bool must_configure = false;
2947 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2949 XMLProperty* prop = (*niter)->property ("type");
2951 if (prop->value() == "amp") {
2952 _amp->set_state (**niter, Stateful::current_state_version);
2953 new_order.push_back (_amp);
2954 } else if (prop->value() == "trim") {
2955 _trim->set_state (**niter, Stateful::current_state_version);
2956 new_order.push_back (_trim);
2957 } else if (prop->value() == "meter") {
2958 _meter->set_state (**niter, Stateful::current_state_version);
2959 new_order.push_back (_meter);
2960 } else if (prop->value() == "polarity") {
2961 _polarity->set_state (**niter, Stateful::current_state_version);
2962 new_order.push_back (_polarity);
2963 } else if (prop->value() == "delay") {
2965 } else if (prop->value() == "main-outs") {
2966 _main_outs->set_state (**niter, Stateful::current_state_version);
2967 } else if (prop->value() == "intreturn") {
2969 _intreturn.reset (new InternalReturn (_session));
2970 must_configure = true;
2972 _intreturn->set_state (**niter, Stateful::current_state_version);
2973 } else if (is_monitor() && prop->value() == "monitor") {
2974 if (!_monitor_control) {
2975 _monitor_control.reset (new MonitorProcessor (_session));
2976 must_configure = true;
2978 _monitor_control->set_state (**niter, Stateful::current_state_version);
2979 } else if (prop->value() == "capture") {
2980 /* CapturingProcessor should never be restored, it's always
2981 added explicitly when needed */
2982 } else if (prop->value() == "diskreader" && _disk_reader) {
2983 _disk_reader->set_state (**niter, Stateful::current_state_version);
2984 new_order.push_back (_disk_reader);
2985 } else if (prop->value() == "diskwriter" && _disk_writer) {
2986 _disk_writer->set_state (**niter, Stateful::current_state_version);
2987 new_order.push_back (_disk_writer);
2989 set_processor_state (**niter, prop, new_order, must_configure);
2993 ProcessorList old_list = _processors; // keep a copy
2995 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2996 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2997 /* re-assign _processors w/o process-lock.
2998 * if there's an IO-processor present in _processors but
2999 * not in new_order, it will be deleted and ~IO takes
3002 _processors = new_order;
3004 /* When a required/existing internal processor is not in the list, it needs to
3005 * be added via configure_processors() -> setup_invisible_processors()
3007 if (_monitor_control) {
3008 must_configure |= find (_processors.begin(), _processors.end(), _monitor_control) == _processors.end ();
3011 must_configure |= find (_processors.begin(), _processors.end(), _main_outs) == _processors.end ();
3014 must_configure |= find (_processors.begin(), _processors.end(), _delayline) == _processors.end ();
3017 must_configure |= find (_processors.begin(), _processors.end(), _intreturn) == _processors.end ();
3020 if (must_configure && !_session.loading()) {
3021 configure_processors_unlocked (0, &lm);
3024 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3026 (*i)->set_owner (this);
3027 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
3029 boost::shared_ptr<PluginInsert> pi;
3031 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
3032 if (pi->has_no_inputs ()) {
3033 _have_internal_generator = true;
3039 /* drop references w/o process-lock (I/O procs may re-take it in ~IO() */
3042 reset_instrument_info ();
3043 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3044 set_processor_positions ();
3048 Route::set_processor_state (XMLNode const & node, XMLProperty const* prop, ProcessorList& new_order, bool& must_configure)
3050 ProcessorList::iterator o;
3052 for (o = _processors.begin(); o != _processors.end(); ++o) {
3053 XMLProperty const * id_prop = node.property(X_("id"));
3054 if (id_prop && (*o)->id() == id_prop->value()) {
3055 (*o)->set_state (node, Stateful::current_state_version);
3056 new_order.push_back (*o);
3061 // If the processor (node) is not on the route then create it
3063 if (o == _processors.end()) {
3065 boost::shared_ptr<Processor> processor;
3067 if (prop->value() == "intsend") {
3069 processor.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), boost::shared_ptr<Route>(), Delivery::Aux, true));
3071 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
3072 prop->value() == "lv2" ||
3073 prop->value() == "windows-vst" ||
3074 prop->value() == "mac-vst" ||
3075 prop->value() == "lxvst" ||
3076 prop->value() == "luaproc" ||
3077 prop->value() == "audiounit") {
3079 if (_session.get_disable_all_loaded_plugins ()) {
3080 processor.reset (new UnknownProcessor (_session, node));
3082 processor.reset (new PluginInsert (_session));
3083 processor->set_owner (this);
3085 } else if (prop->value() == "port") {
3087 processor.reset (new PortInsert (_session, _pannable, _mute_master));
3089 } else if (prop->value() == "send") {
3091 processor.reset (new Send (_session, _pannable, _mute_master, Delivery::Send, true));
3092 boost::shared_ptr<Send> send = boost::dynamic_pointer_cast<Send> (processor);
3093 send->SelfDestruct.connect_same_thread (*this,
3094 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (processor)));
3097 warning << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
3101 if (processor->set_state (node, Stateful::current_state_version) != 0) {
3102 /* This processor could not be configured. Turn it into a UnknownProcessor */
3103 processor.reset (new UnknownProcessor (_session, node));
3106 /* set strict I/O only after loading plugin state, because
3107 * individual plugins may override this */
3108 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
3109 if (pi && _strict_io) {
3110 pi->set_strict_io (true);
3113 /* subscribe to Sidechain IO changes */
3114 if (pi && pi->has_sidechain ()) {
3115 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
3118 /* we have to note the monitor send here, otherwise a new one will be created
3119 and the state of this one will be lost.
3121 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
3122 if (isend && isend->role() == Delivery::Listen) {
3123 _monitor_send = isend;
3126 /* it doesn't matter if invisible processors are added here, as they
3127 will be sorted out by setup_invisible_processors () shortly.
3130 new_order.push_back (processor);
3131 must_configure = true;
3137 Route::silence (samplecnt_t nframes)
3139 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3144 silence_unlocked (nframes);
3148 Route::silence_unlocked (samplecnt_t nframes)
3150 /* Must be called with the processor lock held */
3152 const samplepos_t now = _session.transport_sample ();
3154 _output->silence (nframes);
3156 // update owned automated controllables
3157 automation_run (now, nframes);
3159 _pannable->automation_run (now, nframes);
3162 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3163 boost::shared_ptr<PluginInsert> pi;
3165 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
3166 /* evaluate automated automation controls */
3167 pi->automation_run (now, nframes);
3168 /* skip plugins, they don't need anything when we're not active */
3172 (*i)->silence (nframes, now);
3177 Route::add_internal_return ()
3180 _intreturn.reset (new InternalReturn (_session));
3181 add_processor (_intreturn, PreFader);
3186 Route::add_send_to_internal_return (InternalSend* send)
3188 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3190 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3191 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3194 return d->add_send (send);
3200 Route::remove_send_from_internal_return (InternalSend* send)
3202 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3204 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3205 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3208 return d->remove_send (send);
3214 Route::enable_monitor_send ()
3216 /* Caller must hold process lock */
3217 assert (!AudioEngine::instance()->process_lock().trylock());
3219 /* master never sends to monitor section via the normal mechanism */
3220 assert (!is_master ());
3221 assert (!is_monitor ());
3223 /* make sure we have one */
3224 if (!_monitor_send) {
3225 _monitor_send.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), _session.monitor_out(), Delivery::Listen));
3226 _monitor_send->set_display_to_user (false);
3230 configure_processors (0);
3233 /** Add an aux send to a route.
3234 * @param route route to send to.
3235 * @param before Processor to insert before, or 0 to insert at the end.
3238 Route::add_aux_send (boost::shared_ptr<Route> route, boost::shared_ptr<Processor> before)
3240 assert (route != _session.monitor_out ());
3243 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3245 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3247 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend> (*x);
3249 if (d && d->target_route() == route) {
3250 /* already listening via the specified IO: do nothing */
3258 boost::shared_ptr<InternalSend> listener;
3261 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
3262 listener.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), route, Delivery::Aux));
3265 add_processor (listener, before);
3267 } catch (failed_constructor& err) {
3275 Route::add_foldback_send (boost::shared_ptr<Route> route)
3277 assert (route != _session.monitor_out ());
3278 boost::shared_ptr<Processor> before = before_processor_for_placement (PreFader);
3281 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3283 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3285 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend> (*x);
3287 if (d && d->target_route() == route) {
3288 /* already listening via the specified IO: do nothing */
3296 boost::shared_ptr<InternalSend> listener;
3299 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
3300 listener.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), route, Delivery::Foldback));
3303 listener->panner_shell()->set_linked_to_route (false);
3304 add_processor (listener, before);
3306 } catch (failed_constructor& err) {
3309 _session.FBSendsChanged ();
3315 Route::remove_aux_or_listen (boost::shared_ptr<Route> route)
3317 ProcessorStreams err;
3318 ProcessorList::iterator tmp;
3319 bool do_fb_signal = false;
3322 Glib::Threads::RWLock::ReaderLock rl(_processor_lock);
3324 /* have to do this early because otherwise processor reconfig
3325 * will put _monitor_send back in the list
3328 if (route == _session.monitor_out()) {
3329 _monitor_send.reset ();
3333 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3335 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
3337 if (d && d->target_route() == route) {
3338 boost::shared_ptr<Send> snd = boost::dynamic_pointer_cast<Send>(d);
3339 if (snd && snd->is_foldback()) {
3340 do_fb_signal = true;
3344 if (remove_processor (*x, &err, false) > 0) {
3350 /* list could have been demolished while we dropped the lock
3353 if (_session.engine().running()) {
3354 /* i/o processors cannot be removed if the engine is not running
3355 * so don't live-loop in case the engine is N/A or dies
3363 _session.FBSendsChanged ();
3369 Route::set_comment (string cmt, void *src)
3373 _session.set_dirty ();
3377 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
3379 FeedRecord fr (other, via_sends_only);
3381 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
3383 if (!result.second) {
3385 /* already a record for "other" - make sure sends-only information is correct */
3386 if (!via_sends_only && result.first->sends_only) {
3387 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
3388 frp->sends_only = false;
3392 return result.second;
3396 Route::clear_fed_by ()
3402 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
3404 const FedBy& fed_by (other->fed_by());
3406 for (FedBy::const_iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
3407 boost::shared_ptr<Route> sr = f->r.lock();
3409 if (sr && (sr.get() == this)) {
3411 if (via_sends_only) {
3412 *via_sends_only = f->sends_only;
3423 Route::all_inputs () const
3425 /* TODO, if this works as expected,
3426 * cache the IOVector and maintain it via
3427 * input_change_handler(), sidechain_change_handler() etc
3430 ios.push_back (_input);
3432 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3433 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3435 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3436 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3439 iop = pi->sidechain();
3442 if (iop != 0 && iop->input()) {
3443 ios.push_back (iop->input());
3450 Route::all_outputs () const
3453 // _output is included via Delivery
3454 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3455 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3456 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3457 if (iop != 0 && iop->output()) {
3458 ios.push_back (iop->output());
3465 Route::direct_feeds_according_to_reality (boost::shared_ptr<Route> other, bool* via_send_only)
3467 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds from %1 (-> %2)?\n", _name, other->name()));
3468 if (other->all_inputs().fed_by (_output)) {
3469 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS to %1\n", other->name()));
3470 if (via_send_only) {
3471 *via_send_only = false;
3477 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3479 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
3481 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3482 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3485 iop = pi->sidechain();
3489 boost::shared_ptr<const IO> iop_out = iop->output();
3490 if (other.get() == this && iop_out && iop->input() && iop_out->connected_to (iop->input())) {
3491 // TODO this needs a delaylines in the Insert to align connections (!)
3492 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed its own return (%2)\n", iop->name(), other->name()));
3495 if ((iop_out && other->all_inputs().fed_by (iop_out)) || iop->feeds (other)) {
3496 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
3497 if (via_send_only) {
3498 *via_send_only = true;
3502 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
3507 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
3512 Route::direct_feeds_according_to_graph (boost::shared_ptr<Route> other, bool* via_send_only)
3514 return _session._current_route_graph.has (boost::dynamic_pointer_cast<Route> (shared_from_this ()), other, via_send_only);
3518 Route::feeds_according_to_graph (boost::shared_ptr<Route> other)
3520 return _session._current_route_graph.feeds (boost::dynamic_pointer_cast<Route> (shared_from_this ()), other);
3523 /** Called from the (non-realtime) butler thread when the transport is stopped */
3525 Route::non_realtime_transport_stop (samplepos_t now, bool flush)
3527 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3529 Automatable::non_realtime_transport_stop (now, flush);
3531 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3533 if (!_have_internal_generator && (Config->get_plugins_stop_with_transport() && flush)) {
3537 (*i)->non_realtime_transport_stop (now, flush);
3542 Route::realtime_handle_transport_stopped ()
3544 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3546 /* currently only by Plugin, queue note-off events */
3547 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3548 (*i)->realtime_handle_transport_stopped ();
3554 Route::input_change_handler (IOChange change, void * /*src*/)
3556 if (_session.loading()) {
3560 if ((change.type & IOChange::ConfigurationChanged)) {
3561 /* This is called with the process lock held if change
3562 contains ConfigurationChanged
3564 configure_processors (0);
3565 io_changed (); /* EMIT SIGNAL */
3568 if (_solo_control->soloed_by_others_upstream() || _solo_isolate_control->solo_isolated_by_upstream()) {
3571 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3572 if (_input->connected()) {
3573 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3574 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3578 bool does_feed = (*i)->direct_feeds_according_to_reality (boost::dynamic_pointer_cast<Route> (shared_from_this()), &sends_only);
3579 if (does_feed && !sends_only) {
3580 if ((*i)->soloed()) {
3583 if ((*i)->solo_isolate_control()->solo_isolated()) {
3590 int delta = sbou - _solo_control->soloed_by_others_upstream();
3591 int idelta = ibou - _solo_isolate_control->solo_isolated_by_upstream();
3594 PBD::warning << string_compose (
3595 _("Invalid Solo-Isolate propagation: from:%1 new:%2 - old:%3 = delta:%4"),
3596 _name, ibou, _solo_isolate_control->solo_isolated_by_upstream(), idelta)
3601 if (_solo_control->soloed_by_others_upstream()) {
3602 // ignore new connections (they're not propagated)
3604 _solo_control->mod_solo_by_others_upstream (delta);
3608 if (_solo_isolate_control->solo_isolated_by_upstream()) {
3609 // solo-isolate currently only propagates downstream
3611 _solo_isolate_control->mod_solo_isolated_by_upstream (1);
3613 //_solo_isolated_by_upstream = ibou;
3616 // Session::route_solo_changed does not propagate indirect solo-changes
3617 // propagate downstream to tracks
3618 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3619 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3623 bool does_feed = feeds (*i, &sends_only);
3624 if (delta <= 0 && does_feed && !sends_only) {
3625 (*i)->solo_control()->mod_solo_by_others_upstream (delta);
3628 if (idelta < 0 && does_feed && !sends_only) {
3629 (*i)->solo_isolate_control()->mod_solo_isolated_by_upstream (-1);
3636 Route::output_change_handler (IOChange change, void * /*src*/)
3638 if (_initial_io_setup) {
3642 if ((change.type & IOChange::ConfigurationChanged)) {
3643 /* This is called with the process lock held if change
3644 contains ConfigurationChanged
3646 configure_processors (0);
3649 _session.reset_monitor_section();
3652 io_changed (); /* EMIT SIGNAL */
3655 if ((change.type & IOChange::ConnectionsChanged)) {
3657 /* do this ONLY if connections have changed. Configuration
3658 * changes do not, by themselves alter solo upstream or
3659 * downstream status.
3662 if (_solo_control->soloed_by_others_downstream()) {
3664 /* checking all all downstream routes for
3665 * explicit of implict solo is a rather drastic measure,
3666 * ideally the input_change_handler() of the other route
3667 * would propagate the change to us.
3669 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3670 if (_output->connected()) {
3671 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3672 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3676 bool does_feed = direct_feeds_according_to_reality (*i, &sends_only);
3677 if (does_feed && !sends_only) {
3678 if ((*i)->soloed()) {
3686 int delta = sbod - _solo_control->soloed_by_others_downstream();
3688 // do not allow new connections to change implicit solo (no propagation)
3689 _solo_control->mod_solo_by_others_downstream (delta);
3690 // Session::route_solo_changed() does not propagate indirect solo-changes
3691 // propagate upstream to tracks
3692 boost::shared_ptr<Route> shared_this = boost::dynamic_pointer_cast<Route> (shared_from_this());
3693 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3694 if ((*i).get() == this || !can_solo()) {
3698 bool does_feed = (*i)->feeds (shared_this, &sends_only);
3699 if (delta != 0 && does_feed && !sends_only) {
3700 (*i)->solo_control()->mod_solo_by_others_downstream (delta);
3710 Route::sidechain_change_handler (IOChange change, void* src)
3712 if (_initial_io_setup || _in_sidechain_setup) {
3716 input_change_handler (change, src);
3720 Route::pans_required () const
3722 if (n_outputs().n_audio() < 2) {
3726 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
3730 Route::flush_processor_buffers_locked (samplecnt_t nframes)
3732 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3733 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery> (*i);
3735 d->flush_buffers (nframes);
3737 boost::shared_ptr<PortInsert> p = boost::dynamic_pointer_cast<PortInsert> (*i);
3739 p->flush_buffers (nframes);
3746 Route::flush_processors ()
3748 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3750 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3756 Route::playback_latency (bool incl_downstream) const
3760 rv = _disk_reader->output_latency ();
3762 rv = _signal_latency;
3764 if (incl_downstream) {
3765 rv += _output->connected_latency (true);
3767 rv += _output->latency ();
3773 Route::latency_preroll (pframes_t nframes, samplepos_t& start_sample, samplepos_t& end_sample)
3775 samplecnt_t latency_preroll = _session.remaining_latency_preroll ();
3776 if (latency_preroll == 0) {
3779 if (!_disk_reader) {
3780 start_sample -= latency_preroll;
3781 end_sample -= latency_preroll;
3785 if (latency_preroll > playback_latency ()) {
3786 no_roll_unlocked (nframes, start_sample - latency_preroll, end_sample - latency_preroll, false);
3790 start_sample -= latency_preroll;
3791 end_sample -= latency_preroll;
3796 Route::roll (pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, bool& need_butler)
3798 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3805 silence_unlocked (nframes);
3810 if ((nframes = latency_preroll (nframes, start_sample, end_sample)) == 0) {
3814 run_route (start_sample, end_sample, nframes, (!_disk_writer || !_disk_writer->record_enabled()) && _session.transport_rolling(), true);
3816 if ((_disk_reader && _disk_reader->need_butler()) || (_disk_writer && _disk_writer->need_butler())) {
3823 Route::no_roll (pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, bool session_state_changing)
3825 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3831 return no_roll_unlocked (nframes, start_sample, end_sample, session_state_changing);
3835 Route::no_roll_unlocked (pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, bool session_state_changing)
3837 /* Must be called with the processor lock held */
3840 silence_unlocked (nframes);
3845 if (session_state_changing) {
3846 if (_session.transport_speed() != 0.0f) {
3847 /* we're rolling but some state is changing (e.g. our diskstream contents)
3848 so we cannot use them. Be silent till this is over.
3850 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
3852 silence_unlocked (nframes);
3856 /* we're really not rolling, so we're either delivery silence or actually
3857 monitoring, both of which are safe to do while session_state_changing is true.
3861 run_route (start_sample, end_sample, nframes, false, false);
3866 Route::silent_roll (pframes_t nframes, samplepos_t /*start_sample*/, samplepos_t /*end_sample*/, bool& /* need_butler */)
3869 flush_processor_buffers_locked (nframes);
3874 __attribute__((annotate("realtime")))
3877 Route::apply_processor_changes_rt ()
3879 int emissions = EmitNone;
3881 if (_pending_meter_point != _meter_point) {
3882 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3884 /* meters always have buffers for 'processor_max_streams'
3885 * they can be re-positioned without re-allocation */
3886 if (set_meter_point_unlocked()) {
3887 emissions |= EmitMeterChanged | EmitMeterVisibilityChange;;
3889 emissions |= EmitMeterChanged;
3894 bool changed = false;
3896 if (g_atomic_int_get (&_pending_process_reorder)) {
3897 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3899 apply_processor_order (_pending_processor_order);
3900 setup_invisible_processors ();
3902 g_atomic_int_set (&_pending_process_reorder, 0);
3903 emissions |= EmitRtProcessorChange;
3907 set_processor_positions ();
3908 /* update processor input/output latency
3909 * (total signal_latency does not change)
3911 update_signal_latency (true);
3913 if (emissions != 0) {
3914 g_atomic_int_set (&_pending_signals, emissions);
3917 return (!selfdestruct_sequence.empty ());
3921 Route::emit_pending_signals ()
3923 int sig = g_atomic_int_and (&_pending_signals, 0);
3924 if (sig & EmitMeterChanged) {
3925 _meter->emit_configuration_changed();
3926 meter_change (); /* EMIT SIGNAL */
3927 if (sig & EmitMeterVisibilityChange) {
3928 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3930 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3933 if (sig & EmitRtProcessorChange) {
3934 processors_changed (RouteProcessorChange (RouteProcessorChange::RealTimeChange)); /* EMIT SIGNAL */
3937 /* this would be a job for the butler.
3938 * Conceptually we should not take processe/processor locks here.
3939 * OTOH its more efficient (less overhead for summoning the butler and
3940 * telling her what do do) and signal emission is called
3941 * directly after the process callback, which decreases the chance
3942 * of x-runs when taking the locks.
3944 while (!selfdestruct_sequence.empty ()) {
3945 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
3946 if (selfdestruct_sequence.empty ()) { break; } // re-check with lock
3947 boost::shared_ptr<Processor> proc = selfdestruct_sequence.back ().lock ();
3948 selfdestruct_sequence.pop_back ();
3951 remove_processor (proc);
3957 Route::set_meter_point (MeterPoint p, bool force)
3959 if (_pending_meter_point == p && !force) {
3963 if (force || !AudioEngine::instance()->running()) {
3964 bool meter_visibly_changed = false;
3966 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3967 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3968 _pending_meter_point = p;
3969 if (set_meter_point_unlocked ()) {
3970 meter_visibly_changed = true;
3973 _meter->emit_configuration_changed();
3974 meter_change (); /* EMIT SIGNAL */
3975 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, meter_visibly_changed)); /* EMIT SIGNAL */
3977 _pending_meter_point = p;
3983 __attribute__((annotate("realtime")))
3986 Route::set_meter_point_unlocked ()
3989 /* Caller must hold process and processor write lock */
3990 assert (!AudioEngine::instance()->process_lock().trylock());
3991 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3992 assert (!lm.locked ());
3995 _meter_point = _pending_meter_point;
3997 bool meter_was_visible_to_user = _meter->display_to_user ();
3999 if (!_custom_meter_position_noted) {
4000 maybe_note_meter_position ();
4003 if (_meter_point != MeterCustom) {
4005 _meter->set_display_to_user (false);
4007 setup_invisible_processors ();
4010 _meter->set_display_to_user (true);
4012 /* If we have a previous position for the custom meter, try to put it there */
4013 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
4015 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), after);
4016 if (i != _processors.end ()) {
4017 _processors.remove (_meter);
4018 _processors.insert (i, _meter);
4020 } else {// at end, right before the mains_out/panner
4021 _processors.remove (_meter);
4022 ProcessorList::iterator main = _processors.end();
4023 _processors.insert (--main, _meter);
4027 /* Set up the meter for its new position */
4029 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
4033 if (loc == _processors.begin()) {
4034 m_in = _input->n_ports();
4036 ProcessorList::iterator before = loc;
4038 m_in = (*before)->output_streams ();
4041 _meter->reflect_inputs (m_in);
4043 /* we do not need to reconfigure the processors, because the meter
4044 (a) is always ready to handle processor_max_streams
4045 (b) is always an N-in/N-out processor, and thus moving
4046 it doesn't require any changes to the other processors.
4049 /* these should really be done after releasing the lock
4050 * but all those signals are subscribed to with gui_thread()
4053 return (_meter->display_to_user() != meter_was_visible_to_user);
4057 Route::listen_position_changed ()
4060 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4061 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
4062 ProcessorState pstate (this);
4064 if (configure_processors_unlocked (0, &lm)) {
4065 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
4067 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
4072 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
4073 _session.set_dirty ();
4076 boost::shared_ptr<CapturingProcessor>
4077 Route::add_export_point()
4079 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4080 if (!_capturing_processor) {
4082 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4083 Glib::Threads::RWLock::WriterLock lw (_processor_lock);
4085 /* Align all tracks for stem-export w/o processing.
4086 * Compensate for all plugins between the this route's disk-reader
4087 * and the common final downstream output (ie alignment point for playback).
4089 _capturing_processor.reset (new CapturingProcessor (_session, playback_latency (true)));
4090 configure_processors_unlocked (0, &lw);
4091 _capturing_processor->activate ();
4094 return _capturing_processor;
4098 Route::update_signal_latency (bool apply_to_delayline)
4100 // TODO: bail out if !active() and set/assume _signal_latency = 0,
4101 // here or in Session::* ? -> also zero send latencies,
4102 // and make sure that re-enabling a route updates things again...
4104 samplecnt_t capt_lat_in = _input->connected_latency (false);
4105 samplecnt_t play_lat_out = _output->connected_latency (true);
4107 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4109 samplecnt_t l_in = 0;
4110 samplecnt_t l_out = 0;
4111 for (ProcessorList::reverse_iterator i = _processors.rbegin(); i != _processors.rend(); ++i) {
4112 if (boost::shared_ptr<LatentSend> snd = boost::dynamic_pointer_cast<LatentSend> (*i)) {
4113 snd->set_delay_in (l_out + _output->latency());
4116 if (boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) {
4117 if (boost::shared_ptr<IO> pio = pi->sidechain_input ()) {
4118 samplecnt_t lat = l_out + _output->latency();
4119 pio->set_private_port_latencies (lat, true);
4120 pio->set_public_port_latencies (lat, true);
4123 (*i)->set_output_latency (l_out);
4124 if ((*i)->active ()) { // XXX
4125 l_out += (*i)->effective_latency ();
4129 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal signal latency = %2\n", _name, l_out));
4131 _signal_latency = l_out;
4133 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4135 /* set sidechain, send and insert port latencies */
4136 if (boost::shared_ptr<PortInsert> pi = boost::dynamic_pointer_cast<PortInsert> (*i)) {
4138 /* propagate playback latency from output to input */
4139 pi->input ()->set_private_port_latencies (play_lat_out + l_in, true);
4141 if (pi->output ()) {
4142 /* propagate capture latency from input to output */
4143 pi->output ()->set_private_port_latencies (capt_lat_in + l_in, false);
4146 } else if (boost::shared_ptr<Send> snd = boost::dynamic_pointer_cast<Send> (*i)) {
4147 if (snd->output ()) {
4148 /* set capture latency */
4149 snd->output ()->set_private_port_latencies (capt_lat_in + l_in, false);
4150 /* take send-target's playback latency into account */
4151 snd->set_delay_out (snd->output ()->connected_latency (true));
4152 /* InternalReturn::set_playback_offset() below, also calls set_delay_out() */
4156 (*i)->set_input_latency (l_in);
4157 (*i)->set_playback_offset (_signal_latency + _output->latency ());
4158 (*i)->set_capture_offset (_input->latency ());
4159 if ((*i)->active ()) {
4160 l_in += (*i)->effective_latency ();
4166 if (apply_to_delayline) {
4167 /* see also Session::post_playback_latency() */
4168 apply_latency_compensation ();
4171 if (_signal_latency != l_out) {
4172 signal_latency_changed (); /* EMIT SIGNAL */
4175 return _signal_latency;
4179 Route::apply_latency_compensation ()
4182 samplecnt_t old = _delayline->delay ();
4184 samplecnt_t play_lat_in = _input->connected_latency (true);
4185 samplecnt_t play_lat_out = _output->connected_latency (true);
4186 samplecnt_t latcomp = play_lat_in - play_lat_out - _signal_latency;
4189 samplecnt_t capt_lat_in = _input->connected_latency (false);
4190 samplecnt_t capt_lat_out = _output->connected_latency (false);
4191 samplecnt_t latcomp_capt = capt_lat_out - capt_lat_in - _signal_latency;
4193 cout << "ROUTE " << name() << " delay for " << latcomp << " (c: " << latcomp_capt << ")" << endl;
4196 _delayline->set_delay (latcomp > 0 ? latcomp : 0);
4198 if (old != _delayline->delay ()) {
4199 signal_latency_updated (); /* EMIT SIGNAL */
4205 Route::set_block_size (pframes_t nframes)
4207 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4208 (*i)->set_block_size (nframes);
4211 _session.ensure_buffers (n_process_buffers ());
4215 Route::protect_automation ()
4217 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
4218 (*i)->protect_automation();
4221 /** Shift automation forwards from a particular place, thereby inserting time.
4222 * Adds undo commands for any shifts that are performed.
4224 * @param pos Position to start shifting from.
4225 * @param samples Amount to shift forwards by.
4229 Route::shift (samplepos_t pos, samplecnt_t samples)
4231 /* pan automation */
4233 ControlSet::Controls& c (_pannable->controls());
4235 for (ControlSet::Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
4236 boost::shared_ptr<AutomationControl> pc = boost::dynamic_pointer_cast<AutomationControl> (ci->second);
4238 boost::shared_ptr<AutomationList> al = pc->alist();
4239 XMLNode& before = al->get_state ();
4240 al->shift (pos, samples);
4241 XMLNode& after = al->get_state ();
4242 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4247 /* TODO mute automation, MuteControl */
4249 /* processor automation (incl. gain, trim,..) */
4251 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4252 for (ProcessorList::iterator i = _processors.begin (); i != _processors.end (); ++i) {
4254 set<Evoral::Parameter> parameters = (*i)->what_can_be_automated();
4256 for (set<Evoral::Parameter>::const_iterator p = parameters.begin (); p != parameters.end (); ++p) {
4257 boost::shared_ptr<AutomationControl> ac = (*i)->automation_control (*p);
4259 boost::shared_ptr<AutomationList> al = ac->alist();
4263 XMLNode &before = al->get_state ();
4264 al->shift (pos, samples);
4265 XMLNode &after = al->get_state ();
4266 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4274 Route::set_plugin_state_dir (boost::weak_ptr<Processor> p, const std::string& d)
4276 boost::shared_ptr<Processor> processor (p.lock ());
4277 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
4281 pi->set_state_dir (d);
4285 Route::save_as_template (const string& path, const string& name, const string& description)
4287 std::string state_dir = path.substr (0, path.find_last_of ('.')); // strip template_suffix
4288 PBD::Unwinder<std::string> uw (_session._template_state_dir, state_dir);
4290 XMLNode& node (state (true));
4291 node.set_property (X_("name"), name);
4293 node.remove_nodes (X_("description"));
4294 if (!description.empty()) {
4295 XMLNode* desc = new XMLNode(X_("description"));
4296 XMLNode* desc_cont = new XMLNode(X_("content"), description);
4297 desc->add_child_nocopy (*desc_cont);
4299 node.add_child_nocopy (*desc);
4304 IO::set_name_in_state (*node.children().front(), name);
4306 tree.set_root (&node);
4308 /* return zero on success, non-zero otherwise */
4309 return !tree.write (path.c_str());
4314 Route::set_name (const string& str)
4320 if (str == name()) {
4324 string newname = Route::ensure_track_or_route_name (str);
4326 if (newname == name()) {
4330 SessionObject::set_name (newname);
4332 for (uint32_t n = 0 ; ; ++n) {
4333 boost::shared_ptr<PluginInsert> pi = boost::static_pointer_cast<PluginInsert> (nth_plugin (n));
4337 pi->update_sidechain_name ();
4340 bool ret = (_input->set_name(newname) && _output->set_name(newname));
4343 /* rename the main outs. Leave other IO processors
4344 * with whatever name they already have, because its
4345 * just fine as it is (it will not contain the route
4346 * name if its a port insert, port send or port return).
4350 if (_main_outs->set_name (newname)) {
4351 /* XXX returning false here is stupid because
4352 we already changed the route name.
4362 /** Set the name of a route in an XML description.
4363 * @param node XML <Route> node to set the name in.
4364 * @param name New name.
4367 Route::set_name_in_state (XMLNode& node, string const & name)
4369 node.set_property (X_("name"), name);
4371 XMLNodeList children = node.children();
4372 for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
4374 if ((*i)->name() == X_("IO")) {
4376 IO::set_name_in_state (**i, name);
4378 } else if ((*i)->name() == X_("Processor")) {
4381 if ((*i)->get_property (X_("role"), str) && str == X_("Main")) {
4382 (*i)->set_property (X_("name"), name);
4388 boost::shared_ptr<Send>
4389 Route::internal_send_for (boost::shared_ptr<const Route> target) const
4391 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4393 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4394 boost::shared_ptr<InternalSend> send;
4396 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
4397 if (send->target_route() == target) {
4403 return boost::shared_ptr<Send>();
4407 Route::set_denormal_protection (bool yn)
4409 if (_denormal_protection != yn) {
4410 _denormal_protection = yn;
4411 denormal_protection_changed (); /* EMIT SIGNAL */
4416 Route::denormal_protection () const
4418 return _denormal_protection;
4422 Route::set_active (bool yn, void* src)
4424 if (_session.transport_rolling()) {
4428 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_route_active()) {
4429 _route_group->foreach_route (boost::bind (&Route::set_active, _1, yn, _route_group));
4433 if (_active != yn) {
4435 _input->set_active (yn);
4436 _output->set_active (yn);
4437 flush_processors ();
4438 active_changed (); // EMIT SIGNAL
4439 _session.set_dirty ();
4443 boost::shared_ptr<Pannable>
4444 Route::pannable() const
4449 boost::shared_ptr<Panner>
4450 Route::panner() const
4453 return _main_outs->panner_shell()->panner();
4456 boost::shared_ptr<PannerShell>
4457 Route::panner_shell() const
4459 return _main_outs->panner_shell();
4462 boost::shared_ptr<GainControl>
4463 Route::gain_control() const
4465 return _gain_control;
4468 boost::shared_ptr<GainControl>
4469 Route::trim_control() const
4471 return _trim_control;
4474 boost::shared_ptr<PhaseControl>
4475 Route::phase_control() const
4477 return _phase_control;
4480 boost::shared_ptr<AutomationControl>
4481 Route::get_control (const Evoral::Parameter& param)
4483 /* either we own the control or .... */
4485 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
4489 /* maybe one of our processors does or ... */
4491 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
4492 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4493 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
4501 /* nobody does so we'll make a new one */
4503 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
4510 boost::shared_ptr<Processor>
4511 Route::nth_plugin (uint32_t n) const
4513 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4514 ProcessorList::const_iterator i;
4516 for (i = _processors.begin(); i != _processors.end(); ++i) {
4517 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
4524 return boost::shared_ptr<Processor> ();
4527 boost::shared_ptr<Processor>
4528 Route::nth_send (uint32_t n) const
4530 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4531 ProcessorList::const_iterator i;
4533 for (i = _processors.begin(); i != _processors.end(); ++i) {
4534 if (boost::dynamic_pointer_cast<Send> (*i)) {
4536 if ((*i) == _monitor_send) {
4537 /* send to monitor section is not considered
4538 * to be an accessible send.
4549 return boost::shared_ptr<Processor> ();
4553 Route::has_io_processor_named (const string& name)
4555 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4556 ProcessorList::iterator i;
4558 for (i = _processors.begin(); i != _processors.end(); ++i) {
4559 if (boost::dynamic_pointer_cast<Send> (*i) ||
4560 boost::dynamic_pointer_cast<PortInsert> (*i)) {
4561 if ((*i)->name() == name) {
4571 Route::set_processor_positions ()
4573 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4575 bool had_amp = false;
4576 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4577 (*i)->set_pre_fader (!had_amp);
4584 /** Called when there is a proposed change to the input port count */
4586 Route::input_port_count_changing (ChanCount to)
4588 list<pair<ChanCount, ChanCount> > c = try_configure_processors (to, 0);
4590 /* The processors cannot be configured with the new input arrangement, so
4596 /* The change is ok */
4600 /** Called when there is a proposed change to the output port count */
4602 Route::output_port_count_changing (ChanCount to)
4604 if (_strict_io && !_in_configure_processors) {
4607 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
4608 if (processor_out_streams.get(*t) > to.get(*t)) {
4612 /* The change is ok */
4617 Route::unknown_processors () const
4621 if (_session.get_disable_all_loaded_plugins ()) {
4622 // Do not list "missing plugins" if they are explicitly disabled
4626 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4627 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4628 if (boost::dynamic_pointer_cast<UnknownProcessor const> (*i)) {
4629 p.push_back ((*i)->name ());
4638 Route::update_port_latencies (PortSet& from, PortSet& to, bool playback, samplecnt_t our_latency) const
4640 /* we assume that all our input ports feed all our output ports. its not
4641 universally true, but the alternative is way too corner-case to worry about.
4644 LatencyRange all_connections;
4647 all_connections.min = 0;
4648 all_connections.max = 0;
4650 all_connections.min = ~((pframes_t) 0);
4651 all_connections.max = 0;
4653 /* iterate over all "from" ports and determine the latency range for all of their
4654 connections to the "outside" (outside of this Route).
4657 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4661 p->get_connected_latency_range (range, playback);
4663 all_connections.min = min (all_connections.min, range.min);
4664 all_connections.max = max (all_connections.max, range.max);
4668 /* set the "from" port latencies to the max/min range of all their connections */
4670 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4671 p->set_private_latency_range (all_connections, playback);
4674 /* set the ports "in the direction of the flow" to the same value as above plus our own signal latency */
4676 all_connections.min += our_latency;
4677 all_connections.max += our_latency;
4679 for (PortSet::iterator p = to.begin(); p != to.end(); ++p) {
4680 p->set_private_latency_range (all_connections, playback);
4683 return all_connections.max;
4687 Route::set_private_port_latencies (bool playback) const
4689 samplecnt_t own_latency = 0;
4691 /* Processor list not protected by lock: MUST BE CALLED FROM PROCESS THREAD
4692 OR LATENCY CALLBACK.
4694 This is called (early) from the latency callback. It computes the REAL
4695 latency associated with each port and stores the result as the "private"
4696 latency of the port. A later call to Route::set_public_port_latencies()
4697 sets all ports to the same value to reflect the fact that we do latency
4698 compensation and so all signals are delayed by the same amount as they
4699 flow through ardour.
4702 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4704 if ((*i)->active ()) {
4705 own_latency += (*i)->effective_latency ();
4710 /* playback: propagate latency from "outside the route" to outputs to inputs */
4711 return update_port_latencies (_output->ports (), _input->ports (), true, own_latency);
4713 /* capture: propagate latency from "outside the route" to inputs to outputs */
4714 return update_port_latencies (_input->ports (), _output->ports (), false, own_latency);
4719 Route::set_public_port_latencies (samplecnt_t value, bool playback) const
4721 /* publish private latencies */
4722 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4723 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4724 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*i);
4728 if (iop->input ()) {
4729 iop->input ()->set_public_port_latencies (iop->input()->latency(), true);
4731 if (iop->output ()) {
4732 iop->output ()->set_public_port_latencies (iop->output()->latency(), false);
4736 /* this is called to set the JACK-visible port latencies, which take
4737 * latency compensation into account.
4739 _input->set_public_port_latencies (value, playback);
4740 _output->set_public_port_latencies (value, playback);
4743 /** Put the invisible processors in the right place in _processors.
4744 * Must be called with a writer lock on _processor_lock held.
4747 __attribute__((annotate("realtime")))
4750 Route::setup_invisible_processors ()
4753 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4754 assert (!lm.locked ());
4758 /* too early to be doing this stuff */
4762 /* we'll build this new list here and then use it
4764 * TODO put the ProcessorList is on the stack for RT-safety.
4767 ProcessorList new_processors;
4768 ProcessorList foldback_sends;
4769 ProcessorList::iterator dr;
4770 ProcessorList::iterator dw;
4772 /* find visible processors */
4774 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4775 boost::shared_ptr<Send> auxsnd = boost::dynamic_pointer_cast<Send> ((*i));
4776 if ((*i)->display_to_user ()) {
4777 new_processors.push_back (*i);
4779 else if (auxsnd && auxsnd->is_foldback ()) {
4780 foldback_sends.push_back (*i);
4786 ProcessorList::iterator amp = find (new_processors.begin(), new_processors.end(), _amp);
4788 if (amp == new_processors.end ()) {
4789 error << string_compose (_("Amp/Fader on Route '%1' went AWOL. Re-added."), name()) << endmsg;
4790 new_processors.push_front (_amp);
4791 amp = find (new_processors.begin(), new_processors.end(), _amp);
4794 /* and the processor after the amp */
4796 ProcessorList::iterator after_amp = amp;
4799 /* Pre-fader METER */
4801 if (_meter && _meter_point == MeterPreFader) {
4802 /* add meter just before the fader */
4803 assert (!_meter->display_to_user ());
4804 new_processors.insert (amp, _meter);
4809 assert (_main_outs);
4810 assert (!_main_outs->display_to_user ());
4811 new_processors.push_back (_main_outs);
4813 /* iterator for the main outs */
4815 ProcessorList::iterator main = new_processors.end();
4818 /* OUTPUT METERING */
4820 if (_meter && (_meter_point == MeterOutput || _meter_point == MeterPostFader)) {
4821 assert (!_meter->display_to_user ());
4823 /* add the processor just before or just after the main outs */
4825 ProcessorList::iterator meter_point = main;
4827 if (_meter_point == MeterOutput) {
4830 new_processors.insert (meter_point, _meter);
4833 /* Foldback Sends */
4835 for (ProcessorList::iterator i = foldback_sends.begin(); i != foldback_sends.end(); ++i) {
4836 new_processors.insert (amp, (*i));
4841 if (_monitor_send && !is_monitor ()) {
4842 assert (!_monitor_send->display_to_user ());
4843 switch (Config->get_listen_position ()) {
4844 case PreFaderListen:
4845 switch (Config->get_pfl_position ()) {
4846 case PFLFromBeforeProcessors:
4847 new_processors.push_front (_monitor_send);
4849 case PFLFromAfterProcessors:
4850 new_processors.insert (amp, _monitor_send);
4853 _monitor_send->set_can_pan (false);
4855 case AfterFaderListen:
4856 switch (Config->get_afl_position ()) {
4857 case AFLFromBeforeProcessors:
4858 new_processors.insert (after_amp, _monitor_send);
4860 case AFLFromAfterProcessors:
4861 new_processors.insert (new_processors.end(), _monitor_send);
4864 _monitor_send->set_can_pan (true);
4869 /* MONITOR CONTROL */
4871 if (_monitor_control && is_monitor ()) {
4872 assert (!_monitor_control->display_to_user ());
4873 new_processors.insert (amp, _monitor_control);
4878 ProcessorList::iterator trim = new_processors.end();
4880 if (_trim->active()) {
4881 assert (!_trim->display_to_user ());
4882 new_processors.push_front (_trim);
4883 trim = new_processors.begin();
4886 /* INTERNAL RETURN */
4888 /* doing this here means that any monitor control will come after
4889 the return and trim.
4893 assert (!_intreturn->display_to_user ());
4894 new_processors.push_front (_intreturn);
4897 /* DISK READER & WRITER (for Track objects) */
4899 if (_disk_reader || _disk_writer) {
4900 switch (_disk_io_point) {
4901 case DiskIOPreFader:
4902 if (trim != new_processors.end()) {
4903 /* insert BEFORE TRIM */
4905 new_processors.insert (trim, _disk_writer);
4908 new_processors.insert (trim, _disk_reader);
4912 new_processors.push_front (_disk_writer);
4915 new_processors.push_front (_disk_reader);
4919 case DiskIOPostFader:
4920 /* insert BEFORE main outs */
4922 new_processors.insert (main, _disk_writer);
4925 new_processors.insert (main, _disk_reader);
4929 /* reader and writer are visible under this condition, so they
4930 * are not invisible and thus not handled here.
4936 /* ensure dist-writer is before disk-reader */
4937 if (_disk_reader && _disk_writer) {
4938 ProcessorList::iterator reader_pos = find (new_processors.begin(), new_processors.end(), _disk_reader);
4939 ProcessorList::iterator writer_pos = find (new_processors.begin(), new_processors.end(), _disk_writer);
4940 assert (reader_pos != new_processors.end ());
4941 assert (writer_pos != new_processors.end ());
4942 if (std::distance (new_processors.begin(), reader_pos) < std::distance (new_processors.begin(), writer_pos)) {
4943 new_processors.erase (reader_pos);
4944 assert (writer_pos == find (new_processors.begin(), new_processors.end(), _disk_writer));
4945 new_processors.insert (++writer_pos, _disk_reader);
4949 /* EXPORT PROCESSOR */
4950 if (_capturing_processor) {
4951 assert (!_capturing_processor->display_to_user ());
4952 ProcessorList::iterator reader_pos = find (new_processors.begin(), new_processors.end(), _disk_reader);
4953 if (reader_pos != new_processors.end()) {
4954 /* insert after disk-reader */
4955 new_processors.insert (++reader_pos, _capturing_processor);
4957 ProcessorList::iterator return_pos = find (new_processors.begin(), new_processors.end(), _intreturn);
4958 /* insert after return */
4959 if (return_pos != new_processors.end()) {
4960 new_processors.insert (++return_pos, _capturing_processor);
4962 new_processors.push_front (_capturing_processor);
4967 /* Polarity Invert */
4969 ProcessorList::iterator reader_pos = find (new_processors.begin(), new_processors.end(), _disk_reader);
4970 if (reader_pos != new_processors.end()) {
4971 /* insert after disk-reader */
4972 new_processors.insert (++reader_pos, _polarity);
4974 ProcessorList::iterator return_pos = find (new_processors.begin(), new_processors.end(), _intreturn);
4975 /* insert after return */
4976 if (return_pos != new_processors.end()) {
4977 new_processors.insert (++return_pos, _polarity);
4979 new_processors.push_front (_polarity);
4985 if (_meter && _meter_point == MeterInput) {
4986 /* add meter just before the disk-writer (if any)
4987 * otherwise at the top, but after the latency delayline
4988 * (perhaps it should also be after intreturn on busses ??)
4990 assert (!_meter->display_to_user ());
4991 ProcessorList::iterator writer_pos = find (new_processors.begin(), new_processors.end(), _disk_writer);
4992 if (writer_pos != new_processors.end()) {
4993 /* insert before disk-writer */
4994 new_processors.insert (writer_pos, _meter);
4996 ProcessorList::iterator return_pos = find (new_processors.begin(), new_processors.end(), _intreturn);
4997 /* insert after return */
4998 if (return_pos != new_processors.end()) {
4999 new_processors.insert (++return_pos, _meter);
5001 new_processors.push_front (_meter);
5006 if (!is_master() && !is_monitor() && !is_auditioner()) {
5007 ProcessorList::iterator reader_pos = find (new_processors.begin(), new_processors.end(), _disk_reader);
5008 if (reader_pos != new_processors.end()) {
5009 /* insert before disk-reader */
5010 new_processors.insert (reader_pos, _delayline);
5012 new_processors.push_front (_delayline);
5016 _processors = new_processors;
5018 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5019 if (!(*i)->display_to_user () && !(*i)->enabled () && (*i) != _monitor_send) {
5020 (*i)->enable (true);
5024 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: setup_invisible_processors\n", _name));
5025 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5026 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1\n", (*i)->name ()));
5033 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
5034 Glib::Threads::RWLock::ReaderLock lp (_processor_lock);
5038 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5039 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*i);
5046 /** If the meter point is `Custom', make a note of where the meter is.
5047 * This is so that if the meter point is subsequently set to something else,
5048 * and then back to custom, we can put the meter back where it was last time
5049 * custom was enabled.
5051 * Must be called with the _processor_lock held.
5054 Route::maybe_note_meter_position ()
5056 if (_meter_point != MeterCustom) {
5060 _custom_meter_position_noted = true;
5061 /* custom meter points range from after trim to before panner/main_outs
5062 * this is a limitation by the current processor UI
5064 bool seen_trim = false;
5065 _processor_after_last_custom_meter.reset();
5066 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5067 if ((*i) == _trim) {
5070 if ((*i) == _main_outs) {
5071 _processor_after_last_custom_meter = *i;
5074 if (boost::dynamic_pointer_cast<PeakMeter> (*i)) {
5076 _processor_after_last_custom_meter = _trim;
5078 ProcessorList::iterator j = i;
5080 assert(j != _processors.end ()); // main_outs should be before
5081 _processor_after_last_custom_meter = *j;
5086 assert(_processor_after_last_custom_meter.lock());
5089 boost::shared_ptr<Processor>
5090 Route::processor_by_id (PBD::ID id) const
5092 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5093 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5094 if ((*i)->id() == id) {
5099 return boost::shared_ptr<Processor> ();
5102 /** @return what we should be metering; either the data coming from the input
5103 * IO or the data that is flowing through the route.
5106 Route::metering_state () const
5108 return MeteringRoute;
5112 Route::has_external_redirects () const
5114 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5116 /* ignore inactive processors and obviously ignore the main
5117 * outs since everything has them and we don't care.
5120 if ((*i)->active() && (*i) != _main_outs && (*i)->does_routing()) {
5128 boost::shared_ptr<Processor>
5129 Route::the_instrument () const
5131 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5132 return the_instrument_unlocked ();
5135 boost::shared_ptr<Processor>
5136 Route::the_instrument_unlocked () const
5138 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5139 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
5140 if (pi && pi->plugin ()->get_info ()->is_instrument ()) {
5144 return boost::shared_ptr<Processor>();
5150 return dynamic_cast<Track*>(this) != 0;
5154 Route::non_realtime_locate (samplepos_t pos)
5156 Automatable::non_realtime_locate (pos);
5159 _pannable->non_realtime_locate (pos);
5162 #if 0 // XXX mayhaps clear delayline here (and at stop?)
5164 _delayline->flush ();
5169 //Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
5170 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5172 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5173 (*i)->non_realtime_locate (pos);
5179 Route::fill_buffers_with_input (BufferSet& bufs, boost::shared_ptr<IO> io, pframes_t nframes)
5186 * We don't currently mix MIDI input together, so we don't need the
5187 * complex logic of the audio case.
5190 n_buffers = bufs.count().n_midi ();
5192 for (i = 0; i < n_buffers; ++i) {
5194 boost::shared_ptr<MidiPort> source_port = io->midi (i);
5195 MidiBuffer& buf (bufs.get_midi (i));
5198 buf.copy (source_port->get_midi_buffer(nframes));
5200 buf.silence (nframes);
5206 n_buffers = bufs.count().n_audio();
5208 size_t n_ports = io->n_ports().n_audio();
5209 float scaling = 1.0f;
5211 if (n_ports > n_buffers) {
5212 scaling = ((float) n_buffers) / n_ports;
5215 for (i = 0; i < n_ports; ++i) {
5217 /* if there are more ports than buffers, map them onto buffers
5218 * in a round-robin fashion
5221 boost::shared_ptr<AudioPort> source_port = io->audio (i);
5222 AudioBuffer& buf (bufs.get_audio (i%n_buffers));
5224 if (i < n_buffers) {
5226 /* first time through just copy a channel into
5230 buf.read_from (source_port->get_audio_buffer (nframes), nframes);
5232 if (scaling != 1.0f) {
5233 buf.apply_gain (scaling, nframes);
5238 /* on subsequent times around, merge data from
5239 * the port with what is already there
5242 if (scaling != 1.0f) {
5243 buf.accumulate_with_gain_from (source_port->get_audio_buffer (nframes), nframes, 0, scaling);
5245 buf.accumulate_from (source_port->get_audio_buffer (nframes), nframes);
5250 /* silence any remaining buffers */
5252 for (; i < n_buffers; ++i) {
5253 AudioBuffer& buf (bufs.get_audio (i));
5254 buf.silence (nframes);
5257 /* establish the initial setup of the buffer set, reflecting what was
5258 copied into it. unless, of course, we are the auditioner, in which
5259 case nothing was fed into it from the inputs at all.
5262 if (!is_auditioner()) {
5263 bufs.set_count (io->n_ports());
5267 boost::shared_ptr<AutomationControl>
5268 Route::pan_azimuth_control() const
5272 return _mixbus_send->master_pan_ctrl ();
5274 return boost::shared_ptr<AutomationControl>();
5276 if (!_pannable || !panner()) {
5277 return boost::shared_ptr<AutomationControl>();
5279 return _pannable->pan_azimuth_control;
5283 boost::shared_ptr<AutomationControl>
5284 Route::pan_elevation_control() const
5286 if (Profile->get_mixbus() || !_pannable || !panner()) {
5287 return boost::shared_ptr<AutomationControl>();
5290 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5292 if (c.find (PanElevationAutomation) != c.end()) {
5293 return _pannable->pan_elevation_control;
5295 return boost::shared_ptr<AutomationControl>();
5298 boost::shared_ptr<AutomationControl>
5299 Route::pan_width_control() const
5302 if (mixbus() && _ch_pre) {
5304 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl>(_ch_pre->control(Evoral::Parameter(PluginAutomation, 0, 1)));
5307 if (Profile->get_mixbus() || !_pannable || !panner()) {
5308 return boost::shared_ptr<AutomationControl>();
5311 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5313 if (c.find (PanWidthAutomation) != c.end()) {
5314 return _pannable->pan_width_control;
5316 return boost::shared_ptr<AutomationControl>();
5319 boost::shared_ptr<AutomationControl>
5320 Route::pan_frontback_control() const
5322 if (Profile->get_mixbus() || !_pannable || !panner()) {
5323 return boost::shared_ptr<AutomationControl>();
5326 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5328 if (c.find (PanFrontBackAutomation) != c.end()) {
5329 return _pannable->pan_frontback_control;
5331 return boost::shared_ptr<AutomationControl>();
5334 boost::shared_ptr<AutomationControl>
5335 Route::pan_lfe_control() const
5337 if (Profile->get_mixbus() || !_pannable || !panner()) {
5338 return boost::shared_ptr<AutomationControl>();
5341 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5343 if (c.find (PanLFEAutomation) != c.end()) {
5344 return _pannable->pan_lfe_control;
5346 return boost::shared_ptr<AutomationControl>();
5351 Route::eq_band_cnt () const
5353 if (Profile->get_mixbus()) {
5355 if (is_master() || mixbus()) {
5364 /* Ardour has no well-known EQ object */
5369 boost::shared_ptr<AutomationControl>
5370 Route::eq_gain_controllable (uint32_t band) const
5373 boost::shared_ptr<PluginInsert> eq = _ch_eq;
5376 return boost::shared_ptr<AutomationControl>();
5379 uint32_t port_number;
5380 if (is_master() || mixbus()) {
5382 case 0: port_number = 4; break;
5383 case 1: port_number = 3; break;
5384 case 2: port_number = 2; break;
5386 return boost::shared_ptr<AutomationControl>();
5391 case 0: port_number = 14; break;
5392 case 1: port_number = 12; break;
5393 case 2: port_number = 10; break;
5394 case 3: port_number = 8; break;
5396 return boost::shared_ptr<AutomationControl>();
5400 case 0: port_number = 8; break;
5401 case 1: port_number = 6; break;
5402 case 2: port_number = 4; break;
5404 return boost::shared_ptr<AutomationControl>();
5409 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5411 return boost::shared_ptr<AutomationControl>();
5414 boost::shared_ptr<AutomationControl>
5415 Route::eq_freq_controllable (uint32_t band) const
5418 if (mixbus() || is_master()) {
5419 /* no frequency controls for mixbusses or master */
5420 return boost::shared_ptr<AutomationControl>();
5423 boost::shared_ptr<PluginInsert> eq = _ch_eq;
5426 return boost::shared_ptr<AutomationControl>();
5429 uint32_t port_number;
5432 case 0: port_number = 13; break; // lo
5433 case 1: port_number = 11; break; // lo mid
5434 case 2: port_number = 9; break; // hi mid
5435 case 3: port_number = 7; break; // hi
5437 return boost::shared_ptr<AutomationControl>();
5441 case 0: port_number = 7; break;
5442 case 1: port_number = 5; break;
5443 case 2: port_number = 3; break;
5445 return boost::shared_ptr<AutomationControl>();
5449 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5451 return boost::shared_ptr<AutomationControl>();
5455 boost::shared_ptr<AutomationControl>
5456 Route::eq_q_controllable (uint32_t band) const
5458 return boost::shared_ptr<AutomationControl>();
5461 boost::shared_ptr<AutomationControl>
5462 Route::eq_shape_controllable (uint32_t band) const
5465 if (is_master() || mixbus() || !eq) {
5466 return boost::shared_ptr<AutomationControl>();
5470 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4))); // lo bell
5473 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3))); // hi bell
5479 return boost::shared_ptr<AutomationControl>();
5482 boost::shared_ptr<AutomationControl>
5483 Route::eq_enable_controllable () const
5486 boost::shared_ptr<PluginInsert> eq = _ch_eq;
5489 return boost::shared_ptr<AutomationControl>();
5492 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5494 return boost::shared_ptr<AutomationControl>();
5498 boost::shared_ptr<AutomationControl>
5499 Route::filter_freq_controllable (bool hpf) const
5502 boost::shared_ptr<PluginInsert> eq = _ch_eq;
5504 if (is_master() || mixbus() || !eq) {
5505 return boost::shared_ptr<AutomationControl>();
5509 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5))); // HPF freq
5511 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5515 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 6))); // LPF freq
5517 return boost::shared_ptr<AutomationControl>();
5522 return boost::shared_ptr<AutomationControl>();
5526 boost::shared_ptr<AutomationControl>
5527 Route::filter_slope_controllable (bool) const
5529 return boost::shared_ptr<AutomationControl>();
5532 boost::shared_ptr<AutomationControl>
5533 Route::filter_enable_controllable (bool) const
5536 boost::shared_ptr<PluginInsert> eq = _ch_eq;
5538 if (is_master() || mixbus() || !eq) {
5539 return boost::shared_ptr<AutomationControl>();
5542 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5544 return boost::shared_ptr<AutomationControl>();
5548 boost::shared_ptr<AutomationControl>
5549 Route::tape_drive_controllable () const
5553 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (_ch_pre->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 0)));
5556 return boost::shared_ptr<AutomationControl>();
5559 boost::shared_ptr<ReadOnlyControl>
5560 Route::tape_drive_mtr_controllable () const
5564 return _ch_pre->control_output (is_master() ? 1 : 2);
5567 return boost::shared_ptr<ReadOnlyControl>();
5570 boost::shared_ptr<ReadOnlyControl>
5571 Route::master_correlation_mtr_controllable (bool mm) const
5574 if (is_master() && _ch_post) {
5575 return _ch_post->control_output (mm ? 4 : 3);
5578 return boost::shared_ptr<ReadOnlyControl>();
5581 boost::shared_ptr<AutomationControl>
5582 Route::master_limiter_enable_controllable () const
5585 if (is_master() && _ch_post) {
5586 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (_ch_post->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5589 return boost::shared_ptr<AutomationControl>();
5592 boost::shared_ptr<ReadOnlyControl>
5593 Route::master_limiter_mtr_controllable () const
5596 if (is_master() && _ch_post) {
5597 return _ch_post->control_output (2);
5600 return boost::shared_ptr<ReadOnlyControl>();
5603 boost::shared_ptr<ReadOnlyControl>
5604 Route::master_k_mtr_controllable () const
5607 if (is_master() && _ch_post) {
5608 return _ch_post->control_output (5);
5611 return boost::shared_ptr<ReadOnlyControl>();
5615 Route::eq_band_name (uint32_t band) const
5618 if (is_master() || mixbus()) {
5620 if (Profile->get_mixbus()) {
5622 case 0: return _("lo");
5623 case 1: return _("mid");
5624 case 2: return _("hi");
5625 default: return string();
5633 case 0: return _("lo");
5634 case 1: return _("lm");
5635 case 2: return _("hm");
5636 case 3: return _("hi");
5637 default: return string();
5643 boost::shared_ptr<AutomationControl>
5644 Route::comp_enable_controllable () const
5648 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (_ch_comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5651 return boost::shared_ptr<AutomationControl>();
5653 boost::shared_ptr<AutomationControl>
5654 Route::comp_threshold_controllable () const
5658 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (_ch_comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5661 return boost::shared_ptr<AutomationControl>();
5663 boost::shared_ptr<AutomationControl>
5664 Route::comp_speed_controllable () const
5668 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (_ch_comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3)));
5671 return boost::shared_ptr<AutomationControl>();
5673 boost::shared_ptr<AutomationControl>
5674 Route::comp_mode_controllable () const
5678 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (_ch_comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4)));
5681 return boost::shared_ptr<AutomationControl>();
5683 boost::shared_ptr<AutomationControl>
5684 Route::comp_makeup_controllable () const
5688 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (_ch_comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5)));
5691 return boost::shared_ptr<AutomationControl>();
5693 boost::shared_ptr<ReadOnlyControl>
5694 Route::comp_redux_controllable () const
5698 return _ch_comp->control_output (6);
5701 return boost::shared_ptr<ReadOnlyControl>();
5705 Route::comp_mode_name (uint32_t mode) const
5710 return _("Leveler");
5712 return _("Compressor");
5714 return _("Limiter");
5716 return mixbus() ? _("Sidechain") : _("Limiter");
5726 Route::comp_speed_name (uint32_t mode) const
5744 boost::shared_ptr<AutomationControl>
5745 Route::send_pan_azimuth_controllable (uint32_t n) const
5749 if (n < _mixbus_send->n_busses ()) {
5750 return _mixbus_send->send_pan_ctrl (n + 1);
5754 return boost::shared_ptr<AutomationControl>();
5757 boost::shared_ptr<AutomationControl>
5758 Route::send_level_controllable (uint32_t n) const
5762 if (n < _mixbus_send->n_busses ()) {
5763 return _mixbus_send->send_gain_ctrl (n + 1);
5765 n -= _mixbus_send->n_busses ();
5768 boost::shared_ptr<Send> s = boost::dynamic_pointer_cast<Send>(nth_send (n));
5770 return s->gain_control ();
5772 return boost::shared_ptr<AutomationControl>();
5775 boost::shared_ptr<AutomationControl>
5776 Route::send_enable_controllable (uint32_t n) const
5780 if (n < _mixbus_send->n_busses ()) {
5781 return _mixbus_send->send_enable_ctrl (n + 1);
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>();
5793 boost::shared_ptr<AutomationControl>
5794 Route::send_pan_azimuth_enable_controllable (uint32_t n) const
5798 if (n < _mixbus_send->n_busses ()) {
5799 return _mixbus_send->send_pan_enable_ctrl (n + 1);
5803 return boost::shared_ptr<AutomationControl>();
5807 Route::send_name (uint32_t n) const
5811 if (n < _mixbus_send->n_busses ()) {
5812 return _session.get_mixbus (n)->name();
5814 n -= _mixbus_send->n_busses ();
5817 boost::shared_ptr<Processor> p = nth_send (n);
5824 boost::shared_ptr<AutomationControl>
5825 Route::master_send_enable_controllable () const
5828 if (is_master() || is_monitor() || is_auditioner()) {
5829 return boost::shared_ptr<AutomationControl>();
5833 return _mixbus_send->master_send_enable_ctrl ();
5837 return boost::shared_ptr<AutomationControl>();
5841 Route::slaved () const
5843 if (!_gain_control) {
5846 /* just test one particular control, not all of them */
5847 return _gain_control->slaved ();
5851 Route::slaved_to (boost::shared_ptr<VCA> vca) const
5853 if (!vca || !_gain_control) {
5857 /* just test one particular control, not all of them */
5859 return _gain_control->slaved_to (vca->gain_control());
5863 Route::muted_by_others_soloing () const
5865 if (!can_be_muted_by_others ()) {
5869 return _session.soloing() && !_solo_control->soloed() && !_solo_isolate_control->solo_isolated();
5873 Route::clear_all_solo_state ()
5875 _solo_control->clear_all_solo_state ();
5878 boost::shared_ptr<AutomationControl>
5879 Route::automation_control_recurse (PBD::ID const & id) const
5881 boost::shared_ptr<AutomationControl> ac = Automatable::automation_control (id);
5887 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5889 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5890 if ((ac = (*i)->automation_control (id))) {
5895 return boost::shared_ptr<AutomationControl> ();
5899 Route::slavables () const
5901 SlavableControlList rv;
5902 rv.push_back (_gain_control);
5903 rv.push_back (_mute_control);
5904 rv.push_back (_solo_control);
5909 Route::set_meter_type (MeterType t)
5911 _meter->set_meter_type (t);
5915 Route::meter_type () const
5917 return _meter->meter_type ();
5921 Route::set_disk_io_point (DiskIOPoint diop)
5923 bool display = false;
5925 cerr << "set disk io to " << enum_2_string (diop) << endl;
5936 _disk_writer->set_display_to_user (display);
5940 _disk_reader->set_display_to_user (display);
5943 const bool changed = (diop != _disk_io_point);
5945 _disk_io_point = diop;
5948 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
5949 configure_processors (0);
5952 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
5956 Route::set_loop (Location* l)
5959 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5960 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5966 Route::monitoring_state () const
5968 if (!_disk_reader) {
5969 return MonitoringInput;
5972 /* Explicit requests */
5973 MonitorChoice m (_monitoring_control->monitoring_choice());
5975 if (m != MonitorAuto) {
5977 MonitorState ms ((MonitorState) 0);
5979 if (m & MonitorInput) {
5980 ms = MonitoringInput;
5983 if (m & MonitorDisk) {
5984 ms = MonitorState (ms | MonitoringDisk);
5990 switch (_session.config.get_session_monitoring ()) {
5992 return MonitoringDisk;
5995 return MonitoringInput;
6001 return get_auto_monitoring_state();