2 Copyright (C) 2000 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "libardour-config.h"
29 #include <boost/algorithm/string.hpp>
31 #include "pbd/xml++.h"
32 #include "pbd/enumwriter.h"
33 #include "pbd/locale_guard.h"
34 #include "pbd/memento_command.h"
35 #include "pbd/stacktrace.h"
36 #include "pbd/types_convert.h"
37 #include "pbd/unwind.h"
39 #include "ardour/amp.h"
40 #include "ardour/audio_buffer.h"
41 #include "ardour/audio_track.h"
42 #include "ardour/audio_port.h"
43 #include "ardour/audioengine.h"
44 #include "ardour/boost_debug.h"
45 #include "ardour/buffer.h"
46 #include "ardour/buffer_set.h"
47 #include "ardour/capturing_processor.h"
48 #include "ardour/debug.h"
49 #include "ardour/delivery.h"
50 #include "ardour/disk_reader.h"
51 #include "ardour/disk_writer.h"
52 #include "ardour/event_type_map.h"
53 #include "ardour/gain_control.h"
54 #include "ardour/internal_return.h"
55 #include "ardour/internal_send.h"
56 #include "ardour/meter.h"
57 #include "ardour/delayline.h"
58 #include "ardour/midi_buffer.h"
59 #include "ardour/midi_port.h"
60 #include "ardour/monitor_control.h"
61 #include "ardour/monitor_processor.h"
62 #include "ardour/pannable.h"
63 #include "ardour/panner.h"
64 #include "ardour/panner_shell.h"
65 #include "ardour/parameter_descriptor.h"
66 #include "ardour/phase_control.h"
67 #include "ardour/plugin_insert.h"
68 #include "ardour/port.h"
69 #include "ardour/port_insert.h"
70 #include "ardour/processor.h"
71 #include "ardour/profile.h"
72 #include "ardour/route.h"
73 #include "ardour/route_group.h"
74 #include "ardour/send.h"
75 #include "ardour/session.h"
76 #include "ardour/solo_control.h"
77 #include "ardour/solo_isolate_control.h"
78 #include "ardour/types_convert.h"
79 #include "ardour/unknown_processor.h"
80 #include "ardour/utils.h"
81 #include "ardour/vca.h"
86 using namespace ARDOUR;
89 PBD::Signal3<int,boost::shared_ptr<Route>, boost::shared_ptr<PluginInsert>, Route::PluginSetupOptions > Route::PluginSetup;
91 /** Base class for all routable/mixable objects (tracks and busses) */
92 Route::Route (Session& sess, string name, PresentationInfo::Flag flag, DataType default_type)
93 : Stripable (sess, name, PresentationInfo (flag))
94 , GraphNode (sess._process_graph)
95 , Muteable (sess, name)
98 , _disk_io_point (DiskIOPreFader)
99 , _pending_process_reorder (0)
100 , _pending_signals (0)
101 , _pending_declick (true)
102 , _meter_point (MeterPostFader)
103 , _pending_meter_point (MeterPostFader)
104 , _meter_type (MeterPeak)
105 , _denormal_protection (false)
108 , _declickable (false)
109 , _have_internal_generator (false)
110 , _default_type (default_type)
113 , _in_configure_processors (false)
114 , _initial_io_setup (false)
115 , _in_sidechain_setup (false)
116 , _custom_meter_position_noted (false)
118 , _patch_selector_dialog (0)
120 processor_max_streams.reset();
123 boost::weak_ptr<Route>
124 Route::weakroute () {
125 return boost::weak_ptr<Route> (boost::dynamic_pointer_cast<Route> (shared_from_this ()));
131 /* set default meter type */
133 _meter_type = Config->get_meter_type_master ();
135 else if (dynamic_cast<Track*>(this)) {
136 _meter_type = Config->get_meter_type_track ();
138 _meter_type = Config->get_meter_type_bus ();
141 /* add standard controls */
143 _gain_control.reset (new GainControl (_session, GainAutomation));
144 _trim_control.reset (new GainControl (_session, TrimAutomation));
145 /* While the route has-a gain-control for consistency with Stripable and VCA
146 * ownership is handed over to the Amp Processor which manages the
147 * state of the Control and AutomationList as part of its
148 * Automatable API. -- Don't call add_control () here.
151 _solo_control.reset (new SoloControl (_session, X_("solo"), *this, *this));
152 add_control (_solo_control);
153 _solo_control->Changed.connect_same_thread (*this, boost::bind (&Route::solo_control_changed, this, _1, _2));
155 _mute_control.reset (new MuteControl (_session, X_("mute"), *this));
156 add_control (_mute_control);
158 _phase_control.reset (new PhaseControl (_session, X_("phase")));
159 add_control (_phase_control);
161 _solo_isolate_control.reset (new SoloIsolateControl (_session, X_("solo-iso"), *this, *this));
162 add_control (_solo_isolate_control);
164 _solo_safe_control.reset (new SoloSafeControl (_session, X_("solo-safe")));
165 add_control (_solo_safe_control);
169 if (!(_presentation_info.flags() & PresentationInfo::MonitorOut)) {
170 _pannable.reset (new Pannable (_session));
173 /* input and output objects */
175 _input.reset (new IO (_session, _name, IO::Input, _default_type));
176 _output.reset (new IO (_session, _name, IO::Output, _default_type));
178 _input->changed.connect_same_thread (*this, boost::bind (&Route::input_change_handler, this, _1, _2));
179 _input->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::input_port_count_changing, this, _1));
181 _output->changed.connect_same_thread (*this, boost::bind (&Route::output_change_handler, this, _1, _2));
182 _output->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::output_port_count_changing, this, _1));
184 /* add the amp/fader processor.
185 * it should be the first processor to be added on every route.
188 _amp.reset (new Amp (_session, X_("Fader"), _gain_control, true));
189 add_processor (_amp, PostFader);
192 _amp->set_display_name (_("Monitor"));
195 if (!is_master() && !is_monitor() && !is_auditioner()) {
196 _delayline.reset (new DelayLine (_session, name ()));
201 _trim.reset (new Amp (_session, X_("Trim"), _trim_control, false));
202 _trim->set_display_to_user (false);
204 if (dynamic_cast<AudioTrack*>(this)) {
205 /* we can't do this in the AudioTrack's constructor
206 * because _trim does not exit then
210 else if (!dynamic_cast<Track*>(this) && ! ( is_monitor() || is_auditioner() )) {
215 /* create standard processors: meter, main outs, monitor out;
216 they will be added to _processors by setup_invisible_processors ()
219 _meter.reset (new PeakMeter (_session, _name));
220 _meter->set_owner (this);
221 _meter->set_display_to_user (false);
224 _main_outs.reset (new Delivery (_session, _output, _pannable, _mute_master, _name, Delivery::Main));
225 _main_outs->activate ();
228 /* where we listen to tracks */
229 _intreturn.reset (new InternalReturn (_session));
230 _intreturn->activate ();
232 /* the thing that provides proper control over a control/monitor/listen bus
233 (such as per-channel cut, dim, solo, invert, etc).
235 _monitor_control.reset (new MonitorProcessor (_session));
236 _monitor_control->activate ();
239 /* now that we have _meter, its safe to connect to this */
242 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
243 configure_processors (0);
251 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
253 /* do this early so that we don't get incoming signals as we are going through destruction
258 /* don't use clear_processors here, as it depends on the session which may
259 be half-destroyed by now
262 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
263 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
264 (*i)->drop_references ();
267 _processors.clear ();
271 Route::ensure_track_or_route_name(string name, Session &session)
273 string newname = name;
275 while (!session.io_name_is_legal (newname)) {
276 newname = bump_name_once (newname, ' ');
283 Route::set_trim (gain_t val, Controllable::GroupControlDisposition /* group override */)
285 // TODO route group, see set_gain()
286 // _trim_control->route_set_value (val);
290 Route::maybe_declick (BufferSet&, samplecnt_t, int)
292 /* this is the "bus" implementation and they never declick.
297 /** Process this route for one (sub) cycle (process thread)
299 * @param bufs Scratch buffers to use for the signal path
300 * @param start_sample Initial transport sample
301 * @param end_sample Final transport sample
302 * @param nframes Number of samples to output (to ports)
304 * Note that (end_sample - start_sample) may not be equal to nframes when the
305 * transport speed isn't 1.0 (eg varispeed).
308 Route::process_output_buffers (BufferSet& bufs,
309 samplepos_t start_sample, samplepos_t end_sample, pframes_t nframes,
310 int declick, bool gain_automation_ok, bool run_disk_reader)
312 /* Caller must hold process lock */
313 assert (!AudioEngine::instance()->process_lock().trylock());
315 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
317 // can this actually happen?
318 // Places that need a WriterLock on (_processor_lock) must also take the process-lock.
319 bufs.silence (nframes, 0);
320 assert (0); // ...one way to find out.
324 /* We should offset the route-owned ctrls by the given latency, however
325 * this only affects Mute. Other route-owned controls (solo, polarity..)
326 * are not automatable.
328 * Mute has its own issues since there's not a single mute-point,
331 automation_run (start_sample, nframes);
333 /* figure out if we're going to use gain automation */
334 if (gain_automation_ok) {
335 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
336 _amp->setup_gain_automation (
337 start_sample + _amp->output_latency (),
338 end_sample + _amp->output_latency (),
341 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
342 _trim->setup_gain_automation (
343 start_sample + _trim->output_latency (),
344 end_sample + _trim->output_latency (),
348 /* We align the playhead to output. The user hears what the clock says:
349 * When the playhead/clock says 1:00:00:00 the user will hear the audio sample
350 * at 1:00:00:00. sample_start will be [sample at] 1:00:00:00
352 * e.g. clock says Time T = 0, sample_start = 0
353 * Disk-read(play) -> latent-plugin (+10) -> fader-automation -> output (+5)
354 * -> total playback latency "disk -> out" is 15.
355 * -> at Time T= -15, the disk-reader reads sample T=0.
356 * By the Time T=0 is reached (dt=15 later) that sample is audible.
359 start_sample += _signal_latency;
360 end_sample += _signal_latency;
362 start_sample += _output->latency ();
363 end_sample += _output->latency ();
365 const double speed = (is_auditioner() ? 1.0 : _session.transport_speed ());
367 /* Note: during intial pre-roll 'start_sample' as passed as argument can be negative.
368 * Functions calling process_output_buffers() will set "run_disk_reader"
369 * to false if the pre-roll count-down is larger than playback_latency ().
371 * playback_latency() is guarnteed to be <= _signal_latency + _output->latency ()
373 assert (!_disk_reader || !run_disk_reader || start_sample >= 0);
375 /* however the disk-writer may need to pick up output from other tracks
376 * during pre-roll (in particular if this route has latent effects after the disk).
378 * e.g. track 1 play -> latency A --port--> track2 capture -> latency B ---> out
379 * total pre-roll = A + B.
381 * Note the disk-writer has built-in overlap detection (it's safe to run it early)
384 bool run_disk_writer = false;
385 if (_disk_writer && speed != 0) {
386 samplecnt_t latency_preroll = _session.remaining_latency_preroll ();
387 run_disk_writer = latency_preroll < nframes + (_signal_latency + _output->latency ());
388 if (end_sample - _disk_writer->input_latency () < _session.transport_sample ()) {
389 run_disk_writer = true;
393 /* Tell main outs what to do about monitoring. We do this so that
394 * on a transition between monitoring states we get a de-clicking gain
395 * change in the _main_outs delivery, if config.get_use_monitor_fades()
398 * We override this in the case where we have an internal generator.
400 * FIXME: when punching in/out this also depends on latency compensated time
401 * for this route. monitoring_state() does not currently handle that correctly,.
403 * Also during remaining_latency_preroll, transport_rolling () is false, but
404 * we may need to monitor disk instead.
406 bool silence = _have_internal_generator ? false : (monitoring_state () == 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 double pspeed = speed;
529 if ((!run_disk_reader && (*i) == _disk_reader) || (!run_disk_writer && (*i) == _disk_writer)) {
530 /* run with speed 0, no-roll */
534 (*i)->run (bufs, start_sample - latency, end_sample - latency, pspeed, nframes, *i != _processors.back());
535 bufs.set_count ((*i)->output_streams());
537 /* Note: plugin latency may change. While the plugin does inform the session via
538 * processor_latency_changed(). But the session may not yet have gotten around to
539 * update the actual worste-case and update this track's _signal_latency.
541 * So there can be cases where adding up all latencies may not equal _signal_latency.
543 if ((*i)->active ()) {
544 latency += (*i)->signal_latency ();
547 if ((*i) == _delayline) {
548 latency += _delayline->get_delay ();
555 Route::bounce_process (BufferSet& buffers, samplepos_t start, samplecnt_t nframes,
556 boost::shared_ptr<Processor> endpoint,
557 bool include_endpoint, bool for_export, bool for_freeze)
559 /* If no processing is required, there's no need to go any further. */
560 if (!endpoint && !include_endpoint) {
564 samplecnt_t latency = bounce_get_latency(_amp, false, for_export, for_freeze);
565 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
566 _amp->setup_gain_automation (start - latency, start - latency + nframes, nframes);
568 /* trim is always at the top, for bounce no latency compensation is needed */
569 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
570 _trim->setup_gain_automation (start, start + nframes, nframes);
573 const double speed = _session.transport_speed ();
574 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
576 if (!include_endpoint && (*i) == endpoint) {
580 /* if we're *not* exporting, stop processing if we come across a routing processor. */
581 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
584 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
588 /* special case the panner (export outputs)
589 * Ideally we'd only run the panner, not the delivery itself...
590 * but panners need separate input/output buffers and some context
591 * (panshell, panner type, etc). AFAICT there is no ill side effect
592 * of re-using the main delivery when freewheeling/exporting a region.
594 if ((*i) == _main_outs) {
595 assert ((*i)->does_routing());
596 (*i)->run (buffers, start - latency, start - latency + nframes, speed, nframes, true);
597 buffers.set_count ((*i)->output_streams());
600 /* don't run any processors that do routing.
601 * Also don't bother with metering.
603 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
604 (*i)->run (buffers, start - latency, start - latency + nframes, 1.0, nframes, true);
605 buffers.set_count ((*i)->output_streams());
606 latency += (*i)->signal_latency ();
609 if ((*i) == endpoint) {
616 Route::bounce_get_latency (boost::shared_ptr<Processor> endpoint,
617 bool include_endpoint, bool for_export, bool for_freeze) const
619 samplecnt_t latency = 0;
620 if (!endpoint && !include_endpoint) {
624 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
625 if (!include_endpoint && (*i) == endpoint) {
628 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
631 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
634 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
635 latency += (*i)->signal_latency ();
637 if ((*i) == endpoint) {
645 Route::bounce_get_output_streams (ChanCount &cc, boost::shared_ptr<Processor> endpoint,
646 bool include_endpoint, bool for_export, bool for_freeze) const
648 if (!endpoint && !include_endpoint) {
652 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
653 if (!include_endpoint && (*i) == endpoint) {
656 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
659 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
662 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
663 cc = (*i)->output_streams();
665 if ((*i) == endpoint) {
673 Route::n_process_buffers ()
675 return max (_input->n_ports(), processor_max_streams);
679 Route::monitor_run (samplepos_t start_sample, samplepos_t end_sample, pframes_t nframes, int declick)
681 assert (is_monitor());
682 BufferSet& bufs (_session.get_route_buffers (n_process_buffers()));
683 fill_buffers_with_input (bufs, _input, nframes);
684 passthru (bufs, start_sample, end_sample, nframes, declick, true, false);
688 Route::passthru (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_sample, pframes_t nframes, int declick, bool gain_automation_ok, bool run_disk_reader)
692 if (is_monitor() && _session.listening() && !_session.is_auditioning()) {
694 /* control/monitor bus ignores input ports when something is
695 feeding the listen "stream". data will "arrive" into the
696 route from the intreturn processor element.
699 bufs.silence (nframes, 0);
702 /* append immediate messages to the first MIDI buffer (thus sending it to the first output port) */
704 write_out_of_band_data (bufs, start_sample, end_sample, nframes);
706 /* run processor chain */
708 process_output_buffers (bufs, start_sample, end_sample, nframes, declick, gain_automation_ok, run_disk_reader);
712 Route::passthru_silence (samplepos_t start_sample, samplepos_t end_sample, pframes_t nframes, int declick)
714 BufferSet& bufs (_session.get_route_buffers (n_process_buffers(), true));
716 bufs.set_count (_input->n_ports());
717 write_out_of_band_data (bufs, start_sample, end_sample, nframes);
718 process_output_buffers (bufs, start_sample, end_sample, nframes, declick, false, false);
722 Route::set_listen (bool yn)
725 if (_monitor_send->active() == yn) {
729 _monitor_send->activate ();
731 _monitor_send->deactivate ();
737 Route::solo_control_changed (bool, Controllable::GroupControlDisposition)
739 /* nothing to do if we're not using AFL/PFL. But if we are, we need
740 to alter the active state of the monitor send.
743 if (Config->get_solo_control_is_listen_control ()) {
744 set_listen (_solo_control->self_soloed() || _solo_control->get_masters_value());
749 Route::push_solo_isolate_upstream (int32_t delta)
751 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
753 boost::shared_ptr<RouteList> routes = _session.get_routes ();
754 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
756 if ((*i).get() == this || !(*i)->can_solo()) {
761 bool does_feed = feeds (*i, &sends_only);
763 if (does_feed && !sends_only) {
764 (*i)->solo_isolate_control()->mod_solo_isolated_by_upstream (delta);
770 Route::push_solo_upstream (int delta)
772 DEBUG_TRACE (DEBUG::Solo, string_compose("\t ... INVERT push from %1\n", _name));
773 for (FedBy::iterator i = _fed_by.begin(); i != _fed_by.end(); ++i) {
777 boost::shared_ptr<Route> sr (i->r.lock());
779 sr->solo_control()->mod_solo_by_others_downstream (-delta);
786 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
788 cerr << name << " {" << endl;
789 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
790 p != procs.end(); ++p) {
791 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << " @ " << (*p) << endl;
797 /** Supposing that we want to insert a Processor at a given Placement, return
798 * the processor to add the new one before (or 0 to add at the end).
800 boost::shared_ptr<Processor>
801 Route::before_processor_for_placement (Placement p)
803 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
805 ProcessorList::iterator loc;
808 /* generic pre-fader: insert immediately before the amp */
809 loc = find (_processors.begin(), _processors.end(), _amp);
811 /* generic post-fader: insert right before the main outs */
812 loc = find (_processors.begin(), _processors.end(), _main_outs);
815 return loc != _processors.end() ? *loc : boost::shared_ptr<Processor> ();
818 /** Supposing that we want to insert a Processor at a given index, return
819 * the processor to add the new one before (or 0 to add at the end).
821 boost::shared_ptr<Processor>
822 Route::before_processor_for_index (int index)
825 return boost::shared_ptr<Processor> ();
828 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
830 ProcessorList::iterator i = _processors.begin ();
832 while (i != _processors.end() && j < index) {
833 if ((*i)->display_to_user()) {
840 return (i != _processors.end() ? *i : boost::shared_ptr<Processor> ());
843 /** Add a processor either pre- or post-fader
844 * @return 0 on success, non-0 on failure.
847 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err, bool activation_allowed)
849 return add_processor (processor, before_processor_for_placement (placement), err, activation_allowed);
853 /** Add a processor to a route such that it ends up with a given index into the visible processors.
854 * @param index Index to add the processor at, or -1 to add at the end of the list.
855 * @return 0 on success, non-0 on failure.
858 Route::add_processor_by_index (boost::shared_ptr<Processor> processor, int index, ProcessorStreams* err, bool activation_allowed)
860 return add_processor (processor, before_processor_for_index (index), err, activation_allowed);
863 /** Add a processor to the route.
864 * @param before An existing processor in the list, or 0; the new processor will be inserted immediately before it (or at the end).
865 * @return 0 on success, non-0 on failure.
868 Route::add_processor (boost::shared_ptr<Processor> processor, boost::shared_ptr<Processor> before, ProcessorStreams* err, bool activation_allowed)
870 assert (processor != _meter);
871 assert (processor != _main_outs);
873 DEBUG_TRACE (DEBUG::Processors, string_compose (
874 "%1 adding processor %2\n", name(), processor->name()));
878 pl.push_back (processor);
879 int rv = add_processors (pl, before, err);
885 if (activation_allowed && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user ())) {
886 processor->activate ();
893 Route::processor_selfdestruct (boost::weak_ptr<Processor> wp)
895 /* We cannot destruct the processor here (usually RT-thread
896 * with various locks held - in case of sends also io_locks).
897 * Queue for deletion in low-priority thread.
899 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
900 selfdestruct_sequence.push_back (wp);
904 Route::add_processor_from_xml_2X (const XMLNode& node, int version)
906 XMLProperty const * prop;
909 boost::shared_ptr<Processor> processor;
911 /* bit of a hack: get the `placement' property from the <Redirect> tag here
912 so that we can add the processor in the right place (pre/post-fader)
915 XMLNodeList const & children = node.children ();
916 XMLNodeList::const_iterator i = children.begin ();
918 while (i != children.end() && (*i)->name() != X_("Redirect")) {
922 Placement placement = PreFader;
924 if (i != children.end()) {
925 if ((prop = (*i)->property (X_("placement"))) != 0) {
926 placement = Placement (string_2_enum (prop->value(), placement));
930 if (node.name() == "Insert") {
932 if ((prop = node.property ("type")) != 0) {
934 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
935 prop->value() == "lv2" ||
936 prop->value() == "windows-vst" ||
937 prop->value() == "mac-vst" ||
938 prop->value() == "lxvst" ||
939 prop->value() == "audiounit") {
941 if (_session.get_disable_all_loaded_plugins ()) {
942 processor.reset (new UnknownProcessor (_session, node));
944 processor.reset (new PluginInsert (_session));
945 processor->set_owner (this);
950 processor.reset (new PortInsert (_session, _pannable, _mute_master));
955 } else if (node.name() == "Send") {
957 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
958 processor.reset (new Send (_session, sendpan, _mute_master));
962 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
966 if (processor->set_state (node, version)) {
970 //A2 uses the "active" flag in the toplevel redirect node, not in the child plugin/IO
971 if (i != children.end()) {
972 if ((prop = (*i)->property (X_("active"))) != 0) {
973 if ( string_to<bool> (prop->value()) && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user () ) )
974 processor->activate();
976 processor->deactivate();
980 return (add_processor (processor, placement, 0, false) == 0);
983 catch (failed_constructor &err) {
984 warning << _("processor could not be created. Ignored.") << endmsg;
990 inline Route::PluginSetupOptions operator|= (Route::PluginSetupOptions& a, const Route::PluginSetupOptions& b) {
991 return a = static_cast<Route::PluginSetupOptions> (static_cast <int>(a) | static_cast<int> (b));
994 inline Route::PluginSetupOptions operator&= (Route::PluginSetupOptions& a, const Route::PluginSetupOptions& b) {
995 return a = static_cast<Route::PluginSetupOptions> (static_cast <int>(a) & static_cast<int> (b));
999 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
1001 ProcessorList::iterator loc;
1002 boost::shared_ptr <PluginInsert> fanout;
1004 if (g_atomic_int_get (&_pending_process_reorder)) {
1005 /* we need to flush any pending re-order changes */
1006 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1007 apply_processor_changes_rt ();
1011 loc = find(_processors.begin(), _processors.end(), before);
1012 if (loc == _processors.end ()) {
1016 /* nothing specified - at end */
1017 loc = _processors.end ();
1020 if (others.empty()) {
1024 ProcessorList to_skip;
1026 // check if there's an instrument to replace or configure
1027 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1028 boost::shared_ptr<PluginInsert> pi;
1029 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) == 0) {
1032 if (!pi->plugin ()->get_info ()->is_instrument ()) {
1035 boost::shared_ptr<Processor> instrument = the_instrument ();
1036 ChanCount in (DataType::MIDI, 1);
1037 ChanCount out (DataType::AUDIO, 2); // XXX route's out?!
1039 PluginSetupOptions flags = None;
1041 flags |= CanReplace;
1042 in = instrument->input_streams ();
1043 out = instrument->output_streams ();
1045 if (pi->has_output_presets (in, out)) {
1049 pi->set_strict_io (_strict_io);
1051 PluginSetupOptions mask = None;
1052 if (Config->get_ask_replace_instrument ()) {
1055 if (Config->get_ask_setup_instrument ()) {
1061 if (flags != None) {
1062 boost::optional<int> rv = PluginSetup (boost::dynamic_pointer_cast<Route>(shared_from_this ()), pi, flags); /* EMIT SIGNAL */
1063 int mode = rv.get_value_or (0);
1066 to_skip.push_back (*i); // don't add this one;
1069 replace_processor (instrument, *i, err);
1070 to_skip.push_back (*i);
1075 if ((mode & 5) == 4) {
1082 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1083 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1084 ProcessorState pstate (this);
1086 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1091 ProcessorList::iterator check = find (to_skip.begin(), to_skip.end(), *i);
1092 if (check != to_skip.end()) {
1096 boost::shared_ptr<PluginInsert> pi;
1098 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1099 pi->set_strict_io (_strict_io);
1103 /* Ensure that only one amp is in the list at any time */
1104 ProcessorList::iterator check = find (_processors.begin(), _processors.end(), *i);
1105 if (check != _processors.end()) {
1106 if (before == _amp) {
1107 /* Already in position; all is well */
1110 _processors.erase (check);
1115 assert (find (_processors.begin(), _processors.end(), *i) == _processors.end ());
1117 _processors.insert (loc, *i);
1118 (*i)->set_owner (this);
1121 if (configure_processors_unlocked (err, &lm)) {
1123 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
1128 if (pi && pi->has_sidechain ()) {
1129 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
1132 if ((*i)->active()) {
1133 // emit ActiveChanged() and latency_changed() if needed
1137 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1139 boost::shared_ptr<Send> send;
1140 if ((send = boost::dynamic_pointer_cast<Send> (*i))) {
1141 send->SelfDestruct.connect_same_thread (*this,
1142 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (*i)));
1146 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1147 boost::shared_ptr<PluginInsert> pi;
1149 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1150 if (pi->has_no_inputs ()) {
1151 _have_internal_generator = true;
1157 _output->set_user_latency (0);
1160 reset_instrument_info ();
1161 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1162 set_processor_positions ();
1164 if (fanout && fanout->configured ()
1165 && fanout->output_streams().n_audio() > 2
1166 && boost::dynamic_pointer_cast<PluginInsert> (the_instrument ()) == fanout) {
1167 fan_out (); /* EMIT SIGNAL */
1173 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1175 if (p == PreFader) {
1176 start = _processors.begin();
1177 end = find(_processors.begin(), _processors.end(), _amp);
1179 start = find(_processors.begin(), _processors.end(), _amp);
1181 end = _processors.end();
1185 /** Turn off all processors with a given placement
1186 * @param p Placement of processors to disable
1189 Route::disable_processors (Placement p)
1191 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1193 ProcessorList::iterator start, end;
1194 placement_range(p, start, end);
1196 for (ProcessorList::iterator i = start; i != end; ++i) {
1197 (*i)->enable (false);
1200 _session.set_dirty ();
1203 /** Turn off all redirects
1206 Route::disable_processors ()
1208 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1210 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1211 (*i)->enable (false);
1214 _session.set_dirty ();
1217 /** Turn off all redirects with a given placement
1218 * @param p Placement of redirects to disable
1221 Route::disable_plugins (Placement p)
1223 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1225 ProcessorList::iterator start, end;
1226 placement_range(p, start, end);
1228 for (ProcessorList::iterator i = start; i != end; ++i) {
1229 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1230 (*i)->enable (false);
1234 _session.set_dirty ();
1237 /** Turn off all plugins
1240 Route::disable_plugins ()
1242 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1244 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1245 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1246 (*i)->enable (false);
1250 _session.set_dirty ();
1255 Route::ab_plugins (bool forward)
1257 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1261 /* forward = turn off all active redirects, and mark them so that the next time
1262 we go the other way, we will revert them
1265 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1266 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1269 if (!(*i)->display_to_user ()) {
1273 if (boost::dynamic_pointer_cast<PluginInsert> (*i)->is_channelstrip()) {
1278 if ((*i)->enabled ()) {
1279 (*i)->enable (false);
1280 (*i)->set_next_ab_is_active (true);
1282 (*i)->set_next_ab_is_active (false);
1288 /* backward = if the redirect was marked to go active on the next ab, do so */
1290 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1291 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1294 if (!(*i)->display_to_user ()) {
1298 if (boost::dynamic_pointer_cast<PluginInsert> (*i)->is_channelstrip()) {
1303 (*i)->enable ((*i)->get_next_ab_is_active ());
1307 _session.set_dirty ();
1311 /** Remove processors with a given placement.
1312 * @param p Placement of processors to remove.
1315 Route::clear_processors (Placement p)
1317 if (!_session.engine().connected()) {
1321 bool already_deleting = _session.deletion_in_progress();
1322 if (!already_deleting) {
1323 _session.set_deletion_in_progress();
1326 ProcessorList old_list = _processors;
1328 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1329 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1330 ProcessorList new_list;
1331 ProcessorStreams err;
1332 bool seen_amp = false;
1334 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1340 if (is_internal_processor (*i)) {
1342 /* you can't remove these */
1344 new_list.push_back (*i);
1351 new_list.push_back (*i);
1354 (*i)->drop_references ();
1362 (*i)->drop_references ();
1365 new_list.push_back (*i);
1372 _processors = new_list;
1373 configure_processors_unlocked (&err, &lm); // this can't fail
1375 /* drop references w/o process-lock (I/O procs may re-take it in ~IO() */
1378 processor_max_streams.reset();
1379 _have_internal_generator = false;
1380 reset_instrument_info ();
1381 set_processor_positions ();
1383 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1385 if (!already_deleting) {
1386 _session.clear_deletion_in_progress();
1391 Route::is_internal_processor (boost::shared_ptr<Processor> p) const
1393 if (p == _amp || p == _meter || p == _main_outs || p == _delayline || p == _trim) {
1400 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err, bool need_process_lock)
1402 // TODO once the export point can be configured properly, do something smarter here
1403 if (processor == _capturing_processor) {
1404 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1405 if (need_process_lock) {
1409 _capturing_processor.reset();
1411 if (need_process_lock) {
1416 /* these can never be removed */
1418 if (is_internal_processor (processor)) {
1422 if (!_session.engine().connected()) {
1426 processor_max_streams.reset();
1429 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1430 if (need_process_lock) {
1434 /* Caller must hold process lock */
1435 assert (!AudioEngine::instance()->process_lock().trylock());
1437 Glib::Threads::RWLock::WriterLock lm (_processor_lock); // XXX deadlock after export
1439 ProcessorState pstate (this);
1441 ProcessorList::iterator i;
1442 bool removed = false;
1444 for (i = _processors.begin(); i != _processors.end(); ) {
1445 if (*i == processor) {
1447 /* move along, see failure case for configure_processors()
1448 where we may need to reconfigure the processor.
1451 /* stop redirects that send signals to JACK ports
1452 from causing noise as a result of no longer being
1456 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor> (*i);
1457 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
1461 iop = pi->sidechain();
1468 i = _processors.erase (i);
1476 _output->set_user_latency (0);
1484 if (configure_processors_unlocked (err, &lm)) {
1486 /* we know this will work, because it worked before :) */
1487 configure_processors_unlocked (0, &lm);
1491 _have_internal_generator = false;
1493 for (i = _processors.begin(); i != _processors.end(); ++i) {
1494 boost::shared_ptr<PluginInsert> pi;
1496 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1497 if (pi->has_no_inputs ()) {
1498 _have_internal_generator = true;
1503 if (need_process_lock) {
1508 reset_instrument_info ();
1509 processor->drop_references ();
1510 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1511 set_processor_positions ();
1517 Route::replace_processor (boost::shared_ptr<Processor> old, boost::shared_ptr<Processor> sub, ProcessorStreams* err)
1519 /* these can never be removed */
1520 if (is_internal_processor (old)) {
1523 /* and can't be used as substitute, either */
1524 if (is_internal_processor (sub)) {
1528 /* I/Os are out, too */
1529 if (boost::dynamic_pointer_cast<IOProcessor> (old) || boost::dynamic_pointer_cast<IOProcessor> (sub)) {
1533 /* this function cannot be used to swap/reorder processors */
1534 if (find (_processors.begin(), _processors.end(), sub) != _processors.end ()) {
1538 if (!AudioEngine::instance()->connected() || !old || !sub) {
1542 /* ensure that sub is not owned by another route */
1543 if (sub->owner ()) {
1548 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1549 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1550 ProcessorState pstate (this);
1552 assert (find (_processors.begin(), _processors.end(), sub) == _processors.end ());
1554 ProcessorList::iterator i;
1555 bool replaced = false;
1556 bool enable = old->enabled ();
1558 for (i = _processors.begin(); i != _processors.end(); ) {
1560 i = _processors.erase (i);
1561 _processors.insert (i, sub);
1562 sub->set_owner (this);
1575 boost::shared_ptr<PluginInsert> pi;
1576 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(sub)) != 0) {
1577 pi->set_strict_io (true);
1581 if (configure_processors_unlocked (err, &lm)) {
1583 configure_processors_unlocked (0, &lm);
1587 _have_internal_generator = false;
1589 for (i = _processors.begin(); i != _processors.end(); ++i) {
1590 boost::shared_ptr<PluginInsert> pi;
1591 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1592 if (pi->has_no_inputs ()) {
1593 _have_internal_generator = true;
1603 sub->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1604 _output->set_user_latency (0);
1607 reset_instrument_info ();
1608 old->drop_references ();
1609 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1610 set_processor_positions ();
1615 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1617 ProcessorList deleted;
1619 if (!_session.engine().connected()) {
1623 processor_max_streams.reset();
1626 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1627 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1628 ProcessorState pstate (this);
1630 ProcessorList::iterator i;
1631 boost::shared_ptr<Processor> processor;
1633 for (i = _processors.begin(); i != _processors.end(); ) {
1637 /* these can never be removed */
1639 if (is_internal_processor (processor)) {
1644 /* see if its in the list of processors to delete */
1646 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1651 /* stop IOProcessors that send to JACK ports
1652 from causing noise as a result of no longer being
1656 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(processor);
1657 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
1660 iop = pi->sidechain();
1667 deleted.push_back (processor);
1668 i = _processors.erase (i);
1671 if (deleted.empty()) {
1672 /* none of those in the requested list were found */
1676 _output->set_user_latency (0);
1678 if (configure_processors_unlocked (err, &lm)) {
1680 /* we know this will work, because it worked before :) */
1681 configure_processors_unlocked (0, &lm);
1686 _have_internal_generator = false;
1688 for (i = _processors.begin(); i != _processors.end(); ++i) {
1689 boost::shared_ptr<PluginInsert> pi;
1691 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1692 if (pi->has_no_inputs ()) {
1693 _have_internal_generator = true;
1700 /* now try to do what we need to so that those that were removed will be deleted */
1702 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1703 (*i)->drop_references ();
1706 reset_instrument_info ();
1707 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1708 set_processor_positions ();
1714 Route::reset_instrument_info ()
1716 boost::shared_ptr<Processor> instr = the_instrument();
1718 _instrument_info.set_internal_instrument (instr);
1722 /** Caller must hold process lock */
1724 Route::configure_processors (ProcessorStreams* err)
1726 #ifndef PLATFORM_WINDOWS
1727 assert (!AudioEngine::instance()->process_lock().trylock());
1730 if (!_in_configure_processors) {
1731 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1732 return configure_processors_unlocked (err, &lm);
1739 Route::input_streams () const
1741 return _input->n_ports ();
1744 list<pair<ChanCount, ChanCount> >
1745 Route::try_configure_processors (ChanCount in, ProcessorStreams* err)
1747 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1749 return try_configure_processors_unlocked (in, err);
1752 list<pair<ChanCount, ChanCount> >
1753 Route::try_configure_processors_unlocked (ChanCount in, ProcessorStreams* err)
1755 // Check each processor in order to see if we can configure as requested
1757 list<pair<ChanCount, ChanCount> > configuration;
1760 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1761 DEBUG_TRACE (DEBUG::Processors, "{\n");
1763 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1765 if ((*p)->can_support_io_configuration(in, out)) {
1767 if (boost::dynamic_pointer_cast<Delivery> (*p)
1768 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main
1770 && (is_monitor() || _strict_io || Profile->get_mixbus ())) {
1771 /* with strict I/O the panner + output are forced to
1772 * follow the last processor's output.
1774 * Delivery::can_support_io_configuration() will only add ports,
1775 * but not remove excess ports.
1777 * This works because the delivery only requires
1778 * as many outputs as there are inputs.
1779 * Delivery::configure_io() will do the actual removal
1780 * by calling _output->ensure_io()
1782 if (!is_master() && _session.master_out () && in.n_audio() > 0) {
1783 /* ..but at least as many as there are master-inputs, if
1784 * the delivery is dealing with audio */
1785 // XXX this may need special-casing for mixbus (master-outputs)
1786 // and should maybe be a preference anyway ?!
1787 out = ChanCount::max (in, _session.master_out ()->n_inputs ());
1793 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID=%2 in=%3 out=%4\n",(*p)->name(), (*p)->id(), in, out));
1794 configuration.push_back(make_pair(in, out));
1797 // restriction for Monitor Section Processors
1798 if (in.n_audio() != out.n_audio() || out.n_midi() > 0) {
1799 /* Note: The Monitor follows the master-bus and has no panner.
1801 * The general idea is to only allow plugins that retain the channel-count
1802 * and plugins with MIDI in (e.g VSTs with control that will remain unconnected).
1803 * Then again 5.1 in, monitor stereo is a valid use-case.
1805 * and worse: we only refuse adding plugins *here*.
1807 * 1) stereo-master, stereo-mon, add a stereo-plugin, OK
1808 * 2) change master-bus, add a channel
1809 * 2a) monitor-secion follows
1810 * 3) monitor processors fail to re-reconfigure (stereo plugin)
1811 * 4) re-load session, monitor-processor remains unconfigured, crash.
1813 DEBUG_TRACE (DEBUG::Processors, "Monitor: Channel configuration change.\n");
1815 if (boost::dynamic_pointer_cast<InternalSend> (*p)) {
1816 // internal sends make no sense, only feedback
1817 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1818 return list<pair<ChanCount, ChanCount> > ();
1820 if (boost::dynamic_pointer_cast<PortInsert> (*p)) {
1821 /* External Sends can be problematic. one can add/remove ports
1822 * there signal leaves the DAW to external monitors anyway, so there's
1823 * no real use for allowing them here anyway.
1825 DEBUG_TRACE (DEBUG::Processors, "Monitor: No External Sends allowed.\n");
1826 return list<pair<ChanCount, ChanCount> > ();
1828 if (boost::dynamic_pointer_cast<Send> (*p)) {
1830 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1831 return list<pair<ChanCount, ChanCount> > ();
1840 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
1841 DEBUG_TRACE (DEBUG::Processors, string_compose ("---- %1 cannot support in=%2 out=%3\n", (*p)->name(), in, out));
1842 DEBUG_TRACE (DEBUG::Processors, "}\n");
1843 return list<pair<ChanCount, ChanCount> > ();
1847 DEBUG_TRACE (DEBUG::Processors, "}\n");
1849 return configuration;
1852 /** Set the input/output configuration of each processor in the processors list.
1853 * Caller must hold process lock.
1854 * Return 0 on success, otherwise configuration is impossible.
1857 Route::configure_processors_unlocked (ProcessorStreams* err, Glib::Threads::RWLock::WriterLock* lm)
1859 #ifndef PLATFORM_WINDOWS
1860 assert (!AudioEngine::instance()->process_lock().trylock());
1863 if (_in_configure_processors) {
1867 /* put invisible processors where they should be */
1868 setup_invisible_processors ();
1870 _in_configure_processors = true;
1872 list<pair<ChanCount, ChanCount> > configuration = try_configure_processors_unlocked (input_streams (), err);
1874 if (configuration.empty ()) {
1875 _in_configure_processors = false;
1880 bool seen_mains_out = false;
1881 processor_out_streams = _input->n_ports();
1882 processor_max_streams.reset();
1884 /* processor configure_io() may result in adding ports
1885 * e.g. Delivery::configure_io -> ARDOUR::IO::ensure_io ()
1887 * with jack2 adding ports results in a graph-order callback,
1888 * which calls Session::resort_routes() and eventually
1889 * Route::direct_feeds_according_to_reality()
1890 * which takes a ReaderLock (_processor_lock).
1892 * so we can't hold a WriterLock here until jack2 threading
1895 * NB. we still hold the process lock
1897 * (ardour's own engines do call graph-order from the
1898 * process-thread and hence do not have this issue; besides
1899 * merely adding ports won't trigger a graph-order, only
1900 * making connections does)
1904 // TODO check for a potential ReaderLock after ReaderLock ??
1905 Glib::Threads::RWLock::ReaderLock lr (_processor_lock);
1907 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1908 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1910 if (!(*p)->configure_io(c->first, c->second)) {
1911 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration failed\n", _name));
1912 _in_configure_processors = false;
1918 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1919 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1921 boost::shared_ptr<IOProcessor> iop;
1922 boost::shared_ptr<PluginInsert> pi;
1923 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
1924 /* plugins connected via Split or Hide Match may have more channels.
1925 * route/scratch buffers are needed for all of them
1926 * The configuration may only be a subset (both input and output)
1928 processor_max_streams = ChanCount::max(processor_max_streams, pi->required_buffers());
1930 else if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*p)) != 0) {
1931 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_input_streams());
1932 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_output_streams());
1936 if (boost::dynamic_pointer_cast<Delivery> (*p)
1937 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main) {
1938 /* main delivery will increase port count to match input.
1939 * the Delivery::Main is usually the last processor - followed only by
1942 seen_mains_out = true;
1944 if (!seen_mains_out) {
1945 processor_out_streams = out;
1954 _meter->set_max_channels (processor_max_streams);
1957 /* make sure we have sufficient scratch buffers to cope with the new processor
1960 _session.ensure_buffers (n_process_buffers ());
1962 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration complete\n", _name));
1964 _in_configure_processors = false;
1968 /** Set all visible processors to a given active state (except Fader, whose state is not changed)
1969 * @param state New active state for those processors.
1972 Route::all_visible_processors_active (bool state)
1974 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1976 if (_processors.empty()) {
1980 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1981 if (!(*i)->display_to_user() || boost::dynamic_pointer_cast<Amp> (*i)) {
1985 boost::shared_ptr<PluginInsert> pi;
1986 if (0 != (pi = boost::dynamic_pointer_cast<PluginInsert>(*i))) {
1987 if (pi->is_channelstrip ()) {
1992 (*i)->enable (state);
1995 _session.set_dirty ();
1999 Route::processors_reorder_needs_configure (const ProcessorList& new_order)
2001 /* check if re-order requires re-configuration of any processors
2002 * -> compare channel configuration for all processors
2004 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2005 ChanCount c = input_streams ();
2007 for (ProcessorList::const_iterator j = new_order.begin(); j != new_order.end(); ++j) {
2009 if (c != (*j)->input_streams()) {
2012 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2015 if ((*i)->input_streams() != c) {
2018 c = (*i)->output_streams();
2030 __attribute__((annotate("realtime")))
2033 Route::apply_processor_order (const ProcessorList& new_order)
2035 /* need to hold processor_lock; either read or write lock
2036 * and the engine process_lock.
2037 * Due to r/w lock ambiguity we can only assert the latter
2039 assert (!AudioEngine::instance()->process_lock().trylock());
2042 /* "new_order" is an ordered list of processors to be positioned according to "placement".
2043 * NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
2044 * processors in the current actual processor list that are hidden. Any visible processors
2045 * in the current list but not in "new_order" will be assumed to be deleted.
2048 /* "as_it_will_be" and "_processors" are lists of shared pointers.
2049 * actual memory usage is small, but insert/erase is not actually rt-safe :(
2050 * (note though that ::processors_reorder_needs_configure() ensured that
2051 * this function will only ever be called from the rt-thread if no processor were removed)
2053 * either way, I can't proove it, but an x-run due to re-order here is less likley
2054 * than an x-run-less 'ardour-silent cycle' both of which effectively "click".
2057 ProcessorList as_it_will_be;
2058 ProcessorList::iterator oiter;
2059 ProcessorList::const_iterator niter;
2061 oiter = _processors.begin();
2062 niter = new_order.begin();
2064 while (niter != new_order.end()) {
2066 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
2067 then append it to the temp list.
2069 Otherwise, see if the next processor in the old list is in the new list. if not,
2070 its been deleted. If its there, append it to the temp list.
2073 if (oiter == _processors.end()) {
2075 /* no more elements in the old list, so just stick the rest of
2076 the new order onto the temp list.
2079 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
2080 while (niter != new_order.end()) {
2087 if (!(*oiter)->display_to_user()) {
2089 as_it_will_be.push_back (*oiter);
2093 /* visible processor: check that its in the new order */
2095 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
2096 /* deleted: do nothing, shared_ptr<> will clean up */
2098 /* ignore this one, and add the next item from the new order instead */
2099 as_it_will_be.push_back (*niter);
2104 /* now remove from old order - its taken care of no matter what */
2105 oiter = _processors.erase (oiter);
2109 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
2111 /* If the meter is in a custom position, find it and make a rough note of its position */
2112 maybe_note_meter_position ();
2116 Route::move_instrument_down (bool postfader)
2118 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2119 ProcessorList new_order;
2120 boost::shared_ptr<Processor> instrument;
2121 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2122 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
2123 if (pi && pi->plugin ()->get_info ()->is_instrument ()) {
2125 } else if (instrument && *i == _amp) {
2127 new_order.push_back (*i);
2128 new_order.push_back (instrument);
2130 new_order.push_back (instrument);
2131 new_order.push_back (*i);
2134 new_order.push_back (*i);
2141 reorder_processors (new_order, 0);
2145 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
2147 // it a change is already queued, wait for it
2148 // (unless engine is stopped. apply immediately and proceed
2149 while (g_atomic_int_get (&_pending_process_reorder)) {
2150 if (!AudioEngine::instance()->running()) {
2151 DEBUG_TRACE (DEBUG::Processors, "offline apply queued processor re-order.\n");
2152 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2154 apply_processor_order(_pending_processor_order);
2155 setup_invisible_processors ();
2157 g_atomic_int_set (&_pending_process_reorder, 0);
2159 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2160 set_processor_positions ();
2162 // TODO rather use a semaphore or something.
2163 // but since ::reorder_processors() is called
2164 // from the GUI thread, this is fine..
2169 if (processors_reorder_needs_configure (new_order) || !AudioEngine::instance()->running()) {
2171 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2172 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2173 ProcessorState pstate (this);
2175 apply_processor_order (new_order);
2177 if (configure_processors_unlocked (err, &lm)) {
2185 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2186 set_processor_positions ();
2189 DEBUG_TRACE (DEBUG::Processors, "Queue clickless processor re-order.\n");
2190 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2192 // _pending_processor_order is protected by _processor_lock
2193 _pending_processor_order = new_order;
2194 g_atomic_int_set (&_pending_process_reorder, 1);
2197 /* update processor input/output latency
2198 * (total signal_latency does not change)
2200 update_signal_latency (true);
2206 Route::add_remove_sidechain (boost::shared_ptr<Processor> proc, bool add)
2208 boost::shared_ptr<PluginInsert> pi;
2209 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2213 if (pi->has_sidechain () == add) {
2214 return true; // ?? call failed, but result is as expected.
2218 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2219 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2220 if (i == _processors.end ()) {
2226 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ()); // take before Writerlock to avoid deadlock
2227 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2228 PBD::Unwinder<bool> uw (_in_sidechain_setup, true);
2230 lx.release (); // IO::add_port() and ~IO takes process lock - XXX check if this is safe
2232 if (!pi->add_sidechain ()) {
2236 if (!pi->del_sidechain ()) {
2242 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2247 pi->del_sidechain ();
2249 pi->add_sidechain ();
2250 // TODO restore side-chain's state.
2255 configure_processors_unlocked (0, &lm);
2258 if (pi->has_sidechain ()) {
2259 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
2262 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2263 _session.set_dirty ();
2268 Route::plugin_preset_output (boost::shared_ptr<Processor> proc, ChanCount outs)
2270 boost::shared_ptr<PluginInsert> pi;
2271 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2276 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2277 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2278 if (i == _processors.end ()) {
2284 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2285 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2287 const ChanCount& old (pi->preset_out ());
2288 if (!pi->set_preset_out (outs)) {
2289 return true; // no change, OK
2292 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2295 pi->set_preset_out (old);
2298 configure_processors_unlocked (0, &lm);
2301 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2302 _session.set_dirty ();
2307 Route::reset_plugin_insert (boost::shared_ptr<Processor> proc)
2310 return customize_plugin_insert (proc, 0, unused, unused);
2314 Route::customize_plugin_insert (boost::shared_ptr<Processor> proc, uint32_t count, ChanCount outs, ChanCount sinks)
2316 boost::shared_ptr<PluginInsert> pi;
2317 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2322 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2323 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2324 if (i == _processors.end ()) {
2330 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2331 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2333 bool old_cust = pi->custom_cfg ();
2334 uint32_t old_cnt = pi->get_count ();
2335 ChanCount old_chan = pi->output_streams ();
2336 ChanCount old_sinks = pi->natural_input_streams ();
2339 pi->set_custom_cfg (false);
2341 pi->set_custom_cfg (true);
2342 pi->set_count (count);
2343 pi->set_outputs (outs);
2344 pi->set_sinks (sinks);
2347 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2351 pi->set_count (old_cnt);
2352 pi->set_sinks (old_sinks);
2353 pi->set_outputs (old_chan);
2354 pi->set_custom_cfg (old_cust);
2358 configure_processors_unlocked (0, &lm);
2361 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2362 _session.set_dirty ();
2367 Route::set_strict_io (const bool enable)
2369 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2371 if (_strict_io != enable) {
2372 _strict_io = enable;
2373 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2374 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2375 boost::shared_ptr<PluginInsert> pi;
2376 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2377 pi->set_strict_io (_strict_io);
2381 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2385 _strict_io = !enable; // restore old value
2386 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2387 boost::shared_ptr<PluginInsert> pi;
2388 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2389 pi->set_strict_io (_strict_io);
2396 configure_processors (0);
2399 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2400 _session.set_dirty ();
2412 Route::get_template()
2414 return state(false);
2418 Route::state(bool full_state)
2420 if (!_session._template_state_dir.empty()) {
2421 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), _session._template_state_dir));
2424 XMLNode *node = new XMLNode("Route");
2425 ProcessorList::iterator i;
2427 node->set_property (X_("id"), id ());
2428 node->set_property (X_("name"), name());
2429 node->set_property (X_("default-type"), _default_type);
2430 node->set_property (X_("strict-io"), _strict_io);
2432 node->add_child_nocopy (_presentation_info.get_state());
2434 node->set_property (X_("active"), _active);
2435 node->set_property (X_("denormal-protection"), _denormal_protection);
2436 node->set_property (X_("meter-point"), _meter_point);
2437 node->set_property (X_("disk-io-point"), _disk_io_point);
2439 node->set_property (X_("meter-type"), _meter_type);
2442 node->set_property (X_("route-group"), _route_group->name());
2445 node->add_child_nocopy (_solo_control->get_state ());
2446 node->add_child_nocopy (_solo_isolate_control->get_state ());
2447 node->add_child_nocopy (_solo_safe_control->get_state ());
2449 node->add_child_nocopy (_input->state (full_state));
2450 node->add_child_nocopy (_output->state (full_state));
2451 node->add_child_nocopy (_mute_master->get_state ());
2453 node->add_child_nocopy (_mute_control->get_state ());
2454 node->add_child_nocopy (_phase_control->get_state ());
2457 node->add_child_nocopy (Automatable::get_automation_xml_state ());
2460 if (_comment.length()) {
2461 XMLNode *cmt = node->add_child ("Comment");
2462 cmt->add_content (_comment);
2466 node->add_child_nocopy (_pannable->state (full_state));
2470 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2471 for (i = _processors.begin(); i != _processors.end(); ++i) {
2472 if (*i == _delayline) {
2476 /* template save: do not include internal sends functioning as
2477 aux sends because the chance of the target ID
2478 in the session where this template is used
2481 similarly, do not save listen sends which connect to
2482 the monitor section, because these will always be
2485 boost::shared_ptr<InternalSend> is;
2487 if ((is = boost::dynamic_pointer_cast<InternalSend> (*i)) != 0) {
2488 if (is->role() == Delivery::Listen) {
2493 node->add_child_nocopy((*i)->state (full_state));
2498 node->add_child_copy (*_extra_xml);
2501 if (_custom_meter_position_noted) {
2502 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
2504 node->set_property (X_("processor-after-last-custom-meter"), after->id());
2508 if (!_session._template_state_dir.empty()) {
2509 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), ""));
2512 node->add_child_copy (Slavable::get_state());
2518 Route::set_state (const XMLNode& node, int version)
2520 if (version < 3000) {
2521 return set_state_2X (node, version);
2525 XMLNodeConstIterator niter;
2528 if (node.name() != "Route"){
2529 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2533 std::string route_name;
2534 if (node.get_property (X_("name"), route_name)) {
2535 Route::set_name (route_name);
2539 _initial_io_setup = true;
2541 Stripable::set_state (node, version);
2543 node.get_property (X_("strict-io"), _strict_io);
2546 /* monitor bus does not get a panner, but if (re)created
2547 via XML, it will already have one by the time we
2548 call ::set_state(). so ... remove it.
2553 /* add all processors (except amp, which is always present) */
2555 nlist = node.children();
2556 XMLNode processor_state (X_("processor_state"));
2558 Stateful::save_extra_xml (node);
2560 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2564 if (child->name() == IO::state_node_name) {
2565 std::string direction;
2566 if (!child->get_property (X_("direction"), direction)) {
2570 if (direction == "Input") {
2571 _input->set_state (*child, version);
2572 } else if (direction == "Output") {
2573 _output->set_state (*child, version);
2576 } else if (child->name() == X_("Processor")) {
2577 processor_state.add_child_copy (*child);
2578 } else if (child->name() == X_("Pannable")) {
2580 _pannable->set_state (*child, version);
2582 warning << string_compose (_("Pannable state found for route (%1) without a panner!"), name()) << endmsg;
2584 } else if (child->name() == Slavable::xml_node_name) {
2585 Slavable::set_state (*child, version);
2590 if (node.get_property (X_("meter-point"), mp)) {
2591 set_meter_point (mp, true);
2593 _meter->set_display_to_user (_meter_point == MeterCustom);
2598 if (node.get_property (X_("disk-io-point"), diop)) {
2600 _disk_writer->set_display_to_user (diop == DiskIOCustom);
2603 _disk_reader->set_display_to_user (diop == DiskIOCustom);
2605 set_disk_io_point (diop);
2608 node.get_property (X_("meter-type"), _meter_type);
2610 _initial_io_setup = false;
2612 set_processor_state (processor_state);
2614 // this looks up the internal instrument in processors
2615 reset_instrument_info();
2617 bool denormal_protection;
2618 if (node.get_property (X_("denormal-protection"), denormal_protection)) {
2619 set_denormal_protection (denormal_protection);
2622 /* convert old 3001 state */
2623 std::string phase_invert_str;
2624 if (node.get_property (X_("phase-invert"), phase_invert_str)) {
2625 _phase_control->set_phase_invert (boost::dynamic_bitset<> (phase_invert_str));
2629 if (node.get_property (X_("active"), is_active)) {
2630 set_active (is_active, this);
2633 std::string id_string;
2634 if (node.get_property (X_("processor-after-last-custom-meter"), id_string)) {
2635 PBD::ID id (id_string);
2636 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2637 ProcessorList::const_iterator i = _processors.begin ();
2638 while (i != _processors.end() && (*i)->id() != id) {
2642 if (i != _processors.end ()) {
2643 _processor_after_last_custom_meter = *i;
2644 _custom_meter_position_noted = true;
2648 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2651 if (child->name() == X_("Comment")) {
2653 /* XXX this is a terrible API design in libxml++ */
2655 XMLNode *cmt = *(child->children().begin());
2656 _comment = cmt->content();
2658 } else if (child->name() == Controllable::xml_node_name) {
2659 std::string control_name;
2660 if (!child->get_property (X_("name"), control_name)) {
2664 if (control_name == _solo_control->name()) {
2665 _solo_control->set_state (*child, version);
2666 } else if (control_name == _solo_safe_control->name()) {
2667 _solo_safe_control->set_state (*child, version);
2668 } else if (control_name == _solo_isolate_control->name()) {
2669 _solo_isolate_control->set_state (*child, version);
2670 } else if (control_name == _mute_control->name()) {
2671 _mute_control->set_state (*child, version);
2672 } else if (control_name == _phase_control->name()) {
2673 _phase_control->set_state (*child, version);
2675 Evoral::Parameter p = EventTypeMap::instance().from_symbol (control_name);
2676 if (p.type () >= MidiCCAutomation && p.type () < MidiSystemExclusiveAutomation) {
2677 boost::shared_ptr<AutomationControl> ac = automation_control (p, true);
2679 ac->set_state (*child, version);
2683 } else if (child->name() == MuteMaster::xml_node_name) {
2684 _mute_master->set_state (*child, version);
2686 } else if (child->name() == Automatable::xml_node_name) {
2687 set_automation_xml_state (*child, Evoral::Parameter(NullAutomation));
2692 _delayline->set_name (name ());
2699 Route::set_state_2X (const XMLNode& node, int version)
2703 XMLNodeConstIterator niter;
2705 XMLProperty const * prop;
2707 /* 2X things which still remain to be handled:
2713 if (node.name() != "Route") {
2714 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2718 Stripable::set_state (node, version);
2720 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2721 set_denormal_protection (string_to<bool> (prop->value()));
2724 if ((prop = node.property (X_("muted"))) != 0) {
2727 bool muted = string_to<bool> (prop->value());
2733 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2735 if (string_to<bool> (prop->value())){
2736 mute_point = mute_point + "PreFader";
2741 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2743 if (string_to<bool> (prop->value())){
2746 mute_point = mute_point + ",";
2749 mute_point = mute_point + "PostFader";
2754 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2756 if (string_to<bool> (prop->value())){
2759 mute_point = mute_point + ",";
2762 mute_point = mute_point + "Listen";
2767 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2769 if (string_to<bool> (prop->value())){
2772 mute_point = mute_point + ",";
2775 mute_point = mute_point + "Main";
2779 _mute_master->set_mute_points (mute_point);
2780 _mute_master->set_muted_by_self (true);
2784 if ((prop = node.property (X_("meter-point"))) != 0) {
2785 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2790 nlist = node.children ();
2791 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2795 if (child->name() == IO::state_node_name) {
2797 /* there is a note in IO::set_state_2X() about why we have to call
2801 _input->set_state_2X (*child, version, true);
2802 _output->set_state_2X (*child, version, false);
2804 if ((prop = child->property (X_("name"))) != 0) {
2805 Route::set_name (prop->value ());
2810 if ((prop = child->property (X_("active"))) != 0) {
2811 bool yn = string_to<bool> (prop->value());
2812 _active = !yn; // force switch
2813 set_active (yn, this);
2816 if ((prop = child->property (X_("gain"))) != 0) {
2819 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
2820 _amp->gain_control()->set_value (val, Controllable::NoGroup);
2824 /* Set up Panners in the IO */
2825 XMLNodeList io_nlist = child->children ();
2827 XMLNodeConstIterator io_niter;
2830 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
2832 io_child = *io_niter;
2834 if (io_child->name() == X_("Panner")) {
2835 _main_outs->panner_shell()->set_state(*io_child, version);
2836 } else if (io_child->name() == X_("Automation")) {
2837 /* IO's automation is for the fader */
2838 _amp->set_automation_xml_state (*io_child, Evoral::Parameter (GainAutomation));
2844 XMLNodeList redirect_nodes;
2846 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2850 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2851 redirect_nodes.push_back(child);
2856 set_processor_state_2X (redirect_nodes, version);
2858 Stateful::save_extra_xml (node);
2860 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2863 if (child->name() == X_("Comment")) {
2865 /* XXX this is a terrible API design in libxml++ */
2867 XMLNode *cmt = *(child->children().begin());
2868 _comment = cmt->content();
2870 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2871 if (prop->value() == X_("solo")) {
2872 _solo_control->set_state (*child, version);
2873 } else if (prop->value() == X_("mute")) {
2874 _mute_control->set_state (*child, version);
2884 Route::get_processor_state ()
2886 XMLNode* root = new XMLNode (X_("redirects"));
2887 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2888 root->add_child_nocopy ((*i)->state (true));
2895 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2897 /* We don't bother removing existing processors not in nList, as this
2898 method will only be called when creating a Route from scratch, not
2899 for undo purposes. Just put processors in at the appropriate place
2903 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2904 add_processor_from_xml_2X (**i, version);
2909 Route::set_processor_state (const XMLNode& node)
2911 const XMLNodeList &nlist = node.children();
2912 XMLNodeConstIterator niter;
2913 ProcessorList new_order;
2914 bool must_configure = false;
2916 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2918 XMLProperty* prop = (*niter)->property ("type");
2920 if (prop->value() == "amp") {
2921 _amp->set_state (**niter, Stateful::current_state_version);
2922 new_order.push_back (_amp);
2923 } else if (prop->value() == "trim") {
2924 _trim->set_state (**niter, Stateful::current_state_version);
2925 new_order.push_back (_trim);
2926 } else if (prop->value() == "meter") {
2927 _meter->set_state (**niter, Stateful::current_state_version);
2928 new_order.push_back (_meter);
2929 } else if (prop->value() == "delay") {
2931 } else if (prop->value() == "main-outs") {
2932 _main_outs->set_state (**niter, Stateful::current_state_version);
2933 } else if (prop->value() == "intreturn") {
2935 _intreturn.reset (new InternalReturn (_session));
2936 must_configure = true;
2938 _intreturn->set_state (**niter, Stateful::current_state_version);
2939 } else if (is_monitor() && prop->value() == "monitor") {
2940 if (!_monitor_control) {
2941 _monitor_control.reset (new MonitorProcessor (_session));
2942 must_configure = true;
2944 _monitor_control->set_state (**niter, Stateful::current_state_version);
2945 } else if (prop->value() == "capture") {
2946 /* CapturingProcessor should never be restored, it's always
2947 added explicitly when needed */
2948 } else if (prop->value() == "diskreader" && _disk_reader) {
2949 _disk_reader->set_state (**niter, Stateful::current_state_version);
2950 new_order.push_back (_disk_reader);
2951 } else if (prop->value() == "diskwriter" && _disk_writer) {
2952 _disk_writer->set_state (**niter, Stateful::current_state_version);
2953 new_order.push_back (_disk_writer);
2955 set_processor_state (**niter, prop, new_order, must_configure);
2959 ProcessorList old_list = _processors; // keep a copy
2961 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2962 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2963 /* re-assign _processors w/o process-lock.
2964 * if there's an IO-processor present in _processors but
2965 * not in new_order, it will be deleted and ~IO takes
2968 _processors = new_order;
2970 if (must_configure) {
2971 configure_processors_unlocked (0, &lm);
2974 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2976 (*i)->set_owner (this);
2977 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
2979 boost::shared_ptr<PluginInsert> pi;
2981 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
2982 if (pi->has_no_inputs ()) {
2983 _have_internal_generator = true;
2989 /* drop references w/o process-lock (I/O procs may re-take it in ~IO() */
2992 reset_instrument_info ();
2993 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2994 set_processor_positions ();
2998 Route::set_processor_state (XMLNode const & node, XMLProperty const* prop, ProcessorList& new_order, bool& must_configure)
3000 ProcessorList::iterator o;
3002 for (o = _processors.begin(); o != _processors.end(); ++o) {
3003 XMLProperty const * id_prop = node.property(X_("id"));
3004 if (id_prop && (*o)->id() == id_prop->value()) {
3005 (*o)->set_state (node, Stateful::current_state_version);
3006 new_order.push_back (*o);
3011 // If the processor (node) is not on the route then create it
3013 if (o == _processors.end()) {
3015 boost::shared_ptr<Processor> processor;
3017 if (prop->value() == "intsend") {
3019 processor.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), boost::shared_ptr<Route>(), Delivery::Aux, true));
3021 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
3022 prop->value() == "lv2" ||
3023 prop->value() == "windows-vst" ||
3024 prop->value() == "mac-vst" ||
3025 prop->value() == "lxvst" ||
3026 prop->value() == "luaproc" ||
3027 prop->value() == "audiounit") {
3029 if (_session.get_disable_all_loaded_plugins ()) {
3030 processor.reset (new UnknownProcessor (_session, node));
3032 processor.reset (new PluginInsert (_session));
3033 processor->set_owner (this);
3035 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
3036 pi->set_strict_io (true);
3040 } else if (prop->value() == "port") {
3042 processor.reset (new PortInsert (_session, _pannable, _mute_master));
3044 } else if (prop->value() == "send") {
3046 processor.reset (new Send (_session, _pannable, _mute_master, Delivery::Send, true));
3047 boost::shared_ptr<Send> send = boost::dynamic_pointer_cast<Send> (processor);
3048 send->SelfDestruct.connect_same_thread (*this,
3049 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (processor)));
3055 if (processor->set_state (node, Stateful::current_state_version) != 0) {
3056 /* This processor could not be configured. Turn it into a UnknownProcessor */
3057 processor.reset (new UnknownProcessor (_session, node));
3060 /* subscribe to Sidechain IO changes */
3061 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
3062 if (pi && pi->has_sidechain ()) {
3063 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
3066 /* we have to note the monitor send here, otherwise a new one will be created
3067 and the state of this one will be lost.
3069 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
3070 if (isend && isend->role() == Delivery::Listen) {
3071 _monitor_send = isend;
3074 /* it doesn't matter if invisible processors are added here, as they
3075 will be sorted out by setup_invisible_processors () shortly.
3078 new_order.push_back (processor);
3079 must_configure = true;
3085 Route::curve_reallocate ()
3087 // _gain_automation_curve.finish_resize ();
3088 // _pan_automation_curve.finish_resize ();
3092 Route::silence (samplecnt_t nframes)
3094 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3099 silence_unlocked (nframes);
3103 Route::silence_unlocked (samplecnt_t nframes)
3105 /* Must be called with the processor lock held */
3107 const samplepos_t now = _session.transport_sample ();
3111 _output->silence (nframes);
3113 // update owned automated controllables
3114 automation_run (now, nframes);
3116 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3117 boost::shared_ptr<PluginInsert> pi;
3119 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
3120 /* evaluate automated automation controls */
3121 pi->automation_run (now, nframes);
3122 /* skip plugins, they don't need anything when we're not active */
3126 (*i)->silence (nframes, now);
3129 if (nframes == _session.get_block_size()) {
3136 Route::add_internal_return ()
3139 _intreturn.reset (new InternalReturn (_session));
3140 add_processor (_intreturn, PreFader);
3145 Route::add_send_to_internal_return (InternalSend* send)
3147 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3149 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3150 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3153 return d->add_send (send);
3159 Route::remove_send_from_internal_return (InternalSend* send)
3161 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3163 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3164 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3167 return d->remove_send (send);
3173 Route::enable_monitor_send ()
3175 /* Caller must hold process lock */
3176 assert (!AudioEngine::instance()->process_lock().trylock());
3178 /* master never sends to monitor section via the normal mechanism */
3179 assert (!is_master ());
3180 assert (!is_monitor ());
3182 /* make sure we have one */
3183 if (!_monitor_send) {
3184 _monitor_send.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), _session.monitor_out(), Delivery::Listen));
3185 _monitor_send->set_display_to_user (false);
3189 configure_processors (0);
3192 /** Add an aux send to a route.
3193 * @param route route to send to.
3194 * @param before Processor to insert before, or 0 to insert at the end.
3197 Route::add_aux_send (boost::shared_ptr<Route> route, boost::shared_ptr<Processor> before)
3199 assert (route != _session.monitor_out ());
3202 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3204 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3206 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend> (*x);
3208 if (d && d->target_route() == route) {
3209 /* already listening via the specified IO: do nothing */
3217 boost::shared_ptr<InternalSend> listener;
3220 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
3221 listener.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), route, Delivery::Aux));
3224 add_processor (listener, before);
3226 } catch (failed_constructor& err) {
3234 Route::remove_aux_or_listen (boost::shared_ptr<Route> route)
3236 ProcessorStreams err;
3237 ProcessorList::iterator tmp;
3240 Glib::Threads::RWLock::ReaderLock rl(_processor_lock);
3242 /* have to do this early because otherwise processor reconfig
3243 * will put _monitor_send back in the list
3246 if (route == _session.monitor_out()) {
3247 _monitor_send.reset ();
3251 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3253 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
3255 if (d && d->target_route() == route) {
3257 if (remove_processor (*x, &err, false) > 0) {
3263 /* list could have been demolished while we dropped the lock
3266 if (_session.engine().connected()) {
3267 /* i/o processors cannot be removed if the engine is not running
3268 * so don't live-loop in case the engine is N/A or dies
3278 Route::set_comment (string cmt, void *src)
3282 _session.set_dirty ();
3286 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
3288 FeedRecord fr (other, via_sends_only);
3290 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
3292 if (!result.second) {
3294 /* already a record for "other" - make sure sends-only information is correct */
3295 if (!via_sends_only && result.first->sends_only) {
3296 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
3297 frp->sends_only = false;
3301 return result.second;
3305 Route::clear_fed_by ()
3311 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
3313 const FedBy& fed_by (other->fed_by());
3315 for (FedBy::const_iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
3316 boost::shared_ptr<Route> sr = f->r.lock();
3318 if (sr && (sr.get() == this)) {
3320 if (via_sends_only) {
3321 *via_sends_only = f->sends_only;
3332 Route::all_inputs () const
3334 /* TODO, if this works as expected,
3335 * cache the IOVector and maintain it via
3336 * input_change_handler(), sidechain_change_handler() etc
3339 ios.push_back (_input);
3341 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3342 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3344 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3345 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3348 iop = pi->sidechain();
3351 if (iop != 0 && iop->input()) {
3352 ios.push_back (iop->input());
3359 Route::all_outputs () const
3362 // _output is included via Delivery
3363 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3364 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3365 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3366 if (iop != 0 && iop->output()) {
3367 ios.push_back (iop->output());
3374 Route::direct_feeds_according_to_reality (boost::shared_ptr<Route> other, bool* via_send_only)
3376 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
3377 if (other->all_inputs().fed_by (_output)) {
3378 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
3379 if (via_send_only) {
3380 *via_send_only = false;
3386 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3388 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
3390 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3391 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3394 iop = pi->sidechain();
3398 boost::shared_ptr<const IO> iop_out = iop->output();
3399 if (other.get() == this && iop_out && iop->input() && iop_out->connected_to (iop->input())) {
3400 // TODO this needs a delaylines in the Insert to align connections (!)
3401 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed its own return (%2)\n", iop->name(), other->name()));
3404 if ((iop_out && other->all_inputs().fed_by (iop_out)) || iop->feeds (other)) {
3405 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
3406 if (via_send_only) {
3407 *via_send_only = true;
3411 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
3414 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
3419 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
3424 Route::direct_feeds_according_to_graph (boost::shared_ptr<Route> other, bool* via_send_only)
3426 return _session._current_route_graph.has (boost::dynamic_pointer_cast<Route> (shared_from_this ()), other, via_send_only);
3430 Route::feeds_according_to_graph (boost::shared_ptr<Route> other)
3432 return _session._current_route_graph.feeds (boost::dynamic_pointer_cast<Route> (shared_from_this ()), other);
3435 /** Called from the (non-realtime) butler thread when the transport is stopped */
3437 Route::non_realtime_transport_stop (samplepos_t now, bool flush)
3439 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3441 Automatable::non_realtime_transport_stop (now, flush);
3443 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3445 if (!_have_internal_generator && (Config->get_plugins_stop_with_transport() && flush)) {
3449 (*i)->non_realtime_transport_stop (now, flush);
3454 Route::input_change_handler (IOChange change, void * /*src*/)
3456 if ((change.type & IOChange::ConfigurationChanged)) {
3457 /* This is called with the process lock held if change
3458 contains ConfigurationChanged
3460 configure_processors (0);
3461 _phase_control->resize (_input->n_ports().n_audio ());
3462 io_changed (); /* EMIT SIGNAL */
3465 if (_solo_control->soloed_by_others_upstream() || _solo_isolate_control->solo_isolated_by_upstream()) {
3468 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3469 if (_input->connected()) {
3470 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3471 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3475 bool does_feed = (*i)->direct_feeds_according_to_reality (boost::dynamic_pointer_cast<Route> (shared_from_this()), &sends_only);
3476 if (does_feed && !sends_only) {
3477 if ((*i)->soloed()) {
3480 if ((*i)->solo_isolate_control()->solo_isolated()) {
3487 int delta = sbou - _solo_control->soloed_by_others_upstream();
3488 int idelta = ibou - _solo_isolate_control->solo_isolated_by_upstream();
3491 PBD::warning << string_compose (
3492 _("Invalid Solo-Isolate propagation: from:%1 new:%2 - old:%3 = delta:%4"),
3493 _name, ibou, _solo_isolate_control->solo_isolated_by_upstream(), idelta)
3498 if (_solo_control->soloed_by_others_upstream()) {
3499 // ignore new connections (they're not propagated)
3501 _solo_control->mod_solo_by_others_upstream (delta);
3505 if (_solo_isolate_control->solo_isolated_by_upstream()) {
3506 // solo-isolate currently only propagates downstream
3508 _solo_isolate_control->mod_solo_isolated_by_upstream (1);
3510 //_solo_isolated_by_upstream = ibou;
3513 // Session::route_solo_changed does not propagate indirect solo-changes
3514 // propagate downstream to tracks
3515 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3516 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3520 bool does_feed = feeds (*i, &sends_only);
3521 if (delta <= 0 && does_feed && !sends_only) {
3522 (*i)->solo_control()->mod_solo_by_others_upstream (delta);
3525 if (idelta < 0 && does_feed && !sends_only) {
3526 (*i)->solo_isolate_control()->mod_solo_isolated_by_upstream (-1);
3533 Route::output_change_handler (IOChange change, void * /*src*/)
3535 if (_initial_io_setup) {
3539 if ((change.type & IOChange::ConfigurationChanged)) {
3540 /* This is called with the process lock held if change
3541 contains ConfigurationChanged
3543 configure_processors (0);
3546 _session.reset_monitor_section();
3549 io_changed (); /* EMIT SIGNAL */
3552 if ((change.type & IOChange::ConnectionsChanged)) {
3554 /* do this ONLY if connections have changed. Configuration
3555 * changes do not, by themselves alter solo upstream or
3556 * downstream status.
3559 if (_solo_control->soloed_by_others_downstream()) {
3561 /* checking all all downstream routes for
3562 * explicit of implict solo is a rather drastic measure,
3563 * ideally the input_change_handler() of the other route
3564 * would propagate the change to us.
3566 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3567 if (_output->connected()) {
3568 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3569 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3573 bool does_feed = direct_feeds_according_to_reality (*i, &sends_only);
3574 if (does_feed && !sends_only) {
3575 if ((*i)->soloed()) {
3583 int delta = sbod - _solo_control->soloed_by_others_downstream();
3585 // do not allow new connections to change implicit solo (no propagation)
3586 _solo_control->mod_solo_by_others_downstream (delta);
3587 // Session::route_solo_changed() does not propagate indirect solo-changes
3588 // propagate upstream to tracks
3589 boost::shared_ptr<Route> shared_this = boost::dynamic_pointer_cast<Route> (shared_from_this());
3590 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3591 if ((*i).get() == this || !can_solo()) {
3595 bool does_feed = (*i)->feeds (shared_this, &sends_only);
3596 if (delta != 0 && does_feed && !sends_only) {
3597 (*i)->solo_control()->mod_solo_by_others_downstream (delta);
3607 Route::sidechain_change_handler (IOChange change, void* src)
3609 if (_initial_io_setup || _in_sidechain_setup) {
3613 input_change_handler (change, src);
3617 Route::pans_required () const
3619 if (n_outputs().n_audio() < 2) {
3623 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
3627 Route::flush_processor_buffers_locked (samplecnt_t nframes)
3629 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3630 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery> (*i);
3632 d->flush_buffers (nframes);
3634 boost::shared_ptr<PortInsert> p = boost::dynamic_pointer_cast<PortInsert> (*i);
3636 p->flush_buffers (nframes);
3643 Route::no_roll (pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, bool session_state_changing)
3645 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3651 return no_roll_unlocked (nframes, start_sample, end_sample, session_state_changing);
3655 Route::no_roll_unlocked (pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, bool session_state_changing)
3658 silence_unlocked (nframes);
3662 if (session_state_changing) {
3663 if (_session.transport_speed() != 0.0f) {
3664 /* we're rolling but some state is changing (e.g. our diskstream contents)
3665 so we cannot use them. Be silent till this is over.
3667 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
3669 silence_unlocked (nframes);
3672 /* we're really not rolling, so we're either delivery silence or actually
3673 monitoring, both of which are safe to do while session_state_changing is true.
3677 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3679 fill_buffers_with_input (bufs, _input, nframes);
3681 /* filter captured data before meter sees it */
3682 filter_input (bufs);
3684 passthru (bufs, start_sample, end_sample, nframes, 0, true, false);
3686 flush_processor_buffers_locked (nframes);
3691 Route::playback_latency (bool incl_downstream) const
3695 rv = _disk_reader->output_latency ();
3697 rv = _signal_latency;
3699 if (incl_downstream) {
3700 rv += _output->connected_latency (true);
3702 rv += _output->latency ();
3708 Route::latency_preroll (pframes_t nframes, samplepos_t& start_sample, samplepos_t& end_sample)
3710 samplecnt_t latency_preroll = _session.remaining_latency_preroll ();
3711 if (latency_preroll == 0) {
3714 if (!_disk_reader) {
3715 start_sample -= latency_preroll;
3716 end_sample -= latency_preroll;
3720 if (latency_preroll > playback_latency ()) {
3721 no_roll_unlocked (nframes, start_sample - latency_preroll, end_sample - latency_preroll, false);
3725 start_sample -= latency_preroll;
3726 end_sample -= latency_preroll;
3731 Route::roll (pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, int declick, bool& need_butler)
3733 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3740 silence_unlocked (nframes);
3741 if (_meter_point == MeterInput && ((_monitoring_control->monitoring_choice() & MonitorInput) || (!_disk_writer || _disk_writer->record_enabled()))) {
3746 if ((nframes = latency_preroll (nframes, start_sample, end_sample)) == 0) {
3752 BufferSet& bufs = _session.get_route_buffers (n_process_buffers ());
3754 fill_buffers_with_input (bufs, _input, nframes);
3756 /* filter captured data before meter sees it */
3757 filter_input (bufs);
3759 passthru (bufs, start_sample, end_sample, nframes, declick, (!_disk_writer || !_disk_writer->record_enabled()) && _session.transport_rolling(), true);
3761 if ((_disk_reader && _disk_reader->need_butler()) || (_disk_writer && _disk_writer->need_butler())) {
3765 flush_processor_buffers_locked (nframes);
3771 Route::silent_roll (pframes_t nframes, samplepos_t /*start_sample*/, samplepos_t /*end_sample*/, bool& /* need_butler */)
3774 flush_processor_buffers_locked (nframes);
3779 Route::flush_processors ()
3781 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3783 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3789 __attribute__((annotate("realtime")))
3792 Route::apply_processor_changes_rt ()
3794 int emissions = EmitNone;
3796 if (_pending_meter_point != _meter_point) {
3797 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3799 /* meters always have buffers for 'processor_max_streams'
3800 * they can be re-positioned without re-allocation */
3801 if (set_meter_point_unlocked()) {
3802 emissions |= EmitMeterChanged | EmitMeterVisibilityChange;;
3804 emissions |= EmitMeterChanged;
3809 bool changed = false;
3811 if (g_atomic_int_get (&_pending_process_reorder)) {
3812 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3814 apply_processor_order (_pending_processor_order);
3815 setup_invisible_processors ();
3817 g_atomic_int_set (&_pending_process_reorder, 0);
3818 emissions |= EmitRtProcessorChange;
3822 set_processor_positions ();
3823 /* update processor input/output latency
3824 * (total signal_latency does not change)
3826 update_signal_latency (true);
3828 if (emissions != 0) {
3829 g_atomic_int_set (&_pending_signals, emissions);
3832 return (!selfdestruct_sequence.empty ());
3836 Route::emit_pending_signals ()
3838 int sig = g_atomic_int_and (&_pending_signals, 0);
3839 if (sig & EmitMeterChanged) {
3840 _meter->emit_configuration_changed();
3841 meter_change (); /* EMIT SIGNAL */
3842 if (sig & EmitMeterVisibilityChange) {
3843 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3845 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3848 if (sig & EmitRtProcessorChange) {
3849 processors_changed (RouteProcessorChange (RouteProcessorChange::RealTimeChange)); /* EMIT SIGNAL */
3852 /* this would be a job for the butler.
3853 * Conceptually we should not take processe/processor locks here.
3854 * OTOH its more efficient (less overhead for summoning the butler and
3855 * telling her what do do) and signal emission is called
3856 * directly after the process callback, which decreases the chance
3857 * of x-runs when taking the locks.
3859 while (!selfdestruct_sequence.empty ()) {
3860 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
3861 if (selfdestruct_sequence.empty ()) { break; } // re-check with lock
3862 boost::shared_ptr<Processor> proc = selfdestruct_sequence.back ().lock ();
3863 selfdestruct_sequence.pop_back ();
3866 remove_processor (proc);
3872 Route::set_meter_point (MeterPoint p, bool force)
3874 if (_pending_meter_point == p && !force) {
3878 if (force || !AudioEngine::instance()->running()) {
3879 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3880 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3881 _pending_meter_point = p;
3882 _meter->emit_configuration_changed();
3883 meter_change (); /* EMIT SIGNAL */
3884 if (set_meter_point_unlocked()) {
3885 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3887 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3890 _pending_meter_point = p;
3896 __attribute__((annotate("realtime")))
3899 Route::set_meter_point_unlocked ()
3902 /* Caller must hold process and processor write lock */
3903 assert (!AudioEngine::instance()->process_lock().trylock());
3904 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3905 assert (!lm.locked ());
3908 _meter_point = _pending_meter_point;
3910 bool meter_was_visible_to_user = _meter->display_to_user ();
3912 if (!_custom_meter_position_noted) {
3913 maybe_note_meter_position ();
3916 if (_meter_point != MeterCustom) {
3918 _meter->set_display_to_user (false);
3920 setup_invisible_processors ();
3923 _meter->set_display_to_user (true);
3925 /* If we have a previous position for the custom meter, try to put it there */
3926 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
3928 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), after);
3929 if (i != _processors.end ()) {
3930 _processors.remove (_meter);
3931 _processors.insert (i, _meter);
3933 } else {// at end, right before the mains_out/panner
3934 _processors.remove (_meter);
3935 ProcessorList::iterator main = _processors.end();
3936 _processors.insert (--main, _meter);
3940 /* Set up the meter for its new position */
3942 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
3946 if (loc == _processors.begin()) {
3947 m_in = _input->n_ports();
3949 ProcessorList::iterator before = loc;
3951 m_in = (*before)->output_streams ();
3954 _meter->reflect_inputs (m_in);
3956 /* we do not need to reconfigure the processors, because the meter
3957 (a) is always ready to handle processor_max_streams
3958 (b) is always an N-in/N-out processor, and thus moving
3959 it doesn't require any changes to the other processors.
3962 /* these should really be done after releasing the lock
3963 * but all those signals are subscribed to with gui_thread()
3966 return (_meter->display_to_user() != meter_was_visible_to_user);
3970 Route::listen_position_changed ()
3973 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3974 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3975 ProcessorState pstate (this);
3977 if (configure_processors_unlocked (0, &lm)) {
3978 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
3980 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
3985 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3986 _session.set_dirty ();
3989 boost::shared_ptr<CapturingProcessor>
3990 Route::add_export_point()
3992 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3993 if (!_capturing_processor) {
3995 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3996 Glib::Threads::RWLock::WriterLock lw (_processor_lock);
3998 /* Align all tracks for stem-export w/o processing.
3999 * Compensate for all plugins between the this route's disk-reader
4000 * and the common final downstream output (ie alignment point for playback).
4002 _capturing_processor.reset (new CapturingProcessor (_session, playback_latency (true)));
4003 configure_processors_unlocked (0, &lw);
4004 _capturing_processor->activate ();
4007 return _capturing_processor;
4011 Route::update_signal_latency (bool apply_to_delayline)
4013 // TODO: bail out if !active() and set/assume _signal_latency = 0,
4014 // here or in Session::* ? -> also zero send latencies,
4015 // and make sure that re-enabling a route updates things again...
4017 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4019 samplecnt_t l_in = 0;
4020 samplecnt_t l_out = _output->user_latency();
4021 for (ProcessorList::reverse_iterator i = _processors.rbegin(); i != _processors.rend(); ++i) {
4022 if (boost::shared_ptr<Send> snd = boost::dynamic_pointer_cast<Send> (*i)) {
4023 snd->set_delay_in (l_out + _output->latency());
4025 (*i)->set_output_latency (l_out);
4026 if ((*i)->active ()) {
4027 l_out += (*i)->signal_latency ();
4031 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal signal latency = %2\n", _name, l_out));
4033 _signal_latency = l_out;
4035 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4036 (*i)->set_input_latency (l_in);
4037 (*i)->set_playback_offset (_signal_latency + _output->latency ());
4038 (*i)->set_capture_offset (_input->latency ());
4039 if ((*i)->active ()) {
4040 l_in += (*i)->signal_latency ();
4046 if (apply_to_delayline) {
4047 /* see also Session::post_playback_latency() */
4048 apply_latency_compensation ();
4051 if (_signal_latency != l_out) {
4052 signal_latency_changed (); /* EMIT SIGNAL */
4055 return _signal_latency;
4059 Route::set_user_latency (samplecnt_t nframes)
4061 _output->set_user_latency (nframes);
4062 _session.update_latency_compensation ();
4066 Route::apply_latency_compensation ()
4069 samplecnt_t old = _delayline->get_delay ();
4071 samplecnt_t play_lat_in = _input->connected_latency (true);
4072 samplecnt_t play_lat_out = _output->connected_latency (true);
4073 samplecnt_t latcomp = play_lat_in - play_lat_out - _signal_latency;
4076 samplecnt_t capt_lat_in = _input->connected_latency (false);
4077 samplecnt_t capt_lat_out = _output->connected_latency (false);
4078 samplecnt_t latcomp_capt = capt_lat_out - capt_lat_in - _signal_latency;
4080 cout << "ROUTE " << name() << " delay for " << latcomp << " (c: " << latcomp_capt << ")" << endl;
4083 _delayline->set_delay (latcomp > 0 ? latcomp : 0);
4085 if (old != _delayline->get_delay ()) {
4086 signal_latency_updated (); /* EMIT SIGNAL */
4092 Route::set_block_size (pframes_t nframes)
4094 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4095 (*i)->set_block_size (nframes);
4098 _session.ensure_buffers (n_process_buffers ());
4102 Route::protect_automation ()
4104 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
4105 (*i)->protect_automation();
4108 /** @param declick 1 to set a pending declick fade-in,
4109 * -1 to set a pending declick fade-out
4112 Route::set_pending_declick (int declick)
4115 /* this call is not allowed to turn off a pending declick */
4117 _pending_declick = declick;
4120 _pending_declick = 0;
4124 /** Shift automation forwards from a particular place, thereby inserting time.
4125 * Adds undo commands for any shifts that are performed.
4127 * @param pos Position to start shifting from.
4128 * @param samples Amount to shift forwards by.
4132 Route::shift (samplepos_t pos, samplecnt_t samples)
4134 /* gain automation */
4136 boost::shared_ptr<AutomationControl> gc = _amp->gain_control();
4138 XMLNode &before = gc->alist()->get_state ();
4139 gc->alist()->shift (pos, samples);
4140 XMLNode &after = gc->alist()->get_state ();
4141 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
4144 /* gain automation */
4146 boost::shared_ptr<AutomationControl> gc = _trim->gain_control();
4148 XMLNode &before = gc->alist()->get_state ();
4149 gc->alist()->shift (pos, samples);
4150 XMLNode &after = gc->alist()->get_state ();
4151 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
4154 // TODO mute automation ??
4156 /* pan automation */
4158 ControlSet::Controls& c (_pannable->controls());
4160 for (ControlSet::Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
4161 boost::shared_ptr<AutomationControl> pc = boost::dynamic_pointer_cast<AutomationControl> (ci->second);
4163 boost::shared_ptr<AutomationList> al = pc->alist();
4164 XMLNode& before = al->get_state ();
4165 al->shift (pos, samples);
4166 XMLNode& after = al->get_state ();
4167 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4172 /* redirect automation */
4174 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4175 for (ProcessorList::iterator i = _processors.begin (); i != _processors.end (); ++i) {
4177 set<Evoral::Parameter> parameters = (*i)->what_can_be_automated();
4179 for (set<Evoral::Parameter>::const_iterator p = parameters.begin (); p != parameters.end (); ++p) {
4180 boost::shared_ptr<AutomationControl> ac = (*i)->automation_control (*p);
4182 boost::shared_ptr<AutomationList> al = ac->alist();
4183 XMLNode &before = al->get_state ();
4184 al->shift (pos, samples);
4185 XMLNode &after = al->get_state ();
4186 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4194 Route::set_plugin_state_dir (boost::weak_ptr<Processor> p, const std::string& d)
4196 boost::shared_ptr<Processor> processor (p.lock ());
4197 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
4201 pi->set_state_dir (d);
4205 Route::save_as_template (const string& path, const string& name, const string& description)
4207 std::string state_dir = path.substr (0, path.find_last_of ('.')); // strip template_suffix
4208 PBD::Unwinder<std::string> uw (_session._template_state_dir, state_dir);
4210 XMLNode& node (state (false));
4211 node.set_property (X_("name"), name);
4213 node.remove_nodes (X_("description"));
4214 if (!description.empty()) {
4215 XMLNode* desc = new XMLNode(X_("description"));
4216 XMLNode* desc_cont = new XMLNode(X_("content"), description);
4217 desc->add_child_nocopy (*desc_cont);
4219 node.add_child_nocopy (*desc);
4224 IO::set_name_in_state (*node.children().front(), name);
4226 tree.set_root (&node);
4228 /* return zero on success, non-zero otherwise */
4229 return !tree.write (path.c_str());
4234 Route::set_name (const string& str)
4240 if (str == name()) {
4244 string name = Route::ensure_track_or_route_name (str, _session);
4245 SessionObject::set_name (name);
4247 bool ret = (_input->set_name(name) && _output->set_name(name));
4250 /* rename the main outs. Leave other IO processors
4251 * with whatever name they already have, because its
4252 * just fine as it is (it will not contain the route
4253 * name if its a port insert, port send or port return).
4257 if (_main_outs->set_name (name)) {
4258 /* XXX returning false here is stupid because
4259 we already changed the route name.
4269 /** Set the name of a route in an XML description.
4270 * @param node XML <Route> node to set the name in.
4271 * @param name New name.
4274 Route::set_name_in_state (XMLNode& node, string const & name, bool rename_playlist)
4276 node.set_property (X_("name"), name);
4278 XMLNodeList children = node.children();
4279 for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
4281 if ((*i)->name() == X_("IO")) {
4283 IO::set_name_in_state (**i, name);
4285 } else if ((*i)->name() == X_("Processor")) {
4288 if ((*i)->get_property (X_("role"), str) && str == X_("Main")) {
4289 (*i)->set_property (X_("name"), name);
4292 } else if ((*i)->name() == X_("Diskstream")) {
4294 if (rename_playlist) {
4295 (*i)->set_property (X_("playlist"), name + ".1");
4297 (*i)->set_property (X_("name"), name);
4303 boost::shared_ptr<Send>
4304 Route::internal_send_for (boost::shared_ptr<const Route> target) const
4306 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4308 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4309 boost::shared_ptr<InternalSend> send;
4311 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
4312 if (send->target_route() == target) {
4318 return boost::shared_ptr<Send>();
4322 Route::set_denormal_protection (bool yn)
4324 if (_denormal_protection != yn) {
4325 _denormal_protection = yn;
4326 denormal_protection_changed (); /* EMIT SIGNAL */
4331 Route::denormal_protection () const
4333 return _denormal_protection;
4337 Route::set_active (bool yn, void* src)
4339 if (_session.transport_rolling()) {
4343 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_route_active()) {
4344 _route_group->foreach_route (boost::bind (&Route::set_active, _1, yn, _route_group));
4348 if (_active != yn) {
4350 _input->set_active (yn);
4351 _output->set_active (yn);
4352 flush_processors ();
4353 active_changed (); // EMIT SIGNAL
4354 _session.set_dirty ();
4358 boost::shared_ptr<Pannable>
4359 Route::pannable() const
4364 boost::shared_ptr<Panner>
4365 Route::panner() const
4368 return _main_outs->panner_shell()->panner();
4371 boost::shared_ptr<PannerShell>
4372 Route::panner_shell() const
4374 return _main_outs->panner_shell();
4377 boost::shared_ptr<GainControl>
4378 Route::gain_control() const
4380 return _gain_control;
4383 boost::shared_ptr<GainControl>
4384 Route::trim_control() const
4386 return _trim_control;
4389 boost::shared_ptr<PhaseControl>
4390 Route::phase_control() const
4392 return _phase_control;
4395 boost::shared_ptr<AutomationControl>
4396 Route::get_control (const Evoral::Parameter& param)
4398 /* either we own the control or .... */
4400 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
4404 /* maybe one of our processors does or ... */
4406 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
4407 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4408 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
4416 /* nobody does so we'll make a new one */
4418 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
4425 boost::shared_ptr<Processor>
4426 Route::nth_plugin (uint32_t n) const
4428 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4429 ProcessorList::const_iterator i;
4431 for (i = _processors.begin(); i != _processors.end(); ++i) {
4432 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
4439 return boost::shared_ptr<Processor> ();
4442 boost::shared_ptr<Processor>
4443 Route::nth_send (uint32_t n) const
4445 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4446 ProcessorList::const_iterator i;
4448 for (i = _processors.begin(); i != _processors.end(); ++i) {
4449 if (boost::dynamic_pointer_cast<Send> (*i)) {
4451 if ((*i)->name().find (_("Monitor")) == 0) {
4452 /* send to monitor section is not considered
4453 to be an accessible send.
4464 return boost::shared_ptr<Processor> ();
4468 Route::has_io_processor_named (const string& name)
4470 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4471 ProcessorList::iterator i;
4473 for (i = _processors.begin(); i != _processors.end(); ++i) {
4474 if (boost::dynamic_pointer_cast<Send> (*i) ||
4475 boost::dynamic_pointer_cast<PortInsert> (*i)) {
4476 if ((*i)->name() == name) {
4486 Route::set_processor_positions ()
4488 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4490 bool had_amp = false;
4491 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4492 (*i)->set_pre_fader (!had_amp);
4499 /** Called when there is a proposed change to the input port count */
4501 Route::input_port_count_changing (ChanCount to)
4503 list<pair<ChanCount, ChanCount> > c = try_configure_processors (to, 0);
4505 /* The processors cannot be configured with the new input arrangement, so
4511 /* The change is ok */
4515 /** Called when there is a proposed change to the output port count */
4517 Route::output_port_count_changing (ChanCount to)
4519 if (_strict_io && !_in_configure_processors) {
4522 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
4523 if (processor_out_streams.get(*t) > to.get(*t)) {
4527 /* The change is ok */
4532 Route::unknown_processors () const
4536 if (_session.get_disable_all_loaded_plugins ()) {
4537 // Do not list "missing plugins" if they are explicitly disabled
4541 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4542 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4543 if (boost::dynamic_pointer_cast<UnknownProcessor const> (*i)) {
4544 p.push_back ((*i)->name ());
4553 Route::update_port_latencies (PortSet& from, PortSet& to, bool playback, samplecnt_t our_latency) const
4555 /* we assume that all our input ports feed all our output ports. its not
4556 universally true, but the alternative is way too corner-case to worry about.
4559 LatencyRange all_connections;
4562 all_connections.min = 0;
4563 all_connections.max = 0;
4565 all_connections.min = ~((pframes_t) 0);
4566 all_connections.max = 0;
4568 /* iterate over all "from" ports and determine the latency range for all of their
4569 connections to the "outside" (outside of this Route).
4572 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4576 p->get_connected_latency_range (range, playback);
4578 all_connections.min = min (all_connections.min, range.min);
4579 all_connections.max = max (all_connections.max, range.max);
4583 /* set the "from" port latencies to the max/min range of all their connections */
4585 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4586 p->set_private_latency_range (all_connections, playback);
4589 /* set the ports "in the direction of the flow" to the same value as above plus our own signal latency */
4591 all_connections.min += our_latency;
4592 all_connections.max += our_latency;
4594 for (PortSet::iterator p = to.begin(); p != to.end(); ++p) {
4595 p->set_private_latency_range (all_connections, playback);
4598 return all_connections.max;
4602 Route::set_private_port_latencies (bool playback) const
4604 samplecnt_t own_latency = 0;
4606 /* Processor list not protected by lock: MUST BE CALLED FROM PROCESS THREAD
4607 OR LATENCY CALLBACK.
4609 This is called (early) from the latency callback. It computes the REAL
4610 latency associated with each port and stores the result as the "private"
4611 latency of the port. A later call to Route::set_public_port_latencies()
4612 sets all ports to the same value to reflect the fact that we do latency
4613 compensation and so all signals are delayed by the same amount as they
4614 flow through ardour.
4617 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4618 if ((*i)->active ()) {
4619 own_latency += (*i)->signal_latency ();
4624 /* playback: propagate latency from "outside the route" to outputs to inputs */
4625 return update_port_latencies (_output->ports (), _input->ports (), true, own_latency);
4627 /* capture: propagate latency from "outside the route" to inputs to outputs */
4628 return update_port_latencies (_input->ports (), _output->ports (), false, own_latency);
4633 Route::set_public_port_latencies (samplecnt_t value, bool playback) const
4635 /* this is called to set the JACK-visible port latencies, which take
4636 latency compensation into account.
4645 const PortSet& ports (_input->ports());
4646 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4647 p->set_public_latency_range (range, playback);
4652 const PortSet& ports (_output->ports());
4653 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4654 p->set_public_latency_range (range, playback);
4659 /** Put the invisible processors in the right place in _processors.
4660 * Must be called with a writer lock on _processor_lock held.
4663 __attribute__((annotate("realtime")))
4666 Route::setup_invisible_processors ()
4669 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4670 assert (!lm.locked ());
4674 /* too early to be doing this stuff */
4678 /* we'll build this new list here and then use it
4680 * TODO put the ProcessorList is on the stack for RT-safety.
4683 ProcessorList new_processors;
4684 ProcessorList::iterator dr;
4685 ProcessorList::iterator dw;
4687 /* find visible processors */
4689 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4690 if ((*i)->display_to_user ()) {
4691 new_processors.push_back (*i);
4697 ProcessorList::iterator amp = find (new_processors.begin(), new_processors.end(), _amp);
4699 if (amp == new_processors.end ()) {
4700 error << string_compose (_("Amp/Fader on Route '%1' went AWOL. Re-added."), name()) << endmsg;
4701 new_processors.push_front (_amp);
4702 amp = find (new_processors.begin(), new_processors.end(), _amp);
4705 /* and the processor after the amp */
4707 ProcessorList::iterator after_amp = amp;
4710 /* Pre-fader METER */
4712 if (_meter && _meter_point == MeterPreFader) {
4713 /* add meter just before the fader */
4714 assert (!_meter->display_to_user ());
4715 new_processors.insert (amp, _meter);
4720 assert (_main_outs);
4721 assert (!_main_outs->display_to_user ());
4722 new_processors.push_back (_main_outs);
4724 /* iterator for the main outs */
4726 ProcessorList::iterator main = new_processors.end();
4729 /* OUTPUT METERING */
4731 if (_meter && (_meter_point == MeterOutput || _meter_point == MeterPostFader)) {
4732 assert (!_meter->display_to_user ());
4734 /* add the processor just before or just after the main outs */
4736 ProcessorList::iterator meter_point = main;
4738 if (_meter_point == MeterOutput) {
4741 new_processors.insert (meter_point, _meter);
4746 if (_monitor_send && !is_monitor ()) {
4747 assert (!_monitor_send->display_to_user ());
4748 switch (Config->get_listen_position ()) {
4749 case PreFaderListen:
4750 switch (Config->get_pfl_position ()) {
4751 case PFLFromBeforeProcessors:
4752 new_processors.push_front (_monitor_send);
4754 case PFLFromAfterProcessors:
4755 new_processors.insert (amp, _monitor_send);
4758 _monitor_send->set_can_pan (false);
4760 case AfterFaderListen:
4761 switch (Config->get_afl_position ()) {
4762 case AFLFromBeforeProcessors:
4763 new_processors.insert (after_amp, _monitor_send);
4765 case AFLFromAfterProcessors:
4766 new_processors.insert (new_processors.end(), _monitor_send);
4769 _monitor_send->set_can_pan (true);
4774 /* MONITOR CONTROL */
4776 if (_monitor_control && is_monitor ()) {
4777 assert (!_monitor_control->display_to_user ());
4778 new_processors.insert (amp, _monitor_control);
4783 ProcessorList::iterator trim = new_processors.end();
4785 if (_trim->active()) {
4786 assert (!_trim->display_to_user ());
4787 new_processors.push_front (_trim);
4788 trim = new_processors.begin();
4791 /* INTERNAL RETURN */
4793 /* doing this here means that any monitor control will come after
4794 the return and trim.
4798 assert (!_intreturn->display_to_user ());
4799 new_processors.push_front (_intreturn);
4802 /* DISK READER & WRITER (for Track objects) */
4804 if (_disk_reader || _disk_writer) {
4805 switch (_disk_io_point) {
4806 case DiskIOPreFader:
4807 if (trim != new_processors.end()) {
4808 /* insert BEFORE TRIM */
4810 new_processors.insert (trim, _disk_writer);
4813 new_processors.insert (trim, _disk_reader);
4817 new_processors.push_front (_disk_writer);
4820 new_processors.push_front (_disk_reader);
4824 case DiskIOPostFader:
4825 /* insert BEFORE main outs */
4827 new_processors.insert (main, _disk_writer);
4830 new_processors.insert (main, _disk_reader);
4834 /* reader and writer are visible under this condition, so they
4835 * are not invisible and thus not handled here.
4841 /* ensure dist-writer is before disk-reader */
4842 if (_disk_reader && _disk_writer) {
4843 ProcessorList::iterator reader_pos = find (new_processors.begin(), new_processors.end(), _disk_reader);
4844 ProcessorList::iterator writer_pos = find (new_processors.begin(), new_processors.end(), _disk_writer);
4845 assert (reader_pos != new_processors.end ());
4846 assert (writer_pos != new_processors.end ());
4847 if (std::distance (new_processors.begin(), reader_pos) < std::distance (new_processors.begin(), writer_pos)) {
4848 new_processors.erase (reader_pos);
4849 assert (writer_pos == find (new_processors.begin(), new_processors.end(), _disk_writer));
4850 new_processors.insert (++writer_pos, _disk_reader);
4855 /* EXPORT PROCESSOR */
4856 if (_capturing_processor) {
4857 assert (!_capturing_processor->display_to_user ());
4858 ProcessorList::iterator reader_pos = find (new_processors.begin(), new_processors.end(), _disk_reader);
4859 if (reader_pos != new_processors.end()) {
4860 /* insert after disk-reader */
4861 new_processors.insert (++reader_pos, _capturing_processor);
4863 new_processors.push_front (_capturing_processor);
4868 if (_meter && _meter_point == MeterInput) {
4869 /* add meter just before the disk-writer (if any)
4870 * otherwise at the top, but after the latency delayline
4871 * (perhaps it should also be after intreturn on busses ??)
4873 assert (!_meter->display_to_user ());
4874 ProcessorList::iterator writer_pos = find (new_processors.begin(), new_processors.end(), _disk_writer);
4875 if (writer_pos != new_processors.end()) {
4876 new_processors.insert (writer_pos, _meter);
4878 new_processors.push_front (_meter);
4882 if (!is_master() && !is_monitor() && !is_auditioner()) {
4883 ProcessorList::iterator reader_pos = find (new_processors.begin(), new_processors.end(), _disk_reader);
4884 if (reader_pos != new_processors.end()) {
4885 /* insert before disk-reader */
4886 new_processors.insert (reader_pos, _delayline);
4888 new_processors.push_front (_delayline);
4892 _processors = new_processors;
4894 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4895 if (!(*i)->display_to_user () && !(*i)->enabled () && (*i) != _monitor_send) {
4896 (*i)->enable (true);
4900 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: setup_invisible_processors\n", _name));
4901 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4902 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1\n", (*i)->name ()));
4909 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
4910 Glib::Threads::RWLock::ReaderLock lp (_processor_lock);
4914 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4915 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*i);
4922 /** If the meter point is `Custom', make a note of where the meter is.
4923 * This is so that if the meter point is subsequently set to something else,
4924 * and then back to custom, we can put the meter back where it was last time
4925 * custom was enabled.
4927 * Must be called with the _processor_lock held.
4930 Route::maybe_note_meter_position ()
4932 if (_meter_point != MeterCustom) {
4936 _custom_meter_position_noted = true;
4937 /* custom meter points range from after trim to before panner/main_outs
4938 * this is a limitation by the current processor UI
4940 bool seen_trim = false;
4941 _processor_after_last_custom_meter.reset();
4942 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4943 if ((*i) == _trim) {
4946 if ((*i) == _main_outs) {
4947 _processor_after_last_custom_meter = *i;
4950 if (boost::dynamic_pointer_cast<PeakMeter> (*i)) {
4952 _processor_after_last_custom_meter = _trim;
4954 ProcessorList::iterator j = i;
4956 assert(j != _processors.end ()); // main_outs should be before
4957 _processor_after_last_custom_meter = *j;
4962 assert(_processor_after_last_custom_meter.lock());
4965 boost::shared_ptr<Processor>
4966 Route::processor_by_id (PBD::ID id) const
4968 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4969 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4970 if ((*i)->id() == id) {
4975 return boost::shared_ptr<Processor> ();
4978 /** @return what we should be metering; either the data coming from the input
4979 * IO or the data that is flowing through the route.
4982 Route::metering_state () const
4984 return MeteringRoute;
4988 Route::has_external_redirects () const
4990 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4992 /* ignore inactive processors and obviously ignore the main
4993 * outs since everything has them and we don't care.
4996 if ((*i)->active() && (*i) != _main_outs && (*i)->does_routing()) {
5004 boost::shared_ptr<Processor>
5005 Route::the_instrument () const
5007 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5008 return the_instrument_unlocked ();
5011 boost::shared_ptr<Processor>
5012 Route::the_instrument_unlocked () const
5014 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5015 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
5016 if (pi && pi->plugin ()->get_info ()->is_instrument ()) {
5020 return boost::shared_ptr<Processor>();
5026 Route::non_realtime_locate (samplepos_t pos)
5028 Automatable::non_realtime_locate (pos);
5031 _pannable->non_realtime_locate (pos);
5034 #if 0 // XXX mayhaps clear delayline here (and at stop?)
5036 _delayline->flush ();
5041 //Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
5042 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5044 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5045 (*i)->non_realtime_locate (pos);
5051 Route::fill_buffers_with_input (BufferSet& bufs, boost::shared_ptr<IO> io, pframes_t nframes)
5058 * We don't currently mix MIDI input together, so we don't need the
5059 * complex logic of the audio case.
5062 n_buffers = bufs.count().n_midi ();
5064 for (i = 0; i < n_buffers; ++i) {
5066 boost::shared_ptr<MidiPort> source_port = io->midi (i);
5067 MidiBuffer& buf (bufs.get_midi (i));
5070 buf.copy (source_port->get_midi_buffer(nframes));
5072 buf.silence (nframes);
5078 n_buffers = bufs.count().n_audio();
5080 size_t n_ports = io->n_ports().n_audio();
5081 float scaling = 1.0f;
5083 if (n_ports > n_buffers) {
5084 scaling = ((float) n_buffers) / n_ports;
5087 for (i = 0; i < n_ports; ++i) {
5089 /* if there are more ports than buffers, map them onto buffers
5090 * in a round-robin fashion
5093 boost::shared_ptr<AudioPort> source_port = io->audio (i);
5094 AudioBuffer& buf (bufs.get_audio (i%n_buffers));
5096 if (i < n_buffers) {
5098 /* first time through just copy a channel into
5102 buf.read_from (source_port->get_audio_buffer (nframes), nframes);
5104 if (scaling != 1.0f) {
5105 buf.apply_gain (scaling, nframes);
5110 /* on subsequent times around, merge data from
5111 * the port with what is already there
5114 if (scaling != 1.0f) {
5115 buf.accumulate_with_gain_from (source_port->get_audio_buffer (nframes), nframes, 0, scaling);
5117 buf.accumulate_from (source_port->get_audio_buffer (nframes), nframes);
5122 /* silence any remaining buffers */
5124 for (; i < n_buffers; ++i) {
5125 AudioBuffer& buf (bufs.get_audio (i));
5126 buf.silence (nframes);
5129 /* establish the initial setup of the buffer set, reflecting what was
5130 copied into it. unless, of course, we are the auditioner, in which
5131 case nothing was fed into it from the inputs at all.
5134 if (!is_auditioner()) {
5135 bufs.set_count (io->n_ports());
5139 boost::shared_ptr<AutomationControl>
5140 Route::pan_azimuth_control() const
5143 # undef MIXBUS_PORTS_H
5144 # include "../../gtk2_ardour/mixbus_ports.h"
5145 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5147 return boost::shared_ptr<AutomationControl>();
5149 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_pan)));
5151 if (!_pannable || !panner()) {
5152 return boost::shared_ptr<AutomationControl>();
5154 return _pannable->pan_azimuth_control;
5158 boost::shared_ptr<AutomationControl>
5159 Route::pan_elevation_control() const
5161 if (Profile->get_mixbus() || !_pannable || !panner()) {
5162 return boost::shared_ptr<AutomationControl>();
5165 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5167 if (c.find (PanElevationAutomation) != c.end()) {
5168 return _pannable->pan_elevation_control;
5170 return boost::shared_ptr<AutomationControl>();
5173 boost::shared_ptr<AutomationControl>
5174 Route::pan_width_control() const
5177 if (mixbus() && _ch_pre) {
5179 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl>(_ch_pre->control(Evoral::Parameter(PluginAutomation, 0, 5)));
5182 if (Profile->get_mixbus() || !_pannable || !panner()) {
5183 return boost::shared_ptr<AutomationControl>();
5186 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5188 if (c.find (PanWidthAutomation) != c.end()) {
5189 return _pannable->pan_width_control;
5191 return boost::shared_ptr<AutomationControl>();
5194 boost::shared_ptr<AutomationControl>
5195 Route::pan_frontback_control() const
5197 if (Profile->get_mixbus() || !_pannable || !panner()) {
5198 return boost::shared_ptr<AutomationControl>();
5201 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5203 if (c.find (PanFrontBackAutomation) != c.end()) {
5204 return _pannable->pan_frontback_control;
5206 return boost::shared_ptr<AutomationControl>();
5209 boost::shared_ptr<AutomationControl>
5210 Route::pan_lfe_control() const
5212 if (Profile->get_mixbus() || !_pannable || !panner()) {
5213 return boost::shared_ptr<AutomationControl>();
5216 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5218 if (c.find (PanLFEAutomation) != c.end()) {
5219 return _pannable->pan_lfe_control;
5221 return boost::shared_ptr<AutomationControl>();
5226 Route::eq_band_cnt () const
5228 if (Profile->get_mixbus()) {
5230 if (is_master() || mixbus()) {
5239 /* Ardour has no well-known EQ object */
5244 boost::shared_ptr<AutomationControl>
5245 Route::eq_gain_controllable (uint32_t band) const
5248 boost::shared_ptr<PluginInsert> eq = ch_eq();
5251 return boost::shared_ptr<AutomationControl>();
5254 uint32_t port_number;
5255 if (is_master() || mixbus()) {
5257 case 0: port_number = 4; break;
5258 case 1: port_number = 3; break;
5259 case 2: port_number = 2; break;
5261 return boost::shared_ptr<AutomationControl>();
5266 case 0: port_number = 14; break;
5267 case 1: port_number = 12; break;
5268 case 2: port_number = 10; break;
5269 case 3: port_number = 8; break;
5271 return boost::shared_ptr<AutomationControl>();
5275 case 0: port_number = 8; break;
5276 case 1: port_number = 6; break;
5277 case 2: port_number = 4; break;
5279 return boost::shared_ptr<AutomationControl>();
5284 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5286 return boost::shared_ptr<AutomationControl>();
5289 boost::shared_ptr<AutomationControl>
5290 Route::eq_freq_controllable (uint32_t band) const
5293 if (mixbus() || is_master()) {
5294 /* no frequency controls for mixbusses or master */
5295 return boost::shared_ptr<AutomationControl>();
5298 boost::shared_ptr<PluginInsert> eq = ch_eq();
5301 return boost::shared_ptr<AutomationControl>();
5304 uint32_t port_number;
5307 case 0: port_number = 13; break; // lo
5308 case 1: port_number = 11; break; // lo mid
5309 case 2: port_number = 9; break; // hi mid
5310 case 3: port_number = 7; break; // hi
5312 return boost::shared_ptr<AutomationControl>();
5316 case 0: port_number = 7; break;
5317 case 1: port_number = 5; break;
5318 case 2: port_number = 3; break;
5320 return boost::shared_ptr<AutomationControl>();
5324 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5326 return boost::shared_ptr<AutomationControl>();
5330 boost::shared_ptr<AutomationControl>
5331 Route::eq_q_controllable (uint32_t band) const
5333 return boost::shared_ptr<AutomationControl>();
5336 boost::shared_ptr<AutomationControl>
5337 Route::eq_shape_controllable (uint32_t band) const
5340 boost::shared_ptr<PluginInsert> eq = ch_eq();
5341 if (is_master() || mixbus() || !eq) {
5342 return boost::shared_ptr<AutomationControl>();
5346 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4))); // lo bell
5349 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3))); // hi bell
5355 return boost::shared_ptr<AutomationControl>();
5358 boost::shared_ptr<AutomationControl>
5359 Route::eq_enable_controllable () const
5362 boost::shared_ptr<PluginInsert> eq = ch_eq();
5365 return boost::shared_ptr<AutomationControl>();
5368 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5370 return boost::shared_ptr<AutomationControl>();
5374 boost::shared_ptr<AutomationControl>
5375 Route::filter_freq_controllable (bool hpf) const
5378 boost::shared_ptr<PluginInsert> eq = ch_eq();
5380 if (is_master() || mixbus() || !eq) {
5381 return boost::shared_ptr<AutomationControl>();
5385 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5))); // HPF freq
5387 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5391 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 6))); // LPF freq
5393 return boost::shared_ptr<AutomationControl>();
5398 return boost::shared_ptr<AutomationControl>();
5402 boost::shared_ptr<AutomationControl>
5403 Route::filter_slope_controllable (bool) const
5405 return boost::shared_ptr<AutomationControl>();
5408 boost::shared_ptr<AutomationControl>
5409 Route::filter_enable_controllable (bool) const
5412 boost::shared_ptr<PluginInsert> eq = ch_eq();
5414 if (is_master() || mixbus() || !eq) {
5415 return boost::shared_ptr<AutomationControl>();
5418 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5420 return boost::shared_ptr<AutomationControl>();
5425 Route::eq_band_name (uint32_t band) const
5428 if (is_master() || mixbus()) {
5430 if (Profile->get_mixbus()) {
5432 case 0: return _("lo");
5433 case 1: return _("mid");
5434 case 2: return _("hi");
5435 default: return string();
5443 case 0: return _("lo");
5444 case 1: return _("lo mid");
5445 case 2: return _("hi mid");
5446 case 3: return _("hi");
5447 default: return string();
5453 boost::shared_ptr<AutomationControl>
5454 Route::comp_enable_controllable () const
5457 boost::shared_ptr<PluginInsert> comp = ch_comp();
5460 return boost::shared_ptr<AutomationControl>();
5463 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5465 return boost::shared_ptr<AutomationControl>();
5468 boost::shared_ptr<AutomationControl>
5469 Route::comp_threshold_controllable () const
5472 boost::shared_ptr<PluginInsert> comp = ch_comp();
5475 return boost::shared_ptr<AutomationControl>();
5478 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5481 return boost::shared_ptr<AutomationControl>();
5484 boost::shared_ptr<AutomationControl>
5485 Route::comp_speed_controllable () const
5488 boost::shared_ptr<PluginInsert> comp = ch_comp();
5491 return boost::shared_ptr<AutomationControl>();
5494 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3)));
5496 return boost::shared_ptr<AutomationControl>();
5499 boost::shared_ptr<AutomationControl>
5500 Route::comp_mode_controllable () const
5503 boost::shared_ptr<PluginInsert> comp = ch_comp();
5506 return boost::shared_ptr<AutomationControl>();
5509 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4)));
5511 return boost::shared_ptr<AutomationControl>();
5514 boost::shared_ptr<AutomationControl>
5515 Route::comp_makeup_controllable () const
5518 boost::shared_ptr<PluginInsert> comp = ch_comp();
5521 return boost::shared_ptr<AutomationControl>();
5524 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5)));
5526 return boost::shared_ptr<AutomationControl>();
5529 boost::shared_ptr<ReadOnlyControl>
5530 Route::comp_redux_controllable () const
5533 boost::shared_ptr<PluginInsert> comp = ch_comp();
5536 return boost::shared_ptr<ReadOnlyControl>();
5539 return comp->control_output (2);
5541 return comp->control_output (6);
5545 return boost::shared_ptr<ReadOnlyControl>();
5550 Route::comp_mode_name (uint32_t mode) const
5555 return _("Leveler");
5557 return _("Compressor");
5559 return _("Limiter");
5561 return mixbus() ? _("Sidechain") : _("Limiter");
5571 Route::comp_speed_name (uint32_t mode) const
5589 boost::shared_ptr<AutomationControl>
5590 Route::send_level_controllable (uint32_t n) const
5593 # undef MIXBUS_PORTS_H
5594 # include "../../gtk2_ardour/mixbus_ports.h"
5595 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5596 if (plug && !mixbus()) {
5597 uint32_t port_id = 0;
5599 case 0: port_id = port_channel_post_aux1_level; break;
5600 case 1: port_id = port_channel_post_aux2_level; break;
5601 case 2: port_id = port_channel_post_aux3_level; break;
5602 case 3: port_id = port_channel_post_aux4_level; break;
5603 case 4: port_id = port_channel_post_aux5_level; break;
5604 case 5: port_id = port_channel_post_aux6_level; break;
5605 case 6: port_id = port_channel_post_aux7_level; break;
5606 case 7: port_id = port_channel_post_aux8_level; break;
5608 case 8: port_id = port_channel_post_aux9_level; break;
5609 case 9: port_id = port_channel_post_aux10_level; break;
5610 case 10: port_id = port_channel_post_aux11_level; break;
5611 case 11: port_id = port_channel_post_aux12_level; break;
5618 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5629 boost::shared_ptr<Send> s = boost::dynamic_pointer_cast<Send>(nth_send (n));
5631 return boost::shared_ptr<AutomationControl>();
5633 return s->gain_control ();
5636 boost::shared_ptr<AutomationControl>
5637 Route::send_enable_controllable (uint32_t n) const
5640 # undef MIXBUS_PORTS_H
5641 # include "../../gtk2_ardour/mixbus_ports.h"
5642 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5643 if (plug && !mixbus()) {
5644 uint32_t port_id = 0;
5646 case 0: port_id = port_channel_post_aux1_asgn; break;
5647 case 1: port_id = port_channel_post_aux2_asgn; break;
5648 case 2: port_id = port_channel_post_aux3_asgn; break;
5649 case 3: port_id = port_channel_post_aux4_asgn; break;
5650 case 4: port_id = port_channel_post_aux5_asgn; break;
5651 case 5: port_id = port_channel_post_aux6_asgn; break;
5652 case 6: port_id = port_channel_post_aux7_asgn; break;
5653 case 7: port_id = port_channel_post_aux8_asgn; break;
5655 case 8: port_id = port_channel_post_aux9_asgn; break;
5656 case 9: port_id = port_channel_post_aux10_asgn; break;
5657 case 10: port_id = port_channel_post_aux11_asgn; break;
5658 case 11: port_id = port_channel_post_aux12_asgn; break;
5665 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5676 /* although Ardour sends have enable/disable as part of the Processor
5677 * API, it is not exposed as a controllable.
5679 * XXX: we should fix this (make it click-free, automatable enable-control)
5681 return boost::shared_ptr<AutomationControl>();
5685 Route::send_name (uint32_t n) const
5688 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5689 if (plug && !mixbus()) {
5692 return _session.get_mixbus (n)->name();
5697 return _session.get_mixbus (n)->name();
5703 boost::shared_ptr<Processor> p = nth_send (n);
5711 boost::shared_ptr<AutomationControl>
5712 Route::master_send_enable_controllable () const
5715 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5717 return boost::shared_ptr<AutomationControl>();
5719 # undef MIXBUS_PORTS_H
5720 # include "../../gtk2_ardour/mixbus_ports.h"
5721 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_mstr_assign)));
5723 return boost::shared_ptr<AutomationControl>();
5728 Route::slaved () const
5730 if (!_gain_control) {
5733 /* just test one particular control, not all of them */
5734 return _gain_control->slaved ();
5738 Route::slaved_to (boost::shared_ptr<VCA> vca) const
5740 if (!vca || !_gain_control) {
5744 /* just test one particular control, not all of them */
5746 return _gain_control->slaved_to (vca->gain_control());
5750 Route::muted_by_others_soloing () const
5752 if (!can_be_muted_by_others ()) {
5756 return _session.soloing() && !_solo_control->soloed() && !_solo_isolate_control->solo_isolated();
5760 Route::clear_all_solo_state ()
5762 _solo_control->clear_all_solo_state ();
5765 boost::shared_ptr<AutomationControl>
5766 Route::automation_control_recurse (PBD::ID const & id) const
5768 boost::shared_ptr<AutomationControl> ac = Automatable::automation_control (id);
5774 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5776 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5777 if ((ac = (*i)->automation_control (id))) {
5782 return boost::shared_ptr<AutomationControl> ();
5786 Route::slavables () const
5788 SlavableControlList rv;
5789 rv.push_back (_gain_control);
5790 rv.push_back (_mute_control);
5791 rv.push_back (_solo_control);
5796 Route::set_disk_io_point (DiskIOPoint diop)
5798 bool display = false;
5800 cerr << "set disk io to " << enum_2_string (diop) << endl;
5811 _disk_writer->set_display_to_user (display);
5815 _disk_reader->set_display_to_user (display);
5818 const bool changed = (diop != _disk_io_point);
5820 _disk_io_point = diop;
5823 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
5824 configure_processors (0);
5827 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
5830 #ifdef USE_TRACKS_CODE_FEATURES
5832 /* This is the Tracks version of Track::monitoring_state().
5834 * Ardour developers: try to flag or fix issues if parts of the libardour API
5835 * change in ways that invalidate this
5839 Route::monitoring_state () const
5841 /* Explicit requests */
5843 if (_monitoring != MonitorInput) {
5844 return MonitoringInput;
5847 if (_monitoring & MonitorDisk) {
5848 return MonitoringDisk;
5851 /* This is an implementation of the truth table in doc/monitor_modes.pdf;
5852 I don't think it's ever going to be too pretty too look at.
5855 // GZ: NOT USED IN TRACKS
5856 //bool const auto_input = _session.config.get_auto_input ();
5857 //bool const software_monitor = Config->get_monitoring_model() == SoftwareMonitoring;
5858 //bool const tape_machine_mode = Config->get_tape_machine_mode ();
5860 bool const roll = _session.transport_rolling ();
5861 bool const track_rec = _diskstream->record_enabled ();
5862 bool session_rec = _session.actively_recording ();
5866 if (!session_rec && roll) {
5867 return MonitoringDisk;
5869 return MonitoringInput;
5875 return MonitoringDisk;
5879 return MonitoringSilence;
5884 /* This is the Ardour/Mixbus version of Track::monitoring_state().
5886 * Tracks developers: do NOT modify this method under any circumstances.
5890 Route::monitoring_state () const
5892 if (!_disk_reader) {
5893 return MonitoringInput;
5896 /* Explicit requests */
5897 MonitorChoice m (_monitoring_control->monitoring_choice());
5899 if (m != MonitorAuto) {
5901 MonitorState ms ((MonitorState) 0);
5903 if (m & MonitorInput) {
5904 ms = MonitoringInput;
5907 if (m & MonitorDisk) {
5908 ms = MonitorState (ms | MonitoringDisk);
5914 switch (_session.config.get_session_monitoring ()) {
5916 return MonitoringDisk;
5919 return MonitoringInput;
5925 /* This is an implementation of the truth table in doc/monitor_modes.pdf;
5926 I don't think it's ever going to be too pretty too look at.
5929 bool const roll = _session.transport_rolling ();
5930 bool const track_rec = _disk_writer->record_enabled ();
5931 bool const auto_input = _session.config.get_auto_input ();
5932 bool const software_monitor = Config->get_monitoring_model() == SoftwareMonitoring;
5933 bool const tape_machine_mode = Config->get_tape_machine_mode ();
5936 /* I suspect that just use actively_recording() is good enough all the
5937 * time, but just to keep the semantics the same as they were before
5938 * sept 26th 2012, we differentiate between the cases where punch is
5939 * enabled and those where it is not.
5941 * rg: sept 30 2017: Above is not the case: punch-in/out location is
5942 * global session playhead position.
5943 * When this method is called from process_output_buffers() we need
5944 * to use delay-compensated route's process-position.
5946 * NB. Disk reader/writer may also be offset by a same amount of time.
5948 * Also keep in mind that _session.transport_rolling() is false during
5949 * pre-roll but the disk already produces output.
5954 if (_session.config.get_punch_in() || _session.config.get_punch_out()) {
5955 session_rec = _session.actively_recording ();
5957 session_rec = _session.get_record_enabled();
5962 if (!session_rec && roll && auto_input) {
5963 return MonitoringDisk;
5965 return software_monitor ? MonitoringInput : MonitoringSilence;
5970 if (tape_machine_mode) {
5972 return MonitoringDisk;
5976 if (!roll && auto_input) {
5977 return software_monitor ? MonitoringInput : MonitoringSilence;
5979 return MonitoringDisk;
5985 abort(); /* NOTREACHED */
5986 return MonitoringSilence;