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>
27 #include <pbd/stacktrace.h>
28 #include <pbd/memento_command.h>
30 #include <ardour/timestamps.h>
31 #include <ardour/audioengine.h>
32 #include <ardour/route.h>
33 #include <ardour/buffer.h>
34 #include <ardour/processor.h>
35 #include <ardour/plugin_insert.h>
36 #include <ardour/port_insert.h>
37 #include <ardour/send.h>
38 #include <ardour/session.h>
39 #include <ardour/utils.h>
40 #include <ardour/configuration.h>
41 #include <ardour/cycle_timer.h>
42 #include <ardour/route_group.h>
43 #include <ardour/port.h>
44 #include <ardour/audio_port.h>
45 #include <ardour/ladspa_plugin.h>
46 #include <ardour/panner.h>
47 #include <ardour/dB.h>
48 #include <ardour/amp.h>
49 #include <ardour/meter.h>
50 #include <ardour/buffer_set.h>
51 #include <ardour/mix.h>
52 #include <ardour/profile.h>
57 using namespace ARDOUR;
60 uint32_t Route::order_key_cnt = 0;
61 sigc::signal<void,const char*> Route::SyncOrderKeys;
63 Route::Route (Session& sess, string name,
64 int in_min, int in_max, int out_min, int out_max,
65 Flag flg, DataType default_type)
66 : IO (sess, name, in_min, in_max, out_min, out_max, default_type)
68 , _solo_control (new ToggleControllable (X_("solo"), *this, ToggleControllable::SoloControl))
69 , _mute_control (new ToggleControllable (X_("mute"), *this, ToggleControllable::MuteControl))
74 Route::Route (Session& sess, const XMLNode& node, DataType default_type)
75 : IO (sess, *node.child ("IO"), default_type)
76 , _solo_control (new ToggleControllable (X_("solo"), *this, ToggleControllable::SoloControl))
77 , _mute_control (new ToggleControllable (X_("mute"), *this, ToggleControllable::MuteControl))
80 _set_state (node, false);
86 processor_max_outs.reset();
92 _phase_invert = false;
93 _denormal_protection = false;
94 order_keys[strdup (N_("signal"))] = order_key_cnt++;
96 _meter_point = MeterPostFader;
101 _have_internal_generator = false;
102 _declickable = false;
103 _pending_declick = true;
104 _remote_control_id = 0;
109 _mute_affects_pre_fader = Config->get_mute_affects_pre_fader();
110 _mute_affects_post_fader = Config->get_mute_affects_post_fader();
111 _mute_affects_control_outs = Config->get_mute_affects_control_outs();
112 _mute_affects_main_outs = Config->get_mute_affects_main_outs();
115 desired_solo_gain = 1.0;
117 desired_mute_gain = 1.0;
121 input_changed.connect (mem_fun (this, &Route::input_change_handler));
122 output_changed.connect (mem_fun (this, &Route::output_change_handler));
127 clear_processors (PreFader);
128 clear_processors (PostFader);
130 for (OrderKeys::iterator i = order_keys.begin(); i != order_keys.end(); ++i) {
131 free ((void*)(i->first));
134 delete _control_outs;
138 Route::set_remote_control_id (uint32_t id)
140 if (id != _remote_control_id) {
141 _remote_control_id = id;
142 RemoteControlIDChanged ();
147 Route::remote_control_id() const
149 return _remote_control_id;
153 Route::order_key (const char* name) const
155 OrderKeys::const_iterator i;
157 for (i = order_keys.begin(); i != order_keys.end(); ++i) {
158 if (!strcmp (name, i->first)) {
167 Route::set_order_key (const char* name, long n)
169 order_keys[strdup(name)] = n;
171 if (Config->get_sync_all_route_ordering()) {
172 for (OrderKeys::iterator x = order_keys.begin(); x != order_keys.end(); ++x) {
177 _session.set_dirty ();
181 Route::sync_order_keys (const char* base)
183 if (order_keys.empty()) {
187 OrderKeys::iterator i;
190 if ((i = order_keys.find (base)) == order_keys.end()) {
191 /* key doesn't exist, use the first existing key (during session initialization) */
192 i = order_keys.begin();
196 /* key exists - use it and reset all others (actually, itself included) */
197 i = order_keys.begin();
201 for (; i != order_keys.end(); ++i) {
207 Route::ensure_track_or_route_name(string name, Session &session)
209 string newname = name;
211 while (session.route_by_name (newname) != NULL) {
212 newname = bump_name_once (newname);
220 Route::inc_gain (gain_t fraction, void *src)
222 IO::inc_gain (fraction, src);
226 Route::set_gain (gain_t val, void *src)
228 if (src != 0 && _mix_group && src != _mix_group && _mix_group->is_active()) {
230 if (_mix_group->is_relative()) {
232 gain_t usable_gain = gain();
233 if (usable_gain < 0.000001f) {
234 usable_gain = 0.000001f;
238 if (delta < 0.000001f) {
242 delta -= usable_gain;
247 gain_t factor = delta / usable_gain;
250 factor = _mix_group->get_max_factor(factor);
251 if (factor == 0.0f) {
252 _gain_control->Changed(); /* EMIT SIGNAL */
256 factor = _mix_group->get_min_factor(factor);
257 if (factor == 0.0f) {
258 _gain_control->Changed(); /* EMIT SIGNAL */
263 _mix_group->apply (&Route::inc_gain, factor, _mix_group);
267 _mix_group->apply (&Route::set_gain, val, _mix_group);
277 IO::set_gain (val, src);
280 /** Process this route for one (sub) cycle (process thread)
282 * @param bufs Scratch buffers to use for the signal path
283 * @param start_frame Initial transport frame
284 * @param end_frame Final transport frame
285 * @param nframes Number of frames to output (to ports)
286 * @param offset Output offset (of port buffers, for split cycles)
288 * Note that (end_frame - start_frame) may not be equal to nframes when the
289 * transport speed isn't 1.0 (eg varispeed).
292 Route::process_output_buffers (BufferSet& bufs,
293 nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset,
294 bool with_processors, int declick, bool meter)
296 // This is definitely very audio-only for now
297 assert(_default_type == DataType::AUDIO);
299 ProcessorList::iterator i;
300 bool post_fader_work = false;
301 bool mute_declick_applied = false;
307 gain_t* gab = _session.gain_automation_buffer();
309 switch (Config->get_monitoring_model()) {
310 case HardwareMonitoring:
311 case ExternalMonitoring:
318 declick = _pending_declick;
321 Glib::Mutex::Lock cm (_control_outs_lock, Glib::TRY_LOCK);
331 Glib::Mutex::Lock dm (declick_lock, Glib::TRY_LOCK);
334 dmg = desired_mute_gain;
335 dsg = desired_solo_gain;
344 /* -------------------------------------------------------------------------------------------
345 GLOBAL DECLICK (for transport changes etc.)
346 ----------------------------------------------------------------------------------------- */
349 Amp::run_in_place (bufs, nframes, 0.0, 1.0, false);
350 _pending_declick = 0;
351 } else if (declick < 0) {
352 Amp::run_in_place (bufs, nframes, 1.0, 0.0, false);
353 _pending_declick = 0;
356 /* no global declick */
358 if (solo_gain != dsg) {
359 Amp::run_in_place (bufs, nframes, solo_gain, dsg, false);
365 /* -------------------------------------------------------------------------------------------
366 INPUT METERING & MONITORING
367 ----------------------------------------------------------------------------------------- */
369 if (meter && (_meter_point == MeterInput)) {
370 _meter->run_in_place(bufs, start_frame, end_frame, nframes, offset);
373 if (!_soloed && _mute_affects_pre_fader && (mute_gain != dmg)) {
374 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
376 mute_declick_applied = true;
379 if ((_meter_point == MeterInput) && co) {
381 solo_audible = dsg > 0;
382 mute_audible = dmg > 0;// || !_mute_affects_pre_fader;
384 if ( // muted by solo of another track
388 // muted by mute of this track
392 // rec-enabled but not s/w monitoring
394 // TODO: this is probably wrong
396 ( no_monitor && record_enabled()
397 && (!Config->get_auto_input() || _session.actively_recording()) )
401 co->silence (nframes, offset);
405 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
410 /* -------------------------------------------------------------------------------------------
412 ----------------------------------------------------------------------------------------- */
414 if (_denormal_protection || Config->get_denormal_protection()) {
416 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
417 Sample* const sp = i->data();
419 for (nframes_t nx = offset; nx < nframes + offset; ++nx) {
425 /* -------------------------------------------------------------------------------------------
427 ----------------------------------------------------------------------------------------- */
429 if (with_processors) {
430 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
432 if (mute_gain > 0 || !_mute_affects_pre_fader) {
433 for (i = _processors.begin(); i != _processors.end(); ++i) {
434 switch ((*i)->placement()) {
436 (*i)->run_in_place (bufs, start_frame, end_frame, nframes, offset);
439 post_fader_work = true;
444 for (i = _processors.begin(); i != _processors.end(); ++i) {
445 switch ((*i)->placement()) {
447 (*i)->silence (nframes, offset);
450 post_fader_work = true;
458 /* When we entered this method, the number of bufs was set by n_process_buffers(), so
459 * it may be larger than required. Consider e.g a mono track with two redirects A and B.
460 * If A has one input and three outputs, and B three inputs and one output, n_process_buffers()
461 * will be 3. In this case, now we've done pre-fader redirects, we can reset the number of bufs.
463 bufs.set_count (pre_fader_streams());
465 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_post_fader) {
466 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
468 mute_declick_applied = true;
471 /* -------------------------------------------------------------------------------------------
472 PRE-FADER METERING & MONITORING
473 ----------------------------------------------------------------------------------------- */
475 if (meter && (_meter_point == MeterPreFader)) {
476 _meter->run_in_place(bufs, start_frame, end_frame, nframes, offset);
480 if ((_meter_point == MeterPreFader) && co) {
482 solo_audible = dsg > 0;
483 mute_audible = dmg > 0 || !_mute_affects_pre_fader;
485 if ( // muted by solo of another track
489 // muted by mute of this track
493 // rec-enabled but not s/w monitoring
495 ( no_monitor && record_enabled()
496 && (!Config->get_auto_input() || _session.actively_recording()) )
500 co->silence (nframes, offset);
504 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
508 /* -------------------------------------------------------------------------------------------
510 ----------------------------------------------------------------------------------------- */
512 /* if not recording or recording and requiring any monitor signal, then apply gain */
514 if ( // not recording
516 !(record_enabled() && _session.actively_recording()) ||
520 // AND software monitoring required
522 Config->get_monitoring_model() == SoftwareMonitoring) {
524 if (apply_gain_automation) {
527 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
528 Sample* const sp = i->data();
530 for (nframes_t nx = 0; nx < nframes; ++nx) {
535 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
536 Sample* const sp = i->data();
538 for (nframes_t nx = 0; nx < nframes; ++nx) {
544 if (apply_gain_automation && _session.transport_rolling() && nframes > 0) {
545 _effective_gain = gab[nframes-1];
550 /* manual (scalar) gain */
554 Amp::run_in_place (bufs, nframes, _gain, dg, _phase_invert);
557 } else if (_gain != 0 && (_phase_invert || _gain != 1.0)) {
559 /* no need to interpolate current gain value,
560 but its non-unity, so apply it. if the gain
561 is zero, do nothing because we'll ship silence
573 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
574 Sample* const sp = i->data();
575 apply_gain_to_buffer(sp,nframes,this_gain);
578 } else if (_gain == 0) {
579 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
587 /* actively recording, no monitoring required; leave buffers as-is to save CPU cycles */
591 /* -------------------------------------------------------------------------------------------
593 ----------------------------------------------------------------------------------------- */
595 /* note that post_fader_work cannot be true unless with_processors was also true,
599 if (post_fader_work) {
601 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
603 if (mute_gain > 0 || !_mute_affects_post_fader) {
604 for (i = _processors.begin(); i != _processors.end(); ++i) {
605 switch ((*i)->placement()) {
609 (*i)->run_in_place (bufs, start_frame, end_frame, nframes, offset);
614 for (i = _processors.begin(); i != _processors.end(); ++i) {
615 switch ((*i)->placement()) {
619 (*i)->silence (nframes, offset);
627 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_control_outs) {
628 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
630 mute_declick_applied = true;
633 /* -------------------------------------------------------------------------------------------
635 ----------------------------------------------------------------------------------------- */
637 if ((_meter_point == MeterPostFader) && co) {
639 solo_audible = solo_gain > 0;
640 mute_audible = dmg > 0 || !_mute_affects_control_outs;
642 if ( // silent anyway
644 (_gain == 0 && !apply_gain_automation) ||
646 // muted by solo of another track
650 // muted by mute of this track
654 // recording but not s/w monitoring
656 ( no_monitor && record_enabled()
657 && (!Config->get_auto_input() || _session.actively_recording()) )
661 co->silence (nframes, offset);
665 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
669 /* -------------------------------------------------------------------------------------------
671 ----------------------------------------------------------------------------------------- */
673 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_main_outs) {
674 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
676 mute_declick_applied = true;
679 /* -------------------------------------------------------------------------------------------
681 ----------------------------------------------------------------------------------------- */
683 solo_audible = dsg > 0;
684 mute_audible = dmg > 0 || !_mute_affects_main_outs;
686 if (n_outputs().get(_default_type) == 0) {
690 } else if (no_monitor && record_enabled()
691 && (!Config->get_auto_input() || _session.actively_recording())) {
693 IO::silence (nframes, offset);
697 if ( // silent anyway
699 (_gain == 0 && !apply_gain_automation) ||
701 // muted by solo of another track, but not using control outs for solo
703 (!solo_audible && (Config->get_solo_model() != SoloBus)) ||
705 // muted by mute of this track
711 /* don't use Route::silence() here, because that causes
712 all outputs (sends, port processors, etc. to be silent).
715 if (_meter_point == MeterPostFader) {
716 peak_meter().reset();
719 IO::silence (nframes, offset);
723 deliver_output(bufs, start_frame, end_frame, nframes, offset);
729 /* -------------------------------------------------------------------------------------------
731 ----------------------------------------------------------------------------------------- */
733 if (meter && (_meter_point == MeterPostFader)) {
734 if ((_gain == 0 && !apply_gain_automation) || dmg == 0) {
737 _meter->run_in_place(output_buffers(), start_frame, end_frame, nframes, offset);
743 /** Process this route for one (sub) cycle (process thread)
745 * @param bufs Scratch buffers to use for the signal path
746 * @param start_frame Initial transport frame
747 * @param end_frame Final transport frame
748 * @param nframes Number of frames to output (to ports)
749 * @param offset Output offset (of port buffers, for split cycles)
751 * Note that (end_frame - start_frame) may not be equal to nframes when the
752 * transport speed isn't 1.0 (eg varispeed).
755 Route::process_output_buffers (BufferSet& bufs,
756 nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset,
757 bool with_processors, int declick, bool meter)
759 // This is definitely very audio-only for now
760 assert(_default_type == DataType::AUDIO);
762 ProcessorList::iterator i;
763 bool post_fader_work = false;
764 bool mute_declick_applied = false;
770 gain_t* gab = _session.gain_automation_buffer();
772 switch (Config->get_monitoring_model()) {
773 case HardwareMonitoring:
774 case ExternalMonitoring:
781 declick = _pending_declick;
784 Glib::Mutex::Lock cm (_control_outs_lock, Glib::TRY_LOCK);
794 Glib::Mutex::Lock dm (declick_lock, Glib::TRY_LOCK);
797 dmg = desired_mute_gain;
798 dsg = desired_solo_gain;
807 /* -------------------------------------------------------------------------------------------
808 GLOBAL DECLICK (for transport changes etc.)
809 input metering & monitoring (control outs)
812 pre-fader metering & monitoring (control outs)
817 post-fader metering & monitoring (control outs)
818 ----------------------------------------------------------------------------------------- */
821 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
822 for (i = processors.begin(); i != processors.end(); ++i) {
823 (*i)->run_in_place (bufs, start_frame, end_frame, nframes, offset);
828 /* -------------------------------------------------------------------------------------------
829 INPUT METERING & MONITORING
830 ----------------------------------------------------------------------------------------- */
832 if (meter && (_meter_point == MeterInput)) {
833 _meter->run_in_place(bufs, start_frame, end_frame, nframes, offset);
836 if (!_soloed && _mute_affects_pre_fader && (mute_gain != dmg)) {
837 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
839 mute_declick_applied = true;
842 /* -------------------------------------------------------------------------------------------
844 ----------------------------------------------------------------------------------------- */
846 // This really should already be true...
847 bufs.set_count(pre_fader_streams());
850 if ((_meter_point == MeterPreFader) && co) {
852 solo_audible = dsg > 0;
853 mute_audible = dmg > 0 || !_mute_affects_pre_fader;
855 if ( // muted by solo of another track
859 // muted by mute of this track
863 // rec-enabled but not s/w monitoring
865 ( no_monitor && record_enabled()
866 && (!Config->get_auto_input() || _session.actively_recording()) )
870 co->silence (nframes, offset);
874 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
878 /* -------------------------------------------------------------------------------------------
880 ----------------------------------------------------------------------------------------- */
882 /* if not recording or recording and requiring any monitor signal, then apply gain */
884 if ( // not recording
886 !(record_enabled() && _session.actively_recording()) ||
890 // AND software monitoring required
892 Config->get_monitoring_model() == SoftwareMonitoring) {
894 if (apply_gain_automation) {
897 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
898 Sample* const sp = i->data();
900 for (nframes_t nx = 0; nx < nframes; ++nx) {
905 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
906 Sample* const sp = i->data();
908 for (nframes_t nx = 0; nx < nframes; ++nx) {
914 if (apply_gain_automation && _session.transport_rolling() && nframes > 0) {
915 _effective_gain = gab[nframes-1];
920 /* manual (scalar) gain */
924 Amp::run_in_place (bufs, nframes, _gain, dg, _phase_invert);
927 } else if (_gain != 0 && (_phase_invert || _gain != 1.0)) {
929 /* no need to interpolate current gain value,
930 but its non-unity, so apply it. if the gain
931 is zero, do nothing because we'll ship silence
943 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
944 Sample* const sp = i->data();
945 apply_gain_to_buffer(sp,nframes,this_gain);
948 } else if (_gain == 0) {
949 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
957 /* actively recording, no monitoring required; leave buffers as-is to save CPU cycles */
961 /* -------------------------------------------------------------------------------------------
963 ----------------------------------------------------------------------------------------- */
965 if ((_meter_point == MeterPostFader) && co) {
967 solo_audible = solo_gain > 0;
968 mute_audible = dmg > 0 || !_mute_affects_control_outs;
970 if ( // silent anyway
972 (_gain == 0 && !apply_gain_automation) ||
974 // muted by solo of another track
978 // muted by mute of this track
982 // recording but not s/w monitoring
984 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
988 co->silence (nframes, offset);
992 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
996 /* -------------------------------------------------------------------------------------------
998 ----------------------------------------------------------------------------------------- */
1000 solo_audible = dsg > 0;
1001 mute_audible = dmg > 0 || !_mute_affects_main_outs;
1003 if (n_outputs().get(_default_type) == 0) {
1007 } else if (no_monitor && record_enabled()
1008 && (!Config->get_auto_input() || _session.actively_recording())) {
1010 IO::silence (nframes, offset);
1014 if ( // silent anyway
1016 (_gain == 0 && !apply_gain_automation) ||
1018 // muted by solo of another track, but not using control outs for solo
1020 (!solo_audible && (Config->get_solo_model() != SoloBus)) ||
1022 // muted by mute of this track
1028 /* don't use Route::silence() here, because that causes
1029 all outputs (sends, port processors, etc. to be silent).
1032 if (_meter_point == MeterPostFader) {
1033 peak_meter().reset();
1036 IO::silence (nframes, offset);
1040 deliver_output(bufs, start_frame, end_frame, nframes, offset);
1047 #endif /* NEW_POB */
1050 Route::n_process_buffers ()
1052 return max (n_inputs(), processor_max_outs);
1056 Route::passthru (nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset, int declick, bool meter_first)
1058 BufferSet& bufs = _session.get_scratch_buffers(n_process_buffers());
1062 collect_input (bufs, nframes, offset);
1065 _meter->run_in_place(bufs, start_frame, end_frame, nframes, offset);
1066 meter_first = false;
1071 process_output_buffers (bufs, start_frame, end_frame, nframes, offset, true, declick, meter_first);
1075 Route::passthru_silence (nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset, int declick, bool meter)
1077 process_output_buffers (_session.get_silent_buffers (n_process_buffers()), start_frame, end_frame, nframes, offset, true, declick, meter);
1081 Route::set_solo (bool yn, void *src)
1087 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
1088 _mix_group->apply (&Route::set_solo, yn, _mix_group);
1092 if (_soloed != yn) {
1094 solo_changed (src); /* EMIT SIGNAL */
1095 _solo_control->Changed (); /* EMIT SIGNAL */
1098 catch_up_on_solo_mute_override ();
1102 Route::catch_up_on_solo_mute_override ()
1104 if (Config->get_solo_model() != InverseMute) {
1110 Glib::Mutex::Lock lm (declick_lock);
1113 if (Config->get_solo_mute_override()) {
1114 desired_mute_gain = (_soloed?1.0:0.0);
1116 desired_mute_gain = 0.0;
1119 desired_mute_gain = 1.0;
1125 Route::set_solo_mute (bool yn)
1127 Glib::Mutex::Lock lm (declick_lock);
1129 /* Called by Session in response to another Route being soloed.
1132 desired_solo_gain = (yn?0.0:1.0);
1136 Route::set_solo_safe (bool yn, void *src)
1138 if (_solo_safe != yn) {
1140 solo_safe_changed (src); /* EMIT SIGNAL */
1145 Route::set_mute (bool yn, void *src)
1148 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
1149 _mix_group->apply (&Route::set_mute, yn, _mix_group);
1155 mute_changed (src); /* EMIT SIGNAL */
1157 _mute_control->Changed (); /* EMIT SIGNAL */
1159 Glib::Mutex::Lock lm (declick_lock);
1161 if (_soloed && Config->get_solo_mute_override()){
1162 desired_mute_gain = 1.0f;
1164 desired_mute_gain = (yn?0.0f:1.0f);
1170 Route::add_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err)
1172 ChanCount old_pmo = processor_max_outs;
1174 if (!_session.engine().connected()) {
1179 Glib::RWLock::WriterLock lm (_processor_lock);
1181 boost::shared_ptr<PluginInsert> pi;
1182 boost::shared_ptr<PortInsert> porti;
1184 //processor->set_default_type(_default_type);
1186 _processors.push_back (processor);
1188 // Set up processor list channels. This will set processor->[input|output]_streams(),
1189 // configure redirect ports properly, etc.
1190 if (_reset_processor_counts (err)) {
1191 _processors.pop_back ();
1192 _reset_processor_counts (0); // it worked before we tried to add it ...
1196 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
1198 if (pi->natural_input_streams() == ChanCount::ZERO) {
1199 /* generator plugin */
1200 _have_internal_generator = true;
1205 // Ensure peak vector sizes before the plugin is activated
1207 ChanCount potential_max_streams;
1209 potential_max_streams.set (DataType::AUDIO, max (processor->input_streams().n_audio(),
1210 processor->output_streams().n_audio()));
1211 potential_max_streams.set (DataType::MIDI, max (processor->input_streams().n_midi(),
1212 processor->output_streams().n_midi()));
1214 _meter->configure_io (potential_max_streams, potential_max_streams);
1216 // XXX: do we want to emit the signal here ? change call order.
1217 processor->activate ();
1218 processor->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
1223 if (processor_max_outs != old_pmo || old_pmo == ChanCount::ZERO) {
1227 processors_changed (); /* EMIT SIGNAL */
1233 Route::add_processors (const ProcessorList& others, ProcessorStreams* err)
1235 /* NOTE: this is intended to be used ONLY when copying
1236 processors from another Route. Hence the subtle
1237 differences between this and ::add_processor()
1240 ChanCount old_pmo = processor_max_outs;
1242 if (!_session.engine().connected()) {
1247 Glib::RWLock::WriterLock lm (_processor_lock);
1249 ProcessorList::iterator existing_end = _processors.end();
1252 ChanCount potential_max_streams;
1254 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1256 boost::shared_ptr<PluginInsert> pi;
1258 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1261 ChanCount m = max(pi->input_streams(), pi->output_streams());
1262 if (m > potential_max_streams)
1263 potential_max_streams = m;
1266 // Ensure peak vector sizes before the plugin is activated
1267 _meter->configure_io (potential_max_streams, potential_max_streams);
1269 _processors.push_back (*i);
1271 if (_reset_processor_counts (err)) {
1273 _processors.erase (existing_end, _processors.end());
1274 _reset_processor_counts (0); // it worked before we tried to add it ...
1278 (*i)->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
1284 if (processor_max_outs != old_pmo || old_pmo == ChanCount::ZERO) {
1288 processors_changed (); /* EMIT SIGNAL */
1292 /** Turn off all processors with a given placement
1293 * @param p Placement of processors to disable
1296 Route::disable_processors (Placement p)
1298 Glib::RWLock::ReaderLock lm (_processor_lock);
1300 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1301 if ((*i)->placement() == p) {
1302 (*i)->deactivate ();
1306 _session.set_dirty ();
1309 /** Turn off all redirects
1312 Route::disable_processors ()
1314 Glib::RWLock::ReaderLock lm (_processor_lock);
1316 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1317 (*i)->deactivate ();
1320 _session.set_dirty ();
1323 /** Turn off all redirects with a given placement
1324 * @param p Placement of redirects to disable
1327 Route::disable_plugins (Placement p)
1329 Glib::RWLock::ReaderLock lm (_processor_lock);
1331 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1332 if (boost::dynamic_pointer_cast<PluginInsert> (*i) && (*i)->placement() == p) {
1333 (*i)->deactivate ();
1337 _session.set_dirty ();
1340 /** Turn off all plugins
1343 Route::disable_plugins ()
1345 Glib::RWLock::ReaderLock lm (_processor_lock);
1347 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1348 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1349 (*i)->deactivate ();
1353 _session.set_dirty ();
1358 Route::ab_plugins (bool forward)
1360 Glib::RWLock::ReaderLock lm (_processor_lock);
1364 /* forward = turn off all active redirects, and mark them so that the next time
1365 we go the other way, we will revert them
1368 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1369 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1373 if ((*i)->active()) {
1374 (*i)->deactivate ();
1375 (*i)->set_next_ab_is_active (true);
1377 (*i)->set_next_ab_is_active (false);
1383 /* backward = if the redirect was marked to go active on the next ab, do so */
1385 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1387 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1391 if ((*i)->get_next_ab_is_active()) {
1394 (*i)->deactivate ();
1399 _session.set_dirty ();
1403 /* Figure out the streams that will feed into PreFader */
1405 Route::pre_fader_streams() const
1407 boost::shared_ptr<Processor> processor;
1409 /* Find the last pre-fader redirect that isn't a send; sends don't affect the number
1411 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1412 if ((*i)->placement() == PreFader && boost::dynamic_pointer_cast<Send> (*i) == 0) {
1418 return processor->output_streams();
1425 /** Remove processors with a given placement.
1426 * @param p Placement of processors to remove.
1429 Route::clear_processors (Placement p)
1431 const ChanCount old_pmo = processor_max_outs;
1433 if (!_session.engine().connected()) {
1438 Glib::RWLock::WriterLock lm (_processor_lock);
1439 ProcessorList new_list;
1441 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1442 if ((*i)->placement() == p) {
1443 /* it's the placement we want to get rid of */
1444 (*i)->drop_references ();
1446 /* it's a different placement, so keep it */
1447 new_list.push_back (*i);
1451 _processors = new_list;
1454 /* FIXME: can't see how this test can ever fire */
1455 if (processor_max_outs != old_pmo) {
1459 processor_max_outs.reset();
1460 _have_internal_generator = false;
1461 processors_changed (); /* EMIT SIGNAL */
1465 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err)
1467 ChanCount old_pmo = processor_max_outs;
1469 if (!_session.engine().connected()) {
1473 processor_max_outs.reset();
1476 Glib::RWLock::WriterLock lm (_processor_lock);
1477 ProcessorList::iterator i;
1478 bool removed = false;
1480 for (i = _processors.begin(); i != _processors.end(); ++i) {
1481 if (*i == processor) {
1483 ProcessorList::iterator tmp;
1485 /* move along, see failure case for reset_processor_counts()
1486 where we may need to reprocessor the processor.
1492 /* stop redirects that send signals to JACK ports
1493 from causing noise as a result of no longer being
1497 boost::shared_ptr<IOProcessor> redirect;
1499 if ((redirect = boost::dynamic_pointer_cast<IOProcessor> (*i)) != 0) {
1500 redirect->io()->disconnect_inputs (this);
1501 redirect->io()->disconnect_outputs (this);
1504 _processors.erase (i);
1519 if (_reset_processor_counts (err)) {
1520 /* get back to where we where */
1521 _processors.insert (i, processor);
1522 /* we know this will work, because it worked before :) */
1523 _reset_processor_counts (0);
1527 _have_internal_generator = false;
1529 for (i = _processors.begin(); i != _processors.end(); ++i) {
1530 boost::shared_ptr<PluginInsert> pi;
1532 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1533 if (pi->is_generator()) {
1534 _have_internal_generator = true;
1541 if (old_pmo != processor_max_outs) {
1545 processor->drop_references ();
1547 processors_changed (); /* EMIT SIGNAL */
1552 Route::reset_processor_counts (ProcessorStreams* err)
1554 Glib::RWLock::WriterLock lm (_processor_lock);
1555 return _reset_processor_counts (err);
1560 Route::_reset_processor_counts (ProcessorStreams* err)
1562 ProcessorList::iterator r;
1563 uint32_t insert_cnt = 0;
1564 uint32_t send_cnt = 0;
1565 map<Placement,list<ProcessorCount> > proc_map;
1566 ProcessorList::iterator prev;
1567 ChanCount initial_streams = n_inputs ();
1568 ChanCount previous_initial_streams = n_inputs ();
1570 uint32_t max_audio = 0;
1571 uint32_t max_midi = 0;
1573 processor_max_outs.reset ();
1575 /* Step 1: build a map that links each insert to an in/out channel count
1577 Divide inserts up by placement so we get the signal flow
1578 properly modelled. we need to do this because the _processors
1579 list is not sorted by placement, and because other reasons may
1580 exist now or in the future for this separate treatment.
1583 /* ... but it should/will be... */
1585 for (r = _processors.begin(); r != _processors.end(); ++r) {
1587 boost::shared_ptr<PluginInsert> plugin_insert;
1588 boost::shared_ptr<PortInsert> port_insert;
1590 if ((plugin_insert = boost::dynamic_pointer_cast<PluginInsert>(*r)) != 0) {
1593 proc_map[(*r)->placement()].push_back (ProcessorCount (*r));
1595 /* reset plugin counts back to one for now so
1596 that we have a predictable, controlled
1597 state to try to configure.
1600 plugin_insert->set_count (1);
1602 } else if ((port_insert = boost::dynamic_pointer_cast<PortInsert>(*r)) != 0) {
1605 proc_map[(*r)->placement()].push_back (ProcessorCount (*r));
1607 } else if (boost::dynamic_pointer_cast<Send> (*r) != 0) {
1612 if (insert_cnt == 0) {
1621 /* Now process each placement in order, checking to see if we
1622 can really do what has been requested.
1627 if (check_some_processor_counts (proc_map[PreFader], n_inputs (), err)) {
1631 if (!proc_map[PreFader].empty()) {
1632 previous_initial_streams = n_inputs ();
1633 for (list<ProcessorCount>::iterator i = proc_map[PreFader].begin(); i != proc_map[PreFader].end(); i++) {
1634 if (i->processor->can_support_io_configuration (previous_initial_streams, initial_streams) == false) {
1637 previous_initial_streams = initial_streams;
1643 if (check_some_processor_counts (proc_map[PostFader], initial_streams, err)) {
1647 if (!proc_map[PostFader].empty()) {
1648 for (list<ProcessorCount>::iterator i = proc_map[PostFader].begin(); i != proc_map[PostFader].end(); i++) {
1649 if (i->processor->can_support_io_configuration (previous_initial_streams, initial_streams) == false) {
1652 previous_initial_streams = initial_streams;
1656 /* OK, everything can be set up correctly, so lets do it */
1658 apply_some_processor_counts (proc_map[PreFader]);
1659 apply_some_processor_counts (proc_map[PostFader]);
1661 /* recompute max outs of any processor */
1667 processor_max_outs.reset ();
1668 prev = _processors.end();
1670 for (r = _processors.begin(); r != _processors.end(); prev = r, ++r) {
1671 boost::shared_ptr<Send> s;
1673 if ((s = boost::dynamic_pointer_cast<Send> (*r)) != 0) {
1675 /* don't pay any attention to send output configuration, since it doesn't
1679 if (r == _processors.begin()) {
1680 s->expect_inputs (n_inputs());
1682 s->expect_inputs ((*prev)->output_streams());
1687 max_audio = max ((*r)->output_streams ().n_audio(), max_audio);
1688 max_midi = max ((*r)->output_streams ().n_midi(), max_midi);
1692 processor_max_outs.set (DataType::AUDIO, max_audio);
1693 processor_max_outs.set (DataType::MIDI, max_midi);
1699 for (r = _processors.begin(); r != _processors.end(); ++r) {
1700 max_audio = max ((*r)->output_streams ().n_audio(), max_audio);
1701 max_midi = max ((*r)->output_streams ().n_midi(), max_midi);
1704 processor_max_outs.set (DataType::AUDIO, max_audio);
1705 processor_max_outs.set (DataType::MIDI, max_midi);
1711 Route::apply_some_processor_counts (list<ProcessorCount>& iclist)
1713 list<ProcessorCount>::iterator i;
1715 for (i = iclist.begin(); i != iclist.end(); ++i) {
1717 ProcessorCount& pc (*i);
1719 if (pc.processor->configure_io (pc.in, pc.out)) {
1723 /* make sure that however many we have, they are all active */
1725 pc.processor->activate ();
1731 /** Returns whether \a iclist can be configured and run starting with
1732 * \a required_inputs at the first processor's inputs.
1733 * If false is returned, \a iclist can not be run with \a required_inputs, and \a err is set.
1734 * Otherwise, \a err is set to the output of the list.
1737 Route::check_some_processor_counts (list<ProcessorCount>& iclist, ChanCount required_inputs, ProcessorStreams* err)
1739 list<ProcessorCount>::iterator i;
1744 err->count = required_inputs;
1747 for (i = iclist.begin(); i != iclist.end(); ++i, ++index) {
1749 if (!(*i).processor->can_support_io_configuration (required_inputs, (*i).out)) {
1752 err->count = required_inputs;
1757 (*i).in = required_inputs;
1758 required_inputs = (*i).out;
1765 Route::all_processors_flip ()
1767 Glib::RWLock::ReaderLock lm (_processor_lock);
1769 if (_processors.empty()) {
1773 bool first_is_on = _processors.front()->active();
1775 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1777 (*i)->deactivate ();
1783 _session.set_dirty ();
1786 /** Set all processors with a given placement to a given active state.
1787 * @param p Placement of processors to change.
1788 * @param state New active state for those processors.
1791 Route::all_processors_active (Placement p, bool state)
1793 Glib::RWLock::ReaderLock lm (_processor_lock);
1795 if (_processors.empty()) {
1799 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1800 if ((*i)->placement() == p) {
1804 (*i)->deactivate ();
1809 _session.set_dirty ();
1812 struct ProcessorSorter {
1813 bool operator() (boost::shared_ptr<const Processor> a, boost::shared_ptr<const Processor> b) {
1814 return a->sort_key() < b->sort_key();
1819 Route::sort_processors (ProcessorStreams* err)
1822 ProcessorSorter comparator;
1823 Glib::RWLock::WriterLock lm (_processor_lock);
1824 ChanCount old_pmo = processor_max_outs;
1826 /* the sweet power of C++ ... */
1828 ProcessorList as_it_was_before = _processors;
1830 _processors.sort (comparator);
1832 if (_reset_processor_counts (err)) {
1833 _processors = as_it_was_before;
1834 processor_max_outs = old_pmo;
1840 processors_changed (); /* EMIT SIGNAL */
1852 Route::get_template()
1854 return state(false);
1858 Route::state(bool full_state)
1860 XMLNode *node = new XMLNode("Route");
1861 ProcessorList::iterator i;
1865 node->add_property("flags", enum_2_string (_flags));
1868 node->add_property("default-type", _default_type.to_string());
1870 node->add_property("active", _active?"yes":"no");
1871 node->add_property("muted", _muted?"yes":"no");
1872 node->add_property("soloed", _soloed?"yes":"no");
1873 node->add_property("phase-invert", _phase_invert?"yes":"no");
1874 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
1875 node->add_property("mute-affects-pre-fader", _mute_affects_pre_fader?"yes":"no");
1876 node->add_property("mute-affects-post-fader", _mute_affects_post_fader?"yes":"no");
1877 node->add_property("mute-affects-control-outs", _mute_affects_control_outs?"yes":"no");
1878 node->add_property("mute-affects-main-outs", _mute_affects_main_outs?"yes":"no");
1879 node->add_property("meter-point", enum_2_string (_meter_point));
1882 node->add_property("edit-group", _edit_group->name());
1885 node->add_property("mix-group", _mix_group->name());
1888 string order_string;
1889 OrderKeys::iterator x = order_keys.begin();
1891 while (x != order_keys.end()) {
1892 order_string += string ((*x).first);
1893 order_string += '=';
1894 snprintf (buf, sizeof(buf), "%ld", (*x).second);
1895 order_string += buf;
1899 if (x == order_keys.end()) {
1903 order_string += ':';
1905 node->add_property ("order-keys", order_string);
1907 node->add_child_nocopy (IO::state (full_state));
1908 node->add_child_nocopy (_solo_control->get_state ());
1909 node->add_child_nocopy (_mute_control->get_state ());
1911 XMLNode* remote_control_node = new XMLNode (X_("RemoteControl"));
1912 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
1913 remote_control_node->add_property (X_("id"), buf);
1914 node->add_child_nocopy (*remote_control_node);
1916 if (_control_outs) {
1917 XMLNode* cnode = new XMLNode (X_("ControlOuts"));
1918 cnode->add_child_nocopy (_control_outs->state (full_state));
1919 node->add_child_nocopy (*cnode);
1922 if (_comment.length()) {
1923 XMLNode *cmt = node->add_child ("Comment");
1924 cmt->add_content (_comment);
1927 for (i = _processors.begin(); i != _processors.end(); ++i) {
1928 node->add_child_nocopy((*i)->state (full_state));
1932 node->add_child_copy (*_extra_xml);
1939 Route::get_processor_state ()
1941 XMLNode* root = new XMLNode (X_("redirects"));
1942 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1943 root->add_child_nocopy ((*i)->state (true));
1950 Route::set_processor_state (const XMLNode& root)
1952 if (root.name() != X_("redirects")) {
1958 XMLNodeConstIterator iter;
1959 XMLNodeConstIterator niter;
1960 Glib::RWLock::ReaderLock lm (_processor_lock);
1962 nlist = root.children();
1964 for (iter = nlist.begin(); iter != nlist.end(); ++iter){
1966 /* iter now points to a IOProcessor state node */
1968 nnlist = (*iter)->children ();
1970 for (niter = nnlist.begin(); niter != nnlist.end(); ++niter) {
1972 /* find the IO child node, since it contains the ID we need */
1974 /* XXX OOP encapsulation violation, ugh */
1976 if ((*niter)->name() == IO::state_node_name) {
1978 XMLProperty* prop = (*niter)->property (X_("id"));
1981 warning << _("IOProcessor node has no ID, ignored") << endmsg;
1985 ID id = prop->value ();
1987 /* now look for a processor with that ID */
1989 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1990 if ((*i)->id() == id) {
1991 (*i)->set_state (**iter);
2007 Route::set_deferred_state ()
2010 XMLNodeConstIterator niter;
2012 if (!deferred_state) {
2016 nlist = deferred_state->children();
2018 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2019 add_processor_from_xml (**niter);
2022 delete deferred_state;
2027 Route::add_processor_from_xml (const XMLNode& node)
2029 const XMLProperty *prop;
2031 // legacy sessions use a different node name for sends
2032 if (node.name() == "Send") {
2035 boost::shared_ptr<Send> send (new Send (_session, node));
2036 add_processor (send);
2039 catch (failed_constructor &err) {
2040 error << _("Send construction failed") << endmsg;
2044 // use "Processor" in XML?
2045 } else if (node.name() == "Processor") {
2048 if ((prop = node.property ("type")) != 0) {
2050 boost::shared_ptr<Processor> processor;
2051 bool have_insert = false;
2053 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
2054 prop->value() == "lv2" ||
2055 prop->value() == "vst" ||
2056 prop->value() == "audiounit") {
2058 processor.reset (new PluginInsert(_session, node));
2061 } else if (prop->value() == "port") {
2063 processor.reset (new PortInsert (_session, node));
2065 } else if (prop->value() == "send") {
2067 processor.reset (new Send (_session, node));
2072 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
2075 add_processor (processor);
2078 error << _("Processor XML node has no type property") << endmsg;
2082 catch (failed_constructor &err) {
2083 warning << _("processor could not be created. Ignored.") << endmsg;
2090 Route::set_state (const XMLNode& node)
2092 return _set_state (node, true);
2096 Route::_set_state (const XMLNode& node, bool call_base)
2099 XMLNodeConstIterator niter;
2101 XMLPropertyList plist;
2102 const XMLProperty *prop;
2104 if (node.name() != "Route"){
2105 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2109 if ((prop = node.property (X_("flags"))) != 0) {
2110 _flags = Flag (string_2_enum (prop->value(), _flags));
2115 if ((prop = node.property (X_("default-type"))) != 0) {
2116 _default_type = DataType(prop->value());
2117 assert(_default_type != DataType::NIL);
2120 if ((prop = node.property (X_("phase-invert"))) != 0) {
2121 set_phase_invert (prop->value()=="yes"?true:false, this);
2124 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2125 set_denormal_protection (prop->value()=="yes"?true:false, this);
2129 if ((prop = node.property (X_("active"))) != 0) {
2130 set_active (prop->value() == "yes");
2133 if ((prop = node.property (X_("muted"))) != 0) {
2134 bool yn = prop->value()=="yes"?true:false;
2136 /* force reset of mute status */
2140 mute_gain = desired_mute_gain;
2143 if ((prop = node.property (X_("soloed"))) != 0) {
2144 bool yn = prop->value()=="yes"?true:false;
2146 /* force reset of solo status */
2149 set_solo (yn, this);
2150 solo_gain = desired_solo_gain;
2153 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2154 _mute_affects_pre_fader = (prop->value()=="yes")?true:false;
2157 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2158 _mute_affects_post_fader = (prop->value()=="yes")?true:false;
2161 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2162 _mute_affects_control_outs = (prop->value()=="yes")?true:false;
2165 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2166 _mute_affects_main_outs = (prop->value()=="yes")?true:false;
2169 if ((prop = node.property (X_("meter-point"))) != 0) {
2170 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2173 if ((prop = node.property (X_("edit-group"))) != 0) {
2174 RouteGroup* edit_group = _session.edit_group_by_name(prop->value());
2175 if(edit_group == 0) {
2176 error << string_compose(_("Route %1: unknown edit group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
2178 set_edit_group(edit_group, this);
2182 if ((prop = node.property (X_("order-keys"))) != 0) {
2186 string::size_type colon, equal;
2187 string remaining = prop->value();
2189 while (remaining.length()) {
2191 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2192 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2195 if (sscanf (remaining.substr (equal+1).c_str(), "%ld", &n) != 1) {
2196 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2199 set_order_key (remaining.substr (0, equal).c_str(), n);
2203 colon = remaining.find_first_of (':');
2205 if (colon != string::npos) {
2206 remaining = remaining.substr (colon+1);
2213 nlist = node.children();
2215 delete deferred_state;
2216 deferred_state = new XMLNode(X_("deferred state"));
2218 /* set parent class properties before anything else */
2220 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2224 if (child->name() == IO::state_node_name && call_base) {
2226 IO::set_state (*child);
2231 XMLNodeList processor_nodes;
2233 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2237 if (child->name() == X_("Send") || child->name() == X_("Processor")) {
2238 processor_nodes.push_back(child);
2243 _set_processor_states(processor_nodes);
2246 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2248 // All processors have been applied already
2250 if (child->name() == X_("Automation")) {
2252 if ((prop = child->property (X_("path"))) != 0) {
2253 load_automation (prop->value());
2256 } else if (child->name() == X_("ControlOuts")) {
2258 string coutname = _name;
2259 coutname += _("[control]");
2261 delete _control_outs;
2262 _control_outs = new IO (_session, coutname);
2263 _control_outs->set_state (**(child->children().begin()));
2265 } else if (child->name() == X_("Comment")) {
2267 /* XXX this is a terrible API design in libxml++ */
2269 XMLNode *cmt = *(child->children().begin());
2270 _comment = cmt->content();
2272 } else if (child->name() == X_("Extra")) {
2274 _extra_xml = new XMLNode (*child);
2276 } else if (child->name() == X_("Controllable") && (prop = child->property("name")) != 0) {
2278 if (prop->value() == "solo") {
2279 _solo_control->set_state (*child);
2280 _session.add_controllable (_solo_control);
2281 } else if (prop->value() == "mute") {
2282 _mute_control->set_state (*child);
2283 _session.add_controllable (_mute_control);
2286 else if (child->name() == X_("RemoteControl")) {
2287 if ((prop = child->property (X_("id"))) != 0) {
2289 sscanf (prop->value().c_str(), "%d", &x);
2290 set_remote_control_id (x);
2295 if ((prop = node.property (X_("mix-group"))) != 0) {
2296 RouteGroup* mix_group = _session.mix_group_by_name(prop->value());
2297 if (mix_group == 0) {
2298 error << string_compose(_("Route %1: unknown mix group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
2300 set_mix_group(mix_group, this);
2308 Route::_set_processor_states(const XMLNodeList &nlist)
2310 XMLNodeConstIterator niter;
2313 ProcessorList::iterator i, o;
2315 // Iterate through existing processors, remove those which are not in the state list
2316 for (i = _processors.begin(); i != _processors.end(); ) {
2317 ProcessorList::iterator tmp = i;
2320 bool processorInStateList = false;
2322 (*i)->id().print (buf, sizeof (buf));
2325 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2327 // legacy sessions (IOProcessor as a child of Processor, both is-a IO)
2328 if (strncmp(buf,(*niter)->child(X_("IOProcessor"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf)) == 0) {
2329 processorInStateList = true;
2331 } else if (strncmp(buf,(*niter)->property(X_("id"))->value().c_str(), sizeof(buf)) == 0) {
2332 processorInStateList = true;
2337 if (!processorInStateList) {
2338 remove_processor (*i);
2346 // Iterate through state list and make sure all processors are on the track and in the correct order,
2347 // set the state of existing processors according to the new state on the same go
2348 i = _processors.begin();
2349 for (niter = nlist.begin(); niter != nlist.end(); ++niter, ++i) {
2351 // Check whether the next processor in the list
2354 while (o != _processors.end()) {
2355 (*o)->id().print (buf, sizeof (buf));
2356 if ( strncmp(buf, (*niter)->child(X_("IOProcessor"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf)) == 0)
2358 else if (strncmp(buf,(*niter)->property(X_("id"))->value().c_str(), sizeof(buf)) == 0)
2364 if (o == _processors.end()) {
2365 // If the processor (*niter) is not on the route, we need to create it
2366 // and move it to the correct location
2368 ProcessorList::iterator prev_last = _processors.end();
2369 --prev_last; // We need this to check whether adding succeeded
2371 add_processor_from_xml (**niter);
2373 ProcessorList::iterator last = _processors.end();
2376 if (prev_last == last) {
2377 cerr << "Could not fully restore state as some processors were not possible to create" << endl;
2382 boost::shared_ptr<Processor> tmp = (*last);
2383 // remove the processor from the wrong location
2384 _processors.erase(last);
2385 // processor the new processor at the current location
2386 _processors.insert(i, tmp);
2388 --i; // move pointer to the newly processored processor
2392 // We found the processor (*niter) on the route, first we must make sure the processor
2393 // is at the location provided in the XML state
2395 boost::shared_ptr<Processor> tmp = (*o);
2396 // remove the old copy
2397 _processors.erase(o);
2398 // processor the processor at the correct location
2399 _processors.insert(i, tmp);
2401 --i; // move pointer so it points to the right processor
2404 (*i)->set_state( (**niter) );
2407 processors_changed ();
2411 Route::curve_reallocate ()
2413 // _gain_automation_curve.finish_resize ();
2414 // _pan_automation_curve.finish_resize ();
2418 Route::silence (nframes_t nframes, nframes_t offset)
2422 IO::silence (nframes, offset);
2424 if (_control_outs) {
2425 _control_outs->silence (nframes, offset);
2429 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2432 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2433 boost::shared_ptr<PluginInsert> pi;
2434 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2435 // skip plugins, they don't need anything when we're not active
2439 (*i)->silence (nframes, offset);
2442 if (nframes == _session.get_block_size() && offset == 0) {
2452 Route::set_control_outs (const vector<string>& ports)
2454 Glib::Mutex::Lock lm (_control_outs_lock);
2455 vector<string>::const_iterator i;
2458 delete _control_outs;
2461 if (is_control() || is_master()) {
2462 /* no control outs for these two special busses */
2466 if (ports.empty()) {
2470 string coutname = _name;
2471 coutname += _("[control]");
2473 _control_outs = new IO (_session, coutname);
2475 /* our control outs need as many outputs as we
2476 have audio outputs. we track the changes in ::output_change_handler().
2479 // XXX its stupid that we have to get this value twice
2481 limit = n_outputs().n_audio();
2483 if (_control_outs->ensure_io (ChanCount::ZERO, ChanCount (DataType::AUDIO, n_outputs().get (DataType::AUDIO)), true, this)) {
2487 /* now connect to the named ports */
2489 for (size_t n = 0; n < limit; ++n) {
2490 if (_control_outs->connect_output (_control_outs->output (n), ports[n % ports.size()], this)) {
2491 error << string_compose (_("could not connect %1 to %2"), _control_outs->output(n)->name(), ports[n]) << endmsg;
2500 Route::set_edit_group (RouteGroup *eg, void *src)
2503 if (eg == _edit_group) {
2508 _edit_group->remove (this);
2511 if ((_edit_group = eg) != 0) {
2512 _edit_group->add (this);
2515 _session.set_dirty ();
2516 edit_group_changed (src); /* EMIT SIGNAL */
2520 Route::drop_edit_group (void *src)
2523 _session.set_dirty ();
2524 edit_group_changed (src); /* EMIT SIGNAL */
2528 Route::set_mix_group (RouteGroup *mg, void *src)
2531 if (mg == _mix_group) {
2536 _mix_group->remove (this);
2539 if ((_mix_group = mg) != 0) {
2540 _mix_group->add (this);
2543 _session.set_dirty ();
2544 mix_group_changed (src); /* EMIT SIGNAL */
2548 Route::drop_mix_group (void *src)
2551 _session.set_dirty ();
2552 mix_group_changed (src); /* EMIT SIGNAL */
2556 Route::set_comment (string cmt, void *src)
2559 comment_changed (src);
2560 _session.set_dirty ();
2564 Route::feeds (boost::shared_ptr<Route> other)
2569 uint32_t no = self.n_outputs().n_total();
2570 uint32_t ni = other->n_inputs ().n_total();
2572 for (i = 0; i < no; ++i) {
2573 for (j = 0; j < ni; ++j) {
2574 if (self.output(i)->connected_to (other->input(j)->name())) {
2580 /* check IOProcessors which may also interconnect Routes */
2582 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); r++) {
2584 boost::shared_ptr<IOProcessor> redirect = boost::dynamic_pointer_cast<IOProcessor>(*r);
2589 // TODO: support internal redirects here
2591 no = redirect->io()->n_outputs().n_total();
2593 for (i = 0; i < no; ++i) {
2594 for (j = 0; j < ni; ++j) {
2595 if (redirect->io()->output(i)->connected_to (other->input (j)->name())) {
2602 /* check for control room outputs which may also interconnect Routes */
2604 if (_control_outs) {
2606 no = _control_outs->n_outputs().n_total();
2608 for (i = 0; i < no; ++i) {
2609 for (j = 0; j < ni; ++j) {
2610 if (_control_outs->output(i)->connected_to (other->input (j)->name())) {
2621 Route::set_mute_config (mute_type t, bool onoff, void *src)
2625 _mute_affects_pre_fader = onoff;
2626 pre_fader_changed(src); /* EMIT SIGNAL */
2630 _mute_affects_post_fader = onoff;
2631 post_fader_changed(src); /* EMIT SIGNAL */
2635 _mute_affects_control_outs = onoff;
2636 control_outs_changed(src); /* EMIT SIGNAL */
2640 _mute_affects_main_outs = onoff;
2641 main_outs_changed(src); /* EMIT SIGNAL */
2647 Route::get_mute_config (mute_type t)
2653 onoff = _mute_affects_pre_fader;
2656 onoff = _mute_affects_post_fader;
2659 onoff = _mute_affects_control_outs;
2662 onoff = _mute_affects_main_outs;
2670 Route::handle_transport_stopped (bool abort_ignored, bool did_locate, bool can_flush_processors)
2672 nframes_t now = _session.transport_frame();
2675 Glib::RWLock::ReaderLock lm (_processor_lock);
2678 automation_snapshot (now, true);
2681 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2683 if (Config->get_plugins_stop_with_transport() && can_flush_processors) {
2684 (*i)->deactivate ();
2688 (*i)->transport_stopped (now);
2692 IO::transport_stopped (now);
2694 _roll_delay = _initial_delay;
2698 Route::input_change_handler (IOChange change, void *ignored)
2700 if (change & ConfigurationChanged) {
2701 reset_processor_counts (0);
2706 Route::output_change_handler (IOChange change, void *ignored)
2708 if (change & ConfigurationChanged) {
2709 if (_control_outs) {
2710 _control_outs->ensure_io (ChanCount::ZERO, ChanCount(DataType::AUDIO, n_outputs().n_audio()), true, this);
2713 reset_processor_counts (0);
2718 Route::pans_required () const
2720 if (n_outputs().n_audio() < 2) {
2724 return max (n_inputs ().n_audio(), processor_max_outs.n_audio());
2728 Route::no_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
2729 bool session_state_changing, bool can_record, bool rec_monitors_input)
2731 if (n_outputs().n_total() == 0) {
2735 if (session_state_changing || !_active) {
2736 silence (nframes, offset);
2740 apply_gain_automation = false;
2742 if (n_inputs().n_total()) {
2743 passthru (start_frame, end_frame, nframes, offset, 0, false);
2745 silence (nframes, offset);
2752 Route::check_initial_delay (nframes_t nframes, nframes_t& offset, nframes_t& transport_frame)
2754 if (_roll_delay > nframes) {
2756 _roll_delay -= nframes;
2757 silence (nframes, offset);
2758 /* transport frame is not legal for caller to use */
2761 } else if (_roll_delay > 0) {
2763 nframes -= _roll_delay;
2765 silence (_roll_delay, offset);
2767 offset += _roll_delay;
2768 transport_frame += _roll_delay;
2777 Route::roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset, int declick,
2778 bool can_record, bool rec_monitors_input)
2781 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2783 // automation snapshot can also be called from the non-rt context
2784 // and it uses the processor list, so we take the lock out here
2785 automation_snapshot (_session.transport_frame(), false);
2789 if ((n_outputs().n_total() == 0 && _processors.empty()) || n_inputs().n_total() == 0 || !_active) {
2790 silence (nframes, offset);
2794 nframes_t unused = 0;
2796 if ((nframes = check_initial_delay (nframes, offset, unused)) == 0) {
2802 apply_gain_automation = false;
2805 Glib::Mutex::Lock am (data().control_lock(), Glib::TRY_LOCK);
2807 if (am.locked() && _session.transport_rolling()) {
2809 if (_gain_control->automation_playback()) {
2810 apply_gain_automation = _gain_control->list()->curve().rt_safe_get_vector (
2811 start_frame, end_frame, _session.gain_automation_buffer(), nframes);
2816 passthru (start_frame, end_frame, nframes, offset, declick, false);
2822 Route::silent_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
2823 bool can_record, bool rec_monitors_input)
2825 silence (nframes, offset);
2830 Route::toggle_monitor_input ()
2832 for (PortSet::iterator i = _inputs.begin(); i != _inputs.end(); ++i) {
2833 i->ensure_monitor_input( ! i->monitoring_input());
2838 Route::has_external_redirects () const
2840 // FIXME: what about sends?
2842 boost::shared_ptr<const PortInsert> pi;
2844 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2845 if ((pi = boost::dynamic_pointer_cast<const PortInsert>(*i)) != 0) {
2847 for (PortSet::const_iterator port = pi->io()->outputs().begin();
2848 port != pi->io()->outputs().end(); ++port) {
2850 string port_name = port->name();
2851 string client_name = port_name.substr (0, port_name.find(':'));
2853 /* only say "yes" if the redirect is actually in use */
2855 if (client_name != "ardour" && pi->active()) {
2866 Route::flush_processors ()
2868 /* XXX shouldn't really try to take this lock, since
2869 this is called from the RT audio thread.
2872 Glib::RWLock::ReaderLock lm (_processor_lock);
2874 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2875 (*i)->deactivate ();
2881 Route::set_meter_point (MeterPoint p, void *src)
2883 if (_meter_point != p) {
2885 meter_change (src); /* EMIT SIGNAL */
2886 _session.set_dirty ();
2891 Route::update_total_latency ()
2893 nframes_t old = _own_latency;
2895 if (_user_latency) {
2896 _own_latency = _user_latency;
2900 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2901 if ((*i)->active ()) {
2902 _own_latency += (*i)->signal_latency ();
2907 #undef DEBUG_LATENCY
2908 #ifdef DEBUG_LATENCY
2909 cerr << _name << ": internal redirect latency = " << _own_latency << endl;
2912 set_port_latency (_own_latency);
2914 if (!_user_latency) {
2915 /* this (virtual) function is used for pure Routes,
2916 not derived classes like AudioTrack. this means
2917 that the data processed here comes from an input
2918 port, not prerecorded material, and therefore we
2919 have to take into account any input latency.
2923 _own_latency += input_latency ();
2926 if (old != _own_latency) {
2927 signal_latency_changed (); /* EMIT SIGNAL */
2930 #ifdef DEBUG_LATENCY
2931 cerr << _name << ": input latency = " << input_latency() << " total = "
2932 << _own_latency << endl;
2935 return _own_latency;
2939 Route::set_user_latency (nframes_t nframes)
2941 Latent::set_user_latency (nframes);
2942 _session.update_latency_compensation (false, false);
2946 Route::set_latency_delay (nframes_t longest_session_latency)
2948 nframes_t old = _initial_delay;
2950 if (_own_latency < longest_session_latency) {
2951 _initial_delay = longest_session_latency - _own_latency;
2956 if (_initial_delay != old) {
2957 initial_delay_changed (); /* EMIT SIGNAL */
2960 if (_session.transport_stopped()) {
2961 _roll_delay = _initial_delay;
2966 Route::automation_snapshot (nframes_t now, bool force)
2968 if (!force && !should_snapshot(now)) {
2972 IO::automation_snapshot (now, force);
2974 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2975 (*i)->automation_snapshot (now, force);
2979 Route::ToggleControllable::ToggleControllable (std::string name, Route& s, ToggleType tp)
2980 : Controllable (name), route (s), type(tp)
2986 Route::ToggleControllable::set_value (float val)
2988 bool bval = ((val >= 0.5f) ? true: false);
2992 route.set_mute (bval, this);
2995 route.set_solo (bval, this);
3003 Route::ToggleControllable::get_value (void) const
3009 val = route.muted() ? 1.0f : 0.0f;
3012 val = route.soloed() ? 1.0f : 0.0f;
3022 Route::set_block_size (nframes_t nframes)
3024 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3025 (*i)->set_block_size (nframes);
3030 Route::protect_automation ()
3032 Automatable::protect_automation();
3034 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
3035 (*i)->protect_automation();
3039 Route::set_pending_declick (int declick)
3042 /* this call is not allowed to turn off a pending declick unless "force" is true */
3044 _pending_declick = declick;
3046 // cerr << _name << ": after setting to " << declick << " pending declick = " << _pending_declick << endl;
3048 _pending_declick = 0;
3053 /** Shift automation forwards from a particular place, thereby inserting time.
3054 * Adds undo commands for any shifts that are performed.
3056 * @param pos Position to start shifting from.
3057 * @param frames Amount to shift forwards by.
3061 Route::shift (nframes64_t pos, nframes64_t frames)
3063 #ifdef THIS_NEEDS_FIXING_FOR_V3
3065 /* gain automation */
3066 XMLNode &before = _gain_control->get_state ();
3067 _gain_control->shift (pos, frames);
3068 XMLNode &after = _gain_control->get_state ();
3069 _session.add_command (new MementoCommand<AutomationList> (_gain_automation_curve, &before, &after));
3071 /* pan automation */
3072 for (std::vector<StreamPanner*>::iterator i = _panner->begin (); i != _panner->end (); ++i) {
3073 Curve & c = (*i)->automation ();
3074 XMLNode &before = c.get_state ();
3075 c.shift (pos, frames);
3076 XMLNode &after = c.get_state ();
3077 _session.add_command (new MementoCommand<AutomationList> (c, &before, &after));
3080 /* redirect automation */
3082 Glib::RWLock::ReaderLock lm (redirect_lock);
3083 for (RedirectList::iterator i = _redirects.begin (); i != _redirects.end (); ++i) {
3086 (*i)->what_has_automation (a);
3088 for (set<uint32_t>::const_iterator j = a.begin (); j != a.end (); ++j) {
3089 AutomationList & al = (*i)->automation_list (*j);
3090 XMLNode &before = al.get_state ();
3091 al.shift (pos, frames);
3092 XMLNode &after = al.get_state ();
3093 _session.add_command (new MementoCommand<AutomationList> (al, &before, &after));