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) {
656 Glib::RWLock::WriterLock lm (_processor_lock);
658 boost::shared_ptr<PluginInsert> pi;
659 boost::shared_ptr<PortInsert> porti;
661 ProcessorList::iterator loc = find(_processors.begin(), _processors.end(), processor);
663 if (processor == _amp || processor == _meter || processor == _main_outs) {
664 // Ensure only one of these are in the list at any time
665 if (loc != _processors.end()) {
666 if (iter == loc) { // Already in place, do nothing
668 } else { // New position given, relocate
669 _processors.erase (loc);
674 if (loc != _processors.end()) {
675 cerr << "ERROR: Processor added to route twice!" << endl;
682 _processors.insert (loc, processor);
684 // Set up processor list channels. This will set processor->[input|output]_streams(),
685 // configure redirect ports properly, etc.
688 if (configure_processors_unlocked (err)) {
689 ProcessorList::iterator ploc = loc;
691 _processors.erase(ploc);
692 configure_processors_unlocked (0); // it worked before we tried to add it ...
696 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
698 if (pi->natural_input_streams() == ChanCount::ZERO) {
699 /* generator plugin */
700 _have_internal_generator = true;
705 // Ensure peak vector sizes before the plugin is activated
706 ChanCount potential_max_streams = ChanCount::max (processor->input_streams(), processor->output_streams());
708 _meter->configure_io (potential_max_streams, potential_max_streams);
710 // XXX: do we want to emit the signal here ? change call order.
711 processor->activate ();
712 processor->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
717 if (processor_max_streams != old_pms || old_pms == ChanCount::ZERO) {
721 processors_changed (); /* EMIT SIGNAL */
727 Route::add_processor_from_xml (const XMLNode& node, Placement placement)
729 ProcessorList::iterator loc;
730 if (placement == PreFader) {
731 /* generic pre-fader: insert immediately before the amp */
732 loc = find(_processors.begin(), _processors.end(), _amp);
734 /* generic post-fader: insert at end */
735 loc = _processors.end();
738 return add_processor_from_xml (node, loc);
742 Route::add_processor_from_xml (const XMLNode& node, ProcessorList::iterator iter)
744 const XMLProperty *prop;
746 // legacy sessions use a different node name for sends
747 if (node.name() == "Send") {
750 boost::shared_ptr<Send> send (new Send (_session, node));
751 add_processor (send, iter);
755 catch (failed_constructor &err) {
756 error << _("Send construction failed") << endmsg;
760 } else if (node.name() == "Processor") {
763 if ((prop = node.property ("type")) != 0) {
765 boost::shared_ptr<Processor> processor;
766 bool have_insert = false;
768 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
769 prop->value() == "lv2" ||
770 prop->value() == "vst" ||
771 prop->value() == "audiounit") {
773 processor.reset (new PluginInsert(_session, node));
776 } else if (prop->value() == "port") {
778 processor.reset (new PortInsert (_session, node));
780 } else if (prop->value() == "send") {
782 processor.reset (new Send (_session, node));
785 } else if (prop->value() == "meter") {
789 } else if (prop->value() == "amp") {
793 } else if (prop->value() == "listen" || prop->value() == "deliver") {
795 /* XXX need to generalize */
797 processor = _control_outs;
799 } else if (prop->value() == "main-outs") {
801 processor = _main_outs;
805 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
808 if (iter == _processors.end() && processor->visible() && !_processors.empty()) {
809 /* check for invisible processors stacked at the end and leave them there */
810 ProcessorList::iterator p;
811 p = _processors.end();
813 cerr << "Let's check " << (*p)->name() << " vis ? " << (*p)->visible() << endl;
814 while (!(*p)->visible() && p != _processors.begin()) {
821 return (add_processor (processor, iter) == 0);
824 error << _("Processor XML node has no type property") << endmsg;
828 catch (failed_constructor &err) {
829 warning << _("processor could not be created. Ignored.") << endmsg;
837 Route::add_processors (const ProcessorList& others, Placement placement, ProcessorStreams* err)
839 ProcessorList::iterator loc;
840 if (placement == PreFader) {
841 /* generic pre-fader: insert immediately before the amp */
842 loc = find(_processors.begin(), _processors.end(), _amp);
844 /* generic post-fader: insert at end */
845 loc = _processors.end();
847 if (!_processors.empty()) {
848 /* check for invisible processors stacked at the end and leave them there */
849 ProcessorList::iterator p;
850 p = _processors.end();
852 cerr << "Let's check " << (*p)->name() << " vis ? " << (*p)->visible() << endl;
853 while (!(*p)->visible() && p != _processors.begin()) {
861 return add_processors (others, loc, err);
865 Route::add_processors (const ProcessorList& others, ProcessorList::iterator iter, ProcessorStreams* err)
867 /* NOTE: this is intended to be used ONLY when copying
868 processors from another Route. Hence the subtle
869 differences between this and ::add_processor()
872 ChanCount old_pms = processor_max_streams;
874 if (!_session.engine().connected()) {
878 if (others.empty()) {
883 Glib::RWLock::WriterLock lm (_processor_lock);
884 ProcessorList::iterator existing_end = _processors.end();
887 ChanCount potential_max_streams = ChanCount::max (n_inputs(), n_outputs());
889 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
891 // Ensure meter only appears in the list once
893 ProcessorList::iterator m = find(_processors.begin(), _processors.end(), *i);
894 if (m != _processors.end()) {
895 _processors.erase(m);
899 boost::shared_ptr<PluginInsert> pi;
901 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
904 ChanCount m = max(pi->input_streams(), pi->output_streams());
905 if (m > potential_max_streams)
906 potential_max_streams = m;
909 // Ensure peak vector sizes before the plugin is activated
910 _meter->configure_io (potential_max_streams, potential_max_streams);
912 _processors.insert (iter, *i);
914 if (configure_processors_unlocked (err)) {
916 _processors.erase (existing_end, _processors.end());
917 configure_processors_unlocked (0); // it worked before we tried to add it ...
921 (*i)->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
927 if (processor_max_streams != old_pms || old_pms == ChanCount::ZERO) {
931 processors_changed (); /* EMIT SIGNAL */
937 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
940 start = _processors.begin();
941 end = find(_processors.begin(), _processors.end(), _amp);
943 start = find(_processors.begin(), _processors.end(), _amp);
945 end = _processors.end();
949 /** Turn off all processors with a given placement
950 * @param p Placement of processors to disable
953 Route::disable_processors (Placement p)
955 Glib::RWLock::ReaderLock lm (_processor_lock);
957 ProcessorList::iterator start, end;
958 placement_range(p, start, end);
960 for (ProcessorList::iterator i = start; i != end; ++i) {
964 _session.set_dirty ();
967 /** Turn off all redirects
970 Route::disable_processors ()
972 Glib::RWLock::ReaderLock lm (_processor_lock);
974 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
978 _session.set_dirty ();
981 /** Turn off all redirects with a given placement
982 * @param p Placement of redirects to disable
985 Route::disable_plugins (Placement p)
987 Glib::RWLock::ReaderLock lm (_processor_lock);
989 ProcessorList::iterator start, end;
990 placement_range(p, start, end);
992 for (ProcessorList::iterator i = start; i != end; ++i) {
993 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
998 _session.set_dirty ();
1001 /** Turn off all plugins
1004 Route::disable_plugins ()
1006 Glib::RWLock::ReaderLock lm (_processor_lock);
1008 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1009 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1010 (*i)->deactivate ();
1014 _session.set_dirty ();
1019 Route::ab_plugins (bool forward)
1021 Glib::RWLock::ReaderLock lm (_processor_lock);
1025 /* forward = turn off all active redirects, and mark them so that the next time
1026 we go the other way, we will revert them
1029 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1030 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1034 if ((*i)->active()) {
1035 (*i)->deactivate ();
1036 (*i)->set_next_ab_is_active (true);
1038 (*i)->set_next_ab_is_active (false);
1044 /* backward = if the redirect was marked to go active on the next ab, do so */
1046 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1048 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1052 if ((*i)->get_next_ab_is_active()) {
1055 (*i)->deactivate ();
1060 _session.set_dirty ();
1064 /* Figure out the streams that will feed into PreFader */
1066 Route::pre_fader_streams() const
1068 boost::shared_ptr<Processor> processor;
1070 /* Find the last pre-fader redirect that isn't a send; sends don't affect the number
1072 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1076 if (boost::dynamic_pointer_cast<Send> (*i) == 0) {
1082 return processor->output_streams();
1089 /** Remove processors with a given placement.
1090 * @param p Placement of processors to remove.
1093 Route::clear_processors (Placement p)
1095 const ChanCount old_pms = processor_max_streams;
1097 if (!_session.engine().connected()) {
1101 bool already_deleting = _session.deletion_in_progress();
1102 if (!already_deleting) {
1103 _session.set_deletion_in_progress();
1107 Glib::RWLock::WriterLock lm (_processor_lock);
1108 ProcessorList new_list;
1109 ProcessorStreams err;
1111 ProcessorList::iterator amp_loc = find(_processors.begin(), _processors.end(), _amp);
1112 if (p == PreFader) {
1113 // Get rid of PreFader processors
1114 for (ProcessorList::iterator i = _processors.begin(); i != amp_loc; ++i) {
1115 (*i)->drop_references ();
1118 for (ProcessorList::iterator i = amp_loc; i != _processors.end(); ++i) {
1119 new_list.push_back (*i);
1122 // Keep PreFader processors
1123 for (ProcessorList::iterator i = _processors.begin(); i != amp_loc; ++i) {
1124 new_list.push_back (*i);
1126 new_list.push_back (_amp);
1127 // Get rid of PostFader processors
1128 for (ProcessorList::iterator i = amp_loc; i != _processors.end(); ++i) {
1129 (*i)->drop_references ();
1133 _processors = new_list;
1134 configure_processors_unlocked (&err); // this can't fail
1137 if (processor_max_streams != old_pms) {
1141 processor_max_streams.reset();
1142 _have_internal_generator = false;
1143 processors_changed (); /* EMIT SIGNAL */
1145 if (!already_deleting) {
1146 _session.clear_deletion_in_progress();
1151 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err)
1153 /* these can never be removed */
1155 if (processor == _amp || processor == _meter || processor == _main_outs) {
1159 ChanCount old_pms = processor_max_streams;
1161 if (!_session.engine().connected()) {
1165 processor_max_streams.reset();
1168 Glib::RWLock::WriterLock lm (_processor_lock);
1169 ProcessorList::iterator i;
1170 bool removed = false;
1172 for (i = _processors.begin(); i != _processors.end(); ) {
1173 if (*i == processor) {
1175 /* move along, see failure case for configure_processors()
1176 where we may need to reprocessor the processor.
1179 /* stop redirects that send signals to JACK ports
1180 from causing noise as a result of no longer being
1184 boost::shared_ptr<IOProcessor> redirect;
1186 if ((redirect = boost::dynamic_pointer_cast<IOProcessor> (*i)) != 0) {
1187 redirect->io()->disconnect_inputs (this);
1188 redirect->io()->disconnect_outputs (this);
1191 i = _processors.erase (i);
1207 if (configure_processors_unlocked (err)) {
1208 /* get back to where we where */
1209 _processors.insert (i, processor);
1210 /* we know this will work, because it worked before :) */
1211 configure_processors_unlocked (0);
1215 _have_internal_generator = false;
1217 for (i = _processors.begin(); i != _processors.end(); ++i) {
1218 boost::shared_ptr<PluginInsert> pi;
1220 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1221 if (pi->is_generator()) {
1222 _have_internal_generator = true;
1229 if (old_pms != processor_max_streams) {
1233 processor->drop_references ();
1234 processors_changed (); /* EMIT SIGNAL */
1240 Route::configure_processors (ProcessorStreams* err)
1242 if (!_in_configure_processors) {
1243 Glib::RWLock::WriterLock lm (_processor_lock);
1244 return configure_processors_unlocked (err);
1249 /** Configure the input/output configuration of each processor in the processors list.
1250 * Return 0 on success, otherwise configuration is impossible.
1253 Route::configure_processors_unlocked (ProcessorStreams* err)
1255 if (_in_configure_processors) {
1259 _in_configure_processors = true;
1261 // Check each processor in order to see if we can configure as requested
1262 ChanCount in = n_inputs();
1264 list< pair<ChanCount,ChanCount> > configuration;
1266 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1267 if ((*p)->can_support_io_configuration(in, out)) {
1268 configuration.push_back(make_pair(in, out));
1275 _in_configure_processors = false;
1280 // We can, so configure everything
1281 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1282 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1283 (*p)->configure_io(c->first, c->second);
1285 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1286 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1290 // Ensure route outputs match last processor's outputs
1291 if (out != n_outputs()) {
1292 ensure_io (n_inputs(), out, false, this);
1295 _in_configure_processors = false;
1300 Route::all_processors_flip ()
1302 Glib::RWLock::ReaderLock lm (_processor_lock);
1304 if (_processors.empty()) {
1308 bool first_is_on = _processors.front()->active();
1310 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1312 (*i)->deactivate ();
1318 _session.set_dirty ();
1321 /** Set all processors with a given placement to a given active state.
1322 * @param p Placement of processors to change.
1323 * @param state New active state for those processors.
1326 Route::all_processors_active (Placement p, bool state)
1328 Glib::RWLock::ReaderLock lm (_processor_lock);
1330 if (_processors.empty()) {
1333 ProcessorList::iterator start, end;
1334 placement_range(p, start, end);
1336 bool before_amp = true;
1337 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1342 if (p == PreFader && before_amp) {
1346 (*i)->deactivate ();
1351 _session.set_dirty ();
1355 Route::reorder_processors (const ProcessorList& new_order, Placement placement, ProcessorStreams* err)
1358 Glib::RWLock::WriterLock lm (_processor_lock);
1359 ChanCount old_pms = processor_max_streams;
1360 ProcessorList::iterator oiter;
1361 ProcessorList::const_iterator niter;
1362 ProcessorList as_it_was_before = _processors;
1363 ProcessorList as_it_will_be;
1364 ProcessorList::iterator start, end;
1366 placement_range (placement, start, end);
1369 niter = new_order.begin();
1371 while (niter != new_order.end()) {
1373 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
1374 then append it to the temp list.
1376 Otherwise, see if the next processor in the old list is in the new list. if not,
1377 its been deleted. If its there, append it to the temp list.
1382 /* no more elements in the old list, so just stick the rest of
1383 the new order onto the temp list.
1386 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
1391 if (!(*oiter)->visible()) {
1393 as_it_will_be.push_back (*oiter);
1397 /* visible processor: check that its in the new order */
1399 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
1400 /* deleted: do nothing */
1402 /* ignore this one, and add the next item from the new order instead */
1403 as_it_will_be.push_back (*niter);
1408 /* now remove from old order - its taken care of no matter what */
1409 oiter = _processors.erase (oiter);
1414 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
1416 if (configure_processors_unlocked (err)) {
1417 _processors = as_it_was_before;
1418 processor_max_streams = old_pms;
1423 /* do we really need to do this every time? */
1425 processors_changed (); /* EMIT SIGNAL */
1437 Route::get_template()
1439 return state(false);
1443 Route::state(bool full_state)
1445 XMLNode *node = new XMLNode("Route");
1446 ProcessorList::iterator i;
1450 node->add_property("flags", enum_2_string (_flags));
1453 node->add_property("default-type", _default_type.to_string());
1455 node->add_property("active", _active?"yes":"no");
1456 node->add_property("muted", _muted?"yes":"no");
1457 node->add_property("soloed", _soloed?"yes":"no");
1458 node->add_property("phase-invert", _phase_invert?"yes":"no");
1459 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
1460 node->add_property("mute-affects-pre-fader", _mute_affects_pre_fader?"yes":"no");
1461 node->add_property("mute-affects-post-fader", _mute_affects_post_fader?"yes":"no");
1462 node->add_property("mute-affects-control-outs", _mute_affects_control_outs?"yes":"no");
1463 node->add_property("mute-affects-main-outs", _mute_affects_main_outs?"yes":"no");
1464 node->add_property("meter-point", enum_2_string (_meter_point));
1467 node->add_property("edit-group", _edit_group->name());
1470 node->add_property("mix-group", _mix_group->name());
1473 string order_string;
1474 OrderKeys::iterator x = order_keys.begin();
1476 while (x != order_keys.end()) {
1477 order_string += string ((*x).first);
1478 order_string += '=';
1479 snprintf (buf, sizeof(buf), "%ld", (*x).second);
1480 order_string += buf;
1484 if (x == order_keys.end()) {
1488 order_string += ':';
1490 node->add_property ("order-keys", order_string);
1492 node->add_child_nocopy (IO::state (full_state));
1493 node->add_child_nocopy (_solo_control->get_state ());
1494 node->add_child_nocopy (_mute_control->get_state ());
1496 XMLNode* remote_control_node = new XMLNode (X_("RemoteControl"));
1497 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
1498 remote_control_node->add_property (X_("id"), buf);
1499 node->add_child_nocopy (*remote_control_node);
1501 if (_comment.length()) {
1502 XMLNode *cmt = node->add_child ("Comment");
1503 cmt->add_content (_comment);
1506 for (i = _processors.begin(); i != _processors.end(); ++i) {
1507 node->add_child_nocopy((*i)->state (full_state));
1511 node->add_child_copy (*_extra_xml);
1518 Route::get_processor_state ()
1520 XMLNode* root = new XMLNode (X_("redirects"));
1521 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1522 root->add_child_nocopy ((*i)->state (true));
1529 Route::set_processor_state (const XMLNode& root)
1531 if (root.name() != X_("redirects")) {
1537 XMLNodeConstIterator iter;
1538 XMLNodeConstIterator niter;
1539 Glib::RWLock::ReaderLock lm (_processor_lock);
1541 nlist = root.children();
1543 for (iter = nlist.begin(); iter != nlist.end(); ++iter){
1545 /* iter now points to a IOProcessor state node */
1547 nnlist = (*iter)->children ();
1549 for (niter = nnlist.begin(); niter != nnlist.end(); ++niter) {
1551 /* find the IO child node, since it contains the ID we need */
1553 /* XXX OOP encapsulation violation, ugh */
1555 if ((*niter)->name() == IO::state_node_name) {
1557 XMLProperty* prop = (*niter)->property (X_("id"));
1560 warning << _("IOProcessor node has no ID, ignored") << endmsg;
1564 ID id = prop->value ();
1566 /* now look for a processor with that ID */
1568 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1569 if ((*i)->id() == id) {
1570 (*i)->set_state (**iter);
1586 Route::set_deferred_state ()
1589 XMLNodeConstIterator niter;
1591 if (!deferred_state) {
1595 nlist = deferred_state->children();
1597 _set_processor_states (nlist);
1599 delete deferred_state;
1604 Route::set_state (const XMLNode& node)
1606 return _set_state (node, true);
1610 Route::_set_state (const XMLNode& node, bool call_base)
1613 XMLNodeConstIterator niter;
1615 XMLPropertyList plist;
1616 const XMLProperty *prop;
1618 if (node.name() != "Route"){
1619 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
1623 if ((prop = node.property (X_("flags"))) != 0) {
1624 _flags = Flag (string_2_enum (prop->value(), _flags));
1629 if ((prop = node.property (X_("default-type"))) != 0) {
1630 _default_type = DataType(prop->value());
1631 assert(_default_type != DataType::NIL);
1634 if ((prop = node.property (X_("phase-invert"))) != 0) {
1635 set_phase_invert (prop->value()=="yes"?true:false, this);
1638 if ((prop = node.property (X_("denormal-protection"))) != 0) {
1639 set_denormal_protection (prop->value()=="yes"?true:false, this);
1643 if ((prop = node.property (X_("active"))) != 0) {
1644 set_active (prop->value() == "yes");
1647 if ((prop = node.property (X_("muted"))) != 0) {
1648 bool yn = prop->value()=="yes"?true:false;
1650 /* force reset of mute status */
1654 mute_gain = desired_mute_gain;
1657 if ((prop = node.property (X_("soloed"))) != 0) {
1658 bool yn = prop->value()=="yes"?true:false;
1660 /* force reset of solo status */
1663 set_solo (yn, this);
1664 solo_gain = desired_solo_gain;
1667 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
1668 _mute_affects_pre_fader = (prop->value()=="yes")?true:false;
1671 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
1672 _mute_affects_post_fader = (prop->value()=="yes")?true:false;
1675 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
1676 _mute_affects_control_outs = (prop->value()=="yes")?true:false;
1679 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
1680 _mute_affects_main_outs = (prop->value()=="yes")?true:false;
1683 if ((prop = node.property (X_("meter-point"))) != 0) {
1684 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
1687 if ((prop = node.property (X_("edit-group"))) != 0) {
1688 RouteGroup* edit_group = _session.edit_group_by_name(prop->value());
1689 if(edit_group == 0) {
1690 error << string_compose(_("Route %1: unknown edit group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
1692 set_edit_group(edit_group, this);
1696 if ((prop = node.property (X_("order-keys"))) != 0) {
1700 string::size_type colon, equal;
1701 string remaining = prop->value();
1703 while (remaining.length()) {
1705 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
1706 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1709 if (sscanf (remaining.substr (equal+1).c_str(), "%ld", &n) != 1) {
1710 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1713 set_order_key (remaining.substr (0, equal).c_str(), n);
1717 colon = remaining.find_first_of (':');
1719 if (colon != string::npos) {
1720 remaining = remaining.substr (colon+1);
1727 nlist = node.children();
1729 delete deferred_state;
1730 deferred_state = new XMLNode(X_("deferred state"));
1732 /* set parent class properties before anything else */
1734 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1738 if (child->name() == IO::state_node_name && call_base) {
1739 IO::set_state (*child);
1744 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1748 if (child->name() == X_("Send") || child->name() == X_("Processor")) {
1749 deferred_state->add_child_copy (*child);
1754 _set_processor_states (deferred_state->children());
1755 delete deferred_state;
1759 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1762 if (child->name() == X_("Automation")) {
1764 if ((prop = child->property (X_("path"))) != 0) {
1765 load_automation (prop->value());
1768 } else if (child->name() == X_("ControlOuts")) {
1770 /* ignore this - deprecated */
1772 } else if (child->name() == X_("Comment")) {
1774 /* XXX this is a terrible API design in libxml++ */
1776 XMLNode *cmt = *(child->children().begin());
1777 _comment = cmt->content();
1779 } else if (child->name() == X_("Extra")) {
1781 _extra_xml = new XMLNode (*child);
1783 } else if (child->name() == X_("Controllable") && (prop = child->property("name")) != 0) {
1785 if (prop->value() == "solo") {
1786 _solo_control->set_state (*child);
1787 _session.add_controllable (_solo_control);
1788 } else if (prop->value() == "mute") {
1789 _mute_control->set_state (*child);
1790 _session.add_controllable (_mute_control);
1792 } else if (child->name() == X_("RemoteControl")) {
1793 if ((prop = child->property (X_("id"))) != 0) {
1795 sscanf (prop->value().c_str(), "%d", &x);
1796 set_remote_control_id (x);
1801 if ((prop = node.property (X_("mix-group"))) != 0) {
1802 RouteGroup* mix_group = _session.mix_group_by_name(prop->value());
1803 if (mix_group == 0) {
1804 error << string_compose(_("Route %1: unknown mix group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
1806 set_mix_group(mix_group, this);
1814 Route::_set_processor_states(const XMLNodeList &nlist)
1816 XMLNodeConstIterator niter;
1817 bool has_meter_processor = false; // legacy sessions don't
1818 ProcessorList::iterator i, o;
1820 // Iterate through existing processors, remove those which are not in the state list
1821 for (i = _processors.begin(); i != _processors.end(); ) {
1822 ProcessorList::iterator tmp = i;
1825 bool processorInStateList = false;
1827 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1829 XMLProperty* id_prop = (*niter)->property(X_("id"));
1830 if (id_prop && (*i)->id() == id_prop->value()) {
1831 processorInStateList = true;
1836 if (!processorInStateList) {
1837 remove_processor (*i);
1843 // Iterate through state list and make sure all processors are on the track and in the correct order,
1844 // set the state of existing processors according to the new state on the same go
1845 i = _processors.begin();
1847 for (niter = nlist.begin(); niter != nlist.end(); ++niter, ++i) {
1849 XMLProperty* prop = (*niter)->property ("type");
1851 if (prop && prop->value() == "meter") {
1852 has_meter_processor = true;
1857 if (prop->value() != "meter" && prop->value() != "amp" && prop->value() != "main-outs") {
1859 // Check whether the next processor in the list
1861 while (o != _processors.end()) {
1862 XMLProperty* id_prop = (*niter)->property(X_("id"));
1863 if (id_prop && (*o)->id() == id_prop->value()) {
1871 // If the processor (*niter) is not on the route,
1872 // create it and move it to the correct location
1873 if (o == _processors.end()) {
1875 if (add_processor_from_xml (**niter, i)) {
1876 --i; // move iterator to the newly inserted processor
1878 cerr << "Error restoring route: unable to restore processor" << endl;
1881 // Otherwise, the processor already exists; just
1882 // ensure it is at the location provided in the XML state
1886 boost::shared_ptr<Processor> tmp = (*o);
1887 _processors.erase (o); // remove the old copy
1888 _processors.insert (i, tmp); // insert the processor at the correct location
1889 --i; // move iterator to the correct processor
1892 (*i)->set_state (**niter);
1896 /* note: there is no configure_processors() call because we figure that
1897 the XML state represents a working signal route.
1900 if (!has_meter_processor) {
1901 set_meter_point (_meter_point, NULL);
1904 processors_changed ();
1911 Route::curve_reallocate ()
1913 // _gain_automation_curve.finish_resize ();
1914 // _pan_automation_curve.finish_resize ();
1918 Route::silence (nframes_t nframes)
1922 IO::silence (nframes);
1925 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
1928 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1929 boost::shared_ptr<PluginInsert> pi;
1931 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
1932 // skip plugins, they don't need anything when we're not active
1936 (*i)->silence (nframes);
1939 if (nframes == _session.get_block_size()) {
1948 boost::shared_ptr<Delivery>
1949 Route::add_listener (boost::shared_ptr<IO> io, const string& listen_name)
1951 string name = _name;
1953 name += listen_name;
1956 boost::shared_ptr<Delivery> listener (new Delivery (_session, name, Delivery::Listen));
1958 /* As an IO, our control outs need as many IO outputs as we have outputs
1959 * (we track the changes in ::output_change_handler()).
1960 * As a processor, the listener is an identity processor
1961 * (i.e. it does not modify its input buffers whatsoever)
1964 if (listener->io()->ensure_io (ChanCount::ZERO, n_outputs(), true, this)) {
1965 return boost::shared_ptr<Delivery>();
1968 add_processor (listener, PostFader);
1974 Route::listen_via (boost::shared_ptr<IO> io, const string& listen_name)
1976 vector<string> ports;
1977 vector<string>::const_iterator i;
1980 Glib::RWLock::ReaderLock rm (_processor_lock);
1982 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
1983 boost::shared_ptr<const Delivery> d = boost::dynamic_pointer_cast<const Delivery>(*x);
1985 if (d && d->io() == io) {
1986 /* already listening via the specified IO: do nothing */
1992 uint32_t ni = io->n_inputs().n_total();
1994 for (uint32_t n = 0; n < ni; ++n) {
1995 ports.push_back (io->input(n)->name());
1998 if (ports.empty()) {
2002 boost::shared_ptr<Delivery> listen_point = add_listener (io, listen_name);
2004 /* XXX hack for now .... until we can generalize listen points */
2006 _control_outs = listen_point;
2008 /* now connect to the named ports */
2010 ni = listen_point->io()->n_outputs().n_total();
2011 size_t psize = ports.size();
2013 for (size_t n = 0; n < ni; ++n) {
2014 if (listen_point->io()->connect_output (listen_point->io()->output (n), ports[n % psize], this)) {
2015 error << string_compose (_("could not connect %1 to %2"),
2016 listen_point->io()->output(n)->name(), ports[n % psize]) << endmsg;
2026 Route::drop_listen (boost::shared_ptr<IO> io)
2028 ProcessorStreams err;
2029 ProcessorList::iterator tmp;
2031 Glib::RWLock::ReaderLock rm (_processor_lock);
2033 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ) {
2038 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*x);
2040 if (d && d->io() == io) {
2041 /* already listening via the specified IO: do nothing */
2042 remove_processor (*x, &err);
2051 Route::set_edit_group (RouteGroup *eg, void *src)
2054 if (eg == _edit_group) {
2059 _edit_group->remove (this);
2062 if ((_edit_group = eg) != 0) {
2063 _edit_group->add (this);
2066 _session.set_dirty ();
2067 edit_group_changed (src); /* EMIT SIGNAL */
2071 Route::drop_edit_group (void *src)
2074 _session.set_dirty ();
2075 edit_group_changed (src); /* EMIT SIGNAL */
2079 Route::set_mix_group (RouteGroup *mg, void *src)
2082 if (mg == _mix_group) {
2087 _mix_group->remove (this);
2090 if ((_mix_group = mg) != 0) {
2091 _mix_group->add (this);
2094 _session.set_dirty ();
2095 mix_group_changed (src); /* EMIT SIGNAL */
2099 Route::drop_mix_group (void *src)
2102 _session.set_dirty ();
2103 mix_group_changed (src); /* EMIT SIGNAL */
2107 Route::set_comment (string cmt, void *src)
2110 comment_changed (src);
2111 _session.set_dirty ();
2115 Route::feeds (boost::shared_ptr<IO> other)
2117 if (connected_to (other)) {
2121 /* check IOProcessors which may also interconnect Routes */
2123 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); r++) {
2125 boost::shared_ptr<IOProcessor> proc;
2127 if ((proc = boost::dynamic_pointer_cast<IOProcessor>(*r)) != 0) {
2128 if (proc->io()->connected_to (other)) {
2138 Route::set_mute_config (mute_type t, bool onoff, void *src)
2142 _mute_affects_pre_fader = onoff;
2143 pre_fader_changed(src); /* EMIT SIGNAL */
2147 _mute_affects_post_fader = onoff;
2148 post_fader_changed(src); /* EMIT SIGNAL */
2152 _mute_affects_control_outs = onoff;
2153 control_outs_changed(src); /* EMIT SIGNAL */
2157 _mute_affects_main_outs = onoff;
2158 main_outs_changed(src); /* EMIT SIGNAL */
2164 Route::get_mute_config (mute_type t)
2170 onoff = _mute_affects_pre_fader;
2173 onoff = _mute_affects_post_fader;
2176 onoff = _mute_affects_control_outs;
2179 onoff = _mute_affects_main_outs;
2187 Route::handle_transport_stopped (bool abort_ignored, bool did_locate, bool can_flush_processors)
2189 nframes_t now = _session.transport_frame();
2192 Glib::RWLock::ReaderLock lm (_processor_lock);
2195 automation_snapshot (now, true);
2198 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2200 if (Config->get_plugins_stop_with_transport() && can_flush_processors) {
2201 (*i)->deactivate ();
2205 (*i)->transport_stopped (now);
2209 IO::transport_stopped (now);
2211 _roll_delay = _initial_delay;
2215 Route::input_change_handler (IOChange change, void *src)
2217 if ((change & ConfigurationChanged)) {
2218 configure_processors (0);
2223 Route::output_change_handler (IOChange change, void *src)
2225 if ((change & ConfigurationChanged)) {
2226 if (_control_outs) {
2227 _control_outs->io()->ensure_io (ChanCount::ZERO, n_outputs(), true, this);
2230 configure_processors (0);
2235 Route::pans_required () const
2237 if (n_outputs().n_audio() < 2) {
2241 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
2245 Route::no_roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame,
2246 bool session_state_changing, bool can_record, bool rec_monitors_input)
2248 if (n_outputs().n_total() == 0) {
2252 if (session_state_changing || !_active) {
2257 _amp->apply_gain_automation(false);
2259 if (n_inputs() != ChanCount::ZERO) {
2260 passthru (start_frame, end_frame, nframes, 0);
2269 Route::check_initial_delay (nframes_t nframes, nframes_t& transport_frame)
2271 if (_roll_delay > nframes) {
2273 _roll_delay -= nframes;
2275 /* transport frame is not legal for caller to use */
2278 } else if (_roll_delay > 0) {
2280 nframes -= _roll_delay;
2281 silence (_roll_delay);
2282 /* we've written _roll_delay of samples into the
2283 output ports, so make a note of that for
2286 increment_output_offset (_roll_delay);
2287 transport_frame += _roll_delay;
2296 Route::roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame, int declick,
2297 bool can_record, bool rec_monitors_input)
2300 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2302 // automation snapshot can also be called from the non-rt context
2303 // and it uses the processor list, so we take the lock out here
2304 automation_snapshot (_session.transport_frame(), false);
2308 if ((n_outputs().n_total() == 0 && _processors.empty()) || n_inputs().n_total() == 0 || !_active) {
2313 nframes_t unused = 0;
2315 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
2321 _amp->apply_gain_automation(false);
2324 Glib::Mutex::Lock am (data().control_lock(), Glib::TRY_LOCK);
2326 if (am.locked() && _session.transport_rolling()) {
2328 if (_gain_control->automation_playback()) {
2329 _amp->apply_gain_automation(
2330 _gain_control->list()->curve().rt_safe_get_vector (
2331 start_frame, end_frame, _session.gain_automation_buffer(), nframes));
2336 passthru (start_frame, end_frame, nframes, declick);
2342 Route::silent_roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame,
2343 bool can_record, bool rec_monitors_input)
2350 Route::toggle_monitor_input ()
2352 for (PortSet::iterator i = _inputs.begin(); i != _inputs.end(); ++i) {
2353 i->ensure_monitor_input( ! i->monitoring_input());
2358 Route::has_external_redirects () const
2360 // FIXME: what about sends?
2362 boost::shared_ptr<const PortInsert> pi;
2364 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2365 if ((pi = boost::dynamic_pointer_cast<const PortInsert>(*i)) != 0) {
2367 for (PortSet::const_iterator port = pi->io()->outputs().begin();
2368 port != pi->io()->outputs().end(); ++port) {
2370 string port_name = port->name();
2371 string client_name = port_name.substr (0, port_name.find(':'));
2373 /* only say "yes" if the redirect is actually in use */
2375 if (client_name != "ardour" && pi->active()) {
2386 Route::flush_processors ()
2388 /* XXX shouldn't really try to take this lock, since
2389 this is called from the RT audio thread.
2392 Glib::RWLock::ReaderLock lm (_processor_lock);
2394 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2395 (*i)->deactivate ();
2401 Route::set_meter_point (MeterPoint p, void *src)
2403 if (_meter_point != p) {
2406 // Move meter in the processors list
2407 ProcessorList::iterator loc = find(_processors.begin(), _processors.end(), _meter);
2408 _processors.erase(loc);
2411 loc = _processors.begin();
2414 loc = find(_processors.begin(), _processors.end(), _amp);
2416 case MeterPostFader:
2417 loc = _processors.end();
2420 _processors.insert(loc, _meter);
2422 meter_change (src); /* EMIT SIGNAL */
2423 processors_changed (); /* EMIT SIGNAL */
2424 _session.set_dirty ();
2429 Route::update_total_latency ()
2431 nframes_t old = _own_latency;
2433 if (_user_latency) {
2434 _own_latency = _user_latency;
2438 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2439 if ((*i)->active ()) {
2440 _own_latency += (*i)->signal_latency ();
2445 #undef DEBUG_LATENCY
2446 #ifdef DEBUG_LATENCY
2447 cerr << _name << ": internal redirect latency = " << _own_latency << endl;
2450 set_port_latency (_own_latency);
2452 if (!_user_latency) {
2453 /* this (virtual) function is used for pure Routes,
2454 not derived classes like AudioTrack. this means
2455 that the data processed here comes from an input
2456 port, not prerecorded material, and therefore we
2457 have to take into account any input latency.
2461 _own_latency += input_latency ();
2464 if (old != _own_latency) {
2465 signal_latency_changed (); /* EMIT SIGNAL */
2468 #ifdef DEBUG_LATENCY
2469 cerr << _name << ": input latency = " << input_latency() << " total = "
2470 << _own_latency << endl;
2473 return _own_latency;
2477 Route::set_user_latency (nframes_t nframes)
2479 Latent::set_user_latency (nframes);
2480 _session.update_latency_compensation (false, false);
2484 Route::set_latency_delay (nframes_t longest_session_latency)
2486 nframes_t old = _initial_delay;
2488 if (_own_latency < longest_session_latency) {
2489 _initial_delay = longest_session_latency - _own_latency;
2494 if (_initial_delay != old) {
2495 initial_delay_changed (); /* EMIT SIGNAL */
2498 if (_session.transport_stopped()) {
2499 _roll_delay = _initial_delay;
2504 Route::automation_snapshot (nframes_t now, bool force)
2506 if (!force && !should_snapshot(now)) {
2510 IO::automation_snapshot (now, force);
2512 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2513 (*i)->automation_snapshot (now, force);
2517 Route::ToggleControllable::ToggleControllable (std::string name, Route& s, ToggleType tp)
2518 : Controllable (name), route (s), type(tp)
2524 Route::ToggleControllable::set_value (float val)
2526 bool bval = ((val >= 0.5f) ? true: false);
2530 route.set_mute (bval, this);
2533 route.set_solo (bval, this);
2541 Route::ToggleControllable::get_value (void) const
2547 val = route.muted() ? 1.0f : 0.0f;
2550 val = route.soloed() ? 1.0f : 0.0f;
2560 Route::set_block_size (nframes_t nframes)
2562 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2563 (*i)->set_block_size (nframes);
2565 _session.ensure_buffers(processor_max_streams);
2569 Route::protect_automation ()
2571 Automatable::protect_automation();
2573 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
2574 (*i)->protect_automation();
2578 Route::set_pending_declick (int declick)
2581 /* this call is not allowed to turn off a pending declick unless "force" is true */
2583 _pending_declick = declick;
2585 // cerr << _name << ": after setting to " << declick << " pending declick = " << _pending_declick << endl;
2587 _pending_declick = 0;
2592 /** Shift automation forwards from a particular place, thereby inserting time.
2593 * Adds undo commands for any shifts that are performed.
2595 * @param pos Position to start shifting from.
2596 * @param frames Amount to shift forwards by.
2600 Route::shift (nframes64_t pos, nframes64_t frames)
2602 #ifdef THIS_NEEDS_FIXING_FOR_V3
2604 /* gain automation */
2605 XMLNode &before = _gain_control->get_state ();
2606 _gain_control->shift (pos, frames);
2607 XMLNode &after = _gain_control->get_state ();
2608 _session.add_command (new MementoCommand<AutomationList> (_gain_automation_curve, &before, &after));
2610 /* pan automation */
2611 for (std::vector<StreamPanner*>::iterator i = _panner->begin (); i != _panner->end (); ++i) {
2612 Curve & c = (*i)->automation ();
2613 XMLNode &before = c.get_state ();
2614 c.shift (pos, frames);
2615 XMLNode &after = c.get_state ();
2616 _session.add_command (new MementoCommand<AutomationList> (c, &before, &after));
2619 /* redirect automation */
2621 Glib::RWLock::ReaderLock lm (redirect_lock);
2622 for (RedirectList::iterator i = _redirects.begin (); i != _redirects.end (); ++i) {
2625 (*i)->what_has_automation (a);
2627 for (set<uint32_t>::const_iterator j = a.begin (); j != a.end (); ++j) {
2628 AutomationList & al = (*i)->automation_list (*j);
2629 XMLNode &before = al.get_state ();
2630 al.shift (pos, frames);
2631 XMLNode &after = al.get_state ();
2632 _session.add_command (new MementoCommand<AutomationList> (al, &before, &after));
2642 Route::save_as_template (const string& path, const string& name)
2644 XMLNode& node (state (false));
2647 IO::set_name_in_state (*node.children().front(), name);
2649 tree.set_root (&node);
2650 return tree.write (path.c_str());
2655 Route::set_name (const string& str)
2660 if ((ret = IO::set_name (str)) == true) {
2661 Glib::RWLock::ReaderLock lm (_processor_lock);
2663 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2665 /* rename all delivery objects to reflect our new name */
2667 boost::shared_ptr<Delivery> dp = boost::dynamic_pointer_cast<Delivery> (*i);
2670 string dp_name = str;
2672 dp_name += "XXX FIX ME XXX";
2675 if (!dp->set_name (dp_name)) {
2686 boost::shared_ptr<IO>
2687 Route::send_io_for (boost::shared_ptr<const IO> target) const
2689 Glib::RWLock::ReaderLock lm (_processor_lock);
2691 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2692 boost::shared_ptr<Send> send;
2694 if ((send = boost::dynamic_pointer_cast<Send>(*i)) != 0) {
2695 if (send->io()->connected_to (target)) {
2701 return boost::shared_ptr<IO>();