2 Copyright (C) 2000 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "libardour-config.h"
29 #include <boost/algorithm/string.hpp>
31 #include "pbd/xml++.h"
32 #include "pbd/enumwriter.h"
33 #include "pbd/locale_guard.h"
34 #include "pbd/memento_command.h"
35 #include "pbd/stacktrace.h"
36 #include "pbd/types_convert.h"
37 #include "pbd/unwind.h"
39 #include "ardour/amp.h"
40 #include "ardour/audio_buffer.h"
41 #include "ardour/audio_track.h"
42 #include "ardour/audio_port.h"
43 #include "ardour/audioengine.h"
44 #include "ardour/boost_debug.h"
45 #include "ardour/buffer.h"
46 #include "ardour/buffer_set.h"
47 #include "ardour/capturing_processor.h"
48 #include "ardour/debug.h"
49 #include "ardour/delivery.h"
50 #include "ardour/disk_reader.h"
51 #include "ardour/disk_writer.h"
52 #include "ardour/event_type_map.h"
53 #include "ardour/gain_control.h"
54 #include "ardour/internal_return.h"
55 #include "ardour/internal_send.h"
56 #include "ardour/meter.h"
57 #include "ardour/delayline.h"
58 #include "ardour/midi_buffer.h"
59 #include "ardour/midi_port.h"
60 #include "ardour/monitor_control.h"
61 #include "ardour/monitor_processor.h"
62 #include "ardour/pannable.h"
63 #include "ardour/panner.h"
64 #include "ardour/panner_shell.h"
65 #include "ardour/parameter_descriptor.h"
66 #include "ardour/phase_control.h"
67 #include "ardour/plugin_insert.h"
68 #include "ardour/polarity_processor.h"
69 #include "ardour/port.h"
70 #include "ardour/port_insert.h"
71 #include "ardour/processor.h"
72 #include "ardour/profile.h"
73 #include "ardour/route.h"
74 #include "ardour/route_group.h"
75 #include "ardour/send.h"
76 #include "ardour/session.h"
77 #include "ardour/solo_control.h"
78 #include "ardour/solo_isolate_control.h"
79 #include "ardour/types_convert.h"
80 #include "ardour/unknown_processor.h"
81 #include "ardour/utils.h"
82 #include "ardour/vca.h"
87 using namespace ARDOUR;
90 PBD::Signal3<int,boost::shared_ptr<Route>, boost::shared_ptr<PluginInsert>, Route::PluginSetupOptions > Route::PluginSetup;
92 /** Base class for all routable/mixable objects (tracks and busses) */
93 Route::Route (Session& sess, string name, PresentationInfo::Flag flag, DataType default_type)
94 : Stripable (sess, name, PresentationInfo (flag))
95 , GraphNode (sess._process_graph)
96 , Muteable (sess, name)
99 , _disk_io_point (DiskIOPreFader)
100 , _pending_process_reorder (0)
101 , _pending_signals (0)
102 , _pending_declick (true)
103 , _meter_point (MeterPostFader)
104 , _pending_meter_point (MeterPostFader)
105 , _meter_type (MeterPeak)
106 , _denormal_protection (false)
108 , _declickable (false)
109 , _have_internal_generator (false)
110 , _default_type (default_type)
111 , _loop_location (NULL)
114 , _in_configure_processors (false)
115 , _initial_io_setup (false)
116 , _in_sidechain_setup (false)
117 , _custom_meter_position_noted (false)
119 , _patch_selector_dialog (0)
121 processor_max_streams.reset();
124 boost::weak_ptr<Route>
125 Route::weakroute () {
126 return boost::weak_ptr<Route> (boost::dynamic_pointer_cast<Route> (shared_from_this ()));
132 /* set default meter type */
134 _meter_type = Config->get_meter_type_master ();
136 else if (dynamic_cast<Track*>(this)) {
137 _meter_type = Config->get_meter_type_track ();
139 _meter_type = Config->get_meter_type_bus ();
142 /* add standard controls */
144 _gain_control.reset (new GainControl (_session, GainAutomation));
145 _trim_control.reset (new GainControl (_session, TrimAutomation));
146 /* While the route has-a gain-control for consistency with Stripable and VCA
147 * ownership is handed over to the Amp Processor which manages the
148 * state of the Control and AutomationList as part of its
149 * Automatable API. -- Don't call add_control () here.
152 _solo_control.reset (new SoloControl (_session, X_("solo"), *this, *this));
153 add_control (_solo_control);
154 _solo_control->Changed.connect_same_thread (*this, boost::bind (&Route::solo_control_changed, this, _1, _2));
156 _mute_control.reset (new MuteControl (_session, X_("mute"), *this));
157 add_control (_mute_control);
159 _phase_control.reset (new PhaseControl (_session, X_("phase")));
160 add_control (_phase_control);
162 _solo_isolate_control.reset (new SoloIsolateControl (_session, X_("solo-iso"), *this, *this));
163 add_control (_solo_isolate_control);
165 _solo_safe_control.reset (new SoloSafeControl (_session, X_("solo-safe")));
166 add_control (_solo_safe_control);
170 if (!(_presentation_info.flags() & PresentationInfo::MonitorOut)) {
171 _pannable.reset (new Pannable (_session));
174 /* input and output objects */
176 _input.reset (new IO (_session, _name, IO::Input, _default_type));
177 _output.reset (new IO (_session, _name, IO::Output, _default_type));
179 _input->changed.connect_same_thread (*this, boost::bind (&Route::input_change_handler, this, _1, _2));
180 _input->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::input_port_count_changing, this, _1));
182 _output->changed.connect_same_thread (*this, boost::bind (&Route::output_change_handler, this, _1, _2));
183 _output->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::output_port_count_changing, this, _1));
185 /* add the amp/fader processor.
186 * it should be the first processor to be added on every route.
189 _amp.reset (new Amp (_session, X_("Fader"), _gain_control, true));
190 add_processor (_amp, PostFader);
192 _polarity.reset (new PolarityProcessor (_session, _phase_control));
193 _polarity->activate();
194 _polarity->set_owner (this);
197 _amp->set_display_name (_("Monitor"));
200 if (!is_master() && !is_monitor() && !is_auditioner()) {
201 _delayline.reset (new DelayLine (_session, name ()));
206 _trim.reset (new Amp (_session, X_("Trim"), _trim_control, false));
207 _trim->set_display_to_user (false);
209 if (dynamic_cast<AudioTrack*>(this)) {
210 /* we can't do this in the AudioTrack's constructor
211 * because _trim does not exit then
215 else if (!dynamic_cast<Track*>(this) && ! ( is_monitor() || is_auditioner() )) {
220 /* create standard processors: meter, main outs, monitor out;
221 they will be added to _processors by setup_invisible_processors ()
224 _meter.reset (new PeakMeter (_session, _name));
225 _meter->set_owner (this);
226 _meter->set_display_to_user (false);
229 _main_outs.reset (new Delivery (_session, _output, _pannable, _mute_master, _name, Delivery::Main));
230 _main_outs->activate ();
233 /* where we listen to tracks */
234 _intreturn.reset (new InternalReturn (_session));
235 _intreturn->activate ();
237 /* the thing that provides proper control over a control/monitor/listen bus
238 (such as per-channel cut, dim, solo, invert, etc).
240 _monitor_control.reset (new MonitorProcessor (_session));
241 _monitor_control->activate ();
244 /* now that we have _meter, its safe to connect to this */
247 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
248 configure_processors (0);
256 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
258 /* do this early so that we don't get incoming signals as we are going through destruction
263 /* don't use clear_processors here, as it depends on the session which may
264 be half-destroyed by now
267 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
268 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
269 (*i)->drop_references ();
272 _processors.clear ();
276 Route::ensure_track_or_route_name(string name, Session &session)
278 string newname = name;
280 while (!session.io_name_is_legal (newname)) {
281 newname = bump_name_once (newname, ' ');
288 Route::set_trim (gain_t val, Controllable::GroupControlDisposition /* group override */)
290 // TODO route group, see set_gain()
291 // _trim_control->route_set_value (val);
295 Route::maybe_declick (BufferSet&, samplecnt_t, int)
297 /* this is the "bus" implementation and they never declick.
302 /** Process this route for one (sub) cycle (process thread)
304 * @param bufs Scratch buffers to use for the signal path
305 * @param start_sample Initial transport sample
306 * @param end_sample Final transport sample
307 * @param nframes Number of samples to output (to ports)
309 * Note that (end_sample - start_sample) may not be equal to nframes when the
310 * transport speed isn't 1.0 (eg varispeed).
313 Route::process_output_buffers (BufferSet& bufs,
314 samplepos_t start_sample, samplepos_t end_sample, pframes_t nframes,
315 int declick, bool gain_automation_ok, bool run_disk_reader)
317 /* Caller must hold process lock */
318 assert (!AudioEngine::instance()->process_lock().trylock());
320 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
322 // can this actually happen?
323 // Places that need a WriterLock on (_processor_lock) must also take the process-lock.
324 bufs.silence (nframes, 0);
325 assert (0); // ...one way to find out.
329 /* We should offset the route-owned ctrls by the given latency, however
330 * this only affects Mute. Other route-owned controls (solo, polarity..)
331 * are not automatable.
333 * Mute has its own issues since there's not a single mute-point,
336 automation_run (start_sample, nframes);
338 /* figure out if we're going to use gain automation */
339 if (gain_automation_ok) {
340 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
341 _amp->setup_gain_automation (
342 start_sample + _amp->output_latency (),
343 end_sample + _amp->output_latency (),
346 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
347 _trim->setup_gain_automation (
348 start_sample + _trim->output_latency (),
349 end_sample + _trim->output_latency (),
353 /* We align the playhead to output. The user hears what the clock says:
354 * When the playhead/clock says 1:00:00:00 the user will hear the audio sample
355 * at 1:00:00:00. sample_start will be [sample at] 1:00:00:00
357 * e.g. clock says Time T = 0, sample_start = 0
358 * Disk-read(play) -> latent-plugin (+10) -> fader-automation -> output (+5)
359 * -> total playback latency "disk -> out" is 15.
360 * -> at Time T= -15, the disk-reader reads sample T=0.
361 * By the Time T=0 is reached (dt=15 later) that sample is audible.
364 const double speed = (is_auditioner() ? 1.0 : _session.transport_speed ());
366 const sampleoffset_t latency_offset = _signal_latency + _output->latency ();
368 /* when rolling backwards this can become negative */
369 start_sample -= latency_offset;
370 end_sample -= latency_offset;
372 start_sample += latency_offset;
373 end_sample += latency_offset;
376 /* Note: during intial pre-roll 'start_sample' as passed as argument can be negative.
377 * Functions calling process_output_buffers() will set "run_disk_reader"
378 * to false if the pre-roll count-down is larger than playback_latency ().
380 * playback_latency() is guarnteed to be <= _signal_latency + _output->latency ()
382 assert (!_disk_reader || !run_disk_reader || start_sample >= 0 || speed < 0);
384 /* however the disk-writer may need to pick up output from other tracks
385 * during pre-roll (in particular if this route has latent effects after the disk).
387 * e.g. track 1 play -> latency A --port--> track2 capture -> latency B ---> out
388 * total pre-roll = A + B.
390 * Note the disk-writer has built-in overlap detection (it's safe to run it early)
393 bool run_disk_writer = false;
394 if (_disk_writer && speed > 0) {
395 samplecnt_t latency_preroll = _session.remaining_latency_preroll ();
396 run_disk_writer = latency_preroll < nframes + (_signal_latency + _output->latency ());
397 if (end_sample - _disk_writer->input_latency () < _session.transport_sample ()) {
398 run_disk_writer = true;
402 /* Tell main outs what to do about monitoring. We do this so that
403 * on a transition between monitoring states we get a de-clicking gain
404 * change in the _main_outs delivery, if config.get_use_monitor_fades()
407 * We override this in the case where we have an internal generator.
409 * FIXME: when punching in/out this also depends on latency compensated time
410 * for this route. monitoring_state() does not currently handle that correctly,.
412 * Also during remaining_latency_preroll, transport_rolling () is false, but
413 * we may need to monitor disk instead.
415 MonitorState ms = monitoring_state ();
416 bool silence = _have_internal_generator ? false : (ms == MonitoringSilence);
418 _main_outs->no_outs_cuz_we_no_monitor (silence);
420 /* -------------------------------------------------------------------------------------------
421 GLOBAL DECLICK (for transport changes etc.)
422 ----------------------------------------------------------------------------------------- */
424 // XXX not latency compensated. calls Amp::declick, but there may be
425 // plugins between disk and Fader.
426 maybe_declick (bufs, nframes, declick);
427 _pending_declick = 0;
429 /* -------------------------------------------------------------------------------------------
431 ----------------------------------------------------------------------------------------- */
432 /* XXX We'll need to protect silent inputs as well as silent disk
433 * (when not monitoring input or monitoring disk and there's no region
434 * for a longer time).
436 * ...or simply drop that feature.
438 if (_denormal_protection || Config->get_denormal_protection()) {
440 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
441 Sample* const sp = i->data();
442 for (pframes_t nx = 0; nx < nframes; ++nx) {
449 /* -------------------------------------------------------------------------------------------
451 ----------------------------------------------------------------------------------------- */
453 samplecnt_t latency = 0;
455 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
457 /* TODO check for split cycles here.
459 * start_frame, end_frame is adjusted by latency and may
464 /* if it has any inputs, make sure they match */
465 if (boost::dynamic_pointer_cast<UnknownProcessor> (*i) == 0 && (*i)->input_streams() != ChanCount::ZERO) {
466 if (bufs.count() != (*i)->input_streams()) {
468 DEBUG::Processors, string_compose (
469 "input port mismatch %1 bufs = %2 input for %3 = %4\n",
470 _name, bufs.count(), (*i)->name(), (*i)->input_streams()
477 bool re_inject_oob_data = false;
478 if ((*i) == _disk_reader) {
479 /* Well now, we've made it past the disk-writer and to the disk-reader.
480 * Time to decide what to do about monitoring.
482 * Even when not doing MonitoringDisk, we need to run the processors,
483 * so that it advances its internal buffers (IFF run_disk_reader is true).
486 if (ms == MonitoringDisk || ms == MonitoringSilence) {
487 /* this will clear out-of-band data, too (e.g. MIDI-PC, Panic etc.
488 * OOB data is written at the end of the cycle (nframes - 1),
489 * and jack does not re-order events, so we push them back later */
490 re_inject_oob_data = true;
491 bufs.silence (nframes, 0);
495 double pspeed = speed;
496 if ((!run_disk_reader && (*i) == _disk_reader) || (!run_disk_writer && (*i) == _disk_writer)) {
497 /* run with speed 0, no-roll */
502 (*i)->run (bufs, start_sample + latency, end_sample + latency, pspeed, nframes, *i != _processors.back());
504 (*i)->run (bufs, start_sample - latency, end_sample - latency, pspeed, nframes, *i != _processors.back());
507 bufs.set_count ((*i)->output_streams());
509 /* Note: plugin latency may change. While the plugin does inform the session via
510 * processor_latency_changed(). But the session may not yet have gotten around to
511 * update the actual worste-case and update this track's _signal_latency.
513 * So there can be cases where adding up all latencies may not equal _signal_latency.
515 if ((*i)->active ()) {
516 latency += (*i)->signal_latency ();
519 if (re_inject_oob_data) {
520 write_out_of_band_data (bufs, nframes);
524 if ((*i) == _delayline) {
525 latency += _delayline->delay ();
532 Route::bounce_process (BufferSet& buffers, samplepos_t start, samplecnt_t nframes,
533 boost::shared_ptr<Processor> endpoint,
534 bool include_endpoint, bool for_export, bool for_freeze)
536 /* If no processing is required, there's no need to go any further. */
537 if (!endpoint && !include_endpoint) {
541 samplecnt_t latency = bounce_get_latency(_amp, false, for_export, for_freeze);
542 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
543 _amp->setup_gain_automation (start - latency, start - latency + nframes, nframes);
545 /* trim is always at the top, for bounce no latency compensation is needed */
546 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
547 _trim->setup_gain_automation (start, start + nframes, nframes);
550 const double speed = _session.transport_speed ();
551 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
553 if (!include_endpoint && (*i) == endpoint) {
557 /* if we're *not* exporting, stop processing if we come across a routing processor. */
558 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
561 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
565 /* special case the panner (export outputs)
566 * Ideally we'd only run the panner, not the delivery itself...
567 * but panners need separate input/output buffers and some context
568 * (panshell, panner type, etc). AFAICT there is no ill side effect
569 * of re-using the main delivery when freewheeling/exporting a region.
571 if ((*i) == _main_outs) {
572 assert ((*i)->does_routing());
573 (*i)->run (buffers, start - latency, start - latency + nframes, speed, nframes, true);
574 buffers.set_count ((*i)->output_streams());
577 /* don't run any processors that do routing.
578 * Also don't bother with metering.
580 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
581 (*i)->run (buffers, start - latency, start - latency + nframes, 1.0, nframes, true);
582 buffers.set_count ((*i)->output_streams());
583 latency += (*i)->signal_latency ();
586 if ((*i) == endpoint) {
593 Route::bounce_get_latency (boost::shared_ptr<Processor> endpoint,
594 bool include_endpoint, bool for_export, bool for_freeze) const
596 samplecnt_t latency = 0;
597 if (!endpoint && !include_endpoint) {
601 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
602 if (!include_endpoint && (*i) == endpoint) {
605 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
608 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
611 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
612 latency += (*i)->signal_latency ();
614 if ((*i) == endpoint) {
622 Route::bounce_get_output_streams (ChanCount &cc, boost::shared_ptr<Processor> endpoint,
623 bool include_endpoint, bool for_export, bool for_freeze) const
625 if (!endpoint && !include_endpoint) {
629 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
630 if (!include_endpoint && (*i) == endpoint) {
633 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
636 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
639 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
640 cc = (*i)->output_streams();
642 if ((*i) == endpoint) {
650 Route::n_process_buffers ()
652 return max (_input->n_ports(), processor_max_streams);
656 Route::monitor_run (samplepos_t start_sample, samplepos_t end_sample, pframes_t nframes, int declick)
658 assert (is_monitor());
659 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
660 run_route (start_sample, end_sample, nframes, declick, true, false);
664 Route::run_route (samplepos_t start_sample, samplepos_t end_sample, pframes_t nframes, int declick, bool gain_automation_ok, bool run_disk_reader)
666 BufferSet& bufs (_session.get_route_buffers (n_process_buffers()));
668 fill_buffers_with_input (bufs, _input, nframes);
670 /* filter captured data before meter sees it */
673 if (is_monitor() && _session.listening() && !_session.is_auditioning()) {
675 /* control/monitor bus ignores input ports when something is
676 feeding the listen "stream". data will "arrive" into the
677 route from the intreturn processor element.
680 bufs.silence (nframes, 0);
683 snapshot_out_of_band_data (nframes);
684 /* append immediate messages to the first MIDI buffer (thus sending it to the first output port) */
686 write_out_of_band_data (bufs, nframes);
688 /* run processor chain */
690 process_output_buffers (bufs, start_sample, end_sample, nframes, declick, gain_automation_ok, run_disk_reader);
692 /* map events (e.g. MIDI-CC) back to control-parameters */
693 update_controls (bufs);
695 flush_processor_buffers_locked (nframes);
699 Route::set_listen (bool yn)
702 if (_monitor_send->active() == yn) {
706 _monitor_send->activate ();
708 _monitor_send->deactivate ();
714 Route::solo_control_changed (bool, Controllable::GroupControlDisposition)
716 /* nothing to do if we're not using AFL/PFL. But if we are, we need
717 to alter the active state of the monitor send.
720 if (Config->get_solo_control_is_listen_control ()) {
721 set_listen (_solo_control->self_soloed() || _solo_control->get_masters_value());
726 Route::push_solo_isolate_upstream (int32_t delta)
728 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
730 boost::shared_ptr<RouteList> routes = _session.get_routes ();
731 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
733 if ((*i).get() == this || !(*i)->can_solo()) {
738 bool does_feed = feeds (*i, &sends_only);
740 if (does_feed && !sends_only) {
741 (*i)->solo_isolate_control()->mod_solo_isolated_by_upstream (delta);
747 Route::push_solo_upstream (int delta)
749 DEBUG_TRACE (DEBUG::Solo, string_compose("\t ... INVERT push from %1\n", _name));
750 for (FedBy::iterator i = _fed_by.begin(); i != _fed_by.end(); ++i) {
754 boost::shared_ptr<Route> sr (i->r.lock());
756 sr->solo_control()->mod_solo_by_others_downstream (-delta);
763 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
765 cerr << name << " {" << endl;
766 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
767 p != procs.end(); ++p) {
768 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << " @ " << (*p) << endl;
774 /** Supposing that we want to insert a Processor at a given Placement, return
775 * the processor to add the new one before (or 0 to add at the end).
777 boost::shared_ptr<Processor>
778 Route::before_processor_for_placement (Placement p)
780 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
782 ProcessorList::iterator loc;
785 /* generic pre-fader: insert immediately before the amp */
786 loc = find (_processors.begin(), _processors.end(), _amp);
788 /* generic post-fader: insert right before the main outs */
789 loc = find (_processors.begin(), _processors.end(), _main_outs);
792 return loc != _processors.end() ? *loc : boost::shared_ptr<Processor> ();
795 /** Supposing that we want to insert a Processor at a given index, return
796 * the processor to add the new one before (or 0 to add at the end).
798 boost::shared_ptr<Processor>
799 Route::before_processor_for_index (int index)
802 return boost::shared_ptr<Processor> ();
805 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
807 ProcessorList::iterator i = _processors.begin ();
809 while (i != _processors.end() && j < index) {
810 if ((*i)->display_to_user()) {
817 return (i != _processors.end() ? *i : boost::shared_ptr<Processor> ());
820 /** Add a processor either pre- or post-fader
821 * @return 0 on success, non-0 on failure.
824 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err, bool activation_allowed)
826 return add_processor (processor, before_processor_for_placement (placement), err, activation_allowed);
830 /** Add a processor to a route such that it ends up with a given index into the visible processors.
831 * @param index Index to add the processor at, or -1 to add at the end of the list.
832 * @return 0 on success, non-0 on failure.
835 Route::add_processor_by_index (boost::shared_ptr<Processor> processor, int index, ProcessorStreams* err, bool activation_allowed)
837 return add_processor (processor, before_processor_for_index (index), err, activation_allowed);
840 /** Add a processor to the route.
841 * @param before An existing processor in the list, or 0; the new processor will be inserted immediately before it (or at the end).
842 * @return 0 on success, non-0 on failure.
845 Route::add_processor (boost::shared_ptr<Processor> processor, boost::shared_ptr<Processor> before, ProcessorStreams* err, bool activation_allowed)
847 assert (processor != _meter);
848 assert (processor != _main_outs);
850 DEBUG_TRACE (DEBUG::Processors, string_compose (
851 "%1 adding processor %2\n", name(), processor->name()));
855 pl.push_back (processor);
856 int rv = add_processors (pl, before, err);
862 if (activation_allowed && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user ())) {
863 processor->activate ();
870 Route::processor_selfdestruct (boost::weak_ptr<Processor> wp)
872 /* We cannot destruct the processor here (usually RT-thread
873 * with various locks held - in case of sends also io_locks).
874 * Queue for deletion in low-priority thread.
876 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
877 selfdestruct_sequence.push_back (wp);
881 Route::add_processor_from_xml_2X (const XMLNode& node, int version)
883 XMLProperty const * prop;
886 boost::shared_ptr<Processor> processor;
888 /* bit of a hack: get the `placement' property from the <Redirect> tag here
889 so that we can add the processor in the right place (pre/post-fader)
892 XMLNodeList const & children = node.children ();
893 XMLNodeList::const_iterator i = children.begin ();
895 while (i != children.end() && (*i)->name() != X_("Redirect")) {
899 Placement placement = PreFader;
901 if (i != children.end()) {
902 if ((prop = (*i)->property (X_("placement"))) != 0) {
903 placement = Placement (string_2_enum (prop->value(), placement));
907 if (node.name() == "Insert") {
909 if ((prop = node.property ("type")) != 0) {
911 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
912 prop->value() == "lv2" ||
913 prop->value() == "windows-vst" ||
914 prop->value() == "mac-vst" ||
915 prop->value() == "lxvst" ||
916 prop->value() == "audiounit") {
918 if (_session.get_disable_all_loaded_plugins ()) {
919 processor.reset (new UnknownProcessor (_session, node));
921 processor.reset (new PluginInsert (_session));
922 processor->set_owner (this);
927 processor.reset (new PortInsert (_session, _pannable, _mute_master));
932 } else if (node.name() == "Send") {
934 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
935 processor.reset (new Send (_session, sendpan, _mute_master));
939 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
943 if (processor->set_state (node, version)) {
947 //A2 uses the "active" flag in the toplevel redirect node, not in the child plugin/IO
948 if (i != children.end()) {
949 if ((prop = (*i)->property (X_("active"))) != 0) {
950 if ( string_to<bool> (prop->value()) && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user () ) )
951 processor->activate();
953 processor->deactivate();
957 return (add_processor (processor, placement, 0, false) == 0);
960 catch (failed_constructor &err) {
961 warning << _("processor could not be created. Ignored.") << endmsg;
967 inline Route::PluginSetupOptions operator|= (Route::PluginSetupOptions& a, const Route::PluginSetupOptions& b) {
968 return a = static_cast<Route::PluginSetupOptions> (static_cast <int>(a) | static_cast<int> (b));
971 inline Route::PluginSetupOptions operator&= (Route::PluginSetupOptions& a, const Route::PluginSetupOptions& b) {
972 return a = static_cast<Route::PluginSetupOptions> (static_cast <int>(a) & static_cast<int> (b));
976 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
978 ProcessorList::iterator loc;
979 boost::shared_ptr <PluginInsert> fanout;
981 if (g_atomic_int_get (&_pending_process_reorder)) {
982 /* we need to flush any pending re-order changes */
983 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
984 apply_processor_changes_rt ();
988 loc = find(_processors.begin(), _processors.end(), before);
989 if (loc == _processors.end ()) {
993 /* nothing specified - at end */
994 loc = _processors.end ();
997 if (others.empty()) {
1001 ProcessorList to_skip;
1003 // check if there's an instrument to replace or configure
1004 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1005 boost::shared_ptr<PluginInsert> pi;
1006 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) == 0) {
1009 if (!pi->plugin ()->get_info ()->is_instrument ()) {
1012 boost::shared_ptr<Processor> instrument = the_instrument ();
1013 ChanCount in (DataType::MIDI, 1);
1014 ChanCount out (DataType::AUDIO, 2); // XXX route's out?!
1016 PluginSetupOptions flags = None;
1018 flags |= CanReplace;
1019 in = instrument->input_streams ();
1020 out = instrument->output_streams ();
1022 if (pi->has_output_presets (in, out)) {
1026 pi->set_strict_io (_strict_io);
1028 PluginSetupOptions mask = None;
1029 if (Config->get_ask_replace_instrument ()) {
1032 if (Config->get_ask_setup_instrument ()) {
1038 if (flags != None) {
1039 boost::optional<int> rv = PluginSetup (boost::dynamic_pointer_cast<Route>(shared_from_this ()), pi, flags); /* EMIT SIGNAL */
1040 int mode = rv.get_value_or (0);
1043 to_skip.push_back (*i); // don't add this one;
1046 replace_processor (instrument, *i, err);
1047 to_skip.push_back (*i);
1052 if ((mode & 5) == 4) {
1059 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1060 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1061 ProcessorState pstate (this);
1063 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1068 ProcessorList::iterator check = find (to_skip.begin(), to_skip.end(), *i);
1069 if (check != to_skip.end()) {
1073 boost::shared_ptr<PluginInsert> pi;
1075 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1076 pi->set_strict_io (_strict_io);
1080 /* Ensure that only one amp is in the list at any time */
1081 ProcessorList::iterator check = find (_processors.begin(), _processors.end(), *i);
1082 if (check != _processors.end()) {
1083 if (before == _amp) {
1084 /* Already in position; all is well */
1087 _processors.erase (check);
1092 assert (find (_processors.begin(), _processors.end(), *i) == _processors.end ());
1094 _processors.insert (loc, *i);
1095 (*i)->set_owner (this);
1098 if (configure_processors_unlocked (err, &lm)) {
1100 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
1105 if (pi && pi->has_sidechain ()) {
1106 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
1109 if ((*i)->active()) {
1110 // emit ActiveChanged() and latency_changed() if needed
1114 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1116 boost::shared_ptr<Send> send;
1117 if ((send = boost::dynamic_pointer_cast<Send> (*i))) {
1118 send->SelfDestruct.connect_same_thread (*this,
1119 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (*i)));
1123 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1124 boost::shared_ptr<PluginInsert> pi;
1126 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1127 if (pi->has_no_inputs ()) {
1128 _have_internal_generator = true;
1134 _output->set_user_latency (0);
1137 reset_instrument_info ();
1138 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1139 set_processor_positions ();
1141 if (fanout && fanout->configured ()
1142 && fanout->output_streams().n_audio() > 2
1143 && boost::dynamic_pointer_cast<PluginInsert> (the_instrument ()) == fanout) {
1144 fan_out (); /* EMIT SIGNAL */
1150 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1152 if (p == PreFader) {
1153 start = _processors.begin();
1154 end = find(_processors.begin(), _processors.end(), _amp);
1156 start = find(_processors.begin(), _processors.end(), _amp);
1158 end = _processors.end();
1162 /** Turn off all processors with a given placement
1163 * @param p Placement of processors to disable
1166 Route::disable_processors (Placement p)
1168 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1170 ProcessorList::iterator start, end;
1171 placement_range(p, start, end);
1173 for (ProcessorList::iterator i = start; i != end; ++i) {
1174 (*i)->enable (false);
1177 _session.set_dirty ();
1180 /** Turn off all redirects
1183 Route::disable_processors ()
1185 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1187 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1188 (*i)->enable (false);
1191 _session.set_dirty ();
1194 /** Turn off all redirects with a given placement
1195 * @param p Placement of redirects to disable
1198 Route::disable_plugins (Placement p)
1200 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1202 ProcessorList::iterator start, end;
1203 placement_range(p, start, end);
1205 for (ProcessorList::iterator i = start; i != end; ++i) {
1206 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1207 (*i)->enable (false);
1211 _session.set_dirty ();
1214 /** Turn off all plugins
1217 Route::disable_plugins ()
1219 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1221 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1222 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1223 (*i)->enable (false);
1227 _session.set_dirty ();
1232 Route::ab_plugins (bool forward)
1234 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1238 /* forward = turn off all active redirects, and mark them so that the next time
1239 we go the other way, we will revert them
1242 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1243 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1246 if (!(*i)->display_to_user ()) {
1250 if (boost::dynamic_pointer_cast<PluginInsert> (*i)->is_channelstrip()) {
1255 if ((*i)->enabled ()) {
1256 (*i)->enable (false);
1257 (*i)->set_next_ab_is_active (true);
1259 (*i)->set_next_ab_is_active (false);
1265 /* backward = if the redirect was marked to go active on the next ab, do so */
1267 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1268 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1271 if (!(*i)->display_to_user ()) {
1275 if (boost::dynamic_pointer_cast<PluginInsert> (*i)->is_channelstrip()) {
1280 (*i)->enable ((*i)->get_next_ab_is_active ());
1284 _session.set_dirty ();
1288 /** Remove processors with a given placement.
1289 * @param p Placement of processors to remove.
1292 Route::clear_processors (Placement p)
1294 if (!_session.engine().connected()) {
1298 bool already_deleting = _session.deletion_in_progress();
1299 if (!already_deleting) {
1300 _session.set_deletion_in_progress();
1303 ProcessorList old_list = _processors;
1305 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1306 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1307 ProcessorList new_list;
1308 ProcessorStreams err;
1309 bool seen_amp = false;
1311 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1317 if (is_internal_processor (*i)) {
1319 /* you can't remove these */
1321 new_list.push_back (*i);
1328 new_list.push_back (*i);
1331 (*i)->drop_references ();
1339 (*i)->drop_references ();
1342 new_list.push_back (*i);
1349 _processors = new_list;
1350 configure_processors_unlocked (&err, &lm); // this can't fail
1352 /* drop references w/o process-lock (I/O procs may re-take it in ~IO() */
1355 processor_max_streams.reset();
1356 _have_internal_generator = false;
1357 reset_instrument_info ();
1358 set_processor_positions ();
1360 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1362 if (!already_deleting) {
1363 _session.clear_deletion_in_progress();
1368 Route::is_internal_processor (boost::shared_ptr<Processor> p) const
1370 if (p == _amp || p == _meter || p == _main_outs || p == _delayline || p == _trim || p == _polarity) {
1377 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err, bool need_process_lock)
1379 // TODO once the export point can be configured properly, do something smarter here
1380 if (processor == _capturing_processor) {
1381 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1382 if (need_process_lock) {
1386 _capturing_processor.reset();
1388 if (need_process_lock) {
1393 /* these can never be removed */
1395 if (is_internal_processor (processor)) {
1399 if (!_session.engine().connected()) {
1403 processor_max_streams.reset();
1406 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1407 if (need_process_lock) {
1411 /* Caller must hold process lock */
1412 assert (!AudioEngine::instance()->process_lock().trylock());
1414 Glib::Threads::RWLock::WriterLock lm (_processor_lock); // XXX deadlock after export
1416 ProcessorState pstate (this);
1418 ProcessorList::iterator i;
1419 bool removed = false;
1421 for (i = _processors.begin(); i != _processors.end(); ) {
1422 if (*i == processor) {
1424 /* move along, see failure case for configure_processors()
1425 where we may need to reconfigure the processor.
1428 /* stop redirects that send signals to JACK ports
1429 from causing noise as a result of no longer being
1433 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor> (*i);
1434 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
1438 iop = pi->sidechain();
1445 i = _processors.erase (i);
1453 _output->set_user_latency (0);
1461 if (configure_processors_unlocked (err, &lm)) {
1463 /* we know this will work, because it worked before :) */
1464 configure_processors_unlocked (0, &lm);
1468 _have_internal_generator = false;
1470 for (i = _processors.begin(); i != _processors.end(); ++i) {
1471 boost::shared_ptr<PluginInsert> pi;
1473 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1474 if (pi->has_no_inputs ()) {
1475 _have_internal_generator = true;
1480 if (need_process_lock) {
1485 reset_instrument_info ();
1486 processor->drop_references ();
1487 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1488 set_processor_positions ();
1494 Route::replace_processor (boost::shared_ptr<Processor> old, boost::shared_ptr<Processor> sub, ProcessorStreams* err)
1496 /* these can never be removed */
1497 if (is_internal_processor (old)) {
1500 /* and can't be used as substitute, either */
1501 if (is_internal_processor (sub)) {
1505 /* I/Os are out, too */
1506 if (boost::dynamic_pointer_cast<IOProcessor> (old) || boost::dynamic_pointer_cast<IOProcessor> (sub)) {
1510 /* this function cannot be used to swap/reorder processors */
1511 if (find (_processors.begin(), _processors.end(), sub) != _processors.end ()) {
1515 if (!AudioEngine::instance()->connected() || !old || !sub) {
1519 /* ensure that sub is not owned by another route */
1520 if (sub->owner ()) {
1525 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1526 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1527 ProcessorState pstate (this);
1529 assert (find (_processors.begin(), _processors.end(), sub) == _processors.end ());
1531 ProcessorList::iterator i;
1532 bool replaced = false;
1533 bool enable = old->enabled ();
1535 for (i = _processors.begin(); i != _processors.end(); ) {
1537 i = _processors.erase (i);
1538 _processors.insert (i, sub);
1539 sub->set_owner (this);
1552 boost::shared_ptr<PluginInsert> pi;
1553 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(sub)) != 0) {
1554 pi->set_strict_io (true);
1558 if (configure_processors_unlocked (err, &lm)) {
1560 configure_processors_unlocked (0, &lm);
1564 _have_internal_generator = false;
1566 for (i = _processors.begin(); i != _processors.end(); ++i) {
1567 boost::shared_ptr<PluginInsert> pi;
1568 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1569 if (pi->has_no_inputs ()) {
1570 _have_internal_generator = true;
1580 sub->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1581 _output->set_user_latency (0);
1584 reset_instrument_info ();
1585 old->drop_references ();
1586 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1587 set_processor_positions ();
1592 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1594 ProcessorList deleted;
1596 if (!_session.engine().connected()) {
1600 processor_max_streams.reset();
1603 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1604 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1605 ProcessorState pstate (this);
1607 ProcessorList::iterator i;
1608 boost::shared_ptr<Processor> processor;
1610 for (i = _processors.begin(); i != _processors.end(); ) {
1614 /* these can never be removed */
1616 if (is_internal_processor (processor)) {
1621 /* see if its in the list of processors to delete */
1623 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1628 /* stop IOProcessors that send to JACK ports
1629 from causing noise as a result of no longer being
1633 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(processor);
1634 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
1637 iop = pi->sidechain();
1644 deleted.push_back (processor);
1645 i = _processors.erase (i);
1648 if (deleted.empty()) {
1649 /* none of those in the requested list were found */
1653 _output->set_user_latency (0);
1655 if (configure_processors_unlocked (err, &lm)) {
1657 /* we know this will work, because it worked before :) */
1658 configure_processors_unlocked (0, &lm);
1663 _have_internal_generator = false;
1665 for (i = _processors.begin(); i != _processors.end(); ++i) {
1666 boost::shared_ptr<PluginInsert> pi;
1668 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1669 if (pi->has_no_inputs ()) {
1670 _have_internal_generator = true;
1677 /* now try to do what we need to so that those that were removed will be deleted */
1679 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1680 (*i)->drop_references ();
1683 reset_instrument_info ();
1684 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1685 set_processor_positions ();
1691 Route::reset_instrument_info ()
1693 boost::shared_ptr<Processor> instr = the_instrument();
1695 _instrument_info.set_internal_instrument (instr);
1699 /** Caller must hold process lock */
1701 Route::configure_processors (ProcessorStreams* err)
1703 #ifndef PLATFORM_WINDOWS
1704 assert (!AudioEngine::instance()->process_lock().trylock());
1707 if (!_in_configure_processors) {
1708 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1709 return configure_processors_unlocked (err, &lm);
1716 Route::input_streams () const
1718 return _input->n_ports ();
1721 list<pair<ChanCount, ChanCount> >
1722 Route::try_configure_processors (ChanCount in, ProcessorStreams* err)
1724 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1726 return try_configure_processors_unlocked (in, err);
1729 list<pair<ChanCount, ChanCount> >
1730 Route::try_configure_processors_unlocked (ChanCount in, ProcessorStreams* err)
1732 // Check each processor in order to see if we can configure as requested
1734 list<pair<ChanCount, ChanCount> > configuration;
1737 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1738 DEBUG_TRACE (DEBUG::Processors, "{\n");
1740 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1742 if ((*p)->can_support_io_configuration(in, out)) {
1744 if (boost::dynamic_pointer_cast<Delivery> (*p)
1745 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main
1747 && (is_monitor() || _strict_io || Profile->get_mixbus ())) {
1748 /* with strict I/O the panner + output are forced to
1749 * follow the last processor's output.
1751 * Delivery::can_support_io_configuration() will only add ports,
1752 * but not remove excess ports.
1754 * This works because the delivery only requires
1755 * as many outputs as there are inputs.
1756 * Delivery::configure_io() will do the actual removal
1757 * by calling _output->ensure_io()
1759 if (!is_master() && _session.master_out () && in.n_audio() > 0) {
1760 /* ..but at least as many as there are master-inputs, if
1761 * the delivery is dealing with audio */
1762 // XXX this may need special-casing for mixbus (master-outputs)
1763 // and should maybe be a preference anyway ?!
1764 out = ChanCount::max (in, _session.master_out ()->n_inputs ());
1770 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID=%2 in=%3 out=%4\n",(*p)->name(), (*p)->id(), in, out));
1771 configuration.push_back(make_pair(in, out));
1774 // restriction for Monitor Section Processors
1775 if (in.n_audio() != out.n_audio() || out.n_midi() > 0) {
1776 /* Note: The Monitor follows the master-bus and has no panner.
1778 * The general idea is to only allow plugins that retain the channel-count
1779 * and plugins with MIDI in (e.g VSTs with control that will remain unconnected).
1780 * Then again 5.1 in, monitor stereo is a valid use-case.
1782 * and worse: we only refuse adding plugins *here*.
1784 * 1) stereo-master, stereo-mon, add a stereo-plugin, OK
1785 * 2) change master-bus, add a channel
1786 * 2a) monitor-secion follows
1787 * 3) monitor processors fail to re-reconfigure (stereo plugin)
1788 * 4) re-load session, monitor-processor remains unconfigured, crash.
1790 DEBUG_TRACE (DEBUG::Processors, "Monitor: Channel configuration change.\n");
1792 if (boost::dynamic_pointer_cast<InternalSend> (*p)) {
1793 // internal sends make no sense, only feedback
1794 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1795 return list<pair<ChanCount, ChanCount> > ();
1797 if (boost::dynamic_pointer_cast<PortInsert> (*p)) {
1798 /* External Sends can be problematic. one can add/remove ports
1799 * there signal leaves the DAW to external monitors anyway, so there's
1800 * no real use for allowing them here anyway.
1802 DEBUG_TRACE (DEBUG::Processors, "Monitor: No External Sends allowed.\n");
1803 return list<pair<ChanCount, ChanCount> > ();
1805 if (boost::dynamic_pointer_cast<Send> (*p)) {
1807 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1808 return list<pair<ChanCount, ChanCount> > ();
1817 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
1818 DEBUG_TRACE (DEBUG::Processors, string_compose ("---- %1 cannot support in=%2 out=%3\n", (*p)->name(), in, out));
1819 DEBUG_TRACE (DEBUG::Processors, "}\n");
1820 return list<pair<ChanCount, ChanCount> > ();
1824 DEBUG_TRACE (DEBUG::Processors, "}\n");
1826 return configuration;
1829 /** Set the input/output configuration of each processor in the processors list.
1830 * Caller must hold process lock.
1831 * Return 0 on success, otherwise configuration is impossible.
1834 Route::configure_processors_unlocked (ProcessorStreams* err, Glib::Threads::RWLock::WriterLock* lm)
1836 #ifndef PLATFORM_WINDOWS
1837 assert (!AudioEngine::instance()->process_lock().trylock());
1840 if (_in_configure_processors) {
1844 /* put invisible processors where they should be */
1845 setup_invisible_processors ();
1847 _in_configure_processors = true;
1849 list<pair<ChanCount, ChanCount> > configuration = try_configure_processors_unlocked (input_streams (), err);
1851 if (configuration.empty ()) {
1852 _in_configure_processors = false;
1857 bool seen_mains_out = false;
1858 processor_out_streams = _input->n_ports();
1859 processor_max_streams.reset();
1861 /* processor configure_io() may result in adding ports
1862 * e.g. Delivery::configure_io -> ARDOUR::IO::ensure_io ()
1864 * with jack2 adding ports results in a graph-order callback,
1865 * which calls Session::resort_routes() and eventually
1866 * Route::direct_feeds_according_to_reality()
1867 * which takes a ReaderLock (_processor_lock).
1869 * so we can't hold a WriterLock here until jack2 threading
1872 * NB. we still hold the process lock
1874 * (ardour's own engines do call graph-order from the
1875 * process-thread and hence do not have this issue; besides
1876 * merely adding ports won't trigger a graph-order, only
1877 * making connections does)
1881 // TODO check for a potential ReaderLock after ReaderLock ??
1882 Glib::Threads::RWLock::ReaderLock lr (_processor_lock);
1884 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1885 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1887 if (!(*p)->configure_io(c->first, c->second)) {
1888 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration failed\n", _name));
1889 _in_configure_processors = false;
1895 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1896 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1898 boost::shared_ptr<IOProcessor> iop;
1899 boost::shared_ptr<PluginInsert> pi;
1900 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
1901 /* plugins connected via Split or Hide Match may have more channels.
1902 * route/scratch buffers are needed for all of them
1903 * The configuration may only be a subset (both input and output)
1905 processor_max_streams = ChanCount::max(processor_max_streams, pi->required_buffers());
1907 else if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*p)) != 0) {
1908 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_input_streams());
1909 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_output_streams());
1913 if (boost::dynamic_pointer_cast<Delivery> (*p)
1914 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main) {
1915 /* main delivery will increase port count to match input.
1916 * the Delivery::Main is usually the last processor - followed only by
1919 seen_mains_out = true;
1921 if (!seen_mains_out) {
1922 processor_out_streams = out;
1931 _meter->set_max_channels (processor_max_streams);
1934 /* make sure we have sufficient scratch buffers to cope with the new processor
1937 _session.ensure_buffers (n_process_buffers ());
1939 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration complete\n", _name));
1941 _in_configure_processors = false;
1945 /** Set all visible processors to a given active state (except Fader, whose state is not changed)
1946 * @param state New active state for those processors.
1949 Route::all_visible_processors_active (bool state)
1951 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1953 if (_processors.empty()) {
1957 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1958 if (!(*i)->display_to_user() || boost::dynamic_pointer_cast<Amp> (*i)) {
1962 boost::shared_ptr<PluginInsert> pi;
1963 if (0 != (pi = boost::dynamic_pointer_cast<PluginInsert>(*i))) {
1964 if (pi->is_channelstrip ()) {
1969 (*i)->enable (state);
1972 _session.set_dirty ();
1976 Route::processors_reorder_needs_configure (const ProcessorList& new_order)
1978 /* check if re-order requires re-configuration of any processors
1979 * -> compare channel configuration for all processors
1981 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1982 ChanCount c = input_streams ();
1984 for (ProcessorList::const_iterator j = new_order.begin(); j != new_order.end(); ++j) {
1986 if (c != (*j)->input_streams()) {
1989 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1992 if ((*i)->input_streams() != c) {
1995 c = (*i)->output_streams();
2007 __attribute__((annotate("realtime")))
2010 Route::apply_processor_order (const ProcessorList& new_order)
2012 /* need to hold processor_lock; either read or write lock
2013 * and the engine process_lock.
2014 * Due to r/w lock ambiguity we can only assert the latter
2016 assert (!AudioEngine::instance()->process_lock().trylock());
2019 /* "new_order" is an ordered list of processors to be positioned according to "placement".
2020 * NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
2021 * processors in the current actual processor list that are hidden. Any visible processors
2022 * in the current list but not in "new_order" will be assumed to be deleted.
2025 /* "as_it_will_be" and "_processors" are lists of shared pointers.
2026 * actual memory usage is small, but insert/erase is not actually rt-safe :(
2027 * (note though that ::processors_reorder_needs_configure() ensured that
2028 * this function will only ever be called from the rt-thread if no processor were removed)
2030 * either way, I can't proove it, but an x-run due to re-order here is less likley
2031 * than an x-run-less 'ardour-silent cycle' both of which effectively "click".
2034 ProcessorList as_it_will_be;
2035 ProcessorList::iterator oiter;
2036 ProcessorList::const_iterator niter;
2038 oiter = _processors.begin();
2039 niter = new_order.begin();
2041 while (niter != new_order.end()) {
2043 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
2044 then append it to the temp list.
2046 Otherwise, see if the next processor in the old list is in the new list. if not,
2047 its been deleted. If its there, append it to the temp list.
2050 if (oiter == _processors.end()) {
2052 /* no more elements in the old list, so just stick the rest of
2053 the new order onto the temp list.
2056 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
2057 while (niter != new_order.end()) {
2064 if (!(*oiter)->display_to_user()) {
2066 as_it_will_be.push_back (*oiter);
2070 /* visible processor: check that its in the new order */
2072 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
2073 /* deleted: do nothing, shared_ptr<> will clean up */
2075 /* ignore this one, and add the next item from the new order instead */
2076 as_it_will_be.push_back (*niter);
2081 /* now remove from old order - its taken care of no matter what */
2082 oiter = _processors.erase (oiter);
2086 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
2088 /* If the meter is in a custom position, find it and make a rough note of its position */
2089 maybe_note_meter_position ();
2093 Route::move_instrument_down (bool postfader)
2095 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2096 ProcessorList new_order;
2097 boost::shared_ptr<Processor> instrument;
2098 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2099 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
2100 if (pi && pi->plugin ()->get_info ()->is_instrument ()) {
2102 } else if (instrument && *i == _amp) {
2104 new_order.push_back (*i);
2105 new_order.push_back (instrument);
2107 new_order.push_back (instrument);
2108 new_order.push_back (*i);
2111 new_order.push_back (*i);
2118 reorder_processors (new_order, 0);
2122 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
2124 // it a change is already queued, wait for it
2125 // (unless engine is stopped. apply immediately and proceed
2126 while (g_atomic_int_get (&_pending_process_reorder)) {
2127 if (!AudioEngine::instance()->running()) {
2128 DEBUG_TRACE (DEBUG::Processors, "offline apply queued processor re-order.\n");
2129 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2131 apply_processor_order(_pending_processor_order);
2132 setup_invisible_processors ();
2134 g_atomic_int_set (&_pending_process_reorder, 0);
2136 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2137 set_processor_positions ();
2139 // TODO rather use a semaphore or something.
2140 // but since ::reorder_processors() is called
2141 // from the GUI thread, this is fine..
2146 if (processors_reorder_needs_configure (new_order) || !AudioEngine::instance()->running()) {
2148 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2149 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2150 ProcessorState pstate (this);
2152 apply_processor_order (new_order);
2154 if (configure_processors_unlocked (err, &lm)) {
2162 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2163 set_processor_positions ();
2166 DEBUG_TRACE (DEBUG::Processors, "Queue clickless processor re-order.\n");
2167 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2169 // _pending_processor_order is protected by _processor_lock
2170 _pending_processor_order = new_order;
2171 g_atomic_int_set (&_pending_process_reorder, 1);
2174 /* update processor input/output latency
2175 * (total signal_latency does not change)
2177 update_signal_latency (true);
2183 Route::add_remove_sidechain (boost::shared_ptr<Processor> proc, bool add)
2185 boost::shared_ptr<PluginInsert> pi;
2186 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2190 if (pi->has_sidechain () == add) {
2191 return true; // ?? call failed, but result is as expected.
2195 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2196 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2197 if (i == _processors.end ()) {
2203 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ()); // take before Writerlock to avoid deadlock
2204 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2205 PBD::Unwinder<bool> uw (_in_sidechain_setup, true);
2207 lx.release (); // IO::add_port() and ~IO takes process lock - XXX check if this is safe
2209 if (!pi->add_sidechain ()) {
2213 if (!pi->del_sidechain ()) {
2219 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2224 pi->del_sidechain ();
2226 pi->add_sidechain ();
2227 // TODO restore side-chain's state.
2232 configure_processors_unlocked (0, &lm);
2235 if (pi->has_sidechain ()) {
2236 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
2239 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2240 _session.set_dirty ();
2245 Route::plugin_preset_output (boost::shared_ptr<Processor> proc, ChanCount outs)
2247 boost::shared_ptr<PluginInsert> pi;
2248 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2253 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2254 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2255 if (i == _processors.end ()) {
2261 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2262 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2264 const ChanCount& old (pi->preset_out ());
2265 if (!pi->set_preset_out (outs)) {
2266 return true; // no change, OK
2269 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2272 pi->set_preset_out (old);
2275 configure_processors_unlocked (0, &lm);
2278 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2279 _session.set_dirty ();
2284 Route::reset_plugin_insert (boost::shared_ptr<Processor> proc)
2287 return customize_plugin_insert (proc, 0, unused, unused);
2291 Route::customize_plugin_insert (boost::shared_ptr<Processor> proc, uint32_t count, ChanCount outs, ChanCount sinks)
2293 boost::shared_ptr<PluginInsert> pi;
2294 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2299 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2300 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2301 if (i == _processors.end ()) {
2307 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2308 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2310 bool old_cust = pi->custom_cfg ();
2311 uint32_t old_cnt = pi->get_count ();
2312 ChanCount old_chan = pi->output_streams ();
2313 ChanCount old_sinks = pi->natural_input_streams ();
2316 pi->set_custom_cfg (false);
2318 pi->set_custom_cfg (true);
2319 pi->set_count (count);
2320 pi->set_outputs (outs);
2321 pi->set_sinks (sinks);
2324 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2328 pi->set_count (old_cnt);
2329 pi->set_sinks (old_sinks);
2330 pi->set_outputs (old_chan);
2331 pi->set_custom_cfg (old_cust);
2335 configure_processors_unlocked (0, &lm);
2338 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2339 _session.set_dirty ();
2344 Route::set_strict_io (const bool enable)
2346 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2348 if (_strict_io != enable) {
2349 _strict_io = enable;
2350 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2351 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2352 boost::shared_ptr<PluginInsert> pi;
2353 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2354 pi->set_strict_io (_strict_io);
2358 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2362 _strict_io = !enable; // restore old value
2363 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2364 boost::shared_ptr<PluginInsert> pi;
2365 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2366 pi->set_strict_io (_strict_io);
2373 configure_processors (0);
2376 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2377 _session.set_dirty ();
2385 return state (false);
2389 Route::get_template()
2391 return state (true);
2395 Route::state (bool save_template)
2397 if (!_session._template_state_dir.empty()) {
2398 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), _session._template_state_dir));
2401 XMLNode *node = new XMLNode("Route");
2402 ProcessorList::iterator i;
2404 node->set_property (X_("id"), id ());
2405 node->set_property (X_("name"), name());
2406 node->set_property (X_("default-type"), _default_type);
2407 node->set_property (X_("strict-io"), _strict_io);
2409 node->add_child_nocopy (_presentation_info.get_state());
2411 node->set_property (X_("active"), _active);
2412 node->set_property (X_("denormal-protection"), _denormal_protection);
2413 node->set_property (X_("meter-point"), _meter_point);
2414 node->set_property (X_("disk-io-point"), _disk_io_point);
2416 node->set_property (X_("meter-type"), _meter_type);
2419 node->set_property (X_("route-group"), _route_group->name());
2422 node->add_child_nocopy (_solo_control->get_state ());
2423 node->add_child_nocopy (_solo_isolate_control->get_state ());
2424 node->add_child_nocopy (_solo_safe_control->get_state ());
2426 node->add_child_nocopy (_input->get_state ());
2427 node->add_child_nocopy (_output->get_state ());
2428 node->add_child_nocopy (_mute_master->get_state ());
2430 node->add_child_nocopy (_mute_control->get_state ());
2431 node->add_child_nocopy (_phase_control->get_state ());
2433 if (!skip_saving_automation) {
2434 node->add_child_nocopy (Automatable::get_automation_xml_state ());
2437 if (_comment.length()) {
2438 XMLNode *cmt = node->add_child ("Comment");
2439 cmt->add_content (_comment);
2443 node->add_child_nocopy (_pannable->get_state ());
2447 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2448 for (i = _processors.begin(); i != _processors.end(); ++i) {
2449 if (*i == _delayline) {
2452 if (save_template) {
2453 /* template save: do not include internal sends functioning as
2454 aux sends because the chance of the target ID
2455 in the session where this template is used
2458 similarly, do not save listen sends which connect to
2459 the monitor section, because these will always be
2462 boost::shared_ptr<InternalSend> is;
2464 if ((is = boost::dynamic_pointer_cast<InternalSend> (*i)) != 0) {
2465 if (is->role() == Delivery::Listen) {
2470 node->add_child_nocopy((*i)->get_state ());
2475 node->add_child_copy (*_extra_xml);
2478 if (_custom_meter_position_noted) {
2479 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
2481 node->set_property (X_("processor-after-last-custom-meter"), after->id());
2485 if (!_session._template_state_dir.empty()) {
2486 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), ""));
2489 node->add_child_copy (Slavable::get_state());
2495 Route::set_state (const XMLNode& node, int version)
2497 if (version < 3000) {
2498 return set_state_2X (node, version);
2502 XMLNodeConstIterator niter;
2505 if (node.name() != "Route"){
2506 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2510 std::string route_name;
2511 if (node.get_property (X_("name"), route_name)) {
2512 Route::set_name (route_name);
2516 _initial_io_setup = true;
2518 Stripable::set_state (node, version);
2520 node.get_property (X_("strict-io"), _strict_io);
2523 /* monitor bus does not get a panner, but if (re)created
2524 via XML, it will already have one by the time we
2525 call ::set_state(). so ... remove it.
2530 /* add all processors (except amp, which is always present) */
2532 nlist = node.children();
2533 XMLNode processor_state (X_("processor_state"));
2535 Stateful::save_extra_xml (node);
2537 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2541 if (child->name() == IO::state_node_name) {
2542 std::string direction;
2543 if (!child->get_property (X_("direction"), direction)) {
2547 if (direction == "Input") {
2548 _input->set_state (*child, version);
2549 } else if (direction == "Output") {
2550 _output->set_state (*child, version);
2553 } else if (child->name() == X_("Processor")) {
2554 processor_state.add_child_copy (*child);
2555 } else if (child->name() == X_("Pannable")) {
2557 _pannable->set_state (*child, version);
2559 warning << string_compose (_("Pannable state found for route (%1) without a panner!"), name()) << endmsg;
2561 } else if (child->name() == Slavable::xml_node_name) {
2562 Slavable::set_state (*child, version);
2567 if (node.get_property (X_("meter-point"), mp)) {
2568 set_meter_point (mp, true);
2570 _meter->set_display_to_user (_meter_point == MeterCustom);
2575 if (node.get_property (X_("disk-io-point"), diop)) {
2577 _disk_writer->set_display_to_user (diop == DiskIOCustom);
2580 _disk_reader->set_display_to_user (diop == DiskIOCustom);
2582 set_disk_io_point (diop);
2585 node.get_property (X_("meter-type"), _meter_type);
2587 _initial_io_setup = false;
2589 set_processor_state (processor_state);
2591 // this looks up the internal instrument in processors
2592 reset_instrument_info();
2594 bool denormal_protection;
2595 if (node.get_property (X_("denormal-protection"), denormal_protection)) {
2596 set_denormal_protection (denormal_protection);
2599 /* convert old 3001 state */
2600 std::string phase_invert_str;
2601 if (node.get_property (X_("phase-invert"), phase_invert_str)) {
2602 _phase_control->set_phase_invert (boost::dynamic_bitset<> (phase_invert_str));
2606 if (node.get_property (X_("active"), is_active)) {
2607 set_active (is_active, this);
2610 std::string id_string;
2611 if (node.get_property (X_("processor-after-last-custom-meter"), id_string)) {
2612 PBD::ID id (id_string);
2613 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2614 ProcessorList::const_iterator i = _processors.begin ();
2615 while (i != _processors.end() && (*i)->id() != id) {
2619 if (i != _processors.end ()) {
2620 _processor_after_last_custom_meter = *i;
2621 _custom_meter_position_noted = true;
2625 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2628 if (child->name() == X_("Comment")) {
2630 /* XXX this is a terrible API design in libxml++ */
2632 XMLNode *cmt = *(child->children().begin());
2633 _comment = cmt->content();
2635 } else if (child->name() == Controllable::xml_node_name) {
2636 std::string control_name;
2637 if (!child->get_property (X_("name"), control_name)) {
2641 if (control_name == _solo_control->name()) {
2642 _solo_control->set_state (*child, version);
2643 } else if (control_name == _solo_safe_control->name()) {
2644 _solo_safe_control->set_state (*child, version);
2645 } else if (control_name == _solo_isolate_control->name()) {
2646 _solo_isolate_control->set_state (*child, version);
2647 } else if (control_name == _mute_control->name()) {
2648 _mute_control->set_state (*child, version);
2649 } else if (control_name == _phase_control->name()) {
2650 _phase_control->set_state (*child, version);
2652 Evoral::Parameter p = EventTypeMap::instance().from_symbol (control_name);
2653 if (p.type () >= MidiCCAutomation && p.type () < MidiSystemExclusiveAutomation) {
2654 boost::shared_ptr<AutomationControl> ac = automation_control (p, true);
2656 ac->set_state (*child, version);
2660 } else if (child->name() == MuteMaster::xml_node_name) {
2661 _mute_master->set_state (*child, version);
2663 } else if (child->name() == Automatable::xml_node_name) {
2664 set_automation_xml_state (*child, Evoral::Parameter(NullAutomation));
2669 _delayline->set_name (name ());
2676 Route::set_state_2X (const XMLNode& node, int version)
2680 XMLNodeConstIterator niter;
2682 XMLProperty const * prop;
2684 /* 2X things which still remain to be handled:
2690 if (node.name() != "Route") {
2691 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2695 Stripable::set_state (node, version);
2697 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2698 set_denormal_protection (string_to<bool> (prop->value()));
2701 if ((prop = node.property (X_("muted"))) != 0) {
2704 bool muted = string_to<bool> (prop->value());
2710 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2712 if (string_to<bool> (prop->value())){
2713 mute_point = mute_point + "PreFader";
2718 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2720 if (string_to<bool> (prop->value())){
2723 mute_point = mute_point + ",";
2726 mute_point = mute_point + "PostFader";
2731 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2733 if (string_to<bool> (prop->value())){
2736 mute_point = mute_point + ",";
2739 mute_point = mute_point + "Listen";
2744 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2746 if (string_to<bool> (prop->value())){
2749 mute_point = mute_point + ",";
2752 mute_point = mute_point + "Main";
2756 _mute_master->set_mute_points (mute_point);
2757 _mute_master->set_muted_by_self (true);
2761 if ((prop = node.property (X_("meter-point"))) != 0) {
2762 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2767 nlist = node.children ();
2768 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2772 if (child->name() == IO::state_node_name) {
2774 /* there is a note in IO::set_state_2X() about why we have to call
2778 _input->set_state_2X (*child, version, true);
2779 _output->set_state_2X (*child, version, false);
2781 if ((prop = child->property (X_("name"))) != 0) {
2782 Route::set_name (prop->value ());
2787 if ((prop = child->property (X_("active"))) != 0) {
2788 bool yn = string_to<bool> (prop->value());
2789 _active = !yn; // force switch
2790 set_active (yn, this);
2793 if ((prop = child->property (X_("gain"))) != 0) {
2796 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
2797 _amp->gain_control()->set_value (val, Controllable::NoGroup);
2801 /* Set up Panners in the IO */
2802 XMLNodeList io_nlist = child->children ();
2804 XMLNodeConstIterator io_niter;
2807 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
2809 io_child = *io_niter;
2811 if (io_child->name() == X_("Panner")) {
2812 _main_outs->panner_shell()->set_state(*io_child, version);
2813 } else if (io_child->name() == X_("Automation")) {
2814 /* IO's automation is for the fader */
2815 _amp->set_automation_xml_state (*io_child, Evoral::Parameter (GainAutomation));
2821 XMLNodeList redirect_nodes;
2823 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2827 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2828 redirect_nodes.push_back(child);
2833 set_processor_state_2X (redirect_nodes, version);
2835 Stateful::save_extra_xml (node);
2837 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2840 if (child->name() == X_("Comment")) {
2842 /* XXX this is a terrible API design in libxml++ */
2844 XMLNode *cmt = *(child->children().begin());
2845 _comment = cmt->content();
2847 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2848 if (prop->value() == X_("solo")) {
2849 _solo_control->set_state (*child, version);
2850 } else if (prop->value() == X_("mute")) {
2851 _mute_control->set_state (*child, version);
2861 Route::get_processor_state ()
2863 XMLNode* root = new XMLNode (X_("redirects"));
2864 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2865 root->add_child_nocopy ((*i)->get_state ());
2872 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2874 /* We don't bother removing existing processors not in nList, as this
2875 method will only be called when creating a Route from scratch, not
2876 for undo purposes. Just put processors in at the appropriate place
2880 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2881 add_processor_from_xml_2X (**i, version);
2886 Route::set_processor_state (const XMLNode& node)
2888 const XMLNodeList &nlist = node.children();
2889 XMLNodeConstIterator niter;
2890 ProcessorList new_order;
2891 bool must_configure = false;
2893 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2895 XMLProperty* prop = (*niter)->property ("type");
2897 if (prop->value() == "amp") {
2898 _amp->set_state (**niter, Stateful::current_state_version);
2899 new_order.push_back (_amp);
2900 } else if (prop->value() == "trim") {
2901 _trim->set_state (**niter, Stateful::current_state_version);
2902 new_order.push_back (_trim);
2903 } else if (prop->value() == "meter") {
2904 _meter->set_state (**niter, Stateful::current_state_version);
2905 new_order.push_back (_meter);
2906 } else if (prop->value() == "polarity") {
2907 _polarity->set_state (**niter, Stateful::current_state_version);
2908 new_order.push_back (_polarity);
2909 } else if (prop->value() == "delay") {
2911 } else if (prop->value() == "main-outs") {
2912 _main_outs->set_state (**niter, Stateful::current_state_version);
2913 } else if (prop->value() == "intreturn") {
2915 _intreturn.reset (new InternalReturn (_session));
2916 must_configure = true;
2918 _intreturn->set_state (**niter, Stateful::current_state_version);
2919 } else if (is_monitor() && prop->value() == "monitor") {
2920 if (!_monitor_control) {
2921 _monitor_control.reset (new MonitorProcessor (_session));
2922 must_configure = true;
2924 _monitor_control->set_state (**niter, Stateful::current_state_version);
2925 } else if (prop->value() == "capture") {
2926 /* CapturingProcessor should never be restored, it's always
2927 added explicitly when needed */
2928 } else if (prop->value() == "diskreader" && _disk_reader) {
2929 _disk_reader->set_state (**niter, Stateful::current_state_version);
2930 new_order.push_back (_disk_reader);
2931 } else if (prop->value() == "diskwriter" && _disk_writer) {
2932 _disk_writer->set_state (**niter, Stateful::current_state_version);
2933 new_order.push_back (_disk_writer);
2935 set_processor_state (**niter, prop, new_order, must_configure);
2939 ProcessorList old_list = _processors; // keep a copy
2941 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2942 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2943 /* re-assign _processors w/o process-lock.
2944 * if there's an IO-processor present in _processors but
2945 * not in new_order, it will be deleted and ~IO takes
2948 _processors = new_order;
2950 if (must_configure) {
2951 configure_processors_unlocked (0, &lm);
2954 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2956 (*i)->set_owner (this);
2957 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
2959 boost::shared_ptr<PluginInsert> pi;
2961 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
2962 if (pi->has_no_inputs ()) {
2963 _have_internal_generator = true;
2969 /* drop references w/o process-lock (I/O procs may re-take it in ~IO() */
2972 reset_instrument_info ();
2973 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2974 set_processor_positions ();
2978 Route::set_processor_state (XMLNode const & node, XMLProperty const* prop, ProcessorList& new_order, bool& must_configure)
2980 ProcessorList::iterator o;
2982 for (o = _processors.begin(); o != _processors.end(); ++o) {
2983 XMLProperty const * id_prop = node.property(X_("id"));
2984 if (id_prop && (*o)->id() == id_prop->value()) {
2985 (*o)->set_state (node, Stateful::current_state_version);
2986 new_order.push_back (*o);
2991 // If the processor (node) is not on the route then create it
2993 if (o == _processors.end()) {
2995 boost::shared_ptr<Processor> processor;
2997 if (prop->value() == "intsend") {
2999 processor.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), boost::shared_ptr<Route>(), Delivery::Aux, true));
3001 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
3002 prop->value() == "lv2" ||
3003 prop->value() == "windows-vst" ||
3004 prop->value() == "mac-vst" ||
3005 prop->value() == "lxvst" ||
3006 prop->value() == "luaproc" ||
3007 prop->value() == "audiounit") {
3009 if (_session.get_disable_all_loaded_plugins ()) {
3010 processor.reset (new UnknownProcessor (_session, node));
3012 processor.reset (new PluginInsert (_session));
3013 processor->set_owner (this);
3015 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
3016 pi->set_strict_io (true);
3020 } else if (prop->value() == "port") {
3022 processor.reset (new PortInsert (_session, _pannable, _mute_master));
3024 } else if (prop->value() == "send") {
3026 processor.reset (new Send (_session, _pannable, _mute_master, Delivery::Send, true));
3027 boost::shared_ptr<Send> send = boost::dynamic_pointer_cast<Send> (processor);
3028 send->SelfDestruct.connect_same_thread (*this,
3029 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (processor)));
3035 if (processor->set_state (node, Stateful::current_state_version) != 0) {
3036 /* This processor could not be configured. Turn it into a UnknownProcessor */
3037 processor.reset (new UnknownProcessor (_session, node));
3040 /* subscribe to Sidechain IO changes */
3041 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
3042 if (pi && pi->has_sidechain ()) {
3043 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
3046 /* we have to note the monitor send here, otherwise a new one will be created
3047 and the state of this one will be lost.
3049 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
3050 if (isend && isend->role() == Delivery::Listen) {
3051 _monitor_send = isend;
3054 /* it doesn't matter if invisible processors are added here, as they
3055 will be sorted out by setup_invisible_processors () shortly.
3058 new_order.push_back (processor);
3059 must_configure = true;
3065 Route::curve_reallocate ()
3067 // _gain_automation_curve.finish_resize ();
3068 // _pan_automation_curve.finish_resize ();
3072 Route::silence (samplecnt_t nframes)
3074 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3079 silence_unlocked (nframes);
3083 Route::silence_unlocked (samplecnt_t nframes)
3085 /* Must be called with the processor lock held */
3087 const samplepos_t now = _session.transport_sample ();
3089 _output->silence (nframes);
3091 // update owned automated controllables
3092 automation_run (now, nframes);
3094 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3095 boost::shared_ptr<PluginInsert> pi;
3097 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
3098 /* evaluate automated automation controls */
3099 pi->automation_run (now, nframes);
3100 /* skip plugins, they don't need anything when we're not active */
3104 (*i)->silence (nframes, now);
3109 Route::add_internal_return ()
3112 _intreturn.reset (new InternalReturn (_session));
3113 add_processor (_intreturn, PreFader);
3118 Route::add_send_to_internal_return (InternalSend* send)
3120 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3122 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3123 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3126 return d->add_send (send);
3132 Route::remove_send_from_internal_return (InternalSend* send)
3134 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3136 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3137 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3140 return d->remove_send (send);
3146 Route::enable_monitor_send ()
3148 /* Caller must hold process lock */
3149 assert (!AudioEngine::instance()->process_lock().trylock());
3151 /* master never sends to monitor section via the normal mechanism */
3152 assert (!is_master ());
3153 assert (!is_monitor ());
3155 /* make sure we have one */
3156 if (!_monitor_send) {
3157 _monitor_send.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), _session.monitor_out(), Delivery::Listen));
3158 _monitor_send->set_display_to_user (false);
3162 configure_processors (0);
3165 /** Add an aux send to a route.
3166 * @param route route to send to.
3167 * @param before Processor to insert before, or 0 to insert at the end.
3170 Route::add_aux_send (boost::shared_ptr<Route> route, boost::shared_ptr<Processor> before)
3172 assert (route != _session.monitor_out ());
3175 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3177 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3179 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend> (*x);
3181 if (d && d->target_route() == route) {
3182 /* already listening via the specified IO: do nothing */
3190 boost::shared_ptr<InternalSend> listener;
3193 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
3194 listener.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), route, Delivery::Aux));
3197 add_processor (listener, before);
3199 } catch (failed_constructor& err) {
3207 Route::remove_aux_or_listen (boost::shared_ptr<Route> route)
3209 ProcessorStreams err;
3210 ProcessorList::iterator tmp;
3213 Glib::Threads::RWLock::ReaderLock rl(_processor_lock);
3215 /* have to do this early because otherwise processor reconfig
3216 * will put _monitor_send back in the list
3219 if (route == _session.monitor_out()) {
3220 _monitor_send.reset ();
3224 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3226 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
3228 if (d && d->target_route() == route) {
3230 if (remove_processor (*x, &err, false) > 0) {
3236 /* list could have been demolished while we dropped the lock
3239 if (_session.engine().connected()) {
3240 /* i/o processors cannot be removed if the engine is not running
3241 * so don't live-loop in case the engine is N/A or dies
3251 Route::set_comment (string cmt, void *src)
3255 _session.set_dirty ();
3259 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
3261 FeedRecord fr (other, via_sends_only);
3263 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
3265 if (!result.second) {
3267 /* already a record for "other" - make sure sends-only information is correct */
3268 if (!via_sends_only && result.first->sends_only) {
3269 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
3270 frp->sends_only = false;
3274 return result.second;
3278 Route::clear_fed_by ()
3284 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
3286 const FedBy& fed_by (other->fed_by());
3288 for (FedBy::const_iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
3289 boost::shared_ptr<Route> sr = f->r.lock();
3291 if (sr && (sr.get() == this)) {
3293 if (via_sends_only) {
3294 *via_sends_only = f->sends_only;
3305 Route::all_inputs () const
3307 /* TODO, if this works as expected,
3308 * cache the IOVector and maintain it via
3309 * input_change_handler(), sidechain_change_handler() etc
3312 ios.push_back (_input);
3314 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3315 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3317 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3318 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3321 iop = pi->sidechain();
3324 if (iop != 0 && iop->input()) {
3325 ios.push_back (iop->input());
3332 Route::all_outputs () const
3335 // _output is included via Delivery
3336 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3337 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3338 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3339 if (iop != 0 && iop->output()) {
3340 ios.push_back (iop->output());
3347 Route::direct_feeds_according_to_reality (boost::shared_ptr<Route> other, bool* via_send_only)
3349 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
3350 if (other->all_inputs().fed_by (_output)) {
3351 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
3352 if (via_send_only) {
3353 *via_send_only = false;
3359 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3361 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
3363 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3364 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3367 iop = pi->sidechain();
3371 boost::shared_ptr<const IO> iop_out = iop->output();
3372 if (other.get() == this && iop_out && iop->input() && iop_out->connected_to (iop->input())) {
3373 // TODO this needs a delaylines in the Insert to align connections (!)
3374 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed its own return (%2)\n", iop->name(), other->name()));
3377 if ((iop_out && other->all_inputs().fed_by (iop_out)) || iop->feeds (other)) {
3378 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
3379 if (via_send_only) {
3380 *via_send_only = true;
3384 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
3387 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
3392 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
3397 Route::direct_feeds_according_to_graph (boost::shared_ptr<Route> other, bool* via_send_only)
3399 return _session._current_route_graph.has (boost::dynamic_pointer_cast<Route> (shared_from_this ()), other, via_send_only);
3403 Route::feeds_according_to_graph (boost::shared_ptr<Route> other)
3405 return _session._current_route_graph.feeds (boost::dynamic_pointer_cast<Route> (shared_from_this ()), other);
3408 /** Called from the (non-realtime) butler thread when the transport is stopped */
3410 Route::non_realtime_transport_stop (samplepos_t now, bool flush)
3412 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3414 Automatable::non_realtime_transport_stop (now, flush);
3416 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3418 if (!_have_internal_generator && (Config->get_plugins_stop_with_transport() && flush)) {
3422 (*i)->non_realtime_transport_stop (now, flush);
3427 Route::input_change_handler (IOChange change, void * /*src*/)
3429 if ((change.type & IOChange::ConfigurationChanged)) {
3430 /* This is called with the process lock held if change
3431 contains ConfigurationChanged
3433 configure_processors (0);
3434 io_changed (); /* EMIT SIGNAL */
3437 if (_solo_control->soloed_by_others_upstream() || _solo_isolate_control->solo_isolated_by_upstream()) {
3440 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3441 if (_input->connected()) {
3442 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3443 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3447 bool does_feed = (*i)->direct_feeds_according_to_reality (boost::dynamic_pointer_cast<Route> (shared_from_this()), &sends_only);
3448 if (does_feed && !sends_only) {
3449 if ((*i)->soloed()) {
3452 if ((*i)->solo_isolate_control()->solo_isolated()) {
3459 int delta = sbou - _solo_control->soloed_by_others_upstream();
3460 int idelta = ibou - _solo_isolate_control->solo_isolated_by_upstream();
3463 PBD::warning << string_compose (
3464 _("Invalid Solo-Isolate propagation: from:%1 new:%2 - old:%3 = delta:%4"),
3465 _name, ibou, _solo_isolate_control->solo_isolated_by_upstream(), idelta)
3470 if (_solo_control->soloed_by_others_upstream()) {
3471 // ignore new connections (they're not propagated)
3473 _solo_control->mod_solo_by_others_upstream (delta);
3477 if (_solo_isolate_control->solo_isolated_by_upstream()) {
3478 // solo-isolate currently only propagates downstream
3480 _solo_isolate_control->mod_solo_isolated_by_upstream (1);
3482 //_solo_isolated_by_upstream = ibou;
3485 // Session::route_solo_changed does not propagate indirect solo-changes
3486 // propagate downstream to tracks
3487 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3488 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3492 bool does_feed = feeds (*i, &sends_only);
3493 if (delta <= 0 && does_feed && !sends_only) {
3494 (*i)->solo_control()->mod_solo_by_others_upstream (delta);
3497 if (idelta < 0 && does_feed && !sends_only) {
3498 (*i)->solo_isolate_control()->mod_solo_isolated_by_upstream (-1);
3505 Route::output_change_handler (IOChange change, void * /*src*/)
3507 if (_initial_io_setup) {
3511 if ((change.type & IOChange::ConfigurationChanged)) {
3512 /* This is called with the process lock held if change
3513 contains ConfigurationChanged
3515 configure_processors (0);
3518 _session.reset_monitor_section();
3521 io_changed (); /* EMIT SIGNAL */
3524 if ((change.type & IOChange::ConnectionsChanged)) {
3526 /* do this ONLY if connections have changed. Configuration
3527 * changes do not, by themselves alter solo upstream or
3528 * downstream status.
3531 if (_solo_control->soloed_by_others_downstream()) {
3533 /* checking all all downstream routes for
3534 * explicit of implict solo is a rather drastic measure,
3535 * ideally the input_change_handler() of the other route
3536 * would propagate the change to us.
3538 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3539 if (_output->connected()) {
3540 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3541 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3545 bool does_feed = direct_feeds_according_to_reality (*i, &sends_only);
3546 if (does_feed && !sends_only) {
3547 if ((*i)->soloed()) {
3555 int delta = sbod - _solo_control->soloed_by_others_downstream();
3557 // do not allow new connections to change implicit solo (no propagation)
3558 _solo_control->mod_solo_by_others_downstream (delta);
3559 // Session::route_solo_changed() does not propagate indirect solo-changes
3560 // propagate upstream to tracks
3561 boost::shared_ptr<Route> shared_this = boost::dynamic_pointer_cast<Route> (shared_from_this());
3562 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3563 if ((*i).get() == this || !can_solo()) {
3567 bool does_feed = (*i)->feeds (shared_this, &sends_only);
3568 if (delta != 0 && does_feed && !sends_only) {
3569 (*i)->solo_control()->mod_solo_by_others_downstream (delta);
3579 Route::sidechain_change_handler (IOChange change, void* src)
3581 if (_initial_io_setup || _in_sidechain_setup) {
3585 input_change_handler (change, src);
3589 Route::pans_required () const
3591 if (n_outputs().n_audio() < 2) {
3595 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
3599 Route::flush_processor_buffers_locked (samplecnt_t nframes)
3601 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3602 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery> (*i);
3604 d->flush_buffers (nframes);
3606 boost::shared_ptr<PortInsert> p = boost::dynamic_pointer_cast<PortInsert> (*i);
3608 p->flush_buffers (nframes);
3615 Route::flush_processors ()
3617 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3619 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3625 Route::playback_latency (bool incl_downstream) const
3629 rv = _disk_reader->output_latency ();
3631 rv = _signal_latency;
3633 if (incl_downstream) {
3634 rv += _output->connected_latency (true);
3636 rv += _output->latency ();
3642 Route::latency_preroll (pframes_t nframes, samplepos_t& start_sample, samplepos_t& end_sample)
3644 samplecnt_t latency_preroll = _session.remaining_latency_preroll ();
3645 if (latency_preroll == 0) {
3648 if (!_disk_reader) {
3649 start_sample -= latency_preroll;
3650 end_sample -= latency_preroll;
3654 if (latency_preroll > playback_latency ()) {
3655 no_roll_unlocked (nframes, start_sample - latency_preroll, end_sample - latency_preroll, false);
3659 start_sample -= latency_preroll;
3660 end_sample -= latency_preroll;
3665 Route::roll (pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, int declick, bool& need_butler)
3667 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3674 silence_unlocked (nframes);
3679 if ((nframes = latency_preroll (nframes, start_sample, end_sample)) == 0) {
3683 run_route (start_sample, end_sample, nframes, declick, (!_disk_writer || !_disk_writer->record_enabled()) && _session.transport_rolling(), true);
3685 if ((_disk_reader && _disk_reader->need_butler()) || (_disk_writer && _disk_writer->need_butler())) {
3692 Route::no_roll (pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, bool session_state_changing)
3694 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3700 return no_roll_unlocked (nframes, start_sample, end_sample, session_state_changing);
3704 Route::no_roll_unlocked (pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, bool session_state_changing)
3706 /* Must be called with the processor lock held */
3709 silence_unlocked (nframes);
3714 if (session_state_changing) {
3715 if (_session.transport_speed() != 0.0f) {
3716 /* we're rolling but some state is changing (e.g. our diskstream contents)
3717 so we cannot use them. Be silent till this is over.
3719 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
3721 silence_unlocked (nframes);
3725 /* we're really not rolling, so we're either delivery silence or actually
3726 monitoring, both of which are safe to do while session_state_changing is true.
3730 run_route (start_sample, end_sample, nframes, 0, false, false);
3735 Route::silent_roll (pframes_t nframes, samplepos_t /*start_sample*/, samplepos_t /*end_sample*/, bool& /* need_butler */)
3738 flush_processor_buffers_locked (nframes);
3743 __attribute__((annotate("realtime")))
3746 Route::apply_processor_changes_rt ()
3748 int emissions = EmitNone;
3750 if (_pending_meter_point != _meter_point) {
3751 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3753 /* meters always have buffers for 'processor_max_streams'
3754 * they can be re-positioned without re-allocation */
3755 if (set_meter_point_unlocked()) {
3756 emissions |= EmitMeterChanged | EmitMeterVisibilityChange;;
3758 emissions |= EmitMeterChanged;
3763 bool changed = false;
3765 if (g_atomic_int_get (&_pending_process_reorder)) {
3766 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3768 apply_processor_order (_pending_processor_order);
3769 setup_invisible_processors ();
3771 g_atomic_int_set (&_pending_process_reorder, 0);
3772 emissions |= EmitRtProcessorChange;
3776 set_processor_positions ();
3777 /* update processor input/output latency
3778 * (total signal_latency does not change)
3780 update_signal_latency (true);
3782 if (emissions != 0) {
3783 g_atomic_int_set (&_pending_signals, emissions);
3786 return (!selfdestruct_sequence.empty ());
3790 Route::emit_pending_signals ()
3792 int sig = g_atomic_int_and (&_pending_signals, 0);
3793 if (sig & EmitMeterChanged) {
3794 _meter->emit_configuration_changed();
3795 meter_change (); /* EMIT SIGNAL */
3796 if (sig & EmitMeterVisibilityChange) {
3797 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3799 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3802 if (sig & EmitRtProcessorChange) {
3803 processors_changed (RouteProcessorChange (RouteProcessorChange::RealTimeChange)); /* EMIT SIGNAL */
3806 /* this would be a job for the butler.
3807 * Conceptually we should not take processe/processor locks here.
3808 * OTOH its more efficient (less overhead for summoning the butler and
3809 * telling her what do do) and signal emission is called
3810 * directly after the process callback, which decreases the chance
3811 * of x-runs when taking the locks.
3813 while (!selfdestruct_sequence.empty ()) {
3814 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
3815 if (selfdestruct_sequence.empty ()) { break; } // re-check with lock
3816 boost::shared_ptr<Processor> proc = selfdestruct_sequence.back ().lock ();
3817 selfdestruct_sequence.pop_back ();
3820 remove_processor (proc);
3826 Route::set_meter_point (MeterPoint p, bool force)
3828 if (_pending_meter_point == p && !force) {
3832 if (force || !AudioEngine::instance()->running()) {
3833 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3834 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3835 _pending_meter_point = p;
3836 _meter->emit_configuration_changed();
3837 meter_change (); /* EMIT SIGNAL */
3838 if (set_meter_point_unlocked()) {
3839 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3841 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3844 _pending_meter_point = p;
3850 __attribute__((annotate("realtime")))
3853 Route::set_meter_point_unlocked ()
3856 /* Caller must hold process and processor write lock */
3857 assert (!AudioEngine::instance()->process_lock().trylock());
3858 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3859 assert (!lm.locked ());
3862 _meter_point = _pending_meter_point;
3864 bool meter_was_visible_to_user = _meter->display_to_user ();
3866 if (!_custom_meter_position_noted) {
3867 maybe_note_meter_position ();
3870 if (_meter_point != MeterCustom) {
3872 _meter->set_display_to_user (false);
3874 setup_invisible_processors ();
3877 _meter->set_display_to_user (true);
3879 /* If we have a previous position for the custom meter, try to put it there */
3880 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
3882 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), after);
3883 if (i != _processors.end ()) {
3884 _processors.remove (_meter);
3885 _processors.insert (i, _meter);
3887 } else {// at end, right before the mains_out/panner
3888 _processors.remove (_meter);
3889 ProcessorList::iterator main = _processors.end();
3890 _processors.insert (--main, _meter);
3894 /* Set up the meter for its new position */
3896 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
3900 if (loc == _processors.begin()) {
3901 m_in = _input->n_ports();
3903 ProcessorList::iterator before = loc;
3905 m_in = (*before)->output_streams ();
3908 _meter->reflect_inputs (m_in);
3910 /* we do not need to reconfigure the processors, because the meter
3911 (a) is always ready to handle processor_max_streams
3912 (b) is always an N-in/N-out processor, and thus moving
3913 it doesn't require any changes to the other processors.
3916 /* these should really be done after releasing the lock
3917 * but all those signals are subscribed to with gui_thread()
3920 return (_meter->display_to_user() != meter_was_visible_to_user);
3924 Route::listen_position_changed ()
3927 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3928 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3929 ProcessorState pstate (this);
3931 if (configure_processors_unlocked (0, &lm)) {
3932 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
3934 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
3939 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3940 _session.set_dirty ();
3943 boost::shared_ptr<CapturingProcessor>
3944 Route::add_export_point()
3946 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3947 if (!_capturing_processor) {
3949 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3950 Glib::Threads::RWLock::WriterLock lw (_processor_lock);
3952 /* Align all tracks for stem-export w/o processing.
3953 * Compensate for all plugins between the this route's disk-reader
3954 * and the common final downstream output (ie alignment point for playback).
3956 _capturing_processor.reset (new CapturingProcessor (_session, playback_latency (true)));
3957 configure_processors_unlocked (0, &lw);
3958 _capturing_processor->activate ();
3961 return _capturing_processor;
3965 Route::update_signal_latency (bool apply_to_delayline)
3967 // TODO: bail out if !active() and set/assume _signal_latency = 0,
3968 // here or in Session::* ? -> also zero send latencies,
3969 // and make sure that re-enabling a route updates things again...
3971 samplecnt_t capt_lat_in = _input->connected_latency (false);
3972 samplecnt_t play_lat_out = _output->connected_latency (true);
3974 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3976 samplecnt_t l_in = 0;
3977 samplecnt_t l_out = _output->user_latency();
3978 for (ProcessorList::reverse_iterator i = _processors.rbegin(); i != _processors.rend(); ++i) {
3979 if (boost::shared_ptr<Send> snd = boost::dynamic_pointer_cast<Send> (*i)) {
3980 snd->set_delay_in (l_out + _output->latency());
3983 if (boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) {
3984 if (boost::shared_ptr<IO> pio = pi->sidechain_input ()) {
3985 samplecnt_t lat = l_out + _output->latency();
3986 pio->set_private_port_latencies (lat, true);
3987 pio->set_public_port_latencies (lat, true);
3990 (*i)->set_output_latency (l_out);
3991 if ((*i)->active ()) {
3992 l_out += (*i)->signal_latency ();
3996 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal signal latency = %2\n", _name, l_out));
3998 _signal_latency = l_out;
4000 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4002 /* set sidechain, send and insert port latencies */
4003 if (boost::shared_ptr<PortInsert> pi = boost::dynamic_pointer_cast<PortInsert> (*i)) {
4005 /* propagate playback latency from output to input */
4006 pi->input ()->set_private_port_latencies (play_lat_out + l_in, true);
4008 if (pi->output ()) {
4009 /* propagate capture latency from input to output */
4010 pi->output ()->set_private_port_latencies (capt_lat_in + l_in, false);
4013 } else if (boost::shared_ptr<Send> snd = boost::dynamic_pointer_cast<Send> (*i)) {
4014 if (snd->output ()) {
4015 /* set capture latency */
4016 snd->output ()->set_private_port_latencies (capt_lat_in + l_in, false);
4017 /* take send-target's playback latency into account */
4018 snd->set_delay_out (snd->output ()->connected_latency (true));
4022 (*i)->set_input_latency (l_in);
4023 (*i)->set_playback_offset (_signal_latency + _output->latency ());
4024 (*i)->set_capture_offset (_input->latency ());
4025 if ((*i)->active ()) {
4026 l_in += (*i)->signal_latency ();
4032 if (apply_to_delayline) {
4033 /* see also Session::post_playback_latency() */
4034 apply_latency_compensation ();
4037 if (_signal_latency != l_out) {
4038 signal_latency_changed (); /* EMIT SIGNAL */
4041 return _signal_latency;
4045 Route::set_user_latency (samplecnt_t nframes)
4047 _output->set_user_latency (nframes);
4048 _session.update_latency_compensation ();
4052 Route::apply_latency_compensation ()
4055 samplecnt_t old = _delayline->delay ();
4057 samplecnt_t play_lat_in = _input->connected_latency (true);
4058 samplecnt_t play_lat_out = _output->connected_latency (true);
4059 samplecnt_t latcomp = play_lat_in - play_lat_out - _signal_latency;
4062 samplecnt_t capt_lat_in = _input->connected_latency (false);
4063 samplecnt_t capt_lat_out = _output->connected_latency (false);
4064 samplecnt_t latcomp_capt = capt_lat_out - capt_lat_in - _signal_latency;
4066 cout << "ROUTE " << name() << " delay for " << latcomp << " (c: " << latcomp_capt << ")" << endl;
4069 _delayline->set_delay (latcomp > 0 ? latcomp : 0);
4071 if (old != _delayline->delay ()) {
4072 signal_latency_updated (); /* EMIT SIGNAL */
4078 Route::set_block_size (pframes_t nframes)
4080 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4081 (*i)->set_block_size (nframes);
4084 _session.ensure_buffers (n_process_buffers ());
4088 Route::protect_automation ()
4090 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
4091 (*i)->protect_automation();
4094 /** @param declick 1 to set a pending declick fade-in,
4095 * -1 to set a pending declick fade-out
4098 Route::set_pending_declick (int declick)
4101 /* this call is not allowed to turn off a pending declick */
4103 _pending_declick = declick;
4106 _pending_declick = 0;
4110 /** Shift automation forwards from a particular place, thereby inserting time.
4111 * Adds undo commands for any shifts that are performed.
4113 * @param pos Position to start shifting from.
4114 * @param samples Amount to shift forwards by.
4118 Route::shift (samplepos_t pos, samplecnt_t samples)
4120 /* gain automation */
4122 boost::shared_ptr<AutomationControl> gc = _amp->gain_control();
4124 XMLNode &before = gc->alist()->get_state ();
4125 gc->alist()->shift (pos, samples);
4126 XMLNode &after = gc->alist()->get_state ();
4127 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
4130 /* gain automation */
4132 boost::shared_ptr<AutomationControl> gc = _trim->gain_control();
4134 XMLNode &before = gc->alist()->get_state ();
4135 gc->alist()->shift (pos, samples);
4136 XMLNode &after = gc->alist()->get_state ();
4137 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
4140 // TODO mute automation ??
4142 /* pan automation */
4144 ControlSet::Controls& c (_pannable->controls());
4146 for (ControlSet::Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
4147 boost::shared_ptr<AutomationControl> pc = boost::dynamic_pointer_cast<AutomationControl> (ci->second);
4149 boost::shared_ptr<AutomationList> al = pc->alist();
4150 XMLNode& before = al->get_state ();
4151 al->shift (pos, samples);
4152 XMLNode& after = al->get_state ();
4153 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4158 /* redirect automation */
4160 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4161 for (ProcessorList::iterator i = _processors.begin (); i != _processors.end (); ++i) {
4163 set<Evoral::Parameter> parameters = (*i)->what_can_be_automated();
4165 for (set<Evoral::Parameter>::const_iterator p = parameters.begin (); p != parameters.end (); ++p) {
4166 boost::shared_ptr<AutomationControl> ac = (*i)->automation_control (*p);
4168 boost::shared_ptr<AutomationList> al = ac->alist();
4169 XMLNode &before = al->get_state ();
4170 al->shift (pos, samples);
4171 XMLNode &after = al->get_state ();
4172 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4180 Route::set_plugin_state_dir (boost::weak_ptr<Processor> p, const std::string& d)
4182 boost::shared_ptr<Processor> processor (p.lock ());
4183 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
4187 pi->set_state_dir (d);
4191 Route::save_as_template (const string& path, const string& name, const string& description)
4193 std::string state_dir = path.substr (0, path.find_last_of ('.')); // strip template_suffix
4194 PBD::Unwinder<std::string> uw (_session._template_state_dir, state_dir);
4196 XMLNode& node (state (false));
4197 node.set_property (X_("name"), name);
4199 node.remove_nodes (X_("description"));
4200 if (!description.empty()) {
4201 XMLNode* desc = new XMLNode(X_("description"));
4202 XMLNode* desc_cont = new XMLNode(X_("content"), description);
4203 desc->add_child_nocopy (*desc_cont);
4205 node.add_child_nocopy (*desc);
4210 IO::set_name_in_state (*node.children().front(), name);
4212 tree.set_root (&node);
4214 /* return zero on success, non-zero otherwise */
4215 return !tree.write (path.c_str());
4220 Route::set_name (const string& str)
4226 if (str == name()) {
4230 string name = Route::ensure_track_or_route_name (str, _session);
4231 SessionObject::set_name (name);
4233 bool ret = (_input->set_name(name) && _output->set_name(name));
4236 /* rename the main outs. Leave other IO processors
4237 * with whatever name they already have, because its
4238 * just fine as it is (it will not contain the route
4239 * name if its a port insert, port send or port return).
4243 if (_main_outs->set_name (name)) {
4244 /* XXX returning false here is stupid because
4245 we already changed the route name.
4255 /** Set the name of a route in an XML description.
4256 * @param node XML <Route> node to set the name in.
4257 * @param name New name.
4260 Route::set_name_in_state (XMLNode& node, string const & name, bool rename_playlist)
4262 node.set_property (X_("name"), name);
4264 XMLNodeList children = node.children();
4265 for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
4267 if ((*i)->name() == X_("IO")) {
4269 IO::set_name_in_state (**i, name);
4271 } else if ((*i)->name() == X_("Processor")) {
4274 if ((*i)->get_property (X_("role"), str) && str == X_("Main")) {
4275 (*i)->set_property (X_("name"), name);
4278 } else if ((*i)->name() == X_("Diskstream")) {
4280 if (rename_playlist) {
4281 (*i)->set_property (X_("playlist"), name + ".1");
4283 (*i)->set_property (X_("name"), name);
4289 boost::shared_ptr<Send>
4290 Route::internal_send_for (boost::shared_ptr<const Route> target) const
4292 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4294 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4295 boost::shared_ptr<InternalSend> send;
4297 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
4298 if (send->target_route() == target) {
4304 return boost::shared_ptr<Send>();
4308 Route::set_denormal_protection (bool yn)
4310 if (_denormal_protection != yn) {
4311 _denormal_protection = yn;
4312 denormal_protection_changed (); /* EMIT SIGNAL */
4317 Route::denormal_protection () const
4319 return _denormal_protection;
4323 Route::set_active (bool yn, void* src)
4325 if (_session.transport_rolling()) {
4329 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_route_active()) {
4330 _route_group->foreach_route (boost::bind (&Route::set_active, _1, yn, _route_group));
4334 if (_active != yn) {
4336 _input->set_active (yn);
4337 _output->set_active (yn);
4338 flush_processors ();
4339 active_changed (); // EMIT SIGNAL
4340 _session.set_dirty ();
4344 boost::shared_ptr<Pannable>
4345 Route::pannable() const
4350 boost::shared_ptr<Panner>
4351 Route::panner() const
4354 return _main_outs->panner_shell()->panner();
4357 boost::shared_ptr<PannerShell>
4358 Route::panner_shell() const
4360 return _main_outs->panner_shell();
4363 boost::shared_ptr<GainControl>
4364 Route::gain_control() const
4366 return _gain_control;
4369 boost::shared_ptr<GainControl>
4370 Route::trim_control() const
4372 return _trim_control;
4375 boost::shared_ptr<PhaseControl>
4376 Route::phase_control() const
4378 return _phase_control;
4381 boost::shared_ptr<AutomationControl>
4382 Route::get_control (const Evoral::Parameter& param)
4384 /* either we own the control or .... */
4386 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
4390 /* maybe one of our processors does or ... */
4392 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
4393 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4394 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
4402 /* nobody does so we'll make a new one */
4404 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
4411 boost::shared_ptr<Processor>
4412 Route::nth_plugin (uint32_t n) const
4414 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4415 ProcessorList::const_iterator i;
4417 for (i = _processors.begin(); i != _processors.end(); ++i) {
4418 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
4425 return boost::shared_ptr<Processor> ();
4428 boost::shared_ptr<Processor>
4429 Route::nth_send (uint32_t n) const
4431 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4432 ProcessorList::const_iterator i;
4434 for (i = _processors.begin(); i != _processors.end(); ++i) {
4435 if (boost::dynamic_pointer_cast<Send> (*i)) {
4437 if ((*i)->name().find (_("Monitor")) == 0) {
4438 /* send to monitor section is not considered
4439 to be an accessible send.
4450 return boost::shared_ptr<Processor> ();
4454 Route::has_io_processor_named (const string& name)
4456 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4457 ProcessorList::iterator i;
4459 for (i = _processors.begin(); i != _processors.end(); ++i) {
4460 if (boost::dynamic_pointer_cast<Send> (*i) ||
4461 boost::dynamic_pointer_cast<PortInsert> (*i)) {
4462 if ((*i)->name() == name) {
4472 Route::set_processor_positions ()
4474 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4476 bool had_amp = false;
4477 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4478 (*i)->set_pre_fader (!had_amp);
4485 /** Called when there is a proposed change to the input port count */
4487 Route::input_port_count_changing (ChanCount to)
4489 list<pair<ChanCount, ChanCount> > c = try_configure_processors (to, 0);
4491 /* The processors cannot be configured with the new input arrangement, so
4497 /* The change is ok */
4501 /** Called when there is a proposed change to the output port count */
4503 Route::output_port_count_changing (ChanCount to)
4505 if (_strict_io && !_in_configure_processors) {
4508 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
4509 if (processor_out_streams.get(*t) > to.get(*t)) {
4513 /* The change is ok */
4518 Route::unknown_processors () const
4522 if (_session.get_disable_all_loaded_plugins ()) {
4523 // Do not list "missing plugins" if they are explicitly disabled
4527 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4528 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4529 if (boost::dynamic_pointer_cast<UnknownProcessor const> (*i)) {
4530 p.push_back ((*i)->name ());
4539 Route::update_port_latencies (PortSet& from, PortSet& to, bool playback, samplecnt_t our_latency) const
4541 /* we assume that all our input ports feed all our output ports. its not
4542 universally true, but the alternative is way too corner-case to worry about.
4545 LatencyRange all_connections;
4548 all_connections.min = 0;
4549 all_connections.max = 0;
4551 all_connections.min = ~((pframes_t) 0);
4552 all_connections.max = 0;
4554 /* iterate over all "from" ports and determine the latency range for all of their
4555 connections to the "outside" (outside of this Route).
4558 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4562 p->get_connected_latency_range (range, playback);
4564 all_connections.min = min (all_connections.min, range.min);
4565 all_connections.max = max (all_connections.max, range.max);
4569 /* set the "from" port latencies to the max/min range of all their connections */
4571 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4572 p->set_private_latency_range (all_connections, playback);
4575 /* set the ports "in the direction of the flow" to the same value as above plus our own signal latency */
4577 all_connections.min += our_latency;
4578 all_connections.max += our_latency;
4580 for (PortSet::iterator p = to.begin(); p != to.end(); ++p) {
4581 p->set_private_latency_range (all_connections, playback);
4584 return all_connections.max;
4588 Route::set_private_port_latencies (bool playback) const
4590 samplecnt_t own_latency = 0;
4592 /* Processor list not protected by lock: MUST BE CALLED FROM PROCESS THREAD
4593 OR LATENCY CALLBACK.
4595 This is called (early) from the latency callback. It computes the REAL
4596 latency associated with each port and stores the result as the "private"
4597 latency of the port. A later call to Route::set_public_port_latencies()
4598 sets all ports to the same value to reflect the fact that we do latency
4599 compensation and so all signals are delayed by the same amount as they
4600 flow through ardour.
4603 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4605 if ((*i)->active ()) {
4606 own_latency += (*i)->signal_latency ();
4611 /* playback: propagate latency from "outside the route" to outputs to inputs */
4612 return update_port_latencies (_output->ports (), _input->ports (), true, own_latency);
4614 /* capture: propagate latency from "outside the route" to inputs to outputs */
4615 return update_port_latencies (_input->ports (), _output->ports (), false, own_latency);
4620 Route::set_public_port_latencies (samplecnt_t value, bool playback) const
4622 /* publish private latencies */
4623 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4624 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4625 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*i);
4629 if (iop->input ()) {
4630 iop->input ()->set_public_port_latencies (iop->input()->latency(), true);
4632 if (iop->output ()) {
4633 iop->output ()->set_public_port_latencies (iop->output()->latency(), false);
4637 /* this is called to set the JACK-visible port latencies, which take
4638 * latency compensation into account.
4640 _input->set_public_port_latencies (value, playback);
4641 _output->set_public_port_latencies (value, playback);
4644 /** Put the invisible processors in the right place in _processors.
4645 * Must be called with a writer lock on _processor_lock held.
4648 __attribute__((annotate("realtime")))
4651 Route::setup_invisible_processors ()
4654 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4655 assert (!lm.locked ());
4659 /* too early to be doing this stuff */
4663 /* we'll build this new list here and then use it
4665 * TODO put the ProcessorList is on the stack for RT-safety.
4668 ProcessorList new_processors;
4669 ProcessorList::iterator dr;
4670 ProcessorList::iterator dw;
4672 /* find visible processors */
4674 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4675 if ((*i)->display_to_user ()) {
4676 new_processors.push_back (*i);
4682 ProcessorList::iterator amp = find (new_processors.begin(), new_processors.end(), _amp);
4684 if (amp == new_processors.end ()) {
4685 error << string_compose (_("Amp/Fader on Route '%1' went AWOL. Re-added."), name()) << endmsg;
4686 new_processors.push_front (_amp);
4687 amp = find (new_processors.begin(), new_processors.end(), _amp);
4690 /* and the processor after the amp */
4692 ProcessorList::iterator after_amp = amp;
4695 /* Pre-fader METER */
4697 if (_meter && _meter_point == MeterPreFader) {
4698 /* add meter just before the fader */
4699 assert (!_meter->display_to_user ());
4700 new_processors.insert (amp, _meter);
4705 assert (_main_outs);
4706 assert (!_main_outs->display_to_user ());
4707 new_processors.push_back (_main_outs);
4709 /* iterator for the main outs */
4711 ProcessorList::iterator main = new_processors.end();
4714 /* OUTPUT METERING */
4716 if (_meter && (_meter_point == MeterOutput || _meter_point == MeterPostFader)) {
4717 assert (!_meter->display_to_user ());
4719 /* add the processor just before or just after the main outs */
4721 ProcessorList::iterator meter_point = main;
4723 if (_meter_point == MeterOutput) {
4726 new_processors.insert (meter_point, _meter);
4731 if (_monitor_send && !is_monitor ()) {
4732 assert (!_monitor_send->display_to_user ());
4733 switch (Config->get_listen_position ()) {
4734 case PreFaderListen:
4735 switch (Config->get_pfl_position ()) {
4736 case PFLFromBeforeProcessors:
4737 new_processors.push_front (_monitor_send);
4739 case PFLFromAfterProcessors:
4740 new_processors.insert (amp, _monitor_send);
4743 _monitor_send->set_can_pan (false);
4745 case AfterFaderListen:
4746 switch (Config->get_afl_position ()) {
4747 case AFLFromBeforeProcessors:
4748 new_processors.insert (after_amp, _monitor_send);
4750 case AFLFromAfterProcessors:
4751 new_processors.insert (new_processors.end(), _monitor_send);
4754 _monitor_send->set_can_pan (true);
4759 /* MONITOR CONTROL */
4761 if (_monitor_control && is_monitor ()) {
4762 assert (!_monitor_control->display_to_user ());
4763 new_processors.insert (amp, _monitor_control);
4768 ProcessorList::iterator trim = new_processors.end();
4770 if (_trim->active()) {
4771 assert (!_trim->display_to_user ());
4772 new_processors.push_front (_trim);
4773 trim = new_processors.begin();
4776 /* INTERNAL RETURN */
4778 /* doing this here means that any monitor control will come after
4779 the return and trim.
4783 assert (!_intreturn->display_to_user ());
4784 new_processors.push_front (_intreturn);
4787 /* DISK READER & WRITER (for Track objects) */
4789 if (_disk_reader || _disk_writer) {
4790 switch (_disk_io_point) {
4791 case DiskIOPreFader:
4792 if (trim != new_processors.end()) {
4793 /* insert BEFORE TRIM */
4795 new_processors.insert (trim, _disk_writer);
4798 new_processors.insert (trim, _disk_reader);
4802 new_processors.push_front (_disk_writer);
4805 new_processors.push_front (_disk_reader);
4809 case DiskIOPostFader:
4810 /* insert BEFORE main outs */
4812 new_processors.insert (main, _disk_writer);
4815 new_processors.insert (main, _disk_reader);
4819 /* reader and writer are visible under this condition, so they
4820 * are not invisible and thus not handled here.
4826 /* ensure dist-writer is before disk-reader */
4827 if (_disk_reader && _disk_writer) {
4828 ProcessorList::iterator reader_pos = find (new_processors.begin(), new_processors.end(), _disk_reader);
4829 ProcessorList::iterator writer_pos = find (new_processors.begin(), new_processors.end(), _disk_writer);
4830 assert (reader_pos != new_processors.end ());
4831 assert (writer_pos != new_processors.end ());
4832 if (std::distance (new_processors.begin(), reader_pos) < std::distance (new_processors.begin(), writer_pos)) {
4833 new_processors.erase (reader_pos);
4834 assert (writer_pos == find (new_processors.begin(), new_processors.end(), _disk_writer));
4835 new_processors.insert (++writer_pos, _disk_reader);
4839 /* EXPORT PROCESSOR */
4840 if (_capturing_processor) {
4841 assert (!_capturing_processor->display_to_user ());
4842 ProcessorList::iterator reader_pos = find (new_processors.begin(), new_processors.end(), _disk_reader);
4843 if (reader_pos != new_processors.end()) {
4844 /* insert after disk-reader */
4845 new_processors.insert (++reader_pos, _capturing_processor);
4847 ProcessorList::iterator return_pos = find (new_processors.begin(), new_processors.end(), _intreturn);
4848 /* insert after return */
4849 if (return_pos != new_processors.end()) {
4850 new_processors.insert (++return_pos, _capturing_processor);
4852 new_processors.push_front (_capturing_processor);
4857 /* Polarity Invert */
4859 ProcessorList::iterator reader_pos = find (new_processors.begin(), new_processors.end(), _disk_reader);
4860 if (reader_pos != new_processors.end()) {
4861 /* insert after disk-reader */
4862 new_processors.insert (++reader_pos, _polarity);
4864 ProcessorList::iterator return_pos = find (new_processors.begin(), new_processors.end(), _intreturn);
4865 /* insert after return */
4866 if (return_pos != new_processors.end()) {
4867 new_processors.insert (++return_pos, _polarity);
4869 new_processors.push_front (_polarity);
4875 if (_meter && _meter_point == MeterInput) {
4876 /* add meter just before the disk-writer (if any)
4877 * otherwise at the top, but after the latency delayline
4878 * (perhaps it should also be after intreturn on busses ??)
4880 assert (!_meter->display_to_user ());
4881 ProcessorList::iterator writer_pos = find (new_processors.begin(), new_processors.end(), _disk_writer);
4882 if (writer_pos != new_processors.end()) {
4883 /* insert before disk-writer */
4884 new_processors.insert (writer_pos, _meter);
4886 ProcessorList::iterator return_pos = find (new_processors.begin(), new_processors.end(), _intreturn);
4887 /* insert after return */
4888 if (return_pos != new_processors.end()) {
4889 new_processors.insert (++return_pos, _meter);
4891 new_processors.push_front (_meter);
4896 if (!is_master() && !is_monitor() && !is_auditioner()) {
4897 ProcessorList::iterator reader_pos = find (new_processors.begin(), new_processors.end(), _disk_reader);
4898 if (reader_pos != new_processors.end()) {
4899 /* insert before disk-reader */
4900 new_processors.insert (reader_pos, _delayline);
4902 new_processors.push_front (_delayline);
4906 _processors = new_processors;
4908 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4909 if (!(*i)->display_to_user () && !(*i)->enabled () && (*i) != _monitor_send) {
4910 (*i)->enable (true);
4914 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: setup_invisible_processors\n", _name));
4915 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4916 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1\n", (*i)->name ()));
4923 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
4924 Glib::Threads::RWLock::ReaderLock lp (_processor_lock);
4928 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4929 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*i);
4936 /** If the meter point is `Custom', make a note of where the meter is.
4937 * This is so that if the meter point is subsequently set to something else,
4938 * and then back to custom, we can put the meter back where it was last time
4939 * custom was enabled.
4941 * Must be called with the _processor_lock held.
4944 Route::maybe_note_meter_position ()
4946 if (_meter_point != MeterCustom) {
4950 _custom_meter_position_noted = true;
4951 /* custom meter points range from after trim to before panner/main_outs
4952 * this is a limitation by the current processor UI
4954 bool seen_trim = false;
4955 _processor_after_last_custom_meter.reset();
4956 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4957 if ((*i) == _trim) {
4960 if ((*i) == _main_outs) {
4961 _processor_after_last_custom_meter = *i;
4964 if (boost::dynamic_pointer_cast<PeakMeter> (*i)) {
4966 _processor_after_last_custom_meter = _trim;
4968 ProcessorList::iterator j = i;
4970 assert(j != _processors.end ()); // main_outs should be before
4971 _processor_after_last_custom_meter = *j;
4976 assert(_processor_after_last_custom_meter.lock());
4979 boost::shared_ptr<Processor>
4980 Route::processor_by_id (PBD::ID id) const
4982 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4983 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4984 if ((*i)->id() == id) {
4989 return boost::shared_ptr<Processor> ();
4992 /** @return what we should be metering; either the data coming from the input
4993 * IO or the data that is flowing through the route.
4996 Route::metering_state () const
4998 return MeteringRoute;
5002 Route::has_external_redirects () const
5004 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5006 /* ignore inactive processors and obviously ignore the main
5007 * outs since everything has them and we don't care.
5010 if ((*i)->active() && (*i) != _main_outs && (*i)->does_routing()) {
5018 boost::shared_ptr<Processor>
5019 Route::the_instrument () const
5021 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5022 return the_instrument_unlocked ();
5025 boost::shared_ptr<Processor>
5026 Route::the_instrument_unlocked () const
5028 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5029 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
5030 if (pi && pi->plugin ()->get_info ()->is_instrument ()) {
5034 return boost::shared_ptr<Processor>();
5040 Route::non_realtime_locate (samplepos_t pos)
5042 Automatable::non_realtime_locate (pos);
5045 _pannable->non_realtime_locate (pos);
5048 #if 0 // XXX mayhaps clear delayline here (and at stop?)
5050 _delayline->flush ();
5055 //Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
5056 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5058 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5059 (*i)->non_realtime_locate (pos);
5065 Route::fill_buffers_with_input (BufferSet& bufs, boost::shared_ptr<IO> io, pframes_t nframes)
5072 * We don't currently mix MIDI input together, so we don't need the
5073 * complex logic of the audio case.
5076 n_buffers = bufs.count().n_midi ();
5078 for (i = 0; i < n_buffers; ++i) {
5080 boost::shared_ptr<MidiPort> source_port = io->midi (i);
5081 MidiBuffer& buf (bufs.get_midi (i));
5084 buf.copy (source_port->get_midi_buffer(nframes));
5086 buf.silence (nframes);
5092 n_buffers = bufs.count().n_audio();
5094 size_t n_ports = io->n_ports().n_audio();
5095 float scaling = 1.0f;
5097 if (n_ports > n_buffers) {
5098 scaling = ((float) n_buffers) / n_ports;
5101 for (i = 0; i < n_ports; ++i) {
5103 /* if there are more ports than buffers, map them onto buffers
5104 * in a round-robin fashion
5107 boost::shared_ptr<AudioPort> source_port = io->audio (i);
5108 AudioBuffer& buf (bufs.get_audio (i%n_buffers));
5110 if (i < n_buffers) {
5112 /* first time through just copy a channel into
5116 buf.read_from (source_port->get_audio_buffer (nframes), nframes);
5118 if (scaling != 1.0f) {
5119 buf.apply_gain (scaling, nframes);
5124 /* on subsequent times around, merge data from
5125 * the port with what is already there
5128 if (scaling != 1.0f) {
5129 buf.accumulate_with_gain_from (source_port->get_audio_buffer (nframes), nframes, 0, scaling);
5131 buf.accumulate_from (source_port->get_audio_buffer (nframes), nframes);
5136 /* silence any remaining buffers */
5138 for (; i < n_buffers; ++i) {
5139 AudioBuffer& buf (bufs.get_audio (i));
5140 buf.silence (nframes);
5143 /* establish the initial setup of the buffer set, reflecting what was
5144 copied into it. unless, of course, we are the auditioner, in which
5145 case nothing was fed into it from the inputs at all.
5148 if (!is_auditioner()) {
5149 bufs.set_count (io->n_ports());
5153 boost::shared_ptr<AutomationControl>
5154 Route::pan_azimuth_control() const
5157 # undef MIXBUS_PORTS_H
5158 # include "../../gtk2_ardour/mixbus_ports.h"
5159 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5161 return boost::shared_ptr<AutomationControl>();
5163 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_pan)));
5165 if (!_pannable || !panner()) {
5166 return boost::shared_ptr<AutomationControl>();
5168 return _pannable->pan_azimuth_control;
5172 boost::shared_ptr<AutomationControl>
5173 Route::pan_elevation_control() const
5175 if (Profile->get_mixbus() || !_pannable || !panner()) {
5176 return boost::shared_ptr<AutomationControl>();
5179 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5181 if (c.find (PanElevationAutomation) != c.end()) {
5182 return _pannable->pan_elevation_control;
5184 return boost::shared_ptr<AutomationControl>();
5187 boost::shared_ptr<AutomationControl>
5188 Route::pan_width_control() const
5191 if (mixbus() && _ch_pre) {
5193 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl>(_ch_pre->control(Evoral::Parameter(PluginAutomation, 0, 5)));
5196 if (Profile->get_mixbus() || !_pannable || !panner()) {
5197 return boost::shared_ptr<AutomationControl>();
5200 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5202 if (c.find (PanWidthAutomation) != c.end()) {
5203 return _pannable->pan_width_control;
5205 return boost::shared_ptr<AutomationControl>();
5208 boost::shared_ptr<AutomationControl>
5209 Route::pan_frontback_control() const
5211 if (Profile->get_mixbus() || !_pannable || !panner()) {
5212 return boost::shared_ptr<AutomationControl>();
5215 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5217 if (c.find (PanFrontBackAutomation) != c.end()) {
5218 return _pannable->pan_frontback_control;
5220 return boost::shared_ptr<AutomationControl>();
5223 boost::shared_ptr<AutomationControl>
5224 Route::pan_lfe_control() const
5226 if (Profile->get_mixbus() || !_pannable || !panner()) {
5227 return boost::shared_ptr<AutomationControl>();
5230 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5232 if (c.find (PanLFEAutomation) != c.end()) {
5233 return _pannable->pan_lfe_control;
5235 return boost::shared_ptr<AutomationControl>();
5240 Route::eq_band_cnt () const
5242 if (Profile->get_mixbus()) {
5244 if (is_master() || mixbus()) {
5253 /* Ardour has no well-known EQ object */
5258 boost::shared_ptr<AutomationControl>
5259 Route::eq_gain_controllable (uint32_t band) const
5262 boost::shared_ptr<PluginInsert> eq = ch_eq();
5265 return boost::shared_ptr<AutomationControl>();
5268 uint32_t port_number;
5269 if (is_master() || mixbus()) {
5271 case 0: port_number = 4; break;
5272 case 1: port_number = 3; break;
5273 case 2: port_number = 2; break;
5275 return boost::shared_ptr<AutomationControl>();
5280 case 0: port_number = 14; break;
5281 case 1: port_number = 12; break;
5282 case 2: port_number = 10; break;
5283 case 3: port_number = 8; break;
5285 return boost::shared_ptr<AutomationControl>();
5289 case 0: port_number = 8; break;
5290 case 1: port_number = 6; break;
5291 case 2: port_number = 4; break;
5293 return boost::shared_ptr<AutomationControl>();
5298 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5300 return boost::shared_ptr<AutomationControl>();
5303 boost::shared_ptr<AutomationControl>
5304 Route::eq_freq_controllable (uint32_t band) const
5307 if (mixbus() || is_master()) {
5308 /* no frequency controls for mixbusses or master */
5309 return boost::shared_ptr<AutomationControl>();
5312 boost::shared_ptr<PluginInsert> eq = ch_eq();
5315 return boost::shared_ptr<AutomationControl>();
5318 uint32_t port_number;
5321 case 0: port_number = 13; break; // lo
5322 case 1: port_number = 11; break; // lo mid
5323 case 2: port_number = 9; break; // hi mid
5324 case 3: port_number = 7; break; // hi
5326 return boost::shared_ptr<AutomationControl>();
5330 case 0: port_number = 7; break;
5331 case 1: port_number = 5; break;
5332 case 2: port_number = 3; break;
5334 return boost::shared_ptr<AutomationControl>();
5338 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5340 return boost::shared_ptr<AutomationControl>();
5344 boost::shared_ptr<AutomationControl>
5345 Route::eq_q_controllable (uint32_t band) const
5347 return boost::shared_ptr<AutomationControl>();
5350 boost::shared_ptr<AutomationControl>
5351 Route::eq_shape_controllable (uint32_t band) const
5354 boost::shared_ptr<PluginInsert> eq = ch_eq();
5355 if (is_master() || mixbus() || !eq) {
5356 return boost::shared_ptr<AutomationControl>();
5360 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4))); // lo bell
5363 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3))); // hi bell
5369 return boost::shared_ptr<AutomationControl>();
5372 boost::shared_ptr<AutomationControl>
5373 Route::eq_enable_controllable () const
5376 boost::shared_ptr<PluginInsert> eq = ch_eq();
5379 return boost::shared_ptr<AutomationControl>();
5382 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5384 return boost::shared_ptr<AutomationControl>();
5388 boost::shared_ptr<AutomationControl>
5389 Route::filter_freq_controllable (bool hpf) const
5392 boost::shared_ptr<PluginInsert> eq = ch_eq();
5394 if (is_master() || mixbus() || !eq) {
5395 return boost::shared_ptr<AutomationControl>();
5399 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5))); // HPF freq
5401 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5405 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 6))); // LPF freq
5407 return boost::shared_ptr<AutomationControl>();
5412 return boost::shared_ptr<AutomationControl>();
5416 boost::shared_ptr<AutomationControl>
5417 Route::filter_slope_controllable (bool) const
5419 return boost::shared_ptr<AutomationControl>();
5422 boost::shared_ptr<AutomationControl>
5423 Route::filter_enable_controllable (bool) const
5426 boost::shared_ptr<PluginInsert> eq = ch_eq();
5428 if (is_master() || mixbus() || !eq) {
5429 return boost::shared_ptr<AutomationControl>();
5432 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5434 return boost::shared_ptr<AutomationControl>();
5438 boost::shared_ptr<AutomationControl>
5439 Route::tape_drive_controllable () const
5443 if ( _ch_pre && (is_master() || mixbus()) ) {
5444 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (_ch_pre->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4)));
5448 return boost::shared_ptr<AutomationControl>();
5452 Route::eq_band_name (uint32_t band) const
5455 if (is_master() || mixbus()) {
5457 if (Profile->get_mixbus()) {
5459 case 0: return _("lo");
5460 case 1: return _("mid");
5461 case 2: return _("hi");
5462 default: return string();
5470 case 0: return _("lo");
5471 case 1: return _("lo mid");
5472 case 2: return _("hi mid");
5473 case 3: return _("hi");
5474 default: return string();
5480 boost::shared_ptr<AutomationControl>
5481 Route::comp_enable_controllable () const
5484 boost::shared_ptr<PluginInsert> comp = ch_comp();
5487 return boost::shared_ptr<AutomationControl>();
5490 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5492 return boost::shared_ptr<AutomationControl>();
5495 boost::shared_ptr<AutomationControl>
5496 Route::comp_threshold_controllable () const
5499 boost::shared_ptr<PluginInsert> comp = ch_comp();
5502 return boost::shared_ptr<AutomationControl>();
5505 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5508 return boost::shared_ptr<AutomationControl>();
5511 boost::shared_ptr<AutomationControl>
5512 Route::comp_speed_controllable () const
5515 boost::shared_ptr<PluginInsert> comp = ch_comp();
5518 return boost::shared_ptr<AutomationControl>();
5521 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3)));
5523 return boost::shared_ptr<AutomationControl>();
5526 boost::shared_ptr<AutomationControl>
5527 Route::comp_mode_controllable () const
5530 boost::shared_ptr<PluginInsert> comp = ch_comp();
5533 return boost::shared_ptr<AutomationControl>();
5536 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4)));
5538 return boost::shared_ptr<AutomationControl>();
5541 boost::shared_ptr<AutomationControl>
5542 Route::comp_makeup_controllable () const
5545 boost::shared_ptr<PluginInsert> comp = ch_comp();
5548 return boost::shared_ptr<AutomationControl>();
5551 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5)));
5553 return boost::shared_ptr<AutomationControl>();
5556 boost::shared_ptr<ReadOnlyControl>
5557 Route::comp_redux_controllable () const
5560 boost::shared_ptr<PluginInsert> comp = ch_comp();
5563 return boost::shared_ptr<ReadOnlyControl>();
5566 return comp->control_output (2);
5568 return comp->control_output (6);
5572 return boost::shared_ptr<ReadOnlyControl>();
5577 Route::comp_mode_name (uint32_t mode) const
5582 return _("Leveler");
5584 return _("Compressor");
5586 return _("Limiter");
5588 return mixbus() ? _("Sidechain") : _("Limiter");
5598 Route::comp_speed_name (uint32_t mode) const
5616 boost::shared_ptr<AutomationControl>
5617 Route::send_pan_azi_controllable (uint32_t n) const
5620 # undef MIXBUS_PORTS_H
5621 # include "../../gtk2_ardour/mixbus_ports.h"
5622 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5623 if (plug && !mixbus()) {
5624 uint32_t port_id = 0;
5627 case 0: port_id = port_channel_post_aux0_pan; break; //32c mb "pan" controls use zero-based names, unlike levels. ugh
5628 case 1: port_id = port_channel_post_aux1_pan; break;
5629 case 2: port_id = port_channel_post_aux2_pan; break;
5630 case 3: port_id = port_channel_post_aux3_pan; break;
5631 case 4: port_id = port_channel_post_aux4_pan; break;
5632 case 5: port_id = port_channel_post_aux5_pan; break;
5633 case 6: port_id = port_channel_post_aux6_pan; break;
5634 case 7: port_id = port_channel_post_aux7_pan; break;
5635 case 8: port_id = port_channel_post_aux8_pan; break;
5636 case 9: port_id = port_channel_post_aux9_pan; break;
5637 case 10: port_id = port_channel_post_aux10_pan; break;
5638 case 11: port_id = port_channel_post_aux11_pan; break;
5645 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5650 return boost::shared_ptr<AutomationControl>();
5653 boost::shared_ptr<AutomationControl>
5654 Route::send_level_controllable (uint32_t n) const
5657 # undef MIXBUS_PORTS_H
5658 # include "../../gtk2_ardour/mixbus_ports.h"
5659 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5660 if (plug && !mixbus()) {
5661 uint32_t port_id = 0;
5663 case 0: port_id = port_channel_post_aux1_level; break;
5664 case 1: port_id = port_channel_post_aux2_level; break;
5665 case 2: port_id = port_channel_post_aux3_level; break;
5666 case 3: port_id = port_channel_post_aux4_level; break;
5667 case 4: port_id = port_channel_post_aux5_level; break;
5668 case 5: port_id = port_channel_post_aux6_level; break;
5669 case 6: port_id = port_channel_post_aux7_level; break;
5670 case 7: port_id = port_channel_post_aux8_level; break;
5672 case 8: port_id = port_channel_post_aux9_level; break;
5673 case 9: port_id = port_channel_post_aux10_level; break;
5674 case 10: port_id = port_channel_post_aux11_level; break;
5675 case 11: port_id = port_channel_post_aux12_level; break;
5682 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5693 boost::shared_ptr<Send> s = boost::dynamic_pointer_cast<Send>(nth_send (n));
5695 return boost::shared_ptr<AutomationControl>();
5697 return s->gain_control ();
5700 boost::shared_ptr<AutomationControl>
5701 Route::send_enable_controllable (uint32_t n) const
5704 # undef MIXBUS_PORTS_H
5705 # include "../../gtk2_ardour/mixbus_ports.h"
5706 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5707 if (plug && !mixbus()) {
5708 uint32_t port_id = 0;
5710 case 0: port_id = port_channel_post_aux1_asgn; break;
5711 case 1: port_id = port_channel_post_aux2_asgn; break;
5712 case 2: port_id = port_channel_post_aux3_asgn; break;
5713 case 3: port_id = port_channel_post_aux4_asgn; break;
5714 case 4: port_id = port_channel_post_aux5_asgn; break;
5715 case 5: port_id = port_channel_post_aux6_asgn; break;
5716 case 6: port_id = port_channel_post_aux7_asgn; break;
5717 case 7: port_id = port_channel_post_aux8_asgn; break;
5719 case 8: port_id = port_channel_post_aux9_asgn; break;
5720 case 9: port_id = port_channel_post_aux10_asgn; break;
5721 case 10: port_id = port_channel_post_aux11_asgn; break;
5722 case 11: port_id = port_channel_post_aux12_asgn; break;
5729 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5740 /* although Ardour sends have enable/disable as part of the Processor
5741 * API, it is not exposed as a controllable.
5743 * XXX: we should fix this (make it click-free, automatable enable-control)
5745 return boost::shared_ptr<AutomationControl>();
5749 Route::send_name (uint32_t n) const
5752 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5753 if (plug && !mixbus()) {
5756 return _session.get_mixbus (n)->name();
5761 return _session.get_mixbus (n)->name();
5767 boost::shared_ptr<Processor> p = nth_send (n);
5775 boost::shared_ptr<AutomationControl>
5776 Route::master_send_enable_controllable () const
5779 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5781 return boost::shared_ptr<AutomationControl>();
5783 # undef MIXBUS_PORTS_H
5784 # include "../../gtk2_ardour/mixbus_ports.h"
5785 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_mstr_assign)));
5787 return boost::shared_ptr<AutomationControl>();
5792 Route::slaved () const
5794 if (!_gain_control) {
5797 /* just test one particular control, not all of them */
5798 return _gain_control->slaved ();
5802 Route::slaved_to (boost::shared_ptr<VCA> vca) const
5804 if (!vca || !_gain_control) {
5808 /* just test one particular control, not all of them */
5810 return _gain_control->slaved_to (vca->gain_control());
5814 Route::muted_by_others_soloing () const
5816 if (!can_be_muted_by_others ()) {
5820 return _session.soloing() && !_solo_control->soloed() && !_solo_isolate_control->solo_isolated();
5824 Route::clear_all_solo_state ()
5826 _solo_control->clear_all_solo_state ();
5829 boost::shared_ptr<AutomationControl>
5830 Route::automation_control_recurse (PBD::ID const & id) const
5832 boost::shared_ptr<AutomationControl> ac = Automatable::automation_control (id);
5838 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5840 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5841 if ((ac = (*i)->automation_control (id))) {
5846 return boost::shared_ptr<AutomationControl> ();
5850 Route::slavables () const
5852 SlavableControlList rv;
5853 rv.push_back (_gain_control);
5854 rv.push_back (_mute_control);
5855 rv.push_back (_solo_control);
5860 Route::set_disk_io_point (DiskIOPoint diop)
5862 bool display = false;
5864 cerr << "set disk io to " << enum_2_string (diop) << endl;
5875 _disk_writer->set_display_to_user (display);
5879 _disk_reader->set_display_to_user (display);
5882 const bool changed = (diop != _disk_io_point);
5884 _disk_io_point = diop;
5887 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
5888 configure_processors (0);
5891 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
5895 Route::set_loop (Location* l)
5898 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5899 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5904 #ifdef USE_TRACKS_CODE_FEATURES
5906 /* This is the Tracks version of Track::monitoring_state().
5908 * Ardour developers: try to flag or fix issues if parts of the libardour API
5909 * change in ways that invalidate this
5913 Route::monitoring_state () const
5915 /* Explicit requests */
5917 if (_monitoring != MonitorInput) {
5918 return MonitoringInput;
5921 if (_monitoring & MonitorDisk) {
5922 return MonitoringDisk;
5925 /* This is an implementation of the truth table in doc/monitor_modes.pdf;
5926 I don't think it's ever going to be too pretty too look at.
5929 // GZ: NOT USED IN TRACKS
5930 //bool const auto_input = _session.config.get_auto_input ();
5931 //bool const software_monitor = Config->get_monitoring_model() == SoftwareMonitoring;
5932 //bool const tape_machine_mode = Config->get_tape_machine_mode ();
5934 bool const roll = _session.transport_rolling ();
5935 bool const track_rec = _diskstream->record_enabled ();
5936 bool session_rec = _session.actively_recording ();
5940 if (!session_rec && roll) {
5941 return MonitoringDisk;
5943 return MonitoringInput;
5949 return MonitoringDisk;
5953 return MonitoringSilence;
5958 /* This is the Ardour/Mixbus version of Track::monitoring_state().
5960 * Tracks developers: do NOT modify this method under any circumstances.
5964 Route::monitoring_state () const
5966 if (!_disk_reader) {
5967 return MonitoringInput;
5970 /* Explicit requests */
5971 MonitorChoice m (_monitoring_control->monitoring_choice());
5973 if (m != MonitorAuto) {
5975 MonitorState ms ((MonitorState) 0);
5977 if (m & MonitorInput) {
5978 ms = MonitoringInput;
5981 if (m & MonitorDisk) {
5982 ms = MonitorState (ms | MonitoringDisk);
5988 switch (_session.config.get_session_monitoring ()) {
5990 return MonitoringDisk;
5993 return MonitoringInput;
5999 /* This is an implementation of the truth table in doc/monitor_modes.pdf;
6000 I don't think it's ever going to be too pretty too look at.
6003 bool const roll = _session.transport_rolling ();
6004 bool const track_rec = _disk_writer->record_enabled ();
6005 bool const auto_input = _session.config.get_auto_input ();
6006 bool const software_monitor = Config->get_monitoring_model() == SoftwareMonitoring;
6007 bool const tape_machine_mode = Config->get_tape_machine_mode ();
6010 /* I suspect that just use actively_recording() is good enough all the
6011 * time, but just to keep the semantics the same as they were before
6012 * sept 26th 2012, we differentiate between the cases where punch is
6013 * enabled and those where it is not.
6015 * rg: sept 30 2017: Above is not the case: punch-in/out location is
6016 * global session playhead position.
6017 * When this method is called from process_output_buffers() we need
6018 * to use delay-compensated route's process-position.
6020 * NB. Disk reader/writer may also be offset by a same amount of time.
6022 * Also keep in mind that _session.transport_rolling() is false during
6023 * pre-roll but the disk already produces output.
6028 if (_session.config.get_punch_in() || _session.config.get_punch_out()) {
6029 session_rec = _session.actively_recording ();
6031 session_rec = _session.get_record_enabled();
6036 if (!session_rec && roll && auto_input) {
6037 return MonitoringDisk;
6039 return software_monitor ? MonitoringInput : MonitoringSilence;
6044 if (tape_machine_mode) {
6046 return MonitoringDisk;
6050 if (!roll && auto_input) {
6051 return software_monitor ? MonitoringInput : MonitoringSilence;
6053 return MonitoringDisk;
6059 abort(); /* NOTREACHED */
6060 return MonitoringSilence;