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/stacktrace.h"
29 #include "pbd/memento_command.h"
31 #include "evoral/Curve.hpp"
33 #include "ardour/amp.h"
34 #include "ardour/audio_port.h"
35 #include "ardour/audioengine.h"
36 #include "ardour/buffer.h"
37 #include "ardour/buffer_set.h"
38 #include "ardour/configuration.h"
39 #include "ardour/cycle_timer.h"
40 #include "ardour/dB.h"
41 #include "ardour/ladspa_plugin.h"
42 #include "ardour/meter.h"
43 #include "ardour/mix.h"
44 #include "ardour/panner.h"
45 #include "ardour/plugin_insert.h"
46 #include "ardour/port.h"
47 #include "ardour/port_insert.h"
48 #include "ardour/processor.h"
49 #include "ardour/profile.h"
50 #include "ardour/route.h"
51 #include "ardour/route_group.h"
52 #include "ardour/send.h"
53 #include "ardour/session.h"
54 #include "ardour/timestamps.h"
55 #include "ardour/utils.h"
60 using namespace ARDOUR;
63 uint32_t Route::order_key_cnt = 0;
64 sigc::signal<void,const char*> Route::SyncOrderKeys;
66 Route::Route (Session& sess, string name, Flag flg, DataType default_type)
67 : IO (sess, name, default_type)
69 , _solo_control (new ToggleControllable (X_("solo"), *this, ToggleControllable::SoloControl))
70 , _mute_control (new ToggleControllable (X_("mute"), *this, ToggleControllable::MuteControl))
76 Route::Route (Session& sess, const XMLNode& node, DataType default_type)
77 : IO (sess, *node.child ("IO"), default_type)
78 , _solo_control (new ToggleControllable (X_("solo"), *this, ToggleControllable::SoloControl))
79 , _mute_control (new ToggleControllable (X_("mute"), *this, ToggleControllable::MuteControl))
82 _set_state (node, false);
88 processor_max_streams.reset();
94 _phase_invert = false;
95 _denormal_protection = false;
96 order_keys[strdup (N_("signal"))] = order_key_cnt++;
98 _meter_point = MeterPostFader;
103 _have_internal_generator = false;
104 _declickable = false;
105 _pending_declick = true;
106 _remote_control_id = 0;
107 _in_configure_processors = false;
112 _mute_affects_pre_fader = Config->get_mute_affects_pre_fader();
113 _mute_affects_post_fader = Config->get_mute_affects_post_fader();
114 _mute_affects_control_outs = Config->get_mute_affects_control_outs();
115 _mute_affects_main_outs = Config->get_mute_affects_main_outs();
118 desired_solo_gain = 1.0;
120 desired_mute_gain = 1.0;
122 input_changed.connect (mem_fun (this, &Route::input_change_handler));
123 output_changed.connect (mem_fun (this, &Route::output_change_handler));
125 /* add standard processors: amp, meter, main outs */
127 /* amp & meter belong to IO but need to be added to our processor list */
129 add_processor (_amp, PostFader);
130 add_processor (_meter, PreFader);
132 _main_outs.reset (new Delivery (_session, this, _name, Delivery::Main));
133 add_processor (_main_outs, PostFader);
138 clear_processors (PreFader);
139 clear_processors (PostFader);
141 for (OrderKeys::iterator i = order_keys.begin(); i != order_keys.end(); ++i) {
142 free ((void*)(i->first));
147 Route::set_remote_control_id (uint32_t id)
149 if (id != _remote_control_id) {
150 _remote_control_id = id;
151 RemoteControlIDChanged ();
156 Route::remote_control_id() const
158 return _remote_control_id;
162 Route::order_key (const char* name) const
164 OrderKeys::const_iterator i;
166 for (i = order_keys.begin(); i != order_keys.end(); ++i) {
167 if (!strcmp (name, i->first)) {
176 Route::set_order_key (const char* name, long n)
178 order_keys[strdup(name)] = n;
180 if (Config->get_sync_all_route_ordering()) {
181 for (OrderKeys::iterator x = order_keys.begin(); x != order_keys.end(); ++x) {
186 _session.set_dirty ();
190 Route::sync_order_keys (const char* base)
192 if (order_keys.empty()) {
196 OrderKeys::iterator i;
199 if ((i = order_keys.find (base)) == order_keys.end()) {
200 /* key doesn't exist, use the first existing key (during session initialization) */
201 i = order_keys.begin();
205 /* key exists - use it and reset all others (actually, itself included) */
207 i = order_keys.begin();
210 for (; i != order_keys.end(); ++i) {
216 Route::ensure_track_or_route_name(string name, Session &session)
218 string newname = name;
220 while (session.route_by_name (newname) != NULL) {
221 newname = bump_name_once (newname);
228 Route::inc_gain (gain_t fraction, void *src)
230 IO::inc_gain (fraction, src);
234 Route::set_gain (gain_t val, void *src)
236 if (src != 0 && _mix_group && src != _mix_group && _mix_group->is_active()) {
238 if (_mix_group->is_relative()) {
240 gain_t usable_gain = gain();
241 if (usable_gain < 0.000001f) {
242 usable_gain = 0.000001f;
246 if (delta < 0.000001f) {
250 delta -= usable_gain;
255 gain_t factor = delta / usable_gain;
258 factor = _mix_group->get_max_factor(factor);
259 if (factor == 0.0f) {
260 _gain_control->Changed(); /* EMIT SIGNAL */
264 factor = _mix_group->get_min_factor(factor);
265 if (factor == 0.0f) {
266 _gain_control->Changed(); /* EMIT SIGNAL */
271 _mix_group->apply (&Route::inc_gain, factor, _mix_group);
275 _mix_group->apply (&Route::set_gain, val, _mix_group);
285 IO::set_gain (val, src);
288 /** Process this route for one (sub) cycle (process thread)
290 * @param bufs Scratch buffers to use for the signal path
291 * @param start_frame Initial transport frame
292 * @param end_frame Final transport frame
293 * @param nframes Number of frames to output (to ports)
295 * Note that (end_frame - start_frame) may not be equal to nframes when the
296 * transport speed isn't 1.0 (eg varispeed).
299 Route::process_output_buffers (BufferSet& bufs,
300 sframes_t start_frame, sframes_t end_frame, nframes_t nframes,
301 bool with_processors, int declick)
303 ProcessorList::iterator i;
304 bool mute_declick_applied = false;
308 bufs.is_silent(false);
310 switch (Config->get_monitoring_model()) {
311 case HardwareMonitoring:
312 case ExternalMonitoring:
319 declick = _pending_declick;
321 const bool recording_without_monitoring = no_monitor && record_enabled()
322 && (!_session.config.get_auto_input() || _session.actively_recording());
325 /* -------------------------------------------------------------------------------------------
327 ----------------------------------------------------------------------------------------- */
330 Glib::Mutex::Lock dm (declick_lock, Glib::TRY_LOCK);
333 dmg = desired_mute_gain;
334 dsg = desired_solo_gain;
335 dg = _gain_control->user_float();
343 // apply gain at the amp if...
345 // we're not recording
346 !(record_enabled() && _session.actively_recording())
347 // or (we are recording, and) software monitoring is required
348 || Config->get_monitoring_model() == SoftwareMonitoring);
350 // mute at the amp if...
351 _amp->apply_mute (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_post_fader,
354 _amp->set_gain (_gain, dg);
357 /* -------------------------------------------------------------------------------------------
358 SET UP CONTROL OUTPUTS
359 ----------------------------------------------------------------------------------------- */
361 boost::shared_ptr<Delivery> co = _control_outs;
363 // deliver control outputs unless we're ...
364 bool self_mute = ((dmg == 0 && _mute_affects_control_outs) || // or muted by mute of this track
365 !recording_without_monitoring); // or rec-enabled w/o s/w monitoring
366 bool other_mute = (dsg == 0); // muted by solo of another track
368 co->set_self_mute (self_mute);
369 co->set_nonself_mute (other_mute);
372 /* -------------------------------------------------------------------------------------------
373 SET UP MAIN OUTPUT STAGE
374 ----------------------------------------------------------------------------------------- */
376 bool solo_audible = dsg > 0;
377 bool mute_audible = dmg > 0 || !_mute_affects_main_outs;
379 bool silent_anyway = (_gain == 0 && !_amp->apply_gain_automation());
380 bool muted_by_other_solo = (!solo_audible && (Config->get_solo_model() != SoloBus));
381 bool muted_by_self = !mute_audible;
383 _main_outs->set_nonself_mute (recording_without_monitoring || muted_by_other_solo || silent_anyway);
384 _main_outs->set_self_mute (muted_by_self);
386 /* -------------------------------------------------------------------------------------------
387 GLOBAL DECLICK (for transport changes etc.)
388 ----------------------------------------------------------------------------------------- */
391 Amp::apply_gain (bufs, nframes, 0.0, 1.0, false);
392 _pending_declick = 0;
393 } else if (declick < 0) {
394 Amp::apply_gain (bufs, nframes, 1.0, 0.0, false);
395 _pending_declick = 0;
396 } else { // no global declick
397 if (solo_gain != dsg) {
398 Amp::apply_gain (bufs, nframes, solo_gain, dsg, false);
404 /* -------------------------------------------------------------------------------------------
406 ----------------------------------------------------------------------------------------- */
408 if (!_soloed && _mute_affects_pre_fader && (mute_gain != dmg)) {
409 Amp::apply_gain (bufs, nframes, mute_gain, dmg, false);
411 mute_declick_applied = true;
413 if (mute_gain == 0.0f && dmg == 0.0f) {
414 bufs.is_silent(true);
418 /* -------------------------------------------------------------------------------------------
420 ----------------------------------------------------------------------------------------- */
422 if (_denormal_protection || Config->get_denormal_protection()) {
424 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
425 Sample* const sp = i->data();
427 for (nframes_t nx = 0; nx < nframes; ++nx) {
433 /* -------------------------------------------------------------------------------------------
435 ----------------------------------------------------------------------------------------- */
437 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
440 for (i = _processors.begin(); i != _processors.end(); ++i) {
441 bufs.set_count(ChanCount::max(bufs.count(), (*i)->input_streams()));
442 (*i)->run_in_place (bufs, start_frame, end_frame, nframes);
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()));
451 /* -------------------------------------------------------------------------------------------
453 ----------------------------------------------------------------------------------------- */
455 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_main_outs) {
456 Amp::apply_gain (bufs, nframes, mute_gain, dmg, false);
458 mute_declick_applied = true;
461 if (mute_gain == 0.0f && dmg == 0.0f) {
462 bufs.is_silent(true);
465 // at this point we've reached the desired mute gain regardless
470 Route::n_process_buffers ()
472 return max (n_inputs(), processor_max_streams);
476 Route::setup_peak_meters()
478 ChanCount max_streams = std::max (_inputs.count(), _outputs.count());
479 max_streams = std::max (max_streams, processor_max_streams);
480 _meter->configure_io (max_streams, max_streams);
484 Route::passthru (sframes_t start_frame, sframes_t end_frame, nframes_t nframes, int declick)
486 BufferSet& bufs = _session.get_scratch_buffers(n_process_buffers());
490 collect_input (bufs, nframes);
492 process_output_buffers (bufs, start_frame, end_frame, nframes, true, declick);
496 Route::passthru_silence (sframes_t start_frame, sframes_t end_frame, nframes_t nframes, int declick)
498 process_output_buffers (_session.get_silent_buffers (n_process_buffers()), start_frame, end_frame, nframes, true, declick);
502 Route::set_solo (bool yn, void *src)
508 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
509 _mix_group->apply (&Route::set_solo, yn, _mix_group);
515 solo_changed (src); /* EMIT SIGNAL */
516 _solo_control->Changed (); /* EMIT SIGNAL */
519 catch_up_on_solo_mute_override ();
523 Route::catch_up_on_solo_mute_override ()
525 if (Config->get_solo_model() != InverseMute) {
530 Glib::Mutex::Lock lm (declick_lock);
533 if (Config->get_solo_mute_override()) {
534 desired_mute_gain = (_soloed?1.0:0.0);
536 desired_mute_gain = 0.0;
539 desired_mute_gain = 1.0;
545 Route::set_solo_mute (bool yn)
547 Glib::Mutex::Lock lm (declick_lock);
549 /* Called by Session in response to another Route being soloed.
552 desired_solo_gain = (yn?0.0:1.0);
556 Route::set_solo_safe (bool yn, void *src)
558 if (_solo_safe != yn) {
560 solo_safe_changed (src); /* EMIT SIGNAL */
565 Route::set_mute (bool yn, void *src)
568 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
569 _mix_group->apply (&Route::set_mute, yn, _mix_group);
575 mute_changed (src); /* EMIT SIGNAL */
577 _mute_control->Changed (); /* EMIT SIGNAL */
579 Glib::Mutex::Lock lm (declick_lock);
581 if (_soloed && Config->get_solo_mute_override()) {
582 desired_mute_gain = 1.0f;
584 desired_mute_gain = (yn?0.0f:1.0f);
590 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
592 cerr << name << " {" << endl;
593 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
594 p != procs.end(); ++p) {
595 cerr << "\t" << (*p)->name() << endl;
600 Route::ProcessorList::iterator
601 Route::prefader_iterator()
603 Glib::RWLock::ReaderLock lm (_processor_lock);
604 return find (_processors.begin(), _processors.end(), _amp);
608 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err)
610 ProcessorList::iterator loc;
612 /* XXX this is not thread safe - we don't hold the lock across determining the iter
613 to add before and actually doing the insertion. dammit.
616 if (placement == PreFader) {
617 /* generic pre-fader: insert immediately before the amp */
618 loc = find(_processors.begin(), _processors.end(), _amp);
620 /* generic post-fader: insert at end */
621 loc = _processors.end();
623 if (processor->visible() && !_processors.empty()) {
624 /* check for invisible processors stacked at the end and leave them there */
625 ProcessorList::iterator p;
626 p = _processors.end();
628 cerr << "Let's check " << (*p)->name() << " vis ? " << (*p)->visible() << endl;
629 while (!(*p)->visible() && p != _processors.begin()) {
637 return add_processor (processor, loc, err);
641 /** Add a processor to the route.
642 * If @a iter is not NULL, it must point to an iterator in _processors and the new
643 * processor will be inserted immediately before this location. Otherwise,
644 * @a position is used.
647 Route::add_processor (boost::shared_ptr<Processor> processor, ProcessorList::iterator iter, ProcessorStreams* err)
649 ChanCount old_pms = processor_max_streams;
651 if (!_session.engine().connected() || !processor) {
655 cerr << "Adding a processor called " << processor->name() << endl;
658 Glib::RWLock::WriterLock lm (_processor_lock);
660 boost::shared_ptr<PluginInsert> pi;
661 boost::shared_ptr<PortInsert> porti;
663 ProcessorList::iterator loc = find(_processors.begin(), _processors.end(), processor);
665 if (processor == _amp || processor == _meter || processor == _main_outs) {
666 // Ensure only one of these are in the list at any time
667 if (loc != _processors.end()) {
668 if (iter == loc) { // Already in place, do nothing
670 } else { // New position given, relocate
671 _processors.erase (loc);
676 if (loc != _processors.end()) {
677 cerr << "ERROR: Processor added to route twice!" << endl;
684 cerr << "Adding " << processor->name() << endl;
686 _processors.insert (loc, processor);
688 // Set up processor list channels. This will set processor->[input|output]_streams(),
689 // configure redirect ports properly, etc.
691 ProcessorStreams rerr;
693 if (configure_processors_unlocked (&rerr)) {
695 dump_processors(_name + "bad config", _processors);
699 cerr << "Error at proc " << rerr.index << " with input of " << rerr.count << endl;
700 ProcessorList::iterator ploc = loc;
702 _processors.erase(ploc);
703 configure_processors_unlocked (0); // it worked before we tried to add it ...
704 cerr << "Bad IO config\n";
708 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
710 if (pi->natural_input_streams() == ChanCount::ZERO) {
711 /* generator plugin */
712 _have_internal_generator = true;
717 // Ensure peak vector sizes before the plugin is activated
718 ChanCount potential_max_streams = ChanCount::max (processor->input_streams(), processor->output_streams());
720 _meter->configure_io (potential_max_streams, potential_max_streams);
722 // XXX: do we want to emit the signal here ? change call order.
723 processor->activate ();
724 processor->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
729 if (processor_max_streams != old_pms || old_pms == ChanCount::ZERO) {
733 dump_processors (_name + " added one", _processors);
734 processors_changed (); /* EMIT SIGNAL */
740 Route::add_processor_from_xml (const XMLNode& node, Placement placement)
742 ProcessorList::iterator loc;
743 if (placement == PreFader) {
744 /* generic pre-fader: insert immediately before the amp */
745 loc = find(_processors.begin(), _processors.end(), _amp);
747 /* generic post-fader: insert at end */
748 loc = _processors.end();
751 return add_processor_from_xml (node, loc);
755 Route::add_processor_from_xml (const XMLNode& node, ProcessorList::iterator iter)
757 const XMLProperty *prop;
759 // legacy sessions use a different node name for sends
760 if (node.name() == "Send") {
763 boost::shared_ptr<Send> send (new Send (_session, node));
764 add_processor (send, iter);
768 catch (failed_constructor &err) {
769 error << _("Send construction failed") << endmsg;
773 } else if (node.name() == "Processor") {
776 if ((prop = node.property ("type")) != 0) {
778 boost::shared_ptr<Processor> processor;
779 bool have_insert = false;
781 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
782 prop->value() == "lv2" ||
783 prop->value() == "vst" ||
784 prop->value() == "audiounit") {
786 processor.reset (new PluginInsert(_session, node));
789 } else if (prop->value() == "port") {
791 processor.reset (new PortInsert (_session, node));
793 } else if (prop->value() == "send") {
795 processor.reset (new Send (_session, node));
798 } else if (prop->value() == "meter") {
802 } else if (prop->value() == "amp") {
806 } else if (prop->value() == "listen" || prop->value() == "deliver") {
808 /* XXX need to generalize */
810 processor = _control_outs;
812 } else if (prop->value() == "main-outs") {
814 processor = _main_outs;
818 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
821 if (iter == _processors.end() && processor->visible() && !_processors.empty()) {
822 /* check for invisible processors stacked at the end and leave them there */
823 ProcessorList::iterator p;
824 p = _processors.end();
826 cerr << "Let's check " << (*p)->name() << " vis ? " << (*p)->visible() << endl;
827 while (!(*p)->visible() && p != _processors.begin()) {
834 return (add_processor (processor, iter) == 0);
837 error << _("Processor XML node has no type property") << endmsg;
841 catch (failed_constructor &err) {
842 warning << _("processor could not be created. Ignored.") << endmsg;
850 Route::add_processors (const ProcessorList& others, Placement placement, ProcessorStreams* err)
852 ProcessorList::iterator loc;
853 if (placement == PreFader) {
854 /* generic pre-fader: insert immediately before the amp */
855 loc = find(_processors.begin(), _processors.end(), _amp);
857 /* generic post-fader: insert at end */
858 loc = _processors.end();
860 if (!_processors.empty()) {
861 /* check for invisible processors stacked at the end and leave them there */
862 ProcessorList::iterator p;
863 p = _processors.end();
865 cerr << "Let's check " << (*p)->name() << " vis ? " << (*p)->visible() << endl;
866 while (!(*p)->visible() && p != _processors.begin()) {
874 return add_processors (others, loc, err);
878 Route::add_processors (const ProcessorList& others, ProcessorList::iterator iter, ProcessorStreams* err)
880 /* NOTE: this is intended to be used ONLY when copying
881 processors from another Route. Hence the subtle
882 differences between this and ::add_processor()
885 ChanCount old_pms = processor_max_streams;
887 if (!_session.engine().connected()) {
891 if (others.empty()) {
896 Glib::RWLock::WriterLock lm (_processor_lock);
897 ProcessorList::iterator existing_end = _processors.end();
900 ChanCount potential_max_streams = ChanCount::max (n_inputs(), n_outputs());
902 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
904 // Ensure meter only appears in the list once
906 ProcessorList::iterator m = find(_processors.begin(), _processors.end(), *i);
907 if (m != _processors.end()) {
908 _processors.erase(m);
912 boost::shared_ptr<PluginInsert> pi;
914 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
917 ChanCount m = max(pi->input_streams(), pi->output_streams());
918 if (m > potential_max_streams)
919 potential_max_streams = m;
922 // Ensure peak vector sizes before the plugin is activated
923 _meter->configure_io (potential_max_streams, potential_max_streams);
925 _processors.insert (iter, *i);
927 if (configure_processors_unlocked (err)) {
929 _processors.erase (existing_end, _processors.end());
930 configure_processors_unlocked (0); // it worked before we tried to add it ...
934 (*i)->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
940 if (processor_max_streams != old_pms || old_pms == ChanCount::ZERO) {
944 dump_processors (_name + " added several", _processors);
945 processors_changed (); /* EMIT SIGNAL */
951 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
954 start = _processors.begin();
955 end = find(_processors.begin(), _processors.end(), _amp);
957 start = find(_processors.begin(), _processors.end(), _amp);
959 end = _processors.end();
963 /** Turn off all processors with a given placement
964 * @param p Placement of processors to disable
967 Route::disable_processors (Placement p)
969 Glib::RWLock::ReaderLock lm (_processor_lock);
971 ProcessorList::iterator start, end;
972 placement_range(p, start, end);
974 for (ProcessorList::iterator i = start; i != end; ++i) {
978 _session.set_dirty ();
981 /** Turn off all redirects
984 Route::disable_processors ()
986 Glib::RWLock::ReaderLock lm (_processor_lock);
988 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
992 _session.set_dirty ();
995 /** Turn off all redirects with a given placement
996 * @param p Placement of redirects to disable
999 Route::disable_plugins (Placement p)
1001 Glib::RWLock::ReaderLock lm (_processor_lock);
1003 ProcessorList::iterator start, end;
1004 placement_range(p, start, end);
1006 for (ProcessorList::iterator i = start; i != end; ++i) {
1007 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1008 (*i)->deactivate ();
1012 _session.set_dirty ();
1015 /** Turn off all plugins
1018 Route::disable_plugins ()
1020 Glib::RWLock::ReaderLock lm (_processor_lock);
1022 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1023 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1024 (*i)->deactivate ();
1028 _session.set_dirty ();
1033 Route::ab_plugins (bool forward)
1035 Glib::RWLock::ReaderLock lm (_processor_lock);
1039 /* forward = turn off all active redirects, and mark them so that the next time
1040 we go the other way, we will revert them
1043 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1044 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1048 if ((*i)->active()) {
1049 (*i)->deactivate ();
1050 (*i)->set_next_ab_is_active (true);
1052 (*i)->set_next_ab_is_active (false);
1058 /* backward = if the redirect was marked to go active on the next ab, do so */
1060 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1062 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1066 if ((*i)->get_next_ab_is_active()) {
1069 (*i)->deactivate ();
1074 _session.set_dirty ();
1078 /* Figure out the streams that will feed into PreFader */
1080 Route::pre_fader_streams() const
1082 boost::shared_ptr<Processor> processor;
1084 /* Find the last pre-fader redirect that isn't a send; sends don't affect the number
1086 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1090 if (boost::dynamic_pointer_cast<Send> (*i) == 0) {
1096 return processor->output_streams();
1103 /** Remove processors with a given placement.
1104 * @param p Placement of processors to remove.
1107 Route::clear_processors (Placement p)
1109 const ChanCount old_pms = processor_max_streams;
1111 if (!_session.engine().connected()) {
1115 bool already_deleting = _session.deletion_in_progress();
1116 if (!already_deleting) {
1117 _session.set_deletion_in_progress();
1121 Glib::RWLock::WriterLock lm (_processor_lock);
1122 ProcessorList new_list;
1123 ProcessorStreams err;
1125 ProcessorList::iterator amp_loc = find(_processors.begin(), _processors.end(), _amp);
1126 if (p == PreFader) {
1127 // Get rid of PreFader processors
1128 for (ProcessorList::iterator i = _processors.begin(); i != amp_loc; ++i) {
1129 (*i)->drop_references ();
1132 for (ProcessorList::iterator i = amp_loc; i != _processors.end(); ++i) {
1133 new_list.push_back (*i);
1136 // Keep PreFader processors
1137 for (ProcessorList::iterator i = _processors.begin(); i != amp_loc; ++i) {
1138 new_list.push_back (*i);
1140 new_list.push_back (_amp);
1141 // Get rid of PostFader processors
1142 for (ProcessorList::iterator i = amp_loc; i != _processors.end(); ++i) {
1143 (*i)->drop_references ();
1147 _processors = new_list;
1148 configure_processors_unlocked (&err); // this can't fail
1151 if (processor_max_streams != old_pms) {
1155 processor_max_streams.reset();
1156 _have_internal_generator = false;
1157 processors_changed (); /* EMIT SIGNAL */
1159 if (!already_deleting) {
1160 _session.clear_deletion_in_progress();
1165 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err)
1167 /* these can never be removed */
1169 if (processor == _amp || processor == _meter || processor == _main_outs) {
1173 ChanCount old_pms = processor_max_streams;
1175 if (!_session.engine().connected()) {
1179 processor_max_streams.reset();
1182 Glib::RWLock::WriterLock lm (_processor_lock);
1183 ProcessorList::iterator i;
1184 bool removed = false;
1186 for (i = _processors.begin(); i != _processors.end(); ) {
1187 if (*i == processor) {
1189 /* move along, see failure case for configure_processors()
1190 where we may need to reprocessor the processor.
1193 /* stop redirects that send signals to JACK ports
1194 from causing noise as a result of no longer being
1198 boost::shared_ptr<IOProcessor> redirect;
1200 if ((redirect = boost::dynamic_pointer_cast<IOProcessor> (*i)) != 0) {
1201 redirect->io()->disconnect_inputs (this);
1202 redirect->io()->disconnect_outputs (this);
1205 i = _processors.erase (i);
1221 if (configure_processors_unlocked (err)) {
1222 /* get back to where we where */
1223 _processors.insert (i, processor);
1224 /* we know this will work, because it worked before :) */
1225 configure_processors_unlocked (0);
1229 _have_internal_generator = false;
1231 for (i = _processors.begin(); i != _processors.end(); ++i) {
1232 boost::shared_ptr<PluginInsert> pi;
1234 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1235 if (pi->is_generator()) {
1236 _have_internal_generator = true;
1243 if (old_pms != processor_max_streams) {
1247 processor->drop_references ();
1249 dump_processors (_name + " removed one", _processors);
1250 processors_changed (); /* EMIT SIGNAL */
1256 Route::configure_processors (ProcessorStreams* err)
1258 if (!_in_configure_processors) {
1259 Glib::RWLock::WriterLock lm (_processor_lock);
1260 return configure_processors_unlocked (err);
1265 /** Configure the input/output configuration of each processor in the processors list.
1266 * Return 0 on success, otherwise configuration is impossible.
1269 Route::configure_processors_unlocked (ProcessorStreams* err)
1271 if (_in_configure_processors) {
1275 _in_configure_processors = true;
1277 // Check each processor in order to see if we can configure as requested
1278 ChanCount in = n_inputs();
1280 list< pair<ChanCount,ChanCount> > configuration;
1282 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1283 cerr << "Can " << (*p)->name() << " support in= " << in << " out= " << out;
1284 if ((*p)->can_support_io_configuration(in, out)) {
1286 configuration.push_back(make_pair(in, out));
1294 _in_configure_processors = false;
1299 // We can, so configure everything
1300 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1301 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1302 (*p)->configure_io(c->first, c->second);
1304 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1305 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1309 // Ensure route outputs match last processor's outputs
1310 if (out != n_outputs()) {
1311 ensure_io (n_inputs(), out, false, this);
1314 _in_configure_processors = false;
1319 Route::all_processors_flip ()
1321 Glib::RWLock::ReaderLock lm (_processor_lock);
1323 if (_processors.empty()) {
1327 bool first_is_on = _processors.front()->active();
1329 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1331 (*i)->deactivate ();
1337 _session.set_dirty ();
1340 /** Set all processors with a given placement to a given active state.
1341 * @param p Placement of processors to change.
1342 * @param state New active state for those processors.
1345 Route::all_processors_active (Placement p, bool state)
1347 Glib::RWLock::ReaderLock lm (_processor_lock);
1349 if (_processors.empty()) {
1352 ProcessorList::iterator start, end;
1353 placement_range(p, start, end);
1355 bool before_amp = true;
1356 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1361 if (p == PreFader && before_amp) {
1365 (*i)->deactivate ();
1370 _session.set_dirty ();
1374 Route::reorder_processors (const ProcessorList& new_order, Placement placement, ProcessorStreams* err)
1377 Glib::RWLock::WriterLock lm (_processor_lock);
1378 ChanCount old_pms = processor_max_streams;
1379 ProcessorList::iterator oiter;
1380 ProcessorList::const_iterator niter;
1381 ProcessorList as_it_was_before = _processors;
1382 ProcessorList as_it_will_be;
1383 ProcessorList::iterator start, end;
1385 dump_processors (_name + " PreReorder", _processors);
1386 placement_range (placement, start, end);
1389 niter = new_order.begin();
1391 while (oiter != end && niter != new_order.end()) {
1393 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
1394 then append it to the temp list.
1396 Otherwise, see if the next processor in the old list is in the new list. if not,
1397 its been deleted. If its there, append it to the temp list.
1402 /* no more elements in the old list, so just stick the rest of
1403 the new order onto the temp list.
1406 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
1410 if (!(*oiter)->visible()) {
1412 as_it_will_be.push_back (*oiter);
1416 /* visible processor: check that its in the new order */
1418 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
1419 /* deleted: do nothing */
1421 /* ignore this one, and add the next item from the new order instead */
1422 as_it_will_be.push_back (*niter);
1427 /* now remove from old order - its taken care of no matter what */
1428 oiter = _processors.erase (oiter);
1432 _processors.insert (end, as_it_will_be.begin(), as_it_will_be.end());
1434 dump_processors (_name + " PostReorder", _processors);
1436 if (configure_processors_unlocked (err)) {
1437 _processors = as_it_was_before;
1438 processor_max_streams = old_pms;
1443 dump_processors (_name + " sorted", _processors);
1444 /* do we really need to do this every time? */
1446 processors_changed (); /* EMIT SIGNAL */
1458 Route::get_template()
1460 return state(false);
1464 Route::state(bool full_state)
1466 XMLNode *node = new XMLNode("Route");
1467 ProcessorList::iterator i;
1471 node->add_property("flags", enum_2_string (_flags));
1474 node->add_property("default-type", _default_type.to_string());
1476 node->add_property("active", _active?"yes":"no");
1477 node->add_property("muted", _muted?"yes":"no");
1478 node->add_property("soloed", _soloed?"yes":"no");
1479 node->add_property("phase-invert", _phase_invert?"yes":"no");
1480 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
1481 node->add_property("mute-affects-pre-fader", _mute_affects_pre_fader?"yes":"no");
1482 node->add_property("mute-affects-post-fader", _mute_affects_post_fader?"yes":"no");
1483 node->add_property("mute-affects-control-outs", _mute_affects_control_outs?"yes":"no");
1484 node->add_property("mute-affects-main-outs", _mute_affects_main_outs?"yes":"no");
1485 node->add_property("meter-point", enum_2_string (_meter_point));
1488 node->add_property("edit-group", _edit_group->name());
1491 node->add_property("mix-group", _mix_group->name());
1494 string order_string;
1495 OrderKeys::iterator x = order_keys.begin();
1497 while (x != order_keys.end()) {
1498 order_string += string ((*x).first);
1499 order_string += '=';
1500 snprintf (buf, sizeof(buf), "%ld", (*x).second);
1501 order_string += buf;
1505 if (x == order_keys.end()) {
1509 order_string += ':';
1511 node->add_property ("order-keys", order_string);
1513 node->add_child_nocopy (IO::state (full_state));
1514 node->add_child_nocopy (_solo_control->get_state ());
1515 node->add_child_nocopy (_mute_control->get_state ());
1517 XMLNode* remote_control_node = new XMLNode (X_("RemoteControl"));
1518 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
1519 remote_control_node->add_property (X_("id"), buf);
1520 node->add_child_nocopy (*remote_control_node);
1522 if (_comment.length()) {
1523 XMLNode *cmt = node->add_child ("Comment");
1524 cmt->add_content (_comment);
1527 for (i = _processors.begin(); i != _processors.end(); ++i) {
1528 node->add_child_nocopy((*i)->state (full_state));
1532 node->add_child_copy (*_extra_xml);
1539 Route::get_processor_state ()
1541 XMLNode* root = new XMLNode (X_("redirects"));
1542 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1543 root->add_child_nocopy ((*i)->state (true));
1550 Route::set_processor_state (const XMLNode& root)
1552 if (root.name() != X_("redirects")) {
1558 XMLNodeConstIterator iter;
1559 XMLNodeConstIterator niter;
1560 Glib::RWLock::ReaderLock lm (_processor_lock);
1562 nlist = root.children();
1564 for (iter = nlist.begin(); iter != nlist.end(); ++iter){
1566 /* iter now points to a IOProcessor state node */
1568 nnlist = (*iter)->children ();
1570 for (niter = nnlist.begin(); niter != nnlist.end(); ++niter) {
1572 /* find the IO child node, since it contains the ID we need */
1574 /* XXX OOP encapsulation violation, ugh */
1576 if ((*niter)->name() == IO::state_node_name) {
1578 XMLProperty* prop = (*niter)->property (X_("id"));
1581 warning << _("IOProcessor node has no ID, ignored") << endmsg;
1585 ID id = prop->value ();
1587 /* now look for a processor with that ID */
1589 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1590 if ((*i)->id() == id) {
1591 (*i)->set_state (**iter);
1607 Route::set_deferred_state ()
1610 XMLNodeConstIterator niter;
1612 if (!deferred_state) {
1616 nlist = deferred_state->children();
1618 _set_processor_states (nlist);
1620 delete deferred_state;
1625 Route::set_state (const XMLNode& node)
1627 return _set_state (node, true);
1631 Route::_set_state (const XMLNode& node, bool call_base)
1634 XMLNodeConstIterator niter;
1636 XMLPropertyList plist;
1637 const XMLProperty *prop;
1639 if (node.name() != "Route"){
1640 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
1644 if ((prop = node.property (X_("flags"))) != 0) {
1645 _flags = Flag (string_2_enum (prop->value(), _flags));
1650 if ((prop = node.property (X_("default-type"))) != 0) {
1651 _default_type = DataType(prop->value());
1652 assert(_default_type != DataType::NIL);
1655 if ((prop = node.property (X_("phase-invert"))) != 0) {
1656 set_phase_invert (prop->value()=="yes"?true:false, this);
1659 if ((prop = node.property (X_("denormal-protection"))) != 0) {
1660 set_denormal_protection (prop->value()=="yes"?true:false, this);
1664 if ((prop = node.property (X_("active"))) != 0) {
1665 set_active (prop->value() == "yes");
1668 if ((prop = node.property (X_("muted"))) != 0) {
1669 bool yn = prop->value()=="yes"?true:false;
1671 /* force reset of mute status */
1675 mute_gain = desired_mute_gain;
1678 if ((prop = node.property (X_("soloed"))) != 0) {
1679 bool yn = prop->value()=="yes"?true:false;
1681 /* force reset of solo status */
1684 set_solo (yn, this);
1685 solo_gain = desired_solo_gain;
1688 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
1689 _mute_affects_pre_fader = (prop->value()=="yes")?true:false;
1692 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
1693 _mute_affects_post_fader = (prop->value()=="yes")?true:false;
1696 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
1697 _mute_affects_control_outs = (prop->value()=="yes")?true:false;
1700 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
1701 _mute_affects_main_outs = (prop->value()=="yes")?true:false;
1704 if ((prop = node.property (X_("meter-point"))) != 0) {
1705 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
1708 if ((prop = node.property (X_("edit-group"))) != 0) {
1709 RouteGroup* edit_group = _session.edit_group_by_name(prop->value());
1710 if(edit_group == 0) {
1711 error << string_compose(_("Route %1: unknown edit group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
1713 set_edit_group(edit_group, this);
1717 if ((prop = node.property (X_("order-keys"))) != 0) {
1721 string::size_type colon, equal;
1722 string remaining = prop->value();
1724 while (remaining.length()) {
1726 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
1727 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1730 if (sscanf (remaining.substr (equal+1).c_str(), "%ld", &n) != 1) {
1731 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1734 set_order_key (remaining.substr (0, equal).c_str(), n);
1738 colon = remaining.find_first_of (':');
1740 if (colon != string::npos) {
1741 remaining = remaining.substr (colon+1);
1748 nlist = node.children();
1750 delete deferred_state;
1751 deferred_state = new XMLNode(X_("deferred state"));
1753 /* set parent class properties before anything else */
1755 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1759 if (child->name() == IO::state_node_name && call_base) {
1760 IO::set_state (*child);
1765 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1769 if (child->name() == X_("Send") || child->name() == X_("Processor")) {
1770 deferred_state->add_child_copy (*child);
1775 _set_processor_states (deferred_state->children());
1776 delete deferred_state;
1780 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1783 if (child->name() == X_("Automation")) {
1785 if ((prop = child->property (X_("path"))) != 0) {
1786 load_automation (prop->value());
1789 } else if (child->name() == X_("ControlOuts")) {
1791 /* ignore this - deprecated */
1793 } else if (child->name() == X_("Comment")) {
1795 /* XXX this is a terrible API design in libxml++ */
1797 XMLNode *cmt = *(child->children().begin());
1798 _comment = cmt->content();
1800 } else if (child->name() == X_("Extra")) {
1802 _extra_xml = new XMLNode (*child);
1804 } else if (child->name() == X_("Controllable") && (prop = child->property("name")) != 0) {
1806 if (prop->value() == "solo") {
1807 _solo_control->set_state (*child);
1808 _session.add_controllable (_solo_control);
1809 } else if (prop->value() == "mute") {
1810 _mute_control->set_state (*child);
1811 _session.add_controllable (_mute_control);
1813 } else if (child->name() == X_("RemoteControl")) {
1814 if ((prop = child->property (X_("id"))) != 0) {
1816 sscanf (prop->value().c_str(), "%d", &x);
1817 set_remote_control_id (x);
1822 if ((prop = node.property (X_("mix-group"))) != 0) {
1823 RouteGroup* mix_group = _session.mix_group_by_name(prop->value());
1824 if (mix_group == 0) {
1825 error << string_compose(_("Route %1: unknown mix group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
1827 set_mix_group(mix_group, this);
1835 Route::_set_processor_states(const XMLNodeList &nlist)
1837 XMLNodeConstIterator niter;
1838 bool has_meter_processor = false; // legacy sessions don't
1839 ProcessorList::iterator i, o;
1841 cerr << "Setting processor states with in = " << n_inputs() << endl;
1843 // Iterate through existing processors, remove those which are not in the state list
1844 for (i = _processors.begin(); i != _processors.end(); ) {
1845 ProcessorList::iterator tmp = i;
1848 bool processorInStateList = false;
1850 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1852 XMLProperty* id_prop = (*niter)->property(X_("id"));
1853 if (id_prop && (*i)->id() == id_prop->value()) {
1854 processorInStateList = true;
1859 if (!processorInStateList) {
1860 remove_processor (*i);
1866 // Iterate through state list and make sure all processors are on the track and in the correct order,
1867 // set the state of existing processors according to the new state on the same go
1868 i = _processors.begin();
1870 for (niter = nlist.begin(); niter != nlist.end(); ++niter, ++i) {
1872 XMLProperty* prop = (*niter)->property ("type");
1874 if (prop && prop->value() == "meter") {
1875 has_meter_processor = true;
1880 if (prop->value() != "meter" && prop->value() != "amp" && prop->value() != "main-outs") {
1882 // Check whether the next processor in the list
1884 while (o != _processors.end()) {
1885 XMLProperty* id_prop = (*niter)->property(X_("id"));
1886 if (id_prop && (*o)->id() == id_prop->value()) {
1894 // If the processor (*niter) is not on the route,
1895 // create it and move it to the correct location
1896 if (o == _processors.end()) {
1898 if (add_processor_from_xml (**niter, i)) {
1899 --i; // move iterator to the newly inserted processor
1901 cerr << "Error restoring route: unable to restore processor" << endl;
1904 // Otherwise, the processor already exists; just
1905 // ensure it is at the location provided in the XML state
1909 boost::shared_ptr<Processor> tmp = (*o);
1910 _processors.erase (o); // remove the old copy
1911 _processors.insert (i, tmp); // insert the processor at the correct location
1912 --i; // move iterator to the correct processor
1915 (*i)->set_state (**niter);
1919 /* note: there is no configure_processors() call because we figure that
1920 the XML state represents a working signal route.
1923 if (!has_meter_processor) {
1924 set_meter_point (_meter_point, NULL);
1927 processors_changed ();
1934 Route::curve_reallocate ()
1936 // _gain_automation_curve.finish_resize ();
1937 // _pan_automation_curve.finish_resize ();
1941 Route::silence (nframes_t nframes)
1945 IO::silence (nframes);
1948 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
1951 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1952 boost::shared_ptr<PluginInsert> pi;
1954 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
1955 // skip plugins, they don't need anything when we're not active
1959 (*i)->silence (nframes);
1962 if (nframes == _session.get_block_size()) {
1971 boost::shared_ptr<Delivery>
1972 Route::add_listener (boost::shared_ptr<IO> io, const string& listen_name)
1974 string name = _name;
1976 name += listen_name;
1979 boost::shared_ptr<Delivery> listener (new Delivery (_session, name, Delivery::Listen));
1981 /* As an IO, our control outs need as many IO outputs as we have outputs
1982 * (we track the changes in ::output_change_handler()).
1983 * As a processor, the listener is an identity processor
1984 * (i.e. it does not modify its input buffers whatsoever)
1987 if (listener->io()->ensure_io (ChanCount::ZERO, n_outputs(), true, this)) {
1988 return boost::shared_ptr<Delivery>();
1991 add_processor (listener, PostFader);
1997 Route::listen_via (boost::shared_ptr<IO> io, const string& listen_name)
1999 vector<string> ports;
2000 vector<string>::const_iterator i;
2003 Glib::RWLock::ReaderLock rm (_processor_lock);
2005 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
2006 boost::shared_ptr<const Delivery> d = boost::dynamic_pointer_cast<const Delivery>(*x);
2008 if (d && d->io() == io) {
2009 /* already listening via the specified IO: do nothing */
2015 uint32_t ni = io->n_inputs().n_total();
2017 for (uint32_t n = 0; n < ni; ++n) {
2018 ports.push_back (io->input(n)->name());
2021 if (ports.empty()) {
2025 boost::shared_ptr<Delivery> listen_point = add_listener (io, listen_name);
2027 /* XXX hack for now .... until we can generalize listen points */
2029 _control_outs = listen_point;
2031 /* now connect to the named ports */
2033 ni = listen_point->io()->n_outputs().n_total();
2034 size_t psize = ports.size();
2036 for (size_t n = 0; n < ni; ++n) {
2037 if (listen_point->io()->connect_output (listen_point->io()->output (n), ports[n % psize], this)) {
2038 error << string_compose (_("could not connect %1 to %2"),
2039 listen_point->io()->output(n)->name(), ports[n % psize]) << endmsg;
2049 Route::drop_listen (boost::shared_ptr<IO> io)
2051 ProcessorStreams err;
2052 ProcessorList::iterator tmp;
2054 Glib::RWLock::ReaderLock rm (_processor_lock);
2056 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ) {
2061 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*x);
2063 if (d && d->io() == io) {
2064 /* already listening via the specified IO: do nothing */
2065 remove_processor (*x, &err);
2074 Route::set_edit_group (RouteGroup *eg, void *src)
2077 if (eg == _edit_group) {
2082 _edit_group->remove (this);
2085 if ((_edit_group = eg) != 0) {
2086 _edit_group->add (this);
2089 _session.set_dirty ();
2090 edit_group_changed (src); /* EMIT SIGNAL */
2094 Route::drop_edit_group (void *src)
2097 _session.set_dirty ();
2098 edit_group_changed (src); /* EMIT SIGNAL */
2102 Route::set_mix_group (RouteGroup *mg, void *src)
2105 if (mg == _mix_group) {
2110 _mix_group->remove (this);
2113 if ((_mix_group = mg) != 0) {
2114 _mix_group->add (this);
2117 _session.set_dirty ();
2118 mix_group_changed (src); /* EMIT SIGNAL */
2122 Route::drop_mix_group (void *src)
2125 _session.set_dirty ();
2126 mix_group_changed (src); /* EMIT SIGNAL */
2130 Route::set_comment (string cmt, void *src)
2133 comment_changed (src);
2134 _session.set_dirty ();
2138 Route::feeds (boost::shared_ptr<Route> other)
2143 uint32_t no = self.n_outputs().n_total();
2144 uint32_t ni = other->n_inputs ().n_total();
2146 for (i = 0; i < no; ++i) {
2147 for (j = 0; j < ni; ++j) {
2148 if (self.output(i)->connected_to (other->input(j)->name())) {
2154 /* check IOProcessors which may also interconnect Routes */
2156 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); r++) {
2158 boost::shared_ptr<IOProcessor> proc = boost::dynamic_pointer_cast<IOProcessor>(*r);
2164 no = proc->io()->n_outputs().n_total();
2166 for (i = 0; i < no; ++i) {
2167 for (j = 0; j < ni; ++j) {
2168 if (proc->io()->output(i)->connected_to (other->input (j)->name())) {
2179 Route::set_mute_config (mute_type t, bool onoff, void *src)
2183 _mute_affects_pre_fader = onoff;
2184 pre_fader_changed(src); /* EMIT SIGNAL */
2188 _mute_affects_post_fader = onoff;
2189 post_fader_changed(src); /* EMIT SIGNAL */
2193 _mute_affects_control_outs = onoff;
2194 control_outs_changed(src); /* EMIT SIGNAL */
2198 _mute_affects_main_outs = onoff;
2199 main_outs_changed(src); /* EMIT SIGNAL */
2205 Route::get_mute_config (mute_type t)
2211 onoff = _mute_affects_pre_fader;
2214 onoff = _mute_affects_post_fader;
2217 onoff = _mute_affects_control_outs;
2220 onoff = _mute_affects_main_outs;
2228 Route::handle_transport_stopped (bool abort_ignored, bool did_locate, bool can_flush_processors)
2230 nframes_t now = _session.transport_frame();
2233 Glib::RWLock::ReaderLock lm (_processor_lock);
2236 automation_snapshot (now, true);
2239 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2241 if (Config->get_plugins_stop_with_transport() && can_flush_processors) {
2242 (*i)->deactivate ();
2246 (*i)->transport_stopped (now);
2250 IO::transport_stopped (now);
2252 _roll_delay = _initial_delay;
2256 Route::input_change_handler (IOChange change, void *src)
2258 if ((change & ConfigurationChanged)) {
2259 configure_processors (0);
2264 Route::output_change_handler (IOChange change, void *src)
2266 if ((change & ConfigurationChanged)) {
2267 if (_control_outs) {
2268 _control_outs->io()->ensure_io (ChanCount::ZERO, n_outputs(), true, this);
2271 configure_processors (0);
2276 Route::pans_required () const
2278 if (n_outputs().n_audio() < 2) {
2282 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
2286 Route::no_roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame,
2287 bool session_state_changing, bool can_record, bool rec_monitors_input)
2289 if (n_outputs().n_total() == 0) {
2293 if (session_state_changing || !_active) {
2298 _amp->apply_gain_automation(false);
2300 if (n_inputs() != ChanCount::ZERO) {
2301 passthru (start_frame, end_frame, nframes, 0);
2310 Route::check_initial_delay (nframes_t nframes, nframes_t& transport_frame)
2312 if (_roll_delay > nframes) {
2314 _roll_delay -= nframes;
2316 /* transport frame is not legal for caller to use */
2319 } else if (_roll_delay > 0) {
2321 nframes -= _roll_delay;
2322 silence (_roll_delay);
2323 /* we've written _roll_delay of samples into the
2324 output ports, so make a note of that for
2327 increment_output_offset (_roll_delay);
2328 transport_frame += _roll_delay;
2337 Route::roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame, int declick,
2338 bool can_record, bool rec_monitors_input)
2341 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2343 // automation snapshot can also be called from the non-rt context
2344 // and it uses the processor list, so we take the lock out here
2345 automation_snapshot (_session.transport_frame(), false);
2349 if ((n_outputs().n_total() == 0 && _processors.empty()) || n_inputs().n_total() == 0 || !_active) {
2354 nframes_t unused = 0;
2356 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
2362 _amp->apply_gain_automation(false);
2365 Glib::Mutex::Lock am (data().control_lock(), Glib::TRY_LOCK);
2367 if (am.locked() && _session.transport_rolling()) {
2369 if (_gain_control->automation_playback()) {
2370 _amp->apply_gain_automation(
2371 _gain_control->list()->curve().rt_safe_get_vector (
2372 start_frame, end_frame, _session.gain_automation_buffer(), nframes));
2377 passthru (start_frame, end_frame, nframes, declick);
2383 Route::silent_roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame,
2384 bool can_record, bool rec_monitors_input)
2391 Route::toggle_monitor_input ()
2393 for (PortSet::iterator i = _inputs.begin(); i != _inputs.end(); ++i) {
2394 i->ensure_monitor_input( ! i->monitoring_input());
2399 Route::has_external_redirects () const
2401 // FIXME: what about sends?
2403 boost::shared_ptr<const PortInsert> pi;
2405 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2406 if ((pi = boost::dynamic_pointer_cast<const PortInsert>(*i)) != 0) {
2408 for (PortSet::const_iterator port = pi->io()->outputs().begin();
2409 port != pi->io()->outputs().end(); ++port) {
2411 string port_name = port->name();
2412 string client_name = port_name.substr (0, port_name.find(':'));
2414 /* only say "yes" if the redirect is actually in use */
2416 if (client_name != "ardour" && pi->active()) {
2427 Route::flush_processors ()
2429 /* XXX shouldn't really try to take this lock, since
2430 this is called from the RT audio thread.
2433 Glib::RWLock::ReaderLock lm (_processor_lock);
2435 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2436 (*i)->deactivate ();
2442 Route::set_meter_point (MeterPoint p, void *src)
2444 if (_meter_point != p) {
2447 // Move meter in the processors list
2448 ProcessorList::iterator loc = find(_processors.begin(), _processors.end(), _meter);
2449 _processors.erase(loc);
2452 loc = _processors.begin();
2455 loc = find(_processors.begin(), _processors.end(), _amp);
2457 case MeterPostFader:
2458 loc = _processors.end();
2461 _processors.insert(loc, _meter);
2463 meter_change (src); /* EMIT SIGNAL */
2464 processors_changed (); /* EMIT SIGNAL */
2465 _session.set_dirty ();
2470 Route::update_total_latency ()
2472 nframes_t old = _own_latency;
2474 if (_user_latency) {
2475 _own_latency = _user_latency;
2479 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2480 if ((*i)->active ()) {
2481 _own_latency += (*i)->signal_latency ();
2486 #undef DEBUG_LATENCY
2487 #ifdef DEBUG_LATENCY
2488 cerr << _name << ": internal redirect latency = " << _own_latency << endl;
2491 set_port_latency (_own_latency);
2493 if (!_user_latency) {
2494 /* this (virtual) function is used for pure Routes,
2495 not derived classes like AudioTrack. this means
2496 that the data processed here comes from an input
2497 port, not prerecorded material, and therefore we
2498 have to take into account any input latency.
2502 _own_latency += input_latency ();
2505 if (old != _own_latency) {
2506 signal_latency_changed (); /* EMIT SIGNAL */
2509 #ifdef DEBUG_LATENCY
2510 cerr << _name << ": input latency = " << input_latency() << " total = "
2511 << _own_latency << endl;
2514 return _own_latency;
2518 Route::set_user_latency (nframes_t nframes)
2520 Latent::set_user_latency (nframes);
2521 _session.update_latency_compensation (false, false);
2525 Route::set_latency_delay (nframes_t longest_session_latency)
2527 nframes_t old = _initial_delay;
2529 if (_own_latency < longest_session_latency) {
2530 _initial_delay = longest_session_latency - _own_latency;
2535 if (_initial_delay != old) {
2536 initial_delay_changed (); /* EMIT SIGNAL */
2539 if (_session.transport_stopped()) {
2540 _roll_delay = _initial_delay;
2545 Route::automation_snapshot (nframes_t now, bool force)
2547 if (!force && !should_snapshot(now)) {
2551 IO::automation_snapshot (now, force);
2553 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2554 (*i)->automation_snapshot (now, force);
2558 Route::ToggleControllable::ToggleControllable (std::string name, Route& s, ToggleType tp)
2559 : Controllable (name), route (s), type(tp)
2565 Route::ToggleControllable::set_value (float val)
2567 bool bval = ((val >= 0.5f) ? true: false);
2571 route.set_mute (bval, this);
2574 route.set_solo (bval, this);
2582 Route::ToggleControllable::get_value (void) const
2588 val = route.muted() ? 1.0f : 0.0f;
2591 val = route.soloed() ? 1.0f : 0.0f;
2601 Route::set_block_size (nframes_t nframes)
2603 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2604 (*i)->set_block_size (nframes);
2606 _session.ensure_buffers(processor_max_streams);
2610 Route::protect_automation ()
2612 Automatable::protect_automation();
2614 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
2615 (*i)->protect_automation();
2619 Route::set_pending_declick (int declick)
2622 /* this call is not allowed to turn off a pending declick unless "force" is true */
2624 _pending_declick = declick;
2626 // cerr << _name << ": after setting to " << declick << " pending declick = " << _pending_declick << endl;
2628 _pending_declick = 0;
2633 /** Shift automation forwards from a particular place, thereby inserting time.
2634 * Adds undo commands for any shifts that are performed.
2636 * @param pos Position to start shifting from.
2637 * @param frames Amount to shift forwards by.
2641 Route::shift (nframes64_t pos, nframes64_t frames)
2643 #ifdef THIS_NEEDS_FIXING_FOR_V3
2645 /* gain automation */
2646 XMLNode &before = _gain_control->get_state ();
2647 _gain_control->shift (pos, frames);
2648 XMLNode &after = _gain_control->get_state ();
2649 _session.add_command (new MementoCommand<AutomationList> (_gain_automation_curve, &before, &after));
2651 /* pan automation */
2652 for (std::vector<StreamPanner*>::iterator i = _panner->begin (); i != _panner->end (); ++i) {
2653 Curve & c = (*i)->automation ();
2654 XMLNode &before = c.get_state ();
2655 c.shift (pos, frames);
2656 XMLNode &after = c.get_state ();
2657 _session.add_command (new MementoCommand<AutomationList> (c, &before, &after));
2660 /* redirect automation */
2662 Glib::RWLock::ReaderLock lm (redirect_lock);
2663 for (RedirectList::iterator i = _redirects.begin (); i != _redirects.end (); ++i) {
2666 (*i)->what_has_automation (a);
2668 for (set<uint32_t>::const_iterator j = a.begin (); j != a.end (); ++j) {
2669 AutomationList & al = (*i)->automation_list (*j);
2670 XMLNode &before = al.get_state ();
2671 al.shift (pos, frames);
2672 XMLNode &after = al.get_state ();
2673 _session.add_command (new MementoCommand<AutomationList> (al, &before, &after));
2683 Route::save_as_template (const string& path, const string& name)
2685 XMLNode& node (state (false));
2688 IO::set_name_in_state (*node.children().front(), name);
2690 tree.set_root (&node);
2691 return tree.write (path.c_str());
2696 Route::set_name (const string& str)
2701 if ((ret = IO::set_name (str)) == true) {
2702 Glib::RWLock::ReaderLock lm (_processor_lock);
2704 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2706 /* rename all delivery objects to reflect our new name */
2708 boost::shared_ptr<Delivery> dp = boost::dynamic_pointer_cast<Delivery> (*i);
2711 string dp_name = str;
2713 dp_name += "XXX FIX ME XXX";
2716 if (!dp->set_name (dp_name)) {