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)
76 , _solo_control (new SoloControllable (X_("solo"), *this))
77 , _mute_control (new MuteControllable (X_("mute"), *this))
78 , _mute_master (new MuteMaster (sess, name))
79 , _default_type (default_type)
84 /* add standard processors other than amp (added by ::init()) */
86 _meter.reset (new PeakMeter (_session));
87 _meter->set_display_to_user (false);
89 add_processor (_meter, PostFader);
91 _main_outs.reset (new Delivery (_session, _output, _mute_master, _name, Delivery::Main));
93 add_processor (_main_outs, PostFader);
96 /* where we listen to tracks */
97 _intreturn.reset (new InternalReturn (_session));
98 add_processor (_intreturn, PreFader);
100 ProcessorList::iterator i;
102 for (i = _processors.begin(); i != _processors.end(); ++i) {
103 if (*i == _intreturn) {
109 /* the thing that provides proper control over a control/monitor/listen bus
110 (such as per-channel cut, dim, solo, invert, etc).
111 It always goes right after the internal return;
113 _monitor_control.reset (new MonitorProcessor (_session));
114 add_processor (_monitor_control, i);
119 /* now that we have _meter, its safe to connect to this */
121 Metering::Meter.connect_same_thread (*this, (boost::bind (&Route::meter, this)));
124 Route::Route (Session& sess, const XMLNode& node, DataType default_type)
125 : SessionObject (sess, "toBeReset")
126 , AutomatableControls (sess)
127 , _solo_control (new SoloControllable (X_("solo"), *this))
128 , _mute_control (new MuteControllable (X_("mute"), *this))
129 , _mute_master (new MuteMaster (sess, "toBeReset"))
130 , _default_type (default_type)
134 _set_state (node, Stateful::loading_state_version, false);
136 /* now that we have _meter, its safe to connect to this */
138 Metering::Meter.connect_same_thread (*this, (boost::bind (&Route::meter, this)));
145 _soloed_by_others = 0;
149 processor_max_streams.reset();
151 order_keys[N_("signal")] = order_key_cnt++;
153 _meter_point = MeterPostFader;
156 _have_internal_generator = false;
157 _declickable = false;
158 _pending_declick = true;
159 _remote_control_id = 0;
160 _in_configure_processors = false;
161 _mute_points = MuteMaster::AllPoints;
164 _denormal_protection = false;
166 /* add standard controls */
168 _solo_control->set_flags (Controllable::Flag (_solo_control->flags() | Controllable::Toggle));
169 _mute_control->set_flags (Controllable::Flag (_solo_control->flags() | Controllable::Toggle));
171 add_control (_solo_control);
172 add_control (_mute_control);
174 /* input and output objects */
176 _input.reset (new IO (_session, _name, IO::Input, _default_type));
177 _output.reset (new IO (_session, _name, IO::Output, _default_type));
179 _input->changed.connect_same_thread (*this, boost::bind (&Route::input_change_handler, this, _1, _2));
180 _output->changed.connect_same_thread (*this, boost::bind (&Route::output_change_handler, this, _1, _2));
182 /* add amp processor */
184 _amp.reset (new Amp (_session, _mute_master));
185 add_processor (_amp, PostFader);
190 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
192 /* do this early so that we don't get incoming signals as we are going through destruction
197 /* don't use clear_processors here, as it depends on the session which may
198 be half-destroyed by now
201 Glib::RWLock::WriterLock lm (_processor_lock);
202 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
203 (*i)->drop_references ();
206 _processors.clear ();
210 Route::set_remote_control_id (uint32_t id, bool notify_class_listeners)
212 if (id != _remote_control_id) {
213 _remote_control_id = id;
214 RemoteControlIDChanged ();
215 if (notify_class_listeners) {
216 RemoteControlIDChange ();
222 Route::remote_control_id() const
224 return _remote_control_id;
228 Route::order_key (std::string const & name) const
230 OrderKeys::const_iterator i = order_keys.find (name);
231 if (i == order_keys.end()) {
239 Route::set_order_key (std::string const & name, long n)
241 order_keys[name] = n;
243 if (Config->get_sync_all_route_ordering()) {
244 for (OrderKeys::iterator x = order_keys.begin(); x != order_keys.end(); ++x) {
249 _session.set_dirty ();
252 /** Set all order keys to be the same as that for `base', if such a key
253 * exists in this route.
254 * @param base Base key.
257 Route::sync_order_keys (std::string const & base)
259 if (order_keys.empty()) {
263 OrderKeys::iterator i;
266 if ((i = order_keys.find (base)) == order_keys.end()) {
267 /* key doesn't exist, use the first existing key (during session initialization) */
268 i = order_keys.begin();
272 /* key exists - use it and reset all others (actually, itself included) */
274 i = order_keys.begin();
277 for (; i != order_keys.end(); ++i) {
283 Route::ensure_track_or_route_name(string name, Session &session)
285 string newname = name;
287 while (session.route_by_name (newname) != NULL) {
288 newname = bump_name_once (newname);
296 Route::inc_gain (gain_t fraction, void *src)
298 _amp->inc_gain (fraction, src);
302 Route::set_gain (gain_t val, void *src)
304 if (src != 0 && _route_group && src != _route_group && _route_group->is_active() && _route_group->is_gain()) {
306 if (_route_group->is_relative()) {
308 gain_t usable_gain = _amp->gain();
309 if (usable_gain < 0.000001f) {
310 usable_gain = 0.000001f;
314 if (delta < 0.000001f) {
318 delta -= usable_gain;
323 gain_t factor = delta / usable_gain;
326 factor = _route_group->get_max_factor(factor);
327 if (factor == 0.0f) {
328 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
332 factor = _route_group->get_min_factor(factor);
333 if (factor == 0.0f) {
334 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
339 _route_group->apply (&Route::inc_gain, factor, _route_group);
343 _route_group->apply (&Route::set_gain, val, _route_group);
349 if (val == _amp->gain()) {
353 _amp->set_gain (val, src);
356 /** Process this route for one (sub) cycle (process thread)
358 * @param bufs Scratch buffers to use for the signal path
359 * @param start_frame Initial transport frame
360 * @param end_frame Final transport frame
361 * @param nframes Number of frames to output (to ports)
363 * Note that (end_frame - start_frame) may not be equal to nframes when the
364 * transport speed isn't 1.0 (eg varispeed).
367 Route::process_output_buffers (BufferSet& bufs,
368 sframes_t start_frame, sframes_t end_frame, nframes_t nframes,
369 bool /*with_processors*/, int declick)
373 bufs.is_silent (false);
375 switch (Config->get_monitoring_model()) {
376 case HardwareMonitoring:
377 case ExternalMonitoring:
378 monitor = !record_enabled() || (_session.config.get_auto_input() && !_session.actively_recording());
385 declick = _pending_declick;
388 /* figure out if we're going to use gain automation */
389 _amp->setup_gain_automation (start_frame, end_frame, nframes);
392 /* tell main outs what to do about monitoring */
393 _main_outs->no_outs_cuz_we_no_monitor (!monitor);
396 /* -------------------------------------------------------------------------------------------
397 GLOBAL DECLICK (for transport changes etc.)
398 ----------------------------------------------------------------------------------------- */
401 Amp::apply_gain (bufs, nframes, 0.0, 1.0);
402 } else if (declick < 0) {
403 Amp::apply_gain (bufs, nframes, 1.0, 0.0);
406 _pending_declick = 0;
408 /* -------------------------------------------------------------------------------------------
409 DENORMAL CONTROL/PHASE INVERT
410 ----------------------------------------------------------------------------------------- */
416 if (_denormal_protection || Config->get_denormal_protection()) {
418 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
419 Sample* const sp = i->data();
421 if (_phase_invert & chn) {
422 for (nframes_t nx = 0; nx < nframes; ++nx) {
427 for (nframes_t nx = 0; nx < nframes; ++nx) {
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) {
448 if (_denormal_protection || Config->get_denormal_protection()) {
450 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
451 Sample* const sp = i->data();
452 for (nframes_t nx = 0; nx < nframes; ++nx) {
460 /* -------------------------------------------------------------------------------------------
462 ----------------------------------------------------------------------------------------- */
464 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
467 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
469 if (bufs.count() != (*i)->input_streams()) {
470 cerr << _name << " bufs = " << bufs.count()
471 << " input for " << (*i)->name() << " = " << (*i)->input_streams()
474 assert (bufs.count() == (*i)->input_streams());
476 (*i)->run (bufs, start_frame, end_frame, nframes, *i != _processors.back());
477 bufs.set_count ((*i)->output_streams());
483 Route::n_process_buffers ()
485 return max (_input->n_ports(), processor_max_streams);
489 Route::passthru (sframes_t start_frame, sframes_t end_frame, nframes_t nframes, int declick)
491 BufferSet& bufs = _session.get_scratch_buffers (n_process_buffers());
495 assert (bufs.available() >= _input->n_ports());
497 if (_input->n_ports() == ChanCount::ZERO) {
501 bufs.set_count (_input->n_ports());
503 if (is_monitor() && _session.listening()) {
505 /* control/monitor bus ignores input ports when something is
506 feeding the listen "stream". data will "arrive" into the
507 route from the intreturn processor element.
509 bufs.silence (nframes, 0);
513 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
515 BufferSet::iterator o = bufs.begin(*t);
516 PortSet& ports (_input->ports());
518 for (PortSet::iterator i = ports.begin(*t); i != ports.end(*t); ++i, ++o) {
519 o->read_from (i->get_buffer(nframes), nframes);
524 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
525 process_output_buffers (bufs, start_frame, end_frame, nframes, true, declick);
529 Route::passthru_silence (sframes_t start_frame, sframes_t end_frame, nframes_t nframes, int declick)
531 BufferSet& bufs (_session.get_silent_buffers (n_process_buffers()));
532 bufs.set_count (_input->n_ports());
533 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
534 process_output_buffers (bufs, start_frame, end_frame, nframes, true, declick);
538 Route::set_listen (bool yn, void* src)
541 if (yn != _monitor_send->active()) {
543 _monitor_send->set_solo_level (1);
544 _monitor_send->activate ();
546 _monitor_send->set_solo_level (0);
547 _monitor_send->deactivate ();
550 listen_changed (src); /* EMIT SIGNAL */
556 Route::listening () const
559 return _monitor_send->active ();
566 Route::set_solo_safe (bool yn, void *src)
568 if (_solo_safe != yn) {
570 solo_safe_changed (src);
575 Route::solo_safe() const
581 Route::set_solo (bool yn, void *src)
587 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_solo()) {
588 _route_group->apply (&Route::set_solo, yn, _route_group);
592 if (self_soloed() != yn) {
594 set_delivery_solo ();
595 solo_changed (src); /* EMIT SIGNAL */
596 _solo_control->Changed (); /* EMIT SIGNAL */
601 Route::set_self_solo (bool yn)
607 Route::mod_solo_by_others (int32_t delta)
610 if (_soloed_by_others >= (uint32_t) delta) {
611 _soloed_by_others += delta;
613 _soloed_by_others = 0;
616 _soloed_by_others += delta;
619 set_delivery_solo ();
623 Route::set_delivery_solo ()
625 /* tell all delivery processors what the solo situation is, so that they keep
626 delivering even though Session::soloing() is true and they were not
630 Glib::RWLock::ReaderLock rm (_processor_lock);
631 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
632 boost::shared_ptr<Delivery> d;
634 if ((d = boost::dynamic_pointer_cast<Delivery> (*i)) != 0) {
635 d->set_solo_level (soloed ());
636 d->set_solo_isolated (solo_isolated());
642 Route::set_solo_isolated (bool yn, void *src)
644 if (is_master() || is_monitor() || is_hidden()) {
648 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_solo()) {
649 _route_group->apply (&Route::set_solo_isolated, yn, _route_group);
653 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
655 boost::shared_ptr<RouteList> routes = _session.get_routes ();
656 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
658 bool does_feed = feeds (*i, &sends_only);
660 if (does_feed && !sends_only) {
661 (*i)->set_solo_isolated (yn, (*i)->route_group());
665 bool changed = false;
668 if (_solo_isolated == 0) {
673 changed = (_solo_isolated == 1);
674 if (_solo_isolated > 0) {
680 set_delivery_solo ();
681 solo_isolated_changed (src);
686 Route::solo_isolated () const
688 return _solo_isolated > 0;
692 Route::set_mute_points (MuteMaster::MutePoint mp)
695 mute_points_changed (); /* EMIT SIGNAL */
697 if (_mute_master->muted()) {
698 _mute_master->mute_at (_mute_points);
699 mute_changed (this); /* EMIT SIGNAL */
704 Route::set_mute (bool yn, void *src)
706 if (_route_group && src != _route_group && _route_group->is_active() && _route_group->is_mute()) {
707 _route_group->apply (&Route::set_mute, yn, _route_group);
713 _mute_master->mute_at (_mute_points);
715 _mute_master->clear_mute ();
718 mute_changed (src); /* EMIT SIGNAL */
725 return _mute_master->muted ();
730 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
732 cerr << name << " {" << endl;
733 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
734 p != procs.end(); ++p) {
735 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << endl;
742 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err)
744 ProcessorList::iterator loc;
746 /* XXX this is not thread safe - we don't hold the lock across determining the iter
747 to add before and actually doing the insertion. dammit.
750 if (placement == PreFader) {
751 /* generic pre-fader: insert immediately before the amp */
752 loc = find (_processors.begin(), _processors.end(), _amp);
754 /* generic post-fader: insert right before the main outs */
755 loc = find (_processors.begin(), _processors.end(), _main_outs);
758 return add_processor (processor, loc, err);
762 /** Add a processor to the route.
763 * @a iter must point to an iterator in _processors and the new
764 * processor will be inserted immediately before this location. Otherwise,
765 * @a position is used.
768 Route::add_processor (boost::shared_ptr<Processor> processor, ProcessorList::iterator iter, ProcessorStreams* err, bool activation_allowed)
770 ChanCount old_pms = processor_max_streams;
772 if (!_session.engine().connected() || !processor) {
777 Glib::RWLock::WriterLock lm (_processor_lock);
779 boost::shared_ptr<PluginInsert> pi;
780 boost::shared_ptr<PortInsert> porti;
782 ProcessorList::iterator loc = find(_processors.begin(), _processors.end(), processor);
784 if (processor == _amp || processor == _meter || processor == _main_outs) {
785 // Ensure only one of these are in the list at any time
786 if (loc != _processors.end()) {
787 if (iter == loc) { // Already in place, do nothing
789 } else { // New position given, relocate
790 _processors.erase (loc);
795 if (loc != _processors.end()) {
796 cerr << "ERROR: Processor added to route twice!" << endl;
803 _processors.insert (loc, processor);
805 // Set up processor list channels. This will set processor->[input|output]_streams(),
806 // configure redirect ports properly, etc.
808 if (configure_processors_unlocked (err)) {
809 ProcessorList::iterator ploc = loc;
811 _processors.erase(ploc);
812 configure_processors_unlocked (0); // it worked before we tried to add it ...
813 cerr << "configure failed\n";
817 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
819 if (pi->natural_input_streams() == ChanCount::ZERO) {
820 /* generator plugin */
821 _have_internal_generator = true;
826 if (activation_allowed && (processor != _monitor_send)) {
827 processor->activate ();
830 processor->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false, false));
832 _output->set_user_latency (0);
835 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
841 Route::add_processor_from_xml (const XMLNode& node, ProcessorList::iterator iter)
843 const XMLProperty *prop;
845 if (node.name() != "Processor") {
850 if ((prop = node.property ("type")) != 0) {
852 boost::shared_ptr<Processor> processor;
854 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
855 prop->value() == "lv2" ||
856 prop->value() == "vst" ||
857 prop->value() == "audiounit") {
859 processor.reset (new PluginInsert(_session, node));
861 } else if (prop->value() == "port") {
863 processor.reset (new PortInsert (_session, _mute_master, node));
865 } else if (prop->value() == "send") {
867 processor.reset (new Send (_session, _mute_master, node));
869 } else if (prop->value() == "meter") {
872 if (_meter->set_state (node, Stateful::loading_state_version)) {
879 _meter.reset (new PeakMeter (_session, node));
880 _meter->set_display_to_user (_meter_point == MeterCustom);
883 } else if (prop->value() == "monitor") {
885 if (_monitor_control) {
886 if (_monitor_control->set_state (node, Stateful::loading_state_version)) {
893 _monitor_control.reset (new MonitorProcessor (_session));
894 _monitor_control->set_state (node, Stateful::loading_state_version);
895 processor = _monitor_control;
897 } else if (prop->value() == "amp") {
899 /* amp always exists */
902 if (processor->set_state (node, Stateful::loading_state_version)) {
905 /* never any reason to add it */
909 } else if (prop->value() == "intsend") {
911 InternalSend* isend = new InternalSend (_session, _mute_master, node);
913 if (_session.monitor_out() && (isend->target_id() == _session.monitor_out()->id())) {
914 _monitor_send.reset (isend);
915 if (_monitor_send->active()) {
916 _monitor_send->set_solo_level (1);
918 _monitor_send->set_solo_level (0);
922 processor.reset (isend);
924 } else if (prop->value() == "intreturn") {
926 /* a route only has one internal return. If it exists already
927 just set its state, and return
931 if (_intreturn->set_state (node, Stateful::loading_state_version)) {
937 _intreturn.reset (new InternalReturn (_session, node));
938 processor = _intreturn;
940 } else if (prop->value() == "main-outs") {
943 if (_main_outs->set_state (node, Stateful::loading_state_version)) {
950 _main_outs.reset (new Delivery (_session, _output, _mute_master, node));
951 processor = _main_outs;
954 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
958 if (iter == _processors.end() && processor->display_to_user() && !_processors.empty()) {
959 /* check for invisible processors stacked at the end and leave them there */
960 ProcessorList::iterator p;
961 p = _processors.end();
963 while (!(*p)->display_to_user() && p != _processors.begin()) {
970 return (add_processor (processor, iter, 0, false) == 0);
973 error << _("Processor XML node has no type property") << endmsg;
978 catch (failed_constructor &err) {
979 warning << _("processor could not be created. Ignored.") << endmsg;
986 Route::add_processor_from_xml_2X (const XMLNode& node, int version, ProcessorList::iterator iter)
988 const XMLProperty *prop;
991 boost::shared_ptr<Processor> processor;
993 if (node.name() == "Insert") {
995 if ((prop = node.property ("type")) != 0) {
997 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
998 prop->value() == "lv2" ||
999 prop->value() == "vst" ||
1000 prop->value() == "audiounit") {
1002 processor.reset (new PluginInsert (_session, node));
1006 processor.reset (new PortInsert (_session, _mute_master, node));
1011 } else if (node.name() == "Send") {
1013 processor.reset (new Send (_session, _mute_master, node, version));
1017 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
1021 if (iter == _processors.end() && processor->display_to_user() && !_processors.empty()) {
1022 /* check for invisible processors stacked at the end and leave them there */
1023 ProcessorList::iterator p;
1024 p = _processors.end();
1026 while (!(*p)->display_to_user() && p != _processors.begin()) {
1033 return (add_processor (processor, iter) == 0);
1036 catch (failed_constructor &err) {
1037 warning << _("processor could not be created. Ignored.") << endmsg;
1043 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
1045 ProcessorList::iterator loc;
1048 loc = find(_processors.begin(), _processors.end(), before);
1050 /* nothing specified - at end but before main outs */
1051 loc = find (_processors.begin(), _processors.end(), _main_outs);
1054 return add_processors (others, loc, err);
1058 Route::add_processors (const ProcessorList& others, ProcessorList::iterator iter, ProcessorStreams* err)
1060 /* NOTE: this is intended to be used ONLY when copying
1061 processors from another Route. Hence the subtle
1062 differences between this and ::add_processor()
1065 ChanCount old_pms = processor_max_streams;
1067 if (!_session.engine().connected()) {
1071 if (others.empty()) {
1076 Glib::RWLock::WriterLock lm (_processor_lock);
1078 ChanCount potential_max_streams = ChanCount::max (_input->n_ports(), _output->n_ports());
1080 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1082 // Ensure meter only appears in the list once
1084 ProcessorList::iterator m = find(_processors.begin(), _processors.end(), *i);
1085 if (m != _processors.end()) {
1086 _processors.erase(m);
1090 boost::shared_ptr<PluginInsert> pi;
1092 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1095 ChanCount m = max (pi->input_streams(), pi->output_streams());
1097 if (m > potential_max_streams) {
1098 potential_max_streams = m;
1102 ProcessorList::iterator inserted = _processors.insert (iter, *i);
1104 if ((*i)->active()) {
1108 if (configure_processors_unlocked (err)) {
1109 _processors.erase (inserted);
1110 configure_processors_unlocked (0); // it worked before we tried to add it ...
1114 (*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false, false));
1117 _output->set_user_latency (0);
1120 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1126 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1128 if (p == PreFader) {
1129 start = _processors.begin();
1130 end = find(_processors.begin(), _processors.end(), _amp);
1132 start = find(_processors.begin(), _processors.end(), _amp);
1134 end = _processors.end();
1138 /** Turn off all processors with a given placement
1139 * @param p Placement of processors to disable
1142 Route::disable_processors (Placement p)
1144 Glib::RWLock::ReaderLock lm (_processor_lock);
1146 ProcessorList::iterator start, end;
1147 placement_range(p, start, end);
1149 for (ProcessorList::iterator i = start; i != end; ++i) {
1150 (*i)->deactivate ();
1153 _session.set_dirty ();
1156 /** Turn off all redirects
1159 Route::disable_processors ()
1161 Glib::RWLock::ReaderLock lm (_processor_lock);
1163 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1164 (*i)->deactivate ();
1167 _session.set_dirty ();
1170 /** Turn off all redirects with a given placement
1171 * @param p Placement of redirects to disable
1174 Route::disable_plugins (Placement p)
1176 Glib::RWLock::ReaderLock lm (_processor_lock);
1178 ProcessorList::iterator start, end;
1179 placement_range(p, start, end);
1181 for (ProcessorList::iterator i = start; i != end; ++i) {
1182 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1183 (*i)->deactivate ();
1187 _session.set_dirty ();
1190 /** Turn off all plugins
1193 Route::disable_plugins ()
1195 Glib::RWLock::ReaderLock lm (_processor_lock);
1197 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1198 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1199 (*i)->deactivate ();
1203 _session.set_dirty ();
1208 Route::ab_plugins (bool forward)
1210 Glib::RWLock::ReaderLock lm (_processor_lock);
1214 /* forward = turn off all active redirects, and mark them so that the next time
1215 we go the other way, we will revert them
1218 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1219 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1223 if ((*i)->active()) {
1224 (*i)->deactivate ();
1225 (*i)->set_next_ab_is_active (true);
1227 (*i)->set_next_ab_is_active (false);
1233 /* backward = if the redirect was marked to go active on the next ab, do so */
1235 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1237 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1241 if ((*i)->get_next_ab_is_active()) {
1244 (*i)->deactivate ();
1249 _session.set_dirty ();
1253 /** Remove processors with a given placement.
1254 * @param p Placement of processors to remove.
1257 Route::clear_processors (Placement p)
1259 const ChanCount old_pms = processor_max_streams;
1261 if (!_session.engine().connected()) {
1265 bool already_deleting = _session.deletion_in_progress();
1266 if (!already_deleting) {
1267 _session.set_deletion_in_progress();
1271 Glib::RWLock::WriterLock lm (_processor_lock);
1272 ProcessorList new_list;
1273 ProcessorStreams err;
1274 bool seen_amp = false;
1276 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1282 if ((*i) == _amp || (*i) == _meter || (*i) == _main_outs) {
1284 /* you can't remove these */
1286 new_list.push_back (*i);
1293 new_list.push_back (*i);
1296 (*i)->drop_references ();
1304 (*i)->drop_references ();
1307 new_list.push_back (*i);
1314 _processors = new_list;
1315 configure_processors_unlocked (&err); // this can't fail
1318 processor_max_streams.reset();
1319 _have_internal_generator = false;
1320 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1322 if (!already_deleting) {
1323 _session.clear_deletion_in_progress();
1328 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err)
1330 /* these can never be removed */
1332 if (processor == _amp || processor == _meter || processor == _main_outs) {
1336 ChanCount old_pms = processor_max_streams;
1338 if (!_session.engine().connected()) {
1342 processor_max_streams.reset();
1345 Glib::RWLock::WriterLock lm (_processor_lock);
1346 ProcessorList::iterator i;
1347 bool removed = false;
1349 for (i = _processors.begin(); i != _processors.end(); ) {
1350 if (*i == processor) {
1352 /* move along, see failure case for configure_processors()
1353 where we may need to reconfigure the processor.
1356 /* stop redirects that send signals to JACK ports
1357 from causing noise as a result of no longer being
1361 boost::shared_ptr<IOProcessor> iop;
1363 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (*i)) != 0) {
1365 iop->input()->disconnect (this);
1367 if (iop->output()) {
1368 iop->output()->disconnect (this);
1372 i = _processors.erase (i);
1380 _output->set_user_latency (0);
1388 if (configure_processors_unlocked (err)) {
1389 /* get back to where we where */
1390 _processors.insert (i, processor);
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 processor->drop_references ();
1411 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1417 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1419 ProcessorList deleted;
1421 if (!_session.engine().connected()) {
1425 processor_max_streams.reset();
1428 Glib::RWLock::WriterLock lm (_processor_lock);
1429 ProcessorList::iterator i;
1430 boost::shared_ptr<Processor> processor;
1432 ProcessorList as_we_were = _processors;
1434 for (i = _processors.begin(); i != _processors.end(); ) {
1438 /* these can never be removed */
1440 if (processor == _amp || processor == _meter || processor == _main_outs) {
1445 /* see if its in the list of processors to delete */
1447 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1452 /* stop IOProcessors that send to JACK ports
1453 from causing noise as a result of no longer being
1457 boost::shared_ptr<IOProcessor> iop;
1459 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (processor)) != 0) {
1463 deleted.push_back (processor);
1464 i = _processors.erase (i);
1467 if (deleted.empty()) {
1468 /* none of those in the requested list were found */
1472 _output->set_user_latency (0);
1474 if (configure_processors_unlocked (err)) {
1475 /* get back to where we where */
1476 _processors = as_we_were;
1477 /* we know this will work, because it worked before :) */
1478 configure_processors_unlocked (0);
1482 _have_internal_generator = false;
1484 for (i = _processors.begin(); i != _processors.end(); ++i) {
1485 boost::shared_ptr<PluginInsert> pi;
1487 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1488 if (pi->is_generator()) {
1489 _have_internal_generator = true;
1496 /* now try to do what we need to so that those that were removed will be deleted */
1498 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1499 (*i)->drop_references ();
1502 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1509 Route::configure_processors (ProcessorStreams* err)
1511 if (!_in_configure_processors) {
1512 Glib::RWLock::WriterLock lm (_processor_lock);
1513 return configure_processors_unlocked (err);
1518 /** Configure the input/output configuration of each processor in the processors list.
1519 * Return 0 on success, otherwise configuration is impossible.
1522 Route::configure_processors_unlocked (ProcessorStreams* err)
1524 if (_in_configure_processors) {
1528 _in_configure_processors = true;
1530 // Check each processor in order to see if we can configure as requested
1531 ChanCount in = _input->n_ports ();
1533 list< pair<ChanCount,ChanCount> > configuration;
1536 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1538 DEBUG_TRACE (DEBUG::Processors, "{\n");
1539 for (list<boost::shared_ptr<Processor> >::const_iterator p = _processors.begin(); p != _processors.end(); ++p) {
1540 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID = %2\n", (*p)->name(), (*p)->id()));
1542 DEBUG_TRACE (DEBUG::Processors, "}\n");
1545 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1547 if ((*p)->can_support_io_configuration(in, out)) {
1548 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1in = %2 out = %3\n",(*p)->name(), in, out));
1549 configuration.push_back(make_pair(in, out));
1556 _in_configure_processors = false;
1561 // We can, so configure everything
1562 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1563 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1564 (*p)->configure_io(c->first, c->second);
1565 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1566 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1571 _meter->reset_max_channels (processor_max_streams);
1574 /* make sure we have sufficient scratch buffers to cope with the new processor
1576 _session.ensure_buffers (n_process_buffers ());
1578 _in_configure_processors = false;
1583 Route::all_processors_flip ()
1585 Glib::RWLock::ReaderLock lm (_processor_lock);
1587 if (_processors.empty()) {
1591 bool first_is_on = _processors.front()->active();
1593 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1595 (*i)->deactivate ();
1601 _session.set_dirty ();
1604 /** Set all processors with a given placement to a given active state.
1605 * @param p Placement of processors to change.
1606 * @param state New active state for those processors.
1609 Route::all_processors_active (Placement p, bool state)
1611 Glib::RWLock::ReaderLock lm (_processor_lock);
1613 if (_processors.empty()) {
1616 ProcessorList::iterator start, end;
1617 placement_range(p, start, end);
1619 bool before_amp = true;
1620 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1625 if (p == PreFader && before_amp) {
1629 (*i)->deactivate ();
1634 _session.set_dirty ();
1638 Route::processor_is_prefader (boost::shared_ptr<Processor> p)
1640 bool pre_fader = true;
1641 Glib::RWLock::ReaderLock lm (_processor_lock);
1643 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1645 /* semantic note: if p == amp, we want to return true, so test
1646 for equality before checking if this is the amp
1663 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
1665 /* "new_order" is an ordered list of processors to be positioned according to "placement".
1666 NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
1667 processors in the current actual processor list that are hidden. Any visible processors
1668 in the current list but not in "new_order" will be assumed to be deleted.
1672 Glib::RWLock::WriterLock lm (_processor_lock);
1673 ChanCount old_pms = processor_max_streams;
1674 ProcessorList::iterator oiter;
1675 ProcessorList::const_iterator niter;
1676 ProcessorList as_it_was_before = _processors;
1677 ProcessorList as_it_will_be;
1679 oiter = _processors.begin();
1680 niter = new_order.begin();
1682 while (niter != new_order.end()) {
1684 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
1685 then append it to the temp list.
1687 Otherwise, see if the next processor in the old list is in the new list. if not,
1688 its been deleted. If its there, append it to the temp list.
1691 if (oiter == _processors.end()) {
1693 /* no more elements in the old list, so just stick the rest of
1694 the new order onto the temp list.
1697 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
1698 while (niter != new_order.end()) {
1705 if (!(*oiter)->display_to_user()) {
1707 as_it_will_be.push_back (*oiter);
1711 /* visible processor: check that its in the new order */
1713 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
1714 /* deleted: do nothing, shared_ptr<> will clean up */
1716 /* ignore this one, and add the next item from the new order instead */
1717 as_it_will_be.push_back (*niter);
1722 /* now remove from old order - its taken care of no matter what */
1723 oiter = _processors.erase (oiter);
1728 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
1730 if (configure_processors_unlocked (err)) {
1731 _processors = as_it_was_before;
1732 processor_max_streams = old_pms;
1737 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1749 Route::get_template()
1751 return state(false);
1755 Route::state(bool full_state)
1757 XMLNode *node = new XMLNode("Route");
1758 ProcessorList::iterator i;
1761 id().print (buf, sizeof (buf));
1762 node->add_property("id", buf);
1763 node->add_property ("name", _name);
1764 node->add_property("default-type", _default_type.to_string());
1767 node->add_property("flags", enum_2_string (_flags));
1770 node->add_property("active", _active?"yes":"no");
1771 node->add_property("phase-invert", _phase_invert?"yes":"no");
1772 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
1773 node->add_property("meter-point", enum_2_string (_meter_point));
1776 node->add_property("route-group", _route_group->name());
1779 string order_string;
1780 OrderKeys::iterator x = order_keys.begin();
1782 while (x != order_keys.end()) {
1783 order_string += string ((*x).first);
1784 order_string += '=';
1785 snprintf (buf, sizeof(buf), "%ld", (*x).second);
1786 order_string += buf;
1790 if (x == order_keys.end()) {
1794 order_string += ':';
1796 node->add_property ("order-keys", order_string);
1797 node->add_property ("self-solo", (_self_solo ? "yes" : "no"));
1798 snprintf (buf, sizeof (buf), "%d", _soloed_by_others);
1799 node->add_property ("soloed-by-others", buf);
1801 node->add_child_nocopy (_input->state (full_state));
1802 node->add_child_nocopy (_output->state (full_state));
1803 node->add_child_nocopy (_solo_control->get_state ());
1804 node->add_child_nocopy (_mute_master->get_state ());
1806 XMLNode* remote_control_node = new XMLNode (X_("RemoteControl"));
1807 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
1808 remote_control_node->add_property (X_("id"), buf);
1809 node->add_child_nocopy (*remote_control_node);
1811 if (_comment.length()) {
1812 XMLNode *cmt = node->add_child ("Comment");
1813 cmt->add_content (_comment);
1816 for (i = _processors.begin(); i != _processors.end(); ++i) {
1817 node->add_child_nocopy((*i)->state (full_state));
1821 node->add_child_copy (*_extra_xml);
1828 Route::set_state (const XMLNode& node, int version)
1830 return _set_state (node, version, true);
1834 Route::_set_state (const XMLNode& node, int version, bool /*call_base*/)
1836 if (version < 3000) {
1837 return _set_state_2X (node, version);
1841 XMLNodeConstIterator niter;
1843 XMLPropertyList plist;
1844 const XMLProperty *prop;
1846 if (node.name() != "Route"){
1847 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
1851 if ((prop = node.property (X_("name"))) != 0) {
1852 Route::set_name (prop->value());
1855 if ((prop = node.property ("id")) != 0) {
1856 _id = prop->value ();
1859 if ((prop = node.property (X_("flags"))) != 0) {
1860 _flags = Flag (string_2_enum (prop->value(), _flags));
1865 /* add all processors (except amp, which is always present) */
1867 nlist = node.children();
1868 XMLNode processor_state (X_("processor_state"));
1870 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1874 if (child->name() == IO::state_node_name) {
1875 if ((prop = child->property (X_("direction"))) == 0) {
1879 if (prop->value() == "Input") {
1880 _input->set_state (*child, version);
1881 } else if (prop->value() == "Output") {
1882 _output->set_state (*child, version);
1886 if (child->name() == X_("Processor")) {
1887 processor_state.add_child_copy (*child);
1891 set_processor_state (processor_state);
1893 if ((prop = node.property ("self-solo")) != 0) {
1894 set_self_solo (string_is_affirmative (prop->value()));
1897 if ((prop = node.property ("soloed-by-others")) != 0) {
1898 _soloed_by_others = 0; // needed for mod_solo_by_others () to work
1899 mod_solo_by_others (atoi (prop->value()));
1902 if ((prop = node.property ("solo-isolated")) != 0) {
1903 set_solo_isolated (string_is_affirmative (prop->value()), this);
1906 if ((prop = node.property (X_("phase-invert"))) != 0) {
1907 set_phase_invert (string_is_affirmative (prop->value()));
1910 if ((prop = node.property (X_("denormal-protection"))) != 0) {
1911 set_denormal_protection (string_is_affirmative (prop->value()));
1914 if ((prop = node.property (X_("active"))) != 0) {
1915 bool yn = string_is_affirmative (prop->value());
1916 _active = !yn; // force switch
1920 if ((prop = node.property (X_("meter-point"))) != 0) {
1921 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
1923 _meter->set_display_to_user (_meter_point == MeterCustom);
1927 if ((prop = node.property (X_("order-keys"))) != 0) {
1931 string::size_type colon, equal;
1932 string remaining = prop->value();
1934 while (remaining.length()) {
1936 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
1937 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1940 if (sscanf (remaining.substr (equal+1).c_str(), "%ld", &n) != 1) {
1941 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1944 set_order_key (remaining.substr (0, equal), n);
1948 colon = remaining.find_first_of (':');
1950 if (colon != string::npos) {
1951 remaining = remaining.substr (colon+1);
1958 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1961 if (child->name() == X_("Comment")) {
1963 /* XXX this is a terrible API design in libxml++ */
1965 XMLNode *cmt = *(child->children().begin());
1966 _comment = cmt->content();
1968 } else if (child->name() == X_("Extra")) {
1970 _extra_xml = new XMLNode (*child);
1972 } else if (child->name() == X_("Controllable") && (prop = child->property("name")) != 0) {
1974 if (prop->value() == "solo") {
1975 _solo_control->set_state (*child, version);
1976 _session.add_controllable (_solo_control);
1979 } else if (child->name() == X_("RemoteControl")) {
1980 if ((prop = child->property (X_("id"))) != 0) {
1982 sscanf (prop->value().c_str(), "%d", &x);
1983 set_remote_control_id (x);
1986 } else if (child->name() == X_("MuteMaster")) {
1987 _mute_master->set_state (*child, version);
1995 Route::_set_state_2X (const XMLNode& node, int version)
1998 XMLNodeConstIterator niter;
2000 XMLPropertyList plist;
2001 const XMLProperty *prop;
2003 /* 2X things which still remain to be handled:
2006 * mute-affects-pre-fader
2007 * mute-affects-post-fader
2008 * mute-affects-control-outs
2009 * mute-affects-main-outs
2014 if (node.name() != "Route") {
2015 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2019 if ((prop = node.property (X_("flags"))) != 0) {
2020 _flags = Flag (string_2_enum (prop->value(), _flags));
2025 /* add standard processors */
2027 _meter.reset (new PeakMeter (_session));
2028 add_processor (_meter, PreFader);
2031 /* where we listen to tracks */
2032 _intreturn.reset (new InternalReturn (_session));
2033 add_processor (_intreturn, PreFader);
2035 _monitor_control.reset (new MonitorProcessor (_session));
2036 add_processor (_monitor_control, PostFader);
2039 _main_outs.reset (new Delivery (_session, _output, _mute_master, _name, Delivery::Main));
2040 add_processor (_main_outs, PostFader);
2044 nlist = node.children ();
2045 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2049 if (child->name() == IO::state_node_name) {
2051 /* there is a note in IO::set_state_2X() about why we have to call
2055 _input->set_state_2X (*child, version, true);
2056 _output->set_state_2X (*child, version, false);
2058 if ((prop = child->property (X_("name"))) != 0) {
2059 set_name (prop->value ());
2062 if ((prop = child->property (X_("id"))) != 0) {
2063 _id = prop->value ();
2066 if ((prop = child->property (X_("active"))) != 0) {
2067 bool yn = string_is_affirmative (prop->value());
2068 _active = !yn; // force switch
2076 if ((prop = node.property (X_("phase-invert"))) != 0) {
2077 set_phase_invert (string_is_affirmative (prop->value()));
2080 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2081 set_denormal_protection (string_is_affirmative (prop->value()));
2084 if ((prop = node.property (X_("soloed"))) != 0) {
2085 bool yn = string_is_affirmative (prop->value());
2087 /* XXX force reset of solo status */
2089 set_solo (yn, this);
2092 if ((prop = node.property (X_("meter-point"))) != 0) {
2093 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2096 /* do not carry over edit/mix groups from 2.X because (a) its hard (b) they
2097 don't mean the same thing.
2100 if ((prop = node.property (X_("order-keys"))) != 0) {
2104 string::size_type colon, equal;
2105 string remaining = prop->value();
2107 while (remaining.length()) {
2109 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2110 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2113 if (sscanf (remaining.substr (equal+1).c_str(), "%ld", &n) != 1) {
2114 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2117 set_order_key (remaining.substr (0, equal), n);
2121 colon = remaining.find_first_of (':');
2123 if (colon != string::npos) {
2124 remaining = remaining.substr (colon+1);
2131 XMLNodeList redirect_nodes;
2133 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2137 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2138 redirect_nodes.push_back(child);
2143 set_processor_state_2X (redirect_nodes, version);
2145 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2148 if (child->name() == X_("Comment")) {
2150 /* XXX this is a terrible API design in libxml++ */
2152 XMLNode *cmt = *(child->children().begin());
2153 _comment = cmt->content();
2155 } else if (child->name() == X_("Extra")) {
2157 _extra_xml = new XMLNode (*child);
2159 } else if (child->name() == X_("Controllable") && (prop = child->property("name")) != 0) {
2161 if (prop->value() == "solo") {
2162 _solo_control->set_state (*child, version);
2163 _session.add_controllable (_solo_control);
2166 } else if (child->name() == X_("RemoteControl")) {
2167 if ((prop = child->property (X_("id"))) != 0) {
2169 sscanf (prop->value().c_str(), "%d", &x);
2170 set_remote_control_id (x);
2180 Route::get_processor_state ()
2182 XMLNode* root = new XMLNode (X_("redirects"));
2183 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2184 root->add_child_nocopy ((*i)->state (true));
2191 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2193 /* We don't bother removing existing processors not in nList, as this
2194 method will only be called when creating a Route from scratch, not
2195 for undo purposes. Just put processors in at the appropriate place
2199 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2200 add_processor_from_xml_2X (**i, version, _processors.begin ());
2205 Route::set_processor_state (const XMLNode& node)
2207 const XMLNodeList &nlist = node.children();
2208 XMLNodeConstIterator niter;
2209 ProcessorList::iterator i, o;
2211 // Iterate through existing processors, remove those which are not in the state list
2213 for (i = _processors.begin(); i != _processors.end(); ) {
2215 /* leave amp alone, always */
2222 ProcessorList::iterator tmp = i;
2225 bool processorInStateList = false;
2227 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2229 XMLProperty* id_prop = (*niter)->property(X_("id"));
2231 if (id_prop && (*i)->id() == id_prop->value()) {
2232 processorInStateList = true;
2237 if (!processorInStateList) {
2238 remove_processor (*i);
2244 // Iterate through state list and make sure all processors are on the track and in the correct order,
2245 // set the state of existing processors according to the new state on the same go
2247 i = _processors.begin();
2249 for (niter = nlist.begin(); niter != nlist.end(); ++niter, ++i) {
2251 XMLProperty* prop = (*niter)->property ("type");
2255 // Check whether the next processor in the list is the right one,
2256 // except for "amp" which is always there and may not have the
2257 // old ID since it is always created anew in every Route
2259 if (prop->value() != "amp") {
2260 while (o != _processors.end()) {
2261 XMLProperty* id_prop = (*niter)->property(X_("id"));
2262 if (id_prop && (*o)->id() == id_prop->value()) {
2270 // If the processor (*niter) is not on the route,
2271 // create it and move it to the correct location
2273 if (o == _processors.end()) {
2275 if (add_processor_from_xml (**niter, i)) {
2276 --i; // move iterator to the newly inserted processor
2278 cerr << "Error restoring route: unable to restore processor" << endl;
2283 // Otherwise, the processor already exists; just
2284 // ensure it is at the location provided in the XML state
2287 boost::shared_ptr<Processor> tmp = (*o);
2288 _processors.erase (o); // remove the old copy
2289 _processors.insert (i, tmp); // insert the processor at the correct location
2290 --i; // move iterator to the correct processor
2293 // and make it (just) so
2295 (*i)->set_state (**niter, Stateful::current_state_version);
2299 /* note: there is no configure_processors() call because we figure that
2300 the XML state represents a working signal route.
2303 processors_changed (RouteProcessorChange ());
2307 Route::curve_reallocate ()
2309 // _gain_automation_curve.finish_resize ();
2310 // _pan_automation_curve.finish_resize ();
2314 Route::silence (nframes_t nframes)
2318 _output->silence (nframes);
2321 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2324 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2325 boost::shared_ptr<PluginInsert> pi;
2327 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2328 // skip plugins, they don't need anything when we're not active
2332 (*i)->silence (nframes);
2335 if (nframes == _session.get_block_size()) {
2345 Route::add_internal_return ()
2348 _intreturn.reset (new InternalReturn (_session));
2349 add_processor (_intreturn, PreFader);
2354 Route::get_return_buffer () const
2356 Glib::RWLock::ReaderLock rm (_processor_lock);
2358 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2359 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
2362 BufferSet* bs = d->get_buffers ();
2371 Route::release_return_buffer () const
2373 Glib::RWLock::ReaderLock rm (_processor_lock);
2375 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2376 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
2379 return d->release_buffers ();
2385 Route::listen_via (boost::shared_ptr<Route> route, Placement placement, bool /*active*/, bool aux)
2387 vector<string> ports;
2388 vector<string>::const_iterator i;
2391 Glib::RWLock::ReaderLock rm (_processor_lock);
2393 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
2395 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
2397 if (d && d->target_route() == route) {
2399 /* if the target is the control outs, then make sure
2400 we take note of which i-send is doing that.
2403 if (route == _session.monitor_out()) {
2404 _monitor_send = boost::dynamic_pointer_cast<Delivery>(d);
2405 if (_monitor_send->active()) {
2406 _monitor_send->set_solo_level (1);
2408 _monitor_send->set_solo_level (0);
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)));
2434 if (route == _session.monitor_out()) {
2438 } catch (failed_constructor& err) {
2442 if (route == _session.monitor_out()) {
2443 _monitor_send = listener;
2446 if (placement == PostFader) {
2447 /* put it *really* at the end, not just after the panner (main outs)
2449 add_processor (listener, _processors.end());
2451 add_processor (listener, PreFader);
2458 Route::drop_listen (boost::shared_ptr<Route> route)
2460 ProcessorStreams err;
2461 ProcessorList::iterator tmp;
2463 Glib::RWLock::ReaderLock rl(_processor_lock);
2467 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ) {
2469 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
2471 if (d && d->target_route() == route) {
2473 remove_processor (*x, &err);
2476 /* list could have been demolished while we dropped the lock
2486 if (route == _session.monitor_out()) {
2487 _monitor_send.reset ();
2492 Route::set_comment (string cmt, void *src)
2495 comment_changed (src);
2496 _session.set_dirty ();
2500 Route::feeds (boost::shared_ptr<Route> other, bool* only_send)
2502 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
2504 if (_output->connected_to (other->input())) {
2505 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
2514 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); ++r) {
2516 boost::shared_ptr<IOProcessor> iop;
2518 if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*r)) != 0) {
2519 if (iop->feeds (other)) {
2520 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
2526 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
2529 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
2534 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
2539 Route::handle_transport_stopped (bool /*abort_ignored*/, bool did_locate, bool can_flush_processors)
2541 nframes_t now = _session.transport_frame();
2544 Glib::RWLock::ReaderLock lm (_processor_lock);
2547 automation_snapshot (now, true);
2550 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2552 if (Config->get_plugins_stop_with_transport() && can_flush_processors) {
2553 (*i)->deactivate ();
2557 (*i)->transport_stopped (now);
2561 _roll_delay = _initial_delay;
2565 Route::input_change_handler (IOChange change, void * /*src*/)
2567 if ((change & ConfigurationChanged)) {
2568 configure_processors (0);
2573 Route::output_change_handler (IOChange change, void * /*src*/)
2575 if ((change & ConfigurationChanged)) {
2577 /* XXX resize all listeners to match _main_outs? */
2579 // configure_processors (0);
2584 Route::pans_required () const
2586 if (n_outputs().n_audio() < 2) {
2590 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
2594 Route::no_roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame,
2595 bool session_state_changing, bool /*can_record*/, bool /*rec_monitors_input*/)
2597 if (n_outputs().n_total() == 0) {
2601 if (!_active || n_inputs() == ChanCount::ZERO) {
2605 if (session_state_changing) {
2606 if (_session.transport_speed() != 0.0f) {
2607 /* we're rolling but some state is changing (e.g. our diskstream contents)
2608 so we cannot use them. Be silent till this is over.
2610 XXX note the absurdity of ::no_roll() being called when we ARE rolling!
2615 /* we're really not rolling, so we're either delivery silence or actually
2616 monitoring, both of which are safe to do while session_state_changing is true.
2620 _amp->apply_gain_automation (false);
2621 passthru (start_frame, end_frame, nframes, 0);
2627 Route::check_initial_delay (nframes_t nframes, nframes_t& transport_frame)
2629 if (_roll_delay > nframes) {
2631 _roll_delay -= nframes;
2633 /* transport frame is not legal for caller to use */
2636 } else if (_roll_delay > 0) {
2638 nframes -= _roll_delay;
2639 silence (_roll_delay);
2640 /* we've written _roll_delay of samples into the
2641 output ports, so make a note of that for
2644 _main_outs->increment_output_offset (_roll_delay);
2645 transport_frame += _roll_delay;
2654 Route::roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame, int declick,
2655 bool /*can_record*/, bool /*rec_monitors_input*/)
2658 // automation snapshot can also be called from the non-rt context
2659 // and it uses the processor list, so we try to acquire the lock here
2660 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2663 automation_snapshot (_session.transport_frame(), false);
2667 if (n_outputs().n_total() == 0) {
2671 if (!_active || n_inputs().n_total() == 0) {
2676 nframes_t unused = 0;
2678 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
2684 passthru (start_frame, end_frame, nframes, declick);
2690 Route::silent_roll (nframes_t nframes, sframes_t /*start_frame*/, sframes_t /*end_frame*/,
2691 bool /*can_record*/, bool /*rec_monitors_input*/)
2698 Route::toggle_monitor_input ()
2700 for (PortSet::iterator i = _input->ports().begin(); i != _input->ports().end(); ++i) {
2701 i->ensure_monitor_input( ! i->monitoring_input());
2706 Route::has_external_redirects () const
2708 // FIXME: what about sends? - they don't return a signal back to ardour?
2710 boost::shared_ptr<const PortInsert> pi;
2712 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2714 if ((pi = boost::dynamic_pointer_cast<const PortInsert>(*i)) != 0) {
2716 for (PortSet::const_iterator port = pi->output()->ports().begin(); port != pi->output()->ports().end(); ++port) {
2718 string port_name = port->name();
2719 string client_name = port_name.substr (0, port_name.find(':'));
2721 /* only say "yes" if the redirect is actually in use */
2723 if (client_name != "ardour" && pi->active()) {
2734 Route::flush_processors ()
2736 /* XXX shouldn't really try to take this lock, since
2737 this is called from the RT audio thread.
2740 Glib::RWLock::ReaderLock lm (_processor_lock);
2742 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2743 (*i)->deactivate ();
2749 Route::set_meter_point (MeterPoint p, void *src)
2751 /* CAN BE CALLED FROM PROCESS CONTEXT */
2753 if (_meter_point == p) {
2757 bool meter_was_visible_to_user = _meter->display_to_user ();
2760 Glib::RWLock::WriterLock lm (_processor_lock);
2762 if (p != MeterCustom) {
2763 // Move meter in the processors list to reflect the new position
2764 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
2765 _processors.erase(loc);
2768 loc = _processors.begin();
2771 loc = find (_processors.begin(), _processors.end(), _amp);
2773 case MeterPostFader:
2774 loc = _processors.end();
2782 if (loc == _processors.begin()) {
2783 m_in = _input->n_ports();
2785 ProcessorList::iterator before = loc;
2787 m_in = (*before)->output_streams ();
2790 _meter->reflect_inputs (m_in);
2792 _processors.insert (loc, _meter);
2794 /* we do not need to reconfigure the processors, because the meter
2795 (a) is always ready to handle processor_max_streams
2796 (b) is always an N-in/N-out processor, and thus moving
2797 it doesn't require any changes to the other processors.
2800 _meter->set_display_to_user (false);
2804 // just make it visible and let the user move it
2806 _meter->set_display_to_user (true);
2811 meter_change (src); /* EMIT SIGNAL */
2813 bool const meter_visibly_changed = (_meter->display_to_user() != meter_was_visible_to_user);
2815 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, meter_visibly_changed)); /* EMIT SIGNAL */
2819 Route::put_monitor_send_at (Placement p)
2821 if (!_monitor_send) {
2826 Glib::RWLock::WriterLock lm (_processor_lock);
2827 ProcessorList as_it_was (_processors);
2828 ProcessorList::iterator loc = find(_processors.begin(), _processors.end(), _monitor_send);
2829 _processors.erase(loc);
2833 loc = find(_processors.begin(), _processors.end(), _amp);
2834 if (loc != _processors.begin()) {
2839 loc = _processors.end();
2843 _processors.insert (loc, _monitor_send);
2845 if (configure_processors_unlocked (0)) {
2846 _processors = as_it_was;
2847 configure_processors_unlocked (0); // it worked before we tried to add it ...
2852 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2853 _session.set_dirty ();
2857 Route::update_total_latency ()
2859 nframes_t old = _output->effective_latency();
2860 nframes_t own_latency = _output->user_latency();
2862 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2863 if ((*i)->active ()) {
2864 own_latency += (*i)->signal_latency ();
2868 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal redirect latency = %2\n", _name, own_latency));
2870 _output->set_port_latency (own_latency);
2872 if (_output->user_latency() == 0) {
2874 /* this (virtual) function is used for pure Routes,
2875 not derived classes like AudioTrack. this means
2876 that the data processed here comes from an input
2877 port, not prerecorded material, and therefore we
2878 have to take into account any input latency.
2881 own_latency += _input->signal_latency ();
2884 if (old != own_latency) {
2885 _output->set_latency_delay (own_latency);
2886 signal_latency_changed (); /* EMIT SIGNAL */
2889 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: input latency = %2 total = %3\n", _name, _input->signal_latency(), own_latency));
2891 return _output->effective_latency ();
2895 Route::set_user_latency (nframes_t nframes)
2897 _output->set_user_latency (nframes);
2898 _session.update_latency_compensation (false, false);
2902 Route::set_latency_delay (nframes_t longest_session_latency)
2904 nframes_t old = _initial_delay;
2906 if (_output->effective_latency() < longest_session_latency) {
2907 _initial_delay = longest_session_latency - _output->effective_latency();
2912 if (_initial_delay != old) {
2913 initial_delay_changed (); /* EMIT SIGNAL */
2916 if (_session.transport_stopped()) {
2917 _roll_delay = _initial_delay;
2922 Route::automation_snapshot (nframes_t now, bool force)
2924 panner()->automation_snapshot (now, force);
2926 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2927 (*i)->automation_snapshot (now, force);
2931 Route::SoloControllable::SoloControllable (std::string name, Route& r)
2932 : AutomationControl (r.session(), Evoral::Parameter (SoloAutomation),
2933 boost::shared_ptr<AutomationList>(), name)
2936 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(SoloAutomation)));
2941 Route::SoloControllable::set_value (float val)
2943 bool bval = ((val >= 0.5f) ? true: false);
2945 this is how it should be done
2947 boost::shared_ptr<RouteList> rl (new RouteList);
2948 rl->push_back (route);
2950 if (Config->get_solo_control_is_listen_control()) {
2951 _session.set_listen (rl, bval);
2953 _session.set_solo (rl, bval);
2956 route.set_solo (bval, this);
2961 Route::SoloControllable::get_value (void) const
2963 if (Config->get_solo_control_is_listen_control()) {
2964 return route.listening() ? 1.0f : 0.0f;
2966 return route.self_soloed() ? 1.0f : 0.0f;
2970 Route::MuteControllable::MuteControllable (std::string name, Route& r)
2971 : AutomationControl (r.session(), Evoral::Parameter (MuteAutomation),
2972 boost::shared_ptr<AutomationList>(), name)
2975 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(MuteAutomation)));
2980 Route::MuteControllable::set_value (float val)
2982 bool bval = ((val >= 0.5f) ? true: false);
2984 this is how it should be done
2986 boost::shared_ptr<RouteList> rl (new RouteList);
2987 rl->push_back (route);
2988 _session.set_mute (rl, bval);
2990 route.set_mute (bval, this);
2995 Route::MuteControllable::get_value (void) const
2997 return route.muted() ? 1.0f : 0.0f;
3001 Route::set_block_size (nframes_t nframes)
3003 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3004 (*i)->set_block_size (nframes);
3007 _session.ensure_buffers (n_process_buffers ());
3011 Route::protect_automation ()
3013 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
3014 (*i)->protect_automation();
3018 Route::set_pending_declick (int declick)
3021 /* this call is not allowed to turn off a pending declick unless "force" is true */
3023 _pending_declick = declick;
3025 // cerr << _name << ": after setting to " << declick << " pending declick = " << _pending_declick << endl;
3027 _pending_declick = 0;
3032 /** Shift automation forwards from a particular place, thereby inserting time.
3033 * Adds undo commands for any shifts that are performed.
3035 * @param pos Position to start shifting from.
3036 * @param frames Amount to shift forwards by.
3040 Route::shift (nframes64_t /*pos*/, nframes64_t /*frames*/)
3042 #ifdef THIS_NEEDS_FIXING_FOR_V3
3044 /* gain automation */
3045 XMLNode &before = _gain_control->get_state ();
3046 _gain_control->shift (pos, frames);
3047 XMLNode &after = _gain_control->get_state ();
3048 _session.add_command (new MementoCommand<AutomationList> (_gain_automation_curve, &before, &after));
3050 /* pan automation */
3051 for (std::vector<StreamPanner*>::iterator i = _panner->begin (); i != _panner->end (); ++i) {
3052 Curve & c = (*i)->automation ();
3053 XMLNode &before = c.get_state ();
3054 c.shift (pos, frames);
3055 XMLNode &after = c.get_state ();
3056 _session.add_command (new MementoCommand<AutomationList> (c, &before, &after));
3059 /* redirect automation */
3061 Glib::RWLock::ReaderLock lm (redirect_lock);
3062 for (RedirectList::iterator i = _redirects.begin (); i != _redirects.end (); ++i) {
3065 (*i)->what_has_automation (a);
3067 for (set<uint32_t>::const_iterator j = a.begin (); j != a.end (); ++j) {
3068 AutomationList & al = (*i)->automation_list (*j);
3069 XMLNode &before = al.get_state ();
3070 al.shift (pos, frames);
3071 XMLNode &after = al.get_state ();
3072 _session.add_command (new MementoCommand<AutomationList> (al, &before, &after));
3082 Route::save_as_template (const string& path, const string& name)
3084 XMLNode& node (state (false));
3087 IO::set_name_in_state (*node.children().front(), name);
3089 tree.set_root (&node);
3090 return tree.write (path.c_str());
3095 Route::set_name (const string& str)
3101 name = Route::ensure_track_or_route_name (str, _session);
3102 SessionObject::set_name (name);
3104 ret = (_input->set_name(name) && _output->set_name(name));
3108 Glib::RWLock::ReaderLock lm (_processor_lock);
3110 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3112 /* rename all I/O processors that have inputs or outputs */
3114 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor> (*i);
3116 if (iop && (iop->output() || iop->input())) {
3117 if (!iop->set_name (name)) {
3128 boost::shared_ptr<Send>
3129 Route::internal_send_for (boost::shared_ptr<const Route> target) const
3131 Glib::RWLock::ReaderLock lm (_processor_lock);
3133 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
3134 boost::shared_ptr<InternalSend> send;
3136 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
3137 if (send->target_route() == target) {
3143 return boost::shared_ptr<Send>();
3147 Route::set_phase_invert (bool yn)
3149 if (_phase_invert != yn) {
3150 _phase_invert = 0xffff; // XXX all channels
3151 phase_invert_changed (); /* EMIT SIGNAL */
3156 Route::phase_invert () const
3158 return _phase_invert != 0;
3162 Route::set_denormal_protection (bool yn)
3164 if (_denormal_protection != yn) {
3165 _denormal_protection = yn;
3166 denormal_protection_changed (); /* EMIT SIGNAL */
3171 Route::denormal_protection () const
3173 return _denormal_protection;
3177 Route::set_active (bool yn)
3179 if (_active != yn) {
3181 _input->set_active (yn);
3182 _output->set_active (yn);
3183 active_changed (); // EMIT SIGNAL
3190 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
3196 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3198 boost::shared_ptr<Send> s;
3199 boost::shared_ptr<Return> r;
3201 if ((s = boost::dynamic_pointer_cast<Send> (*i)) != 0) {
3202 s->meter()->meter();
3203 } else if ((r = boost::dynamic_pointer_cast<Return> (*i)) != 0) {
3204 r->meter()->meter ();
3209 boost::shared_ptr<Panner>
3210 Route::panner() const
3212 return _main_outs->panner();
3215 boost::shared_ptr<AutomationControl>
3216 Route::gain_control() const
3218 return _amp->gain_control();
3221 boost::shared_ptr<AutomationControl>
3222 Route::get_control (const Evoral::Parameter& param)
3224 /* either we own the control or .... */
3226 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(control (param));
3230 /* maybe one of our processors does or ... */
3232 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
3233 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3234 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->control (param))) != 0) {
3242 /* nobody does so we'll make a new one */
3244 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
3251 boost::shared_ptr<Processor>
3252 Route::nth_plugin (uint32_t n)
3254 Glib::RWLock::ReaderLock lm (_processor_lock);
3255 ProcessorList::iterator i;
3257 for (i = _processors.begin(); i != _processors.end(); ++i) {
3258 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
3265 return boost::shared_ptr<Processor> ();
3268 boost::shared_ptr<Processor>
3269 Route::nth_send (uint32_t n)
3271 Glib::RWLock::ReaderLock lm (_processor_lock);
3272 ProcessorList::iterator i;
3274 for (i = _processors.begin(); i != _processors.end(); ++i) {
3275 cerr << "check " << (*i)->name() << endl;
3276 if (boost::dynamic_pointer_cast<Send> (*i)) {
3281 cerr << "\tnot a send\n";
3285 return boost::shared_ptr<Processor> ();