2 Copyright (C) 2000 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "libardour-config.h"
29 #include <boost/algorithm/string.hpp>
31 #include "pbd/xml++.h"
32 #include "pbd/enumwriter.h"
33 #include "pbd/locale_guard.h"
34 #include "pbd/memento_command.h"
35 #include "pbd/stacktrace.h"
36 #include "pbd/types_convert.h"
37 #include "pbd/unwind.h"
39 #include "ardour/amp.h"
40 #include "ardour/audio_buffer.h"
41 #include "ardour/audio_track.h"
42 #include "ardour/audio_port.h"
43 #include "ardour/audioengine.h"
44 #include "ardour/boost_debug.h"
45 #include "ardour/buffer.h"
46 #include "ardour/buffer_set.h"
47 #include "ardour/capturing_processor.h"
48 #include "ardour/debug.h"
49 #include "ardour/delivery.h"
50 #include "ardour/disk_reader.h"
51 #include "ardour/disk_writer.h"
52 #include "ardour/event_type_map.h"
53 #include "ardour/gain_control.h"
54 #include "ardour/internal_return.h"
55 #include "ardour/internal_send.h"
56 #include "ardour/meter.h"
57 #include "ardour/delayline.h"
58 #include "ardour/midi_buffer.h"
59 #include "ardour/midi_port.h"
60 #include "ardour/midi_track.h"
61 #include "ardour/monitor_control.h"
62 #include "ardour/monitor_processor.h"
63 #include "ardour/pannable.h"
64 #include "ardour/panner.h"
65 #include "ardour/panner_shell.h"
66 #include "ardour/parameter_descriptor.h"
67 #include "ardour/phase_control.h"
68 #include "ardour/plugin_insert.h"
69 #include "ardour/polarity_processor.h"
70 #include "ardour/port.h"
71 #include "ardour/port_insert.h"
72 #include "ardour/processor.h"
73 #include "ardour/profile.h"
74 #include "ardour/route.h"
75 #include "ardour/route_group.h"
76 #include "ardour/send.h"
77 #include "ardour/session.h"
78 #include "ardour/solo_control.h"
79 #include "ardour/solo_isolate_control.h"
80 #include "ardour/types_convert.h"
81 #include "ardour/unknown_processor.h"
82 #include "ardour/utils.h"
83 #include "ardour/vca.h"
88 using namespace ARDOUR;
91 PBD::Signal3<int,boost::shared_ptr<Route>, boost::shared_ptr<PluginInsert>, Route::PluginSetupOptions > Route::PluginSetup;
93 /** Base class for all routable/mixable objects (tracks and busses) */
94 Route::Route (Session& sess, string name, PresentationInfo::Flag flag, DataType default_type)
95 : Stripable (sess, name, PresentationInfo (flag))
96 , GraphNode (sess._process_graph)
97 , Muteable (sess, name)
100 , _disk_io_point (DiskIOPreFader)
101 , _pending_process_reorder (0)
102 , _pending_signals (0)
103 , _pending_declick (true)
104 , _meter_point (MeterPostFader)
105 , _pending_meter_point (MeterPostFader)
106 , _meter_type (MeterPeak)
107 , _denormal_protection (false)
109 , _declickable (false)
110 , _have_internal_generator (false)
111 , _default_type (default_type)
112 , _loop_location (NULL)
115 , _in_configure_processors (false)
116 , _initial_io_setup (false)
117 , _in_sidechain_setup (false)
118 , _custom_meter_position_noted (false)
120 , _patch_selector_dialog (0)
122 processor_max_streams.reset();
125 boost::weak_ptr<Route>
126 Route::weakroute () {
127 return boost::weak_ptr<Route> (boost::dynamic_pointer_cast<Route> (shared_from_this ()));
133 /* set default meter type */
135 _meter_type = Config->get_meter_type_master ();
137 else if (dynamic_cast<Track*>(this)) {
138 _meter_type = Config->get_meter_type_track ();
140 _meter_type = Config->get_meter_type_bus ();
143 /* add standard controls */
145 _gain_control.reset (new GainControl (_session, GainAutomation));
146 _trim_control.reset (new GainControl (_session, TrimAutomation));
147 /* While the route has-a gain-control for consistency with Stripable and VCA
148 * ownership is handed over to the Amp Processor which manages the
149 * state of the Control and AutomationList as part of its
150 * Automatable API. -- Don't call add_control () here.
153 _solo_control.reset (new SoloControl (_session, X_("solo"), *this, *this));
154 add_control (_solo_control);
155 _solo_control->Changed.connect_same_thread (*this, boost::bind (&Route::solo_control_changed, this, _1, _2));
157 _mute_control.reset (new MuteControl (_session, X_("mute"), *this));
158 add_control (_mute_control);
160 _phase_control.reset (new PhaseControl (_session, X_("phase")));
161 add_control (_phase_control);
163 _solo_isolate_control.reset (new SoloIsolateControl (_session, X_("solo-iso"), *this, *this));
164 add_control (_solo_isolate_control);
166 _solo_safe_control.reset (new SoloSafeControl (_session, X_("solo-safe")));
167 add_control (_solo_safe_control);
171 if (!(_presentation_info.flags() & PresentationInfo::MonitorOut)) {
172 _pannable.reset (new Pannable (_session));
175 /* input and output objects */
177 _input.reset (new IO (_session, _name, IO::Input, _default_type));
178 _output.reset (new IO (_session, _name, IO::Output, _default_type));
180 _input->changed.connect_same_thread (*this, boost::bind (&Route::input_change_handler, this, _1, _2));
181 _input->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::input_port_count_changing, this, _1));
183 _output->changed.connect_same_thread (*this, boost::bind (&Route::output_change_handler, this, _1, _2));
184 _output->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::output_port_count_changing, this, _1));
186 /* add the amp/fader processor.
187 * it should be the first processor to be added on every route.
190 _amp.reset (new Amp (_session, X_("Fader"), _gain_control, true));
191 add_processor (_amp, PostFader);
193 _polarity.reset (new PolarityProcessor (_session, _phase_control));
194 _polarity->activate();
195 _polarity->set_owner (this);
198 _amp->set_display_name (_("Monitor"));
201 if (!is_master() && !is_monitor() && !is_auditioner()) {
202 _delayline.reset (new DelayLine (_session, name ()));
207 _trim.reset (new Amp (_session, X_("Trim"), _trim_control, false));
208 _trim->set_display_to_user (false);
210 if (dynamic_cast<AudioTrack*>(this)) {
211 /* we can't do this in the AudioTrack's constructor
212 * because _trim does not exit then
216 else if (!dynamic_cast<Track*>(this) && ! ( is_monitor() || is_auditioner() )) {
221 /* create standard processors: meter, main outs, monitor out;
222 they will be added to _processors by setup_invisible_processors ()
225 _meter.reset (new PeakMeter (_session, _name));
226 _meter->set_owner (this);
227 _meter->set_display_to_user (false);
230 _main_outs.reset (new Delivery (_session, _output, _pannable, _mute_master, _name, Delivery::Main));
231 _main_outs->activate ();
234 /* where we listen to tracks */
235 _intreturn.reset (new InternalReturn (_session));
236 _intreturn->activate ();
238 /* the thing that provides proper control over a control/monitor/listen bus
239 (such as per-channel cut, dim, solo, invert, etc).
241 _monitor_control.reset (new MonitorProcessor (_session));
242 _monitor_control->activate ();
245 /* now that we have _meter, its safe to connect to this */
248 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
249 configure_processors (0);
257 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
259 /* do this early so that we don't get incoming signals as we are going through destruction
264 /* don't use clear_processors here, as it depends on the session which may
265 be half-destroyed by now
268 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
269 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
270 (*i)->drop_references ();
273 _processors.clear ();
277 Route::ensure_track_or_route_name(string name, Session &session)
279 string newname = name;
281 while (!session.io_name_is_legal (newname)) {
282 newname = bump_name_once (newname, ' ');
289 Route::set_trim (gain_t val, Controllable::GroupControlDisposition /* group override */)
291 // TODO route group, see set_gain()
292 // _trim_control->route_set_value (val);
296 Route::maybe_declick (BufferSet&, samplecnt_t, int)
298 /* this is the "bus" implementation and they never declick.
303 /** Process this route for one (sub) cycle (process thread)
305 * @param bufs Scratch buffers to use for the signal path
306 * @param start_sample Initial transport sample
307 * @param end_sample Final transport sample
308 * @param nframes Number of samples to output (to ports)
310 * Note that (end_sample - start_sample) may not be equal to nframes when the
311 * transport speed isn't 1.0 (eg varispeed).
314 Route::process_output_buffers (BufferSet& bufs,
315 samplepos_t start_sample, samplepos_t end_sample, pframes_t nframes,
316 int declick, bool gain_automation_ok, bool run_disk_reader)
318 /* Caller must hold process lock */
319 assert (!AudioEngine::instance()->process_lock().trylock());
321 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
323 // can this actually happen?
324 // Places that need a WriterLock on (_processor_lock) must also take the process-lock.
325 bufs.silence (nframes, 0);
326 assert (0); // ...one way to find out.
330 /* We should offset the route-owned ctrls by the given latency, however
331 * this only affects Mute. Other route-owned controls (solo, polarity..)
332 * are not automatable.
334 * Mute has its own issues since there's not a single mute-point,
337 automation_run (start_sample, nframes);
340 _pannable->automation_run (start_sample + _signal_latency, nframes);
343 /* figure out if we're going to use gain automation */
344 if (gain_automation_ok) {
345 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
346 _amp->setup_gain_automation (
347 start_sample + _amp->output_latency (),
348 end_sample + _amp->output_latency (),
351 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
352 _trim->setup_gain_automation (
353 start_sample + _trim->output_latency (),
354 end_sample + _trim->output_latency (),
358 /* We align the playhead to output. The user hears what the clock says:
359 * When the playhead/clock says 1:00:00:00 the user will hear the audio sample
360 * at 1:00:00:00. sample_start will be [sample at] 1:00:00:00
362 * e.g. clock says Time T = 0, sample_start = 0
363 * Disk-read(play) -> latent-plugin (+10) -> fader-automation -> output (+5)
364 * -> total playback latency "disk -> out" is 15.
365 * -> at Time T= -15, the disk-reader reads sample T=0.
366 * By the Time T=0 is reached (dt=15 later) that sample is audible.
369 const double speed = (is_auditioner() ? 1.0 : _session.transport_speed ());
371 const sampleoffset_t latency_offset = _signal_latency + _output->latency ();
373 /* when rolling backwards this can become negative */
374 start_sample -= latency_offset;
375 end_sample -= latency_offset;
377 start_sample += latency_offset;
378 end_sample += latency_offset;
381 /* Note: during intial pre-roll 'start_sample' as passed as argument can be negative.
382 * Functions calling process_output_buffers() will set "run_disk_reader"
383 * to false if the pre-roll count-down is larger than playback_latency ().
385 * playback_latency() is guarnteed to be <= _signal_latency + _output->latency ()
387 assert (!_disk_reader || !run_disk_reader || start_sample >= 0 || speed < 0);
389 /* however the disk-writer may need to pick up output from other tracks
390 * during pre-roll (in particular if this route has latent effects after the disk).
392 * e.g. track 1 play -> latency A --port--> track2 capture -> latency B ---> out
393 * total pre-roll = A + B.
395 * Note the disk-writer has built-in overlap detection (it's safe to run it early)
398 bool run_disk_writer = false;
399 if (_disk_writer && speed > 0) {
400 samplecnt_t latency_preroll = _session.remaining_latency_preroll ();
401 run_disk_writer = latency_preroll < nframes + (_signal_latency + _output->latency ());
402 if (end_sample - _disk_writer->input_latency () < _session.transport_sample ()) {
403 run_disk_writer = true;
407 /* Tell main outs what to do about monitoring. We do this so that
408 * on a transition between monitoring states we get a de-clicking gain
409 * change in the _main_outs delivery, if config.get_use_monitor_fades()
412 * We override this in the case where we have an internal generator.
414 * FIXME: when punching in/out this also depends on latency compensated time
415 * for this route. monitoring_state() does not currently handle that correctly,.
417 * Also during remaining_latency_preroll, transport_rolling () is false, but
418 * we may need to monitor disk instead.
420 MonitorState ms = monitoring_state ();
421 bool silence = _have_internal_generator ? false : (ms == MonitoringSilence);
423 _main_outs->no_outs_cuz_we_no_monitor (silence);
425 /* -------------------------------------------------------------------------------------------
426 GLOBAL DECLICK (for transport changes etc.)
427 ----------------------------------------------------------------------------------------- */
429 // XXX not latency compensated. calls Amp::declick, but there may be
430 // plugins between disk and Fader.
431 maybe_declick (bufs, nframes, declick);
432 _pending_declick = 0;
434 /* -------------------------------------------------------------------------------------------
436 ----------------------------------------------------------------------------------------- */
437 /* XXX We'll need to protect silent inputs as well as silent disk
438 * (when not monitoring input or monitoring disk and there's no region
439 * for a longer time).
441 * ...or simply drop that feature.
443 if (_denormal_protection || Config->get_denormal_protection()) {
445 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
446 Sample* const sp = i->data();
447 for (pframes_t nx = 0; nx < nframes; ++nx) {
454 /* -------------------------------------------------------------------------------------------
456 ----------------------------------------------------------------------------------------- */
458 samplecnt_t latency = 0;
460 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
462 /* TODO check for split cycles here.
464 * start_frame, end_frame is adjusted by latency and may
469 /* if it has any inputs, make sure they match */
470 if (boost::dynamic_pointer_cast<UnknownProcessor> (*i) == 0 && (*i)->input_streams() != ChanCount::ZERO) {
471 if (bufs.count() != (*i)->input_streams()) {
473 DEBUG::Processors, string_compose (
474 "input port mismatch %1 bufs = %2 input for %3 = %4\n",
475 _name, bufs.count(), (*i)->name(), (*i)->input_streams()
482 bool re_inject_oob_data = false;
483 if ((*i) == _disk_reader) {
484 /* Well now, we've made it past the disk-writer and to the disk-reader.
485 * Time to decide what to do about monitoring.
487 * Even when not doing MonitoringDisk, we need to run the processors,
488 * so that it advances its internal buffers (IFF run_disk_reader is true).
491 if (ms == MonitoringDisk || ms == MonitoringSilence) {
492 /* this will clear out-of-band data, too (e.g. MIDI-PC, Panic etc.
493 * OOB data is written at the end of the cycle (nframes - 1),
494 * and jack does not re-order events, so we push them back later */
495 re_inject_oob_data = true;
496 bufs.silence (nframes, 0);
500 double pspeed = speed;
501 if ((!run_disk_reader && (*i) == _disk_reader) || (!run_disk_writer && (*i) == _disk_writer)) {
502 /* run with speed 0, no-roll */
507 (*i)->run (bufs, start_sample + latency, end_sample + latency, pspeed, nframes, *i != _processors.back());
509 (*i)->run (bufs, start_sample - latency, end_sample - latency, pspeed, nframes, *i != _processors.back());
512 bufs.set_count ((*i)->output_streams());
514 /* Note: plugin latency may change. While the plugin does inform the session via
515 * processor_latency_changed(). But the session may not yet have gotten around to
516 * update the actual worste-case and update this track's _signal_latency.
518 * So there can be cases where adding up all latencies may not equal _signal_latency.
520 if ((*i)->active ()) {
521 latency += (*i)->signal_latency ();
524 if (re_inject_oob_data) {
525 write_out_of_band_data (bufs, nframes);
529 if ((*i) == _delayline) {
530 latency += _delayline->delay ();
537 Route::bounce_process (BufferSet& buffers, samplepos_t start, samplecnt_t nframes,
538 boost::shared_ptr<Processor> endpoint,
539 bool include_endpoint, bool for_export, bool for_freeze)
541 /* If no processing is required, there's no need to go any further. */
542 if (!endpoint && !include_endpoint) {
546 samplecnt_t latency = bounce_get_latency(_amp, false, for_export, for_freeze);
547 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
548 _amp->setup_gain_automation (start - latency, start - latency + nframes, nframes);
550 /* trim is always at the top, for bounce no latency compensation is needed */
551 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
552 _trim->setup_gain_automation (start, start + nframes, nframes);
555 const double speed = _session.transport_speed ();
556 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
558 if (!include_endpoint && (*i) == endpoint) {
562 /* if we're *not* exporting, stop processing if we come across a routing processor. */
563 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
566 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
570 /* special case the panner (export outputs)
571 * Ideally we'd only run the panner, not the delivery itself...
572 * but panners need separate input/output buffers and some context
573 * (panshell, panner type, etc). AFAICT there is no ill side effect
574 * of re-using the main delivery when freewheeling/exporting a region.
576 if ((*i) == _main_outs) {
577 assert ((*i)->does_routing());
578 (*i)->run (buffers, start - latency, start - latency + nframes, speed, nframes, true);
579 buffers.set_count ((*i)->output_streams());
582 /* don't run any processors that do routing.
583 * Also don't bother with metering.
585 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
586 (*i)->run (buffers, start - latency, start - latency + nframes, 1.0, nframes, true);
587 buffers.set_count ((*i)->output_streams());
588 latency += (*i)->signal_latency ();
591 if ((*i) == endpoint) {
598 Route::bounce_get_latency (boost::shared_ptr<Processor> endpoint,
599 bool include_endpoint, bool for_export, bool for_freeze) const
601 samplecnt_t latency = 0;
602 if (!endpoint && !include_endpoint) {
606 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
607 if (!include_endpoint && (*i) == endpoint) {
610 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
613 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
616 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
617 latency += (*i)->signal_latency ();
619 if ((*i) == endpoint) {
627 Route::bounce_get_output_streams (ChanCount &cc, boost::shared_ptr<Processor> endpoint,
628 bool include_endpoint, bool for_export, bool for_freeze) const
630 if (!endpoint && !include_endpoint) {
634 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
635 if (!include_endpoint && (*i) == endpoint) {
638 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
641 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
644 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
645 cc = (*i)->output_streams();
647 if ((*i) == endpoint) {
655 Route::n_process_buffers ()
657 return max (_input->n_ports(), processor_max_streams);
661 Route::monitor_run (samplepos_t start_sample, samplepos_t end_sample, pframes_t nframes, int declick)
663 assert (is_monitor());
664 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
665 run_route (start_sample, end_sample, nframes, declick, true, false);
669 Route::run_route (samplepos_t start_sample, samplepos_t end_sample, pframes_t nframes, int declick, bool gain_automation_ok, bool run_disk_reader)
671 BufferSet& bufs (_session.get_route_buffers (n_process_buffers()));
673 fill_buffers_with_input (bufs, _input, nframes);
675 /* filter captured data before meter sees it */
678 if (is_monitor() && _session.listening() && !_session.is_auditioning()) {
680 /* control/monitor bus ignores input ports when something is
681 feeding the listen "stream". data will "arrive" into the
682 route from the intreturn processor element.
685 bufs.silence (nframes, 0);
688 snapshot_out_of_band_data (nframes);
689 /* append immediate messages to the first MIDI buffer (thus sending it to the first output port) */
691 write_out_of_band_data (bufs, nframes);
693 /* run processor chain */
695 process_output_buffers (bufs, start_sample, end_sample, nframes, declick, gain_automation_ok, run_disk_reader);
697 /* map events (e.g. MIDI-CC) back to control-parameters */
698 update_controls (bufs);
700 flush_processor_buffers_locked (nframes);
704 Route::set_listen (bool yn)
707 if (_monitor_send->active() == yn) {
711 _monitor_send->activate ();
713 _monitor_send->deactivate ();
719 Route::solo_control_changed (bool, Controllable::GroupControlDisposition)
721 /* nothing to do if we're not using AFL/PFL. But if we are, we need
722 to alter the active state of the monitor send.
725 if (Config->get_solo_control_is_listen_control ()) {
726 set_listen (_solo_control->self_soloed() || _solo_control->get_masters_value());
731 Route::push_solo_isolate_upstream (int32_t delta)
733 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
735 boost::shared_ptr<RouteList> routes = _session.get_routes ();
736 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
738 if ((*i).get() == this || !(*i)->can_solo()) {
743 bool does_feed = feeds (*i, &sends_only);
745 if (does_feed && !sends_only) {
746 (*i)->solo_isolate_control()->mod_solo_isolated_by_upstream (delta);
752 Route::push_solo_upstream (int delta)
754 DEBUG_TRACE (DEBUG::Solo, string_compose("\t ... INVERT push from %1\n", _name));
755 for (FedBy::iterator i = _fed_by.begin(); i != _fed_by.end(); ++i) {
759 boost::shared_ptr<Route> sr (i->r.lock());
761 sr->solo_control()->mod_solo_by_others_downstream (-delta);
768 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
770 cerr << name << " {" << endl;
771 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
772 p != procs.end(); ++p) {
773 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << " @ " << (*p) << endl;
779 /** Supposing that we want to insert a Processor at a given Placement, return
780 * the processor to add the new one before (or 0 to add at the end).
782 boost::shared_ptr<Processor>
783 Route::before_processor_for_placement (Placement p)
785 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
787 ProcessorList::iterator loc;
790 /* generic pre-fader: insert immediately before the amp */
791 loc = find (_processors.begin(), _processors.end(), _amp);
793 /* generic post-fader: insert right before the main outs */
794 loc = find (_processors.begin(), _processors.end(), _main_outs);
797 return loc != _processors.end() ? *loc : boost::shared_ptr<Processor> ();
800 /** Supposing that we want to insert a Processor at a given index, return
801 * the processor to add the new one before (or 0 to add at the end).
803 boost::shared_ptr<Processor>
804 Route::before_processor_for_index (int index)
807 return boost::shared_ptr<Processor> ();
810 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
812 ProcessorList::iterator i = _processors.begin ();
814 while (i != _processors.end() && j < index) {
815 if ((*i)->display_to_user()) {
822 return (i != _processors.end() ? *i : boost::shared_ptr<Processor> ());
825 /** Add a processor either pre- or post-fader
826 * @return 0 on success, non-0 on failure.
829 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err, bool activation_allowed)
831 return add_processor (processor, before_processor_for_placement (placement), err, activation_allowed);
835 /** Add a processor to a route such that it ends up with a given index into the visible processors.
836 * @param index Index to add the processor at, or -1 to add at the end of the list.
837 * @return 0 on success, non-0 on failure.
840 Route::add_processor_by_index (boost::shared_ptr<Processor> processor, int index, ProcessorStreams* err, bool activation_allowed)
842 return add_processor (processor, before_processor_for_index (index), err, activation_allowed);
845 /** Add a processor to the route.
846 * @param before An existing processor in the list, or 0; the new processor will be inserted immediately before it (or at the end).
847 * @return 0 on success, non-0 on failure.
850 Route::add_processor (boost::shared_ptr<Processor> processor, boost::shared_ptr<Processor> before, ProcessorStreams* err, bool activation_allowed)
852 assert (processor != _meter);
853 assert (processor != _main_outs);
855 DEBUG_TRACE (DEBUG::Processors, string_compose (
856 "%1 adding processor %2\n", name(), processor->name()));
860 pl.push_back (processor);
861 int rv = add_processors (pl, before, err);
867 if (activation_allowed && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user ())) {
868 processor->activate ();
875 Route::processor_selfdestruct (boost::weak_ptr<Processor> wp)
877 /* We cannot destruct the processor here (usually RT-thread
878 * with various locks held - in case of sends also io_locks).
879 * Queue for deletion in low-priority thread.
881 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
882 selfdestruct_sequence.push_back (wp);
886 Route::add_processor_from_xml_2X (const XMLNode& node, int version)
888 XMLProperty const * prop;
891 boost::shared_ptr<Processor> processor;
893 /* bit of a hack: get the `placement' property from the <Redirect> tag here
894 so that we can add the processor in the right place (pre/post-fader)
897 XMLNodeList const & children = node.children ();
898 XMLNodeList::const_iterator i = children.begin ();
900 while (i != children.end() && (*i)->name() != X_("Redirect")) {
904 Placement placement = PreFader;
906 if (i != children.end()) {
907 if ((prop = (*i)->property (X_("placement"))) != 0) {
908 placement = Placement (string_2_enum (prop->value(), placement));
912 if (node.name() == "Insert") {
914 if ((prop = node.property ("type")) != 0) {
916 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
917 prop->value() == "lv2" ||
918 prop->value() == "windows-vst" ||
919 prop->value() == "mac-vst" ||
920 prop->value() == "lxvst" ||
921 prop->value() == "audiounit") {
923 if (_session.get_disable_all_loaded_plugins ()) {
924 processor.reset (new UnknownProcessor (_session, node));
926 processor.reset (new PluginInsert (_session));
927 processor->set_owner (this);
932 processor.reset (new PortInsert (_session, _pannable, _mute_master));
937 } else if (node.name() == "Send") {
939 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
940 processor.reset (new Send (_session, sendpan, _mute_master));
944 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
948 if (processor->set_state (node, version)) {
952 //A2 uses the "active" flag in the toplevel redirect node, not in the child plugin/IO
953 if (i != children.end()) {
954 if ((prop = (*i)->property (X_("active"))) != 0) {
955 if ( string_to<bool> (prop->value()) && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user () ) )
956 processor->activate();
958 processor->deactivate();
962 return (add_processor (processor, placement, 0, false) == 0);
965 catch (failed_constructor &err) {
966 warning << _("processor could not be created. Ignored.") << endmsg;
972 inline Route::PluginSetupOptions operator|= (Route::PluginSetupOptions& a, const Route::PluginSetupOptions& b) {
973 return a = static_cast<Route::PluginSetupOptions> (static_cast <int>(a) | static_cast<int> (b));
976 inline Route::PluginSetupOptions operator&= (Route::PluginSetupOptions& a, const Route::PluginSetupOptions& b) {
977 return a = static_cast<Route::PluginSetupOptions> (static_cast <int>(a) & static_cast<int> (b));
981 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
983 ProcessorList::iterator loc;
984 boost::shared_ptr <PluginInsert> fanout;
986 if (g_atomic_int_get (&_pending_process_reorder)) {
987 /* we need to flush any pending re-order changes */
988 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
989 apply_processor_changes_rt ();
993 loc = find(_processors.begin(), _processors.end(), before);
994 if (loc == _processors.end ()) {
998 /* nothing specified - at end */
999 loc = _processors.end ();
1002 if (others.empty()) {
1006 ProcessorList to_skip;
1008 // check if there's an instrument to replace or configure
1009 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1010 boost::shared_ptr<PluginInsert> pi;
1011 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) == 0) {
1014 if (!pi->plugin ()->get_info ()->is_instrument ()) {
1017 boost::shared_ptr<Processor> instrument = the_instrument ();
1018 ChanCount in (DataType::MIDI, 1);
1019 ChanCount out (DataType::AUDIO, 2); // XXX route's out?!
1021 PluginSetupOptions flags = None;
1023 flags |= CanReplace;
1024 in = instrument->input_streams ();
1025 out = instrument->output_streams ();
1027 if (pi->has_output_presets (in, out)) {
1031 pi->set_strict_io (_strict_io);
1033 PluginSetupOptions mask = None;
1034 if (Config->get_ask_replace_instrument ()) {
1037 if (Config->get_ask_setup_instrument ()) {
1043 if (flags != None) {
1044 boost::optional<int> rv = PluginSetup (boost::dynamic_pointer_cast<Route>(shared_from_this ()), pi, flags); /* EMIT SIGNAL */
1045 int mode = rv.get_value_or (0);
1048 to_skip.push_back (*i); // don't add this one;
1051 replace_processor (instrument, *i, err);
1052 to_skip.push_back (*i);
1057 if ((mode & 5) == 4) {
1064 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1065 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1066 ProcessorState pstate (this);
1068 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1073 ProcessorList::iterator check = find (to_skip.begin(), to_skip.end(), *i);
1074 if (check != to_skip.end()) {
1078 boost::shared_ptr<PluginInsert> pi;
1080 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1081 pi->set_strict_io (_strict_io);
1085 /* Ensure that only one amp is in the list at any time */
1086 ProcessorList::iterator check = find (_processors.begin(), _processors.end(), *i);
1087 if (check != _processors.end()) {
1088 if (before == _amp) {
1089 /* Already in position; all is well */
1092 _processors.erase (check);
1097 assert (find (_processors.begin(), _processors.end(), *i) == _processors.end ());
1099 _processors.insert (loc, *i);
1100 (*i)->set_owner (this);
1103 if (configure_processors_unlocked (err, &lm)) {
1105 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
1110 if (pi && pi->has_sidechain ()) {
1111 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
1114 if ((*i)->active()) {
1115 // emit ActiveChanged() and latency_changed() if needed
1119 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1121 boost::shared_ptr<Send> send;
1122 if ((send = boost::dynamic_pointer_cast<Send> (*i))) {
1123 send->SelfDestruct.connect_same_thread (*this,
1124 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (*i)));
1128 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1129 boost::shared_ptr<PluginInsert> pi;
1131 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1132 if (pi->has_no_inputs ()) {
1133 _have_internal_generator = true;
1139 _output->set_user_latency (0);
1142 reset_instrument_info ();
1143 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1144 set_processor_positions ();
1146 if (fanout && fanout->configured ()
1147 && fanout->output_streams().n_audio() > 2
1148 && boost::dynamic_pointer_cast<PluginInsert> (the_instrument ()) == fanout) {
1149 fan_out (); /* EMIT SIGNAL */
1155 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1157 if (p == PreFader) {
1158 start = _processors.begin();
1159 end = find(_processors.begin(), _processors.end(), _amp);
1161 start = find(_processors.begin(), _processors.end(), _amp);
1163 end = _processors.end();
1167 /** Turn off all processors with a given placement
1168 * @param p Placement of processors to disable
1171 Route::disable_processors (Placement p)
1173 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1175 ProcessorList::iterator start, end;
1176 placement_range(p, start, end);
1178 for (ProcessorList::iterator i = start; i != end; ++i) {
1179 (*i)->enable (false);
1182 _session.set_dirty ();
1185 /** Turn off all redirects
1188 Route::disable_processors ()
1190 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1192 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1193 (*i)->enable (false);
1196 _session.set_dirty ();
1199 /** Turn off all redirects with a given placement
1200 * @param p Placement of redirects to disable
1203 Route::disable_plugins (Placement p)
1205 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1207 ProcessorList::iterator start, end;
1208 placement_range(p, start, end);
1210 for (ProcessorList::iterator i = start; i != end; ++i) {
1211 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1212 (*i)->enable (false);
1216 _session.set_dirty ();
1219 /** Turn off all plugins
1222 Route::disable_plugins ()
1224 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1226 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1227 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1228 (*i)->enable (false);
1232 _session.set_dirty ();
1237 Route::ab_plugins (bool forward)
1239 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1243 /* forward = turn off all active redirects, and mark them so that the next time
1244 we go the other way, we will revert them
1247 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1248 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1251 if (!(*i)->display_to_user ()) {
1255 if (boost::dynamic_pointer_cast<PluginInsert> (*i)->is_channelstrip()) {
1260 if ((*i)->enabled ()) {
1261 (*i)->enable (false);
1262 (*i)->set_next_ab_is_active (true);
1264 (*i)->set_next_ab_is_active (false);
1270 /* backward = if the redirect was marked to go active on the next ab, do so */
1272 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1273 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1276 if (!(*i)->display_to_user ()) {
1280 if (boost::dynamic_pointer_cast<PluginInsert> (*i)->is_channelstrip()) {
1285 (*i)->enable ((*i)->get_next_ab_is_active ());
1289 _session.set_dirty ();
1293 /** Remove processors with a given placement.
1294 * @param p Placement of processors to remove.
1297 Route::clear_processors (Placement p)
1299 if (!_session.engine().connected()) {
1303 bool already_deleting = _session.deletion_in_progress();
1304 if (!already_deleting) {
1305 _session.set_deletion_in_progress();
1308 ProcessorList old_list = _processors;
1310 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1311 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1312 ProcessorList new_list;
1313 ProcessorStreams err;
1314 bool seen_amp = false;
1316 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1322 if (is_internal_processor (*i)) {
1324 /* you can't remove these */
1326 new_list.push_back (*i);
1333 new_list.push_back (*i);
1336 (*i)->drop_references ();
1344 (*i)->drop_references ();
1347 new_list.push_back (*i);
1354 _processors = new_list;
1355 configure_processors_unlocked (&err, &lm); // this can't fail
1357 /* drop references w/o process-lock (I/O procs may re-take it in ~IO() */
1360 processor_max_streams.reset();
1361 _have_internal_generator = false;
1362 reset_instrument_info ();
1363 set_processor_positions ();
1365 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1367 if (!already_deleting) {
1368 _session.clear_deletion_in_progress();
1373 Route::is_internal_processor (boost::shared_ptr<Processor> p) const
1375 if (p == _amp || p == _meter || p == _main_outs || p == _delayline || p == _trim || p == _polarity) {
1382 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err, bool need_process_lock)
1384 // TODO once the export point can be configured properly, do something smarter here
1385 if (processor == _capturing_processor) {
1386 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1387 if (need_process_lock) {
1391 _capturing_processor.reset();
1393 if (need_process_lock) {
1398 /* these can never be removed */
1400 if (is_internal_processor (processor)) {
1404 if (!_session.engine().connected()) {
1408 processor_max_streams.reset();
1411 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1412 if (need_process_lock) {
1416 /* Caller must hold process lock */
1417 assert (!AudioEngine::instance()->process_lock().trylock());
1419 Glib::Threads::RWLock::WriterLock lm (_processor_lock); // XXX deadlock after export
1421 ProcessorState pstate (this);
1423 ProcessorList::iterator i;
1424 bool removed = false;
1426 for (i = _processors.begin(); i != _processors.end(); ) {
1427 if (*i == processor) {
1429 /* move along, see failure case for configure_processors()
1430 where we may need to reconfigure the processor.
1433 /* stop redirects that send signals to JACK ports
1434 from causing noise as a result of no longer being
1438 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor> (*i);
1439 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
1443 iop = pi->sidechain();
1450 i = _processors.erase (i);
1458 _output->set_user_latency (0);
1466 if (configure_processors_unlocked (err, &lm)) {
1468 /* we know this will work, because it worked before :) */
1469 configure_processors_unlocked (0, &lm);
1473 _have_internal_generator = false;
1475 for (i = _processors.begin(); i != _processors.end(); ++i) {
1476 boost::shared_ptr<PluginInsert> pi;
1478 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1479 if (pi->has_no_inputs ()) {
1480 _have_internal_generator = true;
1485 if (need_process_lock) {
1490 reset_instrument_info ();
1491 processor->drop_references ();
1492 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1493 set_processor_positions ();
1499 Route::replace_processor (boost::shared_ptr<Processor> old, boost::shared_ptr<Processor> sub, ProcessorStreams* err)
1501 /* these can never be removed */
1502 if (is_internal_processor (old)) {
1505 /* and can't be used as substitute, either */
1506 if (is_internal_processor (sub)) {
1510 /* I/Os are out, too */
1511 if (boost::dynamic_pointer_cast<IOProcessor> (old) || boost::dynamic_pointer_cast<IOProcessor> (sub)) {
1515 /* this function cannot be used to swap/reorder processors */
1516 if (find (_processors.begin(), _processors.end(), sub) != _processors.end ()) {
1520 if (!AudioEngine::instance()->connected() || !old || !sub) {
1524 /* ensure that sub is not owned by another route */
1525 if (sub->owner ()) {
1530 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1531 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1532 ProcessorState pstate (this);
1534 assert (find (_processors.begin(), _processors.end(), sub) == _processors.end ());
1536 ProcessorList::iterator i;
1537 bool replaced = false;
1538 bool enable = old->enabled ();
1540 for (i = _processors.begin(); i != _processors.end(); ) {
1542 i = _processors.erase (i);
1543 _processors.insert (i, sub);
1544 sub->set_owner (this);
1557 boost::shared_ptr<PluginInsert> pi;
1558 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(sub)) != 0) {
1559 pi->set_strict_io (true);
1563 if (configure_processors_unlocked (err, &lm)) {
1565 configure_processors_unlocked (0, &lm);
1569 _have_internal_generator = false;
1571 for (i = _processors.begin(); i != _processors.end(); ++i) {
1572 boost::shared_ptr<PluginInsert> pi;
1573 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1574 if (pi->has_no_inputs ()) {
1575 _have_internal_generator = true;
1585 sub->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1586 _output->set_user_latency (0);
1589 reset_instrument_info ();
1590 old->drop_references ();
1591 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1592 set_processor_positions ();
1597 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1599 ProcessorList deleted;
1601 if (!_session.engine().connected()) {
1605 processor_max_streams.reset();
1608 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1609 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1610 ProcessorState pstate (this);
1612 ProcessorList::iterator i;
1613 boost::shared_ptr<Processor> processor;
1615 for (i = _processors.begin(); i != _processors.end(); ) {
1619 /* these can never be removed */
1621 if (is_internal_processor (processor)) {
1626 /* see if its in the list of processors to delete */
1628 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1633 /* stop IOProcessors that send to JACK ports
1634 from causing noise as a result of no longer being
1638 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(processor);
1639 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
1642 iop = pi->sidechain();
1649 deleted.push_back (processor);
1650 i = _processors.erase (i);
1653 if (deleted.empty()) {
1654 /* none of those in the requested list were found */
1658 _output->set_user_latency (0);
1660 if (configure_processors_unlocked (err, &lm)) {
1662 /* we know this will work, because it worked before :) */
1663 configure_processors_unlocked (0, &lm);
1668 _have_internal_generator = false;
1670 for (i = _processors.begin(); i != _processors.end(); ++i) {
1671 boost::shared_ptr<PluginInsert> pi;
1673 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1674 if (pi->has_no_inputs ()) {
1675 _have_internal_generator = true;
1682 /* now try to do what we need to so that those that were removed will be deleted */
1684 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1685 (*i)->drop_references ();
1688 reset_instrument_info ();
1689 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1690 set_processor_positions ();
1696 Route::reset_instrument_info ()
1698 boost::shared_ptr<Processor> instr = the_instrument();
1700 _instrument_info.set_internal_instrument (instr);
1704 /** Caller must hold process lock */
1706 Route::configure_processors (ProcessorStreams* err)
1708 #ifndef PLATFORM_WINDOWS
1709 assert (!AudioEngine::instance()->process_lock().trylock());
1712 if (!_in_configure_processors) {
1713 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1714 return configure_processors_unlocked (err, &lm);
1721 Route::input_streams () const
1723 return _input->n_ports ();
1726 list<pair<ChanCount, ChanCount> >
1727 Route::try_configure_processors (ChanCount in, ProcessorStreams* err)
1729 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1731 return try_configure_processors_unlocked (in, err);
1734 list<pair<ChanCount, ChanCount> >
1735 Route::try_configure_processors_unlocked (ChanCount in, ProcessorStreams* err)
1737 // Check each processor in order to see if we can configure as requested
1739 list<pair<ChanCount, ChanCount> > configuration;
1742 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1743 DEBUG_TRACE (DEBUG::Processors, "{\n");
1745 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1747 if ((*p)->can_support_io_configuration(in, out)) {
1749 if (boost::dynamic_pointer_cast<Delivery> (*p)
1750 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main
1752 && (is_monitor() || _strict_io || Profile->get_mixbus ())) {
1753 /* with strict I/O the panner + output are forced to
1754 * follow the last processor's output.
1756 * Delivery::can_support_io_configuration() will only add ports,
1757 * but not remove excess ports.
1759 * This works because the delivery only requires
1760 * as many outputs as there are inputs.
1761 * Delivery::configure_io() will do the actual removal
1762 * by calling _output->ensure_io()
1764 if (!is_master() && _session.master_out () && in.n_audio() > 0) {
1765 /* ..but at least as many as there are master-inputs, if
1766 * the delivery is dealing with audio */
1767 // XXX this may need special-casing for mixbus (master-outputs)
1768 // and should maybe be a preference anyway ?!
1769 out = ChanCount::max (in, _session.master_out ()->n_inputs ());
1775 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID=%2 in=%3 out=%4\n",(*p)->name(), (*p)->id(), in, out));
1776 configuration.push_back(make_pair(in, out));
1779 // restriction for Monitor Section Processors
1780 if (in.n_audio() != out.n_audio() || out.n_midi() > 0) {
1781 /* Note: The Monitor follows the master-bus and has no panner.
1783 * The general idea is to only allow plugins that retain the channel-count
1784 * and plugins with MIDI in (e.g VSTs with control that will remain unconnected).
1785 * Then again 5.1 in, monitor stereo is a valid use-case.
1787 * and worse: we only refuse adding plugins *here*.
1789 * 1) stereo-master, stereo-mon, add a stereo-plugin, OK
1790 * 2) change master-bus, add a channel
1791 * 2a) monitor-secion follows
1792 * 3) monitor processors fail to re-reconfigure (stereo plugin)
1793 * 4) re-load session, monitor-processor remains unconfigured, crash.
1795 DEBUG_TRACE (DEBUG::Processors, "Monitor: Channel configuration change.\n");
1797 if (boost::dynamic_pointer_cast<InternalSend> (*p)) {
1798 // internal sends make no sense, only feedback
1799 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1800 return list<pair<ChanCount, ChanCount> > ();
1802 if (boost::dynamic_pointer_cast<PortInsert> (*p)) {
1803 /* External Sends can be problematic. one can add/remove ports
1804 * there signal leaves the DAW to external monitors anyway, so there's
1805 * no real use for allowing them here anyway.
1807 DEBUG_TRACE (DEBUG::Processors, "Monitor: No External Sends allowed.\n");
1808 return list<pair<ChanCount, ChanCount> > ();
1810 if (boost::dynamic_pointer_cast<Send> (*p)) {
1812 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1813 return list<pair<ChanCount, ChanCount> > ();
1822 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
1823 DEBUG_TRACE (DEBUG::Processors, string_compose ("---- %1 cannot support in=%2 out=%3\n", (*p)->name(), in, out));
1824 DEBUG_TRACE (DEBUG::Processors, "}\n");
1825 return list<pair<ChanCount, ChanCount> > ();
1829 DEBUG_TRACE (DEBUG::Processors, "}\n");
1831 return configuration;
1834 /** Set the input/output configuration of each processor in the processors list.
1835 * Caller must hold process lock.
1836 * Return 0 on success, otherwise configuration is impossible.
1839 Route::configure_processors_unlocked (ProcessorStreams* err, Glib::Threads::RWLock::WriterLock* lm)
1841 #ifndef PLATFORM_WINDOWS
1842 assert (!AudioEngine::instance()->process_lock().trylock());
1845 if (_in_configure_processors) {
1849 /* put invisible processors where they should be */
1850 setup_invisible_processors ();
1852 _in_configure_processors = true;
1854 list<pair<ChanCount, ChanCount> > configuration = try_configure_processors_unlocked (input_streams (), err);
1856 if (configuration.empty ()) {
1857 _in_configure_processors = false;
1862 bool seen_mains_out = false;
1863 processor_out_streams = _input->n_ports();
1864 processor_max_streams.reset();
1866 /* processor configure_io() may result in adding ports
1867 * e.g. Delivery::configure_io -> ARDOUR::IO::ensure_io ()
1869 * with jack2 adding ports results in a graph-order callback,
1870 * which calls Session::resort_routes() and eventually
1871 * Route::direct_feeds_according_to_reality()
1872 * which takes a ReaderLock (_processor_lock).
1874 * so we can't hold a WriterLock here until jack2 threading
1877 * NB. we still hold the process lock
1879 * (ardour's own engines do call graph-order from the
1880 * process-thread and hence do not have this issue; besides
1881 * merely adding ports won't trigger a graph-order, only
1882 * making connections does)
1886 // TODO check for a potential ReaderLock after ReaderLock ??
1887 Glib::Threads::RWLock::ReaderLock lr (_processor_lock);
1889 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1890 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1892 if (!(*p)->configure_io(c->first, c->second)) {
1893 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration failed\n", _name));
1894 _in_configure_processors = false;
1900 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1901 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1903 boost::shared_ptr<IOProcessor> iop;
1904 boost::shared_ptr<PluginInsert> pi;
1905 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
1906 /* plugins connected via Split or Hide Match may have more channels.
1907 * route/scratch buffers are needed for all of them
1908 * The configuration may only be a subset (both input and output)
1910 processor_max_streams = ChanCount::max(processor_max_streams, pi->required_buffers());
1912 else if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*p)) != 0) {
1913 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_input_streams());
1914 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_output_streams());
1918 if (boost::dynamic_pointer_cast<Delivery> (*p)
1919 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main) {
1920 /* main delivery will increase port count to match input.
1921 * the Delivery::Main is usually the last processor - followed only by
1924 seen_mains_out = true;
1926 if (!seen_mains_out) {
1927 processor_out_streams = out;
1936 _meter->set_max_channels (processor_max_streams);
1939 /* make sure we have sufficient scratch buffers to cope with the new processor
1942 _session.ensure_buffers (n_process_buffers ());
1944 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration complete\n", _name));
1946 _in_configure_processors = false;
1950 /** Set all visible processors to a given active state (except Fader, whose state is not changed)
1951 * @param state New active state for those processors.
1954 Route::all_visible_processors_active (bool state)
1956 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1958 if (_processors.empty()) {
1962 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1963 if (!(*i)->display_to_user() || boost::dynamic_pointer_cast<Amp> (*i)) {
1967 boost::shared_ptr<PluginInsert> pi;
1968 if (0 != (pi = boost::dynamic_pointer_cast<PluginInsert>(*i))) {
1969 if (pi->is_channelstrip ()) {
1974 (*i)->enable (state);
1977 _session.set_dirty ();
1981 Route::processors_reorder_needs_configure (const ProcessorList& new_order)
1983 /* check if re-order requires re-configuration of any processors
1984 * -> compare channel configuration for all processors
1986 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1987 ChanCount c = input_streams ();
1989 for (ProcessorList::const_iterator j = new_order.begin(); j != new_order.end(); ++j) {
1991 if (c != (*j)->input_streams()) {
1994 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1997 if ((*i)->input_streams() != c) {
2000 c = (*i)->output_streams();
2012 __attribute__((annotate("realtime")))
2015 Route::apply_processor_order (const ProcessorList& new_order)
2017 /* need to hold processor_lock; either read or write lock
2018 * and the engine process_lock.
2019 * Due to r/w lock ambiguity we can only assert the latter
2021 assert (!AudioEngine::instance()->process_lock().trylock());
2024 /* "new_order" is an ordered list of processors to be positioned according to "placement".
2025 * NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
2026 * processors in the current actual processor list that are hidden. Any visible processors
2027 * in the current list but not in "new_order" will be assumed to be deleted.
2030 /* "as_it_will_be" and "_processors" are lists of shared pointers.
2031 * actual memory usage is small, but insert/erase is not actually rt-safe :(
2032 * (note though that ::processors_reorder_needs_configure() ensured that
2033 * this function will only ever be called from the rt-thread if no processor were removed)
2035 * either way, I can't proove it, but an x-run due to re-order here is less likley
2036 * than an x-run-less 'ardour-silent cycle' both of which effectively "click".
2039 ProcessorList as_it_will_be;
2040 ProcessorList::iterator oiter;
2041 ProcessorList::const_iterator niter;
2043 oiter = _processors.begin();
2044 niter = new_order.begin();
2046 while (niter != new_order.end()) {
2048 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
2049 then append it to the temp list.
2051 Otherwise, see if the next processor in the old list is in the new list. if not,
2052 its been deleted. If its there, append it to the temp list.
2055 if (oiter == _processors.end()) {
2057 /* no more elements in the old list, so just stick the rest of
2058 the new order onto the temp list.
2061 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
2062 while (niter != new_order.end()) {
2069 if (!(*oiter)->display_to_user()) {
2071 as_it_will_be.push_back (*oiter);
2075 /* visible processor: check that its in the new order */
2077 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
2078 /* deleted: do nothing, shared_ptr<> will clean up */
2080 /* ignore this one, and add the next item from the new order instead */
2081 as_it_will_be.push_back (*niter);
2086 /* now remove from old order - its taken care of no matter what */
2087 oiter = _processors.erase (oiter);
2091 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
2093 /* If the meter is in a custom position, find it and make a rough note of its position */
2094 maybe_note_meter_position ();
2098 Route::move_instrument_down (bool postfader)
2100 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2101 ProcessorList new_order;
2102 boost::shared_ptr<Processor> instrument;
2103 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2104 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
2105 if (pi && pi->plugin ()->get_info ()->is_instrument ()) {
2107 } else if (instrument && *i == _amp) {
2109 new_order.push_back (*i);
2110 new_order.push_back (instrument);
2112 new_order.push_back (instrument);
2113 new_order.push_back (*i);
2116 new_order.push_back (*i);
2123 reorder_processors (new_order, 0);
2127 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
2129 // it a change is already queued, wait for it
2130 // (unless engine is stopped. apply immediately and proceed
2131 while (g_atomic_int_get (&_pending_process_reorder)) {
2132 if (!AudioEngine::instance()->running()) {
2133 DEBUG_TRACE (DEBUG::Processors, "offline apply queued processor re-order.\n");
2134 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2136 apply_processor_order(_pending_processor_order);
2137 setup_invisible_processors ();
2139 g_atomic_int_set (&_pending_process_reorder, 0);
2141 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2142 set_processor_positions ();
2144 // TODO rather use a semaphore or something.
2145 // but since ::reorder_processors() is called
2146 // from the GUI thread, this is fine..
2151 if (processors_reorder_needs_configure (new_order) || !AudioEngine::instance()->running()) {
2153 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2154 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2155 ProcessorState pstate (this);
2157 apply_processor_order (new_order);
2159 if (configure_processors_unlocked (err, &lm)) {
2167 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2168 set_processor_positions ();
2171 DEBUG_TRACE (DEBUG::Processors, "Queue clickless processor re-order.\n");
2172 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2174 // _pending_processor_order is protected by _processor_lock
2175 _pending_processor_order = new_order;
2176 g_atomic_int_set (&_pending_process_reorder, 1);
2179 /* update processor input/output latency
2180 * (total signal_latency does not change)
2182 update_signal_latency (true);
2188 Route::add_remove_sidechain (boost::shared_ptr<Processor> proc, bool add)
2190 boost::shared_ptr<PluginInsert> pi;
2191 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2195 if (pi->has_sidechain () == add) {
2196 return true; // ?? call failed, but result is as expected.
2200 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2201 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2202 if (i == _processors.end ()) {
2208 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ()); // take before Writerlock to avoid deadlock
2209 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2210 PBD::Unwinder<bool> uw (_in_sidechain_setup, true);
2212 lx.release (); // IO::add_port() and ~IO takes process lock - XXX check if this is safe
2214 if (!pi->add_sidechain ()) {
2218 if (!pi->del_sidechain ()) {
2224 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2229 pi->del_sidechain ();
2231 pi->add_sidechain ();
2232 // TODO restore side-chain's state.
2237 configure_processors_unlocked (0, &lm);
2240 if (pi->has_sidechain ()) {
2241 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
2244 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2245 _session.set_dirty ();
2250 Route::plugin_preset_output (boost::shared_ptr<Processor> proc, ChanCount outs)
2252 boost::shared_ptr<PluginInsert> pi;
2253 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2258 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2259 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2260 if (i == _processors.end ()) {
2266 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2267 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2269 const ChanCount& old (pi->preset_out ());
2270 if (!pi->set_preset_out (outs)) {
2271 return true; // no change, OK
2274 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2277 pi->set_preset_out (old);
2280 configure_processors_unlocked (0, &lm);
2283 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2284 _session.set_dirty ();
2289 Route::reset_plugin_insert (boost::shared_ptr<Processor> proc)
2292 return customize_plugin_insert (proc, 0, unused, unused);
2296 Route::customize_plugin_insert (boost::shared_ptr<Processor> proc, uint32_t count, ChanCount outs, ChanCount sinks)
2298 boost::shared_ptr<PluginInsert> pi;
2299 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2304 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2305 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2306 if (i == _processors.end ()) {
2312 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2313 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2315 bool old_cust = pi->custom_cfg ();
2316 uint32_t old_cnt = pi->get_count ();
2317 ChanCount old_chan = pi->output_streams ();
2318 ChanCount old_sinks = pi->natural_input_streams ();
2321 pi->set_custom_cfg (false);
2323 pi->set_custom_cfg (true);
2324 pi->set_count (count);
2325 pi->set_outputs (outs);
2326 pi->set_sinks (sinks);
2329 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2333 pi->set_count (old_cnt);
2334 pi->set_sinks (old_sinks);
2335 pi->set_outputs (old_chan);
2336 pi->set_custom_cfg (old_cust);
2340 configure_processors_unlocked (0, &lm);
2343 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2344 _session.set_dirty ();
2349 Route::set_strict_io (const bool enable)
2351 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2353 if (_strict_io != enable) {
2354 _strict_io = enable;
2355 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2356 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2357 boost::shared_ptr<PluginInsert> pi;
2358 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2359 pi->set_strict_io (_strict_io);
2363 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2367 _strict_io = !enable; // restore old value
2368 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2369 boost::shared_ptr<PluginInsert> pi;
2370 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2371 pi->set_strict_io (_strict_io);
2378 configure_processors (0);
2381 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2382 _session.set_dirty ();
2390 return state (false);
2394 Route::get_template()
2396 return state (true);
2400 Route::state (bool save_template)
2402 if (!_session._template_state_dir.empty()) {
2403 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), _session._template_state_dir));
2406 XMLNode *node = new XMLNode("Route");
2407 ProcessorList::iterator i;
2409 node->set_property (X_("id"), id ());
2410 node->set_property (X_("name"), name());
2411 node->set_property (X_("default-type"), _default_type);
2412 node->set_property (X_("strict-io"), _strict_io);
2414 node->add_child_nocopy (_presentation_info.get_state());
2416 node->set_property (X_("active"), _active);
2417 node->set_property (X_("denormal-protection"), _denormal_protection);
2418 node->set_property (X_("meter-point"), _meter_point);
2419 node->set_property (X_("disk-io-point"), _disk_io_point);
2421 node->set_property (X_("meter-type"), _meter_type);
2424 node->set_property (X_("route-group"), _route_group->name());
2427 node->add_child_nocopy (_solo_control->get_state ());
2428 node->add_child_nocopy (_solo_isolate_control->get_state ());
2429 node->add_child_nocopy (_solo_safe_control->get_state ());
2431 node->add_child_nocopy (_input->get_state ());
2432 node->add_child_nocopy (_output->get_state ());
2433 node->add_child_nocopy (_mute_master->get_state ());
2435 node->add_child_nocopy (_mute_control->get_state ());
2436 node->add_child_nocopy (_phase_control->get_state ());
2438 if (!skip_saving_automation) {
2439 node->add_child_nocopy (Automatable::get_automation_xml_state ());
2442 if (_comment.length()) {
2443 XMLNode *cmt = node->add_child ("Comment");
2444 cmt->add_content (_comment);
2448 node->add_child_nocopy (_pannable->get_state ());
2452 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2453 for (i = _processors.begin(); i != _processors.end(); ++i) {
2454 if (*i == _delayline) {
2457 if (save_template) {
2458 /* template save: do not include internal sends functioning as
2459 aux sends because the chance of the target ID
2460 in the session where this template is used
2463 similarly, do not save listen sends which connect to
2464 the monitor section, because these will always be
2467 boost::shared_ptr<InternalSend> is;
2469 if ((is = boost::dynamic_pointer_cast<InternalSend> (*i)) != 0) {
2470 if (is->role() == Delivery::Listen) {
2475 node->add_child_nocopy((*i)->get_state ());
2480 node->add_child_copy (*_extra_xml);
2483 if (_custom_meter_position_noted) {
2484 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
2486 node->set_property (X_("processor-after-last-custom-meter"), after->id());
2490 if (!_session._template_state_dir.empty()) {
2491 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), ""));
2494 node->add_child_copy (Slavable::get_state());
2500 Route::set_state (const XMLNode& node, int version)
2502 if (version < 3000) {
2503 return set_state_2X (node, version);
2507 XMLNodeConstIterator niter;
2510 if (node.name() != "Route"){
2511 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2515 std::string route_name;
2516 if (node.get_property (X_("name"), route_name)) {
2517 Route::set_name (route_name);
2521 _initial_io_setup = true;
2523 Stripable::set_state (node, version);
2525 node.get_property (X_("strict-io"), _strict_io);
2528 /* monitor bus does not get a panner, but if (re)created
2529 via XML, it will already have one by the time we
2530 call ::set_state(). so ... remove it.
2535 /* add all processors (except amp, which is always present) */
2537 nlist = node.children();
2538 XMLNode processor_state (X_("processor_state"));
2540 Stateful::save_extra_xml (node);
2542 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2546 if (child->name() == IO::state_node_name) {
2547 std::string direction;
2548 if (!child->get_property (X_("direction"), direction)) {
2552 if (direction == "Input") {
2553 _input->set_state (*child, version);
2554 } else if (direction == "Output") {
2555 _output->set_state (*child, version);
2558 } else if (child->name() == X_("Processor")) {
2559 processor_state.add_child_copy (*child);
2560 } else if (child->name() == X_("Pannable")) {
2562 _pannable->set_state (*child, version);
2564 warning << string_compose (_("Pannable state found for route (%1) without a panner!"), name()) << endmsg;
2566 } else if (child->name() == Slavable::xml_node_name) {
2567 Slavable::set_state (*child, version);
2572 if (node.get_property (X_("meter-point"), mp)) {
2573 set_meter_point (mp, true);
2575 _meter->set_display_to_user (_meter_point == MeterCustom);
2580 if (node.get_property (X_("disk-io-point"), diop)) {
2582 _disk_writer->set_display_to_user (diop == DiskIOCustom);
2585 _disk_reader->set_display_to_user (diop == DiskIOCustom);
2587 set_disk_io_point (diop);
2590 node.get_property (X_("meter-type"), _meter_type);
2592 _initial_io_setup = false;
2594 set_processor_state (processor_state);
2596 // this looks up the internal instrument in processors
2597 reset_instrument_info();
2599 bool denormal_protection;
2600 if (node.get_property (X_("denormal-protection"), denormal_protection)) {
2601 set_denormal_protection (denormal_protection);
2604 /* convert old 3001 state */
2605 std::string phase_invert_str;
2606 if (node.get_property (X_("phase-invert"), phase_invert_str)) {
2607 _phase_control->set_phase_invert (boost::dynamic_bitset<> (phase_invert_str));
2611 if (node.get_property (X_("active"), is_active)) {
2612 set_active (is_active, this);
2615 std::string id_string;
2616 if (node.get_property (X_("processor-after-last-custom-meter"), id_string)) {
2617 PBD::ID id (id_string);
2618 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2619 ProcessorList::const_iterator i = _processors.begin ();
2620 while (i != _processors.end() && (*i)->id() != id) {
2624 if (i != _processors.end ()) {
2625 _processor_after_last_custom_meter = *i;
2626 _custom_meter_position_noted = true;
2630 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2633 if (child->name() == X_("Comment")) {
2635 /* XXX this is a terrible API design in libxml++ */
2637 XMLNode *cmt = *(child->children().begin());
2638 _comment = cmt->content();
2640 } else if (child->name() == Controllable::xml_node_name) {
2641 std::string control_name;
2642 if (!child->get_property (X_("name"), control_name)) {
2646 if (control_name == _solo_control->name()) {
2647 _solo_control->set_state (*child, version);
2648 } else if (control_name == _solo_safe_control->name()) {
2649 _solo_safe_control->set_state (*child, version);
2650 } else if (control_name == _solo_isolate_control->name()) {
2651 _solo_isolate_control->set_state (*child, version);
2652 } else if (control_name == _mute_control->name()) {
2653 _mute_control->set_state (*child, version);
2654 } else if (control_name == _phase_control->name()) {
2655 _phase_control->set_state (*child, version);
2657 Evoral::Parameter p = EventTypeMap::instance().from_symbol (control_name);
2658 if (p.type () >= MidiCCAutomation && p.type () < MidiSystemExclusiveAutomation) {
2659 boost::shared_ptr<AutomationControl> ac = automation_control (p, true);
2661 ac->set_state (*child, version);
2665 } else if (child->name() == MuteMaster::xml_node_name) {
2666 _mute_master->set_state (*child, version);
2668 } else if (child->name() == Automatable::xml_node_name) {
2669 set_automation_xml_state (*child, Evoral::Parameter(NullAutomation));
2674 _delayline->set_name (name ());
2681 Route::set_state_2X (const XMLNode& node, int version)
2685 XMLNodeConstIterator niter;
2687 XMLProperty const * prop;
2689 /* 2X things which still remain to be handled:
2695 if (node.name() != "Route") {
2696 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2700 Stripable::set_state (node, version);
2702 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2703 set_denormal_protection (string_to<bool> (prop->value()));
2706 if ((prop = node.property (X_("muted"))) != 0) {
2709 bool muted = string_to<bool> (prop->value());
2715 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2717 if (string_to<bool> (prop->value())){
2718 mute_point = mute_point + "PreFader";
2723 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2725 if (string_to<bool> (prop->value())){
2728 mute_point = mute_point + ",";
2731 mute_point = mute_point + "PostFader";
2736 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2738 if (string_to<bool> (prop->value())){
2741 mute_point = mute_point + ",";
2744 mute_point = mute_point + "Listen";
2749 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2751 if (string_to<bool> (prop->value())){
2754 mute_point = mute_point + ",";
2757 mute_point = mute_point + "Main";
2761 _mute_master->set_mute_points (mute_point);
2762 _mute_master->set_muted_by_self (true);
2766 if ((prop = node.property (X_("meter-point"))) != 0) {
2767 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2772 nlist = node.children ();
2773 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2777 if (child->name() == IO::state_node_name) {
2779 /* there is a note in IO::set_state_2X() about why we have to call
2783 _input->set_state_2X (*child, version, true);
2784 _output->set_state_2X (*child, version, false);
2786 if ((prop = child->property (X_("name"))) != 0) {
2787 Route::set_name (prop->value ());
2792 if ((prop = child->property (X_("active"))) != 0) {
2793 bool yn = string_to<bool> (prop->value());
2794 _active = !yn; // force switch
2795 set_active (yn, this);
2798 if ((prop = child->property (X_("gain"))) != 0) {
2801 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
2802 _amp->gain_control()->set_value (val, Controllable::NoGroup);
2806 /* Set up Panners in the IO */
2807 XMLNodeList io_nlist = child->children ();
2809 XMLNodeConstIterator io_niter;
2812 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
2814 io_child = *io_niter;
2816 if (io_child->name() == X_("Panner")) {
2817 _main_outs->panner_shell()->set_state(*io_child, version);
2818 } else if (io_child->name() == X_("Automation")) {
2819 /* IO's automation is for the fader */
2820 _amp->set_automation_xml_state (*io_child, Evoral::Parameter (GainAutomation));
2826 XMLNodeList redirect_nodes;
2828 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2832 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2833 redirect_nodes.push_back(child);
2838 set_processor_state_2X (redirect_nodes, version);
2840 Stateful::save_extra_xml (node);
2842 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2845 if (child->name() == X_("Comment")) {
2847 /* XXX this is a terrible API design in libxml++ */
2849 XMLNode *cmt = *(child->children().begin());
2850 _comment = cmt->content();
2852 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2853 if (prop->value() == X_("solo")) {
2854 _solo_control->set_state (*child, version);
2855 } else if (prop->value() == X_("mute")) {
2856 _mute_control->set_state (*child, version);
2866 Route::get_processor_state ()
2868 XMLNode* root = new XMLNode (X_("redirects"));
2869 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2870 root->add_child_nocopy ((*i)->get_state ());
2877 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2879 /* We don't bother removing existing processors not in nList, as this
2880 method will only be called when creating a Route from scratch, not
2881 for undo purposes. Just put processors in at the appropriate place
2885 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2886 add_processor_from_xml_2X (**i, version);
2891 Route::set_processor_state (const XMLNode& node)
2893 const XMLNodeList &nlist = node.children();
2894 XMLNodeConstIterator niter;
2895 ProcessorList new_order;
2896 bool must_configure = false;
2898 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2900 XMLProperty* prop = (*niter)->property ("type");
2902 if (prop->value() == "amp") {
2903 _amp->set_state (**niter, Stateful::current_state_version);
2904 new_order.push_back (_amp);
2905 } else if (prop->value() == "trim") {
2906 _trim->set_state (**niter, Stateful::current_state_version);
2907 new_order.push_back (_trim);
2908 } else if (prop->value() == "meter") {
2909 _meter->set_state (**niter, Stateful::current_state_version);
2910 new_order.push_back (_meter);
2911 } else if (prop->value() == "polarity") {
2912 _polarity->set_state (**niter, Stateful::current_state_version);
2913 new_order.push_back (_polarity);
2914 } else if (prop->value() == "delay") {
2916 } else if (prop->value() == "main-outs") {
2917 _main_outs->set_state (**niter, Stateful::current_state_version);
2918 } else if (prop->value() == "intreturn") {
2920 _intreturn.reset (new InternalReturn (_session));
2921 must_configure = true;
2923 _intreturn->set_state (**niter, Stateful::current_state_version);
2924 } else if (is_monitor() && prop->value() == "monitor") {
2925 if (!_monitor_control) {
2926 _monitor_control.reset (new MonitorProcessor (_session));
2927 must_configure = true;
2929 _monitor_control->set_state (**niter, Stateful::current_state_version);
2930 } else if (prop->value() == "capture") {
2931 /* CapturingProcessor should never be restored, it's always
2932 added explicitly when needed */
2933 } else if (prop->value() == "diskreader" && _disk_reader) {
2934 _disk_reader->set_state (**niter, Stateful::current_state_version);
2935 new_order.push_back (_disk_reader);
2936 } else if (prop->value() == "diskwriter" && _disk_writer) {
2937 _disk_writer->set_state (**niter, Stateful::current_state_version);
2938 new_order.push_back (_disk_writer);
2940 set_processor_state (**niter, prop, new_order, must_configure);
2944 ProcessorList old_list = _processors; // keep a copy
2946 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2947 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2948 /* re-assign _processors w/o process-lock.
2949 * if there's an IO-processor present in _processors but
2950 * not in new_order, it will be deleted and ~IO takes
2953 _processors = new_order;
2955 if (must_configure) {
2956 configure_processors_unlocked (0, &lm);
2959 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2961 (*i)->set_owner (this);
2962 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
2964 boost::shared_ptr<PluginInsert> pi;
2966 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
2967 if (pi->has_no_inputs ()) {
2968 _have_internal_generator = true;
2974 /* drop references w/o process-lock (I/O procs may re-take it in ~IO() */
2977 reset_instrument_info ();
2978 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2979 set_processor_positions ();
2983 Route::set_processor_state (XMLNode const & node, XMLProperty const* prop, ProcessorList& new_order, bool& must_configure)
2985 ProcessorList::iterator o;
2987 for (o = _processors.begin(); o != _processors.end(); ++o) {
2988 XMLProperty const * id_prop = node.property(X_("id"));
2989 if (id_prop && (*o)->id() == id_prop->value()) {
2990 (*o)->set_state (node, Stateful::current_state_version);
2991 new_order.push_back (*o);
2996 // If the processor (node) is not on the route then create it
2998 if (o == _processors.end()) {
3000 boost::shared_ptr<Processor> processor;
3002 if (prop->value() == "intsend") {
3004 processor.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), boost::shared_ptr<Route>(), Delivery::Aux, true));
3006 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
3007 prop->value() == "lv2" ||
3008 prop->value() == "windows-vst" ||
3009 prop->value() == "mac-vst" ||
3010 prop->value() == "lxvst" ||
3011 prop->value() == "luaproc" ||
3012 prop->value() == "audiounit") {
3014 if (_session.get_disable_all_loaded_plugins ()) {
3015 processor.reset (new UnknownProcessor (_session, node));
3017 processor.reset (new PluginInsert (_session));
3018 processor->set_owner (this);
3020 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
3021 pi->set_strict_io (true);
3025 } else if (prop->value() == "port") {
3027 processor.reset (new PortInsert (_session, _pannable, _mute_master));
3029 } else if (prop->value() == "send") {
3031 processor.reset (new Send (_session, _pannable, _mute_master, Delivery::Send, true));
3032 boost::shared_ptr<Send> send = boost::dynamic_pointer_cast<Send> (processor);
3033 send->SelfDestruct.connect_same_thread (*this,
3034 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (processor)));
3040 if (processor->set_state (node, Stateful::current_state_version) != 0) {
3041 /* This processor could not be configured. Turn it into a UnknownProcessor */
3042 processor.reset (new UnknownProcessor (_session, node));
3045 /* subscribe to Sidechain IO changes */
3046 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
3047 if (pi && pi->has_sidechain ()) {
3048 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
3051 /* we have to note the monitor send here, otherwise a new one will be created
3052 and the state of this one will be lost.
3054 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
3055 if (isend && isend->role() == Delivery::Listen) {
3056 _monitor_send = isend;
3059 /* it doesn't matter if invisible processors are added here, as they
3060 will be sorted out by setup_invisible_processors () shortly.
3063 new_order.push_back (processor);
3064 must_configure = true;
3070 Route::curve_reallocate ()
3072 // _gain_automation_curve.finish_resize ();
3073 // _pan_automation_curve.finish_resize ();
3077 Route::silence (samplecnt_t nframes)
3079 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3084 silence_unlocked (nframes);
3088 Route::silence_unlocked (samplecnt_t nframes)
3090 /* Must be called with the processor lock held */
3092 const samplepos_t now = _session.transport_sample ();
3094 _output->silence (nframes);
3096 // update owned automated controllables
3097 automation_run (now, nframes);
3099 _pannable->automation_run (now, nframes);
3102 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3103 boost::shared_ptr<PluginInsert> pi;
3105 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
3106 /* evaluate automated automation controls */
3107 pi->automation_run (now, nframes);
3108 /* skip plugins, they don't need anything when we're not active */
3112 (*i)->silence (nframes, now);
3117 Route::add_internal_return ()
3120 _intreturn.reset (new InternalReturn (_session));
3121 add_processor (_intreturn, PreFader);
3126 Route::add_send_to_internal_return (InternalSend* send)
3128 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3130 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3131 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3134 return d->add_send (send);
3140 Route::remove_send_from_internal_return (InternalSend* send)
3142 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3144 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3145 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3148 return d->remove_send (send);
3154 Route::enable_monitor_send ()
3156 /* Caller must hold process lock */
3157 assert (!AudioEngine::instance()->process_lock().trylock());
3159 /* master never sends to monitor section via the normal mechanism */
3160 assert (!is_master ());
3161 assert (!is_monitor ());
3163 /* make sure we have one */
3164 if (!_monitor_send) {
3165 _monitor_send.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), _session.monitor_out(), Delivery::Listen));
3166 _monitor_send->set_display_to_user (false);
3170 configure_processors (0);
3173 /** Add an aux send to a route.
3174 * @param route route to send to.
3175 * @param before Processor to insert before, or 0 to insert at the end.
3178 Route::add_aux_send (boost::shared_ptr<Route> route, boost::shared_ptr<Processor> before)
3180 assert (route != _session.monitor_out ());
3183 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3185 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3187 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend> (*x);
3189 if (d && d->target_route() == route) {
3190 /* already listening via the specified IO: do nothing */
3198 boost::shared_ptr<InternalSend> listener;
3201 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
3202 listener.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), route, Delivery::Aux));
3205 add_processor (listener, before);
3207 } catch (failed_constructor& err) {
3215 Route::remove_aux_or_listen (boost::shared_ptr<Route> route)
3217 ProcessorStreams err;
3218 ProcessorList::iterator tmp;
3221 Glib::Threads::RWLock::ReaderLock rl(_processor_lock);
3223 /* have to do this early because otherwise processor reconfig
3224 * will put _monitor_send back in the list
3227 if (route == _session.monitor_out()) {
3228 _monitor_send.reset ();
3232 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3234 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
3236 if (d && d->target_route() == route) {
3238 if (remove_processor (*x, &err, false) > 0) {
3244 /* list could have been demolished while we dropped the lock
3247 if (_session.engine().connected()) {
3248 /* i/o processors cannot be removed if the engine is not running
3249 * so don't live-loop in case the engine is N/A or dies
3259 Route::set_comment (string cmt, void *src)
3263 _session.set_dirty ();
3267 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
3269 FeedRecord fr (other, via_sends_only);
3271 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
3273 if (!result.second) {
3275 /* already a record for "other" - make sure sends-only information is correct */
3276 if (!via_sends_only && result.first->sends_only) {
3277 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
3278 frp->sends_only = false;
3282 return result.second;
3286 Route::clear_fed_by ()
3292 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
3294 const FedBy& fed_by (other->fed_by());
3296 for (FedBy::const_iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
3297 boost::shared_ptr<Route> sr = f->r.lock();
3299 if (sr && (sr.get() == this)) {
3301 if (via_sends_only) {
3302 *via_sends_only = f->sends_only;
3313 Route::all_inputs () const
3315 /* TODO, if this works as expected,
3316 * cache the IOVector and maintain it via
3317 * input_change_handler(), sidechain_change_handler() etc
3320 ios.push_back (_input);
3322 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3323 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3325 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3326 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3329 iop = pi->sidechain();
3332 if (iop != 0 && iop->input()) {
3333 ios.push_back (iop->input());
3340 Route::all_outputs () const
3343 // _output is included via Delivery
3344 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3345 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3346 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3347 if (iop != 0 && iop->output()) {
3348 ios.push_back (iop->output());
3355 Route::direct_feeds_according_to_reality (boost::shared_ptr<Route> other, bool* via_send_only)
3357 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
3358 if (other->all_inputs().fed_by (_output)) {
3359 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
3360 if (via_send_only) {
3361 *via_send_only = false;
3367 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3369 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
3371 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3372 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3375 iop = pi->sidechain();
3379 boost::shared_ptr<const IO> iop_out = iop->output();
3380 if (other.get() == this && iop_out && iop->input() && iop_out->connected_to (iop->input())) {
3381 // TODO this needs a delaylines in the Insert to align connections (!)
3382 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed its own return (%2)\n", iop->name(), other->name()));
3385 if ((iop_out && other->all_inputs().fed_by (iop_out)) || iop->feeds (other)) {
3386 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
3387 if (via_send_only) {
3388 *via_send_only = true;
3392 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
3395 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
3400 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
3405 Route::direct_feeds_according_to_graph (boost::shared_ptr<Route> other, bool* via_send_only)
3407 return _session._current_route_graph.has (boost::dynamic_pointer_cast<Route> (shared_from_this ()), other, via_send_only);
3411 Route::feeds_according_to_graph (boost::shared_ptr<Route> other)
3413 return _session._current_route_graph.feeds (boost::dynamic_pointer_cast<Route> (shared_from_this ()), other);
3416 /** Called from the (non-realtime) butler thread when the transport is stopped */
3418 Route::non_realtime_transport_stop (samplepos_t now, bool flush)
3420 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3422 Automatable::non_realtime_transport_stop (now, flush);
3424 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3426 if (!_have_internal_generator && (Config->get_plugins_stop_with_transport() && flush)) {
3430 (*i)->non_realtime_transport_stop (now, flush);
3435 Route::input_change_handler (IOChange change, void * /*src*/)
3437 if ((change.type & IOChange::ConfigurationChanged)) {
3438 /* This is called with the process lock held if change
3439 contains ConfigurationChanged
3441 configure_processors (0);
3442 io_changed (); /* EMIT SIGNAL */
3445 if (_solo_control->soloed_by_others_upstream() || _solo_isolate_control->solo_isolated_by_upstream()) {
3448 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3449 if (_input->connected()) {
3450 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3451 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3455 bool does_feed = (*i)->direct_feeds_according_to_reality (boost::dynamic_pointer_cast<Route> (shared_from_this()), &sends_only);
3456 if (does_feed && !sends_only) {
3457 if ((*i)->soloed()) {
3460 if ((*i)->solo_isolate_control()->solo_isolated()) {
3467 int delta = sbou - _solo_control->soloed_by_others_upstream();
3468 int idelta = ibou - _solo_isolate_control->solo_isolated_by_upstream();
3471 PBD::warning << string_compose (
3472 _("Invalid Solo-Isolate propagation: from:%1 new:%2 - old:%3 = delta:%4"),
3473 _name, ibou, _solo_isolate_control->solo_isolated_by_upstream(), idelta)
3478 if (_solo_control->soloed_by_others_upstream()) {
3479 // ignore new connections (they're not propagated)
3481 _solo_control->mod_solo_by_others_upstream (delta);
3485 if (_solo_isolate_control->solo_isolated_by_upstream()) {
3486 // solo-isolate currently only propagates downstream
3488 _solo_isolate_control->mod_solo_isolated_by_upstream (1);
3490 //_solo_isolated_by_upstream = ibou;
3493 // Session::route_solo_changed does not propagate indirect solo-changes
3494 // propagate downstream to tracks
3495 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3496 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3500 bool does_feed = feeds (*i, &sends_only);
3501 if (delta <= 0 && does_feed && !sends_only) {
3502 (*i)->solo_control()->mod_solo_by_others_upstream (delta);
3505 if (idelta < 0 && does_feed && !sends_only) {
3506 (*i)->solo_isolate_control()->mod_solo_isolated_by_upstream (-1);
3513 Route::output_change_handler (IOChange change, void * /*src*/)
3515 if (_initial_io_setup) {
3519 if ((change.type & IOChange::ConfigurationChanged)) {
3520 /* This is called with the process lock held if change
3521 contains ConfigurationChanged
3523 configure_processors (0);
3526 _session.reset_monitor_section();
3529 io_changed (); /* EMIT SIGNAL */
3532 if ((change.type & IOChange::ConnectionsChanged)) {
3534 /* do this ONLY if connections have changed. Configuration
3535 * changes do not, by themselves alter solo upstream or
3536 * downstream status.
3539 if (_solo_control->soloed_by_others_downstream()) {
3541 /* checking all all downstream routes for
3542 * explicit of implict solo is a rather drastic measure,
3543 * ideally the input_change_handler() of the other route
3544 * would propagate the change to us.
3546 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3547 if (_output->connected()) {
3548 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3549 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3553 bool does_feed = direct_feeds_according_to_reality (*i, &sends_only);
3554 if (does_feed && !sends_only) {
3555 if ((*i)->soloed()) {
3563 int delta = sbod - _solo_control->soloed_by_others_downstream();
3565 // do not allow new connections to change implicit solo (no propagation)
3566 _solo_control->mod_solo_by_others_downstream (delta);
3567 // Session::route_solo_changed() does not propagate indirect solo-changes
3568 // propagate upstream to tracks
3569 boost::shared_ptr<Route> shared_this = boost::dynamic_pointer_cast<Route> (shared_from_this());
3570 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3571 if ((*i).get() == this || !can_solo()) {
3575 bool does_feed = (*i)->feeds (shared_this, &sends_only);
3576 if (delta != 0 && does_feed && !sends_only) {
3577 (*i)->solo_control()->mod_solo_by_others_downstream (delta);
3587 Route::sidechain_change_handler (IOChange change, void* src)
3589 if (_initial_io_setup || _in_sidechain_setup) {
3593 input_change_handler (change, src);
3597 Route::pans_required () const
3599 if (n_outputs().n_audio() < 2) {
3603 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
3607 Route::flush_processor_buffers_locked (samplecnt_t nframes)
3609 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3610 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery> (*i);
3612 d->flush_buffers (nframes);
3614 boost::shared_ptr<PortInsert> p = boost::dynamic_pointer_cast<PortInsert> (*i);
3616 p->flush_buffers (nframes);
3623 Route::flush_processors ()
3625 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3627 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3633 Route::playback_latency (bool incl_downstream) const
3637 rv = _disk_reader->output_latency ();
3639 rv = _signal_latency;
3641 if (incl_downstream) {
3642 rv += _output->connected_latency (true);
3644 rv += _output->latency ();
3650 Route::latency_preroll (pframes_t nframes, samplepos_t& start_sample, samplepos_t& end_sample)
3652 samplecnt_t latency_preroll = _session.remaining_latency_preroll ();
3653 if (latency_preroll == 0) {
3656 if (!_disk_reader) {
3657 start_sample -= latency_preroll;
3658 end_sample -= latency_preroll;
3662 if (latency_preroll > playback_latency ()) {
3663 no_roll_unlocked (nframes, start_sample - latency_preroll, end_sample - latency_preroll, false);
3667 start_sample -= latency_preroll;
3668 end_sample -= latency_preroll;
3673 Route::roll (pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, int declick, bool& need_butler)
3675 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3682 silence_unlocked (nframes);
3687 if ((nframes = latency_preroll (nframes, start_sample, end_sample)) == 0) {
3691 run_route (start_sample, end_sample, nframes, declick, (!_disk_writer || !_disk_writer->record_enabled()) && _session.transport_rolling(), true);
3693 if ((_disk_reader && _disk_reader->need_butler()) || (_disk_writer && _disk_writer->need_butler())) {
3700 Route::no_roll (pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, bool session_state_changing)
3702 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3708 return no_roll_unlocked (nframes, start_sample, end_sample, session_state_changing);
3712 Route::no_roll_unlocked (pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, bool session_state_changing)
3714 /* Must be called with the processor lock held */
3717 silence_unlocked (nframes);
3722 if (session_state_changing) {
3723 if (_session.transport_speed() != 0.0f) {
3724 /* we're rolling but some state is changing (e.g. our diskstream contents)
3725 so we cannot use them. Be silent till this is over.
3727 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
3729 silence_unlocked (nframes);
3733 /* we're really not rolling, so we're either delivery silence or actually
3734 monitoring, both of which are safe to do while session_state_changing is true.
3738 run_route (start_sample, end_sample, nframes, 0, false, false);
3743 Route::silent_roll (pframes_t nframes, samplepos_t /*start_sample*/, samplepos_t /*end_sample*/, bool& /* need_butler */)
3746 flush_processor_buffers_locked (nframes);
3751 __attribute__((annotate("realtime")))
3754 Route::apply_processor_changes_rt ()
3756 int emissions = EmitNone;
3758 if (_pending_meter_point != _meter_point) {
3759 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3761 /* meters always have buffers for 'processor_max_streams'
3762 * they can be re-positioned without re-allocation */
3763 if (set_meter_point_unlocked()) {
3764 emissions |= EmitMeterChanged | EmitMeterVisibilityChange;;
3766 emissions |= EmitMeterChanged;
3771 bool changed = false;
3773 if (g_atomic_int_get (&_pending_process_reorder)) {
3774 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3776 apply_processor_order (_pending_processor_order);
3777 setup_invisible_processors ();
3779 g_atomic_int_set (&_pending_process_reorder, 0);
3780 emissions |= EmitRtProcessorChange;
3784 set_processor_positions ();
3785 /* update processor input/output latency
3786 * (total signal_latency does not change)
3788 update_signal_latency (true);
3790 if (emissions != 0) {
3791 g_atomic_int_set (&_pending_signals, emissions);
3794 return (!selfdestruct_sequence.empty ());
3798 Route::emit_pending_signals ()
3800 int sig = g_atomic_int_and (&_pending_signals, 0);
3801 if (sig & EmitMeterChanged) {
3802 _meter->emit_configuration_changed();
3803 meter_change (); /* EMIT SIGNAL */
3804 if (sig & EmitMeterVisibilityChange) {
3805 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3807 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3810 if (sig & EmitRtProcessorChange) {
3811 processors_changed (RouteProcessorChange (RouteProcessorChange::RealTimeChange)); /* EMIT SIGNAL */
3814 /* this would be a job for the butler.
3815 * Conceptually we should not take processe/processor locks here.
3816 * OTOH its more efficient (less overhead for summoning the butler and
3817 * telling her what do do) and signal emission is called
3818 * directly after the process callback, which decreases the chance
3819 * of x-runs when taking the locks.
3821 while (!selfdestruct_sequence.empty ()) {
3822 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
3823 if (selfdestruct_sequence.empty ()) { break; } // re-check with lock
3824 boost::shared_ptr<Processor> proc = selfdestruct_sequence.back ().lock ();
3825 selfdestruct_sequence.pop_back ();
3828 remove_processor (proc);
3834 Route::set_meter_point (MeterPoint p, bool force)
3836 if (_pending_meter_point == p && !force) {
3840 if (force || !AudioEngine::instance()->running()) {
3841 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3842 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3843 _pending_meter_point = p;
3844 _meter->emit_configuration_changed();
3845 meter_change (); /* EMIT SIGNAL */
3846 if (set_meter_point_unlocked()) {
3847 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3849 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3852 _pending_meter_point = p;
3858 __attribute__((annotate("realtime")))
3861 Route::set_meter_point_unlocked ()
3864 /* Caller must hold process and processor write lock */
3865 assert (!AudioEngine::instance()->process_lock().trylock());
3866 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3867 assert (!lm.locked ());
3870 _meter_point = _pending_meter_point;
3872 bool meter_was_visible_to_user = _meter->display_to_user ();
3874 if (!_custom_meter_position_noted) {
3875 maybe_note_meter_position ();
3878 if (_meter_point != MeterCustom) {
3880 _meter->set_display_to_user (false);
3882 setup_invisible_processors ();
3885 _meter->set_display_to_user (true);
3887 /* If we have a previous position for the custom meter, try to put it there */
3888 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
3890 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), after);
3891 if (i != _processors.end ()) {
3892 _processors.remove (_meter);
3893 _processors.insert (i, _meter);
3895 } else {// at end, right before the mains_out/panner
3896 _processors.remove (_meter);
3897 ProcessorList::iterator main = _processors.end();
3898 _processors.insert (--main, _meter);
3902 /* Set up the meter for its new position */
3904 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
3908 if (loc == _processors.begin()) {
3909 m_in = _input->n_ports();
3911 ProcessorList::iterator before = loc;
3913 m_in = (*before)->output_streams ();
3916 _meter->reflect_inputs (m_in);
3918 /* we do not need to reconfigure the processors, because the meter
3919 (a) is always ready to handle processor_max_streams
3920 (b) is always an N-in/N-out processor, and thus moving
3921 it doesn't require any changes to the other processors.
3924 /* these should really be done after releasing the lock
3925 * but all those signals are subscribed to with gui_thread()
3928 return (_meter->display_to_user() != meter_was_visible_to_user);
3932 Route::listen_position_changed ()
3935 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3936 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3937 ProcessorState pstate (this);
3939 if (configure_processors_unlocked (0, &lm)) {
3940 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
3942 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
3947 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3948 _session.set_dirty ();
3951 boost::shared_ptr<CapturingProcessor>
3952 Route::add_export_point()
3954 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3955 if (!_capturing_processor) {
3957 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3958 Glib::Threads::RWLock::WriterLock lw (_processor_lock);
3960 /* Align all tracks for stem-export w/o processing.
3961 * Compensate for all plugins between the this route's disk-reader
3962 * and the common final downstream output (ie alignment point for playback).
3964 _capturing_processor.reset (new CapturingProcessor (_session, playback_latency (true)));
3965 configure_processors_unlocked (0, &lw);
3966 _capturing_processor->activate ();
3969 return _capturing_processor;
3973 Route::update_signal_latency (bool apply_to_delayline)
3975 // TODO: bail out if !active() and set/assume _signal_latency = 0,
3976 // here or in Session::* ? -> also zero send latencies,
3977 // and make sure that re-enabling a route updates things again...
3979 samplecnt_t capt_lat_in = _input->connected_latency (false);
3980 samplecnt_t play_lat_out = _output->connected_latency (true);
3982 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3984 samplecnt_t l_in = 0;
3985 samplecnt_t l_out = _output->user_latency();
3986 for (ProcessorList::reverse_iterator i = _processors.rbegin(); i != _processors.rend(); ++i) {
3987 if (boost::shared_ptr<Send> snd = boost::dynamic_pointer_cast<Send> (*i)) {
3988 snd->set_delay_in (l_out + _output->latency());
3991 if (boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) {
3992 if (boost::shared_ptr<IO> pio = pi->sidechain_input ()) {
3993 samplecnt_t lat = l_out + _output->latency();
3994 pio->set_private_port_latencies (lat, true);
3995 pio->set_public_port_latencies (lat, true);
3998 (*i)->set_output_latency (l_out);
3999 if ((*i)->active ()) {
4000 l_out += (*i)->signal_latency ();
4004 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal signal latency = %2\n", _name, l_out));
4006 _signal_latency = l_out;
4008 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4010 /* set sidechain, send and insert port latencies */
4011 if (boost::shared_ptr<PortInsert> pi = boost::dynamic_pointer_cast<PortInsert> (*i)) {
4013 /* propagate playback latency from output to input */
4014 pi->input ()->set_private_port_latencies (play_lat_out + l_in, true);
4016 if (pi->output ()) {
4017 /* propagate capture latency from input to output */
4018 pi->output ()->set_private_port_latencies (capt_lat_in + l_in, false);
4021 } else if (boost::shared_ptr<Send> snd = boost::dynamic_pointer_cast<Send> (*i)) {
4022 if (snd->output ()) {
4023 /* set capture latency */
4024 snd->output ()->set_private_port_latencies (capt_lat_in + l_in, false);
4025 /* take send-target's playback latency into account */
4026 snd->set_delay_out (snd->output ()->connected_latency (true));
4030 (*i)->set_input_latency (l_in);
4031 (*i)->set_playback_offset (_signal_latency + _output->latency ());
4032 (*i)->set_capture_offset (_input->latency ());
4033 if ((*i)->active ()) {
4034 l_in += (*i)->signal_latency ();
4040 if (apply_to_delayline) {
4041 /* see also Session::post_playback_latency() */
4042 apply_latency_compensation ();
4045 if (_signal_latency != l_out) {
4046 signal_latency_changed (); /* EMIT SIGNAL */
4049 return _signal_latency;
4053 Route::set_user_latency (samplecnt_t nframes)
4055 _output->set_user_latency (nframes);
4056 _session.update_latency_compensation ();
4060 Route::apply_latency_compensation ()
4063 samplecnt_t old = _delayline->delay ();
4065 samplecnt_t play_lat_in = _input->connected_latency (true);
4066 samplecnt_t play_lat_out = _output->connected_latency (true);
4067 samplecnt_t latcomp = play_lat_in - play_lat_out - _signal_latency;
4070 samplecnt_t capt_lat_in = _input->connected_latency (false);
4071 samplecnt_t capt_lat_out = _output->connected_latency (false);
4072 samplecnt_t latcomp_capt = capt_lat_out - capt_lat_in - _signal_latency;
4074 cout << "ROUTE " << name() << " delay for " << latcomp << " (c: " << latcomp_capt << ")" << endl;
4077 _delayline->set_delay (latcomp > 0 ? latcomp : 0);
4079 if (old != _delayline->delay ()) {
4080 signal_latency_updated (); /* EMIT SIGNAL */
4086 Route::set_block_size (pframes_t nframes)
4088 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4089 (*i)->set_block_size (nframes);
4092 _session.ensure_buffers (n_process_buffers ());
4096 Route::protect_automation ()
4098 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
4099 (*i)->protect_automation();
4102 /** @param declick 1 to set a pending declick fade-in,
4103 * -1 to set a pending declick fade-out
4106 Route::set_pending_declick (int declick)
4109 /* this call is not allowed to turn off a pending declick */
4111 _pending_declick = declick;
4114 _pending_declick = 0;
4118 /** Shift automation forwards from a particular place, thereby inserting time.
4119 * Adds undo commands for any shifts that are performed.
4121 * @param pos Position to start shifting from.
4122 * @param samples Amount to shift forwards by.
4126 Route::shift (samplepos_t pos, samplecnt_t samples)
4128 /* gain automation */
4130 boost::shared_ptr<AutomationControl> gc = _amp->gain_control();
4132 XMLNode &before = gc->alist()->get_state ();
4133 gc->alist()->shift (pos, samples);
4134 XMLNode &after = gc->alist()->get_state ();
4135 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
4138 /* gain automation */
4140 boost::shared_ptr<AutomationControl> gc = _trim->gain_control();
4142 XMLNode &before = gc->alist()->get_state ();
4143 gc->alist()->shift (pos, samples);
4144 XMLNode &after = gc->alist()->get_state ();
4145 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
4148 // TODO mute automation ??
4150 /* pan automation */
4152 ControlSet::Controls& c (_pannable->controls());
4154 for (ControlSet::Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
4155 boost::shared_ptr<AutomationControl> pc = boost::dynamic_pointer_cast<AutomationControl> (ci->second);
4157 boost::shared_ptr<AutomationList> al = pc->alist();
4158 XMLNode& before = al->get_state ();
4159 al->shift (pos, samples);
4160 XMLNode& after = al->get_state ();
4161 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4166 /* redirect automation */
4168 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4169 for (ProcessorList::iterator i = _processors.begin (); i != _processors.end (); ++i) {
4171 set<Evoral::Parameter> parameters = (*i)->what_can_be_automated();
4173 for (set<Evoral::Parameter>::const_iterator p = parameters.begin (); p != parameters.end (); ++p) {
4174 boost::shared_ptr<AutomationControl> ac = (*i)->automation_control (*p);
4176 boost::shared_ptr<AutomationList> al = ac->alist();
4177 XMLNode &before = al->get_state ();
4178 al->shift (pos, samples);
4179 XMLNode &after = al->get_state ();
4180 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4188 Route::set_plugin_state_dir (boost::weak_ptr<Processor> p, const std::string& d)
4190 boost::shared_ptr<Processor> processor (p.lock ());
4191 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
4195 pi->set_state_dir (d);
4199 Route::save_as_template (const string& path, const string& name, const string& description)
4201 std::string state_dir = path.substr (0, path.find_last_of ('.')); // strip template_suffix
4202 PBD::Unwinder<std::string> uw (_session._template_state_dir, state_dir);
4204 XMLNode& node (state (false));
4205 node.set_property (X_("name"), name);
4207 node.remove_nodes (X_("description"));
4208 if (!description.empty()) {
4209 XMLNode* desc = new XMLNode(X_("description"));
4210 XMLNode* desc_cont = new XMLNode(X_("content"), description);
4211 desc->add_child_nocopy (*desc_cont);
4213 node.add_child_nocopy (*desc);
4218 IO::set_name_in_state (*node.children().front(), name);
4220 tree.set_root (&node);
4222 /* return zero on success, non-zero otherwise */
4223 return !tree.write (path.c_str());
4228 Route::set_name (const string& str)
4234 if (str == name()) {
4238 string name = Route::ensure_track_or_route_name (str, _session);
4239 SessionObject::set_name (name);
4241 bool ret = (_input->set_name(name) && _output->set_name(name));
4244 /* rename the main outs. Leave other IO processors
4245 * with whatever name they already have, because its
4246 * just fine as it is (it will not contain the route
4247 * name if its a port insert, port send or port return).
4251 if (_main_outs->set_name (name)) {
4252 /* XXX returning false here is stupid because
4253 we already changed the route name.
4263 /** Set the name of a route in an XML description.
4264 * @param node XML <Route> node to set the name in.
4265 * @param name New name.
4268 Route::set_name_in_state (XMLNode& node, string const & name, bool rename_playlist)
4270 node.set_property (X_("name"), name);
4272 XMLNodeList children = node.children();
4273 for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
4275 if ((*i)->name() == X_("IO")) {
4277 IO::set_name_in_state (**i, name);
4279 } else if ((*i)->name() == X_("Processor")) {
4282 if ((*i)->get_property (X_("role"), str) && str == X_("Main")) {
4283 (*i)->set_property (X_("name"), name);
4286 } else if ((*i)->name() == X_("Diskstream")) {
4288 if (rename_playlist) {
4289 (*i)->set_property (X_("playlist"), name + ".1");
4291 (*i)->set_property (X_("name"), name);
4297 boost::shared_ptr<Send>
4298 Route::internal_send_for (boost::shared_ptr<const Route> target) const
4300 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4302 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4303 boost::shared_ptr<InternalSend> send;
4305 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
4306 if (send->target_route() == target) {
4312 return boost::shared_ptr<Send>();
4316 Route::set_denormal_protection (bool yn)
4318 if (_denormal_protection != yn) {
4319 _denormal_protection = yn;
4320 denormal_protection_changed (); /* EMIT SIGNAL */
4325 Route::denormal_protection () const
4327 return _denormal_protection;
4331 Route::set_active (bool yn, void* src)
4333 if (_session.transport_rolling()) {
4337 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_route_active()) {
4338 _route_group->foreach_route (boost::bind (&Route::set_active, _1, yn, _route_group));
4342 if (_active != yn) {
4344 _input->set_active (yn);
4345 _output->set_active (yn);
4346 flush_processors ();
4347 active_changed (); // EMIT SIGNAL
4348 _session.set_dirty ();
4352 boost::shared_ptr<Pannable>
4353 Route::pannable() const
4358 boost::shared_ptr<Panner>
4359 Route::panner() const
4362 return _main_outs->panner_shell()->panner();
4365 boost::shared_ptr<PannerShell>
4366 Route::panner_shell() const
4368 return _main_outs->panner_shell();
4371 boost::shared_ptr<GainControl>
4372 Route::gain_control() const
4374 return _gain_control;
4377 boost::shared_ptr<GainControl>
4378 Route::trim_control() const
4380 return _trim_control;
4383 boost::shared_ptr<PhaseControl>
4384 Route::phase_control() const
4386 return _phase_control;
4389 boost::shared_ptr<AutomationControl>
4390 Route::get_control (const Evoral::Parameter& param)
4392 /* either we own the control or .... */
4394 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
4398 /* maybe one of our processors does or ... */
4400 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
4401 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4402 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
4410 /* nobody does so we'll make a new one */
4412 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
4419 boost::shared_ptr<Processor>
4420 Route::nth_plugin (uint32_t n) const
4422 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4423 ProcessorList::const_iterator i;
4425 for (i = _processors.begin(); i != _processors.end(); ++i) {
4426 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
4433 return boost::shared_ptr<Processor> ();
4436 boost::shared_ptr<Processor>
4437 Route::nth_send (uint32_t n) const
4439 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4440 ProcessorList::const_iterator i;
4442 for (i = _processors.begin(); i != _processors.end(); ++i) {
4443 if (boost::dynamic_pointer_cast<Send> (*i)) {
4445 if ((*i)->name().find (_("Monitor")) == 0) {
4446 /* send to monitor section is not considered
4447 to be an accessible send.
4458 return boost::shared_ptr<Processor> ();
4462 Route::has_io_processor_named (const string& name)
4464 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4465 ProcessorList::iterator i;
4467 for (i = _processors.begin(); i != _processors.end(); ++i) {
4468 if (boost::dynamic_pointer_cast<Send> (*i) ||
4469 boost::dynamic_pointer_cast<PortInsert> (*i)) {
4470 if ((*i)->name() == name) {
4480 Route::set_processor_positions ()
4482 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4484 bool had_amp = false;
4485 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4486 (*i)->set_pre_fader (!had_amp);
4493 /** Called when there is a proposed change to the input port count */
4495 Route::input_port_count_changing (ChanCount to)
4497 list<pair<ChanCount, ChanCount> > c = try_configure_processors (to, 0);
4499 /* The processors cannot be configured with the new input arrangement, so
4505 /* The change is ok */
4509 /** Called when there is a proposed change to the output port count */
4511 Route::output_port_count_changing (ChanCount to)
4513 if (_strict_io && !_in_configure_processors) {
4516 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
4517 if (processor_out_streams.get(*t) > to.get(*t)) {
4521 /* The change is ok */
4526 Route::unknown_processors () const
4530 if (_session.get_disable_all_loaded_plugins ()) {
4531 // Do not list "missing plugins" if they are explicitly disabled
4535 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4536 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4537 if (boost::dynamic_pointer_cast<UnknownProcessor const> (*i)) {
4538 p.push_back ((*i)->name ());
4547 Route::update_port_latencies (PortSet& from, PortSet& to, bool playback, samplecnt_t our_latency) const
4549 /* we assume that all our input ports feed all our output ports. its not
4550 universally true, but the alternative is way too corner-case to worry about.
4553 LatencyRange all_connections;
4556 all_connections.min = 0;
4557 all_connections.max = 0;
4559 all_connections.min = ~((pframes_t) 0);
4560 all_connections.max = 0;
4562 /* iterate over all "from" ports and determine the latency range for all of their
4563 connections to the "outside" (outside of this Route).
4566 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4570 p->get_connected_latency_range (range, playback);
4572 all_connections.min = min (all_connections.min, range.min);
4573 all_connections.max = max (all_connections.max, range.max);
4577 /* set the "from" port latencies to the max/min range of all their connections */
4579 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4580 p->set_private_latency_range (all_connections, playback);
4583 /* set the ports "in the direction of the flow" to the same value as above plus our own signal latency */
4585 all_connections.min += our_latency;
4586 all_connections.max += our_latency;
4588 for (PortSet::iterator p = to.begin(); p != to.end(); ++p) {
4589 p->set_private_latency_range (all_connections, playback);
4592 return all_connections.max;
4596 Route::set_private_port_latencies (bool playback) const
4598 samplecnt_t own_latency = 0;
4600 /* Processor list not protected by lock: MUST BE CALLED FROM PROCESS THREAD
4601 OR LATENCY CALLBACK.
4603 This is called (early) from the latency callback. It computes the REAL
4604 latency associated with each port and stores the result as the "private"
4605 latency of the port. A later call to Route::set_public_port_latencies()
4606 sets all ports to the same value to reflect the fact that we do latency
4607 compensation and so all signals are delayed by the same amount as they
4608 flow through ardour.
4611 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4613 if ((*i)->active ()) {
4614 own_latency += (*i)->signal_latency ();
4619 /* playback: propagate latency from "outside the route" to outputs to inputs */
4620 return update_port_latencies (_output->ports (), _input->ports (), true, own_latency);
4622 /* capture: propagate latency from "outside the route" to inputs to outputs */
4623 return update_port_latencies (_input->ports (), _output->ports (), false, own_latency);
4628 Route::set_public_port_latencies (samplecnt_t value, bool playback) const
4630 /* publish private latencies */
4631 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4632 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4633 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*i);
4637 if (iop->input ()) {
4638 iop->input ()->set_public_port_latencies (iop->input()->latency(), true);
4640 if (iop->output ()) {
4641 iop->output ()->set_public_port_latencies (iop->output()->latency(), false);
4645 /* this is called to set the JACK-visible port latencies, which take
4646 * latency compensation into account.
4648 _input->set_public_port_latencies (value, playback);
4649 _output->set_public_port_latencies (value, playback);
4652 /** Put the invisible processors in the right place in _processors.
4653 * Must be called with a writer lock on _processor_lock held.
4656 __attribute__((annotate("realtime")))
4659 Route::setup_invisible_processors ()
4662 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4663 assert (!lm.locked ());
4667 /* too early to be doing this stuff */
4671 /* we'll build this new list here and then use it
4673 * TODO put the ProcessorList is on the stack for RT-safety.
4676 ProcessorList new_processors;
4677 ProcessorList::iterator dr;
4678 ProcessorList::iterator dw;
4680 /* find visible processors */
4682 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4683 if ((*i)->display_to_user ()) {
4684 new_processors.push_back (*i);
4690 ProcessorList::iterator amp = find (new_processors.begin(), new_processors.end(), _amp);
4692 if (amp == new_processors.end ()) {
4693 error << string_compose (_("Amp/Fader on Route '%1' went AWOL. Re-added."), name()) << endmsg;
4694 new_processors.push_front (_amp);
4695 amp = find (new_processors.begin(), new_processors.end(), _amp);
4698 /* and the processor after the amp */
4700 ProcessorList::iterator after_amp = amp;
4703 /* Pre-fader METER */
4705 if (_meter && _meter_point == MeterPreFader) {
4706 /* add meter just before the fader */
4707 assert (!_meter->display_to_user ());
4708 new_processors.insert (amp, _meter);
4713 assert (_main_outs);
4714 assert (!_main_outs->display_to_user ());
4715 new_processors.push_back (_main_outs);
4717 /* iterator for the main outs */
4719 ProcessorList::iterator main = new_processors.end();
4722 /* OUTPUT METERING */
4724 if (_meter && (_meter_point == MeterOutput || _meter_point == MeterPostFader)) {
4725 assert (!_meter->display_to_user ());
4727 /* add the processor just before or just after the main outs */
4729 ProcessorList::iterator meter_point = main;
4731 if (_meter_point == MeterOutput) {
4734 new_processors.insert (meter_point, _meter);
4739 if (_monitor_send && !is_monitor ()) {
4740 assert (!_monitor_send->display_to_user ());
4741 switch (Config->get_listen_position ()) {
4742 case PreFaderListen:
4743 switch (Config->get_pfl_position ()) {
4744 case PFLFromBeforeProcessors:
4745 new_processors.push_front (_monitor_send);
4747 case PFLFromAfterProcessors:
4748 new_processors.insert (amp, _monitor_send);
4751 _monitor_send->set_can_pan (false);
4753 case AfterFaderListen:
4754 switch (Config->get_afl_position ()) {
4755 case AFLFromBeforeProcessors:
4756 new_processors.insert (after_amp, _monitor_send);
4758 case AFLFromAfterProcessors:
4759 new_processors.insert (new_processors.end(), _monitor_send);
4762 _monitor_send->set_can_pan (true);
4767 /* MONITOR CONTROL */
4769 if (_monitor_control && is_monitor ()) {
4770 assert (!_monitor_control->display_to_user ());
4771 new_processors.insert (amp, _monitor_control);
4776 ProcessorList::iterator trim = new_processors.end();
4778 if (_trim->active()) {
4779 assert (!_trim->display_to_user ());
4780 new_processors.push_front (_trim);
4781 trim = new_processors.begin();
4784 /* INTERNAL RETURN */
4786 /* doing this here means that any monitor control will come after
4787 the return and trim.
4791 assert (!_intreturn->display_to_user ());
4792 new_processors.push_front (_intreturn);
4795 /* DISK READER & WRITER (for Track objects) */
4797 if (_disk_reader || _disk_writer) {
4798 switch (_disk_io_point) {
4799 case DiskIOPreFader:
4800 if (trim != new_processors.end()) {
4801 /* insert BEFORE TRIM */
4803 new_processors.insert (trim, _disk_writer);
4806 new_processors.insert (trim, _disk_reader);
4810 new_processors.push_front (_disk_writer);
4813 new_processors.push_front (_disk_reader);
4817 case DiskIOPostFader:
4818 /* insert BEFORE main outs */
4820 new_processors.insert (main, _disk_writer);
4823 new_processors.insert (main, _disk_reader);
4827 /* reader and writer are visible under this condition, so they
4828 * are not invisible and thus not handled here.
4834 /* ensure dist-writer is before disk-reader */
4835 if (_disk_reader && _disk_writer) {
4836 ProcessorList::iterator reader_pos = find (new_processors.begin(), new_processors.end(), _disk_reader);
4837 ProcessorList::iterator writer_pos = find (new_processors.begin(), new_processors.end(), _disk_writer);
4838 assert (reader_pos != new_processors.end ());
4839 assert (writer_pos != new_processors.end ());
4840 if (std::distance (new_processors.begin(), reader_pos) < std::distance (new_processors.begin(), writer_pos)) {
4841 new_processors.erase (reader_pos);
4842 assert (writer_pos == find (new_processors.begin(), new_processors.end(), _disk_writer));
4843 new_processors.insert (++writer_pos, _disk_reader);
4847 /* EXPORT PROCESSOR */
4848 if (_capturing_processor) {
4849 assert (!_capturing_processor->display_to_user ());
4850 ProcessorList::iterator reader_pos = find (new_processors.begin(), new_processors.end(), _disk_reader);
4851 if (reader_pos != new_processors.end()) {
4852 /* insert after disk-reader */
4853 new_processors.insert (++reader_pos, _capturing_processor);
4855 ProcessorList::iterator return_pos = find (new_processors.begin(), new_processors.end(), _intreturn);
4856 /* insert after return */
4857 if (return_pos != new_processors.end()) {
4858 new_processors.insert (++return_pos, _capturing_processor);
4860 new_processors.push_front (_capturing_processor);
4865 /* Polarity Invert */
4867 ProcessorList::iterator reader_pos = find (new_processors.begin(), new_processors.end(), _disk_reader);
4868 if (reader_pos != new_processors.end()) {
4869 /* insert after disk-reader */
4870 new_processors.insert (++reader_pos, _polarity);
4872 ProcessorList::iterator return_pos = find (new_processors.begin(), new_processors.end(), _intreturn);
4873 /* insert after return */
4874 if (return_pos != new_processors.end()) {
4875 new_processors.insert (++return_pos, _polarity);
4877 new_processors.push_front (_polarity);
4883 if (_meter && _meter_point == MeterInput) {
4884 /* add meter just before the disk-writer (if any)
4885 * otherwise at the top, but after the latency delayline
4886 * (perhaps it should also be after intreturn on busses ??)
4888 assert (!_meter->display_to_user ());
4889 ProcessorList::iterator writer_pos = find (new_processors.begin(), new_processors.end(), _disk_writer);
4890 if (writer_pos != new_processors.end()) {
4891 /* insert before disk-writer */
4892 new_processors.insert (writer_pos, _meter);
4894 ProcessorList::iterator return_pos = find (new_processors.begin(), new_processors.end(), _intreturn);
4895 /* insert after return */
4896 if (return_pos != new_processors.end()) {
4897 new_processors.insert (++return_pos, _meter);
4899 new_processors.push_front (_meter);
4904 if (!is_master() && !is_monitor() && !is_auditioner()) {
4905 ProcessorList::iterator reader_pos = find (new_processors.begin(), new_processors.end(), _disk_reader);
4906 if (reader_pos != new_processors.end()) {
4907 /* insert before disk-reader */
4908 new_processors.insert (reader_pos, _delayline);
4910 new_processors.push_front (_delayline);
4914 _processors = new_processors;
4916 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4917 if (!(*i)->display_to_user () && !(*i)->enabled () && (*i) != _monitor_send) {
4918 (*i)->enable (true);
4922 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: setup_invisible_processors\n", _name));
4923 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4924 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1\n", (*i)->name ()));
4931 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
4932 Glib::Threads::RWLock::ReaderLock lp (_processor_lock);
4936 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4937 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*i);
4944 /** If the meter point is `Custom', make a note of where the meter is.
4945 * This is so that if the meter point is subsequently set to something else,
4946 * and then back to custom, we can put the meter back where it was last time
4947 * custom was enabled.
4949 * Must be called with the _processor_lock held.
4952 Route::maybe_note_meter_position ()
4954 if (_meter_point != MeterCustom) {
4958 _custom_meter_position_noted = true;
4959 /* custom meter points range from after trim to before panner/main_outs
4960 * this is a limitation by the current processor UI
4962 bool seen_trim = false;
4963 _processor_after_last_custom_meter.reset();
4964 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4965 if ((*i) == _trim) {
4968 if ((*i) == _main_outs) {
4969 _processor_after_last_custom_meter = *i;
4972 if (boost::dynamic_pointer_cast<PeakMeter> (*i)) {
4974 _processor_after_last_custom_meter = _trim;
4976 ProcessorList::iterator j = i;
4978 assert(j != _processors.end ()); // main_outs should be before
4979 _processor_after_last_custom_meter = *j;
4984 assert(_processor_after_last_custom_meter.lock());
4987 boost::shared_ptr<Processor>
4988 Route::processor_by_id (PBD::ID id) const
4990 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4991 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4992 if ((*i)->id() == id) {
4997 return boost::shared_ptr<Processor> ();
5000 /** @return what we should be metering; either the data coming from the input
5001 * IO or the data that is flowing through the route.
5004 Route::metering_state () const
5006 return MeteringRoute;
5010 Route::has_external_redirects () const
5012 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5014 /* ignore inactive processors and obviously ignore the main
5015 * outs since everything has them and we don't care.
5018 if ((*i)->active() && (*i) != _main_outs && (*i)->does_routing()) {
5026 boost::shared_ptr<Processor>
5027 Route::the_instrument () const
5029 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5030 return the_instrument_unlocked ();
5033 boost::shared_ptr<Processor>
5034 Route::the_instrument_unlocked () const
5036 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5037 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
5038 if (pi && pi->plugin ()->get_info ()->is_instrument ()) {
5042 return boost::shared_ptr<Processor>();
5048 return dynamic_cast<Track*>(this) != 0;
5052 Route::non_realtime_locate (samplepos_t pos)
5054 Automatable::non_realtime_locate (pos);
5057 _pannable->non_realtime_locate (pos);
5060 #if 0 // XXX mayhaps clear delayline here (and at stop?)
5062 _delayline->flush ();
5067 //Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
5068 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5070 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5071 (*i)->non_realtime_locate (pos);
5077 Route::fill_buffers_with_input (BufferSet& bufs, boost::shared_ptr<IO> io, pframes_t nframes)
5084 * We don't currently mix MIDI input together, so we don't need the
5085 * complex logic of the audio case.
5088 n_buffers = bufs.count().n_midi ();
5090 for (i = 0; i < n_buffers; ++i) {
5092 boost::shared_ptr<MidiPort> source_port = io->midi (i);
5093 MidiBuffer& buf (bufs.get_midi (i));
5096 buf.copy (source_port->get_midi_buffer(nframes));
5098 buf.silence (nframes);
5104 n_buffers = bufs.count().n_audio();
5106 size_t n_ports = io->n_ports().n_audio();
5107 float scaling = 1.0f;
5109 if (n_ports > n_buffers) {
5110 scaling = ((float) n_buffers) / n_ports;
5113 for (i = 0; i < n_ports; ++i) {
5115 /* if there are more ports than buffers, map them onto buffers
5116 * in a round-robin fashion
5119 boost::shared_ptr<AudioPort> source_port = io->audio (i);
5120 AudioBuffer& buf (bufs.get_audio (i%n_buffers));
5122 if (i < n_buffers) {
5124 /* first time through just copy a channel into
5128 buf.read_from (source_port->get_audio_buffer (nframes), nframes);
5130 if (scaling != 1.0f) {
5131 buf.apply_gain (scaling, nframes);
5136 /* on subsequent times around, merge data from
5137 * the port with what is already there
5140 if (scaling != 1.0f) {
5141 buf.accumulate_with_gain_from (source_port->get_audio_buffer (nframes), nframes, 0, scaling);
5143 buf.accumulate_from (source_port->get_audio_buffer (nframes), nframes);
5148 /* silence any remaining buffers */
5150 for (; i < n_buffers; ++i) {
5151 AudioBuffer& buf (bufs.get_audio (i));
5152 buf.silence (nframes);
5155 /* establish the initial setup of the buffer set, reflecting what was
5156 copied into it. unless, of course, we are the auditioner, in which
5157 case nothing was fed into it from the inputs at all.
5160 if (!is_auditioner()) {
5161 bufs.set_count (io->n_ports());
5165 boost::shared_ptr<AutomationControl>
5166 Route::pan_azimuth_control() const
5169 # undef MIXBUS_PORTS_H
5170 # include "../../gtk2_ardour/mixbus_ports.h"
5171 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5173 return boost::shared_ptr<AutomationControl>();
5175 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_pan)));
5177 if (!_pannable || !panner()) {
5178 return boost::shared_ptr<AutomationControl>();
5180 return _pannable->pan_azimuth_control;
5184 boost::shared_ptr<AutomationControl>
5185 Route::pan_elevation_control() const
5187 if (Profile->get_mixbus() || !_pannable || !panner()) {
5188 return boost::shared_ptr<AutomationControl>();
5191 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5193 if (c.find (PanElevationAutomation) != c.end()) {
5194 return _pannable->pan_elevation_control;
5196 return boost::shared_ptr<AutomationControl>();
5199 boost::shared_ptr<AutomationControl>
5200 Route::pan_width_control() const
5203 if (mixbus() && _ch_pre) {
5205 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl>(_ch_pre->control(Evoral::Parameter(PluginAutomation, 0, 5)));
5208 if (Profile->get_mixbus() || !_pannable || !panner()) {
5209 return boost::shared_ptr<AutomationControl>();
5212 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5214 if (c.find (PanWidthAutomation) != c.end()) {
5215 return _pannable->pan_width_control;
5217 return boost::shared_ptr<AutomationControl>();
5220 boost::shared_ptr<AutomationControl>
5221 Route::pan_frontback_control() const
5223 if (Profile->get_mixbus() || !_pannable || !panner()) {
5224 return boost::shared_ptr<AutomationControl>();
5227 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5229 if (c.find (PanFrontBackAutomation) != c.end()) {
5230 return _pannable->pan_frontback_control;
5232 return boost::shared_ptr<AutomationControl>();
5235 boost::shared_ptr<AutomationControl>
5236 Route::pan_lfe_control() const
5238 if (Profile->get_mixbus() || !_pannable || !panner()) {
5239 return boost::shared_ptr<AutomationControl>();
5242 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5244 if (c.find (PanLFEAutomation) != c.end()) {
5245 return _pannable->pan_lfe_control;
5247 return boost::shared_ptr<AutomationControl>();
5252 Route::eq_band_cnt () const
5254 if (Profile->get_mixbus()) {
5256 if (is_master() || mixbus()) {
5265 /* Ardour has no well-known EQ object */
5270 boost::shared_ptr<AutomationControl>
5271 Route::eq_gain_controllable (uint32_t band) const
5274 boost::shared_ptr<PluginInsert> eq = ch_eq();
5277 return boost::shared_ptr<AutomationControl>();
5280 uint32_t port_number;
5281 if (is_master() || mixbus()) {
5283 case 0: port_number = 4; break;
5284 case 1: port_number = 3; break;
5285 case 2: port_number = 2; break;
5287 return boost::shared_ptr<AutomationControl>();
5292 case 0: port_number = 14; break;
5293 case 1: port_number = 12; break;
5294 case 2: port_number = 10; break;
5295 case 3: port_number = 8; break;
5297 return boost::shared_ptr<AutomationControl>();
5301 case 0: port_number = 8; break;
5302 case 1: port_number = 6; break;
5303 case 2: port_number = 4; break;
5305 return boost::shared_ptr<AutomationControl>();
5310 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5312 return boost::shared_ptr<AutomationControl>();
5315 boost::shared_ptr<AutomationControl>
5316 Route::eq_freq_controllable (uint32_t band) const
5319 if (mixbus() || is_master()) {
5320 /* no frequency controls for mixbusses or master */
5321 return boost::shared_ptr<AutomationControl>();
5324 boost::shared_ptr<PluginInsert> eq = ch_eq();
5327 return boost::shared_ptr<AutomationControl>();
5330 uint32_t port_number;
5333 case 0: port_number = 13; break; // lo
5334 case 1: port_number = 11; break; // lo mid
5335 case 2: port_number = 9; break; // hi mid
5336 case 3: port_number = 7; break; // hi
5338 return boost::shared_ptr<AutomationControl>();
5342 case 0: port_number = 7; break;
5343 case 1: port_number = 5; break;
5344 case 2: port_number = 3; break;
5346 return boost::shared_ptr<AutomationControl>();
5350 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5352 return boost::shared_ptr<AutomationControl>();
5356 boost::shared_ptr<AutomationControl>
5357 Route::eq_q_controllable (uint32_t band) const
5359 return boost::shared_ptr<AutomationControl>();
5362 boost::shared_ptr<AutomationControl>
5363 Route::eq_shape_controllable (uint32_t band) const
5366 boost::shared_ptr<PluginInsert> eq = ch_eq();
5367 if (is_master() || mixbus() || !eq) {
5368 return boost::shared_ptr<AutomationControl>();
5372 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4))); // lo bell
5375 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3))); // hi bell
5381 return boost::shared_ptr<AutomationControl>();
5384 boost::shared_ptr<AutomationControl>
5385 Route::eq_enable_controllable () const
5388 boost::shared_ptr<PluginInsert> eq = ch_eq();
5391 return boost::shared_ptr<AutomationControl>();
5394 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5396 return boost::shared_ptr<AutomationControl>();
5400 boost::shared_ptr<AutomationControl>
5401 Route::filter_freq_controllable (bool hpf) const
5404 boost::shared_ptr<PluginInsert> eq = ch_eq();
5406 if (is_master() || mixbus() || !eq) {
5407 return boost::shared_ptr<AutomationControl>();
5411 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5))); // HPF freq
5413 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5417 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 6))); // LPF freq
5419 return boost::shared_ptr<AutomationControl>();
5424 return boost::shared_ptr<AutomationControl>();
5428 boost::shared_ptr<AutomationControl>
5429 Route::filter_slope_controllable (bool) const
5431 return boost::shared_ptr<AutomationControl>();
5434 boost::shared_ptr<AutomationControl>
5435 Route::filter_enable_controllable (bool) const
5438 boost::shared_ptr<PluginInsert> eq = ch_eq();
5440 if (is_master() || mixbus() || !eq) {
5441 return boost::shared_ptr<AutomationControl>();
5444 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5446 return boost::shared_ptr<AutomationControl>();
5450 boost::shared_ptr<AutomationControl>
5451 Route::tape_drive_controllable () const
5455 if ( _ch_pre && (is_master() || mixbus()) ) {
5456 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (_ch_pre->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4)));
5460 return boost::shared_ptr<AutomationControl>();
5464 Route::eq_band_name (uint32_t band) const
5467 if (is_master() || mixbus()) {
5469 if (Profile->get_mixbus()) {
5471 case 0: return _("lo");
5472 case 1: return _("mid");
5473 case 2: return _("hi");
5474 default: return string();
5482 case 0: return _("lo");
5483 case 1: return _("lo mid");
5484 case 2: return _("hi mid");
5485 case 3: return _("hi");
5486 default: return string();
5492 boost::shared_ptr<AutomationControl>
5493 Route::comp_enable_controllable () const
5496 boost::shared_ptr<PluginInsert> comp = ch_comp();
5499 return boost::shared_ptr<AutomationControl>();
5502 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5504 return boost::shared_ptr<AutomationControl>();
5507 boost::shared_ptr<AutomationControl>
5508 Route::comp_threshold_controllable () const
5511 boost::shared_ptr<PluginInsert> comp = ch_comp();
5514 return boost::shared_ptr<AutomationControl>();
5517 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5520 return boost::shared_ptr<AutomationControl>();
5523 boost::shared_ptr<AutomationControl>
5524 Route::comp_speed_controllable () const
5527 boost::shared_ptr<PluginInsert> comp = ch_comp();
5530 return boost::shared_ptr<AutomationControl>();
5533 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3)));
5535 return boost::shared_ptr<AutomationControl>();
5538 boost::shared_ptr<AutomationControl>
5539 Route::comp_mode_controllable () const
5542 boost::shared_ptr<PluginInsert> comp = ch_comp();
5545 return boost::shared_ptr<AutomationControl>();
5548 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4)));
5550 return boost::shared_ptr<AutomationControl>();
5553 boost::shared_ptr<AutomationControl>
5554 Route::comp_makeup_controllable () const
5557 boost::shared_ptr<PluginInsert> comp = ch_comp();
5560 return boost::shared_ptr<AutomationControl>();
5563 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5)));
5565 return boost::shared_ptr<AutomationControl>();
5568 boost::shared_ptr<ReadOnlyControl>
5569 Route::comp_redux_controllable () const
5572 boost::shared_ptr<PluginInsert> comp = ch_comp();
5575 return boost::shared_ptr<ReadOnlyControl>();
5578 return comp->control_output (2);
5580 return comp->control_output (6);
5584 return boost::shared_ptr<ReadOnlyControl>();
5589 Route::comp_mode_name (uint32_t mode) const
5594 return _("Leveler");
5596 return _("Compressor");
5598 return _("Limiter");
5600 return mixbus() ? _("Sidechain") : _("Limiter");
5610 Route::comp_speed_name (uint32_t mode) const
5628 boost::shared_ptr<AutomationControl>
5629 Route::send_pan_azi_controllable (uint32_t n) const
5632 # undef MIXBUS_PORTS_H
5633 # include "../../gtk2_ardour/mixbus_ports.h"
5634 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5635 if (plug && !mixbus()) {
5636 uint32_t port_id = 0;
5639 case 0: port_id = port_channel_post_aux0_pan; break; //32c mb "pan" controls use zero-based names, unlike levels. ugh
5640 case 1: port_id = port_channel_post_aux1_pan; break;
5641 case 2: port_id = port_channel_post_aux2_pan; break;
5642 case 3: port_id = port_channel_post_aux3_pan; break;
5643 case 4: port_id = port_channel_post_aux4_pan; break;
5644 case 5: port_id = port_channel_post_aux5_pan; break;
5645 case 6: port_id = port_channel_post_aux6_pan; break;
5646 case 7: port_id = port_channel_post_aux7_pan; break;
5647 case 8: port_id = port_channel_post_aux8_pan; break;
5648 case 9: port_id = port_channel_post_aux9_pan; break;
5649 case 10: port_id = port_channel_post_aux10_pan; break;
5650 case 11: port_id = port_channel_post_aux11_pan; break;
5657 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5662 return boost::shared_ptr<AutomationControl>();
5665 boost::shared_ptr<AutomationControl>
5666 Route::send_level_controllable (uint32_t n) const
5669 # undef MIXBUS_PORTS_H
5670 # include "../../gtk2_ardour/mixbus_ports.h"
5671 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5672 if (plug && !mixbus()) {
5673 uint32_t port_id = 0;
5675 case 0: port_id = port_channel_post_aux1_level; break;
5676 case 1: port_id = port_channel_post_aux2_level; break;
5677 case 2: port_id = port_channel_post_aux3_level; break;
5678 case 3: port_id = port_channel_post_aux4_level; break;
5679 case 4: port_id = port_channel_post_aux5_level; break;
5680 case 5: port_id = port_channel_post_aux6_level; break;
5681 case 6: port_id = port_channel_post_aux7_level; break;
5682 case 7: port_id = port_channel_post_aux8_level; break;
5684 case 8: port_id = port_channel_post_aux9_level; break;
5685 case 9: port_id = port_channel_post_aux10_level; break;
5686 case 10: port_id = port_channel_post_aux11_level; break;
5687 case 11: port_id = port_channel_post_aux12_level; break;
5694 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5705 boost::shared_ptr<Send> s = boost::dynamic_pointer_cast<Send>(nth_send (n));
5707 return boost::shared_ptr<AutomationControl>();
5709 return s->gain_control ();
5712 boost::shared_ptr<AutomationControl>
5713 Route::send_enable_controllable (uint32_t n) const
5716 # undef MIXBUS_PORTS_H
5717 # include "../../gtk2_ardour/mixbus_ports.h"
5718 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5719 if (plug && !mixbus()) {
5720 uint32_t port_id = 0;
5722 case 0: port_id = port_channel_post_aux1_asgn; break;
5723 case 1: port_id = port_channel_post_aux2_asgn; break;
5724 case 2: port_id = port_channel_post_aux3_asgn; break;
5725 case 3: port_id = port_channel_post_aux4_asgn; break;
5726 case 4: port_id = port_channel_post_aux5_asgn; break;
5727 case 5: port_id = port_channel_post_aux6_asgn; break;
5728 case 6: port_id = port_channel_post_aux7_asgn; break;
5729 case 7: port_id = port_channel_post_aux8_asgn; break;
5731 case 8: port_id = port_channel_post_aux9_asgn; break;
5732 case 9: port_id = port_channel_post_aux10_asgn; break;
5733 case 10: port_id = port_channel_post_aux11_asgn; break;
5734 case 11: port_id = port_channel_post_aux12_asgn; break;
5741 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5752 /* although Ardour sends have enable/disable as part of the Processor
5753 * API, it is not exposed as a controllable.
5755 * XXX: we should fix this (make it click-free, automatable enable-control)
5757 return boost::shared_ptr<AutomationControl>();
5761 Route::send_name (uint32_t n) const
5764 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5765 if (plug && !mixbus()) {
5768 return _session.get_mixbus (n)->name();
5773 return _session.get_mixbus (n)->name();
5779 boost::shared_ptr<Processor> p = nth_send (n);
5787 boost::shared_ptr<AutomationControl>
5788 Route::master_send_enable_controllable () const
5791 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5793 return boost::shared_ptr<AutomationControl>();
5795 # undef MIXBUS_PORTS_H
5796 # include "../../gtk2_ardour/mixbus_ports.h"
5797 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_mstr_assign)));
5799 return boost::shared_ptr<AutomationControl>();
5804 Route::slaved () const
5806 if (!_gain_control) {
5809 /* just test one particular control, not all of them */
5810 return _gain_control->slaved ();
5814 Route::slaved_to (boost::shared_ptr<VCA> vca) const
5816 if (!vca || !_gain_control) {
5820 /* just test one particular control, not all of them */
5822 return _gain_control->slaved_to (vca->gain_control());
5826 Route::muted_by_others_soloing () const
5828 if (!can_be_muted_by_others ()) {
5832 return _session.soloing() && !_solo_control->soloed() && !_solo_isolate_control->solo_isolated();
5836 Route::clear_all_solo_state ()
5838 _solo_control->clear_all_solo_state ();
5841 boost::shared_ptr<AutomationControl>
5842 Route::automation_control_recurse (PBD::ID const & id) const
5844 boost::shared_ptr<AutomationControl> ac = Automatable::automation_control (id);
5850 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5852 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5853 if ((ac = (*i)->automation_control (id))) {
5858 return boost::shared_ptr<AutomationControl> ();
5862 Route::slavables () const
5864 SlavableControlList rv;
5865 rv.push_back (_gain_control);
5866 rv.push_back (_mute_control);
5867 rv.push_back (_solo_control);
5872 Route::set_disk_io_point (DiskIOPoint diop)
5874 bool display = false;
5876 cerr << "set disk io to " << enum_2_string (diop) << endl;
5887 _disk_writer->set_display_to_user (display);
5891 _disk_reader->set_display_to_user (display);
5894 const bool changed = (diop != _disk_io_point);
5896 _disk_io_point = diop;
5899 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
5900 configure_processors (0);
5903 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
5907 Route::set_loop (Location* l)
5910 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5911 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5916 #ifdef USE_TRACKS_CODE_FEATURES
5918 /* This is the Tracks version of Track::monitoring_state().
5920 * Ardour developers: try to flag or fix issues if parts of the libardour API
5921 * change in ways that invalidate this
5925 Route::monitoring_state () const
5927 /* Explicit requests */
5929 if (_monitoring != MonitorInput) {
5930 return MonitoringInput;
5933 if (_monitoring & MonitorDisk) {
5934 return MonitoringDisk;
5937 /* This is an implementation of the truth table in doc/monitor_modes.pdf;
5938 I don't think it's ever going to be too pretty too look at.
5941 // GZ: NOT USED IN TRACKS
5942 //bool const auto_input = _session.config.get_auto_input ();
5943 //bool const software_monitor = Config->get_monitoring_model() == SoftwareMonitoring;
5944 //bool const tape_machine_mode = Config->get_tape_machine_mode ();
5946 bool const roll = _session.transport_rolling ();
5947 bool const track_rec = _diskstream->record_enabled ();
5948 bool session_rec = _session.actively_recording ();
5952 if (!session_rec && roll) {
5953 return MonitoringDisk;
5955 return MonitoringInput;
5961 return MonitoringDisk;
5965 return MonitoringSilence;
5970 /* This is the Ardour/Mixbus version of Track::monitoring_state().
5972 * Tracks developers: do NOT modify this method under any circumstances.
5976 Route::monitoring_state () const
5978 if (!_disk_reader) {
5979 return MonitoringInput;
5982 /* Explicit requests */
5983 MonitorChoice m (_monitoring_control->monitoring_choice());
5985 if (m != MonitorAuto) {
5987 MonitorState ms ((MonitorState) 0);
5989 if (m & MonitorInput) {
5990 ms = MonitoringInput;
5993 if (m & MonitorDisk) {
5994 ms = MonitorState (ms | MonitoringDisk);
6000 switch (_session.config.get_session_monitoring ()) {
6002 return MonitoringDisk;
6005 return MonitoringInput;
6011 return get_auto_monitoring_state();