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 (_meter_point == MeterCustom);
84 add_processor (_meter, PreFader);
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;
121 _solo_isolated = false;
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;
141 _denormal_protection = false;
143 /* add standard controls */
145 add_control (_solo_control);
146 add_control (_mute_master);
148 /* input and output objects */
150 _input.reset (new IO (_session, _name, IO::Input, _default_type));
151 _output.reset (new IO (_session, _name, IO::Output, _default_type));
153 _input->changed.connect (mem_fun (this, &Route::input_change_handler));
154 _output->changed.connect (mem_fun (this, &Route::output_change_handler));
156 /* add amp processor */
158 _amp.reset (new Amp (_session, _mute_master));
159 add_processor (_amp, PostFader);
164 DEBUG_TRACE (DEBUG::Destruction, string_compose ("route %1 destructor\n", _name));
165 Metering::disconnect (_meter_connection);
167 /* don't use clear_processors here, as it depends on the session which may
168 be half-destroyed by now */
170 Glib::RWLock::WriterLock lm (_processor_lock);
171 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
172 (*i)->drop_references ();
175 _processors.clear ();
179 Route::set_remote_control_id (uint32_t id)
181 if (id != _remote_control_id) {
182 _remote_control_id = id;
183 RemoteControlIDChanged ();
188 Route::remote_control_id() const
190 return _remote_control_id;
194 Route::order_key (std::string const & name) const
196 OrderKeys::const_iterator i = order_keys.find (name);
197 if (i == order_keys.end()) {
205 Route::set_order_key (std::string const & name, long n)
207 order_keys[name] = n;
209 if (Config->get_sync_all_route_ordering()) {
210 for (OrderKeys::iterator x = order_keys.begin(); x != order_keys.end(); ++x) {
215 _session.set_dirty ();
218 /** Set all order keys to be the same as that for `base', if such a key
219 * exists in this route.
220 * @param base Base key.
223 Route::sync_order_keys (std::string const & base)
225 if (order_keys.empty()) {
229 OrderKeys::iterator i;
232 if ((i = order_keys.find (base)) == order_keys.end()) {
233 /* key doesn't exist, use the first existing key (during session initialization) */
234 i = order_keys.begin();
238 /* key exists - use it and reset all others (actually, itself included) */
240 i = order_keys.begin();
243 for (; i != order_keys.end(); ++i) {
249 Route::ensure_track_or_route_name(string name, Session &session)
251 string newname = name;
253 while (session.route_by_name (newname) != NULL) {
254 newname = bump_name_once (newname);
262 Route::inc_gain (gain_t fraction, void *src)
264 _amp->inc_gain (fraction, src);
268 Route::set_gain (gain_t val, void *src)
270 if (src != 0 && _route_group && src != _route_group && _route_group->active_property (RouteGroup::Gain)) {
272 if (_route_group->is_relative()) {
274 gain_t usable_gain = _amp->gain();
275 if (usable_gain < 0.000001f) {
276 usable_gain = 0.000001f;
280 if (delta < 0.000001f) {
284 delta -= usable_gain;
289 gain_t factor = delta / usable_gain;
292 factor = _route_group->get_max_factor(factor);
293 if (factor == 0.0f) {
294 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
298 factor = _route_group->get_min_factor(factor);
299 if (factor == 0.0f) {
300 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
305 _route_group->apply (&Route::inc_gain, factor, _route_group);
309 _route_group->apply (&Route::set_gain, val, _route_group);
315 if (val == _amp->gain()) {
319 _amp->set_gain (val, src);
322 /** Process this route for one (sub) cycle (process thread)
324 * @param bufs Scratch buffers to use for the signal path
325 * @param start_frame Initial transport frame
326 * @param end_frame Final transport frame
327 * @param nframes Number of frames to output (to ports)
329 * Note that (end_frame - start_frame) may not be equal to nframes when the
330 * transport speed isn't 1.0 (eg varispeed).
333 Route::process_output_buffers (BufferSet& bufs,
334 sframes_t start_frame, sframes_t end_frame, nframes_t nframes,
335 bool /*with_processors*/, int declick)
339 bufs.is_silent (false);
341 switch (Config->get_monitoring_model()) {
342 case HardwareMonitoring:
343 case ExternalMonitoring:
344 monitor = !record_enabled() || (_session.config.get_auto_input() && !_session.actively_recording());
351 declick = _pending_declick;
354 /* figure out if we're going to use gain automation */
355 _amp->setup_gain_automation (start_frame, end_frame, nframes);
358 /* tell main outs what to do about monitoring */
359 _main_outs->no_outs_cuz_we_no_monitor (!monitor);
362 /* -------------------------------------------------------------------------------------------
363 GLOBAL DECLICK (for transport changes etc.)
364 ----------------------------------------------------------------------------------------- */
367 Amp::apply_gain (bufs, nframes, 0.0, 1.0);
368 } else if (declick < 0) {
369 Amp::apply_gain (bufs, nframes, 1.0, 0.0);
372 _pending_declick = 0;
374 /* -------------------------------------------------------------------------------------------
375 DENORMAL CONTROL/PHASE INVERT
376 ----------------------------------------------------------------------------------------- */
382 if (_denormal_protection || Config->get_denormal_protection()) {
384 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
385 Sample* const sp = i->data();
387 if (_phase_invert & chn) {
388 for (nframes_t nx = 0; nx < nframes; ++nx) {
393 for (nframes_t nx = 0; nx < nframes; ++nx) {
401 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
402 Sample* const sp = i->data();
404 if (_phase_invert & chn) {
405 for (nframes_t nx = 0; nx < nframes; ++nx) {
414 if (_denormal_protection || Config->get_denormal_protection()) {
416 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
417 Sample* const sp = i->data();
418 for (nframes_t nx = 0; nx < nframes; ++nx) {
426 /* -------------------------------------------------------------------------------------------
428 ----------------------------------------------------------------------------------------- */
430 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
433 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
435 if (bufs.count() != (*i)->input_streams()) {
436 cerr << _name << " bufs = " << bufs.count()
437 << " input for " << (*i)->name() << " = " << (*i)->input_streams()
440 assert (bufs.count() == (*i)->input_streams());
442 (*i)->run (bufs, start_frame, end_frame, nframes, *i != _processors.back());
443 bufs.set_count (ChanCount::max(bufs.count(), (*i)->output_streams()));
446 if (!_processors.empty()) {
447 bufs.set_count (ChanCount::max (bufs.count(), _processors.back()->output_streams()));
453 Route::n_process_buffers ()
455 return max (_input->n_ports(), processor_max_streams);
459 Route::passthru (sframes_t start_frame, sframes_t end_frame, nframes_t nframes, int declick)
461 BufferSet& bufs = _session.get_scratch_buffers (n_process_buffers());
465 assert (bufs.available() >= _input->n_ports());
467 if (_input->n_ports() == ChanCount::ZERO) {
471 bufs.set_count (_input->n_ports());
473 if (is_control() && _session.listening()) {
475 /* control/monitor bus ignores input ports when something is
476 feeding the listen "stream". data will "arrive" into the
477 route from the intreturn processor element.
480 bufs.silence (nframes, 0);
484 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
486 BufferSet::iterator o = bufs.begin(*t);
487 PortSet& ports (_input->ports());
489 for (PortSet::iterator i = ports.begin(*t); i != ports.end(*t); ++i, ++o) {
490 o->read_from (i->get_buffer(nframes), nframes);
495 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
496 process_output_buffers (bufs, start_frame, end_frame, nframes, true, declick);
500 Route::passthru_silence (sframes_t start_frame, sframes_t end_frame, nframes_t nframes, int declick)
502 BufferSet& bufs (_session.get_silent_buffers (n_process_buffers()));
503 bufs.set_count (_input->n_ports());
504 write_out_of_band_data (bufs, start_frame, end_frame, nframes);
505 process_output_buffers (bufs, start_frame, end_frame, nframes, true, declick);
509 Route::set_listen (bool yn, void* src)
512 if (yn != _control_outs->active()) {
514 _control_outs->activate ();
516 _control_outs->deactivate ();
519 listen_changed (src); /* EMIT SIGNAL */
525 Route::listening () const
528 return _control_outs->active ();
535 Route::set_solo_safe (bool yn, void *src)
537 if (_solo_safe != yn) {
539 solo_safe_changed (src);
544 Route::solo_safe() const
550 Route::set_solo (bool yn, void *src)
556 if (_route_group && src != _route_group && _route_group->active_property (RouteGroup::Solo)) {
557 _route_group->apply (&Route::set_solo, yn, _route_group);
561 if (self_soloed() != yn) {
563 set_delivery_solo ();
564 solo_changed (src); /* EMIT SIGNAL */
565 _solo_control->Changed (); /* EMIT SIGNAL */
570 Route::set_self_solo (bool yn)
576 Route::mod_solo_by_others (int32_t delta)
579 if (_soloed_by_others >= (uint32_t) delta) {
580 _soloed_by_others += delta;
582 _soloed_by_others = 0;
585 _soloed_by_others += delta;
588 set_delivery_solo ();
592 Route::set_delivery_solo ()
594 /* tell all delivery processors what the solo situation is, so that they keep
595 delivering even though Session::soloing() is true and they were not
599 Glib::RWLock::ReaderLock rm (_processor_lock);
600 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
601 boost::shared_ptr<Delivery> d;
603 if ((d = boost::dynamic_pointer_cast<Delivery> (*i)) != 0) {
604 d->set_solo_level (soloed ());
605 d->set_solo_isolated (solo_isolated());
611 Route::set_solo_isolated (bool yn, void *src)
613 if (_route_group && src != _route_group && _route_group->active_property (RouteGroup::Solo)) {
614 _route_group->apply (&Route::set_solo_isolated, yn, _route_group);
618 if (yn != _solo_isolated) {
620 set_delivery_solo ();
621 solo_isolated_changed (src);
626 Route::solo_isolated () const
628 return _solo_isolated;
632 Route::set_mute_points (MuteMaster::MutePoint mp)
635 mute_points_changed (); /* EMIT SIGNAL */
637 if (_mute_master->muted()) {
638 _mute_master->mute_at (_mute_points);
639 mute_changed (this); /* EMIT SIGNAL */
644 Route::set_mute (bool yn, void *src)
646 if (_route_group && src != _route_group && _route_group->active_property (RouteGroup::Mute)) {
647 _route_group->apply (&Route::set_mute, yn, _route_group);
653 _mute_master->mute_at (_mute_points);
655 _mute_master->clear_mute ();
658 mute_changed (src); /* EMIT SIGNAL */
665 return _mute_master->muted ();
670 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
672 cerr << name << " {" << endl;
673 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
674 p != procs.end(); ++p) {
675 cerr << "\t" << (*p)->name() << " ID = " << (*p)->id() << endl;
682 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err)
684 ProcessorList::iterator loc;
686 /* XXX this is not thread safe - we don't hold the lock across determining the iter
687 to add before and actually doing the insertion. dammit.
690 if (placement == PreFader) {
691 /* generic pre-fader: insert immediately before the amp */
692 loc = find (_processors.begin(), _processors.end(), _amp);
694 /* generic post-fader: insert right before the main outs */
695 loc = find (_processors.begin(), _processors.end(), _main_outs);
698 return add_processor (processor, loc, err);
702 /** Add a processor to the route.
703 * If @a iter is not NULL, it must point to an iterator in _processors and the new
704 * processor will be inserted immediately before this location. Otherwise,
705 * @a position is used.
708 Route::add_processor (boost::shared_ptr<Processor> processor, ProcessorList::iterator iter, ProcessorStreams* err)
710 ChanCount old_pms = processor_max_streams;
712 if (!_session.engine().connected() || !processor) {
717 Glib::RWLock::WriterLock lm (_processor_lock);
719 boost::shared_ptr<PluginInsert> pi;
720 boost::shared_ptr<PortInsert> porti;
722 ProcessorList::iterator loc = find(_processors.begin(), _processors.end(), processor);
724 if (processor == _amp || processor == _meter || processor == _main_outs) {
725 // Ensure only one of these are in the list at any time
726 if (loc != _processors.end()) {
727 if (iter == loc) { // Already in place, do nothing
729 } else { // New position given, relocate
730 _processors.erase (loc);
735 if (loc != _processors.end()) {
736 cerr << "ERROR: Processor added to route twice!" << endl;
743 _processors.insert (loc, processor);
745 // Set up processor list channels. This will set processor->[input|output]_streams(),
746 // configure redirect ports properly, etc.
748 if (configure_processors_unlocked (err)) {
749 ProcessorList::iterator ploc = loc;
751 _processors.erase(ploc);
752 configure_processors_unlocked (0); // it worked before we tried to add it ...
753 cerr << "configure failed\n";
757 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
759 if (pi->natural_input_streams() == ChanCount::ZERO) {
760 /* generator plugin */
761 _have_internal_generator = true;
766 if (_control_outs != processor) {
767 // XXX: do we want to emit the signal here ? change call order.
768 processor->activate ();
770 processor->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
772 _output->set_user_latency (0);
775 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
781 Route::add_processor_from_xml (const XMLNode& node, ProcessorList::iterator iter)
783 const XMLProperty *prop;
785 if (node.name() != "Processor") {
790 if ((prop = node.property ("type")) != 0) {
792 boost::shared_ptr<Processor> processor;
794 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
795 prop->value() == "lv2" ||
796 prop->value() == "vst" ||
797 prop->value() == "audiounit") {
799 processor.reset (new PluginInsert(_session, node));
801 } else if (prop->value() == "port") {
803 processor.reset (new PortInsert (_session, _mute_master, node));
805 } else if (prop->value() == "send") {
807 processor.reset (new Send (_session, _mute_master, node));
809 } else if (prop->value() == "meter") {
812 if (_meter->set_state (node, Stateful::loading_state_version)) {
819 _meter.reset (new PeakMeter (_session, node));
820 _meter->set_display_to_user (_meter_point == MeterCustom);
823 } else if (prop->value() == "amp") {
825 /* amp always exists */
828 if (processor->set_state (node, Stateful::loading_state_version)) {
831 /* never any reason to add it */
835 } else if (prop->value() == "intsend") {
837 processor.reset (new InternalSend (_session, _mute_master, node));
839 } else if (prop->value() == "intreturn") {
842 if (_intreturn->set_state (node, Stateful::loading_state_version)) {
848 _intreturn.reset (new InternalReturn (_session, node));
849 processor = _intreturn;
851 } else if (prop->value() == "main-outs") {
854 if (_main_outs->set_state (node, Stateful::loading_state_version)) {
861 _main_outs.reset (new Delivery (_session, _output, _mute_master, node));
862 processor = _main_outs;
865 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
869 if (iter == _processors.end() && processor->display_to_user() && !_processors.empty()) {
870 /* check for invisible processors stacked at the end and leave them there */
871 ProcessorList::iterator p;
872 p = _processors.end();
874 while (!(*p)->display_to_user() && p != _processors.begin()) {
881 return (add_processor (processor, iter) == 0);
884 error << _("Processor XML node has no type property") << endmsg;
889 catch (failed_constructor &err) {
890 warning << _("processor could not be created. Ignored.") << endmsg;
897 Route::add_processor_from_xml_2X (const XMLNode& node, int version, ProcessorList::iterator iter)
899 const XMLProperty *prop;
902 boost::shared_ptr<Processor> processor;
904 if (node.name() == "Insert") {
906 if ((prop = node.property ("type")) != 0) {
908 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
909 prop->value() == "lv2" ||
910 prop->value() == "vst" ||
911 prop->value() == "audiounit") {
913 processor.reset (new PluginInsert (_session, node));
917 processor.reset (new PortInsert (_session, _mute_master, node));
922 } else if (node.name() == "Send") {
924 processor.reset (new Send (_session, _mute_master, node, version));
928 error << string_compose(_("unknown Processor type \"%1\"; ignored"), node.name()) << endmsg;
932 if (iter == _processors.end() && processor->display_to_user() && !_processors.empty()) {
933 /* check for invisible processors stacked at the end and leave them there */
934 ProcessorList::iterator p;
935 p = _processors.end();
937 while (!(*p)->display_to_user() && p != _processors.begin()) {
944 return (add_processor (processor, iter) == 0);
947 catch (failed_constructor &err) {
948 warning << _("processor could not be created. Ignored.") << endmsg;
954 Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
956 ProcessorList::iterator loc;
959 loc = find(_processors.begin(), _processors.end(), before);
961 /* nothing specified - at end but before main outs */
962 loc = find (_processors.begin(), _processors.end(), _main_outs);
965 return add_processors (others, loc, err);
969 Route::add_processors (const ProcessorList& others, ProcessorList::iterator iter, ProcessorStreams* err)
971 /* NOTE: this is intended to be used ONLY when copying
972 processors from another Route. Hence the subtle
973 differences between this and ::add_processor()
976 ChanCount old_pms = processor_max_streams;
978 if (!_session.engine().connected()) {
982 if (others.empty()) {
987 Glib::RWLock::WriterLock lm (_processor_lock);
989 ChanCount potential_max_streams = ChanCount::max (_input->n_ports(), _output->n_ports());
991 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
993 // Ensure meter only appears in the list once
995 ProcessorList::iterator m = find(_processors.begin(), _processors.end(), *i);
996 if (m != _processors.end()) {
997 _processors.erase(m);
1001 boost::shared_ptr<PluginInsert> pi;
1003 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1006 ChanCount m = max (pi->input_streams(), pi->output_streams());
1008 if (m > potential_max_streams) {
1009 potential_max_streams = m;
1013 ProcessorList::iterator inserted = _processors.insert (iter, *i);
1015 if ((*i)->active()) {
1019 if (configure_processors_unlocked (err)) {
1020 _processors.erase (inserted);
1021 configure_processors_unlocked (0); // it worked before we tried to add it ...
1025 (*i)->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
1028 _output->set_user_latency (0);
1031 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1037 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
1039 if (p == PreFader) {
1040 start = _processors.begin();
1041 end = find(_processors.begin(), _processors.end(), _amp);
1043 start = find(_processors.begin(), _processors.end(), _amp);
1045 end = _processors.end();
1049 /** Turn off all processors with a given placement
1050 * @param p Placement of processors to disable
1053 Route::disable_processors (Placement p)
1055 Glib::RWLock::ReaderLock lm (_processor_lock);
1057 ProcessorList::iterator start, end;
1058 placement_range(p, start, end);
1060 for (ProcessorList::iterator i = start; i != end; ++i) {
1061 (*i)->deactivate ();
1064 _session.set_dirty ();
1067 /** Turn off all redirects
1070 Route::disable_processors ()
1072 Glib::RWLock::ReaderLock lm (_processor_lock);
1074 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1075 (*i)->deactivate ();
1078 _session.set_dirty ();
1081 /** Turn off all redirects with a given placement
1082 * @param p Placement of redirects to disable
1085 Route::disable_plugins (Placement p)
1087 Glib::RWLock::ReaderLock lm (_processor_lock);
1089 ProcessorList::iterator start, end;
1090 placement_range(p, start, end);
1092 for (ProcessorList::iterator i = start; i != end; ++i) {
1093 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1094 (*i)->deactivate ();
1098 _session.set_dirty ();
1101 /** Turn off all plugins
1104 Route::disable_plugins ()
1106 Glib::RWLock::ReaderLock lm (_processor_lock);
1108 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1109 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1110 (*i)->deactivate ();
1114 _session.set_dirty ();
1119 Route::ab_plugins (bool forward)
1121 Glib::RWLock::ReaderLock lm (_processor_lock);
1125 /* forward = turn off all active redirects, and mark them so that the next time
1126 we go the other way, we will revert them
1129 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1130 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1134 if ((*i)->active()) {
1135 (*i)->deactivate ();
1136 (*i)->set_next_ab_is_active (true);
1138 (*i)->set_next_ab_is_active (false);
1144 /* backward = if the redirect was marked to go active on the next ab, do so */
1146 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1148 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1152 if ((*i)->get_next_ab_is_active()) {
1155 (*i)->deactivate ();
1160 _session.set_dirty ();
1164 /** Remove processors with a given placement.
1165 * @param p Placement of processors to remove.
1168 Route::clear_processors (Placement p)
1170 const ChanCount old_pms = processor_max_streams;
1172 if (!_session.engine().connected()) {
1176 bool already_deleting = _session.deletion_in_progress();
1177 if (!already_deleting) {
1178 _session.set_deletion_in_progress();
1182 Glib::RWLock::WriterLock lm (_processor_lock);
1183 ProcessorList new_list;
1184 ProcessorStreams err;
1185 bool seen_amp = false;
1187 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1193 if ((*i) == _amp || (*i) == _meter || (*i) == _main_outs) {
1195 /* you can't remove these */
1197 new_list.push_back (*i);
1204 new_list.push_back (*i);
1207 (*i)->drop_references ();
1215 (*i)->drop_references ();
1218 new_list.push_back (*i);
1225 _processors = new_list;
1226 configure_processors_unlocked (&err); // this can't fail
1229 processor_max_streams.reset();
1230 _have_internal_generator = false;
1231 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1233 if (!already_deleting) {
1234 _session.clear_deletion_in_progress();
1239 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err)
1241 /* these can never be removed */
1243 if (processor == _amp || processor == _meter || processor == _main_outs) {
1247 ChanCount old_pms = processor_max_streams;
1249 if (!_session.engine().connected()) {
1253 processor_max_streams.reset();
1256 Glib::RWLock::WriterLock lm (_processor_lock);
1257 ProcessorList::iterator i;
1258 bool removed = false;
1260 for (i = _processors.begin(); i != _processors.end(); ) {
1261 if (*i == processor) {
1263 /* move along, see failure case for configure_processors()
1264 where we may need to reconfigure the processor.
1267 /* stop redirects that send signals to JACK ports
1268 from causing noise as a result of no longer being
1272 boost::shared_ptr<IOProcessor> iop;
1274 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (*i)) != 0) {
1276 iop->input()->disconnect (this);
1278 if (iop->output()) {
1279 iop->output()->disconnect (this);
1283 i = _processors.erase (i);
1291 _output->set_user_latency (0);
1299 if (configure_processors_unlocked (err)) {
1300 /* get back to where we where */
1301 _processors.insert (i, processor);
1302 /* we know this will work, because it worked before :) */
1303 configure_processors_unlocked (0);
1307 _have_internal_generator = false;
1309 for (i = _processors.begin(); i != _processors.end(); ++i) {
1310 boost::shared_ptr<PluginInsert> pi;
1312 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1313 if (pi->is_generator()) {
1314 _have_internal_generator = true;
1321 processor->drop_references ();
1322 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1328 Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err)
1330 ProcessorList deleted;
1331 ProcessorList as_we_were;
1333 if (!_session.engine().connected()) {
1337 processor_max_streams.reset();
1340 Glib::RWLock::WriterLock lm (_processor_lock);
1341 ProcessorList::iterator i;
1342 boost::shared_ptr<Processor> processor;
1344 as_we_were = _processors;
1346 for (i = _processors.begin(); i != _processors.end(); ) {
1350 /* these can never be removed */
1352 if (processor == _amp || processor == _meter || processor == _main_outs) {
1357 /* see if its in the list of processors to delete */
1359 if (find (to_be_deleted.begin(), to_be_deleted.end(), processor) == to_be_deleted.end()) {
1364 /* stop IOProcessors that send to JACK ports
1365 from causing noise as a result of no longer being
1369 boost::shared_ptr<IOProcessor> iop;
1371 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (processor)) != 0) {
1375 deleted.push_back (processor);
1376 i = _processors.erase (i);
1379 if (deleted.empty()) {
1380 /* none of those in the requested list were found */
1384 _output->set_user_latency (0);
1386 if (configure_processors_unlocked (err)) {
1387 /* get back to where we where */
1388 _processors = as_we_were;
1389 /* we know this will work, because it worked before :) */
1390 configure_processors_unlocked (0);
1394 _have_internal_generator = false;
1396 for (i = _processors.begin(); i != _processors.end(); ++i) {
1397 boost::shared_ptr<PluginInsert> pi;
1399 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1400 if (pi->is_generator()) {
1401 _have_internal_generator = true;
1408 /* now try to do what we need to so that those that were removed will be deleted */
1410 for (ProcessorList::iterator i = deleted.begin(); i != deleted.end(); ++i) {
1411 (*i)->drop_references ();
1414 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1421 Route::configure_processors (ProcessorStreams* err)
1423 if (!_in_configure_processors) {
1424 Glib::RWLock::WriterLock lm (_processor_lock);
1425 return configure_processors_unlocked (err);
1430 /** Configure the input/output configuration of each processor in the processors list.
1431 * Return 0 on success, otherwise configuration is impossible.
1434 Route::configure_processors_unlocked (ProcessorStreams* err)
1436 if (_in_configure_processors) {
1440 _in_configure_processors = true;
1442 // Check each processor in order to see if we can configure as requested
1443 ChanCount in = _input->n_ports ();
1445 list< pair<ChanCount,ChanCount> > configuration;
1448 DEBUG_TRACE (DEBUG::Processors, string_compose ("%1: configure processors\n", _name));
1450 DEBUG_TRACE (DEBUG::Processors, "{\n");
1451 for (list<boost::shared_ptr<Processor> >::const_iterator p = _processors.begin(); p != _processors.end(); ++p) {
1452 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1 ID = %2\n", (*p)->name(), (*p)->id()));
1454 DEBUG_TRACE (DEBUG::Processors, "}\n");
1457 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1459 if ((*p)->can_support_io_configuration(in, out)) {
1460 DEBUG_TRACE (DEBUG::Processors, string_compose ("\t%1in = %2 out = %3\n",(*p)->name(), in, out));
1461 configuration.push_back(make_pair(in, out));
1468 _in_configure_processors = false;
1473 // We can, so configure everything
1474 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1475 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1476 (*p)->configure_io(c->first, c->second);
1477 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1478 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1482 /* make sure we have sufficient scratch buffers to cope with the new processor
1484 _session.ensure_buffers (n_process_buffers ());
1486 _in_configure_processors = false;
1491 Route::all_processors_flip ()
1493 Glib::RWLock::ReaderLock lm (_processor_lock);
1495 if (_processors.empty()) {
1499 bool first_is_on = _processors.front()->active();
1501 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1503 (*i)->deactivate ();
1509 _session.set_dirty ();
1512 /** Set all processors with a given placement to a given active state.
1513 * @param p Placement of processors to change.
1514 * @param state New active state for those processors.
1517 Route::all_processors_active (Placement p, bool state)
1519 Glib::RWLock::ReaderLock lm (_processor_lock);
1521 if (_processors.empty()) {
1524 ProcessorList::iterator start, end;
1525 placement_range(p, start, end);
1527 bool before_amp = true;
1528 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1533 if (p == PreFader && before_amp) {
1537 (*i)->deactivate ();
1542 _session.set_dirty ();
1546 Route::processor_is_prefader (boost::shared_ptr<Processor> p)
1548 bool pre_fader = true;
1549 Glib::RWLock::ReaderLock lm (_processor_lock);
1551 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1553 /* semantic note: if p == amp, we want to return true, so test
1554 for equality before checking if this is the amp
1571 Route::reorder_processors (const ProcessorList& new_order, ProcessorStreams* err)
1573 /* "new_order" is an ordered list of processors to be positioned according to "placement".
1574 NOTE: all processors in "new_order" MUST be marked as display_to_user(). There maybe additional
1575 processors in the current actual processor list that are hidden. Any visible processors
1576 in the current list but not in "new_order" will be assumed to be deleted.
1580 Glib::RWLock::WriterLock lm (_processor_lock);
1581 ChanCount old_pms = processor_max_streams;
1582 ProcessorList::iterator oiter;
1583 ProcessorList::const_iterator niter;
1584 ProcessorList as_it_was_before = _processors;
1585 ProcessorList as_it_will_be;
1587 oiter = _processors.begin();
1588 niter = new_order.begin();
1590 while (niter != new_order.end()) {
1592 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
1593 then append it to the temp list.
1595 Otherwise, see if the next processor in the old list is in the new list. if not,
1596 its been deleted. If its there, append it to the temp list.
1599 if (oiter == _processors.end()) {
1601 /* no more elements in the old list, so just stick the rest of
1602 the new order onto the temp list.
1605 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
1606 while (niter != new_order.end()) {
1613 if (!(*oiter)->display_to_user()) {
1615 as_it_will_be.push_back (*oiter);
1619 /* visible processor: check that its in the new order */
1621 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
1622 /* deleted: do nothing, shared_ptr<> will clean up */
1624 /* ignore this one, and add the next item from the new order instead */
1625 as_it_will_be.push_back (*niter);
1630 /* now remove from old order - its taken care of no matter what */
1631 oiter = _processors.erase (oiter);
1636 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
1638 if (configure_processors_unlocked (err)) {
1639 _processors = as_it_was_before;
1640 processor_max_streams = old_pms;
1645 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
1657 Route::get_template()
1659 return state(false);
1663 Route::state(bool full_state)
1665 XMLNode *node = new XMLNode("Route");
1666 ProcessorList::iterator i;
1669 id().print (buf, sizeof (buf));
1670 node->add_property("id", buf);
1671 node->add_property ("name", _name);
1672 node->add_property("default-type", _default_type.to_string());
1675 node->add_property("flags", enum_2_string (_flags));
1678 node->add_property("active", _active?"yes":"no");
1679 node->add_property("phase-invert", _phase_invert?"yes":"no");
1680 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
1681 node->add_property("meter-point", enum_2_string (_meter_point));
1684 node->add_property("route-group", _route_group->name());
1687 string order_string;
1688 OrderKeys::iterator x = order_keys.begin();
1690 while (x != order_keys.end()) {
1691 order_string += string ((*x).first);
1692 order_string += '=';
1693 snprintf (buf, sizeof(buf), "%ld", (*x).second);
1694 order_string += buf;
1698 if (x == order_keys.end()) {
1702 order_string += ':';
1704 node->add_property ("order-keys", order_string);
1705 node->add_property ("self-solo", (_self_solo ? "yes" : "no"));
1706 snprintf (buf, sizeof (buf), "%d", _soloed_by_others);
1707 node->add_property ("soloed-by-others", buf);
1709 node->add_child_nocopy (_input->state (full_state));
1710 node->add_child_nocopy (_output->state (full_state));
1711 node->add_child_nocopy (_solo_control->get_state ());
1712 node->add_child_nocopy (_mute_master->get_state ());
1714 XMLNode* remote_control_node = new XMLNode (X_("RemoteControl"));
1715 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
1716 remote_control_node->add_property (X_("id"), buf);
1717 node->add_child_nocopy (*remote_control_node);
1719 if (_comment.length()) {
1720 XMLNode *cmt = node->add_child ("Comment");
1721 cmt->add_content (_comment);
1724 for (i = _processors.begin(); i != _processors.end(); ++i) {
1725 node->add_child_nocopy((*i)->state (full_state));
1729 node->add_child_copy (*_extra_xml);
1736 Route::set_state (const XMLNode& node, int version)
1738 return _set_state (node, version, true);
1742 Route::_set_state (const XMLNode& node, int version, bool /*call_base*/)
1744 if (version < 3000) {
1745 return _set_state_2X (node, version);
1749 XMLNodeConstIterator niter;
1751 XMLPropertyList plist;
1752 const XMLProperty *prop;
1754 if (node.name() != "Route"){
1755 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
1759 if ((prop = node.property (X_("name"))) != 0) {
1760 Route::set_name (prop->value());
1763 if ((prop = node.property ("id")) != 0) {
1764 _id = prop->value ();
1767 if ((prop = node.property (X_("flags"))) != 0) {
1768 _flags = Flag (string_2_enum (prop->value(), _flags));
1773 /* add all processors (except amp, which is always present) */
1775 nlist = node.children();
1776 XMLNode processor_state (X_("processor_state"));
1778 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1782 if (child->name() == IO::state_node_name) {
1783 if ((prop = child->property (X_("direction"))) == 0) {
1787 if (prop->value() == "Input") {
1788 _input->set_state (*child, version);
1789 } else if (prop->value() == "Output") {
1790 _output->set_state (*child, version);
1794 if (child->name() == X_("Processor")) {
1795 processor_state.add_child_copy (*child);
1799 set_processor_state (processor_state);
1801 if ((prop = node.property ("self-solo")) != 0) {
1802 set_self_solo (string_is_affirmative (prop->value()));
1805 if ((prop = node.property ("soloed-by-others")) != 0) {
1806 _soloed_by_others = 0; // needed for mod_solo_by_others () to work
1807 mod_solo_by_others (atoi (prop->value()));
1810 if ((prop = node.property ("solo-isolated")) != 0) {
1811 set_solo_isolated (string_is_affirmative (prop->value()), this);
1814 if ((prop = node.property (X_("phase-invert"))) != 0) {
1815 set_phase_invert (string_is_affirmative (prop->value()));
1818 if ((prop = node.property (X_("denormal-protection"))) != 0) {
1819 set_denormal_protection (string_is_affirmative (prop->value()));
1822 if ((prop = node.property (X_("active"))) != 0) {
1823 bool yn = string_is_affirmative (prop->value());
1824 _active = !yn; // force switch
1828 if ((prop = node.property (X_("meter-point"))) != 0) {
1829 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
1831 _meter->set_display_to_user (_meter_point == MeterCustom);
1835 if ((prop = node.property (X_("route-group"))) != 0) {
1836 RouteGroup* route_group = _session.route_group_by_name(prop->value());
1837 if (route_group == 0) {
1838 error << string_compose(_("Route %1: unknown route group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
1840 set_route_group (route_group, this);
1844 if ((prop = node.property (X_("order-keys"))) != 0) {
1848 string::size_type colon, equal;
1849 string remaining = prop->value();
1851 while (remaining.length()) {
1853 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
1854 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1857 if (sscanf (remaining.substr (equal+1).c_str(), "%ld", &n) != 1) {
1858 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1861 set_order_key (remaining.substr (0, equal), n);
1865 colon = remaining.find_first_of (':');
1867 if (colon != string::npos) {
1868 remaining = remaining.substr (colon+1);
1875 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1878 if (child->name() == X_("Comment")) {
1880 /* XXX this is a terrible API design in libxml++ */
1882 XMLNode *cmt = *(child->children().begin());
1883 _comment = cmt->content();
1885 } else if (child->name() == X_("Extra")) {
1887 _extra_xml = new XMLNode (*child);
1889 } else if (child->name() == X_("Controllable") && (prop = child->property("name")) != 0) {
1891 if (prop->value() == "solo") {
1892 _solo_control->set_state (*child, version);
1893 _session.add_controllable (_solo_control);
1896 } else if (child->name() == X_("RemoteControl")) {
1897 if ((prop = child->property (X_("id"))) != 0) {
1899 sscanf (prop->value().c_str(), "%d", &x);
1900 set_remote_control_id (x);
1903 } else if (child->name() == X_("MuteMaster")) {
1904 _mute_master->set_state (*child, version);
1912 Route::_set_state_2X (const XMLNode& node, int version)
1915 XMLNodeConstIterator niter;
1917 XMLPropertyList plist;
1918 const XMLProperty *prop;
1920 /* 2X things which still remain to be handled:
1923 * mute-affects-pre-fader
1924 * mute-affects-post-fader
1925 * mute-affects-control-outs
1926 * mute-affects-main-outs
1931 if (node.name() != "Route") {
1932 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
1936 if ((prop = node.property (X_("flags"))) != 0) {
1937 _flags = Flag (string_2_enum (prop->value(), _flags));
1942 /* add standard processors */
1944 _meter.reset (new PeakMeter (_session));
1945 add_processor (_meter, PreFader);
1947 if (_flags & ControlOut) {
1948 /* where we listen to tracks */
1949 _intreturn.reset (new InternalReturn (_session));
1950 add_processor (_intreturn, PreFader);
1953 _main_outs.reset (new Delivery (_session, _output, _mute_master, _name, Delivery::Main));
1954 add_processor (_main_outs, PostFader);
1958 nlist = node.children ();
1959 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1963 if (child->name() == IO::state_node_name) {
1965 /* there is a note in IO::set_state_2X() about why we have to call
1969 _input->set_state_2X (*child, version, true);
1970 _output->set_state_2X (*child, version, false);
1972 if ((prop = child->property (X_("name"))) != 0) {
1973 set_name (prop->value ());
1976 if ((prop = child->property (X_("id"))) != 0) {
1977 _id = prop->value ();
1980 if ((prop = child->property (X_("active"))) != 0) {
1981 bool yn = string_is_affirmative (prop->value());
1982 _active = !yn; // force switch
1990 if ((prop = node.property (X_("phase-invert"))) != 0) {
1991 set_phase_invert (string_is_affirmative (prop->value()));
1994 if ((prop = node.property (X_("denormal-protection"))) != 0) {
1995 set_denormal_protection (string_is_affirmative (prop->value()));
1998 if ((prop = node.property (X_("soloed"))) != 0) {
1999 bool yn = string_is_affirmative (prop->value());
2001 /* XXX force reset of solo status */
2003 set_solo (yn, this);
2006 if ((prop = node.property (X_("meter-point"))) != 0) {
2007 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2010 /* XXX: if the route was in both a mix group and an edit group, it'll end up
2011 just in the edit group. */
2013 if ((prop = node.property (X_("mix-group"))) != 0) {
2014 RouteGroup* route_group = _session.route_group_by_name(prop->value());
2015 if (route_group == 0) {
2016 error << string_compose(_("Route %1: unknown route group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
2018 set_route_group (route_group, this);
2022 if ((prop = node.property (X_("edit-group"))) != 0) {
2023 RouteGroup* route_group = _session.route_group_by_name(prop->value());
2024 if (route_group == 0) {
2025 error << string_compose(_("Route %1: unknown route group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
2027 set_route_group (route_group, this);
2031 if ((prop = node.property (X_("order-keys"))) != 0) {
2035 string::size_type colon, equal;
2036 string remaining = prop->value();
2038 while (remaining.length()) {
2040 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2041 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2044 if (sscanf (remaining.substr (equal+1).c_str(), "%ld", &n) != 1) {
2045 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2048 set_order_key (remaining.substr (0, equal), n);
2052 colon = remaining.find_first_of (':');
2054 if (colon != string::npos) {
2055 remaining = remaining.substr (colon+1);
2062 XMLNodeList redirect_nodes;
2064 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2068 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
2069 redirect_nodes.push_back(child);
2074 set_processor_state_2X (redirect_nodes, version);
2076 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2079 if (child->name() == X_("Comment")) {
2081 /* XXX this is a terrible API design in libxml++ */
2083 XMLNode *cmt = *(child->children().begin());
2084 _comment = cmt->content();
2086 } else if (child->name() == X_("Extra")) {
2088 _extra_xml = new XMLNode (*child);
2090 } else if (child->name() == X_("Controllable") && (prop = child->property("name")) != 0) {
2092 if (prop->value() == "solo") {
2093 _solo_control->set_state (*child, version);
2094 _session.add_controllable (_solo_control);
2097 } else if (child->name() == X_("RemoteControl")) {
2098 if ((prop = child->property (X_("id"))) != 0) {
2100 sscanf (prop->value().c_str(), "%d", &x);
2101 set_remote_control_id (x);
2111 Route::get_processor_state ()
2113 XMLNode* root = new XMLNode (X_("redirects"));
2114 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2115 root->add_child_nocopy ((*i)->state (true));
2122 Route::set_processor_state_2X (XMLNodeList const & nList, int version)
2124 /* We don't bother removing existing processors not in nList, as this
2125 method will only be called when creating a Route from scratch, not
2126 for undo purposes. Just put processors in at the appropriate place
2130 for (XMLNodeConstIterator i = nList.begin(); i != nList.end(); ++i) {
2131 add_processor_from_xml_2X (**i, version, _processors.begin ());
2136 Route::set_processor_state (const XMLNode& node)
2138 const XMLNodeList &nlist = node.children();
2139 XMLNodeConstIterator niter;
2140 ProcessorList::iterator i, o;
2142 // Iterate through existing processors, remove those which are not in the state list
2144 for (i = _processors.begin(); i != _processors.end(); ) {
2146 /* leave amp alone, always */
2153 ProcessorList::iterator tmp = i;
2156 bool processorInStateList = false;
2158 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2160 XMLProperty* id_prop = (*niter)->property(X_("id"));
2162 if (id_prop && (*i)->id() == id_prop->value()) {
2163 processorInStateList = true;
2168 if (!processorInStateList) {
2169 remove_processor (*i);
2175 // Iterate through state list and make sure all processors are on the track and in the correct order,
2176 // set the state of existing processors according to the new state on the same go
2178 i = _processors.begin();
2180 for (niter = nlist.begin(); niter != nlist.end(); ++niter, ++i) {
2182 XMLProperty* prop = (*niter)->property ("type");
2186 // Check whether the next processor in the list is the right one,
2187 // except for "amp" which is always there and may not have the
2188 // old ID since it is always created anew in every Route
2190 if (prop->value() != "amp") {
2191 while (o != _processors.end()) {
2192 XMLProperty* id_prop = (*niter)->property(X_("id"));
2193 if (id_prop && (*o)->id() == id_prop->value()) {
2201 // If the processor (*niter) is not on the route,
2202 // create it and move it to the correct location
2204 if (o == _processors.end()) {
2206 if (add_processor_from_xml (**niter, i)) {
2207 --i; // move iterator to the newly inserted processor
2209 cerr << "Error restoring route: unable to restore processor" << endl;
2214 // Otherwise, the processor already exists; just
2215 // ensure it is at the location provided in the XML state
2218 boost::shared_ptr<Processor> tmp = (*o);
2219 _processors.erase (o); // remove the old copy
2220 _processors.insert (i, tmp); // insert the processor at the correct location
2221 --i; // move iterator to the correct processor
2224 // and make it (just) so
2226 (*i)->set_state (**niter, Stateful::current_state_version);
2230 /* note: there is no configure_processors() call because we figure that
2231 the XML state represents a working signal route.
2234 processors_changed (RouteProcessorChange ());
2238 Route::curve_reallocate ()
2240 // _gain_automation_curve.finish_resize ();
2241 // _pan_automation_curve.finish_resize ();
2245 Route::silence (nframes_t nframes)
2249 _output->silence (nframes);
2252 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2255 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2256 boost::shared_ptr<PluginInsert> pi;
2258 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2259 // skip plugins, they don't need anything when we're not active
2263 (*i)->silence (nframes);
2266 if (nframes == _session.get_block_size()) {
2276 Route::add_internal_return ()
2279 _intreturn.reset (new InternalReturn (_session));
2280 add_processor (_intreturn, PreFader);
2285 Route::get_return_buffer () const
2287 Glib::RWLock::ReaderLock rm (_processor_lock);
2289 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2290 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
2293 BufferSet* bs = d->get_buffers ();
2302 Route::release_return_buffer () const
2304 Glib::RWLock::ReaderLock rm (_processor_lock);
2306 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2307 boost::shared_ptr<InternalReturn> d = boost::dynamic_pointer_cast<InternalReturn>(*x);
2310 return d->release_buffers ();
2316 Route::listen_via (boost::shared_ptr<Route> route, Placement placement, bool /*active*/, bool aux)
2318 vector<string> ports;
2319 vector<string>::const_iterator i;
2322 Glib::RWLock::ReaderLock rm (_processor_lock);
2324 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ++x) {
2326 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
2328 if (d && d->target_route() == route) {
2330 /* if the target is the control outs, then make sure
2331 we take note of which i-send is doing that.
2334 if (route == _session.control_out()) {
2335 _control_outs = boost::dynamic_pointer_cast<Delivery>(d);
2338 /* already listening via the specified IO: do nothing */
2345 boost::shared_ptr<InternalSend> listener;
2348 listener.reset (new InternalSend (_session, _mute_master, route, (aux ? Delivery::Aux : Delivery::Listen)));
2350 } catch (failed_constructor& err) {
2354 if (route == _session.control_out()) {
2355 _control_outs = listener;
2358 add_processor (listener, placement);
2364 Route::drop_listen (boost::shared_ptr<Route> route)
2366 ProcessorStreams err;
2367 ProcessorList::iterator tmp;
2369 Glib::RWLock::ReaderLock rl(_processor_lock);
2373 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ) {
2375 boost::shared_ptr<InternalSend> d = boost::dynamic_pointer_cast<InternalSend>(*x);
2377 if (d && d->target_route() == route) {
2379 remove_processor (*x, &err);
2382 /* list could have been demolished while we dropped the lock
2392 if (route == _session.control_out()) {
2393 _control_outs.reset ();
2398 Route::set_route_group (RouteGroup *rg, void *src)
2400 if (rg == _route_group) {
2405 _route_group->remove (this);
2408 if ((_route_group = rg) != 0) {
2409 _route_group->add (this);
2412 _session.set_dirty ();
2413 route_group_changed (src); /* EMIT SIGNAL */
2417 Route::drop_route_group (void *src)
2420 _session.set_dirty ();
2421 route_group_changed (src); /* EMIT SIGNAL */
2425 Route::set_comment (string cmt, void *src)
2428 comment_changed (src);
2429 _session.set_dirty ();
2433 Route::feeds (boost::shared_ptr<Route> other, bool* only_send)
2435 DEBUG_TRACE (DEBUG::Graph, string_compose ("Feeds? %1\n", _name));
2437 if (_output->connected_to (other->input())) {
2438 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdirect FEEDS %2\n", other->name()));
2447 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); r++) {
2449 boost::shared_ptr<IOProcessor> iop;
2451 if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*r)) != 0) {
2452 if (iop->feeds (other)) {
2453 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does feed %2\n", iop->name(), other->name()));
2459 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tIOP %1 does NOT feed %2\n", iop->name(), other->name()));
2462 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tPROC %1 is not an IOP\n", (*r)->name()));
2467 DEBUG_TRACE (DEBUG::Graph, string_compose ("\tdoes NOT feed %1\n", other->name()));
2472 Route::handle_transport_stopped (bool /*abort_ignored*/, bool did_locate, bool can_flush_processors)
2474 nframes_t now = _session.transport_frame();
2477 Glib::RWLock::ReaderLock lm (_processor_lock);
2480 automation_snapshot (now, true);
2483 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2485 if (Config->get_plugins_stop_with_transport() && can_flush_processors) {
2486 (*i)->deactivate ();
2490 (*i)->transport_stopped (now);
2494 _roll_delay = _initial_delay;
2498 Route::input_change_handler (IOChange change, void * /*src*/)
2500 if ((change & ConfigurationChanged)) {
2501 configure_processors (0);
2506 Route::output_change_handler (IOChange change, void * /*src*/)
2508 if ((change & ConfigurationChanged)) {
2510 /* XXX resize all listeners to match _main_outs? */
2512 // configure_processors (0);
2517 Route::pans_required () const
2519 if (n_outputs().n_audio() < 2) {
2523 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
2527 Route::no_roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame,
2528 bool session_state_changing, bool /*can_record*/, bool /*rec_monitors_input*/)
2530 if (n_outputs().n_total() == 0) {
2534 if (session_state_changing || !_active || n_inputs() == ChanCount::ZERO) {
2539 _amp->apply_gain_automation (false);
2540 passthru (start_frame, end_frame, nframes, 0);
2546 Route::check_initial_delay (nframes_t nframes, nframes_t& transport_frame)
2548 if (_roll_delay > nframes) {
2550 _roll_delay -= nframes;
2552 /* transport frame is not legal for caller to use */
2555 } else if (_roll_delay > 0) {
2557 nframes -= _roll_delay;
2558 silence (_roll_delay);
2559 /* we've written _roll_delay of samples into the
2560 output ports, so make a note of that for
2563 _main_outs->increment_output_offset (_roll_delay);
2564 transport_frame += _roll_delay;
2573 Route::roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame, int declick,
2574 bool /*can_record*/, bool /*rec_monitors_input*/)
2577 // automation snapshot can also be called from the non-rt context
2578 // and it uses the processor list, so we try to acquire the lock here
2579 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2582 automation_snapshot (_session.transport_frame(), false);
2586 if (n_outputs().n_total() == 0) {
2590 if (!_active || n_inputs().n_total() == 0) {
2595 nframes_t unused = 0;
2597 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
2603 passthru (start_frame, end_frame, nframes, declick);
2609 Route::silent_roll (nframes_t nframes, sframes_t /*start_frame*/, sframes_t /*end_frame*/,
2610 bool /*can_record*/, bool /*rec_monitors_input*/)
2617 Route::toggle_monitor_input ()
2619 for (PortSet::iterator i = _input->ports().begin(); i != _input->ports().end(); ++i) {
2620 i->ensure_monitor_input( ! i->monitoring_input());
2625 Route::has_external_redirects () const
2627 // FIXME: what about sends? - they don't return a signal back to ardour?
2629 boost::shared_ptr<const PortInsert> pi;
2631 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2633 if ((pi = boost::dynamic_pointer_cast<const PortInsert>(*i)) != 0) {
2635 for (PortSet::const_iterator port = pi->output()->ports().begin(); port != pi->output()->ports().end(); ++port) {
2637 string port_name = port->name();
2638 string client_name = port_name.substr (0, port_name.find(':'));
2640 /* only say "yes" if the redirect is actually in use */
2642 if (client_name != "ardour" && pi->active()) {
2653 Route::flush_processors ()
2655 /* XXX shouldn't really try to take this lock, since
2656 this is called from the RT audio thread.
2659 Glib::RWLock::ReaderLock lm (_processor_lock);
2661 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2662 (*i)->deactivate ();
2668 Route::set_meter_point (MeterPoint p, void *src)
2670 if (_meter_point == p) {
2674 bool meter_was_visible_to_user = _meter->display_to_user ();
2677 Glib::RWLock::WriterLock lm (_processor_lock);
2678 ProcessorList as_it_was (_processors);
2680 if (p != MeterCustom) {
2681 // Move meter in the processors list to reflect the new position
2682 ProcessorList::iterator loc = find(_processors.begin(), _processors.end(), _meter);
2683 _processors.erase(loc);
2686 loc = _processors.begin();
2689 loc = find(_processors.begin(), _processors.end(), _amp);
2691 case MeterPostFader:
2692 loc = _processors.end();
2698 _processors.insert(loc, _meter);
2700 if (configure_processors_unlocked (0)) {
2701 _processors = as_it_was;
2702 configure_processors_unlocked (0); // it worked before we tried to add it ...
2706 _meter->set_display_to_user (false);
2710 // just make it visible and let the user move it
2712 _meter->set_display_to_user (true);
2718 meter_change (src); /* EMIT SIGNAL */
2720 /* the meter has visibly changed if it is not visible to the user, or if it was and now isn't */
2721 bool const meter_visibly_changed = _meter->display_to_user() || meter_was_visible_to_user;
2723 processors_changed (RouteProcessorChange (RouteProcessorChange::MeterPointChange, meter_visibly_changed)); /* EMIT SIGNAL */
2725 _session.set_dirty ();
2729 Route::put_control_outs_at (Placement p)
2731 if (!_control_outs) {
2736 Glib::RWLock::WriterLock lm (_processor_lock);
2737 ProcessorList as_it_was (_processors);
2738 // Move meter in the processors list
2739 ProcessorList::iterator loc = find(_processors.begin(), _processors.end(), _control_outs);
2740 _processors.erase(loc);
2744 loc = find(_processors.begin(), _processors.end(), _amp);
2745 if (loc != _processors.begin()) {
2750 loc = find(_processors.begin(), _processors.end(), _amp);
2751 assert (loc != _processors.end());
2756 _processors.insert(loc, _control_outs);
2758 if (configure_processors_unlocked (0)) {
2759 _processors = as_it_was;
2760 configure_processors_unlocked (0); // it worked before we tried to add it ...
2765 processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
2766 _session.set_dirty ();
2770 Route::update_total_latency ()
2772 nframes_t old = _output->effective_latency();
2773 nframes_t own_latency = _output->user_latency();
2775 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2776 if ((*i)->active ()) {
2777 own_latency += (*i)->signal_latency ();
2781 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: internal redirect latency = %2\n", _name, own_latency));
2783 _output->set_port_latency (own_latency);
2785 if (_output->user_latency() == 0) {
2787 /* this (virtual) function is used for pure Routes,
2788 not derived classes like AudioTrack. this means
2789 that the data processed here comes from an input
2790 port, not prerecorded material, and therefore we
2791 have to take into account any input latency.
2794 own_latency += _input->signal_latency ();
2797 if (old != own_latency) {
2798 _output->set_latency_delay (own_latency);
2799 signal_latency_changed (); /* EMIT SIGNAL */
2802 DEBUG_TRACE (DEBUG::Latency, string_compose ("%1: input latency = %2 total = %3\n", _name, _input->signal_latency(), own_latency));
2804 return _output->effective_latency ();
2808 Route::set_user_latency (nframes_t nframes)
2810 _output->set_user_latency (nframes);
2811 _session.update_latency_compensation (false, false);
2815 Route::set_latency_delay (nframes_t longest_session_latency)
2817 nframes_t old = _initial_delay;
2819 if (_output->effective_latency() < longest_session_latency) {
2820 _initial_delay = longest_session_latency - _output->effective_latency();
2825 if (_initial_delay != old) {
2826 initial_delay_changed (); /* EMIT SIGNAL */
2829 if (_session.transport_stopped()) {
2830 _roll_delay = _initial_delay;
2835 Route::automation_snapshot (nframes_t now, bool force)
2837 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2838 (*i)->automation_snapshot (now, force);
2842 Route::SoloControllable::SoloControllable (std::string name, Route& r)
2843 : AutomationControl (r.session(), Evoral::Parameter (SoloAutomation),
2844 boost::shared_ptr<AutomationList>(), name)
2847 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(SoloAutomation)));
2852 Route::SoloControllable::set_value (float val)
2854 bool bval = ((val >= 0.5f) ? true: false);
2856 route.set_solo (bval, this);
2860 Route::SoloControllable::get_value (void) const
2862 return route.self_soloed() ? 1.0f : 0.0f;
2866 Route::set_block_size (nframes_t nframes)
2868 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2869 (*i)->set_block_size (nframes);
2872 _session.ensure_buffers (n_process_buffers ());
2876 Route::protect_automation ()
2878 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
2879 (*i)->protect_automation();
2883 Route::set_pending_declick (int declick)
2886 /* this call is not allowed to turn off a pending declick unless "force" is true */
2888 _pending_declick = declick;
2890 // cerr << _name << ": after setting to " << declick << " pending declick = " << _pending_declick << endl;
2892 _pending_declick = 0;
2897 /** Shift automation forwards from a particular place, thereby inserting time.
2898 * Adds undo commands for any shifts that are performed.
2900 * @param pos Position to start shifting from.
2901 * @param frames Amount to shift forwards by.
2905 Route::shift (nframes64_t /*pos*/, nframes64_t /*frames*/)
2907 #ifdef THIS_NEEDS_FIXING_FOR_V3
2909 /* gain automation */
2910 XMLNode &before = _gain_control->get_state ();
2911 _gain_control->shift (pos, frames);
2912 XMLNode &after = _gain_control->get_state ();
2913 _session.add_command (new MementoCommand<AutomationList> (_gain_automation_curve, &before, &after));
2915 /* pan automation */
2916 for (std::vector<StreamPanner*>::iterator i = _panner->begin (); i != _panner->end (); ++i) {
2917 Curve & c = (*i)->automation ();
2918 XMLNode &before = c.get_state ();
2919 c.shift (pos, frames);
2920 XMLNode &after = c.get_state ();
2921 _session.add_command (new MementoCommand<AutomationList> (c, &before, &after));
2924 /* redirect automation */
2926 Glib::RWLock::ReaderLock lm (redirect_lock);
2927 for (RedirectList::iterator i = _redirects.begin (); i != _redirects.end (); ++i) {
2930 (*i)->what_has_automation (a);
2932 for (set<uint32_t>::const_iterator j = a.begin (); j != a.end (); ++j) {
2933 AutomationList & al = (*i)->automation_list (*j);
2934 XMLNode &before = al.get_state ();
2935 al.shift (pos, frames);
2936 XMLNode &after = al.get_state ();
2937 _session.add_command (new MementoCommand<AutomationList> (al, &before, &after));
2947 Route::save_as_template (const string& path, const string& name)
2949 XMLNode& node (state (false));
2952 IO::set_name_in_state (*node.children().front(), name);
2954 tree.set_root (&node);
2955 return tree.write (path.c_str());
2960 Route::set_name (const string& str)
2966 name = Route::ensure_track_or_route_name (str, _session);
2967 SessionObject::set_name (name);
2969 ret = (_input->set_name(name) && _output->set_name(name));
2973 Glib::RWLock::ReaderLock lm (_processor_lock);
2975 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2977 /* rename all I/O processors that have inputs or outputs */
2979 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor> (*i);
2981 if (iop && (iop->output() || iop->input())) {
2982 if (!iop->set_name (name)) {
2993 boost::shared_ptr<Send>
2994 Route::internal_send_for (boost::shared_ptr<const Route> target) const
2996 Glib::RWLock::ReaderLock lm (_processor_lock);
2998 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2999 boost::shared_ptr<InternalSend> send;
3001 if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
3002 if (send->target_route() == target) {
3008 return boost::shared_ptr<Send>();
3012 Route::set_phase_invert (bool yn)
3014 if (_phase_invert != yn) {
3015 _phase_invert = 0xffff; // XXX all channels
3016 phase_invert_changed (); /* EMIT SIGNAL */
3021 Route::phase_invert () const
3023 return _phase_invert != 0;
3027 Route::set_denormal_protection (bool yn)
3029 if (_denormal_protection != yn) {
3030 _denormal_protection = yn;
3031 denormal_protection_changed (); /* EMIT SIGNAL */
3036 Route::denormal_protection () const
3038 return _denormal_protection;
3042 Route::set_active (bool yn)
3044 if (_active != yn) {
3046 _input->set_active (yn);
3047 _output->set_active (yn);
3048 active_changed (); // EMIT SIGNAL
3055 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
3061 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3063 boost::shared_ptr<Send> s;
3064 boost::shared_ptr<Return> r;
3066 if ((s = boost::dynamic_pointer_cast<Send> (*i)) != 0) {
3067 s->meter()->meter();
3068 } else if ((r = boost::dynamic_pointer_cast<Return> (*i)) != 0) {
3069 r->meter()->meter ();
3074 boost::shared_ptr<Panner>
3075 Route::panner() const
3078 return _main_outs->panner();
3081 boost::shared_ptr<AutomationControl>
3082 Route::gain_control() const
3085 return _amp->gain_control();
3088 boost::shared_ptr<AutomationControl>
3089 Route::get_control (const Evoral::Parameter& param)
3091 /* either we own the control or .... */
3093 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(data().control (param));
3097 /* maybe one of our processors does or ... */
3099 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
3100 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3101 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->data().control (param))) != 0) {
3109 /* nobody does so we'll make a new one */
3111 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));