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.
24 #include <sigc++/bind.h>
25 #include <pbd/xml++.h>
26 #include <pbd/enumwriter.h>
28 #include <ardour/timestamps.h>
29 #include <ardour/audioengine.h>
30 #include <ardour/route.h>
31 #include <ardour/buffer.h>
32 #include <ardour/processor.h>
33 #include <ardour/plugin_insert.h>
34 #include <ardour/port_insert.h>
35 #include <ardour/send.h>
36 #include <ardour/session.h>
37 #include <ardour/utils.h>
38 #include <ardour/configuration.h>
39 #include <ardour/cycle_timer.h>
40 #include <ardour/route_group.h>
41 #include <ardour/port.h>
42 #include <ardour/audio_port.h>
43 #include <ardour/ladspa_plugin.h>
44 #include <ardour/panner.h>
45 #include <ardour/dB.h>
46 #include <ardour/amp.h>
47 #include <ardour/meter.h>
48 #include <ardour/buffer_set.h>
52 using namespace ARDOUR;
55 uint32_t Route::order_key_cnt = 0;
56 sigc::signal<void> Route::SyncOrderKeys;
58 Route::Route (Session& sess, string name, int input_min, int input_max, int output_min, int output_max, Flag flg, DataType default_type)
59 : IO (sess, name, input_min, input_max, output_min, output_max, default_type),
61 _solo_control (new ToggleControllable (X_("solo"), *this, ToggleControllable::SoloControl)),
62 _mute_control (new ToggleControllable (X_("mute"), *this, ToggleControllable::MuteControl))
67 Route::Route (Session& sess, const XMLNode& node, DataType default_type)
68 : IO (sess, *node.child ("IO"), default_type),
69 _solo_control (new ToggleControllable (X_("solo"), *this, ToggleControllable::SoloControl)),
70 _mute_control (new ToggleControllable (X_("mute"), *this, ToggleControllable::MuteControl))
73 _set_state (node, false);
79 processor_max_outs.reset();
83 _phase_invert = false;
84 _denormal_protection = false;
85 order_keys[strdup (N_("signal"))] = order_key_cnt++;
88 _meter_point = MeterPostFader;
93 _have_internal_generator = false;
95 _pending_declick = true;
96 _remote_control_id = 0;
101 _mute_affects_pre_fader = Config->get_mute_affects_pre_fader();
102 _mute_affects_post_fader = Config->get_mute_affects_post_fader();
103 _mute_affects_control_outs = Config->get_mute_affects_control_outs();
104 _mute_affects_main_outs = Config->get_mute_affects_main_outs();
107 desired_solo_gain = 1.0;
109 desired_mute_gain = 1.0;
113 input_changed.connect (mem_fun (this, &Route::input_change_handler));
114 output_changed.connect (mem_fun (this, &Route::output_change_handler));
119 clear_processors (PreFader);
120 clear_processors (PostFader);
122 for (OrderKeys::iterator i = order_keys.begin(); i != order_keys.end(); ++i) {
123 free ((void*)(i->first));
127 delete _control_outs;
132 Route::set_remote_control_id (uint32_t id)
134 if (id != _remote_control_id) {
135 _remote_control_id = id;
136 RemoteControlIDChanged ();
141 Route::remote_control_id() const
143 return _remote_control_id;
147 Route::order_key (const char* name) const
149 OrderKeys::const_iterator i;
151 for (i = order_keys.begin(); i != order_keys.end(); ++i) {
152 if (!strcmp (name, i->first)) {
161 Route::set_order_key (const char* name, long n)
163 order_keys[strdup(name)] = n;
165 if (Config->get_sync_all_route_ordering()) {
166 for (OrderKeys::iterator x = order_keys.begin(); x != order_keys.end(); ++x) {
171 _session.set_dirty ();
175 Route::sync_order_keys ()
179 if (order_keys.empty()) {
183 OrderKeys::iterator x = order_keys.begin();
187 for (; x != order_keys.end(); ++x) {
193 Route::inc_gain (gain_t fraction, void *src)
195 IO::inc_gain (fraction, src);
199 Route::set_gain (gain_t val, void *src)
201 if (src != 0 && _mix_group && src != _mix_group && _mix_group->is_active()) {
203 if (_mix_group->is_relative()) {
205 gain_t usable_gain = gain();
206 if (usable_gain < 0.000001f) {
207 usable_gain = 0.000001f;
211 if (delta < 0.000001f) {
215 delta -= usable_gain;
220 gain_t factor = delta / usable_gain;
223 factor = _mix_group->get_max_factor(factor);
224 if (factor == 0.0f) {
225 _gain_control->Changed(); /* EMIT SIGNAL */
229 factor = _mix_group->get_min_factor(factor);
230 if (factor == 0.0f) {
231 _gain_control->Changed(); /* EMIT SIGNAL */
236 _mix_group->apply (&Route::inc_gain, factor, _mix_group);
240 _mix_group->apply (&Route::set_gain, val, _mix_group);
250 IO::set_gain (val, src);
253 /** Process this route for one (sub) cycle (process thread)
255 * @param bufs Scratch buffers to use for the signal path
256 * @param start_frame Initial transport frame
257 * @param end_frame Final transport frame
258 * @param nframes Number of frames to output (to ports)
259 * @param offset Output offset (of port buffers, for split cycles)
261 * Note that (end_frame - start_frame) may not be equal to nframes when the
262 * transport speed isn't 1.0 (eg varispeed).
265 Route::process_output_buffers (BufferSet& bufs,
266 nframes_t start_frame, nframes_t end_frame,
267 nframes_t nframes, nframes_t offset, bool with_processors, int declick,
270 // This is definitely very audio-only for now
271 assert(_default_type == DataType::AUDIO);
273 ProcessorList::iterator i;
274 bool post_fader_work = false;
275 bool mute_declick_applied = false;
281 gain_t* gab = _session.gain_automation_buffer();
283 switch (Config->get_monitoring_model()) {
284 case HardwareMonitoring:
285 case ExternalMonitoring:
292 declick = _pending_declick;
295 Glib::Mutex::Lock cm (_control_outs_lock, Glib::TRY_LOCK);
305 Glib::Mutex::Lock dm (declick_lock, Glib::TRY_LOCK);
308 dmg = desired_mute_gain;
309 dsg = desired_solo_gain;
318 /* ----------------------------------------------------------------------------------------------------
319 GLOBAL DECLICK (for transport changes etc.)
320 -------------------------------------------------------------------------------------------------- */
323 Amp::run_in_place (bufs, nframes, 0.0, 1.0, false);
324 _pending_declick = 0;
325 } else if (declick < 0) {
326 Amp::run_in_place (bufs, nframes, 1.0, 0.0, false);
327 _pending_declick = 0;
330 /* no global declick */
332 if (solo_gain != dsg) {
333 Amp::run_in_place (bufs, nframes, solo_gain, dsg, false);
339 /* ----------------------------------------------------------------------------------------------------
340 INPUT METERING & MONITORING
341 -------------------------------------------------------------------------------------------------- */
343 if (meter && (_meter_point == MeterInput)) {
344 _meter->run_in_place(bufs, start_frame, end_frame, nframes, offset);
347 if (!_soloed && _mute_affects_pre_fader && (mute_gain != dmg)) {
348 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
350 mute_declick_applied = true;
353 if ((_meter_point == MeterInput) && co) {
355 solo_audible = dsg > 0;
356 mute_audible = dmg > 0;// || !_mute_affects_pre_fader;
358 if ( // muted by solo of another track
362 // muted by mute of this track
366 // rec-enabled but not s/w monitoring
368 // TODO: this is probably wrong
370 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
374 co->silence (nframes, offset);
378 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
383 /* -----------------------------------------------------------------------------------------------------
385 -------------------------------------------------------------------------------------------------- */
387 if (_denormal_protection || Config->get_denormal_protection()) {
389 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
390 Sample* const sp = i->data();
392 for (nframes_t nx = offset; nx < nframes + offset; ++nx) {
398 /* ----------------------------------------------------------------------------------------------------
400 -------------------------------------------------------------------------------------------------- */
402 if (with_processors) {
403 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
405 if (mute_gain > 0 || !_mute_affects_pre_fader) {
406 for (i = _processors.begin(); i != _processors.end(); ++i) {
407 switch ((*i)->placement()) {
409 (*i)->run_in_place (bufs, start_frame, end_frame, nframes, offset);
412 post_fader_work = true;
417 for (i = _processors.begin(); i != _processors.end(); ++i) {
418 switch ((*i)->placement()) {
420 (*i)->silence (nframes, offset);
423 post_fader_work = true;
431 // This really should already be true...
432 bufs.set_count(pre_fader_streams());
434 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_post_fader) {
435 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
437 mute_declick_applied = true;
440 /* ----------------------------------------------------------------------------------------------------
441 PRE-FADER METERING & MONITORING
442 -------------------------------------------------------------------------------------------------- */
444 if (meter && (_meter_point == MeterPreFader)) {
445 _meter->run_in_place(bufs, start_frame, end_frame, nframes, offset);
449 if ((_meter_point == MeterPreFader) && co) {
451 solo_audible = dsg > 0;
452 mute_audible = dmg > 0 || !_mute_affects_pre_fader;
454 if ( // muted by solo of another track
458 // muted by mute of this track
462 // rec-enabled but not s/w monitoring
464 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
468 co->silence (nframes, offset);
472 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
476 /* ----------------------------------------------------------------------------------------------------
478 -------------------------------------------------------------------------------------------------- */
480 /* if not recording or recording and requiring any monitor signal, then apply gain */
482 if ( // not recording
484 !(record_enabled() && _session.actively_recording()) ||
488 // AND software monitoring required
490 Config->get_monitoring_model() == SoftwareMonitoring) {
492 if (apply_gain_automation) {
495 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
496 Sample* const sp = i->data();
498 for (nframes_t nx = 0; nx < nframes; ++nx) {
503 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
504 Sample* const sp = i->data();
506 for (nframes_t nx = 0; nx < nframes; ++nx) {
512 if (apply_gain_automation && _session.transport_rolling() && nframes > 0) {
513 _effective_gain = gab[nframes-1];
518 /* manual (scalar) gain */
522 Amp::run_in_place (bufs, nframes, _gain, dg, _phase_invert);
525 } else if (_gain != 0 && (_phase_invert || _gain != 1.0)) {
527 /* no need to interpolate current gain value,
528 but its non-unity, so apply it. if the gain
529 is zero, do nothing because we'll ship silence
541 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
542 Sample* const sp = i->data();
543 apply_gain_to_buffer(sp,nframes,this_gain);
546 } else if (_gain == 0) {
547 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
555 /* actively recording, no monitoring required; leave buffers as-is to save CPU cycles */
559 /* ----------------------------------------------------------------------------------------------------
561 -------------------------------------------------------------------------------------------------- */
563 /* note that post_fader_work cannot be true unless with_processors was also true, so don't test both */
565 if (post_fader_work) {
567 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
569 if (mute_gain > 0 || !_mute_affects_post_fader) {
570 for (i = _processors.begin(); i != _processors.end(); ++i) {
571 switch ((*i)->placement()) {
575 (*i)->run_in_place (bufs, start_frame, end_frame, nframes, offset);
580 for (i = _processors.begin(); i != _processors.end(); ++i) {
581 switch ((*i)->placement()) {
585 (*i)->silence (nframes, offset);
593 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_control_outs) {
594 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
596 mute_declick_applied = true;
599 /* ----------------------------------------------------------------------------------------------------
601 -------------------------------------------------------------------------------------------------- */
603 if ((_meter_point == MeterPostFader) && co) {
605 solo_audible = solo_gain > 0;
606 mute_audible = dmg > 0 || !_mute_affects_control_outs;
608 if ( // silent anyway
610 (_gain == 0 && !apply_gain_automation) ||
612 // muted by solo of another track
616 // muted by mute of this track
620 // recording but not s/w monitoring
622 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
626 co->silence (nframes, offset);
630 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
634 /* ----------------------------------------------------------------------
636 ----------------------------------------------------------------------*/
638 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_main_outs) {
639 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
641 mute_declick_applied = true;
644 /* ----------------------------------------------------------------------------------------------------
646 -------------------------------------------------------------------------------------------------- */
648 solo_audible = dsg > 0;
649 mute_audible = dmg > 0 || !_mute_affects_main_outs;
651 if (n_outputs().get(_default_type) == 0) {
655 } else if (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording())) {
657 IO::silence (nframes, offset);
661 if ( // silent anyway
663 (_gain == 0 && !apply_gain_automation) ||
665 // muted by solo of another track, but not using control outs for solo
667 (!solo_audible && (Config->get_solo_model() != SoloBus)) ||
669 // muted by mute of this track
675 /* don't use Route::silence() here, because that causes
676 all outputs (sends, port processors, etc. to be silent).
679 if (_meter_point == MeterPostFader) {
680 peak_meter().reset();
683 IO::silence (nframes, offset);
687 deliver_output(bufs, start_frame, end_frame, nframes, offset);
693 /* ----------------------------------------------------------------------------------------------------
695 -------------------------------------------------------------------------------------------------- */
697 if (meter && (_meter_point == MeterPostFader)) {
698 if ((_gain == 0 && !apply_gain_automation) || dmg == 0) {
701 _meter->run_in_place(output_buffers(), start_frame, end_frame, nframes, offset);
707 Route::n_process_buffers ()
709 return max (n_inputs(), processor_max_outs);
713 Route::passthru (nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset, int declick, bool meter_first)
715 BufferSet& bufs = _session.get_scratch_buffers(n_process_buffers());
719 collect_input (bufs, nframes, offset);
722 _meter->run_in_place(bufs, start_frame, end_frame, nframes, offset);
726 process_output_buffers (bufs, start_frame, end_frame, nframes, offset, true, declick, meter_first);
730 Route::passthru_silence (nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset, int declick, bool meter)
732 process_output_buffers (_session.get_silent_buffers (n_process_buffers()), start_frame, end_frame, nframes, offset, true, declick, meter);
736 Route::set_solo (bool yn, void *src)
742 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
743 _mix_group->apply (&Route::set_solo, yn, _mix_group);
749 solo_changed (src); /* EMIT SIGNAL */
750 _solo_control->Changed (); /* EMIT SIGNAL */
755 Route::set_solo_mute (bool yn)
757 Glib::Mutex::Lock lm (declick_lock);
759 /* Called by Session in response to another Route being soloed.
762 desired_solo_gain = (yn?0.0:1.0);
766 Route::set_solo_safe (bool yn, void *src)
768 if (_solo_safe != yn) {
770 solo_safe_changed (src); /* EMIT SIGNAL */
775 Route::set_mute (bool yn, void *src)
778 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
779 _mix_group->apply (&Route::set_mute, yn, _mix_group);
785 mute_changed (src); /* EMIT SIGNAL */
787 _mute_control->Changed (); /* EMIT SIGNAL */
789 Glib::Mutex::Lock lm (declick_lock);
790 desired_mute_gain = (yn?0.0f:1.0f);
795 Route::add_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err)
797 ChanCount old_rmo = processor_max_outs;
799 if (!_session.engine().connected()) {
804 Glib::RWLock::WriterLock lm (_processor_lock);
806 boost::shared_ptr<PluginInsert> pi;
807 boost::shared_ptr<PortInsert> porti;
809 //processor->set_default_type(_default_type);
811 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
814 if (pi->natural_input_streams() == ChanCount::ZERO) {
815 /* generator plugin */
816 _have_internal_generator = true;
821 _processors.push_back (processor);
823 // Set up processor list channels. This will set processor->[input|output]_streams(),
824 // configure redirect ports properly, etc.
825 if (_reset_plugin_counts (err)) {
826 _processors.pop_back ();
827 _reset_plugin_counts (0); // it worked before we tried to add it ...
831 // Ensure peak vector sizes before the plugin is activated
832 ChanCount potential_max_streams = max(processor->input_streams(), processor->output_streams());
833 _meter->configure_io(potential_max_streams, potential_max_streams);
835 processor->activate ();
836 processor->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
841 if (processor_max_outs != old_rmo || old_rmo == ChanCount::ZERO) {
846 processors_changed (); /* EMIT SIGNAL */
851 Route::add_processors (const ProcessorList& others, ProcessorStreams* err)
853 ChanCount old_rmo = processor_max_outs;
855 if (!_session.engine().connected()) {
860 Glib::RWLock::WriterLock lm (_processor_lock);
862 ProcessorList::iterator existing_end = _processors.end();
865 ChanCount potential_max_streams;
867 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
869 boost::shared_ptr<PluginInsert> pi;
871 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
874 ChanCount m = max(pi->input_streams(), pi->output_streams());
875 if (m > potential_max_streams)
876 potential_max_streams = m;
879 // Ensure peak vector sizes before the plugin is activated
880 _meter->configure_io(potential_max_streams, potential_max_streams);
882 _processors.push_back (*i);
884 if (_reset_plugin_counts (err)) {
886 _processors.erase (existing_end, _processors.end());
887 _reset_plugin_counts (0); // it worked before we tried to add it ...
892 (*i)->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
898 if (processor_max_outs != old_rmo || old_rmo == ChanCount::ZERO) {
902 processors_changed (); /* EMIT SIGNAL */
906 /** Turn off all processors with a given placement
907 * @param p Placement of processors to disable
911 Route::disable_processors (Placement p)
913 Glib::RWLock::ReaderLock lm (_processor_lock);
915 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
916 if ((*i)->placement() == p) {
917 (*i)->set_active (false);
921 _session.set_dirty ();
924 /** Turn off all redirects
928 Route::disable_processors ()
930 Glib::RWLock::ReaderLock lm (_processor_lock);
932 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
933 (*i)->set_active (false);
936 _session.set_dirty ();
939 /** Turn off all redirects with a given placement
940 * @param p Placement of redirects to disable
944 Route::disable_plugins (Placement p)
946 Glib::RWLock::ReaderLock lm (_processor_lock);
948 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
949 if (boost::dynamic_pointer_cast<PluginInsert> (*i) && (*i)->placement() == p) {
950 (*i)->set_active (false);
954 _session.set_dirty ();
957 /** Turn off all plugins
961 Route::disable_plugins ()
963 Glib::RWLock::ReaderLock lm (_processor_lock);
965 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
966 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
967 (*i)->set_active (false);
971 _session.set_dirty ();
976 Route::ab_plugins (bool forward)
978 Glib::RWLock::ReaderLock lm (_processor_lock);
982 /* forward = turn off all active redirects, and mark them so that the next time
983 we go the other way, we will revert them
986 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
987 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
991 if ((*i)->active()) {
992 (*i)->set_active (false);
993 (*i)->set_next_ab_is_active (true);
995 (*i)->set_next_ab_is_active (false);
1001 /* backward = if the redirect was marked to go active on the next ab, do so */
1003 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1005 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1009 if ((*i)->get_next_ab_is_active()) {
1010 (*i)->set_active (true);
1012 (*i)->set_active (false);
1017 _session.set_dirty ();
1021 /* Figure out the streams that will feed into PreFader */
1023 Route::pre_fader_streams() const
1025 boost::shared_ptr<Processor> processor;
1027 // Find the last pre-fader redirect
1028 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1029 if ((*i)->placement() == PreFader) {
1035 return processor->output_streams();
1042 /** Remove processors with a given placement.
1043 * @param p Placement of processors to remove.
1046 Route::clear_processors (Placement p)
1048 const ChanCount old_rmo = processor_max_outs;
1050 if (!_session.engine().connected()) {
1055 Glib::RWLock::WriterLock lm (_processor_lock);
1056 ProcessorList new_list;
1058 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1059 if ((*i)->placement() == p) {
1060 /* it's the placement we want to get rid of */
1061 (*i)->drop_references ();
1063 /* it's a different placement, so keep it */
1064 new_list.push_back (*i);
1068 _processors = new_list;
1071 /* FIXME: can't see how this test can ever fire */
1072 if (processor_max_outs != old_rmo) {
1076 processor_max_outs.reset();
1077 _have_internal_generator = false;
1078 processors_changed (); /* EMIT SIGNAL */
1082 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err)
1084 ChanCount old_rmo = processor_max_outs;
1086 if (!_session.engine().connected()) {
1090 processor_max_outs.reset();
1093 Glib::RWLock::WriterLock lm (_processor_lock);
1094 ProcessorList::iterator i;
1095 bool removed = false;
1097 for (i = _processors.begin(); i != _processors.end(); ++i) {
1098 if (*i == processor) {
1100 ProcessorList::iterator tmp;
1102 /* move along, see failure case for reset_plugin_counts()
1103 where we may need to reprocessor the processor.
1109 /* stop redirects that send signals to JACK ports
1110 from causing noise as a result of no longer being
1114 boost::shared_ptr<IOProcessor> redirect;
1116 if ((redirect = boost::dynamic_pointer_cast<IOProcessor> (*i)) != 0) {
1117 redirect->io()->disconnect_inputs (this);
1118 redirect->io()->disconnect_outputs (this);
1121 _processors.erase (i);
1136 if (_reset_plugin_counts (err)) {
1137 /* get back to where we where */
1138 _processors.insert (i, processor);
1139 /* we know this will work, because it worked before :) */
1140 _reset_plugin_counts (0);
1146 for (i = _processors.begin(); i != _processors.end(); ++i) {
1147 boost::shared_ptr<PluginInsert> pi;
1149 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1150 if (pi->is_generator()) {
1156 _have_internal_generator = foo;
1159 if (old_rmo != processor_max_outs) {
1163 processor->drop_references ();
1165 processors_changed (); /* EMIT SIGNAL */
1170 Route::reset_plugin_counts (ProcessorStreams* err)
1172 Glib::RWLock::WriterLock lm (_processor_lock);
1173 return _reset_plugin_counts (err);
1178 Route::_reset_plugin_counts (ProcessorStreams* err)
1180 ProcessorList::iterator r;
1181 map<Placement,list<ProcessorCount> > processor_map;
1182 ChanCount initial_streams;
1184 /* Process each placement in order, checking to see if we
1185 can really do what has been requested.
1188 /* divide processors up by placement so we get the signal flow
1189 properly modelled. we need to do this because the _processors
1190 list is not sorted by placement
1193 /* ... but it should/will be... */
1195 for (r = _processors.begin(); r != _processors.end(); ++r) {
1197 boost::shared_ptr<Processor> processor;
1199 if ((processor = boost::dynamic_pointer_cast<Processor>(*r)) != 0) {
1200 processor_map[processor->placement()].push_back (ProcessorCount (processor));
1207 if ( ! check_some_plugin_counts (processor_map[PreFader], n_inputs (), err)) {
1211 ChanCount post_fader_input = (err ? err->count : n_inputs());
1215 if ( ! check_some_plugin_counts (processor_map[PostFader], post_fader_input, err)) {
1219 /* OK, everything can be set up correctly, so lets do it */
1221 apply_some_plugin_counts (processor_map[PreFader]);
1222 apply_some_plugin_counts (processor_map[PostFader]);
1224 /* recompute max outs of any processor */
1226 processor_max_outs.reset();
1227 ProcessorList::iterator prev = _processors.end();
1229 for (r = _processors.begin(); r != _processors.end(); prev = r, ++r) {
1230 processor_max_outs = max ((*r)->output_streams (), processor_max_outs);
1239 Route::apply_some_plugin_counts (list<ProcessorCount>& iclist)
1241 list<ProcessorCount>::iterator i;
1243 for (i = iclist.begin(); i != iclist.end(); ++i) {
1245 cerr << "now applying for " << (*i).processor->name() << " in = " << (*i).in.n_audio() << " out = " << (*i).out.n_audio() << endl;
1247 if ((*i).processor->configure_io ((*i).in, (*i).out)) {
1250 /* make sure that however many we have, they are all active */
1251 (*i).processor->activate ();
1257 /** Returns whether \a iclist can be configured and run starting with
1258 * \a required_inputs at the first processor's inputs.
1259 * If false is returned, \a iclist can not be run with \a required_inputs, and \a err is set.
1260 * Otherwise, \a err is set to the output of the list.
1263 Route::check_some_plugin_counts (list<ProcessorCount>& iclist, ChanCount required_inputs, ProcessorStreams* err)
1265 list<ProcessorCount>::iterator i;
1270 err->count = required_inputs;
1273 for (i = iclist.begin(); i != iclist.end(); ++i) {
1276 cerr << "Checking whether " << (*i).processor->name() << " can support " << required_inputs.n_audio() << " inputs\n";
1278 if ((*i).processor->can_support_input_configuration (required_inputs) < 0) {
1281 err->count = required_inputs;
1286 (*i).in = required_inputs;
1287 (*i).out = (*i).processor->output_for_input_configuration (required_inputs);
1289 cerr << "config looks like " << (*i).processor->name() << " in = " << (*i).in.n_audio() << " out = " << (*i).out.n_audio() << endl;
1291 required_inputs = (*i).out;
1297 if (!iclist.empty()) {
1299 err->count = iclist.back().processor->output_for_input_configuration(required_inputs);
1307 Route::copy_processors (const Route& other, Placement placement, ProcessorStreams* err)
1309 ChanCount old_rmo = processor_max_outs;
1311 ProcessorList to_be_deleted;
1314 Glib::RWLock::WriterLock lm (_processor_lock);
1315 ProcessorList::iterator tmp;
1316 ProcessorList the_copy;
1318 the_copy = _processors;
1320 /* remove all relevant processors */
1322 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ) {
1326 if ((*i)->placement() == placement) {
1327 to_be_deleted.push_back (*i);
1328 _processors.erase (i);
1334 /* now copy the relevant ones from "other" */
1336 for (ProcessorList::const_iterator i = other._processors.begin(); i != other._processors.end(); ++i) {
1337 if ((*i)->placement() == placement) {
1338 _processors.push_back (IOProcessor::clone (*i));
1342 /* reset plugin stream handling */
1344 if (_reset_plugin_counts (err)) {
1346 /* FAILED COPY ATTEMPT: we have to restore order */
1348 /* delete all cloned processors */
1350 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ) {
1355 if ((*i)->placement() == placement) {
1356 _processors.erase (i);
1362 /* restore the natural order */
1364 _processors = the_copy;
1365 processor_max_outs = old_rmo;
1367 /* we failed, even though things are OK again */
1373 /* SUCCESSFUL COPY ATTEMPT: delete the processors we removed pre-copy */
1374 to_be_deleted.clear ();
1379 if (processor_max_outs != old_rmo || old_rmo == ChanCount::ZERO) {
1383 processors_changed (); /* EMIT SIGNAL */
1388 Route::all_processors_flip ()
1390 Glib::RWLock::ReaderLock lm (_processor_lock);
1392 if (_processors.empty()) {
1396 bool first_is_on = _processors.front()->active();
1398 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1399 (*i)->set_active (!first_is_on);
1402 _session.set_dirty ();
1405 /** Set all processors with a given placement to a given active state.
1406 * @param p Placement of processors to change.
1407 * @param state New active state for those processors.
1410 Route::all_processors_active (Placement p, bool state)
1412 Glib::RWLock::ReaderLock lm (_processor_lock);
1414 if (_processors.empty()) {
1418 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1419 if ((*i)->placement() == p) {
1420 (*i)->set_active (state);
1424 _session.set_dirty ();
1427 struct ProcessorSorter {
1428 bool operator() (boost::shared_ptr<const Processor> a, boost::shared_ptr<const Processor> b) {
1429 return a->sort_key() < b->sort_key();
1434 Route::sort_processors (ProcessorStreams* err)
1437 ProcessorSorter comparator;
1438 Glib::RWLock::WriterLock lm (_processor_lock);
1439 ChanCount old_rmo = processor_max_outs;
1441 /* the sweet power of C++ ... */
1443 ProcessorList as_it_was_before = _processors;
1445 _processors.sort (comparator);
1447 if (_reset_plugin_counts (err)) {
1448 _processors = as_it_was_before;
1449 processor_max_outs = old_rmo;
1455 processors_changed (); /* EMIT SIGNAL */
1467 Route::get_template()
1469 return state(false);
1473 Route::state(bool full_state)
1475 XMLNode *node = new XMLNode("Route");
1476 ProcessorList::iterator i;
1480 node->add_property("flags", enum_2_string (_flags));
1483 node->add_property("default-type", _default_type.to_string());
1485 node->add_property("active", _active?"yes":"no");
1486 node->add_property("muted", _muted?"yes":"no");
1487 node->add_property("soloed", _soloed?"yes":"no");
1488 node->add_property("phase-invert", _phase_invert?"yes":"no");
1489 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
1490 node->add_property("mute-affects-pre-fader", _mute_affects_pre_fader?"yes":"no");
1491 node->add_property("mute-affects-post-fader", _mute_affects_post_fader?"yes":"no");
1492 node->add_property("mute-affects-control-outs", _mute_affects_control_outs?"yes":"no");
1493 node->add_property("mute-affects-main-outs", _mute_affects_main_outs?"yes":"no");
1496 node->add_property("edit-group", _edit_group->name());
1499 node->add_property("mix-group", _mix_group->name());
1502 string order_string;
1503 OrderKeys::iterator x = order_keys.begin();
1505 while (x != order_keys.end()) {
1506 order_string += string ((*x).first);
1507 order_string += '=';
1508 snprintf (buf, sizeof(buf), "%ld", (*x).second);
1509 order_string += buf;
1513 if (x == order_keys.end()) {
1517 order_string += ':';
1519 node->add_property ("order-keys", order_string);
1521 node->add_child_nocopy (IO::state (full_state));
1522 node->add_child_nocopy (_solo_control->get_state ());
1523 node->add_child_nocopy (_mute_control->get_state ());
1525 XMLNode* remote_control_node = new XMLNode (X_("remote_control"));
1526 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
1527 remote_control_node->add_property (X_("id"), buf);
1528 node->add_child_nocopy (*remote_control_node);
1530 if (_control_outs) {
1531 XMLNode* cnode = new XMLNode (X_("ControlOuts"));
1532 cnode->add_child_nocopy (_control_outs->state (full_state));
1533 node->add_child_nocopy (*cnode);
1536 if (_comment.length()) {
1537 XMLNode *cmt = node->add_child ("Comment");
1538 cmt->add_content (_comment);
1541 for (i = _processors.begin(); i != _processors.end(); ++i) {
1542 node->add_child_nocopy((*i)->state (full_state));
1546 node->add_child_copy (*_extra_xml);
1553 Route::get_processor_state ()
1555 XMLNode* root = new XMLNode (X_("redirects"));
1556 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1557 root->add_child_nocopy ((*i)->state (true));
1564 Route::set_processor_state (const XMLNode& root)
1566 if (root.name() != X_("redirects")) {
1572 XMLNodeConstIterator iter;
1573 XMLNodeConstIterator niter;
1574 Glib::RWLock::ReaderLock lm (_processor_lock);
1576 nlist = root.children();
1578 for (iter = nlist.begin(); iter != nlist.end(); ++iter){
1580 /* iter now points to a IOProcessor state node */
1582 nnlist = (*iter)->children ();
1584 for (niter = nnlist.begin(); niter != nnlist.end(); ++niter) {
1586 /* find the IO child node, since it contains the ID we need */
1588 /* XXX OOP encapsulation violation, ugh */
1590 if ((*niter)->name() == IO::state_node_name) {
1592 XMLProperty* prop = (*niter)->property (X_("id"));
1595 warning << _("IOProcessor node has no ID, ignored") << endmsg;
1599 ID id = prop->value ();
1601 /* now look for a processor with that ID */
1603 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1604 if ((*i)->id() == id) {
1605 (*i)->set_state (**iter);
1621 Route::set_deferred_state ()
1624 XMLNodeConstIterator niter;
1626 if (!deferred_state) {
1630 nlist = deferred_state->children();
1632 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1633 add_processor_from_xml (**niter);
1636 delete deferred_state;
1641 Route::add_processor_from_xml (const XMLNode& node)
1643 const XMLProperty *prop;
1645 // legacy sessions use a different node name for sends
1646 if (node.name() == "Send") {
1649 boost::shared_ptr<Send> send (new Send (_session, node));
1650 add_processor (send);
1653 catch (failed_constructor &err) {
1654 error << _("Send construction failed") << endmsg;
1658 // use "Processor" in XML?
1659 } else if (node.name() == "Processor") {
1662 if ((prop = node.property ("type")) != 0) {
1664 boost::shared_ptr<Processor> processor;
1666 if (prop->value() == "ladspa" || prop->value() == "Ladspa" || prop->value() == "vst") {
1668 processor.reset (new PluginInsert(_session, node));
1670 } else if (prop->value() == "port") {
1672 processor.reset (new PortInsert (_session, node));
1674 } else if (prop->value() == "send") {
1676 processor.reset (new Send (_session, node));
1680 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
1683 add_processor (processor);
1686 error << _("Processor XML node has no type property") << endmsg;
1690 catch (failed_constructor &err) {
1691 warning << _("processor could not be created. Ignored.") << endmsg;
1698 Route::set_state (const XMLNode& node)
1700 return _set_state (node, true);
1704 Route::_set_state (const XMLNode& node, bool call_base)
1707 XMLNodeConstIterator niter;
1709 XMLPropertyList plist;
1710 const XMLProperty *prop;
1712 if (node.name() != "Route"){
1713 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
1717 if ((prop = node.property (X_("flags"))) != 0) {
1718 _flags = Flag (string_2_enum (prop->value(), _flags));
1723 if ((prop = node.property (X_("default-type"))) != 0) {
1724 _default_type = DataType(prop->value());
1725 assert(_default_type != DataType::NIL);
1728 if ((prop = node.property (X_("phase-invert"))) != 0) {
1729 set_phase_invert (prop->value()=="yes"?true:false, this);
1732 if ((prop = node.property (X_("denormal-protection"))) != 0) {
1733 set_denormal_protection (prop->value()=="yes"?true:false, this);
1736 if ((prop = node.property (X_("active"))) != 0) {
1737 set_active (prop->value() == "yes");
1740 if ((prop = node.property (X_("muted"))) != 0) {
1741 bool yn = prop->value()=="yes"?true:false;
1743 /* force reset of mute status */
1747 mute_gain = desired_mute_gain;
1750 if ((prop = node.property (X_("soloed"))) != 0) {
1751 bool yn = prop->value()=="yes"?true:false;
1753 /* force reset of solo status */
1756 set_solo (yn, this);
1757 solo_gain = desired_solo_gain;
1760 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
1761 _mute_affects_pre_fader = (prop->value()=="yes")?true:false;
1764 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
1765 _mute_affects_post_fader = (prop->value()=="yes")?true:false;
1768 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
1769 _mute_affects_control_outs = (prop->value()=="yes")?true:false;
1772 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
1773 _mute_affects_main_outs = (prop->value()=="yes")?true:false;
1776 if ((prop = node.property (X_("edit-group"))) != 0) {
1777 RouteGroup* edit_group = _session.edit_group_by_name(prop->value());
1778 if(edit_group == 0) {
1779 error << string_compose(_("Route %1: unknown edit group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
1781 set_edit_group(edit_group, this);
1785 if ((prop = node.property (X_("order-keys"))) != 0) {
1789 string::size_type colon, equal;
1790 string remaining = prop->value();
1792 while (remaining.length()) {
1794 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
1795 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1798 if (sscanf (remaining.substr (equal+1).c_str(), "%ld", &n) != 1) {
1799 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1802 set_order_key (remaining.substr (0, equal).c_str(), n);
1806 colon = remaining.find_first_of (':');
1808 if (colon != string::npos) {
1809 remaining = remaining.substr (colon+1);
1816 nlist = node.children();
1818 if (deferred_state) {
1819 delete deferred_state;
1822 deferred_state = new XMLNode(X_("deferred state"));
1824 /* set parent class properties before anything else */
1826 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1830 if (child->name() == IO::state_node_name && call_base) {
1832 IO::set_state (*child);
1837 XMLNodeList processor_nodes;
1839 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1843 if (child->name() == X_("Send") || child->name() == X_("Processor")) {
1844 processor_nodes.push_back(child);
1849 _set_processor_states(processor_nodes);
1852 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1854 // All processors have been applied already
1856 if (child->name() == X_("Automation")) {
1858 if ((prop = child->property (X_("path"))) != 0) {
1859 load_automation (prop->value());
1862 } else if (child->name() == X_("ControlOuts")) {
1864 string coutname = _name;
1865 coutname += _("[control]");
1867 _control_outs = new IO (_session, coutname);
1868 _control_outs->set_state (**(child->children().begin()));
1870 } else if (child->name() == X_("Comment")) {
1872 /* XXX this is a terrible API design in libxml++ */
1874 XMLNode *cmt = *(child->children().begin());
1875 _comment = cmt->content();
1877 } else if (child->name() == X_("extra")) {
1879 _extra_xml = new XMLNode (*child);
1881 } else if (child->name() == X_("controllable") && (prop = child->property("name")) != 0) {
1883 if (prop->value() == "solo") {
1884 _solo_control->set_state (*child);
1885 _session.add_controllable (_solo_control);
1887 else if (prop->value() == "mute") {
1888 _mute_control->set_state (*child);
1889 _session.add_controllable (_mute_control);
1892 else if (child->name() == X_("remote_control")) {
1893 if ((prop = child->property (X_("id"))) != 0) {
1895 sscanf (prop->value().c_str(), "%d", &x);
1896 set_remote_control_id (x);
1901 if ((prop = node.property (X_("mix-group"))) != 0) {
1902 RouteGroup* mix_group = _session.mix_group_by_name(prop->value());
1903 if (mix_group == 0) {
1904 error << string_compose(_("Route %1: unknown mix group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
1906 set_mix_group(mix_group, this);
1914 Route::_set_processor_states(const XMLNodeList &nlist)
1916 XMLNodeConstIterator niter;
1919 ProcessorList::iterator i, o;
1921 // Iterate through existing processors, remove those which are not in the state list
1922 for (i = _processors.begin(); i != _processors.end(); ) {
1923 ProcessorList::iterator tmp = i;
1926 bool processorInStateList = false;
1928 (*i)->id().print (buf, sizeof (buf));
1931 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1933 // legacy sessions (IOProcessor as a child of Processor, both is-a IO)
1934 if (strncmp(buf,(*niter)->child(X_("IOProcessor"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf)) == 0) {
1935 processorInStateList = true;
1937 } else if (strncmp(buf,(*niter)->property(X_("id"))->value().c_str(), sizeof(buf)) == 0) {
1938 processorInStateList = true;
1943 if (!processorInStateList) {
1944 remove_processor (*i);
1952 // Iterate through state list and make sure all processors are on the track and in the correct order,
1953 // set the state of existing processors according to the new state on the same go
1954 i = _processors.begin();
1955 for (niter = nlist.begin(); niter != nlist.end(); ++niter, ++i) {
1957 // Check whether the next processor in the list
1960 while (o != _processors.end()) {
1961 (*o)->id().print (buf, sizeof (buf));
1962 if ( strncmp(buf, (*niter)->child(X_("IOProcessor"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf)) == 0)
1964 else if (strncmp(buf,(*niter)->property(X_("id"))->value().c_str(), sizeof(buf)) == 0)
1970 if (o == _processors.end()) {
1971 // If the processor (*niter) is not on the route, we need to create it
1972 // and move it to the correct location
1974 ProcessorList::iterator prev_last = _processors.end();
1975 --prev_last; // We need this to check whether adding succeeded
1977 add_processor_from_xml (**niter);
1979 ProcessorList::iterator last = _processors.end();
1982 if (prev_last == last) {
1983 cerr << "Could not fully restore state as some processors were not possible to create" << endl;
1988 boost::shared_ptr<Processor> tmp = (*last);
1989 // remove the processor from the wrong location
1990 _processors.erase(last);
1991 // processor the new processor at the current location
1992 _processors.insert(i, tmp);
1994 --i; // move pointer to the newly processored processor
1998 // We found the processor (*niter) on the route, first we must make sure the processor
1999 // is at the location provided in the XML state
2001 boost::shared_ptr<Processor> tmp = (*o);
2002 // remove the old copy
2003 _processors.erase(o);
2004 // processor the processor at the correct location
2005 _processors.insert(i, tmp);
2007 --i; // move pointer so it points to the right processor
2010 (*i)->set_state( (**niter) );
2013 processors_changed ();
2017 Route::curve_reallocate ()
2019 // _gain_automation_curve.finish_resize ();
2020 // _pan_automation_curve.finish_resize ();
2024 Route::silence (nframes_t nframes, nframes_t offset)
2028 IO::silence (nframes, offset);
2030 if (_control_outs) {
2031 _control_outs->silence (nframes, offset);
2035 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2038 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2039 boost::shared_ptr<PluginInsert> pi;
2040 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2041 // skip plugins, they don't need anything when we're not active
2045 (*i)->silence (nframes, offset);
2048 if (nframes == _session.get_block_size() && offset == 0) {
2058 Route::set_control_outs (const vector<string>& ports)
2060 Glib::Mutex::Lock lm (_control_outs_lock);
2061 vector<string>::const_iterator i;
2064 if (_control_outs) {
2065 delete _control_outs;
2069 if (is_control() || is_master()) {
2070 /* no control outs for these two special busses */
2074 if (ports.empty()) {
2078 string coutname = _name;
2079 coutname += _("[control]");
2081 _control_outs = new IO (_session, coutname);
2083 /* our control outs need as many outputs as we
2084 have audio outputs. we track the changes in ::output_change_handler().
2087 // XXX its stupid that we have to get this value twice
2089 limit = n_outputs().n_audio();
2091 if (_control_outs->ensure_io (ChanCount::ZERO, ChanCount (DataType::AUDIO, n_outputs().get (DataType::AUDIO)), true, this)) {
2095 /* now connect to the named ports */
2097 for (size_t n = 0; n < limit; ++n) {
2098 if (_control_outs->connect_output (_control_outs->output (n), ports[n % ports.size()], this)) {
2099 error << string_compose (_("could not connect %1 to %2"), _control_outs->output(n)->name(), ports[n]) << endmsg;
2108 Route::set_edit_group (RouteGroup *eg, void *src)
2111 if (eg == _edit_group) {
2116 _edit_group->remove (this);
2119 if ((_edit_group = eg) != 0) {
2120 _edit_group->add (this);
2123 _session.set_dirty ();
2124 edit_group_changed (src); /* EMIT SIGNAL */
2128 Route::drop_edit_group (void *src)
2131 _session.set_dirty ();
2132 edit_group_changed (src); /* EMIT SIGNAL */
2136 Route::set_mix_group (RouteGroup *mg, void *src)
2139 if (mg == _mix_group) {
2144 _mix_group->remove (this);
2147 if ((_mix_group = mg) != 0) {
2148 _mix_group->add (this);
2151 _session.set_dirty ();
2152 mix_group_changed (src); /* EMIT SIGNAL */
2156 Route::drop_mix_group (void *src)
2159 _session.set_dirty ();
2160 mix_group_changed (src); /* EMIT SIGNAL */
2164 Route::set_comment (string cmt, void *src)
2167 comment_changed (src);
2168 _session.set_dirty ();
2172 Route::feeds (boost::shared_ptr<Route> other)
2177 uint32_t no = self.n_outputs().n_total();
2178 uint32_t ni = other->n_inputs ().n_total();
2180 for (i = 0; i < no; ++i) {
2181 for (j = 0; j < ni; ++j) {
2182 if (self.output(i)->connected_to (other->input(j)->name())) {
2188 /* check IOProcessors which may also interconnect Routes */
2190 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); r++) {
2192 boost::shared_ptr<IOProcessor> redirect = boost::dynamic_pointer_cast<IOProcessor>(*r);
2197 // TODO: support internal redirects here
2199 no = redirect->io()->n_outputs().n_total();
2201 for (i = 0; i < no; ++i) {
2202 for (j = 0; j < ni; ++j) {
2203 if (redirect->io()->output(i)->connected_to (other->input (j)->name())) {
2210 /* check for control room outputs which may also interconnect Routes */
2212 if (_control_outs) {
2214 no = _control_outs->n_outputs().n_total();
2216 for (i = 0; i < no; ++i) {
2217 for (j = 0; j < ni; ++j) {
2218 if (_control_outs->output(i)->connected_to (other->input (j)->name())) {
2229 Route::set_mute_config (mute_type t, bool onoff, void *src)
2233 _mute_affects_pre_fader = onoff;
2234 pre_fader_changed(src); /* EMIT SIGNAL */
2238 _mute_affects_post_fader = onoff;
2239 post_fader_changed(src); /* EMIT SIGNAL */
2243 _mute_affects_control_outs = onoff;
2244 control_outs_changed(src); /* EMIT SIGNAL */
2248 _mute_affects_main_outs = onoff;
2249 main_outs_changed(src); /* EMIT SIGNAL */
2255 Route::get_mute_config (mute_type t)
2261 onoff = _mute_affects_pre_fader;
2264 onoff = _mute_affects_post_fader;
2267 onoff = _mute_affects_control_outs;
2270 onoff = _mute_affects_main_outs;
2278 Route::set_active (bool yn)
2281 active_changed(); /* EMIT SIGNAL */
2285 Route::handle_transport_stopped (bool abort_ignored, bool did_locate, bool can_flush_processors)
2287 nframes_t now = _session.transport_frame();
2290 Glib::RWLock::ReaderLock lm (_processor_lock);
2293 automation_snapshot (now);
2296 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2298 if (Config->get_plugins_stop_with_transport() && can_flush_processors) {
2299 (*i)->deactivate ();
2303 (*i)->transport_stopped (now);
2307 IO::transport_stopped (now);
2309 _roll_delay = _initial_delay;
2313 Route::input_change_handler (IOChange change, void *ignored)
2315 if (change & ConfigurationChanged) {
2316 reset_plugin_counts (0);
2321 Route::output_change_handler (IOChange change, void *ignored)
2323 if (change & ConfigurationChanged) {
2324 if (_control_outs) {
2325 _control_outs->ensure_io (ChanCount::ZERO, ChanCount(DataType::AUDIO, n_outputs().n_audio()), true, this);
2328 reset_plugin_counts (0);
2333 Route::pans_required () const
2335 if (n_outputs().n_audio() < 2) {
2339 return max (n_inputs ().n_audio(), processor_max_outs.n_audio());
2343 Route::no_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
2344 bool session_state_changing, bool can_record, bool rec_monitors_input)
2346 if (n_outputs().n_total() == 0) {
2350 if (session_state_changing || !_active) {
2351 silence (nframes, offset);
2355 apply_gain_automation = false;
2357 if (n_inputs().n_total()) {
2358 passthru (start_frame, end_frame, nframes, offset, 0, false);
2360 silence (nframes, offset);
2367 Route::check_initial_delay (nframes_t nframes, nframes_t& offset, nframes_t& transport_frame)
2369 if (_roll_delay > nframes) {
2371 _roll_delay -= nframes;
2372 silence (nframes, offset);
2373 /* transport frame is not legal for caller to use */
2376 } else if (_roll_delay > 0) {
2378 nframes -= _roll_delay;
2380 silence (_roll_delay, offset);
2382 offset += _roll_delay;
2383 transport_frame += _roll_delay;
2392 Route::roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset, int declick,
2393 bool can_record, bool rec_monitors_input)
2396 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2398 // automation snapshot can also be called from the non-rt context
2399 // and it uses the processor list, so we take the lock out here
2400 automation_snapshot (_session.transport_frame());
2404 if ((n_outputs().n_total() == 0 && _processors.empty()) || n_inputs().n_total() == 0 || !_active) {
2405 silence (nframes, offset);
2409 nframes_t unused = 0;
2411 if ((nframes = check_initial_delay (nframes, offset, unused)) == 0) {
2417 apply_gain_automation = false;
2420 Glib::Mutex::Lock am (_automation_lock, Glib::TRY_LOCK);
2422 if (am.locked() && _session.transport_rolling()) {
2424 if (_gain_control->list()->automation_playback()) {
2425 apply_gain_automation = _gain_control->list()->curve().rt_safe_get_vector (
2426 start_frame, end_frame, _session.gain_automation_buffer(), nframes);
2431 passthru (start_frame, end_frame, nframes, offset, declick, false);
2437 Route::silent_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
2438 bool can_record, bool rec_monitors_input)
2440 silence (nframes, offset);
2445 Route::toggle_monitor_input ()
2447 for (PortSet::iterator i = _inputs.begin(); i != _inputs.end(); ++i) {
2448 i->ensure_monitor_input( ! i->monitoring_input());
2453 Route::has_external_redirects () const
2455 // FIXME: what about sends?
2457 boost::shared_ptr<const PortInsert> pi;
2459 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2460 if ((pi = boost::dynamic_pointer_cast<const PortInsert>(*i)) != 0) {
2462 for (PortSet::const_iterator port = pi->io()->outputs().begin();
2463 port != pi->io()->outputs().end(); ++port) {
2465 string port_name = port->name();
2466 string client_name = port_name.substr (0, port_name.find(':'));
2468 /* only say "yes" if the redirect is actually in use */
2470 if (client_name != "ardour" && pi->active()) {
2481 Route::flush_processors ()
2483 /* XXX shouldn't really try to take this lock, since
2484 this is called from the RT audio thread.
2487 Glib::RWLock::ReaderLock lm (_processor_lock);
2489 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2490 (*i)->deactivate ();
2496 Route::set_meter_point (MeterPoint p, void *src)
2498 if (_meter_point != p) {
2500 meter_change (src); /* EMIT SIGNAL */
2501 _session.set_dirty ();
2506 Route::update_total_latency ()
2508 nframes_t old = _own_latency;
2510 if (_user_latency) {
2511 _own_latency = _user_latency;
2515 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2516 if ((*i)->active ()) {
2517 _own_latency += (*i)->signal_latency ();
2522 set_port_latency (_own_latency);
2524 if (!_user_latency) {
2525 /* this (virtual) function is used for pure Routes,
2526 not derived classes like AudioTrack. this means
2527 that the data processed here comes from an input
2528 port, not prerecorded material, and therefore we
2529 have to take into account any input latency.
2533 _own_latency += input_latency ();
2536 if (old != _own_latency) {
2537 signal_latency_changed (); /* EMIT SIGNAL */
2540 return _own_latency;
2544 Route::set_user_latency (nframes_t nframes)
2546 Latent::set_user_latency (nframes);
2547 _session.update_latency_compensation (false, false);
2551 Route::set_latency_delay (nframes_t longest_session_latency)
2553 nframes_t old = _initial_delay;
2555 if (_own_latency < longest_session_latency) {
2556 _initial_delay = longest_session_latency - _own_latency;
2561 if (_initial_delay != old) {
2562 initial_delay_changed (); /* EMIT SIGNAL */
2565 if (_session.transport_stopped()) {
2566 _roll_delay = _initial_delay;
2571 Route::automation_snapshot (nframes_t now)
2573 IO::automation_snapshot (now);
2575 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2576 (*i)->automation_snapshot (now);
2580 Route::ToggleControllable::ToggleControllable (std::string name, Route& s, ToggleType tp)
2581 : Controllable (name), route (s), type(tp)
2587 Route::ToggleControllable::set_value (float val)
2589 bool bval = ((val >= 0.5f) ? true: false);
2593 route.set_mute (bval, this);
2596 route.set_solo (bval, this);
2604 Route::ToggleControllable::get_value (void) const
2610 val = route.muted() ? 1.0f : 0.0f;
2613 val = route.soloed() ? 1.0f : 0.0f;
2623 Route::set_block_size (nframes_t nframes)
2625 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2626 (*i)->set_block_size (nframes);
2631 Route::protect_automation ()
2633 Automatable::protect_automation();
2635 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
2636 (*i)->protect_automation();
2640 Route::set_pending_declick (int declick)
2643 /* this call is not allowed to turn off a pending declick unless "force" is true */
2645 _pending_declick = declick;
2647 // cerr << _name << ": after setting to " << declick << " pending declick = " << _pending_declick << endl;
2649 _pending_declick = 0;