2 Copyright (C) 2000 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "libardour-config.h"
29 #include <boost/algorithm/string.hpp>
31 #include "pbd/xml++.h"
32 #include "pbd/enumwriter.h"
33 #include "pbd/locale_guard.h"
34 #include "pbd/memento_command.h"
35 #include "pbd/stacktrace.h"
36 #include "pbd/types_convert.h"
37 #include "pbd/unwind.h"
39 #include "ardour/amp.h"
40 #include "ardour/audio_buffer.h"
41 #include "ardour/audio_track.h"
42 #include "ardour/audio_port.h"
43 #include "ardour/audioengine.h"
44 #include "ardour/boost_debug.h"
45 #include "ardour/buffer.h"
46 #include "ardour/buffer_set.h"
47 #include "ardour/capturing_processor.h"
48 #include "ardour/debug.h"
49 #include "ardour/delivery.h"
50 #include "ardour/disk_reader.h"
51 #include "ardour/disk_writer.h"
52 #include "ardour/event_type_map.h"
53 #include "ardour/gain_control.h"
54 #include "ardour/internal_return.h"
55 #include "ardour/internal_send.h"
56 #include "ardour/meter.h"
57 #include "ardour/delayline.h"
58 #include "ardour/midi_buffer.h"
59 #include "ardour/midi_port.h"
60 #include "ardour/midi_track.h"
61 #include "ardour/monitor_control.h"
62 #include "ardour/monitor_processor.h"
63 #include "ardour/pannable.h"
64 #include "ardour/panner.h"
65 #include "ardour/panner_shell.h"
66 #include "ardour/parameter_descriptor.h"
67 #include "ardour/phase_control.h"
68 #include "ardour/plugin_insert.h"
69 #include "ardour/polarity_processor.h"
70 #include "ardour/port.h"
71 #include "ardour/port_insert.h"
72 #include "ardour/processor.h"
73 #include "ardour/profile.h"
74 #include "ardour/revision.h"
75 #include "ardour/route.h"
76 #include "ardour/route_group.h"
77 #include "ardour/send.h"
78 #include "ardour/session.h"
79 #include "ardour/solo_control.h"
80 #include "ardour/solo_isolate_control.h"
81 #include "ardour/types_convert.h"
82 #include "ardour/unknown_processor.h"
83 #include "ardour/utils.h"
84 #include "ardour/vca.h"
89 using namespace ARDOUR;
92 PBD::Signal3<int,boost::shared_ptr<Route>, boost::shared_ptr<PluginInsert>, Route::PluginSetupOptions > Route::PluginSetup;
94 /** Base class for all routable/mixable objects (tracks and busses) */
95 Route::Route (Session& sess, string name, PresentationInfo::Flag flag, DataType default_type)
96 : Stripable (sess, name, PresentationInfo (flag))
97 , GraphNode (sess._process_graph)
98 , Muteable (sess, name)
100 , _signal_latency (0)
101 , _disk_io_point (DiskIOPreFader)
102 , _pending_process_reorder (0)
103 , _pending_signals (0)
104 , _meter_point (MeterPostFader)
105 , _pending_meter_point (MeterPostFader)
106 , _meter_type (MeterPeak)
107 , _denormal_protection (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));
191 _amp->set_owner (this);
193 _polarity.reset (new PolarityProcessor (_session, _phase_control));
194 _polarity->activate();
195 _polarity->set_owner (this);
198 _amp->set_display_name (_("Monitor"));
201 if (!is_master() && !is_monitor() && !is_auditioner()) {
202 _delayline.reset (new DelayLine (_session, name ()));
207 _trim.reset (new Amp (_session, X_("Trim"), _trim_control, false));
208 _trim->set_display_to_user (false);
210 if (dynamic_cast<AudioTrack*>(this)) {
211 /* we can't do this in the AudioTrack's constructor
212 * because _trim does not exit then
216 else if (!dynamic_cast<Track*>(this) && ! (is_monitor() || is_auditioner())) {
221 /* create standard processors: meter, main outs, monitor out;
222 they will be added to _processors by setup_invisible_processors ()
225 _meter.reset (new PeakMeter (_session, _name));
226 _meter->set_owner (this);
227 _meter->set_display_to_user (false);
230 _main_outs.reset (new Delivery (_session, _output, _pannable, _mute_master, _name, Delivery::Main));
231 _main_outs->activate ();
234 /* where we listen to tracks */
235 _intreturn.reset (new InternalReturn (_session));
236 _intreturn->activate ();
238 /* the thing that provides proper control over a control/monitor/listen bus
239 (such as per-channel cut, dim, solo, invert, etc).
241 _monitor_control.reset (new MonitorProcessor (_session));
242 _monitor_control->activate ();
244 if (_presentation_info.flags() & PresentationInfo::FoldbackBus) {
245 panner_shell()->select_panner_by_uri ("http://ardour.org/plugin/panner_balance");
248 /* now set up processor chain and invisible processors */
250 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
252 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
253 _processors.push_back (_amp);
255 if (!_session.loading()) {
256 configure_processors (0);
265 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
267 /* do this early so that we don't get incoming signals as we are going through destruction
272 /* don't use clear_processors here, as it depends on the session which may
273 be half-destroyed by now
276 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
277 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
278 (*i)->drop_references ();
281 _processors.clear ();
285 Route::ensure_track_or_route_name (string newname) const
287 while (!_session.io_name_is_legal (newname)) {
288 newname = bump_name_once (newname, ' ');
289 if (newname == name()) {
297 Route::set_trim (gain_t val, Controllable::GroupControlDisposition /* group override */)
299 // TODO route group, see set_gain()
300 // _trim_control->route_set_value (val);
303 /** Process this route for one (sub) cycle (process thread)
305 * @param bufs Scratch buffers to use for the signal path
306 * @param start_sample Initial transport sample
307 * @param end_sample Final transport sample
308 * @param nframes Number of samples to output (to ports)
310 * Note that (end_sample - start_sample) may not be equal to nframes when the
311 * transport speed isn't 1.0 (eg varispeed).
314 Route::process_output_buffers (BufferSet& bufs,
315 samplepos_t start_sample, samplepos_t end_sample, pframes_t nframes,
316 bool gain_automation_ok, bool run_disk_reader)
318 /* Caller must hold process lock */
319 assert (!AudioEngine::instance()->process_lock().trylock());
321 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
323 // can this actually happen?
324 // Places that need a WriterLock on (_processor_lock) must also take the process-lock.
325 bufs.silence (nframes, 0);
326 assert (0); // ...one way to find out.
330 /* We should offset the route-owned ctrls by the given latency, however
331 * this only affects Mute. Other route-owned controls (solo, polarity..)
332 * are not automatable.
334 * Mute has its own issues since there's not a single mute-point,
337 automation_run (start_sample, nframes);
340 _pannable->automation_run (start_sample + _signal_latency, nframes);
343 /* figure out if we're going to use gain automation */
344 if (gain_automation_ok) {
345 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
346 _amp->setup_gain_automation (
347 start_sample + _amp->output_latency (),
348 end_sample + _amp->output_latency (),
351 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
352 _trim->setup_gain_automation (
353 start_sample + _trim->output_latency (),
354 end_sample + _trim->output_latency (),
358 /* We align the playhead to output. The user hears what the clock says:
359 * When the playhead/clock says 1:00:00:00 the user will hear the audio sample
360 * at 1:00:00:00. sample_start will be [sample at] 1:00:00:00
362 * e.g. clock says Time T = 0, sample_start = 0
363 * Disk-read(play) -> latent-plugin (+10) -> fader-automation -> output (+5)
364 * -> total playback latency "disk -> out" is 15.
365 * -> at Time T= -15, the disk-reader reads sample T=0.
366 * By the Time T=0 is reached (dt=15 later) that sample is audible.
369 const double speed = (is_auditioner() ? 1.0 : _session.transport_speed ());
371 const sampleoffset_t latency_offset = _signal_latency + _output->latency ();
373 /* when rolling backwards this can become negative */
374 start_sample -= latency_offset;
375 end_sample -= latency_offset;
377 start_sample += latency_offset;
378 end_sample += latency_offset;
381 /* Note: during intial pre-roll 'start_sample' as passed as argument can be negative.
382 * Functions calling process_output_buffers() will set "run_disk_reader"
383 * to false if the pre-roll count-down is larger than playback_latency ().
385 * playback_latency() is guarnteed to be <= _signal_latency + _output->latency ()
387 assert (!_disk_reader || !run_disk_reader || start_sample >= 0 || speed < 0);
389 /* however the disk-writer may need to pick up output from other tracks
390 * during pre-roll (in particular if this route has latent effects after the disk).
392 * e.g. track 1 play -> latency A --port--> track2 capture -> latency B ---> out
393 * total pre-roll = A + B.
395 * Note the disk-writer has built-in overlap detection (it's safe to run it early)
398 bool run_disk_writer = false;
399 if (_disk_writer && speed > 0) {
400 samplecnt_t latency_preroll = _session.remaining_latency_preroll ();
401 run_disk_writer = latency_preroll < nframes + (_signal_latency + _output->latency ());
402 if (end_sample - _disk_writer->input_latency () < _session.transport_sample ()) {
403 run_disk_writer = true;
407 /* Tell main outs what to do about monitoring. We do this so that
408 * on a transition between monitoring states we get a de-clicking gain
409 * change in the _main_outs delivery, if config.get_use_monitor_fades()
412 * We override this in the case where we have an internal generator.
414 * FIXME: when punching in/out this also depends on latency compensated time
415 * for this route. monitoring_state() does not currently handle that correctly,.
417 * Also during remaining_latency_preroll, transport_rolling () is false, but
418 * we may need to monitor disk instead.
420 MonitorState ms = monitoring_state ();
421 bool silence = _have_internal_generator ? false : (ms == MonitoringSilence);
423 _main_outs->no_outs_cuz_we_no_monitor (silence);
425 /* -------------------------------------------------------------------------------------------
427 ----------------------------------------------------------------------------------------- */
428 /* XXX We'll need to protect silent inputs as well as silent disk
429 * (when not monitoring input or monitoring disk and there's no region
430 * for a longer time).
432 * ...or simply drop that feature.
434 if (_denormal_protection || Config->get_denormal_protection()) {
436 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
437 Sample* const sp = i->data();
438 for (pframes_t nx = 0; nx < nframes; ++nx) {
445 /* -------------------------------------------------------------------------------------------
447 ----------------------------------------------------------------------------------------- */
449 samplecnt_t latency = 0;
451 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
453 /* TODO check for split cycles here.
455 * start_frame, end_frame is adjusted by latency and may
460 /* if it has any inputs, make sure they match */
461 if (boost::dynamic_pointer_cast<UnknownProcessor> (*i) == 0 && (*i)->input_streams() != ChanCount::ZERO) {
462 if (bufs.count() != (*i)->input_streams()) {
464 DEBUG::Processors, string_compose (
465 "input port mismatch %1 bufs = %2 input for %3 = %4\n",
466 _name, bufs.count(), (*i)->name(), (*i)->input_streams()
473 bool re_inject_oob_data = false;
474 if ((*i) == _disk_reader) {
475 /* Well now, we've made it past the disk-writer and to the disk-reader.
476 * Time to decide what to do about monitoring.
478 * Even when not doing MonitoringDisk, we need to run the processors,
479 * so that it advances its internal buffers (IFF run_disk_reader is true).
482 if (ms == MonitoringDisk || ms == MonitoringSilence) {
483 /* this will clear out-of-band data, too (e.g. MIDI-PC, Panic etc.
484 * OOB data is written at the end of the cycle (nframes - 1),
485 * and jack does not re-order events, so we push them back later */
486 re_inject_oob_data = true;
487 bufs.silence (nframes, 0);
491 double pspeed = speed;
492 if ((!run_disk_reader && (*i) == _disk_reader) || (!run_disk_writer && (*i) == _disk_writer)) {
493 /* run with speed 0, no-roll */
498 (*i)->run (bufs, start_sample + latency, end_sample + latency, pspeed, nframes, *i != _processors.back());
500 (*i)->run (bufs, start_sample - latency, end_sample - latency, pspeed, nframes, *i != _processors.back());
503 bufs.set_count ((*i)->output_streams());
505 /* Note: plugin latency may change. While the plugin does inform the session via
506 * processor_latency_changed(). But the session may not yet have gotten around to
507 * update the actual worste-case and update this track's _signal_latency.
509 * So there can be cases where adding up all latencies may not equal _signal_latency.
511 if ((*i)->active ()) {
512 latency += (*i)->effective_latency ();
515 if (re_inject_oob_data) {
516 write_out_of_band_data (bufs, nframes);
520 if ((*i) == _delayline) {
521 latency += _delayline->delay ();
528 Route::bounce_process (BufferSet& buffers, samplepos_t start, samplecnt_t nframes,
529 boost::shared_ptr<Processor> endpoint,
530 bool include_endpoint, bool for_export, bool for_freeze)
532 /* If no processing is required, there's no need to go any further. */
533 if (!endpoint && !include_endpoint) {
537 samplecnt_t latency = bounce_get_latency(_amp, false, for_export, for_freeze);
538 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
539 _amp->setup_gain_automation (start - latency, start - latency + nframes, nframes);
541 /* trim is always at the top, for bounce no latency compensation is needed */
542 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
543 _trim->setup_gain_automation (start, start + nframes, nframes);
546 bool seen_disk_io = false;
547 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
549 if (!include_endpoint && (*i) == endpoint) {
553 if (!for_export && !seen_disk_io) {
554 if (boost::dynamic_pointer_cast<DiskReader> (*i)) {
556 buffers.set_count ((*i)->output_streams());
561 /* if we're *not* exporting, stop processing if we come across a routing processor. */
562 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
565 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
569 /* special case the panner (export outputs)
570 * Ideally we'd only run the panner, not the delivery itself...
571 * but panners need separate input/output buffers and some context
572 * (panshell, panner type, etc). AFAICT there is no ill side effect
573 * of re-using the main delivery when freewheeling/exporting a region.
575 if ((*i) == _main_outs) {
576 assert ((*i)->does_routing());
577 (*i)->run (buffers, start - latency, start - latency + nframes, 1.0, nframes, true);
578 buffers.set_count ((*i)->output_streams());
581 /* don't run any processors that do routing.
582 * Also don't bother with metering.
584 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
585 (*i)->run (buffers, start - latency, start - latency + nframes, 1.0, nframes, true);
586 buffers.set_count ((*i)->output_streams());
587 latency += (*i)->effective_latency ();
590 if ((*i) == endpoint) {
597 Route::bounce_get_latency (boost::shared_ptr<Processor> endpoint,
598 bool include_endpoint, bool for_export, bool for_freeze) const
600 samplecnt_t latency = 0;
601 if (!endpoint && !include_endpoint) {
605 bool seen_disk_io = false;
606 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
607 if (!include_endpoint && (*i) == endpoint) {
610 if (!for_export && !seen_disk_io) {
611 if (boost::dynamic_pointer_cast<DiskReader> (*i)) {
616 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
619 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
622 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
623 latency += (*i)->effective_latency ();
625 if ((*i) == endpoint) {
633 Route::bounce_get_output_streams (ChanCount &cc, boost::shared_ptr<Processor> endpoint,
634 bool include_endpoint, bool for_export, bool for_freeze) const
636 if (!endpoint && !include_endpoint) {
640 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
641 if (!include_endpoint && (*i) == endpoint) {
644 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
647 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
650 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
651 cc = (*i)->output_streams();
653 if ((*i) == endpoint) {
661 Route::n_process_buffers ()
663 return max (_input->n_ports(), processor_max_streams);
667 Route::monitor_run (samplepos_t start_sample, samplepos_t end_sample, pframes_t nframes)
669 assert (is_monitor());
670 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
671 run_route (start_sample, end_sample, nframes, true, false);
675 Route::run_route (samplepos_t start_sample, samplepos_t end_sample, pframes_t nframes, bool gain_automation_ok, bool run_disk_reader)
677 BufferSet& bufs (_session.get_route_buffers (n_process_buffers()));
679 fill_buffers_with_input (bufs, _input, nframes);
681 /* filter captured data before meter sees it */
684 if (is_monitor() && _session.listening() && !_session.is_auditioning()) {
686 /* control/monitor bus ignores input ports when something is
687 feeding the listen "stream". data will "arrive" into the
688 route from the intreturn processor element.
691 bufs.silence (nframes, 0);
694 snapshot_out_of_band_data (nframes);
695 /* append immediate messages to the first MIDI buffer (thus sending it to the first output port) */
697 write_out_of_band_data (bufs, nframes);
699 /* run processor chain */
701 process_output_buffers (bufs, start_sample, end_sample, nframes, gain_automation_ok, run_disk_reader);
703 /* map events (e.g. MIDI-CC) back to control-parameters */
704 update_controls (bufs);
706 flush_processor_buffers_locked (nframes);
710 Route::set_listen (bool yn)
713 if (_monitor_send->active() == yn) {
717 _monitor_send->activate ();
719 _monitor_send->deactivate ();
725 Route::solo_control_changed (bool, Controllable::GroupControlDisposition)
727 /* nothing to do if we're not using AFL/PFL. But if we are, we need
728 to alter the active state of the monitor send.
731 if (Config->get_solo_control_is_listen_control ()) {
732 set_listen (_solo_control->self_soloed() || _solo_control->get_masters_value());
737 Route::push_solo_isolate_upstream (int32_t delta)
739 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
741 boost::shared_ptr<RouteList> routes = _session.get_routes ();
742 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
744 if ((*i).get() == this || !(*i)->can_solo()) {
749 bool does_feed = feeds (*i, &sends_only);
751 if (does_feed && !sends_only) {
752 (*i)->solo_isolate_control()->mod_solo_isolated_by_upstream (delta);
758 Route::push_solo_upstream (int delta)
760 DEBUG_TRACE (DEBUG::Solo, string_compose("\t ... INVERT push from %1\n", _name));
761 for (FedBy::iterator i = _fed_by.begin(); i != _fed_by.end(); ++i) {
765 boost::shared_ptr<Route> sr (i->r.lock());
767 sr->solo_control()->mod_solo_by_others_downstream (-delta);
774 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
776 cerr << name << " {" << endl;
777 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
778 p != procs.end(); ++p) {
779 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << " @ " << (*p) << endl;
785 /** Supposing that we want to insert a Processor at a given Placement, return
786 * the processor to add the new one before (or 0 to add at the end).
788 boost::shared_ptr<Processor>
789 Route::before_processor_for_placement (Placement p)
791 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
793 ProcessorList::iterator loc;
796 /* generic pre-fader: insert immediately before the amp */
797 loc = find (_processors.begin(), _processors.end(), _amp);
799 /* generic post-fader: insert right before the main outs */
800 loc = find (_processors.begin(), _processors.end(), _main_outs);
803 return loc != _processors.end() ? *loc : boost::shared_ptr<Processor> ();
806 /** Supposing that we want to insert a Processor at a given index, return
807 * the processor to add the new one before (or 0 to add at the end).
809 boost::shared_ptr<Processor>
810 Route::before_processor_for_index (int index)
813 return boost::shared_ptr<Processor> ();
816 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
818 ProcessorList::iterator i = _processors.begin ();
820 while (i != _processors.end() && j < index) {
821 if ((*i)->display_to_user()) {
828 return (i != _processors.end() ? *i : boost::shared_ptr<Processor> ());
831 /** Add a processor either pre- or post-fader
832 * @return 0 on success, non-0 on failure.
835 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err, bool activation_allowed)
837 return add_processor (processor, before_processor_for_placement (placement), err, activation_allowed);
841 /** Add a processor to a route such that it ends up with a given index into the visible processors.
842 * @param index Index to add the processor at, or -1 to add at the end of the list.
843 * @return 0 on success, non-0 on failure.
846 Route::add_processor_by_index (boost::shared_ptr<Processor> processor, int index, ProcessorStreams* err, bool activation_allowed)
848 return add_processor (processor, before_processor_for_index (index), err, activation_allowed);
851 /** Add a processor to the route.
852 * @param before An existing processor in the list, or 0; the new processor will be inserted immediately before it (or at the end).
853 * @return 0 on success, non-0 on failure.
856 Route::add_processor (boost::shared_ptr<Processor> processor, boost::shared_ptr<Processor> before, ProcessorStreams* err, bool activation_allowed)
858 assert (processor != _meter);
859 assert (processor != _main_outs);
861 DEBUG_TRACE (DEBUG::Processors, string_compose (
862 "%1 adding processor %2\n", name(), processor->name()));
866 pl.push_back (processor);
867 int rv = add_processors (pl, before, err);
873 if (activation_allowed && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user ())) {
874 processor->activate ();
877 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
879 pi->update_sidechain_name ();
886 Route::processor_selfdestruct (boost::weak_ptr<Processor> wp)
888 /* We cannot destruct the processor here (usually RT-thread
889 * with various locks held - in case of sends also io_locks).
890 * Queue for deletion in low-priority thread.
892 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
893 selfdestruct_sequence.push_back (wp);
897 Route::add_processor_from_xml_2X (const XMLNode& node, int version)
899 XMLProperty const * prop;
902 boost::shared_ptr<Processor> processor;
904 /* bit of a hack: get the `placement' property from the <Redirect> tag here
905 so that we can add the processor in the right place (pre/post-fader)
908 XMLNodeList const & children = node.children ();
909 XMLNodeList::const_iterator i = children.begin ();
911 while (i != children.end() && (*i)->name() != X_("Redirect")) {
915 Placement placement = PreFader;
917 if (i != children.end()) {
918 if ((prop = (*i)->property (X_("placement"))) != 0) {
919 placement = Placement (string_2_enum (prop->value(), placement));
923 if (node.name() == "Insert") {
925 if ((prop = node.property ("type")) != 0) {
927 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
928 prop->value() == "lv2" ||
929 prop->value() == "windows-vst" ||
930 prop->value() == "mac-vst" ||
931 prop->value() == "lxvst" ||
932 prop->value() == "audiounit") {
934 if (_session.get_disable_all_loaded_plugins ()) {
935 processor.reset (new UnknownProcessor (_session, node));
937 processor.reset (new PluginInsert (_session));
938 processor->set_owner (this);
943 processor.reset (new PortInsert (_session, _pannable, _mute_master));
948 } else if (node.name() == "Send") {
950 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
951 processor.reset (new Send (_session, sendpan, _mute_master));
955 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
959 if (processor->set_state (node, version)) {
963 //A2 uses the "active" flag in the toplevel redirect node, not in the child plugin/IO
964 if (i != children.end()) {
965 if ((prop = (*i)->property (X_("active"))) != 0) {
966 if (string_to<bool> (prop->value()) && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user ()))
967 processor->activate();
969 processor->deactivate();
973 return (add_processor (processor, placement, 0, false) == 0);
976 catch (failed_constructor &err) {
977 warning << _("processor could not be created. Ignored.") << endmsg;
983 inline Route::PluginSetupOptions operator|= (Route::PluginSetupOptions& a, const Route::PluginSetupOptions& b) {
984 return a = static_cast<Route::PluginSetupOptions> (static_cast <int>(a) | static_cast<int> (b));
987 inline Route::PluginSetupOptions operator&= (Route::PluginSetupOptions& a, const Route::PluginSetupOptions& b) {
988 return a = static_cast<Route::PluginSetupOptions> (static_cast <int>(a) & static_cast<int> (b));
992 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
994 ProcessorList::iterator loc;
995 boost::shared_ptr <PluginInsert> fanout;
997 if (g_atomic_int_get (&_pending_process_reorder)) {
998 /* we need to flush any pending re-order changes */
999 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1000 apply_processor_changes_rt ();
1004 loc = find(_processors.begin(), _processors.end(), before);
1005 if (loc == _processors.end ()) {
1009 /* nothing specified - at end */
1010 loc = _processors.end ();
1013 if (others.empty()) {
1017 ProcessorList to_skip;
1019 // check if there's an instrument to replace or configure
1020 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1021 boost::shared_ptr<PluginInsert> pi;
1022 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) == 0) {
1025 if (!pi->plugin ()->get_info ()->is_instrument ()) {
1028 boost::shared_ptr<Processor> instrument = the_instrument ();
1029 ChanCount in (DataType::MIDI, 1);
1030 ChanCount out (DataType::AUDIO, 2); // XXX route's out?!
1032 PluginSetupOptions flags = None;
1034 flags |= CanReplace;
1035 in = instrument->input_streams ();
1036 out = instrument->output_streams ();
1038 if (pi->has_output_presets (in, out)) {
1042 pi->set_strict_io (_strict_io);
1044 if (is_auditioner()) {
1048 PluginSetupOptions mask = None;
1049 if (Config->get_ask_replace_instrument ()) {
1052 if (Config->get_ask_setup_instrument ()) {
1058 if (flags != None) {
1059 boost::optional<int> rv = PluginSetup (boost::dynamic_pointer_cast<Route>(shared_from_this ()), pi, flags); /* EMIT SIGNAL */
1060 int mode = rv.get_value_or (0);
1063 to_skip.push_back (*i); // don't add this one;
1066 replace_processor (instrument, *i, err);
1067 to_skip.push_back (*i);
1072 if ((mode & 5) == 4) {
1079 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1080 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1081 ProcessorState pstate (this);
1083 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1088 ProcessorList::iterator check = find (to_skip.begin(), to_skip.end(), *i);
1089 if (check != to_skip.end()) {
1093 boost::shared_ptr<PluginInsert> pi;
1095 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1096 pi->set_strict_io (_strict_io);
1100 /* Ensure that only one amp is in the list at any time */
1101 ProcessorList::iterator check = find (_processors.begin(), _processors.end(), *i);
1102 if (check != _processors.end()) {
1103 if (before == _amp) {
1104 /* Already in position; all is well */
1107 _processors.erase (check);
1112 assert (find (_processors.begin(), _processors.end(), *i) == _processors.end ());
1114 _processors.insert (loc, *i);
1115 (*i)->set_owner (this);
1118 if (configure_processors_unlocked (err, &lm)) {
1120 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
1125 if (pi && pi->has_sidechain ()) {
1126 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
1129 if ((*i)->active()) {
1130 // emit ActiveChanged() and latency_changed() if needed
1134 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1136 boost::shared_ptr<Send> send;
1137 if ((send = boost::dynamic_pointer_cast<Send> (*i))) {
1138 send->SelfDestruct.connect_same_thread (*this,
1139 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (*i)));
1143 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1144 boost::shared_ptr<PluginInsert> pi;
1146 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1147 if (pi->has_no_inputs ()) {
1148 _have_internal_generator = true;
1154 _output->unset_user_latency ();
1157 reset_instrument_info ();
1158 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1159 set_processor_positions ();
1161 if (fanout && fanout->configured ()
1162 && fanout->output_streams().n_audio() > 2
1163 && boost::dynamic_pointer_cast<PluginInsert> (the_instrument ()) == fanout) {
1164 fan_out (); /* EMIT SIGNAL */
1170 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1172 if (p == PreFader) {
1173 start = _processors.begin();
1174 end = find(_processors.begin(), _processors.end(), _amp);
1176 start = find(_processors.begin(), _processors.end(), _amp);
1178 end = _processors.end();
1182 /** Turn off all processors with a given placement
1183 * @param p Placement of processors to disable
1186 Route::disable_processors (Placement p)
1188 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1190 ProcessorList::iterator start, end;
1191 placement_range(p, start, end);
1193 for (ProcessorList::iterator i = start; i != end; ++i) {
1194 (*i)->enable (false);
1197 _session.set_dirty ();
1200 /** Turn off all redirects
1203 Route::disable_processors ()
1205 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1207 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1208 (*i)->enable (false);
1211 _session.set_dirty ();
1214 /** Turn off all redirects with a given placement
1215 * @param p Placement of redirects to disable
1218 Route::disable_plugins (Placement p)
1220 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1222 ProcessorList::iterator start, end;
1223 placement_range(p, start, end);
1225 for (ProcessorList::iterator i = start; i != end; ++i) {
1226 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1227 (*i)->enable (false);
1231 _session.set_dirty ();
1234 /** Turn off all plugins
1237 Route::disable_plugins ()
1239 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1241 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1242 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1243 (*i)->enable (false);
1247 _session.set_dirty ();
1252 Route::ab_plugins (bool forward)
1254 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1258 /* forward = turn off all active redirects, and mark them so that the next time
1259 we go the other way, we will revert them
1262 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1263 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1266 if (!(*i)->display_to_user ()) {
1270 if (boost::dynamic_pointer_cast<PluginInsert> (*i)->is_channelstrip()) {
1275 if ((*i)->enabled ()) {
1276 (*i)->enable (false);
1277 (*i)->set_next_ab_is_active (true);
1279 (*i)->set_next_ab_is_active (false);
1285 /* backward = if the redirect was marked to go active on the next ab, do so */
1287 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1288 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1291 if (!(*i)->display_to_user ()) {
1295 if (boost::dynamic_pointer_cast<PluginInsert> (*i)->is_channelstrip()) {
1300 (*i)->enable ((*i)->get_next_ab_is_active ());
1304 _session.set_dirty ();
1308 /** Remove processors with a given placement.
1309 * @param p Placement of processors to remove.
1312 Route::clear_processors (Placement p)
1314 if (!_session.engine().running()) {
1318 bool already_deleting = _session.deletion_in_progress();
1319 if (!already_deleting) {
1320 _session.set_deletion_in_progress();
1323 ProcessorList old_list = _processors;
1325 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1326 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1327 ProcessorList new_list;
1328 ProcessorStreams err;
1329 bool seen_amp = false;
1331 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1337 if (is_internal_processor (*i)) {
1339 /* you can't remove these */
1341 new_list.push_back (*i);
1348 new_list.push_back (*i);
1351 (*i)->drop_references ();
1359 (*i)->drop_references ();
1362 new_list.push_back (*i);
1369 _processors = new_list;
1370 configure_processors_unlocked (&err, &lm); // this can't fail
1372 /* drop references w/o process-lock (I/O procs may re-take it in ~IO() */
1375 processor_max_streams.reset();
1376 _have_internal_generator = false;
1377 reset_instrument_info ();
1378 set_processor_positions ();
1380 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1382 if (!already_deleting) {
1383 _session.clear_deletion_in_progress();
1388 Route::is_internal_processor (boost::shared_ptr<Processor> p) const
1390 if (p == _amp || p == _meter || p == _main_outs || p == _delayline || p == _trim || p == _polarity) {
1394 if (p == _ch_pre || p == _ch_post || p == _ch_eq || p == _ch_comp) {
1402 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err, bool need_process_lock)
1404 // TODO once the export point can be configured properly, do something smarter here
1405 if (processor == _capturing_processor) {
1406 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1407 if (need_process_lock) {
1411 _capturing_processor.reset();
1413 if (need_process_lock) {
1418 /* these can never be removed */
1420 if (is_internal_processor (processor)) {
1424 if (!_session.engine().running()) {
1428 processor_max_streams.reset();
1431 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1432 if (need_process_lock) {
1436 /* Caller must hold process lock */
1437 assert (!AudioEngine::instance()->process_lock().trylock());
1439 Glib::Threads::RWLock::WriterLock lm (_processor_lock); // XXX deadlock after export
1441 ProcessorState pstate (this);
1443 ProcessorList::iterator i;
1444 bool removed = false;
1446 for (i = _processors.begin(); i != _processors.end(); ) {
1447 if (*i == processor) {
1449 /* move along, see failure case for configure_processors()
1450 where we may need to reconfigure the processor.
1453 /* stop redirects that send signals to JACK ports
1454 from causing noise as a result of no longer being
1458 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor> (*i);
1459 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
1463 iop = pi->sidechain();
1470 i = _processors.erase (i);
1478 _output->unset_user_latency ();
1486 if (configure_processors_unlocked (err, &lm)) {
1488 /* we know this will work, because it worked before :) */
1489 configure_processors_unlocked (0, &lm);
1493 _have_internal_generator = false;
1495 for (i = _processors.begin(); i != _processors.end(); ++i) {
1496 boost::shared_ptr<PluginInsert> pi;
1498 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1499 if (pi->has_no_inputs ()) {
1500 _have_internal_generator = true;
1505 if (need_process_lock) {
1510 reset_instrument_info ();
1511 processor->drop_references ();
1512 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1513 set_processor_positions ();
1519 Route::replace_processor (boost::shared_ptr<Processor> old, boost::shared_ptr<Processor> sub, ProcessorStreams* err)
1521 /* these can never be removed */
1522 if (is_internal_processor (old)) {
1525 /* and can't be used as substitute, either */
1526 if (is_internal_processor (sub)) {
1530 /* I/Os are out, too */
1531 if (boost::dynamic_pointer_cast<IOProcessor> (old) || boost::dynamic_pointer_cast<IOProcessor> (sub)) {
1535 /* this function cannot be used to swap/reorder processors */
1536 if (find (_processors.begin(), _processors.end(), sub) != _processors.end ()) {
1540 if (!AudioEngine::instance()->running() || !old || !sub) {
1544 /* ensure that sub is not owned by another route */
1545 if (sub->owner ()) {
1550 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1551 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1552 ProcessorState pstate (this);
1554 assert (find (_processors.begin(), _processors.end(), sub) == _processors.end ());
1556 ProcessorList::iterator i;
1557 bool replaced = false;
1558 bool enable = old->enabled ();
1560 for (i = _processors.begin(); i != _processors.end(); ) {
1562 i = _processors.erase (i);
1563 _processors.insert (i, sub);
1564 sub->set_owner (this);
1577 boost::shared_ptr<PluginInsert> pi;
1578 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(sub)) != 0) {
1579 pi->set_strict_io (true);
1583 if (configure_processors_unlocked (err, &lm)) {
1585 configure_processors_unlocked (0, &lm);
1589 _have_internal_generator = false;
1591 for (i = _processors.begin(); i != _processors.end(); ++i) {
1592 boost::shared_ptr<PluginInsert> pi;
1593 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1594 if (pi->has_no_inputs ()) {
1595 _have_internal_generator = true;
1605 sub->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1606 _output->unset_user_latency ();
1609 reset_instrument_info ();
1610 old->drop_references ();
1611 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1612 set_processor_positions ();
1617 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1619 ProcessorList deleted;
1621 if (!_session.engine().running()) {
1625 processor_max_streams.reset();
1628 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1629 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1630 ProcessorState pstate (this);
1632 ProcessorList::iterator i;
1633 boost::shared_ptr<Processor> processor;
1635 for (i = _processors.begin(); i != _processors.end(); ) {
1639 /* these can never be removed */
1641 if (is_internal_processor (processor)) {
1646 /* see if its in the list of processors to delete */
1648 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1653 /* stop IOProcessors that send to JACK ports
1654 from causing noise as a result of no longer being
1658 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(processor);
1659 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
1662 iop = pi->sidechain();
1669 deleted.push_back (processor);
1670 i = _processors.erase (i);
1673 if (deleted.empty()) {
1674 /* none of those in the requested list were found */
1678 _output->unset_user_latency ();
1680 if (configure_processors_unlocked (err, &lm)) {
1682 /* we know this will work, because it worked before :) */
1683 configure_processors_unlocked (0, &lm);
1688 _have_internal_generator = false;
1690 for (i = _processors.begin(); i != _processors.end(); ++i) {
1691 boost::shared_ptr<PluginInsert> pi;
1693 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1694 if (pi->has_no_inputs ()) {
1695 _have_internal_generator = true;
1702 /* now try to do what we need to so that those that were removed will be deleted */
1704 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1705 (*i)->drop_references ();
1708 reset_instrument_info ();
1709 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1710 set_processor_positions ();
1716 Route::reset_instrument_info ()
1718 boost::shared_ptr<Processor> instr = the_instrument();
1720 _instrument_info.set_internal_instrument (instr);
1724 /** Caller must hold process lock */
1726 Route::configure_processors (ProcessorStreams* err)
1728 #ifndef PLATFORM_WINDOWS
1729 assert (!AudioEngine::instance()->process_lock().trylock());
1732 if (!_in_configure_processors) {
1733 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1734 return configure_processors_unlocked (err, &lm);
1741 Route::input_streams () const
1743 return _input->n_ports ();
1746 list<pair<ChanCount, ChanCount> >
1747 Route::try_configure_processors (ChanCount in, ProcessorStreams* err)
1749 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1751 return try_configure_processors_unlocked (in, err);
1754 list<pair<ChanCount, ChanCount> >
1755 Route::try_configure_processors_unlocked (ChanCount in, ProcessorStreams* err)
1757 // Check each processor in order to see if we can configure as requested
1759 list<pair<ChanCount, ChanCount> > configuration;
1762 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1763 DEBUG_TRACE (DEBUG::Processors, "{\n");
1765 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1767 if ((*p)->can_support_io_configuration(in, out)) {
1769 if (boost::dynamic_pointer_cast<Delivery> (*p)
1770 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main
1772 && (is_monitor() || _strict_io || Profile->get_mixbus ())) {
1773 /* with strict I/O the panner + output are forced to
1774 * follow the last processor's output.
1776 * Delivery::can_support_io_configuration() will only add ports,
1777 * but not remove excess ports.
1779 * This works because the delivery only requires
1780 * as many outputs as there are inputs.
1781 * Delivery::configure_io() will do the actual removal
1782 * by calling _output->ensure_io()
1784 if (!is_master() && _session.master_out () && in.n_audio() > 0) {
1785 /* ..but at least as many as there are master-inputs, if
1786 * the delivery is dealing with audio */
1787 // XXX this may need special-casing for mixbus (master-outputs)
1788 // and should maybe be a preference anyway ?!
1789 out = ChanCount::max (in, _session.master_out ()->n_inputs ());
1795 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID=%2 in=%3 out=%4\n",(*p)->name(), (*p)->id(), in, out));
1796 configuration.push_back(make_pair(in, out));
1799 // restriction for Monitor Section Processors
1800 if (in.n_audio() != out.n_audio() || out.n_midi() > 0) {
1801 /* Note: The Monitor follows the master-bus and has no panner.
1803 * The general idea is to only allow plugins that retain the channel-count
1804 * and plugins with MIDI in (e.g VSTs with control that will remain unconnected).
1805 * Then again 5.1 in, monitor stereo is a valid use-case.
1807 * and worse: we only refuse adding plugins *here*.
1809 * 1) stereo-master, stereo-mon, add a stereo-plugin, OK
1810 * 2) change master-bus, add a channel
1811 * 2a) monitor-secion follows
1812 * 3) monitor processors fail to re-reconfigure (stereo plugin)
1813 * 4) re-load session, monitor-processor remains unconfigured, crash.
1815 DEBUG_TRACE (DEBUG::Processors, "Monitor: Channel configuration change.\n");
1817 if (boost::dynamic_pointer_cast<InternalSend> (*p)) {
1818 // internal sends make no sense, only feedback
1819 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1820 return list<pair<ChanCount, ChanCount> > ();
1822 if (boost::dynamic_pointer_cast<PortInsert> (*p)) {
1823 /* External Sends can be problematic. one can add/remove ports
1824 * there signal leaves the DAW to external monitors anyway, so there's
1825 * no real use for allowing them here anyway.
1827 DEBUG_TRACE (DEBUG::Processors, "Monitor: No External Sends allowed.\n");
1828 return list<pair<ChanCount, ChanCount> > ();
1830 if (boost::dynamic_pointer_cast<Send> (*p)) {
1832 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1833 return list<pair<ChanCount, ChanCount> > ();
1842 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
1843 DEBUG_TRACE (DEBUG::Processors, string_compose ("---- %1 cannot support in=%2 out=%3\n", (*p)->name(), in, out));
1844 DEBUG_TRACE (DEBUG::Processors, "}\n");
1845 return list<pair<ChanCount, ChanCount> > ();
1849 DEBUG_TRACE (DEBUG::Processors, "}\n");
1851 return configuration;
1854 /** Set the input/output configuration of each processor in the processors list.
1855 * Caller must hold process lock.
1856 * Return 0 on success, otherwise configuration is impossible.
1859 Route::configure_processors_unlocked (ProcessorStreams* err, Glib::Threads::RWLock::WriterLock* lm)
1861 #ifndef PLATFORM_WINDOWS
1862 assert (!AudioEngine::instance()->process_lock().trylock());
1865 if (_in_configure_processors) {
1869 /* put invisible processors where they should be */
1870 setup_invisible_processors ();
1872 _in_configure_processors = true;
1874 list<pair<ChanCount, ChanCount> > configuration = try_configure_processors_unlocked (input_streams (), err);
1876 if (configuration.empty ()) {
1877 _in_configure_processors = false;
1882 bool seen_mains_out = false;
1883 processor_out_streams = _input->n_ports();
1884 processor_max_streams.reset();
1886 /* processor configure_io() may result in adding ports
1887 * e.g. Delivery::configure_io -> ARDOUR::IO::ensure_io ()
1889 * with jack2 adding ports results in a graph-order callback,
1890 * which calls Session::resort_routes() and eventually
1891 * Route::direct_feeds_according_to_reality()
1892 * which takes a ReaderLock (_processor_lock).
1894 * so we can't hold a WriterLock here until jack2 threading
1897 * NB. we still hold the process lock
1899 * (ardour's own engines do call graph-order from the
1900 * process-thread and hence do not have this issue; besides
1901 * merely adding ports won't trigger a graph-order, only
1902 * making connections does)
1906 // TODO check for a potential ReaderLock after ReaderLock ??
1907 Glib::Threads::RWLock::ReaderLock lr (_processor_lock);
1909 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1910 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1912 if (!(*p)->configure_io(c->first, c->second)) {
1913 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration failed\n", _name));
1914 _in_configure_processors = false;
1920 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1921 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1923 boost::shared_ptr<IOProcessor> iop;
1924 boost::shared_ptr<PluginInsert> pi;
1925 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
1926 /* plugins connected via Split or Hide Match may have more channels.
1927 * route/scratch buffers are needed for all of them
1928 * The configuration may only be a subset (both input and output)
1930 processor_max_streams = ChanCount::max(processor_max_streams, pi->required_buffers());
1932 else if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*p)) != 0) {
1933 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_input_streams());
1934 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_output_streams());
1938 if (boost::dynamic_pointer_cast<Delivery> (*p)
1939 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main) {
1940 /* main delivery will increase port count to match input.
1941 * the Delivery::Main is usually the last processor - followed only by
1944 seen_mains_out = true;
1946 if (!seen_mains_out) {
1947 processor_out_streams = out;
1956 _meter->set_max_channels (processor_max_streams);
1959 /* make sure we have sufficient scratch buffers to cope with the new processor
1962 _session.ensure_buffers (n_process_buffers ());
1964 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration complete\n", _name));
1966 _in_configure_processors = false;
1970 /** Set all visible processors to a given active state (except Fader, whose state is not changed)
1971 * @param state New active state for those processors.
1974 Route::all_visible_processors_active (bool state)
1976 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1978 if (_processors.empty()) {
1982 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1983 if (!(*i)->display_to_user() || boost::dynamic_pointer_cast<Amp> (*i)) {
1987 boost::shared_ptr<PluginInsert> pi;
1988 if (0 != (pi = boost::dynamic_pointer_cast<PluginInsert>(*i))) {
1989 if (pi->is_channelstrip ()) {
1994 (*i)->enable (state);
1997 _session.set_dirty ();
2001 Route::processors_reorder_needs_configure (const ProcessorList& new_order)
2003 /* check if re-order requires re-configuration of any processors
2004 * -> compare channel configuration for all processors
2006 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2007 ChanCount c = input_streams ();
2009 for (ProcessorList::const_iterator j = new_order.begin(); j != new_order.end(); ++j) {
2011 if (c != (*j)->input_streams()) {
2014 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2017 if ((*i)->input_streams() != c) {
2020 c = (*i)->output_streams();
2032 __attribute__((annotate("realtime")))
2035 Route::apply_processor_order (const ProcessorList& new_order)
2037 /* need to hold processor_lock; either read or write lock
2038 * and the engine process_lock.
2039 * Due to r/w lock ambiguity we can only assert the latter
2041 assert (!AudioEngine::instance()->process_lock().trylock());
2044 /* "new_order" is an ordered list of processors to be positioned according to "placement".
2045 * NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
2046 * processors in the current actual processor list that are hidden. Any visible processors
2047 * in the current list but not in "new_order" will be assumed to be deleted.
2050 /* "as_it_will_be" and "_processors" are lists of shared pointers.
2051 * actual memory usage is small, but insert/erase is not actually rt-safe :(
2052 * (note though that ::processors_reorder_needs_configure() ensured that
2053 * this function will only ever be called from the rt-thread if no processor were removed)
2055 * either way, I can't proove it, but an x-run due to re-order here is less likley
2056 * than an x-run-less 'ardour-silent cycle' both of which effectively "click".
2059 ProcessorList as_it_will_be;
2060 ProcessorList::iterator oiter;
2061 ProcessorList::const_iterator niter;
2063 oiter = _processors.begin();
2064 niter = new_order.begin();
2066 while (niter != new_order.end()) {
2068 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
2069 then append it to the temp list.
2071 Otherwise, see if the next processor in the old list is in the new list. if not,
2072 its been deleted. If its there, append it to the temp list.
2075 if (oiter == _processors.end()) {
2077 /* no more elements in the old list, so just stick the rest of
2078 the new order onto the temp list.
2081 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
2082 while (niter != new_order.end()) {
2089 if (!(*oiter)->display_to_user()) {
2091 as_it_will_be.push_back (*oiter);
2095 /* visible processor: check that its in the new order */
2097 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
2098 /* deleted: do nothing, shared_ptr<> will clean up */
2100 /* ignore this one, and add the next item from the new order instead */
2101 as_it_will_be.push_back (*niter);
2106 /* now remove from old order - its taken care of no matter what */
2107 oiter = _processors.erase (oiter);
2111 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
2113 /* If the meter is in a custom position, find it and make a rough note of its position */
2114 maybe_note_meter_position ();
2118 Route::move_instrument_down (bool postfader)
2120 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2121 ProcessorList new_order;
2122 boost::shared_ptr<Processor> instrument;
2123 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2124 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
2125 if (pi && pi->plugin ()->get_info ()->is_instrument ()) {
2127 } else if (instrument && *i == _amp) {
2129 new_order.push_back (*i);
2130 new_order.push_back (instrument);
2132 new_order.push_back (instrument);
2133 new_order.push_back (*i);
2136 new_order.push_back (*i);
2143 reorder_processors (new_order, 0);
2147 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
2149 // it a change is already queued, wait for it
2150 // (unless engine is stopped. apply immediately and proceed
2151 while (g_atomic_int_get (&_pending_process_reorder)) {
2152 if (!AudioEngine::instance()->running()) {
2153 DEBUG_TRACE (DEBUG::Processors, "offline apply queued processor re-order.\n");
2154 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2156 apply_processor_order(_pending_processor_order);
2157 setup_invisible_processors ();
2159 g_atomic_int_set (&_pending_process_reorder, 0);
2161 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2162 set_processor_positions ();
2164 // TODO rather use a semaphore or something.
2165 // but since ::reorder_processors() is called
2166 // from the GUI thread, this is fine..
2171 if (processors_reorder_needs_configure (new_order) || !AudioEngine::instance()->running()) {
2173 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2174 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2175 ProcessorState pstate (this);
2177 apply_processor_order (new_order);
2179 if (configure_processors_unlocked (err, &lm)) {
2187 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2188 set_processor_positions ();
2191 DEBUG_TRACE (DEBUG::Processors, "Queue clickless processor re-order.\n");
2192 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2194 // _pending_processor_order is protected by _processor_lock
2195 _pending_processor_order = new_order;
2196 g_atomic_int_set (&_pending_process_reorder, 1);
2199 /* update processor input/output latency
2200 * (total signal_latency does not change)
2202 update_signal_latency (true);
2208 Route::add_remove_sidechain (boost::shared_ptr<Processor> proc, bool add)
2210 if (_session.actively_recording ()) {
2214 boost::shared_ptr<PluginInsert> pi;
2215 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2219 if (pi->has_sidechain () == add) {
2220 return true; // ?? call failed, but result is as expected.
2224 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2225 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2226 if (i == _processors.end ()) {
2232 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ()); // take before Writerlock to avoid deadlock
2233 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2234 PBD::Unwinder<bool> uw (_in_sidechain_setup, true);
2236 lx.release (); // IO::add_port() and ~IO takes process lock - XXX check if this is safe
2238 if (!pi->add_sidechain ()) {
2242 if (!pi->del_sidechain ()) {
2248 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2253 pi->del_sidechain ();
2255 pi->add_sidechain ();
2256 // TODO restore side-chain's state.
2261 configure_processors_unlocked (0, &lm);
2264 if (pi->has_sidechain ()) {
2265 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
2268 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2269 _session.set_dirty ();
2274 Route::plugin_preset_output (boost::shared_ptr<Processor> proc, ChanCount outs)
2276 if (_session.actively_recording ()) {
2280 boost::shared_ptr<PluginInsert> pi;
2281 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2286 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2287 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2288 if (i == _processors.end ()) {
2294 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2295 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2297 const ChanCount& old (pi->preset_out ());
2298 if (!pi->set_preset_out (outs)) {
2299 return true; // no change, OK
2302 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2305 pi->set_preset_out (old);
2308 configure_processors_unlocked (0, &lm);
2311 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2312 _session.set_dirty ();
2317 Route::reset_plugin_insert (boost::shared_ptr<Processor> proc)
2320 return customize_plugin_insert (proc, 0, unused, unused);
2324 Route::customize_plugin_insert (boost::shared_ptr<Processor> proc, uint32_t count, ChanCount outs, ChanCount sinks)
2326 if (_session.actively_recording ()) {
2329 boost::shared_ptr<PluginInsert> pi;
2330 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2335 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2336 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2337 if (i == _processors.end ()) {
2343 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2344 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2346 bool old_cust = pi->custom_cfg ();
2347 uint32_t old_cnt = pi->get_count ();
2348 ChanCount old_chan = pi->output_streams ();
2349 ChanCount old_sinks = pi->natural_input_streams ();
2352 pi->set_custom_cfg (false);
2354 pi->set_custom_cfg (true);
2355 pi->set_count (count);
2356 pi->set_outputs (outs);
2357 pi->set_sinks (sinks);
2360 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2364 pi->set_count (old_cnt);
2365 pi->set_sinks (old_sinks);
2366 pi->set_outputs (old_chan);
2367 pi->set_custom_cfg (old_cust);
2371 configure_processors_unlocked (0, &lm);
2374 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2375 _session.set_dirty ();
2380 Route::set_strict_io (const bool enable)
2382 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2384 if (_strict_io != enable) {
2385 _strict_io = enable;
2386 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2387 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2388 boost::shared_ptr<PluginInsert> pi;
2389 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2390 pi->set_strict_io (_strict_io);
2394 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2398 _strict_io = !enable; // restore old value
2399 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2400 boost::shared_ptr<PluginInsert> pi;
2401 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2402 pi->set_strict_io (_strict_io);
2409 configure_processors (0);
2412 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2413 _session.set_dirty ();
2421 return state (false);
2425 Route::get_template()
2427 return state (true);
2431 Route::state (bool save_template)
2433 if (!_session._template_state_dir.empty()) {
2434 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), _session._template_state_dir));
2437 XMLNode *node = new XMLNode("Route");
2438 ProcessorList::iterator i;
2441 XMLNode* child = node->add_child("ProgramVersion");
2442 child->set_property("created-with", _session.created_with);
2444 std::string modified_with = string_compose ("%1 %2", PROGRAM_NAME, revision);
2445 child->set_property("modified-with", modified_with);
2448 node->set_property (X_("id"), id ());
2449 node->set_property (X_("name"), name());
2450 node->set_property (X_("default-type"), _default_type);
2451 node->set_property (X_("strict-io"), _strict_io);
2453 node->add_child_nocopy (_presentation_info.get_state());
2455 node->set_property (X_("active"), _active);
2456 node->set_property (X_("denormal-protection"), _denormal_protection);
2457 node->set_property (X_("meter-point"), _meter_point);
2458 node->set_property (X_("disk-io-point"), _disk_io_point);
2460 node->set_property (X_("meter-type"), _meter_type);
2463 node->set_property (X_("route-group"), _route_group->name());
2466 node->add_child_nocopy (_solo_control->get_state ());
2467 node->add_child_nocopy (_solo_isolate_control->get_state ());
2468 node->add_child_nocopy (_solo_safe_control->get_state ());
2470 node->add_child_nocopy (_input->get_state ());
2471 node->add_child_nocopy (_output->get_state ());
2472 node->add_child_nocopy (_mute_master->get_state ());
2474 node->add_child_nocopy (_mute_control->get_state ());
2475 node->add_child_nocopy (_phase_control->get_state ());
2477 if (!skip_saving_automation) {
2478 node->add_child_nocopy (Automatable::get_automation_xml_state ());
2481 if (_comment.length()) {
2482 XMLNode *cmt = node->add_child ("Comment");
2483 cmt->add_content (_comment);
2487 node->add_child_nocopy (_pannable->get_state ());
2491 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2492 for (i = _processors.begin(); i != _processors.end(); ++i) {
2493 if (*i == _delayline) {
2496 if (save_template) {
2497 /* template save: do not include internal sends functioning as
2498 aux sends because the chance of the target ID
2499 in the session where this template is used
2502 similarly, do not save listen sends which connect to
2503 the monitor section, because these will always be
2506 boost::shared_ptr<InternalSend> is;
2508 if ((is = boost::dynamic_pointer_cast<InternalSend> (*i)) != 0) {
2509 if (is->role() == Delivery::Listen) {
2514 node->add_child_nocopy((*i)->get_state ());
2519 node->add_child_copy (*_extra_xml);
2522 if (_custom_meter_position_noted) {
2523 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
2525 node->set_property (X_("processor-after-last-custom-meter"), after->id());
2529 if (!_session._template_state_dir.empty()) {
2530 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), ""));
2533 node->add_child_copy (Slavable::get_state());
2539 Route::set_state (const XMLNode& node, int version)
2541 if (version < 3000) {
2542 return set_state_2X (node, version);
2546 XMLNodeConstIterator niter;
2549 if (node.name() != "Route"){
2550 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2554 std::string route_name;
2555 if (node.get_property (X_("name"), route_name)) {
2556 Route::set_name (route_name);
2560 _initial_io_setup = true;
2562 Stripable::set_state (node, version);
2564 node.get_property (X_("strict-io"), _strict_io);
2567 /* monitor bus does not get a panner, but if (re)created
2568 via XML, it will already have one by the time we
2569 call ::set_state(). so ... remove it.
2574 /* add all processors (except amp, which is always present) */
2576 nlist = node.children();
2577 XMLNode processor_state (X_("processor_state"));
2579 Stateful::save_extra_xml (node);
2581 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2585 if (child->name() == IO::state_node_name) {
2586 std::string direction;
2587 if (!child->get_property (X_("direction"), direction)) {
2591 if (direction == "Input") {
2592 _input->set_state (*child, version);
2593 } else if (direction == "Output") {
2594 _output->set_state (*child, version);
2597 } else if (child->name() == X_("Processor")) {
2598 processor_state.add_child_copy (*child);
2599 } else if (child->name() == X_("Pannable")) {
2601 _pannable->set_state (*child, version);
2603 warning << string_compose (_("Pannable state found for route (%1) without a panner!"), name()) << endmsg;
2605 } else if (child->name() == Slavable::xml_node_name) {
2606 Slavable::set_state (*child, version);
2611 if (node.get_property (X_("meter-point"), mp)) {
2612 set_meter_point (mp, true);
2614 _meter->set_display_to_user (_meter_point == MeterCustom);
2619 if (node.get_property (X_("disk-io-point"), diop)) {
2621 _disk_writer->set_display_to_user (diop == DiskIOCustom);
2624 _disk_reader->set_display_to_user (diop == DiskIOCustom);
2626 set_disk_io_point (diop);
2629 node.get_property (X_("meter-type"), _meter_type);
2631 _initial_io_setup = false;
2633 set_processor_state (processor_state);
2635 // this looks up the internal instrument in processors
2636 reset_instrument_info();
2638 bool denormal_protection;
2639 if (node.get_property (X_("denormal-protection"), denormal_protection)) {
2640 set_denormal_protection (denormal_protection);
2643 /* convert old 3001 state */
2644 std::string phase_invert_str;
2645 if (node.get_property (X_("phase-invert"), phase_invert_str)) {
2646 _phase_control->set_phase_invert (boost::dynamic_bitset<> (phase_invert_str));
2650 if (node.get_property (X_("active"), is_active)) {
2651 set_active (is_active, this);
2654 std::string id_string;
2655 if (node.get_property (X_("processor-after-last-custom-meter"), id_string)) {
2656 PBD::ID id (id_string);
2657 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2658 ProcessorList::const_iterator i = _processors.begin ();
2659 while (i != _processors.end() && (*i)->id() != id) {
2663 if (i != _processors.end ()) {
2664 _processor_after_last_custom_meter = *i;
2665 _custom_meter_position_noted = true;
2669 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2672 if (child->name() == X_("Comment")) {
2674 /* XXX this is a terrible API design in libxml++ */
2676 XMLNode *cmt = *(child->children().begin());
2677 _comment = cmt->content();
2679 } else if (child->name() == Controllable::xml_node_name) {
2680 std::string control_name;
2681 if (!child->get_property (X_("name"), control_name)) {
2685 if (control_name == _solo_control->name()) {
2686 _solo_control->set_state (*child, version);
2687 } else if (control_name == _solo_safe_control->name()) {
2688 _solo_safe_control->set_state (*child, version);
2689 } else if (control_name == _solo_isolate_control->name()) {
2690 _solo_isolate_control->set_state (*child, version);
2691 } else if (control_name == _mute_control->name()) {
2692 _mute_control->set_state (*child, version);
2693 } else if (control_name == _phase_control->name()) {
2694 _phase_control->set_state (*child, version);
2696 Evoral::Parameter p = EventTypeMap::instance().from_symbol (control_name);
2697 if (p.type () >= MidiCCAutomation && p.type () < MidiSystemExclusiveAutomation) {
2698 boost::shared_ptr<AutomationControl> ac = automation_control (p, true);
2700 ac->set_state (*child, version);
2704 } else if (child->name() == MuteMaster::xml_node_name) {
2705 _mute_master->set_state (*child, version);
2707 } else if (child->name() == Automatable::xml_node_name) {
2708 set_automation_xml_state (*child, Evoral::Parameter(NullAutomation));
2713 _delayline->set_name (name ());
2720 Route::set_state_2X (const XMLNode& node, int version)
2724 XMLNodeConstIterator niter;
2726 XMLProperty const * prop;
2728 /* 2X things which still remain to be handled:
2734 if (node.name() != "Route") {
2735 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2739 Stripable::set_state (node, version);
2741 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2742 set_denormal_protection (string_to<bool> (prop->value()));
2745 if ((prop = node.property (X_("muted"))) != 0) {
2748 bool muted = string_to<bool> (prop->value());
2754 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2756 if (string_to<bool> (prop->value())){
2757 mute_point = mute_point + "PreFader";
2762 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2764 if (string_to<bool> (prop->value())){
2767 mute_point = mute_point + ",";
2770 mute_point = mute_point + "PostFader";
2775 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2777 if (string_to<bool> (prop->value())){
2780 mute_point = mute_point + ",";
2783 mute_point = mute_point + "Listen";
2788 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2790 if (string_to<bool> (prop->value())){
2793 mute_point = mute_point + ",";
2796 mute_point = mute_point + "Main";
2800 _mute_master->set_mute_points (mute_point);
2801 _mute_master->set_muted_by_self (true);
2805 if ((prop = node.property (X_("meter-point"))) != 0) {
2806 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2811 nlist = node.children ();
2812 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2816 if (child->name() == IO::state_node_name) {
2818 /* there is a note in IO::set_state_2X() about why we have to call
2822 _input->set_state_2X (*child, version, true);
2823 _output->set_state_2X (*child, version, false);
2825 if ((prop = child->property (X_("name"))) != 0) {
2826 Route::set_name (prop->value ());
2831 if ((prop = child->property (X_("active"))) != 0) {
2832 bool yn = string_to<bool> (prop->value());
2833 _active = !yn; // force switch
2834 set_active (yn, this);
2837 if ((prop = child->property (X_("gain"))) != 0) {
2840 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
2841 _amp->gain_control()->set_value (val, Controllable::NoGroup);
2845 /* Set up Panners in the IO */
2846 XMLNodeList io_nlist = child->children ();
2848 XMLNodeConstIterator io_niter;
2851 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
2853 io_child = *io_niter;
2855 if (io_child->name() == X_("Panner")) {
2856 _main_outs->panner_shell()->set_state(*io_child, version);
2857 } else if (io_child->name() == X_("Automation")) {
2858 /* IO's automation is for the fader */
2859 _amp->set_automation_xml_state (*io_child, Evoral::Parameter (GainAutomation));
2865 XMLNodeList redirect_nodes;
2867 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2871 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2872 redirect_nodes.push_back(child);
2877 set_processor_state_2X (redirect_nodes, version);
2879 Stateful::save_extra_xml (node);
2881 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2884 if (child->name() == X_("Comment")) {
2886 /* XXX this is a terrible API design in libxml++ */
2888 XMLNode *cmt = *(child->children().begin());
2889 _comment = cmt->content();
2891 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2892 if (prop->value() == X_("solo")) {
2893 _solo_control->set_state (*child, version);
2894 } else if (prop->value() == X_("mute")) {
2895 _mute_control->set_state (*child, version);
2905 Route::get_processor_state ()
2907 XMLNode* root = new XMLNode (X_("redirects"));
2908 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2909 root->add_child_nocopy ((*i)->get_state ());
2916 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2918 /* We don't bother removing existing processors not in nList, as this
2919 method will only be called when creating a Route from scratch, not
2920 for undo purposes. Just put processors in at the appropriate place
2924 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2925 add_processor_from_xml_2X (**i, version);
2930 Route::set_processor_state (const XMLNode& node)
2932 const XMLNodeList &nlist = node.children();
2933 XMLNodeConstIterator niter;
2934 ProcessorList new_order;
2935 bool must_configure = false;
2937 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2939 XMLProperty* prop = (*niter)->property ("type");
2941 if (prop->value() == "amp") {
2942 _amp->set_state (**niter, Stateful::current_state_version);
2943 new_order.push_back (_amp);
2944 } else if (prop->value() == "trim") {
2945 _trim->set_state (**niter, Stateful::current_state_version);
2946 new_order.push_back (_trim);
2947 } else if (prop->value() == "meter") {
2948 _meter->set_state (**niter, Stateful::current_state_version);
2949 new_order.push_back (_meter);
2950 } else if (prop->value() == "polarity") {
2951 _polarity->set_state (**niter, Stateful::current_state_version);
2952 new_order.push_back (_polarity);
2953 } else if (prop->value() == "delay") {
2955 } else if (prop->value() == "main-outs") {
2956 _main_outs->set_state (**niter, Stateful::current_state_version);
2957 } else if (prop->value() == "intreturn") {
2959 _intreturn.reset (new InternalReturn (_session));
2960 must_configure = true;
2962 _intreturn->set_state (**niter, Stateful::current_state_version);
2963 } else if (is_monitor() && prop->value() == "monitor") {
2964 if (!_monitor_control) {
2965 _monitor_control.reset (new MonitorProcessor (_session));
2966 must_configure = true;
2968 _monitor_control->set_state (**niter, Stateful::current_state_version);
2969 } else if (prop->value() == "capture") {
2970 /* CapturingProcessor should never be restored, it's always
2971 added explicitly when needed */
2972 } else if (prop->value() == "diskreader" && _disk_reader) {
2973 _disk_reader->set_state (**niter, Stateful::current_state_version);
2974 new_order.push_back (_disk_reader);
2975 } else if (prop->value() == "diskwriter" && _disk_writer) {
2976 _disk_writer->set_state (**niter, Stateful::current_state_version);
2977 new_order.push_back (_disk_writer);
2979 set_processor_state (**niter, prop, new_order, must_configure);
2983 ProcessorList old_list = _processors; // keep a copy
2985 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2986 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2987 /* re-assign _processors w/o process-lock.
2988 * if there's an IO-processor present in _processors but
2989 * not in new_order, it will be deleted and ~IO takes
2992 _processors = new_order;
2994 /* When a required/existing internal processor is not in the list, it needs to
2995 * be added via configure_processors() -> setup_invisible_processors()
2997 if (_monitor_control) {
2998 must_configure |= find (_processors.begin(), _processors.end(), _monitor_control) == _processors.end ();
3001 must_configure |= find (_processors.begin(), _processors.end(), _main_outs) == _processors.end ();
3004 must_configure |= find (_processors.begin(), _processors.end(), _delayline) == _processors.end ();
3007 must_configure |= find (_processors.begin(), _processors.end(), _intreturn) == _processors.end ();
3010 if (must_configure && !_session.loading()) {
3011 configure_processors_unlocked (0, &lm);
3014 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3016 (*i)->set_owner (this);
3017 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
3019 boost::shared_ptr<PluginInsert> pi;
3021 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
3022 if (pi->has_no_inputs ()) {
3023 _have_internal_generator = true;
3029 /* drop references w/o process-lock (I/O procs may re-take it in ~IO() */
3032 reset_instrument_info ();
3033 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3034 set_processor_positions ();
3038 Route::set_processor_state (XMLNode const & node, XMLProperty const* prop, ProcessorList& new_order, bool& must_configure)
3040 ProcessorList::iterator o;
3042 for (o = _processors.begin(); o != _processors.end(); ++o) {
3043 XMLProperty const * id_prop = node.property(X_("id"));
3044 if (id_prop && (*o)->id() == id_prop->value()) {
3045 (*o)->set_state (node, Stateful::current_state_version);
3046 new_order.push_back (*o);
3051 // If the processor (node) is not on the route then create it
3053 if (o == _processors.end()) {
3055 boost::shared_ptr<Processor> processor;
3057 if (prop->value() == "intsend") {
3059 processor.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), boost::shared_ptr<Route>(), Delivery::Aux, true));
3061 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
3062 prop->value() == "lv2" ||
3063 prop->value() == "windows-vst" ||
3064 prop->value() == "mac-vst" ||
3065 prop->value() == "lxvst" ||
3066 prop->value() == "luaproc" ||
3067 prop->value() == "audiounit") {
3069 if (_session.get_disable_all_loaded_plugins ()) {
3070 processor.reset (new UnknownProcessor (_session, node));
3072 processor.reset (new PluginInsert (_session));
3073 processor->set_owner (this);
3075 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
3076 pi->set_strict_io (true);
3080 } else if (prop->value() == "port") {
3082 processor.reset (new PortInsert (_session, _pannable, _mute_master));
3084 } else if (prop->value() == "send") {
3086 processor.reset (new Send (_session, _pannable, _mute_master, Delivery::Send, true));
3087 boost::shared_ptr<Send> send = boost::dynamic_pointer_cast<Send> (processor);
3088 send->SelfDestruct.connect_same_thread (*this,
3089 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (processor)));
3092 warning << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
3096 if (processor->set_state (node, Stateful::current_state_version) != 0) {
3097 /* This processor could not be configured. Turn it into a UnknownProcessor */
3098 processor.reset (new UnknownProcessor (_session, node));
3101 /* subscribe to Sidechain IO changes */
3102 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
3103 if (pi && pi->has_sidechain ()) {
3104 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
3107 /* we have to note the monitor send here, otherwise a new one will be created
3108 and the state of this one will be lost.
3110 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
3111 if (isend && isend->role() == Delivery::Listen) {
3112 _monitor_send = isend;
3115 /* it doesn't matter if invisible processors are added here, as they
3116 will be sorted out by setup_invisible_processors () shortly.
3119 new_order.push_back (processor);
3120 must_configure = true;
3126 Route::silence (samplecnt_t nframes)
3128 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3133 silence_unlocked (nframes);
3137 Route::silence_unlocked (samplecnt_t nframes)
3139 /* Must be called with the processor lock held */
3141 const samplepos_t now = _session.transport_sample ();
3143 _output->silence (nframes);
3145 // update owned automated controllables
3146 automation_run (now, nframes);
3148 _pannable->automation_run (now, nframes);
3151 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3152 boost::shared_ptr<PluginInsert> pi;
3154 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
3155 /* evaluate automated automation controls */
3156 pi->automation_run (now, nframes);
3157 /* skip plugins, they don't need anything when we're not active */
3161 (*i)->silence (nframes, now);
3166 Route::add_internal_return ()
3169 _intreturn.reset (new InternalReturn (_session));
3170 add_processor (_intreturn, PreFader);
3175 Route::add_send_to_internal_return (InternalSend* send)
3177 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3179 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3180 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3183 return d->add_send (send);
3189 Route::remove_send_from_internal_return (InternalSend* send)
3191 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3193 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3194 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3197 return d->remove_send (send);
3203 Route::enable_monitor_send ()
3205 /* Caller must hold process lock */
3206 assert (!AudioEngine::instance()->process_lock().trylock());
3208 /* master never sends to monitor section via the normal mechanism */
3209 assert (!is_master ());
3210 assert (!is_monitor ());
3212 /* make sure we have one */
3213 if (!_monitor_send) {
3214 _monitor_send.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), _session.monitor_out(), Delivery::Listen));
3215 _monitor_send->set_display_to_user (false);
3219 configure_processors (0);
3222 /** Add an aux send to a route.
3223 * @param route route to send to.
3224 * @param before Processor to insert before, or 0 to insert at the end.
3227 Route::add_aux_send (boost::shared_ptr<Route> route, boost::shared_ptr<Processor> before)
3229 assert (route != _session.monitor_out ());
3232 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3234 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3236 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend> (*x);
3238 if (d && d->target_route() == route) {
3239 /* already listening via the specified IO: do nothing */
3247 boost::shared_ptr<InternalSend> listener;
3250 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
3251 listener.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), route, Delivery::Aux));
3254 add_processor (listener, before);
3256 } catch (failed_constructor& err) {
3264 Route::add_foldback_send (boost::shared_ptr<Route> route)
3266 assert (route != _session.monitor_out ());
3267 boost::shared_ptr<Processor> before = before_processor_for_placement (PreFader);
3270 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3272 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3274 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend> (*x);
3276 if (d && d->target_route() == route) {
3277 /* already listening via the specified IO: do nothing */
3285 boost::shared_ptr<InternalSend> listener;
3288 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
3289 listener.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), route, Delivery::Foldback));
3292 listener->panner_shell()->set_linked_to_route (false);
3293 listener->panner_shell()->select_panner_by_uri ("http://ardour.org/plugin/panner_balance");
3294 add_processor (listener, before);
3296 } catch (failed_constructor& err) {
3304 Route::remove_aux_or_listen (boost::shared_ptr<Route> route)
3306 ProcessorStreams err;
3307 ProcessorList::iterator tmp;
3310 Glib::Threads::RWLock::ReaderLock rl(_processor_lock);
3312 /* have to do this early because otherwise processor reconfig
3313 * will put _monitor_send back in the list
3316 if (route == _session.monitor_out()) {
3317 _monitor_send.reset ();
3321 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3323 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
3325 if (d && d->target_route() == route) {
3327 if (remove_processor (*x, &err, false) > 0) {
3333 /* list could have been demolished while we dropped the lock
3336 if (_session.engine().running()) {
3337 /* i/o processors cannot be removed if the engine is not running
3338 * so don't live-loop in case the engine is N/A or dies
3348 Route::set_comment (string cmt, void *src)
3352 _session.set_dirty ();
3356 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
3358 FeedRecord fr (other, via_sends_only);
3360 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
3362 if (!result.second) {
3364 /* already a record for "other" - make sure sends-only information is correct */
3365 if (!via_sends_only && result.first->sends_only) {
3366 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
3367 frp->sends_only = false;
3371 return result.second;
3375 Route::clear_fed_by ()
3381 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
3383 const FedBy& fed_by (other->fed_by());
3385 for (FedBy::const_iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
3386 boost::shared_ptr<Route> sr = f->r.lock();
3388 if (sr && (sr.get() == this)) {
3390 if (via_sends_only) {
3391 *via_sends_only = f->sends_only;
3402 Route::all_inputs () const
3404 /* TODO, if this works as expected,
3405 * cache the IOVector and maintain it via
3406 * input_change_handler(), sidechain_change_handler() etc
3409 ios.push_back (_input);
3411 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3412 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3414 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3415 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3418 iop = pi->sidechain();
3421 if (iop != 0 && iop->input()) {
3422 ios.push_back (iop->input());
3429 Route::all_outputs () const
3432 // _output is included via Delivery
3433 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3434 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3435 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3436 if (iop != 0 && iop->output()) {
3437 ios.push_back (iop->output());
3444 Route::direct_feeds_according_to_reality (boost::shared_ptr<Route> other, bool* via_send_only)
3446 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds from %1 (-> %2)?\n", _name, other->name()));
3447 if (other->all_inputs().fed_by (_output)) {
3448 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS to %1\n", other->name()));
3449 if (via_send_only) {
3450 *via_send_only = false;
3456 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3458 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
3460 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3461 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3464 iop = pi->sidechain();
3468 boost::shared_ptr<const IO> iop_out = iop->output();
3469 if (other.get() == this && iop_out && iop->input() && iop_out->connected_to (iop->input())) {
3470 // TODO this needs a delaylines in the Insert to align connections (!)
3471 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed its own return (%2)\n", iop->name(), other->name()));
3474 if ((iop_out && other->all_inputs().fed_by (iop_out)) || iop->feeds (other)) {
3475 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
3476 if (via_send_only) {
3477 *via_send_only = true;
3481 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
3486 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
3491 Route::direct_feeds_according_to_graph (boost::shared_ptr<Route> other, bool* via_send_only)
3493 return _session._current_route_graph.has (boost::dynamic_pointer_cast<Route> (shared_from_this ()), other, via_send_only);
3497 Route::feeds_according_to_graph (boost::shared_ptr<Route> other)
3499 return _session._current_route_graph.feeds (boost::dynamic_pointer_cast<Route> (shared_from_this ()), other);
3502 /** Called from the (non-realtime) butler thread when the transport is stopped */
3504 Route::non_realtime_transport_stop (samplepos_t now, bool flush)
3506 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3508 Automatable::non_realtime_transport_stop (now, flush);
3510 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3512 if (!_have_internal_generator && (Config->get_plugins_stop_with_transport() && flush)) {
3516 (*i)->non_realtime_transport_stop (now, flush);
3521 Route::realtime_handle_transport_stopped ()
3523 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3525 /* currently only by Plugin, queue note-off events */
3526 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3527 (*i)->realtime_handle_transport_stopped ();
3533 Route::input_change_handler (IOChange change, void * /*src*/)
3535 if (_session.loading()) {
3539 if ((change.type & IOChange::ConfigurationChanged)) {
3540 /* This is called with the process lock held if change
3541 contains ConfigurationChanged
3543 configure_processors (0);
3544 io_changed (); /* EMIT SIGNAL */
3547 if (_solo_control->soloed_by_others_upstream() || _solo_isolate_control->solo_isolated_by_upstream()) {
3550 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3551 if (_input->connected()) {
3552 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3553 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3557 bool does_feed = (*i)->direct_feeds_according_to_reality (boost::dynamic_pointer_cast<Route> (shared_from_this()), &sends_only);
3558 if (does_feed && !sends_only) {
3559 if ((*i)->soloed()) {
3562 if ((*i)->solo_isolate_control()->solo_isolated()) {
3569 int delta = sbou - _solo_control->soloed_by_others_upstream();
3570 int idelta = ibou - _solo_isolate_control->solo_isolated_by_upstream();
3573 PBD::warning << string_compose (
3574 _("Invalid Solo-Isolate propagation: from:%1 new:%2 - old:%3 = delta:%4"),
3575 _name, ibou, _solo_isolate_control->solo_isolated_by_upstream(), idelta)
3580 if (_solo_control->soloed_by_others_upstream()) {
3581 // ignore new connections (they're not propagated)
3583 _solo_control->mod_solo_by_others_upstream (delta);
3587 if (_solo_isolate_control->solo_isolated_by_upstream()) {
3588 // solo-isolate currently only propagates downstream
3590 _solo_isolate_control->mod_solo_isolated_by_upstream (1);
3592 //_solo_isolated_by_upstream = ibou;
3595 // Session::route_solo_changed does not propagate indirect solo-changes
3596 // propagate downstream to tracks
3597 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3598 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3602 bool does_feed = feeds (*i, &sends_only);
3603 if (delta <= 0 && does_feed && !sends_only) {
3604 (*i)->solo_control()->mod_solo_by_others_upstream (delta);
3607 if (idelta < 0 && does_feed && !sends_only) {
3608 (*i)->solo_isolate_control()->mod_solo_isolated_by_upstream (-1);
3615 Route::output_change_handler (IOChange change, void * /*src*/)
3617 if (_initial_io_setup) {
3621 if ((change.type & IOChange::ConfigurationChanged)) {
3622 /* This is called with the process lock held if change
3623 contains ConfigurationChanged
3625 configure_processors (0);
3628 _session.reset_monitor_section();
3631 io_changed (); /* EMIT SIGNAL */
3634 if ((change.type & IOChange::ConnectionsChanged)) {
3636 /* do this ONLY if connections have changed. Configuration
3637 * changes do not, by themselves alter solo upstream or
3638 * downstream status.
3641 if (_solo_control->soloed_by_others_downstream()) {
3643 /* checking all all downstream routes for
3644 * explicit of implict solo is a rather drastic measure,
3645 * ideally the input_change_handler() of the other route
3646 * would propagate the change to us.
3648 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3649 if (_output->connected()) {
3650 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3651 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3655 bool does_feed = direct_feeds_according_to_reality (*i, &sends_only);
3656 if (does_feed && !sends_only) {
3657 if ((*i)->soloed()) {
3665 int delta = sbod - _solo_control->soloed_by_others_downstream();
3667 // do not allow new connections to change implicit solo (no propagation)
3668 _solo_control->mod_solo_by_others_downstream (delta);
3669 // Session::route_solo_changed() does not propagate indirect solo-changes
3670 // propagate upstream to tracks
3671 boost::shared_ptr<Route> shared_this = boost::dynamic_pointer_cast<Route> (shared_from_this());
3672 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3673 if ((*i).get() == this || !can_solo()) {
3677 bool does_feed = (*i)->feeds (shared_this, &sends_only);
3678 if (delta != 0 && does_feed && !sends_only) {
3679 (*i)->solo_control()->mod_solo_by_others_downstream (delta);
3689 Route::sidechain_change_handler (IOChange change, void* src)
3691 if (_initial_io_setup || _in_sidechain_setup) {
3695 input_change_handler (change, src);
3699 Route::pans_required () const
3701 if (n_outputs().n_audio() < 2) {
3705 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
3709 Route::flush_processor_buffers_locked (samplecnt_t nframes)
3711 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3712 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery> (*i);
3714 d->flush_buffers (nframes);
3716 boost::shared_ptr<PortInsert> p = boost::dynamic_pointer_cast<PortInsert> (*i);
3718 p->flush_buffers (nframes);
3725 Route::flush_processors ()
3727 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3729 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3735 Route::playback_latency (bool incl_downstream) const
3739 rv = _disk_reader->output_latency ();
3741 rv = _signal_latency;
3743 if (incl_downstream) {
3744 rv += _output->connected_latency (true);
3746 rv += _output->latency ();
3752 Route::latency_preroll (pframes_t nframes, samplepos_t& start_sample, samplepos_t& end_sample)
3754 samplecnt_t latency_preroll = _session.remaining_latency_preroll ();
3755 if (latency_preroll == 0) {
3758 if (!_disk_reader) {
3759 start_sample -= latency_preroll;
3760 end_sample -= latency_preroll;
3764 if (latency_preroll > playback_latency ()) {
3765 no_roll_unlocked (nframes, start_sample - latency_preroll, end_sample - latency_preroll, false);
3769 start_sample -= latency_preroll;
3770 end_sample -= latency_preroll;
3775 Route::roll (pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, bool& need_butler)
3777 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3784 silence_unlocked (nframes);
3789 if ((nframes = latency_preroll (nframes, start_sample, end_sample)) == 0) {
3793 run_route (start_sample, end_sample, nframes, (!_disk_writer || !_disk_writer->record_enabled()) && _session.transport_rolling(), true);
3795 if ((_disk_reader && _disk_reader->need_butler()) || (_disk_writer && _disk_writer->need_butler())) {
3802 Route::no_roll (pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, bool session_state_changing)
3804 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3810 return no_roll_unlocked (nframes, start_sample, end_sample, session_state_changing);
3814 Route::no_roll_unlocked (pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, bool session_state_changing)
3816 /* Must be called with the processor lock held */
3819 silence_unlocked (nframes);
3824 if (session_state_changing) {
3825 if (_session.transport_speed() != 0.0f) {
3826 /* we're rolling but some state is changing (e.g. our diskstream contents)
3827 so we cannot use them. Be silent till this is over.
3829 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
3831 silence_unlocked (nframes);
3835 /* we're really not rolling, so we're either delivery silence or actually
3836 monitoring, both of which are safe to do while session_state_changing is true.
3840 run_route (start_sample, end_sample, nframes, false, false);
3845 Route::silent_roll (pframes_t nframes, samplepos_t /*start_sample*/, samplepos_t /*end_sample*/, bool& /* need_butler */)
3848 flush_processor_buffers_locked (nframes);
3853 __attribute__((annotate("realtime")))
3856 Route::apply_processor_changes_rt ()
3858 int emissions = EmitNone;
3860 if (_pending_meter_point != _meter_point) {
3861 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3863 /* meters always have buffers for 'processor_max_streams'
3864 * they can be re-positioned without re-allocation */
3865 if (set_meter_point_unlocked()) {
3866 emissions |= EmitMeterChanged | EmitMeterVisibilityChange;;
3868 emissions |= EmitMeterChanged;
3873 bool changed = false;
3875 if (g_atomic_int_get (&_pending_process_reorder)) {
3876 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3878 apply_processor_order (_pending_processor_order);
3879 setup_invisible_processors ();
3881 g_atomic_int_set (&_pending_process_reorder, 0);
3882 emissions |= EmitRtProcessorChange;
3886 set_processor_positions ();
3887 /* update processor input/output latency
3888 * (total signal_latency does not change)
3890 update_signal_latency (true);
3892 if (emissions != 0) {
3893 g_atomic_int_set (&_pending_signals, emissions);
3896 return (!selfdestruct_sequence.empty ());
3900 Route::emit_pending_signals ()
3902 int sig = g_atomic_int_and (&_pending_signals, 0);
3903 if (sig & EmitMeterChanged) {
3904 _meter->emit_configuration_changed();
3905 meter_change (); /* EMIT SIGNAL */
3906 if (sig & EmitMeterVisibilityChange) {
3907 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3909 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3912 if (sig & EmitRtProcessorChange) {
3913 processors_changed (RouteProcessorChange (RouteProcessorChange::RealTimeChange)); /* EMIT SIGNAL */
3916 /* this would be a job for the butler.
3917 * Conceptually we should not take processe/processor locks here.
3918 * OTOH its more efficient (less overhead for summoning the butler and
3919 * telling her what do do) and signal emission is called
3920 * directly after the process callback, which decreases the chance
3921 * of x-runs when taking the locks.
3923 while (!selfdestruct_sequence.empty ()) {
3924 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
3925 if (selfdestruct_sequence.empty ()) { break; } // re-check with lock
3926 boost::shared_ptr<Processor> proc = selfdestruct_sequence.back ().lock ();
3927 selfdestruct_sequence.pop_back ();
3930 remove_processor (proc);
3936 Route::set_meter_point (MeterPoint p, bool force)
3938 if (_pending_meter_point == p && !force) {
3942 if (force || !AudioEngine::instance()->running()) {
3943 bool meter_visibly_changed = false;
3945 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3946 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3947 _pending_meter_point = p;
3948 if (set_meter_point_unlocked ()) {
3949 meter_visibly_changed = true;
3952 _meter->emit_configuration_changed();
3953 meter_change (); /* EMIT SIGNAL */
3954 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, meter_visibly_changed)); /* EMIT SIGNAL */
3956 _pending_meter_point = p;
3962 __attribute__((annotate("realtime")))
3965 Route::set_meter_point_unlocked ()
3968 /* Caller must hold process and processor write lock */
3969 assert (!AudioEngine::instance()->process_lock().trylock());
3970 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3971 assert (!lm.locked ());
3974 _meter_point = _pending_meter_point;
3976 bool meter_was_visible_to_user = _meter->display_to_user ();
3978 if (!_custom_meter_position_noted) {
3979 maybe_note_meter_position ();
3982 if (_meter_point != MeterCustom) {
3984 _meter->set_display_to_user (false);
3986 setup_invisible_processors ();
3989 _meter->set_display_to_user (true);
3991 /* If we have a previous position for the custom meter, try to put it there */
3992 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
3994 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), after);
3995 if (i != _processors.end ()) {
3996 _processors.remove (_meter);
3997 _processors.insert (i, _meter);
3999 } else {// at end, right before the mains_out/panner
4000 _processors.remove (_meter);
4001 ProcessorList::iterator main = _processors.end();
4002 _processors.insert (--main, _meter);
4006 /* Set up the meter for its new position */
4008 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
4012 if (loc == _processors.begin()) {
4013 m_in = _input->n_ports();
4015 ProcessorList::iterator before = loc;
4017 m_in = (*before)->output_streams ();
4020 _meter->reflect_inputs (m_in);
4022 /* we do not need to reconfigure the processors, because the meter
4023 (a) is always ready to handle processor_max_streams
4024 (b) is always an N-in/N-out processor, and thus moving
4025 it doesn't require any changes to the other processors.
4028 /* these should really be done after releasing the lock
4029 * but all those signals are subscribed to with gui_thread()
4032 return (_meter->display_to_user() != meter_was_visible_to_user);
4036 Route::listen_position_changed ()
4039 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4040 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
4041 ProcessorState pstate (this);
4043 if (configure_processors_unlocked (0, &lm)) {
4044 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
4046 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
4051 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
4052 _session.set_dirty ();
4055 boost::shared_ptr<CapturingProcessor>
4056 Route::add_export_point()
4058 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4059 if (!_capturing_processor) {
4061 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4062 Glib::Threads::RWLock::WriterLock lw (_processor_lock);
4064 /* Align all tracks for stem-export w/o processing.
4065 * Compensate for all plugins between the this route's disk-reader
4066 * and the common final downstream output (ie alignment point for playback).
4068 _capturing_processor.reset (new CapturingProcessor (_session, playback_latency (true)));
4069 configure_processors_unlocked (0, &lw);
4070 _capturing_processor->activate ();
4073 return _capturing_processor;
4077 Route::update_signal_latency (bool apply_to_delayline)
4079 // TODO: bail out if !active() and set/assume _signal_latency = 0,
4080 // here or in Session::* ? -> also zero send latencies,
4081 // and make sure that re-enabling a route updates things again...
4083 samplecnt_t capt_lat_in = _input->connected_latency (false);
4084 samplecnt_t play_lat_out = _output->connected_latency (true);
4086 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4088 samplecnt_t l_in = 0;
4089 samplecnt_t l_out = _output->effective_latency ();
4090 for (ProcessorList::reverse_iterator i = _processors.rbegin(); i != _processors.rend(); ++i) {
4091 if (boost::shared_ptr<Send> snd = boost::dynamic_pointer_cast<Send> (*i)) {
4092 snd->set_delay_in (l_out + _output->latency());
4095 if (boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) {
4096 if (boost::shared_ptr<IO> pio = pi->sidechain_input ()) {
4097 samplecnt_t lat = l_out + _output->latency();
4098 pio->set_private_port_latencies (lat, true);
4099 pio->set_public_port_latencies (lat, true);
4102 (*i)->set_output_latency (l_out);
4103 if ((*i)->active ()) { // XXX
4104 l_out += (*i)->effective_latency ();
4108 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal signal latency = %2\n", _name, l_out));
4110 _signal_latency = l_out;
4112 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4114 /* set sidechain, send and insert port latencies */
4115 if (boost::shared_ptr<PortInsert> pi = boost::dynamic_pointer_cast<PortInsert> (*i)) {
4117 /* propagate playback latency from output to input */
4118 pi->input ()->set_private_port_latencies (play_lat_out + l_in, true);
4120 if (pi->output ()) {
4121 /* propagate capture latency from input to output */
4122 pi->output ()->set_private_port_latencies (capt_lat_in + l_in, false);
4125 } else if (boost::shared_ptr<Send> snd = boost::dynamic_pointer_cast<Send> (*i)) {
4126 if (snd->output ()) {
4127 /* set capture latency */
4128 snd->output ()->set_private_port_latencies (capt_lat_in + l_in, false);
4129 /* take send-target's playback latency into account */
4130 snd->set_delay_out (snd->output ()->connected_latency (true));
4134 (*i)->set_input_latency (l_in);
4135 (*i)->set_playback_offset (_signal_latency + _output->latency ());
4136 (*i)->set_capture_offset (_input->latency ());
4137 if ((*i)->active ()) {
4138 l_in += (*i)->effective_latency ();
4144 if (apply_to_delayline) {
4145 /* see also Session::post_playback_latency() */
4146 apply_latency_compensation ();
4149 if (_signal_latency != l_out) {
4150 signal_latency_changed (); /* EMIT SIGNAL */
4153 return _signal_latency;
4157 Route::set_user_latency (samplecnt_t nframes)
4159 _output->set_user_latency (nframes);
4160 _session.update_latency_compensation ();
4164 Route::apply_latency_compensation ()
4167 samplecnt_t old = _delayline->delay ();
4169 samplecnt_t play_lat_in = _input->connected_latency (true);
4170 samplecnt_t play_lat_out = _output->connected_latency (true);
4171 samplecnt_t latcomp = play_lat_in - play_lat_out - _signal_latency;
4174 samplecnt_t capt_lat_in = _input->connected_latency (false);
4175 samplecnt_t capt_lat_out = _output->connected_latency (false);
4176 samplecnt_t latcomp_capt = capt_lat_out - capt_lat_in - _signal_latency;
4178 cout << "ROUTE " << name() << " delay for " << latcomp << " (c: " << latcomp_capt << ")" << endl;
4181 _delayline->set_delay (latcomp > 0 ? latcomp : 0);
4183 if (old != _delayline->delay ()) {
4184 signal_latency_updated (); /* EMIT SIGNAL */
4190 Route::set_block_size (pframes_t nframes)
4192 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4193 (*i)->set_block_size (nframes);
4196 _session.ensure_buffers (n_process_buffers ());
4200 Route::protect_automation ()
4202 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
4203 (*i)->protect_automation();
4206 /** Shift automation forwards from a particular place, thereby inserting time.
4207 * Adds undo commands for any shifts that are performed.
4209 * @param pos Position to start shifting from.
4210 * @param samples Amount to shift forwards by.
4214 Route::shift (samplepos_t pos, samplecnt_t samples)
4216 /* pan automation */
4218 ControlSet::Controls& c (_pannable->controls());
4220 for (ControlSet::Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
4221 boost::shared_ptr<AutomationControl> pc = boost::dynamic_pointer_cast<AutomationControl> (ci->second);
4223 boost::shared_ptr<AutomationList> al = pc->alist();
4224 XMLNode& before = al->get_state ();
4225 al->shift (pos, samples);
4226 XMLNode& after = al->get_state ();
4227 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4232 /* TODO mute automation, MuteControl */
4234 /* processor automation (incl. gain, trim,..) */
4236 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4237 for (ProcessorList::iterator i = _processors.begin (); i != _processors.end (); ++i) {
4239 set<Evoral::Parameter> parameters = (*i)->what_can_be_automated();
4241 for (set<Evoral::Parameter>::const_iterator p = parameters.begin (); p != parameters.end (); ++p) {
4242 boost::shared_ptr<AutomationControl> ac = (*i)->automation_control (*p);
4244 boost::shared_ptr<AutomationList> al = ac->alist();
4248 XMLNode &before = al->get_state ();
4249 al->shift (pos, samples);
4250 XMLNode &after = al->get_state ();
4251 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4259 Route::set_plugin_state_dir (boost::weak_ptr<Processor> p, const std::string& d)
4261 boost::shared_ptr<Processor> processor (p.lock ());
4262 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
4266 pi->set_state_dir (d);
4270 Route::save_as_template (const string& path, const string& name, const string& description)
4272 std::string state_dir = path.substr (0, path.find_last_of ('.')); // strip template_suffix
4273 PBD::Unwinder<std::string> uw (_session._template_state_dir, state_dir);
4275 XMLNode& node (state (true));
4276 node.set_property (X_("name"), name);
4278 node.remove_nodes (X_("description"));
4279 if (!description.empty()) {
4280 XMLNode* desc = new XMLNode(X_("description"));
4281 XMLNode* desc_cont = new XMLNode(X_("content"), description);
4282 desc->add_child_nocopy (*desc_cont);
4284 node.add_child_nocopy (*desc);
4289 IO::set_name_in_state (*node.children().front(), name);
4291 tree.set_root (&node);
4293 /* return zero on success, non-zero otherwise */
4294 return !tree.write (path.c_str());
4299 Route::set_name (const string& str)
4305 if (str == name()) {
4309 string newname = Route::ensure_track_or_route_name (str);
4311 if (newname == name()) {
4315 SessionObject::set_name (newname);
4317 for (uint32_t n = 0 ; ; ++n) {
4318 boost::shared_ptr<PluginInsert> pi = boost::static_pointer_cast<PluginInsert> (nth_plugin (n));
4322 pi->update_sidechain_name ();
4325 bool ret = (_input->set_name(newname) && _output->set_name(newname));
4328 /* rename the main outs. Leave other IO processors
4329 * with whatever name they already have, because its
4330 * just fine as it is (it will not contain the route
4331 * name if its a port insert, port send or port return).
4335 if (_main_outs->set_name (newname)) {
4336 /* XXX returning false here is stupid because
4337 we already changed the route name.
4347 /** Set the name of a route in an XML description.
4348 * @param node XML <Route> node to set the name in.
4349 * @param name New name.
4352 Route::set_name_in_state (XMLNode& node, string const & name)
4354 node.set_property (X_("name"), name);
4356 XMLNodeList children = node.children();
4357 for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
4359 if ((*i)->name() == X_("IO")) {
4361 IO::set_name_in_state (**i, name);
4363 } else if ((*i)->name() == X_("Processor")) {
4366 if ((*i)->get_property (X_("role"), str) && str == X_("Main")) {
4367 (*i)->set_property (X_("name"), name);
4373 boost::shared_ptr<Send>
4374 Route::internal_send_for (boost::shared_ptr<const Route> target) const
4376 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4378 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4379 boost::shared_ptr<InternalSend> send;
4381 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
4382 if (send->target_route() == target) {
4388 return boost::shared_ptr<Send>();
4392 Route::set_denormal_protection (bool yn)
4394 if (_denormal_protection != yn) {
4395 _denormal_protection = yn;
4396 denormal_protection_changed (); /* EMIT SIGNAL */
4401 Route::denormal_protection () const
4403 return _denormal_protection;
4407 Route::set_active (bool yn, void* src)
4409 if (_session.transport_rolling()) {
4413 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_route_active()) {
4414 _route_group->foreach_route (boost::bind (&Route::set_active, _1, yn, _route_group));
4418 if (_active != yn) {
4420 _input->set_active (yn);
4421 _output->set_active (yn);
4422 flush_processors ();
4423 active_changed (); // EMIT SIGNAL
4424 _session.set_dirty ();
4428 boost::shared_ptr<Pannable>
4429 Route::pannable() const
4434 boost::shared_ptr<Panner>
4435 Route::panner() const
4438 return _main_outs->panner_shell()->panner();
4441 boost::shared_ptr<PannerShell>
4442 Route::panner_shell() const
4444 return _main_outs->panner_shell();
4447 boost::shared_ptr<GainControl>
4448 Route::gain_control() const
4450 return _gain_control;
4453 boost::shared_ptr<GainControl>
4454 Route::trim_control() const
4456 return _trim_control;
4459 boost::shared_ptr<PhaseControl>
4460 Route::phase_control() const
4462 return _phase_control;
4465 boost::shared_ptr<AutomationControl>
4466 Route::get_control (const Evoral::Parameter& param)
4468 /* either we own the control or .... */
4470 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
4474 /* maybe one of our processors does or ... */
4476 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
4477 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4478 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
4486 /* nobody does so we'll make a new one */
4488 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
4495 boost::shared_ptr<Processor>
4496 Route::nth_plugin (uint32_t n) const
4498 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4499 ProcessorList::const_iterator i;
4501 for (i = _processors.begin(); i != _processors.end(); ++i) {
4502 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
4509 return boost::shared_ptr<Processor> ();
4512 boost::shared_ptr<Processor>
4513 Route::nth_send (uint32_t n) const
4515 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4516 ProcessorList::const_iterator i;
4518 for (i = _processors.begin(); i != _processors.end(); ++i) {
4519 if (boost::dynamic_pointer_cast<Send> (*i)) {
4521 if ((*i)->name().find (_("Monitor")) == 0) {
4522 /* send to monitor section is not considered
4523 to be an accessible send.
4534 return boost::shared_ptr<Processor> ();
4538 Route::has_io_processor_named (const string& name)
4540 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4541 ProcessorList::iterator i;
4543 for (i = _processors.begin(); i != _processors.end(); ++i) {
4544 if (boost::dynamic_pointer_cast<Send> (*i) ||
4545 boost::dynamic_pointer_cast<PortInsert> (*i)) {
4546 if ((*i)->name() == name) {
4556 Route::set_processor_positions ()
4558 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4560 bool had_amp = false;
4561 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4562 (*i)->set_pre_fader (!had_amp);
4569 /** Called when there is a proposed change to the input port count */
4571 Route::input_port_count_changing (ChanCount to)
4573 list<pair<ChanCount, ChanCount> > c = try_configure_processors (to, 0);
4575 /* The processors cannot be configured with the new input arrangement, so
4581 /* The change is ok */
4585 /** Called when there is a proposed change to the output port count */
4587 Route::output_port_count_changing (ChanCount to)
4589 if (_strict_io && !_in_configure_processors) {
4592 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
4593 if (processor_out_streams.get(*t) > to.get(*t)) {
4597 /* The change is ok */
4602 Route::unknown_processors () const
4606 if (_session.get_disable_all_loaded_plugins ()) {
4607 // Do not list "missing plugins" if they are explicitly disabled
4611 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4612 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4613 if (boost::dynamic_pointer_cast<UnknownProcessor const> (*i)) {
4614 p.push_back ((*i)->name ());
4623 Route::update_port_latencies (PortSet& from, PortSet& to, bool playback, samplecnt_t our_latency) const
4625 /* we assume that all our input ports feed all our output ports. its not
4626 universally true, but the alternative is way too corner-case to worry about.
4629 LatencyRange all_connections;
4632 all_connections.min = 0;
4633 all_connections.max = 0;
4635 all_connections.min = ~((pframes_t) 0);
4636 all_connections.max = 0;
4638 /* iterate over all "from" ports and determine the latency range for all of their
4639 connections to the "outside" (outside of this Route).
4642 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4646 p->get_connected_latency_range (range, playback);
4648 all_connections.min = min (all_connections.min, range.min);
4649 all_connections.max = max (all_connections.max, range.max);
4653 /* set the "from" port latencies to the max/min range of all their connections */
4655 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4656 p->set_private_latency_range (all_connections, playback);
4659 /* set the ports "in the direction of the flow" to the same value as above plus our own signal latency */
4661 all_connections.min += our_latency;
4662 all_connections.max += our_latency;
4664 for (PortSet::iterator p = to.begin(); p != to.end(); ++p) {
4665 p->set_private_latency_range (all_connections, playback);
4668 return all_connections.max;
4672 Route::set_private_port_latencies (bool playback) const
4674 samplecnt_t own_latency = 0;
4676 /* Processor list not protected by lock: MUST BE CALLED FROM PROCESS THREAD
4677 OR LATENCY CALLBACK.
4679 This is called (early) from the latency callback. It computes the REAL
4680 latency associated with each port and stores the result as the "private"
4681 latency of the port. A later call to Route::set_public_port_latencies()
4682 sets all ports to the same value to reflect the fact that we do latency
4683 compensation and so all signals are delayed by the same amount as they
4684 flow through ardour.
4687 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4689 if ((*i)->active ()) {
4690 own_latency += (*i)->effective_latency ();
4695 /* playback: propagate latency from "outside the route" to outputs to inputs */
4696 return update_port_latencies (_output->ports (), _input->ports (), true, own_latency);
4698 /* capture: propagate latency from "outside the route" to inputs to outputs */
4699 return update_port_latencies (_input->ports (), _output->ports (), false, own_latency);
4704 Route::set_public_port_latencies (samplecnt_t value, bool playback) const
4706 /* publish private latencies */
4707 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4708 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4709 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*i);
4713 if (iop->input ()) {
4714 iop->input ()->set_public_port_latencies (iop->input()->latency(), true);
4716 if (iop->output ()) {
4717 iop->output ()->set_public_port_latencies (iop->output()->latency(), false);
4721 /* this is called to set the JACK-visible port latencies, which take
4722 * latency compensation into account.
4724 _input->set_public_port_latencies (value, playback);
4725 _output->set_public_port_latencies (value, playback);
4728 /** Put the invisible processors in the right place in _processors.
4729 * Must be called with a writer lock on _processor_lock held.
4732 __attribute__((annotate("realtime")))
4735 Route::setup_invisible_processors ()
4738 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4739 assert (!lm.locked ());
4743 /* too early to be doing this stuff */
4747 /* we'll build this new list here and then use it
4749 * TODO put the ProcessorList is on the stack for RT-safety.
4752 ProcessorList new_processors;
4753 ProcessorList foldback_sends;
4754 ProcessorList::iterator dr;
4755 ProcessorList::iterator dw;
4757 /* find visible processors */
4759 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4760 boost::shared_ptr<Send> auxsnd = boost::dynamic_pointer_cast<Send> ((*i));
4761 if ((*i)->display_to_user ()) {
4762 new_processors.push_back (*i);
4764 else if (auxsnd && auxsnd->is_foldback ()) {
4765 foldback_sends.push_back (*i);
4771 ProcessorList::iterator amp = find (new_processors.begin(), new_processors.end(), _amp);
4773 if (amp == new_processors.end ()) {
4774 error << string_compose (_("Amp/Fader on Route '%1' went AWOL. Re-added."), name()) << endmsg;
4775 new_processors.push_front (_amp);
4776 amp = find (new_processors.begin(), new_processors.end(), _amp);
4779 /* and the processor after the amp */
4781 ProcessorList::iterator after_amp = amp;
4784 /* Pre-fader METER */
4786 if (_meter && _meter_point == MeterPreFader) {
4787 /* add meter just before the fader */
4788 assert (!_meter->display_to_user ());
4789 new_processors.insert (amp, _meter);
4794 assert (_main_outs);
4795 assert (!_main_outs->display_to_user ());
4796 new_processors.push_back (_main_outs);
4798 /* iterator for the main outs */
4800 ProcessorList::iterator main = new_processors.end();
4803 /* OUTPUT METERING */
4805 if (_meter && (_meter_point == MeterOutput || _meter_point == MeterPostFader)) {
4806 assert (!_meter->display_to_user ());
4808 /* add the processor just before or just after the main outs */
4810 ProcessorList::iterator meter_point = main;
4812 if (_meter_point == MeterOutput) {
4815 new_processors.insert (meter_point, _meter);
4818 /* Foldback Sends */
4820 for (ProcessorList::iterator i = foldback_sends.begin(); i != foldback_sends.end(); ++i) {
4821 new_processors.insert (amp, (*i));
4826 if (_monitor_send && !is_monitor ()) {
4827 assert (!_monitor_send->display_to_user ());
4828 switch (Config->get_listen_position ()) {
4829 case PreFaderListen:
4830 switch (Config->get_pfl_position ()) {
4831 case PFLFromBeforeProcessors:
4832 new_processors.push_front (_monitor_send);
4834 case PFLFromAfterProcessors:
4835 new_processors.insert (amp, _monitor_send);
4838 _monitor_send->set_can_pan (false);
4840 case AfterFaderListen:
4841 switch (Config->get_afl_position ()) {
4842 case AFLFromBeforeProcessors:
4843 new_processors.insert (after_amp, _monitor_send);
4845 case AFLFromAfterProcessors:
4846 new_processors.insert (new_processors.end(), _monitor_send);
4849 _monitor_send->set_can_pan (true);
4854 /* MONITOR CONTROL */
4856 if (_monitor_control && is_monitor ()) {
4857 assert (!_monitor_control->display_to_user ());
4858 new_processors.insert (amp, _monitor_control);
4863 ProcessorList::iterator trim = new_processors.end();
4865 if (_trim->active()) {
4866 assert (!_trim->display_to_user ());
4867 new_processors.push_front (_trim);
4868 trim = new_processors.begin();
4871 /* INTERNAL RETURN */
4873 /* doing this here means that any monitor control will come after
4874 the return and trim.
4878 assert (!_intreturn->display_to_user ());
4879 new_processors.push_front (_intreturn);
4882 /* DISK READER & WRITER (for Track objects) */
4884 if (_disk_reader || _disk_writer) {
4885 switch (_disk_io_point) {
4886 case DiskIOPreFader:
4887 if (trim != new_processors.end()) {
4888 /* insert BEFORE TRIM */
4890 new_processors.insert (trim, _disk_writer);
4893 new_processors.insert (trim, _disk_reader);
4897 new_processors.push_front (_disk_writer);
4900 new_processors.push_front (_disk_reader);
4904 case DiskIOPostFader:
4905 /* insert BEFORE main outs */
4907 new_processors.insert (main, _disk_writer);
4910 new_processors.insert (main, _disk_reader);
4914 /* reader and writer are visible under this condition, so they
4915 * are not invisible and thus not handled here.
4921 /* ensure dist-writer is before disk-reader */
4922 if (_disk_reader && _disk_writer) {
4923 ProcessorList::iterator reader_pos = find (new_processors.begin(), new_processors.end(), _disk_reader);
4924 ProcessorList::iterator writer_pos = find (new_processors.begin(), new_processors.end(), _disk_writer);
4925 assert (reader_pos != new_processors.end ());
4926 assert (writer_pos != new_processors.end ());
4927 if (std::distance (new_processors.begin(), reader_pos) < std::distance (new_processors.begin(), writer_pos)) {
4928 new_processors.erase (reader_pos);
4929 assert (writer_pos == find (new_processors.begin(), new_processors.end(), _disk_writer));
4930 new_processors.insert (++writer_pos, _disk_reader);
4934 /* EXPORT PROCESSOR */
4935 if (_capturing_processor) {
4936 assert (!_capturing_processor->display_to_user ());
4937 ProcessorList::iterator reader_pos = find (new_processors.begin(), new_processors.end(), _disk_reader);
4938 if (reader_pos != new_processors.end()) {
4939 /* insert after disk-reader */
4940 new_processors.insert (++reader_pos, _capturing_processor);
4942 ProcessorList::iterator return_pos = find (new_processors.begin(), new_processors.end(), _intreturn);
4943 /* insert after return */
4944 if (return_pos != new_processors.end()) {
4945 new_processors.insert (++return_pos, _capturing_processor);
4947 new_processors.push_front (_capturing_processor);
4952 /* Polarity Invert */
4954 ProcessorList::iterator reader_pos = find (new_processors.begin(), new_processors.end(), _disk_reader);
4955 if (reader_pos != new_processors.end()) {
4956 /* insert after disk-reader */
4957 new_processors.insert (++reader_pos, _polarity);
4959 ProcessorList::iterator return_pos = find (new_processors.begin(), new_processors.end(), _intreturn);
4960 /* insert after return */
4961 if (return_pos != new_processors.end()) {
4962 new_processors.insert (++return_pos, _polarity);
4964 new_processors.push_front (_polarity);
4970 if (_meter && _meter_point == MeterInput) {
4971 /* add meter just before the disk-writer (if any)
4972 * otherwise at the top, but after the latency delayline
4973 * (perhaps it should also be after intreturn on busses ??)
4975 assert (!_meter->display_to_user ());
4976 ProcessorList::iterator writer_pos = find (new_processors.begin(), new_processors.end(), _disk_writer);
4977 if (writer_pos != new_processors.end()) {
4978 /* insert before disk-writer */
4979 new_processors.insert (writer_pos, _meter);
4981 ProcessorList::iterator return_pos = find (new_processors.begin(), new_processors.end(), _intreturn);
4982 /* insert after return */
4983 if (return_pos != new_processors.end()) {
4984 new_processors.insert (++return_pos, _meter);
4986 new_processors.push_front (_meter);
4991 if (!is_master() && !is_monitor() && !is_auditioner()) {
4992 ProcessorList::iterator reader_pos = find (new_processors.begin(), new_processors.end(), _disk_reader);
4993 if (reader_pos != new_processors.end()) {
4994 /* insert before disk-reader */
4995 new_processors.insert (reader_pos, _delayline);
4997 new_processors.push_front (_delayline);
5001 _processors = new_processors;
5003 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5004 if (!(*i)->display_to_user () && !(*i)->enabled () && (*i) != _monitor_send) {
5005 (*i)->enable (true);
5009 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: setup_invisible_processors\n", _name));
5010 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5011 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1\n", (*i)->name ()));
5018 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
5019 Glib::Threads::RWLock::ReaderLock lp (_processor_lock);
5023 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5024 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*i);
5031 /** If the meter point is `Custom', make a note of where the meter is.
5032 * This is so that if the meter point is subsequently set to something else,
5033 * and then back to custom, we can put the meter back where it was last time
5034 * custom was enabled.
5036 * Must be called with the _processor_lock held.
5039 Route::maybe_note_meter_position ()
5041 if (_meter_point != MeterCustom) {
5045 _custom_meter_position_noted = true;
5046 /* custom meter points range from after trim to before panner/main_outs
5047 * this is a limitation by the current processor UI
5049 bool seen_trim = false;
5050 _processor_after_last_custom_meter.reset();
5051 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5052 if ((*i) == _trim) {
5055 if ((*i) == _main_outs) {
5056 _processor_after_last_custom_meter = *i;
5059 if (boost::dynamic_pointer_cast<PeakMeter> (*i)) {
5061 _processor_after_last_custom_meter = _trim;
5063 ProcessorList::iterator j = i;
5065 assert(j != _processors.end ()); // main_outs should be before
5066 _processor_after_last_custom_meter = *j;
5071 assert(_processor_after_last_custom_meter.lock());
5074 boost::shared_ptr<Processor>
5075 Route::processor_by_id (PBD::ID id) const
5077 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5078 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5079 if ((*i)->id() == id) {
5084 return boost::shared_ptr<Processor> ();
5087 /** @return what we should be metering; either the data coming from the input
5088 * IO or the data that is flowing through the route.
5091 Route::metering_state () const
5093 return MeteringRoute;
5097 Route::has_external_redirects () const
5099 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5101 /* ignore inactive processors and obviously ignore the main
5102 * outs since everything has them and we don't care.
5105 if ((*i)->active() && (*i) != _main_outs && (*i)->does_routing()) {
5113 boost::shared_ptr<Processor>
5114 Route::the_instrument () const
5116 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5117 return the_instrument_unlocked ();
5120 boost::shared_ptr<Processor>
5121 Route::the_instrument_unlocked () const
5123 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5124 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
5125 if (pi && pi->plugin ()->get_info ()->is_instrument ()) {
5129 return boost::shared_ptr<Processor>();
5135 return dynamic_cast<Track*>(this) != 0;
5139 Route::non_realtime_locate (samplepos_t pos)
5141 Automatable::non_realtime_locate (pos);
5144 _pannable->non_realtime_locate (pos);
5147 #if 0 // XXX mayhaps clear delayline here (and at stop?)
5149 _delayline->flush ();
5154 //Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
5155 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5157 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5158 (*i)->non_realtime_locate (pos);
5164 Route::fill_buffers_with_input (BufferSet& bufs, boost::shared_ptr<IO> io, pframes_t nframes)
5171 * We don't currently mix MIDI input together, so we don't need the
5172 * complex logic of the audio case.
5175 n_buffers = bufs.count().n_midi ();
5177 for (i = 0; i < n_buffers; ++i) {
5179 boost::shared_ptr<MidiPort> source_port = io->midi (i);
5180 MidiBuffer& buf (bufs.get_midi (i));
5183 buf.copy (source_port->get_midi_buffer(nframes));
5185 buf.silence (nframes);
5191 n_buffers = bufs.count().n_audio();
5193 size_t n_ports = io->n_ports().n_audio();
5194 float scaling = 1.0f;
5196 if (n_ports > n_buffers) {
5197 scaling = ((float) n_buffers) / n_ports;
5200 for (i = 0; i < n_ports; ++i) {
5202 /* if there are more ports than buffers, map them onto buffers
5203 * in a round-robin fashion
5206 boost::shared_ptr<AudioPort> source_port = io->audio (i);
5207 AudioBuffer& buf (bufs.get_audio (i%n_buffers));
5209 if (i < n_buffers) {
5211 /* first time through just copy a channel into
5215 buf.read_from (source_port->get_audio_buffer (nframes), nframes);
5217 if (scaling != 1.0f) {
5218 buf.apply_gain (scaling, nframes);
5223 /* on subsequent times around, merge data from
5224 * the port with what is already there
5227 if (scaling != 1.0f) {
5228 buf.accumulate_with_gain_from (source_port->get_audio_buffer (nframes), nframes, 0, scaling);
5230 buf.accumulate_from (source_port->get_audio_buffer (nframes), nframes);
5235 /* silence any remaining buffers */
5237 for (; i < n_buffers; ++i) {
5238 AudioBuffer& buf (bufs.get_audio (i));
5239 buf.silence (nframes);
5242 /* establish the initial setup of the buffer set, reflecting what was
5243 copied into it. unless, of course, we are the auditioner, in which
5244 case nothing was fed into it from the inputs at all.
5247 if (!is_auditioner()) {
5248 bufs.set_count (io->n_ports());
5252 boost::shared_ptr<AutomationControl>
5253 Route::pan_azimuth_control() const
5256 # undef MIXBUS_PORTS_H
5257 # include "../../gtk2_ardour/mixbus_ports.h"
5258 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5260 return boost::shared_ptr<AutomationControl>();
5262 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_pan)));
5264 if (!_pannable || !panner()) {
5265 return boost::shared_ptr<AutomationControl>();
5267 return _pannable->pan_azimuth_control;
5271 boost::shared_ptr<AutomationControl>
5272 Route::pan_elevation_control() const
5274 if (Profile->get_mixbus() || !_pannable || !panner()) {
5275 return boost::shared_ptr<AutomationControl>();
5278 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5280 if (c.find (PanElevationAutomation) != c.end()) {
5281 return _pannable->pan_elevation_control;
5283 return boost::shared_ptr<AutomationControl>();
5286 boost::shared_ptr<AutomationControl>
5287 Route::pan_width_control() const
5290 if (mixbus() && _ch_pre) {
5292 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl>(_ch_pre->control(Evoral::Parameter(PluginAutomation, 0, 5)));
5295 if (Profile->get_mixbus() || !_pannable || !panner()) {
5296 return boost::shared_ptr<AutomationControl>();
5299 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5301 if (c.find (PanWidthAutomation) != c.end()) {
5302 return _pannable->pan_width_control;
5304 return boost::shared_ptr<AutomationControl>();
5307 boost::shared_ptr<AutomationControl>
5308 Route::pan_frontback_control() const
5310 if (Profile->get_mixbus() || !_pannable || !panner()) {
5311 return boost::shared_ptr<AutomationControl>();
5314 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5316 if (c.find (PanFrontBackAutomation) != c.end()) {
5317 return _pannable->pan_frontback_control;
5319 return boost::shared_ptr<AutomationControl>();
5322 boost::shared_ptr<AutomationControl>
5323 Route::pan_lfe_control() const
5325 if (Profile->get_mixbus() || !_pannable || !panner()) {
5326 return boost::shared_ptr<AutomationControl>();
5329 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5331 if (c.find (PanLFEAutomation) != c.end()) {
5332 return _pannable->pan_lfe_control;
5334 return boost::shared_ptr<AutomationControl>();
5339 Route::eq_band_cnt () const
5341 if (Profile->get_mixbus()) {
5343 if (is_master() || mixbus()) {
5352 /* Ardour has no well-known EQ object */
5357 boost::shared_ptr<AutomationControl>
5358 Route::eq_gain_controllable (uint32_t band) const
5361 boost::shared_ptr<PluginInsert> eq = ch_eq();
5364 return boost::shared_ptr<AutomationControl>();
5367 uint32_t port_number;
5368 if (is_master() || mixbus()) {
5370 case 0: port_number = 4; break;
5371 case 1: port_number = 3; break;
5372 case 2: port_number = 2; break;
5374 return boost::shared_ptr<AutomationControl>();
5379 case 0: port_number = 14; break;
5380 case 1: port_number = 12; break;
5381 case 2: port_number = 10; break;
5382 case 3: port_number = 8; break;
5384 return boost::shared_ptr<AutomationControl>();
5388 case 0: port_number = 8; break;
5389 case 1: port_number = 6; break;
5390 case 2: port_number = 4; break;
5392 return boost::shared_ptr<AutomationControl>();
5397 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5399 return boost::shared_ptr<AutomationControl>();
5402 boost::shared_ptr<AutomationControl>
5403 Route::eq_freq_controllable (uint32_t band) const
5406 if (mixbus() || is_master()) {
5407 /* no frequency controls for mixbusses or master */
5408 return boost::shared_ptr<AutomationControl>();
5411 boost::shared_ptr<PluginInsert> eq = ch_eq();
5414 return boost::shared_ptr<AutomationControl>();
5417 uint32_t port_number;
5420 case 0: port_number = 13; break; // lo
5421 case 1: port_number = 11; break; // lo mid
5422 case 2: port_number = 9; break; // hi mid
5423 case 3: port_number = 7; break; // hi
5425 return boost::shared_ptr<AutomationControl>();
5429 case 0: port_number = 7; break;
5430 case 1: port_number = 5; break;
5431 case 2: port_number = 3; break;
5433 return boost::shared_ptr<AutomationControl>();
5437 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5439 return boost::shared_ptr<AutomationControl>();
5443 boost::shared_ptr<AutomationControl>
5444 Route::eq_q_controllable (uint32_t band) const
5446 return boost::shared_ptr<AutomationControl>();
5449 boost::shared_ptr<AutomationControl>
5450 Route::eq_shape_controllable (uint32_t band) const
5453 boost::shared_ptr<PluginInsert> eq = ch_eq();
5454 if (is_master() || mixbus() || !eq) {
5455 return boost::shared_ptr<AutomationControl>();
5459 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4))); // lo bell
5462 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3))); // hi bell
5468 return boost::shared_ptr<AutomationControl>();
5471 boost::shared_ptr<AutomationControl>
5472 Route::eq_enable_controllable () const
5475 boost::shared_ptr<PluginInsert> eq = ch_eq();
5478 return boost::shared_ptr<AutomationControl>();
5481 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5483 return boost::shared_ptr<AutomationControl>();
5487 boost::shared_ptr<AutomationControl>
5488 Route::filter_freq_controllable (bool hpf) const
5491 boost::shared_ptr<PluginInsert> eq = ch_eq();
5493 if (is_master() || mixbus() || !eq) {
5494 return boost::shared_ptr<AutomationControl>();
5498 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5))); // HPF freq
5500 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5504 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 6))); // LPF freq
5506 return boost::shared_ptr<AutomationControl>();
5511 return boost::shared_ptr<AutomationControl>();
5515 boost::shared_ptr<AutomationControl>
5516 Route::filter_slope_controllable (bool) const
5518 return boost::shared_ptr<AutomationControl>();
5521 boost::shared_ptr<AutomationControl>
5522 Route::filter_enable_controllable (bool) const
5525 boost::shared_ptr<PluginInsert> eq = ch_eq();
5527 if (is_master() || mixbus() || !eq) {
5528 return boost::shared_ptr<AutomationControl>();
5531 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5533 return boost::shared_ptr<AutomationControl>();
5537 boost::shared_ptr<AutomationControl>
5538 Route::tape_drive_controllable () const
5541 if (_ch_pre && mixbus()) {
5542 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (_ch_pre->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4)));
5544 if (_ch_pre && is_master()) {
5545 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (_ch_pre->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5549 return boost::shared_ptr<AutomationControl>();
5553 Route::eq_band_name (uint32_t band) const
5556 if (is_master() || mixbus()) {
5558 if (Profile->get_mixbus()) {
5560 case 0: return _("lo");
5561 case 1: return _("mid");
5562 case 2: return _("hi");
5563 default: return string();
5571 case 0: return _("lo");
5572 case 1: return _("lm");
5573 case 2: return _("hm");
5574 case 3: return _("hi");
5575 default: return string();
5581 boost::shared_ptr<AutomationControl>
5582 Route::comp_enable_controllable () const
5585 boost::shared_ptr<PluginInsert> comp = ch_comp();
5588 return boost::shared_ptr<AutomationControl>();
5591 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5593 return boost::shared_ptr<AutomationControl>();
5596 boost::shared_ptr<AutomationControl>
5597 Route::comp_threshold_controllable () const
5600 boost::shared_ptr<PluginInsert> comp = ch_comp();
5603 return boost::shared_ptr<AutomationControl>();
5606 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5609 return boost::shared_ptr<AutomationControl>();
5612 boost::shared_ptr<AutomationControl>
5613 Route::comp_speed_controllable () const
5616 boost::shared_ptr<PluginInsert> comp = ch_comp();
5619 return boost::shared_ptr<AutomationControl>();
5622 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3)));
5624 return boost::shared_ptr<AutomationControl>();
5627 boost::shared_ptr<AutomationControl>
5628 Route::comp_mode_controllable () const
5631 boost::shared_ptr<PluginInsert> comp = ch_comp();
5634 return boost::shared_ptr<AutomationControl>();
5637 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4)));
5639 return boost::shared_ptr<AutomationControl>();
5642 boost::shared_ptr<AutomationControl>
5643 Route::comp_makeup_controllable () const
5646 boost::shared_ptr<PluginInsert> comp = ch_comp();
5649 return boost::shared_ptr<AutomationControl>();
5652 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5)));
5654 return boost::shared_ptr<AutomationControl>();
5657 boost::shared_ptr<ReadOnlyControl>
5658 Route::comp_redux_controllable () const
5661 boost::shared_ptr<PluginInsert> comp = ch_comp();
5664 return boost::shared_ptr<ReadOnlyControl>();
5667 return comp->control_output (2);
5669 return comp->control_output (6);
5673 return boost::shared_ptr<ReadOnlyControl>();
5678 Route::comp_mode_name (uint32_t mode) const
5683 return _("Leveler");
5685 return _("Compressor");
5687 return _("Limiter");
5689 return mixbus() ? _("Sidechain") : _("Limiter");
5699 Route::comp_speed_name (uint32_t mode) const
5717 boost::shared_ptr<AutomationControl>
5718 Route::send_pan_azi_controllable (uint32_t n) const
5721 # undef MIXBUS_PORTS_H
5722 # include "../../gtk2_ardour/mixbus_ports.h"
5723 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5724 if (plug && !mixbus()) {
5725 uint32_t port_id = 0;
5728 case 0: port_id = port_channel_post_aux0_pan; break; //32c mb "pan" controls use zero-based names, unlike levels. ugh
5729 case 1: port_id = port_channel_post_aux1_pan; break;
5730 case 2: port_id = port_channel_post_aux2_pan; break;
5731 case 3: port_id = port_channel_post_aux3_pan; break;
5732 case 4: port_id = port_channel_post_aux4_pan; break;
5733 case 5: port_id = port_channel_post_aux5_pan; break;
5734 case 6: port_id = port_channel_post_aux6_pan; break;
5735 case 7: port_id = port_channel_post_aux7_pan; break;
5736 case 8: port_id = port_channel_post_aux8_pan; break;
5737 case 9: port_id = port_channel_post_aux9_pan; break;
5738 case 10: port_id = port_channel_post_aux10_pan; break;
5739 case 11: port_id = port_channel_post_aux11_pan; break;
5746 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5751 return boost::shared_ptr<AutomationControl>();
5754 boost::shared_ptr<AutomationControl>
5755 Route::send_level_controllable (uint32_t n) const
5758 # undef MIXBUS_PORTS_H
5759 # include "../../gtk2_ardour/mixbus_ports.h"
5760 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5761 if (plug && !mixbus()) {
5762 uint32_t port_id = 0;
5764 case 0: port_id = port_channel_post_aux1_level; break;
5765 case 1: port_id = port_channel_post_aux2_level; break;
5766 case 2: port_id = port_channel_post_aux3_level; break;
5767 case 3: port_id = port_channel_post_aux4_level; break;
5768 case 4: port_id = port_channel_post_aux5_level; break;
5769 case 5: port_id = port_channel_post_aux6_level; break;
5770 case 6: port_id = port_channel_post_aux7_level; break;
5771 case 7: port_id = port_channel_post_aux8_level; break;
5773 case 8: port_id = port_channel_post_aux9_level; break;
5774 case 9: port_id = port_channel_post_aux10_level; break;
5775 case 10: port_id = port_channel_post_aux11_level; break;
5776 case 11: port_id = port_channel_post_aux12_level; break;
5783 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5794 boost::shared_ptr<Send> s = boost::dynamic_pointer_cast<Send>(nth_send (n));
5796 return boost::shared_ptr<AutomationControl>();
5798 return s->gain_control ();
5801 boost::shared_ptr<AutomationControl>
5802 Route::send_enable_controllable (uint32_t n) const
5805 # undef MIXBUS_PORTS_H
5806 # include "../../gtk2_ardour/mixbus_ports.h"
5807 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5808 if (plug && !mixbus()) {
5809 uint32_t port_id = 0;
5811 case 0: port_id = port_channel_post_aux1_asgn; break;
5812 case 1: port_id = port_channel_post_aux2_asgn; break;
5813 case 2: port_id = port_channel_post_aux3_asgn; break;
5814 case 3: port_id = port_channel_post_aux4_asgn; break;
5815 case 4: port_id = port_channel_post_aux5_asgn; break;
5816 case 5: port_id = port_channel_post_aux6_asgn; break;
5817 case 6: port_id = port_channel_post_aux7_asgn; break;
5818 case 7: port_id = port_channel_post_aux8_asgn; break;
5820 case 8: port_id = port_channel_post_aux9_asgn; break;
5821 case 9: port_id = port_channel_post_aux10_asgn; break;
5822 case 10: port_id = port_channel_post_aux11_asgn; break;
5823 case 11: port_id = port_channel_post_aux12_asgn; break;
5830 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5841 /* although Ardour sends have enable/disable as part of the Processor
5842 * API, it is not exposed as a controllable.
5844 * XXX: we should fix this (make it click-free, automatable enable-control)
5846 return boost::shared_ptr<AutomationControl>();
5850 Route::send_name (uint32_t n) const
5853 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5854 if (plug && !mixbus()) {
5857 return _session.get_mixbus (n)->name();
5862 return _session.get_mixbus (n)->name();
5868 boost::shared_ptr<Processor> p = nth_send (n);
5876 boost::shared_ptr<AutomationControl>
5877 Route::master_send_enable_controllable () const
5880 if (is_master() || is_monitor() || is_auditioner()) {
5881 return boost::shared_ptr<AutomationControl>();
5884 boost::shared_ptr<ARDOUR::PluginInsert> plug = mixbus() ? ch_pre () : ch_post();
5886 return boost::shared_ptr<AutomationControl>();
5888 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, mixbus() ? 3 : 19)));
5890 return boost::shared_ptr<AutomationControl>();
5895 Route::slaved () const
5897 if (!_gain_control) {
5900 /* just test one particular control, not all of them */
5901 return _gain_control->slaved ();
5905 Route::slaved_to (boost::shared_ptr<VCA> vca) const
5907 if (!vca || !_gain_control) {
5911 /* just test one particular control, not all of them */
5913 return _gain_control->slaved_to (vca->gain_control());
5917 Route::muted_by_others_soloing () const
5919 if (!can_be_muted_by_others ()) {
5923 return _session.soloing() && !_solo_control->soloed() && !_solo_isolate_control->solo_isolated();
5927 Route::clear_all_solo_state ()
5929 _solo_control->clear_all_solo_state ();
5932 boost::shared_ptr<AutomationControl>
5933 Route::automation_control_recurse (PBD::ID const & id) const
5935 boost::shared_ptr<AutomationControl> ac = Automatable::automation_control (id);
5941 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5943 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5944 if ((ac = (*i)->automation_control (id))) {
5949 return boost::shared_ptr<AutomationControl> ();
5953 Route::slavables () const
5955 SlavableControlList rv;
5956 rv.push_back (_gain_control);
5957 rv.push_back (_mute_control);
5958 rv.push_back (_solo_control);
5963 Route::set_disk_io_point (DiskIOPoint diop)
5965 bool display = false;
5967 cerr << "set disk io to " << enum_2_string (diop) << endl;
5978 _disk_writer->set_display_to_user (display);
5982 _disk_reader->set_display_to_user (display);
5985 const bool changed = (diop != _disk_io_point);
5987 _disk_io_point = diop;
5990 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
5991 configure_processors (0);
5994 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
5998 Route::set_loop (Location* l)
6001 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
6002 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
6007 #ifdef USE_TRACKS_CODE_FEATURES
6009 /* This is the Tracks version of Track::monitoring_state().
6011 * Ardour developers: try to flag or fix issues if parts of the libardour API
6012 * change in ways that invalidate this
6016 Route::monitoring_state () const
6018 /* Explicit requests */
6020 if (_monitoring != MonitorInput) {
6021 return MonitoringInput;
6024 if (_monitoring & MonitorDisk) {
6025 return MonitoringDisk;
6028 /* This is an implementation of the truth table in doc/monitor_modes.pdf;
6029 I don't think it's ever going to be too pretty too look at.
6032 // GZ: NOT USED IN TRACKS
6033 //bool const auto_input = _session.config.get_auto_input ();
6034 //bool const software_monitor = Config->get_monitoring_model() == SoftwareMonitoring;
6035 //bool const tape_machine_mode = Config->get_tape_machine_mode ();
6037 bool const roll = _session.transport_rolling ();
6038 bool const track_rec = _diskstream->record_enabled ();
6039 bool session_rec = _session.actively_recording ();
6043 if (!session_rec && roll) {
6044 return MonitoringDisk;
6046 return MonitoringInput;
6052 return MonitoringDisk;
6056 return MonitoringSilence;
6061 /* This is the Ardour/Mixbus version of Track::monitoring_state().
6063 * Tracks developers: do NOT modify this method under any circumstances.
6067 Route::monitoring_state () const
6069 if (!_disk_reader) {
6070 return MonitoringInput;
6073 /* Explicit requests */
6074 MonitorChoice m (_monitoring_control->monitoring_choice());
6076 if (m != MonitorAuto) {
6078 MonitorState ms ((MonitorState) 0);
6080 if (m & MonitorInput) {
6081 ms = MonitoringInput;
6084 if (m & MonitorDisk) {
6085 ms = MonitorState (ms | MonitoringDisk);
6091 switch (_session.config.get_session_monitoring ()) {
6093 return MonitoringDisk;
6096 return MonitoringInput;
6102 return get_auto_monitoring_state();