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/memento_command.h"
34 #include "pbd/stacktrace.h"
35 #include "pbd/convert.h"
36 #include "pbd/unwind.h"
38 #include "ardour/amp.h"
39 #include "ardour/audio_buffer.h"
40 #include "ardour/audio_track.h"
41 #include "ardour/audio_port.h"
42 #include "ardour/audioengine.h"
43 #include "ardour/boost_debug.h"
44 #include "ardour/buffer.h"
45 #include "ardour/buffer_set.h"
46 #include "ardour/capturing_processor.h"
47 #include "ardour/debug.h"
48 #include "ardour/delivery.h"
49 #include "ardour/gain_control.h"
50 #include "ardour/internal_return.h"
51 #include "ardour/internal_send.h"
52 #include "ardour/meter.h"
53 #include "ardour/delayline.h"
54 #include "ardour/midi_buffer.h"
55 #include "ardour/midi_port.h"
56 #include "ardour/monitor_processor.h"
57 #include "ardour/pannable.h"
58 #include "ardour/panner.h"
59 #include "ardour/panner_shell.h"
60 #include "ardour/parameter_descriptor.h"
61 #include "ardour/phase_control.h"
62 #include "ardour/plugin_insert.h"
63 #include "ardour/port.h"
64 #include "ardour/port_insert.h"
65 #include "ardour/processor.h"
66 #include "ardour/profile.h"
67 #include "ardour/route.h"
68 #include "ardour/route_group.h"
69 #include "ardour/send.h"
70 #include "ardour/session.h"
71 #include "ardour/solo_control.h"
72 #include "ardour/solo_isolate_control.h"
73 #include "ardour/unknown_processor.h"
74 #include "ardour/utils.h"
75 #include "ardour/vca.h"
80 using namespace ARDOUR;
83 PBD::Signal0<void> Route::SyncOrderKeys;
84 PBD::Signal0<void> Route::RemoteControlIDChange;
85 PBD::Signal3<int,boost::shared_ptr<Route>, boost::shared_ptr<PluginInsert>, Route::PluginSetupOptions > Route::PluginSetup;
87 /** Base class for all routable/mixable objects (tracks and busses) */
88 Route::Route (Session& sess, string name, Flag flg, DataType default_type)
89 : Stripable (sess, name)
90 , Muteable (sess, name)
92 , GraphNode (sess._process_graph)
95 , _signal_latency_at_amp_position (0)
96 , _signal_latency_at_trim_position (0)
99 , _pending_process_reorder (0)
100 , _pending_signals (0)
102 , _pending_declick (true)
103 , _meter_point (MeterPostFader)
104 , _pending_meter_point (MeterPostFader)
105 , _meter_type (MeterPeak)
106 , _denormal_protection (false)
109 , _declickable (false)
110 , _have_internal_generator (false)
111 , _default_type (default_type)
113 , _has_order_key (false)
114 , _remote_control_id (0)
116 , _in_configure_processors (false)
117 , _initial_io_setup (false)
118 , _in_sidechain_setup (false)
120 , _custom_meter_position_noted (false)
123 processor_max_streams.reset();
129 /* set default meter type */
131 _meter_type = Config->get_meter_type_master ();
133 else if (dynamic_cast<Track*>(this)) {
134 _meter_type = Config->get_meter_type_track ();
136 _meter_type = Config->get_meter_type_bus ();
139 /* add standard controls */
141 _gain_control.reset (new GainControl (_session, GainAutomation));
142 add_control (_gain_control);
144 _trim_control.reset (new GainControl (_session, TrimAutomation));
145 add_control (_trim_control);
147 _solo_control.reset (new SoloControl (_session, X_("solo"), *this, *this));
148 _solo_control->set_flags (Controllable::Flag (_solo_control->flags() | Controllable::Toggle));
149 add_control (_solo_control);
150 _solo_control->Changed.connect_same_thread (*this, boost::bind (&Route::solo_control_changed, this, _1, _2));
152 _mute_control.reset (new MuteControl (_session, X_("mute"), *this));
153 _mute_control->set_flags (Controllable::Flag (_mute_control->flags() | Controllable::Toggle));
154 add_control (_mute_control);
156 _phase_control.reset (new PhaseControl (_session, X_("phase")));
157 add_control (_phase_control);
159 _solo_isolate_control.reset (new SoloIsolateControl (_session, X_("solo-iso"), *this, *this));
160 add_control (_solo_isolate_control);
162 _solo_safe_control.reset (new SoloSafeControl (_session, X_("solo-safe")));
163 add_control (_solo_safe_control);
167 if (!(_flags & Route::MonitorOut)) {
168 _pannable.reset (new Pannable (_session));
171 /* input and output objects */
173 _input.reset (new IO (_session, _name, IO::Input, _default_type));
174 _output.reset (new IO (_session, _name, IO::Output, _default_type));
176 _input->changed.connect_same_thread (*this, boost::bind (&Route::input_change_handler, this, _1, _2));
177 _input->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::input_port_count_changing, this, _1));
179 _output->changed.connect_same_thread (*this, boost::bind (&Route::output_change_handler, this, _1, _2));
180 _output->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::output_port_count_changing, this, _1));
182 /* add the amp/fader processor.
183 * it should be the first processor to be added on every route.
186 _amp.reset (new Amp (_session, X_("Fader"), _gain_control, true));
187 add_processor (_amp, PostFader);
190 _amp->set_display_name (_("Monitor"));
193 #if 0 // not used - just yet
194 if (!is_master() && !is_monitor() && !is_auditioner()) {
195 _delayline.reset (new DelayLine (_session, _name));
196 add_processor (_delayline, PreFader);
202 _trim.reset (new Amp (_session, X_("Trim"), _trim_control, false));
203 _trim->set_display_to_user (false);
205 if (dynamic_cast<AudioTrack*>(this)) {
206 /* we can't do this in the AudioTrack's constructor
207 * because _trim does not exit then
211 else if (!dynamic_cast<Track*>(this) && ! ( is_monitor() || is_auditioner() )) {
216 /* create standard processors: meter, main outs, monitor out;
217 they will be added to _processors by setup_invisible_processors ()
220 _meter.reset (new PeakMeter (_session, _name));
221 _meter->set_owner (this);
222 _meter->set_display_to_user (false);
225 _main_outs.reset (new Delivery (_session, _output, _pannable, _mute_master, _name, Delivery::Main));
226 _main_outs->activate ();
229 /* where we listen to tracks */
230 _intreturn.reset (new InternalReturn (_session));
231 _intreturn->activate ();
233 /* the thing that provides proper control over a control/monitor/listen bus
234 (such as per-channel cut, dim, solo, invert, etc).
236 _monitor_control.reset (new MonitorProcessor (_session));
237 _monitor_control->activate ();
240 if (is_master() || is_monitor() || is_auditioner()) {
241 _mute_master->set_solo_ignore (true);
244 /* now that we have _meter, its safe to connect to this */
247 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
248 configure_processors (0);
256 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
258 /* do this early so that we don't get incoming signals as we are going through destruction
263 /* don't use clear_processors here, as it depends on the session which may
264 be half-destroyed by now
267 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
268 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
269 (*i)->drop_references ();
272 _processors.clear ();
276 Route::set_remote_control_id (uint32_t id, bool notify_class_listeners)
278 if (Config->get_remote_model() != UserOrdered) {
282 set_remote_control_id_internal (id, notify_class_listeners);
286 Route::set_remote_control_id_internal (uint32_t id, bool notify_class_listeners)
288 /* force IDs for master/monitor busses and prevent
289 any other route from accidentally getting these IDs
290 (i.e. legacy sessions)
293 if (is_master() && id != MasterBusRemoteControlID) {
294 id = MasterBusRemoteControlID;
297 if (is_monitor() && id != MonitorBusRemoteControlID) {
298 id = MonitorBusRemoteControlID;
305 /* don't allow it to collide */
307 if (!is_master () && !is_monitor() &&
308 (id == MasterBusRemoteControlID || id == MonitorBusRemoteControlID)) {
309 id += MonitorBusRemoteControlID;
312 if (id != remote_control_id()) {
313 _remote_control_id = id;
314 RemoteControlIDChanged ();
316 if (notify_class_listeners) {
317 RemoteControlIDChange ();
323 Route::remote_control_id() const
326 return MasterBusRemoteControlID;
330 return MonitorBusRemoteControlID;
333 return _remote_control_id;
337 Route::has_order_key () const
339 return _has_order_key;
343 Route::order_key () const
349 Route::set_remote_control_id_explicit (uint32_t rid)
351 if (is_master() || is_monitor() || is_auditioner()) {
352 /* hard-coded remote IDs, or no remote ID */
356 if (_remote_control_id != rid) {
357 DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1: set edit-based RID to %2\n", name(), rid));
358 _remote_control_id = rid;
359 RemoteControlIDChanged (); /* EMIT SIGNAL (per-route) */
362 /* don't emit the class-level RID signal RemoteControlIDChange here,
363 leave that to the entity that changed the order key, so that we
364 don't get lots of emissions for no good reasons (e.g. when changing
365 all route order keys).
367 See Session::sync_remote_id_from_order_keys() for the (primary|only)
368 spot where that is emitted.
373 Route::set_order_key (uint32_t n)
375 _has_order_key = true;
377 if (_order_key == n) {
383 DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1 order key set to %2\n",
384 name(), order_key ()));
386 _session.set_dirty ();
390 Route::ensure_track_or_route_name(string name, Session &session)
392 string newname = name;
394 while (!session.io_name_is_legal (newname)) {
395 newname = bump_name_once (newname, ' ');
402 Route::set_trim (gain_t val, Controllable::GroupControlDisposition /* group override */)
404 // TODO route group, see set_gain()
405 // _trim_control->route_set_value (val);
409 Route::maybe_declick (BufferSet&, framecnt_t, int)
411 /* this is the "bus" implementation and they never declick.
416 /** Process this route for one (sub) cycle (process thread)
418 * @param bufs Scratch buffers to use for the signal path
419 * @param start_frame Initial transport frame
420 * @param end_frame Final transport frame
421 * @param nframes Number of frames to output (to ports)
423 * Note that (end_frame - start_frame) may not be equal to nframes when the
424 * transport speed isn't 1.0 (eg varispeed).
427 Route::process_output_buffers (BufferSet& bufs,
428 framepos_t start_frame, framepos_t end_frame, pframes_t nframes,
429 int declick, bool gain_automation_ok)
431 /* Caller must hold process lock */
432 assert (!AudioEngine::instance()->process_lock().trylock());
434 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
436 // can this actually happen? functions calling process_output_buffers()
437 // already take a reader-lock.
438 bufs.silence (nframes, 0);
442 /* figure out if we're going to use gain automation */
443 if (gain_automation_ok) {
444 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
445 _amp->setup_gain_automation (
446 start_frame + _signal_latency_at_amp_position,
447 end_frame + _signal_latency_at_amp_position,
450 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
451 _trim->setup_gain_automation (
452 start_frame + _signal_latency_at_trim_position,
453 end_frame + _signal_latency_at_trim_position,
456 _amp->apply_gain_automation (false);
457 _trim->apply_gain_automation (false);
460 /* Tell main outs what to do about monitoring. We do this so that
461 on a transition between monitoring states we get a de-clicking gain
462 change in the _main_outs delivery, if config.get_use_monitor_fades()
465 We override this in the case where we have an internal generator.
467 bool silence = _have_internal_generator ? false : (monitoring_state () == MonitoringSilence);
469 _main_outs->no_outs_cuz_we_no_monitor (silence);
471 /* -------------------------------------------------------------------------------------------
472 GLOBAL DECLICK (for transport changes etc.)
473 ----------------------------------------------------------------------------------------- */
475 maybe_declick (bufs, nframes, declick);
476 _pending_declick = 0;
478 /* -------------------------------------------------------------------------------------------
479 DENORMAL CONTROL/PHASE INVERT
480 ----------------------------------------------------------------------------------------- */
482 if (!_phase_control->none()) {
486 if (_denormal_protection || Config->get_denormal_protection()) {
488 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
489 Sample* const sp = i->data();
491 if (_phase_control->inverted (chn)) {
492 for (pframes_t nx = 0; nx < nframes; ++nx) {
497 for (pframes_t nx = 0; nx < nframes; ++nx) {
505 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
506 Sample* const sp = i->data();
508 if (_phase_control->inverted (chn)) {
509 for (pframes_t nx = 0; nx < nframes; ++nx) {
518 if (_denormal_protection || Config->get_denormal_protection()) {
520 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
521 Sample* const sp = i->data();
522 for (pframes_t nx = 0; nx < nframes; ++nx) {
530 /* -------------------------------------------------------------------------------------------
532 ----------------------------------------------------------------------------------------- */
534 /* set this to be true if the meter will already have been ::run() earlier */
535 bool const meter_already_run = metering_state() == MeteringInput;
537 framecnt_t latency = 0;
539 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
541 if (meter_already_run && boost::dynamic_pointer_cast<PeakMeter> (*i)) {
542 /* don't ::run() the meter, otherwise it will have its previous peak corrupted */
547 /* if it has any inputs, make sure they match */
548 if (boost::dynamic_pointer_cast<UnknownProcessor> (*i) == 0 && (*i)->input_streams() != ChanCount::ZERO) {
549 if (bufs.count() != (*i)->input_streams()) {
551 DEBUG::Processors, string_compose (
552 "input port mismatch %1 bufs = %2 input for %3 = %4\n",
553 _name, bufs.count(), (*i)->name(), (*i)->input_streams()
560 /* should we NOT run plugins here if the route is inactive?
561 do we catch route != active somewhere higher?
564 if (boost::dynamic_pointer_cast<Send>(*i) != 0) {
565 boost::dynamic_pointer_cast<Send>(*i)->set_delay_in(_signal_latency - latency);
568 (*i)->run (bufs, start_frame - latency, end_frame - latency, nframes, *i != _processors.back());
569 bufs.set_count ((*i)->output_streams());
571 if ((*i)->active ()) {
572 latency += (*i)->signal_latency ();
578 Route::bounce_process (BufferSet& buffers, framepos_t start, framecnt_t nframes,
579 boost::shared_ptr<Processor> endpoint,
580 bool include_endpoint, bool for_export, bool for_freeze)
582 /* If no processing is required, there's no need to go any further. */
583 if (!endpoint && !include_endpoint) {
587 framecnt_t latency = bounce_get_latency(_amp, false, for_export, for_freeze);
588 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
589 _amp->setup_gain_automation (start - latency, start - latency + nframes, nframes);
591 /* trim is always at the top, for bounce no latency compensation is needed */
592 _trim->set_gain_automation_buffer (_session.trim_automation_buffer ());
593 _trim->setup_gain_automation (start, start + nframes, nframes);
596 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
598 if (!include_endpoint && (*i) == endpoint) {
602 /* if we're *not* exporting, stop processing if we come across a routing processor. */
603 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
606 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
610 /* special case the panner (export outputs)
611 * Ideally we'd only run the panner, not the delivery itself...
612 * but panners need separate input/output buffers and some context
613 * (panshell, panner type, etc). AFAICT there is no ill side effect
614 * of re-using the main delivery when freewheeling/exporting a region.
616 if ((*i) == _main_outs) {
617 assert ((*i)->does_routing());
618 (*i)->run (buffers, start - latency, start - latency + nframes, nframes, true);
619 buffers.set_count ((*i)->output_streams());
622 /* don't run any processors that do routing.
623 * Also don't bother with metering.
625 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
626 (*i)->run (buffers, start - latency, start - latency + nframes, nframes, true);
627 buffers.set_count ((*i)->output_streams());
628 latency += (*i)->signal_latency ();
631 if ((*i) == endpoint) {
638 Route::bounce_get_latency (boost::shared_ptr<Processor> endpoint,
639 bool include_endpoint, bool for_export, bool for_freeze) const
641 framecnt_t latency = 0;
642 if (!endpoint && !include_endpoint) {
646 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
647 if (!include_endpoint && (*i) == endpoint) {
650 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
653 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
656 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
657 latency += (*i)->signal_latency ();
659 if ((*i) == endpoint) {
667 Route::bounce_get_output_streams (ChanCount &cc, boost::shared_ptr<Processor> endpoint,
668 bool include_endpoint, bool for_export, bool for_freeze) const
670 if (!endpoint && !include_endpoint) {
674 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
675 if (!include_endpoint && (*i) == endpoint) {
678 if (!for_export && boost::dynamic_pointer_cast<PortInsert>(*i)) {
681 if (!for_export && for_freeze && (*i)->does_routing() && (*i)->active()) {
684 if (!(*i)->does_routing() && !boost::dynamic_pointer_cast<PeakMeter>(*i)) {
685 cc = (*i)->output_streams();
687 if ((*i) == endpoint) {
695 Route::n_process_buffers ()
697 return max (_input->n_ports(), processor_max_streams);
701 Route::monitor_run (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
703 assert (is_monitor());
704 BufferSet& bufs (_session.get_route_buffers (n_process_buffers()));
705 fill_buffers_with_input (bufs, _input, nframes);
706 passthru (bufs, start_frame, end_frame, nframes, declick);
710 Route::passthru (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
714 if (is_monitor() && _session.listening() && !_session.is_auditioning()) {
716 /* control/monitor bus ignores input ports when something is
717 feeding the listen "stream". data will "arrive" into the
718 route from the intreturn processor element.
721 bufs.silence (nframes, 0);
724 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
725 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, true);
729 Route::passthru_silence (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
731 BufferSet& bufs (_session.get_route_buffers (n_process_buffers(), true));
733 bufs.set_count (_input->n_ports());
734 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
735 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, false);
739 Route::set_listen (bool yn)
742 _monitor_send->activate ();
744 _monitor_send->deactivate ();
749 Route::solo_control_changed (bool, Controllable::GroupControlDisposition)
751 /* nothing to do if we're not using AFL/PFL. But if we are, we need
752 to alter the active state of the monitor send.
755 if (Config->get_solo_control_is_listen_control ()) {
756 set_listen (_solo_control->self_soloed());
761 Route::listening_via_monitor () const
764 return _monitor_send->active ();
771 Route::push_solo_isolate_upstream (int32_t delta)
773 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
775 boost::shared_ptr<RouteList> routes = _session.get_routes ();
776 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
778 if ((*i).get() == this || !(*i)->can_solo()) {
783 bool does_feed = feeds (*i, &sends_only);
785 if (does_feed && !sends_only) {
786 (*i)->solo_isolate_control()->mod_solo_isolated_by_upstream (delta);
792 Route::push_solo_upstream (int delta)
794 DEBUG_TRACE (DEBUG::Solo, string_compose("\t ... INVERT push from %1\n", _name));
795 for (FedBy::iterator i = _fed_by.begin(); i != _fed_by.end(); ++i) {
799 boost::shared_ptr<Route> sr (i->r.lock());
801 sr->solo_control()->mod_solo_by_others_downstream (-delta);
808 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
810 cerr << name << " {" << endl;
811 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
812 p != procs.end(); ++p) {
813 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << " @ " << (*p) << endl;
819 /** Supposing that we want to insert a Processor at a given Placement, return
820 * the processor to add the new one before (or 0 to add at the end).
822 boost::shared_ptr<Processor>
823 Route::before_processor_for_placement (Placement p)
825 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
827 ProcessorList::iterator loc;
830 /* generic pre-fader: insert immediately before the amp */
831 loc = find (_processors.begin(), _processors.end(), _amp);
833 /* generic post-fader: insert right before the main outs */
834 loc = find (_processors.begin(), _processors.end(), _main_outs);
837 return loc != _processors.end() ? *loc : boost::shared_ptr<Processor> ();
840 /** Supposing that we want to insert a Processor at a given index, return
841 * the processor to add the new one before (or 0 to add at the end).
843 boost::shared_ptr<Processor>
844 Route::before_processor_for_index (int index)
847 return boost::shared_ptr<Processor> ();
850 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
852 ProcessorList::iterator i = _processors.begin ();
854 while (i != _processors.end() && j < index) {
855 if ((*i)->display_to_user()) {
862 return (i != _processors.end() ? *i : boost::shared_ptr<Processor> ());
865 /** Add a processor either pre- or post-fader
866 * @return 0 on success, non-0 on failure.
869 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err, bool activation_allowed)
871 return add_processor (processor, before_processor_for_placement (placement), err, activation_allowed);
875 /** Add a processor to a route such that it ends up with a given index into the visible processors.
876 * @param index Index to add the processor at, or -1 to add at the end of the list.
877 * @return 0 on success, non-0 on failure.
880 Route::add_processor_by_index (boost::shared_ptr<Processor> processor, int index, ProcessorStreams* err, bool activation_allowed)
882 return add_processor (processor, before_processor_for_index (index), err, activation_allowed);
885 /** Add a processor to the route.
886 * @param before An existing processor in the list, or 0; the new processor will be inserted immediately before it (or at the end).
887 * @return 0 on success, non-0 on failure.
890 Route::add_processor (boost::shared_ptr<Processor> processor, boost::shared_ptr<Processor> before, ProcessorStreams* err, bool activation_allowed)
892 assert (processor != _meter);
893 assert (processor != _main_outs);
895 DEBUG_TRACE (DEBUG::Processors, string_compose (
896 "%1 adding processor %2\n", name(), processor->name()));
900 pl.push_back (processor);
901 int rv = add_processors (pl, before, err);
907 if (activation_allowed && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user ())) {
908 processor->activate ();
915 Route::processor_selfdestruct (boost::weak_ptr<Processor> wp)
917 /* We cannot destruct the processor here (usually RT-thread
918 * with various locks held - in case of sends also io_locks).
919 * Queue for deletion in low-priority thread.
921 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
922 selfdestruct_sequence.push_back (wp);
926 Route::add_processor_from_xml_2X (const XMLNode& node, int version)
928 XMLProperty const * prop;
931 boost::shared_ptr<Processor> processor;
933 /* bit of a hack: get the `placement' property from the <Redirect> tag here
934 so that we can add the processor in the right place (pre/post-fader)
937 XMLNodeList const & children = node.children ();
938 XMLNodeList::const_iterator i = children.begin ();
940 while (i != children.end() && (*i)->name() != X_("Redirect")) {
944 Placement placement = PreFader;
946 if (i != children.end()) {
947 if ((prop = (*i)->property (X_("placement"))) != 0) {
948 placement = Placement (string_2_enum (prop->value(), placement));
952 if (node.name() == "Insert") {
954 if ((prop = node.property ("type")) != 0) {
956 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
957 prop->value() == "lv2" ||
958 prop->value() == "windows-vst" ||
959 prop->value() == "lxvst" ||
960 prop->value() == "audiounit") {
962 if (_session.get_disable_all_loaded_plugins ()) {
963 processor.reset (new UnknownProcessor (_session, node));
965 processor.reset (new PluginInsert (_session));
966 processor->set_owner (this);
971 processor.reset (new PortInsert (_session, _pannable, _mute_master));
976 } else if (node.name() == "Send") {
978 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
979 processor.reset (new Send (_session, sendpan, _mute_master));
983 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
987 if (processor->set_state (node, version)) {
991 //A2 uses the "active" flag in the toplevel redirect node, not in the child plugin/IO
992 if (i != children.end()) {
993 if ((prop = (*i)->property (X_("active"))) != 0) {
994 if ( string_is_affirmative (prop->value()) && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user () ) )
995 processor->activate();
997 processor->deactivate();
1001 return (add_processor (processor, placement, 0, false) == 0);
1004 catch (failed_constructor &err) {
1005 warning << _("processor could not be created. Ignored.") << endmsg;
1011 inline Route::PluginSetupOptions operator|= (Route::PluginSetupOptions& a, const Route::PluginSetupOptions& b) {
1012 return a = static_cast<Route::PluginSetupOptions> (static_cast <int>(a) | static_cast<int> (b));
1015 inline Route::PluginSetupOptions operator&= (Route::PluginSetupOptions& a, const Route::PluginSetupOptions& b) {
1016 return a = static_cast<Route::PluginSetupOptions> (static_cast <int>(a) & static_cast<int> (b));
1020 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
1022 ProcessorList::iterator loc;
1025 loc = find(_processors.begin(), _processors.end(), before);
1026 if (loc == _processors.end ()) {
1030 /* nothing specified - at end */
1031 loc = _processors.end ();
1034 if (!AudioEngine::instance()->connected()) {
1038 if (others.empty()) {
1042 ProcessorList to_skip;
1044 // check if there's an instrument to replace or configure
1045 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1046 boost::shared_ptr<PluginInsert> pi;
1047 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) == 0) {
1050 if (!pi->plugin ()->get_info ()->is_instrument ()) {
1053 boost::shared_ptr<Processor> instrument = the_instrument ();
1054 ChanCount in (DataType::MIDI, 1);
1055 ChanCount out (DataType::AUDIO, 2); // XXX route's out?!
1057 PluginSetupOptions flags = None;
1059 flags |= CanReplace;
1060 in = instrument->input_streams ();
1061 out = instrument->output_streams ();
1063 if (pi->has_output_presets (in, out)) {
1067 pi->set_strict_io (_strict_io);
1069 PluginSetupOptions mask = None;
1070 if (Config->get_ask_replace_instrument ()) {
1073 if (Config->get_ask_setup_instrument ()) {
1079 if (flags != None) {
1080 boost::optional<int> rv = PluginSetup (shared_from_this (), pi, flags); /* EMIT SIGNAL */
1081 switch (rv.get_value_or (0)) {
1083 to_skip.push_back (*i); // don't add this one;
1086 replace_processor (instrument, *i, err);
1087 to_skip.push_back (*i);
1096 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1097 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1098 ProcessorState pstate (this);
1100 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1105 ProcessorList::iterator check = find (to_skip.begin(), to_skip.end(), *i);
1106 if (check != to_skip.end()) {
1110 boost::shared_ptr<PluginInsert> pi;
1112 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1113 pi->set_strict_io (_strict_io);
1117 /* Ensure that only one amp is in the list at any time */
1118 ProcessorList::iterator check = find (_processors.begin(), _processors.end(), *i);
1119 if (check != _processors.end()) {
1120 if (before == _amp) {
1121 /* Already in position; all is well */
1124 _processors.erase (check);
1129 assert (find (_processors.begin(), _processors.end(), *i) == _processors.end ());
1131 _processors.insert (loc, *i);
1132 (*i)->set_owner (this);
1135 if (configure_processors_unlocked (err, &lm)) {
1137 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
1142 if ((*i)->active()) {
1146 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1148 boost::shared_ptr<Send> send;
1149 if ((send = boost::dynamic_pointer_cast<Send> (*i))) {
1150 send->SelfDestruct.connect_same_thread (*this,
1151 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (*i)));
1155 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1156 boost::shared_ptr<PluginInsert> pi;
1158 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1159 if (pi->has_no_inputs ()) {
1160 _have_internal_generator = true;
1166 _output->set_user_latency (0);
1169 reset_instrument_info ();
1170 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1171 set_processor_positions ();
1177 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1179 if (p == PreFader) {
1180 start = _processors.begin();
1181 end = find(_processors.begin(), _processors.end(), _amp);
1183 start = find(_processors.begin(), _processors.end(), _amp);
1185 end = _processors.end();
1189 /** Turn off all processors with a given placement
1190 * @param p Placement of processors to disable
1193 Route::disable_processors (Placement p)
1195 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1197 ProcessorList::iterator start, end;
1198 placement_range(p, start, end);
1200 for (ProcessorList::iterator i = start; i != end; ++i) {
1201 (*i)->deactivate ();
1204 _session.set_dirty ();
1207 /** Turn off all redirects
1210 Route::disable_processors ()
1212 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1214 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1215 (*i)->deactivate ();
1218 _session.set_dirty ();
1221 /** Turn off all redirects with a given placement
1222 * @param p Placement of redirects to disable
1225 Route::disable_plugins (Placement p)
1227 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1229 ProcessorList::iterator start, end;
1230 placement_range(p, start, end);
1232 for (ProcessorList::iterator i = start; i != end; ++i) {
1233 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1234 (*i)->deactivate ();
1238 _session.set_dirty ();
1241 /** Turn off all plugins
1244 Route::disable_plugins ()
1246 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1248 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1249 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1250 (*i)->deactivate ();
1254 _session.set_dirty ();
1259 Route::ab_plugins (bool forward)
1261 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1265 /* forward = turn off all active redirects, and mark them so that the next time
1266 we go the other way, we will revert them
1269 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1270 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1274 if ((*i)->active()) {
1275 (*i)->deactivate ();
1276 (*i)->set_next_ab_is_active (true);
1278 (*i)->set_next_ab_is_active (false);
1284 /* backward = if the redirect was marked to go active on the next ab, do so */
1286 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1288 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1292 if ((*i)->get_next_ab_is_active()) {
1295 (*i)->deactivate ();
1300 _session.set_dirty ();
1304 /** Remove processors with a given placement.
1305 * @param p Placement of processors to remove.
1308 Route::clear_processors (Placement p)
1310 if (!_session.engine().connected()) {
1314 bool already_deleting = _session.deletion_in_progress();
1315 if (!already_deleting) {
1316 _session.set_deletion_in_progress();
1320 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1321 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1322 ProcessorList new_list;
1323 ProcessorStreams err;
1324 bool seen_amp = false;
1326 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1332 if ((*i) == _amp || (*i) == _meter || (*i) == _main_outs || (*i) == _delayline || (*i) == _trim) {
1334 /* you can't remove these */
1336 new_list.push_back (*i);
1343 new_list.push_back (*i);
1346 (*i)->drop_references ();
1354 (*i)->drop_references ();
1357 new_list.push_back (*i);
1364 _processors = new_list;
1365 configure_processors_unlocked (&err, &lm); // this can't fail
1368 processor_max_streams.reset();
1369 _have_internal_generator = false;
1370 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1371 set_processor_positions ();
1373 reset_instrument_info ();
1375 if (!already_deleting) {
1376 _session.clear_deletion_in_progress();
1381 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err, bool need_process_lock)
1383 // TODO once the export point can be configured properly, do something smarter here
1384 if (processor == _capturing_processor) {
1385 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1386 if (need_process_lock) {
1390 _capturing_processor.reset();
1392 if (need_process_lock) {
1397 /* these can never be removed */
1399 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline || processor == _trim) {
1403 if (!_session.engine().connected()) {
1407 processor_max_streams.reset();
1410 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock (), Glib::Threads::NOT_LOCK);
1411 if (need_process_lock) {
1415 /* Caller must hold process lock */
1416 assert (!AudioEngine::instance()->process_lock().trylock());
1418 Glib::Threads::RWLock::WriterLock lm (_processor_lock); // XXX deadlock after export
1420 ProcessorState pstate (this);
1422 ProcessorList::iterator i;
1423 bool removed = false;
1425 for (i = _processors.begin(); i != _processors.end(); ) {
1426 if (*i == processor) {
1428 /* move along, see failure case for configure_processors()
1429 where we may need to reconfigure the processor.
1432 /* stop redirects that send signals to JACK ports
1433 from causing noise as a result of no longer being
1437 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor> (*i);
1438 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
1442 iop = pi->sidechain();
1449 i = _processors.erase (i);
1457 _output->set_user_latency (0);
1465 if (configure_processors_unlocked (err, &lm)) {
1467 /* we know this will work, because it worked before :) */
1468 configure_processors_unlocked (0, &lm);
1472 _have_internal_generator = false;
1474 for (i = _processors.begin(); i != _processors.end(); ++i) {
1475 boost::shared_ptr<PluginInsert> pi;
1477 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1478 if (pi->has_no_inputs ()) {
1479 _have_internal_generator = true;
1484 if (need_process_lock) {
1489 reset_instrument_info ();
1490 processor->drop_references ();
1491 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1492 set_processor_positions ();
1498 Route::replace_processor (boost::shared_ptr<Processor> old, boost::shared_ptr<Processor> sub, ProcessorStreams* err)
1500 /* these can never be removed */
1501 if (old == _amp || old == _meter || old == _main_outs || old == _delayline || old == _trim) {
1504 /* and can't be used as substitute, either */
1505 if (sub == _amp || sub == _meter || sub == _main_outs || sub == _delayline || sub == _trim) {
1509 /* I/Os are out, too */
1510 if (boost::dynamic_pointer_cast<IOProcessor> (old) || boost::dynamic_pointer_cast<IOProcessor> (sub)) {
1514 /* this function cannot be used to swap/reorder processors */
1515 if (find (_processors.begin(), _processors.end(), sub) != _processors.end ()) {
1519 if (!AudioEngine::instance()->connected() || !old || !sub) {
1523 /* ensure that sub is not owned by another route */
1524 if (sub->owner ()) {
1529 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1530 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1531 ProcessorState pstate (this);
1533 assert (find (_processors.begin(), _processors.end(), sub) == _processors.end ());
1535 ProcessorList::iterator i;
1536 bool replaced = false;
1537 bool enable = old->active ();
1539 for (i = _processors.begin(); i != _processors.end(); ) {
1541 i = _processors.erase (i);
1542 _processors.insert (i, sub);
1543 sub->set_owner (this);
1556 boost::shared_ptr<PluginInsert> pi;
1557 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(sub)) != 0) {
1558 pi->set_strict_io (true);
1562 if (configure_processors_unlocked (err, &lm)) {
1564 configure_processors_unlocked (0, &lm);
1568 _have_internal_generator = false;
1570 for (i = _processors.begin(); i != _processors.end(); ++i) {
1571 boost::shared_ptr<PluginInsert> pi;
1572 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1573 if (pi->has_no_inputs ()) {
1574 _have_internal_generator = true;
1584 sub->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1585 _output->set_user_latency (0);
1588 reset_instrument_info ();
1589 old->drop_references ();
1590 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1591 set_processor_positions ();
1596 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1598 ProcessorList deleted;
1600 if (!_session.engine().connected()) {
1604 processor_max_streams.reset();
1607 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
1608 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1609 ProcessorState pstate (this);
1611 ProcessorList::iterator i;
1612 boost::shared_ptr<Processor> processor;
1614 for (i = _processors.begin(); i != _processors.end(); ) {
1618 /* these can never be removed */
1620 if (processor == _amp || processor == _meter || processor == _main_outs || processor == _delayline || processor == _trim) {
1625 /* see if its in the list of processors to delete */
1627 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1632 /* stop IOProcessors that send to JACK ports
1633 from causing noise as a result of no longer being
1637 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(processor);
1638 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
1641 iop = pi->sidechain();
1648 deleted.push_back (processor);
1649 i = _processors.erase (i);
1652 if (deleted.empty()) {
1653 /* none of those in the requested list were found */
1657 _output->set_user_latency (0);
1659 if (configure_processors_unlocked (err, &lm)) {
1661 /* we know this will work, because it worked before :) */
1662 configure_processors_unlocked (0, &lm);
1667 _have_internal_generator = false;
1669 for (i = _processors.begin(); i != _processors.end(); ++i) {
1670 boost::shared_ptr<PluginInsert> pi;
1672 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1673 if (pi->has_no_inputs ()) {
1674 _have_internal_generator = true;
1681 /* now try to do what we need to so that those that were removed will be deleted */
1683 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1684 (*i)->drop_references ();
1687 reset_instrument_info ();
1688 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1689 set_processor_positions ();
1695 Route::reset_instrument_info ()
1697 boost::shared_ptr<Processor> instr = the_instrument();
1699 _instrument_info.set_internal_instrument (instr);
1703 /** Caller must hold process lock */
1705 Route::configure_processors (ProcessorStreams* err)
1707 #ifndef PLATFORM_WINDOWS
1708 assert (!AudioEngine::instance()->process_lock().trylock());
1711 if (!_in_configure_processors) {
1712 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1713 return configure_processors_unlocked (err, &lm);
1720 Route::input_streams () const
1722 return _input->n_ports ();
1725 list<pair<ChanCount, ChanCount> >
1726 Route::try_configure_processors (ChanCount in, ProcessorStreams* err)
1728 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1730 return try_configure_processors_unlocked (in, err);
1733 list<pair<ChanCount, ChanCount> >
1734 Route::try_configure_processors_unlocked (ChanCount in, ProcessorStreams* err)
1736 // Check each processor in order to see if we can configure as requested
1738 list<pair<ChanCount, ChanCount> > configuration;
1741 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1742 DEBUG_TRACE (DEBUG::Processors, "{\n");
1744 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1746 if ((*p)->can_support_io_configuration(in, out)) {
1748 if (boost::dynamic_pointer_cast<Delivery> (*p)
1749 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main
1750 && !(is_monitor() || is_auditioner())
1751 && ( _strict_io || Profile->get_mixbus ())) {
1752 /* with strict I/O the panner + output are forced to
1753 * follow the last processor's output.
1755 * Delivery::can_support_io_configuration() will only add ports,
1756 * but not remove excess ports.
1758 * This works because the delivery only requires
1759 * as many outputs as there are inputs.
1760 * Delivery::configure_io() will do the actual removal
1761 * by calling _output->ensure_io()
1763 if (!is_master() && _session.master_out ()) {
1764 /* ..but at least as many as there are master-inputs */
1765 // XXX this may need special-casing for mixbus (master-outputs)
1766 // and should maybe be a preference anyway ?!
1767 out = ChanCount::max (in, _session.master_out ()->n_inputs ());
1773 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID=%2 in=%3 out=%4\n",(*p)->name(), (*p)->id(), in, out));
1774 configuration.push_back(make_pair(in, out));
1777 // restriction for Monitor Section Processors
1778 if (in.n_audio() != out.n_audio() || out.n_midi() > 0) {
1779 /* do not allow to add/remove channels (for now)
1780 * The Monitor follows the master-bus and has no panner (unpan)
1781 * but do allow processors with midi-in to be added (e.g VSTs with control that
1782 * will remain unconnected)
1784 DEBUG_TRACE (DEBUG::Processors, "Monitor: Channel configuration not allowed.\n");
1785 return list<pair<ChanCount, ChanCount> > ();
1787 if (boost::dynamic_pointer_cast<InternalSend> (*p)) {
1788 // internal sends make no sense, only feedback
1789 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1790 return list<pair<ChanCount, ChanCount> > ();
1792 if (boost::dynamic_pointer_cast<PortInsert> (*p)) {
1793 /* External Sends can be problematic. one can add/remove ports
1794 * there signal leaves the DAW to external monitors anyway, so there's
1795 * no real use for allowing them here anyway.
1797 DEBUG_TRACE (DEBUG::Processors, "Monitor: No External Sends allowed.\n");
1798 return list<pair<ChanCount, ChanCount> > ();
1800 if (boost::dynamic_pointer_cast<Send> (*p)) {
1802 DEBUG_TRACE (DEBUG::Processors, "Monitor: No Sends allowed.\n");
1803 return list<pair<ChanCount, ChanCount> > ();
1812 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
1813 DEBUG_TRACE (DEBUG::Processors, string_compose ("---- %1 cannot support in=%2 out=%3\n", (*p)->name(), in, out));
1814 DEBUG_TRACE (DEBUG::Processors, "}\n");
1815 return list<pair<ChanCount, ChanCount> > ();
1819 DEBUG_TRACE (DEBUG::Processors, "}\n");
1821 return configuration;
1824 /** Set the input/output configuration of each processor in the processors list.
1825 * Caller must hold process lock.
1826 * Return 0 on success, otherwise configuration is impossible.
1829 Route::configure_processors_unlocked (ProcessorStreams* err, Glib::Threads::RWLock::WriterLock* lm)
1831 #ifndef PLATFORM_WINDOWS
1832 assert (!AudioEngine::instance()->process_lock().trylock());
1835 if (_in_configure_processors) {
1839 /* put invisible processors where they should be */
1840 setup_invisible_processors ();
1842 _in_configure_processors = true;
1844 list<pair<ChanCount, ChanCount> > configuration = try_configure_processors_unlocked (input_streams (), err);
1846 if (configuration.empty ()) {
1847 _in_configure_processors = false;
1852 bool seen_mains_out = false;
1853 processor_out_streams = _input->n_ports();
1854 processor_max_streams.reset();
1856 /* processor configure_io() may result in adding ports
1857 * e.g. Delivery::configure_io -> ARDOUR::IO::ensure_io ()
1859 * with jack2 adding ports results in a graph-order callback,
1860 * which calls Session::resort_routes() and eventually
1861 * Route::direct_feeds_according_to_reality()
1862 * which takes a ReaderLock (_processor_lock).
1864 * so we can't hold a WriterLock here until jack2 threading
1867 * NB. we still hold the process lock
1869 * (ardour's own engines do call graph-order from the
1870 * process-thread and hence do not have this issue; besides
1871 * merely adding ports won't trigger a graph-order, only
1872 * making connections does)
1876 // TODO check for a potential ReaderLock after ReaderLock ??
1877 Glib::Threads::RWLock::ReaderLock lr (_processor_lock);
1879 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1880 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1882 if (!(*p)->configure_io(c->first, c->second)) {
1883 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration failed\n", _name));
1884 _in_configure_processors = false;
1889 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1890 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1892 boost::shared_ptr<IOProcessor> iop;
1893 boost::shared_ptr<PluginInsert> pi;
1894 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
1895 /* plugins connected via Split or Hide Match may have more channels.
1896 * route/scratch buffers are needed for all of them
1897 * The configuration may only be a subset (both input and output)
1899 processor_max_streams = ChanCount::max(processor_max_streams, pi->required_buffers());
1901 else if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*p)) != 0) {
1902 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_input_streams());
1903 processor_max_streams = ChanCount::max(processor_max_streams, iop->natural_output_streams());
1907 if (boost::dynamic_pointer_cast<Delivery> (*p)
1908 && boost::dynamic_pointer_cast<Delivery> (*p)->role() == Delivery::Main) {
1909 /* main delivery will increase port count to match input.
1910 * the Delivery::Main is usually the last processor - followed only by
1913 seen_mains_out = true;
1915 if (!seen_mains_out) {
1916 processor_out_streams = out;
1925 _meter->set_max_channels (processor_max_streams);
1928 /* make sure we have sufficient scratch buffers to cope with the new processor
1931 _session.ensure_buffers (n_process_buffers ());
1933 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration complete\n", _name));
1935 _in_configure_processors = false;
1939 /** Set all visible processors to a given active state (except Fader, whose state is not changed)
1940 * @param state New active state for those processors.
1943 Route::all_visible_processors_active (bool state)
1945 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1947 if (_processors.empty()) {
1951 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1952 if (!(*i)->display_to_user() || boost::dynamic_pointer_cast<Amp> (*i)) {
1959 (*i)->deactivate ();
1963 _session.set_dirty ();
1967 Route::processors_reorder_needs_configure (const ProcessorList& new_order)
1969 /* check if re-order requires re-configuration of any processors
1970 * -> compare channel configuration for all processors
1972 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1973 ChanCount c = input_streams ();
1975 for (ProcessorList::const_iterator j = new_order.begin(); j != new_order.end(); ++j) {
1977 if (c != (*j)->input_streams()) {
1980 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1983 if ((*i)->input_streams() != c) {
1986 c = (*i)->output_streams();
1998 __attribute__((annotate("realtime")))
2001 Route::apply_processor_order (const ProcessorList& new_order)
2003 /* need to hold processor_lock; either read or write lock
2004 * and the engine process_lock.
2005 * Due to r/w lock ambiguity we can only assert the latter
2007 assert (!AudioEngine::instance()->process_lock().trylock());
2010 /* "new_order" is an ordered list of processors to be positioned according to "placement".
2011 * NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
2012 * processors in the current actual processor list that are hidden. Any visible processors
2013 * in the current list but not in "new_order" will be assumed to be deleted.
2016 /* "as_it_will_be" and "_processors" are lists of shared pointers.
2017 * actual memory usage is small, but insert/erase is not actually rt-safe :(
2018 * (note though that ::processors_reorder_needs_configure() ensured that
2019 * this function will only ever be called from the rt-thread if no processor were removed)
2021 * either way, I can't proove it, but an x-run due to re-order here is less likley
2022 * than an x-run-less 'ardour-silent cycle' both of which effectively "click".
2025 ProcessorList as_it_will_be;
2026 ProcessorList::iterator oiter;
2027 ProcessorList::const_iterator niter;
2029 oiter = _processors.begin();
2030 niter = new_order.begin();
2032 while (niter != new_order.end()) {
2034 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
2035 then append it to the temp list.
2037 Otherwise, see if the next processor in the old list is in the new list. if not,
2038 its been deleted. If its there, append it to the temp list.
2041 if (oiter == _processors.end()) {
2043 /* no more elements in the old list, so just stick the rest of
2044 the new order onto the temp list.
2047 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
2048 while (niter != new_order.end()) {
2055 if (!(*oiter)->display_to_user()) {
2057 as_it_will_be.push_back (*oiter);
2061 /* visible processor: check that its in the new order */
2063 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
2064 /* deleted: do nothing, shared_ptr<> will clean up */
2066 /* ignore this one, and add the next item from the new order instead */
2067 as_it_will_be.push_back (*niter);
2072 /* now remove from old order - its taken care of no matter what */
2073 oiter = _processors.erase (oiter);
2077 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
2079 /* If the meter is in a custom position, find it and make a rough note of its position */
2080 maybe_note_meter_position ();
2084 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
2086 // it a change is already queued, wait for it
2087 // (unless engine is stopped. apply immediately and proceed
2088 while (g_atomic_int_get (&_pending_process_reorder)) {
2089 if (!AudioEngine::instance()->running()) {
2090 DEBUG_TRACE (DEBUG::Processors, "offline apply queued processor re-order.\n");
2091 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2093 apply_processor_order(_pending_processor_order);
2094 setup_invisible_processors ();
2096 g_atomic_int_set (&_pending_process_reorder, 0);
2098 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2099 set_processor_positions ();
2101 // TODO rather use a semaphore or something.
2102 // but since ::reorder_processors() is called
2103 // from the GUI thread, this is fine..
2108 if (processors_reorder_needs_configure (new_order) || !AudioEngine::instance()->running()) {
2110 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2111 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2112 ProcessorState pstate (this);
2114 apply_processor_order (new_order);
2116 if (configure_processors_unlocked (err, &lm)) {
2124 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2125 set_processor_positions ();
2128 DEBUG_TRACE (DEBUG::Processors, "Queue clickless processor re-order.\n");
2129 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2131 // _pending_processor_order is protected by _processor_lock
2132 _pending_processor_order = new_order;
2133 g_atomic_int_set (&_pending_process_reorder, 1);
2140 Route::add_remove_sidechain (boost::shared_ptr<Processor> proc, bool add)
2142 boost::shared_ptr<PluginInsert> pi;
2143 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2147 if (pi->has_sidechain () == add) {
2148 return true; // ?? call failed, but result is as expected.
2152 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2153 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2154 if (i == _processors.end ()) {
2160 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ()); // take before Writerlock to avoid deadlock
2161 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2162 PBD::Unwinder<bool> uw (_in_sidechain_setup, true);
2164 lx.release (); // IO::add_port() and ~IO takes process lock - XXX check if this is safe
2166 if (!pi->add_sidechain ()) {
2170 if (!pi->del_sidechain ()) {
2176 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2181 pi->del_sidechain ();
2183 pi->add_sidechain ();
2184 // TODO restore side-chain's state.
2189 configure_processors_unlocked (0, &lm);
2192 if (pi->has_sidechain ()) {
2193 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
2196 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2197 _session.set_dirty ();
2202 Route::plugin_preset_output (boost::shared_ptr<Processor> proc, ChanCount outs)
2204 boost::shared_ptr<PluginInsert> pi;
2205 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2210 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2211 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2212 if (i == _processors.end ()) {
2218 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2219 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2221 const ChanCount& old (pi->preset_out ());
2222 if (!pi->set_preset_out (outs)) {
2223 return true; // no change, OK
2226 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2229 pi->set_preset_out (old);
2232 configure_processors_unlocked (0, &lm);
2235 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2236 _session.set_dirty ();
2241 Route::reset_plugin_insert (boost::shared_ptr<Processor> proc)
2244 return customize_plugin_insert (proc, 0, unused, unused);
2248 Route::customize_plugin_insert (boost::shared_ptr<Processor> proc, uint32_t count, ChanCount outs, ChanCount sinks)
2250 boost::shared_ptr<PluginInsert> pi;
2251 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(proc)) == 0) {
2256 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2257 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), proc);
2258 if (i == _processors.end ()) {
2264 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2265 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2267 bool old_cust = pi->custom_cfg ();
2268 uint32_t old_cnt = pi->get_count ();
2269 ChanCount old_chan = pi->output_streams ();
2270 ChanCount old_sinks = pi->natural_input_streams ();
2273 pi->set_custom_cfg (false);
2275 pi->set_custom_cfg (true);
2276 pi->set_count (count);
2277 pi->set_outputs (outs);
2278 pi->set_sinks (sinks);
2281 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2285 pi->set_count (old_cnt);
2286 pi->set_sinks (old_sinks);
2287 pi->set_outputs (old_chan);
2288 pi->set_custom_cfg (old_cust);
2292 configure_processors_unlocked (0, &lm);
2295 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2296 _session.set_dirty ();
2301 Route::set_strict_io (const bool enable)
2303 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
2305 if (_strict_io != enable) {
2306 _strict_io = enable;
2307 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2308 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2309 boost::shared_ptr<PluginInsert> pi;
2310 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2311 pi->set_strict_io (_strict_io);
2315 list<pair<ChanCount, ChanCount> > c = try_configure_processors_unlocked (n_inputs (), 0);
2319 _strict_io = !enable; // restore old value
2320 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p) {
2321 boost::shared_ptr<PluginInsert> pi;
2322 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*p)) != 0) {
2323 pi->set_strict_io (_strict_io);
2330 configure_processors (0);
2333 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2334 _session.set_dirty ();
2346 Route::get_template()
2348 return state(false);
2352 Route::state(bool full_state)
2355 if (!_session._template_state_dir.empty()) {
2356 assert (!full_state); // only for templates
2357 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), _session._template_state_dir));
2360 XMLNode *node = new XMLNode("Route");
2361 ProcessorList::iterator i;
2364 id().print (buf, sizeof (buf));
2365 node->add_property("id", buf);
2366 node->add_property ("name", _name);
2367 node->add_property("default-type", _default_type.to_string());
2368 node->add_property ("strict-io", _strict_io);
2371 node->add_property("flags", enum_2_string (_flags));
2374 node->add_property("active", _active?"yes":"no");
2376 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
2377 node->add_property("meter-point", enum_2_string (_meter_point));
2379 node->add_property("meter-type", enum_2_string (_meter_type));
2382 node->add_property("route-group", _route_group->name());
2385 snprintf (buf, sizeof (buf), "%d", _order_key);
2386 node->add_property ("order-key", buf);
2388 node->add_child_nocopy (_input->state (full_state));
2389 node->add_child_nocopy (_output->state (full_state));
2390 node->add_child_nocopy (_mute_master->get_state ());
2393 node->add_child_nocopy (Automatable::get_automation_xml_state ());
2396 XMLNode* remote_control_node = new XMLNode (X_("RemoteControl"));
2397 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
2398 remote_control_node->add_property (X_("id"), buf);
2399 node->add_child_nocopy (*remote_control_node);
2401 if (_comment.length()) {
2402 XMLNode *cmt = node->add_child ("Comment");
2403 cmt->add_content (_comment);
2407 node->add_child_nocopy (_pannable->state (full_state));
2411 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2412 for (i = _processors.begin(); i != _processors.end(); ++i) {
2414 /* template save: do not include internal sends functioning as
2415 aux sends because the chance of the target ID
2416 in the session where this template is used
2419 similarly, do not save listen sends which connect to
2420 the monitor section, because these will always be
2423 boost::shared_ptr<InternalSend> is;
2425 if ((is = boost::dynamic_pointer_cast<InternalSend> (*i)) != 0) {
2426 if (is->role() == Delivery::Listen) {
2431 node->add_child_nocopy((*i)->state (full_state));
2436 node->add_child_copy (*_extra_xml);
2439 if (_custom_meter_position_noted) {
2440 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
2442 after->id().print (buf, sizeof (buf));
2443 node->add_property (X_("processor-after-last-custom-meter"), buf);
2447 if (!_session._template_state_dir.empty()) {
2448 foreach_processor (sigc::bind (sigc::mem_fun (*this, &Route::set_plugin_state_dir), ""));
2455 Route::set_state (const XMLNode& node, int version)
2457 if (version < 3000) {
2458 return set_state_2X (node, version);
2462 XMLNodeConstIterator niter;
2464 XMLProperty const * prop;
2466 if (node.name() != "Route"){
2467 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2471 if ((prop = node.property (X_("name"))) != 0) {
2472 Route::set_name (prop->value());
2476 _initial_io_setup = true;
2478 if ((prop = node.property (X_("flags"))) != 0) {
2479 _flags = Flag (string_2_enum (prop->value(), _flags));
2484 if ((prop = node.property (X_("strict-io"))) != 0) {
2485 _strict_io = string_is_affirmative (prop->value());
2489 _mute_master->set_solo_ignore (true);
2493 /* monitor bus does not get a panner, but if (re)created
2494 via XML, it will already have one by the time we
2495 call ::set_state(). so ... remove it.
2500 /* add all processors (except amp, which is always present) */
2502 nlist = node.children();
2503 XMLNode processor_state (X_("processor_state"));
2505 Stateful::save_extra_xml (node);
2507 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2511 if (child->name() == IO::state_node_name) {
2512 if ((prop = child->property (X_("direction"))) == 0) {
2516 if (prop->value() == "Input") {
2517 _input->set_state (*child, version);
2518 } else if (prop->value() == "Output") {
2519 _output->set_state (*child, version);
2523 if (child->name() == X_("Processor")) {
2524 processor_state.add_child_copy (*child);
2527 if (child->name() == X_("Pannable")) {
2529 _pannable->set_state (*child, version);
2531 warning << string_compose (_("Pannable state found for route (%1) without a panner!"), name()) << endmsg;
2536 if ((prop = node.property (X_("meter-point"))) != 0) {
2537 MeterPoint mp = MeterPoint (string_2_enum (prop->value (), _meter_point));
2538 set_meter_point (mp, true);
2540 _meter->set_display_to_user (_meter_point == MeterCustom);
2544 if ((prop = node.property (X_("meter-type"))) != 0) {
2545 _meter_type = MeterType (string_2_enum (prop->value (), _meter_type));
2548 _initial_io_setup = false;
2550 set_processor_state (processor_state);
2552 // this looks up the internal instrument in processors
2553 reset_instrument_info();
2555 _solo_control->set_state (node, version);
2556 _solo_safe_control->set_state (node, version);
2557 _solo_isolate_control->set_state (node, version);
2558 _mute_control->set_state (node, version);
2560 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2561 set_denormal_protection (string_is_affirmative (prop->value()));
2564 if ((prop = node.property (X_("active"))) != 0) {
2565 bool yn = string_is_affirmative (prop->value());
2566 set_active (yn, this);
2569 if ((prop = node.property (X_("order-key"))) != 0) { // New order key (no separate mixer/editor ordering)
2570 set_order_key (atoi(prop->value()));
2573 if ((prop = node.property (X_("order-keys"))) != 0) { // Deprecated order keys
2577 string::size_type colon, equal;
2578 string remaining = prop->value();
2580 while (remaining.length()) {
2582 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2583 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2586 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2587 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2590 string keyname = remaining.substr (0, equal);
2592 if ((keyname == "EditorSort") || (keyname == "editor")) {
2593 cerr << "Setting " << name() << " order key to " << n << " using saved Editor order." << endl;
2599 colon = remaining.find_first_of (':');
2601 if (colon != string::npos) {
2602 remaining = remaining.substr (colon+1);
2609 if ((prop = node.property (X_("processor-after-last-custom-meter"))) != 0) {
2610 PBD::ID id (prop->value ());
2611 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2612 ProcessorList::const_iterator i = _processors.begin ();
2613 while (i != _processors.end() && (*i)->id() != id) {
2617 if (i != _processors.end ()) {
2618 _processor_after_last_custom_meter = *i;
2619 _custom_meter_position_noted = true;
2623 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2626 if (child->name() == X_("Comment")) {
2628 /* XXX this is a terrible API design in libxml++ */
2630 XMLNode *cmt = *(child->children().begin());
2631 _comment = cmt->content();
2633 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2634 if (prop->value() == "solo") {
2635 _solo_control->set_state (*child, version);
2636 } else if (prop->value() == "mute") {
2637 _mute_control->set_state (*child, version);
2640 } else if (child->name() == X_("RemoteControl")) {
2641 if ((prop = child->property (X_("id"))) != 0) {
2643 sscanf (prop->value().c_str(), "%d", &x);
2644 set_remote_control_id_internal (x);
2647 } else if (child->name() == MuteMaster::xml_node_name) {
2648 _mute_master->set_state (*child, version);
2650 } else if (child->name() == Automatable::xml_node_name) {
2651 set_automation_xml_state (*child, Evoral::Parameter(NullAutomation));
2659 Route::set_state_2X (const XMLNode& node, int version)
2663 XMLNodeConstIterator niter;
2665 XMLProperty const * prop;
2667 /* 2X things which still remain to be handled:
2673 if (node.name() != "Route") {
2674 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2678 if ((prop = node.property (X_("flags"))) != 0) {
2679 string f = prop->value ();
2680 boost::replace_all (f, "ControlOut", "MonitorOut");
2681 _flags = Flag (string_2_enum (f, _flags));
2686 if (is_master() || is_monitor() || is_auditioner()) {
2687 _mute_master->set_solo_ignore (true);
2690 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2691 set_denormal_protection (string_is_affirmative (prop->value()));
2694 if ((prop = node.property (X_("muted"))) != 0) {
2697 bool muted = string_is_affirmative (prop->value());
2703 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2705 if (string_is_affirmative (prop->value())){
2706 mute_point = mute_point + "PreFader";
2711 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2713 if (string_is_affirmative (prop->value())){
2716 mute_point = mute_point + ",";
2719 mute_point = mute_point + "PostFader";
2724 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2726 if (string_is_affirmative (prop->value())){
2729 mute_point = mute_point + ",";
2732 mute_point = mute_point + "Listen";
2737 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2739 if (string_is_affirmative (prop->value())){
2742 mute_point = mute_point + ",";
2745 mute_point = mute_point + "Main";
2749 _mute_master->set_mute_points (mute_point);
2750 _mute_master->set_muted_by_self (true);
2754 if ((prop = node.property (X_("meter-point"))) != 0) {
2755 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2758 /* do not carry over edit/mix groups from 2.X because (a) its hard (b) they
2759 don't mean the same thing.
2762 if ((prop = node.property (X_("order-keys"))) != 0) {
2766 string::size_type colon, equal;
2767 string remaining = prop->value();
2769 while (remaining.length()) {
2771 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2772 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2775 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2776 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2779 string keyname = remaining.substr (0, equal);
2781 if (keyname == "EditorSort" || keyname == "editor") {
2782 info << string_compose(_("Converting deprecated order key for %1 using Editor order %2"), name (), n) << endmsg;
2788 colon = remaining.find_first_of (':');
2790 if (colon != string::npos) {
2791 remaining = remaining.substr (colon+1);
2800 nlist = node.children ();
2801 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2805 if (child->name() == IO::state_node_name) {
2807 /* there is a note in IO::set_state_2X() about why we have to call
2811 _input->set_state_2X (*child, version, true);
2812 _output->set_state_2X (*child, version, false);
2814 if ((prop = child->property (X_("name"))) != 0) {
2815 Route::set_name (prop->value ());
2820 if ((prop = child->property (X_("active"))) != 0) {
2821 bool yn = string_is_affirmative (prop->value());
2822 _active = !yn; // force switch
2823 set_active (yn, this);
2826 if ((prop = child->property (X_("gain"))) != 0) {
2829 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
2830 _amp->gain_control()->set_value (val, Controllable::NoGroup);
2834 /* Set up Panners in the IO */
2835 XMLNodeList io_nlist = child->children ();
2837 XMLNodeConstIterator io_niter;
2840 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
2842 io_child = *io_niter;
2844 if (io_child->name() == X_("Panner")) {
2845 _main_outs->panner_shell()->set_state(*io_child, version);
2846 } else if (io_child->name() == X_("Automation")) {
2847 /* IO's automation is for the fader */
2848 _amp->set_automation_xml_state (*io_child, Evoral::Parameter (GainAutomation));
2854 XMLNodeList redirect_nodes;
2856 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2860 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2861 redirect_nodes.push_back(child);
2866 set_processor_state_2X (redirect_nodes, version);
2868 Stateful::save_extra_xml (node);
2870 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2873 if (child->name() == X_("Comment")) {
2875 /* XXX this is a terrible API design in libxml++ */
2877 XMLNode *cmt = *(child->children().begin());
2878 _comment = cmt->content();
2880 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2881 if (prop->value() == X_("solo")) {
2882 _solo_control->set_state (*child, version);
2883 } else if (prop->value() == X_("mute")) {
2884 _mute_control->set_state (*child, version);
2887 } else if (child->name() == X_("RemoteControl")) {
2888 if ((prop = child->property (X_("id"))) != 0) {
2890 sscanf (prop->value().c_str(), "%d", &x);
2891 set_remote_control_id_internal (x);
2901 Route::get_processor_state ()
2903 XMLNode* root = new XMLNode (X_("redirects"));
2904 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2905 root->add_child_nocopy ((*i)->state (true));
2912 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2914 /* We don't bother removing existing processors not in nList, as this
2915 method will only be called when creating a Route from scratch, not
2916 for undo purposes. Just put processors in at the appropriate place
2920 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2921 add_processor_from_xml_2X (**i, version);
2926 Route::set_processor_state (const XMLNode& node)
2928 const XMLNodeList &nlist = node.children();
2929 XMLNodeConstIterator niter;
2930 ProcessorList new_order;
2931 bool must_configure = false;
2933 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2935 XMLProperty* prop = (*niter)->property ("type");
2937 if (prop->value() == "amp") {
2938 _amp->set_state (**niter, Stateful::current_state_version);
2939 new_order.push_back (_amp);
2940 } else if (prop->value() == "trim") {
2941 _trim->set_state (**niter, Stateful::current_state_version);
2942 new_order.push_back (_trim);
2943 } else if (prop->value() == "meter") {
2944 _meter->set_state (**niter, Stateful::current_state_version);
2945 new_order.push_back (_meter);
2946 } else if (prop->value() == "delay") {
2948 _delayline->set_state (**niter, Stateful::current_state_version);
2949 new_order.push_back (_delayline);
2951 } else if (prop->value() == "main-outs") {
2952 _main_outs->set_state (**niter, Stateful::current_state_version);
2953 } else if (prop->value() == "intreturn") {
2955 _intreturn.reset (new InternalReturn (_session));
2956 must_configure = true;
2958 _intreturn->set_state (**niter, Stateful::current_state_version);
2959 } else if (is_monitor() && prop->value() == "monitor") {
2960 if (!_monitor_control) {
2961 _monitor_control.reset (new MonitorProcessor (_session));
2962 must_configure = true;
2964 _monitor_control->set_state (**niter, Stateful::current_state_version);
2965 } else if (prop->value() == "capture") {
2966 /* CapturingProcessor should never be restored, it's always
2967 added explicitly when needed */
2969 ProcessorList::iterator o;
2971 for (o = _processors.begin(); o != _processors.end(); ++o) {
2972 XMLProperty const * id_prop = (*niter)->property(X_("id"));
2973 if (id_prop && (*o)->id() == id_prop->value()) {
2974 (*o)->set_state (**niter, Stateful::current_state_version);
2975 new_order.push_back (*o);
2980 // If the processor (*niter) is not on the route then create it
2982 if (o == _processors.end()) {
2984 boost::shared_ptr<Processor> processor;
2986 if (prop->value() == "intsend") {
2988 processor.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), boost::shared_ptr<Route>(), Delivery::Aux, true));
2990 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
2991 prop->value() == "lv2" ||
2992 prop->value() == "windows-vst" ||
2993 prop->value() == "lxvst" ||
2994 prop->value() == "luaproc" ||
2995 prop->value() == "audiounit") {
2997 if (_session.get_disable_all_loaded_plugins ()) {
2998 processor.reset (new UnknownProcessor (_session, **niter));
3000 processor.reset (new PluginInsert (_session));
3001 processor->set_owner (this);
3003 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(processor);
3004 pi->set_strict_io (true);
3008 } else if (prop->value() == "port") {
3010 processor.reset (new PortInsert (_session, _pannable, _mute_master));
3012 } else if (prop->value() == "send") {
3014 processor.reset (new Send (_session, _pannable, _mute_master, Delivery::Send, true));
3015 boost::shared_ptr<Send> send = boost::dynamic_pointer_cast<Send> (processor);
3016 send->SelfDestruct.connect_same_thread (*this,
3017 boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (processor)));
3020 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
3024 if (processor->set_state (**niter, Stateful::current_state_version) != 0) {
3025 /* This processor could not be configured. Turn it into a UnknownProcessor */
3026 processor.reset (new UnknownProcessor (_session, **niter));
3029 /* subscribe to Sidechain IO changes */
3030 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
3031 if (pi && pi->has_sidechain ()) {
3032 pi->sidechain_input ()->changed.connect_same_thread (*this, boost::bind (&Route::sidechain_change_handler, this, _1, _2));
3035 /* we have to note the monitor send here, otherwise a new one will be created
3036 and the state of this one will be lost.
3038 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
3039 if (isend && isend->role() == Delivery::Listen) {
3040 _monitor_send = isend;
3043 /* it doesn't matter if invisible processors are added here, as they
3044 will be sorted out by setup_invisible_processors () shortly.
3047 new_order.push_back (processor);
3048 must_configure = true;
3054 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3055 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3056 _processors = new_order;
3058 if (must_configure) {
3059 configure_processors_unlocked (0, &lm);
3062 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3064 (*i)->set_owner (this);
3065 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
3067 boost::shared_ptr<PluginInsert> pi;
3069 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
3070 if (pi->has_no_inputs ()) {
3071 _have_internal_generator = true;
3078 reset_instrument_info ();
3079 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3080 set_processor_positions ();
3084 Route::curve_reallocate ()
3086 // _gain_automation_curve.finish_resize ();
3087 // _pan_automation_curve.finish_resize ();
3091 Route::silence (framecnt_t nframes)
3093 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3098 silence_unlocked (nframes);
3102 Route::silence_unlocked (framecnt_t nframes)
3104 /* Must be called with the processor lock held */
3108 _output->silence (nframes);
3110 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3111 boost::shared_ptr<PluginInsert> pi;
3113 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
3114 // skip plugins, they don't need anything when we're not active
3118 (*i)->silence (nframes);
3121 if (nframes == _session.get_block_size()) {
3128 Route::add_internal_return ()
3131 _intreturn.reset (new InternalReturn (_session));
3132 add_processor (_intreturn, PreFader);
3137 Route::add_send_to_internal_return (InternalSend* send)
3139 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3141 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3142 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3145 return d->add_send (send);
3151 Route::remove_send_from_internal_return (InternalSend* send)
3153 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3155 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
3156 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
3159 return d->remove_send (send);
3165 Route::enable_monitor_send ()
3167 /* Caller must hold process lock */
3168 assert (!AudioEngine::instance()->process_lock().trylock());
3170 /* master never sends to monitor section via the normal mechanism */
3171 assert (!is_master ());
3172 assert (!is_monitor ());
3174 /* make sure we have one */
3175 if (!_monitor_send) {
3176 _monitor_send.reset (new InternalSend (_session, _pannable, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), _session.monitor_out(), Delivery::Listen));
3177 _monitor_send->set_display_to_user (false);
3181 configure_processors (0);
3184 /** Add an aux send to a route.
3185 * @param route route to send to.
3186 * @param before Processor to insert before, or 0 to insert at the end.
3189 Route::add_aux_send (boost::shared_ptr<Route> route, boost::shared_ptr<Processor> before)
3191 assert (route != _session.monitor_out ());
3194 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
3196 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3198 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend> (*x);
3200 if (d && d->target_route() == route) {
3201 /* already listening via the specified IO: do nothing */
3209 boost::shared_ptr<InternalSend> listener;
3212 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
3213 boost::shared_ptr<Pannable> sendpan (new Pannable (_session));
3214 listener.reset (new InternalSend (_session, sendpan, _mute_master, boost::dynamic_pointer_cast<ARDOUR::Route>(shared_from_this()), route, Delivery::Aux));
3217 add_processor (listener, before);
3219 } catch (failed_constructor& err) {
3227 Route::remove_aux_or_listen (boost::shared_ptr<Route> route)
3229 ProcessorStreams err;
3230 ProcessorList::iterator tmp;
3233 Glib::Threads::RWLock::ReaderLock rl(_processor_lock);
3235 /* have to do this early because otherwise processor reconfig
3236 * will put _monitor_send back in the list
3239 if (route == _session.monitor_out()) {
3240 _monitor_send.reset ();
3244 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
3246 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
3248 if (d && d->target_route() == route) {
3250 if (remove_processor (*x, &err, false) > 0) {
3256 /* list could have been demolished while we dropped the lock
3259 if (_session.engine().connected()) {
3260 /* i/o processors cannot be removed if the engine is not running
3261 * so don't live-loop in case the engine is N/A or dies
3271 Route::set_comment (string cmt, void *src)
3275 _session.set_dirty ();
3279 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
3281 FeedRecord fr (other, via_sends_only);
3283 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
3285 if (!result.second) {
3287 /* already a record for "other" - make sure sends-only information is correct */
3288 if (!via_sends_only && result.first->sends_only) {
3289 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
3290 frp->sends_only = false;
3294 return result.second;
3298 Route::clear_fed_by ()
3304 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
3306 const FedBy& fed_by (other->fed_by());
3308 for (FedBy::const_iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
3309 boost::shared_ptr<Route> sr = f->r.lock();
3311 if (sr && (sr.get() == this)) {
3313 if (via_sends_only) {
3314 *via_sends_only = f->sends_only;
3325 Route::all_inputs () const
3327 /* TODO, if this works as expected,
3328 * cache the IOVector and maintain it via
3329 * input_change_handler(), sidechain_change_handler() etc
3332 ios.push_back (_input);
3334 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3335 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3337 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3338 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3341 iop = pi->sidechain();
3344 if (iop != 0 && iop->input()) {
3345 ios.push_back (iop->input());
3352 Route::all_outputs () const
3355 // _output is included via Delivery
3356 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3357 for (ProcessorList::const_iterator r = _processors.begin(); r != _processors.end(); ++r) {
3358 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3359 if (iop != 0 && iop->output()) {
3360 ios.push_back (iop->output());
3367 Route::direct_feeds_according_to_reality (boost::shared_ptr<Route> other, bool* via_send_only)
3369 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
3370 if (other->all_inputs().fed_by (_output)) {
3371 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
3372 if (via_send_only) {
3373 *via_send_only = false;
3379 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3381 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
3383 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor>(*r);
3384 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*r);
3387 iop = pi->sidechain();
3391 boost::shared_ptr<const IO> iop_out = iop->output();
3392 if ((iop_out && other->all_inputs().fed_by (iop_out)) || iop->feeds (other)) {
3393 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
3394 if (via_send_only) {
3395 *via_send_only = true;
3399 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
3402 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
3407 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
3412 Route::direct_feeds_according_to_graph (boost::shared_ptr<Route> other, bool* via_send_only)
3414 return _session._current_route_graph.has (shared_from_this (), other, via_send_only);
3418 Route::feeds_according_to_graph (boost::shared_ptr<Route> other)
3420 return _session._current_route_graph.feeds (shared_from_this (), other);
3423 /** Called from the (non-realtime) butler thread when the transport is stopped */
3425 Route::nonrealtime_handle_transport_stopped (bool /*abort_ignored*/, bool /*did_locate*/, bool can_flush_processors)
3427 framepos_t now = _session.transport_frame();
3430 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3432 Automatable::transport_stopped (now);
3434 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3436 if (!_have_internal_generator && (Config->get_plugins_stop_with_transport() && can_flush_processors)) {
3440 (*i)->transport_stopped (now);
3444 _roll_delay = _initial_delay;
3448 Route::input_change_handler (IOChange change, void * /*src*/)
3450 if ((change.type & IOChange::ConfigurationChanged)) {
3451 /* This is called with the process lock held if change
3452 contains ConfigurationChanged
3454 configure_processors (0);
3455 _phase_control->resize (_input->n_ports().n_audio ());
3456 io_changed (); /* EMIT SIGNAL */
3459 if (_solo_control->soloed_by_others_upstream() || _solo_isolate_control->solo_isolated_by_upstream()) {
3462 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3463 if (_input->connected()) {
3464 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3465 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3469 bool does_feed = (*i)->direct_feeds_according_to_reality (shared_from_this(), &sends_only);
3470 if (does_feed && !sends_only) {
3471 if ((*i)->soloed()) {
3474 if ((*i)->solo_isolate_control()->solo_isolated()) {
3481 int delta = sbou - _solo_control->soloed_by_others_upstream();
3482 int idelta = ibou - _solo_isolate_control->solo_isolated_by_upstream();
3485 PBD::warning << string_compose (
3486 _("Invalid Solo-Isolate propagation: from:%1 new:%2 - old:%3 = delta:%4"),
3487 _name, ibou, _solo_isolate_control->solo_isolated_by_upstream(), idelta)
3492 if (_solo_control->soloed_by_others_upstream()) {
3493 // ignore new connections (they're not propagated)
3495 _solo_control->mod_solo_by_others_upstream (delta);
3499 if (_solo_isolate_control->solo_isolated_by_upstream()) {
3500 // solo-isolate currently only propagates downstream
3502 _solo_isolate_control->mod_solo_isolated_by_upstream (1);
3504 //_solo_isolated_by_upstream = ibou;
3507 // Session::route_solo_changed does not propagate indirect solo-changes
3508 // propagate downstream to tracks
3509 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3510 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_auditioner()) {
3514 bool does_feed = feeds (*i, &sends_only);
3515 if (delta <= 0 && does_feed && !sends_only) {
3516 (*i)->solo_control()->mod_solo_by_others_upstream (delta);
3519 if (idelta < 0 && does_feed && !sends_only) {
3520 (*i)->solo_isolate_control()->mod_solo_isolated_by_upstream (-1);
3527 Route::output_change_handler (IOChange change, void * /*src*/)
3529 if (_initial_io_setup) {
3533 if ((change.type & IOChange::ConfigurationChanged)) {
3534 /* This is called with the process lock held if change
3535 contains ConfigurationChanged
3537 configure_processors (0);
3540 _session.reset_monitor_section();
3543 io_changed (); /* EMIT SIGNAL */
3546 if (_solo_control->soloed_by_others_downstream()) {
3548 /* checking all all downstream routes for
3549 * explicit of implict solo is a rather drastic measure,
3550 * ideally the input_change_handler() of the other route
3551 * would propagate the change to us.
3553 boost::shared_ptr<RouteList> routes = _session.get_routes ();
3554 if (_output->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 = direct_feeds_according_to_reality (*i, &sends_only);
3561 if (does_feed && !sends_only) {
3562 if ((*i)->soloed()) {
3569 int delta = sbod - _solo_control->soloed_by_others_downstream();
3571 // do not allow new connections to change implicit solo (no propagation)
3572 _solo_control->mod_solo_by_others_downstream (delta);
3573 // Session::route_solo_changed() does not propagate indirect solo-changes
3574 // propagate upstream to tracks
3575 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
3576 if ((*i).get() == this || !can_solo()) {
3580 bool does_feed = (*i)->feeds (shared_from_this(), &sends_only);
3581 if (delta != 0 && does_feed && !sends_only) {
3582 (*i)->solo_control()->mod_solo_by_others_downstream (delta);
3591 Route::sidechain_change_handler (IOChange change, void* src)
3593 if (_initial_io_setup || _in_sidechain_setup) {
3597 input_change_handler (change, src);
3601 Route::pans_required () const
3603 if (n_outputs().n_audio() < 2) {
3607 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
3611 Route::no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, bool session_state_changing)
3613 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3619 if (n_outputs().n_total() == 0) {
3623 if (!_active || n_inputs() == ChanCount::ZERO) {
3624 silence_unlocked (nframes);
3628 if (session_state_changing) {
3629 if (_session.transport_speed() != 0.0f) {
3630 /* we're rolling but some state is changing (e.g. our diskstream contents)
3631 so we cannot use them. Be silent till this is over.
3633 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
3635 silence_unlocked (nframes);
3638 /* we're really not rolling, so we're either delivery silence or actually
3639 monitoring, both of which are safe to do while session_state_changing is true.
3643 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3645 fill_buffers_with_input (bufs, _input, nframes);
3647 if (_meter_point == MeterInput) {
3648 _meter->run (bufs, start_frame, end_frame, nframes, true);
3651 _amp->apply_gain_automation (false);
3652 _trim->apply_gain_automation (false);
3653 passthru (bufs, start_frame, end_frame, nframes, 0);
3659 Route::roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, int declick, bool& /* need_butler */)
3661 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3666 if (n_outputs().n_total() == 0) {
3670 if (!_active || n_inputs().n_total() == 0) {
3671 silence_unlocked (nframes);
3675 framepos_t unused = 0;
3677 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
3683 BufferSet& bufs = _session.get_route_buffers (n_process_buffers());
3685 fill_buffers_with_input (bufs, _input, nframes);
3687 if (_meter_point == MeterInput) {
3688 _meter->run (bufs, start_frame, end_frame, nframes, true);
3691 passthru (bufs, start_frame, end_frame, nframes, declick);
3697 Route::silent_roll (pframes_t nframes, framepos_t /*start_frame*/, framepos_t /*end_frame*/, bool& /* need_butler */)
3704 Route::flush_processors ()
3706 /* XXX shouldn't really try to take this lock, since
3707 this is called from the RT audio thread.
3710 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3712 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3718 __attribute__((annotate("realtime")))
3721 Route::apply_processor_changes_rt ()
3723 int emissions = EmitNone;
3725 if (_pending_meter_point != _meter_point) {
3726 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3728 /* meters always have buffers for 'processor_max_streams'
3729 * they can be re-positioned without re-allocation */
3730 if (set_meter_point_unlocked()) {
3731 emissions |= EmitMeterChanged | EmitMeterVisibilityChange;;
3733 emissions |= EmitMeterChanged;
3738 bool changed = false;
3740 if (g_atomic_int_get (&_pending_process_reorder)) {
3741 Glib::Threads::RWLock::WriterLock pwl (_processor_lock, Glib::Threads::TRY_LOCK);
3743 apply_processor_order (_pending_processor_order);
3744 setup_invisible_processors ();
3746 g_atomic_int_set (&_pending_process_reorder, 0);
3747 emissions |= EmitRtProcessorChange;
3751 set_processor_positions ();
3753 if (emissions != 0) {
3754 g_atomic_int_set (&_pending_signals, emissions);
3757 return (!selfdestruct_sequence.empty ());
3761 Route::emit_pending_signals ()
3763 int sig = g_atomic_int_and (&_pending_signals, 0);
3764 if (sig & EmitMeterChanged) {
3765 _meter->emit_configuration_changed();
3766 meter_change (); /* EMIT SIGNAL */
3767 if (sig & EmitMeterVisibilityChange) {
3768 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3770 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3773 if (sig & EmitRtProcessorChange) {
3774 processors_changed (RouteProcessorChange (RouteProcessorChange::RealTimeChange)); /* EMIT SIGNAL */
3777 /* this would be a job for the butler.
3778 * Conceptually we should not take processe/processor locks here.
3779 * OTOH its more efficient (less overhead for summoning the butler and
3780 * telling her what do do) and signal emission is called
3781 * directly after the process callback, which decreases the chance
3782 * of x-runs when taking the locks.
3784 while (!selfdestruct_sequence.empty ()) {
3785 Glib::Threads::Mutex::Lock lx (selfdestruct_lock);
3786 if (selfdestruct_sequence.empty ()) { break; } // re-check with lock
3787 boost::shared_ptr<Processor> proc = selfdestruct_sequence.back ().lock ();
3788 selfdestruct_sequence.pop_back ();
3791 remove_processor (proc);
3797 Route::set_meter_point (MeterPoint p, bool force)
3799 if (_pending_meter_point == p && !force) {
3803 if (force || !AudioEngine::instance()->running()) {
3804 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3805 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3806 _pending_meter_point = p;
3807 _meter->emit_configuration_changed();
3808 meter_change (); /* EMIT SIGNAL */
3809 if (set_meter_point_unlocked()) {
3810 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, true)); /* EMIT SIGNAL */
3812 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, false)); /* EMIT SIGNAL */
3815 _pending_meter_point = p;
3821 __attribute__((annotate("realtime")))
3824 Route::set_meter_point_unlocked ()
3827 /* Caller must hold process and processor write lock */
3828 assert (!AudioEngine::instance()->process_lock().trylock());
3829 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3830 assert (!lm.locked ());
3833 _meter_point = _pending_meter_point;
3835 bool meter_was_visible_to_user = _meter->display_to_user ();
3837 if (!_custom_meter_position_noted) {
3838 maybe_note_meter_position ();
3841 if (_meter_point != MeterCustom) {
3843 _meter->set_display_to_user (false);
3845 setup_invisible_processors ();
3848 _meter->set_display_to_user (true);
3850 /* If we have a previous position for the custom meter, try to put it there */
3851 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
3853 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), after);
3854 if (i != _processors.end ()) {
3855 _processors.remove (_meter);
3856 _processors.insert (i, _meter);
3858 } else {// at end, right before the mains_out/panner
3859 _processors.remove (_meter);
3860 ProcessorList::iterator main = _processors.end();
3861 _processors.insert (--main, _meter);
3865 /* Set up the meter for its new position */
3867 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
3871 if (loc == _processors.begin()) {
3872 m_in = _input->n_ports();
3874 ProcessorList::iterator before = loc;
3876 m_in = (*before)->output_streams ();
3879 _meter->reflect_inputs (m_in);
3881 /* we do not need to reconfigure the processors, because the meter
3882 (a) is always ready to handle processor_max_streams
3883 (b) is always an N-in/N-out processor, and thus moving
3884 it doesn't require any changes to the other processors.
3887 /* these should really be done after releasing the lock
3888 * but all those signals are subscribed to with gui_thread()
3891 return (_meter->display_to_user() != meter_was_visible_to_user);
3895 Route::listen_position_changed ()
3898 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3899 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3900 ProcessorState pstate (this);
3902 if (configure_processors_unlocked (0, &lm)) {
3903 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
3905 configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
3910 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3911 _session.set_dirty ();
3914 boost::shared_ptr<CapturingProcessor>
3915 Route::add_export_point()
3917 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3918 if (!_capturing_processor) {
3920 Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
3921 Glib::Threads::RWLock::WriterLock lw (_processor_lock);
3923 _capturing_processor.reset (new CapturingProcessor (_session));
3924 _capturing_processor->activate ();
3926 configure_processors_unlocked (0, &lw);
3930 return _capturing_processor;
3934 Route::update_signal_latency ()
3936 framecnt_t l = _output->user_latency();
3937 framecnt_t lamp = 0;
3938 bool before_amp = true;
3939 framecnt_t ltrim = 0;
3940 bool before_trim = true;
3942 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3943 if ((*i)->active ()) {
3944 l += (*i)->signal_latency ();
3949 if ((*i) == _trim) {
3960 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal signal latency = %2\n", _name, l));
3962 // TODO: (lamp - _signal_latency) to sync to output (read-ahed), currently _roll_delay shifts this around
3963 _signal_latency_at_amp_position = lamp;
3964 _signal_latency_at_trim_position = ltrim;
3966 if (_signal_latency != l) {
3967 _signal_latency = l;
3968 signal_latency_changed (); /* EMIT SIGNAL */
3971 return _signal_latency;
3975 Route::set_user_latency (framecnt_t nframes)
3977 _output->set_user_latency (nframes);
3978 _session.update_latency_compensation ();
3982 Route::set_latency_compensation (framecnt_t longest_session_latency)
3984 framecnt_t old = _initial_delay;
3986 if (_signal_latency < longest_session_latency) {
3987 _initial_delay = longest_session_latency - _signal_latency;
3992 DEBUG_TRACE (DEBUG::Latency, string_compose (
3993 "%1: compensate for maximum latency of %2,"
3994 "given own latency of %3, using initial delay of %4\n",
3995 name(), longest_session_latency, _signal_latency, _initial_delay));
3997 if (_initial_delay != old) {
3998 initial_delay_changed (); /* EMIT SIGNAL */
4001 if (_session.transport_stopped()) {
4002 _roll_delay = _initial_delay;
4007 Route::set_block_size (pframes_t nframes)
4009 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4010 (*i)->set_block_size (nframes);
4013 _session.ensure_buffers (n_process_buffers ());
4017 Route::protect_automation ()
4019 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
4020 (*i)->protect_automation();
4023 /** @param declick 1 to set a pending declick fade-in,
4024 * -1 to set a pending declick fade-out
4027 Route::set_pending_declick (int declick)
4030 /* this call is not allowed to turn off a pending declick */
4032 _pending_declick = declick;
4035 _pending_declick = 0;
4039 /** Shift automation forwards from a particular place, thereby inserting time.
4040 * Adds undo commands for any shifts that are performed.
4042 * @param pos Position to start shifting from.
4043 * @param frames Amount to shift forwards by.
4047 Route::shift (framepos_t pos, framecnt_t frames)
4049 /* gain automation */
4051 boost::shared_ptr<AutomationControl> gc = _amp->gain_control();
4053 XMLNode &before = gc->alist()->get_state ();
4054 gc->alist()->shift (pos, frames);
4055 XMLNode &after = gc->alist()->get_state ();
4056 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
4059 /* gain automation */
4061 boost::shared_ptr<AutomationControl> gc = _trim->gain_control();
4063 XMLNode &before = gc->alist()->get_state ();
4064 gc->alist()->shift (pos, frames);
4065 XMLNode &after = gc->alist()->get_state ();
4066 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
4069 // TODO mute automation ??
4071 /* pan automation */
4073 ControlSet::Controls& c (_pannable->controls());
4075 for (ControlSet::Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
4076 boost::shared_ptr<AutomationControl> pc = boost::dynamic_pointer_cast<AutomationControl> (ci->second);
4078 boost::shared_ptr<AutomationList> al = pc->alist();
4079 XMLNode& before = al->get_state ();
4080 al->shift (pos, frames);
4081 XMLNode& after = al->get_state ();
4082 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4087 /* redirect automation */
4089 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4090 for (ProcessorList::iterator i = _processors.begin (); i != _processors.end (); ++i) {
4092 set<Evoral::Parameter> parameters = (*i)->what_can_be_automated();
4094 for (set<Evoral::Parameter>::const_iterator p = parameters.begin (); p != parameters.end (); ++p) {
4095 boost::shared_ptr<AutomationControl> ac = (*i)->automation_control (*p);
4097 boost::shared_ptr<AutomationList> al = ac->alist();
4098 XMLNode &before = al->get_state ();
4099 al->shift (pos, frames);
4100 XMLNode &after = al->get_state ();
4101 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
4109 Route::set_plugin_state_dir (boost::weak_ptr<Processor> p, const std::string& d)
4111 boost::shared_ptr<Processor> processor (p.lock ());
4112 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (processor);
4116 pi->set_state_dir (d);
4120 Route::save_as_template (const string& path, const string& name)
4122 std::string state_dir = path.substr (0, path.find_last_of ('.')); // strip template_suffix
4123 PBD::Unwinder<std::string> uw (_session._template_state_dir, state_dir);
4125 XMLNode& node (state (false));
4129 IO::set_name_in_state (*node.children().front(), name);
4131 tree.set_root (&node);
4133 /* return zero on success, non-zero otherwise */
4134 return !tree.write (path.c_str());
4139 Route::set_name (const string& str)
4141 if (str == name()) {
4145 string name = Route::ensure_track_or_route_name (str, _session);
4146 SessionObject::set_name (name);
4148 bool ret = (_input->set_name(name) && _output->set_name(name));
4151 /* rename the main outs. Leave other IO processors
4152 * with whatever name they already have, because its
4153 * just fine as it is (it will not contain the route
4154 * name if its a port insert, port send or port return).
4158 if (_main_outs->set_name (name)) {
4159 /* XXX returning false here is stupid because
4160 we already changed the route name.
4170 /** Set the name of a route in an XML description.
4171 * @param node XML <Route> node to set the name in.
4172 * @param name New name.
4175 Route::set_name_in_state (XMLNode& node, string const & name, bool rename_playlist)
4177 node.add_property (X_("name"), name);
4179 XMLNodeList children = node.children();
4180 for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
4182 if ((*i)->name() == X_("IO")) {
4184 IO::set_name_in_state (**i, name);
4186 } else if ((*i)->name() == X_("Processor")) {
4188 XMLProperty const * role = (*i)->property (X_("role"));
4189 if (role && role->value() == X_("Main")) {
4190 (*i)->add_property (X_("name"), name);
4193 } else if ((*i)->name() == X_("Diskstream")) {
4195 if (rename_playlist) {
4196 (*i)->add_property (X_("playlist"), string_compose ("%1.1", name).c_str());
4198 (*i)->add_property (X_("name"), name);
4204 boost::shared_ptr<Send>
4205 Route::internal_send_for (boost::shared_ptr<const Route> target) const
4207 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4209 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4210 boost::shared_ptr<InternalSend> send;
4212 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
4213 if (send->target_route() == target) {
4219 return boost::shared_ptr<Send>();
4223 Route::set_denormal_protection (bool yn)
4225 if (_denormal_protection != yn) {
4226 _denormal_protection = yn;
4227 denormal_protection_changed (); /* EMIT SIGNAL */
4232 Route::denormal_protection () const
4234 return _denormal_protection;
4238 Route::set_active (bool yn, void* src)
4240 if (_session.transport_rolling()) {
4244 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_route_active()) {
4245 _route_group->foreach_route (boost::bind (&Route::set_active, _1, yn, _route_group));
4249 if (_active != yn) {
4251 _input->set_active (yn);
4252 _output->set_active (yn);
4253 active_changed (); // EMIT SIGNAL
4254 _session.set_dirty ();
4258 boost::shared_ptr<Pannable>
4259 Route::pannable() const
4264 boost::shared_ptr<Panner>
4265 Route::panner() const
4268 return _main_outs->panner_shell()->panner();
4271 boost::shared_ptr<PannerShell>
4272 Route::panner_shell() const
4274 return _main_outs->panner_shell();
4277 boost::shared_ptr<GainControl>
4278 Route::gain_control() const
4280 return _gain_control;
4283 boost::shared_ptr<GainControl>
4284 Route::trim_control() const
4286 return _trim_control;
4289 boost::shared_ptr<PhaseControl>
4290 Route::phase_control() const
4292 return _phase_control;
4295 boost::shared_ptr<AutomationControl>
4296 Route::get_control (const Evoral::Parameter& param)
4298 /* either we own the control or .... */
4300 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
4304 /* maybe one of our processors does or ... */
4306 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
4307 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4308 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
4316 /* nobody does so we'll make a new one */
4318 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
4325 boost::shared_ptr<Processor>
4326 Route::nth_plugin (uint32_t n) const
4328 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4329 ProcessorList::const_iterator i;
4331 for (i = _processors.begin(); i != _processors.end(); ++i) {
4332 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
4339 return boost::shared_ptr<Processor> ();
4342 boost::shared_ptr<Processor>
4343 Route::nth_send (uint32_t n) const
4345 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4346 ProcessorList::const_iterator i;
4348 for (i = _processors.begin(); i != _processors.end(); ++i) {
4349 if (boost::dynamic_pointer_cast<Send> (*i)) {
4351 if ((*i)->name().find (_("Monitor")) == 0) {
4352 /* send to monitor section is not considered
4353 to be an accessible send.
4364 return boost::shared_ptr<Processor> ();
4368 Route::has_io_processor_named (const string& name)
4370 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4371 ProcessorList::iterator i;
4373 for (i = _processors.begin(); i != _processors.end(); ++i) {
4374 if (boost::dynamic_pointer_cast<Send> (*i) ||
4375 boost::dynamic_pointer_cast<PortInsert> (*i)) {
4376 if ((*i)->name() == name) {
4386 Route::set_processor_positions ()
4388 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4390 bool had_amp = false;
4391 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4392 (*i)->set_pre_fader (!had_amp);
4399 /** Called when there is a proposed change to the input port count */
4401 Route::input_port_count_changing (ChanCount to)
4403 list<pair<ChanCount, ChanCount> > c = try_configure_processors (to, 0);
4405 /* The processors cannot be configured with the new input arrangement, so
4411 /* The change is ok */
4415 /** Called when there is a proposed change to the output port count */
4417 Route::output_port_count_changing (ChanCount to)
4419 if (_strict_io && !_in_configure_processors) {
4422 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
4423 if (processor_out_streams.get(*t) > to.get(*t)) {
4427 /* The change is ok */
4432 Route::unknown_processors () const
4436 if (_session.get_disable_all_loaded_plugins ()) {
4437 // Do not list "missing plugins" if they are explicitly disabled
4441 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4442 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4443 if (boost::dynamic_pointer_cast<UnknownProcessor const> (*i)) {
4444 p.push_back ((*i)->name ());
4453 Route::update_port_latencies (PortSet& from, PortSet& to, bool playback, framecnt_t our_latency) const
4455 /* we assume that all our input ports feed all our output ports. its not
4456 universally true, but the alternative is way too corner-case to worry about.
4459 LatencyRange all_connections;
4462 all_connections.min = 0;
4463 all_connections.max = 0;
4465 all_connections.min = ~((pframes_t) 0);
4466 all_connections.max = 0;
4468 /* iterate over all "from" ports and determine the latency range for all of their
4469 connections to the "outside" (outside of this Route).
4472 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4476 p->get_connected_latency_range (range, playback);
4478 all_connections.min = min (all_connections.min, range.min);
4479 all_connections.max = max (all_connections.max, range.max);
4483 /* set the "from" port latencies to the max/min range of all their connections */
4485 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
4486 p->set_private_latency_range (all_connections, playback);
4489 /* set the ports "in the direction of the flow" to the same value as above plus our own signal latency */
4491 all_connections.min += our_latency;
4492 all_connections.max += our_latency;
4494 for (PortSet::iterator p = to.begin(); p != to.end(); ++p) {
4495 p->set_private_latency_range (all_connections, playback);
4498 return all_connections.max;
4502 Route::set_private_port_latencies (bool playback) const
4504 framecnt_t own_latency = 0;
4506 /* Processor list not protected by lock: MUST BE CALLED FROM PROCESS THREAD
4507 OR LATENCY CALLBACK.
4509 This is called (early) from the latency callback. It computes the REAL
4510 latency associated with each port and stores the result as the "private"
4511 latency of the port. A later call to Route::set_public_port_latencies()
4512 sets all ports to the same value to reflect the fact that we do latency
4513 compensation and so all signals are delayed by the same amount as they
4514 flow through ardour.
4517 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4518 if ((*i)->active ()) {
4519 own_latency += (*i)->signal_latency ();
4524 /* playback: propagate latency from "outside the route" to outputs to inputs */
4525 return update_port_latencies (_output->ports (), _input->ports (), true, own_latency);
4527 /* capture: propagate latency from "outside the route" to inputs to outputs */
4528 return update_port_latencies (_input->ports (), _output->ports (), false, own_latency);
4533 Route::set_public_port_latencies (framecnt_t value, bool playback) const
4535 /* this is called to set the JACK-visible port latencies, which take
4536 latency compensation into account.
4545 const PortSet& ports (_input->ports());
4546 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4547 p->set_public_latency_range (range, playback);
4552 const PortSet& ports (_output->ports());
4553 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
4554 p->set_public_latency_range (range, playback);
4559 /** Put the invisible processors in the right place in _processors.
4560 * Must be called with a writer lock on _processor_lock held.
4563 __attribute__((annotate("realtime")))
4566 Route::setup_invisible_processors ()
4569 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
4570 assert (!lm.locked ());
4574 /* too early to be doing this stuff */
4578 /* we'll build this new list here and then use it
4580 * TODO put the ProcessorList is on the stack for RT-safety.
4583 ProcessorList new_processors;
4585 /* find visible processors */
4587 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4588 if ((*i)->display_to_user ()) {
4589 new_processors.push_back (*i);
4595 ProcessorList::iterator amp = find (new_processors.begin(), new_processors.end(), _amp);
4597 if (amp == new_processors.end ()) {
4598 error << string_compose (_("Amp/Fader on Route '%1' went AWOL. Re-added."), name()) << endmsg;
4599 new_processors.push_front (_amp);
4600 amp = find (new_processors.begin(), new_processors.end(), _amp);
4603 /* and the processor after the amp */
4605 ProcessorList::iterator after_amp = amp;
4611 switch (_meter_point) {
4613 assert (!_meter->display_to_user ());
4614 new_processors.push_front (_meter);
4617 assert (!_meter->display_to_user ());
4618 new_processors.insert (amp, _meter);
4620 case MeterPostFader:
4621 /* do nothing here */
4624 /* do nothing here */
4627 /* the meter is visible, so we don't touch it here */
4634 assert (_main_outs);
4635 assert (!_main_outs->display_to_user ());
4636 new_processors.push_back (_main_outs);
4638 /* iterator for the main outs */
4640 ProcessorList::iterator main = new_processors.end();
4643 /* OUTPUT METERING */
4645 if (_meter && (_meter_point == MeterOutput || _meter_point == MeterPostFader)) {
4646 assert (!_meter->display_to_user ());
4648 /* add the processor just before or just after the main outs */
4650 ProcessorList::iterator meter_point = main;
4652 if (_meter_point == MeterOutput) {
4655 new_processors.insert (meter_point, _meter);
4660 if (_monitor_send && !is_monitor ()) {
4661 assert (!_monitor_send->display_to_user ());
4662 switch (Config->get_listen_position ()) {
4663 case PreFaderListen:
4664 switch (Config->get_pfl_position ()) {
4665 case PFLFromBeforeProcessors:
4666 new_processors.push_front (_monitor_send);
4668 case PFLFromAfterProcessors:
4669 new_processors.insert (amp, _monitor_send);
4672 _monitor_send->set_can_pan (false);
4674 case AfterFaderListen:
4675 switch (Config->get_afl_position ()) {
4676 case AFLFromBeforeProcessors:
4677 new_processors.insert (after_amp, _monitor_send);
4679 case AFLFromAfterProcessors:
4680 new_processors.insert (new_processors.end(), _monitor_send);
4683 _monitor_send->set_can_pan (true);
4688 #if 0 // not used - just yet
4689 if (!is_master() && !is_monitor() && !is_auditioner()) {
4690 new_processors.push_front (_delayline);
4694 /* MONITOR CONTROL */
4696 if (_monitor_control && is_monitor ()) {
4697 assert (!_monitor_control->display_to_user ());
4698 new_processors.insert (amp, _monitor_control);
4701 /* INTERNAL RETURN */
4703 /* doing this here means that any monitor control will come just after
4708 assert (!_intreturn->display_to_user ());
4709 new_processors.push_front (_intreturn);
4712 if (_trim && _trim->active()) {
4713 assert (!_trim->display_to_user ());
4714 new_processors.push_front (_trim);
4716 /* EXPORT PROCESSOR */
4718 if (_capturing_processor) {
4719 assert (!_capturing_processor->display_to_user ());
4720 new_processors.push_front (_capturing_processor);
4723 _processors = new_processors;
4725 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4726 if (!(*i)->display_to_user () && !(*i)->active () && (*i) != _monitor_send) {
4731 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: setup_invisible_processors\n", _name));
4732 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4733 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1\n", (*i)->name ()));
4740 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
4741 Glib::Threads::RWLock::ReaderLock lp (_processor_lock);
4745 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4746 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*i);
4753 /** If the meter point is `Custom', make a note of where the meter is.
4754 * This is so that if the meter point is subsequently set to something else,
4755 * and then back to custom, we can put the meter back where it was last time
4756 * custom was enabled.
4758 * Must be called with the _processor_lock held.
4761 Route::maybe_note_meter_position ()
4763 if (_meter_point != MeterCustom) {
4767 _custom_meter_position_noted = true;
4768 /* custom meter points range from after trim to before panner/main_outs
4769 * this is a limitation by the current processor UI
4771 bool seen_trim = false;
4772 _processor_after_last_custom_meter.reset();
4773 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4774 if ((*i) == _trim) {
4777 if ((*i) == _main_outs) {
4778 _processor_after_last_custom_meter = *i;
4781 if (boost::dynamic_pointer_cast<PeakMeter> (*i)) {
4783 _processor_after_last_custom_meter = _trim;
4785 ProcessorList::iterator j = i;
4787 assert(j != _processors.end ()); // main_outs should be before
4788 _processor_after_last_custom_meter = *j;
4793 assert(_processor_after_last_custom_meter.lock());
4796 boost::shared_ptr<Processor>
4797 Route::processor_by_id (PBD::ID id) const
4799 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4800 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4801 if ((*i)->id() == id) {
4806 return boost::shared_ptr<Processor> ();
4809 /** @return the monitoring state, or in other words what data we are pushing
4810 * into the route (data from the inputs, data from disk or silence)
4813 Route::monitoring_state () const
4815 return MonitoringInput;
4818 /** @return what we should be metering; either the data coming from the input
4819 * IO or the data that is flowing through the route.
4822 Route::metering_state () const
4824 return MeteringRoute;
4828 Route::has_external_redirects () const
4830 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4832 /* ignore inactive processors and obviously ignore the main
4833 * outs since everything has them and we don't care.
4836 if ((*i)->active() && (*i) != _main_outs && (*i)->does_routing()) {
4844 boost::shared_ptr<Processor>
4845 Route::the_instrument () const
4847 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4848 return the_instrument_unlocked ();
4851 boost::shared_ptr<Processor>
4852 Route::the_instrument_unlocked () const
4854 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4855 boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert>(*i);
4856 if (pi && pi->plugin ()->get_info ()->is_instrument ()) {
4860 return boost::shared_ptr<Processor>();
4866 Route::non_realtime_locate (framepos_t pos)
4869 _pannable->transport_located (pos);
4872 if (_delayline.get()) {
4873 _delayline.get()->flush();
4877 //Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
4878 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4880 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4881 (*i)->transport_located (pos);
4884 _roll_delay = _initial_delay;
4888 Route::fill_buffers_with_input (BufferSet& bufs, boost::shared_ptr<IO> io, pframes_t nframes)
4895 * We don't currently mix MIDI input together, so we don't need the
4896 * complex logic of the audio case.
4899 n_buffers = bufs.count().n_midi ();
4901 for (i = 0; i < n_buffers; ++i) {
4903 boost::shared_ptr<MidiPort> source_port = io->midi (i);
4904 MidiBuffer& buf (bufs.get_midi (i));
4907 buf.copy (source_port->get_midi_buffer(nframes));
4909 buf.silence (nframes);
4915 n_buffers = bufs.count().n_audio();
4917 size_t n_ports = io->n_ports().n_audio();
4918 float scaling = 1.0f;
4920 if (n_ports > n_buffers) {
4921 scaling = ((float) n_buffers) / n_ports;
4924 for (i = 0; i < n_ports; ++i) {
4926 /* if there are more ports than buffers, map them onto buffers
4927 * in a round-robin fashion
4930 boost::shared_ptr<AudioPort> source_port = io->audio (i);
4931 AudioBuffer& buf (bufs.get_audio (i%n_buffers));
4934 if (i < n_buffers) {
4936 /* first time through just copy a channel into
4940 buf.read_from (source_port->get_audio_buffer (nframes), nframes);
4942 if (scaling != 1.0f) {
4943 buf.apply_gain (scaling, nframes);
4948 /* on subsequent times around, merge data from
4949 * the port with what is already there
4952 if (scaling != 1.0f) {
4953 buf.accumulate_with_gain_from (source_port->get_audio_buffer (nframes), nframes, 0, scaling);
4955 buf.accumulate_from (source_port->get_audio_buffer (nframes), nframes);
4960 /* silence any remaining buffers */
4962 for (; i < n_buffers; ++i) {
4963 AudioBuffer& buf (bufs.get_audio (i));
4964 buf.silence (nframes);
4967 /* establish the initial setup of the buffer set, reflecting what was
4968 copied into it. unless, of course, we are the auditioner, in which
4969 case nothing was fed into it from the inputs at all.
4972 if (!is_auditioner()) {
4973 bufs.set_count (io->n_ports());
4977 boost::shared_ptr<AutomationControl>
4978 Route::pan_azimuth_control() const
4981 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
4983 return boost::shared_ptr<AutomationControl>();
4985 const uint32_t port_channel_post_pan = 2; // gtk2_ardour/mixbus_ports.h
4986 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_pan)));
4988 if (!_pannable || !panner()) {
4989 return boost::shared_ptr<AutomationControl>();
4991 return _pannable->pan_azimuth_control;
4995 boost::shared_ptr<AutomationControl>
4996 Route::pan_elevation_control() const
4998 if (Profile->get_mixbus() || !_pannable || !panner()) {
4999 return boost::shared_ptr<AutomationControl>();
5002 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5004 if (c.find (PanElevationAutomation) != c.end()) {
5005 return _pannable->pan_elevation_control;
5007 return boost::shared_ptr<AutomationControl>();
5010 boost::shared_ptr<AutomationControl>
5011 Route::pan_width_control() const
5013 if (Profile->get_mixbus() || !_pannable || !panner()) {
5014 return boost::shared_ptr<AutomationControl>();
5017 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5019 if (c.find (PanWidthAutomation) != c.end()) {
5020 return _pannable->pan_width_control;
5022 return boost::shared_ptr<AutomationControl>();
5025 boost::shared_ptr<AutomationControl>
5026 Route::pan_frontback_control() const
5028 if (Profile->get_mixbus() || !_pannable || !panner()) {
5029 return boost::shared_ptr<AutomationControl>();
5032 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5034 if (c.find (PanFrontBackAutomation) != c.end()) {
5035 return _pannable->pan_frontback_control;
5037 return boost::shared_ptr<AutomationControl>();
5040 boost::shared_ptr<AutomationControl>
5041 Route::pan_lfe_control() const
5043 if (Profile->get_mixbus() || !_pannable || !panner()) {
5044 return boost::shared_ptr<AutomationControl>();
5047 set<Evoral::Parameter> c = panner()->what_can_be_automated ();
5049 if (c.find (PanLFEAutomation) != c.end()) {
5050 return _pannable->pan_lfe_control;
5052 return boost::shared_ptr<AutomationControl>();
5057 Route::eq_band_cnt () const
5059 if (Profile->get_mixbus()) {
5062 /* Ardour has no well-known EQ object */
5067 boost::shared_ptr<AutomationControl>
5068 Route::eq_gain_controllable (uint32_t band) const
5071 boost::shared_ptr<PluginInsert> eq = ch_eq();
5074 return boost::shared_ptr<AutomationControl>();
5077 uint32_t port_number;
5080 if (is_master() || mixbus()) {
5087 if (is_master() || mixbus()) {
5094 if (is_master() || mixbus()) {
5101 return boost::shared_ptr<AutomationControl>();
5104 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5106 return boost::shared_ptr<AutomationControl>();
5109 boost::shared_ptr<AutomationControl>
5110 Route::eq_freq_controllable (uint32_t band) const
5114 if (mixbus() || is_master()) {
5115 /* no frequency controls for mixbusses or master */
5116 return boost::shared_ptr<AutomationControl>();
5119 boost::shared_ptr<PluginInsert> eq = ch_eq();
5122 return boost::shared_ptr<AutomationControl>();
5125 uint32_t port_number;
5137 return boost::shared_ptr<AutomationControl>();
5140 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_number)));
5142 return boost::shared_ptr<AutomationControl>();
5146 boost::shared_ptr<AutomationControl>
5147 Route::eq_q_controllable (uint32_t band) const
5149 return boost::shared_ptr<AutomationControl>();
5152 boost::shared_ptr<AutomationControl>
5153 Route::eq_shape_controllable (uint32_t band) const
5155 return boost::shared_ptr<AutomationControl>();
5158 boost::shared_ptr<AutomationControl>
5159 Route::eq_enable_controllable () const
5162 boost::shared_ptr<PluginInsert> eq = ch_eq();
5165 return boost::shared_ptr<AutomationControl>();
5168 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5170 return boost::shared_ptr<AutomationControl>();
5174 boost::shared_ptr<AutomationControl>
5175 Route::eq_hpf_controllable () const
5178 boost::shared_ptr<PluginInsert> eq = ch_eq();
5181 return boost::shared_ptr<AutomationControl>();
5184 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (eq->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5186 return boost::shared_ptr<AutomationControl>();
5191 Route::eq_band_name (uint32_t band) const
5193 if (Profile->get_mixbus()) {
5209 boost::shared_ptr<AutomationControl>
5210 Route::comp_enable_controllable () const
5213 boost::shared_ptr<PluginInsert> comp = ch_comp();
5216 return boost::shared_ptr<AutomationControl>();
5219 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 1)));
5221 return boost::shared_ptr<AutomationControl>();
5224 boost::shared_ptr<AutomationControl>
5225 Route::comp_threshold_controllable () const
5228 boost::shared_ptr<PluginInsert> comp = ch_comp();
5231 return boost::shared_ptr<AutomationControl>();
5234 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 2)));
5237 return boost::shared_ptr<AutomationControl>();
5240 boost::shared_ptr<AutomationControl>
5241 Route::comp_speed_controllable () const
5244 boost::shared_ptr<PluginInsert> comp = ch_comp();
5247 return boost::shared_ptr<AutomationControl>();
5250 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 3)));
5252 return boost::shared_ptr<AutomationControl>();
5255 boost::shared_ptr<AutomationControl>
5256 Route::comp_mode_controllable () const
5259 boost::shared_ptr<PluginInsert> comp = ch_comp();
5262 return boost::shared_ptr<AutomationControl>();
5265 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 4)));
5267 return boost::shared_ptr<AutomationControl>();
5270 boost::shared_ptr<AutomationControl>
5271 Route::comp_makeup_controllable () const
5274 boost::shared_ptr<PluginInsert> comp = ch_comp();
5277 return boost::shared_ptr<AutomationControl>();
5280 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 5)));
5282 return boost::shared_ptr<AutomationControl>();
5285 boost::shared_ptr<AutomationControl>
5286 Route::comp_redux_controllable () const
5289 boost::shared_ptr<PluginInsert> comp = ch_comp();
5292 return boost::shared_ptr<AutomationControl>();
5295 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (comp->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, 6)));
5297 return boost::shared_ptr<AutomationControl>();
5302 Route::comp_mode_name (uint32_t mode) const
5307 return _("Leveler");
5309 return _("Compressor");
5311 return _("Limiter");
5313 return mixbus() ? _("Sidechain") : _("Limiter");
5323 Route::comp_speed_name (uint32_t mode) const
5341 boost::shared_ptr<AutomationControl>
5342 Route::send_level_controllable (uint32_t n) const
5345 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5347 return boost::shared_ptr<AutomationControl>();
5352 return boost::shared_ptr<AutomationControl>();
5355 const uint32_t port_id = port_channel_post_aux1_level + (2*n); // gtk2_ardour/mixbus_ports.h
5356 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5358 boost::shared_ptr<Send> s = boost::dynamic_pointer_cast<Send>(nth_send (n));
5360 return boost::shared_ptr<AutomationControl>();
5362 return s->gain_control ();
5366 boost::shared_ptr<AutomationControl>
5367 Route::send_enable_controllable (uint32_t n) const
5370 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5372 return boost::shared_ptr<AutomationControl>();
5377 return boost::shared_ptr<AutomationControl>();
5380 const uint32_t port_id = port_channel_post_aux1_asgn + (2*n); // gtk2_ardour/mixbus_ports.h
5381 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_id)));
5383 /* although Ardour sends have enable/disable as part of the Processor
5384 API, it is not exposed as a controllable.
5386 XXX: we should fix this.
5388 return boost::shared_ptr<AutomationControl>();
5393 Route::send_name (uint32_t n) const
5399 boost::shared_ptr<Route> r = _session.get_mixbus (n);
5403 boost::shared_ptr<Processor> p = nth_send (n);
5412 boost::shared_ptr<AutomationControl>
5413 Route::master_send_enable_controllable () const
5416 boost::shared_ptr<ARDOUR::PluginInsert> plug = ch_post();
5418 return boost::shared_ptr<AutomationControl>();
5420 return boost::dynamic_pointer_cast<ARDOUR::AutomationControl> (plug->control (Evoral::Parameter (ARDOUR::PluginAutomation, 0, port_channel_post_mstr_assign)));
5422 return boost::shared_ptr<AutomationControl>();
5427 Route::slaved_to (boost::shared_ptr<VCA> vca) const
5429 if (!vca || !_gain_control) {
5433 return _gain_control->slaved_to (vca->gain_control());
5437 Route::vca_assign (boost::shared_ptr<VCA> vca)
5439 _gain_control->add_master (vca->gain_control());
5440 _solo_control->add_master (vca->solo_control());
5441 // _mute_control->add_master (vca->mute_control());
5445 Route::vca_unassign (boost::shared_ptr<VCA> vca)
5448 /* unassign from all */
5449 _gain_control->clear_masters ();
5450 _solo_control->clear_masters ();
5451 //_mute_control->clear_masters ();
5453 _gain_control->remove_master (vca->gain_control());
5454 _solo_control->remove_master (vca->solo_control());
5455 //_mute_control->remove_master (vca->mute_control());
5460 Route::muted_by_others_soloing () const
5462 // This method is only used by route_ui for display state.
5463 // The DSP version is MuteMaster::muted_by_others_at()
5465 if (!can_be_muted_by_others ()) {
5469 return _session.soloing() && !_solo_control->soloed() && !_solo_isolate_control->solo_isolated();
5473 Route::muted_by_others () const
5475 // This method is only used by route_ui for display state.
5476 // The DSP version is MuteMaster::muted_by_others_at()
5478 if (!can_be_muted_by_others()) {
5482 return _mute_master->muted_by_others();
5486 Route::clear_all_solo_state ()
5488 double v = _solo_safe_control->get_value ();
5490 _solo_control->clear_all_solo_state ();
5493 _solo_safe_control->set_value (v, Controllable::NoGroup);