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 <sigc++/bind.h>
26 #include "pbd/xml++.h"
27 #include "pbd/enumwriter.h"
28 #include "pbd/memento_command.h"
30 #include "evoral/Curve.hpp"
32 #include "ardour/amp.h"
33 #include "ardour/audio_port.h"
34 #include "ardour/audioengine.h"
35 #include "ardour/buffer.h"
36 #include "ardour/buffer_set.h"
37 #include "ardour/configuration.h"
38 #include "ardour/cycle_timer.h"
39 #include "ardour/debug.h"
40 #include "ardour/delivery.h"
41 #include "ardour/dB.h"
42 #include "ardour/internal_send.h"
43 #include "ardour/internal_return.h"
44 #include "ardour/ladspa_plugin.h"
45 #include "ardour/meter.h"
46 #include "ardour/mix.h"
47 #include "ardour/panner.h"
48 #include "ardour/plugin_insert.h"
49 #include "ardour/port.h"
50 #include "ardour/port_insert.h"
51 #include "ardour/processor.h"
52 #include "ardour/profile.h"
53 #include "ardour/route.h"
54 #include "ardour/route_group.h"
55 #include "ardour/send.h"
56 #include "ardour/session.h"
57 #include "ardour/timestamps.h"
58 #include "ardour/utils.h"
63 using namespace ARDOUR;
66 uint32_t Route::order_key_cnt = 0;
67 sigc::signal<void, string const &> Route::SyncOrderKeys;
69 Route::Route (Session& sess, string name, Flag flg, DataType default_type)
70 : SessionObject (sess, name)
71 , AutomatableControls (sess)
73 , _solo_control (new SoloControllable (X_("solo"), *this))
74 , _mute_master (new MuteMaster (sess, name))
75 , _default_type (default_type)
80 /* add standard processors other than amp (added by ::init()) */
82 _meter.reset (new PeakMeter (_session));
83 _meter->set_display_to_user (false);
84 add_processor (_meter, PostFader);
86 if (_flags & ControlOut) {
87 /* where we listen to tracks */
88 _intreturn.reset (new InternalReturn (_session));
89 add_processor (_intreturn, PreFader);
92 _main_outs.reset (new Delivery (_session, _output, _mute_master, _name, Delivery::Main));
93 add_processor (_main_outs, PostFader);
95 /* now that we have _meter, its safe to connect to this */
97 _meter_connection = Metering::connect (mem_fun (*this, &Route::meter));
100 Route::Route (Session& sess, const XMLNode& node, DataType default_type)
101 : SessionObject (sess, "toBeReset")
102 , AutomatableControls (sess)
103 , _solo_control (new SoloControllable (X_("solo"), *this))
104 , _mute_master (new MuteMaster (sess, "toBeReset"))
105 , _default_type (default_type)
109 _set_state (node, Stateful::loading_state_version, false);
111 /* now that we have _meter, its safe to connect to this */
113 _meter_connection = Metering::connect (mem_fun (*this, &Route::meter));
120 _soloed_by_others = 0;
124 processor_max_streams.reset();
126 order_keys[N_("signal")] = order_key_cnt++;
128 _meter_point = MeterPostFader;
131 _have_internal_generator = false;
132 _declickable = false;
133 _pending_declick = true;
134 _remote_control_id = 0;
135 _in_configure_processors = false;
136 _mute_points = MuteMaster::AllPoints;
139 _denormal_protection = false;
141 /* add standard controls */
143 add_control (_solo_control);
144 add_control (_mute_master);
146 /* input and output objects */
148 _input.reset (new IO (_session, _name, IO::Input, _default_type));
149 _output.reset (new IO (_session, _name, IO::Output, _default_type));
151 _input->changed.connect (mem_fun (this, &Route::input_change_handler));
152 _output->changed.connect (mem_fun (this, &Route::output_change_handler));
154 /* add amp processor */
156 _amp.reset (new Amp (_session, _mute_master));
157 add_processor (_amp, PostFader);
162 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
163 Metering::disconnect (_meter_connection);
165 /* don't use clear_processors here, as it depends on the session which may
166 be half-destroyed by now */
168 Glib::RWLock::WriterLock lm (_processor_lock);
169 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
170 (*i)->drop_references ();
173 _processors.clear ();
177 Route::set_remote_control_id (uint32_t id)
179 if (id != _remote_control_id) {
180 _remote_control_id = id;
181 RemoteControlIDChanged ();
186 Route::remote_control_id() const
188 return _remote_control_id;
192 Route::order_key (std::string const & name) const
194 OrderKeys::const_iterator i = order_keys.find (name);
195 if (i == order_keys.end()) {
203 Route::set_order_key (std::string const & name, long n)
205 order_keys[name] = n;
207 if (Config->get_sync_all_route_ordering()) {
208 for (OrderKeys::iterator x = order_keys.begin(); x != order_keys.end(); ++x) {
213 _session.set_dirty ();
216 /** Set all order keys to be the same as that for `base', if such a key
217 * exists in this route.
218 * @param base Base key.
221 Route::sync_order_keys (std::string const & base)
223 if (order_keys.empty()) {
227 OrderKeys::iterator i;
230 if ((i = order_keys.find (base)) == order_keys.end()) {
231 /* key doesn't exist, use the first existing key (during session initialization) */
232 i = order_keys.begin();
236 /* key exists - use it and reset all others (actually, itself included) */
238 i = order_keys.begin();
241 for (; i != order_keys.end(); ++i) {
247 Route::ensure_track_or_route_name(string name, Session &session)
249 string newname = name;
251 while (session.route_by_name (newname) != NULL) {
252 newname = bump_name_once (newname);
260 Route::inc_gain (gain_t fraction, void *src)
262 _amp->inc_gain (fraction, src);
266 Route::set_gain (gain_t val, void *src)
268 if (src != 0 && _route_group && src != _route_group && _route_group->active_property (RouteGroup::Gain)) {
270 if (_route_group->is_relative()) {
272 gain_t usable_gain = _amp->gain();
273 if (usable_gain < 0.000001f) {
274 usable_gain = 0.000001f;
278 if (delta < 0.000001f) {
282 delta -= usable_gain;
287 gain_t factor = delta / usable_gain;
290 factor = _route_group->get_max_factor(factor);
291 if (factor == 0.0f) {
292 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
296 factor = _route_group->get_min_factor(factor);
297 if (factor == 0.0f) {
298 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
303 _route_group->apply (&Route::inc_gain, factor, _route_group);
307 _route_group->apply (&Route::set_gain, val, _route_group);
313 if (val == _amp->gain()) {
317 _amp->set_gain (val, src);
320 /** Process this route for one (sub) cycle (process thread)
322 * @param bufs Scratch buffers to use for the signal path
323 * @param start_frame Initial transport frame
324 * @param end_frame Final transport frame
325 * @param nframes Number of frames to output (to ports)
327 * Note that (end_frame - start_frame) may not be equal to nframes when the
328 * transport speed isn't 1.0 (eg varispeed).
331 Route::process_output_buffers (BufferSet& bufs,
332 sframes_t start_frame, sframes_t end_frame, nframes_t nframes,
333 bool /*with_processors*/, int declick)
337 bufs.is_silent (false);
339 switch (Config->get_monitoring_model()) {
340 case HardwareMonitoring:
341 case ExternalMonitoring:
342 monitor = !record_enabled() || (_session.config.get_auto_input() && !_session.actively_recording());
349 declick = _pending_declick;
352 /* figure out if we're going to use gain automation */
353 _amp->setup_gain_automation (start_frame, end_frame, nframes);
356 /* tell main outs what to do about monitoring */
357 _main_outs->no_outs_cuz_we_no_monitor (!monitor);
360 /* -------------------------------------------------------------------------------------------
361 GLOBAL DECLICK (for transport changes etc.)
362 ----------------------------------------------------------------------------------------- */
365 Amp::apply_gain (bufs, nframes, 0.0, 1.0);
366 } else if (declick < 0) {
367 Amp::apply_gain (bufs, nframes, 1.0, 0.0);
370 _pending_declick = 0;
372 /* -------------------------------------------------------------------------------------------
373 DENORMAL CONTROL/PHASE INVERT
374 ----------------------------------------------------------------------------------------- */
380 if (_denormal_protection || Config->get_denormal_protection()) {
382 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
383 Sample* const sp = i->data();
385 if (_phase_invert & chn) {
386 for (nframes_t nx = 0; nx < nframes; ++nx) {
391 for (nframes_t nx = 0; nx < nframes; ++nx) {
399 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
400 Sample* const sp = i->data();
402 if (_phase_invert & chn) {
403 for (nframes_t nx = 0; nx < nframes; ++nx) {
412 if (_denormal_protection || Config->get_denormal_protection()) {
414 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
415 Sample* const sp = i->data();
416 for (nframes_t nx = 0; nx < nframes; ++nx) {
424 /* -------------------------------------------------------------------------------------------
426 ----------------------------------------------------------------------------------------- */
428 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
431 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
433 if (bufs.count() != (*i)->input_streams()) {
434 cerr << _name << " bufs = " << bufs.count()
435 << " input for " << (*i)->name() << " = " << (*i)->input_streams()
438 assert (bufs.count() == (*i)->input_streams());
440 (*i)->run (bufs, start_frame, end_frame, nframes, *i != _processors.back());
441 bufs.set_count (ChanCount::max(bufs.count(), (*i)->output_streams()));
444 if (!_processors.empty()) {
445 bufs.set_count (ChanCount::max (bufs.count(), _processors.back()->output_streams()));
451 Route::n_process_buffers ()
453 return max (_input->n_ports(), processor_max_streams);
457 Route::passthru (sframes_t start_frame, sframes_t end_frame, nframes_t nframes, int declick)
459 BufferSet& bufs = _session.get_scratch_buffers (n_process_buffers());
463 assert (bufs.available() >= _input->n_ports());
465 if (_input->n_ports() == ChanCount::ZERO) {
469 bufs.set_count (_input->n_ports());
471 if (is_control() && _session.listening()) {
473 /* control/monitor bus ignores input ports when something is
474 feeding the listen "stream". data will "arrive" into the
475 route from the intreturn processor element.
478 bufs.silence (nframes, 0);
482 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
484 BufferSet::iterator o = bufs.begin(*t);
485 PortSet& ports (_input->ports());
487 for (PortSet::iterator i = ports.begin(*t); i != ports.end(*t); ++i, ++o) {
488 o->read_from (i->get_buffer(nframes), nframes);
493 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
494 process_output_buffers (bufs, start_frame, end_frame, nframes, true, declick);
498 Route::passthru_silence (sframes_t start_frame, sframes_t end_frame, nframes_t nframes, int declick)
500 BufferSet& bufs (_session.get_silent_buffers (n_process_buffers()));
501 bufs.set_count (_input->n_ports());
502 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
503 process_output_buffers (bufs, start_frame, end_frame, nframes, true, declick);
507 Route::set_listen (bool yn, void* src)
510 if (yn != _control_outs->active()) {
512 _control_outs->activate ();
514 _control_outs->deactivate ();
517 listen_changed (src); /* EMIT SIGNAL */
523 Route::listening () const
526 return _control_outs->active ();
533 Route::set_solo_safe (bool yn, void *src)
535 if (_solo_safe != yn) {
537 solo_safe_changed (src);
542 Route::solo_safe() const
548 Route::set_solo (bool yn, void *src)
554 if (_route_group && src != _route_group && _route_group->active_property (RouteGroup::Solo)) {
555 _route_group->apply (&Route::set_solo, yn, _route_group);
559 if (self_soloed() != yn) {
561 set_delivery_solo ();
562 solo_changed (src); /* EMIT SIGNAL */
563 _solo_control->Changed (); /* EMIT SIGNAL */
568 Route::set_self_solo (bool yn)
574 Route::mod_solo_by_others (int32_t delta)
577 if (_soloed_by_others >= (uint32_t) delta) {
578 _soloed_by_others += delta;
580 _soloed_by_others = 0;
583 _soloed_by_others += delta;
586 set_delivery_solo ();
590 Route::set_delivery_solo ()
592 /* tell all delivery processors what the solo situation is, so that they keep
593 delivering even though Session::soloing() is true and they were not
597 Glib::RWLock::ReaderLock rm (_processor_lock);
598 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
599 boost::shared_ptr<Delivery> d;
601 if ((d = boost::dynamic_pointer_cast<Delivery> (*i)) != 0) {
602 d->set_solo_level (soloed ());
603 d->set_solo_isolated (solo_isolated());
609 Route::set_solo_isolated (bool yn, void *src)
611 if (is_master() || is_control() || is_hidden()) {
615 if (_route_group && src != _route_group && _route_group->active_property (RouteGroup::Solo)) {
616 _route_group->apply (&Route::set_solo_isolated, yn, _route_group);
620 /* forward propagate solo-isolate status to everything fed by this route, but not those via sends only */
622 boost::shared_ptr<RouteList> routes = _session.get_routes ();
623 for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
625 bool does_feed = feeds (*i, &sends_only);
627 if (does_feed && !sends_only) {
628 (*i)->set_solo_isolated (yn, (*i)->route_group());
632 bool changed = false;
635 if (_solo_isolated == 0) {
640 changed = (_solo_isolated == 1);
641 if (_solo_isolated > 0) {
647 set_delivery_solo ();
648 solo_isolated_changed (src);
653 Route::solo_isolated () const
655 return _solo_isolated > 0;
659 Route::set_mute_points (MuteMaster::MutePoint mp)
662 mute_points_changed (); /* EMIT SIGNAL */
664 if (_mute_master->muted()) {
665 _mute_master->mute_at (_mute_points);
666 mute_changed (this); /* EMIT SIGNAL */
671 Route::set_mute (bool yn, void *src)
673 if (_route_group && src != _route_group && _route_group->active_property (RouteGroup::Mute)) {
674 _route_group->apply (&Route::set_mute, yn, _route_group);
680 _mute_master->mute_at (_mute_points);
682 _mute_master->clear_mute ();
685 mute_changed (src); /* EMIT SIGNAL */
692 return _mute_master->muted ();
697 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
699 cerr << name << " {" << endl;
700 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
701 p != procs.end(); ++p) {
702 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << endl;
709 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err)
711 ProcessorList::iterator loc;
713 /* XXX this is not thread safe - we don't hold the lock across determining the iter
714 to add before and actually doing the insertion. dammit.
717 if (placement == PreFader) {
718 /* generic pre-fader: insert immediately before the amp */
719 loc = find (_processors.begin(), _processors.end(), _amp);
721 /* generic post-fader: insert right before the main outs */
722 loc = find (_processors.begin(), _processors.end(), _main_outs);
725 return add_processor (processor, loc, err);
729 /** Add a processor to the route.
730 * If @a iter is not NULL, it must point to an iterator in _processors and the new
731 * processor will be inserted immediately before this location. Otherwise,
732 * @a position is used.
735 Route::add_processor (boost::shared_ptr<Processor> processor, ProcessorList::iterator iter, ProcessorStreams* err)
737 ChanCount old_pms = processor_max_streams;
739 if (!_session.engine().connected() || !processor) {
744 Glib::RWLock::WriterLock lm (_processor_lock);
746 boost::shared_ptr<PluginInsert> pi;
747 boost::shared_ptr<PortInsert> porti;
749 ProcessorList::iterator loc = find(_processors.begin(), _processors.end(), processor);
751 if (processor == _amp || processor == _meter || processor == _main_outs) {
752 // Ensure only one of these are in the list at any time
753 if (loc != _processors.end()) {
754 if (iter == loc) { // Already in place, do nothing
756 } else { // New position given, relocate
757 _processors.erase (loc);
762 if (loc != _processors.end()) {
763 cerr << "ERROR: Processor added to route twice!" << endl;
770 _processors.insert (loc, processor);
772 // Set up processor list channels. This will set processor->[input|output]_streams(),
773 // configure redirect ports properly, etc.
775 if (configure_processors_unlocked (err)) {
776 ProcessorList::iterator ploc = loc;
778 _processors.erase(ploc);
779 configure_processors_unlocked (0); // it worked before we tried to add it ...
780 cerr << "configure failed\n";
784 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
786 if (pi->natural_input_streams() == ChanCount::ZERO) {
787 /* generator plugin */
788 _have_internal_generator = true;
793 if (_control_outs != processor) {
794 // XXX: do we want to emit the signal here ? change call order.
795 processor->activate ();
797 processor->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
799 _output->set_user_latency (0);
802 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
808 Route::add_processor_from_xml (const XMLNode& node, ProcessorList::iterator iter)
810 const XMLProperty *prop;
812 if (node.name() != "Processor") {
817 if ((prop = node.property ("type")) != 0) {
819 boost::shared_ptr<Processor> processor;
821 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
822 prop->value() == "lv2" ||
823 prop->value() == "vst" ||
824 prop->value() == "audiounit") {
826 processor.reset (new PluginInsert(_session, node));
828 } else if (prop->value() == "port") {
830 processor.reset (new PortInsert (_session, _mute_master, node));
832 } else if (prop->value() == "send") {
834 processor.reset (new Send (_session, _mute_master, node));
836 } else if (prop->value() == "meter") {
839 if (_meter->set_state (node, Stateful::loading_state_version)) {
846 _meter.reset (new PeakMeter (_session, node));
847 _meter->set_display_to_user (_meter_point == MeterCustom);
850 } else if (prop->value() == "amp") {
852 /* amp always exists */
855 if (processor->set_state (node, Stateful::loading_state_version)) {
858 /* never any reason to add it */
862 } else if (prop->value() == "intsend") {
864 processor.reset (new InternalSend (_session, _mute_master, node));
866 } else if (prop->value() == "intreturn") {
869 if (_intreturn->set_state (node, Stateful::loading_state_version)) {
875 _intreturn.reset (new InternalReturn (_session, node));
876 processor = _intreturn;
878 } else if (prop->value() == "main-outs") {
881 if (_main_outs->set_state (node, Stateful::loading_state_version)) {
888 _main_outs.reset (new Delivery (_session, _output, _mute_master, node));
889 processor = _main_outs;
892 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
896 if (iter == _processors.end() && processor->display_to_user() && !_processors.empty()) {
897 /* check for invisible processors stacked at the end and leave them there */
898 ProcessorList::iterator p;
899 p = _processors.end();
901 while (!(*p)->display_to_user() && p != _processors.begin()) {
908 return (add_processor (processor, iter) == 0);
911 error << _("Processor XML node has no type property") << endmsg;
916 catch (failed_constructor &err) {
917 warning << _("processor could not be created. Ignored.") << endmsg;
924 Route::add_processor_from_xml_2X (const XMLNode& node, int version, ProcessorList::iterator iter)
926 const XMLProperty *prop;
929 boost::shared_ptr<Processor> processor;
931 if (node.name() == "Insert") {
933 if ((prop = node.property ("type")) != 0) {
935 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
936 prop->value() == "lv2" ||
937 prop->value() == "vst" ||
938 prop->value() == "audiounit") {
940 processor.reset (new PluginInsert (_session, node));
944 processor.reset (new PortInsert (_session, _mute_master, node));
949 } else if (node.name() == "Send") {
951 processor.reset (new Send (_session, _mute_master, node, version));
955 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
959 if (iter == _processors.end() && processor->display_to_user() && !_processors.empty()) {
960 /* check for invisible processors stacked at the end and leave them there */
961 ProcessorList::iterator p;
962 p = _processors.end();
964 while (!(*p)->display_to_user() && p != _processors.begin()) {
971 return (add_processor (processor, iter) == 0);
974 catch (failed_constructor &err) {
975 warning << _("processor could not be created. Ignored.") << endmsg;
981 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
983 ProcessorList::iterator loc;
986 loc = find(_processors.begin(), _processors.end(), before);
988 /* nothing specified - at end but before main outs */
989 loc = find (_processors.begin(), _processors.end(), _main_outs);
992 return add_processors (others, loc, err);
996 Route::add_processors (const ProcessorList& others, ProcessorList::iterator iter, ProcessorStreams* err)
998 /* NOTE: this is intended to be used ONLY when copying
999 processors from another Route. Hence the subtle
1000 differences between this and ::add_processor()
1003 ChanCount old_pms = processor_max_streams;
1005 if (!_session.engine().connected()) {
1009 if (others.empty()) {
1014 Glib::RWLock::WriterLock lm (_processor_lock);
1016 ChanCount potential_max_streams = ChanCount::max (_input->n_ports(), _output->n_ports());
1018 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1020 // Ensure meter only appears in the list once
1022 ProcessorList::iterator m = find(_processors.begin(), _processors.end(), *i);
1023 if (m != _processors.end()) {
1024 _processors.erase(m);
1028 boost::shared_ptr<PluginInsert> pi;
1030 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1033 ChanCount m = max (pi->input_streams(), pi->output_streams());
1035 if (m > potential_max_streams) {
1036 potential_max_streams = m;
1040 ProcessorList::iterator inserted = _processors.insert (iter, *i);
1042 if ((*i)->active()) {
1046 if (configure_processors_unlocked (err)) {
1047 _processors.erase (inserted);
1048 configure_processors_unlocked (0); // it worked before we tried to add it ...
1052 (*i)->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
1055 _output->set_user_latency (0);
1058 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1064 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1066 if (p == PreFader) {
1067 start = _processors.begin();
1068 end = find(_processors.begin(), _processors.end(), _amp);
1070 start = find(_processors.begin(), _processors.end(), _amp);
1072 end = _processors.end();
1076 /** Turn off all processors with a given placement
1077 * @param p Placement of processors to disable
1080 Route::disable_processors (Placement p)
1082 Glib::RWLock::ReaderLock lm (_processor_lock);
1084 ProcessorList::iterator start, end;
1085 placement_range(p, start, end);
1087 for (ProcessorList::iterator i = start; i != end; ++i) {
1088 (*i)->deactivate ();
1091 _session.set_dirty ();
1094 /** Turn off all redirects
1097 Route::disable_processors ()
1099 Glib::RWLock::ReaderLock lm (_processor_lock);
1101 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1102 (*i)->deactivate ();
1105 _session.set_dirty ();
1108 /** Turn off all redirects with a given placement
1109 * @param p Placement of redirects to disable
1112 Route::disable_plugins (Placement p)
1114 Glib::RWLock::ReaderLock lm (_processor_lock);
1116 ProcessorList::iterator start, end;
1117 placement_range(p, start, end);
1119 for (ProcessorList::iterator i = start; i != end; ++i) {
1120 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1121 (*i)->deactivate ();
1125 _session.set_dirty ();
1128 /** Turn off all plugins
1131 Route::disable_plugins ()
1133 Glib::RWLock::ReaderLock lm (_processor_lock);
1135 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1136 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1137 (*i)->deactivate ();
1141 _session.set_dirty ();
1146 Route::ab_plugins (bool forward)
1148 Glib::RWLock::ReaderLock lm (_processor_lock);
1152 /* forward = turn off all active redirects, and mark them so that the next time
1153 we go the other way, we will revert them
1156 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1157 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1161 if ((*i)->active()) {
1162 (*i)->deactivate ();
1163 (*i)->set_next_ab_is_active (true);
1165 (*i)->set_next_ab_is_active (false);
1171 /* backward = if the redirect was marked to go active on the next ab, do so */
1173 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1175 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1179 if ((*i)->get_next_ab_is_active()) {
1182 (*i)->deactivate ();
1187 _session.set_dirty ();
1191 /** Remove processors with a given placement.
1192 * @param p Placement of processors to remove.
1195 Route::clear_processors (Placement p)
1197 const ChanCount old_pms = processor_max_streams;
1199 if (!_session.engine().connected()) {
1203 bool already_deleting = _session.deletion_in_progress();
1204 if (!already_deleting) {
1205 _session.set_deletion_in_progress();
1209 Glib::RWLock::WriterLock lm (_processor_lock);
1210 ProcessorList new_list;
1211 ProcessorStreams err;
1212 bool seen_amp = false;
1214 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1220 if ((*i) == _amp || (*i) == _meter || (*i) == _main_outs) {
1222 /* you can't remove these */
1224 new_list.push_back (*i);
1231 new_list.push_back (*i);
1234 (*i)->drop_references ();
1242 (*i)->drop_references ();
1245 new_list.push_back (*i);
1252 _processors = new_list;
1253 configure_processors_unlocked (&err); // this can't fail
1256 processor_max_streams.reset();
1257 _have_internal_generator = false;
1258 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1260 if (!already_deleting) {
1261 _session.clear_deletion_in_progress();
1266 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err)
1268 /* these can never be removed */
1270 if (processor == _amp || processor == _meter || processor == _main_outs) {
1274 ChanCount old_pms = processor_max_streams;
1276 if (!_session.engine().connected()) {
1280 processor_max_streams.reset();
1283 Glib::RWLock::WriterLock lm (_processor_lock);
1284 ProcessorList::iterator i;
1285 bool removed = false;
1287 for (i = _processors.begin(); i != _processors.end(); ) {
1288 if (*i == processor) {
1290 /* move along, see failure case for configure_processors()
1291 where we may need to reconfigure the processor.
1294 /* stop redirects that send signals to JACK ports
1295 from causing noise as a result of no longer being
1299 boost::shared_ptr<IOProcessor> iop;
1301 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (*i)) != 0) {
1303 iop->input()->disconnect (this);
1305 if (iop->output()) {
1306 iop->output()->disconnect (this);
1310 i = _processors.erase (i);
1318 _output->set_user_latency (0);
1326 if (configure_processors_unlocked (err)) {
1327 /* get back to where we where */
1328 _processors.insert (i, processor);
1329 /* we know this will work, because it worked before :) */
1330 configure_processors_unlocked (0);
1334 _have_internal_generator = false;
1336 for (i = _processors.begin(); i != _processors.end(); ++i) {
1337 boost::shared_ptr<PluginInsert> pi;
1339 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1340 if (pi->is_generator()) {
1341 _have_internal_generator = true;
1348 processor->drop_references ();
1349 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1355 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1357 ProcessorList deleted;
1358 ProcessorList as_we_were;
1360 if (!_session.engine().connected()) {
1364 processor_max_streams.reset();
1367 Glib::RWLock::WriterLock lm (_processor_lock);
1368 ProcessorList::iterator i;
1369 boost::shared_ptr<Processor> processor;
1371 as_we_were = _processors;
1373 for (i = _processors.begin(); i != _processors.end(); ) {
1377 /* these can never be removed */
1379 if (processor == _amp || processor == _meter || processor == _main_outs) {
1384 /* see if its in the list of processors to delete */
1386 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1391 /* stop IOProcessors that send to JACK ports
1392 from causing noise as a result of no longer being
1396 boost::shared_ptr<IOProcessor> iop;
1398 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (processor)) != 0) {
1402 deleted.push_back (processor);
1403 i = _processors.erase (i);
1406 if (deleted.empty()) {
1407 /* none of those in the requested list were found */
1411 _output->set_user_latency (0);
1413 if (configure_processors_unlocked (err)) {
1414 /* get back to where we where */
1415 _processors = as_we_were;
1416 /* we know this will work, because it worked before :) */
1417 configure_processors_unlocked (0);
1421 _have_internal_generator = false;
1423 for (i = _processors.begin(); i != _processors.end(); ++i) {
1424 boost::shared_ptr<PluginInsert> pi;
1426 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1427 if (pi->is_generator()) {
1428 _have_internal_generator = true;
1435 /* now try to do what we need to so that those that were removed will be deleted */
1437 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1438 (*i)->drop_references ();
1441 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1448 Route::configure_processors (ProcessorStreams* err)
1450 if (!_in_configure_processors) {
1451 Glib::RWLock::WriterLock lm (_processor_lock);
1452 return configure_processors_unlocked (err);
1457 /** Configure the input/output configuration of each processor in the processors list.
1458 * Return 0 on success, otherwise configuration is impossible.
1461 Route::configure_processors_unlocked (ProcessorStreams* err)
1463 if (_in_configure_processors) {
1467 _in_configure_processors = true;
1469 // Check each processor in order to see if we can configure as requested
1470 ChanCount in = _input->n_ports ();
1472 list< pair<ChanCount,ChanCount> > configuration;
1475 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1477 DEBUG_TRACE (DEBUG::Processors, "{\n");
1478 for (list<boost::shared_ptr<Processor> >::const_iterator p = _processors.begin(); p != _processors.end(); ++p) {
1479 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID = %2\n", (*p)->name(), (*p)->id()));
1481 DEBUG_TRACE (DEBUG::Processors, "}\n");
1484 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1486 if ((*p)->can_support_io_configuration(in, out)) {
1487 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1in = %2 out = %3\n",(*p)->name(), in, out));
1488 configuration.push_back(make_pair(in, out));
1495 _in_configure_processors = false;
1500 // We can, so configure everything
1501 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1502 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1503 (*p)->configure_io(c->first, c->second);
1504 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1505 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1510 _meter->reset_max_channels (processor_max_streams);
1513 /* make sure we have sufficient scratch buffers to cope with the new processor
1515 _session.ensure_buffers (n_process_buffers ());
1517 _in_configure_processors = false;
1522 Route::all_processors_flip ()
1524 Glib::RWLock::ReaderLock lm (_processor_lock);
1526 if (_processors.empty()) {
1530 bool first_is_on = _processors.front()->active();
1532 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1534 (*i)->deactivate ();
1540 _session.set_dirty ();
1543 /** Set all processors with a given placement to a given active state.
1544 * @param p Placement of processors to change.
1545 * @param state New active state for those processors.
1548 Route::all_processors_active (Placement p, bool state)
1550 Glib::RWLock::ReaderLock lm (_processor_lock);
1552 if (_processors.empty()) {
1555 ProcessorList::iterator start, end;
1556 placement_range(p, start, end);
1558 bool before_amp = true;
1559 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1564 if (p == PreFader && before_amp) {
1568 (*i)->deactivate ();
1573 _session.set_dirty ();
1577 Route::processor_is_prefader (boost::shared_ptr<Processor> p)
1579 bool pre_fader = true;
1580 Glib::RWLock::ReaderLock lm (_processor_lock);
1582 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1584 /* semantic note: if p == amp, we want to return true, so test
1585 for equality before checking if this is the amp
1602 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
1604 /* "new_order" is an ordered list of processors to be positioned according to "placement".
1605 NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
1606 processors in the current actual processor list that are hidden. Any visible processors
1607 in the current list but not in "new_order" will be assumed to be deleted.
1611 Glib::RWLock::WriterLock lm (_processor_lock);
1612 ChanCount old_pms = processor_max_streams;
1613 ProcessorList::iterator oiter;
1614 ProcessorList::const_iterator niter;
1615 ProcessorList as_it_was_before = _processors;
1616 ProcessorList as_it_will_be;
1618 oiter = _processors.begin();
1619 niter = new_order.begin();
1621 while (niter != new_order.end()) {
1623 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
1624 then append it to the temp list.
1626 Otherwise, see if the next processor in the old list is in the new list. if not,
1627 its been deleted. If its there, append it to the temp list.
1630 if (oiter == _processors.end()) {
1632 /* no more elements in the old list, so just stick the rest of
1633 the new order onto the temp list.
1636 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
1637 while (niter != new_order.end()) {
1644 if (!(*oiter)->display_to_user()) {
1646 as_it_will_be.push_back (*oiter);
1650 /* visible processor: check that its in the new order */
1652 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
1653 /* deleted: do nothing, shared_ptr<> will clean up */
1655 /* ignore this one, and add the next item from the new order instead */
1656 as_it_will_be.push_back (*niter);
1661 /* now remove from old order - its taken care of no matter what */
1662 oiter = _processors.erase (oiter);
1667 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
1669 if (configure_processors_unlocked (err)) {
1670 _processors = as_it_was_before;
1671 processor_max_streams = old_pms;
1676 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1688 Route::get_template()
1690 return state(false);
1694 Route::state(bool full_state)
1696 XMLNode *node = new XMLNode("Route");
1697 ProcessorList::iterator i;
1700 id().print (buf, sizeof (buf));
1701 node->add_property("id", buf);
1702 node->add_property ("name", _name);
1703 node->add_property("default-type", _default_type.to_string());
1706 node->add_property("flags", enum_2_string (_flags));
1709 node->add_property("active", _active?"yes":"no");
1710 node->add_property("phase-invert", _phase_invert?"yes":"no");
1711 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
1712 node->add_property("meter-point", enum_2_string (_meter_point));
1715 node->add_property("route-group", _route_group->name());
1718 string order_string;
1719 OrderKeys::iterator x = order_keys.begin();
1721 while (x != order_keys.end()) {
1722 order_string += string ((*x).first);
1723 order_string += '=';
1724 snprintf (buf, sizeof(buf), "%ld", (*x).second);
1725 order_string += buf;
1729 if (x == order_keys.end()) {
1733 order_string += ':';
1735 node->add_property ("order-keys", order_string);
1736 node->add_property ("self-solo", (_self_solo ? "yes" : "no"));
1737 snprintf (buf, sizeof (buf), "%d", _soloed_by_others);
1738 node->add_property ("soloed-by-others", buf);
1740 node->add_child_nocopy (_input->state (full_state));
1741 node->add_child_nocopy (_output->state (full_state));
1742 node->add_child_nocopy (_solo_control->get_state ());
1743 node->add_child_nocopy (_mute_master->get_state ());
1745 XMLNode* remote_control_node = new XMLNode (X_("RemoteControl"));
1746 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
1747 remote_control_node->add_property (X_("id"), buf);
1748 node->add_child_nocopy (*remote_control_node);
1750 if (_comment.length()) {
1751 XMLNode *cmt = node->add_child ("Comment");
1752 cmt->add_content (_comment);
1755 for (i = _processors.begin(); i != _processors.end(); ++i) {
1756 node->add_child_nocopy((*i)->state (full_state));
1760 node->add_child_copy (*_extra_xml);
1767 Route::set_state (const XMLNode& node, int version)
1769 return _set_state (node, version, true);
1773 Route::_set_state (const XMLNode& node, int version, bool /*call_base*/)
1775 if (version < 3000) {
1776 return _set_state_2X (node, version);
1780 XMLNodeConstIterator niter;
1782 XMLPropertyList plist;
1783 const XMLProperty *prop;
1785 if (node.name() != "Route"){
1786 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
1790 if ((prop = node.property (X_("name"))) != 0) {
1791 Route::set_name (prop->value());
1794 if ((prop = node.property ("id")) != 0) {
1795 _id = prop->value ();
1798 if ((prop = node.property (X_("flags"))) != 0) {
1799 _flags = Flag (string_2_enum (prop->value(), _flags));
1804 /* add all processors (except amp, which is always present) */
1806 nlist = node.children();
1807 XMLNode processor_state (X_("processor_state"));
1809 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1813 if (child->name() == IO::state_node_name) {
1814 if ((prop = child->property (X_("direction"))) == 0) {
1818 if (prop->value() == "Input") {
1819 _input->set_state (*child, version);
1820 } else if (prop->value() == "Output") {
1821 _output->set_state (*child, version);
1825 if (child->name() == X_("Processor")) {
1826 processor_state.add_child_copy (*child);
1830 set_processor_state (processor_state);
1832 if ((prop = node.property ("self-solo")) != 0) {
1833 set_self_solo (string_is_affirmative (prop->value()));
1836 if ((prop = node.property ("soloed-by-others")) != 0) {
1837 _soloed_by_others = 0; // needed for mod_solo_by_others () to work
1838 mod_solo_by_others (atoi (prop->value()));
1841 if ((prop = node.property ("solo-isolated")) != 0) {
1842 set_solo_isolated (string_is_affirmative (prop->value()), this);
1845 if ((prop = node.property (X_("phase-invert"))) != 0) {
1846 set_phase_invert (string_is_affirmative (prop->value()));
1849 if ((prop = node.property (X_("denormal-protection"))) != 0) {
1850 set_denormal_protection (string_is_affirmative (prop->value()));
1853 if ((prop = node.property (X_("active"))) != 0) {
1854 bool yn = string_is_affirmative (prop->value());
1855 _active = !yn; // force switch
1859 if ((prop = node.property (X_("meter-point"))) != 0) {
1860 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
1862 _meter->set_display_to_user (_meter_point == MeterCustom);
1866 if ((prop = node.property (X_("order-keys"))) != 0) {
1870 string::size_type colon, equal;
1871 string remaining = prop->value();
1873 while (remaining.length()) {
1875 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
1876 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1879 if (sscanf (remaining.substr (equal+1).c_str(), "%ld", &n) != 1) {
1880 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1883 set_order_key (remaining.substr (0, equal), n);
1887 colon = remaining.find_first_of (':');
1889 if (colon != string::npos) {
1890 remaining = remaining.substr (colon+1);
1897 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1900 if (child->name() == X_("Comment")) {
1902 /* XXX this is a terrible API design in libxml++ */
1904 XMLNode *cmt = *(child->children().begin());
1905 _comment = cmt->content();
1907 } else if (child->name() == X_("Extra")) {
1909 _extra_xml = new XMLNode (*child);
1911 } else if (child->name() == X_("Controllable") && (prop = child->property("name")) != 0) {
1913 if (prop->value() == "solo") {
1914 _solo_control->set_state (*child, version);
1915 _session.add_controllable (_solo_control);
1918 } else if (child->name() == X_("RemoteControl")) {
1919 if ((prop = child->property (X_("id"))) != 0) {
1921 sscanf (prop->value().c_str(), "%d", &x);
1922 set_remote_control_id (x);
1925 } else if (child->name() == X_("MuteMaster")) {
1926 _mute_master->set_state (*child, version);
1934 Route::_set_state_2X (const XMLNode& node, int version)
1937 XMLNodeConstIterator niter;
1939 XMLPropertyList plist;
1940 const XMLProperty *prop;
1942 /* 2X things which still remain to be handled:
1945 * mute-affects-pre-fader
1946 * mute-affects-post-fader
1947 * mute-affects-control-outs
1948 * mute-affects-main-outs
1953 if (node.name() != "Route") {
1954 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
1958 if ((prop = node.property (X_("flags"))) != 0) {
1959 _flags = Flag (string_2_enum (prop->value(), _flags));
1964 /* add standard processors */
1966 _meter.reset (new PeakMeter (_session));
1967 add_processor (_meter, PreFader);
1969 if (_flags & ControlOut) {
1970 /* where we listen to tracks */
1971 _intreturn.reset (new InternalReturn (_session));
1972 add_processor (_intreturn, PreFader);
1975 _main_outs.reset (new Delivery (_session, _output, _mute_master, _name, Delivery::Main));
1976 add_processor (_main_outs, PostFader);
1980 nlist = node.children ();
1981 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1985 if (child->name() == IO::state_node_name) {
1987 /* there is a note in IO::set_state_2X() about why we have to call
1991 _input->set_state_2X (*child, version, true);
1992 _output->set_state_2X (*child, version, false);
1994 if ((prop = child->property (X_("name"))) != 0) {
1995 set_name (prop->value ());
1998 if ((prop = child->property (X_("id"))) != 0) {
1999 _id = prop->value ();
2002 if ((prop = child->property (X_("active"))) != 0) {
2003 bool yn = string_is_affirmative (prop->value());
2004 _active = !yn; // force switch
2012 if ((prop = node.property (X_("phase-invert"))) != 0) {
2013 set_phase_invert (string_is_affirmative (prop->value()));
2016 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2017 set_denormal_protection (string_is_affirmative (prop->value()));
2020 if ((prop = node.property (X_("soloed"))) != 0) {
2021 bool yn = string_is_affirmative (prop->value());
2023 /* XXX force reset of solo status */
2025 set_solo (yn, this);
2028 if ((prop = node.property (X_("meter-point"))) != 0) {
2029 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2032 /* do not carry over edit/mix groups from 2.X because (a) its hard (b) they
2033 don't mean the same thing.
2036 if ((prop = node.property (X_("order-keys"))) != 0) {
2040 string::size_type colon, equal;
2041 string remaining = prop->value();
2043 while (remaining.length()) {
2045 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2046 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2049 if (sscanf (remaining.substr (equal+1).c_str(), "%ld", &n) != 1) {
2050 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2053 set_order_key (remaining.substr (0, equal), n);
2057 colon = remaining.find_first_of (':');
2059 if (colon != string::npos) {
2060 remaining = remaining.substr (colon+1);
2067 XMLNodeList redirect_nodes;
2069 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2073 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2074 redirect_nodes.push_back(child);
2079 set_processor_state_2X (redirect_nodes, version);
2081 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2084 if (child->name() == X_("Comment")) {
2086 /* XXX this is a terrible API design in libxml++ */
2088 XMLNode *cmt = *(child->children().begin());
2089 _comment = cmt->content();
2091 } else if (child->name() == X_("Extra")) {
2093 _extra_xml = new XMLNode (*child);
2095 } else if (child->name() == X_("Controllable") && (prop = child->property("name")) != 0) {
2097 if (prop->value() == "solo") {
2098 _solo_control->set_state (*child, version);
2099 _session.add_controllable (_solo_control);
2102 } else if (child->name() == X_("RemoteControl")) {
2103 if ((prop = child->property (X_("id"))) != 0) {
2105 sscanf (prop->value().c_str(), "%d", &x);
2106 set_remote_control_id (x);
2116 Route::get_processor_state ()
2118 XMLNode* root = new XMLNode (X_("redirects"));
2119 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2120 root->add_child_nocopy ((*i)->state (true));
2127 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2129 /* We don't bother removing existing processors not in nList, as this
2130 method will only be called when creating a Route from scratch, not
2131 for undo purposes. Just put processors in at the appropriate place
2135 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2136 add_processor_from_xml_2X (**i, version, _processors.begin ());
2141 Route::set_processor_state (const XMLNode& node)
2143 const XMLNodeList &nlist = node.children();
2144 XMLNodeConstIterator niter;
2145 ProcessorList::iterator i, o;
2147 // Iterate through existing processors, remove those which are not in the state list
2149 for (i = _processors.begin(); i != _processors.end(); ) {
2151 /* leave amp alone, always */
2158 ProcessorList::iterator tmp = i;
2161 bool processorInStateList = false;
2163 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2165 XMLProperty* id_prop = (*niter)->property(X_("id"));
2167 if (id_prop && (*i)->id() == id_prop->value()) {
2168 processorInStateList = true;
2173 if (!processorInStateList) {
2174 remove_processor (*i);
2180 // Iterate through state list and make sure all processors are on the track and in the correct order,
2181 // set the state of existing processors according to the new state on the same go
2183 i = _processors.begin();
2185 for (niter = nlist.begin(); niter != nlist.end(); ++niter, ++i) {
2187 XMLProperty* prop = (*niter)->property ("type");
2191 // Check whether the next processor in the list is the right one,
2192 // except for "amp" which is always there and may not have the
2193 // old ID since it is always created anew in every Route
2195 if (prop->value() != "amp") {
2196 while (o != _processors.end()) {
2197 XMLProperty* id_prop = (*niter)->property(X_("id"));
2198 if (id_prop && (*o)->id() == id_prop->value()) {
2206 // If the processor (*niter) is not on the route,
2207 // create it and move it to the correct location
2209 if (o == _processors.end()) {
2211 if (add_processor_from_xml (**niter, i)) {
2212 --i; // move iterator to the newly inserted processor
2214 cerr << "Error restoring route: unable to restore processor" << endl;
2219 // Otherwise, the processor already exists; just
2220 // ensure it is at the location provided in the XML state
2223 boost::shared_ptr<Processor> tmp = (*o);
2224 _processors.erase (o); // remove the old copy
2225 _processors.insert (i, tmp); // insert the processor at the correct location
2226 --i; // move iterator to the correct processor
2229 // and make it (just) so
2231 (*i)->set_state (**niter, Stateful::current_state_version);
2235 /* note: there is no configure_processors() call because we figure that
2236 the XML state represents a working signal route.
2239 processors_changed (RouteProcessorChange ());
2243 Route::curve_reallocate ()
2245 // _gain_automation_curve.finish_resize ();
2246 // _pan_automation_curve.finish_resize ();
2250 Route::silence (nframes_t nframes)
2254 _output->silence (nframes);
2257 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2260 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2261 boost::shared_ptr<PluginInsert> pi;
2263 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2264 // skip plugins, they don't need anything when we're not active
2268 (*i)->silence (nframes);
2271 if (nframes == _session.get_block_size()) {
2281 Route::add_internal_return ()
2284 _intreturn.reset (new InternalReturn (_session));
2285 add_processor (_intreturn, PreFader);
2290 Route::get_return_buffer () const
2292 Glib::RWLock::ReaderLock rm (_processor_lock);
2294 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2295 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
2298 BufferSet* bs = d->get_buffers ();
2307 Route::release_return_buffer () const
2309 Glib::RWLock::ReaderLock rm (_processor_lock);
2311 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2312 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
2315 return d->release_buffers ();
2321 Route::listen_via (boost::shared_ptr<Route> route, Placement placement, bool /*active*/, bool aux)
2323 vector<string> ports;
2324 vector<string>::const_iterator i;
2327 Glib::RWLock::ReaderLock rm (_processor_lock);
2329 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
2331 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
2333 if (d && d->target_route() == route) {
2335 /* if the target is the control outs, then make sure
2336 we take note of which i-send is doing that.
2339 if (route == _session.control_out()) {
2340 _control_outs = boost::dynamic_pointer_cast<Delivery>(d);
2343 /* already listening via the specified IO: do nothing */
2350 boost::shared_ptr<InternalSend> listener;
2353 listener.reset (new InternalSend (_session, _mute_master, route, (aux ? Delivery::Aux : Delivery::Listen)));
2355 } catch (failed_constructor& err) {
2359 if (route == _session.control_out()) {
2360 _control_outs = listener;
2363 add_processor (listener, placement);
2369 Route::drop_listen (boost::shared_ptr<Route> route)
2371 ProcessorStreams err;
2372 ProcessorList::iterator tmp;
2374 Glib::RWLock::ReaderLock rl(_processor_lock);
2378 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ) {
2380 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
2382 if (d && d->target_route() == route) {
2384 remove_processor (*x, &err);
2387 /* list could have been demolished while we dropped the lock
2397 if (route == _session.control_out()) {
2398 _control_outs.reset ();
2403 Route::set_comment (string cmt, void *src)
2406 comment_changed (src);
2407 _session.set_dirty ();
2411 Route::feeds (boost::shared_ptr<Route> other, bool* only_send)
2413 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
2415 if (_output->connected_to (other->input())) {
2416 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
2425 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); r++) {
2427 boost::shared_ptr<IOProcessor> iop;
2429 if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*r)) != 0) {
2430 if (iop->feeds (other)) {
2431 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
2437 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
2440 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
2445 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
2450 Route::handle_transport_stopped (bool /*abort_ignored*/, bool did_locate, bool can_flush_processors)
2452 nframes_t now = _session.transport_frame();
2455 Glib::RWLock::ReaderLock lm (_processor_lock);
2458 automation_snapshot (now, true);
2461 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2463 if (Config->get_plugins_stop_with_transport() && can_flush_processors) {
2464 (*i)->deactivate ();
2468 (*i)->transport_stopped (now);
2472 _roll_delay = _initial_delay;
2476 Route::input_change_handler (IOChange change, void * /*src*/)
2478 if ((change & ConfigurationChanged)) {
2479 configure_processors (0);
2484 Route::output_change_handler (IOChange change, void * /*src*/)
2486 if ((change & ConfigurationChanged)) {
2488 /* XXX resize all listeners to match _main_outs? */
2490 // configure_processors (0);
2495 Route::pans_required () const
2497 if (n_outputs().n_audio() < 2) {
2501 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
2505 Route::no_roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame,
2506 bool session_state_changing, bool /*can_record*/, bool /*rec_monitors_input*/)
2508 if (n_outputs().n_total() == 0) {
2512 if (session_state_changing || !_active || n_inputs() == ChanCount::ZERO) {
2517 _amp->apply_gain_automation (false);
2518 passthru (start_frame, end_frame, nframes, 0);
2524 Route::check_initial_delay (nframes_t nframes, nframes_t& transport_frame)
2526 if (_roll_delay > nframes) {
2528 _roll_delay -= nframes;
2530 /* transport frame is not legal for caller to use */
2533 } else if (_roll_delay > 0) {
2535 nframes -= _roll_delay;
2536 silence (_roll_delay);
2537 /* we've written _roll_delay of samples into the
2538 output ports, so make a note of that for
2541 _main_outs->increment_output_offset (_roll_delay);
2542 transport_frame += _roll_delay;
2551 Route::roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame, int declick,
2552 bool /*can_record*/, bool /*rec_monitors_input*/)
2555 // automation snapshot can also be called from the non-rt context
2556 // and it uses the processor list, so we try to acquire the lock here
2557 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2560 automation_snapshot (_session.transport_frame(), false);
2564 if (n_outputs().n_total() == 0) {
2568 if (!_active || n_inputs().n_total() == 0) {
2573 nframes_t unused = 0;
2575 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
2581 passthru (start_frame, end_frame, nframes, declick);
2587 Route::silent_roll (nframes_t nframes, sframes_t /*start_frame*/, sframes_t /*end_frame*/,
2588 bool /*can_record*/, bool /*rec_monitors_input*/)
2595 Route::toggle_monitor_input ()
2597 for (PortSet::iterator i = _input->ports().begin(); i != _input->ports().end(); ++i) {
2598 i->ensure_monitor_input( ! i->monitoring_input());
2603 Route::has_external_redirects () const
2605 // FIXME: what about sends? - they don't return a signal back to ardour?
2607 boost::shared_ptr<const PortInsert> pi;
2609 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2611 if ((pi = boost::dynamic_pointer_cast<const PortInsert>(*i)) != 0) {
2613 for (PortSet::const_iterator port = pi->output()->ports().begin(); port != pi->output()->ports().end(); ++port) {
2615 string port_name = port->name();
2616 string client_name = port_name.substr (0, port_name.find(':'));
2618 /* only say "yes" if the redirect is actually in use */
2620 if (client_name != "ardour" && pi->active()) {
2631 Route::flush_processors ()
2633 /* XXX shouldn't really try to take this lock, since
2634 this is called from the RT audio thread.
2637 Glib::RWLock::ReaderLock lm (_processor_lock);
2639 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2640 (*i)->deactivate ();
2646 Route::set_meter_point (MeterPoint p, void *src)
2648 /* CAN BE CALLED FROM PROCESS CONTEXT */
2650 if (_meter_point == p) {
2654 bool meter_was_visible_to_user = _meter->display_to_user ();
2657 Glib::RWLock::WriterLock lm (_processor_lock);
2659 if (p != MeterCustom) {
2660 // Move meter in the processors list to reflect the new position
2661 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
2662 _processors.erase(loc);
2665 loc = _processors.begin();
2668 loc = find (_processors.begin(), _processors.end(), _amp);
2670 case MeterPostFader:
2671 loc = _processors.end();
2679 if (loc == _processors.begin()) {
2680 m_in = _input->n_ports();
2682 ProcessorList::iterator before = loc;
2684 m_in = (*before)->output_streams ();
2687 _meter->reflect_inputs (m_in);
2689 _processors.insert (loc, _meter);
2691 /* we do not need to reconfigure the processors, because the meter
2692 (a) is always ready to handle processor_max_streams
2693 (b) is always an N-in/N-out processor, and thus moving
2694 it doesn't require any changes to the other processors.
2697 _meter->set_display_to_user (false);
2701 // just make it visible and let the user move it
2703 _meter->set_display_to_user (true);
2708 meter_change (src); /* EMIT SIGNAL */
2710 bool const meter_visibly_changed = (_meter->display_to_user() != meter_was_visible_to_user);
2712 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, meter_visibly_changed)); /* EMIT SIGNAL */
2716 Route::put_control_outs_at (Placement p)
2718 if (!_control_outs) {
2723 Glib::RWLock::WriterLock lm (_processor_lock);
2724 ProcessorList as_it_was (_processors);
2725 // Move meter in the processors list
2726 ProcessorList::iterator loc = find(_processors.begin(), _processors.end(), _control_outs);
2727 _processors.erase(loc);
2731 loc = find(_processors.begin(), _processors.end(), _amp);
2732 if (loc != _processors.begin()) {
2737 loc = find(_processors.begin(), _processors.end(), _amp);
2738 assert (loc != _processors.end());
2743 _processors.insert(loc, _control_outs);
2745 if (configure_processors_unlocked (0)) {
2746 _processors = as_it_was;
2747 configure_processors_unlocked (0); // it worked before we tried to add it ...
2752 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2753 _session.set_dirty ();
2757 Route::update_total_latency ()
2759 nframes_t old = _output->effective_latency();
2760 nframes_t own_latency = _output->user_latency();
2762 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2763 if ((*i)->active ()) {
2764 own_latency += (*i)->signal_latency ();
2768 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal redirect latency = %2\n", _name, own_latency));
2770 _output->set_port_latency (own_latency);
2772 if (_output->user_latency() == 0) {
2774 /* this (virtual) function is used for pure Routes,
2775 not derived classes like AudioTrack. this means
2776 that the data processed here comes from an input
2777 port, not prerecorded material, and therefore we
2778 have to take into account any input latency.
2781 own_latency += _input->signal_latency ();
2784 if (old != own_latency) {
2785 _output->set_latency_delay (own_latency);
2786 signal_latency_changed (); /* EMIT SIGNAL */
2789 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: input latency = %2 total = %3\n", _name, _input->signal_latency(), own_latency));
2791 return _output->effective_latency ();
2795 Route::set_user_latency (nframes_t nframes)
2797 _output->set_user_latency (nframes);
2798 _session.update_latency_compensation (false, false);
2802 Route::set_latency_delay (nframes_t longest_session_latency)
2804 nframes_t old = _initial_delay;
2806 if (_output->effective_latency() < longest_session_latency) {
2807 _initial_delay = longest_session_latency - _output->effective_latency();
2812 if (_initial_delay != old) {
2813 initial_delay_changed (); /* EMIT SIGNAL */
2816 if (_session.transport_stopped()) {
2817 _roll_delay = _initial_delay;
2822 Route::automation_snapshot (nframes_t now, bool force)
2824 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2825 (*i)->automation_snapshot (now, force);
2829 Route::SoloControllable::SoloControllable (std::string name, Route& r)
2830 : AutomationControl (r.session(), Evoral::Parameter (SoloAutomation),
2831 boost::shared_ptr<AutomationList>(), name)
2834 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(SoloAutomation)));
2839 Route::SoloControllable::set_value (float val)
2841 bool bval = ((val >= 0.5f) ? true: false);
2843 route.set_solo (bval, this);
2847 Route::SoloControllable::get_value (void) const
2849 return route.self_soloed() ? 1.0f : 0.0f;
2853 Route::set_block_size (nframes_t nframes)
2855 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2856 (*i)->set_block_size (nframes);
2859 _session.ensure_buffers (n_process_buffers ());
2863 Route::protect_automation ()
2865 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
2866 (*i)->protect_automation();
2870 Route::set_pending_declick (int declick)
2873 /* this call is not allowed to turn off a pending declick unless "force" is true */
2875 _pending_declick = declick;
2877 // cerr << _name << ": after setting to " << declick << " pending declick = " << _pending_declick << endl;
2879 _pending_declick = 0;
2884 /** Shift automation forwards from a particular place, thereby inserting time.
2885 * Adds undo commands for any shifts that are performed.
2887 * @param pos Position to start shifting from.
2888 * @param frames Amount to shift forwards by.
2892 Route::shift (nframes64_t /*pos*/, nframes64_t /*frames*/)
2894 #ifdef THIS_NEEDS_FIXING_FOR_V3
2896 /* gain automation */
2897 XMLNode &before = _gain_control->get_state ();
2898 _gain_control->shift (pos, frames);
2899 XMLNode &after = _gain_control->get_state ();
2900 _session.add_command (new MementoCommand<AutomationList> (_gain_automation_curve, &before, &after));
2902 /* pan automation */
2903 for (std::vector<StreamPanner*>::iterator i = _panner->begin (); i != _panner->end (); ++i) {
2904 Curve & c = (*i)->automation ();
2905 XMLNode &before = c.get_state ();
2906 c.shift (pos, frames);
2907 XMLNode &after = c.get_state ();
2908 _session.add_command (new MementoCommand<AutomationList> (c, &before, &after));
2911 /* redirect automation */
2913 Glib::RWLock::ReaderLock lm (redirect_lock);
2914 for (RedirectList::iterator i = _redirects.begin (); i != _redirects.end (); ++i) {
2917 (*i)->what_has_automation (a);
2919 for (set<uint32_t>::const_iterator j = a.begin (); j != a.end (); ++j) {
2920 AutomationList & al = (*i)->automation_list (*j);
2921 XMLNode &before = al.get_state ();
2922 al.shift (pos, frames);
2923 XMLNode &after = al.get_state ();
2924 _session.add_command (new MementoCommand<AutomationList> (al, &before, &after));
2934 Route::save_as_template (const string& path, const string& name)
2936 XMLNode& node (state (false));
2939 IO::set_name_in_state (*node.children().front(), name);
2941 tree.set_root (&node);
2942 return tree.write (path.c_str());
2947 Route::set_name (const string& str)
2953 name = Route::ensure_track_or_route_name (str, _session);
2954 SessionObject::set_name (name);
2956 ret = (_input->set_name(name) && _output->set_name(name));
2960 Glib::RWLock::ReaderLock lm (_processor_lock);
2962 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2964 /* rename all I/O processors that have inputs or outputs */
2966 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor> (*i);
2968 if (iop && (iop->output() || iop->input())) {
2969 if (!iop->set_name (name)) {
2980 boost::shared_ptr<Send>
2981 Route::internal_send_for (boost::shared_ptr<const Route> target) const
2983 Glib::RWLock::ReaderLock lm (_processor_lock);
2985 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2986 boost::shared_ptr<InternalSend> send;
2988 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
2989 if (send->target_route() == target) {
2995 return boost::shared_ptr<Send>();
2999 Route::set_phase_invert (bool yn)
3001 if (_phase_invert != yn) {
3002 _phase_invert = 0xffff; // XXX all channels
3003 phase_invert_changed (); /* EMIT SIGNAL */
3008 Route::phase_invert () const
3010 return _phase_invert != 0;
3014 Route::set_denormal_protection (bool yn)
3016 if (_denormal_protection != yn) {
3017 _denormal_protection = yn;
3018 denormal_protection_changed (); /* EMIT SIGNAL */
3023 Route::denormal_protection () const
3025 return _denormal_protection;
3029 Route::set_active (bool yn)
3031 if (_active != yn) {
3033 _input->set_active (yn);
3034 _output->set_active (yn);
3035 active_changed (); // EMIT SIGNAL
3042 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
3048 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3050 boost::shared_ptr<Send> s;
3051 boost::shared_ptr<Return> r;
3053 if ((s = boost::dynamic_pointer_cast<Send> (*i)) != 0) {
3054 s->meter()->meter();
3055 } else if ((r = boost::dynamic_pointer_cast<Return> (*i)) != 0) {
3056 r->meter()->meter ();
3061 boost::shared_ptr<Panner>
3062 Route::panner() const
3065 return _main_outs->panner();
3068 boost::shared_ptr<AutomationControl>
3069 Route::gain_control() const
3072 return _amp->gain_control();
3075 boost::shared_ptr<AutomationControl>
3076 Route::get_control (const Evoral::Parameter& param)
3078 /* either we own the control or .... */
3080 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(data().control (param));
3084 /* maybe one of our processors does or ... */
3086 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
3087 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3088 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->data().control (param))) != 0) {
3096 /* nobody does so we'll make a new one */
3098 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));