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)
107 , _declickable (false)
108 , _have_internal_generator (false)
109 , _default_type (default_type)
112 , _in_configure_processors (false)
113 , _initial_io_setup (false)
114 , _in_sidechain_setup (false)
115 , _custom_meter_position_noted (false)
117 , _patch_selector_dialog (0)
119 processor_max_streams.reset();
122 boost::weak_ptr<Route>
123 Route::weakroute () {
124 return boost::weak_ptr<Route> (boost::dynamic_pointer_cast<Route> (shared_from_this ()));
130 /* set default meter type */
132 _meter_type = Config->get_meter_type_master ();
134 else if (dynamic_cast<Track*>(this)) {
135 _meter_type = Config->get_meter_type_track ();
137 _meter_type = Config->get_meter_type_bus ();
140 /* add standard controls */
142 _gain_control.reset (new GainControl (_session, GainAutomation));
143 _trim_control.reset (new GainControl (_session, TrimAutomation));
144 /* While the route has-a gain-control for consistency with Stripable and VCA
145 * ownership is handed over to the Amp Processor which manages the
146 * state of the Control and AutomationList as part of its
147 * Automatable API. -- Don't call add_control () here.
150 _solo_control.reset (new SoloControl (_session, X_("solo"), *this, *this));
151 add_control (_solo_control);
152 _solo_control->Changed.connect_same_thread (*this, boost::bind (&Route::solo_control_changed, this, _1, _2));
154 _mute_control.reset (new MuteControl (_session, X_("mute"), *this));
155 add_control (_mute_control);
157 _phase_control.reset (new PhaseControl (_session, X_("phase")));
158 add_control (_phase_control);
160 _solo_isolate_control.reset (new SoloIsolateControl (_session, X_("solo-iso"), *this, *this));
161 add_control (_solo_isolate_control);
163 _solo_safe_control.reset (new SoloSafeControl (_session, X_("solo-safe")));
164 add_control (_solo_safe_control);
168 if (!(_presentation_info.flags() & PresentationInfo::MonitorOut)) {
169 _pannable.reset (new Pannable (_session));
172 /* input and output objects */
174 _input.reset (new IO (_session, _name, IO::Input, _default_type));
175 _output.reset (new IO (_session, _name, IO::Output, _default_type));
177 _input->changed.connect_same_thread (*this, boost::bind (&Route::input_change_handler, this, _1, _2));
178 _input->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::input_port_count_changing, this, _1));
180 _output->changed.connect_same_thread (*this, boost::bind (&Route::output_change_handler, this, _1, _2));
181 _output->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::output_port_count_changing, this, _1));
183 /* add the amp/fader processor.
184 * it should be the first processor to be added on every route.
187 _amp.reset (new Amp (_session, X_("Fader"), _gain_control, true));
188 add_processor (_amp, PostFader);
191 _amp->set_display_name (_("Monitor"));
194 if (!is_master() && !is_monitor() && !is_auditioner()) {
195 _delayline.reset (new DelayLine (_session, name ()));
200 _trim.reset (new Amp (_session, X_("Trim"), _trim_control, false));
201 _trim->set_display_to_user (false);
203 if (dynamic_cast<AudioTrack*>(this)) {
204 /* we can't do this in the AudioTrack's constructor
205 * because _trim does not exit then
209 else if (!dynamic_cast<Track*>(this) && ! ( is_monitor() || is_auditioner() )) {
214 /* create standard processors: meter, main outs, monitor out;
215 they will be added to _processors by setup_invisible_processors ()
218 _meter.reset (new PeakMeter (_session, _name));
219 _meter->set_owner (this);
220 _meter->set_display_to_user (false);
223 _main_outs.reset (new Delivery (_session, _output, _pannable, _mute_master, _name, Delivery::Main));
224 _main_outs->activate ();
227 /* where we listen to tracks */
228 _intreturn.reset (new InternalReturn (_session));
229 _intreturn->activate ();
231 /* the thing that provides proper control over a control/monitor/listen bus
232 (such as per-channel cut, dim, solo, invert, etc).
234 _monitor_control.reset (new MonitorProcessor (_session));
235 _monitor_control->activate ();
238 /* now that we have _meter, its safe to connect to this */
241 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
242 configure_processors (0);
250 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
252 /* do this early so that we don't get incoming signals as we are going through destruction
257 /* don't use clear_processors here, as it depends on the session which may
258 be half-destroyed by now
261 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
262 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
263 (*i)->drop_references ();
266 _processors.clear ();
270 Route::ensure_track_or_route_name(string name, Session &session)
272 string newname = name;
274 while (!session.io_name_is_legal (newname)) {
275 newname = bump_name_once (newname, ' ');
282 Route::set_trim (gain_t val, Controllable::GroupControlDisposition /* group override */)
284 // TODO route group, see set_gain()
285 // _trim_control->route_set_value (val);
289 Route::maybe_declick (BufferSet&, samplecnt_t, int)
291 /* this is the "bus" implementation and they never declick.
296 /** Process this route for one (sub) cycle (process thread)
298 * @param bufs Scratch buffers to use for the signal path
299 * @param start_sample Initial transport sample
300 * @param end_sample Final transport sample
301 * @param nframes Number of samples to output (to ports)
303 * Note that (end_sample - start_sample) may not be equal to nframes when the
304 * transport speed isn't 1.0 (eg varispeed).
307 Route::process_output_buffers (BufferSet& bufs,
308 samplepos_t start_sample, samplepos_t end_sample, pframes_t nframes,
309 int declick, bool gain_automation_ok, bool run_disk_reader)
311 /* Caller must hold process lock */
312 assert (!AudioEngine::instance()->process_lock().trylock());
314 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
316 // can this actually happen?
317 // Places that need a WriterLock on (_processor_lock) must also take the process-lock.
318 bufs.silence (nframes, 0);
319 assert (0); // ...one way to find out.
323 /* We should offset the route-owned ctrls by the given latency, however
324 * this only affects Mute. Other route-owned controls (solo, polarity..)
325 * are not automatable.
327 * Mute has its own issues since there's not a single mute-point,
330 automation_run (start_sample, nframes);
332 /* figure out if we're going to use gain automation */
333 if (gain_automation_ok) {
334 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
335 _amp->setup_gain_automation (
336 start_sample + _amp->output_latency (),
337 end_sample + _amp->output_latency (),
340 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
341 _trim->setup_gain_automation (
342 start_sample + _trim->output_latency (),
343 end_sample + _trim->output_latency (),
347 /* We align the playhead to output. The user hears what the clock says:
348 * When the playhead/clock says 1:00:00:00 the user will hear the audio sample
349 * at 1:00:00:00. sample_start will be [sample at] 1:00:00:00
351 * e.g. clock says Time T = 0, sample_start = 0
352 * Disk-read(play) -> latent-plugin (+10) -> fader-automation -> output (+5)
353 * -> total playback latency "disk -> out" is 15.
354 * -> at Time T= -15, the disk-reader reads sample T=0.
355 * By the Time T=0 is reached (dt=15 later) that sample is audible.
358 start_sample += _signal_latency;
359 end_sample += _signal_latency;
361 start_sample += _output->latency ();
362 end_sample += _output->latency ();
364 const double speed = (is_auditioner() ? 1.0 : _session.transport_speed ());
366 /* Note: during intial pre-roll 'start_sample' as passed as argument can be negative.
367 * Functions calling process_output_buffers() will set "run_disk_reader"
368 * to false if the pre-roll count-down is larger than playback_latency ().
370 * playback_latency() is guarnteed to be <= _signal_latency + _output->latency ()
372 assert (!_disk_reader || !run_disk_reader || start_sample >= 0);
374 /* however the disk-writer may need to pick up output from other tracks
375 * during pre-roll (in particular if this route has latent effects after the disk).
377 * e.g. track 1 play -> latency A --port--> track2 capture -> latency B ---> out
378 * total pre-roll = A + B.
380 * Note the disk-writer has built-in overlap detection (it's safe to run it early)
383 bool run_disk_writer = false;
384 if (_disk_writer && speed != 0) {
385 samplecnt_t latency_preroll = _session.remaining_latency_preroll ();
386 run_disk_writer = latency_preroll < nframes + (_signal_latency + _output->latency ());
387 if (end_sample - _disk_writer->input_latency () < _session.transport_sample ()) {
388 run_disk_writer = true;
392 /* Tell main outs what to do about monitoring. We do this so that
393 * on a transition between monitoring states we get a de-clicking gain
394 * change in the _main_outs delivery, if config.get_use_monitor_fades()
397 * We override this in the case where we have an internal generator.
399 * FIXME: when punching in/out this also depends on latency compensated time
400 * for this route. monitoring_state() does not currently handle that correctly,.
402 * Also during remaining_latency_preroll, transport_rolling () is false, but
403 * we may need to monitor disk instead.
405 MonitorState ms = monitoring_state ();
406 bool silence = _have_internal_generator ? false : (ms == MonitoringSilence);
408 _main_outs->no_outs_cuz_we_no_monitor (silence);
410 /* -------------------------------------------------------------------------------------------
411 GLOBAL DECLICK (for transport changes etc.)
412 ----------------------------------------------------------------------------------------- */
414 // XXX not latency compensated. calls Amp::declick, but there may be
415 // plugins between disk and Fader.
416 maybe_declick (bufs, nframes, declick);
417 _pending_declick = 0;
419 /* -------------------------------------------------------------------------------------------
420 DENORMAL CONTROL/PHASE INVERT
421 ----------------------------------------------------------------------------------------- */
423 /* TODO phase-control should become a processor, or rather a Stub-processor:
424 * a point in the chain which calls a special-cased private Route method.
425 * _phase_control is route-owned and dynamic.)
426 * and we should rename it to polarity.
428 * denormals: we'll need to protect silent inputs as well as silent disk
429 * (when not monitoring input). Or simply drop that feature.
431 if (!_phase_control->none()) {
435 if (_denormal_protection || Config->get_denormal_protection()) {
437 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
438 Sample* const sp = i->data();
440 if (_phase_control->inverted (chn)) {
441 for (pframes_t nx = 0; nx < nframes; ++nx) {
446 for (pframes_t nx = 0; nx < nframes; ++nx) {
454 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
455 Sample* const sp = i->data();
457 if (_phase_control->inverted (chn)) {
458 for (pframes_t nx = 0; nx < nframes; ++nx) {
467 if (_denormal_protection || Config->get_denormal_protection()) {
469 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
470 Sample* const sp = i->data();
471 for (pframes_t nx = 0; nx < nframes; ++nx) {
479 /* -------------------------------------------------------------------------------------------
481 ----------------------------------------------------------------------------------------- */
483 samplecnt_t latency = 0;
485 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
487 /* TODO check for split cycles here.
489 * start_frame, end_frame is adjusted by latency and may
494 /* if it has any inputs, make sure they match */
495 if (boost::dynamic_pointer_cast<UnknownProcessor> (*i) == 0 && (*i)->input_streams() != ChanCount::ZERO) {
496 if (bufs.count() != (*i)->input_streams()) {
498 DEBUG::Processors, string_compose (
499 "input port mismatch %1 bufs = %2 input for %3 = %4\n",
500 _name, bufs.count(), (*i)->name(), (*i)->input_streams()
507 if (boost::dynamic_pointer_cast<PluginInsert>(*i) != 0) {
508 /* set potential sidechain ports, capture and playback latency.
509 * This effectively sets jack port latency which should include
510 * up/downstream latencies.
512 * However, the value is not used by Ardour (2017-09-20) and calling
513 * IO::latency() is expensive, so we punt.
516 * input()->latenct + latency,
518 * output->latency() + _signal_latency - latency
520 * Also see note below, _signal_latency may be smaller than latency
521 * if a plugin's latency increases while it's running.
523 const samplecnt_t playback_latency = std::max ((samplecnt_t)0, _signal_latency - latency);
524 boost::dynamic_pointer_cast<PluginInsert>(*i)->set_sidechain_latency (
525 /* input->latency() + */ latency, /* output->latency() + */ playback_latency);
528 bool re_inject_oob_data = false;
529 if ((*i) == _disk_reader) {
530 /* Well now, we've made it past the disk-writer and to the disk-reader.
531 * Time to decide what to do about monitoring.
533 * Even when not doing MonitoringDisk, we need to run the processors,
534 * so that it advances its internal buffers (IFF run_disk_reader is true).
537 if (ms == MonitoringDisk || ms == MonitoringSilence) {
538 /* this will clear out-of-band data, too (e.g. MIDI-PC, Panic etc.
539 * OOB data is written at the end of the cycle (nframes - 1),
540 * and jack does not re-order events, so we push them back later */
541 re_inject_oob_data = true;
542 bufs.silence (nframes, 0);
546 double pspeed = speed;
547 if ((!run_disk_reader && (*i) == _disk_reader) || (!run_disk_writer && (*i) == _disk_writer)) {
548 /* run with speed 0, no-roll */
552 (*i)->run (bufs, start_sample - latency, end_sample - latency, pspeed, nframes, *i != _processors.back());
554 bufs.set_count ((*i)->output_streams());
556 /* Note: plugin latency may change. While the plugin does inform the session via
557 * processor_latency_changed(). But the session may not yet have gotten around to
558 * update the actual worste-case and update this track's _signal_latency.
560 * So there can be cases where adding up all latencies may not equal _signal_latency.
562 if ((*i)->active ()) {
563 latency += (*i)->signal_latency ();
566 if (re_inject_oob_data) {
567 write_out_of_band_data (bufs, nframes);
571 if ((*i) == _delayline) {
572 latency += _delayline->get_delay ();
579 Route::bounce_process (BufferSet& buffers, samplepos_t start, samplecnt_t nframes,
580 boost::shared_ptr<Processor> endpoint,
581 bool include_endpoint, bool for_export, bool for_freeze)
583 /* If no processing is required, there's no need to go any further. */
584 if (!endpoint && !include_endpoint) {
588 samplecnt_t latency = bounce_get_latency(_amp, false, for_export, for_freeze);
589 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
590 _amp->setup_gain_automation (start - latency, start - latency + nframes, nframes);
592 /* trim is always at the top, for bounce no latency compensation is needed */
593 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
594 _trim->setup_gain_automation (start, start + nframes, nframes);
597 const double speed = _session.transport_speed ();
598 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
600 if (!include_endpoint && (*i) == endpoint) {
604 /* if we're *not* exporting, stop processing if we come across a routing processor. */
605 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
608 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
612 /* special case the panner (export outputs)
613 * Ideally we'd only run the panner, not the delivery itself...
614 * but panners need separate input/output buffers and some context
615 * (panshell, panner type, etc). AFAICT there is no ill side effect
616 * of re-using the main delivery when freewheeling/exporting a region.
618 if ((*i) == _main_outs) {
619 assert ((*i)->does_routing());
620 (*i)->run (buffers, start - latency, start - latency + nframes, speed, nframes, true);
621 buffers.set_count ((*i)->output_streams());
624 /* don't run any processors that do routing.
625 * Also don't bother with metering.
627 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
628 (*i)->run (buffers, start - latency, start - latency + nframes, 1.0, nframes, true);
629 buffers.set_count ((*i)->output_streams());
630 latency += (*i)->signal_latency ();
633 if ((*i) == endpoint) {
640 Route::bounce_get_latency (boost::shared_ptr<Processor> endpoint,
641 bool include_endpoint, bool for_export, bool for_freeze) const
643 samplecnt_t latency = 0;
644 if (!endpoint && !include_endpoint) {
648 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
649 if (!include_endpoint && (*i) == endpoint) {
652 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
655 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
658 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
659 latency += (*i)->signal_latency ();
661 if ((*i) == endpoint) {
669 Route::bounce_get_output_streams (ChanCount &cc, boost::shared_ptr<Processor> endpoint,
670 bool include_endpoint, bool for_export, bool for_freeze) const
672 if (!endpoint && !include_endpoint) {
676 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
677 if (!include_endpoint && (*i) == endpoint) {
680 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
683 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
686 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
687 cc = (*i)->output_streams();
689 if ((*i) == endpoint) {
697 Route::n_process_buffers ()
699 return max (_input->n_ports(), processor_max_streams);
703 Route::monitor_run (samplepos_t start_sample, samplepos_t end_sample, pframes_t nframes, int declick)
705 assert (is_monitor());
706 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
707 run_route (start_sample, end_sample, nframes, declick, true, false);
711 Route::run_route (samplepos_t start_sample, samplepos_t end_sample, pframes_t nframes, int declick, bool gain_automation_ok, bool run_disk_reader)
713 BufferSet& bufs (_session.get_route_buffers (n_process_buffers()));
715 fill_buffers_with_input (bufs, _input, nframes);
717 /* filter captured data before meter sees it */
720 if (is_monitor() && _session.listening() && !_session.is_auditioning()) {
722 /* control/monitor bus ignores input ports when something is
723 feeding the listen "stream". data will "arrive" into the
724 route from the intreturn processor element.
727 bufs.silence (nframes, 0);
730 snapshot_out_of_band_data (nframes);
731 /* append immediate messages to the first MIDI buffer (thus sending it to the first output port) */
733 write_out_of_band_data (bufs, nframes);
735 /* run processor chain */
737 process_output_buffers (bufs, start_sample, end_sample, nframes, declick, gain_automation_ok, run_disk_reader);
739 /* map events (e.g. MIDI-CC) back to control-parameters */
740 update_controls (bufs);
742 flush_processor_buffers_locked (nframes);
746 Route::set_listen (bool yn)
749 if (_monitor_send->active() == yn) {
753 _monitor_send->activate ();
755 _monitor_send->deactivate ();
761 Route::solo_control_changed (bool, Controllable::GroupControlDisposition)
763 /* nothing to do if we're not using AFL/PFL. But if we are, we need
764 to alter the active state of the monitor send.
767 if (Config->get_solo_control_is_listen_control ()) {
768 set_listen (_solo_control->self_soloed() || _solo_control->get_masters_value());
773 Route::push_solo_isolate_upstream (int32_t delta)
775 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
777 boost::shared_ptr<RouteList> routes = _session.get_routes ();
778 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
780 if ((*i).get() == this || !(*i)->can_solo()) {
785 bool does_feed = feeds (*i, &sends_only);
787 if (does_feed && !sends_only) {
788 (*i)->solo_isolate_control()->mod_solo_isolated_by_upstream (delta);
794 Route::push_solo_upstream (int delta)
796 DEBUG_TRACE (DEBUG::Solo, string_compose("\t ... INVERT push from %1\n", _name));
797 for (FedBy::iterator i = _fed_by.begin(); i != _fed_by.end(); ++i) {
801 boost::shared_ptr<Route> sr (i->r.lock());
803 sr->solo_control()->mod_solo_by_others_downstream (-delta);
810 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
812 cerr << name << " {" << endl;
813 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
814 p != procs.end(); ++p) {
815 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << " @ " << (*p) << endl;
821 /** Supposing that we want to insert a Processor at a given Placement, 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_placement (Placement p)
827 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
829 ProcessorList::iterator loc;
832 /* generic pre-fader: insert immediately before the amp */
833 loc = find (_processors.begin(), _processors.end(), _amp);
835 /* generic post-fader: insert right before the main outs */
836 loc = find (_processors.begin(), _processors.end(), _main_outs);
839 return loc != _processors.end() ? *loc : boost::shared_ptr<Processor> ();
842 /** Supposing that we want to insert a Processor at a given index, return
843 * the processor to add the new one before (or 0 to add at the end).
845 boost::shared_ptr<Processor>
846 Route::before_processor_for_index (int index)
849 return boost::shared_ptr<Processor> ();
852 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
854 ProcessorList::iterator i = _processors.begin ();
856 while (i != _processors.end() && j < index) {
857 if ((*i)->display_to_user()) {
864 return (i != _processors.end() ? *i : boost::shared_ptr<Processor> ());
867 /** Add a processor either pre- or post-fader
868 * @return 0 on success, non-0 on failure.
871 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err, bool activation_allowed)
873 return add_processor (processor, before_processor_for_placement (placement), err, activation_allowed);
877 /** Add a processor to a route such that it ends up with a given index into the visible processors.
878 * @param index Index to add the processor at, or -1 to add at the end of the list.
879 * @return 0 on success, non-0 on failure.
882 Route::add_processor_by_index (boost::shared_ptr<Processor> processor, int index, ProcessorStreams* err, bool activation_allowed)
884 return add_processor (processor, before_processor_for_index (index), err, activation_allowed);
887 /** Add a processor to the route.
888 * @param before An existing processor in the list, or 0; the new processor will be inserted immediately before it (or at the end).
889 * @return 0 on success, non-0 on failure.
892 Route::add_processor (boost::shared_ptr<Processor> processor, boost::shared_ptr<Processor> before, ProcessorStreams* err, bool activation_allowed)
894 assert (processor != _meter);
895 assert (processor != _main_outs);
897 DEBUG_TRACE (DEBUG::Processors, string_compose (
898 "%1 adding processor %2\n", name(), processor->name()));
902 pl.push_back (processor);
903 int rv = add_processors (pl, before, err);
909 if (activation_allowed && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user ())) {
910 processor->activate ();
917 Route::processor_selfdestruct (boost::weak_ptr<Processor> wp)
919 /* We cannot destruct the processor here (usually RT-thread
920 * with various locks held - in case of sends also io_locks).
921 * Queue for deletion in low-priority thread.
923 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
924 selfdestruct_sequence.push_back (wp);
928 Route::add_processor_from_xml_2X (const XMLNode& node, int version)
930 XMLProperty const * prop;
933 boost::shared_ptr<Processor> processor;
935 /* bit of a hack: get the `placement' property from the <Redirect> tag here
936 so that we can add the processor in the right place (pre/post-fader)
939 XMLNodeList const & children = node.children ();
940 XMLNodeList::const_iterator i = children.begin ();
942 while (i != children.end() && (*i)->name() != X_("Redirect")) {
946 Placement placement = PreFader;
948 if (i != children.end()) {
949 if ((prop = (*i)->property (X_("placement"))) != 0) {
950 placement = Placement (string_2_enum (prop->value(), placement));
954 if (node.name() == "Insert") {
956 if ((prop = node.property ("type")) != 0) {
958 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
959 prop->value() == "lv2" ||
960 prop->value() == "windows-vst" ||
961 prop->value() == "mac-vst" ||
962 prop->value() == "lxvst" ||
963 prop->value() == "audiounit") {
965 if (_session.get_disable_all_loaded_plugins ()) {
966 processor.reset (new UnknownProcessor (_session, node));
968 processor.reset (new PluginInsert (_session));
969 processor->set_owner (this);
974 processor.reset (new PortInsert (_session, _pannable, _mute_master));
979 } else if (node.name() == "Send") {
981 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
982 processor.reset (new Send (_session, sendpan, _mute_master));
986 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
990 if (processor->set_state (node, version)) {
994 //A2 uses the "active" flag in the toplevel redirect node, not in the child plugin/IO
995 if (i != children.end()) {
996 if ((prop = (*i)->property (X_("active"))) != 0) {
997 if ( string_to<bool> (prop->value()) && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user () ) )
998 processor->activate();
1000 processor->deactivate();
1004 return (add_processor (processor, placement, 0, false) == 0);
1007 catch (failed_constructor &err) {
1008 warning << _("processor could not be created. Ignored.") << endmsg;
1014 inline Route::PluginSetupOptions operator|= (Route::PluginSetupOptions& a, const Route::PluginSetupOptions& b) {
1015 return a = static_cast<Route::PluginSetupOptions> (static_cast <int>(a) | static_cast<int> (b));
1018 inline Route::PluginSetupOptions operator&= (Route::PluginSetupOptions& a, const Route::PluginSetupOptions& b) {
1019 return a = static_cast<Route::PluginSetupOptions> (static_cast <int>(a) & static_cast<int> (b));
1023 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
1025 ProcessorList::iterator loc;
1026 boost::shared_ptr <PluginInsert> fanout;
1028 if (g_atomic_int_get (&_pending_process_reorder)) {
1029 /* we need to flush any pending re-order changes */
1030 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1031 apply_processor_changes_rt ();
1035 loc = find(_processors.begin(), _processors.end(), before);
1036 if (loc == _processors.end ()) {
1040 /* nothing specified - at end */
1041 loc = _processors.end ();
1044 if (others.empty()) {
1048 ProcessorList to_skip;
1050 // check if there's an instrument to replace or configure
1051 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1052 boost::shared_ptr<PluginInsert> pi;
1053 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) == 0) {
1056 if (!pi->plugin ()->get_info ()->is_instrument ()) {
1059 boost::shared_ptr<Processor> instrument = the_instrument ();
1060 ChanCount in (DataType::MIDI, 1);
1061 ChanCount out (DataType::AUDIO, 2); // XXX route's out?!
1063 PluginSetupOptions flags = None;
1065 flags |= CanReplace;
1066 in = instrument->input_streams ();
1067 out = instrument->output_streams ();
1069 if (pi->has_output_presets (in, out)) {
1073 pi->set_strict_io (_strict_io);
1075 PluginSetupOptions mask = None;
1076 if (Config->get_ask_replace_instrument ()) {
1079 if (Config->get_ask_setup_instrument ()) {
1085 if (flags != None) {
1086 boost::optional<int> rv = PluginSetup (boost::dynamic_pointer_cast<Route>(shared_from_this ()), pi, flags); /* EMIT SIGNAL */
1087 int mode = rv.get_value_or (0);
1090 to_skip.push_back (*i); // don't add this one;
1093 replace_processor (instrument, *i, err);
1094 to_skip.push_back (*i);
1099 if ((mode & 5) == 4) {
1106 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1107 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1108 ProcessorState pstate (this);
1110 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1115 ProcessorList::iterator check = find (to_skip.begin(), to_skip.end(), *i);
1116 if (check != to_skip.end()) {
1120 boost::shared_ptr<PluginInsert> pi;
1122 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1123 pi->set_strict_io (_strict_io);
1127 /* Ensure that only one amp is in the list at any time */
1128 ProcessorList::iterator check = find (_processors.begin(), _processors.end(), *i);
1129 if (check != _processors.end()) {
1130 if (before == _amp) {
1131 /* Already in position; all is well */
1134 _processors.erase (check);
1139 assert (find (_processors.begin(), _processors.end(), *i) == _processors.end ());
1141 _processors.insert (loc, *i);
1142 (*i)->set_owner (this);
1145 if (configure_processors_unlocked (err, &lm)) {
1147 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
1152 if (pi && pi->has_sidechain ()) {
1153 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
1156 if ((*i)->active()) {
1157 // emit ActiveChanged() and latency_changed() if needed
1161 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1163 boost::shared_ptr<Send> send;
1164 if ((send = boost::dynamic_pointer_cast<Send> (*i))) {
1165 send->SelfDestruct.connect_same_thread (*this,
1166 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (*i)));
1170 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1171 boost::shared_ptr<PluginInsert> pi;
1173 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1174 if (pi->has_no_inputs ()) {
1175 _have_internal_generator = true;
1181 _output->set_user_latency (0);
1184 reset_instrument_info ();
1185 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1186 set_processor_positions ();
1188 if (fanout && fanout->configured ()
1189 && fanout->output_streams().n_audio() > 2
1190 && boost::dynamic_pointer_cast<PluginInsert> (the_instrument ()) == fanout) {
1191 fan_out (); /* EMIT SIGNAL */
1197 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1199 if (p == PreFader) {
1200 start = _processors.begin();
1201 end = find(_processors.begin(), _processors.end(), _amp);
1203 start = find(_processors.begin(), _processors.end(), _amp);
1205 end = _processors.end();
1209 /** Turn off all processors with a given placement
1210 * @param p Placement of processors to disable
1213 Route::disable_processors (Placement p)
1215 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1217 ProcessorList::iterator start, end;
1218 placement_range(p, start, end);
1220 for (ProcessorList::iterator i = start; i != end; ++i) {
1221 (*i)->enable (false);
1224 _session.set_dirty ();
1227 /** Turn off all redirects
1230 Route::disable_processors ()
1232 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1234 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1235 (*i)->enable (false);
1238 _session.set_dirty ();
1241 /** Turn off all redirects with a given placement
1242 * @param p Placement of redirects to disable
1245 Route::disable_plugins (Placement p)
1247 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1249 ProcessorList::iterator start, end;
1250 placement_range(p, start, end);
1252 for (ProcessorList::iterator i = start; i != end; ++i) {
1253 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1254 (*i)->enable (false);
1258 _session.set_dirty ();
1261 /** Turn off all plugins
1264 Route::disable_plugins ()
1266 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1268 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1269 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1270 (*i)->enable (false);
1274 _session.set_dirty ();
1279 Route::ab_plugins (bool forward)
1281 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1285 /* forward = turn off all active redirects, and mark them so that the next time
1286 we go the other way, we will revert them
1289 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1290 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1293 if (!(*i)->display_to_user ()) {
1297 if (boost::dynamic_pointer_cast<PluginInsert> (*i)->is_channelstrip()) {
1302 if ((*i)->enabled ()) {
1303 (*i)->enable (false);
1304 (*i)->set_next_ab_is_active (true);
1306 (*i)->set_next_ab_is_active (false);
1312 /* backward = if the redirect was marked to go active on the next ab, do so */
1314 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1315 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1318 if (!(*i)->display_to_user ()) {
1322 if (boost::dynamic_pointer_cast<PluginInsert> (*i)->is_channelstrip()) {
1327 (*i)->enable ((*i)->get_next_ab_is_active ());
1331 _session.set_dirty ();
1335 /** Remove processors with a given placement.
1336 * @param p Placement of processors to remove.
1339 Route::clear_processors (Placement p)
1341 if (!_session.engine().connected()) {
1345 bool already_deleting = _session.deletion_in_progress();
1346 if (!already_deleting) {
1347 _session.set_deletion_in_progress();
1350 ProcessorList old_list = _processors;
1352 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1353 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1354 ProcessorList new_list;
1355 ProcessorStreams err;
1356 bool seen_amp = false;
1358 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1364 if (is_internal_processor (*i)) {
1366 /* you can't remove these */
1368 new_list.push_back (*i);
1375 new_list.push_back (*i);
1378 (*i)->drop_references ();
1386 (*i)->drop_references ();
1389 new_list.push_back (*i);
1396 _processors = new_list;
1397 configure_processors_unlocked (&err, &lm); // this can't fail
1399 /* drop references w/o process-lock (I/O procs may re-take it in ~IO() */
1402 processor_max_streams.reset();
1403 _have_internal_generator = false;
1404 reset_instrument_info ();
1405 set_processor_positions ();
1407 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1409 if (!already_deleting) {
1410 _session.clear_deletion_in_progress();
1415 Route::is_internal_processor (boost::shared_ptr<Processor> p) const
1417 if (p == _amp || p == _meter || p == _main_outs || p == _delayline || p == _trim) {
1424 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err, bool need_process_lock)
1426 // TODO once the export point can be configured properly, do something smarter here
1427 if (processor == _capturing_processor) {
1428 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1429 if (need_process_lock) {
1433 _capturing_processor.reset();
1435 if (need_process_lock) {
1440 /* these can never be removed */
1442 if (is_internal_processor (processor)) {
1446 if (!_session.engine().connected()) {
1450 processor_max_streams.reset();
1453 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1454 if (need_process_lock) {
1458 /* Caller must hold process lock */
1459 assert (!AudioEngine::instance()->process_lock().trylock());
1461 Glib::Threads::RWLock::WriterLock lm (_processor_lock); // XXX deadlock after export
1463 ProcessorState pstate (this);
1465 ProcessorList::iterator i;
1466 bool removed = false;
1468 for (i = _processors.begin(); i != _processors.end(); ) {
1469 if (*i == processor) {
1471 /* move along, see failure case for configure_processors()
1472 where we may need to reconfigure the processor.
1475 /* stop redirects that send signals to JACK ports
1476 from causing noise as a result of no longer being
1480 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor> (*i);
1481 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
1485 iop = pi->sidechain();
1492 i = _processors.erase (i);
1500 _output->set_user_latency (0);
1508 if (configure_processors_unlocked (err, &lm)) {
1510 /* we know this will work, because it worked before :) */
1511 configure_processors_unlocked (0, &lm);
1515 _have_internal_generator = false;
1517 for (i = _processors.begin(); i != _processors.end(); ++i) {
1518 boost::shared_ptr<PluginInsert> pi;
1520 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1521 if (pi->has_no_inputs ()) {
1522 _have_internal_generator = true;
1527 if (need_process_lock) {
1532 reset_instrument_info ();
1533 processor->drop_references ();
1534 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1535 set_processor_positions ();
1541 Route::replace_processor (boost::shared_ptr<Processor> old, boost::shared_ptr<Processor> sub, ProcessorStreams* err)
1543 /* these can never be removed */
1544 if (is_internal_processor (old)) {
1547 /* and can't be used as substitute, either */
1548 if (is_internal_processor (sub)) {
1552 /* I/Os are out, too */
1553 if (boost::dynamic_pointer_cast<IOProcessor> (old) || boost::dynamic_pointer_cast<IOProcessor> (sub)) {
1557 /* this function cannot be used to swap/reorder processors */
1558 if (find (_processors.begin(), _processors.end(), sub) != _processors.end ()) {
1562 if (!AudioEngine::instance()->connected() || !old || !sub) {
1566 /* ensure that sub is not owned by another route */
1567 if (sub->owner ()) {
1572 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1573 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1574 ProcessorState pstate (this);
1576 assert (find (_processors.begin(), _processors.end(), sub) == _processors.end ());
1578 ProcessorList::iterator i;
1579 bool replaced = false;
1580 bool enable = old->enabled ();
1582 for (i = _processors.begin(); i != _processors.end(); ) {
1584 i = _processors.erase (i);
1585 _processors.insert (i, sub);
1586 sub->set_owner (this);
1599 boost::shared_ptr<PluginInsert> pi;
1600 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(sub)) != 0) {
1601 pi->set_strict_io (true);
1605 if (configure_processors_unlocked (err, &lm)) {
1607 configure_processors_unlocked (0, &lm);
1611 _have_internal_generator = false;
1613 for (i = _processors.begin(); i != _processors.end(); ++i) {
1614 boost::shared_ptr<PluginInsert> pi;
1615 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1616 if (pi->has_no_inputs ()) {
1617 _have_internal_generator = true;
1627 sub->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1628 _output->set_user_latency (0);
1631 reset_instrument_info ();
1632 old->drop_references ();
1633 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1634 set_processor_positions ();
1639 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1641 ProcessorList deleted;
1643 if (!_session.engine().connected()) {
1647 processor_max_streams.reset();
1650 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1651 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1652 ProcessorState pstate (this);
1654 ProcessorList::iterator i;
1655 boost::shared_ptr<Processor> processor;
1657 for (i = _processors.begin(); i != _processors.end(); ) {
1661 /* these can never be removed */
1663 if (is_internal_processor (processor)) {
1668 /* see if its in the list of processors to delete */
1670 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1675 /* stop IOProcessors that send to JACK ports
1676 from causing noise as a result of no longer being
1680 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(processor);
1681 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
1684 iop = pi->sidechain();
1691 deleted.push_back (processor);
1692 i = _processors.erase (i);
1695 if (deleted.empty()) {
1696 /* none of those in the requested list were found */
1700 _output->set_user_latency (0);
1702 if (configure_processors_unlocked (err, &lm)) {
1704 /* we know this will work, because it worked before :) */
1705 configure_processors_unlocked (0, &lm);
1710 _have_internal_generator = false;
1712 for (i = _processors.begin(); i != _processors.end(); ++i) {
1713 boost::shared_ptr<PluginInsert> pi;
1715 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1716 if (pi->has_no_inputs ()) {
1717 _have_internal_generator = true;
1724 /* now try to do what we need to so that those that were removed will be deleted */
1726 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1727 (*i)->drop_references ();
1730 reset_instrument_info ();
1731 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1732 set_processor_positions ();
1738 Route::reset_instrument_info ()
1740 boost::shared_ptr<Processor> instr = the_instrument();
1742 _instrument_info.set_internal_instrument (instr);
1746 /** Caller must hold process lock */
1748 Route::configure_processors (ProcessorStreams* err)
1750 #ifndef PLATFORM_WINDOWS
1751 assert (!AudioEngine::instance()->process_lock().trylock());
1754 if (!_in_configure_processors) {
1755 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1756 return configure_processors_unlocked (err, &lm);
1763 Route::input_streams () const
1765 return _input->n_ports ();
1768 list<pair<ChanCount, ChanCount> >
1769 Route::try_configure_processors (ChanCount in, ProcessorStreams* err)
1771 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1773 return try_configure_processors_unlocked (in, err);
1776 list<pair<ChanCount, ChanCount> >
1777 Route::try_configure_processors_unlocked (ChanCount in, ProcessorStreams* err)
1779 // Check each processor in order to see if we can configure as requested
1781 list<pair<ChanCount, ChanCount> > configuration;
1784 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1785 DEBUG_TRACE (DEBUG::Processors, "{\n");
1787 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1789 if ((*p)->can_support_io_configuration(in, out)) {
1791 if (boost::dynamic_pointer_cast<Delivery> (*p)
1792 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main
1794 && (is_monitor() || _strict_io || Profile->get_mixbus ())) {
1795 /* with strict I/O the panner + output are forced to
1796 * follow the last processor's output.
1798 * Delivery::can_support_io_configuration() will only add ports,
1799 * but not remove excess ports.
1801 * This works because the delivery only requires
1802 * as many outputs as there are inputs.
1803 * Delivery::configure_io() will do the actual removal
1804 * by calling _output->ensure_io()
1806 if (!is_master() && _session.master_out () && in.n_audio() > 0) {
1807 /* ..but at least as many as there are master-inputs, if
1808 * the delivery is dealing with audio */
1809 // XXX this may need special-casing for mixbus (master-outputs)
1810 // and should maybe be a preference anyway ?!
1811 out = ChanCount::max (in, _session.master_out ()->n_inputs ());
1817 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID=%2 in=%3 out=%4\n",(*p)->name(), (*p)->id(), in, out));
1818 configuration.push_back(make_pair(in, out));
1821 // restriction for Monitor Section Processors
1822 if (in.n_audio() != out.n_audio() || out.n_midi() > 0) {
1823 /* Note: The Monitor follows the master-bus and has no panner.
1825 * The general idea is to only allow plugins that retain the channel-count
1826 * and plugins with MIDI in (e.g VSTs with control that will remain unconnected).
1827 * Then again 5.1 in, monitor stereo is a valid use-case.
1829 * and worse: we only refuse adding plugins *here*.
1831 * 1) stereo-master, stereo-mon, add a stereo-plugin, OK
1832 * 2) change master-bus, add a channel
1833 * 2a) monitor-secion follows
1834 * 3) monitor processors fail to re-reconfigure (stereo plugin)
1835 * 4) re-load session, monitor-processor remains unconfigured, crash.
1837 DEBUG_TRACE (DEBUG::Processors, "Monitor: Channel configuration change.\n");
1839 if (boost::dynamic_pointer_cast<InternalSend> (*p)) {
1840 // internal sends make no sense, only feedback
1841 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1842 return list<pair<ChanCount, ChanCount> > ();
1844 if (boost::dynamic_pointer_cast<PortInsert> (*p)) {
1845 /* External Sends can be problematic. one can add/remove ports
1846 * there signal leaves the DAW to external monitors anyway, so there's
1847 * no real use for allowing them here anyway.
1849 DEBUG_TRACE (DEBUG::Processors, "Monitor: No External Sends allowed.\n");
1850 return list<pair<ChanCount, ChanCount> > ();
1852 if (boost::dynamic_pointer_cast<Send> (*p)) {
1854 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1855 return list<pair<ChanCount, ChanCount> > ();
1864 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
1865 DEBUG_TRACE (DEBUG::Processors, string_compose ("---- %1 cannot support in=%2 out=%3\n", (*p)->name(), in, out));
1866 DEBUG_TRACE (DEBUG::Processors, "}\n");
1867 return list<pair<ChanCount, ChanCount> > ();
1871 DEBUG_TRACE (DEBUG::Processors, "}\n");
1873 return configuration;
1876 /** Set the input/output configuration of each processor in the processors list.
1877 * Caller must hold process lock.
1878 * Return 0 on success, otherwise configuration is impossible.
1881 Route::configure_processors_unlocked (ProcessorStreams* err, Glib::Threads::RWLock::WriterLock* lm)
1883 #ifndef PLATFORM_WINDOWS
1884 assert (!AudioEngine::instance()->process_lock().trylock());
1887 if (_in_configure_processors) {
1891 /* put invisible processors where they should be */
1892 setup_invisible_processors ();
1894 _in_configure_processors = true;
1896 list<pair<ChanCount, ChanCount> > configuration = try_configure_processors_unlocked (input_streams (), err);
1898 if (configuration.empty ()) {
1899 _in_configure_processors = false;
1904 bool seen_mains_out = false;
1905 processor_out_streams = _input->n_ports();
1906 processor_max_streams.reset();
1908 /* processor configure_io() may result in adding ports
1909 * e.g. Delivery::configure_io -> ARDOUR::IO::ensure_io ()
1911 * with jack2 adding ports results in a graph-order callback,
1912 * which calls Session::resort_routes() and eventually
1913 * Route::direct_feeds_according_to_reality()
1914 * which takes a ReaderLock (_processor_lock).
1916 * so we can't hold a WriterLock here until jack2 threading
1919 * NB. we still hold the process lock
1921 * (ardour's own engines do call graph-order from the
1922 * process-thread and hence do not have this issue; besides
1923 * merely adding ports won't trigger a graph-order, only
1924 * making connections does)
1928 // TODO check for a potential ReaderLock after ReaderLock ??
1929 Glib::Threads::RWLock::ReaderLock lr (_processor_lock);
1931 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1932 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1934 if (!(*p)->configure_io(c->first, c->second)) {
1935 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration failed\n", _name));
1936 _in_configure_processors = false;
1942 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1943 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1945 boost::shared_ptr<IOProcessor> iop;
1946 boost::shared_ptr<PluginInsert> pi;
1947 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
1948 /* plugins connected via Split or Hide Match may have more channels.
1949 * route/scratch buffers are needed for all of them
1950 * The configuration may only be a subset (both input and output)
1952 processor_max_streams = ChanCount::max(processor_max_streams, pi->required_buffers());
1954 else if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*p)) != 0) {
1955 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_input_streams());
1956 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_output_streams());
1960 if (boost::dynamic_pointer_cast<Delivery> (*p)
1961 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main) {
1962 /* main delivery will increase port count to match input.
1963 * the Delivery::Main is usually the last processor - followed only by
1966 seen_mains_out = true;
1968 if (!seen_mains_out) {
1969 processor_out_streams = out;
1978 _meter->set_max_channels (processor_max_streams);
1981 /* make sure we have sufficient scratch buffers to cope with the new processor
1984 _session.ensure_buffers (n_process_buffers ());
1986 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration complete\n", _name));
1988 _in_configure_processors = false;
1992 /** Set all visible processors to a given active state (except Fader, whose state is not changed)
1993 * @param state New active state for those processors.
1996 Route::all_visible_processors_active (bool state)
1998 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2000 if (_processors.empty()) {
2004 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2005 if (!(*i)->display_to_user() || boost::dynamic_pointer_cast<Amp> (*i)) {
2009 boost::shared_ptr<PluginInsert> pi;
2010 if (0 != (pi = boost::dynamic_pointer_cast<PluginInsert>(*i))) {
2011 if (pi->is_channelstrip ()) {
2016 (*i)->enable (state);
2019 _session.set_dirty ();
2023 Route::processors_reorder_needs_configure (const ProcessorList& new_order)
2025 /* check if re-order requires re-configuration of any processors
2026 * -> compare channel configuration for all processors
2028 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2029 ChanCount c = input_streams ();
2031 for (ProcessorList::const_iterator j = new_order.begin(); j != new_order.end(); ++j) {
2033 if (c != (*j)->input_streams()) {
2036 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2039 if ((*i)->input_streams() != c) {
2042 c = (*i)->output_streams();
2054 __attribute__((annotate("realtime")))
2057 Route::apply_processor_order (const ProcessorList& new_order)
2059 /* need to hold processor_lock; either read or write lock
2060 * and the engine process_lock.
2061 * Due to r/w lock ambiguity we can only assert the latter
2063 assert (!AudioEngine::instance()->process_lock().trylock());
2066 /* "new_order" is an ordered list of processors to be positioned according to "placement".
2067 * NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
2068 * processors in the current actual processor list that are hidden. Any visible processors
2069 * in the current list but not in "new_order" will be assumed to be deleted.
2072 /* "as_it_will_be" and "_processors" are lists of shared pointers.
2073 * actual memory usage is small, but insert/erase is not actually rt-safe :(
2074 * (note though that ::processors_reorder_needs_configure() ensured that
2075 * this function will only ever be called from the rt-thread if no processor were removed)
2077 * either way, I can't proove it, but an x-run due to re-order here is less likley
2078 * than an x-run-less 'ardour-silent cycle' both of which effectively "click".
2081 ProcessorList as_it_will_be;
2082 ProcessorList::iterator oiter;
2083 ProcessorList::const_iterator niter;
2085 oiter = _processors.begin();
2086 niter = new_order.begin();
2088 while (niter != new_order.end()) {
2090 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
2091 then append it to the temp list.
2093 Otherwise, see if the next processor in the old list is in the new list. if not,
2094 its been deleted. If its there, append it to the temp list.
2097 if (oiter == _processors.end()) {
2099 /* no more elements in the old list, so just stick the rest of
2100 the new order onto the temp list.
2103 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
2104 while (niter != new_order.end()) {
2111 if (!(*oiter)->display_to_user()) {
2113 as_it_will_be.push_back (*oiter);
2117 /* visible processor: check that its in the new order */
2119 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
2120 /* deleted: do nothing, shared_ptr<> will clean up */
2122 /* ignore this one, and add the next item from the new order instead */
2123 as_it_will_be.push_back (*niter);
2128 /* now remove from old order - its taken care of no matter what */
2129 oiter = _processors.erase (oiter);
2133 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
2135 /* If the meter is in a custom position, find it and make a rough note of its position */
2136 maybe_note_meter_position ();
2140 Route::move_instrument_down (bool postfader)
2142 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2143 ProcessorList new_order;
2144 boost::shared_ptr<Processor> instrument;
2145 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2146 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
2147 if (pi && pi->plugin ()->get_info ()->is_instrument ()) {
2149 } else if (instrument && *i == _amp) {
2151 new_order.push_back (*i);
2152 new_order.push_back (instrument);
2154 new_order.push_back (instrument);
2155 new_order.push_back (*i);
2158 new_order.push_back (*i);
2165 reorder_processors (new_order, 0);
2169 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
2171 // it a change is already queued, wait for it
2172 // (unless engine is stopped. apply immediately and proceed
2173 while (g_atomic_int_get (&_pending_process_reorder)) {
2174 if (!AudioEngine::instance()->running()) {
2175 DEBUG_TRACE (DEBUG::Processors, "offline apply queued processor re-order.\n");
2176 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2178 apply_processor_order(_pending_processor_order);
2179 setup_invisible_processors ();
2181 g_atomic_int_set (&_pending_process_reorder, 0);
2183 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2184 set_processor_positions ();
2186 // TODO rather use a semaphore or something.
2187 // but since ::reorder_processors() is called
2188 // from the GUI thread, this is fine..
2193 if (processors_reorder_needs_configure (new_order) || !AudioEngine::instance()->running()) {
2195 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2196 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2197 ProcessorState pstate (this);
2199 apply_processor_order (new_order);
2201 if (configure_processors_unlocked (err, &lm)) {
2209 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2210 set_processor_positions ();
2213 DEBUG_TRACE (DEBUG::Processors, "Queue clickless processor re-order.\n");
2214 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2216 // _pending_processor_order is protected by _processor_lock
2217 _pending_processor_order = new_order;
2218 g_atomic_int_set (&_pending_process_reorder, 1);
2221 /* update processor input/output latency
2222 * (total signal_latency does not change)
2224 update_signal_latency (true);
2230 Route::add_remove_sidechain (boost::shared_ptr<Processor> proc, bool add)
2232 boost::shared_ptr<PluginInsert> pi;
2233 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2237 if (pi->has_sidechain () == add) {
2238 return true; // ?? call failed, but result is as expected.
2242 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2243 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2244 if (i == _processors.end ()) {
2250 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ()); // take before Writerlock to avoid deadlock
2251 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2252 PBD::Unwinder<bool> uw (_in_sidechain_setup, true);
2254 lx.release (); // IO::add_port() and ~IO takes process lock - XXX check if this is safe
2256 if (!pi->add_sidechain ()) {
2260 if (!pi->del_sidechain ()) {
2266 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2271 pi->del_sidechain ();
2273 pi->add_sidechain ();
2274 // TODO restore side-chain's state.
2279 configure_processors_unlocked (0, &lm);
2282 if (pi->has_sidechain ()) {
2283 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
2286 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2287 _session.set_dirty ();
2292 Route::plugin_preset_output (boost::shared_ptr<Processor> proc, ChanCount outs)
2294 boost::shared_ptr<PluginInsert> pi;
2295 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2300 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2301 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2302 if (i == _processors.end ()) {
2308 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2309 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2311 const ChanCount& old (pi->preset_out ());
2312 if (!pi->set_preset_out (outs)) {
2313 return true; // no change, OK
2316 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2319 pi->set_preset_out (old);
2322 configure_processors_unlocked (0, &lm);
2325 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2326 _session.set_dirty ();
2331 Route::reset_plugin_insert (boost::shared_ptr<Processor> proc)
2334 return customize_plugin_insert (proc, 0, unused, unused);
2338 Route::customize_plugin_insert (boost::shared_ptr<Processor> proc, uint32_t count, ChanCount outs, ChanCount sinks)
2340 boost::shared_ptr<PluginInsert> pi;
2341 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2346 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2347 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2348 if (i == _processors.end ()) {
2354 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2355 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2357 bool old_cust = pi->custom_cfg ();
2358 uint32_t old_cnt = pi->get_count ();
2359 ChanCount old_chan = pi->output_streams ();
2360 ChanCount old_sinks = pi->natural_input_streams ();
2363 pi->set_custom_cfg (false);
2365 pi->set_custom_cfg (true);
2366 pi->set_count (count);
2367 pi->set_outputs (outs);
2368 pi->set_sinks (sinks);
2371 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2375 pi->set_count (old_cnt);
2376 pi->set_sinks (old_sinks);
2377 pi->set_outputs (old_chan);
2378 pi->set_custom_cfg (old_cust);
2382 configure_processors_unlocked (0, &lm);
2385 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2386 _session.set_dirty ();
2391 Route::set_strict_io (const bool enable)
2393 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2395 if (_strict_io != enable) {
2396 _strict_io = enable;
2397 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2398 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2399 boost::shared_ptr<PluginInsert> pi;
2400 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2401 pi->set_strict_io (_strict_io);
2405 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2409 _strict_io = !enable; // restore old value
2410 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2411 boost::shared_ptr<PluginInsert> pi;
2412 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2413 pi->set_strict_io (_strict_io);
2420 configure_processors (0);
2423 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2424 _session.set_dirty ();
2432 return state (false);
2436 Route::get_template()
2438 return state (true);
2442 Route::state (bool save_template)
2444 if (!_session._template_state_dir.empty()) {
2445 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), _session._template_state_dir));
2448 XMLNode *node = new XMLNode("Route");
2449 ProcessorList::iterator i;
2451 node->set_property (X_("id"), id ());
2452 node->set_property (X_("name"), name());
2453 node->set_property (X_("default-type"), _default_type);
2454 node->set_property (X_("strict-io"), _strict_io);
2456 node->add_child_nocopy (_presentation_info.get_state());
2458 node->set_property (X_("active"), _active);
2459 node->set_property (X_("denormal-protection"), _denormal_protection);
2460 node->set_property (X_("meter-point"), _meter_point);
2461 node->set_property (X_("disk-io-point"), _disk_io_point);
2463 node->set_property (X_("meter-type"), _meter_type);
2466 node->set_property (X_("route-group"), _route_group->name());
2469 node->add_child_nocopy (_solo_control->get_state ());
2470 node->add_child_nocopy (_solo_isolate_control->get_state ());
2471 node->add_child_nocopy (_solo_safe_control->get_state ());
2473 node->add_child_nocopy (_input->get_state ());
2474 node->add_child_nocopy (_output->get_state ());
2475 node->add_child_nocopy (_mute_master->get_state ());
2477 node->add_child_nocopy (_mute_control->get_state ());
2478 node->add_child_nocopy (_phase_control->get_state ());
2480 if (!skip_saving_automation) {
2481 node->add_child_nocopy (Automatable::get_automation_xml_state ());
2484 if (_comment.length()) {
2485 XMLNode *cmt = node->add_child ("Comment");
2486 cmt->add_content (_comment);
2490 node->add_child_nocopy (_pannable->get_state ());
2494 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2495 for (i = _processors.begin(); i != _processors.end(); ++i) {
2496 if (*i == _delayline) {
2499 if (save_template) {
2500 /* template save: do not include internal sends functioning as
2501 aux sends because the chance of the target ID
2502 in the session where this template is used
2505 similarly, do not save listen sends which connect to
2506 the monitor section, because these will always be
2509 boost::shared_ptr<InternalSend> is;
2511 if ((is = boost::dynamic_pointer_cast<InternalSend> (*i)) != 0) {
2512 if (is->role() == Delivery::Listen) {
2517 node->add_child_nocopy((*i)->get_state ());
2522 node->add_child_copy (*_extra_xml);
2525 if (_custom_meter_position_noted) {
2526 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
2528 node->set_property (X_("processor-after-last-custom-meter"), after->id());
2532 if (!_session._template_state_dir.empty()) {
2533 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), ""));
2536 node->add_child_copy (Slavable::get_state());
2542 Route::set_state (const XMLNode& node, int version)
2544 if (version < 3000) {
2545 return set_state_2X (node, version);
2549 XMLNodeConstIterator niter;
2552 if (node.name() != "Route"){
2553 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2557 std::string route_name;
2558 if (node.get_property (X_("name"), route_name)) {
2559 Route::set_name (route_name);
2563 _initial_io_setup = true;
2565 Stripable::set_state (node, version);
2567 node.get_property (X_("strict-io"), _strict_io);
2570 /* monitor bus does not get a panner, but if (re)created
2571 via XML, it will already have one by the time we
2572 call ::set_state(). so ... remove it.
2577 /* add all processors (except amp, which is always present) */
2579 nlist = node.children();
2580 XMLNode processor_state (X_("processor_state"));
2582 Stateful::save_extra_xml (node);
2584 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2588 if (child->name() == IO::state_node_name) {
2589 std::string direction;
2590 if (!child->get_property (X_("direction"), direction)) {
2594 if (direction == "Input") {
2595 _input->set_state (*child, version);
2596 } else if (direction == "Output") {
2597 _output->set_state (*child, version);
2600 } else if (child->name() == X_("Processor")) {
2601 processor_state.add_child_copy (*child);
2602 } else if (child->name() == X_("Pannable")) {
2604 _pannable->set_state (*child, version);
2606 warning << string_compose (_("Pannable state found for route (%1) without a panner!"), name()) << endmsg;
2608 } else if (child->name() == Slavable::xml_node_name) {
2609 Slavable::set_state (*child, version);
2614 if (node.get_property (X_("meter-point"), mp)) {
2615 set_meter_point (mp, true);
2617 _meter->set_display_to_user (_meter_point == MeterCustom);
2622 if (node.get_property (X_("disk-io-point"), diop)) {
2624 _disk_writer->set_display_to_user (diop == DiskIOCustom);
2627 _disk_reader->set_display_to_user (diop == DiskIOCustom);
2629 set_disk_io_point (diop);
2632 node.get_property (X_("meter-type"), _meter_type);
2634 _initial_io_setup = false;
2636 set_processor_state (processor_state);
2638 // this looks up the internal instrument in processors
2639 reset_instrument_info();
2641 bool denormal_protection;
2642 if (node.get_property (X_("denormal-protection"), denormal_protection)) {
2643 set_denormal_protection (denormal_protection);
2646 /* convert old 3001 state */
2647 std::string phase_invert_str;
2648 if (node.get_property (X_("phase-invert"), phase_invert_str)) {
2649 _phase_control->set_phase_invert (boost::dynamic_bitset<> (phase_invert_str));
2653 if (node.get_property (X_("active"), is_active)) {
2654 set_active (is_active, this);
2657 std::string id_string;
2658 if (node.get_property (X_("processor-after-last-custom-meter"), id_string)) {
2659 PBD::ID id (id_string);
2660 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2661 ProcessorList::const_iterator i = _processors.begin ();
2662 while (i != _processors.end() && (*i)->id() != id) {
2666 if (i != _processors.end ()) {
2667 _processor_after_last_custom_meter = *i;
2668 _custom_meter_position_noted = true;
2672 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2675 if (child->name() == X_("Comment")) {
2677 /* XXX this is a terrible API design in libxml++ */
2679 XMLNode *cmt = *(child->children().begin());
2680 _comment = cmt->content();
2682 } else if (child->name() == Controllable::xml_node_name) {
2683 std::string control_name;
2684 if (!child->get_property (X_("name"), control_name)) {
2688 if (control_name == _solo_control->name()) {
2689 _solo_control->set_state (*child, version);
2690 } else if (control_name == _solo_safe_control->name()) {
2691 _solo_safe_control->set_state (*child, version);
2692 } else if (control_name == _solo_isolate_control->name()) {
2693 _solo_isolate_control->set_state (*child, version);
2694 } else if (control_name == _mute_control->name()) {
2695 _mute_control->set_state (*child, version);
2696 } else if (control_name == _phase_control->name()) {
2697 _phase_control->set_state (*child, version);
2699 Evoral::Parameter p = EventTypeMap::instance().from_symbol (control_name);
2700 if (p.type () >= MidiCCAutomation && p.type () < MidiSystemExclusiveAutomation) {
2701 boost::shared_ptr<AutomationControl> ac = automation_control (p, true);
2703 ac->set_state (*child, version);
2707 } else if (child->name() == MuteMaster::xml_node_name) {
2708 _mute_master->set_state (*child, version);
2710 } else if (child->name() == Automatable::xml_node_name) {
2711 set_automation_xml_state (*child, Evoral::Parameter(NullAutomation));
2716 _delayline->set_name (name ());
2723 Route::set_state_2X (const XMLNode& node, int version)
2727 XMLNodeConstIterator niter;
2729 XMLProperty const * prop;
2731 /* 2X things which still remain to be handled:
2737 if (node.name() != "Route") {
2738 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2742 Stripable::set_state (node, version);
2744 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2745 set_denormal_protection (string_to<bool> (prop->value()));
2748 if ((prop = node.property (X_("muted"))) != 0) {
2751 bool muted = string_to<bool> (prop->value());
2757 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2759 if (string_to<bool> (prop->value())){
2760 mute_point = mute_point + "PreFader";
2765 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2767 if (string_to<bool> (prop->value())){
2770 mute_point = mute_point + ",";
2773 mute_point = mute_point + "PostFader";
2778 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2780 if (string_to<bool> (prop->value())){
2783 mute_point = mute_point + ",";
2786 mute_point = mute_point + "Listen";
2791 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2793 if (string_to<bool> (prop->value())){
2796 mute_point = mute_point + ",";
2799 mute_point = mute_point + "Main";
2803 _mute_master->set_mute_points (mute_point);
2804 _mute_master->set_muted_by_self (true);
2808 if ((prop = node.property (X_("meter-point"))) != 0) {
2809 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2814 nlist = node.children ();
2815 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2819 if (child->name() == IO::state_node_name) {
2821 /* there is a note in IO::set_state_2X() about why we have to call
2825 _input->set_state_2X (*child, version, true);
2826 _output->set_state_2X (*child, version, false);
2828 if ((prop = child->property (X_("name"))) != 0) {
2829 Route::set_name (prop->value ());
2834 if ((prop = child->property (X_("active"))) != 0) {
2835 bool yn = string_to<bool> (prop->value());
2836 _active = !yn; // force switch
2837 set_active (yn, this);
2840 if ((prop = child->property (X_("gain"))) != 0) {
2843 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
2844 _amp->gain_control()->set_value (val, Controllable::NoGroup);
2848 /* Set up Panners in the IO */
2849 XMLNodeList io_nlist = child->children ();
2851 XMLNodeConstIterator io_niter;
2854 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
2856 io_child = *io_niter;
2858 if (io_child->name() == X_("Panner")) {
2859 _main_outs->panner_shell()->set_state(*io_child, version);
2860 } else if (io_child->name() == X_("Automation")) {
2861 /* IO's automation is for the fader */
2862 _amp->set_automation_xml_state (*io_child, Evoral::Parameter (GainAutomation));
2868 XMLNodeList redirect_nodes;
2870 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2874 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2875 redirect_nodes.push_back(child);
2880 set_processor_state_2X (redirect_nodes, version);
2882 Stateful::save_extra_xml (node);
2884 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2887 if (child->name() == X_("Comment")) {
2889 /* XXX this is a terrible API design in libxml++ */
2891 XMLNode *cmt = *(child->children().begin());
2892 _comment = cmt->content();
2894 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2895 if (prop->value() == X_("solo")) {
2896 _solo_control->set_state (*child, version);
2897 } else if (prop->value() == X_("mute")) {
2898 _mute_control->set_state (*child, version);
2908 Route::get_processor_state ()
2910 XMLNode* root = new XMLNode (X_("redirects"));
2911 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2912 root->add_child_nocopy ((*i)->get_state ());
2919 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2921 /* We don't bother removing existing processors not in nList, as this
2922 method will only be called when creating a Route from scratch, not
2923 for undo purposes. Just put processors in at the appropriate place
2927 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2928 add_processor_from_xml_2X (**i, version);
2933 Route::set_processor_state (const XMLNode& node)
2935 const XMLNodeList &nlist = node.children();
2936 XMLNodeConstIterator niter;
2937 ProcessorList new_order;
2938 bool must_configure = false;
2940 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2942 XMLProperty* prop = (*niter)->property ("type");
2944 if (prop->value() == "amp") {
2945 _amp->set_state (**niter, Stateful::current_state_version);
2946 new_order.push_back (_amp);
2947 } else if (prop->value() == "trim") {
2948 _trim->set_state (**niter, Stateful::current_state_version);
2949 new_order.push_back (_trim);
2950 } else if (prop->value() == "meter") {
2951 _meter->set_state (**niter, Stateful::current_state_version);
2952 new_order.push_back (_meter);
2953 } else if (prop->value() == "delay") {
2955 } else if (prop->value() == "main-outs") {
2956 _main_outs->set_state (**niter, Stateful::current_state_version);
2957 } else if (prop->value() == "intreturn") {
2959 _intreturn.reset (new InternalReturn (_session));
2960 must_configure = true;
2962 _intreturn->set_state (**niter, Stateful::current_state_version);
2963 } else if (is_monitor() && prop->value() == "monitor") {
2964 if (!_monitor_control) {
2965 _monitor_control.reset (new MonitorProcessor (_session));
2966 must_configure = true;
2968 _monitor_control->set_state (**niter, Stateful::current_state_version);
2969 } else if (prop->value() == "capture") {
2970 /* CapturingProcessor should never be restored, it's always
2971 added explicitly when needed */
2972 } else if (prop->value() == "diskreader" && _disk_reader) {
2973 _disk_reader->set_state (**niter, Stateful::current_state_version);
2974 new_order.push_back (_disk_reader);
2975 } else if (prop->value() == "diskwriter" && _disk_writer) {
2976 _disk_writer->set_state (**niter, Stateful::current_state_version);
2977 new_order.push_back (_disk_writer);
2979 set_processor_state (**niter, prop, new_order, must_configure);
2983 ProcessorList old_list = _processors; // keep a copy
2985 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2986 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2987 /* re-assign _processors w/o process-lock.
2988 * if there's an IO-processor present in _processors but
2989 * not in new_order, it will be deleted and ~IO takes
2992 _processors = new_order;
2994 if (must_configure) {
2995 configure_processors_unlocked (0, &lm);
2998 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3000 (*i)->set_owner (this);
3001 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
3003 boost::shared_ptr<PluginInsert> pi;
3005 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
3006 if (pi->has_no_inputs ()) {
3007 _have_internal_generator = true;
3013 /* drop references w/o process-lock (I/O procs may re-take it in ~IO() */
3016 reset_instrument_info ();
3017 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3018 set_processor_positions ();
3022 Route::set_processor_state (XMLNode const & node, XMLProperty const* prop, ProcessorList& new_order, bool& must_configure)
3024 ProcessorList::iterator o;
3026 for (o = _processors.begin(); o != _processors.end(); ++o) {
3027 XMLProperty const * id_prop = node.property(X_("id"));
3028 if (id_prop && (*o)->id() == id_prop->value()) {
3029 (*o)->set_state (node, Stateful::current_state_version);
3030 new_order.push_back (*o);
3035 // If the processor (node) is not on the route then create it
3037 if (o == _processors.end()) {
3039 boost::shared_ptr<Processor> processor;
3041 if (prop->value() == "intsend") {
3043 processor.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), boost::shared_ptr<Route>(), Delivery::Aux, true));
3045 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
3046 prop->value() == "lv2" ||
3047 prop->value() == "windows-vst" ||
3048 prop->value() == "mac-vst" ||
3049 prop->value() == "lxvst" ||
3050 prop->value() == "luaproc" ||
3051 prop->value() == "audiounit") {
3053 if (_session.get_disable_all_loaded_plugins ()) {
3054 processor.reset (new UnknownProcessor (_session, node));
3056 processor.reset (new PluginInsert (_session));
3057 processor->set_owner (this);
3059 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
3060 pi->set_strict_io (true);
3064 } else if (prop->value() == "port") {
3066 processor.reset (new PortInsert (_session, _pannable, _mute_master));
3068 } else if (prop->value() == "send") {
3070 processor.reset (new Send (_session, _pannable, _mute_master, Delivery::Send, true));
3071 boost::shared_ptr<Send> send = boost::dynamic_pointer_cast<Send> (processor);
3072 send->SelfDestruct.connect_same_thread (*this,
3073 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (processor)));
3079 if (processor->set_state (node, Stateful::current_state_version) != 0) {
3080 /* This processor could not be configured. Turn it into a UnknownProcessor */
3081 processor.reset (new UnknownProcessor (_session, node));
3084 /* subscribe to Sidechain IO changes */
3085 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
3086 if (pi && pi->has_sidechain ()) {
3087 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
3090 /* we have to note the monitor send here, otherwise a new one will be created
3091 and the state of this one will be lost.
3093 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
3094 if (isend && isend->role() == Delivery::Listen) {
3095 _monitor_send = isend;
3098 /* it doesn't matter if invisible processors are added here, as they
3099 will be sorted out by setup_invisible_processors () shortly.
3102 new_order.push_back (processor);
3103 must_configure = true;
3109 Route::curve_reallocate ()
3111 // _gain_automation_curve.finish_resize ();
3112 // _pan_automation_curve.finish_resize ();
3116 Route::silence (samplecnt_t nframes)
3118 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3123 silence_unlocked (nframes);
3127 Route::silence_unlocked (samplecnt_t nframes)
3129 /* Must be called with the processor lock held */
3131 const samplepos_t now = _session.transport_sample ();
3133 _output->silence (nframes);
3135 // update owned automated controllables
3136 automation_run (now, nframes);
3138 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3139 boost::shared_ptr<PluginInsert> pi;
3141 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
3142 /* evaluate automated automation controls */
3143 pi->automation_run (now, nframes);
3144 /* skip plugins, they don't need anything when we're not active */
3148 (*i)->silence (nframes, now);
3153 Route::add_internal_return ()
3156 _intreturn.reset (new InternalReturn (_session));
3157 add_processor (_intreturn, PreFader);
3162 Route::add_send_to_internal_return (InternalSend* send)
3164 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3166 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3167 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3170 return d->add_send (send);
3176 Route::remove_send_from_internal_return (InternalSend* send)
3178 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3180 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3181 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3184 return d->remove_send (send);
3190 Route::enable_monitor_send ()
3192 /* Caller must hold process lock */
3193 assert (!AudioEngine::instance()->process_lock().trylock());
3195 /* master never sends to monitor section via the normal mechanism */
3196 assert (!is_master ());
3197 assert (!is_monitor ());
3199 /* make sure we have one */
3200 if (!_monitor_send) {
3201 _monitor_send.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), _session.monitor_out(), Delivery::Listen));
3202 _monitor_send->set_display_to_user (false);
3206 configure_processors (0);
3209 /** Add an aux send to a route.
3210 * @param route route to send to.
3211 * @param before Processor to insert before, or 0 to insert at the end.
3214 Route::add_aux_send (boost::shared_ptr<Route> route, boost::shared_ptr<Processor> before)
3216 assert (route != _session.monitor_out ());
3219 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3221 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3223 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend> (*x);
3225 if (d && d->target_route() == route) {
3226 /* already listening via the specified IO: do nothing */
3234 boost::shared_ptr<InternalSend> listener;
3237 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
3238 listener.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), route, Delivery::Aux));
3241 add_processor (listener, before);
3243 } catch (failed_constructor& err) {
3251 Route::remove_aux_or_listen (boost::shared_ptr<Route> route)
3253 ProcessorStreams err;
3254 ProcessorList::iterator tmp;
3257 Glib::Threads::RWLock::ReaderLock rl(_processor_lock);
3259 /* have to do this early because otherwise processor reconfig
3260 * will put _monitor_send back in the list
3263 if (route == _session.monitor_out()) {
3264 _monitor_send.reset ();
3268 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3270 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
3272 if (d && d->target_route() == route) {
3274 if (remove_processor (*x, &err, false) > 0) {
3280 /* list could have been demolished while we dropped the lock
3283 if (_session.engine().connected()) {
3284 /* i/o processors cannot be removed if the engine is not running
3285 * so don't live-loop in case the engine is N/A or dies
3295 Route::set_comment (string cmt, void *src)
3299 _session.set_dirty ();
3303 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
3305 FeedRecord fr (other, via_sends_only);
3307 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
3309 if (!result.second) {
3311 /* already a record for "other" - make sure sends-only information is correct */
3312 if (!via_sends_only && result.first->sends_only) {
3313 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
3314 frp->sends_only = false;
3318 return result.second;
3322 Route::clear_fed_by ()
3328 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
3330 const FedBy& fed_by (other->fed_by());
3332 for (FedBy::const_iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
3333 boost::shared_ptr<Route> sr = f->r.lock();
3335 if (sr && (sr.get() == this)) {
3337 if (via_sends_only) {
3338 *via_sends_only = f->sends_only;
3349 Route::all_inputs () const
3351 /* TODO, if this works as expected,
3352 * cache the IOVector and maintain it via
3353 * input_change_handler(), sidechain_change_handler() etc
3356 ios.push_back (_input);
3358 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3359 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3361 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3362 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3365 iop = pi->sidechain();
3368 if (iop != 0 && iop->input()) {
3369 ios.push_back (iop->input());
3376 Route::all_outputs () const
3379 // _output is included via Delivery
3380 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3381 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3382 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3383 if (iop != 0 && iop->output()) {
3384 ios.push_back (iop->output());
3391 Route::direct_feeds_according_to_reality (boost::shared_ptr<Route> other, bool* via_send_only)
3393 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
3394 if (other->all_inputs().fed_by (_output)) {
3395 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
3396 if (via_send_only) {
3397 *via_send_only = false;
3403 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3405 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
3407 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3408 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3411 iop = pi->sidechain();
3415 boost::shared_ptr<const IO> iop_out = iop->output();
3416 if (other.get() == this && iop_out && iop->input() && iop_out->connected_to (iop->input())) {
3417 // TODO this needs a delaylines in the Insert to align connections (!)
3418 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed its own return (%2)\n", iop->name(), other->name()));
3421 if ((iop_out && other->all_inputs().fed_by (iop_out)) || iop->feeds (other)) {
3422 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
3423 if (via_send_only) {
3424 *via_send_only = true;
3428 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
3431 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
3436 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
3441 Route::direct_feeds_according_to_graph (boost::shared_ptr<Route> other, bool* via_send_only)
3443 return _session._current_route_graph.has (boost::dynamic_pointer_cast<Route> (shared_from_this ()), other, via_send_only);
3447 Route::feeds_according_to_graph (boost::shared_ptr<Route> other)
3449 return _session._current_route_graph.feeds (boost::dynamic_pointer_cast<Route> (shared_from_this ()), other);
3452 /** Called from the (non-realtime) butler thread when the transport is stopped */
3454 Route::non_realtime_transport_stop (samplepos_t now, bool flush)
3456 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3458 Automatable::non_realtime_transport_stop (now, flush);
3460 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3462 if (!_have_internal_generator && (Config->get_plugins_stop_with_transport() && flush)) {
3466 (*i)->non_realtime_transport_stop (now, flush);
3471 Route::input_change_handler (IOChange change, void * /*src*/)
3473 if ((change.type & IOChange::ConfigurationChanged)) {
3474 /* This is called with the process lock held if change
3475 contains ConfigurationChanged
3477 configure_processors (0);
3478 _phase_control->resize (_input->n_ports().n_audio ());
3479 io_changed (); /* EMIT SIGNAL */
3482 if (_solo_control->soloed_by_others_upstream() || _solo_isolate_control->solo_isolated_by_upstream()) {
3485 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3486 if (_input->connected()) {
3487 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3488 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3492 bool does_feed = (*i)->direct_feeds_according_to_reality (boost::dynamic_pointer_cast<Route> (shared_from_this()), &sends_only);
3493 if (does_feed && !sends_only) {
3494 if ((*i)->soloed()) {
3497 if ((*i)->solo_isolate_control()->solo_isolated()) {
3504 int delta = sbou - _solo_control->soloed_by_others_upstream();
3505 int idelta = ibou - _solo_isolate_control->solo_isolated_by_upstream();
3508 PBD::warning << string_compose (
3509 _("Invalid Solo-Isolate propagation: from:%1 new:%2 - old:%3 = delta:%4"),
3510 _name, ibou, _solo_isolate_control->solo_isolated_by_upstream(), idelta)
3515 if (_solo_control->soloed_by_others_upstream()) {
3516 // ignore new connections (they're not propagated)
3518 _solo_control->mod_solo_by_others_upstream (delta);
3522 if (_solo_isolate_control->solo_isolated_by_upstream()) {
3523 // solo-isolate currently only propagates downstream
3525 _solo_isolate_control->mod_solo_isolated_by_upstream (1);
3527 //_solo_isolated_by_upstream = ibou;
3530 // Session::route_solo_changed does not propagate indirect solo-changes
3531 // propagate downstream to tracks
3532 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3533 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3537 bool does_feed = feeds (*i, &sends_only);
3538 if (delta <= 0 && does_feed && !sends_only) {
3539 (*i)->solo_control()->mod_solo_by_others_upstream (delta);
3542 if (idelta < 0 && does_feed && !sends_only) {
3543 (*i)->solo_isolate_control()->mod_solo_isolated_by_upstream (-1);
3550 Route::output_change_handler (IOChange change, void * /*src*/)
3552 if (_initial_io_setup) {
3556 if ((change.type & IOChange::ConfigurationChanged)) {
3557 /* This is called with the process lock held if change
3558 contains ConfigurationChanged
3560 configure_processors (0);
3563 _session.reset_monitor_section();
3566 io_changed (); /* EMIT SIGNAL */
3569 if ((change.type & IOChange::ConnectionsChanged)) {
3571 /* do this ONLY if connections have changed. Configuration
3572 * changes do not, by themselves alter solo upstream or
3573 * downstream status.
3576 if (_solo_control->soloed_by_others_downstream()) {
3578 /* checking all all downstream routes for
3579 * explicit of implict solo is a rather drastic measure,
3580 * ideally the input_change_handler() of the other route
3581 * would propagate the change to us.
3583 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3584 if (_output->connected()) {
3585 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3586 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3590 bool does_feed = direct_feeds_according_to_reality (*i, &sends_only);
3591 if (does_feed && !sends_only) {
3592 if ((*i)->soloed()) {
3600 int delta = sbod - _solo_control->soloed_by_others_downstream();
3602 // do not allow new connections to change implicit solo (no propagation)
3603 _solo_control->mod_solo_by_others_downstream (delta);
3604 // Session::route_solo_changed() does not propagate indirect solo-changes
3605 // propagate upstream to tracks
3606 boost::shared_ptr<Route> shared_this = boost::dynamic_pointer_cast<Route> (shared_from_this());
3607 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3608 if ((*i).get() == this || !can_solo()) {
3612 bool does_feed = (*i)->feeds (shared_this, &sends_only);
3613 if (delta != 0 && does_feed && !sends_only) {
3614 (*i)->solo_control()->mod_solo_by_others_downstream (delta);
3624 Route::sidechain_change_handler (IOChange change, void* src)
3626 if (_initial_io_setup || _in_sidechain_setup) {
3630 input_change_handler (change, src);
3634 Route::pans_required () const
3636 if (n_outputs().n_audio() < 2) {
3640 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
3644 Route::flush_processor_buffers_locked (samplecnt_t nframes)
3646 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3647 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery> (*i);
3649 d->flush_buffers (nframes);
3651 boost::shared_ptr<PortInsert> p = boost::dynamic_pointer_cast<PortInsert> (*i);
3653 p->flush_buffers (nframes);
3660 Route::flush_processors ()
3662 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3664 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3670 Route::playback_latency (bool incl_downstream) const
3674 rv = _disk_reader->output_latency ();
3676 rv = _signal_latency;
3678 if (incl_downstream) {
3679 rv += _output->connected_latency (true);
3681 rv += _output->latency ();
3687 Route::latency_preroll (pframes_t nframes, samplepos_t& start_sample, samplepos_t& end_sample)
3689 samplecnt_t latency_preroll = _session.remaining_latency_preroll ();
3690 if (latency_preroll == 0) {
3693 if (!_disk_reader) {
3694 start_sample -= latency_preroll;
3695 end_sample -= latency_preroll;
3699 if (latency_preroll > playback_latency ()) {
3700 no_roll_unlocked (nframes, start_sample - latency_preroll, end_sample - latency_preroll, false);
3704 start_sample -= latency_preroll;
3705 end_sample -= latency_preroll;
3710 Route::roll (pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, int declick, bool& need_butler)
3712 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3719 silence_unlocked (nframes);
3724 if ((nframes = latency_preroll (nframes, start_sample, end_sample)) == 0) {
3728 run_route (start_sample, end_sample, nframes, declick, (!_disk_writer || !_disk_writer->record_enabled()) && _session.transport_rolling(), true);
3730 if ((_disk_reader && _disk_reader->need_butler()) || (_disk_writer && _disk_writer->need_butler())) {
3737 Route::no_roll (pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, bool session_state_changing)
3739 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3745 return no_roll_unlocked (nframes, start_sample, end_sample, session_state_changing);
3749 Route::no_roll_unlocked (pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, bool session_state_changing)
3751 /* Must be called with the processor lock held */
3754 silence_unlocked (nframes);
3759 if (session_state_changing) {
3760 if (_session.transport_speed() != 0.0f) {
3761 /* we're rolling but some state is changing (e.g. our diskstream contents)
3762 so we cannot use them. Be silent till this is over.
3764 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
3766 silence_unlocked (nframes);
3770 /* we're really not rolling, so we're either delivery silence or actually
3771 monitoring, both of which are safe to do while session_state_changing is true.
3775 run_route (start_sample, end_sample, nframes, 0, false, false);
3780 Route::silent_roll (pframes_t nframes, samplepos_t /*start_sample*/, samplepos_t /*end_sample*/, bool& /* need_butler */)
3783 flush_processor_buffers_locked (nframes);
3788 __attribute__((annotate("realtime")))
3791 Route::apply_processor_changes_rt ()
3793 int emissions = EmitNone;
3795 if (_pending_meter_point != _meter_point) {
3796 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3798 /* meters always have buffers for 'processor_max_streams'
3799 * they can be re-positioned without re-allocation */
3800 if (set_meter_point_unlocked()) {
3801 emissions |= EmitMeterChanged | EmitMeterVisibilityChange;;
3803 emissions |= EmitMeterChanged;
3808 bool changed = false;
3810 if (g_atomic_int_get (&_pending_process_reorder)) {
3811 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3813 apply_processor_order (_pending_processor_order);
3814 setup_invisible_processors ();
3816 g_atomic_int_set (&_pending_process_reorder, 0);
3817 emissions |= EmitRtProcessorChange;
3821 set_processor_positions ();
3822 /* update processor input/output latency
3823 * (total signal_latency does not change)
3825 update_signal_latency (true);
3827 if (emissions != 0) {
3828 g_atomic_int_set (&_pending_signals, emissions);
3831 return (!selfdestruct_sequence.empty ());
3835 Route::emit_pending_signals ()
3837 int sig = g_atomic_int_and (&_pending_signals, 0);
3838 if (sig & EmitMeterChanged) {
3839 _meter->emit_configuration_changed();
3840 meter_change (); /* EMIT SIGNAL */
3841 if (sig & EmitMeterVisibilityChange) {
3842 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3844 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3847 if (sig & EmitRtProcessorChange) {
3848 processors_changed (RouteProcessorChange (RouteProcessorChange::RealTimeChange)); /* EMIT SIGNAL */
3851 /* this would be a job for the butler.
3852 * Conceptually we should not take processe/processor locks here.
3853 * OTOH its more efficient (less overhead for summoning the butler and
3854 * telling her what do do) and signal emission is called
3855 * directly after the process callback, which decreases the chance
3856 * of x-runs when taking the locks.
3858 while (!selfdestruct_sequence.empty ()) {
3859 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
3860 if (selfdestruct_sequence.empty ()) { break; } // re-check with lock
3861 boost::shared_ptr<Processor> proc = selfdestruct_sequence.back ().lock ();
3862 selfdestruct_sequence.pop_back ();
3865 remove_processor (proc);
3871 Route::set_meter_point (MeterPoint p, bool force)
3873 if (_pending_meter_point == p && !force) {
3877 if (force || !AudioEngine::instance()->running()) {
3878 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3879 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3880 _pending_meter_point = p;
3881 _meter->emit_configuration_changed();
3882 meter_change (); /* EMIT SIGNAL */
3883 if (set_meter_point_unlocked()) {
3884 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3886 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3889 _pending_meter_point = p;
3895 __attribute__((annotate("realtime")))
3898 Route::set_meter_point_unlocked ()
3901 /* Caller must hold process and processor write lock */
3902 assert (!AudioEngine::instance()->process_lock().trylock());
3903 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3904 assert (!lm.locked ());
3907 _meter_point = _pending_meter_point;
3909 bool meter_was_visible_to_user = _meter->display_to_user ();
3911 if (!_custom_meter_position_noted) {
3912 maybe_note_meter_position ();
3915 if (_meter_point != MeterCustom) {
3917 _meter->set_display_to_user (false);
3919 setup_invisible_processors ();
3922 _meter->set_display_to_user (true);
3924 /* If we have a previous position for the custom meter, try to put it there */
3925 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
3927 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), after);
3928 if (i != _processors.end ()) {
3929 _processors.remove (_meter);
3930 _processors.insert (i, _meter);
3932 } else {// at end, right before the mains_out/panner
3933 _processors.remove (_meter);
3934 ProcessorList::iterator main = _processors.end();
3935 _processors.insert (--main, _meter);
3939 /* Set up the meter for its new position */
3941 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
3945 if (loc == _processors.begin()) {
3946 m_in = _input->n_ports();
3948 ProcessorList::iterator before = loc;
3950 m_in = (*before)->output_streams ();
3953 _meter->reflect_inputs (m_in);
3955 /* we do not need to reconfigure the processors, because the meter
3956 (a) is always ready to handle processor_max_streams
3957 (b) is always an N-in/N-out processor, and thus moving
3958 it doesn't require any changes to the other processors.
3961 /* these should really be done after releasing the lock
3962 * but all those signals are subscribed to with gui_thread()
3965 return (_meter->display_to_user() != meter_was_visible_to_user);
3969 Route::listen_position_changed ()
3972 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3973 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3974 ProcessorState pstate (this);
3976 if (configure_processors_unlocked (0, &lm)) {
3977 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
3979 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
3984 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3985 _session.set_dirty ();
3988 boost::shared_ptr<CapturingProcessor>
3989 Route::add_export_point()
3991 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3992 if (!_capturing_processor) {
3994 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3995 Glib::Threads::RWLock::WriterLock lw (_processor_lock);
3997 /* Align all tracks for stem-export w/o processing.
3998 * Compensate for all plugins between the this route's disk-reader
3999 * and the common final downstream output (ie alignment point for playback).
4001 _capturing_processor.reset (new CapturingProcessor (_session, playback_latency (true)));
4002 configure_processors_unlocked (0, &lw);
4003 _capturing_processor->activate ();
4006 return _capturing_processor;
4010 Route::update_signal_latency (bool apply_to_delayline)
4012 // TODO: bail out if !active() and set/assume _signal_latency = 0,
4013 // here or in Session::* ? -> also zero send latencies,
4014 // and make sure that re-enabling a route updates things again...
4016 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4018 samplecnt_t l_in = 0;
4019 samplecnt_t l_out = _output->user_latency();
4020 for (ProcessorList::reverse_iterator i = _processors.rbegin(); i != _processors.rend(); ++i) {
4021 if (boost::shared_ptr<Send> snd = boost::dynamic_pointer_cast<Send> (*i)) {
4022 snd->set_delay_in (l_out + _output->latency());
4024 (*i)->set_output_latency (l_out);
4025 if ((*i)->active ()) {
4026 l_out += (*i)->signal_latency ();
4030 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal signal latency = %2\n", _name, l_out));
4032 _signal_latency = l_out;
4034 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4035 (*i)->set_input_latency (l_in);
4036 (*i)->set_playback_offset (_signal_latency + _output->latency ());
4037 (*i)->set_capture_offset (_input->latency ());
4038 if ((*i)->active ()) {
4039 l_in += (*i)->signal_latency ();
4045 if (apply_to_delayline) {
4046 /* see also Session::post_playback_latency() */
4047 apply_latency_compensation ();
4050 if (_signal_latency != l_out) {
4051 signal_latency_changed (); /* EMIT SIGNAL */
4054 return _signal_latency;
4058 Route::set_user_latency (samplecnt_t nframes)
4060 _output->set_user_latency (nframes);
4061 _session.update_latency_compensation ();
4065 Route::apply_latency_compensation ()
4068 samplecnt_t old = _delayline->get_delay ();
4070 samplecnt_t play_lat_in = _input->connected_latency (true);
4071 samplecnt_t play_lat_out = _output->connected_latency (true);
4072 samplecnt_t latcomp = play_lat_in - play_lat_out - _signal_latency;
4075 samplecnt_t capt_lat_in = _input->connected_latency (false);
4076 samplecnt_t capt_lat_out = _output->connected_latency (false);
4077 samplecnt_t latcomp_capt = capt_lat_out - capt_lat_in - _signal_latency;
4079 cout << "ROUTE " << name() << " delay for " << latcomp << " (c: " << latcomp_capt << ")" << endl;
4082 _delayline->set_delay (latcomp > 0 ? latcomp : 0);
4084 if (old != _delayline->get_delay ()) {
4085 signal_latency_updated (); /* EMIT SIGNAL */
4091 Route::set_block_size (pframes_t nframes)
4093 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4094 (*i)->set_block_size (nframes);
4097 _session.ensure_buffers (n_process_buffers ());
4101 Route::protect_automation ()
4103 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
4104 (*i)->protect_automation();
4107 /** @param declick 1 to set a pending declick fade-in,
4108 * -1 to set a pending declick fade-out
4111 Route::set_pending_declick (int declick)
4114 /* this call is not allowed to turn off a pending declick */
4116 _pending_declick = declick;
4119 _pending_declick = 0;
4123 /** Shift automation forwards from a particular place, thereby inserting time.
4124 * Adds undo commands for any shifts that are performed.
4126 * @param pos Position to start shifting from.
4127 * @param samples Amount to shift forwards by.
4131 Route::shift (samplepos_t pos, samplecnt_t samples)
4133 /* gain automation */
4135 boost::shared_ptr<AutomationControl> gc = _amp->gain_control();
4137 XMLNode &before = gc->alist()->get_state ();
4138 gc->alist()->shift (pos, samples);
4139 XMLNode &after = gc->alist()->get_state ();
4140 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
4143 /* gain automation */
4145 boost::shared_ptr<AutomationControl> gc = _trim->gain_control();
4147 XMLNode &before = gc->alist()->get_state ();
4148 gc->alist()->shift (pos, samples);
4149 XMLNode &after = gc->alist()->get_state ();
4150 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
4153 // TODO mute automation ??
4155 /* pan automation */
4157 ControlSet::Controls& c (_pannable->controls());
4159 for (ControlSet::Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
4160 boost::shared_ptr<AutomationControl> pc = boost::dynamic_pointer_cast<AutomationControl> (ci->second);
4162 boost::shared_ptr<AutomationList> al = pc->alist();
4163 XMLNode& before = al->get_state ();
4164 al->shift (pos, samples);
4165 XMLNode& after = al->get_state ();
4166 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4171 /* redirect automation */
4173 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4174 for (ProcessorList::iterator i = _processors.begin (); i != _processors.end (); ++i) {
4176 set<Evoral::Parameter> parameters = (*i)->what_can_be_automated();
4178 for (set<Evoral::Parameter>::const_iterator p = parameters.begin (); p != parameters.end (); ++p) {
4179 boost::shared_ptr<AutomationControl> ac = (*i)->automation_control (*p);
4181 boost::shared_ptr<AutomationList> al = ac->alist();
4182 XMLNode &before = al->get_state ();
4183 al->shift (pos, samples);
4184 XMLNode &after = al->get_state ();
4185 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4193 Route::set_plugin_state_dir (boost::weak_ptr<Processor> p, const std::string& d)
4195 boost::shared_ptr<Processor> processor (p.lock ());
4196 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
4200 pi->set_state_dir (d);
4204 Route::save_as_template (const string& path, const string& name, const string& description)
4206 std::string state_dir = path.substr (0, path.find_last_of ('.')); // strip template_suffix
4207 PBD::Unwinder<std::string> uw (_session._template_state_dir, state_dir);
4209 XMLNode& node (state (false));
4210 node.set_property (X_("name"), name);
4212 node.remove_nodes (X_("description"));
4213 if (!description.empty()) {
4214 XMLNode* desc = new XMLNode(X_("description"));
4215 XMLNode* desc_cont = new XMLNode(X_("content"), description);
4216 desc->add_child_nocopy (*desc_cont);
4218 node.add_child_nocopy (*desc);
4223 IO::set_name_in_state (*node.children().front(), name);
4225 tree.set_root (&node);
4227 /* return zero on success, non-zero otherwise */
4228 return !tree.write (path.c_str());
4233 Route::set_name (const string& str)
4239 if (str == name()) {
4243 string name = Route::ensure_track_or_route_name (str, _session);
4244 SessionObject::set_name (name);
4246 bool ret = (_input->set_name(name) && _output->set_name(name));
4249 /* rename the main outs. Leave other IO processors
4250 * with whatever name they already have, because its
4251 * just fine as it is (it will not contain the route
4252 * name if its a port insert, port send or port return).
4256 if (_main_outs->set_name (name)) {
4257 /* XXX returning false here is stupid because
4258 we already changed the route name.
4268 /** Set the name of a route in an XML description.
4269 * @param node XML <Route> node to set the name in.
4270 * @param name New name.
4273 Route::set_name_in_state (XMLNode& node, string const & name, bool rename_playlist)
4275 node.set_property (X_("name"), name);
4277 XMLNodeList children = node.children();
4278 for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
4280 if ((*i)->name() == X_("IO")) {
4282 IO::set_name_in_state (**i, name);
4284 } else if ((*i)->name() == X_("Processor")) {
4287 if ((*i)->get_property (X_("role"), str) && str == X_("Main")) {
4288 (*i)->set_property (X_("name"), name);
4291 } else if ((*i)->name() == X_("Diskstream")) {
4293 if (rename_playlist) {
4294 (*i)->set_property (X_("playlist"), name + ".1");
4296 (*i)->set_property (X_("name"), name);
4302 boost::shared_ptr<Send>
4303 Route::internal_send_for (boost::shared_ptr<const Route> target) const
4305 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4307 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4308 boost::shared_ptr<InternalSend> send;
4310 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
4311 if (send->target_route() == target) {
4317 return boost::shared_ptr<Send>();
4321 Route::set_denormal_protection (bool yn)
4323 if (_denormal_protection != yn) {
4324 _denormal_protection = yn;
4325 denormal_protection_changed (); /* EMIT SIGNAL */
4330 Route::denormal_protection () const
4332 return _denormal_protection;
4336 Route::set_active (bool yn, void* src)
4338 if (_session.transport_rolling()) {
4342 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_route_active()) {
4343 _route_group->foreach_route (boost::bind (&Route::set_active, _1, yn, _route_group));
4347 if (_active != yn) {
4349 _input->set_active (yn);
4350 _output->set_active (yn);
4351 flush_processors ();
4352 active_changed (); // EMIT SIGNAL
4353 _session.set_dirty ();
4357 boost::shared_ptr<Pannable>
4358 Route::pannable() const
4363 boost::shared_ptr<Panner>
4364 Route::panner() const
4367 return _main_outs->panner_shell()->panner();
4370 boost::shared_ptr<PannerShell>
4371 Route::panner_shell() const
4373 return _main_outs->panner_shell();
4376 boost::shared_ptr<GainControl>
4377 Route::gain_control() const
4379 return _gain_control;
4382 boost::shared_ptr<GainControl>
4383 Route::trim_control() const
4385 return _trim_control;
4388 boost::shared_ptr<PhaseControl>
4389 Route::phase_control() const
4391 return _phase_control;
4394 boost::shared_ptr<AutomationControl>
4395 Route::get_control (const Evoral::Parameter& param)
4397 /* either we own the control or .... */
4399 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
4403 /* maybe one of our processors does or ... */
4405 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
4406 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4407 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
4415 /* nobody does so we'll make a new one */
4417 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
4424 boost::shared_ptr<Processor>
4425 Route::nth_plugin (uint32_t n) const
4427 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4428 ProcessorList::const_iterator i;
4430 for (i = _processors.begin(); i != _processors.end(); ++i) {
4431 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
4438 return boost::shared_ptr<Processor> ();
4441 boost::shared_ptr<Processor>
4442 Route::nth_send (uint32_t n) const
4444 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4445 ProcessorList::const_iterator i;
4447 for (i = _processors.begin(); i != _processors.end(); ++i) {
4448 if (boost::dynamic_pointer_cast<Send> (*i)) {
4450 if ((*i)->name().find (_("Monitor")) == 0) {
4451 /* send to monitor section is not considered
4452 to be an accessible send.
4463 return boost::shared_ptr<Processor> ();
4467 Route::has_io_processor_named (const string& name)
4469 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4470 ProcessorList::iterator i;
4472 for (i = _processors.begin(); i != _processors.end(); ++i) {
4473 if (boost::dynamic_pointer_cast<Send> (*i) ||
4474 boost::dynamic_pointer_cast<PortInsert> (*i)) {
4475 if ((*i)->name() == name) {
4485 Route::set_processor_positions ()
4487 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4489 bool had_amp = false;
4490 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4491 (*i)->set_pre_fader (!had_amp);
4498 /** Called when there is a proposed change to the input port count */
4500 Route::input_port_count_changing (ChanCount to)
4502 list<pair<ChanCount, ChanCount> > c = try_configure_processors (to, 0);
4504 /* The processors cannot be configured with the new input arrangement, so
4510 /* The change is ok */
4514 /** Called when there is a proposed change to the output port count */
4516 Route::output_port_count_changing (ChanCount to)
4518 if (_strict_io && !_in_configure_processors) {
4521 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
4522 if (processor_out_streams.get(*t) > to.get(*t)) {
4526 /* The change is ok */
4531 Route::unknown_processors () const
4535 if (_session.get_disable_all_loaded_plugins ()) {
4536 // Do not list "missing plugins" if they are explicitly disabled
4540 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4541 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4542 if (boost::dynamic_pointer_cast<UnknownProcessor const> (*i)) {
4543 p.push_back ((*i)->name ());
4552 Route::update_port_latencies (PortSet& from, PortSet& to, bool playback, samplecnt_t our_latency) const
4554 /* we assume that all our input ports feed all our output ports. its not
4555 universally true, but the alternative is way too corner-case to worry about.
4558 LatencyRange all_connections;
4561 all_connections.min = 0;
4562 all_connections.max = 0;
4564 all_connections.min = ~((pframes_t) 0);
4565 all_connections.max = 0;
4567 /* iterate over all "from" ports and determine the latency range for all of their
4568 connections to the "outside" (outside of this Route).
4571 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4575 p->get_connected_latency_range (range, playback);
4577 all_connections.min = min (all_connections.min, range.min);
4578 all_connections.max = max (all_connections.max, range.max);
4582 /* set the "from" port latencies to the max/min range of all their connections */
4584 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4585 p->set_private_latency_range (all_connections, playback);
4588 /* set the ports "in the direction of the flow" to the same value as above plus our own signal latency */
4590 all_connections.min += our_latency;
4591 all_connections.max += our_latency;
4593 for (PortSet::iterator p = to.begin(); p != to.end(); ++p) {
4594 p->set_private_latency_range (all_connections, playback);
4597 return all_connections.max;
4601 Route::set_private_port_latencies (bool playback) const
4603 samplecnt_t own_latency = 0;
4605 /* Processor list not protected by lock: MUST BE CALLED FROM PROCESS THREAD
4606 OR LATENCY CALLBACK.
4608 This is called (early) from the latency callback. It computes the REAL
4609 latency associated with each port and stores the result as the "private"
4610 latency of the port. A later call to Route::set_public_port_latencies()
4611 sets all ports to the same value to reflect the fact that we do latency
4612 compensation and so all signals are delayed by the same amount as they
4613 flow through ardour.
4616 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4617 if ((*i)->active ()) {
4618 own_latency += (*i)->signal_latency ();
4623 /* playback: propagate latency from "outside the route" to outputs to inputs */
4624 return update_port_latencies (_output->ports (), _input->ports (), true, own_latency);
4626 /* capture: propagate latency from "outside the route" to inputs to outputs */
4627 return update_port_latencies (_input->ports (), _output->ports (), false, own_latency);
4632 Route::set_public_port_latencies (samplecnt_t value, bool playback) const
4634 /* this is called to set the JACK-visible port latencies, which take
4635 latency compensation into account.
4644 const PortSet& ports (_input->ports());
4645 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4646 p->set_public_latency_range (range, playback);
4651 const PortSet& ports (_output->ports());
4652 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4653 p->set_public_latency_range (range, playback);
4658 /** Put the invisible processors in the right place in _processors.
4659 * Must be called with a writer lock on _processor_lock held.
4662 __attribute__((annotate("realtime")))
4665 Route::setup_invisible_processors ()
4668 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4669 assert (!lm.locked ());
4673 /* too early to be doing this stuff */
4677 /* we'll build this new list here and then use it
4679 * TODO put the ProcessorList is on the stack for RT-safety.
4682 ProcessorList new_processors;
4683 ProcessorList::iterator dr;
4684 ProcessorList::iterator dw;
4686 /* find visible processors */
4688 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4689 if ((*i)->display_to_user ()) {
4690 new_processors.push_back (*i);
4696 ProcessorList::iterator amp = find (new_processors.begin(), new_processors.end(), _amp);
4698 if (amp == new_processors.end ()) {
4699 error << string_compose (_("Amp/Fader on Route '%1' went AWOL. Re-added."), name()) << endmsg;
4700 new_processors.push_front (_amp);
4701 amp = find (new_processors.begin(), new_processors.end(), _amp);
4704 /* and the processor after the amp */
4706 ProcessorList::iterator after_amp = amp;
4709 /* Pre-fader METER */
4711 if (_meter && _meter_point == MeterPreFader) {
4712 /* add meter just before the fader */
4713 assert (!_meter->display_to_user ());
4714 new_processors.insert (amp, _meter);
4719 assert (_main_outs);
4720 assert (!_main_outs->display_to_user ());
4721 new_processors.push_back (_main_outs);
4723 /* iterator for the main outs */
4725 ProcessorList::iterator main = new_processors.end();
4728 /* OUTPUT METERING */
4730 if (_meter && (_meter_point == MeterOutput || _meter_point == MeterPostFader)) {
4731 assert (!_meter->display_to_user ());
4733 /* add the processor just before or just after the main outs */
4735 ProcessorList::iterator meter_point = main;
4737 if (_meter_point == MeterOutput) {
4740 new_processors.insert (meter_point, _meter);
4745 if (_monitor_send && !is_monitor ()) {
4746 assert (!_monitor_send->display_to_user ());
4747 switch (Config->get_listen_position ()) {
4748 case PreFaderListen:
4749 switch (Config->get_pfl_position ()) {
4750 case PFLFromBeforeProcessors:
4751 new_processors.push_front (_monitor_send);
4753 case PFLFromAfterProcessors:
4754 new_processors.insert (amp, _monitor_send);
4757 _monitor_send->set_can_pan (false);
4759 case AfterFaderListen:
4760 switch (Config->get_afl_position ()) {
4761 case AFLFromBeforeProcessors:
4762 new_processors.insert (after_amp, _monitor_send);
4764 case AFLFromAfterProcessors:
4765 new_processors.insert (new_processors.end(), _monitor_send);
4768 _monitor_send->set_can_pan (true);
4773 /* MONITOR CONTROL */
4775 if (_monitor_control && is_monitor ()) {
4776 assert (!_monitor_control->display_to_user ());
4777 new_processors.insert (amp, _monitor_control);
4782 ProcessorList::iterator trim = new_processors.end();
4784 if (_trim->active()) {
4785 assert (!_trim->display_to_user ());
4786 new_processors.push_front (_trim);
4787 trim = new_processors.begin();
4790 /* INTERNAL RETURN */
4792 /* doing this here means that any monitor control will come after
4793 the return and trim.
4797 assert (!_intreturn->display_to_user ());
4798 new_processors.push_front (_intreturn);
4801 /* DISK READER & WRITER (for Track objects) */
4803 if (_disk_reader || _disk_writer) {
4804 switch (_disk_io_point) {
4805 case DiskIOPreFader:
4806 if (trim != new_processors.end()) {
4807 /* insert BEFORE TRIM */
4809 new_processors.insert (trim, _disk_writer);
4812 new_processors.insert (trim, _disk_reader);
4816 new_processors.push_front (_disk_writer);
4819 new_processors.push_front (_disk_reader);
4823 case DiskIOPostFader:
4824 /* insert BEFORE main outs */
4826 new_processors.insert (main, _disk_writer);
4829 new_processors.insert (main, _disk_reader);
4833 /* reader and writer are visible under this condition, so they
4834 * are not invisible and thus not handled here.
4840 /* ensure dist-writer is before disk-reader */
4841 if (_disk_reader && _disk_writer) {
4842 ProcessorList::iterator reader_pos = find (new_processors.begin(), new_processors.end(), _disk_reader);
4843 ProcessorList::iterator writer_pos = find (new_processors.begin(), new_processors.end(), _disk_writer);
4844 assert (reader_pos != new_processors.end ());
4845 assert (writer_pos != new_processors.end ());
4846 if (std::distance (new_processors.begin(), reader_pos) < std::distance (new_processors.begin(), writer_pos)) {
4847 new_processors.erase (reader_pos);
4848 assert (writer_pos == find (new_processors.begin(), new_processors.end(), _disk_writer));
4849 new_processors.insert (++writer_pos, _disk_reader);
4854 /* EXPORT PROCESSOR */
4855 if (_capturing_processor) {
4856 assert (!_capturing_processor->display_to_user ());
4857 ProcessorList::iterator reader_pos = find (new_processors.begin(), new_processors.end(), _disk_reader);
4858 if (reader_pos != new_processors.end()) {
4859 /* insert after disk-reader */
4860 new_processors.insert (++reader_pos, _capturing_processor);
4862 new_processors.push_front (_capturing_processor);
4867 if (_meter && _meter_point == MeterInput) {
4868 /* add meter just before the disk-writer (if any)
4869 * otherwise at the top, but after the latency delayline
4870 * (perhaps it should also be after intreturn on busses ??)
4872 assert (!_meter->display_to_user ());
4873 ProcessorList::iterator writer_pos = find (new_processors.begin(), new_processors.end(), _disk_writer);
4874 if (writer_pos != new_processors.end()) {
4875 new_processors.insert (writer_pos, _meter);
4877 new_processors.push_front (_meter);
4881 if (!is_master() && !is_monitor() && !is_auditioner()) {
4882 ProcessorList::iterator reader_pos = find (new_processors.begin(), new_processors.end(), _disk_reader);
4883 if (reader_pos != new_processors.end()) {
4884 /* insert before disk-reader */
4885 new_processors.insert (reader_pos, _delayline);
4887 new_processors.push_front (_delayline);
4891 _processors = new_processors;
4893 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4894 if (!(*i)->display_to_user () && !(*i)->enabled () && (*i) != _monitor_send) {
4895 (*i)->enable (true);
4899 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: setup_invisible_processors\n", _name));
4900 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4901 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1\n", (*i)->name ()));
4908 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
4909 Glib::Threads::RWLock::ReaderLock lp (_processor_lock);
4913 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4914 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*i);
4921 /** If the meter point is `Custom', make a note of where the meter is.
4922 * This is so that if the meter point is subsequently set to something else,
4923 * and then back to custom, we can put the meter back where it was last time
4924 * custom was enabled.
4926 * Must be called with the _processor_lock held.
4929 Route::maybe_note_meter_position ()
4931 if (_meter_point != MeterCustom) {
4935 _custom_meter_position_noted = true;
4936 /* custom meter points range from after trim to before panner/main_outs
4937 * this is a limitation by the current processor UI
4939 bool seen_trim = false;
4940 _processor_after_last_custom_meter.reset();
4941 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4942 if ((*i) == _trim) {
4945 if ((*i) == _main_outs) {
4946 _processor_after_last_custom_meter = *i;
4949 if (boost::dynamic_pointer_cast<PeakMeter> (*i)) {
4951 _processor_after_last_custom_meter = _trim;
4953 ProcessorList::iterator j = i;
4955 assert(j != _processors.end ()); // main_outs should be before
4956 _processor_after_last_custom_meter = *j;
4961 assert(_processor_after_last_custom_meter.lock());
4964 boost::shared_ptr<Processor>
4965 Route::processor_by_id (PBD::ID id) const
4967 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4968 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4969 if ((*i)->id() == id) {
4974 return boost::shared_ptr<Processor> ();
4977 /** @return what we should be metering; either the data coming from the input
4978 * IO or the data that is flowing through the route.
4981 Route::metering_state () const
4983 return MeteringRoute;
4987 Route::has_external_redirects () const
4989 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4991 /* ignore inactive processors and obviously ignore the main
4992 * outs since everything has them and we don't care.
4995 if ((*i)->active() && (*i) != _main_outs && (*i)->does_routing()) {
5003 boost::shared_ptr<Processor>
5004 Route::the_instrument () const
5006 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5007 return the_instrument_unlocked ();
5010 boost::shared_ptr<Processor>
5011 Route::the_instrument_unlocked () const
5013 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5014 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
5015 if (pi && pi->plugin ()->get_info ()->is_instrument ()) {
5019 return boost::shared_ptr<Processor>();
5025 Route::non_realtime_locate (samplepos_t pos)
5027 Automatable::non_realtime_locate (pos);
5030 _pannable->non_realtime_locate (pos);
5033 #if 0 // XXX mayhaps clear delayline here (and at stop?)
5035 _delayline->flush ();
5040 //Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
5041 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5043 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5044 (*i)->non_realtime_locate (pos);
5050 Route::fill_buffers_with_input (BufferSet& bufs, boost::shared_ptr<IO> io, pframes_t nframes)
5057 * We don't currently mix MIDI input together, so we don't need the
5058 * complex logic of the audio case.
5061 n_buffers = bufs.count().n_midi ();
5063 for (i = 0; i < n_buffers; ++i) {
5065 boost::shared_ptr<MidiPort> source_port = io->midi (i);
5066 MidiBuffer& buf (bufs.get_midi (i));
5069 buf.copy (source_port->get_midi_buffer(nframes));
5071 buf.silence (nframes);
5077 n_buffers = bufs.count().n_audio();
5079 size_t n_ports = io->n_ports().n_audio();
5080 float scaling = 1.0f;
5082 if (n_ports > n_buffers) {
5083 scaling = ((float) n_buffers) / n_ports;
5086 for (i = 0; i < n_ports; ++i) {
5088 /* if there are more ports than buffers, map them onto buffers
5089 * in a round-robin fashion
5092 boost::shared_ptr<AudioPort> source_port = io->audio (i);
5093 AudioBuffer& buf (bufs.get_audio (i%n_buffers));
5095 if (i < n_buffers) {
5097 /* first time through just copy a channel into
5101 buf.read_from (source_port->get_audio_buffer (nframes), nframes);
5103 if (scaling != 1.0f) {
5104 buf.apply_gain (scaling, nframes);
5109 /* on subsequent times around, merge data from
5110 * the port with what is already there
5113 if (scaling != 1.0f) {
5114 buf.accumulate_with_gain_from (source_port->get_audio_buffer (nframes), nframes, 0, scaling);
5116 buf.accumulate_from (source_port->get_audio_buffer (nframes), nframes);
5121 /* silence any remaining buffers */
5123 for (; i < n_buffers; ++i) {
5124 AudioBuffer& buf (bufs.get_audio (i));
5125 buf.silence (nframes);
5128 /* establish the initial setup of the buffer set, reflecting what was
5129 copied into it. unless, of course, we are the auditioner, in which
5130 case nothing was fed into it from the inputs at all.
5133 if (!is_auditioner()) {
5134 bufs.set_count (io->n_ports());
5138 boost::shared_ptr<AutomationControl>
5139 Route::pan_azimuth_control() const
5142 # undef MIXBUS_PORTS_H
5143 # include "../../gtk2_ardour/mixbus_ports.h"
5144 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5146 return boost::shared_ptr<AutomationControl>();
5148 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_pan)));
5150 if (!_pannable || !panner()) {
5151 return boost::shared_ptr<AutomationControl>();
5153 return _pannable->pan_azimuth_control;
5157 boost::shared_ptr<AutomationControl>
5158 Route::pan_elevation_control() const
5160 if (Profile->get_mixbus() || !_pannable || !panner()) {
5161 return boost::shared_ptr<AutomationControl>();
5164 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5166 if (c.find (PanElevationAutomation) != c.end()) {
5167 return _pannable->pan_elevation_control;
5169 return boost::shared_ptr<AutomationControl>();
5172 boost::shared_ptr<AutomationControl>
5173 Route::pan_width_control() const
5176 if (mixbus() && _ch_pre) {
5178 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl>(_ch_pre->control(Evoral::Parameter(PluginAutomation, 0, 5)));
5181 if (Profile->get_mixbus() || !_pannable || !panner()) {
5182 return boost::shared_ptr<AutomationControl>();
5185 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5187 if (c.find (PanWidthAutomation) != c.end()) {
5188 return _pannable->pan_width_control;
5190 return boost::shared_ptr<AutomationControl>();
5193 boost::shared_ptr<AutomationControl>
5194 Route::pan_frontback_control() const
5196 if (Profile->get_mixbus() || !_pannable || !panner()) {
5197 return boost::shared_ptr<AutomationControl>();
5200 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5202 if (c.find (PanFrontBackAutomation) != c.end()) {
5203 return _pannable->pan_frontback_control;
5205 return boost::shared_ptr<AutomationControl>();
5208 boost::shared_ptr<AutomationControl>
5209 Route::pan_lfe_control() const
5211 if (Profile->get_mixbus() || !_pannable || !panner()) {
5212 return boost::shared_ptr<AutomationControl>();
5215 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5217 if (c.find (PanLFEAutomation) != c.end()) {
5218 return _pannable->pan_lfe_control;
5220 return boost::shared_ptr<AutomationControl>();
5225 Route::eq_band_cnt () const
5227 if (Profile->get_mixbus()) {
5229 if (is_master() || mixbus()) {
5238 /* Ardour has no well-known EQ object */
5243 boost::shared_ptr<AutomationControl>
5244 Route::eq_gain_controllable (uint32_t band) const
5247 boost::shared_ptr<PluginInsert> eq = ch_eq();
5250 return boost::shared_ptr<AutomationControl>();
5253 uint32_t port_number;
5254 if (is_master() || mixbus()) {
5256 case 0: port_number = 4; break;
5257 case 1: port_number = 3; break;
5258 case 2: port_number = 2; break;
5260 return boost::shared_ptr<AutomationControl>();
5265 case 0: port_number = 14; break;
5266 case 1: port_number = 12; break;
5267 case 2: port_number = 10; break;
5268 case 3: port_number = 8; break;
5270 return boost::shared_ptr<AutomationControl>();
5274 case 0: port_number = 8; break;
5275 case 1: port_number = 6; break;
5276 case 2: port_number = 4; break;
5278 return boost::shared_ptr<AutomationControl>();
5283 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5285 return boost::shared_ptr<AutomationControl>();
5288 boost::shared_ptr<AutomationControl>
5289 Route::eq_freq_controllable (uint32_t band) const
5292 if (mixbus() || is_master()) {
5293 /* no frequency controls for mixbusses or master */
5294 return boost::shared_ptr<AutomationControl>();
5297 boost::shared_ptr<PluginInsert> eq = ch_eq();
5300 return boost::shared_ptr<AutomationControl>();
5303 uint32_t port_number;
5306 case 0: port_number = 13; break; // lo
5307 case 1: port_number = 11; break; // lo mid
5308 case 2: port_number = 9; break; // hi mid
5309 case 3: port_number = 7; break; // hi
5311 return boost::shared_ptr<AutomationControl>();
5315 case 0: port_number = 7; break;
5316 case 1: port_number = 5; break;
5317 case 2: port_number = 3; break;
5319 return boost::shared_ptr<AutomationControl>();
5323 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5325 return boost::shared_ptr<AutomationControl>();
5329 boost::shared_ptr<AutomationControl>
5330 Route::eq_q_controllable (uint32_t band) const
5332 return boost::shared_ptr<AutomationControl>();
5335 boost::shared_ptr<AutomationControl>
5336 Route::eq_shape_controllable (uint32_t band) const
5339 boost::shared_ptr<PluginInsert> eq = ch_eq();
5340 if (is_master() || mixbus() || !eq) {
5341 return boost::shared_ptr<AutomationControl>();
5345 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4))); // lo bell
5348 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3))); // hi bell
5354 return boost::shared_ptr<AutomationControl>();
5357 boost::shared_ptr<AutomationControl>
5358 Route::eq_enable_controllable () const
5361 boost::shared_ptr<PluginInsert> eq = ch_eq();
5364 return boost::shared_ptr<AutomationControl>();
5367 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5369 return boost::shared_ptr<AutomationControl>();
5373 boost::shared_ptr<AutomationControl>
5374 Route::filter_freq_controllable (bool hpf) const
5377 boost::shared_ptr<PluginInsert> eq = ch_eq();
5379 if (is_master() || mixbus() || !eq) {
5380 return boost::shared_ptr<AutomationControl>();
5384 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5))); // HPF freq
5386 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5390 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 6))); // LPF freq
5392 return boost::shared_ptr<AutomationControl>();
5397 return boost::shared_ptr<AutomationControl>();
5401 boost::shared_ptr<AutomationControl>
5402 Route::filter_slope_controllable (bool) const
5404 return boost::shared_ptr<AutomationControl>();
5407 boost::shared_ptr<AutomationControl>
5408 Route::filter_enable_controllable (bool) const
5411 boost::shared_ptr<PluginInsert> eq = ch_eq();
5413 if (is_master() || mixbus() || !eq) {
5414 return boost::shared_ptr<AutomationControl>();
5417 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5419 return boost::shared_ptr<AutomationControl>();
5423 boost::shared_ptr<AutomationControl>
5424 Route::tape_drive_controllable () const
5428 if ( _ch_pre && (is_master() || mixbus()) ) {
5429 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (_ch_pre->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4)));
5433 return boost::shared_ptr<AutomationControl>();
5437 Route::eq_band_name (uint32_t band) const
5440 if (is_master() || mixbus()) {
5442 if (Profile->get_mixbus()) {
5444 case 0: return _("lo");
5445 case 1: return _("mid");
5446 case 2: return _("hi");
5447 default: return string();
5455 case 0: return _("lo");
5456 case 1: return _("lo mid");
5457 case 2: return _("hi mid");
5458 case 3: return _("hi");
5459 default: return string();
5465 boost::shared_ptr<AutomationControl>
5466 Route::comp_enable_controllable () const
5469 boost::shared_ptr<PluginInsert> comp = ch_comp();
5472 return boost::shared_ptr<AutomationControl>();
5475 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5477 return boost::shared_ptr<AutomationControl>();
5480 boost::shared_ptr<AutomationControl>
5481 Route::comp_threshold_controllable () const
5484 boost::shared_ptr<PluginInsert> comp = ch_comp();
5487 return boost::shared_ptr<AutomationControl>();
5490 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5493 return boost::shared_ptr<AutomationControl>();
5496 boost::shared_ptr<AutomationControl>
5497 Route::comp_speed_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, 3)));
5508 return boost::shared_ptr<AutomationControl>();
5511 boost::shared_ptr<AutomationControl>
5512 Route::comp_mode_controllable () const
5515 boost::shared_ptr<PluginInsert> comp = ch_comp();
5518 return boost::shared_ptr<AutomationControl>();
5521 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4)));
5523 return boost::shared_ptr<AutomationControl>();
5526 boost::shared_ptr<AutomationControl>
5527 Route::comp_makeup_controllable () const
5530 boost::shared_ptr<PluginInsert> comp = ch_comp();
5533 return boost::shared_ptr<AutomationControl>();
5536 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5)));
5538 return boost::shared_ptr<AutomationControl>();
5541 boost::shared_ptr<ReadOnlyControl>
5542 Route::comp_redux_controllable () const
5545 boost::shared_ptr<PluginInsert> comp = ch_comp();
5548 return boost::shared_ptr<ReadOnlyControl>();
5551 return comp->control_output (2);
5553 return comp->control_output (6);
5557 return boost::shared_ptr<ReadOnlyControl>();
5562 Route::comp_mode_name (uint32_t mode) const
5567 return _("Leveler");
5569 return _("Compressor");
5571 return _("Limiter");
5573 return mixbus() ? _("Sidechain") : _("Limiter");
5583 Route::comp_speed_name (uint32_t mode) const
5601 boost::shared_ptr<AutomationControl>
5602 Route::send_pan_azi_controllable (uint32_t n) const
5605 # undef MIXBUS_PORTS_H
5606 # include "../../gtk2_ardour/mixbus_ports.h"
5607 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5608 if (plug && !mixbus()) {
5609 uint32_t port_id = 0;
5612 case 0: port_id = port_channel_post_aux0_pan; break; //32c mb "pan" controls use zero-based names, unlike levels. ugh
5613 case 1: port_id = port_channel_post_aux1_pan; break;
5614 case 2: port_id = port_channel_post_aux2_pan; break;
5615 case 3: port_id = port_channel_post_aux3_pan; break;
5616 case 4: port_id = port_channel_post_aux4_pan; break;
5617 case 5: port_id = port_channel_post_aux5_pan; break;
5618 case 6: port_id = port_channel_post_aux6_pan; break;
5619 case 7: port_id = port_channel_post_aux7_pan; break;
5620 case 8: port_id = port_channel_post_aux8_pan; break;
5621 case 9: port_id = port_channel_post_aux9_pan; break;
5622 case 10: port_id = port_channel_post_aux10_pan; break;
5623 case 11: port_id = port_channel_post_aux11_pan; break;
5630 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5635 return boost::shared_ptr<AutomationControl>();
5638 boost::shared_ptr<AutomationControl>
5639 Route::send_level_controllable (uint32_t n) const
5642 # undef MIXBUS_PORTS_H
5643 # include "../../gtk2_ardour/mixbus_ports.h"
5644 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5645 if (plug && !mixbus()) {
5646 uint32_t port_id = 0;
5648 case 0: port_id = port_channel_post_aux1_level; break;
5649 case 1: port_id = port_channel_post_aux2_level; break;
5650 case 2: port_id = port_channel_post_aux3_level; break;
5651 case 3: port_id = port_channel_post_aux4_level; break;
5652 case 4: port_id = port_channel_post_aux5_level; break;
5653 case 5: port_id = port_channel_post_aux6_level; break;
5654 case 6: port_id = port_channel_post_aux7_level; break;
5655 case 7: port_id = port_channel_post_aux8_level; break;
5657 case 8: port_id = port_channel_post_aux9_level; break;
5658 case 9: port_id = port_channel_post_aux10_level; break;
5659 case 10: port_id = port_channel_post_aux11_level; break;
5660 case 11: port_id = port_channel_post_aux12_level; break;
5667 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5678 boost::shared_ptr<Send> s = boost::dynamic_pointer_cast<Send>(nth_send (n));
5680 return boost::shared_ptr<AutomationControl>();
5682 return s->gain_control ();
5685 boost::shared_ptr<AutomationControl>
5686 Route::send_enable_controllable (uint32_t n) const
5689 # undef MIXBUS_PORTS_H
5690 # include "../../gtk2_ardour/mixbus_ports.h"
5691 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5692 if (plug && !mixbus()) {
5693 uint32_t port_id = 0;
5695 case 0: port_id = port_channel_post_aux1_asgn; break;
5696 case 1: port_id = port_channel_post_aux2_asgn; break;
5697 case 2: port_id = port_channel_post_aux3_asgn; break;
5698 case 3: port_id = port_channel_post_aux4_asgn; break;
5699 case 4: port_id = port_channel_post_aux5_asgn; break;
5700 case 5: port_id = port_channel_post_aux6_asgn; break;
5701 case 6: port_id = port_channel_post_aux7_asgn; break;
5702 case 7: port_id = port_channel_post_aux8_asgn; break;
5704 case 8: port_id = port_channel_post_aux9_asgn; break;
5705 case 9: port_id = port_channel_post_aux10_asgn; break;
5706 case 10: port_id = port_channel_post_aux11_asgn; break;
5707 case 11: port_id = port_channel_post_aux12_asgn; break;
5714 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5725 /* although Ardour sends have enable/disable as part of the Processor
5726 * API, it is not exposed as a controllable.
5728 * XXX: we should fix this (make it click-free, automatable enable-control)
5730 return boost::shared_ptr<AutomationControl>();
5734 Route::send_name (uint32_t n) const
5737 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5738 if (plug && !mixbus()) {
5741 return _session.get_mixbus (n)->name();
5746 return _session.get_mixbus (n)->name();
5752 boost::shared_ptr<Processor> p = nth_send (n);
5760 boost::shared_ptr<AutomationControl>
5761 Route::master_send_enable_controllable () const
5764 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5766 return boost::shared_ptr<AutomationControl>();
5768 # undef MIXBUS_PORTS_H
5769 # include "../../gtk2_ardour/mixbus_ports.h"
5770 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_mstr_assign)));
5772 return boost::shared_ptr<AutomationControl>();
5777 Route::slaved () const
5779 if (!_gain_control) {
5782 /* just test one particular control, not all of them */
5783 return _gain_control->slaved ();
5787 Route::slaved_to (boost::shared_ptr<VCA> vca) const
5789 if (!vca || !_gain_control) {
5793 /* just test one particular control, not all of them */
5795 return _gain_control->slaved_to (vca->gain_control());
5799 Route::muted_by_others_soloing () const
5801 if (!can_be_muted_by_others ()) {
5805 return _session.soloing() && !_solo_control->soloed() && !_solo_isolate_control->solo_isolated();
5809 Route::clear_all_solo_state ()
5811 _solo_control->clear_all_solo_state ();
5814 boost::shared_ptr<AutomationControl>
5815 Route::automation_control_recurse (PBD::ID const & id) const
5817 boost::shared_ptr<AutomationControl> ac = Automatable::automation_control (id);
5823 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5825 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5826 if ((ac = (*i)->automation_control (id))) {
5831 return boost::shared_ptr<AutomationControl> ();
5835 Route::slavables () const
5837 SlavableControlList rv;
5838 rv.push_back (_gain_control);
5839 rv.push_back (_mute_control);
5840 rv.push_back (_solo_control);
5845 Route::set_disk_io_point (DiskIOPoint diop)
5847 bool display = false;
5849 cerr << "set disk io to " << enum_2_string (diop) << endl;
5860 _disk_writer->set_display_to_user (display);
5864 _disk_reader->set_display_to_user (display);
5867 const bool changed = (diop != _disk_io_point);
5869 _disk_io_point = diop;
5872 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
5873 configure_processors (0);
5876 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
5879 #ifdef USE_TRACKS_CODE_FEATURES
5881 /* This is the Tracks version of Track::monitoring_state().
5883 * Ardour developers: try to flag or fix issues if parts of the libardour API
5884 * change in ways that invalidate this
5888 Route::monitoring_state () const
5890 /* Explicit requests */
5892 if (_monitoring != MonitorInput) {
5893 return MonitoringInput;
5896 if (_monitoring & MonitorDisk) {
5897 return MonitoringDisk;
5900 /* This is an implementation of the truth table in doc/monitor_modes.pdf;
5901 I don't think it's ever going to be too pretty too look at.
5904 // GZ: NOT USED IN TRACKS
5905 //bool const auto_input = _session.config.get_auto_input ();
5906 //bool const software_monitor = Config->get_monitoring_model() == SoftwareMonitoring;
5907 //bool const tape_machine_mode = Config->get_tape_machine_mode ();
5909 bool const roll = _session.transport_rolling ();
5910 bool const track_rec = _diskstream->record_enabled ();
5911 bool session_rec = _session.actively_recording ();
5915 if (!session_rec && roll) {
5916 return MonitoringDisk;
5918 return MonitoringInput;
5924 return MonitoringDisk;
5928 return MonitoringSilence;
5933 /* This is the Ardour/Mixbus version of Track::monitoring_state().
5935 * Tracks developers: do NOT modify this method under any circumstances.
5939 Route::monitoring_state () const
5941 if (!_disk_reader) {
5942 return MonitoringInput;
5945 /* Explicit requests */
5946 MonitorChoice m (_monitoring_control->monitoring_choice());
5948 if (m != MonitorAuto) {
5950 MonitorState ms ((MonitorState) 0);
5952 if (m & MonitorInput) {
5953 ms = MonitoringInput;
5956 if (m & MonitorDisk) {
5957 ms = MonitorState (ms | MonitoringDisk);
5963 switch (_session.config.get_session_monitoring ()) {
5965 return MonitoringDisk;
5968 return MonitoringInput;
5974 /* This is an implementation of the truth table in doc/monitor_modes.pdf;
5975 I don't think it's ever going to be too pretty too look at.
5978 bool const roll = _session.transport_rolling ();
5979 bool const track_rec = _disk_writer->record_enabled ();
5980 bool const auto_input = _session.config.get_auto_input ();
5981 bool const software_monitor = Config->get_monitoring_model() == SoftwareMonitoring;
5982 bool const tape_machine_mode = Config->get_tape_machine_mode ();
5985 /* I suspect that just use actively_recording() is good enough all the
5986 * time, but just to keep the semantics the same as they were before
5987 * sept 26th 2012, we differentiate between the cases where punch is
5988 * enabled and those where it is not.
5990 * rg: sept 30 2017: Above is not the case: punch-in/out location is
5991 * global session playhead position.
5992 * When this method is called from process_output_buffers() we need
5993 * to use delay-compensated route's process-position.
5995 * NB. Disk reader/writer may also be offset by a same amount of time.
5997 * Also keep in mind that _session.transport_rolling() is false during
5998 * pre-roll but the disk already produces output.
6003 if (_session.config.get_punch_in() || _session.config.get_punch_out()) {
6004 session_rec = _session.actively_recording ();
6006 session_rec = _session.get_record_enabled();
6011 if (!session_rec && roll && auto_input) {
6012 return MonitoringDisk;
6014 return software_monitor ? MonitoringInput : MonitoringSilence;
6019 if (tape_machine_mode) {
6021 return MonitoringDisk;
6025 if (!roll && auto_input) {
6026 return software_monitor ? MonitoringInput : MonitoringSilence;
6028 return MonitoringDisk;
6034 abort(); /* NOTREACHED */
6035 return MonitoringSilence;