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.
25 #include "pbd/xml++.h"
26 #include "pbd/enumwriter.h"
27 #include "pbd/memento_command.h"
28 #include "pbd/stacktrace.h"
29 #include "pbd/convert.h"
31 #include "evoral/Curve.hpp"
33 #include "ardour/amp.h"
34 #include "ardour/audio_port.h"
35 #include "ardour/audioengine.h"
36 #include "ardour/buffer.h"
37 #include "ardour/buffer_set.h"
38 #include "ardour/configuration.h"
39 #include "ardour/cycle_timer.h"
40 #include "ardour/debug.h"
41 #include "ardour/delivery.h"
42 #include "ardour/dB.h"
43 #include "ardour/internal_send.h"
44 #include "ardour/internal_return.h"
45 #include "ardour/ladspa_plugin.h"
46 #include "ardour/meter.h"
47 #include "ardour/mix.h"
48 #include "ardour/monitor_processor.h"
49 #include "ardour/panner.h"
50 #include "ardour/plugin_insert.h"
51 #include "ardour/port.h"
52 #include "ardour/port_insert.h"
53 #include "ardour/processor.h"
54 #include "ardour/profile.h"
55 #include "ardour/route.h"
56 #include "ardour/route_group.h"
57 #include "ardour/send.h"
58 #include "ardour/session.h"
59 #include "ardour/timestamps.h"
60 #include "ardour/utils.h"
61 #include "ardour/graph.h"
62 #include "ardour/unknown_processor.h"
67 using namespace ARDOUR;
70 uint32_t Route::order_key_cnt = 0;
71 PBD::Signal1<void,string const&> Route::SyncOrderKeys;
72 PBD::Signal0<void> Route::RemoteControlIDChange;
74 Route::Route (Session& sess, string name, Flag flg, DataType default_type)
75 : SessionObject (sess, name)
77 , GraphNode( sess.route_graph )
82 , _pending_declick (true)
83 , _meter_point (MeterPostFader)
85 , _soloed_by_others_upstream (0)
86 , _soloed_by_others_downstream (0)
88 , _denormal_protection (false)
91 , _declickable (false)
92 , _solo_control (new SoloControllable (X_("solo"), *this))
93 , _mute_control (new MuteControllable (X_("mute"), *this))
94 , _mute_master (new MuteMaster (sess, name))
95 , _have_internal_generator (false)
97 , _default_type (default_type)
98 , _remote_control_id (0)
99 , _in_configure_processors (false)
101 processor_max_streams.reset();
102 order_keys[N_("signal")] = order_key_cnt++;
108 /* add standard controls */
110 _solo_control->set_flags (Controllable::Flag (_solo_control->flags() | Controllable::Toggle));
111 _mute_control->set_flags (Controllable::Flag (_solo_control->flags() | Controllable::Toggle));
113 add_control (_solo_control);
114 add_control (_mute_control);
116 /* input and output objects */
118 _input.reset (new IO (_session, _name, IO::Input, _default_type));
119 _output.reset (new IO (_session, _name, IO::Output, _default_type));
121 _input->changed.connect_same_thread (*this, boost::bind (&Route::input_change_handler, this, _1, _2));
122 _output->changed.connect_same_thread (*this, boost::bind (&Route::output_change_handler, this, _1, _2));
124 _input->PortCountChanging.connect_same_thread (*this, boost::bind (&Route::input_port_count_changing, this, _1));
126 /* add amp processor */
128 _amp.reset (new Amp (_session));
129 add_processor (_amp, PostFader);
131 /* add standard processors: meter, main outs, monitor out */
133 _meter.reset (new PeakMeter (_session));
134 _meter->set_display_to_user (false);
136 add_processor (_meter, PostFader);
138 _main_outs.reset (new Delivery (_session, _output, _mute_master, _name, Delivery::Main));
140 add_processor (_main_outs, PostFader);
143 /* where we listen to tracks */
144 _intreturn.reset (new InternalReturn (_session));
145 add_processor (_intreturn, PreFader);
147 ProcessorList::iterator i;
149 for (i = _processors.begin(); i != _processors.end(); ++i) {
150 if (*i == _intreturn) {
156 /* the thing that provides proper control over a control/monitor/listen bus
157 (such as per-channel cut, dim, solo, invert, etc).
158 It always goes right after the internal return;
160 _monitor_control.reset (new MonitorProcessor (_session));
161 add_processor (_monitor_control, i);
163 /* no panning on the monitor main outs */
165 _main_outs->panner()->set_bypassed (true);
168 if (is_master() || is_monitor() || is_hidden()) {
169 _mute_master->set_solo_ignore (true);
172 /* now that we have _meter, its safe to connect to this */
174 Metering::Meter.connect_same_thread (*this, (boost::bind (&Route::meter, this)));
181 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
183 /* do this early so that we don't get incoming signals as we are going through destruction
188 /* don't use clear_processors here, as it depends on the session which may
189 be half-destroyed by now
192 Glib::RWLock::WriterLock lm (_processor_lock);
193 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
194 (*i)->drop_references ();
197 _processors.clear ();
201 Route::set_remote_control_id (uint32_t id, bool notify_class_listeners)
203 if (id != _remote_control_id) {
204 _remote_control_id = id;
205 RemoteControlIDChanged ();
206 if (notify_class_listeners) {
207 RemoteControlIDChange ();
213 Route::remote_control_id() const
215 return _remote_control_id;
219 Route::order_key (std::string const & name) const
221 OrderKeys::const_iterator i = order_keys.find (name);
222 if (i == order_keys.end()) {
230 Route::set_order_key (std::string const & name, int32_t n)
232 bool changed = false;
234 /* This method looks more complicated than it should, but
235 it's important that we don't emit order_key_changed unless
236 it actually has, as expensive things happen on receipt of that
240 if (order_keys.find(name) == order_keys.end() || order_keys[name] != n) {
241 order_keys[name] = n;
245 if (Config->get_sync_all_route_ordering()) {
246 for (OrderKeys::iterator x = order_keys.begin(); x != order_keys.end(); ++x) {
247 if (x->second != n) {
255 order_key_changed (); /* EMIT SIGNAL */
256 _session.set_dirty ();
260 /** Set all order keys to be the same as that for `base', if such a key
261 * exists in this route.
262 * @param base Base key.
265 Route::sync_order_keys (std::string const & base)
267 if (order_keys.empty()) {
271 OrderKeys::iterator i;
274 if ((i = order_keys.find (base)) == order_keys.end()) {
275 /* key doesn't exist, use the first existing key (during session initialization) */
276 i = order_keys.begin();
280 /* key exists - use it and reset all others (actually, itself included) */
282 i = order_keys.begin();
285 bool changed = false;
287 for (; i != order_keys.end(); ++i) {
288 if (i->second != key) {
295 order_key_changed (); /* EMIT SIGNAL */
300 Route::ensure_track_or_route_name(string name, Session &session)
302 string newname = name;
304 while (!session.io_name_is_legal (newname)) {
305 newname = bump_name_once (newname, '.');
313 Route::inc_gain (gain_t fraction, void *src)
315 _amp->inc_gain (fraction, src);
319 Route::set_gain (gain_t val, void *src)
321 if (src != 0 && _route_group && src != _route_group && _route_group->is_active() && _route_group->is_gain()) {
323 if (_route_group->is_relative()) {
325 gain_t usable_gain = _amp->gain();
326 if (usable_gain < 0.000001f) {
327 usable_gain = 0.000001f;
331 if (delta < 0.000001f) {
335 delta -= usable_gain;
340 gain_t factor = delta / usable_gain;
343 factor = _route_group->get_max_factor(factor);
344 if (factor == 0.0f) {
345 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
349 factor = _route_group->get_min_factor(factor);
350 if (factor == 0.0f) {
351 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
356 _route_group->apply (&Route::inc_gain, factor, _route_group);
360 _route_group->apply (&Route::set_gain, val, _route_group);
366 if (val == _amp->gain()) {
370 _amp->set_gain (val, src);
373 /** Process this route for one (sub) cycle (process thread)
375 * @param bufs Scratch buffers to use for the signal path
376 * @param start_frame Initial transport frame
377 * @param end_frame Final transport frame
378 * @param nframes Number of frames to output (to ports)
380 * Note that (end_frame - start_frame) may not be equal to nframes when the
381 * transport speed isn't 1.0 (eg varispeed).
384 Route::process_output_buffers (BufferSet& bufs,
385 framepos_t start_frame, framepos_t end_frame, nframes_t nframes,
386 bool /*with_processors*/, int declick)
390 bufs.is_silent (false);
392 switch (Config->get_monitoring_model()) {
393 case HardwareMonitoring:
394 case ExternalMonitoring:
395 monitor = !record_enabled() || (_session.config.get_auto_input() && !_session.actively_recording());
402 declick = _pending_declick;
405 /* figure out if we're going to use gain automation */
406 _amp->setup_gain_automation (start_frame, end_frame, nframes);
409 /* tell main outs what to do about monitoring */
410 _main_outs->no_outs_cuz_we_no_monitor (!monitor);
413 /* -------------------------------------------------------------------------------------------
414 GLOBAL DECLICK (for transport changes etc.)
415 ----------------------------------------------------------------------------------------- */
418 Amp::declick (bufs, nframes, 1);
419 } else if (declick < 0) {
420 Amp::declick (bufs, nframes, -1);
423 _pending_declick = 0;
425 /* -------------------------------------------------------------------------------------------
426 DENORMAL CONTROL/PHASE INVERT
427 ----------------------------------------------------------------------------------------- */
429 if (_phase_invert.any ()) {
433 if (_denormal_protection || Config->get_denormal_protection()) {
435 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
436 Sample* const sp = i->data();
438 if (_phase_invert[chn]) {
439 for (nframes_t nx = 0; nx < nframes; ++nx) {
444 for (nframes_t nx = 0; nx < nframes; ++nx) {
452 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
453 Sample* const sp = i->data();
455 if (_phase_invert[chn]) {
456 for (nframes_t nx = 0; nx < nframes; ++nx) {
465 if (_denormal_protection || Config->get_denormal_protection()) {
467 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
468 Sample* const sp = i->data();
469 for (nframes_t nx = 0; nx < nframes; ++nx) {
477 /* -------------------------------------------------------------------------------------------
479 ----------------------------------------------------------------------------------------- */
481 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
483 if (boost::dynamic_pointer_cast<UnknownProcessor> (*i)) {
487 if (bufs.count() != (*i)->input_streams()) {
488 cerr << _name << " bufs = " << bufs.count()
489 << " input for " << (*i)->name() << " = " << (*i)->input_streams()
492 assert (bufs.count() == (*i)->input_streams());
494 /* should we NOT run plugins here if the route is inactive?
495 do we catch route != active somewhere higher?
498 (*i)->run (bufs, start_frame, end_frame, nframes, *i != _processors.back());
499 bufs.set_count ((*i)->output_streams());
504 Route::n_process_buffers ()
506 return max (_input->n_ports(), processor_max_streams);
510 Route::passthru (framepos_t start_frame, framepos_t end_frame, nframes_t nframes, int declick)
512 BufferSet& bufs = _session.get_scratch_buffers (n_process_buffers());
516 assert (bufs.available() >= input_streams());
518 if (_input->n_ports() == ChanCount::ZERO) {
519 silence_unlocked (nframes);
522 bufs.set_count (input_streams());
524 if (is_monitor() && _session.listening() && !_session.is_auditioning()) {
526 /* control/monitor bus ignores input ports when something is
527 feeding the listen "stream". data will "arrive" into the
528 route from the intreturn processor element.
530 bufs.silence (nframes, 0);
534 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
536 BufferSet::iterator o = bufs.begin(*t);
537 PortSet& ports (_input->ports());
539 for (PortSet::iterator i = ports.begin(*t); i != ports.end(*t); ++i, ++o) {
540 o->read_from (i->get_buffer(nframes), nframes);
545 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
546 process_output_buffers (bufs, start_frame, end_frame, nframes, true, declick);
550 Route::passthru_silence (framepos_t start_frame, framepos_t end_frame, nframes_t nframes, int declick)
552 BufferSet& bufs (_session.get_silent_buffers (n_process_buffers()));
553 bufs.set_count (_input->n_ports());
554 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
555 process_output_buffers (bufs, start_frame, end_frame, nframes, true, declick);
559 Route::set_listen (bool yn, void* src)
566 if (yn != _monitor_send->active()) {
568 _monitor_send->activate ();
569 _mute_master->set_soloed (true);
571 _monitor_send->deactivate ();
572 _mute_master->set_soloed (false);
575 listen_changed (src); /* EMIT SIGNAL */
581 Route::listening () const
584 return _monitor_send->active ();
591 Route::set_solo_safe (bool yn, void *src)
593 if (_solo_safe != yn) {
595 solo_safe_changed (src);
600 Route::solo_safe() const
606 Route::set_solo (bool yn, void *src)
612 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_solo()) {
613 _route_group->apply (&Route::set_solo, yn, _route_group);
617 if (self_soloed() != yn) {
619 set_mute_master_solo ();
620 solo_changed (true, src); /* EMIT SIGNAL */
621 _solo_control->Changed (); /* EMIT SIGNAL */
626 Route::set_self_solo (bool yn)
632 Route::mod_solo_by_others_upstream (int32_t delta)
638 uint32_t old_sbu = _soloed_by_others_upstream;
641 if (_soloed_by_others_upstream >= (uint32_t) abs (delta)) {
642 _soloed_by_others_upstream += delta;
644 _soloed_by_others_upstream = 0;
647 _soloed_by_others_upstream += delta;
650 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 SbU delta %2 = %3 old = %4 sbd %5 ss %6 exclusive %7\n",
651 name(), delta, _soloed_by_others_upstream, old_sbu,
652 _soloed_by_others_downstream, _self_solo, Config->get_exclusive_solo()));
654 /* push the inverse solo change to everything that feeds us.
656 This is important for solo-within-group. When we solo 1 track out of N that
657 feed a bus, that track will cause mod_solo_by_upstream (+1) to be called
658 on the bus. The bus then needs to call mod_solo_by_downstream (-1) on all
659 tracks that feed it. This will silence them if they were audible because
660 of a bus solo, but the newly soloed track will still be audible (because
663 but .. do this only when we are being told to solo-by-upstream (i.e delta = +1),
667 if ((_self_solo || _soloed_by_others_downstream) &&
668 ((old_sbu == 0 && _soloed_by_others_upstream > 0) ||
669 (old_sbu > 0 && _soloed_by_others_upstream == 0))) {
671 if (delta > 0 || !Config->get_exclusive_solo()) {
672 DEBUG_TRACE (DEBUG::Solo, "\t ... INVERT push\n");
673 for (FedBy::iterator i = _fed_by.begin(); i != _fed_by.end(); ++i) {
674 boost::shared_ptr<Route> sr = i->r.lock();
676 sr->mod_solo_by_others_downstream (-delta);
682 set_mute_master_solo ();
683 solo_changed (false, this);
687 Route::mod_solo_by_others_downstream (int32_t delta)
694 if (_soloed_by_others_downstream >= (uint32_t) abs (delta)) {
695 _soloed_by_others_downstream += delta;
697 _soloed_by_others_downstream = 0;
700 _soloed_by_others_downstream += delta;
703 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 SbD delta %2 = %3\n", name(), delta, _soloed_by_others_downstream));
705 set_mute_master_solo ();
706 solo_changed (false, this);
710 Route::set_mute_master_solo ()
712 _mute_master->set_soloed (self_soloed() || soloed_by_others_downstream() || soloed_by_others_upstream());
716 Route::set_solo_isolated (bool yn, void *src)
718 if (is_master() || is_monitor() || is_hidden()) {
722 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_solo()) {
723 _route_group->apply (&Route::set_solo_isolated, yn, _route_group);
727 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
729 boost::shared_ptr<RouteList> routes = _session.get_routes ();
730 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
732 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_hidden()) {
737 bool does_feed = direct_feeds (*i, &sends_only); // we will recurse anyway, so don't use ::feeds()
739 if (does_feed && !sends_only) {
740 (*i)->set_solo_isolated (yn, (*i)->route_group());
744 /* XXX should we back-propagate as well? (April 2010: myself and chris goddard think not) */
746 bool changed = false;
749 if (_solo_isolated == 0) {
750 _mute_master->set_solo_ignore (true);
755 if (_solo_isolated > 0) {
757 if (_solo_isolated == 0) {
758 _mute_master->set_solo_ignore (false);
765 solo_isolated_changed (src);
770 Route::solo_isolated () const
772 return _solo_isolated > 0;
776 Route::set_mute_points (MuteMaster::MutePoint mp)
778 _mute_master->set_mute_points (mp);
779 mute_points_changed (); /* EMIT SIGNAL */
781 if (_mute_master->muted_by_self()) {
782 mute_changed (this); /* EMIT SIGNAL */
787 Route::set_mute (bool yn, void *src)
789 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_mute()) {
790 _route_group->apply (&Route::set_mute, yn, _route_group);
795 _mute_master->set_muted_by_self (yn);
796 mute_changed (src); /* EMIT SIGNAL */
801 Route::muted () const
803 return _mute_master->muted_by_self();
808 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
810 cerr << name << " {" << endl;
811 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
812 p != procs.end(); ++p) {
813 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << endl;
820 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err)
822 ProcessorList::iterator loc;
824 /* XXX this is not thread safe - we don't hold the lock across determining the iter
825 to add before and actually doing the insertion. dammit.
828 if (placement == PreFader) {
829 /* generic pre-fader: insert immediately before the amp */
830 loc = find (_processors.begin(), _processors.end(), _amp);
832 /* generic post-fader: insert right before the main outs */
833 loc = find (_processors.begin(), _processors.end(), _main_outs);
836 return add_processor (processor, loc, err);
840 /** Add a processor to the route.
841 * @a iter must point to an iterator in _processors and the new
842 * processor will be inserted immediately before this location. Otherwise,
843 * @a position is used.
846 Route::add_processor (boost::shared_ptr<Processor> processor, ProcessorList::iterator iter, ProcessorStreams* err, bool activation_allowed)
848 ChanCount old_pms = processor_max_streams;
850 if (!_session.engine().connected() || !processor) {
855 Glib::RWLock::WriterLock lm (_processor_lock);
857 boost::shared_ptr<PluginInsert> pi;
858 boost::shared_ptr<PortInsert> porti;
860 ProcessorList::iterator loc = find(_processors.begin(), _processors.end(), processor);
862 if (processor == _amp || processor == _meter || processor == _main_outs) {
863 // Ensure only one of these are in the list at any time
864 if (loc != _processors.end()) {
865 if (iter == loc) { // Already in place, do nothing
867 } else { // New position given, relocate
868 _processors.erase (loc);
873 if (loc != _processors.end()) {
874 cerr << "ERROR: Processor added to route twice!" << endl;
881 _processors.insert (loc, processor);
883 // Set up processor list channels. This will set processor->[input|output]_streams(),
884 // configure redirect ports properly, etc.
887 Glib::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
889 if (configure_processors_unlocked (err)) {
890 ProcessorList::iterator ploc = loc;
892 _processors.erase(ploc);
893 configure_processors_unlocked (0); // it worked before we tried to add it ...
894 cerr << "configure failed\n";
899 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
901 if (pi->natural_input_streams() == ChanCount::ZERO) {
902 /* generator plugin */
903 _have_internal_generator = true;
908 /* is this the monitor send ? if so, make sure we keep track of it */
910 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
912 if (isend && _session.monitor_out() && (isend->target_id() == _session.monitor_out()->id())) {
913 _monitor_send = isend;
916 if (activation_allowed && (processor != _monitor_send)) {
917 processor->activate ();
920 processor->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false, false));
922 _output->set_user_latency (0);
925 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
926 set_processor_positions ();
932 Route::add_processor_from_xml_2X (const XMLNode& node, int version)
934 const XMLProperty *prop;
937 boost::shared_ptr<Processor> processor;
939 /* bit of a hack: get the `placement' property from the <Redirect> tag here
940 so that we can add the processor in the right place (pre/post-fader)
943 XMLNodeList const & children = node.children ();
944 XMLNodeList::const_iterator i = children.begin ();
946 while (i != children.end() && (*i)->name() != X_("Redirect")) {
950 Placement placement = PreFader;
952 if (i != children.end()) {
953 if ((prop = (*i)->property (X_("placement"))) != 0) {
954 placement = Placement (string_2_enum (prop->value(), placement));
958 if (node.name() == "Insert") {
960 if ((prop = node.property ("type")) != 0) {
962 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
963 prop->value() == "lv2" ||
964 prop->value() == "vst" ||
965 prop->value() == "audiounit") {
967 processor.reset (new PluginInsert (_session));
971 processor.reset (new PortInsert (_session, _mute_master));
976 } else if (node.name() == "Send") {
978 processor.reset (new Send (_session, _mute_master));
982 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
986 if (processor->set_state (node, version)) {
990 return (add_processor (processor, placement) == 0);
993 catch (failed_constructor &err) {
994 warning << _("processor could not be created. Ignored.") << endmsg;
1000 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
1002 ProcessorList::iterator loc;
1005 loc = find(_processors.begin(), _processors.end(), before);
1007 /* nothing specified - at end but before main outs */
1008 loc = find (_processors.begin(), _processors.end(), _main_outs);
1011 return add_processors (others, loc, err);
1015 Route::add_processors (const ProcessorList& others, ProcessorList::iterator iter, ProcessorStreams* err)
1017 /* NOTE: this is intended to be used ONLY when copying
1018 processors from another Route. Hence the subtle
1019 differences between this and ::add_processor()
1022 ChanCount old_pms = processor_max_streams;
1024 if (!_session.engine().connected()) {
1028 if (others.empty()) {
1033 Glib::RWLock::WriterLock lm (_processor_lock);
1035 ChanCount potential_max_streams = ChanCount::max (_input->n_ports(), _output->n_ports());
1037 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1039 // Ensure meter only appears in the list once
1041 ProcessorList::iterator m = find(_processors.begin(), _processors.end(), *i);
1042 if (m != _processors.end()) {
1043 _processors.erase(m);
1047 boost::shared_ptr<PluginInsert> pi;
1049 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1052 ChanCount m = max (pi->input_streams(), pi->output_streams());
1054 if (m > potential_max_streams) {
1055 potential_max_streams = m;
1059 ProcessorList::iterator inserted = _processors.insert (iter, *i);
1061 if ((*i)->active()) {
1066 Glib::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
1067 if (configure_processors_unlocked (err)) {
1068 _processors.erase (inserted);
1069 configure_processors_unlocked (0); // it worked before we tried to add it ...
1074 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false, false));
1077 _output->set_user_latency (0);
1080 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1081 set_processor_positions ();
1087 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1089 if (p == PreFader) {
1090 start = _processors.begin();
1091 end = find(_processors.begin(), _processors.end(), _amp);
1093 start = find(_processors.begin(), _processors.end(), _amp);
1095 end = _processors.end();
1099 /** Turn off all processors with a given placement
1100 * @param p Placement of processors to disable
1103 Route::disable_processors (Placement p)
1105 Glib::RWLock::ReaderLock lm (_processor_lock);
1107 ProcessorList::iterator start, end;
1108 placement_range(p, start, end);
1110 for (ProcessorList::iterator i = start; i != end; ++i) {
1111 (*i)->deactivate ();
1114 _session.set_dirty ();
1117 /** Turn off all redirects
1120 Route::disable_processors ()
1122 Glib::RWLock::ReaderLock lm (_processor_lock);
1124 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1125 (*i)->deactivate ();
1128 _session.set_dirty ();
1131 /** Turn off all redirects with a given placement
1132 * @param p Placement of redirects to disable
1135 Route::disable_plugins (Placement p)
1137 Glib::RWLock::ReaderLock lm (_processor_lock);
1139 ProcessorList::iterator start, end;
1140 placement_range(p, start, end);
1142 for (ProcessorList::iterator i = start; i != end; ++i) {
1143 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1144 (*i)->deactivate ();
1148 _session.set_dirty ();
1151 /** Turn off all plugins
1154 Route::disable_plugins ()
1156 Glib::RWLock::ReaderLock lm (_processor_lock);
1158 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1159 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1160 (*i)->deactivate ();
1164 _session.set_dirty ();
1169 Route::ab_plugins (bool forward)
1171 Glib::RWLock::ReaderLock lm (_processor_lock);
1175 /* forward = turn off all active redirects, and mark them so that the next time
1176 we go the other way, we will revert them
1179 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1180 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1184 if ((*i)->active()) {
1185 (*i)->deactivate ();
1186 (*i)->set_next_ab_is_active (true);
1188 (*i)->set_next_ab_is_active (false);
1194 /* backward = if the redirect was marked to go active on the next ab, do so */
1196 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1198 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1202 if ((*i)->get_next_ab_is_active()) {
1205 (*i)->deactivate ();
1210 _session.set_dirty ();
1214 /** Remove processors with a given placement.
1215 * @param p Placement of processors to remove.
1218 Route::clear_processors (Placement p)
1220 const ChanCount old_pms = processor_max_streams;
1222 if (!_session.engine().connected()) {
1226 bool already_deleting = _session.deletion_in_progress();
1227 if (!already_deleting) {
1228 _session.set_deletion_in_progress();
1232 Glib::RWLock::WriterLock lm (_processor_lock);
1233 ProcessorList new_list;
1234 ProcessorStreams err;
1235 bool seen_amp = false;
1237 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1243 if ((*i) == _amp || (*i) == _meter || (*i) == _main_outs) {
1245 /* you can't remove these */
1247 new_list.push_back (*i);
1254 new_list.push_back (*i);
1257 (*i)->drop_references ();
1265 (*i)->drop_references ();
1268 new_list.push_back (*i);
1275 _processors = new_list;
1278 Glib::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
1279 configure_processors_unlocked (&err); // this can't fail
1283 processor_max_streams.reset();
1284 _have_internal_generator = false;
1285 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1286 set_processor_positions ();
1288 if (!already_deleting) {
1289 _session.clear_deletion_in_progress();
1294 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err)
1296 /* these can never be removed */
1298 if (processor == _amp || processor == _meter || processor == _main_outs) {
1302 ChanCount old_pms = processor_max_streams;
1304 if (!_session.engine().connected()) {
1308 processor_max_streams.reset();
1311 Glib::RWLock::WriterLock lm (_processor_lock);
1312 ProcessorList::iterator i;
1313 bool removed = false;
1315 for (i = _processors.begin(); i != _processors.end(); ) {
1316 if (*i == processor) {
1318 /* move along, see failure case for configure_processors()
1319 where we may need to reconfigure the processor.
1322 /* stop redirects that send signals to JACK ports
1323 from causing noise as a result of no longer being
1327 boost::shared_ptr<IOProcessor> iop;
1329 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (*i)) != 0) {
1331 iop->input()->disconnect (this);
1333 if (iop->output()) {
1334 iop->output()->disconnect (this);
1338 i = _processors.erase (i);
1346 _output->set_user_latency (0);
1355 Glib::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
1357 if (configure_processors_unlocked (err)) {
1358 /* get back to where we where */
1359 _processors.insert (i, processor);
1360 /* we know this will work, because it worked before :) */
1361 configure_processors_unlocked (0);
1366 _have_internal_generator = false;
1368 for (i = _processors.begin(); i != _processors.end(); ++i) {
1369 boost::shared_ptr<PluginInsert> pi;
1371 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1372 if (pi->is_generator()) {
1373 _have_internal_generator = true;
1380 processor->drop_references ();
1381 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1382 set_processor_positions ();
1388 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1390 ProcessorList deleted;
1392 if (!_session.engine().connected()) {
1396 processor_max_streams.reset();
1399 Glib::RWLock::WriterLock lm (_processor_lock);
1400 ProcessorList::iterator i;
1401 boost::shared_ptr<Processor> processor;
1403 ProcessorList as_we_were = _processors;
1405 for (i = _processors.begin(); i != _processors.end(); ) {
1409 /* these can never be removed */
1411 if (processor == _amp || processor == _meter || processor == _main_outs) {
1416 /* see if its in the list of processors to delete */
1418 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1423 /* stop IOProcessors that send to JACK ports
1424 from causing noise as a result of no longer being
1428 boost::shared_ptr<IOProcessor> iop;
1430 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (processor)) != 0) {
1434 deleted.push_back (processor);
1435 i = _processors.erase (i);
1438 if (deleted.empty()) {
1439 /* none of those in the requested list were found */
1443 _output->set_user_latency (0);
1446 Glib::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
1448 if (configure_processors_unlocked (err)) {
1449 /* get back to where we where */
1450 _processors = as_we_were;
1451 /* we know this will work, because it worked before :) */
1452 configure_processors_unlocked (0);
1457 _have_internal_generator = false;
1459 for (i = _processors.begin(); i != _processors.end(); ++i) {
1460 boost::shared_ptr<PluginInsert> pi;
1462 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1463 if (pi->is_generator()) {
1464 _have_internal_generator = true;
1471 /* now try to do what we need to so that those that were removed will be deleted */
1473 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1474 (*i)->drop_references ();
1477 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1478 set_processor_positions ();
1483 /** Caller must hold process lock */
1485 Route::configure_processors (ProcessorStreams* err)
1487 assert (!AudioEngine::instance()->process_lock().trylock());
1489 if (!_in_configure_processors) {
1490 Glib::RWLock::WriterLock lm (_processor_lock);
1491 return configure_processors_unlocked (err);
1497 Route::input_streams () const
1499 return _input->n_ports ();
1502 list<pair<ChanCount, ChanCount> >
1503 Route::try_configure_processors (ChanCount in, ProcessorStreams* err)
1505 Glib::RWLock::ReaderLock lm (_processor_lock);
1507 return try_configure_processors_unlocked (in, err);
1510 list<pair<ChanCount, ChanCount> >
1511 Route::try_configure_processors_unlocked (ChanCount in, ProcessorStreams* err)
1513 // Check each processor in order to see if we can configure as requested
1515 list<pair<ChanCount, ChanCount> > configuration;
1518 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1519 DEBUG_TRACE (DEBUG::Processors, "{\n");
1521 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1523 if (boost::dynamic_pointer_cast<UnknownProcessor> (*p)) {
1524 DEBUG_TRACE (DEBUG::Processors, "--- CONFIGURE ABORTED due to unknown processor.\n");
1528 if ((*p)->can_support_io_configuration(in, out)) {
1529 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID=%2 in=%3 out=%4\n",(*p)->name(), (*p)->id(), in, out));
1530 configuration.push_back(make_pair(in, out));
1537 DEBUG_TRACE (DEBUG::Processors, "---- CONFIGURATION FAILED.\n");
1538 DEBUG_TRACE (DEBUG::Processors, string_compose ("---- %1 cannot support in=%2 out=%3\n", (*p)->name(), in, out));
1539 DEBUG_TRACE (DEBUG::Processors, "}\n");
1540 return list<pair<ChanCount, ChanCount> > ();
1544 DEBUG_TRACE (DEBUG::Processors, "}\n");
1546 return configuration;
1549 /** Set the input/output configuration of each processor in the processors list.
1550 * Caller must hold process lock.
1551 * Return 0 on success, otherwise configuration is impossible.
1554 Route::configure_processors_unlocked (ProcessorStreams* err)
1556 assert (!AudioEngine::instance()->process_lock().trylock());
1558 if (_in_configure_processors) {
1562 _in_configure_processors = true;
1564 list<pair<ChanCount, ChanCount> > configuration = try_configure_processors_unlocked (input_streams (), err);
1566 if (configuration.empty ()) {
1567 _in_configure_processors = false;
1573 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1574 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1576 if (boost::dynamic_pointer_cast<UnknownProcessor> (*p)) {
1580 (*p)->configure_io(c->first, c->second);
1581 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1582 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1587 _meter->reset_max_channels (processor_max_streams);
1590 /* make sure we have sufficient scratch buffers to cope with the new processor
1592 _session.ensure_buffers (n_process_buffers ());
1594 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configuration complete\n", _name));
1596 _in_configure_processors = false;
1601 Route::all_processors_flip ()
1603 Glib::RWLock::ReaderLock lm (_processor_lock);
1605 if (_processors.empty()) {
1609 bool first_is_on = _processors.front()->active();
1611 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1613 (*i)->deactivate ();
1619 _session.set_dirty ();
1622 /** Set all processors with a given placement to a given active state.
1623 * @param p Placement of processors to change.
1624 * @param state New active state for those processors.
1627 Route::all_processors_active (Placement p, bool state)
1629 Glib::RWLock::ReaderLock lm (_processor_lock);
1631 if (_processors.empty()) {
1634 ProcessorList::iterator start, end;
1635 placement_range(p, start, end);
1637 bool before_amp = true;
1638 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1643 if (p == PreFader && before_amp) {
1647 (*i)->deactivate ();
1652 _session.set_dirty ();
1656 Route::processor_is_prefader (boost::shared_ptr<Processor> p)
1658 bool pre_fader = true;
1659 Glib::RWLock::ReaderLock lm (_processor_lock);
1661 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1663 /* semantic note: if p == amp, we want to return true, so test
1664 for equality before checking if this is the amp
1681 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
1683 /* "new_order" is an ordered list of processors to be positioned according to "placement".
1684 NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
1685 processors in the current actual processor list that are hidden. Any visible processors
1686 in the current list but not in "new_order" will be assumed to be deleted.
1690 Glib::RWLock::WriterLock lm (_processor_lock);
1691 ChanCount old_pms = processor_max_streams;
1692 ProcessorList::iterator oiter;
1693 ProcessorList::const_iterator niter;
1694 ProcessorList as_it_was_before = _processors;
1695 ProcessorList as_it_will_be;
1697 oiter = _processors.begin();
1698 niter = new_order.begin();
1700 while (niter != new_order.end()) {
1702 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
1703 then append it to the temp list.
1705 Otherwise, see if the next processor in the old list is in the new list. if not,
1706 its been deleted. If its there, append it to the temp list.
1709 if (oiter == _processors.end()) {
1711 /* no more elements in the old list, so just stick the rest of
1712 the new order onto the temp list.
1715 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
1716 while (niter != new_order.end()) {
1723 if (!(*oiter)->display_to_user()) {
1725 as_it_will_be.push_back (*oiter);
1729 /* visible processor: check that its in the new order */
1731 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
1732 /* deleted: do nothing, shared_ptr<> will clean up */
1734 /* ignore this one, and add the next item from the new order instead */
1735 as_it_will_be.push_back (*niter);
1740 /* now remove from old order - its taken care of no matter what */
1741 oiter = _processors.erase (oiter);
1746 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
1749 Glib::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
1751 if (configure_processors_unlocked (err)) {
1752 _processors = as_it_was_before;
1753 processor_max_streams = old_pms;
1760 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1761 set_processor_positions ();
1774 Route::get_template()
1776 return state(false);
1780 Route::state(bool full_state)
1782 XMLNode *node = new XMLNode("Route");
1783 ProcessorList::iterator i;
1786 id().print (buf, sizeof (buf));
1787 node->add_property("id", buf);
1788 node->add_property ("name", _name);
1789 node->add_property("default-type", _default_type.to_string());
1792 node->add_property("flags", enum_2_string (_flags));
1795 node->add_property("active", _active?"yes":"no");
1797 boost::to_string (_phase_invert, p);
1798 node->add_property("phase-invert", p);
1799 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
1800 node->add_property("meter-point", enum_2_string (_meter_point));
1803 node->add_property("route-group", _route_group->name());
1806 string order_string;
1807 OrderKeys::iterator x = order_keys.begin();
1809 while (x != order_keys.end()) {
1810 order_string += string ((*x).first);
1811 order_string += '=';
1812 snprintf (buf, sizeof(buf), "%ld", (*x).second);
1813 order_string += buf;
1817 if (x == order_keys.end()) {
1821 order_string += ':';
1823 node->add_property ("order-keys", order_string);
1824 node->add_property ("self-solo", (_self_solo ? "yes" : "no"));
1825 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_upstream);
1826 node->add_property ("soloed-by-upstream", buf);
1827 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_downstream);
1828 node->add_property ("soloed-by-downstream", buf);
1829 node->add_property ("solo-isolated", solo_isolated() ? "yes" : "no");
1830 node->add_property ("solo-safe", _solo_safe ? "yes" : "no");
1832 node->add_child_nocopy (_input->state (full_state));
1833 node->add_child_nocopy (_output->state (full_state));
1834 node->add_child_nocopy (_solo_control->get_state ());
1835 node->add_child_nocopy (_mute_master->get_state ());
1837 XMLNode* remote_control_node = new XMLNode (X_("RemoteControl"));
1838 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
1839 remote_control_node->add_property (X_("id"), buf);
1840 node->add_child_nocopy (*remote_control_node);
1842 if (_comment.length()) {
1843 XMLNode *cmt = node->add_child ("Comment");
1844 cmt->add_content (_comment);
1847 for (i = _processors.begin(); i != _processors.end(); ++i) {
1848 node->add_child_nocopy((*i)->state (full_state));
1852 node->add_child_copy (*_extra_xml);
1859 Route::set_state (const XMLNode& node, int version)
1861 return _set_state (node, version, true);
1865 Route::_set_state (const XMLNode& node, int version, bool /*call_base*/)
1867 if (version < 3000) {
1868 return _set_state_2X (node, version);
1872 XMLNodeConstIterator niter;
1874 const XMLProperty *prop;
1876 if (node.name() != "Route"){
1877 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
1881 if ((prop = node.property (X_("name"))) != 0) {
1882 Route::set_name (prop->value());
1885 if ((prop = node.property ("id")) != 0) {
1886 _id = prop->value ();
1889 if ((prop = node.property (X_("flags"))) != 0) {
1890 _flags = Flag (string_2_enum (prop->value(), _flags));
1895 if (is_master() || is_monitor() || is_hidden()) {
1896 _mute_master->set_solo_ignore (true);
1899 /* add all processors (except amp, which is always present) */
1901 nlist = node.children();
1902 XMLNode processor_state (X_("processor_state"));
1904 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1908 if (child->name() == IO::state_node_name) {
1909 if ((prop = child->property (X_("direction"))) == 0) {
1913 if (prop->value() == "Input") {
1914 _input->set_state (*child, version);
1915 } else if (prop->value() == "Output") {
1916 _output->set_state (*child, version);
1920 if (child->name() == X_("Processor")) {
1921 processor_state.add_child_copy (*child);
1925 set_processor_state (processor_state);
1927 if ((prop = node.property ("self-solo")) != 0) {
1928 set_self_solo (string_is_affirmative (prop->value()));
1931 if ((prop = node.property ("soloed-by-upstream")) != 0) {
1932 _soloed_by_others_upstream = 0; // needed for mod_.... () to work
1933 mod_solo_by_others_upstream (atoi (prop->value()));
1936 if ((prop = node.property ("soloed-by-downstream")) != 0) {
1937 _soloed_by_others_downstream = 0; // needed for mod_.... () to work
1938 mod_solo_by_others_downstream (atoi (prop->value()));
1941 if ((prop = node.property ("solo-isolated")) != 0) {
1942 set_solo_isolated (string_is_affirmative (prop->value()), this);
1945 if ((prop = node.property ("solo-safe")) != 0) {
1946 set_solo_safe (string_is_affirmative (prop->value()), this);
1949 if ((prop = node.property (X_("phase-invert"))) != 0) {
1950 set_phase_invert (boost::dynamic_bitset<> (prop->value ()));
1953 if ((prop = node.property (X_("denormal-protection"))) != 0) {
1954 set_denormal_protection (string_is_affirmative (prop->value()));
1957 if ((prop = node.property (X_("active"))) != 0) {
1958 bool yn = string_is_affirmative (prop->value());
1959 _active = !yn; // force switch
1963 if ((prop = node.property (X_("meter-point"))) != 0) {
1964 MeterPoint mp = MeterPoint (string_2_enum (prop->value (), _meter_point));
1965 set_meter_point (mp);
1967 _meter->set_display_to_user (_meter_point == MeterCustom);
1971 if ((prop = node.property (X_("order-keys"))) != 0) {
1975 string::size_type colon, equal;
1976 string remaining = prop->value();
1978 while (remaining.length()) {
1980 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
1981 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1984 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
1985 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1988 set_order_key (remaining.substr (0, equal), n);
1992 colon = remaining.find_first_of (':');
1994 if (colon != string::npos) {
1995 remaining = remaining.substr (colon+1);
2002 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2005 if (child->name() == X_("Comment")) {
2007 /* XXX this is a terrible API design in libxml++ */
2009 XMLNode *cmt = *(child->children().begin());
2010 _comment = cmt->content();
2012 } else if (child->name() == X_("Extra")) {
2014 _extra_xml = new XMLNode (*child);
2016 } else if (child->name() == X_("Controllable") && (prop = child->property("name")) != 0) {
2018 if (prop->value() == "solo") {
2019 _solo_control->set_state (*child, version);
2020 _session.add_controllable (_solo_control);
2023 } else if (child->name() == X_("RemoteControl")) {
2024 if ((prop = child->property (X_("id"))) != 0) {
2026 sscanf (prop->value().c_str(), "%d", &x);
2027 set_remote_control_id (x);
2030 } else if (child->name() == X_("MuteMaster")) {
2031 _mute_master->set_state (*child, version);
2039 Route::_set_state_2X (const XMLNode& node, int version)
2042 XMLNodeConstIterator niter;
2044 const XMLProperty *prop;
2046 /* 2X things which still remain to be handled:
2052 if (node.name() != "Route") {
2053 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2057 if ((prop = node.property (X_("flags"))) != 0) {
2058 _flags = Flag (string_2_enum (prop->value(), _flags));
2063 if ((prop = node.property (X_("phase-invert"))) != 0) {
2064 boost::dynamic_bitset<> p (_input->n_ports().n_audio ());
2065 if (string_is_affirmative (prop->value ())) {
2068 set_phase_invert (p);
2071 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2072 set_denormal_protection (string_is_affirmative (prop->value()));
2075 if ((prop = node.property (X_("soloed"))) != 0) {
2076 bool yn = string_is_affirmative (prop->value());
2078 /* XXX force reset of solo status */
2080 set_solo (yn, this);
2083 if ((prop = node.property (X_("muted"))) != 0) {
2086 bool muted = string_is_affirmative (prop->value());
2092 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2094 if (string_is_affirmative (prop->value())){
2095 mute_point = mute_point + "PreFader";
2100 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2102 if (string_is_affirmative (prop->value())){
2105 mute_point = mute_point + ",";
2108 mute_point = mute_point + "PostFader";
2113 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2115 if (string_is_affirmative (prop->value())){
2118 mute_point = mute_point + ",";
2121 mute_point = mute_point + "Listen";
2126 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2128 if (string_is_affirmative (prop->value())){
2131 mute_point = mute_point + ",";
2134 mute_point = mute_point + "Main";
2138 _mute_master->set_mute_points (mute_point);
2142 if ((prop = node.property (X_("meter-point"))) != 0) {
2143 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2146 /* do not carry over edit/mix groups from 2.X because (a) its hard (b) they
2147 don't mean the same thing.
2150 if ((prop = node.property (X_("order-keys"))) != 0) {
2154 string::size_type colon, equal;
2155 string remaining = prop->value();
2157 while (remaining.length()) {
2159 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2160 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2163 if (sscanf (remaining.substr (equal+1).c_str(), "%d", &n) != 1) {
2164 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2167 set_order_key (remaining.substr (0, equal), n);
2171 colon = remaining.find_first_of (':');
2173 if (colon != string::npos) {
2174 remaining = remaining.substr (colon+1);
2183 nlist = node.children ();
2184 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2188 if (child->name() == IO::state_node_name) {
2190 /* there is a note in IO::set_state_2X() about why we have to call
2194 _input->set_state_2X (*child, version, true);
2195 _output->set_state_2X (*child, version, false);
2197 if ((prop = child->property (X_("name"))) != 0) {
2198 Route::set_name (prop->value ());
2201 if ((prop = child->property (X_("id"))) != 0) {
2202 _id = prop->value ();
2205 if ((prop = child->property (X_("active"))) != 0) {
2206 bool yn = string_is_affirmative (prop->value());
2207 _active = !yn; // force switch
2211 if ((prop = child->property (X_("gain"))) != 0) {
2214 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
2215 _amp->gain_control()->set_value (val);
2219 /* Set up Panners in the IO */
2220 XMLNodeList io_nlist = child->children ();
2222 XMLNodeConstIterator io_niter;
2225 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
2227 io_child = *io_niter;
2229 if (io_child->name() == X_("Panner")) {
2230 _main_outs->panner()->set_state(*io_child, version);
2231 } else if (io_child->name() == X_("Automation")) {
2232 /* IO's automation is for the fader */
2233 _amp->set_automation_xml_state (*io_child, Evoral::Parameter (GainAutomation));
2239 XMLNodeList redirect_nodes;
2241 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2245 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2246 redirect_nodes.push_back(child);
2251 set_processor_state_2X (redirect_nodes, version);
2253 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2256 if (child->name() == X_("Comment")) {
2258 /* XXX this is a terrible API design in libxml++ */
2260 XMLNode *cmt = *(child->children().begin());
2261 _comment = cmt->content();
2263 } else if (child->name() == X_("extra")) {
2265 _extra_xml = new XMLNode (*child);
2267 } else if (child->name() == X_("Controllable") && (prop = child->property("name")) != 0) {
2269 if (prop->value() == "solo") {
2270 _solo_control->set_state (*child, version);
2271 _session.add_controllable (_solo_control);
2274 } else if (child->name() == X_("RemoteControl")) {
2275 if ((prop = child->property (X_("id"))) != 0) {
2277 sscanf (prop->value().c_str(), "%d", &x);
2278 set_remote_control_id (x);
2288 Route::get_processor_state ()
2290 XMLNode* root = new XMLNode (X_("redirects"));
2291 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2292 root->add_child_nocopy ((*i)->state (true));
2299 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2301 /* We don't bother removing existing processors not in nList, as this
2302 method will only be called when creating a Route from scratch, not
2303 for undo purposes. Just put processors in at the appropriate place
2307 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2308 add_processor_from_xml_2X (**i, version);
2313 Route::set_processor_state (const XMLNode& node)
2315 const XMLNodeList &nlist = node.children();
2316 XMLNodeConstIterator niter;
2317 ProcessorList new_order;
2318 bool must_configure = false;
2320 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2322 XMLProperty* prop = (*niter)->property ("type");
2324 if (prop->value() == "amp") {
2325 _amp->set_state (**niter, Stateful::current_state_version);
2326 new_order.push_back (_amp);
2327 } else if (prop->value() == "meter") {
2328 _meter->set_state (**niter, Stateful::current_state_version);
2329 new_order.push_back (_meter);
2330 } else if (prop->value() == "main-outs") {
2331 _main_outs->set_state (**niter, Stateful::current_state_version);
2332 new_order.push_back (_main_outs);
2333 } else if (prop->value() == "intreturn") {
2335 _intreturn.reset (new InternalReturn (_session));
2336 must_configure = true;
2338 _intreturn->set_state (**niter, Stateful::current_state_version);
2339 new_order.push_back (_intreturn);
2340 } else if (is_monitor() && prop->value() == "monitor") {
2341 if (!_monitor_control) {
2342 _monitor_control.reset (new MonitorProcessor (_session));
2343 must_configure = true;
2345 _monitor_control->set_state (**niter, Stateful::current_state_version);
2346 new_order.push_back (_monitor_control);
2348 ProcessorList::iterator o;
2350 for (o = _processors.begin(); o != _processors.end(); ++o) {
2351 XMLProperty* id_prop = (*niter)->property(X_("id"));
2352 if (id_prop && (*o)->id() == id_prop->value()) {
2353 (*o)->set_state (**niter, Stateful::current_state_version);
2354 new_order.push_back (*o);
2359 // If the processor (*niter) is not on the route then create it
2361 if (o == _processors.end()) {
2363 boost::shared_ptr<Processor> processor;
2365 if (prop->value() == "intsend") {
2367 processor.reset (new InternalSend (_session, _mute_master, boost::shared_ptr<Route>(), Delivery::Role (0)));
2369 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
2370 prop->value() == "lv2" ||
2371 prop->value() == "vst" ||
2372 prop->value() == "audiounit") {
2374 processor.reset (new PluginInsert(_session));
2376 } else if (prop->value() == "port") {
2378 processor.reset (new PortInsert (_session, _mute_master));
2380 } else if (prop->value() == "send") {
2382 processor.reset (new Send (_session, _mute_master));
2385 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
2389 if (processor->set_state (**niter, Stateful::current_state_version) != 0) {
2390 /* This processor could not be configured. Turn it into a UnknownProcessor */
2391 processor.reset (new UnknownProcessor (_session, **niter));
2394 new_order.push_back (processor);
2395 must_configure = true;
2401 Glib::RWLock::WriterLock lm (_processor_lock);
2402 _processors = new_order;
2403 if (must_configure) {
2404 Glib::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
2405 configure_processors_unlocked (0);
2409 processors_changed (RouteProcessorChange ());
2410 set_processor_positions ();
2414 Route::curve_reallocate ()
2416 // _gain_automation_curve.finish_resize ();
2417 // _pan_automation_curve.finish_resize ();
2421 Route::silence (nframes_t nframes)
2423 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2428 silence_unlocked (nframes);
2432 Route::silence_unlocked (nframes_t nframes)
2434 /* Must be called with the processor lock held */
2438 _output->silence (nframes);
2440 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2441 boost::shared_ptr<PluginInsert> pi;
2443 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2444 // skip plugins, they don't need anything when we're not active
2448 (*i)->silence (nframes);
2451 if (nframes == _session.get_block_size()) {
2458 Route::add_internal_return ()
2461 _intreturn.reset (new InternalReturn (_session));
2462 add_processor (_intreturn, PreFader);
2467 Route::get_return_buffer () const
2469 Glib::RWLock::ReaderLock rm (_processor_lock);
2471 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2472 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
2475 BufferSet* bs = d->get_buffers ();
2484 Route::release_return_buffer () const
2486 Glib::RWLock::ReaderLock rm (_processor_lock);
2488 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2489 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
2492 return d->release_buffers ();
2498 Route::listen_via (boost::shared_ptr<Route> route, Placement placement, bool /*active*/, bool aux)
2500 vector<string> ports;
2501 vector<string>::const_iterator i;
2504 Glib::RWLock::ReaderLock rm (_processor_lock);
2506 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
2508 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
2510 if (d && d->target_route() == route) {
2512 /* if the target is the control outs, then make sure
2513 we take note of which i-send is doing that.
2516 if (route == _session.monitor_out()) {
2517 _monitor_send = boost::dynamic_pointer_cast<Delivery>(d);
2520 /* already listening via the specified IO: do nothing */
2527 boost::shared_ptr<InternalSend> listener;
2533 if (route == _session.monitor_out()) {
2534 /* master never sends to control outs */
2537 listener.reset (new InternalSend (_session, _mute_master, route, (aux ? Delivery::Aux : Delivery::Listen)));
2541 listener.reset (new InternalSend (_session, _mute_master, route, (aux ? Delivery::Aux : Delivery::Listen)));
2544 } catch (failed_constructor& err) {
2548 if (route == _session.monitor_out()) {
2549 _monitor_send = listener;
2552 if (placement == PostFader) {
2553 /* put it *really* at the end, not just after the panner (main outs)
2555 add_processor (listener, _processors.end());
2557 add_processor (listener, PreFader);
2564 Route::drop_listen (boost::shared_ptr<Route> route)
2566 ProcessorStreams err;
2567 ProcessorList::iterator tmp;
2569 Glib::RWLock::ReaderLock rl(_processor_lock);
2573 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ) {
2575 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
2577 if (d && d->target_route() == route) {
2579 remove_processor (*x, &err);
2582 /* list could have been demolished while we dropped the lock
2592 if (route == _session.monitor_out()) {
2593 _monitor_send.reset ();
2598 Route::set_comment (string cmt, void *src)
2601 comment_changed (src);
2602 _session.set_dirty ();
2606 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
2608 FeedRecord fr (other, via_sends_only);
2610 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
2612 if (!result.second) {
2614 /* already a record for "other" - make sure sends-only information is correct */
2615 if (!via_sends_only && result.first->sends_only) {
2616 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
2617 frp->sends_only = false;
2621 return result.second;
2625 Route::clear_fed_by ()
2631 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
2633 const FedBy& fed_by (other->fed_by());
2635 for (FedBy::iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
2636 boost::shared_ptr<Route> sr = f->r.lock();
2638 if (sr && (sr.get() == this)) {
2640 if (via_sends_only) {
2641 *via_sends_only = f->sends_only;
2652 Route::direct_feeds (boost::shared_ptr<Route> other, bool* only_send)
2654 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
2656 if (_output->connected_to (other->input())) {
2657 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
2666 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
2668 boost::shared_ptr<IOProcessor> iop;
2670 if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*r)) != 0) {
2671 if (iop->feeds (other)) {
2672 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
2678 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
2681 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
2686 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
2691 Route::handle_transport_stopped (bool /*abort_ignored*/, bool did_locate, bool can_flush_processors)
2693 framepos_t now = _session.transport_frame();
2696 Glib::RWLock::ReaderLock lm (_processor_lock);
2699 automation_snapshot (now, true);
2702 Automatable::transport_stopped (now);
2704 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2706 if (Config->get_plugins_stop_with_transport() && can_flush_processors) {
2710 (*i)->transport_stopped (now);
2714 _roll_delay = _initial_delay;
2717 /** Called with the process lock held */
2719 Route::input_change_handler (IOChange change, void * /*src*/)
2721 if ((change.type & IOChange::ConfigurationChanged)) {
2722 configure_processors (0);
2723 _phase_invert.resize (_input->n_ports().n_audio ());
2724 io_changed (); /* EMIT SIGNAL */
2728 /** Called with the process lock held */
2730 Route::output_change_handler (IOChange change, void * /*src*/)
2732 if ((change.type & IOChange::ConfigurationChanged)) {
2734 /* XXX resize all listeners to match _main_outs? */
2736 /* Auto-connect newly-created outputs, unless we're auto-connecting to master
2737 and we are master (as an auto-connect in this situation would cause a
2740 AutoConnectOption ac = Config->get_output_auto_connect ();
2741 if (ac == AutoConnectPhysical || (ac == AutoConnectMaster && !is_master ())) {
2743 ChanCount start = change.before;
2745 for (DataType::iterator i = DataType::begin(); i != DataType::end(); ++i) {
2746 if (change.before.get(*i) < change.after.get(*i)) {
2747 /* the existing ChanCounts don't matter for this call as they are only
2748 to do with matching input and output indices, and we are only changing
2753 /* only auto-connect the newly-created outputs, not the ones that were
2756 start.set (*i, start.get (*i) + 1);
2758 _session.auto_connect_route (this, dummy, dummy, false, ChanCount(), change.before);
2763 // configure_processors (0);
2768 Route::pans_required () const
2770 if (n_outputs().n_audio() < 2) {
2774 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
2778 Route::no_roll (nframes_t nframes, framepos_t start_frame, framepos_t end_frame,
2779 bool session_state_changing, bool /*can_record*/, bool /*rec_monitors_input*/)
2781 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2786 if (n_outputs().n_total() == 0) {
2790 if (!_active || n_inputs() == ChanCount::ZERO) {
2791 silence_unlocked (nframes);
2794 if (session_state_changing) {
2795 if (_session.transport_speed() != 0.0f) {
2796 /* we're rolling but some state is changing (e.g. our diskstream contents)
2797 so we cannot use them. Be silent till this is over.
2799 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
2801 silence_unlocked (nframes);
2804 /* we're really not rolling, so we're either delivery silence or actually
2805 monitoring, both of which are safe to do while session_state_changing is true.
2809 _amp->apply_gain_automation (false);
2810 passthru (start_frame, end_frame, nframes, 0);
2816 Route::check_initial_delay (nframes_t nframes, nframes_t& transport_frame)
2818 if (_roll_delay > nframes) {
2820 _roll_delay -= nframes;
2821 silence_unlocked (nframes);
2822 /* transport frame is not legal for caller to use */
2825 } else if (_roll_delay > 0) {
2827 nframes -= _roll_delay;
2828 silence_unlocked (_roll_delay);
2829 /* we've written _roll_delay of samples into the
2830 output ports, so make a note of that for
2833 _main_outs->increment_output_offset (_roll_delay);
2834 transport_frame += _roll_delay;
2843 Route::roll (nframes_t nframes, framepos_t start_frame, framepos_t end_frame, int declick,
2844 bool /*can_record*/, bool /*rec_monitors_input*/, bool& /* need_butler */)
2846 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2851 automation_snapshot (_session.transport_frame(), false);
2853 if (n_outputs().n_total() == 0) {
2857 if (!_active || n_inputs().n_total() == 0) {
2858 silence_unlocked (nframes);
2862 nframes_t unused = 0;
2864 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
2870 passthru (start_frame, end_frame, nframes, declick);
2876 Route::silent_roll (nframes_t nframes, framepos_t /*start_frame*/, framepos_t /*end_frame*/,
2877 bool /*can_record*/, bool /*rec_monitors_input*/, bool& /* need_butler */)
2884 Route::toggle_monitor_input ()
2886 for (PortSet::iterator i = _input->ports().begin(); i != _input->ports().end(); ++i) {
2887 i->ensure_monitor_input( ! i->monitoring_input());
2892 Route::has_external_redirects () const
2894 // FIXME: what about sends? - they don't return a signal back to ardour?
2896 boost::shared_ptr<const PortInsert> pi;
2898 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2900 if ((pi = boost::dynamic_pointer_cast<const PortInsert>(*i)) != 0) {
2902 for (PortSet::const_iterator port = pi->output()->ports().begin(); port != pi->output()->ports().end(); ++port) {
2904 string port_name = port->name();
2905 string client_name = port_name.substr (0, port_name.find(':'));
2907 /* only say "yes" if the redirect is actually in use */
2909 if (client_name != "ardour" && pi->active()) {
2920 Route::flush_processors ()
2922 /* XXX shouldn't really try to take this lock, since
2923 this is called from the RT audio thread.
2926 Glib::RWLock::ReaderLock lm (_processor_lock);
2928 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2934 Route::set_meter_point (MeterPoint p)
2936 /* CAN BE CALLED FROM PROCESS CONTEXT */
2938 if (_meter_point == p) {
2942 bool meter_was_visible_to_user = _meter->display_to_user ();
2945 Glib::RWLock::WriterLock lm (_processor_lock);
2947 if (p != MeterCustom) {
2948 // Move meter in the processors list to reflect the new position
2949 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
2950 _processors.erase(loc);
2953 loc = _processors.begin();
2956 loc = find (_processors.begin(), _processors.end(), _amp);
2958 case MeterPostFader:
2959 loc = _processors.end();
2967 if (loc == _processors.begin()) {
2968 m_in = _input->n_ports();
2970 ProcessorList::iterator before = loc;
2972 m_in = (*before)->output_streams ();
2975 _meter->reflect_inputs (m_in);
2977 _processors.insert (loc, _meter);
2979 /* we do not need to reconfigure the processors, because the meter
2980 (a) is always ready to handle processor_max_streams
2981 (b) is always an N-in/N-out processor, and thus moving
2982 it doesn't require any changes to the other processors.
2985 _meter->set_display_to_user (false);
2989 // just make it visible and let the user move it
2991 _meter->set_display_to_user (true);
2996 meter_change (); /* EMIT SIGNAL */
2998 bool const meter_visibly_changed = (_meter->display_to_user() != meter_was_visible_to_user);
3000 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, meter_visibly_changed)); /* EMIT SIGNAL */
3004 Route::put_monitor_send_at (Placement p)
3006 if (!_monitor_send) {
3011 Glib::RWLock::WriterLock lm (_processor_lock);
3012 ProcessorList as_it_was (_processors);
3013 ProcessorList::iterator loc = find(_processors.begin(), _processors.end(), _monitor_send);
3014 _processors.erase(loc);
3018 loc = find(_processors.begin(), _processors.end(), _amp);
3019 if (loc != _processors.begin()) {
3024 loc = _processors.end();
3028 _processors.insert (loc, _monitor_send);
3031 Glib::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
3033 if (configure_processors_unlocked (0)) {
3034 _processors = as_it_was;
3035 configure_processors_unlocked (0); // it worked before we tried to add it ...
3041 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
3042 _session.set_dirty ();
3046 Route::update_total_latency ()
3048 nframes_t old = _output->effective_latency();
3049 nframes_t own_latency = _output->user_latency();
3051 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3052 if ((*i)->active ()) {
3053 own_latency += (*i)->signal_latency ();
3057 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal redirect latency = %2\n", _name, own_latency));
3059 _output->set_port_latency (own_latency);
3061 if (_output->user_latency() == 0) {
3063 /* this (virtual) function is used for pure Routes,
3064 not derived classes like AudioTrack. this means
3065 that the data processed here comes from an input
3066 port, not prerecorded material, and therefore we
3067 have to take into account any input latency.
3070 own_latency += _input->signal_latency ();
3073 if (old != own_latency) {
3074 _output->set_latency_delay (own_latency);
3075 signal_latency_changed (); /* EMIT SIGNAL */
3078 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: input latency = %2 total = %3\n", _name, _input->signal_latency(), own_latency));
3080 return _output->effective_latency ();
3084 Route::set_user_latency (nframes_t nframes)
3086 _output->set_user_latency (nframes);
3087 _session.update_latency_compensation (false, false);
3091 Route::set_latency_delay (nframes_t longest_session_latency)
3093 nframes_t old = _initial_delay;
3095 if (_output->effective_latency() < longest_session_latency) {
3096 _initial_delay = longest_session_latency - _output->effective_latency();
3101 if (_initial_delay != old) {
3102 initial_delay_changed (); /* EMIT SIGNAL */
3105 if (_session.transport_stopped()) {
3106 _roll_delay = _initial_delay;
3111 Route::automation_snapshot (nframes_t now, bool force)
3113 panner()->automation_snapshot (now, force);
3115 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3116 (*i)->automation_snapshot (now, force);
3120 Route::SoloControllable::SoloControllable (std::string name, Route& r)
3121 : AutomationControl (r.session(), Evoral::Parameter (SoloAutomation),
3122 boost::shared_ptr<AutomationList>(), name)
3125 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(SoloAutomation)));
3130 Route::SoloControllable::set_value (double val)
3132 bool bval = ((val >= 0.5f) ? true: false);
3134 this is how it should be done
3136 boost::shared_ptr<RouteList> rl (new RouteList);
3137 rl->push_back (route);
3139 if (Config->get_solo_control_is_listen_control()) {
3140 _session.set_listen (rl, bval);
3142 _session.set_solo (rl, bval);
3145 route.set_solo (bval, this);
3150 Route::SoloControllable::get_value (void) const
3152 if (Config->get_solo_control_is_listen_control()) {
3153 return route.listening() ? 1.0f : 0.0f;
3155 return route.self_soloed() ? 1.0f : 0.0f;
3159 Route::MuteControllable::MuteControllable (std::string name, Route& r)
3160 : AutomationControl (r.session(), Evoral::Parameter (MuteAutomation),
3161 boost::shared_ptr<AutomationList>(), name)
3164 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(MuteAutomation)));
3169 Route::MuteControllable::set_value (double val)
3171 bool bval = ((val >= 0.5f) ? true: false);
3173 this is how it should be done
3175 boost::shared_ptr<RouteList> rl (new RouteList);
3176 rl->push_back (route);
3177 _session.set_mute (rl, bval);
3179 route.set_mute (bval, this);
3184 Route::MuteControllable::get_value (void) const
3186 return route.muted() ? 1.0f : 0.0f;
3190 Route::set_block_size (nframes_t nframes)
3192 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3193 (*i)->set_block_size (nframes);
3196 _session.ensure_buffers (n_process_buffers ());
3200 Route::protect_automation ()
3202 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
3203 (*i)->protect_automation();
3207 Route::set_pending_declick (int declick)
3210 /* this call is not allowed to turn off a pending declick unless "force" is true */
3212 _pending_declick = declick;
3214 // cerr << _name << ": after setting to " << declick << " pending declick = " << _pending_declick << endl;
3216 _pending_declick = 0;
3221 /** Shift automation forwards from a particular place, thereby inserting time.
3222 * Adds undo commands for any shifts that are performed.
3224 * @param pos Position to start shifting from.
3225 * @param frames Amount to shift forwards by.
3229 Route::shift (framepos_t /*pos*/, framecnt_t /*frames*/)
3231 #ifdef THIS_NEEDS_FIXING_FOR_V3
3233 /* gain automation */
3234 XMLNode &before = _gain_control->get_state ();
3235 _gain_control->shift (pos, frames);
3236 XMLNode &after = _gain_control->get_state ();
3237 _session.add_command (new MementoCommand<AutomationList> (_gain_automation_curve, &before, &after));
3239 /* pan automation */
3240 for (std::vector<StreamPanner*>::iterator i = _panner->begin (); i != _panner->end (); ++i) {
3241 Curve & c = (*i)->automation ();
3242 XMLNode &before = c.get_state ();
3243 c.shift (pos, frames);
3244 XMLNode &after = c.get_state ();
3245 _session.add_command (new MementoCommand<AutomationList> (c, &before, &after));
3248 /* redirect automation */
3250 Glib::RWLock::ReaderLock lm (redirect_lock);
3251 for (RedirectList::iterator i = _redirects.begin (); i != _redirects.end (); ++i) {
3254 (*i)->what_has_automation (a);
3256 for (set<uint32_t>::const_iterator j = a.begin (); j != a.end (); ++j) {
3257 AutomationList & al = (*i)->automation_list (*j);
3258 XMLNode &before = al.get_state ();
3259 al.shift (pos, frames);
3260 XMLNode &after = al.get_state ();
3261 _session.add_command (new MementoCommand<AutomationList> (al, &before, &after));
3271 Route::save_as_template (const string& path, const string& name)
3273 XMLNode& node (state (false));
3276 IO::set_name_in_state (*node.children().front(), name);
3278 tree.set_root (&node);
3279 return tree.write (path.c_str());
3284 Route::set_name (const string& str)
3290 name = Route::ensure_track_or_route_name (str, _session);
3291 SessionObject::set_name (name);
3293 ret = (_input->set_name(name) && _output->set_name(name));
3297 Glib::RWLock::ReaderLock lm (_processor_lock);
3299 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3301 /* rename all I/O processors that have inputs or outputs */
3303 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor> (*i);
3305 if (iop && (iop->output() || iop->input())) {
3306 if (!iop->set_name (name)) {
3317 boost::shared_ptr<Send>
3318 Route::internal_send_for (boost::shared_ptr<const Route> target) const
3320 Glib::RWLock::ReaderLock lm (_processor_lock);
3322 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3323 boost::shared_ptr<InternalSend> send;
3325 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
3326 if (send->target_route() == target) {
3332 return boost::shared_ptr<Send>();
3335 /** @param c Audio channel index.
3336 * @param yn true to invert phase, otherwise false.
3339 Route::set_phase_invert (uint32_t c, bool yn)
3341 if (_phase_invert[c] != yn) {
3342 _phase_invert[c] = yn;
3343 phase_invert_changed (); /* EMIT SIGNAL */
3344 _session.set_dirty ();
3349 Route::set_phase_invert (boost::dynamic_bitset<> p)
3351 if (_phase_invert != p) {
3353 phase_invert_changed (); /* EMIT SIGNAL */
3354 _session.set_dirty ();
3359 Route::phase_invert (uint32_t c) const
3361 return _phase_invert[c];
3364 boost::dynamic_bitset<>
3365 Route::phase_invert () const
3367 return _phase_invert;
3371 Route::set_denormal_protection (bool yn)
3373 if (_denormal_protection != yn) {
3374 _denormal_protection = yn;
3375 denormal_protection_changed (); /* EMIT SIGNAL */
3380 Route::denormal_protection () const
3382 return _denormal_protection;
3386 Route::set_active (bool yn)
3388 if (_active != yn) {
3390 _input->set_active (yn);
3391 _output->set_active (yn);
3392 active_changed (); // EMIT SIGNAL
3399 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
3405 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3407 boost::shared_ptr<Send> s;
3408 boost::shared_ptr<Return> r;
3410 if ((s = boost::dynamic_pointer_cast<Send> (*i)) != 0) {
3411 s->meter()->meter();
3412 } else if ((r = boost::dynamic_pointer_cast<Return> (*i)) != 0) {
3413 r->meter()->meter ();
3418 boost::shared_ptr<Panner>
3419 Route::panner() const
3421 return _main_outs->panner();
3424 boost::shared_ptr<AutomationControl>
3425 Route::gain_control() const
3427 return _amp->gain_control();
3430 boost::shared_ptr<AutomationControl>
3431 Route::get_control (const Evoral::Parameter& param)
3433 /* either we own the control or .... */
3435 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
3439 /* maybe one of our processors does or ... */
3441 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
3442 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3443 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
3451 /* nobody does so we'll make a new one */
3453 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
3460 boost::shared_ptr<Processor>
3461 Route::nth_plugin (uint32_t n)
3463 Glib::RWLock::ReaderLock lm (_processor_lock);
3464 ProcessorList::iterator i;
3466 for (i = _processors.begin(); i != _processors.end(); ++i) {
3467 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
3474 return boost::shared_ptr<Processor> ();
3477 boost::shared_ptr<Processor>
3478 Route::nth_send (uint32_t n)
3480 Glib::RWLock::ReaderLock lm (_processor_lock);
3481 ProcessorList::iterator i;
3483 for (i = _processors.begin(); i != _processors.end(); ++i) {
3484 if (boost::dynamic_pointer_cast<Send> (*i)) {
3491 return boost::shared_ptr<Processor> ();
3495 Route::has_io_processor_named (const string& name)
3497 Glib::RWLock::ReaderLock lm (_processor_lock);
3498 ProcessorList::iterator i;
3500 for (i = _processors.begin(); i != _processors.end(); ++i) {
3501 if (boost::dynamic_pointer_cast<Send> (*i) ||
3502 boost::dynamic_pointer_cast<PortInsert> (*i)) {
3503 if ((*i)->name() == name) {
3512 MuteMaster::MutePoint
3513 Route::mute_points () const
3515 return _mute_master->mute_points ();
3519 Route::set_processor_positions ()
3521 Glib::RWLock::ReaderLock lm (_processor_lock);
3523 bool had_amp = false;
3524 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3525 (*i)->set_pre_fader (!had_amp);
3526 if (boost::dynamic_pointer_cast<Amp> (*i)) {
3532 /** Called when there is a proposed change to the input port count */
3534 Route::input_port_count_changing (ChanCount to)
3536 list<pair<ChanCount, ChanCount> > c = try_configure_processors (to, 0);
3538 /* The processors cannot be configured with the new input arrangement, so
3544 /* The change is ok */
3549 Route::unknown_processors () const
3553 Glib::RWLock::ReaderLock lm (_processor_lock);
3554 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3555 if (boost::dynamic_pointer_cast<UnknownProcessor const> (*i)) {
3556 p.push_back ((*i)->name ());