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 if (boost::dynamic_pointer_cast<PluginInsert>(*i) != 0) {
478 /* set potential sidechain ports, capture and playback latency.
479 * This effectively sets jack port latency which should include
480 * up/downstream latencies.
482 * However, the value is not used by Ardour (2017-09-20) and calling
483 * IO::latency() is expensive, so we punt.
486 * input()->latenct + latency,
488 * output->latency() + _signal_latency - latency
490 * Also see note below, _signal_latency may be smaller than latency
491 * if a plugin's latency increases while it's running.
493 const samplecnt_t playback_latency = std::max ((samplecnt_t)0, _signal_latency - latency);
494 boost::dynamic_pointer_cast<PluginInsert>(*i)->set_sidechain_latency (
495 /* input->latency() + */ latency, /* output->latency() + */ playback_latency);
498 bool re_inject_oob_data = false;
499 if ((*i) == _disk_reader) {
500 /* Well now, we've made it past the disk-writer and to the disk-reader.
501 * Time to decide what to do about monitoring.
503 * Even when not doing MonitoringDisk, we need to run the processors,
504 * so that it advances its internal buffers (IFF run_disk_reader is true).
507 if (ms == MonitoringDisk || ms == MonitoringSilence) {
508 /* this will clear out-of-band data, too (e.g. MIDI-PC, Panic etc.
509 * OOB data is written at the end of the cycle (nframes - 1),
510 * and jack does not re-order events, so we push them back later */
511 re_inject_oob_data = true;
512 bufs.silence (nframes, 0);
516 double pspeed = speed;
517 if ((!run_disk_reader && (*i) == _disk_reader) || (!run_disk_writer && (*i) == _disk_writer)) {
518 /* run with speed 0, no-roll */
523 (*i)->run (bufs, start_sample + latency, end_sample + latency, pspeed, nframes, *i != _processors.back());
525 (*i)->run (bufs, start_sample - latency, end_sample - latency, pspeed, nframes, *i != _processors.back());
528 bufs.set_count ((*i)->output_streams());
530 /* Note: plugin latency may change. While the plugin does inform the session via
531 * processor_latency_changed(). But the session may not yet have gotten around to
532 * update the actual worste-case and update this track's _signal_latency.
534 * So there can be cases where adding up all latencies may not equal _signal_latency.
536 if ((*i)->active ()) {
537 latency += (*i)->signal_latency ();
540 if (re_inject_oob_data) {
541 write_out_of_band_data (bufs, nframes);
545 if ((*i) == _delayline) {
546 latency += _delayline->get_delay ();
553 Route::bounce_process (BufferSet& buffers, samplepos_t start, samplecnt_t nframes,
554 boost::shared_ptr<Processor> endpoint,
555 bool include_endpoint, bool for_export, bool for_freeze)
557 /* If no processing is required, there's no need to go any further. */
558 if (!endpoint && !include_endpoint) {
562 samplecnt_t latency = bounce_get_latency(_amp, false, for_export, for_freeze);
563 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
564 _amp->setup_gain_automation (start - latency, start - latency + nframes, nframes);
566 /* trim is always at the top, for bounce no latency compensation is needed */
567 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
568 _trim->setup_gain_automation (start, start + nframes, nframes);
571 const double speed = _session.transport_speed ();
572 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
574 if (!include_endpoint && (*i) == endpoint) {
578 /* if we're *not* exporting, stop processing if we come across a routing processor. */
579 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
582 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
586 /* special case the panner (export outputs)
587 * Ideally we'd only run the panner, not the delivery itself...
588 * but panners need separate input/output buffers and some context
589 * (panshell, panner type, etc). AFAICT there is no ill side effect
590 * of re-using the main delivery when freewheeling/exporting a region.
592 if ((*i) == _main_outs) {
593 assert ((*i)->does_routing());
594 (*i)->run (buffers, start - latency, start - latency + nframes, speed, nframes, true);
595 buffers.set_count ((*i)->output_streams());
598 /* don't run any processors that do routing.
599 * Also don't bother with metering.
601 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
602 (*i)->run (buffers, start - latency, start - latency + nframes, 1.0, nframes, true);
603 buffers.set_count ((*i)->output_streams());
604 latency += (*i)->signal_latency ();
607 if ((*i) == endpoint) {
614 Route::bounce_get_latency (boost::shared_ptr<Processor> endpoint,
615 bool include_endpoint, bool for_export, bool for_freeze) const
617 samplecnt_t latency = 0;
618 if (!endpoint && !include_endpoint) {
622 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
623 if (!include_endpoint && (*i) == endpoint) {
626 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
629 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
632 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
633 latency += (*i)->signal_latency ();
635 if ((*i) == endpoint) {
643 Route::bounce_get_output_streams (ChanCount &cc, boost::shared_ptr<Processor> endpoint,
644 bool include_endpoint, bool for_export, bool for_freeze) const
646 if (!endpoint && !include_endpoint) {
650 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
651 if (!include_endpoint && (*i) == endpoint) {
654 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
657 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
660 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
661 cc = (*i)->output_streams();
663 if ((*i) == endpoint) {
671 Route::n_process_buffers ()
673 return max (_input->n_ports(), processor_max_streams);
677 Route::monitor_run (samplepos_t start_sample, samplepos_t end_sample, pframes_t nframes, int declick)
679 assert (is_monitor());
680 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
681 run_route (start_sample, end_sample, nframes, declick, true, false);
685 Route::run_route (samplepos_t start_sample, samplepos_t end_sample, pframes_t nframes, int declick, bool gain_automation_ok, bool run_disk_reader)
687 BufferSet& bufs (_session.get_route_buffers (n_process_buffers()));
689 fill_buffers_with_input (bufs, _input, nframes);
691 /* filter captured data before meter sees it */
694 if (is_monitor() && _session.listening() && !_session.is_auditioning()) {
696 /* control/monitor bus ignores input ports when something is
697 feeding the listen "stream". data will "arrive" into the
698 route from the intreturn processor element.
701 bufs.silence (nframes, 0);
704 snapshot_out_of_band_data (nframes);
705 /* append immediate messages to the first MIDI buffer (thus sending it to the first output port) */
707 write_out_of_band_data (bufs, nframes);
709 /* run processor chain */
711 process_output_buffers (bufs, start_sample, end_sample, nframes, declick, gain_automation_ok, run_disk_reader);
713 /* map events (e.g. MIDI-CC) back to control-parameters */
714 update_controls (bufs);
716 flush_processor_buffers_locked (nframes);
720 Route::set_listen (bool yn)
723 if (_monitor_send->active() == yn) {
727 _monitor_send->activate ();
729 _monitor_send->deactivate ();
735 Route::solo_control_changed (bool, Controllable::GroupControlDisposition)
737 /* nothing to do if we're not using AFL/PFL. But if we are, we need
738 to alter the active state of the monitor send.
741 if (Config->get_solo_control_is_listen_control ()) {
742 set_listen (_solo_control->self_soloed() || _solo_control->get_masters_value());
747 Route::push_solo_isolate_upstream (int32_t delta)
749 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
751 boost::shared_ptr<RouteList> routes = _session.get_routes ();
752 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
754 if ((*i).get() == this || !(*i)->can_solo()) {
759 bool does_feed = feeds (*i, &sends_only);
761 if (does_feed && !sends_only) {
762 (*i)->solo_isolate_control()->mod_solo_isolated_by_upstream (delta);
768 Route::push_solo_upstream (int delta)
770 DEBUG_TRACE (DEBUG::Solo, string_compose("\t ... INVERT push from %1\n", _name));
771 for (FedBy::iterator i = _fed_by.begin(); i != _fed_by.end(); ++i) {
775 boost::shared_ptr<Route> sr (i->r.lock());
777 sr->solo_control()->mod_solo_by_others_downstream (-delta);
784 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
786 cerr << name << " {" << endl;
787 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
788 p != procs.end(); ++p) {
789 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << " @ " << (*p) << endl;
795 /** Supposing that we want to insert a Processor at a given Placement, 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_placement (Placement p)
801 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
803 ProcessorList::iterator loc;
806 /* generic pre-fader: insert immediately before the amp */
807 loc = find (_processors.begin(), _processors.end(), _amp);
809 /* generic post-fader: insert right before the main outs */
810 loc = find (_processors.begin(), _processors.end(), _main_outs);
813 return loc != _processors.end() ? *loc : boost::shared_ptr<Processor> ();
816 /** Supposing that we want to insert a Processor at a given index, return
817 * the processor to add the new one before (or 0 to add at the end).
819 boost::shared_ptr<Processor>
820 Route::before_processor_for_index (int index)
823 return boost::shared_ptr<Processor> ();
826 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
828 ProcessorList::iterator i = _processors.begin ();
830 while (i != _processors.end() && j < index) {
831 if ((*i)->display_to_user()) {
838 return (i != _processors.end() ? *i : boost::shared_ptr<Processor> ());
841 /** Add a processor either pre- or post-fader
842 * @return 0 on success, non-0 on failure.
845 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err, bool activation_allowed)
847 return add_processor (processor, before_processor_for_placement (placement), err, activation_allowed);
851 /** Add a processor to a route such that it ends up with a given index into the visible processors.
852 * @param index Index to add the processor at, or -1 to add at the end of the list.
853 * @return 0 on success, non-0 on failure.
856 Route::add_processor_by_index (boost::shared_ptr<Processor> processor, int index, ProcessorStreams* err, bool activation_allowed)
858 return add_processor (processor, before_processor_for_index (index), err, activation_allowed);
861 /** Add a processor to the route.
862 * @param before An existing processor in the list, or 0; the new processor will be inserted immediately before it (or at the end).
863 * @return 0 on success, non-0 on failure.
866 Route::add_processor (boost::shared_ptr<Processor> processor, boost::shared_ptr<Processor> before, ProcessorStreams* err, bool activation_allowed)
868 assert (processor != _meter);
869 assert (processor != _main_outs);
871 DEBUG_TRACE (DEBUG::Processors, string_compose (
872 "%1 adding processor %2\n", name(), processor->name()));
876 pl.push_back (processor);
877 int rv = add_processors (pl, before, err);
883 if (activation_allowed && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user ())) {
884 processor->activate ();
891 Route::processor_selfdestruct (boost::weak_ptr<Processor> wp)
893 /* We cannot destruct the processor here (usually RT-thread
894 * with various locks held - in case of sends also io_locks).
895 * Queue for deletion in low-priority thread.
897 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
898 selfdestruct_sequence.push_back (wp);
902 Route::add_processor_from_xml_2X (const XMLNode& node, int version)
904 XMLProperty const * prop;
907 boost::shared_ptr<Processor> processor;
909 /* bit of a hack: get the `placement' property from the <Redirect> tag here
910 so that we can add the processor in the right place (pre/post-fader)
913 XMLNodeList const & children = node.children ();
914 XMLNodeList::const_iterator i = children.begin ();
916 while (i != children.end() && (*i)->name() != X_("Redirect")) {
920 Placement placement = PreFader;
922 if (i != children.end()) {
923 if ((prop = (*i)->property (X_("placement"))) != 0) {
924 placement = Placement (string_2_enum (prop->value(), placement));
928 if (node.name() == "Insert") {
930 if ((prop = node.property ("type")) != 0) {
932 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
933 prop->value() == "lv2" ||
934 prop->value() == "windows-vst" ||
935 prop->value() == "mac-vst" ||
936 prop->value() == "lxvst" ||
937 prop->value() == "audiounit") {
939 if (_session.get_disable_all_loaded_plugins ()) {
940 processor.reset (new UnknownProcessor (_session, node));
942 processor.reset (new PluginInsert (_session));
943 processor->set_owner (this);
948 processor.reset (new PortInsert (_session, _pannable, _mute_master));
953 } else if (node.name() == "Send") {
955 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
956 processor.reset (new Send (_session, sendpan, _mute_master));
960 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
964 if (processor->set_state (node, version)) {
968 //A2 uses the "active" flag in the toplevel redirect node, not in the child plugin/IO
969 if (i != children.end()) {
970 if ((prop = (*i)->property (X_("active"))) != 0) {
971 if ( string_to<bool> (prop->value()) && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user () ) )
972 processor->activate();
974 processor->deactivate();
978 return (add_processor (processor, placement, 0, false) == 0);
981 catch (failed_constructor &err) {
982 warning << _("processor could not be created. Ignored.") << endmsg;
988 inline Route::PluginSetupOptions operator|= (Route::PluginSetupOptions& a, const Route::PluginSetupOptions& b) {
989 return a = static_cast<Route::PluginSetupOptions> (static_cast <int>(a) | static_cast<int> (b));
992 inline Route::PluginSetupOptions operator&= (Route::PluginSetupOptions& a, const Route::PluginSetupOptions& b) {
993 return a = static_cast<Route::PluginSetupOptions> (static_cast <int>(a) & static_cast<int> (b));
997 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
999 ProcessorList::iterator loc;
1000 boost::shared_ptr <PluginInsert> fanout;
1002 if (g_atomic_int_get (&_pending_process_reorder)) {
1003 /* we need to flush any pending re-order changes */
1004 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1005 apply_processor_changes_rt ();
1009 loc = find(_processors.begin(), _processors.end(), before);
1010 if (loc == _processors.end ()) {
1014 /* nothing specified - at end */
1015 loc = _processors.end ();
1018 if (others.empty()) {
1022 ProcessorList to_skip;
1024 // check if there's an instrument to replace or configure
1025 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1026 boost::shared_ptr<PluginInsert> pi;
1027 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) == 0) {
1030 if (!pi->plugin ()->get_info ()->is_instrument ()) {
1033 boost::shared_ptr<Processor> instrument = the_instrument ();
1034 ChanCount in (DataType::MIDI, 1);
1035 ChanCount out (DataType::AUDIO, 2); // XXX route's out?!
1037 PluginSetupOptions flags = None;
1039 flags |= CanReplace;
1040 in = instrument->input_streams ();
1041 out = instrument->output_streams ();
1043 if (pi->has_output_presets (in, out)) {
1047 pi->set_strict_io (_strict_io);
1049 PluginSetupOptions mask = None;
1050 if (Config->get_ask_replace_instrument ()) {
1053 if (Config->get_ask_setup_instrument ()) {
1059 if (flags != None) {
1060 boost::optional<int> rv = PluginSetup (boost::dynamic_pointer_cast<Route>(shared_from_this ()), pi, flags); /* EMIT SIGNAL */
1061 int mode = rv.get_value_or (0);
1064 to_skip.push_back (*i); // don't add this one;
1067 replace_processor (instrument, *i, err);
1068 to_skip.push_back (*i);
1073 if ((mode & 5) == 4) {
1080 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1081 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1082 ProcessorState pstate (this);
1084 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1089 ProcessorList::iterator check = find (to_skip.begin(), to_skip.end(), *i);
1090 if (check != to_skip.end()) {
1094 boost::shared_ptr<PluginInsert> pi;
1096 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1097 pi->set_strict_io (_strict_io);
1101 /* Ensure that only one amp is in the list at any time */
1102 ProcessorList::iterator check = find (_processors.begin(), _processors.end(), *i);
1103 if (check != _processors.end()) {
1104 if (before == _amp) {
1105 /* Already in position; all is well */
1108 _processors.erase (check);
1113 assert (find (_processors.begin(), _processors.end(), *i) == _processors.end ());
1115 _processors.insert (loc, *i);
1116 (*i)->set_owner (this);
1119 if (configure_processors_unlocked (err, &lm)) {
1121 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
1126 if (pi && pi->has_sidechain ()) {
1127 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
1130 if ((*i)->active()) {
1131 // emit ActiveChanged() and latency_changed() if needed
1135 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1137 boost::shared_ptr<Send> send;
1138 if ((send = boost::dynamic_pointer_cast<Send> (*i))) {
1139 send->SelfDestruct.connect_same_thread (*this,
1140 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (*i)));
1144 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1145 boost::shared_ptr<PluginInsert> pi;
1147 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1148 if (pi->has_no_inputs ()) {
1149 _have_internal_generator = true;
1155 _output->set_user_latency (0);
1158 reset_instrument_info ();
1159 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1160 set_processor_positions ();
1162 if (fanout && fanout->configured ()
1163 && fanout->output_streams().n_audio() > 2
1164 && boost::dynamic_pointer_cast<PluginInsert> (the_instrument ()) == fanout) {
1165 fan_out (); /* EMIT SIGNAL */
1171 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1173 if (p == PreFader) {
1174 start = _processors.begin();
1175 end = find(_processors.begin(), _processors.end(), _amp);
1177 start = find(_processors.begin(), _processors.end(), _amp);
1179 end = _processors.end();
1183 /** Turn off all processors with a given placement
1184 * @param p Placement of processors to disable
1187 Route::disable_processors (Placement p)
1189 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1191 ProcessorList::iterator start, end;
1192 placement_range(p, start, end);
1194 for (ProcessorList::iterator i = start; i != end; ++i) {
1195 (*i)->enable (false);
1198 _session.set_dirty ();
1201 /** Turn off all redirects
1204 Route::disable_processors ()
1206 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1208 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1209 (*i)->enable (false);
1212 _session.set_dirty ();
1215 /** Turn off all redirects with a given placement
1216 * @param p Placement of redirects to disable
1219 Route::disable_plugins (Placement p)
1221 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1223 ProcessorList::iterator start, end;
1224 placement_range(p, start, end);
1226 for (ProcessorList::iterator i = start; i != end; ++i) {
1227 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1228 (*i)->enable (false);
1232 _session.set_dirty ();
1235 /** Turn off all plugins
1238 Route::disable_plugins ()
1240 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1242 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1243 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1244 (*i)->enable (false);
1248 _session.set_dirty ();
1253 Route::ab_plugins (bool forward)
1255 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1259 /* forward = turn off all active redirects, and mark them so that the next time
1260 we go the other way, we will revert them
1263 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1264 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1267 if (!(*i)->display_to_user ()) {
1271 if (boost::dynamic_pointer_cast<PluginInsert> (*i)->is_channelstrip()) {
1276 if ((*i)->enabled ()) {
1277 (*i)->enable (false);
1278 (*i)->set_next_ab_is_active (true);
1280 (*i)->set_next_ab_is_active (false);
1286 /* backward = if the redirect was marked to go active on the next ab, do so */
1288 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1289 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1292 if (!(*i)->display_to_user ()) {
1296 if (boost::dynamic_pointer_cast<PluginInsert> (*i)->is_channelstrip()) {
1301 (*i)->enable ((*i)->get_next_ab_is_active ());
1305 _session.set_dirty ();
1309 /** Remove processors with a given placement.
1310 * @param p Placement of processors to remove.
1313 Route::clear_processors (Placement p)
1315 if (!_session.engine().connected()) {
1319 bool already_deleting = _session.deletion_in_progress();
1320 if (!already_deleting) {
1321 _session.set_deletion_in_progress();
1324 ProcessorList old_list = _processors;
1326 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1327 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1328 ProcessorList new_list;
1329 ProcessorStreams err;
1330 bool seen_amp = false;
1332 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1338 if (is_internal_processor (*i)) {
1340 /* you can't remove these */
1342 new_list.push_back (*i);
1349 new_list.push_back (*i);
1352 (*i)->drop_references ();
1360 (*i)->drop_references ();
1363 new_list.push_back (*i);
1370 _processors = new_list;
1371 configure_processors_unlocked (&err, &lm); // this can't fail
1373 /* drop references w/o process-lock (I/O procs may re-take it in ~IO() */
1376 processor_max_streams.reset();
1377 _have_internal_generator = false;
1378 reset_instrument_info ();
1379 set_processor_positions ();
1381 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1383 if (!already_deleting) {
1384 _session.clear_deletion_in_progress();
1389 Route::is_internal_processor (boost::shared_ptr<Processor> p) const
1391 if (p == _amp || p == _meter || p == _main_outs || p == _delayline || p == _trim || p == _polarity) {
1398 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err, bool need_process_lock)
1400 // TODO once the export point can be configured properly, do something smarter here
1401 if (processor == _capturing_processor) {
1402 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1403 if (need_process_lock) {
1407 _capturing_processor.reset();
1409 if (need_process_lock) {
1414 /* these can never be removed */
1416 if (is_internal_processor (processor)) {
1420 if (!_session.engine().connected()) {
1424 processor_max_streams.reset();
1427 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1428 if (need_process_lock) {
1432 /* Caller must hold process lock */
1433 assert (!AudioEngine::instance()->process_lock().trylock());
1435 Glib::Threads::RWLock::WriterLock lm (_processor_lock); // XXX deadlock after export
1437 ProcessorState pstate (this);
1439 ProcessorList::iterator i;
1440 bool removed = false;
1442 for (i = _processors.begin(); i != _processors.end(); ) {
1443 if (*i == processor) {
1445 /* move along, see failure case for configure_processors()
1446 where we may need to reconfigure the processor.
1449 /* stop redirects that send signals to JACK ports
1450 from causing noise as a result of no longer being
1454 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor> (*i);
1455 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
1459 iop = pi->sidechain();
1466 i = _processors.erase (i);
1474 _output->set_user_latency (0);
1482 if (configure_processors_unlocked (err, &lm)) {
1484 /* we know this will work, because it worked before :) */
1485 configure_processors_unlocked (0, &lm);
1489 _have_internal_generator = false;
1491 for (i = _processors.begin(); i != _processors.end(); ++i) {
1492 boost::shared_ptr<PluginInsert> pi;
1494 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1495 if (pi->has_no_inputs ()) {
1496 _have_internal_generator = true;
1501 if (need_process_lock) {
1506 reset_instrument_info ();
1507 processor->drop_references ();
1508 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1509 set_processor_positions ();
1515 Route::replace_processor (boost::shared_ptr<Processor> old, boost::shared_ptr<Processor> sub, ProcessorStreams* err)
1517 /* these can never be removed */
1518 if (is_internal_processor (old)) {
1521 /* and can't be used as substitute, either */
1522 if (is_internal_processor (sub)) {
1526 /* I/Os are out, too */
1527 if (boost::dynamic_pointer_cast<IOProcessor> (old) || boost::dynamic_pointer_cast<IOProcessor> (sub)) {
1531 /* this function cannot be used to swap/reorder processors */
1532 if (find (_processors.begin(), _processors.end(), sub) != _processors.end ()) {
1536 if (!AudioEngine::instance()->connected() || !old || !sub) {
1540 /* ensure that sub is not owned by another route */
1541 if (sub->owner ()) {
1546 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1547 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1548 ProcessorState pstate (this);
1550 assert (find (_processors.begin(), _processors.end(), sub) == _processors.end ());
1552 ProcessorList::iterator i;
1553 bool replaced = false;
1554 bool enable = old->enabled ();
1556 for (i = _processors.begin(); i != _processors.end(); ) {
1558 i = _processors.erase (i);
1559 _processors.insert (i, sub);
1560 sub->set_owner (this);
1573 boost::shared_ptr<PluginInsert> pi;
1574 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(sub)) != 0) {
1575 pi->set_strict_io (true);
1579 if (configure_processors_unlocked (err, &lm)) {
1581 configure_processors_unlocked (0, &lm);
1585 _have_internal_generator = false;
1587 for (i = _processors.begin(); i != _processors.end(); ++i) {
1588 boost::shared_ptr<PluginInsert> pi;
1589 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1590 if (pi->has_no_inputs ()) {
1591 _have_internal_generator = true;
1601 sub->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1602 _output->set_user_latency (0);
1605 reset_instrument_info ();
1606 old->drop_references ();
1607 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1608 set_processor_positions ();
1613 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1615 ProcessorList deleted;
1617 if (!_session.engine().connected()) {
1621 processor_max_streams.reset();
1624 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1625 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1626 ProcessorState pstate (this);
1628 ProcessorList::iterator i;
1629 boost::shared_ptr<Processor> processor;
1631 for (i = _processors.begin(); i != _processors.end(); ) {
1635 /* these can never be removed */
1637 if (is_internal_processor (processor)) {
1642 /* see if its in the list of processors to delete */
1644 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1649 /* stop IOProcessors that send to JACK ports
1650 from causing noise as a result of no longer being
1654 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(processor);
1655 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
1658 iop = pi->sidechain();
1665 deleted.push_back (processor);
1666 i = _processors.erase (i);
1669 if (deleted.empty()) {
1670 /* none of those in the requested list were found */
1674 _output->set_user_latency (0);
1676 if (configure_processors_unlocked (err, &lm)) {
1678 /* we know this will work, because it worked before :) */
1679 configure_processors_unlocked (0, &lm);
1684 _have_internal_generator = false;
1686 for (i = _processors.begin(); i != _processors.end(); ++i) {
1687 boost::shared_ptr<PluginInsert> pi;
1689 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1690 if (pi->has_no_inputs ()) {
1691 _have_internal_generator = true;
1698 /* now try to do what we need to so that those that were removed will be deleted */
1700 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1701 (*i)->drop_references ();
1704 reset_instrument_info ();
1705 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1706 set_processor_positions ();
1712 Route::reset_instrument_info ()
1714 boost::shared_ptr<Processor> instr = the_instrument();
1716 _instrument_info.set_internal_instrument (instr);
1720 /** Caller must hold process lock */
1722 Route::configure_processors (ProcessorStreams* err)
1724 #ifndef PLATFORM_WINDOWS
1725 assert (!AudioEngine::instance()->process_lock().trylock());
1728 if (!_in_configure_processors) {
1729 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1730 return configure_processors_unlocked (err, &lm);
1737 Route::input_streams () const
1739 return _input->n_ports ();
1742 list<pair<ChanCount, ChanCount> >
1743 Route::try_configure_processors (ChanCount in, ProcessorStreams* err)
1745 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1747 return try_configure_processors_unlocked (in, err);
1750 list<pair<ChanCount, ChanCount> >
1751 Route::try_configure_processors_unlocked (ChanCount in, ProcessorStreams* err)
1753 // Check each processor in order to see if we can configure as requested
1755 list<pair<ChanCount, ChanCount> > configuration;
1758 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1759 DEBUG_TRACE (DEBUG::Processors, "{\n");
1761 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1763 if ((*p)->can_support_io_configuration(in, out)) {
1765 if (boost::dynamic_pointer_cast<Delivery> (*p)
1766 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main
1768 && (is_monitor() || _strict_io || Profile->get_mixbus ())) {
1769 /* with strict I/O the panner + output are forced to
1770 * follow the last processor's output.
1772 * Delivery::can_support_io_configuration() will only add ports,
1773 * but not remove excess ports.
1775 * This works because the delivery only requires
1776 * as many outputs as there are inputs.
1777 * Delivery::configure_io() will do the actual removal
1778 * by calling _output->ensure_io()
1780 if (!is_master() && _session.master_out () && in.n_audio() > 0) {
1781 /* ..but at least as many as there are master-inputs, if
1782 * the delivery is dealing with audio */
1783 // XXX this may need special-casing for mixbus (master-outputs)
1784 // and should maybe be a preference anyway ?!
1785 out = ChanCount::max (in, _session.master_out ()->n_inputs ());
1791 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID=%2 in=%3 out=%4\n",(*p)->name(), (*p)->id(), in, out));
1792 configuration.push_back(make_pair(in, out));
1795 // restriction for Monitor Section Processors
1796 if (in.n_audio() != out.n_audio() || out.n_midi() > 0) {
1797 /* Note: The Monitor follows the master-bus and has no panner.
1799 * The general idea is to only allow plugins that retain the channel-count
1800 * and plugins with MIDI in (e.g VSTs with control that will remain unconnected).
1801 * Then again 5.1 in, monitor stereo is a valid use-case.
1803 * and worse: we only refuse adding plugins *here*.
1805 * 1) stereo-master, stereo-mon, add a stereo-plugin, OK
1806 * 2) change master-bus, add a channel
1807 * 2a) monitor-secion follows
1808 * 3) monitor processors fail to re-reconfigure (stereo plugin)
1809 * 4) re-load session, monitor-processor remains unconfigured, crash.
1811 DEBUG_TRACE (DEBUG::Processors, "Monitor: Channel configuration change.\n");
1813 if (boost::dynamic_pointer_cast<InternalSend> (*p)) {
1814 // internal sends make no sense, only feedback
1815 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1816 return list<pair<ChanCount, ChanCount> > ();
1818 if (boost::dynamic_pointer_cast<PortInsert> (*p)) {
1819 /* External Sends can be problematic. one can add/remove ports
1820 * there signal leaves the DAW to external monitors anyway, so there's
1821 * no real use for allowing them here anyway.
1823 DEBUG_TRACE (DEBUG::Processors, "Monitor: No External Sends allowed.\n");
1824 return list<pair<ChanCount, ChanCount> > ();
1826 if (boost::dynamic_pointer_cast<Send> (*p)) {
1828 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1829 return list<pair<ChanCount, ChanCount> > ();
1838 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
1839 DEBUG_TRACE (DEBUG::Processors, string_compose ("---- %1 cannot support in=%2 out=%3\n", (*p)->name(), in, out));
1840 DEBUG_TRACE (DEBUG::Processors, "}\n");
1841 return list<pair<ChanCount, ChanCount> > ();
1845 DEBUG_TRACE (DEBUG::Processors, "}\n");
1847 return configuration;
1850 /** Set the input/output configuration of each processor in the processors list.
1851 * Caller must hold process lock.
1852 * Return 0 on success, otherwise configuration is impossible.
1855 Route::configure_processors_unlocked (ProcessorStreams* err, Glib::Threads::RWLock::WriterLock* lm)
1857 #ifndef PLATFORM_WINDOWS
1858 assert (!AudioEngine::instance()->process_lock().trylock());
1861 if (_in_configure_processors) {
1865 /* put invisible processors where they should be */
1866 setup_invisible_processors ();
1868 _in_configure_processors = true;
1870 list<pair<ChanCount, ChanCount> > configuration = try_configure_processors_unlocked (input_streams (), err);
1872 if (configuration.empty ()) {
1873 _in_configure_processors = false;
1878 bool seen_mains_out = false;
1879 processor_out_streams = _input->n_ports();
1880 processor_max_streams.reset();
1882 /* processor configure_io() may result in adding ports
1883 * e.g. Delivery::configure_io -> ARDOUR::IO::ensure_io ()
1885 * with jack2 adding ports results in a graph-order callback,
1886 * which calls Session::resort_routes() and eventually
1887 * Route::direct_feeds_according_to_reality()
1888 * which takes a ReaderLock (_processor_lock).
1890 * so we can't hold a WriterLock here until jack2 threading
1893 * NB. we still hold the process lock
1895 * (ardour's own engines do call graph-order from the
1896 * process-thread and hence do not have this issue; besides
1897 * merely adding ports won't trigger a graph-order, only
1898 * making connections does)
1902 // TODO check for a potential ReaderLock after ReaderLock ??
1903 Glib::Threads::RWLock::ReaderLock lr (_processor_lock);
1905 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1906 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1908 if (!(*p)->configure_io(c->first, c->second)) {
1909 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration failed\n", _name));
1910 _in_configure_processors = false;
1916 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1917 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1919 boost::shared_ptr<IOProcessor> iop;
1920 boost::shared_ptr<PluginInsert> pi;
1921 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
1922 /* plugins connected via Split or Hide Match may have more channels.
1923 * route/scratch buffers are needed for all of them
1924 * The configuration may only be a subset (both input and output)
1926 processor_max_streams = ChanCount::max(processor_max_streams, pi->required_buffers());
1928 else if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*p)) != 0) {
1929 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_input_streams());
1930 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_output_streams());
1934 if (boost::dynamic_pointer_cast<Delivery> (*p)
1935 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main) {
1936 /* main delivery will increase port count to match input.
1937 * the Delivery::Main is usually the last processor - followed only by
1940 seen_mains_out = true;
1942 if (!seen_mains_out) {
1943 processor_out_streams = out;
1952 _meter->set_max_channels (processor_max_streams);
1955 /* make sure we have sufficient scratch buffers to cope with the new processor
1958 _session.ensure_buffers (n_process_buffers ());
1960 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration complete\n", _name));
1962 _in_configure_processors = false;
1966 /** Set all visible processors to a given active state (except Fader, whose state is not changed)
1967 * @param state New active state for those processors.
1970 Route::all_visible_processors_active (bool state)
1972 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1974 if (_processors.empty()) {
1978 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1979 if (!(*i)->display_to_user() || boost::dynamic_pointer_cast<Amp> (*i)) {
1983 boost::shared_ptr<PluginInsert> pi;
1984 if (0 != (pi = boost::dynamic_pointer_cast<PluginInsert>(*i))) {
1985 if (pi->is_channelstrip ()) {
1990 (*i)->enable (state);
1993 _session.set_dirty ();
1997 Route::processors_reorder_needs_configure (const ProcessorList& new_order)
1999 /* check if re-order requires re-configuration of any processors
2000 * -> compare channel configuration for all processors
2002 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2003 ChanCount c = input_streams ();
2005 for (ProcessorList::const_iterator j = new_order.begin(); j != new_order.end(); ++j) {
2007 if (c != (*j)->input_streams()) {
2010 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2013 if ((*i)->input_streams() != c) {
2016 c = (*i)->output_streams();
2028 __attribute__((annotate("realtime")))
2031 Route::apply_processor_order (const ProcessorList& new_order)
2033 /* need to hold processor_lock; either read or write lock
2034 * and the engine process_lock.
2035 * Due to r/w lock ambiguity we can only assert the latter
2037 assert (!AudioEngine::instance()->process_lock().trylock());
2040 /* "new_order" is an ordered list of processors to be positioned according to "placement".
2041 * NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
2042 * processors in the current actual processor list that are hidden. Any visible processors
2043 * in the current list but not in "new_order" will be assumed to be deleted.
2046 /* "as_it_will_be" and "_processors" are lists of shared pointers.
2047 * actual memory usage is small, but insert/erase is not actually rt-safe :(
2048 * (note though that ::processors_reorder_needs_configure() ensured that
2049 * this function will only ever be called from the rt-thread if no processor were removed)
2051 * either way, I can't proove it, but an x-run due to re-order here is less likley
2052 * than an x-run-less 'ardour-silent cycle' both of which effectively "click".
2055 ProcessorList as_it_will_be;
2056 ProcessorList::iterator oiter;
2057 ProcessorList::const_iterator niter;
2059 oiter = _processors.begin();
2060 niter = new_order.begin();
2062 while (niter != new_order.end()) {
2064 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
2065 then append it to the temp list.
2067 Otherwise, see if the next processor in the old list is in the new list. if not,
2068 its been deleted. If its there, append it to the temp list.
2071 if (oiter == _processors.end()) {
2073 /* no more elements in the old list, so just stick the rest of
2074 the new order onto the temp list.
2077 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
2078 while (niter != new_order.end()) {
2085 if (!(*oiter)->display_to_user()) {
2087 as_it_will_be.push_back (*oiter);
2091 /* visible processor: check that its in the new order */
2093 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
2094 /* deleted: do nothing, shared_ptr<> will clean up */
2096 /* ignore this one, and add the next item from the new order instead */
2097 as_it_will_be.push_back (*niter);
2102 /* now remove from old order - its taken care of no matter what */
2103 oiter = _processors.erase (oiter);
2107 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
2109 /* If the meter is in a custom position, find it and make a rough note of its position */
2110 maybe_note_meter_position ();
2114 Route::move_instrument_down (bool postfader)
2116 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2117 ProcessorList new_order;
2118 boost::shared_ptr<Processor> instrument;
2119 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2120 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
2121 if (pi && pi->plugin ()->get_info ()->is_instrument ()) {
2123 } else if (instrument && *i == _amp) {
2125 new_order.push_back (*i);
2126 new_order.push_back (instrument);
2128 new_order.push_back (instrument);
2129 new_order.push_back (*i);
2132 new_order.push_back (*i);
2139 reorder_processors (new_order, 0);
2143 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
2145 // it a change is already queued, wait for it
2146 // (unless engine is stopped. apply immediately and proceed
2147 while (g_atomic_int_get (&_pending_process_reorder)) {
2148 if (!AudioEngine::instance()->running()) {
2149 DEBUG_TRACE (DEBUG::Processors, "offline apply queued processor re-order.\n");
2150 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2152 apply_processor_order(_pending_processor_order);
2153 setup_invisible_processors ();
2155 g_atomic_int_set (&_pending_process_reorder, 0);
2157 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2158 set_processor_positions ();
2160 // TODO rather use a semaphore or something.
2161 // but since ::reorder_processors() is called
2162 // from the GUI thread, this is fine..
2167 if (processors_reorder_needs_configure (new_order) || !AudioEngine::instance()->running()) {
2169 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2170 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2171 ProcessorState pstate (this);
2173 apply_processor_order (new_order);
2175 if (configure_processors_unlocked (err, &lm)) {
2183 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2184 set_processor_positions ();
2187 DEBUG_TRACE (DEBUG::Processors, "Queue clickless processor re-order.\n");
2188 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2190 // _pending_processor_order is protected by _processor_lock
2191 _pending_processor_order = new_order;
2192 g_atomic_int_set (&_pending_process_reorder, 1);
2195 /* update processor input/output latency
2196 * (total signal_latency does not change)
2198 update_signal_latency (true);
2204 Route::add_remove_sidechain (boost::shared_ptr<Processor> proc, bool add)
2206 boost::shared_ptr<PluginInsert> pi;
2207 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2211 if (pi->has_sidechain () == add) {
2212 return true; // ?? call failed, but result is as expected.
2216 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2217 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2218 if (i == _processors.end ()) {
2224 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ()); // take before Writerlock to avoid deadlock
2225 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2226 PBD::Unwinder<bool> uw (_in_sidechain_setup, true);
2228 lx.release (); // IO::add_port() and ~IO takes process lock - XXX check if this is safe
2230 if (!pi->add_sidechain ()) {
2234 if (!pi->del_sidechain ()) {
2240 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2245 pi->del_sidechain ();
2247 pi->add_sidechain ();
2248 // TODO restore side-chain's state.
2253 configure_processors_unlocked (0, &lm);
2256 if (pi->has_sidechain ()) {
2257 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
2260 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2261 _session.set_dirty ();
2266 Route::plugin_preset_output (boost::shared_ptr<Processor> proc, ChanCount outs)
2268 boost::shared_ptr<PluginInsert> pi;
2269 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2274 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2275 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2276 if (i == _processors.end ()) {
2282 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2283 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2285 const ChanCount& old (pi->preset_out ());
2286 if (!pi->set_preset_out (outs)) {
2287 return true; // no change, OK
2290 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2293 pi->set_preset_out (old);
2296 configure_processors_unlocked (0, &lm);
2299 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2300 _session.set_dirty ();
2305 Route::reset_plugin_insert (boost::shared_ptr<Processor> proc)
2308 return customize_plugin_insert (proc, 0, unused, unused);
2312 Route::customize_plugin_insert (boost::shared_ptr<Processor> proc, uint32_t count, ChanCount outs, ChanCount sinks)
2314 boost::shared_ptr<PluginInsert> pi;
2315 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2320 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2321 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2322 if (i == _processors.end ()) {
2328 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2329 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2331 bool old_cust = pi->custom_cfg ();
2332 uint32_t old_cnt = pi->get_count ();
2333 ChanCount old_chan = pi->output_streams ();
2334 ChanCount old_sinks = pi->natural_input_streams ();
2337 pi->set_custom_cfg (false);
2339 pi->set_custom_cfg (true);
2340 pi->set_count (count);
2341 pi->set_outputs (outs);
2342 pi->set_sinks (sinks);
2345 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2349 pi->set_count (old_cnt);
2350 pi->set_sinks (old_sinks);
2351 pi->set_outputs (old_chan);
2352 pi->set_custom_cfg (old_cust);
2356 configure_processors_unlocked (0, &lm);
2359 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2360 _session.set_dirty ();
2365 Route::set_strict_io (const bool enable)
2367 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2369 if (_strict_io != enable) {
2370 _strict_io = enable;
2371 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2372 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2373 boost::shared_ptr<PluginInsert> pi;
2374 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2375 pi->set_strict_io (_strict_io);
2379 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2383 _strict_io = !enable; // restore old value
2384 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2385 boost::shared_ptr<PluginInsert> pi;
2386 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2387 pi->set_strict_io (_strict_io);
2394 configure_processors (0);
2397 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2398 _session.set_dirty ();
2406 return state (false);
2410 Route::get_template()
2412 return state (true);
2416 Route::state (bool save_template)
2418 if (!_session._template_state_dir.empty()) {
2419 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), _session._template_state_dir));
2422 XMLNode *node = new XMLNode("Route");
2423 ProcessorList::iterator i;
2425 node->set_property (X_("id"), id ());
2426 node->set_property (X_("name"), name());
2427 node->set_property (X_("default-type"), _default_type);
2428 node->set_property (X_("strict-io"), _strict_io);
2430 node->add_child_nocopy (_presentation_info.get_state());
2432 node->set_property (X_("active"), _active);
2433 node->set_property (X_("denormal-protection"), _denormal_protection);
2434 node->set_property (X_("meter-point"), _meter_point);
2435 node->set_property (X_("disk-io-point"), _disk_io_point);
2437 node->set_property (X_("meter-type"), _meter_type);
2440 node->set_property (X_("route-group"), _route_group->name());
2443 node->add_child_nocopy (_solo_control->get_state ());
2444 node->add_child_nocopy (_solo_isolate_control->get_state ());
2445 node->add_child_nocopy (_solo_safe_control->get_state ());
2447 node->add_child_nocopy (_input->get_state ());
2448 node->add_child_nocopy (_output->get_state ());
2449 node->add_child_nocopy (_mute_master->get_state ());
2451 node->add_child_nocopy (_mute_control->get_state ());
2452 node->add_child_nocopy (_phase_control->get_state ());
2454 if (!skip_saving_automation) {
2455 node->add_child_nocopy (Automatable::get_automation_xml_state ());
2458 if (_comment.length()) {
2459 XMLNode *cmt = node->add_child ("Comment");
2460 cmt->add_content (_comment);
2464 node->add_child_nocopy (_pannable->get_state ());
2468 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2469 for (i = _processors.begin(); i != _processors.end(); ++i) {
2470 if (*i == _delayline) {
2473 if (save_template) {
2474 /* template save: do not include internal sends functioning as
2475 aux sends because the chance of the target ID
2476 in the session where this template is used
2479 similarly, do not save listen sends which connect to
2480 the monitor section, because these will always be
2483 boost::shared_ptr<InternalSend> is;
2485 if ((is = boost::dynamic_pointer_cast<InternalSend> (*i)) != 0) {
2486 if (is->role() == Delivery::Listen) {
2491 node->add_child_nocopy((*i)->get_state ());
2496 node->add_child_copy (*_extra_xml);
2499 if (_custom_meter_position_noted) {
2500 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
2502 node->set_property (X_("processor-after-last-custom-meter"), after->id());
2506 if (!_session._template_state_dir.empty()) {
2507 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), ""));
2510 node->add_child_copy (Slavable::get_state());
2516 Route::set_state (const XMLNode& node, int version)
2518 if (version < 3000) {
2519 return set_state_2X (node, version);
2523 XMLNodeConstIterator niter;
2526 if (node.name() != "Route"){
2527 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2531 std::string route_name;
2532 if (node.get_property (X_("name"), route_name)) {
2533 Route::set_name (route_name);
2537 _initial_io_setup = true;
2539 Stripable::set_state (node, version);
2541 node.get_property (X_("strict-io"), _strict_io);
2544 /* monitor bus does not get a panner, but if (re)created
2545 via XML, it will already have one by the time we
2546 call ::set_state(). so ... remove it.
2551 /* add all processors (except amp, which is always present) */
2553 nlist = node.children();
2554 XMLNode processor_state (X_("processor_state"));
2556 Stateful::save_extra_xml (node);
2558 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2562 if (child->name() == IO::state_node_name) {
2563 std::string direction;
2564 if (!child->get_property (X_("direction"), direction)) {
2568 if (direction == "Input") {
2569 _input->set_state (*child, version);
2570 } else if (direction == "Output") {
2571 _output->set_state (*child, version);
2574 } else if (child->name() == X_("Processor")) {
2575 processor_state.add_child_copy (*child);
2576 } else if (child->name() == X_("Pannable")) {
2578 _pannable->set_state (*child, version);
2580 warning << string_compose (_("Pannable state found for route (%1) without a panner!"), name()) << endmsg;
2582 } else if (child->name() == Slavable::xml_node_name) {
2583 Slavable::set_state (*child, version);
2588 if (node.get_property (X_("meter-point"), mp)) {
2589 set_meter_point (mp, true);
2591 _meter->set_display_to_user (_meter_point == MeterCustom);
2596 if (node.get_property (X_("disk-io-point"), diop)) {
2598 _disk_writer->set_display_to_user (diop == DiskIOCustom);
2601 _disk_reader->set_display_to_user (diop == DiskIOCustom);
2603 set_disk_io_point (diop);
2606 node.get_property (X_("meter-type"), _meter_type);
2608 _initial_io_setup = false;
2610 set_processor_state (processor_state);
2612 // this looks up the internal instrument in processors
2613 reset_instrument_info();
2615 bool denormal_protection;
2616 if (node.get_property (X_("denormal-protection"), denormal_protection)) {
2617 set_denormal_protection (denormal_protection);
2620 /* convert old 3001 state */
2621 std::string phase_invert_str;
2622 if (node.get_property (X_("phase-invert"), phase_invert_str)) {
2623 _phase_control->set_phase_invert (boost::dynamic_bitset<> (phase_invert_str));
2627 if (node.get_property (X_("active"), is_active)) {
2628 set_active (is_active, this);
2631 std::string id_string;
2632 if (node.get_property (X_("processor-after-last-custom-meter"), id_string)) {
2633 PBD::ID id (id_string);
2634 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2635 ProcessorList::const_iterator i = _processors.begin ();
2636 while (i != _processors.end() && (*i)->id() != id) {
2640 if (i != _processors.end ()) {
2641 _processor_after_last_custom_meter = *i;
2642 _custom_meter_position_noted = true;
2646 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2649 if (child->name() == X_("Comment")) {
2651 /* XXX this is a terrible API design in libxml++ */
2653 XMLNode *cmt = *(child->children().begin());
2654 _comment = cmt->content();
2656 } else if (child->name() == Controllable::xml_node_name) {
2657 std::string control_name;
2658 if (!child->get_property (X_("name"), control_name)) {
2662 if (control_name == _solo_control->name()) {
2663 _solo_control->set_state (*child, version);
2664 } else if (control_name == _solo_safe_control->name()) {
2665 _solo_safe_control->set_state (*child, version);
2666 } else if (control_name == _solo_isolate_control->name()) {
2667 _solo_isolate_control->set_state (*child, version);
2668 } else if (control_name == _mute_control->name()) {
2669 _mute_control->set_state (*child, version);
2670 } else if (control_name == _phase_control->name()) {
2671 _phase_control->set_state (*child, version);
2673 Evoral::Parameter p = EventTypeMap::instance().from_symbol (control_name);
2674 if (p.type () >= MidiCCAutomation && p.type () < MidiSystemExclusiveAutomation) {
2675 boost::shared_ptr<AutomationControl> ac = automation_control (p, true);
2677 ac->set_state (*child, version);
2681 } else if (child->name() == MuteMaster::xml_node_name) {
2682 _mute_master->set_state (*child, version);
2684 } else if (child->name() == Automatable::xml_node_name) {
2685 set_automation_xml_state (*child, Evoral::Parameter(NullAutomation));
2690 _delayline->set_name (name ());
2697 Route::set_state_2X (const XMLNode& node, int version)
2701 XMLNodeConstIterator niter;
2703 XMLProperty const * prop;
2705 /* 2X things which still remain to be handled:
2711 if (node.name() != "Route") {
2712 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2716 Stripable::set_state (node, version);
2718 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2719 set_denormal_protection (string_to<bool> (prop->value()));
2722 if ((prop = node.property (X_("muted"))) != 0) {
2725 bool muted = string_to<bool> (prop->value());
2731 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2733 if (string_to<bool> (prop->value())){
2734 mute_point = mute_point + "PreFader";
2739 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2741 if (string_to<bool> (prop->value())){
2744 mute_point = mute_point + ",";
2747 mute_point = mute_point + "PostFader";
2752 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2754 if (string_to<bool> (prop->value())){
2757 mute_point = mute_point + ",";
2760 mute_point = mute_point + "Listen";
2765 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2767 if (string_to<bool> (prop->value())){
2770 mute_point = mute_point + ",";
2773 mute_point = mute_point + "Main";
2777 _mute_master->set_mute_points (mute_point);
2778 _mute_master->set_muted_by_self (true);
2782 if ((prop = node.property (X_("meter-point"))) != 0) {
2783 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2788 nlist = node.children ();
2789 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2793 if (child->name() == IO::state_node_name) {
2795 /* there is a note in IO::set_state_2X() about why we have to call
2799 _input->set_state_2X (*child, version, true);
2800 _output->set_state_2X (*child, version, false);
2802 if ((prop = child->property (X_("name"))) != 0) {
2803 Route::set_name (prop->value ());
2808 if ((prop = child->property (X_("active"))) != 0) {
2809 bool yn = string_to<bool> (prop->value());
2810 _active = !yn; // force switch
2811 set_active (yn, this);
2814 if ((prop = child->property (X_("gain"))) != 0) {
2817 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
2818 _amp->gain_control()->set_value (val, Controllable::NoGroup);
2822 /* Set up Panners in the IO */
2823 XMLNodeList io_nlist = child->children ();
2825 XMLNodeConstIterator io_niter;
2828 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
2830 io_child = *io_niter;
2832 if (io_child->name() == X_("Panner")) {
2833 _main_outs->panner_shell()->set_state(*io_child, version);
2834 } else if (io_child->name() == X_("Automation")) {
2835 /* IO's automation is for the fader */
2836 _amp->set_automation_xml_state (*io_child, Evoral::Parameter (GainAutomation));
2842 XMLNodeList redirect_nodes;
2844 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2848 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2849 redirect_nodes.push_back(child);
2854 set_processor_state_2X (redirect_nodes, version);
2856 Stateful::save_extra_xml (node);
2858 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2861 if (child->name() == X_("Comment")) {
2863 /* XXX this is a terrible API design in libxml++ */
2865 XMLNode *cmt = *(child->children().begin());
2866 _comment = cmt->content();
2868 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2869 if (prop->value() == X_("solo")) {
2870 _solo_control->set_state (*child, version);
2871 } else if (prop->value() == X_("mute")) {
2872 _mute_control->set_state (*child, version);
2882 Route::get_processor_state ()
2884 XMLNode* root = new XMLNode (X_("redirects"));
2885 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2886 root->add_child_nocopy ((*i)->get_state ());
2893 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2895 /* We don't bother removing existing processors not in nList, as this
2896 method will only be called when creating a Route from scratch, not
2897 for undo purposes. Just put processors in at the appropriate place
2901 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2902 add_processor_from_xml_2X (**i, version);
2907 Route::set_processor_state (const XMLNode& node)
2909 const XMLNodeList &nlist = node.children();
2910 XMLNodeConstIterator niter;
2911 ProcessorList new_order;
2912 bool must_configure = false;
2914 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2916 XMLProperty* prop = (*niter)->property ("type");
2918 if (prop->value() == "amp") {
2919 _amp->set_state (**niter, Stateful::current_state_version);
2920 new_order.push_back (_amp);
2921 } else if (prop->value() == "trim") {
2922 _trim->set_state (**niter, Stateful::current_state_version);
2923 new_order.push_back (_trim);
2924 } else if (prop->value() == "meter") {
2925 _meter->set_state (**niter, Stateful::current_state_version);
2926 new_order.push_back (_meter);
2927 } else if (prop->value() == "polarity") {
2928 _polarity->set_state (**niter, Stateful::current_state_version);
2929 new_order.push_back (_polarity);
2930 } else if (prop->value() == "delay") {
2932 } else if (prop->value() == "main-outs") {
2933 _main_outs->set_state (**niter, Stateful::current_state_version);
2934 } else if (prop->value() == "intreturn") {
2936 _intreturn.reset (new InternalReturn (_session));
2937 must_configure = true;
2939 _intreturn->set_state (**niter, Stateful::current_state_version);
2940 } else if (is_monitor() && prop->value() == "monitor") {
2941 if (!_monitor_control) {
2942 _monitor_control.reset (new MonitorProcessor (_session));
2943 must_configure = true;
2945 _monitor_control->set_state (**niter, Stateful::current_state_version);
2946 } else if (prop->value() == "capture") {
2947 /* CapturingProcessor should never be restored, it's always
2948 added explicitly when needed */
2949 } else if (prop->value() == "diskreader" && _disk_reader) {
2950 _disk_reader->set_state (**niter, Stateful::current_state_version);
2951 new_order.push_back (_disk_reader);
2952 } else if (prop->value() == "diskwriter" && _disk_writer) {
2953 _disk_writer->set_state (**niter, Stateful::current_state_version);
2954 new_order.push_back (_disk_writer);
2956 set_processor_state (**niter, prop, new_order, must_configure);
2960 ProcessorList old_list = _processors; // keep a copy
2962 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2963 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2964 /* re-assign _processors w/o process-lock.
2965 * if there's an IO-processor present in _processors but
2966 * not in new_order, it will be deleted and ~IO takes
2969 _processors = new_order;
2971 if (must_configure) {
2972 configure_processors_unlocked (0, &lm);
2975 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2977 (*i)->set_owner (this);
2978 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
2980 boost::shared_ptr<PluginInsert> pi;
2982 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
2983 if (pi->has_no_inputs ()) {
2984 _have_internal_generator = true;
2990 /* drop references w/o process-lock (I/O procs may re-take it in ~IO() */
2993 reset_instrument_info ();
2994 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2995 set_processor_positions ();
2999 Route::set_processor_state (XMLNode const & node, XMLProperty const* prop, ProcessorList& new_order, bool& must_configure)
3001 ProcessorList::iterator o;
3003 for (o = _processors.begin(); o != _processors.end(); ++o) {
3004 XMLProperty const * id_prop = node.property(X_("id"));
3005 if (id_prop && (*o)->id() == id_prop->value()) {
3006 (*o)->set_state (node, Stateful::current_state_version);
3007 new_order.push_back (*o);
3012 // If the processor (node) is not on the route then create it
3014 if (o == _processors.end()) {
3016 boost::shared_ptr<Processor> processor;
3018 if (prop->value() == "intsend") {
3020 processor.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), boost::shared_ptr<Route>(), Delivery::Aux, true));
3022 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
3023 prop->value() == "lv2" ||
3024 prop->value() == "windows-vst" ||
3025 prop->value() == "mac-vst" ||
3026 prop->value() == "lxvst" ||
3027 prop->value() == "luaproc" ||
3028 prop->value() == "audiounit") {
3030 if (_session.get_disable_all_loaded_plugins ()) {
3031 processor.reset (new UnknownProcessor (_session, node));
3033 processor.reset (new PluginInsert (_session));
3034 processor->set_owner (this);
3036 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
3037 pi->set_strict_io (true);
3041 } else if (prop->value() == "port") {
3043 processor.reset (new PortInsert (_session, _pannable, _mute_master));
3045 } else if (prop->value() == "send") {
3047 processor.reset (new Send (_session, _pannable, _mute_master, Delivery::Send, true));
3048 boost::shared_ptr<Send> send = boost::dynamic_pointer_cast<Send> (processor);
3049 send->SelfDestruct.connect_same_thread (*this,
3050 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (processor)));
3056 if (processor->set_state (node, Stateful::current_state_version) != 0) {
3057 /* This processor could not be configured. Turn it into a UnknownProcessor */
3058 processor.reset (new UnknownProcessor (_session, node));
3061 /* subscribe to Sidechain IO changes */
3062 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
3063 if (pi && pi->has_sidechain ()) {
3064 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
3067 /* we have to note the monitor send here, otherwise a new one will be created
3068 and the state of this one will be lost.
3070 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
3071 if (isend && isend->role() == Delivery::Listen) {
3072 _monitor_send = isend;
3075 /* it doesn't matter if invisible processors are added here, as they
3076 will be sorted out by setup_invisible_processors () shortly.
3079 new_order.push_back (processor);
3080 must_configure = true;
3086 Route::curve_reallocate ()
3088 // _gain_automation_curve.finish_resize ();
3089 // _pan_automation_curve.finish_resize ();
3093 Route::silence (samplecnt_t nframes)
3095 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3100 silence_unlocked (nframes);
3104 Route::silence_unlocked (samplecnt_t nframes)
3106 /* Must be called with the processor lock held */
3108 const samplepos_t now = _session.transport_sample ();
3110 _output->silence (nframes);
3112 // update owned automated controllables
3113 automation_run (now, nframes);
3115 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3116 boost::shared_ptr<PluginInsert> pi;
3118 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
3119 /* evaluate automated automation controls */
3120 pi->automation_run (now, nframes);
3121 /* skip plugins, they don't need anything when we're not active */
3125 (*i)->silence (nframes, now);
3130 Route::add_internal_return ()
3133 _intreturn.reset (new InternalReturn (_session));
3134 add_processor (_intreturn, PreFader);
3139 Route::add_send_to_internal_return (InternalSend* send)
3141 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3143 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3144 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3147 return d->add_send (send);
3153 Route::remove_send_from_internal_return (InternalSend* send)
3155 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3157 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3158 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3161 return d->remove_send (send);
3167 Route::enable_monitor_send ()
3169 /* Caller must hold process lock */
3170 assert (!AudioEngine::instance()->process_lock().trylock());
3172 /* master never sends to monitor section via the normal mechanism */
3173 assert (!is_master ());
3174 assert (!is_monitor ());
3176 /* make sure we have one */
3177 if (!_monitor_send) {
3178 _monitor_send.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), _session.monitor_out(), Delivery::Listen));
3179 _monitor_send->set_display_to_user (false);
3183 configure_processors (0);
3186 /** Add an aux send to a route.
3187 * @param route route to send to.
3188 * @param before Processor to insert before, or 0 to insert at the end.
3191 Route::add_aux_send (boost::shared_ptr<Route> route, boost::shared_ptr<Processor> before)
3193 assert (route != _session.monitor_out ());
3196 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3198 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3200 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend> (*x);
3202 if (d && d->target_route() == route) {
3203 /* already listening via the specified IO: do nothing */
3211 boost::shared_ptr<InternalSend> listener;
3214 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
3215 listener.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), route, Delivery::Aux));
3218 add_processor (listener, before);
3220 } catch (failed_constructor& err) {
3228 Route::remove_aux_or_listen (boost::shared_ptr<Route> route)
3230 ProcessorStreams err;
3231 ProcessorList::iterator tmp;
3234 Glib::Threads::RWLock::ReaderLock rl(_processor_lock);
3236 /* have to do this early because otherwise processor reconfig
3237 * will put _monitor_send back in the list
3240 if (route == _session.monitor_out()) {
3241 _monitor_send.reset ();
3245 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3247 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
3249 if (d && d->target_route() == route) {
3251 if (remove_processor (*x, &err, false) > 0) {
3257 /* list could have been demolished while we dropped the lock
3260 if (_session.engine().connected()) {
3261 /* i/o processors cannot be removed if the engine is not running
3262 * so don't live-loop in case the engine is N/A or dies
3272 Route::set_comment (string cmt, void *src)
3276 _session.set_dirty ();
3280 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
3282 FeedRecord fr (other, via_sends_only);
3284 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
3286 if (!result.second) {
3288 /* already a record for "other" - make sure sends-only information is correct */
3289 if (!via_sends_only && result.first->sends_only) {
3290 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
3291 frp->sends_only = false;
3295 return result.second;
3299 Route::clear_fed_by ()
3305 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
3307 const FedBy& fed_by (other->fed_by());
3309 for (FedBy::const_iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
3310 boost::shared_ptr<Route> sr = f->r.lock();
3312 if (sr && (sr.get() == this)) {
3314 if (via_sends_only) {
3315 *via_sends_only = f->sends_only;
3326 Route::all_inputs () const
3328 /* TODO, if this works as expected,
3329 * cache the IOVector and maintain it via
3330 * input_change_handler(), sidechain_change_handler() etc
3333 ios.push_back (_input);
3335 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3336 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3338 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3339 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3342 iop = pi->sidechain();
3345 if (iop != 0 && iop->input()) {
3346 ios.push_back (iop->input());
3353 Route::all_outputs () const
3356 // _output is included via Delivery
3357 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3358 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3359 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3360 if (iop != 0 && iop->output()) {
3361 ios.push_back (iop->output());
3368 Route::direct_feeds_according_to_reality (boost::shared_ptr<Route> other, bool* via_send_only)
3370 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
3371 if (other->all_inputs().fed_by (_output)) {
3372 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
3373 if (via_send_only) {
3374 *via_send_only = false;
3380 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3382 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
3384 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3385 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3388 iop = pi->sidechain();
3392 boost::shared_ptr<const IO> iop_out = iop->output();
3393 if (other.get() == this && iop_out && iop->input() && iop_out->connected_to (iop->input())) {
3394 // TODO this needs a delaylines in the Insert to align connections (!)
3395 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed its own return (%2)\n", iop->name(), other->name()));
3398 if ((iop_out && other->all_inputs().fed_by (iop_out)) || iop->feeds (other)) {
3399 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
3400 if (via_send_only) {
3401 *via_send_only = true;
3405 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
3408 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
3413 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
3418 Route::direct_feeds_according_to_graph (boost::shared_ptr<Route> other, bool* via_send_only)
3420 return _session._current_route_graph.has (boost::dynamic_pointer_cast<Route> (shared_from_this ()), other, via_send_only);
3424 Route::feeds_according_to_graph (boost::shared_ptr<Route> other)
3426 return _session._current_route_graph.feeds (boost::dynamic_pointer_cast<Route> (shared_from_this ()), other);
3429 /** Called from the (non-realtime) butler thread when the transport is stopped */
3431 Route::non_realtime_transport_stop (samplepos_t now, bool flush)
3433 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3435 Automatable::non_realtime_transport_stop (now, flush);
3437 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3439 if (!_have_internal_generator && (Config->get_plugins_stop_with_transport() && flush)) {
3443 (*i)->non_realtime_transport_stop (now, flush);
3448 Route::input_change_handler (IOChange change, void * /*src*/)
3450 if ((change.type & IOChange::ConfigurationChanged)) {
3451 /* This is called with the process lock held if change
3452 contains ConfigurationChanged
3454 configure_processors (0);
3455 _phase_control->resize (_input->n_ports().n_audio ());
3456 io_changed (); /* EMIT SIGNAL */
3459 if (_solo_control->soloed_by_others_upstream() || _solo_isolate_control->solo_isolated_by_upstream()) {
3462 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3463 if (_input->connected()) {
3464 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3465 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3469 bool does_feed = (*i)->direct_feeds_according_to_reality (boost::dynamic_pointer_cast<Route> (shared_from_this()), &sends_only);
3470 if (does_feed && !sends_only) {
3471 if ((*i)->soloed()) {
3474 if ((*i)->solo_isolate_control()->solo_isolated()) {
3481 int delta = sbou - _solo_control->soloed_by_others_upstream();
3482 int idelta = ibou - _solo_isolate_control->solo_isolated_by_upstream();
3485 PBD::warning << string_compose (
3486 _("Invalid Solo-Isolate propagation: from:%1 new:%2 - old:%3 = delta:%4"),
3487 _name, ibou, _solo_isolate_control->solo_isolated_by_upstream(), idelta)
3492 if (_solo_control->soloed_by_others_upstream()) {
3493 // ignore new connections (they're not propagated)
3495 _solo_control->mod_solo_by_others_upstream (delta);
3499 if (_solo_isolate_control->solo_isolated_by_upstream()) {
3500 // solo-isolate currently only propagates downstream
3502 _solo_isolate_control->mod_solo_isolated_by_upstream (1);
3504 //_solo_isolated_by_upstream = ibou;
3507 // Session::route_solo_changed does not propagate indirect solo-changes
3508 // propagate downstream to tracks
3509 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3510 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3514 bool does_feed = feeds (*i, &sends_only);
3515 if (delta <= 0 && does_feed && !sends_only) {
3516 (*i)->solo_control()->mod_solo_by_others_upstream (delta);
3519 if (idelta < 0 && does_feed && !sends_only) {
3520 (*i)->solo_isolate_control()->mod_solo_isolated_by_upstream (-1);
3527 Route::output_change_handler (IOChange change, void * /*src*/)
3529 if (_initial_io_setup) {
3533 if ((change.type & IOChange::ConfigurationChanged)) {
3534 /* This is called with the process lock held if change
3535 contains ConfigurationChanged
3537 configure_processors (0);
3540 _session.reset_monitor_section();
3543 io_changed (); /* EMIT SIGNAL */
3546 if ((change.type & IOChange::ConnectionsChanged)) {
3548 /* do this ONLY if connections have changed. Configuration
3549 * changes do not, by themselves alter solo upstream or
3550 * downstream status.
3553 if (_solo_control->soloed_by_others_downstream()) {
3555 /* checking all all downstream routes for
3556 * explicit of implict solo is a rather drastic measure,
3557 * ideally the input_change_handler() of the other route
3558 * would propagate the change to us.
3560 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3561 if (_output->connected()) {
3562 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3563 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3567 bool does_feed = direct_feeds_according_to_reality (*i, &sends_only);
3568 if (does_feed && !sends_only) {
3569 if ((*i)->soloed()) {
3577 int delta = sbod - _solo_control->soloed_by_others_downstream();
3579 // do not allow new connections to change implicit solo (no propagation)
3580 _solo_control->mod_solo_by_others_downstream (delta);
3581 // Session::route_solo_changed() does not propagate indirect solo-changes
3582 // propagate upstream to tracks
3583 boost::shared_ptr<Route> shared_this = boost::dynamic_pointer_cast<Route> (shared_from_this());
3584 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3585 if ((*i).get() == this || !can_solo()) {
3589 bool does_feed = (*i)->feeds (shared_this, &sends_only);
3590 if (delta != 0 && does_feed && !sends_only) {
3591 (*i)->solo_control()->mod_solo_by_others_downstream (delta);
3601 Route::sidechain_change_handler (IOChange change, void* src)
3603 if (_initial_io_setup || _in_sidechain_setup) {
3607 input_change_handler (change, src);
3611 Route::pans_required () const
3613 if (n_outputs().n_audio() < 2) {
3617 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
3621 Route::flush_processor_buffers_locked (samplecnt_t nframes)
3623 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3624 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery> (*i);
3626 d->flush_buffers (nframes);
3628 boost::shared_ptr<PortInsert> p = boost::dynamic_pointer_cast<PortInsert> (*i);
3630 p->flush_buffers (nframes);
3637 Route::flush_processors ()
3639 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3641 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3647 Route::playback_latency (bool incl_downstream) const
3651 rv = _disk_reader->output_latency ();
3653 rv = _signal_latency;
3655 if (incl_downstream) {
3656 rv += _output->connected_latency (true);
3658 rv += _output->latency ();
3664 Route::latency_preroll (pframes_t nframes, samplepos_t& start_sample, samplepos_t& end_sample)
3666 samplecnt_t latency_preroll = _session.remaining_latency_preroll ();
3667 if (latency_preroll == 0) {
3670 if (!_disk_reader) {
3671 start_sample -= latency_preroll;
3672 end_sample -= latency_preroll;
3676 if (latency_preroll > playback_latency ()) {
3677 no_roll_unlocked (nframes, start_sample - latency_preroll, end_sample - latency_preroll, false);
3681 start_sample -= latency_preroll;
3682 end_sample -= latency_preroll;
3687 Route::roll (pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, int declick, bool& need_butler)
3689 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3696 silence_unlocked (nframes);
3701 if ((nframes = latency_preroll (nframes, start_sample, end_sample)) == 0) {
3705 run_route (start_sample, end_sample, nframes, declick, (!_disk_writer || !_disk_writer->record_enabled()) && _session.transport_rolling(), true);
3707 if ((_disk_reader && _disk_reader->need_butler()) || (_disk_writer && _disk_writer->need_butler())) {
3714 Route::no_roll (pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, bool session_state_changing)
3716 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3722 return no_roll_unlocked (nframes, start_sample, end_sample, session_state_changing);
3726 Route::no_roll_unlocked (pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, bool session_state_changing)
3728 /* Must be called with the processor lock held */
3731 silence_unlocked (nframes);
3736 if (session_state_changing) {
3737 if (_session.transport_speed() != 0.0f) {
3738 /* we're rolling but some state is changing (e.g. our diskstream contents)
3739 so we cannot use them. Be silent till this is over.
3741 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
3743 silence_unlocked (nframes);
3747 /* we're really not rolling, so we're either delivery silence or actually
3748 monitoring, both of which are safe to do while session_state_changing is true.
3752 run_route (start_sample, end_sample, nframes, 0, false, false);
3757 Route::silent_roll (pframes_t nframes, samplepos_t /*start_sample*/, samplepos_t /*end_sample*/, bool& /* need_butler */)
3760 flush_processor_buffers_locked (nframes);
3765 __attribute__((annotate("realtime")))
3768 Route::apply_processor_changes_rt ()
3770 int emissions = EmitNone;
3772 if (_pending_meter_point != _meter_point) {
3773 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3775 /* meters always have buffers for 'processor_max_streams'
3776 * they can be re-positioned without re-allocation */
3777 if (set_meter_point_unlocked()) {
3778 emissions |= EmitMeterChanged | EmitMeterVisibilityChange;;
3780 emissions |= EmitMeterChanged;
3785 bool changed = false;
3787 if (g_atomic_int_get (&_pending_process_reorder)) {
3788 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3790 apply_processor_order (_pending_processor_order);
3791 setup_invisible_processors ();
3793 g_atomic_int_set (&_pending_process_reorder, 0);
3794 emissions |= EmitRtProcessorChange;
3798 set_processor_positions ();
3799 /* update processor input/output latency
3800 * (total signal_latency does not change)
3802 update_signal_latency (true);
3804 if (emissions != 0) {
3805 g_atomic_int_set (&_pending_signals, emissions);
3808 return (!selfdestruct_sequence.empty ());
3812 Route::emit_pending_signals ()
3814 int sig = g_atomic_int_and (&_pending_signals, 0);
3815 if (sig & EmitMeterChanged) {
3816 _meter->emit_configuration_changed();
3817 meter_change (); /* EMIT SIGNAL */
3818 if (sig & EmitMeterVisibilityChange) {
3819 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3821 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3824 if (sig & EmitRtProcessorChange) {
3825 processors_changed (RouteProcessorChange (RouteProcessorChange::RealTimeChange)); /* EMIT SIGNAL */
3828 /* this would be a job for the butler.
3829 * Conceptually we should not take processe/processor locks here.
3830 * OTOH its more efficient (less overhead for summoning the butler and
3831 * telling her what do do) and signal emission is called
3832 * directly after the process callback, which decreases the chance
3833 * of x-runs when taking the locks.
3835 while (!selfdestruct_sequence.empty ()) {
3836 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
3837 if (selfdestruct_sequence.empty ()) { break; } // re-check with lock
3838 boost::shared_ptr<Processor> proc = selfdestruct_sequence.back ().lock ();
3839 selfdestruct_sequence.pop_back ();
3842 remove_processor (proc);
3848 Route::set_meter_point (MeterPoint p, bool force)
3850 if (_pending_meter_point == p && !force) {
3854 if (force || !AudioEngine::instance()->running()) {
3855 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3856 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3857 _pending_meter_point = p;
3858 _meter->emit_configuration_changed();
3859 meter_change (); /* EMIT SIGNAL */
3860 if (set_meter_point_unlocked()) {
3861 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3863 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3866 _pending_meter_point = p;
3872 __attribute__((annotate("realtime")))
3875 Route::set_meter_point_unlocked ()
3878 /* Caller must hold process and processor write lock */
3879 assert (!AudioEngine::instance()->process_lock().trylock());
3880 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3881 assert (!lm.locked ());
3884 _meter_point = _pending_meter_point;
3886 bool meter_was_visible_to_user = _meter->display_to_user ();
3888 if (!_custom_meter_position_noted) {
3889 maybe_note_meter_position ();
3892 if (_meter_point != MeterCustom) {
3894 _meter->set_display_to_user (false);
3896 setup_invisible_processors ();
3899 _meter->set_display_to_user (true);
3901 /* If we have a previous position for the custom meter, try to put it there */
3902 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
3904 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), after);
3905 if (i != _processors.end ()) {
3906 _processors.remove (_meter);
3907 _processors.insert (i, _meter);
3909 } else {// at end, right before the mains_out/panner
3910 _processors.remove (_meter);
3911 ProcessorList::iterator main = _processors.end();
3912 _processors.insert (--main, _meter);
3916 /* Set up the meter for its new position */
3918 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
3922 if (loc == _processors.begin()) {
3923 m_in = _input->n_ports();
3925 ProcessorList::iterator before = loc;
3927 m_in = (*before)->output_streams ();
3930 _meter->reflect_inputs (m_in);
3932 /* we do not need to reconfigure the processors, because the meter
3933 (a) is always ready to handle processor_max_streams
3934 (b) is always an N-in/N-out processor, and thus moving
3935 it doesn't require any changes to the other processors.
3938 /* these should really be done after releasing the lock
3939 * but all those signals are subscribed to with gui_thread()
3942 return (_meter->display_to_user() != meter_was_visible_to_user);
3946 Route::listen_position_changed ()
3949 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3950 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3951 ProcessorState pstate (this);
3953 if (configure_processors_unlocked (0, &lm)) {
3954 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
3956 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
3961 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3962 _session.set_dirty ();
3965 boost::shared_ptr<CapturingProcessor>
3966 Route::add_export_point()
3968 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3969 if (!_capturing_processor) {
3971 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3972 Glib::Threads::RWLock::WriterLock lw (_processor_lock);
3974 /* Align all tracks for stem-export w/o processing.
3975 * Compensate for all plugins between the this route's disk-reader
3976 * and the common final downstream output (ie alignment point for playback).
3978 _capturing_processor.reset (new CapturingProcessor (_session, playback_latency (true)));
3979 configure_processors_unlocked (0, &lw);
3980 _capturing_processor->activate ();
3983 return _capturing_processor;
3987 Route::update_signal_latency (bool apply_to_delayline)
3989 // TODO: bail out if !active() and set/assume _signal_latency = 0,
3990 // here or in Session::* ? -> also zero send latencies,
3991 // and make sure that re-enabling a route updates things again...
3993 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3995 samplecnt_t l_in = 0;
3996 samplecnt_t l_out = _output->user_latency();
3997 for (ProcessorList::reverse_iterator i = _processors.rbegin(); i != _processors.rend(); ++i) {
3998 if (boost::shared_ptr<Send> snd = boost::dynamic_pointer_cast<Send> (*i)) {
3999 snd->set_delay_in (l_out + _output->latency());
4001 (*i)->set_output_latency (l_out);
4002 if ((*i)->active ()) {
4003 l_out += (*i)->signal_latency ();
4007 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal signal latency = %2\n", _name, l_out));
4009 _signal_latency = l_out;
4011 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4012 (*i)->set_input_latency (l_in);
4013 (*i)->set_playback_offset (_signal_latency + _output->latency ());
4014 (*i)->set_capture_offset (_input->latency ());
4015 if ((*i)->active ()) {
4016 l_in += (*i)->signal_latency ();
4022 if (apply_to_delayline) {
4023 /* see also Session::post_playback_latency() */
4024 apply_latency_compensation ();
4027 if (_signal_latency != l_out) {
4028 signal_latency_changed (); /* EMIT SIGNAL */
4031 return _signal_latency;
4035 Route::set_user_latency (samplecnt_t nframes)
4037 _output->set_user_latency (nframes);
4038 _session.update_latency_compensation ();
4042 Route::apply_latency_compensation ()
4045 samplecnt_t old = _delayline->get_delay ();
4047 samplecnt_t play_lat_in = _input->connected_latency (true);
4048 samplecnt_t play_lat_out = _output->connected_latency (true);
4049 samplecnt_t latcomp = play_lat_in - play_lat_out - _signal_latency;
4052 samplecnt_t capt_lat_in = _input->connected_latency (false);
4053 samplecnt_t capt_lat_out = _output->connected_latency (false);
4054 samplecnt_t latcomp_capt = capt_lat_out - capt_lat_in - _signal_latency;
4056 cout << "ROUTE " << name() << " delay for " << latcomp << " (c: " << latcomp_capt << ")" << endl;
4059 _delayline->set_delay (latcomp > 0 ? latcomp : 0);
4061 if (old != _delayline->get_delay ()) {
4062 signal_latency_updated (); /* EMIT SIGNAL */
4068 Route::set_block_size (pframes_t nframes)
4070 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4071 (*i)->set_block_size (nframes);
4074 _session.ensure_buffers (n_process_buffers ());
4078 Route::protect_automation ()
4080 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
4081 (*i)->protect_automation();
4084 /** @param declick 1 to set a pending declick fade-in,
4085 * -1 to set a pending declick fade-out
4088 Route::set_pending_declick (int declick)
4091 /* this call is not allowed to turn off a pending declick */
4093 _pending_declick = declick;
4096 _pending_declick = 0;
4100 /** Shift automation forwards from a particular place, thereby inserting time.
4101 * Adds undo commands for any shifts that are performed.
4103 * @param pos Position to start shifting from.
4104 * @param samples Amount to shift forwards by.
4108 Route::shift (samplepos_t pos, samplecnt_t samples)
4110 /* gain automation */
4112 boost::shared_ptr<AutomationControl> gc = _amp->gain_control();
4114 XMLNode &before = gc->alist()->get_state ();
4115 gc->alist()->shift (pos, samples);
4116 XMLNode &after = gc->alist()->get_state ();
4117 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
4120 /* gain automation */
4122 boost::shared_ptr<AutomationControl> gc = _trim->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 // TODO mute automation ??
4132 /* pan automation */
4134 ControlSet::Controls& c (_pannable->controls());
4136 for (ControlSet::Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
4137 boost::shared_ptr<AutomationControl> pc = boost::dynamic_pointer_cast<AutomationControl> (ci->second);
4139 boost::shared_ptr<AutomationList> al = pc->alist();
4140 XMLNode& before = al->get_state ();
4141 al->shift (pos, samples);
4142 XMLNode& after = al->get_state ();
4143 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4148 /* redirect automation */
4150 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4151 for (ProcessorList::iterator i = _processors.begin (); i != _processors.end (); ++i) {
4153 set<Evoral::Parameter> parameters = (*i)->what_can_be_automated();
4155 for (set<Evoral::Parameter>::const_iterator p = parameters.begin (); p != parameters.end (); ++p) {
4156 boost::shared_ptr<AutomationControl> ac = (*i)->automation_control (*p);
4158 boost::shared_ptr<AutomationList> al = ac->alist();
4159 XMLNode &before = al->get_state ();
4160 al->shift (pos, samples);
4161 XMLNode &after = al->get_state ();
4162 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4170 Route::set_plugin_state_dir (boost::weak_ptr<Processor> p, const std::string& d)
4172 boost::shared_ptr<Processor> processor (p.lock ());
4173 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
4177 pi->set_state_dir (d);
4181 Route::save_as_template (const string& path, const string& name, const string& description)
4183 std::string state_dir = path.substr (0, path.find_last_of ('.')); // strip template_suffix
4184 PBD::Unwinder<std::string> uw (_session._template_state_dir, state_dir);
4186 XMLNode& node (state (false));
4187 node.set_property (X_("name"), name);
4189 node.remove_nodes (X_("description"));
4190 if (!description.empty()) {
4191 XMLNode* desc = new XMLNode(X_("description"));
4192 XMLNode* desc_cont = new XMLNode(X_("content"), description);
4193 desc->add_child_nocopy (*desc_cont);
4195 node.add_child_nocopy (*desc);
4200 IO::set_name_in_state (*node.children().front(), name);
4202 tree.set_root (&node);
4204 /* return zero on success, non-zero otherwise */
4205 return !tree.write (path.c_str());
4210 Route::set_name (const string& str)
4216 if (str == name()) {
4220 string name = Route::ensure_track_or_route_name (str, _session);
4221 SessionObject::set_name (name);
4223 bool ret = (_input->set_name(name) && _output->set_name(name));
4226 /* rename the main outs. Leave other IO processors
4227 * with whatever name they already have, because its
4228 * just fine as it is (it will not contain the route
4229 * name if its a port insert, port send or port return).
4233 if (_main_outs->set_name (name)) {
4234 /* XXX returning false here is stupid because
4235 we already changed the route name.
4245 /** Set the name of a route in an XML description.
4246 * @param node XML <Route> node to set the name in.
4247 * @param name New name.
4250 Route::set_name_in_state (XMLNode& node, string const & name, bool rename_playlist)
4252 node.set_property (X_("name"), name);
4254 XMLNodeList children = node.children();
4255 for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
4257 if ((*i)->name() == X_("IO")) {
4259 IO::set_name_in_state (**i, name);
4261 } else if ((*i)->name() == X_("Processor")) {
4264 if ((*i)->get_property (X_("role"), str) && str == X_("Main")) {
4265 (*i)->set_property (X_("name"), name);
4268 } else if ((*i)->name() == X_("Diskstream")) {
4270 if (rename_playlist) {
4271 (*i)->set_property (X_("playlist"), name + ".1");
4273 (*i)->set_property (X_("name"), name);
4279 boost::shared_ptr<Send>
4280 Route::internal_send_for (boost::shared_ptr<const Route> target) const
4282 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4284 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4285 boost::shared_ptr<InternalSend> send;
4287 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
4288 if (send->target_route() == target) {
4294 return boost::shared_ptr<Send>();
4298 Route::set_denormal_protection (bool yn)
4300 if (_denormal_protection != yn) {
4301 _denormal_protection = yn;
4302 denormal_protection_changed (); /* EMIT SIGNAL */
4307 Route::denormal_protection () const
4309 return _denormal_protection;
4313 Route::set_active (bool yn, void* src)
4315 if (_session.transport_rolling()) {
4319 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_route_active()) {
4320 _route_group->foreach_route (boost::bind (&Route::set_active, _1, yn, _route_group));
4324 if (_active != yn) {
4326 _input->set_active (yn);
4327 _output->set_active (yn);
4328 flush_processors ();
4329 active_changed (); // EMIT SIGNAL
4330 _session.set_dirty ();
4334 boost::shared_ptr<Pannable>
4335 Route::pannable() const
4340 boost::shared_ptr<Panner>
4341 Route::panner() const
4344 return _main_outs->panner_shell()->panner();
4347 boost::shared_ptr<PannerShell>
4348 Route::panner_shell() const
4350 return _main_outs->panner_shell();
4353 boost::shared_ptr<GainControl>
4354 Route::gain_control() const
4356 return _gain_control;
4359 boost::shared_ptr<GainControl>
4360 Route::trim_control() const
4362 return _trim_control;
4365 boost::shared_ptr<PhaseControl>
4366 Route::phase_control() const
4368 return _phase_control;
4371 boost::shared_ptr<AutomationControl>
4372 Route::get_control (const Evoral::Parameter& param)
4374 /* either we own the control or .... */
4376 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
4380 /* maybe one of our processors does or ... */
4382 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
4383 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4384 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
4392 /* nobody does so we'll make a new one */
4394 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
4401 boost::shared_ptr<Processor>
4402 Route::nth_plugin (uint32_t n) const
4404 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4405 ProcessorList::const_iterator i;
4407 for (i = _processors.begin(); i != _processors.end(); ++i) {
4408 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
4415 return boost::shared_ptr<Processor> ();
4418 boost::shared_ptr<Processor>
4419 Route::nth_send (uint32_t n) const
4421 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4422 ProcessorList::const_iterator i;
4424 for (i = _processors.begin(); i != _processors.end(); ++i) {
4425 if (boost::dynamic_pointer_cast<Send> (*i)) {
4427 if ((*i)->name().find (_("Monitor")) == 0) {
4428 /* send to monitor section is not considered
4429 to be an accessible send.
4440 return boost::shared_ptr<Processor> ();
4444 Route::has_io_processor_named (const string& name)
4446 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4447 ProcessorList::iterator i;
4449 for (i = _processors.begin(); i != _processors.end(); ++i) {
4450 if (boost::dynamic_pointer_cast<Send> (*i) ||
4451 boost::dynamic_pointer_cast<PortInsert> (*i)) {
4452 if ((*i)->name() == name) {
4462 Route::set_processor_positions ()
4464 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4466 bool had_amp = false;
4467 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4468 (*i)->set_pre_fader (!had_amp);
4475 /** Called when there is a proposed change to the input port count */
4477 Route::input_port_count_changing (ChanCount to)
4479 list<pair<ChanCount, ChanCount> > c = try_configure_processors (to, 0);
4481 /* The processors cannot be configured with the new input arrangement, so
4487 /* The change is ok */
4491 /** Called when there is a proposed change to the output port count */
4493 Route::output_port_count_changing (ChanCount to)
4495 if (_strict_io && !_in_configure_processors) {
4498 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
4499 if (processor_out_streams.get(*t) > to.get(*t)) {
4503 /* The change is ok */
4508 Route::unknown_processors () const
4512 if (_session.get_disable_all_loaded_plugins ()) {
4513 // Do not list "missing plugins" if they are explicitly disabled
4517 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4518 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4519 if (boost::dynamic_pointer_cast<UnknownProcessor const> (*i)) {
4520 p.push_back ((*i)->name ());
4529 Route::update_port_latencies (PortSet& from, PortSet& to, bool playback, samplecnt_t our_latency) const
4531 /* we assume that all our input ports feed all our output ports. its not
4532 universally true, but the alternative is way too corner-case to worry about.
4535 LatencyRange all_connections;
4538 all_connections.min = 0;
4539 all_connections.max = 0;
4541 all_connections.min = ~((pframes_t) 0);
4542 all_connections.max = 0;
4544 /* iterate over all "from" ports and determine the latency range for all of their
4545 connections to the "outside" (outside of this Route).
4548 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4552 p->get_connected_latency_range (range, playback);
4554 all_connections.min = min (all_connections.min, range.min);
4555 all_connections.max = max (all_connections.max, range.max);
4559 /* set the "from" port latencies to the max/min range of all their connections */
4561 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4562 p->set_private_latency_range (all_connections, playback);
4565 /* set the ports "in the direction of the flow" to the same value as above plus our own signal latency */
4567 all_connections.min += our_latency;
4568 all_connections.max += our_latency;
4570 for (PortSet::iterator p = to.begin(); p != to.end(); ++p) {
4571 p->set_private_latency_range (all_connections, playback);
4574 return all_connections.max;
4578 Route::set_private_port_latencies (bool playback) const
4580 samplecnt_t own_latency = 0;
4582 /* Processor list not protected by lock: MUST BE CALLED FROM PROCESS THREAD
4583 OR LATENCY CALLBACK.
4585 This is called (early) from the latency callback. It computes the REAL
4586 latency associated with each port and stores the result as the "private"
4587 latency of the port. A later call to Route::set_public_port_latencies()
4588 sets all ports to the same value to reflect the fact that we do latency
4589 compensation and so all signals are delayed by the same amount as they
4590 flow through ardour.
4593 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4594 if ((*i)->active ()) {
4595 own_latency += (*i)->signal_latency ();
4600 /* playback: propagate latency from "outside the route" to outputs to inputs */
4601 return update_port_latencies (_output->ports (), _input->ports (), true, own_latency);
4603 /* capture: propagate latency from "outside the route" to inputs to outputs */
4604 return update_port_latencies (_input->ports (), _output->ports (), false, own_latency);
4609 Route::set_public_port_latencies (samplecnt_t value, bool playback) const
4611 /* this is called to set the JACK-visible port latencies, which take
4612 latency compensation into account.
4621 const PortSet& ports (_input->ports());
4622 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4623 p->set_public_latency_range (range, playback);
4628 const PortSet& ports (_output->ports());
4629 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4630 p->set_public_latency_range (range, playback);
4635 /** Put the invisible processors in the right place in _processors.
4636 * Must be called with a writer lock on _processor_lock held.
4639 __attribute__((annotate("realtime")))
4642 Route::setup_invisible_processors ()
4645 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4646 assert (!lm.locked ());
4650 /* too early to be doing this stuff */
4654 /* we'll build this new list here and then use it
4656 * TODO put the ProcessorList is on the stack for RT-safety.
4659 ProcessorList new_processors;
4660 ProcessorList::iterator dr;
4661 ProcessorList::iterator dw;
4663 /* find visible processors */
4665 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4666 if ((*i)->display_to_user ()) {
4667 new_processors.push_back (*i);
4673 ProcessorList::iterator amp = find (new_processors.begin(), new_processors.end(), _amp);
4675 if (amp == new_processors.end ()) {
4676 error << string_compose (_("Amp/Fader on Route '%1' went AWOL. Re-added."), name()) << endmsg;
4677 new_processors.push_front (_amp);
4678 amp = find (new_processors.begin(), new_processors.end(), _amp);
4681 /* and the processor after the amp */
4683 ProcessorList::iterator after_amp = amp;
4686 /* Pre-fader METER */
4688 if (_meter && _meter_point == MeterPreFader) {
4689 /* add meter just before the fader */
4690 assert (!_meter->display_to_user ());
4691 new_processors.insert (amp, _meter);
4696 assert (_main_outs);
4697 assert (!_main_outs->display_to_user ());
4698 new_processors.push_back (_main_outs);
4700 /* iterator for the main outs */
4702 ProcessorList::iterator main = new_processors.end();
4705 /* OUTPUT METERING */
4707 if (_meter && (_meter_point == MeterOutput || _meter_point == MeterPostFader)) {
4708 assert (!_meter->display_to_user ());
4710 /* add the processor just before or just after the main outs */
4712 ProcessorList::iterator meter_point = main;
4714 if (_meter_point == MeterOutput) {
4717 new_processors.insert (meter_point, _meter);
4722 if (_monitor_send && !is_monitor ()) {
4723 assert (!_monitor_send->display_to_user ());
4724 switch (Config->get_listen_position ()) {
4725 case PreFaderListen:
4726 switch (Config->get_pfl_position ()) {
4727 case PFLFromBeforeProcessors:
4728 new_processors.push_front (_monitor_send);
4730 case PFLFromAfterProcessors:
4731 new_processors.insert (amp, _monitor_send);
4734 _monitor_send->set_can_pan (false);
4736 case AfterFaderListen:
4737 switch (Config->get_afl_position ()) {
4738 case AFLFromBeforeProcessors:
4739 new_processors.insert (after_amp, _monitor_send);
4741 case AFLFromAfterProcessors:
4742 new_processors.insert (new_processors.end(), _monitor_send);
4745 _monitor_send->set_can_pan (true);
4750 /* MONITOR CONTROL */
4752 if (_monitor_control && is_monitor ()) {
4753 assert (!_monitor_control->display_to_user ());
4754 new_processors.insert (amp, _monitor_control);
4759 ProcessorList::iterator trim = new_processors.end();
4761 if (_trim->active()) {
4762 assert (!_trim->display_to_user ());
4763 new_processors.push_front (_trim);
4764 trim = new_processors.begin();
4767 /* INTERNAL RETURN */
4769 /* doing this here means that any monitor control will come after
4770 the return and trim.
4774 assert (!_intreturn->display_to_user ());
4775 new_processors.push_front (_intreturn);
4778 /* DISK READER & WRITER (for Track objects) */
4780 if (_disk_reader || _disk_writer) {
4781 switch (_disk_io_point) {
4782 case DiskIOPreFader:
4783 if (trim != new_processors.end()) {
4784 /* insert BEFORE TRIM */
4786 new_processors.insert (trim, _disk_writer);
4789 new_processors.insert (trim, _disk_reader);
4793 new_processors.push_front (_disk_writer);
4796 new_processors.push_front (_disk_reader);
4800 case DiskIOPostFader:
4801 /* insert BEFORE main outs */
4803 new_processors.insert (main, _disk_writer);
4806 new_processors.insert (main, _disk_reader);
4810 /* reader and writer are visible under this condition, so they
4811 * are not invisible and thus not handled here.
4817 /* ensure dist-writer is before disk-reader */
4818 if (_disk_reader && _disk_writer) {
4819 ProcessorList::iterator reader_pos = find (new_processors.begin(), new_processors.end(), _disk_reader);
4820 ProcessorList::iterator writer_pos = find (new_processors.begin(), new_processors.end(), _disk_writer);
4821 assert (reader_pos != new_processors.end ());
4822 assert (writer_pos != new_processors.end ());
4823 if (std::distance (new_processors.begin(), reader_pos) < std::distance (new_processors.begin(), writer_pos)) {
4824 new_processors.erase (reader_pos);
4825 assert (writer_pos == find (new_processors.begin(), new_processors.end(), _disk_writer));
4826 new_processors.insert (++writer_pos, _disk_reader);
4830 /* EXPORT PROCESSOR */
4831 if (_capturing_processor) {
4832 assert (!_capturing_processor->display_to_user ());
4833 ProcessorList::iterator reader_pos = find (new_processors.begin(), new_processors.end(), _disk_reader);
4834 if (reader_pos != new_processors.end()) {
4835 /* insert after disk-reader */
4836 new_processors.insert (++reader_pos, _capturing_processor);
4838 ProcessorList::iterator return_pos = find (new_processors.begin(), new_processors.end(), _intreturn);
4839 /* insert after return */
4840 if (return_pos != new_processors.end()) {
4841 new_processors.insert (++return_pos, _capturing_processor);
4843 new_processors.push_front (_capturing_processor);
4848 /* Polarity Invert */
4850 ProcessorList::iterator reader_pos = find (new_processors.begin(), new_processors.end(), _disk_reader);
4851 if (reader_pos != new_processors.end()) {
4852 /* insert after disk-reader */
4853 new_processors.insert (++reader_pos, _polarity);
4855 ProcessorList::iterator return_pos = find (new_processors.begin(), new_processors.end(), _intreturn);
4856 /* insert after return */
4857 if (return_pos != new_processors.end()) {
4858 new_processors.insert (++return_pos, _polarity);
4860 new_processors.push_front (_polarity);
4866 if (_meter && _meter_point == MeterInput) {
4867 /* add meter just before the disk-writer (if any)
4868 * otherwise at the top, but after the latency delayline
4869 * (perhaps it should also be after intreturn on busses ??)
4871 assert (!_meter->display_to_user ());
4872 ProcessorList::iterator writer_pos = find (new_processors.begin(), new_processors.end(), _disk_writer);
4873 if (writer_pos != new_processors.end()) {
4874 /* insert before disk-writer */
4875 new_processors.insert (writer_pos, _meter);
4877 ProcessorList::iterator return_pos = find (new_processors.begin(), new_processors.end(), _intreturn);
4878 /* insert after return */
4879 if (return_pos != new_processors.end()) {
4880 new_processors.insert (++return_pos, _meter);
4882 new_processors.push_front (_meter);
4887 if (!is_master() && !is_monitor() && !is_auditioner()) {
4888 ProcessorList::iterator reader_pos = find (new_processors.begin(), new_processors.end(), _disk_reader);
4889 if (reader_pos != new_processors.end()) {
4890 /* insert before disk-reader */
4891 new_processors.insert (reader_pos, _delayline);
4893 new_processors.push_front (_delayline);
4897 _processors = new_processors;
4899 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4900 if (!(*i)->display_to_user () && !(*i)->enabled () && (*i) != _monitor_send) {
4901 (*i)->enable (true);
4905 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: setup_invisible_processors\n", _name));
4906 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4907 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1\n", (*i)->name ()));
4914 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
4915 Glib::Threads::RWLock::ReaderLock lp (_processor_lock);
4919 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4920 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*i);
4927 /** If the meter point is `Custom', make a note of where the meter is.
4928 * This is so that if the meter point is subsequently set to something else,
4929 * and then back to custom, we can put the meter back where it was last time
4930 * custom was enabled.
4932 * Must be called with the _processor_lock held.
4935 Route::maybe_note_meter_position ()
4937 if (_meter_point != MeterCustom) {
4941 _custom_meter_position_noted = true;
4942 /* custom meter points range from after trim to before panner/main_outs
4943 * this is a limitation by the current processor UI
4945 bool seen_trim = false;
4946 _processor_after_last_custom_meter.reset();
4947 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4948 if ((*i) == _trim) {
4951 if ((*i) == _main_outs) {
4952 _processor_after_last_custom_meter = *i;
4955 if (boost::dynamic_pointer_cast<PeakMeter> (*i)) {
4957 _processor_after_last_custom_meter = _trim;
4959 ProcessorList::iterator j = i;
4961 assert(j != _processors.end ()); // main_outs should be before
4962 _processor_after_last_custom_meter = *j;
4967 assert(_processor_after_last_custom_meter.lock());
4970 boost::shared_ptr<Processor>
4971 Route::processor_by_id (PBD::ID id) const
4973 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4974 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4975 if ((*i)->id() == id) {
4980 return boost::shared_ptr<Processor> ();
4983 /** @return what we should be metering; either the data coming from the input
4984 * IO or the data that is flowing through the route.
4987 Route::metering_state () const
4989 return MeteringRoute;
4993 Route::has_external_redirects () const
4995 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4997 /* ignore inactive processors and obviously ignore the main
4998 * outs since everything has them and we don't care.
5001 if ((*i)->active() && (*i) != _main_outs && (*i)->does_routing()) {
5009 boost::shared_ptr<Processor>
5010 Route::the_instrument () const
5012 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5013 return the_instrument_unlocked ();
5016 boost::shared_ptr<Processor>
5017 Route::the_instrument_unlocked () const
5019 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5020 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
5021 if (pi && pi->plugin ()->get_info ()->is_instrument ()) {
5025 return boost::shared_ptr<Processor>();
5031 Route::non_realtime_locate (samplepos_t pos)
5033 Automatable::non_realtime_locate (pos);
5036 _pannable->non_realtime_locate (pos);
5039 #if 0 // XXX mayhaps clear delayline here (and at stop?)
5041 _delayline->flush ();
5046 //Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
5047 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5049 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5050 (*i)->non_realtime_locate (pos);
5056 Route::fill_buffers_with_input (BufferSet& bufs, boost::shared_ptr<IO> io, pframes_t nframes)
5063 * We don't currently mix MIDI input together, so we don't need the
5064 * complex logic of the audio case.
5067 n_buffers = bufs.count().n_midi ();
5069 for (i = 0; i < n_buffers; ++i) {
5071 boost::shared_ptr<MidiPort> source_port = io->midi (i);
5072 MidiBuffer& buf (bufs.get_midi (i));
5075 buf.copy (source_port->get_midi_buffer(nframes));
5077 buf.silence (nframes);
5083 n_buffers = bufs.count().n_audio();
5085 size_t n_ports = io->n_ports().n_audio();
5086 float scaling = 1.0f;
5088 if (n_ports > n_buffers) {
5089 scaling = ((float) n_buffers) / n_ports;
5092 for (i = 0; i < n_ports; ++i) {
5094 /* if there are more ports than buffers, map them onto buffers
5095 * in a round-robin fashion
5098 boost::shared_ptr<AudioPort> source_port = io->audio (i);
5099 AudioBuffer& buf (bufs.get_audio (i%n_buffers));
5101 if (i < n_buffers) {
5103 /* first time through just copy a channel into
5107 buf.read_from (source_port->get_audio_buffer (nframes), nframes);
5109 if (scaling != 1.0f) {
5110 buf.apply_gain (scaling, nframes);
5115 /* on subsequent times around, merge data from
5116 * the port with what is already there
5119 if (scaling != 1.0f) {
5120 buf.accumulate_with_gain_from (source_port->get_audio_buffer (nframes), nframes, 0, scaling);
5122 buf.accumulate_from (source_port->get_audio_buffer (nframes), nframes);
5127 /* silence any remaining buffers */
5129 for (; i < n_buffers; ++i) {
5130 AudioBuffer& buf (bufs.get_audio (i));
5131 buf.silence (nframes);
5134 /* establish the initial setup of the buffer set, reflecting what was
5135 copied into it. unless, of course, we are the auditioner, in which
5136 case nothing was fed into it from the inputs at all.
5139 if (!is_auditioner()) {
5140 bufs.set_count (io->n_ports());
5144 boost::shared_ptr<AutomationControl>
5145 Route::pan_azimuth_control() const
5148 # undef MIXBUS_PORTS_H
5149 # include "../../gtk2_ardour/mixbus_ports.h"
5150 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5152 return boost::shared_ptr<AutomationControl>();
5154 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_pan)));
5156 if (!_pannable || !panner()) {
5157 return boost::shared_ptr<AutomationControl>();
5159 return _pannable->pan_azimuth_control;
5163 boost::shared_ptr<AutomationControl>
5164 Route::pan_elevation_control() const
5166 if (Profile->get_mixbus() || !_pannable || !panner()) {
5167 return boost::shared_ptr<AutomationControl>();
5170 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5172 if (c.find (PanElevationAutomation) != c.end()) {
5173 return _pannable->pan_elevation_control;
5175 return boost::shared_ptr<AutomationControl>();
5178 boost::shared_ptr<AutomationControl>
5179 Route::pan_width_control() const
5182 if (mixbus() && _ch_pre) {
5184 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl>(_ch_pre->control(Evoral::Parameter(PluginAutomation, 0, 5)));
5187 if (Profile->get_mixbus() || !_pannable || !panner()) {
5188 return boost::shared_ptr<AutomationControl>();
5191 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5193 if (c.find (PanWidthAutomation) != c.end()) {
5194 return _pannable->pan_width_control;
5196 return boost::shared_ptr<AutomationControl>();
5199 boost::shared_ptr<AutomationControl>
5200 Route::pan_frontback_control() const
5202 if (Profile->get_mixbus() || !_pannable || !panner()) {
5203 return boost::shared_ptr<AutomationControl>();
5206 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5208 if (c.find (PanFrontBackAutomation) != c.end()) {
5209 return _pannable->pan_frontback_control;
5211 return boost::shared_ptr<AutomationControl>();
5214 boost::shared_ptr<AutomationControl>
5215 Route::pan_lfe_control() const
5217 if (Profile->get_mixbus() || !_pannable || !panner()) {
5218 return boost::shared_ptr<AutomationControl>();
5221 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5223 if (c.find (PanLFEAutomation) != c.end()) {
5224 return _pannable->pan_lfe_control;
5226 return boost::shared_ptr<AutomationControl>();
5231 Route::eq_band_cnt () const
5233 if (Profile->get_mixbus()) {
5235 if (is_master() || mixbus()) {
5244 /* Ardour has no well-known EQ object */
5249 boost::shared_ptr<AutomationControl>
5250 Route::eq_gain_controllable (uint32_t band) const
5253 boost::shared_ptr<PluginInsert> eq = ch_eq();
5256 return boost::shared_ptr<AutomationControl>();
5259 uint32_t port_number;
5260 if (is_master() || mixbus()) {
5262 case 0: port_number = 4; break;
5263 case 1: port_number = 3; break;
5264 case 2: port_number = 2; break;
5266 return boost::shared_ptr<AutomationControl>();
5271 case 0: port_number = 14; break;
5272 case 1: port_number = 12; break;
5273 case 2: port_number = 10; break;
5274 case 3: port_number = 8; break;
5276 return boost::shared_ptr<AutomationControl>();
5280 case 0: port_number = 8; break;
5281 case 1: port_number = 6; break;
5282 case 2: port_number = 4; break;
5284 return boost::shared_ptr<AutomationControl>();
5289 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5291 return boost::shared_ptr<AutomationControl>();
5294 boost::shared_ptr<AutomationControl>
5295 Route::eq_freq_controllable (uint32_t band) const
5298 if (mixbus() || is_master()) {
5299 /* no frequency controls for mixbusses or master */
5300 return boost::shared_ptr<AutomationControl>();
5303 boost::shared_ptr<PluginInsert> eq = ch_eq();
5306 return boost::shared_ptr<AutomationControl>();
5309 uint32_t port_number;
5312 case 0: port_number = 13; break; // lo
5313 case 1: port_number = 11; break; // lo mid
5314 case 2: port_number = 9; break; // hi mid
5315 case 3: port_number = 7; break; // hi
5317 return boost::shared_ptr<AutomationControl>();
5321 case 0: port_number = 7; break;
5322 case 1: port_number = 5; break;
5323 case 2: port_number = 3; break;
5325 return boost::shared_ptr<AutomationControl>();
5329 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5331 return boost::shared_ptr<AutomationControl>();
5335 boost::shared_ptr<AutomationControl>
5336 Route::eq_q_controllable (uint32_t band) const
5338 return boost::shared_ptr<AutomationControl>();
5341 boost::shared_ptr<AutomationControl>
5342 Route::eq_shape_controllable (uint32_t band) const
5345 boost::shared_ptr<PluginInsert> eq = ch_eq();
5346 if (is_master() || mixbus() || !eq) {
5347 return boost::shared_ptr<AutomationControl>();
5351 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4))); // lo bell
5354 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3))); // hi bell
5360 return boost::shared_ptr<AutomationControl>();
5363 boost::shared_ptr<AutomationControl>
5364 Route::eq_enable_controllable () const
5367 boost::shared_ptr<PluginInsert> eq = ch_eq();
5370 return boost::shared_ptr<AutomationControl>();
5373 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5375 return boost::shared_ptr<AutomationControl>();
5379 boost::shared_ptr<AutomationControl>
5380 Route::filter_freq_controllable (bool hpf) const
5383 boost::shared_ptr<PluginInsert> eq = ch_eq();
5385 if (is_master() || mixbus() || !eq) {
5386 return boost::shared_ptr<AutomationControl>();
5390 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5))); // HPF freq
5392 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5396 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 6))); // LPF freq
5398 return boost::shared_ptr<AutomationControl>();
5403 return boost::shared_ptr<AutomationControl>();
5407 boost::shared_ptr<AutomationControl>
5408 Route::filter_slope_controllable (bool) const
5410 return boost::shared_ptr<AutomationControl>();
5413 boost::shared_ptr<AutomationControl>
5414 Route::filter_enable_controllable (bool) const
5417 boost::shared_ptr<PluginInsert> eq = ch_eq();
5419 if (is_master() || mixbus() || !eq) {
5420 return boost::shared_ptr<AutomationControl>();
5423 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5425 return boost::shared_ptr<AutomationControl>();
5429 boost::shared_ptr<AutomationControl>
5430 Route::tape_drive_controllable () const
5434 if ( _ch_pre && (is_master() || mixbus()) ) {
5435 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (_ch_pre->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4)));
5439 return boost::shared_ptr<AutomationControl>();
5443 Route::eq_band_name (uint32_t band) const
5446 if (is_master() || mixbus()) {
5448 if (Profile->get_mixbus()) {
5450 case 0: return _("lo");
5451 case 1: return _("mid");
5452 case 2: return _("hi");
5453 default: return string();
5461 case 0: return _("lo");
5462 case 1: return _("lo mid");
5463 case 2: return _("hi mid");
5464 case 3: return _("hi");
5465 default: return string();
5471 boost::shared_ptr<AutomationControl>
5472 Route::comp_enable_controllable () const
5475 boost::shared_ptr<PluginInsert> comp = ch_comp();
5478 return boost::shared_ptr<AutomationControl>();
5481 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5483 return boost::shared_ptr<AutomationControl>();
5486 boost::shared_ptr<AutomationControl>
5487 Route::comp_threshold_controllable () const
5490 boost::shared_ptr<PluginInsert> comp = ch_comp();
5493 return boost::shared_ptr<AutomationControl>();
5496 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5499 return boost::shared_ptr<AutomationControl>();
5502 boost::shared_ptr<AutomationControl>
5503 Route::comp_speed_controllable () const
5506 boost::shared_ptr<PluginInsert> comp = ch_comp();
5509 return boost::shared_ptr<AutomationControl>();
5512 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3)));
5514 return boost::shared_ptr<AutomationControl>();
5517 boost::shared_ptr<AutomationControl>
5518 Route::comp_mode_controllable () const
5521 boost::shared_ptr<PluginInsert> comp = ch_comp();
5524 return boost::shared_ptr<AutomationControl>();
5527 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4)));
5529 return boost::shared_ptr<AutomationControl>();
5532 boost::shared_ptr<AutomationControl>
5533 Route::comp_makeup_controllable () const
5536 boost::shared_ptr<PluginInsert> comp = ch_comp();
5539 return boost::shared_ptr<AutomationControl>();
5542 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5)));
5544 return boost::shared_ptr<AutomationControl>();
5547 boost::shared_ptr<ReadOnlyControl>
5548 Route::comp_redux_controllable () const
5551 boost::shared_ptr<PluginInsert> comp = ch_comp();
5554 return boost::shared_ptr<ReadOnlyControl>();
5557 return comp->control_output (2);
5559 return comp->control_output (6);
5563 return boost::shared_ptr<ReadOnlyControl>();
5568 Route::comp_mode_name (uint32_t mode) const
5573 return _("Leveler");
5575 return _("Compressor");
5577 return _("Limiter");
5579 return mixbus() ? _("Sidechain") : _("Limiter");
5589 Route::comp_speed_name (uint32_t mode) const
5607 boost::shared_ptr<AutomationControl>
5608 Route::send_pan_azi_controllable (uint32_t n) const
5611 # undef MIXBUS_PORTS_H
5612 # include "../../gtk2_ardour/mixbus_ports.h"
5613 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5614 if (plug && !mixbus()) {
5615 uint32_t port_id = 0;
5618 case 0: port_id = port_channel_post_aux0_pan; break; //32c mb "pan" controls use zero-based names, unlike levels. ugh
5619 case 1: port_id = port_channel_post_aux1_pan; break;
5620 case 2: port_id = port_channel_post_aux2_pan; break;
5621 case 3: port_id = port_channel_post_aux3_pan; break;
5622 case 4: port_id = port_channel_post_aux4_pan; break;
5623 case 5: port_id = port_channel_post_aux5_pan; break;
5624 case 6: port_id = port_channel_post_aux6_pan; break;
5625 case 7: port_id = port_channel_post_aux7_pan; break;
5626 case 8: port_id = port_channel_post_aux8_pan; break;
5627 case 9: port_id = port_channel_post_aux9_pan; break;
5628 case 10: port_id = port_channel_post_aux10_pan; break;
5629 case 11: port_id = port_channel_post_aux11_pan; break;
5636 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5641 return boost::shared_ptr<AutomationControl>();
5644 boost::shared_ptr<AutomationControl>
5645 Route::send_level_controllable (uint32_t n) const
5648 # undef MIXBUS_PORTS_H
5649 # include "../../gtk2_ardour/mixbus_ports.h"
5650 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5651 if (plug && !mixbus()) {
5652 uint32_t port_id = 0;
5654 case 0: port_id = port_channel_post_aux1_level; break;
5655 case 1: port_id = port_channel_post_aux2_level; break;
5656 case 2: port_id = port_channel_post_aux3_level; break;
5657 case 3: port_id = port_channel_post_aux4_level; break;
5658 case 4: port_id = port_channel_post_aux5_level; break;
5659 case 5: port_id = port_channel_post_aux6_level; break;
5660 case 6: port_id = port_channel_post_aux7_level; break;
5661 case 7: port_id = port_channel_post_aux8_level; break;
5663 case 8: port_id = port_channel_post_aux9_level; break;
5664 case 9: port_id = port_channel_post_aux10_level; break;
5665 case 10: port_id = port_channel_post_aux11_level; break;
5666 case 11: port_id = port_channel_post_aux12_level; break;
5673 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5684 boost::shared_ptr<Send> s = boost::dynamic_pointer_cast<Send>(nth_send (n));
5686 return boost::shared_ptr<AutomationControl>();
5688 return s->gain_control ();
5691 boost::shared_ptr<AutomationControl>
5692 Route::send_enable_controllable (uint32_t n) const
5695 # undef MIXBUS_PORTS_H
5696 # include "../../gtk2_ardour/mixbus_ports.h"
5697 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5698 if (plug && !mixbus()) {
5699 uint32_t port_id = 0;
5701 case 0: port_id = port_channel_post_aux1_asgn; break;
5702 case 1: port_id = port_channel_post_aux2_asgn; break;
5703 case 2: port_id = port_channel_post_aux3_asgn; break;
5704 case 3: port_id = port_channel_post_aux4_asgn; break;
5705 case 4: port_id = port_channel_post_aux5_asgn; break;
5706 case 5: port_id = port_channel_post_aux6_asgn; break;
5707 case 6: port_id = port_channel_post_aux7_asgn; break;
5708 case 7: port_id = port_channel_post_aux8_asgn; break;
5710 case 8: port_id = port_channel_post_aux9_asgn; break;
5711 case 9: port_id = port_channel_post_aux10_asgn; break;
5712 case 10: port_id = port_channel_post_aux11_asgn; break;
5713 case 11: port_id = port_channel_post_aux12_asgn; break;
5720 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5731 /* although Ardour sends have enable/disable as part of the Processor
5732 * API, it is not exposed as a controllable.
5734 * XXX: we should fix this (make it click-free, automatable enable-control)
5736 return boost::shared_ptr<AutomationControl>();
5740 Route::send_name (uint32_t n) const
5743 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5744 if (plug && !mixbus()) {
5747 return _session.get_mixbus (n)->name();
5752 return _session.get_mixbus (n)->name();
5758 boost::shared_ptr<Processor> p = nth_send (n);
5766 boost::shared_ptr<AutomationControl>
5767 Route::master_send_enable_controllable () const
5770 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5772 return boost::shared_ptr<AutomationControl>();
5774 # undef MIXBUS_PORTS_H
5775 # include "../../gtk2_ardour/mixbus_ports.h"
5776 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_mstr_assign)));
5778 return boost::shared_ptr<AutomationControl>();
5783 Route::slaved () const
5785 if (!_gain_control) {
5788 /* just test one particular control, not all of them */
5789 return _gain_control->slaved ();
5793 Route::slaved_to (boost::shared_ptr<VCA> vca) const
5795 if (!vca || !_gain_control) {
5799 /* just test one particular control, not all of them */
5801 return _gain_control->slaved_to (vca->gain_control());
5805 Route::muted_by_others_soloing () const
5807 if (!can_be_muted_by_others ()) {
5811 return _session.soloing() && !_solo_control->soloed() && !_solo_isolate_control->solo_isolated();
5815 Route::clear_all_solo_state ()
5817 _solo_control->clear_all_solo_state ();
5820 boost::shared_ptr<AutomationControl>
5821 Route::automation_control_recurse (PBD::ID const & id) const
5823 boost::shared_ptr<AutomationControl> ac = Automatable::automation_control (id);
5829 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5831 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5832 if ((ac = (*i)->automation_control (id))) {
5837 return boost::shared_ptr<AutomationControl> ();
5841 Route::slavables () const
5843 SlavableControlList rv;
5844 rv.push_back (_gain_control);
5845 rv.push_back (_mute_control);
5846 rv.push_back (_solo_control);
5851 Route::set_disk_io_point (DiskIOPoint diop)
5853 bool display = false;
5855 cerr << "set disk io to " << enum_2_string (diop) << endl;
5866 _disk_writer->set_display_to_user (display);
5870 _disk_reader->set_display_to_user (display);
5873 const bool changed = (diop != _disk_io_point);
5875 _disk_io_point = diop;
5878 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
5879 configure_processors (0);
5882 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
5886 Route::set_loop (Location* l)
5889 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5890 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5895 #ifdef USE_TRACKS_CODE_FEATURES
5897 /* This is the Tracks version of Track::monitoring_state().
5899 * Ardour developers: try to flag or fix issues if parts of the libardour API
5900 * change in ways that invalidate this
5904 Route::monitoring_state () const
5906 /* Explicit requests */
5908 if (_monitoring != MonitorInput) {
5909 return MonitoringInput;
5912 if (_monitoring & MonitorDisk) {
5913 return MonitoringDisk;
5916 /* This is an implementation of the truth table in doc/monitor_modes.pdf;
5917 I don't think it's ever going to be too pretty too look at.
5920 // GZ: NOT USED IN TRACKS
5921 //bool const auto_input = _session.config.get_auto_input ();
5922 //bool const software_monitor = Config->get_monitoring_model() == SoftwareMonitoring;
5923 //bool const tape_machine_mode = Config->get_tape_machine_mode ();
5925 bool const roll = _session.transport_rolling ();
5926 bool const track_rec = _diskstream->record_enabled ();
5927 bool session_rec = _session.actively_recording ();
5931 if (!session_rec && roll) {
5932 return MonitoringDisk;
5934 return MonitoringInput;
5940 return MonitoringDisk;
5944 return MonitoringSilence;
5949 /* This is the Ardour/Mixbus version of Track::monitoring_state().
5951 * Tracks developers: do NOT modify this method under any circumstances.
5955 Route::monitoring_state () const
5957 if (!_disk_reader) {
5958 return MonitoringInput;
5961 /* Explicit requests */
5962 MonitorChoice m (_monitoring_control->monitoring_choice());
5964 if (m != MonitorAuto) {
5966 MonitorState ms ((MonitorState) 0);
5968 if (m & MonitorInput) {
5969 ms = MonitoringInput;
5972 if (m & MonitorDisk) {
5973 ms = MonitorState (ms | MonitoringDisk);
5979 switch (_session.config.get_session_monitoring ()) {
5981 return MonitoringDisk;
5984 return MonitoringInput;
5990 /* This is an implementation of the truth table in doc/monitor_modes.pdf;
5991 I don't think it's ever going to be too pretty too look at.
5994 bool const roll = _session.transport_rolling ();
5995 bool const track_rec = _disk_writer->record_enabled ();
5996 bool const auto_input = _session.config.get_auto_input ();
5997 bool const software_monitor = Config->get_monitoring_model() == SoftwareMonitoring;
5998 bool const tape_machine_mode = Config->get_tape_machine_mode ();
6001 /* I suspect that just use actively_recording() is good enough all the
6002 * time, but just to keep the semantics the same as they were before
6003 * sept 26th 2012, we differentiate between the cases where punch is
6004 * enabled and those where it is not.
6006 * rg: sept 30 2017: Above is not the case: punch-in/out location is
6007 * global session playhead position.
6008 * When this method is called from process_output_buffers() we need
6009 * to use delay-compensated route's process-position.
6011 * NB. Disk reader/writer may also be offset by a same amount of time.
6013 * Also keep in mind that _session.transport_rolling() is false during
6014 * pre-roll but the disk already produces output.
6019 if (_session.config.get_punch_in() || _session.config.get_punch_out()) {
6020 session_rec = _session.actively_recording ();
6022 session_rec = _session.get_record_enabled();
6027 if (!session_rec && roll && auto_input) {
6028 return MonitoringDisk;
6030 return software_monitor ? MonitoringInput : MonitoringSilence;
6035 if (tape_machine_mode) {
6037 return MonitoringDisk;
6041 if (!roll && auto_input) {
6042 return software_monitor ? MonitoringInput : MonitoringSilence;
6044 return MonitoringDisk;
6050 abort(); /* NOTREACHED */
6051 return MonitoringSilence;