2 Copyright (C) 2000 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "libardour-config.h"
29 #include <boost/algorithm/string.hpp>
31 #include "pbd/xml++.h"
32 #include "pbd/enumwriter.h"
33 #include "pbd/locale_guard.h"
34 #include "pbd/memento_command.h"
35 #include "pbd/stacktrace.h"
36 #include "pbd/types_convert.h"
37 #include "pbd/unwind.h"
39 #include "ardour/amp.h"
40 #include "ardour/audio_buffer.h"
41 #include "ardour/audio_track.h"
42 #include "ardour/audio_port.h"
43 #include "ardour/audioengine.h"
44 #include "ardour/boost_debug.h"
45 #include "ardour/buffer.h"
46 #include "ardour/buffer_set.h"
47 #include "ardour/capturing_processor.h"
48 #include "ardour/debug.h"
49 #include "ardour/delivery.h"
50 #include "ardour/disk_reader.h"
51 #include "ardour/disk_writer.h"
52 #include "ardour/event_type_map.h"
53 #include "ardour/gain_control.h"
54 #include "ardour/internal_return.h"
55 #include "ardour/internal_send.h"
56 #include "ardour/meter.h"
57 #include "ardour/delayline.h"
58 #include "ardour/midi_buffer.h"
59 #include "ardour/midi_port.h"
60 #include "ardour/monitor_control.h"
61 #include "ardour/monitor_processor.h"
62 #include "ardour/pannable.h"
63 #include "ardour/panner.h"
64 #include "ardour/panner_shell.h"
65 #include "ardour/parameter_descriptor.h"
66 #include "ardour/phase_control.h"
67 #include "ardour/plugin_insert.h"
68 #include "ardour/port.h"
69 #include "ardour/port_insert.h"
70 #include "ardour/processor.h"
71 #include "ardour/profile.h"
72 #include "ardour/route.h"
73 #include "ardour/route_group.h"
74 #include "ardour/send.h"
75 #include "ardour/session.h"
76 #include "ardour/solo_control.h"
77 #include "ardour/solo_isolate_control.h"
78 #include "ardour/types_convert.h"
79 #include "ardour/unknown_processor.h"
80 #include "ardour/utils.h"
81 #include "ardour/vca.h"
86 using namespace ARDOUR;
89 PBD::Signal3<int,boost::shared_ptr<Route>, boost::shared_ptr<PluginInsert>, Route::PluginSetupOptions > Route::PluginSetup;
91 /** Base class for all routable/mixable objects (tracks and busses) */
92 Route::Route (Session& sess, string name, PresentationInfo::Flag flag, DataType default_type)
93 : Stripable (sess, name, PresentationInfo (flag))
94 , GraphNode (sess._process_graph)
95 , Muteable (sess, name)
98 , _disk_io_point (DiskIOPreFader)
99 , _pending_process_reorder (0)
100 , _pending_signals (0)
101 , _pending_declick (true)
102 , _meter_point (MeterPostFader)
103 , _pending_meter_point (MeterPostFader)
104 , _meter_type (MeterPeak)
105 , _denormal_protection (false)
108 , _declickable (false)
109 , _have_internal_generator (false)
110 , _default_type (default_type)
113 , _in_configure_processors (false)
114 , _initial_io_setup (false)
115 , _in_sidechain_setup (false)
116 , _custom_meter_position_noted (false)
118 , _patch_selector_dialog (0)
120 processor_max_streams.reset();
123 boost::weak_ptr<Route>
124 Route::weakroute () {
125 return boost::weak_ptr<Route> (boost::dynamic_pointer_cast<Route> (shared_from_this ()));
131 /* set default meter type */
133 _meter_type = Config->get_meter_type_master ();
135 else if (dynamic_cast<Track*>(this)) {
136 _meter_type = Config->get_meter_type_track ();
138 _meter_type = Config->get_meter_type_bus ();
141 /* add standard controls */
143 _gain_control.reset (new GainControl (_session, GainAutomation));
144 _trim_control.reset (new GainControl (_session, TrimAutomation));
145 /* While the route has-a gain-control for consistency with Stripable and VCA
146 * ownership is handed over to the Amp Processor which manages the
147 * state of the Control and AutomationList as part of its
148 * Automatable API. -- Don't call add_control () here.
151 _solo_control.reset (new SoloControl (_session, X_("solo"), *this, *this));
152 add_control (_solo_control);
153 _solo_control->Changed.connect_same_thread (*this, boost::bind (&Route::solo_control_changed, this, _1, _2));
155 _mute_control.reset (new MuteControl (_session, X_("mute"), *this));
156 add_control (_mute_control);
158 _phase_control.reset (new PhaseControl (_session, X_("phase")));
159 add_control (_phase_control);
161 _solo_isolate_control.reset (new SoloIsolateControl (_session, X_("solo-iso"), *this, *this));
162 add_control (_solo_isolate_control);
164 _solo_safe_control.reset (new SoloSafeControl (_session, X_("solo-safe")));
165 add_control (_solo_safe_control);
169 if (!(_presentation_info.flags() & PresentationInfo::MonitorOut)) {
170 _pannable.reset (new Pannable (_session));
173 /* input and output objects */
175 _input.reset (new IO (_session, _name, IO::Input, _default_type));
176 _output.reset (new IO (_session, _name, IO::Output, _default_type));
178 _input->changed.connect_same_thread (*this, boost::bind (&Route::input_change_handler, this, _1, _2));
179 _input->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::input_port_count_changing, this, _1));
181 _output->changed.connect_same_thread (*this, boost::bind (&Route::output_change_handler, this, _1, _2));
182 _output->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::output_port_count_changing, this, _1));
184 /* add the amp/fader processor.
185 * it should be the first processor to be added on every route.
188 _amp.reset (new Amp (_session, X_("Fader"), _gain_control, true));
189 add_processor (_amp, PostFader);
192 _amp->set_display_name (_("Monitor"));
195 if (!is_master() && !is_monitor() && !is_auditioner()) {
196 _delayline.reset (new DelayLine (_session, name () + ":in"));
201 _trim.reset (new Amp (_session, X_("Trim"), _trim_control, false));
202 _trim->set_display_to_user (false);
204 if (dynamic_cast<AudioTrack*>(this)) {
205 /* we can't do this in the AudioTrack's constructor
206 * because _trim does not exit then
210 else if (!dynamic_cast<Track*>(this) && ! ( is_monitor() || is_auditioner() )) {
215 /* create standard processors: meter, main outs, monitor out;
216 they will be added to _processors by setup_invisible_processors ()
219 _meter.reset (new PeakMeter (_session, _name));
220 _meter->set_owner (this);
221 _meter->set_display_to_user (false);
224 _main_outs.reset (new Delivery (_session, _output, _pannable, _mute_master, _name, Delivery::Main));
225 _main_outs->activate ();
228 /* where we listen to tracks */
229 _intreturn.reset (new InternalReturn (_session));
230 _intreturn->activate ();
232 /* the thing that provides proper control over a control/monitor/listen bus
233 (such as per-channel cut, dim, solo, invert, etc).
235 _monitor_control.reset (new MonitorProcessor (_session));
236 _monitor_control->activate ();
239 /* now that we have _meter, its safe to connect to this */
242 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
243 configure_processors (0);
251 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
253 /* do this early so that we don't get incoming signals as we are going through destruction
258 /* don't use clear_processors here, as it depends on the session which may
259 be half-destroyed by now
262 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
263 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
264 (*i)->drop_references ();
267 _processors.clear ();
271 Route::ensure_track_or_route_name(string name, Session &session)
273 string newname = name;
275 while (!session.io_name_is_legal (newname)) {
276 newname = bump_name_once (newname, ' ');
283 Route::set_trim (gain_t val, Controllable::GroupControlDisposition /* group override */)
285 // TODO route group, see set_gain()
286 // _trim_control->route_set_value (val);
290 Route::maybe_declick (BufferSet&, samplecnt_t, int)
292 /* this is the "bus" implementation and they never declick.
297 /** Process this route for one (sub) cycle (process thread)
299 * @param bufs Scratch buffers to use for the signal path
300 * @param start_sample Initial transport sample
301 * @param end_sample Final transport sample
302 * @param nframes Number of samples to output (to ports)
304 * Note that (end_sample - start_sample) may not be equal to nframes when the
305 * transport speed isn't 1.0 (eg varispeed).
308 Route::process_output_buffers (BufferSet& bufs,
309 samplepos_t start_sample, samplepos_t end_sample, pframes_t nframes,
310 int declick, bool gain_automation_ok, bool run_disk_reader)
312 /* Caller must hold process lock */
313 assert (!AudioEngine::instance()->process_lock().trylock());
315 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
317 // can this actually happen?
318 // Places that need a WriterLock on (_processor_lock) must also take the process-lock.
319 bufs.silence (nframes, 0);
320 assert (0); // ...one way to find out.
324 /* We should offset the route-owned ctrls by the given latency, however
325 * this only affects Mute. Other route-owned controls (solo, polarity..)
326 * are not automatable.
328 * Mute has its own issues since there's not a single mute-point,
331 automation_run (start_sample, nframes);
333 /* figure out if we're going to use gain automation */
334 if (gain_automation_ok) {
335 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
336 _amp->setup_gain_automation (
337 start_sample + _amp->output_latency (),
338 end_sample + _amp->output_latency (),
341 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
342 _trim->setup_gain_automation (
343 start_sample + _trim->output_latency (),
344 end_sample + _trim->output_latency (),
348 /* We align the playhead to output. The user hears what the clock says:
349 * When the playhead/clock says 1:00:00:00 the user will hear the audio sample
350 * at 1:00:00:00. sample_start will be [sample at] 1:00:00:00
352 * e.g. clock says Time T = 0, sample_start = 0
353 * Disk-read(play) -> latent-plugin (+10) -> fader-automation -> output (+5)
354 * -> total playback latency "disk -> out" is 15.
355 * -> at Time T= -15, the disk-reader reads sample T=0.
356 * By the Time T=0 is reached (dt=15 later) that sample is audible.
359 start_sample += _signal_latency;
360 end_sample += _signal_latency;
362 start_sample += _output->latency ();
363 end_sample += _output->latency ();
365 /* Note: during intial pre-roll 'start_sample' as passed as argument can be negative.
366 * Functions calling process_output_buffers() will set "run_disk_reader"
367 * to false if the pre-roll count-down is larger than playback_latency ().
369 * playback_latency() is guarnteed to be <= _signal_latency + _output->latency ()
371 assert (!_disk_reader || !run_disk_reader || start_sample >= 0);
373 /* however the disk-writer may need to pick up output from other tracks
374 * during pre-roll (in particular if this route has latent effects after the disk).
376 * e.g. track 1 play -> latency A --port--> track2 capture -> latency B ---> out
377 * total pre-roll = A + B.
379 * Note the disk-writer has built-in overlap detection (it's safe to run it early)
382 bool run_disk_writer = false;
384 samplecnt_t latency_preroll = _session.remaining_latency_preroll ();
385 run_disk_writer = latency_preroll < nframes + (_signal_latency + _output->latency ());
388 /* Tell main outs what to do about monitoring. We do this so that
389 * on a transition between monitoring states we get a de-clicking gain
390 * change in the _main_outs delivery, if config.get_use_monitor_fades()
393 * We override this in the case where we have an internal generator.
395 bool silence = _have_internal_generator ? false : (monitoring_state () == MonitoringSilence);
397 _main_outs->no_outs_cuz_we_no_monitor (silence);
399 /* -------------------------------------------------------------------------------------------
400 GLOBAL DECLICK (for transport changes etc.)
401 ----------------------------------------------------------------------------------------- */
403 // XXX not latency compensated. calls Amp::declick, but there may be
404 // plugins between disk and Fader.
405 maybe_declick (bufs, nframes, declick);
406 _pending_declick = 0;
408 /* -------------------------------------------------------------------------------------------
409 DENORMAL CONTROL/PHASE INVERT
410 ----------------------------------------------------------------------------------------- */
412 /* TODO phase-control should become a processor, or rather a Stub-processor:
413 * a point in the chain which calls a special-cased private Route method.
414 * _phase_control is route-owned and dynamic.)
415 * and we should rename it to polarity.
417 * denormals: we'll need to protect silent inputs as well as silent disk
418 * (when not monitoring input). Or simply drop that feature.
420 if (!_phase_control->none()) {
424 if (_denormal_protection || Config->get_denormal_protection()) {
426 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
427 Sample* const sp = i->data();
429 if (_phase_control->inverted (chn)) {
430 for (pframes_t nx = 0; nx < nframes; ++nx) {
435 for (pframes_t nx = 0; nx < nframes; ++nx) {
443 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
444 Sample* const sp = i->data();
446 if (_phase_control->inverted (chn)) {
447 for (pframes_t nx = 0; nx < nframes; ++nx) {
456 if (_denormal_protection || Config->get_denormal_protection()) {
458 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
459 Sample* const sp = i->data();
460 for (pframes_t nx = 0; nx < nframes; ++nx) {
468 /* -------------------------------------------------------------------------------------------
470 ----------------------------------------------------------------------------------------- */
472 /* set this to be true if the meter will already have been ::run() earlier */
473 bool const meter_already_run = metering_state() == MeteringInput;
475 samplecnt_t latency = 0;
476 const double speed = (is_auditioner() ? 1.0 : _session.transport_speed ());
478 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
480 /* TODO check for split cycles here.
482 * start_frame, end_frame is adjusted by latency and may
486 if (meter_already_run && boost::dynamic_pointer_cast<PeakMeter> (*i)) {
487 /* don't ::run() the meter, otherwise it will have its previous peak corrupted */
492 /* if it has any inputs, make sure they match */
493 if (boost::dynamic_pointer_cast<UnknownProcessor> (*i) == 0 && (*i)->input_streams() != ChanCount::ZERO) {
494 if (bufs.count() != (*i)->input_streams()) {
496 DEBUG::Processors, string_compose (
497 "input port mismatch %1 bufs = %2 input for %3 = %4\n",
498 _name, bufs.count(), (*i)->name(), (*i)->input_streams()
505 if (boost::dynamic_pointer_cast<Send>(*i) != 0) {
506 // inform the reader that we're sending a late signal,
507 // relative to original (output aligned) start_sample
508 boost::dynamic_pointer_cast<Send>(*i)->set_delay_in (latency);
510 if (boost::dynamic_pointer_cast<PluginInsert>(*i) != 0) {
511 /* set potential sidechain ports, capture and playback latency.
512 * This effectively sets jack port latency which should include
513 * up/downstream latencies.
515 * However, the value is not used by Ardour (2017-09-20) and calling
516 * IO::latency() is expensive, so we punt.
519 * input()->latenct + latency,
521 * output->latency() + _signal_latency - latency
523 * Also see note below, _signal_latency may be smaller than latency
524 * if a plugin's latency increases while it's running.
526 const samplecnt_t playback_latency = std::max ((samplecnt_t)0, _signal_latency - latency);
527 boost::dynamic_pointer_cast<PluginInsert>(*i)->set_sidechain_latency (
528 /* input->latency() + */ latency, /* output->latency() + */ playback_latency);
531 double pspeed = speed;
532 if ((!run_disk_reader && (*i) == _disk_reader) || (!run_disk_writer && (*i) == _disk_writer)) {
533 /* run with speed 0, no-roll */
537 (*i)->run (bufs, start_sample - latency, end_sample - latency, pspeed, nframes, *i != _processors.back());
538 bufs.set_count ((*i)->output_streams());
540 /* Note: plugin latency may change. While the plugin does inform the session via
541 * processor_latency_changed(). But the session may not yet have gotten around to
542 * update the actual worste-case and update this track's _signal_latency.
544 * So there can be cases where adding up all latencies may not equal _signal_latency.
546 if ((*i)->active ()) {
547 latency += (*i)->signal_latency ();
550 if ((*i) == _delayline) {
551 latency += _delayline->get_delay ();
558 Route::bounce_process (BufferSet& buffers, samplepos_t start, samplecnt_t nframes,
559 boost::shared_ptr<Processor> endpoint,
560 bool include_endpoint, bool for_export, bool for_freeze)
562 /* If no processing is required, there's no need to go any further. */
563 if (!endpoint && !include_endpoint) {
567 samplecnt_t latency = bounce_get_latency(_amp, false, for_export, for_freeze);
568 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
569 _amp->setup_gain_automation (start - latency, start - latency + nframes, nframes);
571 /* trim is always at the top, for bounce no latency compensation is needed */
572 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
573 _trim->setup_gain_automation (start, start + nframes, nframes);
576 const double speed = _session.transport_speed ();
577 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
579 if (!include_endpoint && (*i) == endpoint) {
583 /* if we're *not* exporting, stop processing if we come across a routing processor. */
584 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
587 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
591 /* special case the panner (export outputs)
592 * Ideally we'd only run the panner, not the delivery itself...
593 * but panners need separate input/output buffers and some context
594 * (panshell, panner type, etc). AFAICT there is no ill side effect
595 * of re-using the main delivery when freewheeling/exporting a region.
597 if ((*i) == _main_outs) {
598 assert ((*i)->does_routing());
599 (*i)->run (buffers, start - latency, start - latency + nframes, speed, nframes, true);
600 buffers.set_count ((*i)->output_streams());
603 /* don't run any processors that do routing.
604 * Also don't bother with metering.
606 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
607 (*i)->run (buffers, start - latency, start - latency + nframes, 1.0, nframes, true);
608 buffers.set_count ((*i)->output_streams());
609 latency += (*i)->signal_latency ();
612 if ((*i) == endpoint) {
619 Route::bounce_get_latency (boost::shared_ptr<Processor> endpoint,
620 bool include_endpoint, bool for_export, bool for_freeze) const
622 samplecnt_t latency = 0;
623 if (!endpoint && !include_endpoint) {
627 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
628 if (!include_endpoint && (*i) == endpoint) {
631 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
634 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
637 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
638 latency += (*i)->signal_latency ();
640 if ((*i) == endpoint) {
648 Route::bounce_get_output_streams (ChanCount &cc, boost::shared_ptr<Processor> endpoint,
649 bool include_endpoint, bool for_export, bool for_freeze) const
651 if (!endpoint && !include_endpoint) {
655 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
656 if (!include_endpoint && (*i) == endpoint) {
659 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
662 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
665 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
666 cc = (*i)->output_streams();
668 if ((*i) == endpoint) {
676 Route::n_process_buffers ()
678 return max (_input->n_ports(), processor_max_streams);
682 Route::monitor_run (samplepos_t start_sample, samplepos_t end_sample, pframes_t nframes, int declick)
684 assert (is_monitor());
685 BufferSet& bufs (_session.get_route_buffers (n_process_buffers()));
686 fill_buffers_with_input (bufs, _input, nframes);
687 passthru (bufs, start_sample, end_sample, nframes, declick, true, false);
691 Route::passthru (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_sample, pframes_t nframes, int declick, bool gain_automation_ok, bool run_disk_reader)
695 if (is_monitor() && _session.listening() && !_session.is_auditioning()) {
697 /* control/monitor bus ignores input ports when something is
698 feeding the listen "stream". data will "arrive" into the
699 route from the intreturn processor element.
702 bufs.silence (nframes, 0);
705 /* append immediate messages to the first MIDI buffer (thus sending it to the first output port) */
707 write_out_of_band_data (bufs, start_sample, end_sample, nframes);
709 /* run processor chain */
711 process_output_buffers (bufs, start_sample, end_sample, nframes, declick, gain_automation_ok, run_disk_reader);
715 Route::passthru_silence (samplepos_t start_sample, samplepos_t end_sample, pframes_t nframes, int declick)
717 BufferSet& bufs (_session.get_route_buffers (n_process_buffers(), true));
719 bufs.set_count (_input->n_ports());
720 write_out_of_band_data (bufs, start_sample, end_sample, nframes);
721 process_output_buffers (bufs, start_sample, end_sample, nframes, declick, false, false);
725 Route::set_listen (bool yn)
728 if (_monitor_send->active() == yn) {
732 _monitor_send->activate ();
734 _monitor_send->deactivate ();
740 Route::solo_control_changed (bool, Controllable::GroupControlDisposition)
742 /* nothing to do if we're not using AFL/PFL. But if we are, we need
743 to alter the active state of the monitor send.
746 if (Config->get_solo_control_is_listen_control ()) {
747 set_listen (_solo_control->self_soloed() || _solo_control->get_masters_value());
752 Route::push_solo_isolate_upstream (int32_t delta)
754 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
756 boost::shared_ptr<RouteList> routes = _session.get_routes ();
757 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
759 if ((*i).get() == this || !(*i)->can_solo()) {
764 bool does_feed = feeds (*i, &sends_only);
766 if (does_feed && !sends_only) {
767 (*i)->solo_isolate_control()->mod_solo_isolated_by_upstream (delta);
773 Route::push_solo_upstream (int delta)
775 DEBUG_TRACE (DEBUG::Solo, string_compose("\t ... INVERT push from %1\n", _name));
776 for (FedBy::iterator i = _fed_by.begin(); i != _fed_by.end(); ++i) {
780 boost::shared_ptr<Route> sr (i->r.lock());
782 sr->solo_control()->mod_solo_by_others_downstream (-delta);
789 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
791 cerr << name << " {" << endl;
792 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
793 p != procs.end(); ++p) {
794 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << " @ " << (*p) << endl;
800 /** Supposing that we want to insert a Processor at a given Placement, return
801 * the processor to add the new one before (or 0 to add at the end).
803 boost::shared_ptr<Processor>
804 Route::before_processor_for_placement (Placement p)
806 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
808 ProcessorList::iterator loc;
811 /* generic pre-fader: insert immediately before the amp */
812 loc = find (_processors.begin(), _processors.end(), _amp);
814 /* generic post-fader: insert right before the main outs */
815 loc = find (_processors.begin(), _processors.end(), _main_outs);
818 return loc != _processors.end() ? *loc : boost::shared_ptr<Processor> ();
821 /** Supposing that we want to insert a Processor at a given index, return
822 * the processor to add the new one before (or 0 to add at the end).
824 boost::shared_ptr<Processor>
825 Route::before_processor_for_index (int index)
828 return boost::shared_ptr<Processor> ();
831 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
833 ProcessorList::iterator i = _processors.begin ();
835 while (i != _processors.end() && j < index) {
836 if ((*i)->display_to_user()) {
843 return (i != _processors.end() ? *i : boost::shared_ptr<Processor> ());
846 /** Add a processor either pre- or post-fader
847 * @return 0 on success, non-0 on failure.
850 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err, bool activation_allowed)
852 return add_processor (processor, before_processor_for_placement (placement), err, activation_allowed);
856 /** Add a processor to a route such that it ends up with a given index into the visible processors.
857 * @param index Index to add the processor at, or -1 to add at the end of the list.
858 * @return 0 on success, non-0 on failure.
861 Route::add_processor_by_index (boost::shared_ptr<Processor> processor, int index, ProcessorStreams* err, bool activation_allowed)
863 return add_processor (processor, before_processor_for_index (index), err, activation_allowed);
866 /** Add a processor to the route.
867 * @param before An existing processor in the list, or 0; the new processor will be inserted immediately before it (or at the end).
868 * @return 0 on success, non-0 on failure.
871 Route::add_processor (boost::shared_ptr<Processor> processor, boost::shared_ptr<Processor> before, ProcessorStreams* err, bool activation_allowed)
873 assert (processor != _meter);
874 assert (processor != _main_outs);
876 DEBUG_TRACE (DEBUG::Processors, string_compose (
877 "%1 adding processor %2\n", name(), processor->name()));
881 pl.push_back (processor);
882 int rv = add_processors (pl, before, err);
888 if (activation_allowed && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user ())) {
889 processor->activate ();
896 Route::processor_selfdestruct (boost::weak_ptr<Processor> wp)
898 /* We cannot destruct the processor here (usually RT-thread
899 * with various locks held - in case of sends also io_locks).
900 * Queue for deletion in low-priority thread.
902 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
903 selfdestruct_sequence.push_back (wp);
907 Route::add_processor_from_xml_2X (const XMLNode& node, int version)
909 XMLProperty const * prop;
912 boost::shared_ptr<Processor> processor;
914 /* bit of a hack: get the `placement' property from the <Redirect> tag here
915 so that we can add the processor in the right place (pre/post-fader)
918 XMLNodeList const & children = node.children ();
919 XMLNodeList::const_iterator i = children.begin ();
921 while (i != children.end() && (*i)->name() != X_("Redirect")) {
925 Placement placement = PreFader;
927 if (i != children.end()) {
928 if ((prop = (*i)->property (X_("placement"))) != 0) {
929 placement = Placement (string_2_enum (prop->value(), placement));
933 if (node.name() == "Insert") {
935 if ((prop = node.property ("type")) != 0) {
937 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
938 prop->value() == "lv2" ||
939 prop->value() == "windows-vst" ||
940 prop->value() == "mac-vst" ||
941 prop->value() == "lxvst" ||
942 prop->value() == "audiounit") {
944 if (_session.get_disable_all_loaded_plugins ()) {
945 processor.reset (new UnknownProcessor (_session, node));
947 processor.reset (new PluginInsert (_session));
948 processor->set_owner (this);
953 processor.reset (new PortInsert (_session, _pannable, _mute_master));
958 } else if (node.name() == "Send") {
960 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
961 processor.reset (new Send (_session, sendpan, _mute_master));
965 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
969 if (processor->set_state (node, version)) {
973 //A2 uses the "active" flag in the toplevel redirect node, not in the child plugin/IO
974 if (i != children.end()) {
975 if ((prop = (*i)->property (X_("active"))) != 0) {
976 if ( string_to<bool> (prop->value()) && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user () ) )
977 processor->activate();
979 processor->deactivate();
983 return (add_processor (processor, placement, 0, false) == 0);
986 catch (failed_constructor &err) {
987 warning << _("processor could not be created. Ignored.") << endmsg;
993 inline Route::PluginSetupOptions operator|= (Route::PluginSetupOptions& a, const Route::PluginSetupOptions& b) {
994 return a = static_cast<Route::PluginSetupOptions> (static_cast <int>(a) | static_cast<int> (b));
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));
1002 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
1004 ProcessorList::iterator loc;
1005 boost::shared_ptr <PluginInsert> fanout;
1007 if (g_atomic_int_get (&_pending_process_reorder)) {
1008 /* we need to flush any pending re-order changes */
1009 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1010 apply_processor_changes_rt ();
1014 loc = find(_processors.begin(), _processors.end(), before);
1015 if (loc == _processors.end ()) {
1019 /* nothing specified - at end */
1020 loc = _processors.end ();
1023 if (others.empty()) {
1027 ProcessorList to_skip;
1029 // check if there's an instrument to replace or configure
1030 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1031 boost::shared_ptr<PluginInsert> pi;
1032 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) == 0) {
1035 if (!pi->plugin ()->get_info ()->is_instrument ()) {
1038 boost::shared_ptr<Processor> instrument = the_instrument ();
1039 ChanCount in (DataType::MIDI, 1);
1040 ChanCount out (DataType::AUDIO, 2); // XXX route's out?!
1042 PluginSetupOptions flags = None;
1044 flags |= CanReplace;
1045 in = instrument->input_streams ();
1046 out = instrument->output_streams ();
1048 if (pi->has_output_presets (in, out)) {
1052 pi->set_strict_io (_strict_io);
1054 PluginSetupOptions mask = None;
1055 if (Config->get_ask_replace_instrument ()) {
1058 if (Config->get_ask_setup_instrument ()) {
1064 if (flags != None) {
1065 boost::optional<int> rv = PluginSetup (boost::dynamic_pointer_cast<Route>(shared_from_this ()), pi, flags); /* EMIT SIGNAL */
1066 int mode = rv.get_value_or (0);
1069 to_skip.push_back (*i); // don't add this one;
1072 replace_processor (instrument, *i, err);
1073 to_skip.push_back (*i);
1078 if ((mode & 5) == 4) {
1085 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1086 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1087 ProcessorState pstate (this);
1089 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1094 ProcessorList::iterator check = find (to_skip.begin(), to_skip.end(), *i);
1095 if (check != to_skip.end()) {
1099 boost::shared_ptr<PluginInsert> pi;
1101 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1102 pi->set_strict_io (_strict_io);
1106 /* Ensure that only one amp is in the list at any time */
1107 ProcessorList::iterator check = find (_processors.begin(), _processors.end(), *i);
1108 if (check != _processors.end()) {
1109 if (before == _amp) {
1110 /* Already in position; all is well */
1113 _processors.erase (check);
1118 assert (find (_processors.begin(), _processors.end(), *i) == _processors.end ());
1120 _processors.insert (loc, *i);
1121 (*i)->set_owner (this);
1124 if (configure_processors_unlocked (err, &lm)) {
1126 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
1131 if (pi && pi->has_sidechain ()) {
1132 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
1135 if ((*i)->active()) {
1136 // emit ActiveChanged() and latency_changed() if needed
1140 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1142 boost::shared_ptr<Send> send;
1143 if ((send = boost::dynamic_pointer_cast<Send> (*i))) {
1144 send->SelfDestruct.connect_same_thread (*this,
1145 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (*i)));
1149 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1150 boost::shared_ptr<PluginInsert> pi;
1152 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1153 if (pi->has_no_inputs ()) {
1154 _have_internal_generator = true;
1160 _output->set_user_latency (0);
1163 reset_instrument_info ();
1164 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1165 set_processor_positions ();
1167 if (fanout && fanout->configured ()
1168 && fanout->output_streams().n_audio() > 2
1169 && boost::dynamic_pointer_cast<PluginInsert> (the_instrument ()) == fanout) {
1170 fan_out (); /* EMIT SIGNAL */
1176 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1178 if (p == PreFader) {
1179 start = _processors.begin();
1180 end = find(_processors.begin(), _processors.end(), _amp);
1182 start = find(_processors.begin(), _processors.end(), _amp);
1184 end = _processors.end();
1188 /** Turn off all processors with a given placement
1189 * @param p Placement of processors to disable
1192 Route::disable_processors (Placement p)
1194 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1196 ProcessorList::iterator start, end;
1197 placement_range(p, start, end);
1199 for (ProcessorList::iterator i = start; i != end; ++i) {
1200 (*i)->enable (false);
1203 _session.set_dirty ();
1206 /** Turn off all redirects
1209 Route::disable_processors ()
1211 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1213 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1214 (*i)->enable (false);
1217 _session.set_dirty ();
1220 /** Turn off all redirects with a given placement
1221 * @param p Placement of redirects to disable
1224 Route::disable_plugins (Placement p)
1226 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1228 ProcessorList::iterator start, end;
1229 placement_range(p, start, end);
1231 for (ProcessorList::iterator i = start; i != end; ++i) {
1232 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1233 (*i)->enable (false);
1237 _session.set_dirty ();
1240 /** Turn off all plugins
1243 Route::disable_plugins ()
1245 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1247 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1248 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1249 (*i)->enable (false);
1253 _session.set_dirty ();
1258 Route::ab_plugins (bool forward)
1260 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1264 /* forward = turn off all active redirects, and mark them so that the next time
1265 we go the other way, we will revert them
1268 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1269 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1272 if (!(*i)->display_to_user ()) {
1276 if (boost::dynamic_pointer_cast<PluginInsert> (*i)->is_channelstrip()) {
1281 if ((*i)->enabled ()) {
1282 (*i)->enable (false);
1283 (*i)->set_next_ab_is_active (true);
1285 (*i)->set_next_ab_is_active (false);
1291 /* backward = if the redirect was marked to go active on the next ab, do so */
1293 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1294 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1297 if (!(*i)->display_to_user ()) {
1301 if (boost::dynamic_pointer_cast<PluginInsert> (*i)->is_channelstrip()) {
1306 (*i)->enable ((*i)->get_next_ab_is_active ());
1310 _session.set_dirty ();
1314 /** Remove processors with a given placement.
1315 * @param p Placement of processors to remove.
1318 Route::clear_processors (Placement p)
1320 if (!_session.engine().connected()) {
1324 bool already_deleting = _session.deletion_in_progress();
1325 if (!already_deleting) {
1326 _session.set_deletion_in_progress();
1329 ProcessorList old_list = _processors;
1331 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1332 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1333 ProcessorList new_list;
1334 ProcessorStreams err;
1335 bool seen_amp = false;
1337 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1343 if (is_internal_processor (*i)) {
1345 /* you can't remove these */
1347 new_list.push_back (*i);
1354 new_list.push_back (*i);
1357 (*i)->drop_references ();
1365 (*i)->drop_references ();
1368 new_list.push_back (*i);
1375 _processors = new_list;
1376 configure_processors_unlocked (&err, &lm); // this can't fail
1378 /* drop references w/o process-lock (I/O procs may re-take it in ~IO() */
1381 processor_max_streams.reset();
1382 _have_internal_generator = false;
1383 reset_instrument_info ();
1384 set_processor_positions ();
1386 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1388 if (!already_deleting) {
1389 _session.clear_deletion_in_progress();
1394 Route::is_internal_processor (boost::shared_ptr<Processor> p) const
1396 if (p == _amp || p == _meter || p == _main_outs || p == _delayline || p == _trim) {
1403 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err, bool need_process_lock)
1405 // TODO once the export point can be configured properly, do something smarter here
1406 if (processor == _capturing_processor) {
1407 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1408 if (need_process_lock) {
1412 _capturing_processor.reset();
1414 if (need_process_lock) {
1419 /* these can never be removed */
1421 if (is_internal_processor (processor)) {
1425 if (!_session.engine().connected()) {
1429 processor_max_streams.reset();
1432 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1433 if (need_process_lock) {
1437 /* Caller must hold process lock */
1438 assert (!AudioEngine::instance()->process_lock().trylock());
1440 Glib::Threads::RWLock::WriterLock lm (_processor_lock); // XXX deadlock after export
1442 ProcessorState pstate (this);
1444 ProcessorList::iterator i;
1445 bool removed = false;
1447 for (i = _processors.begin(); i != _processors.end(); ) {
1448 if (*i == processor) {
1450 /* move along, see failure case for configure_processors()
1451 where we may need to reconfigure the processor.
1454 /* stop redirects that send signals to JACK ports
1455 from causing noise as a result of no longer being
1459 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor> (*i);
1460 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
1464 iop = pi->sidechain();
1471 i = _processors.erase (i);
1479 _output->set_user_latency (0);
1487 if (configure_processors_unlocked (err, &lm)) {
1489 /* we know this will work, because it worked before :) */
1490 configure_processors_unlocked (0, &lm);
1494 _have_internal_generator = false;
1496 for (i = _processors.begin(); i != _processors.end(); ++i) {
1497 boost::shared_ptr<PluginInsert> pi;
1499 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1500 if (pi->has_no_inputs ()) {
1501 _have_internal_generator = true;
1506 if (need_process_lock) {
1511 reset_instrument_info ();
1512 processor->drop_references ();
1513 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1514 set_processor_positions ();
1520 Route::replace_processor (boost::shared_ptr<Processor> old, boost::shared_ptr<Processor> sub, ProcessorStreams* err)
1522 /* these can never be removed */
1523 if (is_internal_processor (old)) {
1526 /* and can't be used as substitute, either */
1527 if (is_internal_processor (sub)) {
1531 /* I/Os are out, too */
1532 if (boost::dynamic_pointer_cast<IOProcessor> (old) || boost::dynamic_pointer_cast<IOProcessor> (sub)) {
1536 /* this function cannot be used to swap/reorder processors */
1537 if (find (_processors.begin(), _processors.end(), sub) != _processors.end ()) {
1541 if (!AudioEngine::instance()->connected() || !old || !sub) {
1545 /* ensure that sub is not owned by another route */
1546 if (sub->owner ()) {
1551 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1552 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1553 ProcessorState pstate (this);
1555 assert (find (_processors.begin(), _processors.end(), sub) == _processors.end ());
1557 ProcessorList::iterator i;
1558 bool replaced = false;
1559 bool enable = old->enabled ();
1561 for (i = _processors.begin(); i != _processors.end(); ) {
1563 i = _processors.erase (i);
1564 _processors.insert (i, sub);
1565 sub->set_owner (this);
1578 boost::shared_ptr<PluginInsert> pi;
1579 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(sub)) != 0) {
1580 pi->set_strict_io (true);
1584 if (configure_processors_unlocked (err, &lm)) {
1586 configure_processors_unlocked (0, &lm);
1590 _have_internal_generator = false;
1592 for (i = _processors.begin(); i != _processors.end(); ++i) {
1593 boost::shared_ptr<PluginInsert> pi;
1594 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1595 if (pi->has_no_inputs ()) {
1596 _have_internal_generator = true;
1606 sub->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1607 _output->set_user_latency (0);
1610 reset_instrument_info ();
1611 old->drop_references ();
1612 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1613 set_processor_positions ();
1618 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1620 ProcessorList deleted;
1622 if (!_session.engine().connected()) {
1626 processor_max_streams.reset();
1629 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1630 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1631 ProcessorState pstate (this);
1633 ProcessorList::iterator i;
1634 boost::shared_ptr<Processor> processor;
1636 for (i = _processors.begin(); i != _processors.end(); ) {
1640 /* these can never be removed */
1642 if (is_internal_processor (processor)) {
1647 /* see if its in the list of processors to delete */
1649 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1654 /* stop IOProcessors that send to JACK ports
1655 from causing noise as a result of no longer being
1659 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(processor);
1660 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
1663 iop = pi->sidechain();
1670 deleted.push_back (processor);
1671 i = _processors.erase (i);
1674 if (deleted.empty()) {
1675 /* none of those in the requested list were found */
1679 _output->set_user_latency (0);
1681 if (configure_processors_unlocked (err, &lm)) {
1683 /* we know this will work, because it worked before :) */
1684 configure_processors_unlocked (0, &lm);
1689 _have_internal_generator = false;
1691 for (i = _processors.begin(); i != _processors.end(); ++i) {
1692 boost::shared_ptr<PluginInsert> pi;
1694 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1695 if (pi->has_no_inputs ()) {
1696 _have_internal_generator = true;
1703 /* now try to do what we need to so that those that were removed will be deleted */
1705 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1706 (*i)->drop_references ();
1709 reset_instrument_info ();
1710 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1711 set_processor_positions ();
1717 Route::reset_instrument_info ()
1719 boost::shared_ptr<Processor> instr = the_instrument();
1721 _instrument_info.set_internal_instrument (instr);
1725 /** Caller must hold process lock */
1727 Route::configure_processors (ProcessorStreams* err)
1729 #ifndef PLATFORM_WINDOWS
1730 assert (!AudioEngine::instance()->process_lock().trylock());
1733 if (!_in_configure_processors) {
1734 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1735 return configure_processors_unlocked (err, &lm);
1742 Route::input_streams () const
1744 return _input->n_ports ();
1747 list<pair<ChanCount, ChanCount> >
1748 Route::try_configure_processors (ChanCount in, ProcessorStreams* err)
1750 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1752 return try_configure_processors_unlocked (in, err);
1755 list<pair<ChanCount, ChanCount> >
1756 Route::try_configure_processors_unlocked (ChanCount in, ProcessorStreams* err)
1758 // Check each processor in order to see if we can configure as requested
1760 list<pair<ChanCount, ChanCount> > configuration;
1763 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1764 DEBUG_TRACE (DEBUG::Processors, "{\n");
1766 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1768 if ((*p)->can_support_io_configuration(in, out)) {
1770 if (boost::dynamic_pointer_cast<Delivery> (*p)
1771 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main
1773 && (is_monitor() || _strict_io || Profile->get_mixbus ())) {
1774 /* with strict I/O the panner + output are forced to
1775 * follow the last processor's output.
1777 * Delivery::can_support_io_configuration() will only add ports,
1778 * but not remove excess ports.
1780 * This works because the delivery only requires
1781 * as many outputs as there are inputs.
1782 * Delivery::configure_io() will do the actual removal
1783 * by calling _output->ensure_io()
1785 if (!is_master() && _session.master_out () && in.n_audio() > 0) {
1786 /* ..but at least as many as there are master-inputs, if
1787 * the delivery is dealing with audio */
1788 // XXX this may need special-casing for mixbus (master-outputs)
1789 // and should maybe be a preference anyway ?!
1790 out = ChanCount::max (in, _session.master_out ()->n_inputs ());
1796 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID=%2 in=%3 out=%4\n",(*p)->name(), (*p)->id(), in, out));
1797 configuration.push_back(make_pair(in, out));
1800 // restriction for Monitor Section Processors
1801 if (in.n_audio() != out.n_audio() || out.n_midi() > 0) {
1802 /* Note: The Monitor follows the master-bus and has no panner.
1804 * The general idea is to only allow plugins that retain the channel-count
1805 * and plugins with MIDI in (e.g VSTs with control that will remain unconnected).
1806 * Then again 5.1 in, monitor stereo is a valid use-case.
1808 * and worse: we only refuse adding plugins *here*.
1810 * 1) stereo-master, stereo-mon, add a stereo-plugin, OK
1811 * 2) change master-bus, add a channel
1812 * 2a) monitor-secion follows
1813 * 3) monitor processors fail to re-reconfigure (stereo plugin)
1814 * 4) re-load session, monitor-processor remains unconfigured, crash.
1816 DEBUG_TRACE (DEBUG::Processors, "Monitor: Channel configuration change.\n");
1818 if (boost::dynamic_pointer_cast<InternalSend> (*p)) {
1819 // internal sends make no sense, only feedback
1820 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1821 return list<pair<ChanCount, ChanCount> > ();
1823 if (boost::dynamic_pointer_cast<PortInsert> (*p)) {
1824 /* External Sends can be problematic. one can add/remove ports
1825 * there signal leaves the DAW to external monitors anyway, so there's
1826 * no real use for allowing them here anyway.
1828 DEBUG_TRACE (DEBUG::Processors, "Monitor: No External Sends allowed.\n");
1829 return list<pair<ChanCount, ChanCount> > ();
1831 if (boost::dynamic_pointer_cast<Send> (*p)) {
1833 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1834 return list<pair<ChanCount, ChanCount> > ();
1843 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
1844 DEBUG_TRACE (DEBUG::Processors, string_compose ("---- %1 cannot support in=%2 out=%3\n", (*p)->name(), in, out));
1845 DEBUG_TRACE (DEBUG::Processors, "}\n");
1846 return list<pair<ChanCount, ChanCount> > ();
1850 DEBUG_TRACE (DEBUG::Processors, "}\n");
1852 return configuration;
1855 /** Set the input/output configuration of each processor in the processors list.
1856 * Caller must hold process lock.
1857 * Return 0 on success, otherwise configuration is impossible.
1860 Route::configure_processors_unlocked (ProcessorStreams* err, Glib::Threads::RWLock::WriterLock* lm)
1862 #ifndef PLATFORM_WINDOWS
1863 assert (!AudioEngine::instance()->process_lock().trylock());
1866 if (_in_configure_processors) {
1870 /* put invisible processors where they should be */
1871 setup_invisible_processors ();
1873 _in_configure_processors = true;
1875 list<pair<ChanCount, ChanCount> > configuration = try_configure_processors_unlocked (input_streams (), err);
1877 if (configuration.empty ()) {
1878 _in_configure_processors = false;
1883 bool seen_mains_out = false;
1884 processor_out_streams = _input->n_ports();
1885 processor_max_streams.reset();
1887 /* processor configure_io() may result in adding ports
1888 * e.g. Delivery::configure_io -> ARDOUR::IO::ensure_io ()
1890 * with jack2 adding ports results in a graph-order callback,
1891 * which calls Session::resort_routes() and eventually
1892 * Route::direct_feeds_according_to_reality()
1893 * which takes a ReaderLock (_processor_lock).
1895 * so we can't hold a WriterLock here until jack2 threading
1898 * NB. we still hold the process lock
1900 * (ardour's own engines do call graph-order from the
1901 * process-thread and hence do not have this issue; besides
1902 * merely adding ports won't trigger a graph-order, only
1903 * making connections does)
1907 // TODO check for a potential ReaderLock after ReaderLock ??
1908 Glib::Threads::RWLock::ReaderLock lr (_processor_lock);
1910 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1911 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1913 if (!(*p)->configure_io(c->first, c->second)) {
1914 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration failed\n", _name));
1915 _in_configure_processors = false;
1921 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1922 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1924 boost::shared_ptr<IOProcessor> iop;
1925 boost::shared_ptr<PluginInsert> pi;
1926 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
1927 /* plugins connected via Split or Hide Match may have more channels.
1928 * route/scratch buffers are needed for all of them
1929 * The configuration may only be a subset (both input and output)
1931 processor_max_streams = ChanCount::max(processor_max_streams, pi->required_buffers());
1933 else if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*p)) != 0) {
1934 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_input_streams());
1935 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_output_streams());
1939 if (boost::dynamic_pointer_cast<Delivery> (*p)
1940 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main) {
1941 /* main delivery will increase port count to match input.
1942 * the Delivery::Main is usually the last processor - followed only by
1945 seen_mains_out = true;
1947 if (!seen_mains_out) {
1948 processor_out_streams = out;
1957 _meter->set_max_channels (processor_max_streams);
1960 /* make sure we have sufficient scratch buffers to cope with the new processor
1963 _session.ensure_buffers (n_process_buffers ());
1965 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration complete\n", _name));
1967 _in_configure_processors = false;
1971 /** Set all visible processors to a given active state (except Fader, whose state is not changed)
1972 * @param state New active state for those processors.
1975 Route::all_visible_processors_active (bool state)
1977 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1979 if (_processors.empty()) {
1983 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1984 if (!(*i)->display_to_user() || boost::dynamic_pointer_cast<Amp> (*i)) {
1988 boost::shared_ptr<PluginInsert> pi;
1989 if (0 != (pi = boost::dynamic_pointer_cast<PluginInsert>(*i))) {
1990 if (pi->is_channelstrip ()) {
1995 (*i)->enable (state);
1998 _session.set_dirty ();
2002 Route::processors_reorder_needs_configure (const ProcessorList& new_order)
2004 /* check if re-order requires re-configuration of any processors
2005 * -> compare channel configuration for all processors
2007 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2008 ChanCount c = input_streams ();
2010 for (ProcessorList::const_iterator j = new_order.begin(); j != new_order.end(); ++j) {
2012 if (c != (*j)->input_streams()) {
2015 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2018 if ((*i)->input_streams() != c) {
2021 c = (*i)->output_streams();
2033 __attribute__((annotate("realtime")))
2036 Route::apply_processor_order (const ProcessorList& new_order)
2038 /* need to hold processor_lock; either read or write lock
2039 * and the engine process_lock.
2040 * Due to r/w lock ambiguity we can only assert the latter
2042 assert (!AudioEngine::instance()->process_lock().trylock());
2045 /* "new_order" is an ordered list of processors to be positioned according to "placement".
2046 * NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
2047 * processors in the current actual processor list that are hidden. Any visible processors
2048 * in the current list but not in "new_order" will be assumed to be deleted.
2051 /* "as_it_will_be" and "_processors" are lists of shared pointers.
2052 * actual memory usage is small, but insert/erase is not actually rt-safe :(
2053 * (note though that ::processors_reorder_needs_configure() ensured that
2054 * this function will only ever be called from the rt-thread if no processor were removed)
2056 * either way, I can't proove it, but an x-run due to re-order here is less likley
2057 * than an x-run-less 'ardour-silent cycle' both of which effectively "click".
2060 ProcessorList as_it_will_be;
2061 ProcessorList::iterator oiter;
2062 ProcessorList::const_iterator niter;
2064 oiter = _processors.begin();
2065 niter = new_order.begin();
2067 while (niter != new_order.end()) {
2069 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
2070 then append it to the temp list.
2072 Otherwise, see if the next processor in the old list is in the new list. if not,
2073 its been deleted. If its there, append it to the temp list.
2076 if (oiter == _processors.end()) {
2078 /* no more elements in the old list, so just stick the rest of
2079 the new order onto the temp list.
2082 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
2083 while (niter != new_order.end()) {
2090 if (!(*oiter)->display_to_user()) {
2092 as_it_will_be.push_back (*oiter);
2096 /* visible processor: check that its in the new order */
2098 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
2099 /* deleted: do nothing, shared_ptr<> will clean up */
2101 /* ignore this one, and add the next item from the new order instead */
2102 as_it_will_be.push_back (*niter);
2107 /* now remove from old order - its taken care of no matter what */
2108 oiter = _processors.erase (oiter);
2112 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
2114 /* If the meter is in a custom position, find it and make a rough note of its position */
2115 maybe_note_meter_position ();
2119 Route::move_instrument_down (bool postfader)
2121 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2122 ProcessorList new_order;
2123 boost::shared_ptr<Processor> instrument;
2124 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2125 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
2126 if (pi && pi->plugin ()->get_info ()->is_instrument ()) {
2128 } else if (instrument && *i == _amp) {
2130 new_order.push_back (*i);
2131 new_order.push_back (instrument);
2133 new_order.push_back (instrument);
2134 new_order.push_back (*i);
2137 new_order.push_back (*i);
2144 reorder_processors (new_order, 0);
2148 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
2150 // it a change is already queued, wait for it
2151 // (unless engine is stopped. apply immediately and proceed
2152 while (g_atomic_int_get (&_pending_process_reorder)) {
2153 if (!AudioEngine::instance()->running()) {
2154 DEBUG_TRACE (DEBUG::Processors, "offline apply queued processor re-order.\n");
2155 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2157 apply_processor_order(_pending_processor_order);
2158 setup_invisible_processors ();
2160 g_atomic_int_set (&_pending_process_reorder, 0);
2162 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2163 set_processor_positions ();
2165 // TODO rather use a semaphore or something.
2166 // but since ::reorder_processors() is called
2167 // from the GUI thread, this is fine..
2172 if (processors_reorder_needs_configure (new_order) || !AudioEngine::instance()->running()) {
2174 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2175 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2176 ProcessorState pstate (this);
2178 apply_processor_order (new_order);
2180 if (configure_processors_unlocked (err, &lm)) {
2188 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2189 set_processor_positions ();
2192 DEBUG_TRACE (DEBUG::Processors, "Queue clickless processor re-order.\n");
2193 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2195 // _pending_processor_order is protected by _processor_lock
2196 _pending_processor_order = new_order;
2197 g_atomic_int_set (&_pending_process_reorder, 1);
2200 /* update processor input/output latency
2201 * (total signal_latency does not change)
2203 update_signal_latency (true);
2209 Route::add_remove_sidechain (boost::shared_ptr<Processor> proc, bool add)
2211 boost::shared_ptr<PluginInsert> pi;
2212 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2216 if (pi->has_sidechain () == add) {
2217 return true; // ?? call failed, but result is as expected.
2221 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2222 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2223 if (i == _processors.end ()) {
2229 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ()); // take before Writerlock to avoid deadlock
2230 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2231 PBD::Unwinder<bool> uw (_in_sidechain_setup, true);
2233 lx.release (); // IO::add_port() and ~IO takes process lock - XXX check if this is safe
2235 if (!pi->add_sidechain ()) {
2239 if (!pi->del_sidechain ()) {
2245 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2250 pi->del_sidechain ();
2252 pi->add_sidechain ();
2253 // TODO restore side-chain's state.
2258 configure_processors_unlocked (0, &lm);
2261 if (pi->has_sidechain ()) {
2262 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
2265 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2266 _session.set_dirty ();
2271 Route::plugin_preset_output (boost::shared_ptr<Processor> proc, ChanCount outs)
2273 boost::shared_ptr<PluginInsert> pi;
2274 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2279 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2280 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2281 if (i == _processors.end ()) {
2287 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2288 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2290 const ChanCount& old (pi->preset_out ());
2291 if (!pi->set_preset_out (outs)) {
2292 return true; // no change, OK
2295 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2298 pi->set_preset_out (old);
2301 configure_processors_unlocked (0, &lm);
2304 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2305 _session.set_dirty ();
2310 Route::reset_plugin_insert (boost::shared_ptr<Processor> proc)
2313 return customize_plugin_insert (proc, 0, unused, unused);
2317 Route::customize_plugin_insert (boost::shared_ptr<Processor> proc, uint32_t count, ChanCount outs, ChanCount sinks)
2319 boost::shared_ptr<PluginInsert> pi;
2320 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2325 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2326 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2327 if (i == _processors.end ()) {
2333 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2334 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2336 bool old_cust = pi->custom_cfg ();
2337 uint32_t old_cnt = pi->get_count ();
2338 ChanCount old_chan = pi->output_streams ();
2339 ChanCount old_sinks = pi->natural_input_streams ();
2342 pi->set_custom_cfg (false);
2344 pi->set_custom_cfg (true);
2345 pi->set_count (count);
2346 pi->set_outputs (outs);
2347 pi->set_sinks (sinks);
2350 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2354 pi->set_count (old_cnt);
2355 pi->set_sinks (old_sinks);
2356 pi->set_outputs (old_chan);
2357 pi->set_custom_cfg (old_cust);
2361 configure_processors_unlocked (0, &lm);
2364 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2365 _session.set_dirty ();
2370 Route::set_strict_io (const bool enable)
2372 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2374 if (_strict_io != enable) {
2375 _strict_io = enable;
2376 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2377 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2378 boost::shared_ptr<PluginInsert> pi;
2379 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2380 pi->set_strict_io (_strict_io);
2384 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2388 _strict_io = !enable; // restore old value
2389 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2390 boost::shared_ptr<PluginInsert> pi;
2391 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2392 pi->set_strict_io (_strict_io);
2399 configure_processors (0);
2402 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2403 _session.set_dirty ();
2415 Route::get_template()
2417 return state(false);
2421 Route::state(bool full_state)
2423 if (!_session._template_state_dir.empty()) {
2424 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), _session._template_state_dir));
2427 XMLNode *node = new XMLNode("Route");
2428 ProcessorList::iterator i;
2430 node->set_property (X_("id"), id ());
2431 node->set_property (X_("name"), name());
2432 node->set_property (X_("default-type"), _default_type);
2433 node->set_property (X_("strict-io"), _strict_io);
2435 node->add_child_nocopy (_presentation_info.get_state());
2437 node->set_property (X_("active"), _active);
2438 node->set_property (X_("denormal-protection"), _denormal_protection);
2439 node->set_property (X_("meter-point"), _meter_point);
2440 node->set_property (X_("disk-io-point"), _disk_io_point);
2442 node->set_property (X_("meter-type"), _meter_type);
2445 node->set_property (X_("route-group"), _route_group->name());
2448 node->add_child_nocopy (_solo_control->get_state ());
2449 node->add_child_nocopy (_solo_isolate_control->get_state ());
2450 node->add_child_nocopy (_solo_safe_control->get_state ());
2452 node->add_child_nocopy (_input->state (full_state));
2453 node->add_child_nocopy (_output->state (full_state));
2454 node->add_child_nocopy (_mute_master->get_state ());
2456 node->add_child_nocopy (_mute_control->get_state ());
2457 node->add_child_nocopy (_phase_control->get_state ());
2460 node->add_child_nocopy (Automatable::get_automation_xml_state ());
2463 if (_comment.length()) {
2464 XMLNode *cmt = node->add_child ("Comment");
2465 cmt->add_content (_comment);
2469 node->add_child_nocopy (_pannable->state (full_state));
2473 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2474 for (i = _processors.begin(); i != _processors.end(); ++i) {
2476 /* template save: do not include internal sends functioning as
2477 aux sends because the chance of the target ID
2478 in the session where this template is used
2481 similarly, do not save listen sends which connect to
2482 the monitor section, because these will always be
2485 boost::shared_ptr<InternalSend> is;
2487 if ((is = boost::dynamic_pointer_cast<InternalSend> (*i)) != 0) {
2488 if (is->role() == Delivery::Listen) {
2493 node->add_child_nocopy((*i)->state (full_state));
2498 node->add_child_copy (*_extra_xml);
2501 if (_custom_meter_position_noted) {
2502 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
2504 node->set_property (X_("processor-after-last-custom-meter"), after->id());
2508 if (!_session._template_state_dir.empty()) {
2509 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), ""));
2512 node->add_child_copy (Slavable::get_state());
2518 Route::set_state (const XMLNode& node, int version)
2520 if (version < 3000) {
2521 return set_state_2X (node, version);
2525 XMLNodeConstIterator niter;
2528 if (node.name() != "Route"){
2529 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2533 std::string route_name;
2534 if (node.get_property (X_("name"), route_name)) {
2535 Route::set_name (route_name);
2539 _initial_io_setup = true;
2541 Stripable::set_state (node, version);
2543 node.get_property (X_("strict-io"), _strict_io);
2546 /* monitor bus does not get a panner, but if (re)created
2547 via XML, it will already have one by the time we
2548 call ::set_state(). so ... remove it.
2553 /* add all processors (except amp, which is always present) */
2555 nlist = node.children();
2556 XMLNode processor_state (X_("processor_state"));
2558 Stateful::save_extra_xml (node);
2560 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2564 if (child->name() == IO::state_node_name) {
2565 std::string direction;
2566 if (!child->get_property (X_("direction"), direction)) {
2570 if (direction == "Input") {
2571 _input->set_state (*child, version);
2572 } else if (direction == "Output") {
2573 _output->set_state (*child, version);
2576 } else if (child->name() == X_("Processor")) {
2577 processor_state.add_child_copy (*child);
2578 } else if (child->name() == X_("Pannable")) {
2580 _pannable->set_state (*child, version);
2582 warning << string_compose (_("Pannable state found for route (%1) without a panner!"), name()) << endmsg;
2584 } else if (child->name() == Slavable::xml_node_name) {
2585 Slavable::set_state (*child, version);
2590 if (node.get_property (X_("meter-point"), mp)) {
2591 set_meter_point (mp, true);
2593 _meter->set_display_to_user (_meter_point == MeterCustom);
2598 if (node.get_property (X_("disk-io-point"), diop)) {
2600 _disk_writer->set_display_to_user (diop == DiskIOCustom);
2603 _disk_reader->set_display_to_user (diop == DiskIOCustom);
2605 set_disk_io_point (diop);
2608 node.get_property (X_("meter-type"), _meter_type);
2610 _initial_io_setup = false;
2612 set_processor_state (processor_state);
2614 // this looks up the internal instrument in processors
2615 reset_instrument_info();
2617 bool denormal_protection;
2618 if (node.get_property (X_("denormal-protection"), denormal_protection)) {
2619 set_denormal_protection (denormal_protection);
2622 /* convert old 3001 state */
2623 std::string phase_invert_str;
2624 if (node.get_property (X_("phase-invert"), phase_invert_str)) {
2625 _phase_control->set_phase_invert (boost::dynamic_bitset<> (phase_invert_str));
2629 if (node.get_property (X_("active"), is_active)) {
2630 set_active (is_active, this);
2633 std::string id_string;
2634 if (node.get_property (X_("processor-after-last-custom-meter"), id_string)) {
2635 PBD::ID id (id_string);
2636 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2637 ProcessorList::const_iterator i = _processors.begin ();
2638 while (i != _processors.end() && (*i)->id() != id) {
2642 if (i != _processors.end ()) {
2643 _processor_after_last_custom_meter = *i;
2644 _custom_meter_position_noted = true;
2648 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2651 if (child->name() == X_("Comment")) {
2653 /* XXX this is a terrible API design in libxml++ */
2655 XMLNode *cmt = *(child->children().begin());
2656 _comment = cmt->content();
2658 } else if (child->name() == Controllable::xml_node_name) {
2659 std::string control_name;
2660 if (!child->get_property (X_("name"), control_name)) {
2664 if (control_name == _solo_control->name()) {
2665 _solo_control->set_state (*child, version);
2666 } else if (control_name == _solo_safe_control->name()) {
2667 _solo_safe_control->set_state (*child, version);
2668 } else if (control_name == _solo_isolate_control->name()) {
2669 _solo_isolate_control->set_state (*child, version);
2670 } else if (control_name == _mute_control->name()) {
2671 _mute_control->set_state (*child, version);
2672 } else if (control_name == _phase_control->name()) {
2673 _phase_control->set_state (*child, version);
2675 Evoral::Parameter p = EventTypeMap::instance().from_symbol (control_name);
2676 if (p.type () >= MidiCCAutomation && p.type () < MidiSystemExclusiveAutomation) {
2677 boost::shared_ptr<AutomationControl> ac = automation_control (p, true);
2679 ac->set_state (*child, version);
2683 } else if (child->name() == MuteMaster::xml_node_name) {
2684 _mute_master->set_state (*child, version);
2686 } else if (child->name() == Automatable::xml_node_name) {
2687 set_automation_xml_state (*child, Evoral::Parameter(NullAutomation));
2695 Route::set_state_2X (const XMLNode& node, int version)
2699 XMLNodeConstIterator niter;
2701 XMLProperty const * prop;
2703 /* 2X things which still remain to be handled:
2709 if (node.name() != "Route") {
2710 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2714 Stripable::set_state (node, version);
2716 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2717 set_denormal_protection (string_to<bool> (prop->value()));
2720 if ((prop = node.property (X_("muted"))) != 0) {
2723 bool muted = string_to<bool> (prop->value());
2729 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2731 if (string_to<bool> (prop->value())){
2732 mute_point = mute_point + "PreFader";
2737 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2739 if (string_to<bool> (prop->value())){
2742 mute_point = mute_point + ",";
2745 mute_point = mute_point + "PostFader";
2750 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2752 if (string_to<bool> (prop->value())){
2755 mute_point = mute_point + ",";
2758 mute_point = mute_point + "Listen";
2763 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2765 if (string_to<bool> (prop->value())){
2768 mute_point = mute_point + ",";
2771 mute_point = mute_point + "Main";
2775 _mute_master->set_mute_points (mute_point);
2776 _mute_master->set_muted_by_self (true);
2780 if ((prop = node.property (X_("meter-point"))) != 0) {
2781 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2786 nlist = node.children ();
2787 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2791 if (child->name() == IO::state_node_name) {
2793 /* there is a note in IO::set_state_2X() about why we have to call
2797 _input->set_state_2X (*child, version, true);
2798 _output->set_state_2X (*child, version, false);
2800 if ((prop = child->property (X_("name"))) != 0) {
2801 Route::set_name (prop->value ());
2806 if ((prop = child->property (X_("active"))) != 0) {
2807 bool yn = string_to<bool> (prop->value());
2808 _active = !yn; // force switch
2809 set_active (yn, this);
2812 if ((prop = child->property (X_("gain"))) != 0) {
2815 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
2816 _amp->gain_control()->set_value (val, Controllable::NoGroup);
2820 /* Set up Panners in the IO */
2821 XMLNodeList io_nlist = child->children ();
2823 XMLNodeConstIterator io_niter;
2826 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
2828 io_child = *io_niter;
2830 if (io_child->name() == X_("Panner")) {
2831 _main_outs->panner_shell()->set_state(*io_child, version);
2832 } else if (io_child->name() == X_("Automation")) {
2833 /* IO's automation is for the fader */
2834 _amp->set_automation_xml_state (*io_child, Evoral::Parameter (GainAutomation));
2840 XMLNodeList redirect_nodes;
2842 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2846 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2847 redirect_nodes.push_back(child);
2852 set_processor_state_2X (redirect_nodes, version);
2854 Stateful::save_extra_xml (node);
2856 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2859 if (child->name() == X_("Comment")) {
2861 /* XXX this is a terrible API design in libxml++ */
2863 XMLNode *cmt = *(child->children().begin());
2864 _comment = cmt->content();
2866 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2867 if (prop->value() == X_("solo")) {
2868 _solo_control->set_state (*child, version);
2869 } else if (prop->value() == X_("mute")) {
2870 _mute_control->set_state (*child, version);
2880 Route::get_processor_state ()
2882 XMLNode* root = new XMLNode (X_("redirects"));
2883 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2884 root->add_child_nocopy ((*i)->state (true));
2891 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2893 /* We don't bother removing existing processors not in nList, as this
2894 method will only be called when creating a Route from scratch, not
2895 for undo purposes. Just put processors in at the appropriate place
2899 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2900 add_processor_from_xml_2X (**i, version);
2905 Route::set_processor_state (const XMLNode& node)
2907 const XMLNodeList &nlist = node.children();
2908 XMLNodeConstIterator niter;
2909 ProcessorList new_order;
2910 bool must_configure = false;
2912 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2914 XMLProperty* prop = (*niter)->property ("type");
2916 if (prop->value() == "amp") {
2917 _amp->set_state (**niter, Stateful::current_state_version);
2918 new_order.push_back (_amp);
2919 } else if (prop->value() == "trim") {
2920 _trim->set_state (**niter, Stateful::current_state_version);
2921 new_order.push_back (_trim);
2922 } else if (prop->value() == "meter") {
2923 _meter->set_state (**niter, Stateful::current_state_version);
2924 new_order.push_back (_meter);
2925 } else if (prop->value() == "delay") {
2927 } else if (prop->value() == "main-outs") {
2928 _main_outs->set_state (**niter, Stateful::current_state_version);
2929 } else if (prop->value() == "intreturn") {
2931 _intreturn.reset (new InternalReturn (_session));
2932 must_configure = true;
2934 _intreturn->set_state (**niter, Stateful::current_state_version);
2935 } else if (is_monitor() && prop->value() == "monitor") {
2936 if (!_monitor_control) {
2937 _monitor_control.reset (new MonitorProcessor (_session));
2938 must_configure = true;
2940 _monitor_control->set_state (**niter, Stateful::current_state_version);
2941 } else if (prop->value() == "capture") {
2942 /* CapturingProcessor should never be restored, it's always
2943 added explicitly when needed */
2944 } else if (prop->value() == "diskreader" && _disk_reader) {
2945 _disk_reader->set_state (**niter, Stateful::current_state_version);
2946 new_order.push_back (_disk_reader);
2947 } else if (prop->value() == "diskwriter" && _disk_writer) {
2948 _disk_writer->set_state (**niter, Stateful::current_state_version);
2949 new_order.push_back (_disk_writer);
2951 set_processor_state (**niter, prop, new_order, must_configure);
2955 ProcessorList old_list = _processors; // keep a copy
2957 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2958 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2959 /* re-assign _processors w/o process-lock.
2960 * if there's an IO-processor present in _processors but
2961 * not in new_order, it will be deleted and ~IO takes
2964 _processors = new_order;
2966 if (must_configure) {
2967 configure_processors_unlocked (0, &lm);
2970 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2972 (*i)->set_owner (this);
2973 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
2975 boost::shared_ptr<PluginInsert> pi;
2977 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
2978 if (pi->has_no_inputs ()) {
2979 _have_internal_generator = true;
2985 /* drop references w/o process-lock (I/O procs may re-take it in ~IO() */
2988 reset_instrument_info ();
2989 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2990 set_processor_positions ();
2994 Route::set_processor_state (XMLNode const & node, XMLProperty const* prop, ProcessorList& new_order, bool& must_configure)
2996 ProcessorList::iterator o;
2998 for (o = _processors.begin(); o != _processors.end(); ++o) {
2999 XMLProperty const * id_prop = node.property(X_("id"));
3000 if (id_prop && (*o)->id() == id_prop->value()) {
3001 (*o)->set_state (node, Stateful::current_state_version);
3002 new_order.push_back (*o);
3007 // If the processor (node) is not on the route then create it
3009 if (o == _processors.end()) {
3011 boost::shared_ptr<Processor> processor;
3013 if (prop->value() == "intsend") {
3015 processor.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), boost::shared_ptr<Route>(), Delivery::Aux, true));
3017 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
3018 prop->value() == "lv2" ||
3019 prop->value() == "windows-vst" ||
3020 prop->value() == "mac-vst" ||
3021 prop->value() == "lxvst" ||
3022 prop->value() == "luaproc" ||
3023 prop->value() == "audiounit") {
3025 if (_session.get_disable_all_loaded_plugins ()) {
3026 processor.reset (new UnknownProcessor (_session, node));
3028 processor.reset (new PluginInsert (_session));
3029 processor->set_owner (this);
3031 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
3032 pi->set_strict_io (true);
3036 } else if (prop->value() == "port") {
3038 processor.reset (new PortInsert (_session, _pannable, _mute_master));
3040 } else if (prop->value() == "send") {
3042 processor.reset (new Send (_session, _pannable, _mute_master, Delivery::Send, true));
3043 boost::shared_ptr<Send> send = boost::dynamic_pointer_cast<Send> (processor);
3044 send->SelfDestruct.connect_same_thread (*this,
3045 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (processor)));
3051 if (processor->set_state (node, Stateful::current_state_version) != 0) {
3052 /* This processor could not be configured. Turn it into a UnknownProcessor */
3053 processor.reset (new UnknownProcessor (_session, node));
3056 /* subscribe to Sidechain IO changes */
3057 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
3058 if (pi && pi->has_sidechain ()) {
3059 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
3062 /* we have to note the monitor send here, otherwise a new one will be created
3063 and the state of this one will be lost.
3065 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
3066 if (isend && isend->role() == Delivery::Listen) {
3067 _monitor_send = isend;
3070 /* it doesn't matter if invisible processors are added here, as they
3071 will be sorted out by setup_invisible_processors () shortly.
3074 new_order.push_back (processor);
3075 must_configure = true;
3081 Route::curve_reallocate ()
3083 // _gain_automation_curve.finish_resize ();
3084 // _pan_automation_curve.finish_resize ();
3088 Route::silence (samplecnt_t nframes)
3090 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3095 silence_unlocked (nframes);
3099 Route::silence_unlocked (samplecnt_t nframes)
3101 /* Must be called with the processor lock held */
3103 const samplepos_t now = _session.transport_sample ();
3107 _output->silence (nframes);
3109 // update owned automated controllables
3110 automation_run (now, nframes);
3112 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3113 boost::shared_ptr<PluginInsert> pi;
3115 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
3116 /* evaluate automated automation controls */
3117 pi->automation_run (now, nframes);
3118 /* skip plugins, they don't need anything when we're not active */
3122 (*i)->silence (nframes, now);
3125 if (nframes == _session.get_block_size()) {
3132 Route::add_internal_return ()
3135 _intreturn.reset (new InternalReturn (_session));
3136 add_processor (_intreturn, PreFader);
3141 Route::add_send_to_internal_return (InternalSend* send)
3143 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3145 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3146 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3149 return d->add_send (send);
3155 Route::remove_send_from_internal_return (InternalSend* send)
3157 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3159 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3160 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3163 return d->remove_send (send);
3169 Route::enable_monitor_send ()
3171 /* Caller must hold process lock */
3172 assert (!AudioEngine::instance()->process_lock().trylock());
3174 /* master never sends to monitor section via the normal mechanism */
3175 assert (!is_master ());
3176 assert (!is_monitor ());
3178 /* make sure we have one */
3179 if (!_monitor_send) {
3180 _monitor_send.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), _session.monitor_out(), Delivery::Listen));
3181 _monitor_send->set_display_to_user (false);
3185 configure_processors (0);
3188 /** Add an aux send to a route.
3189 * @param route route to send to.
3190 * @param before Processor to insert before, or 0 to insert at the end.
3193 Route::add_aux_send (boost::shared_ptr<Route> route, boost::shared_ptr<Processor> before)
3195 assert (route != _session.monitor_out ());
3198 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3200 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3202 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend> (*x);
3204 if (d && d->target_route() == route) {
3205 /* already listening via the specified IO: do nothing */
3213 boost::shared_ptr<InternalSend> listener;
3216 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
3217 listener.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), route, Delivery::Aux));
3220 add_processor (listener, before);
3222 } catch (failed_constructor& err) {
3230 Route::remove_aux_or_listen (boost::shared_ptr<Route> route)
3232 ProcessorStreams err;
3233 ProcessorList::iterator tmp;
3236 Glib::Threads::RWLock::ReaderLock rl(_processor_lock);
3238 /* have to do this early because otherwise processor reconfig
3239 * will put _monitor_send back in the list
3242 if (route == _session.monitor_out()) {
3243 _monitor_send.reset ();
3247 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3249 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
3251 if (d && d->target_route() == route) {
3253 if (remove_processor (*x, &err, false) > 0) {
3259 /* list could have been demolished while we dropped the lock
3262 if (_session.engine().connected()) {
3263 /* i/o processors cannot be removed if the engine is not running
3264 * so don't live-loop in case the engine is N/A or dies
3274 Route::set_comment (string cmt, void *src)
3278 _session.set_dirty ();
3282 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
3284 FeedRecord fr (other, via_sends_only);
3286 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
3288 if (!result.second) {
3290 /* already a record for "other" - make sure sends-only information is correct */
3291 if (!via_sends_only && result.first->sends_only) {
3292 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
3293 frp->sends_only = false;
3297 return result.second;
3301 Route::clear_fed_by ()
3307 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
3309 const FedBy& fed_by (other->fed_by());
3311 for (FedBy::const_iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
3312 boost::shared_ptr<Route> sr = f->r.lock();
3314 if (sr && (sr.get() == this)) {
3316 if (via_sends_only) {
3317 *via_sends_only = f->sends_only;
3328 Route::all_inputs () const
3330 /* TODO, if this works as expected,
3331 * cache the IOVector and maintain it via
3332 * input_change_handler(), sidechain_change_handler() etc
3335 ios.push_back (_input);
3337 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3338 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3340 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3341 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3344 iop = pi->sidechain();
3347 if (iop != 0 && iop->input()) {
3348 ios.push_back (iop->input());
3355 Route::all_outputs () const
3358 // _output is included via Delivery
3359 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3360 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3361 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3362 if (iop != 0 && iop->output()) {
3363 ios.push_back (iop->output());
3370 Route::direct_feeds_according_to_reality (boost::shared_ptr<Route> other, bool* via_send_only)
3372 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
3373 if (other->all_inputs().fed_by (_output)) {
3374 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
3375 if (via_send_only) {
3376 *via_send_only = false;
3382 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3384 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
3386 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3387 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3390 iop = pi->sidechain();
3394 boost::shared_ptr<const IO> iop_out = iop->output();
3395 if (other.get() == this && iop_out && iop->input() && iop_out->connected_to (iop->input())) {
3396 // TODO this needs a delaylines in the Insert to align connections (!)
3397 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed its own return (%2)\n", iop->name(), other->name()));
3400 if ((iop_out && other->all_inputs().fed_by (iop_out)) || iop->feeds (other)) {
3401 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
3402 if (via_send_only) {
3403 *via_send_only = true;
3407 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
3410 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
3415 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
3420 Route::direct_feeds_according_to_graph (boost::shared_ptr<Route> other, bool* via_send_only)
3422 return _session._current_route_graph.has (boost::dynamic_pointer_cast<Route> (shared_from_this ()), other, via_send_only);
3426 Route::feeds_according_to_graph (boost::shared_ptr<Route> other)
3428 return _session._current_route_graph.feeds (boost::dynamic_pointer_cast<Route> (shared_from_this ()), other);
3431 /** Called from the (non-realtime) butler thread when the transport is stopped */
3433 Route::non_realtime_transport_stop (samplepos_t now, bool flush)
3435 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3437 Automatable::non_realtime_transport_stop (now, flush);
3439 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3441 if (!_have_internal_generator && (Config->get_plugins_stop_with_transport() && flush)) {
3445 (*i)->non_realtime_transport_stop (now, flush);
3450 Route::input_change_handler (IOChange change, void * /*src*/)
3452 if ((change.type & IOChange::ConfigurationChanged)) {
3453 /* This is called with the process lock held if change
3454 contains ConfigurationChanged
3456 configure_processors (0);
3457 _phase_control->resize (_input->n_ports().n_audio ());
3458 io_changed (); /* EMIT SIGNAL */
3461 if (_solo_control->soloed_by_others_upstream() || _solo_isolate_control->solo_isolated_by_upstream()) {
3464 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3465 if (_input->connected()) {
3466 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3467 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3471 bool does_feed = (*i)->direct_feeds_according_to_reality (boost::dynamic_pointer_cast<Route> (shared_from_this()), &sends_only);
3472 if (does_feed && !sends_only) {
3473 if ((*i)->soloed()) {
3476 if ((*i)->solo_isolate_control()->solo_isolated()) {
3483 int delta = sbou - _solo_control->soloed_by_others_upstream();
3484 int idelta = ibou - _solo_isolate_control->solo_isolated_by_upstream();
3487 PBD::warning << string_compose (
3488 _("Invalid Solo-Isolate propagation: from:%1 new:%2 - old:%3 = delta:%4"),
3489 _name, ibou, _solo_isolate_control->solo_isolated_by_upstream(), idelta)
3494 if (_solo_control->soloed_by_others_upstream()) {
3495 // ignore new connections (they're not propagated)
3497 _solo_control->mod_solo_by_others_upstream (delta);
3501 if (_solo_isolate_control->solo_isolated_by_upstream()) {
3502 // solo-isolate currently only propagates downstream
3504 _solo_isolate_control->mod_solo_isolated_by_upstream (1);
3506 //_solo_isolated_by_upstream = ibou;
3509 // Session::route_solo_changed does not propagate indirect solo-changes
3510 // propagate downstream to tracks
3511 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3512 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3516 bool does_feed = feeds (*i, &sends_only);
3517 if (delta <= 0 && does_feed && !sends_only) {
3518 (*i)->solo_control()->mod_solo_by_others_upstream (delta);
3521 if (idelta < 0 && does_feed && !sends_only) {
3522 (*i)->solo_isolate_control()->mod_solo_isolated_by_upstream (-1);
3529 Route::output_change_handler (IOChange change, void * /*src*/)
3531 if (_initial_io_setup) {
3535 if ((change.type & IOChange::ConfigurationChanged)) {
3536 /* This is called with the process lock held if change
3537 contains ConfigurationChanged
3539 configure_processors (0);
3542 _session.reset_monitor_section();
3545 io_changed (); /* EMIT SIGNAL */
3548 if ((change.type & IOChange::ConnectionsChanged)) {
3550 /* do this ONLY if connections have changed. Configuration
3551 * changes do not, by themselves alter solo upstream or
3552 * downstream status.
3555 if (_solo_control->soloed_by_others_downstream()) {
3557 /* checking all all downstream routes for
3558 * explicit of implict solo is a rather drastic measure,
3559 * ideally the input_change_handler() of the other route
3560 * would propagate the change to us.
3562 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3563 if (_output->connected()) {
3564 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3565 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3569 bool does_feed = direct_feeds_according_to_reality (*i, &sends_only);
3570 if (does_feed && !sends_only) {
3571 if ((*i)->soloed()) {
3579 int delta = sbod - _solo_control->soloed_by_others_downstream();
3581 // do not allow new connections to change implicit solo (no propagation)
3582 _solo_control->mod_solo_by_others_downstream (delta);
3583 // Session::route_solo_changed() does not propagate indirect solo-changes
3584 // propagate upstream to tracks
3585 boost::shared_ptr<Route> shared_this = boost::dynamic_pointer_cast<Route> (shared_from_this());
3586 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3587 if ((*i).get() == this || !can_solo()) {
3591 bool does_feed = (*i)->feeds (shared_this, &sends_only);
3592 if (delta != 0 && does_feed && !sends_only) {
3593 (*i)->solo_control()->mod_solo_by_others_downstream (delta);
3603 Route::sidechain_change_handler (IOChange change, void* src)
3605 if (_initial_io_setup || _in_sidechain_setup) {
3609 input_change_handler (change, src);
3613 Route::pans_required () const
3615 if (n_outputs().n_audio() < 2) {
3619 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
3623 Route::flush_processor_buffers_locked (samplecnt_t nframes)
3625 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3626 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery> (*i);
3628 d->flush_buffers (nframes);
3630 boost::shared_ptr<PortInsert> p = boost::dynamic_pointer_cast<PortInsert> (*i);
3632 p->flush_buffers (nframes);
3639 Route::no_roll (pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, bool session_state_changing)
3641 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3648 silence_unlocked (nframes);
3652 if (session_state_changing) {
3653 if (_session.transport_speed() != 0.0f) {
3654 /* we're rolling but some state is changing (e.g. our diskstream contents)
3655 so we cannot use them. Be silent till this is over.
3657 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
3659 silence_unlocked (nframes);
3662 /* we're really not rolling, so we're either delivery silence or actually
3663 monitoring, both of which are safe to do while session_state_changing is true.
3667 no_roll_unlocked (nframes, start_sample, end_sample);
3673 Route::no_roll_unlocked (pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample)
3675 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3677 fill_buffers_with_input (bufs, _input, nframes);
3679 /* filter captured data before meter sees it */
3680 filter_input (bufs);
3682 if (_meter_point == MeterInput) {
3683 _meter->run (bufs, start_sample, end_sample, 0.0, nframes, true);
3686 passthru (bufs, start_sample, end_sample, nframes, 0, true, false);
3688 flush_processor_buffers_locked (nframes);
3692 Route::playback_latency (bool incl_downstream) const
3696 rv = _disk_reader->output_latency ();
3698 rv = _signal_latency;
3700 if (incl_downstream) {
3701 rv += _output->connected_latency (true);
3703 rv += _output->latency ();
3709 Route::latency_preroll (pframes_t nframes, samplepos_t& start_sample, samplepos_t& end_sample)
3711 samplecnt_t latency_preroll = _session.remaining_latency_preroll ();
3712 if (latency_preroll == 0) {
3715 if (!_disk_reader) {
3716 start_sample -= latency_preroll;
3717 end_sample -= latency_preroll;
3721 samplecnt_t route_offset = playback_latency ();
3723 if (latency_preroll > route_offset + nframes) {
3724 no_roll_unlocked (nframes, start_sample - latency_preroll, end_sample - latency_preroll);
3728 if (latency_preroll > route_offset) {
3730 samplecnt_t skip = latency_preroll - route_offset;
3731 no_roll_unlocked (skip, start_sample - latency_preroll, start_sample - latency_preroll + skip);
3733 if (nframes == skip) {
3737 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3738 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3739 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor> (*i);
3741 iop->increment_port_buffer_offset (skip);
3744 _input->increment_port_buffer_offset (skip);
3745 _output->increment_port_buffer_offset (skip);
3747 start_sample -= route_offset;
3748 end_sample -= route_offset;
3750 return nframes - skip;
3753 start_sample -= latency_preroll;
3754 end_sample -= latency_preroll;
3759 Route::roll (pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, int declick, bool& need_butler)
3761 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3768 silence_unlocked (nframes);
3769 if (_meter_point == MeterInput && ((_monitoring_control->monitoring_choice() & MonitorInput) || (!_disk_writer || _disk_writer->record_enabled()))) {
3774 if ((nframes = latency_preroll (nframes, start_sample, end_sample)) == 0) {
3780 BufferSet& bufs = _session.get_route_buffers (n_process_buffers ());
3782 fill_buffers_with_input (bufs, _input, nframes);
3784 /* filter captured data before meter sees it */
3785 filter_input (bufs);
3787 if (_meter_point == MeterInput &&
3788 ((_monitoring_control->monitoring_choice() & MonitorInput) || (_disk_writer && _disk_writer->record_enabled()))) {
3789 _meter->run (bufs, start_sample, end_sample, 1.0 /*speed()*/, nframes, true);
3792 passthru (bufs, start_sample, end_sample, nframes, declick, (!_disk_writer || !_disk_writer->record_enabled()) && _session.transport_rolling(), true);
3794 if ((_disk_reader && _disk_reader->need_butler()) || (_disk_writer && _disk_writer->need_butler())) {
3798 flush_processor_buffers_locked (nframes);
3804 Route::silent_roll (pframes_t nframes, samplepos_t /*start_sample*/, samplepos_t /*end_sample*/, bool& /* need_butler */)
3807 flush_processor_buffers_locked (nframes);
3812 Route::flush_processors ()
3814 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3816 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3822 __attribute__((annotate("realtime")))
3825 Route::apply_processor_changes_rt ()
3827 int emissions = EmitNone;
3829 if (_pending_meter_point != _meter_point) {
3830 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3832 /* meters always have buffers for 'processor_max_streams'
3833 * they can be re-positioned without re-allocation */
3834 if (set_meter_point_unlocked()) {
3835 emissions |= EmitMeterChanged | EmitMeterVisibilityChange;;
3837 emissions |= EmitMeterChanged;
3842 bool changed = false;
3844 if (g_atomic_int_get (&_pending_process_reorder)) {
3845 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3847 apply_processor_order (_pending_processor_order);
3848 setup_invisible_processors ();
3850 g_atomic_int_set (&_pending_process_reorder, 0);
3851 emissions |= EmitRtProcessorChange;
3855 set_processor_positions ();
3856 /* update processor input/output latency
3857 * (total signal_latency does not change)
3859 update_signal_latency (true);
3861 if (emissions != 0) {
3862 g_atomic_int_set (&_pending_signals, emissions);
3865 return (!selfdestruct_sequence.empty ());
3869 Route::emit_pending_signals ()
3871 int sig = g_atomic_int_and (&_pending_signals, 0);
3872 if (sig & EmitMeterChanged) {
3873 _meter->emit_configuration_changed();
3874 meter_change (); /* EMIT SIGNAL */
3875 if (sig & EmitMeterVisibilityChange) {
3876 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3878 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3881 if (sig & EmitRtProcessorChange) {
3882 processors_changed (RouteProcessorChange (RouteProcessorChange::RealTimeChange)); /* EMIT SIGNAL */
3885 /* this would be a job for the butler.
3886 * Conceptually we should not take processe/processor locks here.
3887 * OTOH its more efficient (less overhead for summoning the butler and
3888 * telling her what do do) and signal emission is called
3889 * directly after the process callback, which decreases the chance
3890 * of x-runs when taking the locks.
3892 while (!selfdestruct_sequence.empty ()) {
3893 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
3894 if (selfdestruct_sequence.empty ()) { break; } // re-check with lock
3895 boost::shared_ptr<Processor> proc = selfdestruct_sequence.back ().lock ();
3896 selfdestruct_sequence.pop_back ();
3899 remove_processor (proc);
3905 Route::set_meter_point (MeterPoint p, bool force)
3907 if (_pending_meter_point == p && !force) {
3911 if (force || !AudioEngine::instance()->running()) {
3912 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3913 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3914 _pending_meter_point = p;
3915 _meter->emit_configuration_changed();
3916 meter_change (); /* EMIT SIGNAL */
3917 if (set_meter_point_unlocked()) {
3918 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3920 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3923 _pending_meter_point = p;
3929 __attribute__((annotate("realtime")))
3932 Route::set_meter_point_unlocked ()
3935 /* Caller must hold process and processor write lock */
3936 assert (!AudioEngine::instance()->process_lock().trylock());
3937 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3938 assert (!lm.locked ());
3941 _meter_point = _pending_meter_point;
3943 bool meter_was_visible_to_user = _meter->display_to_user ();
3945 if (!_custom_meter_position_noted) {
3946 maybe_note_meter_position ();
3949 if (_meter_point != MeterCustom) {
3951 _meter->set_display_to_user (false);
3953 setup_invisible_processors ();
3956 _meter->set_display_to_user (true);
3958 /* If we have a previous position for the custom meter, try to put it there */
3959 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
3961 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), after);
3962 if (i != _processors.end ()) {
3963 _processors.remove (_meter);
3964 _processors.insert (i, _meter);
3966 } else {// at end, right before the mains_out/panner
3967 _processors.remove (_meter);
3968 ProcessorList::iterator main = _processors.end();
3969 _processors.insert (--main, _meter);
3973 /* Set up the meter for its new position */
3975 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
3979 if (loc == _processors.begin()) {
3980 m_in = _input->n_ports();
3982 ProcessorList::iterator before = loc;
3984 m_in = (*before)->output_streams ();
3987 _meter->reflect_inputs (m_in);
3989 /* we do not need to reconfigure the processors, because the meter
3990 (a) is always ready to handle processor_max_streams
3991 (b) is always an N-in/N-out processor, and thus moving
3992 it doesn't require any changes to the other processors.
3995 /* these should really be done after releasing the lock
3996 * but all those signals are subscribed to with gui_thread()
3999 return (_meter->display_to_user() != meter_was_visible_to_user);
4003 Route::listen_position_changed ()
4006 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4007 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
4008 ProcessorState pstate (this);
4010 if (configure_processors_unlocked (0, &lm)) {
4011 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
4013 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
4018 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
4019 _session.set_dirty ();
4022 boost::shared_ptr<CapturingProcessor>
4023 Route::add_export_point()
4025 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4026 if (!_capturing_processor) {
4028 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4029 Glib::Threads::RWLock::WriterLock lw (_processor_lock);
4031 /* Align all tracks for stem-export w/o processing.
4032 * Compensate for all plugins between the this route's disk-reader
4033 * and the common final downstream output (ie alignment point for playback).
4035 _capturing_processor.reset (new CapturingProcessor (_session, playback_latency (true)));
4036 configure_processors_unlocked (0, &lw);
4037 _capturing_processor->activate ();
4040 return _capturing_processor;
4044 Route::update_signal_latency (bool apply_to_delayline)
4046 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4048 samplecnt_t l_in = 0; // _input->latency ();
4049 samplecnt_t l_out = _output->user_latency();
4050 for (ProcessorList::reverse_iterator i = _processors.rbegin(); i != _processors.rend(); ++i) {
4051 (*i)->set_output_latency (l_out);
4052 if ((*i)->active ()) {
4053 l_out += (*i)->signal_latency ();
4057 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal signal latency = %2\n", _name, l_out));
4059 _signal_latency = l_out;
4061 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4062 if ((*i)->active ()) {
4063 l_in += (*i)->signal_latency ();
4065 (*i)->set_input_latency (l_in);
4066 (*i)->set_playback_offset (_signal_latency + _output->latency ());
4067 (*i)->set_capture_offset (_input->latency ());
4073 if (apply_to_delayline) {
4074 /* see also Session::post_playback_latency() */
4075 apply_latency_compensation ();
4078 if (_signal_latency != l_out) {
4079 signal_latency_changed (); /* EMIT SIGNAL */
4082 return _signal_latency;
4086 Route::set_user_latency (samplecnt_t nframes)
4088 _output->set_user_latency (nframes);
4089 _session.update_latency_compensation ();
4093 Route::apply_latency_compensation ()
4096 samplecnt_t old = _delayline->get_delay ();
4098 samplecnt_t play_lat_in = _input->connected_latency (true);
4099 samplecnt_t play_lat_out = _output->connected_latency (true);
4100 samplecnt_t latcomp = play_lat_in - play_lat_out - _signal_latency;
4103 samplecnt_t capt_lat_in = _input->connected_latency (false);
4104 samplecnt_t capt_lat_out = _output->connected_latency (false);
4105 samplecnt_t latcomp_capt = capt_lat_out - capt_lat_in - _signal_latency;
4107 cout << "ROUTE " << name() << " delay for " << latcomp << " (c: " << latcomp_capt << ")" << endl;
4110 _delayline->set_delay (latcomp > 0 ? latcomp : 0);
4112 if (old != _delayline->get_delay ()) {
4113 signal_latency_updated (); /* EMIT SIGNAL */
4119 Route::set_block_size (pframes_t nframes)
4121 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4122 (*i)->set_block_size (nframes);
4125 _session.ensure_buffers (n_process_buffers ());
4129 Route::protect_automation ()
4131 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
4132 (*i)->protect_automation();
4135 /** @param declick 1 to set a pending declick fade-in,
4136 * -1 to set a pending declick fade-out
4139 Route::set_pending_declick (int declick)
4142 /* this call is not allowed to turn off a pending declick */
4144 _pending_declick = declick;
4147 _pending_declick = 0;
4151 /** Shift automation forwards from a particular place, thereby inserting time.
4152 * Adds undo commands for any shifts that are performed.
4154 * @param pos Position to start shifting from.
4155 * @param samples Amount to shift forwards by.
4159 Route::shift (samplepos_t pos, samplecnt_t samples)
4161 /* gain automation */
4163 boost::shared_ptr<AutomationControl> gc = _amp->gain_control();
4165 XMLNode &before = gc->alist()->get_state ();
4166 gc->alist()->shift (pos, samples);
4167 XMLNode &after = gc->alist()->get_state ();
4168 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
4171 /* gain automation */
4173 boost::shared_ptr<AutomationControl> gc = _trim->gain_control();
4175 XMLNode &before = gc->alist()->get_state ();
4176 gc->alist()->shift (pos, samples);
4177 XMLNode &after = gc->alist()->get_state ();
4178 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
4181 // TODO mute automation ??
4183 /* pan automation */
4185 ControlSet::Controls& c (_pannable->controls());
4187 for (ControlSet::Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
4188 boost::shared_ptr<AutomationControl> pc = boost::dynamic_pointer_cast<AutomationControl> (ci->second);
4190 boost::shared_ptr<AutomationList> al = pc->alist();
4191 XMLNode& before = al->get_state ();
4192 al->shift (pos, samples);
4193 XMLNode& after = al->get_state ();
4194 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4199 /* redirect automation */
4201 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4202 for (ProcessorList::iterator i = _processors.begin (); i != _processors.end (); ++i) {
4204 set<Evoral::Parameter> parameters = (*i)->what_can_be_automated();
4206 for (set<Evoral::Parameter>::const_iterator p = parameters.begin (); p != parameters.end (); ++p) {
4207 boost::shared_ptr<AutomationControl> ac = (*i)->automation_control (*p);
4209 boost::shared_ptr<AutomationList> al = ac->alist();
4210 XMLNode &before = al->get_state ();
4211 al->shift (pos, samples);
4212 XMLNode &after = al->get_state ();
4213 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4221 Route::set_plugin_state_dir (boost::weak_ptr<Processor> p, const std::string& d)
4223 boost::shared_ptr<Processor> processor (p.lock ());
4224 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
4228 pi->set_state_dir (d);
4232 Route::save_as_template (const string& path, const string& name, const string& description)
4234 std::string state_dir = path.substr (0, path.find_last_of ('.')); // strip template_suffix
4235 PBD::Unwinder<std::string> uw (_session._template_state_dir, state_dir);
4237 XMLNode& node (state (false));
4238 node.set_property (X_("name"), name);
4240 node.remove_nodes (X_("description"));
4241 if (!description.empty()) {
4242 XMLNode* desc = new XMLNode(X_("description"));
4243 XMLNode* desc_cont = new XMLNode(X_("content"), description);
4244 desc->add_child_nocopy (*desc_cont);
4246 node.add_child_nocopy (*desc);
4251 IO::set_name_in_state (*node.children().front(), name);
4253 tree.set_root (&node);
4255 /* return zero on success, non-zero otherwise */
4256 return !tree.write (path.c_str());
4261 Route::set_name (const string& str)
4267 if (str == name()) {
4271 string name = Route::ensure_track_or_route_name (str, _session);
4272 SessionObject::set_name (name);
4274 bool ret = (_input->set_name(name) && _output->set_name(name));
4277 /* rename the main outs. Leave other IO processors
4278 * with whatever name they already have, because its
4279 * just fine as it is (it will not contain the route
4280 * name if its a port insert, port send or port return).
4284 if (_main_outs->set_name (name)) {
4285 /* XXX returning false here is stupid because
4286 we already changed the route name.
4296 /** Set the name of a route in an XML description.
4297 * @param node XML <Route> node to set the name in.
4298 * @param name New name.
4301 Route::set_name_in_state (XMLNode& node, string const & name, bool rename_playlist)
4303 node.set_property (X_("name"), name);
4305 XMLNodeList children = node.children();
4306 for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
4308 if ((*i)->name() == X_("IO")) {
4310 IO::set_name_in_state (**i, name);
4312 } else if ((*i)->name() == X_("Processor")) {
4315 if ((*i)->get_property (X_("role"), str) && str == X_("Main")) {
4316 (*i)->set_property (X_("name"), name);
4319 } else if ((*i)->name() == X_("Diskstream")) {
4321 if (rename_playlist) {
4322 (*i)->set_property (X_("playlist"), name + ".1");
4324 (*i)->set_property (X_("name"), name);
4330 boost::shared_ptr<Send>
4331 Route::internal_send_for (boost::shared_ptr<const Route> target) const
4333 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4335 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4336 boost::shared_ptr<InternalSend> send;
4338 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
4339 if (send->target_route() == target) {
4345 return boost::shared_ptr<Send>();
4349 Route::set_denormal_protection (bool yn)
4351 if (_denormal_protection != yn) {
4352 _denormal_protection = yn;
4353 denormal_protection_changed (); /* EMIT SIGNAL */
4358 Route::denormal_protection () const
4360 return _denormal_protection;
4364 Route::set_active (bool yn, void* src)
4366 if (_session.transport_rolling()) {
4370 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_route_active()) {
4371 _route_group->foreach_route (boost::bind (&Route::set_active, _1, yn, _route_group));
4375 if (_active != yn) {
4377 _input->set_active (yn);
4378 _output->set_active (yn);
4379 flush_processors ();
4380 active_changed (); // EMIT SIGNAL
4381 _session.set_dirty ();
4385 boost::shared_ptr<Pannable>
4386 Route::pannable() const
4391 boost::shared_ptr<Panner>
4392 Route::panner() const
4395 return _main_outs->panner_shell()->panner();
4398 boost::shared_ptr<PannerShell>
4399 Route::panner_shell() const
4401 return _main_outs->panner_shell();
4404 boost::shared_ptr<GainControl>
4405 Route::gain_control() const
4407 return _gain_control;
4410 boost::shared_ptr<GainControl>
4411 Route::trim_control() const
4413 return _trim_control;
4416 boost::shared_ptr<PhaseControl>
4417 Route::phase_control() const
4419 return _phase_control;
4422 boost::shared_ptr<AutomationControl>
4423 Route::get_control (const Evoral::Parameter& param)
4425 /* either we own the control or .... */
4427 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
4431 /* maybe one of our processors does or ... */
4433 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
4434 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4435 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
4443 /* nobody does so we'll make a new one */
4445 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
4452 boost::shared_ptr<Processor>
4453 Route::nth_plugin (uint32_t n) const
4455 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4456 ProcessorList::const_iterator i;
4458 for (i = _processors.begin(); i != _processors.end(); ++i) {
4459 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
4466 return boost::shared_ptr<Processor> ();
4469 boost::shared_ptr<Processor>
4470 Route::nth_send (uint32_t n) const
4472 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4473 ProcessorList::const_iterator i;
4475 for (i = _processors.begin(); i != _processors.end(); ++i) {
4476 if (boost::dynamic_pointer_cast<Send> (*i)) {
4478 if ((*i)->name().find (_("Monitor")) == 0) {
4479 /* send to monitor section is not considered
4480 to be an accessible send.
4491 return boost::shared_ptr<Processor> ();
4495 Route::has_io_processor_named (const string& name)
4497 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4498 ProcessorList::iterator i;
4500 for (i = _processors.begin(); i != _processors.end(); ++i) {
4501 if (boost::dynamic_pointer_cast<Send> (*i) ||
4502 boost::dynamic_pointer_cast<PortInsert> (*i)) {
4503 if ((*i)->name() == name) {
4513 Route::set_processor_positions ()
4515 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4517 bool had_amp = false;
4518 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4519 (*i)->set_pre_fader (!had_amp);
4526 /** Called when there is a proposed change to the input port count */
4528 Route::input_port_count_changing (ChanCount to)
4530 list<pair<ChanCount, ChanCount> > c = try_configure_processors (to, 0);
4532 /* The processors cannot be configured with the new input arrangement, so
4538 /* The change is ok */
4542 /** Called when there is a proposed change to the output port count */
4544 Route::output_port_count_changing (ChanCount to)
4546 if (_strict_io && !_in_configure_processors) {
4549 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
4550 if (processor_out_streams.get(*t) > to.get(*t)) {
4554 /* The change is ok */
4559 Route::unknown_processors () const
4563 if (_session.get_disable_all_loaded_plugins ()) {
4564 // Do not list "missing plugins" if they are explicitly disabled
4568 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4569 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4570 if (boost::dynamic_pointer_cast<UnknownProcessor const> (*i)) {
4571 p.push_back ((*i)->name ());
4580 Route::update_port_latencies (PortSet& from, PortSet& to, bool playback, samplecnt_t our_latency) const
4582 /* we assume that all our input ports feed all our output ports. its not
4583 universally true, but the alternative is way too corner-case to worry about.
4586 LatencyRange all_connections;
4589 all_connections.min = 0;
4590 all_connections.max = 0;
4592 all_connections.min = ~((pframes_t) 0);
4593 all_connections.max = 0;
4595 /* iterate over all "from" ports and determine the latency range for all of their
4596 connections to the "outside" (outside of this Route).
4599 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4603 p->get_connected_latency_range (range, playback);
4605 all_connections.min = min (all_connections.min, range.min);
4606 all_connections.max = max (all_connections.max, range.max);
4610 /* set the "from" port latencies to the max/min range of all their connections */
4612 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4613 p->set_private_latency_range (all_connections, playback);
4616 /* set the ports "in the direction of the flow" to the same value as above plus our own signal latency */
4618 all_connections.min += our_latency;
4619 all_connections.max += our_latency;
4621 for (PortSet::iterator p = to.begin(); p != to.end(); ++p) {
4622 p->set_private_latency_range (all_connections, playback);
4625 return all_connections.max;
4629 Route::set_private_port_latencies (bool playback) const
4631 samplecnt_t own_latency = 0;
4633 /* Processor list not protected by lock: MUST BE CALLED FROM PROCESS THREAD
4634 OR LATENCY CALLBACK.
4636 This is called (early) from the latency callback. It computes the REAL
4637 latency associated with each port and stores the result as the "private"
4638 latency of the port. A later call to Route::set_public_port_latencies()
4639 sets all ports to the same value to reflect the fact that we do latency
4640 compensation and so all signals are delayed by the same amount as they
4641 flow through ardour.
4644 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4645 if ((*i)->active ()) {
4646 own_latency += (*i)->signal_latency ();
4651 /* playback: propagate latency from "outside the route" to outputs to inputs */
4652 return update_port_latencies (_output->ports (), _input->ports (), true, own_latency);
4654 /* capture: propagate latency from "outside the route" to inputs to outputs */
4655 return update_port_latencies (_input->ports (), _output->ports (), false, own_latency);
4660 Route::set_public_port_latencies (samplecnt_t value, bool playback) const
4662 /* this is called to set the JACK-visible port latencies, which take
4663 latency compensation into account.
4672 const PortSet& ports (_input->ports());
4673 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4674 p->set_public_latency_range (range, playback);
4679 const PortSet& ports (_output->ports());
4680 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4681 p->set_public_latency_range (range, playback);
4686 /** Put the invisible processors in the right place in _processors.
4687 * Must be called with a writer lock on _processor_lock held.
4690 __attribute__((annotate("realtime")))
4693 Route::setup_invisible_processors ()
4696 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4697 assert (!lm.locked ());
4701 /* too early to be doing this stuff */
4705 /* we'll build this new list here and then use it
4707 * TODO put the ProcessorList is on the stack for RT-safety.
4710 ProcessorList new_processors;
4711 ProcessorList::iterator dr;
4712 ProcessorList::iterator dw;
4714 /* find visible processors */
4716 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4717 if ((*i)->display_to_user ()) {
4718 new_processors.push_back (*i);
4724 ProcessorList::iterator amp = find (new_processors.begin(), new_processors.end(), _amp);
4726 if (amp == new_processors.end ()) {
4727 error << string_compose (_("Amp/Fader on Route '%1' went AWOL. Re-added."), name()) << endmsg;
4728 new_processors.push_front (_amp);
4729 amp = find (new_processors.begin(), new_processors.end(), _amp);
4732 /* and the processor after the amp */
4734 ProcessorList::iterator after_amp = amp;
4740 switch (_meter_point) {
4742 assert (!_meter->display_to_user ());
4743 new_processors.push_front (_meter);
4746 assert (!_meter->display_to_user ());
4747 new_processors.insert (amp, _meter);
4749 case MeterPostFader:
4750 /* do nothing here */
4753 /* do nothing here */
4756 /* the meter is visible, so we don't touch it here */
4763 assert (_main_outs);
4764 assert (!_main_outs->display_to_user ());
4765 new_processors.push_back (_main_outs);
4767 /* iterator for the main outs */
4769 ProcessorList::iterator main = new_processors.end();
4772 /* OUTPUT METERING */
4774 if (_meter && (_meter_point == MeterOutput || _meter_point == MeterPostFader)) {
4775 assert (!_meter->display_to_user ());
4777 /* add the processor just before or just after the main outs */
4779 ProcessorList::iterator meter_point = main;
4781 if (_meter_point == MeterOutput) {
4784 new_processors.insert (meter_point, _meter);
4789 if (_monitor_send && !is_monitor ()) {
4790 assert (!_monitor_send->display_to_user ());
4791 switch (Config->get_listen_position ()) {
4792 case PreFaderListen:
4793 switch (Config->get_pfl_position ()) {
4794 case PFLFromBeforeProcessors:
4795 new_processors.push_front (_monitor_send);
4797 case PFLFromAfterProcessors:
4798 new_processors.insert (amp, _monitor_send);
4801 _monitor_send->set_can_pan (false);
4803 case AfterFaderListen:
4804 switch (Config->get_afl_position ()) {
4805 case AFLFromBeforeProcessors:
4806 new_processors.insert (after_amp, _monitor_send);
4808 case AFLFromAfterProcessors:
4809 new_processors.insert (new_processors.end(), _monitor_send);
4812 _monitor_send->set_can_pan (true);
4817 /* MONITOR CONTROL */
4819 if (_monitor_control && is_monitor ()) {
4820 assert (!_monitor_control->display_to_user ());
4821 new_processors.insert (amp, _monitor_control);
4826 ProcessorList::iterator trim = new_processors.end();
4828 if (_trim->active()) {
4829 assert (!_trim->display_to_user ());
4830 new_processors.push_front (_trim);
4831 trim = new_processors.begin();
4834 /* INTERNAL RETURN */
4836 /* doing this here means that any monitor control will come after
4837 the return and trim.
4841 assert (!_intreturn->display_to_user ());
4842 new_processors.push_front (_intreturn);
4845 /* DISK READER & WRITER (for Track objects) */
4847 if (_disk_reader || _disk_writer) {
4848 switch (_disk_io_point) {
4849 case DiskIOPreFader:
4850 if (trim != new_processors.end()) {
4851 /* insert BEFORE TRIM */
4853 new_processors.insert (trim, _disk_writer);
4856 new_processors.insert (trim, _disk_reader);
4860 new_processors.push_front (_disk_writer);
4863 new_processors.push_front (_disk_reader);
4867 case DiskIOPostFader:
4868 /* insert BEFORE main outs */
4870 new_processors.insert (main, _disk_writer);
4873 new_processors.insert (main, _disk_reader);
4877 /* reader and writer are visible under this condition, so they
4878 * are not invisible and thus not handled here.
4884 /* ensure dist-writer is before disk-reader */
4885 if (_disk_reader && _disk_writer) {
4886 ProcessorList::iterator reader_pos = find (new_processors.begin(), new_processors.end(), _disk_reader);
4887 ProcessorList::iterator writer_pos = find (new_processors.begin(), new_processors.end(), _disk_writer);
4888 assert (reader_pos != new_processors.end ());
4889 assert (writer_pos != new_processors.end ());
4890 if (std::distance (new_processors.begin(), reader_pos) < std::distance (new_processors.begin(), writer_pos)) {
4891 new_processors.erase (reader_pos);
4892 assert (writer_pos == find (new_processors.begin(), new_processors.end(), _disk_writer));
4893 new_processors.insert (++writer_pos, _disk_reader);
4898 /* EXPORT PROCESSOR */
4899 if (_capturing_processor) {
4900 assert (!_capturing_processor->display_to_user ());
4901 ProcessorList::iterator reader_pos = find (new_processors.begin(), new_processors.end(), _disk_reader);
4902 if (reader_pos != new_processors.end()) {
4903 /* insert after disk-reader */
4904 new_processors.insert (++reader_pos, _capturing_processor);
4906 new_processors.push_front (_capturing_processor);
4910 if (!is_master() && !is_monitor() && !is_auditioner()) {
4911 ProcessorList::iterator reader_pos = find (new_processors.begin(), new_processors.end(), _disk_reader);
4912 if (reader_pos != new_processors.end()) {
4913 /* insert before disk-reader */
4914 new_processors.insert (reader_pos, _delayline);
4916 new_processors.push_front (_delayline);
4920 _processors = new_processors;
4922 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4923 if (!(*i)->display_to_user () && !(*i)->enabled () && (*i) != _monitor_send) {
4924 (*i)->enable (true);
4928 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: setup_invisible_processors\n", _name));
4929 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4930 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1\n", (*i)->name ()));
4937 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
4938 Glib::Threads::RWLock::ReaderLock lp (_processor_lock);
4942 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4943 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*i);
4950 /** If the meter point is `Custom', make a note of where the meter is.
4951 * This is so that if the meter point is subsequently set to something else,
4952 * and then back to custom, we can put the meter back where it was last time
4953 * custom was enabled.
4955 * Must be called with the _processor_lock held.
4958 Route::maybe_note_meter_position ()
4960 if (_meter_point != MeterCustom) {
4964 _custom_meter_position_noted = true;
4965 /* custom meter points range from after trim to before panner/main_outs
4966 * this is a limitation by the current processor UI
4968 bool seen_trim = false;
4969 _processor_after_last_custom_meter.reset();
4970 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4971 if ((*i) == _trim) {
4974 if ((*i) == _main_outs) {
4975 _processor_after_last_custom_meter = *i;
4978 if (boost::dynamic_pointer_cast<PeakMeter> (*i)) {
4980 _processor_after_last_custom_meter = _trim;
4982 ProcessorList::iterator j = i;
4984 assert(j != _processors.end ()); // main_outs should be before
4985 _processor_after_last_custom_meter = *j;
4990 assert(_processor_after_last_custom_meter.lock());
4993 boost::shared_ptr<Processor>
4994 Route::processor_by_id (PBD::ID id) const
4996 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4997 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4998 if ((*i)->id() == id) {
5003 return boost::shared_ptr<Processor> ();
5006 /** @return what we should be metering; either the data coming from the input
5007 * IO or the data that is flowing through the route.
5010 Route::metering_state () const
5012 return MeteringRoute;
5016 Route::has_external_redirects () const
5018 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5020 /* ignore inactive processors and obviously ignore the main
5021 * outs since everything has them and we don't care.
5024 if ((*i)->active() && (*i) != _main_outs && (*i)->does_routing()) {
5032 boost::shared_ptr<Processor>
5033 Route::the_instrument () const
5035 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5036 return the_instrument_unlocked ();
5039 boost::shared_ptr<Processor>
5040 Route::the_instrument_unlocked () const
5042 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5043 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
5044 if (pi && pi->plugin ()->get_info ()->is_instrument ()) {
5048 return boost::shared_ptr<Processor>();
5054 Route::non_realtime_locate (samplepos_t pos)
5056 Automatable::non_realtime_locate (pos);
5059 _pannable->non_realtime_locate (pos);
5062 #if 0 // XXX mayhaps clear delayline here (and at stop?)
5064 _delayline->flush ();
5069 //Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
5070 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5072 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5073 (*i)->non_realtime_locate (pos);
5079 Route::fill_buffers_with_input (BufferSet& bufs, boost::shared_ptr<IO> io, pframes_t nframes)
5086 * We don't currently mix MIDI input together, so we don't need the
5087 * complex logic of the audio case.
5090 n_buffers = bufs.count().n_midi ();
5092 for (i = 0; i < n_buffers; ++i) {
5094 boost::shared_ptr<MidiPort> source_port = io->midi (i);
5095 MidiBuffer& buf (bufs.get_midi (i));
5098 buf.copy (source_port->get_midi_buffer(nframes));
5100 buf.silence (nframes);
5106 n_buffers = bufs.count().n_audio();
5108 size_t n_ports = io->n_ports().n_audio();
5109 float scaling = 1.0f;
5111 if (n_ports > n_buffers) {
5112 scaling = ((float) n_buffers) / n_ports;
5115 for (i = 0; i < n_ports; ++i) {
5117 /* if there are more ports than buffers, map them onto buffers
5118 * in a round-robin fashion
5121 boost::shared_ptr<AudioPort> source_port = io->audio (i);
5122 AudioBuffer& buf (bufs.get_audio (i%n_buffers));
5124 if (i < n_buffers) {
5126 /* first time through just copy a channel into
5130 buf.read_from (source_port->get_audio_buffer (nframes), nframes);
5132 if (scaling != 1.0f) {
5133 buf.apply_gain (scaling, nframes);
5138 /* on subsequent times around, merge data from
5139 * the port with what is already there
5142 if (scaling != 1.0f) {
5143 buf.accumulate_with_gain_from (source_port->get_audio_buffer (nframes), nframes, 0, scaling);
5145 buf.accumulate_from (source_port->get_audio_buffer (nframes), nframes);
5150 /* silence any remaining buffers */
5152 for (; i < n_buffers; ++i) {
5153 AudioBuffer& buf (bufs.get_audio (i));
5154 buf.silence (nframes);
5157 /* establish the initial setup of the buffer set, reflecting what was
5158 copied into it. unless, of course, we are the auditioner, in which
5159 case nothing was fed into it from the inputs at all.
5162 if (!is_auditioner()) {
5163 bufs.set_count (io->n_ports());
5167 boost::shared_ptr<AutomationControl>
5168 Route::pan_azimuth_control() const
5171 # undef MIXBUS_PORTS_H
5172 # include "../../gtk2_ardour/mixbus_ports.h"
5173 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5175 return boost::shared_ptr<AutomationControl>();
5177 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_pan)));
5179 if (!_pannable || !panner()) {
5180 return boost::shared_ptr<AutomationControl>();
5182 return _pannable->pan_azimuth_control;
5186 boost::shared_ptr<AutomationControl>
5187 Route::pan_elevation_control() const
5189 if (Profile->get_mixbus() || !_pannable || !panner()) {
5190 return boost::shared_ptr<AutomationControl>();
5193 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5195 if (c.find (PanElevationAutomation) != c.end()) {
5196 return _pannable->pan_elevation_control;
5198 return boost::shared_ptr<AutomationControl>();
5201 boost::shared_ptr<AutomationControl>
5202 Route::pan_width_control() const
5205 if (mixbus() && _ch_pre) {
5207 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl>(_ch_pre->control(Evoral::Parameter(PluginAutomation, 0, 5)));
5210 if (Profile->get_mixbus() || !_pannable || !panner()) {
5211 return boost::shared_ptr<AutomationControl>();
5214 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5216 if (c.find (PanWidthAutomation) != c.end()) {
5217 return _pannable->pan_width_control;
5219 return boost::shared_ptr<AutomationControl>();
5222 boost::shared_ptr<AutomationControl>
5223 Route::pan_frontback_control() const
5225 if (Profile->get_mixbus() || !_pannable || !panner()) {
5226 return boost::shared_ptr<AutomationControl>();
5229 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5231 if (c.find (PanFrontBackAutomation) != c.end()) {
5232 return _pannable->pan_frontback_control;
5234 return boost::shared_ptr<AutomationControl>();
5237 boost::shared_ptr<AutomationControl>
5238 Route::pan_lfe_control() const
5240 if (Profile->get_mixbus() || !_pannable || !panner()) {
5241 return boost::shared_ptr<AutomationControl>();
5244 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5246 if (c.find (PanLFEAutomation) != c.end()) {
5247 return _pannable->pan_lfe_control;
5249 return boost::shared_ptr<AutomationControl>();
5254 Route::eq_band_cnt () const
5256 if (Profile->get_mixbus()) {
5258 if (is_master() || mixbus()) {
5267 /* Ardour has no well-known EQ object */
5272 boost::shared_ptr<AutomationControl>
5273 Route::eq_gain_controllable (uint32_t band) const
5276 boost::shared_ptr<PluginInsert> eq = ch_eq();
5279 return boost::shared_ptr<AutomationControl>();
5282 uint32_t port_number;
5283 if (is_master() || mixbus()) {
5285 case 0: port_number = 4; break;
5286 case 1: port_number = 3; break;
5287 case 2: port_number = 2; break;
5289 return boost::shared_ptr<AutomationControl>();
5294 case 0: port_number = 14; break;
5295 case 1: port_number = 12; break;
5296 case 2: port_number = 10; break;
5297 case 3: port_number = 8; break;
5299 return boost::shared_ptr<AutomationControl>();
5303 case 0: port_number = 8; break;
5304 case 1: port_number = 6; break;
5305 case 2: port_number = 4; break;
5307 return boost::shared_ptr<AutomationControl>();
5312 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5314 return boost::shared_ptr<AutomationControl>();
5317 boost::shared_ptr<AutomationControl>
5318 Route::eq_freq_controllable (uint32_t band) const
5321 if (mixbus() || is_master()) {
5322 /* no frequency controls for mixbusses or master */
5323 return boost::shared_ptr<AutomationControl>();
5326 boost::shared_ptr<PluginInsert> eq = ch_eq();
5329 return boost::shared_ptr<AutomationControl>();
5332 uint32_t port_number;
5335 case 0: port_number = 13; break; // lo
5336 case 1: port_number = 11; break; // lo mid
5337 case 2: port_number = 9; break; // hi mid
5338 case 3: port_number = 7; break; // hi
5340 return boost::shared_ptr<AutomationControl>();
5344 case 0: port_number = 7; break;
5345 case 1: port_number = 5; break;
5346 case 2: port_number = 3; break;
5348 return boost::shared_ptr<AutomationControl>();
5352 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5354 return boost::shared_ptr<AutomationControl>();
5358 boost::shared_ptr<AutomationControl>
5359 Route::eq_q_controllable (uint32_t band) const
5361 return boost::shared_ptr<AutomationControl>();
5364 boost::shared_ptr<AutomationControl>
5365 Route::eq_shape_controllable (uint32_t band) const
5368 boost::shared_ptr<PluginInsert> eq = ch_eq();
5369 if (is_master() || mixbus() || !eq) {
5370 return boost::shared_ptr<AutomationControl>();
5374 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4))); // lo bell
5377 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3))); // hi bell
5383 return boost::shared_ptr<AutomationControl>();
5386 boost::shared_ptr<AutomationControl>
5387 Route::eq_enable_controllable () const
5390 boost::shared_ptr<PluginInsert> eq = ch_eq();
5393 return boost::shared_ptr<AutomationControl>();
5396 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5398 return boost::shared_ptr<AutomationControl>();
5402 boost::shared_ptr<AutomationControl>
5403 Route::filter_freq_controllable (bool hpf) const
5406 boost::shared_ptr<PluginInsert> eq = ch_eq();
5408 if (is_master() || mixbus() || !eq) {
5409 return boost::shared_ptr<AutomationControl>();
5413 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5))); // HPF freq
5415 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5419 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 6))); // LPF freq
5421 return boost::shared_ptr<AutomationControl>();
5426 return boost::shared_ptr<AutomationControl>();
5430 boost::shared_ptr<AutomationControl>
5431 Route::filter_slope_controllable (bool) const
5433 return boost::shared_ptr<AutomationControl>();
5436 boost::shared_ptr<AutomationControl>
5437 Route::filter_enable_controllable (bool) const
5440 boost::shared_ptr<PluginInsert> eq = ch_eq();
5442 if (is_master() || mixbus() || !eq) {
5443 return boost::shared_ptr<AutomationControl>();
5446 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5448 return boost::shared_ptr<AutomationControl>();
5453 Route::eq_band_name (uint32_t band) const
5456 if (is_master() || mixbus()) {
5458 if (Profile->get_mixbus()) {
5460 case 0: return _("lo");
5461 case 1: return _("mid");
5462 case 2: return _("hi");
5463 default: return string();
5471 case 0: return _("lo");
5472 case 1: return _("lo mid");
5473 case 2: return _("hi mid");
5474 case 3: return _("hi");
5475 default: return string();
5481 boost::shared_ptr<AutomationControl>
5482 Route::comp_enable_controllable () const
5485 boost::shared_ptr<PluginInsert> comp = ch_comp();
5488 return boost::shared_ptr<AutomationControl>();
5491 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5493 return boost::shared_ptr<AutomationControl>();
5496 boost::shared_ptr<AutomationControl>
5497 Route::comp_threshold_controllable () const
5500 boost::shared_ptr<PluginInsert> comp = ch_comp();
5503 return boost::shared_ptr<AutomationControl>();
5506 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5509 return boost::shared_ptr<AutomationControl>();
5512 boost::shared_ptr<AutomationControl>
5513 Route::comp_speed_controllable () const
5516 boost::shared_ptr<PluginInsert> comp = ch_comp();
5519 return boost::shared_ptr<AutomationControl>();
5522 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3)));
5524 return boost::shared_ptr<AutomationControl>();
5527 boost::shared_ptr<AutomationControl>
5528 Route::comp_mode_controllable () const
5531 boost::shared_ptr<PluginInsert> comp = ch_comp();
5534 return boost::shared_ptr<AutomationControl>();
5537 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4)));
5539 return boost::shared_ptr<AutomationControl>();
5542 boost::shared_ptr<AutomationControl>
5543 Route::comp_makeup_controllable () const
5546 boost::shared_ptr<PluginInsert> comp = ch_comp();
5549 return boost::shared_ptr<AutomationControl>();
5552 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5)));
5554 return boost::shared_ptr<AutomationControl>();
5557 boost::shared_ptr<ReadOnlyControl>
5558 Route::comp_redux_controllable () const
5561 boost::shared_ptr<PluginInsert> comp = ch_comp();
5564 return boost::shared_ptr<ReadOnlyControl>();
5567 return comp->control_output (2);
5569 return comp->control_output (6);
5573 return boost::shared_ptr<ReadOnlyControl>();
5578 Route::comp_mode_name (uint32_t mode) const
5583 return _("Leveler");
5585 return _("Compressor");
5587 return _("Limiter");
5589 return mixbus() ? _("Sidechain") : _("Limiter");
5599 Route::comp_speed_name (uint32_t mode) const
5617 boost::shared_ptr<AutomationControl>
5618 Route::send_level_controllable (uint32_t n) const
5621 # undef MIXBUS_PORTS_H
5622 # include "../../gtk2_ardour/mixbus_ports.h"
5623 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5624 if (plug && !mixbus()) {
5625 uint32_t port_id = 0;
5627 case 0: port_id = port_channel_post_aux1_level; break;
5628 case 1: port_id = port_channel_post_aux2_level; break;
5629 case 2: port_id = port_channel_post_aux3_level; break;
5630 case 3: port_id = port_channel_post_aux4_level; break;
5631 case 4: port_id = port_channel_post_aux5_level; break;
5632 case 5: port_id = port_channel_post_aux6_level; break;
5633 case 6: port_id = port_channel_post_aux7_level; break;
5634 case 7: port_id = port_channel_post_aux8_level; break;
5636 case 8: port_id = port_channel_post_aux9_level; break;
5637 case 9: port_id = port_channel_post_aux10_level; break;
5638 case 10: port_id = port_channel_post_aux11_level; break;
5639 case 11: port_id = port_channel_post_aux12_level; break;
5646 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5657 boost::shared_ptr<Send> s = boost::dynamic_pointer_cast<Send>(nth_send (n));
5659 return boost::shared_ptr<AutomationControl>();
5661 return s->gain_control ();
5664 boost::shared_ptr<AutomationControl>
5665 Route::send_enable_controllable (uint32_t n) const
5668 # undef MIXBUS_PORTS_H
5669 # include "../../gtk2_ardour/mixbus_ports.h"
5670 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5671 if (plug && !mixbus()) {
5672 uint32_t port_id = 0;
5674 case 0: port_id = port_channel_post_aux1_asgn; break;
5675 case 1: port_id = port_channel_post_aux2_asgn; break;
5676 case 2: port_id = port_channel_post_aux3_asgn; break;
5677 case 3: port_id = port_channel_post_aux4_asgn; break;
5678 case 4: port_id = port_channel_post_aux5_asgn; break;
5679 case 5: port_id = port_channel_post_aux6_asgn; break;
5680 case 6: port_id = port_channel_post_aux7_asgn; break;
5681 case 7: port_id = port_channel_post_aux8_asgn; break;
5683 case 8: port_id = port_channel_post_aux9_asgn; break;
5684 case 9: port_id = port_channel_post_aux10_asgn; break;
5685 case 10: port_id = port_channel_post_aux11_asgn; break;
5686 case 11: port_id = port_channel_post_aux12_asgn; break;
5693 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5704 /* although Ardour sends have enable/disable as part of the Processor
5705 * API, it is not exposed as a controllable.
5707 * XXX: we should fix this (make it click-free, automatable enable-control)
5709 return boost::shared_ptr<AutomationControl>();
5713 Route::send_name (uint32_t n) const
5716 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5717 if (plug && !mixbus()) {
5720 return _session.get_mixbus (n)->name();
5725 return _session.get_mixbus (n)->name();
5731 boost::shared_ptr<Processor> p = nth_send (n);
5739 boost::shared_ptr<AutomationControl>
5740 Route::master_send_enable_controllable () const
5743 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5745 return boost::shared_ptr<AutomationControl>();
5747 # undef MIXBUS_PORTS_H
5748 # include "../../gtk2_ardour/mixbus_ports.h"
5749 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_mstr_assign)));
5751 return boost::shared_ptr<AutomationControl>();
5756 Route::slaved () const
5758 if (!_gain_control) {
5761 /* just test one particular control, not all of them */
5762 return _gain_control->slaved ();
5766 Route::slaved_to (boost::shared_ptr<VCA> vca) const
5768 if (!vca || !_gain_control) {
5772 /* just test one particular control, not all of them */
5774 return _gain_control->slaved_to (vca->gain_control());
5778 Route::muted_by_others_soloing () const
5780 if (!can_be_muted_by_others ()) {
5784 return _session.soloing() && !_solo_control->soloed() && !_solo_isolate_control->solo_isolated();
5788 Route::clear_all_solo_state ()
5790 _solo_control->clear_all_solo_state ();
5793 boost::shared_ptr<AutomationControl>
5794 Route::automation_control_recurse (PBD::ID const & id) const
5796 boost::shared_ptr<AutomationControl> ac = Automatable::automation_control (id);
5802 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5804 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5805 if ((ac = (*i)->automation_control (id))) {
5810 return boost::shared_ptr<AutomationControl> ();
5814 Route::slavables () const
5816 SlavableControlList rv;
5817 rv.push_back (_gain_control);
5818 rv.push_back (_mute_control);
5819 rv.push_back (_solo_control);
5824 Route::set_disk_io_point (DiskIOPoint diop)
5826 bool display = false;
5828 cerr << "set disk io to " << enum_2_string (diop) << endl;
5839 _disk_writer->set_display_to_user (display);
5843 _disk_reader->set_display_to_user (display);
5846 const bool changed = (diop != _disk_io_point);
5848 _disk_io_point = diop;
5851 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
5852 configure_processors (0);
5855 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
5858 #ifdef USE_TRACKS_CODE_FEATURES
5860 /* This is the Tracks version of Track::monitoring_state().
5862 * Ardour developers: try to flag or fix issues if parts of the libardour API
5863 * change in ways that invalidate this
5867 Route::monitoring_state () const
5869 /* Explicit requests */
5871 if (_monitoring != MonitorInput) {
5872 return MonitoringInput;
5875 if (_monitoring & MonitorDisk) {
5876 return MonitoringDisk;
5879 /* This is an implementation of the truth table in doc/monitor_modes.pdf;
5880 I don't think it's ever going to be too pretty too look at.
5883 // GZ: NOT USED IN TRACKS
5884 //bool const auto_input = _session.config.get_auto_input ();
5885 //bool const software_monitor = Config->get_monitoring_model() == SoftwareMonitoring;
5886 //bool const tape_machine_mode = Config->get_tape_machine_mode ();
5888 bool const roll = _session.transport_rolling ();
5889 bool const track_rec = _diskstream->record_enabled ();
5890 bool session_rec = _session.actively_recording ();
5894 if (!session_rec && roll) {
5895 return MonitoringDisk;
5897 return MonitoringInput;
5903 return MonitoringDisk;
5907 return MonitoringSilence;
5912 /* This is the Ardour/Mixbus version of Track::monitoring_state().
5914 * Tracks developers: do NOT modify this method under any circumstances.
5918 Route::monitoring_state () const
5920 if (!_disk_reader) {
5921 return MonitoringInput;
5924 /* Explicit requests */
5925 MonitorChoice m (_monitoring_control->monitoring_choice());
5927 if (m != MonitorAuto) {
5929 MonitorState ms ((MonitorState) 0);
5931 if (m & MonitorInput) {
5932 ms = MonitoringInput;
5935 if (m & MonitorDisk) {
5936 ms = MonitorState (ms | MonitoringDisk);
5942 switch (_session.config.get_session_monitoring ()) {
5944 return MonitoringDisk;
5947 return MonitoringInput;
5953 /* This is an implementation of the truth table in doc/monitor_modes.pdf;
5954 I don't think it's ever going to be too pretty too look at.
5957 bool const roll = _session.transport_rolling ();
5958 bool const track_rec = _disk_writer->record_enabled ();
5959 bool const auto_input = _session.config.get_auto_input ();
5960 bool const software_monitor = Config->get_monitoring_model() == SoftwareMonitoring;
5961 bool const tape_machine_mode = Config->get_tape_machine_mode ();
5964 /* I suspect that just use actively_recording() is good enough all the
5965 * time, but just to keep the semantics the same as they were before
5966 * sept 26th 2012, we differentiate between the cases where punch is
5967 * enabled and those where it is not.
5969 * rg: I suspect this is not the case: monitoring may differ
5972 if (_session.config.get_punch_in() || _session.config.get_punch_out() || _session.preroll_record_punch_enabled ()) {
5973 session_rec = _session.actively_recording ();
5975 session_rec = _session.get_record_enabled();
5980 if (!session_rec && roll && auto_input) {
5981 return MonitoringDisk;
5983 return software_monitor ? MonitoringInput : MonitoringSilence;
5988 if (tape_machine_mode) {
5990 return MonitoringDisk;
5994 if (!roll && auto_input) {
5995 return software_monitor ? MonitoringInput : MonitoringSilence;
5997 return MonitoringDisk;
6003 abort(); /* NOTREACHED */
6004 return MonitoringSilence;