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? %1\n", _name));
3447 if (other->all_inputs().fed_by (_output)) {
3448 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\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()));
3484 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
3489 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
3494 Route::direct_feeds_according_to_graph (boost::shared_ptr<Route> other, bool* via_send_only)
3496 return _session._current_route_graph.has (boost::dynamic_pointer_cast<Route> (shared_from_this ()), other, via_send_only);
3500 Route::feeds_according_to_graph (boost::shared_ptr<Route> other)
3502 return _session._current_route_graph.feeds (boost::dynamic_pointer_cast<Route> (shared_from_this ()), other);
3505 /** Called from the (non-realtime) butler thread when the transport is stopped */
3507 Route::non_realtime_transport_stop (samplepos_t now, bool flush)
3509 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3511 Automatable::non_realtime_transport_stop (now, flush);
3513 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3515 if (!_have_internal_generator && (Config->get_plugins_stop_with_transport() && flush)) {
3519 (*i)->non_realtime_transport_stop (now, flush);
3524 Route::realtime_handle_transport_stopped ()
3526 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3528 /* currently only by Plugin, queue note-off events */
3529 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3530 (*i)->realtime_handle_transport_stopped ();
3536 Route::input_change_handler (IOChange change, void * /*src*/)
3538 if (_session.loading()) {
3542 if ((change.type & IOChange::ConfigurationChanged)) {
3543 /* This is called with the process lock held if change
3544 contains ConfigurationChanged
3546 configure_processors (0);
3547 io_changed (); /* EMIT SIGNAL */
3550 if (_solo_control->soloed_by_others_upstream() || _solo_isolate_control->solo_isolated_by_upstream()) {
3553 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3554 if (_input->connected()) {
3555 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3556 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3560 bool does_feed = (*i)->direct_feeds_according_to_reality (boost::dynamic_pointer_cast<Route> (shared_from_this()), &sends_only);
3561 if (does_feed && !sends_only) {
3562 if ((*i)->soloed()) {
3565 if ((*i)->solo_isolate_control()->solo_isolated()) {
3572 int delta = sbou - _solo_control->soloed_by_others_upstream();
3573 int idelta = ibou - _solo_isolate_control->solo_isolated_by_upstream();
3576 PBD::warning << string_compose (
3577 _("Invalid Solo-Isolate propagation: from:%1 new:%2 - old:%3 = delta:%4"),
3578 _name, ibou, _solo_isolate_control->solo_isolated_by_upstream(), idelta)
3583 if (_solo_control->soloed_by_others_upstream()) {
3584 // ignore new connections (they're not propagated)
3586 _solo_control->mod_solo_by_others_upstream (delta);
3590 if (_solo_isolate_control->solo_isolated_by_upstream()) {
3591 // solo-isolate currently only propagates downstream
3593 _solo_isolate_control->mod_solo_isolated_by_upstream (1);
3595 //_solo_isolated_by_upstream = ibou;
3598 // Session::route_solo_changed does not propagate indirect solo-changes
3599 // propagate downstream to tracks
3600 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3601 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3605 bool does_feed = feeds (*i, &sends_only);
3606 if (delta <= 0 && does_feed && !sends_only) {
3607 (*i)->solo_control()->mod_solo_by_others_upstream (delta);
3610 if (idelta < 0 && does_feed && !sends_only) {
3611 (*i)->solo_isolate_control()->mod_solo_isolated_by_upstream (-1);
3618 Route::output_change_handler (IOChange change, void * /*src*/)
3620 if (_initial_io_setup) {
3624 if ((change.type & IOChange::ConfigurationChanged)) {
3625 /* This is called with the process lock held if change
3626 contains ConfigurationChanged
3628 configure_processors (0);
3631 _session.reset_monitor_section();
3634 io_changed (); /* EMIT SIGNAL */
3637 if ((change.type & IOChange::ConnectionsChanged)) {
3639 /* do this ONLY if connections have changed. Configuration
3640 * changes do not, by themselves alter solo upstream or
3641 * downstream status.
3644 if (_solo_control->soloed_by_others_downstream()) {
3646 /* checking all all downstream routes for
3647 * explicit of implict solo is a rather drastic measure,
3648 * ideally the input_change_handler() of the other route
3649 * would propagate the change to us.
3651 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3652 if (_output->connected()) {
3653 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3654 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3658 bool does_feed = direct_feeds_according_to_reality (*i, &sends_only);
3659 if (does_feed && !sends_only) {
3660 if ((*i)->soloed()) {
3668 int delta = sbod - _solo_control->soloed_by_others_downstream();
3670 // do not allow new connections to change implicit solo (no propagation)
3671 _solo_control->mod_solo_by_others_downstream (delta);
3672 // Session::route_solo_changed() does not propagate indirect solo-changes
3673 // propagate upstream to tracks
3674 boost::shared_ptr<Route> shared_this = boost::dynamic_pointer_cast<Route> (shared_from_this());
3675 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3676 if ((*i).get() == this || !can_solo()) {
3680 bool does_feed = (*i)->feeds (shared_this, &sends_only);
3681 if (delta != 0 && does_feed && !sends_only) {
3682 (*i)->solo_control()->mod_solo_by_others_downstream (delta);
3692 Route::sidechain_change_handler (IOChange change, void* src)
3694 if (_initial_io_setup || _in_sidechain_setup) {
3698 input_change_handler (change, src);
3702 Route::pans_required () const
3704 if (n_outputs().n_audio() < 2) {
3708 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
3712 Route::flush_processor_buffers_locked (samplecnt_t nframes)
3714 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3715 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery> (*i);
3717 d->flush_buffers (nframes);
3719 boost::shared_ptr<PortInsert> p = boost::dynamic_pointer_cast<PortInsert> (*i);
3721 p->flush_buffers (nframes);
3728 Route::flush_processors ()
3730 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3732 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3738 Route::playback_latency (bool incl_downstream) const
3742 rv = _disk_reader->output_latency ();
3744 rv = _signal_latency;
3746 if (incl_downstream) {
3747 rv += _output->connected_latency (true);
3749 rv += _output->latency ();
3755 Route::latency_preroll (pframes_t nframes, samplepos_t& start_sample, samplepos_t& end_sample)
3757 samplecnt_t latency_preroll = _session.remaining_latency_preroll ();
3758 if (latency_preroll == 0) {
3761 if (!_disk_reader) {
3762 start_sample -= latency_preroll;
3763 end_sample -= latency_preroll;
3767 if (latency_preroll > playback_latency ()) {
3768 no_roll_unlocked (nframes, start_sample - latency_preroll, end_sample - latency_preroll, false);
3772 start_sample -= latency_preroll;
3773 end_sample -= latency_preroll;
3778 Route::roll (pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, bool& need_butler)
3780 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3787 silence_unlocked (nframes);
3792 if ((nframes = latency_preroll (nframes, start_sample, end_sample)) == 0) {
3796 run_route (start_sample, end_sample, nframes, (!_disk_writer || !_disk_writer->record_enabled()) && _session.transport_rolling(), true);
3798 if ((_disk_reader && _disk_reader->need_butler()) || (_disk_writer && _disk_writer->need_butler())) {
3805 Route::no_roll (pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, bool session_state_changing)
3807 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3813 return no_roll_unlocked (nframes, start_sample, end_sample, session_state_changing);
3817 Route::no_roll_unlocked (pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, bool session_state_changing)
3819 /* Must be called with the processor lock held */
3822 silence_unlocked (nframes);
3827 if (session_state_changing) {
3828 if (_session.transport_speed() != 0.0f) {
3829 /* we're rolling but some state is changing (e.g. our diskstream contents)
3830 so we cannot use them. Be silent till this is over.
3832 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
3834 silence_unlocked (nframes);
3838 /* we're really not rolling, so we're either delivery silence or actually
3839 monitoring, both of which are safe to do while session_state_changing is true.
3843 run_route (start_sample, end_sample, nframes, false, false);
3848 Route::silent_roll (pframes_t nframes, samplepos_t /*start_sample*/, samplepos_t /*end_sample*/, bool& /* need_butler */)
3851 flush_processor_buffers_locked (nframes);
3856 __attribute__((annotate("realtime")))
3859 Route::apply_processor_changes_rt ()
3861 int emissions = EmitNone;
3863 if (_pending_meter_point != _meter_point) {
3864 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3866 /* meters always have buffers for 'processor_max_streams'
3867 * they can be re-positioned without re-allocation */
3868 if (set_meter_point_unlocked()) {
3869 emissions |= EmitMeterChanged | EmitMeterVisibilityChange;;
3871 emissions |= EmitMeterChanged;
3876 bool changed = false;
3878 if (g_atomic_int_get (&_pending_process_reorder)) {
3879 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3881 apply_processor_order (_pending_processor_order);
3882 setup_invisible_processors ();
3884 g_atomic_int_set (&_pending_process_reorder, 0);
3885 emissions |= EmitRtProcessorChange;
3889 set_processor_positions ();
3890 /* update processor input/output latency
3891 * (total signal_latency does not change)
3893 update_signal_latency (true);
3895 if (emissions != 0) {
3896 g_atomic_int_set (&_pending_signals, emissions);
3899 return (!selfdestruct_sequence.empty ());
3903 Route::emit_pending_signals ()
3905 int sig = g_atomic_int_and (&_pending_signals, 0);
3906 if (sig & EmitMeterChanged) {
3907 _meter->emit_configuration_changed();
3908 meter_change (); /* EMIT SIGNAL */
3909 if (sig & EmitMeterVisibilityChange) {
3910 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3912 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3915 if (sig & EmitRtProcessorChange) {
3916 processors_changed (RouteProcessorChange (RouteProcessorChange::RealTimeChange)); /* EMIT SIGNAL */
3919 /* this would be a job for the butler.
3920 * Conceptually we should not take processe/processor locks here.
3921 * OTOH its more efficient (less overhead for summoning the butler and
3922 * telling her what do do) and signal emission is called
3923 * directly after the process callback, which decreases the chance
3924 * of x-runs when taking the locks.
3926 while (!selfdestruct_sequence.empty ()) {
3927 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
3928 if (selfdestruct_sequence.empty ()) { break; } // re-check with lock
3929 boost::shared_ptr<Processor> proc = selfdestruct_sequence.back ().lock ();
3930 selfdestruct_sequence.pop_back ();
3933 remove_processor (proc);
3939 Route::set_meter_point (MeterPoint p, bool force)
3941 if (_pending_meter_point == p && !force) {
3945 if (force || !AudioEngine::instance()->running()) {
3946 bool meter_visibly_changed = false;
3948 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3949 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3950 _pending_meter_point = p;
3951 if (set_meter_point_unlocked ()) {
3952 meter_visibly_changed = true;
3955 _meter->emit_configuration_changed();
3956 meter_change (); /* EMIT SIGNAL */
3957 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, meter_visibly_changed)); /* EMIT SIGNAL */
3959 _pending_meter_point = p;
3965 __attribute__((annotate("realtime")))
3968 Route::set_meter_point_unlocked ()
3971 /* Caller must hold process and processor write lock */
3972 assert (!AudioEngine::instance()->process_lock().trylock());
3973 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3974 assert (!lm.locked ());
3977 _meter_point = _pending_meter_point;
3979 bool meter_was_visible_to_user = _meter->display_to_user ();
3981 if (!_custom_meter_position_noted) {
3982 maybe_note_meter_position ();
3985 if (_meter_point != MeterCustom) {
3987 _meter->set_display_to_user (false);
3989 setup_invisible_processors ();
3992 _meter->set_display_to_user (true);
3994 /* If we have a previous position for the custom meter, try to put it there */
3995 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
3997 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), after);
3998 if (i != _processors.end ()) {
3999 _processors.remove (_meter);
4000 _processors.insert (i, _meter);
4002 } else {// at end, right before the mains_out/panner
4003 _processors.remove (_meter);
4004 ProcessorList::iterator main = _processors.end();
4005 _processors.insert (--main, _meter);
4009 /* Set up the meter for its new position */
4011 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
4015 if (loc == _processors.begin()) {
4016 m_in = _input->n_ports();
4018 ProcessorList::iterator before = loc;
4020 m_in = (*before)->output_streams ();
4023 _meter->reflect_inputs (m_in);
4025 /* we do not need to reconfigure the processors, because the meter
4026 (a) is always ready to handle processor_max_streams
4027 (b) is always an N-in/N-out processor, and thus moving
4028 it doesn't require any changes to the other processors.
4031 /* these should really be done after releasing the lock
4032 * but all those signals are subscribed to with gui_thread()
4035 return (_meter->display_to_user() != meter_was_visible_to_user);
4039 Route::listen_position_changed ()
4042 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4043 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
4044 ProcessorState pstate (this);
4046 if (configure_processors_unlocked (0, &lm)) {
4047 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
4049 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
4054 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
4055 _session.set_dirty ();
4058 boost::shared_ptr<CapturingProcessor>
4059 Route::add_export_point()
4061 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4062 if (!_capturing_processor) {
4064 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4065 Glib::Threads::RWLock::WriterLock lw (_processor_lock);
4067 /* Align all tracks for stem-export w/o processing.
4068 * Compensate for all plugins between the this route's disk-reader
4069 * and the common final downstream output (ie alignment point for playback).
4071 _capturing_processor.reset (new CapturingProcessor (_session, playback_latency (true)));
4072 configure_processors_unlocked (0, &lw);
4073 _capturing_processor->activate ();
4076 return _capturing_processor;
4080 Route::update_signal_latency (bool apply_to_delayline)
4082 // TODO: bail out if !active() and set/assume _signal_latency = 0,
4083 // here or in Session::* ? -> also zero send latencies,
4084 // and make sure that re-enabling a route updates things again...
4086 samplecnt_t capt_lat_in = _input->connected_latency (false);
4087 samplecnt_t play_lat_out = _output->connected_latency (true);
4089 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4091 samplecnt_t l_in = 0;
4092 samplecnt_t l_out = _output->effective_latency ();
4093 for (ProcessorList::reverse_iterator i = _processors.rbegin(); i != _processors.rend(); ++i) {
4094 if (boost::shared_ptr<Send> snd = boost::dynamic_pointer_cast<Send> (*i)) {
4095 snd->set_delay_in (l_out + _output->latency());
4098 if (boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) {
4099 if (boost::shared_ptr<IO> pio = pi->sidechain_input ()) {
4100 samplecnt_t lat = l_out + _output->latency();
4101 pio->set_private_port_latencies (lat, true);
4102 pio->set_public_port_latencies (lat, true);
4105 (*i)->set_output_latency (l_out);
4106 if ((*i)->active ()) { // XXX
4107 l_out += (*i)->effective_latency ();
4111 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal signal latency = %2\n", _name, l_out));
4113 _signal_latency = l_out;
4115 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4117 /* set sidechain, send and insert port latencies */
4118 if (boost::shared_ptr<PortInsert> pi = boost::dynamic_pointer_cast<PortInsert> (*i)) {
4120 /* propagate playback latency from output to input */
4121 pi->input ()->set_private_port_latencies (play_lat_out + l_in, true);
4123 if (pi->output ()) {
4124 /* propagate capture latency from input to output */
4125 pi->output ()->set_private_port_latencies (capt_lat_in + l_in, false);
4128 } else if (boost::shared_ptr<Send> snd = boost::dynamic_pointer_cast<Send> (*i)) {
4129 if (snd->output ()) {
4130 /* set capture latency */
4131 snd->output ()->set_private_port_latencies (capt_lat_in + l_in, false);
4132 /* take send-target's playback latency into account */
4133 snd->set_delay_out (snd->output ()->connected_latency (true));
4137 (*i)->set_input_latency (l_in);
4138 (*i)->set_playback_offset (_signal_latency + _output->latency ());
4139 (*i)->set_capture_offset (_input->latency ());
4140 if ((*i)->active ()) {
4141 l_in += (*i)->effective_latency ();
4147 if (apply_to_delayline) {
4148 /* see also Session::post_playback_latency() */
4149 apply_latency_compensation ();
4152 if (_signal_latency != l_out) {
4153 signal_latency_changed (); /* EMIT SIGNAL */
4156 return _signal_latency;
4160 Route::set_user_latency (samplecnt_t nframes)
4162 _output->set_user_latency (nframes);
4163 _session.update_latency_compensation ();
4167 Route::apply_latency_compensation ()
4170 samplecnt_t old = _delayline->delay ();
4172 samplecnt_t play_lat_in = _input->connected_latency (true);
4173 samplecnt_t play_lat_out = _output->connected_latency (true);
4174 samplecnt_t latcomp = play_lat_in - play_lat_out - _signal_latency;
4177 samplecnt_t capt_lat_in = _input->connected_latency (false);
4178 samplecnt_t capt_lat_out = _output->connected_latency (false);
4179 samplecnt_t latcomp_capt = capt_lat_out - capt_lat_in - _signal_latency;
4181 cout << "ROUTE " << name() << " delay for " << latcomp << " (c: " << latcomp_capt << ")" << endl;
4184 _delayline->set_delay (latcomp > 0 ? latcomp : 0);
4186 if (old != _delayline->delay ()) {
4187 signal_latency_updated (); /* EMIT SIGNAL */
4193 Route::set_block_size (pframes_t nframes)
4195 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4196 (*i)->set_block_size (nframes);
4199 _session.ensure_buffers (n_process_buffers ());
4203 Route::protect_automation ()
4205 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
4206 (*i)->protect_automation();
4209 /** Shift automation forwards from a particular place, thereby inserting time.
4210 * Adds undo commands for any shifts that are performed.
4212 * @param pos Position to start shifting from.
4213 * @param samples Amount to shift forwards by.
4217 Route::shift (samplepos_t pos, samplecnt_t samples)
4219 /* pan automation */
4221 ControlSet::Controls& c (_pannable->controls());
4223 for (ControlSet::Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
4224 boost::shared_ptr<AutomationControl> pc = boost::dynamic_pointer_cast<AutomationControl> (ci->second);
4226 boost::shared_ptr<AutomationList> al = pc->alist();
4227 XMLNode& before = al->get_state ();
4228 al->shift (pos, samples);
4229 XMLNode& after = al->get_state ();
4230 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4235 /* TODO mute automation, MuteControl */
4237 /* processor automation (incl. gain, trim,..) */
4239 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4240 for (ProcessorList::iterator i = _processors.begin (); i != _processors.end (); ++i) {
4242 set<Evoral::Parameter> parameters = (*i)->what_can_be_automated();
4244 for (set<Evoral::Parameter>::const_iterator p = parameters.begin (); p != parameters.end (); ++p) {
4245 boost::shared_ptr<AutomationControl> ac = (*i)->automation_control (*p);
4247 boost::shared_ptr<AutomationList> al = ac->alist();
4251 XMLNode &before = al->get_state ();
4252 al->shift (pos, samples);
4253 XMLNode &after = al->get_state ();
4254 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4262 Route::set_plugin_state_dir (boost::weak_ptr<Processor> p, const std::string& d)
4264 boost::shared_ptr<Processor> processor (p.lock ());
4265 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
4269 pi->set_state_dir (d);
4273 Route::save_as_template (const string& path, const string& name, const string& description)
4275 std::string state_dir = path.substr (0, path.find_last_of ('.')); // strip template_suffix
4276 PBD::Unwinder<std::string> uw (_session._template_state_dir, state_dir);
4278 XMLNode& node (state (true));
4279 node.set_property (X_("name"), name);
4281 node.remove_nodes (X_("description"));
4282 if (!description.empty()) {
4283 XMLNode* desc = new XMLNode(X_("description"));
4284 XMLNode* desc_cont = new XMLNode(X_("content"), description);
4285 desc->add_child_nocopy (*desc_cont);
4287 node.add_child_nocopy (*desc);
4292 IO::set_name_in_state (*node.children().front(), name);
4294 tree.set_root (&node);
4296 /* return zero on success, non-zero otherwise */
4297 return !tree.write (path.c_str());
4302 Route::set_name (const string& str)
4308 if (str == name()) {
4312 string newname = Route::ensure_track_or_route_name (str);
4314 if (newname == name()) {
4318 SessionObject::set_name (newname);
4320 for (uint32_t n = 0 ; ; ++n) {
4321 boost::shared_ptr<PluginInsert> pi = boost::static_pointer_cast<PluginInsert> (nth_plugin (n));
4325 pi->update_sidechain_name ();
4328 bool ret = (_input->set_name(newname) && _output->set_name(newname));
4331 /* rename the main outs. Leave other IO processors
4332 * with whatever name they already have, because its
4333 * just fine as it is (it will not contain the route
4334 * name if its a port insert, port send or port return).
4338 if (_main_outs->set_name (newname)) {
4339 /* XXX returning false here is stupid because
4340 we already changed the route name.
4350 /** Set the name of a route in an XML description.
4351 * @param node XML <Route> node to set the name in.
4352 * @param name New name.
4355 Route::set_name_in_state (XMLNode& node, string const & name)
4357 node.set_property (X_("name"), name);
4359 XMLNodeList children = node.children();
4360 for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
4362 if ((*i)->name() == X_("IO")) {
4364 IO::set_name_in_state (**i, name);
4366 } else if ((*i)->name() == X_("Processor")) {
4369 if ((*i)->get_property (X_("role"), str) && str == X_("Main")) {
4370 (*i)->set_property (X_("name"), name);
4376 boost::shared_ptr<Send>
4377 Route::internal_send_for (boost::shared_ptr<const Route> target) const
4379 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4381 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4382 boost::shared_ptr<InternalSend> send;
4384 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
4385 if (send->target_route() == target) {
4391 return boost::shared_ptr<Send>();
4395 Route::set_denormal_protection (bool yn)
4397 if (_denormal_protection != yn) {
4398 _denormal_protection = yn;
4399 denormal_protection_changed (); /* EMIT SIGNAL */
4404 Route::denormal_protection () const
4406 return _denormal_protection;
4410 Route::set_active (bool yn, void* src)
4412 if (_session.transport_rolling()) {
4416 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_route_active()) {
4417 _route_group->foreach_route (boost::bind (&Route::set_active, _1, yn, _route_group));
4421 if (_active != yn) {
4423 _input->set_active (yn);
4424 _output->set_active (yn);
4425 flush_processors ();
4426 active_changed (); // EMIT SIGNAL
4427 _session.set_dirty ();
4431 boost::shared_ptr<Pannable>
4432 Route::pannable() const
4437 boost::shared_ptr<Panner>
4438 Route::panner() const
4441 return _main_outs->panner_shell()->panner();
4444 boost::shared_ptr<PannerShell>
4445 Route::panner_shell() const
4447 return _main_outs->panner_shell();
4450 boost::shared_ptr<GainControl>
4451 Route::gain_control() const
4453 return _gain_control;
4456 boost::shared_ptr<GainControl>
4457 Route::trim_control() const
4459 return _trim_control;
4462 boost::shared_ptr<PhaseControl>
4463 Route::phase_control() const
4465 return _phase_control;
4468 boost::shared_ptr<AutomationControl>
4469 Route::get_control (const Evoral::Parameter& param)
4471 /* either we own the control or .... */
4473 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
4477 /* maybe one of our processors does or ... */
4479 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
4480 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4481 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
4489 /* nobody does so we'll make a new one */
4491 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
4498 boost::shared_ptr<Processor>
4499 Route::nth_plugin (uint32_t n) const
4501 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4502 ProcessorList::const_iterator i;
4504 for (i = _processors.begin(); i != _processors.end(); ++i) {
4505 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
4512 return boost::shared_ptr<Processor> ();
4515 boost::shared_ptr<Processor>
4516 Route::nth_send (uint32_t n) const
4518 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4519 ProcessorList::const_iterator i;
4521 for (i = _processors.begin(); i != _processors.end(); ++i) {
4522 if (boost::dynamic_pointer_cast<Send> (*i)) {
4524 if ((*i)->name().find (_("Monitor")) == 0) {
4525 /* send to monitor section is not considered
4526 to be an accessible send.
4537 return boost::shared_ptr<Processor> ();
4541 Route::has_io_processor_named (const string& name)
4543 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4544 ProcessorList::iterator i;
4546 for (i = _processors.begin(); i != _processors.end(); ++i) {
4547 if (boost::dynamic_pointer_cast<Send> (*i) ||
4548 boost::dynamic_pointer_cast<PortInsert> (*i)) {
4549 if ((*i)->name() == name) {
4559 Route::set_processor_positions ()
4561 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4563 bool had_amp = false;
4564 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4565 (*i)->set_pre_fader (!had_amp);
4572 /** Called when there is a proposed change to the input port count */
4574 Route::input_port_count_changing (ChanCount to)
4576 list<pair<ChanCount, ChanCount> > c = try_configure_processors (to, 0);
4578 /* The processors cannot be configured with the new input arrangement, so
4584 /* The change is ok */
4588 /** Called when there is a proposed change to the output port count */
4590 Route::output_port_count_changing (ChanCount to)
4592 if (_strict_io && !_in_configure_processors) {
4595 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
4596 if (processor_out_streams.get(*t) > to.get(*t)) {
4600 /* The change is ok */
4605 Route::unknown_processors () const
4609 if (_session.get_disable_all_loaded_plugins ()) {
4610 // Do not list "missing plugins" if they are explicitly disabled
4614 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4615 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4616 if (boost::dynamic_pointer_cast<UnknownProcessor const> (*i)) {
4617 p.push_back ((*i)->name ());
4626 Route::update_port_latencies (PortSet& from, PortSet& to, bool playback, samplecnt_t our_latency) const
4628 /* we assume that all our input ports feed all our output ports. its not
4629 universally true, but the alternative is way too corner-case to worry about.
4632 LatencyRange all_connections;
4635 all_connections.min = 0;
4636 all_connections.max = 0;
4638 all_connections.min = ~((pframes_t) 0);
4639 all_connections.max = 0;
4641 /* iterate over all "from" ports and determine the latency range for all of their
4642 connections to the "outside" (outside of this Route).
4645 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4649 p->get_connected_latency_range (range, playback);
4651 all_connections.min = min (all_connections.min, range.min);
4652 all_connections.max = max (all_connections.max, range.max);
4656 /* set the "from" port latencies to the max/min range of all their connections */
4658 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4659 p->set_private_latency_range (all_connections, playback);
4662 /* set the ports "in the direction of the flow" to the same value as above plus our own signal latency */
4664 all_connections.min += our_latency;
4665 all_connections.max += our_latency;
4667 for (PortSet::iterator p = to.begin(); p != to.end(); ++p) {
4668 p->set_private_latency_range (all_connections, playback);
4671 return all_connections.max;
4675 Route::set_private_port_latencies (bool playback) const
4677 samplecnt_t own_latency = 0;
4679 /* Processor list not protected by lock: MUST BE CALLED FROM PROCESS THREAD
4680 OR LATENCY CALLBACK.
4682 This is called (early) from the latency callback. It computes the REAL
4683 latency associated with each port and stores the result as the "private"
4684 latency of the port. A later call to Route::set_public_port_latencies()
4685 sets all ports to the same value to reflect the fact that we do latency
4686 compensation and so all signals are delayed by the same amount as they
4687 flow through ardour.
4690 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4692 if ((*i)->active ()) {
4693 own_latency += (*i)->effective_latency ();
4698 /* playback: propagate latency from "outside the route" to outputs to inputs */
4699 return update_port_latencies (_output->ports (), _input->ports (), true, own_latency);
4701 /* capture: propagate latency from "outside the route" to inputs to outputs */
4702 return update_port_latencies (_input->ports (), _output->ports (), false, own_latency);
4707 Route::set_public_port_latencies (samplecnt_t value, bool playback) const
4709 /* publish private latencies */
4710 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4711 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4712 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*i);
4716 if (iop->input ()) {
4717 iop->input ()->set_public_port_latencies (iop->input()->latency(), true);
4719 if (iop->output ()) {
4720 iop->output ()->set_public_port_latencies (iop->output()->latency(), false);
4724 /* this is called to set the JACK-visible port latencies, which take
4725 * latency compensation into account.
4727 _input->set_public_port_latencies (value, playback);
4728 _output->set_public_port_latencies (value, playback);
4731 /** Put the invisible processors in the right place in _processors.
4732 * Must be called with a writer lock on _processor_lock held.
4735 __attribute__((annotate("realtime")))
4738 Route::setup_invisible_processors ()
4741 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4742 assert (!lm.locked ());
4746 /* too early to be doing this stuff */
4750 /* we'll build this new list here and then use it
4752 * TODO put the ProcessorList is on the stack for RT-safety.
4755 ProcessorList new_processors;
4756 ProcessorList foldback_sends;
4757 ProcessorList::iterator dr;
4758 ProcessorList::iterator dw;
4760 /* find visible processors */
4762 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4763 boost::shared_ptr<Send> auxsnd = boost::dynamic_pointer_cast<Send> ((*i));
4764 if ((*i)->display_to_user ()) {
4765 new_processors.push_back (*i);
4767 else if (auxsnd && auxsnd->is_foldback ()) {
4768 foldback_sends.push_back (*i);
4774 ProcessorList::iterator amp = find (new_processors.begin(), new_processors.end(), _amp);
4776 if (amp == new_processors.end ()) {
4777 error << string_compose (_("Amp/Fader on Route '%1' went AWOL. Re-added."), name()) << endmsg;
4778 new_processors.push_front (_amp);
4779 amp = find (new_processors.begin(), new_processors.end(), _amp);
4782 /* and the processor after the amp */
4784 ProcessorList::iterator after_amp = amp;
4787 /* Pre-fader METER */
4789 if (_meter && _meter_point == MeterPreFader) {
4790 /* add meter just before the fader */
4791 assert (!_meter->display_to_user ());
4792 new_processors.insert (amp, _meter);
4797 assert (_main_outs);
4798 assert (!_main_outs->display_to_user ());
4799 new_processors.push_back (_main_outs);
4801 /* iterator for the main outs */
4803 ProcessorList::iterator main = new_processors.end();
4806 /* OUTPUT METERING */
4808 if (_meter && (_meter_point == MeterOutput || _meter_point == MeterPostFader)) {
4809 assert (!_meter->display_to_user ());
4811 /* add the processor just before or just after the main outs */
4813 ProcessorList::iterator meter_point = main;
4815 if (_meter_point == MeterOutput) {
4818 new_processors.insert (meter_point, _meter);
4821 /* Foldback Sends */
4823 for (ProcessorList::iterator i = foldback_sends.begin(); i != foldback_sends.end(); ++i) {
4824 new_processors.insert (amp, (*i));
4829 if (_monitor_send && !is_monitor ()) {
4830 assert (!_monitor_send->display_to_user ());
4831 switch (Config->get_listen_position ()) {
4832 case PreFaderListen:
4833 switch (Config->get_pfl_position ()) {
4834 case PFLFromBeforeProcessors:
4835 new_processors.push_front (_monitor_send);
4837 case PFLFromAfterProcessors:
4838 new_processors.insert (amp, _monitor_send);
4841 _monitor_send->set_can_pan (false);
4843 case AfterFaderListen:
4844 switch (Config->get_afl_position ()) {
4845 case AFLFromBeforeProcessors:
4846 new_processors.insert (after_amp, _monitor_send);
4848 case AFLFromAfterProcessors:
4849 new_processors.insert (new_processors.end(), _monitor_send);
4852 _monitor_send->set_can_pan (true);
4857 /* MONITOR CONTROL */
4859 if (_monitor_control && is_monitor ()) {
4860 assert (!_monitor_control->display_to_user ());
4861 new_processors.insert (amp, _monitor_control);
4866 ProcessorList::iterator trim = new_processors.end();
4868 if (_trim->active()) {
4869 assert (!_trim->display_to_user ());
4870 new_processors.push_front (_trim);
4871 trim = new_processors.begin();
4874 /* INTERNAL RETURN */
4876 /* doing this here means that any monitor control will come after
4877 the return and trim.
4881 assert (!_intreturn->display_to_user ());
4882 new_processors.push_front (_intreturn);
4885 /* DISK READER & WRITER (for Track objects) */
4887 if (_disk_reader || _disk_writer) {
4888 switch (_disk_io_point) {
4889 case DiskIOPreFader:
4890 if (trim != new_processors.end()) {
4891 /* insert BEFORE TRIM */
4893 new_processors.insert (trim, _disk_writer);
4896 new_processors.insert (trim, _disk_reader);
4900 new_processors.push_front (_disk_writer);
4903 new_processors.push_front (_disk_reader);
4907 case DiskIOPostFader:
4908 /* insert BEFORE main outs */
4910 new_processors.insert (main, _disk_writer);
4913 new_processors.insert (main, _disk_reader);
4917 /* reader and writer are visible under this condition, so they
4918 * are not invisible and thus not handled here.
4924 /* ensure dist-writer is before disk-reader */
4925 if (_disk_reader && _disk_writer) {
4926 ProcessorList::iterator reader_pos = find (new_processors.begin(), new_processors.end(), _disk_reader);
4927 ProcessorList::iterator writer_pos = find (new_processors.begin(), new_processors.end(), _disk_writer);
4928 assert (reader_pos != new_processors.end ());
4929 assert (writer_pos != new_processors.end ());
4930 if (std::distance (new_processors.begin(), reader_pos) < std::distance (new_processors.begin(), writer_pos)) {
4931 new_processors.erase (reader_pos);
4932 assert (writer_pos == find (new_processors.begin(), new_processors.end(), _disk_writer));
4933 new_processors.insert (++writer_pos, _disk_reader);
4937 /* EXPORT PROCESSOR */
4938 if (_capturing_processor) {
4939 assert (!_capturing_processor->display_to_user ());
4940 ProcessorList::iterator reader_pos = find (new_processors.begin(), new_processors.end(), _disk_reader);
4941 if (reader_pos != new_processors.end()) {
4942 /* insert after disk-reader */
4943 new_processors.insert (++reader_pos, _capturing_processor);
4945 ProcessorList::iterator return_pos = find (new_processors.begin(), new_processors.end(), _intreturn);
4946 /* insert after return */
4947 if (return_pos != new_processors.end()) {
4948 new_processors.insert (++return_pos, _capturing_processor);
4950 new_processors.push_front (_capturing_processor);
4955 /* Polarity Invert */
4957 ProcessorList::iterator reader_pos = find (new_processors.begin(), new_processors.end(), _disk_reader);
4958 if (reader_pos != new_processors.end()) {
4959 /* insert after disk-reader */
4960 new_processors.insert (++reader_pos, _polarity);
4962 ProcessorList::iterator return_pos = find (new_processors.begin(), new_processors.end(), _intreturn);
4963 /* insert after return */
4964 if (return_pos != new_processors.end()) {
4965 new_processors.insert (++return_pos, _polarity);
4967 new_processors.push_front (_polarity);
4973 if (_meter && _meter_point == MeterInput) {
4974 /* add meter just before the disk-writer (if any)
4975 * otherwise at the top, but after the latency delayline
4976 * (perhaps it should also be after intreturn on busses ??)
4978 assert (!_meter->display_to_user ());
4979 ProcessorList::iterator writer_pos = find (new_processors.begin(), new_processors.end(), _disk_writer);
4980 if (writer_pos != new_processors.end()) {
4981 /* insert before disk-writer */
4982 new_processors.insert (writer_pos, _meter);
4984 ProcessorList::iterator return_pos = find (new_processors.begin(), new_processors.end(), _intreturn);
4985 /* insert after return */
4986 if (return_pos != new_processors.end()) {
4987 new_processors.insert (++return_pos, _meter);
4989 new_processors.push_front (_meter);
4994 if (!is_master() && !is_monitor() && !is_auditioner()) {
4995 ProcessorList::iterator reader_pos = find (new_processors.begin(), new_processors.end(), _disk_reader);
4996 if (reader_pos != new_processors.end()) {
4997 /* insert before disk-reader */
4998 new_processors.insert (reader_pos, _delayline);
5000 new_processors.push_front (_delayline);
5004 _processors = new_processors;
5006 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5007 if (!(*i)->display_to_user () && !(*i)->enabled () && (*i) != _monitor_send) {
5008 (*i)->enable (true);
5012 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: setup_invisible_processors\n", _name));
5013 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5014 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1\n", (*i)->name ()));
5021 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
5022 Glib::Threads::RWLock::ReaderLock lp (_processor_lock);
5026 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5027 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*i);
5034 /** If the meter point is `Custom', make a note of where the meter is.
5035 * This is so that if the meter point is subsequently set to something else,
5036 * and then back to custom, we can put the meter back where it was last time
5037 * custom was enabled.
5039 * Must be called with the _processor_lock held.
5042 Route::maybe_note_meter_position ()
5044 if (_meter_point != MeterCustom) {
5048 _custom_meter_position_noted = true;
5049 /* custom meter points range from after trim to before panner/main_outs
5050 * this is a limitation by the current processor UI
5052 bool seen_trim = false;
5053 _processor_after_last_custom_meter.reset();
5054 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5055 if ((*i) == _trim) {
5058 if ((*i) == _main_outs) {
5059 _processor_after_last_custom_meter = *i;
5062 if (boost::dynamic_pointer_cast<PeakMeter> (*i)) {
5064 _processor_after_last_custom_meter = _trim;
5066 ProcessorList::iterator j = i;
5068 assert(j != _processors.end ()); // main_outs should be before
5069 _processor_after_last_custom_meter = *j;
5074 assert(_processor_after_last_custom_meter.lock());
5077 boost::shared_ptr<Processor>
5078 Route::processor_by_id (PBD::ID id) const
5080 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5081 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5082 if ((*i)->id() == id) {
5087 return boost::shared_ptr<Processor> ();
5090 /** @return what we should be metering; either the data coming from the input
5091 * IO or the data that is flowing through the route.
5094 Route::metering_state () const
5096 return MeteringRoute;
5100 Route::has_external_redirects () const
5102 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5104 /* ignore inactive processors and obviously ignore the main
5105 * outs since everything has them and we don't care.
5108 if ((*i)->active() && (*i) != _main_outs && (*i)->does_routing()) {
5116 boost::shared_ptr<Processor>
5117 Route::the_instrument () const
5119 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5120 return the_instrument_unlocked ();
5123 boost::shared_ptr<Processor>
5124 Route::the_instrument_unlocked () const
5126 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5127 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
5128 if (pi && pi->plugin ()->get_info ()->is_instrument ()) {
5132 return boost::shared_ptr<Processor>();
5138 return dynamic_cast<Track*>(this) != 0;
5142 Route::non_realtime_locate (samplepos_t pos)
5144 Automatable::non_realtime_locate (pos);
5147 _pannable->non_realtime_locate (pos);
5150 #if 0 // XXX mayhaps clear delayline here (and at stop?)
5152 _delayline->flush ();
5157 //Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
5158 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5160 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
5161 (*i)->non_realtime_locate (pos);
5167 Route::fill_buffers_with_input (BufferSet& bufs, boost::shared_ptr<IO> io, pframes_t nframes)
5174 * We don't currently mix MIDI input together, so we don't need the
5175 * complex logic of the audio case.
5178 n_buffers = bufs.count().n_midi ();
5180 for (i = 0; i < n_buffers; ++i) {
5182 boost::shared_ptr<MidiPort> source_port = io->midi (i);
5183 MidiBuffer& buf (bufs.get_midi (i));
5186 buf.copy (source_port->get_midi_buffer(nframes));
5188 buf.silence (nframes);
5194 n_buffers = bufs.count().n_audio();
5196 size_t n_ports = io->n_ports().n_audio();
5197 float scaling = 1.0f;
5199 if (n_ports > n_buffers) {
5200 scaling = ((float) n_buffers) / n_ports;
5203 for (i = 0; i < n_ports; ++i) {
5205 /* if there are more ports than buffers, map them onto buffers
5206 * in a round-robin fashion
5209 boost::shared_ptr<AudioPort> source_port = io->audio (i);
5210 AudioBuffer& buf (bufs.get_audio (i%n_buffers));
5212 if (i < n_buffers) {
5214 /* first time through just copy a channel into
5218 buf.read_from (source_port->get_audio_buffer (nframes), nframes);
5220 if (scaling != 1.0f) {
5221 buf.apply_gain (scaling, nframes);
5226 /* on subsequent times around, merge data from
5227 * the port with what is already there
5230 if (scaling != 1.0f) {
5231 buf.accumulate_with_gain_from (source_port->get_audio_buffer (nframes), nframes, 0, scaling);
5233 buf.accumulate_from (source_port->get_audio_buffer (nframes), nframes);
5238 /* silence any remaining buffers */
5240 for (; i < n_buffers; ++i) {
5241 AudioBuffer& buf (bufs.get_audio (i));
5242 buf.silence (nframes);
5245 /* establish the initial setup of the buffer set, reflecting what was
5246 copied into it. unless, of course, we are the auditioner, in which
5247 case nothing was fed into it from the inputs at all.
5250 if (!is_auditioner()) {
5251 bufs.set_count (io->n_ports());
5255 boost::shared_ptr<AutomationControl>
5256 Route::pan_azimuth_control() const
5259 # undef MIXBUS_PORTS_H
5260 # include "../../gtk2_ardour/mixbus_ports.h"
5261 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5263 return boost::shared_ptr<AutomationControl>();
5265 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_pan)));
5267 if (!_pannable || !panner()) {
5268 return boost::shared_ptr<AutomationControl>();
5270 return _pannable->pan_azimuth_control;
5274 boost::shared_ptr<AutomationControl>
5275 Route::pan_elevation_control() const
5277 if (Profile->get_mixbus() || !_pannable || !panner()) {
5278 return boost::shared_ptr<AutomationControl>();
5281 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5283 if (c.find (PanElevationAutomation) != c.end()) {
5284 return _pannable->pan_elevation_control;
5286 return boost::shared_ptr<AutomationControl>();
5289 boost::shared_ptr<AutomationControl>
5290 Route::pan_width_control() const
5293 if (mixbus() && _ch_pre) {
5295 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl>(_ch_pre->control(Evoral::Parameter(PluginAutomation, 0, 5)));
5298 if (Profile->get_mixbus() || !_pannable || !panner()) {
5299 return boost::shared_ptr<AutomationControl>();
5302 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5304 if (c.find (PanWidthAutomation) != c.end()) {
5305 return _pannable->pan_width_control;
5307 return boost::shared_ptr<AutomationControl>();
5310 boost::shared_ptr<AutomationControl>
5311 Route::pan_frontback_control() const
5313 if (Profile->get_mixbus() || !_pannable || !panner()) {
5314 return boost::shared_ptr<AutomationControl>();
5317 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5319 if (c.find (PanFrontBackAutomation) != c.end()) {
5320 return _pannable->pan_frontback_control;
5322 return boost::shared_ptr<AutomationControl>();
5325 boost::shared_ptr<AutomationControl>
5326 Route::pan_lfe_control() const
5328 if (Profile->get_mixbus() || !_pannable || !panner()) {
5329 return boost::shared_ptr<AutomationControl>();
5332 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5334 if (c.find (PanLFEAutomation) != c.end()) {
5335 return _pannable->pan_lfe_control;
5337 return boost::shared_ptr<AutomationControl>();
5342 Route::eq_band_cnt () const
5344 if (Profile->get_mixbus()) {
5346 if (is_master() || mixbus()) {
5355 /* Ardour has no well-known EQ object */
5360 boost::shared_ptr<AutomationControl>
5361 Route::eq_gain_controllable (uint32_t band) const
5364 boost::shared_ptr<PluginInsert> eq = ch_eq();
5367 return boost::shared_ptr<AutomationControl>();
5370 uint32_t port_number;
5371 if (is_master() || mixbus()) {
5373 case 0: port_number = 4; break;
5374 case 1: port_number = 3; break;
5375 case 2: port_number = 2; break;
5377 return boost::shared_ptr<AutomationControl>();
5382 case 0: port_number = 14; break;
5383 case 1: port_number = 12; break;
5384 case 2: port_number = 10; break;
5385 case 3: port_number = 8; break;
5387 return boost::shared_ptr<AutomationControl>();
5391 case 0: port_number = 8; break;
5392 case 1: port_number = 6; break;
5393 case 2: port_number = 4; break;
5395 return boost::shared_ptr<AutomationControl>();
5400 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5402 return boost::shared_ptr<AutomationControl>();
5405 boost::shared_ptr<AutomationControl>
5406 Route::eq_freq_controllable (uint32_t band) const
5409 if (mixbus() || is_master()) {
5410 /* no frequency controls for mixbusses or master */
5411 return boost::shared_ptr<AutomationControl>();
5414 boost::shared_ptr<PluginInsert> eq = ch_eq();
5417 return boost::shared_ptr<AutomationControl>();
5420 uint32_t port_number;
5423 case 0: port_number = 13; break; // lo
5424 case 1: port_number = 11; break; // lo mid
5425 case 2: port_number = 9; break; // hi mid
5426 case 3: port_number = 7; break; // hi
5428 return boost::shared_ptr<AutomationControl>();
5432 case 0: port_number = 7; break;
5433 case 1: port_number = 5; break;
5434 case 2: port_number = 3; break;
5436 return boost::shared_ptr<AutomationControl>();
5440 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5442 return boost::shared_ptr<AutomationControl>();
5446 boost::shared_ptr<AutomationControl>
5447 Route::eq_q_controllable (uint32_t band) const
5449 return boost::shared_ptr<AutomationControl>();
5452 boost::shared_ptr<AutomationControl>
5453 Route::eq_shape_controllable (uint32_t band) const
5456 boost::shared_ptr<PluginInsert> eq = ch_eq();
5457 if (is_master() || mixbus() || !eq) {
5458 return boost::shared_ptr<AutomationControl>();
5462 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4))); // lo bell
5465 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3))); // hi bell
5471 return boost::shared_ptr<AutomationControl>();
5474 boost::shared_ptr<AutomationControl>
5475 Route::eq_enable_controllable () const
5478 boost::shared_ptr<PluginInsert> eq = ch_eq();
5481 return boost::shared_ptr<AutomationControl>();
5484 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5486 return boost::shared_ptr<AutomationControl>();
5490 boost::shared_ptr<AutomationControl>
5491 Route::filter_freq_controllable (bool hpf) const
5494 boost::shared_ptr<PluginInsert> eq = ch_eq();
5496 if (is_master() || mixbus() || !eq) {
5497 return boost::shared_ptr<AutomationControl>();
5501 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5))); // HPF freq
5503 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5507 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 6))); // LPF freq
5509 return boost::shared_ptr<AutomationControl>();
5514 return boost::shared_ptr<AutomationControl>();
5518 boost::shared_ptr<AutomationControl>
5519 Route::filter_slope_controllable (bool) const
5521 return boost::shared_ptr<AutomationControl>();
5524 boost::shared_ptr<AutomationControl>
5525 Route::filter_enable_controllable (bool) const
5528 boost::shared_ptr<PluginInsert> eq = ch_eq();
5530 if (is_master() || mixbus() || !eq) {
5531 return boost::shared_ptr<AutomationControl>();
5534 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5536 return boost::shared_ptr<AutomationControl>();
5540 boost::shared_ptr<AutomationControl>
5541 Route::tape_drive_controllable () const
5544 if (_ch_pre && mixbus()) {
5545 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (_ch_pre->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4)));
5547 if (_ch_pre && is_master()) {
5548 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (_ch_pre->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5552 return boost::shared_ptr<AutomationControl>();
5556 Route::eq_band_name (uint32_t band) const
5559 if (is_master() || mixbus()) {
5561 if (Profile->get_mixbus()) {
5563 case 0: return _("lo");
5564 case 1: return _("mid");
5565 case 2: return _("hi");
5566 default: return string();
5574 case 0: return _("lo");
5575 case 1: return _("lm");
5576 case 2: return _("hm");
5577 case 3: return _("hi");
5578 default: return string();
5584 boost::shared_ptr<AutomationControl>
5585 Route::comp_enable_controllable () const
5588 boost::shared_ptr<PluginInsert> comp = ch_comp();
5591 return boost::shared_ptr<AutomationControl>();
5594 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5596 return boost::shared_ptr<AutomationControl>();
5599 boost::shared_ptr<AutomationControl>
5600 Route::comp_threshold_controllable () const
5603 boost::shared_ptr<PluginInsert> comp = ch_comp();
5606 return boost::shared_ptr<AutomationControl>();
5609 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5612 return boost::shared_ptr<AutomationControl>();
5615 boost::shared_ptr<AutomationControl>
5616 Route::comp_speed_controllable () const
5619 boost::shared_ptr<PluginInsert> comp = ch_comp();
5622 return boost::shared_ptr<AutomationControl>();
5625 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3)));
5627 return boost::shared_ptr<AutomationControl>();
5630 boost::shared_ptr<AutomationControl>
5631 Route::comp_mode_controllable () const
5634 boost::shared_ptr<PluginInsert> comp = ch_comp();
5637 return boost::shared_ptr<AutomationControl>();
5640 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4)));
5642 return boost::shared_ptr<AutomationControl>();
5645 boost::shared_ptr<AutomationControl>
5646 Route::comp_makeup_controllable () const
5649 boost::shared_ptr<PluginInsert> comp = ch_comp();
5652 return boost::shared_ptr<AutomationControl>();
5655 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5)));
5657 return boost::shared_ptr<AutomationControl>();
5660 boost::shared_ptr<ReadOnlyControl>
5661 Route::comp_redux_controllable () const
5664 boost::shared_ptr<PluginInsert> comp = ch_comp();
5667 return boost::shared_ptr<ReadOnlyControl>();
5670 return comp->control_output (2);
5672 return comp->control_output (6);
5676 return boost::shared_ptr<ReadOnlyControl>();
5681 Route::comp_mode_name (uint32_t mode) const
5686 return _("Leveler");
5688 return _("Compressor");
5690 return _("Limiter");
5692 return mixbus() ? _("Sidechain") : _("Limiter");
5702 Route::comp_speed_name (uint32_t mode) const
5720 boost::shared_ptr<AutomationControl>
5721 Route::send_pan_azi_controllable (uint32_t n) const
5724 # undef MIXBUS_PORTS_H
5725 # include "../../gtk2_ardour/mixbus_ports.h"
5726 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5727 if (plug && !mixbus()) {
5728 uint32_t port_id = 0;
5731 case 0: port_id = port_channel_post_aux0_pan; break; //32c mb "pan" controls use zero-based names, unlike levels. ugh
5732 case 1: port_id = port_channel_post_aux1_pan; break;
5733 case 2: port_id = port_channel_post_aux2_pan; break;
5734 case 3: port_id = port_channel_post_aux3_pan; break;
5735 case 4: port_id = port_channel_post_aux4_pan; break;
5736 case 5: port_id = port_channel_post_aux5_pan; break;
5737 case 6: port_id = port_channel_post_aux6_pan; break;
5738 case 7: port_id = port_channel_post_aux7_pan; break;
5739 case 8: port_id = port_channel_post_aux8_pan; break;
5740 case 9: port_id = port_channel_post_aux9_pan; break;
5741 case 10: port_id = port_channel_post_aux10_pan; break;
5742 case 11: port_id = port_channel_post_aux11_pan; break;
5749 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5754 return boost::shared_ptr<AutomationControl>();
5757 boost::shared_ptr<AutomationControl>
5758 Route::send_level_controllable (uint32_t n) const
5761 # undef MIXBUS_PORTS_H
5762 # include "../../gtk2_ardour/mixbus_ports.h"
5763 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5764 if (plug && !mixbus()) {
5765 uint32_t port_id = 0;
5767 case 0: port_id = port_channel_post_aux1_level; break;
5768 case 1: port_id = port_channel_post_aux2_level; break;
5769 case 2: port_id = port_channel_post_aux3_level; break;
5770 case 3: port_id = port_channel_post_aux4_level; break;
5771 case 4: port_id = port_channel_post_aux5_level; break;
5772 case 5: port_id = port_channel_post_aux6_level; break;
5773 case 6: port_id = port_channel_post_aux7_level; break;
5774 case 7: port_id = port_channel_post_aux8_level; break;
5776 case 8: port_id = port_channel_post_aux9_level; break;
5777 case 9: port_id = port_channel_post_aux10_level; break;
5778 case 10: port_id = port_channel_post_aux11_level; break;
5779 case 11: port_id = port_channel_post_aux12_level; break;
5786 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5797 boost::shared_ptr<Send> s = boost::dynamic_pointer_cast<Send>(nth_send (n));
5799 return boost::shared_ptr<AutomationControl>();
5801 return s->gain_control ();
5804 boost::shared_ptr<AutomationControl>
5805 Route::send_enable_controllable (uint32_t n) const
5808 # undef MIXBUS_PORTS_H
5809 # include "../../gtk2_ardour/mixbus_ports.h"
5810 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5811 if (plug && !mixbus()) {
5812 uint32_t port_id = 0;
5814 case 0: port_id = port_channel_post_aux1_asgn; break;
5815 case 1: port_id = port_channel_post_aux2_asgn; break;
5816 case 2: port_id = port_channel_post_aux3_asgn; break;
5817 case 3: port_id = port_channel_post_aux4_asgn; break;
5818 case 4: port_id = port_channel_post_aux5_asgn; break;
5819 case 5: port_id = port_channel_post_aux6_asgn; break;
5820 case 6: port_id = port_channel_post_aux7_asgn; break;
5821 case 7: port_id = port_channel_post_aux8_asgn; break;
5823 case 8: port_id = port_channel_post_aux9_asgn; break;
5824 case 9: port_id = port_channel_post_aux10_asgn; break;
5825 case 10: port_id = port_channel_post_aux11_asgn; break;
5826 case 11: port_id = port_channel_post_aux12_asgn; break;
5833 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5844 /* although Ardour sends have enable/disable as part of the Processor
5845 * API, it is not exposed as a controllable.
5847 * XXX: we should fix this (make it click-free, automatable enable-control)
5849 return boost::shared_ptr<AutomationControl>();
5853 Route::send_name (uint32_t n) const
5856 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5857 if (plug && !mixbus()) {
5860 return _session.get_mixbus (n)->name();
5865 return _session.get_mixbus (n)->name();
5871 boost::shared_ptr<Processor> p = nth_send (n);
5879 boost::shared_ptr<AutomationControl>
5880 Route::master_send_enable_controllable () const
5883 if (is_master() || is_monitor() || is_auditioner()) {
5884 return boost::shared_ptr<AutomationControl>();
5887 boost::shared_ptr<ARDOUR::PluginInsert> plug = mixbus() ? ch_pre () : ch_post();
5889 return boost::shared_ptr<AutomationControl>();
5891 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, mixbus() ? 3 : 19)));
5893 return boost::shared_ptr<AutomationControl>();
5898 Route::slaved () const
5900 if (!_gain_control) {
5903 /* just test one particular control, not all of them */
5904 return _gain_control->slaved ();
5908 Route::slaved_to (boost::shared_ptr<VCA> vca) const
5910 if (!vca || !_gain_control) {
5914 /* just test one particular control, not all of them */
5916 return _gain_control->slaved_to (vca->gain_control());
5920 Route::muted_by_others_soloing () const
5922 if (!can_be_muted_by_others ()) {
5926 return _session.soloing() && !_solo_control->soloed() && !_solo_isolate_control->solo_isolated();
5930 Route::clear_all_solo_state ()
5932 _solo_control->clear_all_solo_state ();
5935 boost::shared_ptr<AutomationControl>
5936 Route::automation_control_recurse (PBD::ID const & id) const
5938 boost::shared_ptr<AutomationControl> ac = Automatable::automation_control (id);
5944 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
5946 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
5947 if ((ac = (*i)->automation_control (id))) {
5952 return boost::shared_ptr<AutomationControl> ();
5956 Route::slavables () const
5958 SlavableControlList rv;
5959 rv.push_back (_gain_control);
5960 rv.push_back (_mute_control);
5961 rv.push_back (_solo_control);
5966 Route::set_disk_io_point (DiskIOPoint diop)
5968 bool display = false;
5970 cerr << "set disk io to " << enum_2_string (diop) << endl;
5981 _disk_writer->set_display_to_user (display);
5985 _disk_reader->set_display_to_user (display);
5988 const bool changed = (diop != _disk_io_point);
5990 _disk_io_point = diop;
5993 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
5994 configure_processors (0);
5997 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
6001 Route::set_loop (Location* l)
6004 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
6005 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
6010 #ifdef USE_TRACKS_CODE_FEATURES
6012 /* This is the Tracks version of Track::monitoring_state().
6014 * Ardour developers: try to flag or fix issues if parts of the libardour API
6015 * change in ways that invalidate this
6019 Route::monitoring_state () const
6021 /* Explicit requests */
6023 if (_monitoring != MonitorInput) {
6024 return MonitoringInput;
6027 if (_monitoring & MonitorDisk) {
6028 return MonitoringDisk;
6031 /* This is an implementation of the truth table in doc/monitor_modes.pdf;
6032 I don't think it's ever going to be too pretty too look at.
6035 // GZ: NOT USED IN TRACKS
6036 //bool const auto_input = _session.config.get_auto_input ();
6037 //bool const software_monitor = Config->get_monitoring_model() == SoftwareMonitoring;
6038 //bool const tape_machine_mode = Config->get_tape_machine_mode ();
6040 bool const roll = _session.transport_rolling ();
6041 bool const track_rec = _diskstream->record_enabled ();
6042 bool session_rec = _session.actively_recording ();
6046 if (!session_rec && roll) {
6047 return MonitoringDisk;
6049 return MonitoringInput;
6055 return MonitoringDisk;
6059 return MonitoringSilence;
6064 /* This is the Ardour/Mixbus version of Track::monitoring_state().
6066 * Tracks developers: do NOT modify this method under any circumstances.
6070 Route::monitoring_state () const
6072 if (!_disk_reader) {
6073 return MonitoringInput;
6076 /* Explicit requests */
6077 MonitorChoice m (_monitoring_control->monitoring_choice());
6079 if (m != MonitorAuto) {
6081 MonitorState ms ((MonitorState) 0);
6083 if (m & MonitorInput) {
6084 ms = MonitoringInput;
6087 if (m & MonitorDisk) {
6088 ms = MonitorState (ms | MonitoringDisk);
6094 switch (_session.config.get_session_monitoring ()) {
6096 return MonitoringDisk;
6099 return MonitoringInput;
6105 return get_auto_monitoring_state();