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/boost_debug.h"
38 #include "ardour/amp.h"
39 #include "ardour/audio_buffer.h"
40 #include "ardour/audioengine.h"
41 #include "ardour/buffer.h"
42 #include "ardour/buffer_set.h"
43 #include "ardour/capturing_processor.h"
44 #include "ardour/debug.h"
45 #include "ardour/delivery.h"
46 #include "ardour/internal_return.h"
47 #include "ardour/internal_send.h"
48 #include "ardour/meter.h"
49 #include "ardour/monitor_processor.h"
50 #include "ardour/pannable.h"
51 #include "ardour/panner_shell.h"
52 #include "ardour/plugin_insert.h"
53 #include "ardour/port.h"
54 #include "ardour/port_insert.h"
55 #include "ardour/processor.h"
56 #include "ardour/route.h"
57 #include "ardour/route_group.h"
58 #include "ardour/send.h"
59 #include "ardour/session.h"
60 #include "ardour/unknown_processor.h"
61 #include "ardour/utils.h"
66 using namespace ARDOUR;
69 PBD::Signal1<void,RouteSortOrderKey> Route::SyncOrderKeys;
70 PBD::Signal0<void> Route::RemoteControlIDChange;
72 Route::Route (Session& sess, string name, Flag flg, DataType default_type)
73 : SessionObject (sess, name)
75 , GraphNode (sess._process_graph)
81 , _pending_declick (true)
82 , _meter_point (MeterPostFader)
84 , _soloed_by_others_upstream (0)
85 , _soloed_by_others_downstream (0)
87 , _denormal_protection (false)
90 , _declickable (false)
91 , _mute_master (new MuteMaster (sess, name))
92 , _have_internal_generator (false)
94 , _default_type (default_type)
95 , _remote_control_id (0)
96 , _in_configure_processors (false)
97 , _custom_meter_position_noted (false)
98 , _last_custom_meter_was_at_end (false)
100 processor_max_streams.reset();
106 /* add standard controls */
108 _solo_control.reset (new SoloControllable (X_("solo"), shared_from_this ()));
109 _mute_control.reset (new MuteControllable (X_("mute"), shared_from_this ()));
111 _solo_control->set_flags (Controllable::Flag (_solo_control->flags() | Controllable::Toggle));
112 _mute_control->set_flags (Controllable::Flag (_mute_control->flags() | Controllable::Toggle));
114 add_control (_solo_control);
115 add_control (_mute_control);
119 if (!(_flags & Route::MonitorOut)) {
120 _pannable.reset (new Pannable (_session));
123 /* input and output objects */
125 _input.reset (new IO (_session, _name, IO::Input, _default_type));
126 _output.reset (new IO (_session, _name, IO::Output, _default_type));
128 _input->changed.connect_same_thread (*this, boost::bind (&Route::input_change_handler, this, _1, _2));
129 _input->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::input_port_count_changing, this, _1));
131 _output->changed.connect_same_thread (*this, boost::bind (&Route::output_change_handler, this, _1, _2));
133 /* add amp processor */
135 _amp.reset (new Amp (_session));
136 add_processor (_amp, PostFader);
138 /* create standard processors: meter, main outs, monitor out;
139 they will be added to _processors by setup_invisible_processors ()
142 _meter.reset (new PeakMeter (_session));
143 _meter->set_display_to_user (false);
146 _main_outs.reset (new Delivery (_session, _output, _pannable, _mute_master, _name, Delivery::Main));
147 _main_outs->activate ();
150 /* where we listen to tracks */
151 _intreturn.reset (new InternalReturn (_session));
152 _intreturn->activate ();
154 /* the thing that provides proper control over a control/monitor/listen bus
155 (such as per-channel cut, dim, solo, invert, etc).
157 _monitor_control.reset (new MonitorProcessor (_session));
158 _monitor_control->activate ();
161 if (is_master() || is_monitor() || is_hidden()) {
162 _mute_master->set_solo_ignore (true);
165 /* now that we have _meter, its safe to connect to this */
167 Metering::Meter.connect_same_thread (*this, (boost::bind (&Route::meter, this)));
170 /* run a configure so that the invisible processors get set up */
171 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
172 configure_processors (0);
180 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
182 /* do this early so that we don't get incoming signals as we are going through destruction
187 /* don't use clear_processors here, as it depends on the session which may
188 be half-destroyed by now
191 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
192 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
193 (*i)->drop_references ();
196 _processors.clear ();
200 Route::set_remote_control_id (uint32_t id, bool notify_class_listeners)
202 if (Config->get_remote_model() != UserOrdered) {
207 error << _("Remote Control ID's start at one, not zero") << endmsg;
211 /* force IDs for master/monitor busses and prevent
212 any other route from accidentally getting these IDs
213 (i.e. legacy sessions)
216 if (is_master() && id != MasterBusRemoteControlID) {
217 id = MasterBusRemoteControlID;
220 if (is_monitor() && id != MonitorBusRemoteControlID) {
221 id = MonitorBusRemoteControlID;
224 /* don't allow it to collide */
226 if (!is_master () && !is_monitor() &&
227 (id == MasterBusRemoteControlID || id == MonitorBusRemoteControlID)) {
228 id += MonitorBusRemoteControlID;
231 if (id != remote_control_id()) {
232 _remote_control_id = id;
233 RemoteControlIDChanged ();
235 if (notify_class_listeners) {
236 RemoteControlIDChange ();
242 Route::remote_control_id() const
245 return MasterBusRemoteControlID;
249 return MonitorBusRemoteControlID;
252 return _remote_control_id;
256 Route::has_order_key (RouteSortOrderKey key) const
258 return (order_keys.find (key) != order_keys.end());
262 Route::order_key (RouteSortOrderKey key) const
264 OrderKeys::const_iterator i = order_keys.find (key);
266 if (i == order_keys.end()) {
274 Route::sync_order_keys (RouteSortOrderKey base)
276 /* this is called after changes to 1 or more route order keys have been
277 * made, and we want to sync up.
280 OrderKeys::iterator i = order_keys.find (base);
282 if (i == order_keys.end()) {
286 for (OrderKeys::iterator k = order_keys.begin(); k != order_keys.end(); ++k) {
288 if (k->first != base) {
289 DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1 set key for %2 to %3 from %4\n",
291 enum_2_string (k->first),
293 enum_2_string (base)));
295 k->second = i->second;
301 Route::set_remote_control_id_from_order_key (RouteSortOrderKey key, uint32_t rid)
303 if (is_master() || is_monitor() || is_hidden()) {
304 /* hard-coded remote IDs, or no remote ID */
308 if (_remote_control_id != rid) {
309 DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1: set edit-based RID to %2\n", name(), rid));
310 _remote_control_id = rid;
311 RemoteControlIDChanged (); /* EMIT SIGNAL (per-route) */
314 /* don't emit the class-level RID signal RemoteControlIDChange here,
315 leave that to the entity that changed the order key, so that we
316 don't get lots of emissions for no good reasons (e.g. when changing
317 all route order keys).
319 See Session::sync_remote_id_from_order_keys() for the (primary|only)
320 spot where that is emitted.
325 Route::set_order_key (RouteSortOrderKey key, uint32_t n)
327 OrderKeys::iterator i = order_keys.find (key);
329 if (i != order_keys.end() && i->second == n) {
335 DEBUG_TRACE (DEBUG::OrderKeys, string_compose ("%1 order key %2 set to %3\n",
336 name(), enum_2_string (key), order_key (key)));
338 _session.set_dirty ();
342 Route::ensure_track_or_route_name(string name, Session &session)
344 string newname = name;
346 while (!session.io_name_is_legal (newname)) {
347 newname = bump_name_once (newname, '.');
355 Route::inc_gain (gain_t fraction, void *src)
357 _amp->inc_gain (fraction, src);
361 Route::set_gain (gain_t val, void *src)
363 if (src != 0 && _route_group && src != _route_group && _route_group->is_active() && _route_group->is_gain()) {
365 if (_route_group->is_relative()) {
367 gain_t usable_gain = _amp->gain();
368 if (usable_gain < 0.000001f) {
369 usable_gain = 0.000001f;
373 if (delta < 0.000001f) {
377 delta -= usable_gain;
382 gain_t factor = delta / usable_gain;
385 factor = _route_group->get_max_factor(factor);
386 if (factor == 0.0f) {
387 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
391 factor = _route_group->get_min_factor(factor);
392 if (factor == 0.0f) {
393 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
398 _route_group->foreach_route (boost::bind (&Route::inc_gain, _1, factor, _route_group));
402 _route_group->foreach_route (boost::bind (&Route::set_gain, _1, val, _route_group));
408 if (val == _amp->gain()) {
412 _amp->set_gain (val, src);
416 Route::maybe_declick (BufferSet&, framecnt_t, int)
418 /* this is the "bus" implementation and they never declick.
423 /** Process this route for one (sub) cycle (process thread)
425 * @param bufs Scratch buffers to use for the signal path
426 * @param start_frame Initial transport frame
427 * @param end_frame Final transport frame
428 * @param nframes Number of frames to output (to ports)
430 * Note that (end_frame - start_frame) may not be equal to nframes when the
431 * transport speed isn't 1.0 (eg varispeed).
434 Route::process_output_buffers (BufferSet& bufs,
435 framepos_t start_frame, framepos_t end_frame, pframes_t nframes,
436 int declick, bool gain_automation_ok)
438 bufs.set_is_silent (false);
440 /* figure out if we're going to use gain automation */
441 if (gain_automation_ok) {
442 _amp->set_gain_automation_buffer (_session.gain_automation_buffer ());
443 _amp->setup_gain_automation (start_frame, end_frame, nframes);
445 _amp->apply_gain_automation (false);
448 /* Tell main outs what to do about monitoring. We do this so that
449 on a transition between monitoring states we get a de-clicking gain
450 change in the _main_outs delivery.
452 _main_outs->no_outs_cuz_we_no_monitor (monitoring_state () == MonitoringSilence);
455 /* -------------------------------------------------------------------------------------------
456 GLOBAL DECLICK (for transport changes etc.)
457 ----------------------------------------------------------------------------------------- */
459 maybe_declick (bufs, nframes, declick);
460 _pending_declick = 0;
462 /* -------------------------------------------------------------------------------------------
463 DENORMAL CONTROL/PHASE INVERT
464 ----------------------------------------------------------------------------------------- */
466 if (_phase_invert.any ()) {
470 if (_denormal_protection || Config->get_denormal_protection()) {
472 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
473 Sample* const sp = i->data();
475 if (_phase_invert[chn]) {
476 for (pframes_t nx = 0; nx < nframes; ++nx) {
481 for (pframes_t nx = 0; nx < nframes; ++nx) {
489 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
490 Sample* const sp = i->data();
492 if (_phase_invert[chn]) {
493 for (pframes_t nx = 0; nx < nframes; ++nx) {
502 if (_denormal_protection || Config->get_denormal_protection()) {
504 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
505 Sample* const sp = i->data();
506 for (pframes_t nx = 0; nx < nframes; ++nx) {
514 /* -------------------------------------------------------------------------------------------
516 ----------------------------------------------------------------------------------------- */
518 /* set this to be true if the meter will already have been ::run() earlier */
519 bool const meter_already_run = metering_state() == MeteringInput;
521 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
523 if (meter_already_run && boost::dynamic_pointer_cast<PeakMeter> (*i)) {
524 /* don't ::run() the meter, otherwise it will have its previous peak corrupted */
529 /* if it has any inputs, make sure they match */
530 if (boost::dynamic_pointer_cast<UnknownProcessor> (*i) == 0 && (*i)->input_streams() != ChanCount::ZERO) {
531 if (bufs.count() != (*i)->input_streams()) {
533 DEBUG::Processors, string_compose (
534 "%1 bufs = %2 input for %3 = %4\n",
535 _name, bufs.count(), (*i)->name(), (*i)->input_streams()
543 /* should we NOT run plugins here if the route is inactive?
544 do we catch route != active somewhere higher?
547 (*i)->run (bufs, start_frame, end_frame, nframes, *i != _processors.back());
548 bufs.set_count ((*i)->output_streams());
553 Route::n_process_buffers ()
555 return max (_input->n_ports(), processor_max_streams);
559 Route::passthru (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
561 BufferSet& bufs = _session.get_scratch_buffers (n_process_buffers());
565 assert (bufs.available() >= input_streams());
567 if (_input->n_ports() == ChanCount::ZERO) {
568 silence_unlocked (nframes);
571 bufs.set_count (input_streams());
573 if (is_monitor() && _session.listening() && !_session.is_auditioning()) {
575 /* control/monitor bus ignores input ports when something is
576 feeding the listen "stream". data will "arrive" into the
577 route from the intreturn processor element.
579 bufs.silence (nframes, 0);
583 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
585 BufferSet::iterator o = bufs.begin(*t);
586 PortSet& ports (_input->ports());
588 for (PortSet::iterator i = ports.begin(*t); i != ports.end(*t); ++i, ++o) {
589 o->read_from (i->get_buffer(nframes), nframes);
594 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
595 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, true);
599 Route::passthru_silence (framepos_t start_frame, framepos_t end_frame, pframes_t nframes, int declick)
601 BufferSet& bufs (_session.get_silent_buffers (n_process_buffers()));
603 bufs.set_count (_input->n_ports());
604 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
605 process_output_buffers (bufs, start_frame, end_frame, nframes, declick, false);
609 Route::set_listen (bool yn, void* src)
615 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_solo()) {
616 _route_group->foreach_route (boost::bind (&Route::set_listen, _1, yn, _route_group));
621 if (yn != _monitor_send->active()) {
623 _monitor_send->activate ();
624 _mute_master->set_soloed (true);
626 _monitor_send->deactivate ();
627 _mute_master->set_soloed (false);
630 listen_changed (src); /* EMIT SIGNAL */
636 Route::listening_via_monitor () const
639 return _monitor_send->active ();
646 Route::set_solo_safe (bool yn, void *src)
648 if (_solo_safe != yn) {
650 solo_safe_changed (src);
655 Route::solo_safe() const
661 Route::set_solo (bool yn, void *src)
667 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_solo()) {
668 _route_group->foreach_route (boost::bind (&Route::set_solo, _1, yn, _route_group));
672 if (self_soloed() != yn) {
674 set_mute_master_solo ();
675 solo_changed (true, src); /* EMIT SIGNAL */
676 _solo_control->Changed (); /* EMIT SIGNAL */
681 Route::set_self_solo (bool yn)
687 Route::mod_solo_by_others_upstream (int32_t delta)
693 uint32_t old_sbu = _soloed_by_others_upstream;
696 if (_soloed_by_others_upstream >= (uint32_t) abs (delta)) {
697 _soloed_by_others_upstream += delta;
699 _soloed_by_others_upstream = 0;
702 _soloed_by_others_upstream += delta;
705 DEBUG_TRACE (DEBUG::Solo, string_compose (
706 "%1 SbU delta %2 = %3 old = %4 sbd %5 ss %6 exclusive %7\n",
707 name(), delta, _soloed_by_others_upstream, old_sbu,
708 _soloed_by_others_downstream, _self_solo, Config->get_exclusive_solo()));
710 /* push the inverse solo change to everything that feeds us.
712 This is important for solo-within-group. When we solo 1 track out of N that
713 feed a bus, that track will cause mod_solo_by_upstream (+1) to be called
714 on the bus. The bus then needs to call mod_solo_by_downstream (-1) on all
715 tracks that feed it. This will silence them if they were audible because
716 of a bus solo, but the newly soloed track will still be audible (because
719 but .. do this only when we are being told to solo-by-upstream (i.e delta = +1),
723 if ((_self_solo || _soloed_by_others_downstream) &&
724 ((old_sbu == 0 && _soloed_by_others_upstream > 0) ||
725 (old_sbu > 0 && _soloed_by_others_upstream == 0))) {
727 if (delta > 0 || !Config->get_exclusive_solo()) {
728 DEBUG_TRACE (DEBUG::Solo, "\t ... INVERT push\n");
729 for (FedBy::iterator i = _fed_by.begin(); i != _fed_by.end(); ++i) {
730 boost::shared_ptr<Route> sr = i->r.lock();
732 sr->mod_solo_by_others_downstream (-delta);
738 set_mute_master_solo ();
739 solo_changed (false, this);
743 Route::mod_solo_by_others_downstream (int32_t delta)
750 if (_soloed_by_others_downstream >= (uint32_t) abs (delta)) {
751 _soloed_by_others_downstream += delta;
753 _soloed_by_others_downstream = 0;
756 _soloed_by_others_downstream += delta;
759 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 SbD delta %2 = %3\n", name(), delta, _soloed_by_others_downstream));
761 set_mute_master_solo ();
762 solo_changed (false, this);
766 Route::set_mute_master_solo ()
768 _mute_master->set_soloed (self_soloed() || soloed_by_others_downstream() || soloed_by_others_upstream());
772 Route::set_solo_isolated (bool yn, void *src)
774 if (is_master() || is_monitor() || is_hidden()) {
778 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_solo()) {
779 _route_group->foreach_route (boost::bind (&Route::set_solo_isolated, _1, yn, _route_group));
783 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
785 boost::shared_ptr<RouteList> routes = _session.get_routes ();
786 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
788 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_hidden()) {
793 bool does_feed = direct_feeds_according_to_graph (*i, &sends_only); // we will recurse anyway, so don't use ::feeds()
795 if (does_feed && !sends_only) {
796 (*i)->set_solo_isolated (yn, (*i)->route_group());
800 /* XXX should we back-propagate as well? (April 2010: myself and chris goddard think not) */
802 bool changed = false;
805 if (_solo_isolated == 0) {
806 _mute_master->set_solo_ignore (true);
811 if (_solo_isolated > 0) {
813 if (_solo_isolated == 0) {
814 _mute_master->set_solo_ignore (false);
821 solo_isolated_changed (src);
826 Route::solo_isolated () const
828 return _solo_isolated > 0;
832 Route::set_mute_points (MuteMaster::MutePoint mp)
834 _mute_master->set_mute_points (mp);
835 mute_points_changed (); /* EMIT SIGNAL */
837 if (_mute_master->muted_by_self()) {
838 mute_changed (this); /* EMIT SIGNAL */
839 _mute_control->Changed (); /* EMIT SIGNAL */
844 Route::set_mute (bool yn, void *src)
846 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_mute()) {
847 _route_group->foreach_route (boost::bind (&Route::set_mute, _1, yn, _route_group));
852 _mute_master->set_muted_by_self (yn);
853 /* allow any derived classes to respond to the mute change
854 before anybody else knows about it.
857 /* tell everyone else */
858 mute_changed (src); /* EMIT SIGNAL */
859 _mute_control->Changed (); /* EMIT SIGNAL */
864 Route::muted () const
866 return _mute_master->muted_by_self();
871 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
873 cerr << name << " {" << endl;
874 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
875 p != procs.end(); ++p) {
876 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << " @ " << (*p) << endl;
882 /** Supposing that we want to insert a Processor at a given Placement, return
883 * the processor to add the new one before (or 0 to add at the end).
885 boost::shared_ptr<Processor>
886 Route::before_processor_for_placement (Placement p)
888 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
890 ProcessorList::iterator loc;
893 /* generic pre-fader: insert immediately before the amp */
894 loc = find (_processors.begin(), _processors.end(), _amp);
896 /* generic post-fader: insert right before the main outs */
897 loc = find (_processors.begin(), _processors.end(), _main_outs);
900 return loc != _processors.end() ? *loc : boost::shared_ptr<Processor> ();
903 /** Supposing that we want to insert a Processor at a given index, return
904 * the processor to add the new one before (or 0 to add at the end).
906 boost::shared_ptr<Processor>
907 Route::before_processor_for_index (int index)
910 return boost::shared_ptr<Processor> ();
913 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
915 ProcessorList::iterator i = _processors.begin ();
917 while (i != _processors.end() && j < index) {
918 if ((*i)->display_to_user()) {
925 return (i != _processors.end() ? *i : boost::shared_ptr<Processor> ());
928 /** Add a processor either pre- or post-fader
929 * @return 0 on success, non-0 on failure.
932 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err, bool activation_allowed)
934 return add_processor (processor, before_processor_for_placement (placement), err, activation_allowed);
938 /** Add a processor to a route such that it ends up with a given index into the visible processors.
939 * @param index Index to add the processor at, or -1 to add at the end of the list.
940 * @return 0 on success, non-0 on failure.
943 Route::add_processor_by_index (boost::shared_ptr<Processor> processor, int index, ProcessorStreams* err, bool activation_allowed)
945 return add_processor (processor, before_processor_for_index (index), err, activation_allowed);
948 /** Add a processor to the route.
949 * @param before An existing processor in the list, or 0; the new processor will be inserted immediately before it (or at the end).
950 * @return 0 on success, non-0 on failure.
953 Route::add_processor (boost::shared_ptr<Processor> processor, boost::shared_ptr<Processor> before, ProcessorStreams* err, bool activation_allowed)
955 assert (processor != _meter);
956 assert (processor != _main_outs);
958 DEBUG_TRACE (DEBUG::Processors, string_compose (
959 "%1 adding processor %2\n", name(), processor->name()));
961 if (!_session.engine().connected() || !processor) {
966 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
967 ProcessorState pstate (this);
969 boost::shared_ptr<PluginInsert> pi;
970 boost::shared_ptr<PortInsert> porti;
972 if (processor == _amp) {
973 /* Ensure that only one amp is in the list at any time */
974 ProcessorList::iterator check = find (_processors.begin(), _processors.end(), processor);
975 if (check != _processors.end()) {
976 if (before == _amp) {
977 /* Already in position; all is well */
980 _processors.erase (check);
985 assert (find (_processors.begin(), _processors.end(), processor) == _processors.end ());
987 ProcessorList::iterator loc;
989 /* inserting before a processor; find it */
990 loc = find (_processors.begin(), _processors.end(), before);
991 if (loc == _processors.end ()) {
996 /* inserting at end */
997 loc = _processors.end ();
1000 _processors.insert (loc, processor);
1002 // Set up processor list channels. This will set processor->[input|output]_streams(),
1003 // configure redirect ports properly, etc.
1006 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
1008 if (configure_processors_unlocked (err)) {
1010 configure_processors_unlocked (0); // it worked before we tried to add it ...
1015 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
1017 if (pi->has_no_inputs ()) {
1018 /* generator plugin */
1019 _have_internal_generator = true;
1024 if (activation_allowed) {
1025 processor->activate ();
1028 processor->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1030 _output->set_user_latency (0);
1033 reset_instrument_info ();
1034 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1035 set_processor_positions ();
1041 Route::add_processor_from_xml_2X (const XMLNode& node, int version)
1043 const XMLProperty *prop;
1046 boost::shared_ptr<Processor> processor;
1048 /* bit of a hack: get the `placement' property from the <Redirect> tag here
1049 so that we can add the processor in the right place (pre/post-fader)
1052 XMLNodeList const & children = node.children ();
1053 XMLNodeList::const_iterator i = children.begin ();
1055 while (i != children.end() && (*i)->name() != X_("Redirect")) {
1059 Placement placement = PreFader;
1061 if (i != children.end()) {
1062 if ((prop = (*i)->property (X_("placement"))) != 0) {
1063 placement = Placement (string_2_enum (prop->value(), placement));
1067 if (node.name() == "Insert") {
1069 if ((prop = node.property ("type")) != 0) {
1071 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
1072 prop->value() == "lv2" ||
1073 prop->value() == "vst" ||
1074 prop->value() == "lxvst" ||
1075 prop->value() == "audiounit") {
1077 processor.reset (new PluginInsert (_session));
1081 processor.reset (new PortInsert (_session, _pannable, _mute_master));
1086 } else if (node.name() == "Send") {
1088 processor.reset (new Send (_session, _pannable, _mute_master));
1092 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
1096 if (processor->set_state (node, version)) {
1100 return (add_processor (processor, placement) == 0);
1103 catch (failed_constructor &err) {
1104 warning << _("processor could not be created. Ignored.") << endmsg;
1110 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
1112 /* NOTE: this is intended to be used ONLY when copying
1113 processors from another Route. Hence the subtle
1114 differences between this and ::add_processor()
1117 ProcessorList::iterator loc;
1120 loc = find(_processors.begin(), _processors.end(), before);
1122 /* nothing specified - at end */
1123 loc = _processors.end ();
1126 if (!_session.engine().connected()) {
1130 if (others.empty()) {
1135 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1136 ProcessorState pstate (this);
1138 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1144 boost::shared_ptr<PluginInsert> pi;
1146 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1150 _processors.insert (loc, *i);
1152 if ((*i)->active()) {
1157 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
1158 if (configure_processors_unlocked (err)) {
1160 configure_processors_unlocked (0); // it worked before we tried to add it ...
1165 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
1168 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1169 boost::shared_ptr<PluginInsert> pi;
1171 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1172 if (pi->has_no_inputs ()) {
1173 _have_internal_generator = true;
1179 _output->set_user_latency (0);
1182 reset_instrument_info ();
1183 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1184 set_processor_positions ();
1190 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1192 if (p == PreFader) {
1193 start = _processors.begin();
1194 end = find(_processors.begin(), _processors.end(), _amp);
1196 start = find(_processors.begin(), _processors.end(), _amp);
1198 end = _processors.end();
1202 /** Turn off all processors with a given placement
1203 * @param p Placement of processors to disable
1206 Route::disable_processors (Placement p)
1208 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1210 ProcessorList::iterator start, end;
1211 placement_range(p, start, end);
1213 for (ProcessorList::iterator i = start; i != end; ++i) {
1214 (*i)->deactivate ();
1217 _session.set_dirty ();
1220 /** Turn off all redirects
1223 Route::disable_processors ()
1225 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1227 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1228 (*i)->deactivate ();
1231 _session.set_dirty ();
1234 /** Turn off all redirects with a given placement
1235 * @param p Placement of redirects to disable
1238 Route::disable_plugins (Placement p)
1240 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1242 ProcessorList::iterator start, end;
1243 placement_range(p, start, end);
1245 for (ProcessorList::iterator i = start; i != end; ++i) {
1246 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1247 (*i)->deactivate ();
1251 _session.set_dirty ();
1254 /** Turn off all plugins
1257 Route::disable_plugins ()
1259 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1261 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1262 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1263 (*i)->deactivate ();
1267 _session.set_dirty ();
1272 Route::ab_plugins (bool forward)
1274 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1278 /* forward = turn off all active redirects, and mark them so that the next time
1279 we go the other way, we will revert them
1282 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1283 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1287 if ((*i)->active()) {
1288 (*i)->deactivate ();
1289 (*i)->set_next_ab_is_active (true);
1291 (*i)->set_next_ab_is_active (false);
1297 /* backward = if the redirect was marked to go active on the next ab, do so */
1299 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1301 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1305 if ((*i)->get_next_ab_is_active()) {
1308 (*i)->deactivate ();
1313 _session.set_dirty ();
1317 /** Remove processors with a given placement.
1318 * @param p Placement of processors to remove.
1321 Route::clear_processors (Placement p)
1323 if (!_session.engine().connected()) {
1327 bool already_deleting = _session.deletion_in_progress();
1328 if (!already_deleting) {
1329 _session.set_deletion_in_progress();
1333 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1334 ProcessorList new_list;
1335 ProcessorStreams err;
1336 bool seen_amp = false;
1338 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1344 if ((*i) == _amp || (*i) == _meter || (*i) == _main_outs) {
1346 /* you can't remove these */
1348 new_list.push_back (*i);
1355 new_list.push_back (*i);
1358 (*i)->drop_references ();
1366 (*i)->drop_references ();
1369 new_list.push_back (*i);
1376 _processors = new_list;
1379 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
1380 configure_processors_unlocked (&err); // this can't fail
1384 processor_max_streams.reset();
1385 _have_internal_generator = false;
1386 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1387 set_processor_positions ();
1389 reset_instrument_info ();
1391 if (!already_deleting) {
1392 _session.clear_deletion_in_progress();
1397 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err, bool need_process_lock)
1399 // TODO once the export point can be configured properly, do something smarter here
1400 if (processor == _capturing_processor) {
1401 _capturing_processor.reset();
1404 /* these can never be removed */
1406 if (processor == _amp || processor == _meter || processor == _main_outs) {
1410 if (!_session.engine().connected()) {
1414 processor_max_streams.reset();
1417 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1418 ProcessorState pstate (this);
1420 ProcessorList::iterator i;
1421 bool removed = false;
1423 for (i = _processors.begin(); i != _processors.end(); ) {
1424 if (*i == processor) {
1426 /* move along, see failure case for configure_processors()
1427 where we may need to reconfigure the processor.
1430 /* stop redirects that send signals to JACK ports
1431 from causing noise as a result of no longer being
1435 boost::shared_ptr<IOProcessor> iop;
1437 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (*i)) != 0) {
1441 i = _processors.erase (i);
1449 _output->set_user_latency (0);
1457 if (need_process_lock) {
1458 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
1460 if (configure_processors_unlocked (err)) {
1462 /* we know this will work, because it worked before :) */
1463 configure_processors_unlocked (0);
1467 if (configure_processors_unlocked (err)) {
1469 /* we know this will work, because it worked before :) */
1470 configure_processors_unlocked (0);
1475 _have_internal_generator = false;
1477 for (i = _processors.begin(); i != _processors.end(); ++i) {
1478 boost::shared_ptr<PluginInsert> pi;
1480 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1481 if (pi->has_no_inputs ()) {
1482 _have_internal_generator = true;
1489 reset_instrument_info ();
1490 processor->drop_references ();
1491 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1492 set_processor_positions ();
1498 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1500 ProcessorList deleted;
1502 if (!_session.engine().connected()) {
1506 processor_max_streams.reset();
1509 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1510 ProcessorState pstate (this);
1512 ProcessorList::iterator i;
1513 boost::shared_ptr<Processor> processor;
1515 for (i = _processors.begin(); i != _processors.end(); ) {
1519 /* these can never be removed */
1521 if (processor == _amp || processor == _meter || processor == _main_outs) {
1526 /* see if its in the list of processors to delete */
1528 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1533 /* stop IOProcessors that send to JACK ports
1534 from causing noise as a result of no longer being
1538 boost::shared_ptr<IOProcessor> iop;
1540 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (processor)) != 0) {
1544 deleted.push_back (processor);
1545 i = _processors.erase (i);
1548 if (deleted.empty()) {
1549 /* none of those in the requested list were found */
1553 _output->set_user_latency (0);
1556 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
1558 if (configure_processors_unlocked (err)) {
1560 /* we know this will work, because it worked before :) */
1561 configure_processors_unlocked (0);
1566 _have_internal_generator = false;
1568 for (i = _processors.begin(); i != _processors.end(); ++i) {
1569 boost::shared_ptr<PluginInsert> pi;
1571 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1572 if (pi->has_no_inputs ()) {
1573 _have_internal_generator = true;
1580 /* now try to do what we need to so that those that were removed will be deleted */
1582 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1583 (*i)->drop_references ();
1586 reset_instrument_info ();
1587 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1588 set_processor_positions ();
1594 Route::reset_instrument_info ()
1596 boost::shared_ptr<Processor> instr = the_instrument();
1597 _instrument_info.set_internal_instrument (instr);
1600 /** Caller must hold process lock */
1602 Route::configure_processors (ProcessorStreams* err)
1604 assert (!AudioEngine::instance()->process_lock().trylock());
1606 if (!_in_configure_processors) {
1607 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1608 return configure_processors_unlocked (err);
1615 Route::input_streams () const
1617 return _input->n_ports ();
1620 list<pair<ChanCount, ChanCount> >
1621 Route::try_configure_processors (ChanCount in, ProcessorStreams* err)
1623 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1625 return try_configure_processors_unlocked (in, err);
1628 list<pair<ChanCount, ChanCount> >
1629 Route::try_configure_processors_unlocked (ChanCount in, ProcessorStreams* err)
1631 // Check each processor in order to see if we can configure as requested
1633 list<pair<ChanCount, ChanCount> > configuration;
1636 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1637 DEBUG_TRACE (DEBUG::Processors, "{\n");
1639 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1641 if (boost::dynamic_pointer_cast<UnknownProcessor> (*p)) {
1642 DEBUG_TRACE (DEBUG::Processors, "--- CONFIGURE ABORTED due to unknown processor.\n");
1646 if ((*p)->can_support_io_configuration(in, out)) {
1647 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID=%2 in=%3 out=%4\n",(*p)->name(), (*p)->id(), in, out));
1648 configuration.push_back(make_pair(in, out));
1655 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
1656 DEBUG_TRACE (DEBUG::Processors, string_compose ("---- %1 cannot support in=%2 out=%3\n", (*p)->name(), in, out));
1657 DEBUG_TRACE (DEBUG::Processors, "}\n");
1658 return list<pair<ChanCount, ChanCount> > ();
1662 DEBUG_TRACE (DEBUG::Processors, "}\n");
1664 return configuration;
1667 /** Set the input/output configuration of each processor in the processors list.
1668 * Caller must hold process lock.
1669 * Return 0 on success, otherwise configuration is impossible.
1672 Route::configure_processors_unlocked (ProcessorStreams* err)
1674 assert (!AudioEngine::instance()->process_lock().trylock());
1676 if (_in_configure_processors) {
1680 /* put invisible processors where they should be */
1681 setup_invisible_processors ();
1683 _in_configure_processors = true;
1685 list<pair<ChanCount, ChanCount> > configuration = try_configure_processors_unlocked (input_streams (), err);
1687 if (configuration.empty ()) {
1688 _in_configure_processors = false;
1694 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1695 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1697 if (boost::dynamic_pointer_cast<UnknownProcessor> (*p)) {
1701 (*p)->configure_io(c->first, c->second);
1702 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1703 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1708 _meter->reset_max_channels (processor_max_streams);
1711 /* make sure we have sufficient scratch buffers to cope with the new processor
1714 _session.ensure_buffers (n_process_buffers ());
1716 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration complete\n", _name));
1718 _in_configure_processors = false;
1722 /** Set all visible processors to a given active state (except Fader, whose state is not changed)
1723 * @param state New active state for those processors.
1726 Route::all_visible_processors_active (bool state)
1728 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
1730 if (_processors.empty()) {
1734 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1735 if (!(*i)->display_to_user() || boost::dynamic_pointer_cast<Amp> (*i)) {
1742 (*i)->deactivate ();
1746 _session.set_dirty ();
1750 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
1752 /* "new_order" is an ordered list of processors to be positioned according to "placement".
1753 NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
1754 processors in the current actual processor list that are hidden. Any visible processors
1755 in the current list but not in "new_order" will be assumed to be deleted.
1759 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
1760 ProcessorState pstate (this);
1762 ProcessorList::iterator oiter;
1763 ProcessorList::const_iterator niter;
1764 ProcessorList as_it_will_be;
1766 oiter = _processors.begin();
1767 niter = new_order.begin();
1769 while (niter != new_order.end()) {
1771 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
1772 then append it to the temp list.
1774 Otherwise, see if the next processor in the old list is in the new list. if not,
1775 its been deleted. If its there, append it to the temp list.
1778 if (oiter == _processors.end()) {
1780 /* no more elements in the old list, so just stick the rest of
1781 the new order onto the temp list.
1784 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
1785 while (niter != new_order.end()) {
1792 if (!(*oiter)->display_to_user()) {
1794 as_it_will_be.push_back (*oiter);
1798 /* visible processor: check that its in the new order */
1800 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
1801 /* deleted: do nothing, shared_ptr<> will clean up */
1803 /* ignore this one, and add the next item from the new order instead */
1804 as_it_will_be.push_back (*niter);
1809 /* now remove from old order - its taken care of no matter what */
1810 oiter = _processors.erase (oiter);
1815 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
1817 /* If the meter is in a custom position, find it and make a rough note of its position */
1818 maybe_note_meter_position ();
1821 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
1823 if (configure_processors_unlocked (err)) {
1830 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1831 set_processor_positions ();
1843 Route::get_template()
1845 return state(false);
1849 Route::state(bool full_state)
1851 XMLNode *node = new XMLNode("Route");
1852 ProcessorList::iterator i;
1855 id().print (buf, sizeof (buf));
1856 node->add_property("id", buf);
1857 node->add_property ("name", _name);
1858 node->add_property("default-type", _default_type.to_string());
1861 node->add_property("flags", enum_2_string (_flags));
1864 node->add_property("active", _active?"yes":"no");
1866 boost::to_string (_phase_invert, p);
1867 node->add_property("phase-invert", p);
1868 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
1869 node->add_property("meter-point", enum_2_string (_meter_point));
1872 node->add_property("route-group", _route_group->name());
1875 string order_string;
1876 OrderKeys::iterator x = order_keys.begin();
1878 while (x != order_keys.end()) {
1879 order_string += enum_2_string ((*x).first);
1880 order_string += '=';
1881 snprintf (buf, sizeof(buf), "%" PRId32, (*x).second);
1882 order_string += buf;
1886 if (x == order_keys.end()) {
1890 order_string += ':';
1892 node->add_property ("order-keys", order_string);
1893 node->add_property ("self-solo", (_self_solo ? "yes" : "no"));
1894 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_upstream);
1895 node->add_property ("soloed-by-upstream", buf);
1896 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_downstream);
1897 node->add_property ("soloed-by-downstream", buf);
1898 node->add_property ("solo-isolated", solo_isolated() ? "yes" : "no");
1899 node->add_property ("solo-safe", _solo_safe ? "yes" : "no");
1901 node->add_child_nocopy (_input->state (full_state));
1902 node->add_child_nocopy (_output->state (full_state));
1903 node->add_child_nocopy (_solo_control->get_state ());
1904 node->add_child_nocopy (_mute_control->get_state ());
1905 node->add_child_nocopy (_mute_master->get_state ());
1907 XMLNode* remote_control_node = new XMLNode (X_("RemoteControl"));
1908 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
1909 remote_control_node->add_property (X_("id"), buf);
1910 node->add_child_nocopy (*remote_control_node);
1912 if (_comment.length()) {
1913 XMLNode *cmt = node->add_child ("Comment");
1914 cmt->add_content (_comment);
1918 node->add_child_nocopy (_pannable->state (full_state));
1921 for (i = _processors.begin(); i != _processors.end(); ++i) {
1923 /* template save: do not include internal sends functioning as
1924 aux sends because the chance of the target ID
1925 in the session where this template is used
1928 similarly, do not save listen sends which connect to
1929 the monitor section, because these will always be
1932 boost::shared_ptr<InternalSend> is;
1934 if ((is = boost::dynamic_pointer_cast<InternalSend> (*i)) != 0) {
1935 if (is->role() == Delivery::Aux || is->role() == Delivery::Listen) {
1940 node->add_child_nocopy((*i)->state (full_state));
1944 node->add_child_copy (*_extra_xml);
1947 if (_custom_meter_position_noted) {
1948 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
1950 after->id().print (buf, sizeof (buf));
1951 node->add_property (X_("processor-after-last-custom-meter"), buf);
1954 node->add_property (X_("last-custom-meter-was-at-end"), _last_custom_meter_was_at_end ? "yes" : "no");
1961 Route::set_state (const XMLNode& node, int version)
1963 if (version < 3000) {
1964 return set_state_2X (node, version);
1968 XMLNodeConstIterator niter;
1970 const XMLProperty *prop;
1972 if (node.name() != "Route"){
1973 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
1977 if ((prop = node.property (X_("name"))) != 0) {
1978 Route::set_name (prop->value());
1983 if ((prop = node.property (X_("flags"))) != 0) {
1984 _flags = Flag (string_2_enum (prop->value(), _flags));
1989 if (is_master() || is_monitor() || is_hidden()) {
1990 _mute_master->set_solo_ignore (true);
1994 /* monitor bus does not get a panner, but if (re)created
1995 via XML, it will already have one by the time we
1996 call ::set_state(). so ... remove it.
2001 /* add all processors (except amp, which is always present) */
2003 nlist = node.children();
2004 XMLNode processor_state (X_("processor_state"));
2006 Stateful::save_extra_xml (node);
2008 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2012 if (child->name() == IO::state_node_name) {
2013 if ((prop = child->property (X_("direction"))) == 0) {
2017 if (prop->value() == "Input") {
2018 _input->set_state (*child, version);
2019 } else if (prop->value() == "Output") {
2020 _output->set_state (*child, version);
2024 if (child->name() == X_("Processor")) {
2025 processor_state.add_child_copy (*child);
2029 if (child->name() == X_("Pannable")) {
2031 _pannable->set_state (*child, version);
2033 warning << string_compose (_("Pannable state found for route (%1) without a panner!"), name()) << endmsg;
2038 if ((prop = node.property (X_("meter-point"))) != 0) {
2039 MeterPoint mp = MeterPoint (string_2_enum (prop->value (), _meter_point));
2040 set_meter_point (mp, true);
2042 _meter->set_display_to_user (_meter_point == MeterCustom);
2046 set_processor_state (processor_state);
2048 if ((prop = node.property ("self-solo")) != 0) {
2049 set_self_solo (string_is_affirmative (prop->value()));
2052 if ((prop = node.property ("soloed-by-upstream")) != 0) {
2053 _soloed_by_others_upstream = 0; // needed for mod_.... () to work
2054 mod_solo_by_others_upstream (atoi (prop->value()));
2057 if ((prop = node.property ("soloed-by-downstream")) != 0) {
2058 _soloed_by_others_downstream = 0; // needed for mod_.... () to work
2059 mod_solo_by_others_downstream (atoi (prop->value()));
2062 if ((prop = node.property ("solo-isolated")) != 0) {
2063 set_solo_isolated (string_is_affirmative (prop->value()), this);
2066 if ((prop = node.property ("solo-safe")) != 0) {
2067 set_solo_safe (string_is_affirmative (prop->value()), this);
2070 if ((prop = node.property (X_("phase-invert"))) != 0) {
2071 set_phase_invert (boost::dynamic_bitset<> (prop->value ()));
2074 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2075 set_denormal_protection (string_is_affirmative (prop->value()));
2078 if ((prop = node.property (X_("active"))) != 0) {
2079 bool yn = string_is_affirmative (prop->value());
2080 _active = !yn; // force switch
2081 set_active (yn, this);
2084 if ((prop = node.property (X_("order-keys"))) != 0) {
2088 string::size_type colon, equal;
2089 string remaining = prop->value();
2091 while (remaining.length()) {
2093 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2094 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2097 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2098 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2101 string keyname = remaining.substr (0, equal);
2102 RouteSortOrderKey sk;
2104 if (keyname == "signal") {
2106 } else if (keyname == "editor") {
2109 sk = (RouteSortOrderKey) string_2_enum (remaining.substr (0, equal), sk);
2112 set_order_key (sk, n);
2116 colon = remaining.find_first_of (':');
2118 if (colon != string::npos) {
2119 remaining = remaining.substr (colon+1);
2126 if ((prop = node.property (X_("processor-after-last-custom-meter"))) != 0) {
2127 PBD::ID id (prop->value ());
2128 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2129 ProcessorList::const_iterator i = _processors.begin ();
2130 while (i != _processors.end() && (*i)->id() != id) {
2134 if (i != _processors.end ()) {
2135 _processor_after_last_custom_meter = *i;
2136 _custom_meter_position_noted = true;
2140 if ((prop = node.property (X_("last-custom-meter-was-at-end"))) != 0) {
2141 _last_custom_meter_was_at_end = string_is_affirmative (prop->value ());
2144 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2147 if (child->name() == X_("Comment")) {
2149 /* XXX this is a terrible API design in libxml++ */
2151 XMLNode *cmt = *(child->children().begin());
2152 _comment = cmt->content();
2154 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2155 if (prop->value() == "solo") {
2156 _solo_control->set_state (*child, version);
2157 } else if (prop->value() == "mute") {
2158 _mute_control->set_state (*child, version);
2161 } else if (child->name() == X_("RemoteControl")) {
2162 if ((prop = child->property (X_("id"))) != 0) {
2164 sscanf (prop->value().c_str(), "%d", &x);
2165 set_remote_control_id (x);
2168 } else if (child->name() == X_("MuteMaster")) {
2169 _mute_master->set_state (*child, version);
2177 Route::set_state_2X (const XMLNode& node, int version)
2180 XMLNodeConstIterator niter;
2182 const XMLProperty *prop;
2184 /* 2X things which still remain to be handled:
2190 if (node.name() != "Route") {
2191 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2195 if ((prop = node.property (X_("flags"))) != 0) {
2196 string f = prop->value ();
2197 boost::replace_all (f, "ControlOut", "MonitorOut");
2198 _flags = Flag (string_2_enum (f, _flags));
2203 if ((prop = node.property (X_("phase-invert"))) != 0) {
2204 boost::dynamic_bitset<> p (_input->n_ports().n_audio ());
2205 if (string_is_affirmative (prop->value ())) {
2208 set_phase_invert (p);
2211 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2212 set_denormal_protection (string_is_affirmative (prop->value()));
2215 if ((prop = node.property (X_("soloed"))) != 0) {
2216 bool yn = string_is_affirmative (prop->value());
2218 /* XXX force reset of solo status */
2220 set_solo (yn, this);
2223 if ((prop = node.property (X_("muted"))) != 0) {
2226 bool muted = string_is_affirmative (prop->value());
2232 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2234 if (string_is_affirmative (prop->value())){
2235 mute_point = mute_point + "PreFader";
2240 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2242 if (string_is_affirmative (prop->value())){
2245 mute_point = mute_point + ",";
2248 mute_point = mute_point + "PostFader";
2253 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2255 if (string_is_affirmative (prop->value())){
2258 mute_point = mute_point + ",";
2261 mute_point = mute_point + "Listen";
2266 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2268 if (string_is_affirmative (prop->value())){
2271 mute_point = mute_point + ",";
2274 mute_point = mute_point + "Main";
2278 _mute_master->set_mute_points (mute_point);
2279 _mute_master->set_muted_by_self (true);
2283 if ((prop = node.property (X_("meter-point"))) != 0) {
2284 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2287 /* do not carry over edit/mix groups from 2.X because (a) its hard (b) they
2288 don't mean the same thing.
2291 if ((prop = node.property (X_("order-keys"))) != 0) {
2295 string::size_type colon, equal;
2296 string remaining = prop->value();
2298 while (remaining.length()) {
2300 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2301 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2304 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2305 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2308 string keyname = remaining.substr (0, equal);
2309 RouteSortOrderKey sk;
2311 if (keyname == "signal") {
2313 } else if (keyname == "editor") {
2316 RouteSortOrderKey sk = (RouteSortOrderKey) string_2_enum (remaining.substr (0, equal), sk);
2319 set_order_key (sk, n);
2323 colon = remaining.find_first_of (':');
2325 if (colon != string::npos) {
2326 remaining = remaining.substr (colon+1);
2335 nlist = node.children ();
2336 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2340 if (child->name() == IO::state_node_name) {
2342 /* there is a note in IO::set_state_2X() about why we have to call
2346 _input->set_state_2X (*child, version, true);
2347 _output->set_state_2X (*child, version, false);
2349 if ((prop = child->property (X_("name"))) != 0) {
2350 Route::set_name (prop->value ());
2355 if ((prop = child->property (X_("active"))) != 0) {
2356 bool yn = string_is_affirmative (prop->value());
2357 _active = !yn; // force switch
2358 set_active (yn, this);
2361 if ((prop = child->property (X_("gain"))) != 0) {
2364 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
2365 _amp->gain_control()->set_value (val);
2369 /* Set up Panners in the IO */
2370 XMLNodeList io_nlist = child->children ();
2372 XMLNodeConstIterator io_niter;
2375 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
2377 io_child = *io_niter;
2379 if (io_child->name() == X_("Panner")) {
2380 _main_outs->panner_shell()->set_state(*io_child, version);
2381 } else if (io_child->name() == X_("Automation")) {
2382 /* IO's automation is for the fader */
2383 _amp->set_automation_xml_state (*io_child, Evoral::Parameter (GainAutomation));
2389 XMLNodeList redirect_nodes;
2391 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2395 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2396 redirect_nodes.push_back(child);
2401 set_processor_state_2X (redirect_nodes, version);
2403 Stateful::save_extra_xml (node);
2405 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2408 if (child->name() == X_("Comment")) {
2410 /* XXX this is a terrible API design in libxml++ */
2412 XMLNode *cmt = *(child->children().begin());
2413 _comment = cmt->content();
2415 } else if (child->name() == Controllable::xml_node_name && (prop = child->property("name")) != 0) {
2416 if (prop->value() == X_("solo")) {
2417 _solo_control->set_state (*child, version);
2418 } else if (prop->value() == X_("mute")) {
2419 _mute_control->set_state (*child, version);
2422 } else if (child->name() == X_("RemoteControl")) {
2423 if ((prop = child->property (X_("id"))) != 0) {
2425 sscanf (prop->value().c_str(), "%d", &x);
2426 set_remote_control_id (x);
2436 Route::get_processor_state ()
2438 XMLNode* root = new XMLNode (X_("redirects"));
2439 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2440 root->add_child_nocopy ((*i)->state (true));
2447 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2449 /* We don't bother removing existing processors not in nList, as this
2450 method will only be called when creating a Route from scratch, not
2451 for undo purposes. Just put processors in at the appropriate place
2455 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2456 add_processor_from_xml_2X (**i, version);
2461 Route::set_processor_state (const XMLNode& node)
2463 const XMLNodeList &nlist = node.children();
2464 XMLNodeConstIterator niter;
2465 ProcessorList new_order;
2466 bool must_configure = false;
2468 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2470 XMLProperty* prop = (*niter)->property ("type");
2472 if (prop->value() == "amp") {
2473 _amp->set_state (**niter, Stateful::current_state_version);
2474 new_order.push_back (_amp);
2475 } else if (prop->value() == "meter") {
2476 _meter->set_state (**niter, Stateful::current_state_version);
2477 new_order.push_back (_meter);
2478 } else if (prop->value() == "main-outs") {
2479 _main_outs->set_state (**niter, Stateful::current_state_version);
2480 } else if (prop->value() == "intreturn") {
2482 _intreturn.reset (new InternalReturn (_session));
2483 must_configure = true;
2485 _intreturn->set_state (**niter, Stateful::current_state_version);
2486 } else if (is_monitor() && prop->value() == "monitor") {
2487 if (!_monitor_control) {
2488 _monitor_control.reset (new MonitorProcessor (_session));
2489 must_configure = true;
2491 _monitor_control->set_state (**niter, Stateful::current_state_version);
2492 } else if (prop->value() == "capture") {
2493 /* CapturingProcessor should never be restored, it's always
2494 added explicitly when needed */
2496 ProcessorList::iterator o;
2498 for (o = _processors.begin(); o != _processors.end(); ++o) {
2499 XMLProperty* id_prop = (*niter)->property(X_("id"));
2500 if (id_prop && (*o)->id() == id_prop->value()) {
2501 (*o)->set_state (**niter, Stateful::current_state_version);
2502 new_order.push_back (*o);
2507 // If the processor (*niter) is not on the route then create it
2509 if (o == _processors.end()) {
2511 boost::shared_ptr<Processor> processor;
2513 if (prop->value() == "intsend") {
2515 processor.reset (new InternalSend (_session, _pannable, _mute_master, boost::shared_ptr<Route>(), Delivery::Role (0)));
2517 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
2518 prop->value() == "lv2" ||
2519 prop->value() == "vst" ||
2520 prop->value() == "lxvst" ||
2521 prop->value() == "audiounit") {
2523 processor.reset (new PluginInsert(_session));
2525 } else if (prop->value() == "port") {
2527 processor.reset (new PortInsert (_session, _pannable, _mute_master));
2529 } else if (prop->value() == "send") {
2531 processor.reset (new Send (_session, _pannable, _mute_master));
2534 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
2538 if (processor->set_state (**niter, Stateful::current_state_version) != 0) {
2539 /* This processor could not be configured. Turn it into a UnknownProcessor */
2540 processor.reset (new UnknownProcessor (_session, **niter));
2543 /* we have to note the monitor send here, otherwise a new one will be created
2544 and the state of this one will be lost.
2546 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
2547 if (isend && isend->role() == Delivery::Listen) {
2548 _monitor_send = isend;
2551 /* it doesn't matter if invisible processors are added here, as they
2552 will be sorted out by setup_invisible_processors () shortly.
2555 new_order.push_back (processor);
2556 must_configure = true;
2562 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
2563 _processors = new_order;
2565 if (must_configure) {
2566 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
2567 configure_processors_unlocked (0);
2570 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2572 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
2574 boost::shared_ptr<PluginInsert> pi;
2576 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
2577 if (pi->has_no_inputs ()) {
2578 _have_internal_generator = true;
2585 reset_instrument_info ();
2586 processors_changed (RouteProcessorChange ());
2587 set_processor_positions ();
2591 Route::curve_reallocate ()
2593 // _gain_automation_curve.finish_resize ();
2594 // _pan_automation_curve.finish_resize ();
2598 Route::silence (framecnt_t nframes)
2600 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
2605 silence_unlocked (nframes);
2609 Route::silence_unlocked (framecnt_t nframes)
2611 /* Must be called with the processor lock held */
2615 _output->silence (nframes);
2617 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2618 boost::shared_ptr<PluginInsert> pi;
2620 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2621 // skip plugins, they don't need anything when we're not active
2625 (*i)->silence (nframes);
2628 if (nframes == _session.get_block_size()) {
2635 Route::add_internal_return ()
2638 _intreturn.reset (new InternalReturn (_session));
2639 add_processor (_intreturn, PreFader);
2644 Route::add_send_to_internal_return (InternalSend* send)
2646 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
2648 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2649 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
2652 return d->add_send (send);
2658 Route::remove_send_from_internal_return (InternalSend* send)
2660 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
2662 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2663 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
2666 return d->remove_send (send);
2672 Route::enable_monitor_send ()
2674 /* Caller must hold process lock */
2675 assert (!AudioEngine::instance()->process_lock().trylock());
2677 /* master never sends to monitor section via the normal mechanism */
2678 assert (!is_master ());
2680 /* make sure we have one */
2681 if (!_monitor_send) {
2682 _monitor_send.reset (new InternalSend (_session, _pannable, _mute_master, _session.monitor_out(), Delivery::Listen));
2683 _monitor_send->set_display_to_user (false);
2687 configure_processors (0);
2690 /** Add an aux send to a route.
2691 * @param route route to send to.
2692 * @param before Processor to insert before, or 0 to insert at the end.
2695 Route::add_aux_send (boost::shared_ptr<Route> route, boost::shared_ptr<Processor> before)
2697 assert (route != _session.monitor_out ());
2700 Glib::Threads::RWLock::ReaderLock rm (_processor_lock);
2702 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
2704 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend> (*x);
2706 if (d && d->target_route() == route) {
2707 /* already listening via the specified IO: do nothing */
2715 boost::shared_ptr<InternalSend> listener;
2718 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
2719 listener.reset (new InternalSend (_session, _pannable, _mute_master, route, Delivery::Aux));
2722 add_processor (listener, before);
2724 } catch (failed_constructor& err) {
2732 Route::remove_aux_or_listen (boost::shared_ptr<Route> route)
2734 ProcessorStreams err;
2735 ProcessorList::iterator tmp;
2738 Glib::Threads::RWLock::ReaderLock rl(_processor_lock);
2740 /* have to do this early because otherwise processor reconfig
2741 * will put _monitor_send back in the list
2744 if (route == _session.monitor_out()) {
2745 _monitor_send.reset ();
2749 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
2751 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
2753 if (d && d->target_route() == route) {
2755 remove_processor (*x, &err, false);
2758 /* list could have been demolished while we dropped the lock
2769 Route::set_comment (string cmt, void *src)
2772 comment_changed (src);
2773 _session.set_dirty ();
2777 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
2779 FeedRecord fr (other, via_sends_only);
2781 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
2783 if (!result.second) {
2785 /* already a record for "other" - make sure sends-only information is correct */
2786 if (!via_sends_only && result.first->sends_only) {
2787 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
2788 frp->sends_only = false;
2792 return result.second;
2796 Route::clear_fed_by ()
2802 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
2804 const FedBy& fed_by (other->fed_by());
2806 for (FedBy::iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
2807 boost::shared_ptr<Route> sr = f->r.lock();
2809 if (sr && (sr.get() == this)) {
2811 if (via_sends_only) {
2812 *via_sends_only = f->sends_only;
2823 Route::direct_feeds_according_to_reality (boost::shared_ptr<Route> other, bool* via_send_only)
2825 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
2827 if (_output->connected_to (other->input())) {
2828 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
2829 if (via_send_only) {
2830 *via_send_only = false;
2837 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
2839 boost::shared_ptr<IOProcessor> iop;
2841 if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*r)) != 0) {
2842 if (iop->feeds (other)) {
2843 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
2844 if (via_send_only) {
2845 *via_send_only = true;
2849 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
2852 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
2857 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
2862 Route::direct_feeds_according_to_graph (boost::shared_ptr<Route> other, bool* via_send_only)
2864 return _session._current_route_graph.has (shared_from_this (), other, via_send_only);
2867 /** Called from the (non-realtime) butler thread when the transport is stopped */
2869 Route::nonrealtime_handle_transport_stopped (bool /*abort_ignored*/, bool did_locate, bool can_flush_processors)
2871 framepos_t now = _session.transport_frame();
2874 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
2876 Automatable::transport_stopped (now);
2878 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2880 if (!_have_internal_generator && (Config->get_plugins_stop_with_transport() && can_flush_processors)) {
2884 (*i)->transport_stopped (now);
2888 _roll_delay = _initial_delay;
2892 Route::input_change_handler (IOChange change, void * /*src*/)
2894 bool need_to_queue_solo_change = true;
2896 if ((change.type & IOChange::ConfigurationChanged)) {
2897 /* This is called with the process lock held if change
2898 contains ConfigurationChanged
2900 need_to_queue_solo_change = false;
2901 configure_processors (0);
2902 _phase_invert.resize (_input->n_ports().n_audio ());
2903 io_changed (); /* EMIT SIGNAL */
2906 if (!_input->connected() && _soloed_by_others_upstream) {
2907 if (need_to_queue_solo_change) {
2908 _session.cancel_solo_after_disconnect (shared_from_this(), true);
2910 cancel_solo_after_disconnect (true);
2916 Route::output_change_handler (IOChange change, void * /*src*/)
2918 bool need_to_queue_solo_change = true;
2920 if ((change.type & IOChange::ConfigurationChanged)) {
2921 /* This is called with the process lock held if change
2922 contains ConfigurationChanged
2924 need_to_queue_solo_change = false;
2927 if (!_output->connected() && _soloed_by_others_downstream) {
2928 if (need_to_queue_solo_change) {
2929 _session.cancel_solo_after_disconnect (shared_from_this(), false);
2931 cancel_solo_after_disconnect (false);
2937 Route::cancel_solo_after_disconnect (bool upstream)
2940 _soloed_by_others_upstream = 0;
2942 _soloed_by_others_downstream = 0;
2944 set_mute_master_solo ();
2945 solo_changed (false, this);
2949 Route::pans_required () const
2951 if (n_outputs().n_audio() < 2) {
2955 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
2959 Route::no_roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, bool session_state_changing)
2961 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
2966 if (n_outputs().n_total() == 0) {
2970 if (!_active || n_inputs() == ChanCount::ZERO) {
2971 silence_unlocked (nframes);
2974 if (session_state_changing) {
2975 if (_session.transport_speed() != 0.0f) {
2976 /* we're rolling but some state is changing (e.g. our diskstream contents)
2977 so we cannot use them. Be silent till this is over.
2979 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
2981 silence_unlocked (nframes);
2984 /* we're really not rolling, so we're either delivery silence or actually
2985 monitoring, both of which are safe to do while session_state_changing is true.
2989 _amp->apply_gain_automation (false);
2990 passthru (start_frame, end_frame, nframes, 0);
2996 Route::roll (pframes_t nframes, framepos_t start_frame, framepos_t end_frame, int declick, bool& /* need_butler */)
2998 Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3003 if (n_outputs().n_total() == 0) {
3007 if (!_active || n_inputs().n_total() == 0) {
3008 silence_unlocked (nframes);
3012 framepos_t unused = 0;
3014 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
3020 passthru (start_frame, end_frame, nframes, declick);
3026 Route::silent_roll (pframes_t nframes, framepos_t /*start_frame*/, framepos_t /*end_frame*/, bool& /* need_butler */)
3033 Route::flush_processors ()
3035 /* XXX shouldn't really try to take this lock, since
3036 this is called from the RT audio thread.
3039 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3041 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3047 Route::set_meter_point (MeterPoint p, bool force)
3049 /* CAN BE CALLED FROM PROCESS CONTEXT */
3051 if (_meter_point == p && !force) {
3055 bool meter_was_visible_to_user = _meter->display_to_user ();
3058 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3060 maybe_note_meter_position ();
3064 if (_meter_point != MeterCustom) {
3066 _meter->set_display_to_user (false);
3068 setup_invisible_processors ();
3072 _meter->set_display_to_user (true);
3074 /* If we have a previous position for the custom meter, try to put it there */
3075 if (_custom_meter_position_noted) {
3076 boost::shared_ptr<Processor> after = _processor_after_last_custom_meter.lock ();
3079 ProcessorList::iterator i = find (_processors.begin(), _processors.end(), after);
3080 if (i != _processors.end ()) {
3081 _processors.remove (_meter);
3082 _processors.insert (i, _meter);
3084 } else if (_last_custom_meter_was_at_end) {
3085 _processors.remove (_meter);
3086 _processors.push_back (_meter);
3091 /* Set up the meter for its new position */
3093 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
3097 if (loc == _processors.begin()) {
3098 m_in = _input->n_ports();
3100 ProcessorList::iterator before = loc;
3102 m_in = (*before)->output_streams ();
3105 _meter->reflect_inputs (m_in);
3107 /* we do not need to reconfigure the processors, because the meter
3108 (a) is always ready to handle processor_max_streams
3109 (b) is always an N-in/N-out processor, and thus moving
3110 it doesn't require any changes to the other processors.
3114 meter_change (); /* EMIT SIGNAL */
3116 bool const meter_visibly_changed = (_meter->display_to_user() != meter_was_visible_to_user);
3118 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, meter_visibly_changed)); /* EMIT SIGNAL */
3122 Route::listen_position_changed ()
3125 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
3126 ProcessorState pstate (this);
3129 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
3131 if (configure_processors_unlocked (0)) {
3133 configure_processors_unlocked (0); // it worked before we tried to add it ...
3139 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3140 _session.set_dirty ();
3143 boost::shared_ptr<CapturingProcessor>
3144 Route::add_export_point()
3146 if (!_capturing_processor) {
3148 _capturing_processor.reset (new CapturingProcessor (_session));
3149 _capturing_processor->activate ();
3152 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
3153 configure_processors (0);
3158 return _capturing_processor;
3162 Route::update_signal_latency ()
3164 framecnt_t l = _output->user_latency();
3166 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3167 if ((*i)->active ()) {
3168 l += (*i)->signal_latency ();
3172 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal signal latency = %2\n", _name, l));
3174 if (_signal_latency != l) {
3175 _signal_latency = l;
3176 signal_latency_changed (); /* EMIT SIGNAL */
3179 return _signal_latency;
3183 Route::set_user_latency (framecnt_t nframes)
3185 _output->set_user_latency (nframes);
3186 _session.update_latency_compensation ();
3190 Route::set_latency_compensation (framecnt_t longest_session_latency)
3192 framecnt_t old = _initial_delay;
3194 if (_signal_latency < longest_session_latency) {
3195 _initial_delay = longest_session_latency - _signal_latency;
3200 DEBUG_TRACE (DEBUG::Latency, string_compose (
3201 "%1: compensate for maximum latency of %2,"
3202 "given own latency of %3, using initial delay of %4\n",
3203 name(), longest_session_latency, _signal_latency, _initial_delay));
3205 if (_initial_delay != old) {
3206 initial_delay_changed (); /* EMIT SIGNAL */
3209 if (_session.transport_stopped()) {
3210 _roll_delay = _initial_delay;
3214 Route::SoloControllable::SoloControllable (std::string name, boost::shared_ptr<Route> r)
3215 : AutomationControl (r->session(), Evoral::Parameter (SoloAutomation),
3216 boost::shared_ptr<AutomationList>(), name)
3219 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(SoloAutomation)));
3224 Route::SoloControllable::set_value (double val)
3226 bool bval = ((val >= 0.5f) ? true: false);
3228 boost::shared_ptr<RouteList> rl (new RouteList);
3230 boost::shared_ptr<Route> r = _route.lock ();
3237 if (Config->get_solo_control_is_listen_control()) {
3238 _session.set_listen (rl, bval);
3240 _session.set_solo (rl, bval);
3245 Route::SoloControllable::get_value () const
3247 boost::shared_ptr<Route> r = _route.lock ();
3252 if (Config->get_solo_control_is_listen_control()) {
3253 return r->listening_via_monitor() ? 1.0f : 0.0f;
3255 return r->self_soloed() ? 1.0f : 0.0f;
3259 Route::MuteControllable::MuteControllable (std::string name, boost::shared_ptr<Route> r)
3260 : AutomationControl (r->session(), Evoral::Parameter (MuteAutomation),
3261 boost::shared_ptr<AutomationList>(), name)
3264 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(MuteAutomation)));
3269 Route::MuteControllable::set_value (double val)
3271 bool bval = ((val >= 0.5f) ? true: false);
3273 boost::shared_ptr<RouteList> rl (new RouteList);
3275 boost::shared_ptr<Route> r = _route.lock ();
3281 _session.set_mute (rl, bval);
3285 Route::MuteControllable::get_value () const
3287 boost::shared_ptr<Route> r = _route.lock ();
3292 return r->muted() ? 1.0f : 0.0f;
3296 Route::set_block_size (pframes_t nframes)
3298 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3299 (*i)->set_block_size (nframes);
3302 _session.ensure_buffers (n_process_buffers ());
3306 Route::protect_automation ()
3308 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
3309 (*i)->protect_automation();
3312 /** @param declick 1 to set a pending declick fade-in,
3313 * -1 to set a pending declick fade-out
3316 Route::set_pending_declick (int declick)
3319 /* this call is not allowed to turn off a pending declick */
3321 _pending_declick = declick;
3324 _pending_declick = 0;
3328 /** Shift automation forwards from a particular place, thereby inserting time.
3329 * Adds undo commands for any shifts that are performed.
3331 * @param pos Position to start shifting from.
3332 * @param frames Amount to shift forwards by.
3336 Route::shift (framepos_t pos, framecnt_t frames)
3338 /* gain automation */
3340 boost::shared_ptr<AutomationControl> gc = _amp->gain_control();
3342 XMLNode &before = gc->alist()->get_state ();
3343 gc->alist()->shift (pos, frames);
3344 XMLNode &after = gc->alist()->get_state ();
3345 _session.add_command (new MementoCommand<AutomationList> (*gc->alist().get(), &before, &after));
3348 /* pan automation */
3350 ControlSet::Controls& c (_pannable->controls());
3352 for (ControlSet::Controls::const_iterator ci = c.begin(); ci != c.end(); ++ci) {
3353 boost::shared_ptr<AutomationControl> pc = boost::dynamic_pointer_cast<AutomationControl> (ci->second);
3355 boost::shared_ptr<AutomationList> al = pc->alist();
3356 XMLNode& before = al->get_state ();
3357 al->shift (pos, frames);
3358 XMLNode& after = al->get_state ();
3359 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
3364 /* redirect automation */
3366 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3367 for (ProcessorList::iterator i = _processors.begin (); i != _processors.end (); ++i) {
3369 set<Evoral::Parameter> parameters = (*i)->what_can_be_automated();
3371 for (set<Evoral::Parameter>::const_iterator p = parameters.begin (); p != parameters.end (); ++p) {
3372 boost::shared_ptr<AutomationControl> ac = (*i)->automation_control (*p);
3374 boost::shared_ptr<AutomationList> al = ac->alist();
3375 XMLNode &before = al->get_state ();
3376 al->shift (pos, frames);
3377 XMLNode &after = al->get_state ();
3378 _session.add_command (new MementoCommand<AutomationList> (*al.get(), &before, &after));
3387 Route::save_as_template (const string& path, const string& name)
3389 XMLNode& node (state (false));
3392 IO::set_name_in_state (*node.children().front(), name);
3394 tree.set_root (&node);
3395 return tree.write (path.c_str());
3400 Route::set_name (const string& str)
3406 name = Route::ensure_track_or_route_name (str, _session);
3407 SessionObject::set_name (name);
3409 ret = (_input->set_name(name) && _output->set_name(name));
3412 /* rename the main outs. Leave other IO processors
3413 * with whatever name they already have, because its
3414 * just fine as it is (it will not contain the route
3415 * name if its a port insert, port send or port return).
3419 if (_main_outs->set_name (name)) {
3420 /* XXX returning false here is stupid because
3421 we already changed the route name.
3431 /** Set the name of a route in an XML description.
3432 * @param node XML <Route> node to set the name in.
3433 * @param name New name.
3436 Route::set_name_in_state (XMLNode& node, string const & name)
3438 node.add_property (X_("name"), name);
3440 XMLNodeList children = node.children();
3441 for (XMLNodeIterator i = children.begin(); i != children.end(); ++i) {
3443 if ((*i)->name() == X_("IO")) {
3445 IO::set_name_in_state (**i, name);
3447 } else if ((*i)->name() == X_("Processor")) {
3449 XMLProperty* role = (*i)->property (X_("role"));
3450 if (role && role->value() == X_("Main")) {
3451 (*i)->add_property (X_("name"), name);
3454 } else if ((*i)->name() == X_("Diskstream")) {
3456 (*i)->add_property (X_("playlist"), string_compose ("%1.1", name).c_str());
3457 (*i)->add_property (X_("name"), name);
3463 boost::shared_ptr<Send>
3464 Route::internal_send_for (boost::shared_ptr<const Route> target) const
3466 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3468 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3469 boost::shared_ptr<InternalSend> send;
3471 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
3472 if (send->target_route() == target) {
3478 return boost::shared_ptr<Send>();
3481 /** @param c Audio channel index.
3482 * @param yn true to invert phase, otherwise false.
3485 Route::set_phase_invert (uint32_t c, bool yn)
3487 if (_phase_invert[c] != yn) {
3488 _phase_invert[c] = yn;
3489 phase_invert_changed (); /* EMIT SIGNAL */
3490 _session.set_dirty ();
3495 Route::set_phase_invert (boost::dynamic_bitset<> p)
3497 if (_phase_invert != p) {
3499 phase_invert_changed (); /* EMIT SIGNAL */
3500 _session.set_dirty ();
3505 Route::phase_invert (uint32_t c) const
3507 return _phase_invert[c];
3510 boost::dynamic_bitset<>
3511 Route::phase_invert () const
3513 return _phase_invert;
3517 Route::set_denormal_protection (bool yn)
3519 if (_denormal_protection != yn) {
3520 _denormal_protection = yn;
3521 denormal_protection_changed (); /* EMIT SIGNAL */
3526 Route::denormal_protection () const
3528 return _denormal_protection;
3532 Route::set_active (bool yn, void* src)
3534 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_route_active()) {
3535 _route_group->foreach_route (boost::bind (&Route::set_active, _1, yn, _route_group));
3539 if (_active != yn) {
3541 _input->set_active (yn);
3542 _output->set_active (yn);
3543 active_changed (); // EMIT SIGNAL
3550 Glib::Threads::RWLock::ReaderLock rm (_processor_lock, Glib::Threads::TRY_LOCK);
3556 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3558 boost::shared_ptr<Send> s;
3559 boost::shared_ptr<Return> r;
3561 if ((s = boost::dynamic_pointer_cast<Send> (*i)) != 0) {
3562 s->meter()->meter();
3563 } else if ((r = boost::dynamic_pointer_cast<Return> (*i)) != 0) {
3564 r->meter()->meter ();
3569 boost::shared_ptr<Pannable>
3570 Route::pannable() const
3575 boost::shared_ptr<Panner>
3576 Route::panner() const
3579 return _main_outs->panner_shell()->panner();
3582 boost::shared_ptr<PannerShell>
3583 Route::panner_shell() const
3585 return _main_outs->panner_shell();
3588 boost::shared_ptr<AutomationControl>
3589 Route::gain_control() const
3591 return _amp->gain_control();
3594 boost::shared_ptr<AutomationControl>
3595 Route::get_control (const Evoral::Parameter& param)
3597 /* either we own the control or .... */
3599 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
3603 /* maybe one of our processors does or ... */
3605 Glib::Threads::RWLock::ReaderLock rm (_processor_lock, Glib::Threads::TRY_LOCK);
3606 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3607 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
3615 /* nobody does so we'll make a new one */
3617 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
3624 boost::shared_ptr<Processor>
3625 Route::nth_plugin (uint32_t n)
3627 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3628 ProcessorList::iterator i;
3630 for (i = _processors.begin(); i != _processors.end(); ++i) {
3631 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
3638 return boost::shared_ptr<Processor> ();
3641 boost::shared_ptr<Processor>
3642 Route::nth_send (uint32_t n)
3644 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3645 ProcessorList::iterator i;
3647 for (i = _processors.begin(); i != _processors.end(); ++i) {
3648 if (boost::dynamic_pointer_cast<Send> (*i)) {
3655 return boost::shared_ptr<Processor> ();
3659 Route::has_io_processor_named (const string& name)
3661 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3662 ProcessorList::iterator i;
3664 for (i = _processors.begin(); i != _processors.end(); ++i) {
3665 if (boost::dynamic_pointer_cast<Send> (*i) ||
3666 boost::dynamic_pointer_cast<PortInsert> (*i)) {
3667 if ((*i)->name() == name) {
3676 MuteMaster::MutePoint
3677 Route::mute_points () const
3679 return _mute_master->mute_points ();
3683 Route::set_processor_positions ()
3685 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3687 bool had_amp = false;
3688 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3689 (*i)->set_pre_fader (!had_amp);
3690 if (boost::dynamic_pointer_cast<Amp> (*i)) {
3696 /** Called when there is a proposed change to the input port count */
3698 Route::input_port_count_changing (ChanCount to)
3700 list<pair<ChanCount, ChanCount> > c = try_configure_processors (to, 0);
3702 /* The processors cannot be configured with the new input arrangement, so
3708 /* The change is ok */
3713 Route::unknown_processors () const
3717 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
3718 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3719 if (boost::dynamic_pointer_cast<UnknownProcessor const> (*i)) {
3720 p.push_back ((*i)->name ());
3729 Route::update_port_latencies (PortSet& from, PortSet& to, bool playback, framecnt_t our_latency) const
3731 /* we assume that all our input ports feed all our output ports. its not
3732 universally true, but the alternative is way too corner-case to worry about.
3735 jack_latency_range_t all_connections;
3738 all_connections.min = 0;
3739 all_connections.max = 0;
3741 all_connections.min = ~((jack_nframes_t) 0);
3742 all_connections.max = 0;
3744 /* iterate over all "from" ports and determine the latency range for all of their
3745 connections to the "outside" (outside of this Route).
3748 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
3750 jack_latency_range_t range;
3752 p->get_connected_latency_range (range, playback);
3754 all_connections.min = min (all_connections.min, range.min);
3755 all_connections.max = max (all_connections.max, range.max);
3759 /* set the "from" port latencies to the max/min range of all their connections */
3761 for (PortSet::iterator p = from.begin(); p != from.end(); ++p) {
3762 p->set_private_latency_range (all_connections, playback);
3765 /* set the ports "in the direction of the flow" to the same value as above plus our own signal latency */
3767 all_connections.min += our_latency;
3768 all_connections.max += our_latency;
3770 for (PortSet::iterator p = to.begin(); p != to.end(); ++p) {
3771 p->set_private_latency_range (all_connections, playback);
3774 return all_connections.max;
3778 Route::set_private_port_latencies (bool playback) const
3780 framecnt_t own_latency = 0;
3782 /* Processor list not protected by lock: MUST BE CALLED FROM PROCESS THREAD
3783 OR LATENCY CALLBACK.
3785 This is called (early) from the latency callback. It computes the REAL
3786 latency associated with each port and stores the result as the "private"
3787 latency of the port. A later call to Route::set_public_port_latencies()
3788 sets all ports to the same value to reflect the fact that we do latency
3789 compensation and so all signals are delayed by the same amount as they
3790 flow through ardour.
3793 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3794 if ((*i)->active ()) {
3795 own_latency += (*i)->signal_latency ();
3800 /* playback: propagate latency from "outside the route" to outputs to inputs */
3801 return update_port_latencies (_output->ports (), _input->ports (), true, own_latency);
3803 /* capture: propagate latency from "outside the route" to inputs to outputs */
3804 return update_port_latencies (_input->ports (), _output->ports (), false, own_latency);
3809 Route::set_public_port_latencies (framecnt_t value, bool playback) const
3811 /* this is called to set the JACK-visible port latencies, which take
3812 latency compensation into account.
3815 jack_latency_range_t range;
3821 const PortSet& ports (_input->ports());
3822 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
3823 p->set_public_latency_range (range, playback);
3828 const PortSet& ports (_output->ports());
3829 for (PortSet::const_iterator p = ports.begin(); p != ports.end(); ++p) {
3830 p->set_public_latency_range (range, playback);
3835 /** Put the invisible processors in the right place in _processors.
3836 * Must be called with a writer lock on _processor_lock held.
3839 Route::setup_invisible_processors ()
3842 Glib::Threads::RWLock::WriterLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
3843 assert (!lm.locked ());
3847 /* too early to be doing this stuff */
3851 /* we'll build this new list here and then use it */
3853 ProcessorList new_processors;
3855 /* find visible processors */
3857 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3858 if ((*i)->display_to_user ()) {
3859 new_processors.push_back (*i);
3865 ProcessorList::iterator amp = new_processors.begin ();
3866 while (amp != new_processors.end() && boost::dynamic_pointer_cast<Amp> (*amp) == 0) {
3870 assert (amp != _processors.end ());
3872 /* and the processor after the amp */
3874 ProcessorList::iterator after_amp = amp;
3880 switch (_meter_point) {
3882 assert (!_meter->display_to_user ());
3883 new_processors.push_front (_meter);
3886 assert (!_meter->display_to_user ());
3887 new_processors.insert (amp, _meter);
3889 case MeterPostFader:
3890 /* do nothing here */
3893 /* do nothing here */
3896 /* the meter is visible, so we don't touch it here */
3903 assert (_main_outs);
3904 assert (!_main_outs->display_to_user ());
3905 new_processors.push_back (_main_outs);
3907 /* iterator for the main outs */
3909 ProcessorList::iterator main = new_processors.end();
3912 /* OUTPUT METERING */
3914 if (_meter && (_meter_point == MeterOutput || _meter_point == MeterPostFader)) {
3915 assert (!_meter->display_to_user ());
3917 /* add the processor just before or just after the main outs */
3919 ProcessorList::iterator meter_point = main;
3921 if (_meter_point == MeterOutput) {
3924 new_processors.insert (meter_point, _meter);
3929 if (_monitor_send && !is_monitor ()) {
3930 assert (!_monitor_send->display_to_user ());
3931 if (Config->get_solo_control_is_listen_control()) {
3932 switch (Config->get_listen_position ()) {
3933 case PreFaderListen:
3934 switch (Config->get_pfl_position ()) {
3935 case PFLFromBeforeProcessors:
3936 new_processors.push_front (_monitor_send);
3938 case PFLFromAfterProcessors:
3939 new_processors.insert (amp, _monitor_send);
3942 _monitor_send->set_can_pan (false);
3944 case AfterFaderListen:
3945 switch (Config->get_afl_position ()) {
3946 case AFLFromBeforeProcessors:
3947 new_processors.insert (after_amp, _monitor_send);
3949 case AFLFromAfterProcessors:
3950 new_processors.insert (new_processors.end(), _monitor_send);
3953 _monitor_send->set_can_pan (true);
3957 new_processors.insert (new_processors.end(), _monitor_send);
3958 _monitor_send->set_can_pan (false);
3962 /* MONITOR CONTROL */
3964 if (_monitor_control && is_monitor ()) {
3965 assert (!_monitor_control->display_to_user ());
3966 new_processors.push_front (_monitor_control);
3969 /* INTERNAL RETURN */
3971 /* doing this here means that any monitor control will come just after
3976 assert (!_intreturn->display_to_user ());
3977 new_processors.push_front (_intreturn);
3980 /* EXPORT PROCESSOR */
3982 if (_capturing_processor) {
3983 assert (!_capturing_processor->display_to_user ());
3984 new_processors.push_front (_capturing_processor);
3987 _processors = new_processors;
3989 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: setup_invisible_processors\n", _name));
3990 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3991 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1\n", (*i)->name ()));
3998 Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
3999 Glib::Threads::RWLock::ReaderLock lp (_processor_lock);
4003 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4004 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*i);
4011 /** If the meter point is `Custom', make a note of where the meter is.
4012 * This is so that if the meter point is subsequently set to something else,
4013 * and then back to custom, we can put the meter back where it was last time
4014 * custom was enabled.
4016 * Must be called with the _processor_lock held.
4019 Route::maybe_note_meter_position ()
4021 if (_meter_point != MeterCustom) {
4025 _custom_meter_position_noted = true;
4026 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4027 if (boost::dynamic_pointer_cast<PeakMeter> (*i)) {
4028 ProcessorList::iterator j = i;
4030 if (j != _processors.end ()) {
4031 _processor_after_last_custom_meter = *j;
4032 _last_custom_meter_was_at_end = false;
4034 _last_custom_meter_was_at_end = true;
4040 boost::shared_ptr<Processor>
4041 Route::processor_by_id (PBD::ID id) const
4043 Glib::Threads::RWLock::ReaderLock lm (_processor_lock);
4044 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4045 if ((*i)->id() == id) {
4050 return boost::shared_ptr<Processor> ();
4053 /** @return the monitoring state, or in other words what data we are pushing
4054 * into the route (data from the inputs, data from disk or silence)
4057 Route::monitoring_state () const
4059 return MonitoringInput;
4062 /** @return what we should be metering; either the data coming from the input
4063 * IO or the data that is flowing through the route.
4066 Route::metering_state () const
4068 return MeteringRoute;
4072 Route::has_external_redirects () const
4074 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4076 /* ignore inactive processors and obviously ignore the main
4077 * outs since everything has them and we don't care.
4080 if ((*i)->active() && (*i) != _main_outs && (*i)->does_routing()) {
4088 boost::shared_ptr<Processor>
4089 Route::the_instrument () const
4091 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
4092 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
4093 if (boost::dynamic_pointer_cast<PluginInsert>(*i)) {
4094 if ((*i)->input_streams().n_midi() > 0 &&
4095 (*i)->output_streams().n_audio() > 0) {
4100 return boost::shared_ptr<Processor>();
4104 Route::non_realtime_locate (framepos_t pos)
4107 _pannable->transport_located (pos);
4111 Glib::Threads::RWLock::WriterLock lm (_processor_lock);
4113 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
4114 (*i)->transport_located (pos);