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;
634 cerr << _name << " Solo isolated was " << _solo_isolated << endl;
637 if (_solo_isolated == 0) {
642 changed = (_solo_isolated == 1);
643 if (_solo_isolated > 0) {
648 cerr << "\tnow " << _solo_isolated << endl;
651 set_delivery_solo ();
652 solo_isolated_changed (src);
657 Route::solo_isolated () const
659 return _solo_isolated > 0;
663 Route::set_mute_points (MuteMaster::MutePoint mp)
666 mute_points_changed (); /* EMIT SIGNAL */
668 if (_mute_master->muted()) {
669 _mute_master->mute_at (_mute_points);
670 mute_changed (this); /* EMIT SIGNAL */
675 Route::set_mute (bool yn, void *src)
677 if (_route_group && src != _route_group && _route_group->active_property (RouteGroup::Mute)) {
678 _route_group->apply (&Route::set_mute, yn, _route_group);
684 _mute_master->mute_at (_mute_points);
686 _mute_master->clear_mute ();
689 mute_changed (src); /* EMIT SIGNAL */
696 return _mute_master->muted ();
701 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
703 cerr << name << " {" << endl;
704 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
705 p != procs.end(); ++p) {
706 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << endl;
713 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err)
715 ProcessorList::iterator loc;
717 /* XXX this is not thread safe - we don't hold the lock across determining the iter
718 to add before and actually doing the insertion. dammit.
721 if (placement == PreFader) {
722 /* generic pre-fader: insert immediately before the amp */
723 loc = find (_processors.begin(), _processors.end(), _amp);
725 /* generic post-fader: insert right before the main outs */
726 loc = find (_processors.begin(), _processors.end(), _main_outs);
729 return add_processor (processor, loc, err);
733 /** Add a processor to the route.
734 * If @a iter is not NULL, it must point to an iterator in _processors and the new
735 * processor will be inserted immediately before this location. Otherwise,
736 * @a position is used.
739 Route::add_processor (boost::shared_ptr<Processor> processor, ProcessorList::iterator iter, ProcessorStreams* err)
741 ChanCount old_pms = processor_max_streams;
743 if (!_session.engine().connected() || !processor) {
748 Glib::RWLock::WriterLock lm (_processor_lock);
750 boost::shared_ptr<PluginInsert> pi;
751 boost::shared_ptr<PortInsert> porti;
753 ProcessorList::iterator loc = find(_processors.begin(), _processors.end(), processor);
755 if (processor == _amp || processor == _meter || processor == _main_outs) {
756 // Ensure only one of these are in the list at any time
757 if (loc != _processors.end()) {
758 if (iter == loc) { // Already in place, do nothing
760 } else { // New position given, relocate
761 _processors.erase (loc);
766 if (loc != _processors.end()) {
767 cerr << "ERROR: Processor added to route twice!" << endl;
774 _processors.insert (loc, processor);
776 // Set up processor list channels. This will set processor->[input|output]_streams(),
777 // configure redirect ports properly, etc.
779 if (configure_processors_unlocked (err)) {
780 ProcessorList::iterator ploc = loc;
782 _processors.erase(ploc);
783 configure_processors_unlocked (0); // it worked before we tried to add it ...
784 cerr << "configure failed\n";
788 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
790 if (pi->natural_input_streams() == ChanCount::ZERO) {
791 /* generator plugin */
792 _have_internal_generator = true;
797 if (_control_outs != processor) {
798 // XXX: do we want to emit the signal here ? change call order.
799 processor->activate ();
801 processor->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
803 _output->set_user_latency (0);
806 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
812 Route::add_processor_from_xml (const XMLNode& node, ProcessorList::iterator iter)
814 const XMLProperty *prop;
816 if (node.name() != "Processor") {
821 if ((prop = node.property ("type")) != 0) {
823 boost::shared_ptr<Processor> processor;
825 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
826 prop->value() == "lv2" ||
827 prop->value() == "vst" ||
828 prop->value() == "audiounit") {
830 processor.reset (new PluginInsert(_session, node));
832 } else if (prop->value() == "port") {
834 processor.reset (new PortInsert (_session, _mute_master, node));
836 } else if (prop->value() == "send") {
838 processor.reset (new Send (_session, _mute_master, node));
840 } else if (prop->value() == "meter") {
843 if (_meter->set_state (node, Stateful::loading_state_version)) {
850 _meter.reset (new PeakMeter (_session, node));
851 _meter->set_display_to_user (_meter_point == MeterCustom);
854 } else if (prop->value() == "amp") {
856 /* amp always exists */
859 if (processor->set_state (node, Stateful::loading_state_version)) {
862 /* never any reason to add it */
866 } else if (prop->value() == "intsend") {
868 processor.reset (new InternalSend (_session, _mute_master, node));
870 } else if (prop->value() == "intreturn") {
873 if (_intreturn->set_state (node, Stateful::loading_state_version)) {
879 _intreturn.reset (new InternalReturn (_session, node));
880 processor = _intreturn;
882 } else if (prop->value() == "main-outs") {
885 if (_main_outs->set_state (node, Stateful::loading_state_version)) {
892 _main_outs.reset (new Delivery (_session, _output, _mute_master, node));
893 processor = _main_outs;
896 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
900 if (iter == _processors.end() && processor->display_to_user() && !_processors.empty()) {
901 /* check for invisible processors stacked at the end and leave them there */
902 ProcessorList::iterator p;
903 p = _processors.end();
905 while (!(*p)->display_to_user() && p != _processors.begin()) {
912 return (add_processor (processor, iter) == 0);
915 error << _("Processor XML node has no type property") << endmsg;
920 catch (failed_constructor &err) {
921 warning << _("processor could not be created. Ignored.") << endmsg;
928 Route::add_processor_from_xml_2X (const XMLNode& node, int version, ProcessorList::iterator iter)
930 const XMLProperty *prop;
933 boost::shared_ptr<Processor> processor;
935 if (node.name() == "Insert") {
937 if ((prop = node.property ("type")) != 0) {
939 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
940 prop->value() == "lv2" ||
941 prop->value() == "vst" ||
942 prop->value() == "audiounit") {
944 processor.reset (new PluginInsert (_session, node));
948 processor.reset (new PortInsert (_session, _mute_master, node));
953 } else if (node.name() == "Send") {
955 processor.reset (new Send (_session, _mute_master, node, version));
959 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
963 if (iter == _processors.end() && processor->display_to_user() && !_processors.empty()) {
964 /* check for invisible processors stacked at the end and leave them there */
965 ProcessorList::iterator p;
966 p = _processors.end();
968 while (!(*p)->display_to_user() && p != _processors.begin()) {
975 return (add_processor (processor, iter) == 0);
978 catch (failed_constructor &err) {
979 warning << _("processor could not be created. Ignored.") << endmsg;
985 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
987 ProcessorList::iterator loc;
990 loc = find(_processors.begin(), _processors.end(), before);
992 /* nothing specified - at end but before main outs */
993 loc = find (_processors.begin(), _processors.end(), _main_outs);
996 return add_processors (others, loc, err);
1000 Route::add_processors (const ProcessorList& others, ProcessorList::iterator iter, ProcessorStreams* err)
1002 /* NOTE: this is intended to be used ONLY when copying
1003 processors from another Route. Hence the subtle
1004 differences between this and ::add_processor()
1007 ChanCount old_pms = processor_max_streams;
1009 if (!_session.engine().connected()) {
1013 if (others.empty()) {
1018 Glib::RWLock::WriterLock lm (_processor_lock);
1020 ChanCount potential_max_streams = ChanCount::max (_input->n_ports(), _output->n_ports());
1022 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1024 // Ensure meter only appears in the list once
1026 ProcessorList::iterator m = find(_processors.begin(), _processors.end(), *i);
1027 if (m != _processors.end()) {
1028 _processors.erase(m);
1032 boost::shared_ptr<PluginInsert> pi;
1034 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1037 ChanCount m = max (pi->input_streams(), pi->output_streams());
1039 if (m > potential_max_streams) {
1040 potential_max_streams = m;
1044 ProcessorList::iterator inserted = _processors.insert (iter, *i);
1046 if ((*i)->active()) {
1050 if (configure_processors_unlocked (err)) {
1051 _processors.erase (inserted);
1052 configure_processors_unlocked (0); // it worked before we tried to add it ...
1056 (*i)->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
1059 _output->set_user_latency (0);
1062 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1068 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1070 if (p == PreFader) {
1071 start = _processors.begin();
1072 end = find(_processors.begin(), _processors.end(), _amp);
1074 start = find(_processors.begin(), _processors.end(), _amp);
1076 end = _processors.end();
1080 /** Turn off all processors with a given placement
1081 * @param p Placement of processors to disable
1084 Route::disable_processors (Placement p)
1086 Glib::RWLock::ReaderLock lm (_processor_lock);
1088 ProcessorList::iterator start, end;
1089 placement_range(p, start, end);
1091 for (ProcessorList::iterator i = start; i != end; ++i) {
1092 (*i)->deactivate ();
1095 _session.set_dirty ();
1098 /** Turn off all redirects
1101 Route::disable_processors ()
1103 Glib::RWLock::ReaderLock lm (_processor_lock);
1105 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1106 (*i)->deactivate ();
1109 _session.set_dirty ();
1112 /** Turn off all redirects with a given placement
1113 * @param p Placement of redirects to disable
1116 Route::disable_plugins (Placement p)
1118 Glib::RWLock::ReaderLock lm (_processor_lock);
1120 ProcessorList::iterator start, end;
1121 placement_range(p, start, end);
1123 for (ProcessorList::iterator i = start; i != end; ++i) {
1124 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1125 (*i)->deactivate ();
1129 _session.set_dirty ();
1132 /** Turn off all plugins
1135 Route::disable_plugins ()
1137 Glib::RWLock::ReaderLock lm (_processor_lock);
1139 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1140 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1141 (*i)->deactivate ();
1145 _session.set_dirty ();
1150 Route::ab_plugins (bool forward)
1152 Glib::RWLock::ReaderLock lm (_processor_lock);
1156 /* forward = turn off all active redirects, and mark them so that the next time
1157 we go the other way, we will revert them
1160 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1161 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1165 if ((*i)->active()) {
1166 (*i)->deactivate ();
1167 (*i)->set_next_ab_is_active (true);
1169 (*i)->set_next_ab_is_active (false);
1175 /* backward = if the redirect was marked to go active on the next ab, do so */
1177 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1179 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1183 if ((*i)->get_next_ab_is_active()) {
1186 (*i)->deactivate ();
1191 _session.set_dirty ();
1195 /** Remove processors with a given placement.
1196 * @param p Placement of processors to remove.
1199 Route::clear_processors (Placement p)
1201 const ChanCount old_pms = processor_max_streams;
1203 if (!_session.engine().connected()) {
1207 bool already_deleting = _session.deletion_in_progress();
1208 if (!already_deleting) {
1209 _session.set_deletion_in_progress();
1213 Glib::RWLock::WriterLock lm (_processor_lock);
1214 ProcessorList new_list;
1215 ProcessorStreams err;
1216 bool seen_amp = false;
1218 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1224 if ((*i) == _amp || (*i) == _meter || (*i) == _main_outs) {
1226 /* you can't remove these */
1228 new_list.push_back (*i);
1235 new_list.push_back (*i);
1238 (*i)->drop_references ();
1246 (*i)->drop_references ();
1249 new_list.push_back (*i);
1256 _processors = new_list;
1257 configure_processors_unlocked (&err); // this can't fail
1260 processor_max_streams.reset();
1261 _have_internal_generator = false;
1262 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1264 if (!already_deleting) {
1265 _session.clear_deletion_in_progress();
1270 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err)
1272 /* these can never be removed */
1274 if (processor == _amp || processor == _meter || processor == _main_outs) {
1278 ChanCount old_pms = processor_max_streams;
1280 if (!_session.engine().connected()) {
1284 processor_max_streams.reset();
1287 Glib::RWLock::WriterLock lm (_processor_lock);
1288 ProcessorList::iterator i;
1289 bool removed = false;
1291 for (i = _processors.begin(); i != _processors.end(); ) {
1292 if (*i == processor) {
1294 /* move along, see failure case for configure_processors()
1295 where we may need to reconfigure the processor.
1298 /* stop redirects that send signals to JACK ports
1299 from causing noise as a result of no longer being
1303 boost::shared_ptr<IOProcessor> iop;
1305 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (*i)) != 0) {
1307 iop->input()->disconnect (this);
1309 if (iop->output()) {
1310 iop->output()->disconnect (this);
1314 i = _processors.erase (i);
1322 _output->set_user_latency (0);
1330 if (configure_processors_unlocked (err)) {
1331 /* get back to where we where */
1332 _processors.insert (i, processor);
1333 /* we know this will work, because it worked before :) */
1334 configure_processors_unlocked (0);
1338 _have_internal_generator = false;
1340 for (i = _processors.begin(); i != _processors.end(); ++i) {
1341 boost::shared_ptr<PluginInsert> pi;
1343 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1344 if (pi->is_generator()) {
1345 _have_internal_generator = true;
1352 processor->drop_references ();
1353 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1359 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1361 ProcessorList deleted;
1362 ProcessorList as_we_were;
1364 if (!_session.engine().connected()) {
1368 processor_max_streams.reset();
1371 Glib::RWLock::WriterLock lm (_processor_lock);
1372 ProcessorList::iterator i;
1373 boost::shared_ptr<Processor> processor;
1375 as_we_were = _processors;
1377 for (i = _processors.begin(); i != _processors.end(); ) {
1381 /* these can never be removed */
1383 if (processor == _amp || processor == _meter || processor == _main_outs) {
1388 /* see if its in the list of processors to delete */
1390 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1395 /* stop IOProcessors that send to JACK ports
1396 from causing noise as a result of no longer being
1400 boost::shared_ptr<IOProcessor> iop;
1402 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (processor)) != 0) {
1406 deleted.push_back (processor);
1407 i = _processors.erase (i);
1410 if (deleted.empty()) {
1411 /* none of those in the requested list were found */
1415 _output->set_user_latency (0);
1417 if (configure_processors_unlocked (err)) {
1418 /* get back to where we where */
1419 _processors = as_we_were;
1420 /* we know this will work, because it worked before :) */
1421 configure_processors_unlocked (0);
1425 _have_internal_generator = false;
1427 for (i = _processors.begin(); i != _processors.end(); ++i) {
1428 boost::shared_ptr<PluginInsert> pi;
1430 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1431 if (pi->is_generator()) {
1432 _have_internal_generator = true;
1439 /* now try to do what we need to so that those that were removed will be deleted */
1441 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1442 (*i)->drop_references ();
1445 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1452 Route::configure_processors (ProcessorStreams* err)
1454 if (!_in_configure_processors) {
1455 Glib::RWLock::WriterLock lm (_processor_lock);
1456 return configure_processors_unlocked (err);
1461 /** Configure the input/output configuration of each processor in the processors list.
1462 * Return 0 on success, otherwise configuration is impossible.
1465 Route::configure_processors_unlocked (ProcessorStreams* err)
1467 if (_in_configure_processors) {
1471 _in_configure_processors = true;
1473 // Check each processor in order to see if we can configure as requested
1474 ChanCount in = _input->n_ports ();
1476 list< pair<ChanCount,ChanCount> > configuration;
1479 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1481 DEBUG_TRACE (DEBUG::Processors, "{\n");
1482 for (list<boost::shared_ptr<Processor> >::const_iterator p = _processors.begin(); p != _processors.end(); ++p) {
1483 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID = %2\n", (*p)->name(), (*p)->id()));
1485 DEBUG_TRACE (DEBUG::Processors, "}\n");
1488 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1490 if ((*p)->can_support_io_configuration(in, out)) {
1491 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1in = %2 out = %3\n",(*p)->name(), in, out));
1492 configuration.push_back(make_pair(in, out));
1499 _in_configure_processors = false;
1504 // We can, so configure everything
1505 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1506 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1507 (*p)->configure_io(c->first, c->second);
1508 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1509 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1514 _meter->reset_max_channels (processor_max_streams);
1517 /* make sure we have sufficient scratch buffers to cope with the new processor
1519 _session.ensure_buffers (n_process_buffers ());
1521 _in_configure_processors = false;
1526 Route::all_processors_flip ()
1528 Glib::RWLock::ReaderLock lm (_processor_lock);
1530 if (_processors.empty()) {
1534 bool first_is_on = _processors.front()->active();
1536 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1538 (*i)->deactivate ();
1544 _session.set_dirty ();
1547 /** Set all processors with a given placement to a given active state.
1548 * @param p Placement of processors to change.
1549 * @param state New active state for those processors.
1552 Route::all_processors_active (Placement p, bool state)
1554 Glib::RWLock::ReaderLock lm (_processor_lock);
1556 if (_processors.empty()) {
1559 ProcessorList::iterator start, end;
1560 placement_range(p, start, end);
1562 bool before_amp = true;
1563 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1568 if (p == PreFader && before_amp) {
1572 (*i)->deactivate ();
1577 _session.set_dirty ();
1581 Route::processor_is_prefader (boost::shared_ptr<Processor> p)
1583 bool pre_fader = true;
1584 Glib::RWLock::ReaderLock lm (_processor_lock);
1586 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1588 /* semantic note: if p == amp, we want to return true, so test
1589 for equality before checking if this is the amp
1606 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
1608 /* "new_order" is an ordered list of processors to be positioned according to "placement".
1609 NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
1610 processors in the current actual processor list that are hidden. Any visible processors
1611 in the current list but not in "new_order" will be assumed to be deleted.
1615 Glib::RWLock::WriterLock lm (_processor_lock);
1616 ChanCount old_pms = processor_max_streams;
1617 ProcessorList::iterator oiter;
1618 ProcessorList::const_iterator niter;
1619 ProcessorList as_it_was_before = _processors;
1620 ProcessorList as_it_will_be;
1622 oiter = _processors.begin();
1623 niter = new_order.begin();
1625 while (niter != new_order.end()) {
1627 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
1628 then append it to the temp list.
1630 Otherwise, see if the next processor in the old list is in the new list. if not,
1631 its been deleted. If its there, append it to the temp list.
1634 if (oiter == _processors.end()) {
1636 /* no more elements in the old list, so just stick the rest of
1637 the new order onto the temp list.
1640 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
1641 while (niter != new_order.end()) {
1648 if (!(*oiter)->display_to_user()) {
1650 as_it_will_be.push_back (*oiter);
1654 /* visible processor: check that its in the new order */
1656 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
1657 /* deleted: do nothing, shared_ptr<> will clean up */
1659 /* ignore this one, and add the next item from the new order instead */
1660 as_it_will_be.push_back (*niter);
1665 /* now remove from old order - its taken care of no matter what */
1666 oiter = _processors.erase (oiter);
1671 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
1673 if (configure_processors_unlocked (err)) {
1674 _processors = as_it_was_before;
1675 processor_max_streams = old_pms;
1680 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1692 Route::get_template()
1694 return state(false);
1698 Route::state(bool full_state)
1700 XMLNode *node = new XMLNode("Route");
1701 ProcessorList::iterator i;
1704 id().print (buf, sizeof (buf));
1705 node->add_property("id", buf);
1706 node->add_property ("name", _name);
1707 node->add_property("default-type", _default_type.to_string());
1710 node->add_property("flags", enum_2_string (_flags));
1713 node->add_property("active", _active?"yes":"no");
1714 node->add_property("phase-invert", _phase_invert?"yes":"no");
1715 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
1716 node->add_property("meter-point", enum_2_string (_meter_point));
1719 node->add_property("route-group", _route_group->name());
1722 string order_string;
1723 OrderKeys::iterator x = order_keys.begin();
1725 while (x != order_keys.end()) {
1726 order_string += string ((*x).first);
1727 order_string += '=';
1728 snprintf (buf, sizeof(buf), "%ld", (*x).second);
1729 order_string += buf;
1733 if (x == order_keys.end()) {
1737 order_string += ':';
1739 node->add_property ("order-keys", order_string);
1740 node->add_property ("self-solo", (_self_solo ? "yes" : "no"));
1741 snprintf (buf, sizeof (buf), "%d", _soloed_by_others);
1742 node->add_property ("soloed-by-others", buf);
1744 node->add_child_nocopy (_input->state (full_state));
1745 node->add_child_nocopy (_output->state (full_state));
1746 node->add_child_nocopy (_solo_control->get_state ());
1747 node->add_child_nocopy (_mute_master->get_state ());
1749 XMLNode* remote_control_node = new XMLNode (X_("RemoteControl"));
1750 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
1751 remote_control_node->add_property (X_("id"), buf);
1752 node->add_child_nocopy (*remote_control_node);
1754 if (_comment.length()) {
1755 XMLNode *cmt = node->add_child ("Comment");
1756 cmt->add_content (_comment);
1759 for (i = _processors.begin(); i != _processors.end(); ++i) {
1760 node->add_child_nocopy((*i)->state (full_state));
1764 node->add_child_copy (*_extra_xml);
1771 Route::set_state (const XMLNode& node, int version)
1773 return _set_state (node, version, true);
1777 Route::_set_state (const XMLNode& node, int version, bool /*call_base*/)
1779 if (version < 3000) {
1780 return _set_state_2X (node, version);
1784 XMLNodeConstIterator niter;
1786 XMLPropertyList plist;
1787 const XMLProperty *prop;
1789 if (node.name() != "Route"){
1790 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
1794 if ((prop = node.property (X_("name"))) != 0) {
1795 Route::set_name (prop->value());
1798 if ((prop = node.property ("id")) != 0) {
1799 _id = prop->value ();
1802 if ((prop = node.property (X_("flags"))) != 0) {
1803 _flags = Flag (string_2_enum (prop->value(), _flags));
1808 /* add all processors (except amp, which is always present) */
1810 nlist = node.children();
1811 XMLNode processor_state (X_("processor_state"));
1813 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1817 if (child->name() == IO::state_node_name) {
1818 if ((prop = child->property (X_("direction"))) == 0) {
1822 if (prop->value() == "Input") {
1823 _input->set_state (*child, version);
1824 } else if (prop->value() == "Output") {
1825 _output->set_state (*child, version);
1829 if (child->name() == X_("Processor")) {
1830 processor_state.add_child_copy (*child);
1834 set_processor_state (processor_state);
1836 if ((prop = node.property ("self-solo")) != 0) {
1837 set_self_solo (string_is_affirmative (prop->value()));
1840 if ((prop = node.property ("soloed-by-others")) != 0) {
1841 _soloed_by_others = 0; // needed for mod_solo_by_others () to work
1842 mod_solo_by_others (atoi (prop->value()));
1845 if ((prop = node.property ("solo-isolated")) != 0) {
1846 set_solo_isolated (string_is_affirmative (prop->value()), this);
1849 if ((prop = node.property (X_("phase-invert"))) != 0) {
1850 set_phase_invert (string_is_affirmative (prop->value()));
1853 if ((prop = node.property (X_("denormal-protection"))) != 0) {
1854 set_denormal_protection (string_is_affirmative (prop->value()));
1857 if ((prop = node.property (X_("active"))) != 0) {
1858 bool yn = string_is_affirmative (prop->value());
1859 _active = !yn; // force switch
1863 if ((prop = node.property (X_("meter-point"))) != 0) {
1864 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
1866 _meter->set_display_to_user (_meter_point == MeterCustom);
1870 if ((prop = node.property (X_("order-keys"))) != 0) {
1874 string::size_type colon, equal;
1875 string remaining = prop->value();
1877 while (remaining.length()) {
1879 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
1880 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1883 if (sscanf (remaining.substr (equal+1).c_str(), "%ld", &n) != 1) {
1884 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1887 set_order_key (remaining.substr (0, equal), n);
1891 colon = remaining.find_first_of (':');
1893 if (colon != string::npos) {
1894 remaining = remaining.substr (colon+1);
1901 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1904 if (child->name() == X_("Comment")) {
1906 /* XXX this is a terrible API design in libxml++ */
1908 XMLNode *cmt = *(child->children().begin());
1909 _comment = cmt->content();
1911 } else if (child->name() == X_("Extra")) {
1913 _extra_xml = new XMLNode (*child);
1915 } else if (child->name() == X_("Controllable") && (prop = child->property("name")) != 0) {
1917 if (prop->value() == "solo") {
1918 _solo_control->set_state (*child, version);
1919 _session.add_controllable (_solo_control);
1922 } else if (child->name() == X_("RemoteControl")) {
1923 if ((prop = child->property (X_("id"))) != 0) {
1925 sscanf (prop->value().c_str(), "%d", &x);
1926 set_remote_control_id (x);
1929 } else if (child->name() == X_("MuteMaster")) {
1930 _mute_master->set_state (*child, version);
1938 Route::_set_state_2X (const XMLNode& node, int version)
1941 XMLNodeConstIterator niter;
1943 XMLPropertyList plist;
1944 const XMLProperty *prop;
1946 /* 2X things which still remain to be handled:
1949 * mute-affects-pre-fader
1950 * mute-affects-post-fader
1951 * mute-affects-control-outs
1952 * mute-affects-main-outs
1957 if (node.name() != "Route") {
1958 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
1962 if ((prop = node.property (X_("flags"))) != 0) {
1963 _flags = Flag (string_2_enum (prop->value(), _flags));
1968 /* add standard processors */
1970 _meter.reset (new PeakMeter (_session));
1971 add_processor (_meter, PreFader);
1973 if (_flags & ControlOut) {
1974 /* where we listen to tracks */
1975 _intreturn.reset (new InternalReturn (_session));
1976 add_processor (_intreturn, PreFader);
1979 _main_outs.reset (new Delivery (_session, _output, _mute_master, _name, Delivery::Main));
1980 add_processor (_main_outs, PostFader);
1984 nlist = node.children ();
1985 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1989 if (child->name() == IO::state_node_name) {
1991 /* there is a note in IO::set_state_2X() about why we have to call
1995 _input->set_state_2X (*child, version, true);
1996 _output->set_state_2X (*child, version, false);
1998 if ((prop = child->property (X_("name"))) != 0) {
1999 set_name (prop->value ());
2002 if ((prop = child->property (X_("id"))) != 0) {
2003 _id = prop->value ();
2006 if ((prop = child->property (X_("active"))) != 0) {
2007 bool yn = string_is_affirmative (prop->value());
2008 _active = !yn; // force switch
2016 if ((prop = node.property (X_("phase-invert"))) != 0) {
2017 set_phase_invert (string_is_affirmative (prop->value()));
2020 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2021 set_denormal_protection (string_is_affirmative (prop->value()));
2024 if ((prop = node.property (X_("soloed"))) != 0) {
2025 bool yn = string_is_affirmative (prop->value());
2027 /* XXX force reset of solo status */
2029 set_solo (yn, this);
2032 if ((prop = node.property (X_("meter-point"))) != 0) {
2033 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2036 /* do not carry over edit/mix groups from 2.X because (a) its hard (b) they
2037 don't mean the same thing.
2040 if ((prop = node.property (X_("order-keys"))) != 0) {
2044 string::size_type colon, equal;
2045 string remaining = prop->value();
2047 while (remaining.length()) {
2049 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2050 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2053 if (sscanf (remaining.substr (equal+1).c_str(), "%ld", &n) != 1) {
2054 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2057 set_order_key (remaining.substr (0, equal), n);
2061 colon = remaining.find_first_of (':');
2063 if (colon != string::npos) {
2064 remaining = remaining.substr (colon+1);
2071 XMLNodeList redirect_nodes;
2073 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2077 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2078 redirect_nodes.push_back(child);
2083 set_processor_state_2X (redirect_nodes, version);
2085 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2088 if (child->name() == X_("Comment")) {
2090 /* XXX this is a terrible API design in libxml++ */
2092 XMLNode *cmt = *(child->children().begin());
2093 _comment = cmt->content();
2095 } else if (child->name() == X_("Extra")) {
2097 _extra_xml = new XMLNode (*child);
2099 } else if (child->name() == X_("Controllable") && (prop = child->property("name")) != 0) {
2101 if (prop->value() == "solo") {
2102 _solo_control->set_state (*child, version);
2103 _session.add_controllable (_solo_control);
2106 } else if (child->name() == X_("RemoteControl")) {
2107 if ((prop = child->property (X_("id"))) != 0) {
2109 sscanf (prop->value().c_str(), "%d", &x);
2110 set_remote_control_id (x);
2120 Route::get_processor_state ()
2122 XMLNode* root = new XMLNode (X_("redirects"));
2123 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2124 root->add_child_nocopy ((*i)->state (true));
2131 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2133 /* We don't bother removing existing processors not in nList, as this
2134 method will only be called when creating a Route from scratch, not
2135 for undo purposes. Just put processors in at the appropriate place
2139 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2140 add_processor_from_xml_2X (**i, version, _processors.begin ());
2145 Route::set_processor_state (const XMLNode& node)
2147 const XMLNodeList &nlist = node.children();
2148 XMLNodeConstIterator niter;
2149 ProcessorList::iterator i, o;
2151 // Iterate through existing processors, remove those which are not in the state list
2153 for (i = _processors.begin(); i != _processors.end(); ) {
2155 /* leave amp alone, always */
2162 ProcessorList::iterator tmp = i;
2165 bool processorInStateList = false;
2167 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2169 XMLProperty* id_prop = (*niter)->property(X_("id"));
2171 if (id_prop && (*i)->id() == id_prop->value()) {
2172 processorInStateList = true;
2177 if (!processorInStateList) {
2178 remove_processor (*i);
2184 // Iterate through state list and make sure all processors are on the track and in the correct order,
2185 // set the state of existing processors according to the new state on the same go
2187 i = _processors.begin();
2189 for (niter = nlist.begin(); niter != nlist.end(); ++niter, ++i) {
2191 XMLProperty* prop = (*niter)->property ("type");
2195 // Check whether the next processor in the list is the right one,
2196 // except for "amp" which is always there and may not have the
2197 // old ID since it is always created anew in every Route
2199 if (prop->value() != "amp") {
2200 while (o != _processors.end()) {
2201 XMLProperty* id_prop = (*niter)->property(X_("id"));
2202 if (id_prop && (*o)->id() == id_prop->value()) {
2210 // If the processor (*niter) is not on the route,
2211 // create it and move it to the correct location
2213 if (o == _processors.end()) {
2215 if (add_processor_from_xml (**niter, i)) {
2216 --i; // move iterator to the newly inserted processor
2218 cerr << "Error restoring route: unable to restore processor" << endl;
2223 // Otherwise, the processor already exists; just
2224 // ensure it is at the location provided in the XML state
2227 boost::shared_ptr<Processor> tmp = (*o);
2228 _processors.erase (o); // remove the old copy
2229 _processors.insert (i, tmp); // insert the processor at the correct location
2230 --i; // move iterator to the correct processor
2233 // and make it (just) so
2235 (*i)->set_state (**niter, Stateful::current_state_version);
2239 /* note: there is no configure_processors() call because we figure that
2240 the XML state represents a working signal route.
2243 processors_changed (RouteProcessorChange ());
2247 Route::curve_reallocate ()
2249 // _gain_automation_curve.finish_resize ();
2250 // _pan_automation_curve.finish_resize ();
2254 Route::silence (nframes_t nframes)
2258 _output->silence (nframes);
2261 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2264 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2265 boost::shared_ptr<PluginInsert> pi;
2267 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2268 // skip plugins, they don't need anything when we're not active
2272 (*i)->silence (nframes);
2275 if (nframes == _session.get_block_size()) {
2285 Route::add_internal_return ()
2288 _intreturn.reset (new InternalReturn (_session));
2289 add_processor (_intreturn, PreFader);
2294 Route::get_return_buffer () const
2296 Glib::RWLock::ReaderLock rm (_processor_lock);
2298 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2299 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
2302 BufferSet* bs = d->get_buffers ();
2311 Route::release_return_buffer () const
2313 Glib::RWLock::ReaderLock rm (_processor_lock);
2315 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2316 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
2319 return d->release_buffers ();
2325 Route::listen_via (boost::shared_ptr<Route> route, Placement placement, bool /*active*/, bool aux)
2327 vector<string> ports;
2328 vector<string>::const_iterator i;
2331 Glib::RWLock::ReaderLock rm (_processor_lock);
2333 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
2335 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
2337 if (d && d->target_route() == route) {
2339 /* if the target is the control outs, then make sure
2340 we take note of which i-send is doing that.
2343 if (route == _session.control_out()) {
2344 _control_outs = boost::dynamic_pointer_cast<Delivery>(d);
2347 /* already listening via the specified IO: do nothing */
2354 boost::shared_ptr<InternalSend> listener;
2357 listener.reset (new InternalSend (_session, _mute_master, route, (aux ? Delivery::Aux : Delivery::Listen)));
2359 } catch (failed_constructor& err) {
2363 if (route == _session.control_out()) {
2364 _control_outs = listener;
2367 add_processor (listener, placement);
2373 Route::drop_listen (boost::shared_ptr<Route> route)
2375 ProcessorStreams err;
2376 ProcessorList::iterator tmp;
2378 Glib::RWLock::ReaderLock rl(_processor_lock);
2382 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ) {
2384 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
2386 if (d && d->target_route() == route) {
2388 remove_processor (*x, &err);
2391 /* list could have been demolished while we dropped the lock
2401 if (route == _session.control_out()) {
2402 _control_outs.reset ();
2407 Route::set_comment (string cmt, void *src)
2410 comment_changed (src);
2411 _session.set_dirty ();
2415 Route::feeds (boost::shared_ptr<Route> other, bool* only_send)
2417 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
2419 if (_output->connected_to (other->input())) {
2420 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
2429 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); r++) {
2431 boost::shared_ptr<IOProcessor> iop;
2433 if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*r)) != 0) {
2434 if (iop->feeds (other)) {
2435 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
2441 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
2444 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
2449 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
2454 Route::handle_transport_stopped (bool /*abort_ignored*/, bool did_locate, bool can_flush_processors)
2456 nframes_t now = _session.transport_frame();
2459 Glib::RWLock::ReaderLock lm (_processor_lock);
2462 automation_snapshot (now, true);
2465 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2467 if (Config->get_plugins_stop_with_transport() && can_flush_processors) {
2468 (*i)->deactivate ();
2472 (*i)->transport_stopped (now);
2476 _roll_delay = _initial_delay;
2480 Route::input_change_handler (IOChange change, void * /*src*/)
2482 if ((change & ConfigurationChanged)) {
2483 configure_processors (0);
2488 Route::output_change_handler (IOChange change, void * /*src*/)
2490 if ((change & ConfigurationChanged)) {
2492 /* XXX resize all listeners to match _main_outs? */
2494 // configure_processors (0);
2499 Route::pans_required () const
2501 if (n_outputs().n_audio() < 2) {
2505 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
2509 Route::no_roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame,
2510 bool session_state_changing, bool /*can_record*/, bool /*rec_monitors_input*/)
2512 if (n_outputs().n_total() == 0) {
2516 if (session_state_changing || !_active || n_inputs() == ChanCount::ZERO) {
2521 _amp->apply_gain_automation (false);
2522 passthru (start_frame, end_frame, nframes, 0);
2528 Route::check_initial_delay (nframes_t nframes, nframes_t& transport_frame)
2530 if (_roll_delay > nframes) {
2532 _roll_delay -= nframes;
2534 /* transport frame is not legal for caller to use */
2537 } else if (_roll_delay > 0) {
2539 nframes -= _roll_delay;
2540 silence (_roll_delay);
2541 /* we've written _roll_delay of samples into the
2542 output ports, so make a note of that for
2545 _main_outs->increment_output_offset (_roll_delay);
2546 transport_frame += _roll_delay;
2555 Route::roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame, int declick,
2556 bool /*can_record*/, bool /*rec_monitors_input*/)
2559 // automation snapshot can also be called from the non-rt context
2560 // and it uses the processor list, so we try to acquire the lock here
2561 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2564 automation_snapshot (_session.transport_frame(), false);
2568 if (n_outputs().n_total() == 0) {
2572 if (!_active || n_inputs().n_total() == 0) {
2577 nframes_t unused = 0;
2579 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
2585 passthru (start_frame, end_frame, nframes, declick);
2591 Route::silent_roll (nframes_t nframes, sframes_t /*start_frame*/, sframes_t /*end_frame*/,
2592 bool /*can_record*/, bool /*rec_monitors_input*/)
2599 Route::toggle_monitor_input ()
2601 for (PortSet::iterator i = _input->ports().begin(); i != _input->ports().end(); ++i) {
2602 i->ensure_monitor_input( ! i->monitoring_input());
2607 Route::has_external_redirects () const
2609 // FIXME: what about sends? - they don't return a signal back to ardour?
2611 boost::shared_ptr<const PortInsert> pi;
2613 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2615 if ((pi = boost::dynamic_pointer_cast<const PortInsert>(*i)) != 0) {
2617 for (PortSet::const_iterator port = pi->output()->ports().begin(); port != pi->output()->ports().end(); ++port) {
2619 string port_name = port->name();
2620 string client_name = port_name.substr (0, port_name.find(':'));
2622 /* only say "yes" if the redirect is actually in use */
2624 if (client_name != "ardour" && pi->active()) {
2635 Route::flush_processors ()
2637 /* XXX shouldn't really try to take this lock, since
2638 this is called from the RT audio thread.
2641 Glib::RWLock::ReaderLock lm (_processor_lock);
2643 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2644 (*i)->deactivate ();
2650 Route::set_meter_point (MeterPoint p, void *src)
2652 /* CAN BE CALLED FROM PROCESS CONTEXT */
2654 if (_meter_point == p) {
2658 bool meter_was_visible_to_user = _meter->display_to_user ();
2661 Glib::RWLock::WriterLock lm (_processor_lock);
2663 if (p != MeterCustom) {
2664 // Move meter in the processors list to reflect the new position
2665 ProcessorList::iterator loc = find (_processors.begin(), _processors.end(), _meter);
2666 _processors.erase(loc);
2669 loc = _processors.begin();
2672 loc = find (_processors.begin(), _processors.end(), _amp);
2674 case MeterPostFader:
2675 loc = _processors.end();
2683 if (loc == _processors.begin()) {
2684 m_in = _input->n_ports();
2686 ProcessorList::iterator before = loc;
2688 m_in = (*before)->output_streams ();
2691 _meter->reflect_inputs (m_in);
2693 _processors.insert (loc, _meter);
2695 /* we do not need to reconfigure the processors, because the meter
2696 (a) is always ready to handle processor_max_streams
2697 (b) is always an N-in/N-out processor, and thus moving
2698 it doesn't require any changes to the other processors.
2701 _meter->set_display_to_user (false);
2705 // just make it visible and let the user move it
2707 _meter->set_display_to_user (true);
2712 meter_change (src); /* EMIT SIGNAL */
2714 bool const meter_visibly_changed = (_meter->display_to_user() != meter_was_visible_to_user);
2716 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, meter_visibly_changed)); /* EMIT SIGNAL */
2720 Route::put_control_outs_at (Placement p)
2722 if (!_control_outs) {
2727 Glib::RWLock::WriterLock lm (_processor_lock);
2728 ProcessorList as_it_was (_processors);
2729 // Move meter in the processors list
2730 ProcessorList::iterator loc = find(_processors.begin(), _processors.end(), _control_outs);
2731 _processors.erase(loc);
2735 loc = find(_processors.begin(), _processors.end(), _amp);
2736 if (loc != _processors.begin()) {
2741 loc = find(_processors.begin(), _processors.end(), _amp);
2742 assert (loc != _processors.end());
2747 _processors.insert(loc, _control_outs);
2749 if (configure_processors_unlocked (0)) {
2750 _processors = as_it_was;
2751 configure_processors_unlocked (0); // it worked before we tried to add it ...
2756 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2757 _session.set_dirty ();
2761 Route::update_total_latency ()
2763 nframes_t old = _output->effective_latency();
2764 nframes_t own_latency = _output->user_latency();
2766 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2767 if ((*i)->active ()) {
2768 own_latency += (*i)->signal_latency ();
2772 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal redirect latency = %2\n", _name, own_latency));
2774 _output->set_port_latency (own_latency);
2776 if (_output->user_latency() == 0) {
2778 /* this (virtual) function is used for pure Routes,
2779 not derived classes like AudioTrack. this means
2780 that the data processed here comes from an input
2781 port, not prerecorded material, and therefore we
2782 have to take into account any input latency.
2785 own_latency += _input->signal_latency ();
2788 if (old != own_latency) {
2789 _output->set_latency_delay (own_latency);
2790 signal_latency_changed (); /* EMIT SIGNAL */
2793 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: input latency = %2 total = %3\n", _name, _input->signal_latency(), own_latency));
2795 return _output->effective_latency ();
2799 Route::set_user_latency (nframes_t nframes)
2801 _output->set_user_latency (nframes);
2802 _session.update_latency_compensation (false, false);
2806 Route::set_latency_delay (nframes_t longest_session_latency)
2808 nframes_t old = _initial_delay;
2810 if (_output->effective_latency() < longest_session_latency) {
2811 _initial_delay = longest_session_latency - _output->effective_latency();
2816 if (_initial_delay != old) {
2817 initial_delay_changed (); /* EMIT SIGNAL */
2820 if (_session.transport_stopped()) {
2821 _roll_delay = _initial_delay;
2826 Route::automation_snapshot (nframes_t now, bool force)
2828 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2829 (*i)->automation_snapshot (now, force);
2833 Route::SoloControllable::SoloControllable (std::string name, Route& r)
2834 : AutomationControl (r.session(), Evoral::Parameter (SoloAutomation),
2835 boost::shared_ptr<AutomationList>(), name)
2838 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(SoloAutomation)));
2843 Route::SoloControllable::set_value (float val)
2845 bool bval = ((val >= 0.5f) ? true: false);
2847 route.set_solo (bval, this);
2851 Route::SoloControllable::get_value (void) const
2853 return route.self_soloed() ? 1.0f : 0.0f;
2857 Route::set_block_size (nframes_t nframes)
2859 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2860 (*i)->set_block_size (nframes);
2863 _session.ensure_buffers (n_process_buffers ());
2867 Route::protect_automation ()
2869 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
2870 (*i)->protect_automation();
2874 Route::set_pending_declick (int declick)
2877 /* this call is not allowed to turn off a pending declick unless "force" is true */
2879 _pending_declick = declick;
2881 // cerr << _name << ": after setting to " << declick << " pending declick = " << _pending_declick << endl;
2883 _pending_declick = 0;
2888 /** Shift automation forwards from a particular place, thereby inserting time.
2889 * Adds undo commands for any shifts that are performed.
2891 * @param pos Position to start shifting from.
2892 * @param frames Amount to shift forwards by.
2896 Route::shift (nframes64_t /*pos*/, nframes64_t /*frames*/)
2898 #ifdef THIS_NEEDS_FIXING_FOR_V3
2900 /* gain automation */
2901 XMLNode &before = _gain_control->get_state ();
2902 _gain_control->shift (pos, frames);
2903 XMLNode &after = _gain_control->get_state ();
2904 _session.add_command (new MementoCommand<AutomationList> (_gain_automation_curve, &before, &after));
2906 /* pan automation */
2907 for (std::vector<StreamPanner*>::iterator i = _panner->begin (); i != _panner->end (); ++i) {
2908 Curve & c = (*i)->automation ();
2909 XMLNode &before = c.get_state ();
2910 c.shift (pos, frames);
2911 XMLNode &after = c.get_state ();
2912 _session.add_command (new MementoCommand<AutomationList> (c, &before, &after));
2915 /* redirect automation */
2917 Glib::RWLock::ReaderLock lm (redirect_lock);
2918 for (RedirectList::iterator i = _redirects.begin (); i != _redirects.end (); ++i) {
2921 (*i)->what_has_automation (a);
2923 for (set<uint32_t>::const_iterator j = a.begin (); j != a.end (); ++j) {
2924 AutomationList & al = (*i)->automation_list (*j);
2925 XMLNode &before = al.get_state ();
2926 al.shift (pos, frames);
2927 XMLNode &after = al.get_state ();
2928 _session.add_command (new MementoCommand<AutomationList> (al, &before, &after));
2938 Route::save_as_template (const string& path, const string& name)
2940 XMLNode& node (state (false));
2943 IO::set_name_in_state (*node.children().front(), name);
2945 tree.set_root (&node);
2946 return tree.write (path.c_str());
2951 Route::set_name (const string& str)
2957 name = Route::ensure_track_or_route_name (str, _session);
2958 SessionObject::set_name (name);
2960 ret = (_input->set_name(name) && _output->set_name(name));
2964 Glib::RWLock::ReaderLock lm (_processor_lock);
2966 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2968 /* rename all I/O processors that have inputs or outputs */
2970 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor> (*i);
2972 if (iop && (iop->output() || iop->input())) {
2973 if (!iop->set_name (name)) {
2984 boost::shared_ptr<Send>
2985 Route::internal_send_for (boost::shared_ptr<const Route> target) const
2987 Glib::RWLock::ReaderLock lm (_processor_lock);
2989 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2990 boost::shared_ptr<InternalSend> send;
2992 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
2993 if (send->target_route() == target) {
2999 return boost::shared_ptr<Send>();
3003 Route::set_phase_invert (bool yn)
3005 if (_phase_invert != yn) {
3006 _phase_invert = 0xffff; // XXX all channels
3007 phase_invert_changed (); /* EMIT SIGNAL */
3012 Route::phase_invert () const
3014 return _phase_invert != 0;
3018 Route::set_denormal_protection (bool yn)
3020 if (_denormal_protection != yn) {
3021 _denormal_protection = yn;
3022 denormal_protection_changed (); /* EMIT SIGNAL */
3027 Route::denormal_protection () const
3029 return _denormal_protection;
3033 Route::set_active (bool yn)
3035 if (_active != yn) {
3037 _input->set_active (yn);
3038 _output->set_active (yn);
3039 active_changed (); // EMIT SIGNAL
3046 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
3052 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3054 boost::shared_ptr<Send> s;
3055 boost::shared_ptr<Return> r;
3057 if ((s = boost::dynamic_pointer_cast<Send> (*i)) != 0) {
3058 s->meter()->meter();
3059 } else if ((r = boost::dynamic_pointer_cast<Return> (*i)) != 0) {
3060 r->meter()->meter ();
3065 boost::shared_ptr<Panner>
3066 Route::panner() const
3069 return _main_outs->panner();
3072 boost::shared_ptr<AutomationControl>
3073 Route::gain_control() const
3076 return _amp->gain_control();
3079 boost::shared_ptr<AutomationControl>
3080 Route::get_control (const Evoral::Parameter& param)
3082 /* either we own the control or .... */
3084 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(data().control (param));
3088 /* maybe one of our processors does or ... */
3090 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
3091 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3092 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->data().control (param))) != 0) {
3100 /* nobody does so we'll make a new one */
3102 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));