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"
65 using namespace ARDOUR;
68 uint32_t Route::order_key_cnt = 0;
69 PBD::Signal1<void,string const&> Route::SyncOrderKeys;
70 PBD::Signal0<void> Route::RemoteControlIDChange;
72 Route::Route (Session& sess, string name, Flag flg, DataType default_type)
73 : SessionObject (sess, name)
74 , AutomatableControls (sess)
79 , _pending_declick (true)
80 , _meter_point (MeterPostFader)
83 , _soloed_by_others_upstream (0)
84 , _soloed_by_others_downstream (0)
86 , _denormal_protection (false)
89 , _declickable (false)
90 , _solo_control (new SoloControllable (X_("solo"), *this))
91 , _mute_control (new MuteControllable (X_("mute"), *this))
92 , _mute_master (new MuteMaster (sess, name))
93 , _mute_points (MuteMaster::AllPoints)
94 , _have_internal_generator (false)
95 , _physically_connected (false)
98 , _default_type (default_type)
99 , _remote_control_id (0)
100 , _in_configure_processors (false)
102 processor_max_streams.reset();
103 order_keys[N_("signal")] = order_key_cnt++;
109 /* add standard controls */
111 _solo_control->set_flags (Controllable::Flag (_solo_control->flags() | Controllable::Toggle));
112 _mute_control->set_flags (Controllable::Flag (_solo_control->flags() | Controllable::Toggle));
114 add_control (_solo_control);
115 add_control (_mute_control);
117 /* input and output objects */
119 _input.reset (new IO (_session, _name, IO::Input, _default_type));
120 _output.reset (new IO (_session, _name, IO::Output, _default_type));
122 _input->changed.connect_same_thread (*this, boost::bind (&Route::input_change_handler, this, _1, _2));
123 _output->changed.connect_same_thread (*this, boost::bind (&Route::output_change_handler, this, _1, _2));
125 /* add amp processor */
127 _amp.reset (new Amp (_session, _mute_master));
128 add_processor (_amp, PostFader);
130 /* add standard processors: meter, main outs, monitor out */
132 _meter.reset (new PeakMeter (_session));
133 _meter->set_display_to_user (false);
135 add_processor (_meter, PostFader);
137 _main_outs.reset (new Delivery (_session, _output, _mute_master, _name, Delivery::Main));
139 add_processor (_main_outs, PostFader);
142 /* where we listen to tracks */
143 _intreturn.reset (new InternalReturn (_session));
144 add_processor (_intreturn, PreFader);
146 ProcessorList::iterator i;
148 for (i = _processors.begin(); i != _processors.end(); ++i) {
149 if (*i == _intreturn) {
155 /* the thing that provides proper control over a control/monitor/listen bus
156 (such as per-channel cut, dim, solo, invert, etc).
157 It always goes right after the internal return;
159 _monitor_control.reset (new MonitorProcessor (_session));
160 add_processor (_monitor_control, i);
162 /* no panning on the monitor main outs */
164 _main_outs->panner()->set_bypassed (true);
167 if (is_master() || is_monitor() || is_hidden()) {
168 _mute_master->set_solo_ignore (true);
171 /* now that we have _meter, its safe to connect to this */
173 Metering::Meter.connect_same_thread (*this, (boost::bind (&Route::meter, this)));
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::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 (id != _remote_control_id) {
203 _remote_control_id = id;
204 RemoteControlIDChanged ();
205 if (notify_class_listeners) {
206 RemoteControlIDChange ();
212 Route::remote_control_id() const
214 return _remote_control_id;
218 Route::order_key (std::string const & name) const
220 OrderKeys::const_iterator i = order_keys.find (name);
221 if (i == order_keys.end()) {
229 Route::set_order_key (std::string const & name, long n)
231 order_keys[name] = n;
233 if (Config->get_sync_all_route_ordering()) {
234 for (OrderKeys::iterator x = order_keys.begin(); x != order_keys.end(); ++x) {
239 _session.set_dirty ();
242 /** Set all order keys to be the same as that for `base', if such a key
243 * exists in this route.
244 * @param base Base key.
247 Route::sync_order_keys (std::string const & base)
249 if (order_keys.empty()) {
253 OrderKeys::iterator i;
256 if ((i = order_keys.find (base)) == order_keys.end()) {
257 /* key doesn't exist, use the first existing key (during session initialization) */
258 i = order_keys.begin();
262 /* key exists - use it and reset all others (actually, itself included) */
264 i = order_keys.begin();
267 for (; i != order_keys.end(); ++i) {
273 Route::ensure_track_or_route_name(string name, Session &session)
275 string newname = name;
277 while (!session.io_name_is_legal (newname)) {
278 newname = bump_name_once (newname);
286 Route::inc_gain (gain_t fraction, void *src)
288 _amp->inc_gain (fraction, src);
292 Route::set_gain (gain_t val, void *src)
294 if (src != 0 && _route_group && src != _route_group && _route_group->is_active() && _route_group->is_gain()) {
296 if (_route_group->is_relative()) {
298 gain_t usable_gain = _amp->gain();
299 if (usable_gain < 0.000001f) {
300 usable_gain = 0.000001f;
304 if (delta < 0.000001f) {
308 delta -= usable_gain;
313 gain_t factor = delta / usable_gain;
316 factor = _route_group->get_max_factor(factor);
317 if (factor == 0.0f) {
318 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
322 factor = _route_group->get_min_factor(factor);
323 if (factor == 0.0f) {
324 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
329 _route_group->apply (&Route::inc_gain, factor, _route_group);
333 _route_group->apply (&Route::set_gain, val, _route_group);
339 if (val == _amp->gain()) {
343 _amp->set_gain (val, src);
346 /** Process this route for one (sub) cycle (process thread)
348 * @param bufs Scratch buffers to use for the signal path
349 * @param start_frame Initial transport frame
350 * @param end_frame Final transport frame
351 * @param nframes Number of frames to output (to ports)
353 * Note that (end_frame - start_frame) may not be equal to nframes when the
354 * transport speed isn't 1.0 (eg varispeed).
357 Route::process_output_buffers (BufferSet& bufs,
358 sframes_t start_frame, sframes_t end_frame, nframes_t nframes,
359 bool /*with_processors*/, int declick)
363 bufs.is_silent (false);
365 switch (Config->get_monitoring_model()) {
366 case HardwareMonitoring:
367 case ExternalMonitoring:
368 monitor = !record_enabled() || (_session.config.get_auto_input() && !_session.actively_recording());
375 declick = _pending_declick;
378 /* figure out if we're going to use gain automation */
379 _amp->setup_gain_automation (start_frame, end_frame, nframes);
382 /* tell main outs what to do about monitoring */
383 _main_outs->no_outs_cuz_we_no_monitor (!monitor);
386 /* -------------------------------------------------------------------------------------------
387 GLOBAL DECLICK (for transport changes etc.)
388 ----------------------------------------------------------------------------------------- */
391 Amp::apply_gain (bufs, nframes, 0.0, 1.0);
392 } else if (declick < 0) {
393 Amp::apply_gain (bufs, nframes, 1.0, 0.0);
396 _pending_declick = 0;
398 /* -------------------------------------------------------------------------------------------
399 DENORMAL CONTROL/PHASE INVERT
400 ----------------------------------------------------------------------------------------- */
406 if (_denormal_protection || Config->get_denormal_protection()) {
408 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
409 Sample* const sp = i->data();
411 if (_phase_invert & chn) {
412 for (nframes_t nx = 0; nx < nframes; ++nx) {
417 for (nframes_t nx = 0; nx < nframes; ++nx) {
425 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
426 Sample* const sp = i->data();
428 if (_phase_invert & (1<<chn)) {
429 for (nframes_t nx = 0; nx < nframes; ++nx) {
438 if (_denormal_protection || Config->get_denormal_protection()) {
440 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
441 Sample* const sp = i->data();
442 for (nframes_t nx = 0; nx < nframes; ++nx) {
450 /* -------------------------------------------------------------------------------------------
452 ----------------------------------------------------------------------------------------- */
454 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
457 //cerr << name() << " upstream solo " << _soloed_by_others_upstream
458 // << " downstream solo " << _soloed_by_others_downstream
459 // << " self " << _self_solo
461 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
463 if (bufs.count() != (*i)->input_streams()) {
464 cerr << _name << " bufs = " << bufs.count()
465 << " input for " << (*i)->name() << " = " << (*i)->input_streams()
468 assert (bufs.count() == (*i)->input_streams());
470 (*i)->run (bufs, start_frame, end_frame, nframes, *i != _processors.back());
471 bufs.set_count ((*i)->output_streams());
477 Route::n_process_buffers ()
479 return max (_input->n_ports(), processor_max_streams);
483 Route::passthru (sframes_t start_frame, sframes_t end_frame, nframes_t nframes, int declick)
485 BufferSet& bufs = _session.get_scratch_buffers (n_process_buffers());
489 assert (bufs.available() >= input_streams());
491 if (_input->n_ports() == ChanCount::ZERO) {
495 bufs.set_count (input_streams());
497 if (is_monitor() && _session.listening() && !_session.is_auditioning()) {
499 /* control/monitor bus ignores input ports when something is
500 feeding the listen "stream". data will "arrive" into the
501 route from the intreturn processor element.
503 bufs.silence (nframes, 0);
507 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
509 BufferSet::iterator o = bufs.begin(*t);
510 PortSet& ports (_input->ports());
512 for (PortSet::iterator i = ports.begin(*t); i != ports.end(*t); ++i, ++o) {
513 o->read_from (i->get_buffer(nframes), nframes);
518 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
519 process_output_buffers (bufs, start_frame, end_frame, nframes, true, declick);
523 Route::passthru_silence (sframes_t start_frame, sframes_t end_frame, nframes_t nframes, int declick)
525 BufferSet& bufs (_session.get_silent_buffers (n_process_buffers()));
526 bufs.set_count (_input->n_ports());
527 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
528 process_output_buffers (bufs, start_frame, end_frame, nframes, true, declick);
532 Route::set_listen (bool yn, void* src)
539 if (yn != _monitor_send->active()) {
541 _monitor_send->activate ();
542 _mute_master->set_soloed (true);
544 _monitor_send->deactivate ();
545 _mute_master->set_soloed (false);
548 listen_changed (src); /* EMIT SIGNAL */
554 Route::listening () const
557 return _monitor_send->active ();
564 Route::set_solo_safe (bool yn, void *src)
566 if (_solo_safe != yn) {
568 solo_safe_changed (src);
573 Route::solo_safe() const
579 Route::set_solo (bool yn, void *src)
585 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_solo()) {
586 _route_group->apply (&Route::set_solo, yn, _route_group);
590 if (self_soloed() != yn) {
592 set_mute_master_solo ();
593 solo_changed (true, src); /* EMIT SIGNAL */
594 _solo_control->Changed (); /* EMIT SIGNAL */
599 Route::set_self_solo (bool yn)
605 Route::mod_solo_by_others_upstream (int32_t delta)
611 uint32_t old_sbu = _soloed_by_others_upstream;
614 if (_soloed_by_others_upstream >= (uint32_t) abs (delta)) {
615 _soloed_by_others_upstream += delta;
617 _soloed_by_others_upstream = 0;
620 _soloed_by_others_upstream += delta;
623 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 SbU delta %2 = %3 old = %4 sbd %5 ss %6 exclusive %7\n",
624 name(), delta, _soloed_by_others_upstream, old_sbu,
625 _soloed_by_others_downstream, _self_solo, Config->get_exclusive_solo()));
627 /* push the inverse solo change to everything that feeds us.
629 This is important for solo-within-group. When we solo 1 track out of N that
630 feed a bus, that track will cause mod_solo_by_upstream (+1) to be called
631 on the bus. The bus then needs to call mod_solo_by_downstream (-1) on all
632 tracks that feed it. This will silence them if they were audible because
633 of a bus solo, but the newly soloed track will still be audible (because
636 but .. do this only when we are being told to solo-by-upstream (i.e delta = +1),
640 if ((_self_solo || _soloed_by_others_downstream) &&
641 ((old_sbu == 0 && _soloed_by_others_upstream > 0) ||
642 (old_sbu > 0 && _soloed_by_others_upstream == 0))) {
644 if (delta > 0 || !Config->get_exclusive_solo()) {
645 DEBUG_TRACE (DEBUG::Solo, "\t ... INVERT push\n");
646 for (FedBy::iterator i = _fed_by.begin(); i != _fed_by.end(); ++i) {
647 boost::shared_ptr<Route> sr = i->r.lock();
649 sr->mod_solo_by_others_downstream (-delta);
655 set_mute_master_solo ();
656 solo_changed (false, this);
660 Route::mod_solo_by_others_downstream (int32_t delta)
667 if (_soloed_by_others_downstream >= (uint32_t) abs (delta)) {
668 _soloed_by_others_downstream += delta;
670 _soloed_by_others_downstream = 0;
673 _soloed_by_others_downstream += delta;
676 DEBUG_TRACE (DEBUG::Solo, string_compose ("%1 SbD delta %2 = %3\n", name(), delta, _soloed_by_others_downstream));
678 set_mute_master_solo ();
679 solo_changed (false, this);
683 Route::set_mute_master_solo ()
685 _mute_master->set_soloed (self_soloed() || soloed_by_others_downstream() || soloed_by_others_upstream());
689 Route::set_solo_isolated (bool yn, void *src)
691 if (is_master() || is_monitor() || is_hidden()) {
695 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_solo()) {
696 _route_group->apply (&Route::set_solo_isolated, yn, _route_group);
700 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
702 boost::shared_ptr<RouteList> routes = _session.get_routes ();
703 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
705 if ((*i).get() == this || (*i)->is_master() || (*i)->is_monitor() || (*i)->is_hidden()) {
710 bool does_feed = direct_feeds (*i, &sends_only); // we will recurse anyway, so don't use ::feeds()
712 if (does_feed && !sends_only) {
713 (*i)->set_solo_isolated (yn, (*i)->route_group());
717 /* XXX should we back-propagate as well? (April 2010: myself and chris goddard think not) */
720 if (_solo_isolated == 0) {
721 _mute_master->set_solo_ignore (true);
724 solo_isolated_changed (src);
726 if (_solo_isolated > 0) {
728 if (_solo_isolated == 0) {
729 _mute_master->set_solo_ignore (false);
731 solo_isolated_changed (src);
738 Route::solo_isolated () const
740 return _solo_isolated > 0;
744 Route::set_mute_points (MuteMaster::MutePoint mp)
747 _mute_master->set_mute_points (MuteMaster::AllPoints);
748 mute_points_changed (); /* EMIT SIGNAL */
750 if (_mute_master->muted()) {
751 mute_changed (this); /* EMIT SIGNAL */
756 Route::set_mute (bool yn, void *src)
758 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_mute()) {
759 _route_group->apply (&Route::set_mute, yn, _route_group);
764 _mute_master->set_muted (yn);
765 mute_changed (src); /* EMIT SIGNAL */
770 Route::muted () const
772 return _mute_master->muted();
777 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
779 cerr << name << " {" << endl;
780 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
781 p != procs.end(); ++p) {
782 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << endl;
789 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err)
791 ProcessorList::iterator loc;
793 /* XXX this is not thread safe - we don't hold the lock across determining the iter
794 to add before and actually doing the insertion. dammit.
797 if (placement == PreFader) {
798 /* generic pre-fader: insert immediately before the amp */
799 loc = find (_processors.begin(), _processors.end(), _amp);
801 /* generic post-fader: insert right before the main outs */
802 loc = find (_processors.begin(), _processors.end(), _main_outs);
805 return add_processor (processor, loc, err);
809 /** Add a processor to the route.
810 * @a iter must point to an iterator in _processors and the new
811 * processor will be inserted immediately before this location. Otherwise,
812 * @a position is used.
815 Route::add_processor (boost::shared_ptr<Processor> processor, ProcessorList::iterator iter, ProcessorStreams* err, bool activation_allowed)
817 ChanCount old_pms = processor_max_streams;
819 if (!_session.engine().connected() || !processor) {
824 Glib::RWLock::WriterLock lm (_processor_lock);
826 boost::shared_ptr<PluginInsert> pi;
827 boost::shared_ptr<PortInsert> porti;
829 ProcessorList::iterator loc = find(_processors.begin(), _processors.end(), processor);
831 if (processor == _amp || processor == _meter || processor == _main_outs) {
832 // Ensure only one of these are in the list at any time
833 if (loc != _processors.end()) {
834 if (iter == loc) { // Already in place, do nothing
836 } else { // New position given, relocate
837 _processors.erase (loc);
842 if (loc != _processors.end()) {
843 cerr << "ERROR: Processor added to route twice!" << endl;
850 _processors.insert (loc, processor);
852 // Set up processor list channels. This will set processor->[input|output]_streams(),
853 // configure redirect ports properly, etc.
855 if (configure_processors_unlocked (err)) {
856 ProcessorList::iterator ploc = loc;
858 _processors.erase(ploc);
859 configure_processors_unlocked (0); // it worked before we tried to add it ...
860 cerr << "configure failed\n";
864 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
866 if (pi->natural_input_streams() == ChanCount::ZERO) {
867 /* generator plugin */
868 _have_internal_generator = true;
873 /* is this the monitor send ? if so, make sure we keep track of it */
875 boost::shared_ptr<InternalSend> isend = boost::dynamic_pointer_cast<InternalSend> (processor);
877 if (isend && _session.monitor_out() && (isend->target_id() == _session.monitor_out()->id())) {
878 _monitor_send = isend;
881 if (activation_allowed && (processor != _monitor_send)) {
882 processor->activate ();
885 processor->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false, false));
887 _output->set_user_latency (0);
890 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
896 Route::add_processor_from_xml_2X (const XMLNode& node, int version, ProcessorList::iterator iter)
898 const XMLProperty *prop;
901 boost::shared_ptr<Processor> processor;
903 if (node.name() == "Insert") {
905 if ((prop = node.property ("type")) != 0) {
907 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
908 prop->value() == "lv2" ||
909 prop->value() == "vst" ||
910 prop->value() == "audiounit") {
912 processor.reset (new PluginInsert (_session));
916 processor.reset (new PortInsert (_session, _mute_master));
921 } else if (node.name() == "Send") {
923 processor.reset (new Send (_session, _mute_master));
927 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
931 if (processor->set_state (node, version)) {
935 if (iter == _processors.end() && processor->display_to_user() && !_processors.empty()) {
936 /* check for invisible processors stacked at the end and leave them there */
937 ProcessorList::iterator p;
938 p = _processors.end();
940 while (!(*p)->display_to_user() && p != _processors.begin()) {
947 return (add_processor (processor, iter) == 0);
950 catch (failed_constructor &err) {
951 warning << _("processor could not be created. Ignored.") << endmsg;
957 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
959 ProcessorList::iterator loc;
962 loc = find(_processors.begin(), _processors.end(), before);
964 /* nothing specified - at end but before main outs */
965 loc = find (_processors.begin(), _processors.end(), _main_outs);
968 return add_processors (others, loc, err);
972 Route::add_processors (const ProcessorList& others, ProcessorList::iterator iter, ProcessorStreams* err)
974 /* NOTE: this is intended to be used ONLY when copying
975 processors from another Route. Hence the subtle
976 differences between this and ::add_processor()
979 ChanCount old_pms = processor_max_streams;
981 if (!_session.engine().connected()) {
985 if (others.empty()) {
990 Glib::RWLock::WriterLock lm (_processor_lock);
992 ChanCount potential_max_streams = ChanCount::max (_input->n_ports(), _output->n_ports());
994 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
996 // Ensure meter only appears in the list once
998 ProcessorList::iterator m = find(_processors.begin(), _processors.end(), *i);
999 if (m != _processors.end()) {
1000 _processors.erase(m);
1004 boost::shared_ptr<PluginInsert> pi;
1006 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1009 ChanCount m = max (pi->input_streams(), pi->output_streams());
1011 if (m > potential_max_streams) {
1012 potential_max_streams = m;
1016 ProcessorList::iterator inserted = _processors.insert (iter, *i);
1018 if ((*i)->active()) {
1022 if (configure_processors_unlocked (err)) {
1023 _processors.erase (inserted);
1024 configure_processors_unlocked (0); // it worked before we tried to add it ...
1028 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false, false));
1031 _output->set_user_latency (0);
1034 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1040 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1042 if (p == PreFader) {
1043 start = _processors.begin();
1044 end = find(_processors.begin(), _processors.end(), _amp);
1046 start = find(_processors.begin(), _processors.end(), _amp);
1048 end = _processors.end();
1052 /** Turn off all processors with a given placement
1053 * @param p Placement of processors to disable
1056 Route::disable_processors (Placement p)
1058 Glib::RWLock::ReaderLock lm (_processor_lock);
1060 ProcessorList::iterator start, end;
1061 placement_range(p, start, end);
1063 for (ProcessorList::iterator i = start; i != end; ++i) {
1064 (*i)->deactivate ();
1067 _session.set_dirty ();
1070 /** Turn off all redirects
1073 Route::disable_processors ()
1075 Glib::RWLock::ReaderLock lm (_processor_lock);
1077 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1078 (*i)->deactivate ();
1081 _session.set_dirty ();
1084 /** Turn off all redirects with a given placement
1085 * @param p Placement of redirects to disable
1088 Route::disable_plugins (Placement p)
1090 Glib::RWLock::ReaderLock lm (_processor_lock);
1092 ProcessorList::iterator start, end;
1093 placement_range(p, start, end);
1095 for (ProcessorList::iterator i = start; i != end; ++i) {
1096 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1097 (*i)->deactivate ();
1101 _session.set_dirty ();
1104 /** Turn off all plugins
1107 Route::disable_plugins ()
1109 Glib::RWLock::ReaderLock lm (_processor_lock);
1111 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1112 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1113 (*i)->deactivate ();
1117 _session.set_dirty ();
1122 Route::ab_plugins (bool forward)
1124 Glib::RWLock::ReaderLock lm (_processor_lock);
1128 /* forward = turn off all active redirects, and mark them so that the next time
1129 we go the other way, we will revert them
1132 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1133 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1137 if ((*i)->active()) {
1138 (*i)->deactivate ();
1139 (*i)->set_next_ab_is_active (true);
1141 (*i)->set_next_ab_is_active (false);
1147 /* backward = if the redirect was marked to go active on the next ab, do so */
1149 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1151 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1155 if ((*i)->get_next_ab_is_active()) {
1158 (*i)->deactivate ();
1163 _session.set_dirty ();
1167 /** Remove processors with a given placement.
1168 * @param p Placement of processors to remove.
1171 Route::clear_processors (Placement p)
1173 const ChanCount old_pms = processor_max_streams;
1175 if (!_session.engine().connected()) {
1179 bool already_deleting = _session.deletion_in_progress();
1180 if (!already_deleting) {
1181 _session.set_deletion_in_progress();
1185 Glib::RWLock::WriterLock lm (_processor_lock);
1186 ProcessorList new_list;
1187 ProcessorStreams err;
1188 bool seen_amp = false;
1190 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1196 if ((*i) == _amp || (*i) == _meter || (*i) == _main_outs) {
1198 /* you can't remove these */
1200 new_list.push_back (*i);
1207 new_list.push_back (*i);
1210 (*i)->drop_references ();
1218 (*i)->drop_references ();
1221 new_list.push_back (*i);
1228 _processors = new_list;
1229 configure_processors_unlocked (&err); // this can't fail
1232 processor_max_streams.reset();
1233 _have_internal_generator = false;
1234 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1236 if (!already_deleting) {
1237 _session.clear_deletion_in_progress();
1242 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err)
1244 /* these can never be removed */
1246 if (processor == _amp || processor == _meter || processor == _main_outs) {
1250 ChanCount old_pms = processor_max_streams;
1252 if (!_session.engine().connected()) {
1256 processor_max_streams.reset();
1259 Glib::RWLock::WriterLock lm (_processor_lock);
1260 ProcessorList::iterator i;
1261 bool removed = false;
1263 for (i = _processors.begin(); i != _processors.end(); ) {
1264 if (*i == processor) {
1266 /* move along, see failure case for configure_processors()
1267 where we may need to reconfigure the processor.
1270 /* stop redirects that send signals to JACK ports
1271 from causing noise as a result of no longer being
1275 boost::shared_ptr<IOProcessor> iop;
1277 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (*i)) != 0) {
1279 iop->input()->disconnect (this);
1281 if (iop->output()) {
1282 iop->output()->disconnect (this);
1286 i = _processors.erase (i);
1294 _output->set_user_latency (0);
1302 if (configure_processors_unlocked (err)) {
1303 /* get back to where we where */
1304 _processors.insert (i, processor);
1305 /* we know this will work, because it worked before :) */
1306 configure_processors_unlocked (0);
1310 _have_internal_generator = false;
1312 for (i = _processors.begin(); i != _processors.end(); ++i) {
1313 boost::shared_ptr<PluginInsert> pi;
1315 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1316 if (pi->is_generator()) {
1317 _have_internal_generator = true;
1324 processor->drop_references ();
1325 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1331 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1333 ProcessorList deleted;
1335 if (!_session.engine().connected()) {
1339 processor_max_streams.reset();
1342 Glib::RWLock::WriterLock lm (_processor_lock);
1343 ProcessorList::iterator i;
1344 boost::shared_ptr<Processor> processor;
1346 ProcessorList as_we_were = _processors;
1348 for (i = _processors.begin(); i != _processors.end(); ) {
1352 /* these can never be removed */
1354 if (processor == _amp || processor == _meter || processor == _main_outs) {
1359 /* see if its in the list of processors to delete */
1361 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1366 /* stop IOProcessors that send to JACK ports
1367 from causing noise as a result of no longer being
1371 boost::shared_ptr<IOProcessor> iop;
1373 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (processor)) != 0) {
1377 deleted.push_back (processor);
1378 i = _processors.erase (i);
1381 if (deleted.empty()) {
1382 /* none of those in the requested list were found */
1386 _output->set_user_latency (0);
1388 if (configure_processors_unlocked (err)) {
1389 /* get back to where we where */
1390 _processors = as_we_were;
1391 /* we know this will work, because it worked before :) */
1392 configure_processors_unlocked (0);
1396 _have_internal_generator = false;
1398 for (i = _processors.begin(); i != _processors.end(); ++i) {
1399 boost::shared_ptr<PluginInsert> pi;
1401 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1402 if (pi->is_generator()) {
1403 _have_internal_generator = true;
1410 /* now try to do what we need to so that those that were removed will be deleted */
1412 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1413 (*i)->drop_references ();
1416 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1423 Route::configure_processors (ProcessorStreams* err)
1425 if (!_in_configure_processors) {
1426 Glib::RWLock::WriterLock lm (_processor_lock);
1427 return configure_processors_unlocked (err);
1433 Route::input_streams () const
1435 return _input->n_ports ();
1438 /** Configure the input/output configuration of each processor in the processors list.
1439 * Return 0 on success, otherwise configuration is impossible.
1442 Route::configure_processors_unlocked (ProcessorStreams* err)
1444 if (_in_configure_processors) {
1448 _in_configure_processors = true;
1450 // Check each processor in order to see if we can configure as requested
1451 ChanCount in = input_streams ();
1453 list< pair<ChanCount,ChanCount> > configuration;
1456 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1458 DEBUG_TRACE (DEBUG::Processors, "{\n");
1459 for (list<boost::shared_ptr<Processor> >::const_iterator p = _processors.begin(); p != _processors.end(); ++p) {
1460 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID = %2\n", (*p)->name(), (*p)->id()));
1462 DEBUG_TRACE (DEBUG::Processors, "}\n");
1465 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1467 if ((*p)->can_support_io_configuration(in, out)) {
1468 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1in = %2 out = %3\n",(*p)->name(), in, out));
1469 configuration.push_back(make_pair(in, out));
1476 _in_configure_processors = false;
1481 // We can, so configure everything
1482 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1483 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1484 (*p)->configure_io(c->first, c->second);
1485 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1486 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1491 _meter->reset_max_channels (processor_max_streams);
1494 /* make sure we have sufficient scratch buffers to cope with the new processor
1497 Glib::Mutex::Lock em (_session.engine().process_lock ());
1498 _session.ensure_buffers (n_process_buffers ());
1501 _in_configure_processors = false;
1506 Route::all_processors_flip ()
1508 Glib::RWLock::ReaderLock lm (_processor_lock);
1510 if (_processors.empty()) {
1514 bool first_is_on = _processors.front()->active();
1516 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1518 (*i)->deactivate ();
1524 _session.set_dirty ();
1527 /** Set all processors with a given placement to a given active state.
1528 * @param p Placement of processors to change.
1529 * @param state New active state for those processors.
1532 Route::all_processors_active (Placement p, bool state)
1534 Glib::RWLock::ReaderLock lm (_processor_lock);
1536 if (_processors.empty()) {
1539 ProcessorList::iterator start, end;
1540 placement_range(p, start, end);
1542 bool before_amp = true;
1543 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1548 if (p == PreFader && before_amp) {
1552 (*i)->deactivate ();
1557 _session.set_dirty ();
1561 Route::processor_is_prefader (boost::shared_ptr<Processor> p)
1563 bool pre_fader = true;
1564 Glib::RWLock::ReaderLock lm (_processor_lock);
1566 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1568 /* semantic note: if p == amp, we want to return true, so test
1569 for equality before checking if this is the amp
1586 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
1588 /* "new_order" is an ordered list of processors to be positioned according to "placement".
1589 NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
1590 processors in the current actual processor list that are hidden. Any visible processors
1591 in the current list but not in "new_order" will be assumed to be deleted.
1595 Glib::RWLock::WriterLock lm (_processor_lock);
1596 ChanCount old_pms = processor_max_streams;
1597 ProcessorList::iterator oiter;
1598 ProcessorList::const_iterator niter;
1599 ProcessorList as_it_was_before = _processors;
1600 ProcessorList as_it_will_be;
1602 oiter = _processors.begin();
1603 niter = new_order.begin();
1605 while (niter != new_order.end()) {
1607 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
1608 then append it to the temp list.
1610 Otherwise, see if the next processor in the old list is in the new list. if not,
1611 its been deleted. If its there, append it to the temp list.
1614 if (oiter == _processors.end()) {
1616 /* no more elements in the old list, so just stick the rest of
1617 the new order onto the temp list.
1620 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
1621 while (niter != new_order.end()) {
1628 if (!(*oiter)->display_to_user()) {
1630 as_it_will_be.push_back (*oiter);
1634 /* visible processor: check that its in the new order */
1636 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
1637 /* deleted: do nothing, shared_ptr<> will clean up */
1639 /* ignore this one, and add the next item from the new order instead */
1640 as_it_will_be.push_back (*niter);
1645 /* now remove from old order - its taken care of no matter what */
1646 oiter = _processors.erase (oiter);
1651 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
1653 if (configure_processors_unlocked (err)) {
1654 _processors = as_it_was_before;
1655 processor_max_streams = old_pms;
1661 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1674 Route::get_template()
1676 return state(false);
1680 Route::state(bool full_state)
1682 XMLNode *node = new XMLNode("Route");
1683 ProcessorList::iterator i;
1686 id().print (buf, sizeof (buf));
1687 node->add_property("id", buf);
1688 node->add_property ("name", _name);
1689 node->add_property("default-type", _default_type.to_string());
1692 node->add_property("flags", enum_2_string (_flags));
1695 node->add_property("active", _active?"yes":"no");
1696 node->add_property("phase-invert", _phase_invert?"yes":"no");
1697 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
1698 node->add_property("meter-point", enum_2_string (_meter_point));
1701 node->add_property("route-group", _route_group->name());
1704 string order_string;
1705 OrderKeys::iterator x = order_keys.begin();
1707 while (x != order_keys.end()) {
1708 order_string += string ((*x).first);
1709 order_string += '=';
1710 snprintf (buf, sizeof(buf), "%ld", (*x).second);
1711 order_string += buf;
1715 if (x == order_keys.end()) {
1719 order_string += ':';
1721 node->add_property ("order-keys", order_string);
1722 node->add_property ("self-solo", (_self_solo ? "yes" : "no"));
1723 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_upstream);
1724 node->add_property ("soloed-by-upstream", buf);
1725 snprintf (buf, sizeof (buf), "%d", _soloed_by_others_downstream);
1726 node->add_property ("soloed-by-downstream", buf);
1728 node->add_child_nocopy (_input->state (full_state));
1729 node->add_child_nocopy (_output->state (full_state));
1730 node->add_child_nocopy (_solo_control->get_state ());
1731 node->add_child_nocopy (_mute_master->get_state ());
1733 XMLNode* remote_control_node = new XMLNode (X_("RemoteControl"));
1734 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
1735 remote_control_node->add_property (X_("id"), buf);
1736 node->add_child_nocopy (*remote_control_node);
1738 if (_comment.length()) {
1739 XMLNode *cmt = node->add_child ("Comment");
1740 cmt->add_content (_comment);
1743 for (i = _processors.begin(); i != _processors.end(); ++i) {
1744 node->add_child_nocopy((*i)->state (full_state));
1748 node->add_child_copy (*_extra_xml);
1755 Route::set_state (const XMLNode& node, int version)
1757 return _set_state (node, version, true);
1761 Route::_set_state (const XMLNode& node, int version, bool /*call_base*/)
1763 if (version < 3000) {
1764 return _set_state_2X (node, version);
1768 XMLNodeConstIterator niter;
1770 XMLPropertyList plist;
1771 const XMLProperty *prop;
1773 if (node.name() != "Route"){
1774 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
1778 if ((prop = node.property (X_("name"))) != 0) {
1779 Route::set_name (prop->value());
1782 if ((prop = node.property ("id")) != 0) {
1783 _id = prop->value ();
1786 if ((prop = node.property (X_("flags"))) != 0) {
1787 _flags = Flag (string_2_enum (prop->value(), _flags));
1792 if (is_master() || is_monitor() || is_hidden()) {
1793 _mute_master->set_solo_ignore (true);
1796 /* add all processors (except amp, which is always present) */
1798 nlist = node.children();
1799 XMLNode processor_state (X_("processor_state"));
1801 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1805 if (child->name() == IO::state_node_name) {
1806 if ((prop = child->property (X_("direction"))) == 0) {
1810 if (prop->value() == "Input") {
1811 _input->set_state (*child, version);
1812 } else if (prop->value() == "Output") {
1813 _output->set_state (*child, version);
1817 if (child->name() == X_("Processor")) {
1818 processor_state.add_child_copy (*child);
1822 set_processor_state (processor_state);
1824 if ((prop = node.property ("self-solo")) != 0) {
1825 set_self_solo (string_is_affirmative (prop->value()));
1828 if ((prop = node.property ("soloed-by-upstream")) != 0) {
1829 _soloed_by_others_upstream = 0; // needed for mod_.... () to work
1830 mod_solo_by_others_upstream (atoi (prop->value()));
1833 if ((prop = node.property ("soloed-by-downstream")) != 0) {
1834 _soloed_by_others_downstream = 0; // needed for mod_.... () to work
1835 mod_solo_by_others_downstream (atoi (prop->value()));
1838 if ((prop = node.property ("solo-isolated")) != 0) {
1839 set_solo_isolated (string_is_affirmative (prop->value()), this);
1842 if ((prop = node.property (X_("phase-invert"))) != 0) {
1843 set_phase_invert (string_is_affirmative (prop->value()));
1846 if ((prop = node.property (X_("denormal-protection"))) != 0) {
1847 set_denormal_protection (string_is_affirmative (prop->value()));
1850 if ((prop = node.property (X_("active"))) != 0) {
1851 bool yn = string_is_affirmative (prop->value());
1852 _active = !yn; // force switch
1856 if ((prop = node.property (X_("meter-point"))) != 0) {
1857 MeterPoint mp = MeterPoint (string_2_enum (prop->value (), _meter_point));
1858 set_meter_point (mp);
1860 _meter->set_display_to_user (_meter_point == MeterCustom);
1864 if ((prop = node.property (X_("order-keys"))) != 0) {
1868 string::size_type colon, equal;
1869 string remaining = prop->value();
1871 while (remaining.length()) {
1873 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
1874 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1877 if (sscanf (remaining.substr (equal+1).c_str(), "%ld", &n) != 1) {
1878 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1881 set_order_key (remaining.substr (0, equal), n);
1885 colon = remaining.find_first_of (':');
1887 if (colon != string::npos) {
1888 remaining = remaining.substr (colon+1);
1895 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1898 if (child->name() == X_("Comment")) {
1900 /* XXX this is a terrible API design in libxml++ */
1902 XMLNode *cmt = *(child->children().begin());
1903 _comment = cmt->content();
1905 } else if (child->name() == X_("Extra")) {
1907 _extra_xml = new XMLNode (*child);
1909 } else if (child->name() == X_("Controllable") && (prop = child->property("name")) != 0) {
1911 if (prop->value() == "solo") {
1912 _solo_control->set_state (*child, version);
1913 _session.add_controllable (_solo_control);
1916 } else if (child->name() == X_("RemoteControl")) {
1917 if ((prop = child->property (X_("id"))) != 0) {
1919 sscanf (prop->value().c_str(), "%d", &x);
1920 set_remote_control_id (x);
1923 } else if (child->name() == X_("MuteMaster")) {
1924 _mute_master->set_state (*child, version);
1932 Route::_set_state_2X (const XMLNode& node, int version)
1935 XMLNodeConstIterator niter;
1937 XMLPropertyList plist;
1938 const XMLProperty *prop;
1940 /* 2X things which still remain to be handled:
1946 if (node.name() != "Route") {
1947 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
1951 if ((prop = node.property (X_("flags"))) != 0) {
1952 _flags = Flag (string_2_enum (prop->value(), _flags));
1957 if ((prop = node.property (X_("phase-invert"))) != 0) {
1958 set_phase_invert (string_is_affirmative (prop->value()));
1961 if ((prop = node.property (X_("denormal-protection"))) != 0) {
1962 set_denormal_protection (string_is_affirmative (prop->value()));
1965 if ((prop = node.property (X_("soloed"))) != 0) {
1966 bool yn = string_is_affirmative (prop->value());
1968 /* XXX force reset of solo status */
1970 set_solo (yn, this);
1973 if ((prop = node.property (X_("muted"))) != 0) {
1976 bool muted = string_is_affirmative (prop->value());
1982 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
1984 if (string_is_affirmative (prop->value())){
1985 mute_point = mute_point + "PreFader";
1990 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
1992 if (string_is_affirmative (prop->value())){
1995 mute_point = mute_point + ",";
1998 mute_point = mute_point + "PostFader";
2003 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2005 if (string_is_affirmative (prop->value())){
2008 mute_point = mute_point + ",";
2011 mute_point = mute_point + "Listen";
2016 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2018 if (string_is_affirmative (prop->value())){
2021 mute_point = mute_point + ",";
2024 mute_point = mute_point + "Main";
2028 _mute_master->set_mute_points (mute_point);
2032 if ((prop = node.property (X_("meter-point"))) != 0) {
2033 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2036 /* do not carry over edit/mix groups from 2.X because (a) its hard (b) they
2037 don't mean the same thing.
2040 if ((prop = node.property (X_("order-keys"))) != 0) {
2044 string::size_type colon, equal;
2045 string remaining = prop->value();
2047 while (remaining.length()) {
2049 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2050 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2053 if (sscanf (remaining.substr (equal+1).c_str(), "%ld", &n) != 1) {
2054 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2057 set_order_key (remaining.substr (0, equal), n);
2061 colon = remaining.find_first_of (':');
2063 if (colon != string::npos) {
2064 remaining = remaining.substr (colon+1);
2071 /* add standard processors */
2073 //_meter.reset (new PeakMeter (_session));
2074 //add_processor (_meter, PreFader);
2077 /* where we listen to tracks */
2078 _intreturn.reset (new InternalReturn (_session));
2079 add_processor (_intreturn, PreFader);
2081 _monitor_control.reset (new MonitorProcessor (_session));
2082 add_processor (_monitor_control, PostFader);
2085 _main_outs.reset (new Delivery (_session, _output, _mute_master, _name, Delivery::Main));
2086 add_processor (_main_outs, PostFader);
2090 nlist = node.children ();
2091 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2095 if (child->name() == IO::state_node_name) {
2097 /* there is a note in IO::set_state_2X() about why we have to call
2101 _input->set_state_2X (*child, version, true);
2102 _output->set_state_2X (*child, version, false);
2104 if ((prop = child->property (X_("name"))) != 0) {
2105 Route::set_name (prop->value ());
2108 if ((prop = child->property (X_("id"))) != 0) {
2109 _id = prop->value ();
2112 if ((prop = child->property (X_("active"))) != 0) {
2113 bool yn = string_is_affirmative (prop->value());
2114 _active = !yn; // force switch
2118 if ((prop = child->property (X_("gain"))) != 0) {
2121 if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
2122 _amp->gain_control()->set_value (val);
2126 /* Set up Panners in the IO */
2127 XMLNodeList io_nlist = child->children ();
2129 XMLNodeConstIterator io_niter;
2132 for (io_niter = io_nlist.begin(); io_niter != io_nlist.end(); ++io_niter) {
2134 io_child = *io_niter;
2136 if (io_child->name() == X_("Panner")) {
2137 _main_outs->panner()->set_state(*io_child, version);
2143 XMLNodeList redirect_nodes;
2145 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2149 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2150 redirect_nodes.push_back(child);
2155 set_processor_state_2X (redirect_nodes, version);
2157 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2160 if (child->name() == X_("Comment")) {
2162 /* XXX this is a terrible API design in libxml++ */
2164 XMLNode *cmt = *(child->children().begin());
2165 _comment = cmt->content();
2167 } else if (child->name() == X_("Extra")) {
2169 _extra_xml = new XMLNode (*child);
2171 } else if (child->name() == X_("Controllable") && (prop = child->property("name")) != 0) {
2173 if (prop->value() == "solo") {
2174 _solo_control->set_state (*child, version);
2175 _session.add_controllable (_solo_control);
2178 } else if (child->name() == X_("RemoteControl")) {
2179 if ((prop = child->property (X_("id"))) != 0) {
2181 sscanf (prop->value().c_str(), "%d", &x);
2182 set_remote_control_id (x);
2192 Route::get_processor_state ()
2194 XMLNode* root = new XMLNode (X_("redirects"));
2195 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2196 root->add_child_nocopy ((*i)->state (true));
2203 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2205 /* We don't bother removing existing processors not in nList, as this
2206 method will only be called when creating a Route from scratch, not
2207 for undo purposes. Just put processors in at the appropriate place
2211 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2212 add_processor_from_xml_2X (**i, version, _processors.begin ());
2217 Route::set_processor_state (const XMLNode& node)
2219 const XMLNodeList &nlist = node.children();
2220 XMLNodeConstIterator niter;
2221 ProcessorList new_order;
2222 bool must_configure = false;
2224 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2226 XMLProperty* prop = (*niter)->property ("type");
2228 if (prop->value() == "amp") {
2229 _amp->set_state (**niter, Stateful::current_state_version);
2230 new_order.push_back (_amp);
2231 } else if (prop->value() == "meter") {
2232 _meter->set_state (**niter, Stateful::current_state_version);
2233 new_order.push_back (_meter);
2234 } else if (prop->value() == "main-outs") {
2235 _main_outs->set_state (**niter, Stateful::current_state_version);
2236 new_order.push_back (_main_outs);
2237 } else if (prop->value() == "intreturn") {
2239 _intreturn.reset (new InternalReturn (_session));
2240 must_configure = true;
2242 _intreturn->set_state (**niter, Stateful::current_state_version);
2243 new_order.push_back (_intreturn);
2244 } else if (is_monitor() && prop->value() == "monitor") {
2245 if (!_monitor_control) {
2246 _monitor_control.reset (new MonitorProcessor (_session));
2247 must_configure = true;
2249 _monitor_control->set_state (**niter, Stateful::current_state_version);
2250 new_order.push_back (_monitor_control);
2252 ProcessorList::iterator o;
2254 for (o = _processors.begin(); o != _processors.end(); ++o) {
2255 XMLProperty* id_prop = (*niter)->property(X_("id"));
2256 if (id_prop && (*o)->id() == id_prop->value()) {
2257 (*o)->set_state (**niter, Stateful::current_state_version);
2258 new_order.push_back (*o);
2263 // If the processor (*niter) is not on the route then create it
2265 if (o == _processors.end()) {
2267 boost::shared_ptr<Processor> processor;
2269 if (prop->value() == "intsend") {
2271 processor.reset (new InternalSend (_session, _mute_master, boost::shared_ptr<Route>(), Delivery::Role (0)));
2273 } else if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
2274 prop->value() == "lv2" ||
2275 prop->value() == "vst" ||
2276 prop->value() == "audiounit") {
2278 processor.reset (new PluginInsert(_session));
2280 } else if (prop->value() == "port") {
2282 processor.reset (new PortInsert (_session, _mute_master));
2284 } else if (prop->value() == "send") {
2286 processor.reset (new Send (_session, _mute_master));
2289 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
2293 processor->set_state (**niter, Stateful::current_state_version);
2294 new_order.push_back (processor);
2295 must_configure = true;
2301 Glib::RWLock::WriterLock lm (_processor_lock);
2302 _processors = new_order;
2303 if (must_configure) {
2304 configure_processors_unlocked (0);
2308 processors_changed (RouteProcessorChange ());
2312 Route::curve_reallocate ()
2314 // _gain_automation_curve.finish_resize ();
2315 // _pan_automation_curve.finish_resize ();
2319 Route::silence (nframes_t nframes)
2323 _output->silence (nframes);
2326 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2329 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2330 boost::shared_ptr<PluginInsert> pi;
2332 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2333 // skip plugins, they don't need anything when we're not active
2337 (*i)->silence (nframes);
2340 if (nframes == _session.get_block_size()) {
2350 Route::add_internal_return ()
2353 _intreturn.reset (new InternalReturn (_session));
2354 add_processor (_intreturn, PreFader);
2359 Route::get_return_buffer () const
2361 Glib::RWLock::ReaderLock rm (_processor_lock);
2363 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2364 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
2367 BufferSet* bs = d->get_buffers ();
2376 Route::release_return_buffer () const
2378 Glib::RWLock::ReaderLock rm (_processor_lock);
2380 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2381 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
2384 return d->release_buffers ();
2390 Route::listen_via (boost::shared_ptr<Route> route, Placement placement, bool /*active*/, bool aux)
2392 vector<string> ports;
2393 vector<string>::const_iterator i;
2396 Glib::RWLock::ReaderLock rm (_processor_lock);
2398 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
2400 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
2402 if (d && d->target_route() == route) {
2404 /* if the target is the control outs, then make sure
2405 we take note of which i-send is doing that.
2408 if (route == _session.monitor_out()) {
2409 _monitor_send = boost::dynamic_pointer_cast<Delivery>(d);
2412 /* already listening via the specified IO: do nothing */
2419 boost::shared_ptr<InternalSend> listener;
2425 if (route == _session.monitor_out()) {
2426 /* master never sends to control outs */
2429 listener.reset (new InternalSend (_session, _mute_master, route, (aux ? Delivery::Aux : Delivery::Listen)));
2433 listener.reset (new InternalSend (_session, _mute_master, route, (aux ? Delivery::Aux : Delivery::Listen)));
2436 } catch (failed_constructor& err) {
2440 if (route == _session.monitor_out()) {
2441 _monitor_send = listener;
2444 if (placement == PostFader) {
2445 /* put it *really* at the end, not just after the panner (main outs)
2447 add_processor (listener, _processors.end());
2449 add_processor (listener, PreFader);
2456 Route::drop_listen (boost::shared_ptr<Route> route)
2458 ProcessorStreams err;
2459 ProcessorList::iterator tmp;
2461 Glib::RWLock::ReaderLock rl(_processor_lock);
2465 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ) {
2467 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
2469 if (d && d->target_route() == route) {
2471 remove_processor (*x, &err);
2474 /* list could have been demolished while we dropped the lock
2484 if (route == _session.monitor_out()) {
2485 _monitor_send.reset ();
2490 Route::set_comment (string cmt, void *src)
2493 comment_changed (src);
2494 _session.set_dirty ();
2498 Route::add_fed_by (boost::shared_ptr<Route> other, bool via_sends_only)
2500 FeedRecord fr (other, via_sends_only);
2502 pair<FedBy::iterator,bool> result = _fed_by.insert (fr);
2504 if (!result.second) {
2506 /* already a record for "other" - make sure sends-only information is correct */
2507 if (!via_sends_only && result.first->sends_only) {
2508 FeedRecord* frp = const_cast<FeedRecord*>(&(*result.first));
2509 frp->sends_only = false;
2513 return result.second;
2517 Route::clear_fed_by ()
2523 Route::feeds (boost::shared_ptr<Route> other, bool* via_sends_only)
2525 const FedBy& fed_by (other->fed_by());
2527 for (FedBy::iterator f = fed_by.begin(); f != fed_by.end(); ++f) {
2528 boost::shared_ptr<Route> sr = f->r.lock();
2530 if (sr && (sr.get() == this)) {
2532 if (via_sends_only) {
2533 *via_sends_only = f->sends_only;
2544 Route::direct_feeds (boost::shared_ptr<Route> other, bool* only_send)
2546 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
2548 if (_output->connected_to (other->input())) {
2549 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
2558 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
2560 boost::shared_ptr<IOProcessor> iop;
2562 if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*r)) != 0) {
2563 if (iop->feeds (other)) {
2564 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
2570 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
2573 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
2578 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
2583 Route::check_physical_connections ()
2585 _physically_connected = _output->physically_connected ();
2589 Route::handle_transport_stopped (bool /*abort_ignored*/, bool did_locate, bool can_flush_processors)
2591 nframes_t now = _session.transport_frame();
2594 Glib::RWLock::ReaderLock lm (_processor_lock);
2597 automation_snapshot (now, true);
2600 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2602 if (Config->get_plugins_stop_with_transport() && can_flush_processors) {
2603 (*i)->deactivate ();
2607 (*i)->transport_stopped (now);
2611 _roll_delay = _initial_delay;
2615 Route::input_change_handler (IOChange change, void * /*src*/)
2617 if ((change & ConfigurationChanged)) {
2618 configure_processors (0);
2623 Route::output_change_handler (IOChange change, void * /*src*/)
2625 if ((change & ConfigurationChanged)) {
2627 /* XXX resize all listeners to match _main_outs? */
2629 // configure_processors (0);
2634 Route::pans_required () const
2636 if (n_outputs().n_audio() < 2) {
2640 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
2644 Route::no_roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame,
2645 bool session_state_changing, bool /*can_record*/, bool /*rec_monitors_input*/)
2647 if (n_outputs().n_total() == 0) {
2651 if (!_active || n_inputs() == ChanCount::ZERO) {
2655 if (session_state_changing) {
2656 if (_session.transport_speed() != 0.0f) {
2657 /* we're rolling but some state is changing (e.g. our diskstream contents)
2658 so we cannot use them. Be silent till this is over.
2660 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
2665 /* we're really not rolling, so we're either delivery silence or actually
2666 monitoring, both of which are safe to do while session_state_changing is true.
2670 _amp->apply_gain_automation (false);
2671 passthru (start_frame, end_frame, nframes, 0);
2677 Route::check_initial_delay (nframes_t nframes, nframes_t& transport_frame)
2679 if (_roll_delay > nframes) {
2681 _roll_delay -= nframes;
2683 /* transport frame is not legal for caller to use */
2686 } else if (_roll_delay > 0) {
2688 nframes -= _roll_delay;
2689 silence (_roll_delay);
2690 /* we've written _roll_delay of samples into the
2691 output ports, so make a note of that for
2694 _main_outs->increment_output_offset (_roll_delay);
2695 transport_frame += _roll_delay;
2704 Route::roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame, int declick,
2705 bool /*can_record*/, bool /*rec_monitors_input*/, bool& /* need_butler */)
2708 // automation snapshot can also be called from the non-rt context
2709 // and it uses the processor list, so we try to acquire the lock here
2710 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2713 automation_snapshot (_session.transport_frame(), false);
2717 if (n_outputs().n_total() == 0) {
2721 if (!_active || n_inputs().n_total() == 0) {
2726 nframes_t unused = 0;
2728 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
2734 passthru (start_frame, end_frame, nframes, declick);
2740 Route::silent_roll (nframes_t nframes, sframes_t /*start_frame*/, sframes_t /*end_frame*/,
2741 bool /*can_record*/, bool /*rec_monitors_input*/, bool& /* need_butler */)
2748 Route::toggle_monitor_input ()
2750 for (PortSet::iterator i = _input->ports().begin(); i != _input->ports().end(); ++i) {
2751 i->ensure_monitor_input( ! i->monitoring_input());
2756 Route::has_external_redirects () const
2758 // FIXME: what about sends? - they don't return a signal back to ardour?
2760 boost::shared_ptr<const PortInsert> pi;
2762 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2764 if ((pi = boost::dynamic_pointer_cast<const PortInsert>(*i)) != 0) {
2766 for (PortSet::const_iterator port = pi->output()->ports().begin(); port != pi->output()->ports().end(); ++port) {
2768 string port_name = port->name();
2769 string client_name = port_name.substr (0, port_name.find(':'));
2771 /* only say "yes" if the redirect is actually in use */
2773 if (client_name != "ardour" && pi->active()) {
2784 Route::flush_processors ()
2786 /* XXX shouldn't really try to take this lock, since
2787 this is called from the RT audio thread.
2790 Glib::RWLock::ReaderLock lm (_processor_lock);
2792 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2793 (*i)->deactivate ();
2799 Route::set_meter_point (MeterPoint p)
2801 /* CAN BE CALLED FROM PROCESS CONTEXT */
2803 if (_meter_point == p) {
2807 bool meter_was_visible_to_user = _meter->display_to_user ();
2810 Glib::RWLock::WriterLock lm (_processor_lock);
2812 if (p != MeterCustom) {
2813 // Move meter in the processors list to reflect the new position
2814 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
2815 _processors.erase(loc);
2818 loc = _processors.begin();
2821 loc = find (_processors.begin(), _processors.end(), _amp);
2823 case MeterPostFader:
2824 loc = _processors.end();
2832 if (loc == _processors.begin()) {
2833 m_in = _input->n_ports();
2835 ProcessorList::iterator before = loc;
2837 m_in = (*before)->output_streams ();
2840 _meter->reflect_inputs (m_in);
2842 _processors.insert (loc, _meter);
2844 /* we do not need to reconfigure the processors, because the meter
2845 (a) is always ready to handle processor_max_streams
2846 (b) is always an N-in/N-out processor, and thus moving
2847 it doesn't require any changes to the other processors.
2850 _meter->set_display_to_user (false);
2854 // just make it visible and let the user move it
2856 _meter->set_display_to_user (true);
2861 meter_change (); /* EMIT SIGNAL */
2863 bool const meter_visibly_changed = (_meter->display_to_user() != meter_was_visible_to_user);
2865 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, meter_visibly_changed)); /* EMIT SIGNAL */
2869 Route::put_monitor_send_at (Placement p)
2871 if (!_monitor_send) {
2876 Glib::RWLock::WriterLock lm (_processor_lock);
2877 ProcessorList as_it_was (_processors);
2878 ProcessorList::iterator loc = find(_processors.begin(), _processors.end(), _monitor_send);
2879 _processors.erase(loc);
2883 loc = find(_processors.begin(), _processors.end(), _amp);
2884 if (loc != _processors.begin()) {
2889 loc = _processors.end();
2893 _processors.insert (loc, _monitor_send);
2895 if (configure_processors_unlocked (0)) {
2896 _processors = as_it_was;
2897 configure_processors_unlocked (0); // it worked before we tried to add it ...
2902 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2903 _session.set_dirty ();
2907 Route::update_total_latency ()
2909 nframes_t old = _output->effective_latency();
2910 nframes_t own_latency = _output->user_latency();
2912 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2913 if ((*i)->active ()) {
2914 own_latency += (*i)->signal_latency ();
2918 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal redirect latency = %2\n", _name, own_latency));
2920 _output->set_port_latency (own_latency);
2922 if (_output->user_latency() == 0) {
2924 /* this (virtual) function is used for pure Routes,
2925 not derived classes like AudioTrack. this means
2926 that the data processed here comes from an input
2927 port, not prerecorded material, and therefore we
2928 have to take into account any input latency.
2931 own_latency += _input->signal_latency ();
2934 if (old != own_latency) {
2935 _output->set_latency_delay (own_latency);
2936 signal_latency_changed (); /* EMIT SIGNAL */
2939 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: input latency = %2 total = %3\n", _name, _input->signal_latency(), own_latency));
2941 return _output->effective_latency ();
2945 Route::set_user_latency (nframes_t nframes)
2947 _output->set_user_latency (nframes);
2948 _session.update_latency_compensation (false, false);
2952 Route::set_latency_delay (nframes_t longest_session_latency)
2954 nframes_t old = _initial_delay;
2956 if (_output->effective_latency() < longest_session_latency) {
2957 _initial_delay = longest_session_latency - _output->effective_latency();
2962 if (_initial_delay != old) {
2963 initial_delay_changed (); /* EMIT SIGNAL */
2966 if (_session.transport_stopped()) {
2967 _roll_delay = _initial_delay;
2972 Route::automation_snapshot (nframes_t now, bool force)
2974 panner()->automation_snapshot (now, force);
2976 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2977 (*i)->automation_snapshot (now, force);
2981 Route::SoloControllable::SoloControllable (std::string name, Route& r)
2982 : AutomationControl (r.session(), Evoral::Parameter (SoloAutomation),
2983 boost::shared_ptr<AutomationList>(), name)
2986 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(SoloAutomation)));
2991 Route::SoloControllable::set_value (float val)
2993 bool bval = ((val >= 0.5f) ? true: false);
2995 this is how it should be done
2997 boost::shared_ptr<RouteList> rl (new RouteList);
2998 rl->push_back (route);
3000 if (Config->get_solo_control_is_listen_control()) {
3001 _session.set_listen (rl, bval);
3003 _session.set_solo (rl, bval);
3006 route.set_solo (bval, this);
3011 Route::SoloControllable::get_value (void) const
3013 if (Config->get_solo_control_is_listen_control()) {
3014 return route.listening() ? 1.0f : 0.0f;
3016 return route.self_soloed() ? 1.0f : 0.0f;
3020 Route::MuteControllable::MuteControllable (std::string name, Route& r)
3021 : AutomationControl (r.session(), Evoral::Parameter (MuteAutomation),
3022 boost::shared_ptr<AutomationList>(), name)
3025 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(MuteAutomation)));
3030 Route::MuteControllable::set_value (float val)
3032 bool bval = ((val >= 0.5f) ? true: false);
3034 this is how it should be done
3036 boost::shared_ptr<RouteList> rl (new RouteList);
3037 rl->push_back (route);
3038 _session.set_mute (rl, bval);
3040 route.set_mute (bval, this);
3045 Route::MuteControllable::get_value (void) const
3047 return route.muted() ? 1.0f : 0.0f;
3051 Route::set_block_size (nframes_t nframes)
3053 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3054 (*i)->set_block_size (nframes);
3057 _session.ensure_buffers (n_process_buffers ());
3061 Route::protect_automation ()
3063 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
3064 (*i)->protect_automation();
3068 Route::set_pending_declick (int declick)
3071 /* this call is not allowed to turn off a pending declick unless "force" is true */
3073 _pending_declick = declick;
3075 // cerr << _name << ": after setting to " << declick << " pending declick = " << _pending_declick << endl;
3077 _pending_declick = 0;
3082 /** Shift automation forwards from a particular place, thereby inserting time.
3083 * Adds undo commands for any shifts that are performed.
3085 * @param pos Position to start shifting from.
3086 * @param frames Amount to shift forwards by.
3090 Route::shift (nframes64_t /*pos*/, nframes64_t /*frames*/)
3092 #ifdef THIS_NEEDS_FIXING_FOR_V3
3094 /* gain automation */
3095 XMLNode &before = _gain_control->get_state ();
3096 _gain_control->shift (pos, frames);
3097 XMLNode &after = _gain_control->get_state ();
3098 _session.add_command (new MementoCommand<AutomationList> (_gain_automation_curve, &before, &after));
3100 /* pan automation */
3101 for (std::vector<StreamPanner*>::iterator i = _panner->begin (); i != _panner->end (); ++i) {
3102 Curve & c = (*i)->automation ();
3103 XMLNode &before = c.get_state ();
3104 c.shift (pos, frames);
3105 XMLNode &after = c.get_state ();
3106 _session.add_command (new MementoCommand<AutomationList> (c, &before, &after));
3109 /* redirect automation */
3111 Glib::RWLock::ReaderLock lm (redirect_lock);
3112 for (RedirectList::iterator i = _redirects.begin (); i != _redirects.end (); ++i) {
3115 (*i)->what_has_automation (a);
3117 for (set<uint32_t>::const_iterator j = a.begin (); j != a.end (); ++j) {
3118 AutomationList & al = (*i)->automation_list (*j);
3119 XMLNode &before = al.get_state ();
3120 al.shift (pos, frames);
3121 XMLNode &after = al.get_state ();
3122 _session.add_command (new MementoCommand<AutomationList> (al, &before, &after));
3132 Route::save_as_template (const string& path, const string& name)
3134 XMLNode& node (state (false));
3137 IO::set_name_in_state (*node.children().front(), name);
3139 tree.set_root (&node);
3140 return tree.write (path.c_str());
3145 Route::set_name (const string& str)
3151 name = Route::ensure_track_or_route_name (str, _session);
3152 SessionObject::set_name (name);
3154 ret = (_input->set_name(name) && _output->set_name(name));
3158 Glib::RWLock::ReaderLock lm (_processor_lock);
3160 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3162 /* rename all I/O processors that have inputs or outputs */
3164 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor> (*i);
3166 if (iop && (iop->output() || iop->input())) {
3167 if (!iop->set_name (name)) {
3178 boost::shared_ptr<Send>
3179 Route::internal_send_for (boost::shared_ptr<const Route> target) const
3181 Glib::RWLock::ReaderLock lm (_processor_lock);
3183 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3184 boost::shared_ptr<InternalSend> send;
3186 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
3187 if (send->target_route() == target) {
3193 return boost::shared_ptr<Send>();
3197 Route::set_phase_invert (bool yn)
3199 if (_phase_invert != yn) {
3201 _phase_invert = 0xffff; // XXX all channels
3203 _phase_invert = 0; // XXX no channels
3206 phase_invert_changed (); /* EMIT SIGNAL */
3207 _session.set_dirty ();
3212 Route::phase_invert () const
3214 return _phase_invert != 0;
3218 Route::set_denormal_protection (bool yn)
3220 if (_denormal_protection != yn) {
3221 _denormal_protection = yn;
3222 denormal_protection_changed (); /* EMIT SIGNAL */
3227 Route::denormal_protection () const
3229 return _denormal_protection;
3233 Route::set_active (bool yn)
3235 if (_active != yn) {
3237 _input->set_active (yn);
3238 _output->set_active (yn);
3239 active_changed (); // EMIT SIGNAL
3246 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
3252 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3254 boost::shared_ptr<Send> s;
3255 boost::shared_ptr<Return> r;
3257 if ((s = boost::dynamic_pointer_cast<Send> (*i)) != 0) {
3258 s->meter()->meter();
3259 } else if ((r = boost::dynamic_pointer_cast<Return> (*i)) != 0) {
3260 r->meter()->meter ();
3265 boost::shared_ptr<Panner>
3266 Route::panner() const
3268 return _main_outs->panner();
3271 boost::shared_ptr<AutomationControl>
3272 Route::gain_control() const
3274 return _amp->gain_control();
3277 boost::shared_ptr<AutomationControl>
3278 Route::get_control (const Evoral::Parameter& param)
3280 /* either we own the control or .... */
3282 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
3286 /* maybe one of our processors does or ... */
3288 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
3289 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3290 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
3298 /* nobody does so we'll make a new one */
3300 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
3307 boost::shared_ptr<Processor>
3308 Route::nth_plugin (uint32_t n)
3310 Glib::RWLock::ReaderLock lm (_processor_lock);
3311 ProcessorList::iterator i;
3313 for (i = _processors.begin(); i != _processors.end(); ++i) {
3314 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
3321 return boost::shared_ptr<Processor> ();
3324 boost::shared_ptr<Processor>
3325 Route::nth_send (uint32_t n)
3327 Glib::RWLock::ReaderLock lm (_processor_lock);
3328 ProcessorList::iterator i;
3330 for (i = _processors.begin(); i != _processors.end(); ++i) {
3331 if (boost::dynamic_pointer_cast<Send> (*i)) {
3338 return boost::shared_ptr<Processor> ();
3342 Route::has_io_processor_named (const string& name)
3344 Glib::RWLock::ReaderLock lm (_processor_lock);
3345 ProcessorList::iterator i;
3347 for (i = _processors.begin(); i != _processors.end(); ++i) {
3348 if (boost::dynamic_pointer_cast<Send> (*i) ||
3349 boost::dynamic_pointer_cast<PortInsert> (*i)) {
3350 if ((*i)->name() == name) {
3360 Route::set_graph_level (int32_t l)