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/internal_send.h>
39 #include <ardour/session.h>
40 #include <ardour/utils.h>
41 #include <ardour/configuration.h>
42 #include <ardour/cycle_timer.h>
43 #include <ardour/route_group.h>
44 #include <ardour/port.h>
45 #include <ardour/audio_port.h>
46 #include <ardour/ladspa_plugin.h>
47 #include <ardour/panner.h>
48 #include <ardour/dB.h>
49 #include <ardour/amp.h>
50 #include <ardour/meter.h>
51 #include <ardour/buffer_set.h>
52 #include <ardour/mix.h>
53 #include <ardour/profile.h>
58 using namespace ARDOUR;
61 uint32_t Route::order_key_cnt = 0;
62 sigc::signal<void,const char*> Route::SyncOrderKeys;
64 Route::Route (Session& sess, string name, int input_min, int input_max, int output_min, int output_max, Flag flg, DataType default_type)
65 : IO (sess, name, input_min, input_max, output_min, output_max, default_type),
67 _solo_control (new ToggleControllable (X_("solo"), *this, ToggleControllable::SoloControl)),
68 _mute_control (new ToggleControllable (X_("mute"), *this, ToggleControllable::MuteControl))
73 Route::Route (Session& sess, const XMLNode& node, DataType default_type)
74 : IO (sess, *node.child ("IO"), default_type),
75 _solo_control (new ToggleControllable (X_("solo"), *this, ToggleControllable::SoloControl)),
76 _mute_control (new ToggleControllable (X_("mute"), *this, ToggleControllable::MuteControl))
79 _set_state (node, false);
85 processor_max_outs.reset();
91 _phase_invert = false;
92 _denormal_protection = false;
93 order_keys[strdup (N_("signal"))] = order_key_cnt++;
95 _meter_point = MeterPostFader;
100 _have_internal_generator = false;
101 _declickable = false;
102 _pending_declick = true;
103 _remote_control_id = 0;
108 _mute_affects_pre_fader = Config->get_mute_affects_pre_fader();
109 _mute_affects_post_fader = Config->get_mute_affects_post_fader();
110 _mute_affects_control_outs = Config->get_mute_affects_control_outs();
111 _mute_affects_main_outs = Config->get_mute_affects_main_outs();
114 desired_solo_gain = 1.0;
116 desired_mute_gain = 1.0;
120 input_changed.connect (mem_fun (this, &Route::input_change_handler));
121 output_changed.connect (mem_fun (this, &Route::output_change_handler));
126 clear_processors (PreFader);
127 clear_processors (PostFader);
129 for (OrderKeys::iterator i = order_keys.begin(); i != order_keys.end(); ++i) {
130 free ((void*)(i->first));
133 delete _control_outs;
137 Route::set_remote_control_id (uint32_t id)
139 if (id != _remote_control_id) {
140 _remote_control_id = id;
141 RemoteControlIDChanged ();
146 Route::remote_control_id() const
148 return _remote_control_id;
152 Route::order_key (const char* name) const
154 OrderKeys::const_iterator i;
156 for (i = order_keys.begin(); i != order_keys.end(); ++i) {
157 if (!strcmp (name, i->first)) {
166 Route::set_order_key (const char* name, long n)
168 order_keys[strdup(name)] = n;
170 if (Config->get_sync_all_route_ordering()) {
171 for (OrderKeys::iterator x = order_keys.begin(); x != order_keys.end(); ++x) {
176 _session.set_dirty ();
180 Route::sync_order_keys (const char* base)
182 if (order_keys.empty()) {
186 OrderKeys::iterator i;
189 if ((i = order_keys.find (base)) == order_keys.end()) {
190 /* key doesn't exist, use the first existing
191 key (this is done during session initialization)
193 i = order_keys.begin();
197 /* key exists - use it and reset all others
198 (actually, itself included)
200 i = order_keys.begin();
204 for (; i != order_keys.end(); ++i) {
210 Route::ensure_track_or_route_name(string name, Session &session)
212 string newname = name;
214 while (session.route_by_name (newname)!=NULL)
216 newname = bump_name_once (newname);
224 Route::inc_gain (gain_t fraction, void *src)
226 IO::inc_gain (fraction, src);
230 Route::set_gain (gain_t val, void *src)
232 if (src != 0 && _mix_group && src != _mix_group && _mix_group->is_active()) {
234 if (_mix_group->is_relative()) {
236 gain_t usable_gain = gain();
237 if (usable_gain < 0.000001f) {
238 usable_gain = 0.000001f;
242 if (delta < 0.000001f) {
246 delta -= usable_gain;
251 gain_t factor = delta / usable_gain;
254 factor = _mix_group->get_max_factor(factor);
255 if (factor == 0.0f) {
256 _gain_control->Changed(); /* EMIT SIGNAL */
260 factor = _mix_group->get_min_factor(factor);
261 if (factor == 0.0f) {
262 _gain_control->Changed(); /* EMIT SIGNAL */
267 _mix_group->apply (&Route::inc_gain, factor, _mix_group);
271 _mix_group->apply (&Route::set_gain, val, _mix_group);
281 IO::set_gain (val, src);
284 /** Process this route for one (sub) cycle (process thread)
286 * @param bufs Scratch buffers to use for the signal path
287 * @param start_frame Initial transport frame
288 * @param end_frame Final transport frame
289 * @param nframes Number of frames to output (to ports)
290 * @param offset Output offset (of port buffers, for split cycles)
292 * Note that (end_frame - start_frame) may not be equal to nframes when the
293 * transport speed isn't 1.0 (eg varispeed).
296 Route::process_output_buffers (BufferSet& bufs,
297 nframes_t start_frame, nframes_t end_frame,
298 nframes_t nframes, nframes_t offset, bool with_processors, int declick,
301 // This is definitely very audio-only for now
302 assert(_default_type == DataType::AUDIO);
304 ProcessorList::iterator i;
305 bool post_fader_work = false;
306 bool mute_declick_applied = false;
312 gain_t* gab = _session.gain_automation_buffer();
314 switch (Config->get_monitoring_model()) {
315 case HardwareMonitoring:
316 case ExternalMonitoring:
323 declick = _pending_declick;
326 Glib::Mutex::Lock cm (_control_outs_lock, Glib::TRY_LOCK);
336 Glib::Mutex::Lock dm (declick_lock, Glib::TRY_LOCK);
339 dmg = desired_mute_gain;
340 dsg = desired_solo_gain;
349 /* ----------------------------------------------------------------------------------------------------
350 GLOBAL DECLICK (for transport changes etc.)
351 -------------------------------------------------------------------------------------------------- */
354 Amp::run_in_place (bufs, nframes, 0.0, 1.0, false);
355 _pending_declick = 0;
356 } else if (declick < 0) {
357 Amp::run_in_place (bufs, nframes, 1.0, 0.0, false);
358 _pending_declick = 0;
361 /* no global declick */
363 if (solo_gain != dsg) {
364 Amp::run_in_place (bufs, nframes, solo_gain, dsg, false);
370 /* ----------------------------------------------------------------------------------------------------
371 INPUT METERING & MONITORING
372 -------------------------------------------------------------------------------------------------- */
374 if (meter && (_meter_point == MeterInput)) {
375 _meter->run_in_place(bufs, start_frame, end_frame, nframes, offset);
378 if (!_soloed && _mute_affects_pre_fader && (mute_gain != dmg)) {
379 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
381 mute_declick_applied = true;
384 if ((_meter_point == MeterInput) && co) {
386 solo_audible = dsg > 0;
387 mute_audible = dmg > 0;// || !_mute_affects_pre_fader;
389 if ( // muted by solo of another track
393 // muted by mute of this track
397 // rec-enabled but not s/w monitoring
399 // TODO: this is probably wrong
401 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
405 co->silence (nframes, offset);
409 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
414 /* -----------------------------------------------------------------------------------------------------
416 -------------------------------------------------------------------------------------------------- */
418 if (_denormal_protection || Config->get_denormal_protection()) {
420 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
421 Sample* const sp = i->data();
423 for (nframes_t nx = offset; nx < nframes + offset; ++nx) {
429 /* ----------------------------------------------------------------------------------------------------
431 -------------------------------------------------------------------------------------------------- */
433 if (with_processors) {
434 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
436 if (mute_gain > 0 || !_mute_affects_pre_fader) {
437 for (i = _processors.begin(); i != _processors.end(); ++i) {
438 switch ((*i)->placement()) {
440 (*i)->run_in_place (bufs, start_frame, end_frame, nframes, offset);
443 post_fader_work = true;
448 for (i = _processors.begin(); i != _processors.end(); ++i) {
449 switch ((*i)->placement()) {
451 (*i)->silence (nframes, offset);
454 post_fader_work = true;
462 /* When we entered this method, the number of bufs was set by n_process_buffers(), so
463 * it may be larger than required. Consider, for example, a mono track with two redirects A and B.
464 * If A has one input and three outputs, and B three inputs and one output, n_process_buffers()
465 * will be 3. In this case, now we've done pre-fader redirects, we can reset the number of bufs.
467 bufs.set_count (pre_fader_streams());
469 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_post_fader) {
470 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
472 mute_declick_applied = true;
475 /* ----------------------------------------------------------------------------------------------------
476 PRE-FADER METERING & MONITORING
477 -------------------------------------------------------------------------------------------------- */
479 if (meter && (_meter_point == MeterPreFader)) {
480 _meter->run_in_place(bufs, start_frame, end_frame, nframes, offset);
484 if ((_meter_point == MeterPreFader) && co) {
486 solo_audible = dsg > 0;
487 mute_audible = dmg > 0 || !_mute_affects_pre_fader;
489 if ( // muted by solo of another track
493 // muted by mute of this track
497 // rec-enabled but not s/w monitoring
499 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
503 co->silence (nframes, offset);
507 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
511 /* ----------------------------------------------------------------------------------------------------
513 -------------------------------------------------------------------------------------------------- */
515 /* if not recording or recording and requiring any monitor signal, then apply gain */
517 if ( // not recording
519 !(record_enabled() && _session.actively_recording()) ||
523 // AND software monitoring required
525 Config->get_monitoring_model() == SoftwareMonitoring) {
527 if (apply_gain_automation) {
530 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
531 Sample* const sp = i->data();
533 for (nframes_t nx = 0; nx < nframes; ++nx) {
538 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
539 Sample* const sp = i->data();
541 for (nframes_t nx = 0; nx < nframes; ++nx) {
547 if (apply_gain_automation && _session.transport_rolling() && nframes > 0) {
548 _effective_gain = gab[nframes-1];
553 /* manual (scalar) gain */
557 Amp::run_in_place (bufs, nframes, _gain, dg, _phase_invert);
560 } else if (_gain != 0 && (_phase_invert || _gain != 1.0)) {
562 /* no need to interpolate current gain value,
563 but its non-unity, so apply it. if the gain
564 is zero, do nothing because we'll ship silence
576 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
577 Sample* const sp = i->data();
578 apply_gain_to_buffer(sp,nframes,this_gain);
581 } else if (_gain == 0) {
582 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
590 /* actively recording, no monitoring required; leave buffers as-is to save CPU cycles */
594 /* ----------------------------------------------------------------------------------------------------
596 -------------------------------------------------------------------------------------------------- */
598 /* note that post_fader_work cannot be true unless with_processors was also true, so don't test both */
600 if (post_fader_work) {
602 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
604 if (mute_gain > 0 || !_mute_affects_post_fader) {
605 for (i = _processors.begin(); i != _processors.end(); ++i) {
606 switch ((*i)->placement()) {
610 (*i)->run_in_place (bufs, start_frame, end_frame, nframes, offset);
615 for (i = _processors.begin(); i != _processors.end(); ++i) {
616 switch ((*i)->placement()) {
620 (*i)->silence (nframes, offset);
628 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_control_outs) {
629 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
631 mute_declick_applied = true;
634 /* ----------------------------------------------------------------------------------------------------
636 -------------------------------------------------------------------------------------------------- */
638 if ((_meter_point == MeterPostFader) && co) {
640 solo_audible = solo_gain > 0;
641 mute_audible = dmg > 0 || !_mute_affects_control_outs;
643 if ( // silent anyway
645 (_gain == 0 && !apply_gain_automation) ||
647 // muted by solo of another track
651 // muted by mute of this track
655 // recording but not s/w monitoring
657 (no_monitor && record_enabled() && (!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() && (!Config->get_auto_input() || _session.actively_recording())) {
692 IO::silence (nframes, offset);
696 if ( // silent anyway
698 (_gain == 0 && !apply_gain_automation) ||
700 // muted by solo of another track, but not using control outs for solo
702 (!solo_audible && (Config->get_solo_model() != SoloBus)) ||
704 // muted by mute of this track
710 /* don't use Route::silence() here, because that causes
711 all outputs (sends, port processors, etc. to be silent).
714 if (_meter_point == MeterPostFader) {
715 peak_meter().reset();
718 IO::silence (nframes, offset);
722 deliver_output(bufs, start_frame, end_frame, nframes, offset);
728 /* ----------------------------------------------------------------------------------------------------
730 -------------------------------------------------------------------------------------------------- */
732 if (meter && (_meter_point == MeterPostFader)) {
733 if ((_gain == 0 && !apply_gain_automation) || dmg == 0) {
736 _meter->run_in_place(output_buffers(), start_frame, end_frame, nframes, offset);
742 /** Process this route for one (sub) cycle (process thread)
744 * @param bufs Scratch buffers to use for the signal path
745 * @param start_frame Initial transport frame
746 * @param end_frame Final transport frame
747 * @param nframes Number of frames to output (to ports)
748 * @param offset Output offset (of port buffers, for split cycles)
750 * Note that (end_frame - start_frame) may not be equal to nframes when the
751 * transport speed isn't 1.0 (eg varispeed).
754 Route::process_output_buffers (BufferSet& bufs,
755 nframes_t start_frame, nframes_t end_frame,
756 nframes_t nframes, nframes_t offset, bool with_processors, int declick,
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)
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);
827 /* ----------------------------------------------------------------------------------------------------
828 INPUT METERING & MONITORING
829 -------------------------------------------------------------------------------------------------- */
831 if (meter && (_meter_point == MeterInput)) {
832 _meter->run_in_place(bufs, start_frame, end_frame, nframes, offset);
835 if (!_soloed && _mute_affects_pre_fader && (mute_gain != dmg)) {
836 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
838 mute_declick_applied = true;
841 /* ----------------------------------------------------------------------------------------------------
843 -------------------------------------------------------------------------------------------------- */
845 // This really should already be true...
846 bufs.set_count(pre_fader_streams());
849 if ((_meter_point == MeterPreFader) && co) {
851 solo_audible = dsg > 0;
852 mute_audible = dmg > 0 || !_mute_affects_pre_fader;
854 if ( // muted by solo of another track
858 // muted by mute of this track
862 // rec-enabled but not s/w monitoring
864 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
868 co->silence (nframes, offset);
872 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
876 /* ----------------------------------------------------------------------------------------------------
878 -------------------------------------------------------------------------------------------------- */
880 /* if not recording or recording and requiring any monitor signal, then apply gain */
882 if ( // not recording
884 !(record_enabled() && _session.actively_recording()) ||
888 // AND software monitoring required
890 Config->get_monitoring_model() == SoftwareMonitoring) {
892 if (apply_gain_automation) {
895 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
896 Sample* const sp = i->data();
898 for (nframes_t nx = 0; nx < nframes; ++nx) {
903 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
904 Sample* const sp = i->data();
906 for (nframes_t nx = 0; nx < nframes; ++nx) {
912 if (apply_gain_automation && _session.transport_rolling() && nframes > 0) {
913 _effective_gain = gab[nframes-1];
918 /* manual (scalar) gain */
922 Amp::run_in_place (bufs, nframes, _gain, dg, _phase_invert);
925 } else if (_gain != 0 && (_phase_invert || _gain != 1.0)) {
927 /* no need to interpolate current gain value,
928 but its non-unity, so apply it. if the gain
929 is zero, do nothing because we'll ship silence
941 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
942 Sample* const sp = i->data();
943 apply_gain_to_buffer(sp,nframes,this_gain);
946 } else if (_gain == 0) {
947 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
955 /* actively recording, no monitoring required; leave buffers as-is to save CPU cycles */
960 /* ----------------------------------------------------------------------------------------------------
962 -------------------------------------------------------------------------------------------------- */
964 if ((_meter_point == MeterPostFader) && co) {
966 solo_audible = solo_gain > 0;
967 mute_audible = dmg > 0 || !_mute_affects_control_outs;
969 if ( // silent anyway
971 (_gain == 0 && !apply_gain_automation) ||
973 // muted by solo of another track
977 // muted by mute of this track
981 // recording but not s/w monitoring
983 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
987 co->silence (nframes, offset);
991 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
995 /* ----------------------------------------------------------------------------------------------------
997 -------------------------------------------------------------------------------------------------- */
999 solo_audible = dsg > 0;
1000 mute_audible = dmg > 0 || !_mute_affects_main_outs;
1002 if (n_outputs().get(_default_type) == 0) {
1006 } else if (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording())) {
1008 IO::silence (nframes, offset);
1012 if ( // silent anyway
1014 (_gain == 0 && !apply_gain_automation) ||
1016 // muted by solo of another track, but not using control outs for solo
1018 (!solo_audible && (Config->get_solo_model() != SoloBus)) ||
1020 // muted by mute of this track
1026 /* don't use Route::silence() here, because that causes
1027 all outputs (sends, port processors, etc. to be silent).
1030 if (_meter_point == MeterPostFader) {
1031 peak_meter().reset();
1034 IO::silence (nframes, offset);
1038 deliver_output(bufs, start_frame, end_frame, nframes, offset);
1045 #endif /* NEW_POB */
1048 Route::n_process_buffers ()
1050 return max (n_inputs(), processor_max_outs);
1054 Route::passthru (nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset, int declick, bool meter_first)
1056 BufferSet& bufs = _session.get_scratch_buffers(n_process_buffers());
1060 collect_input (bufs, nframes, offset);
1063 _meter->run_in_place(bufs, start_frame, end_frame, nframes, offset);
1064 meter_first = false;
1069 process_output_buffers (bufs, start_frame, end_frame, nframes, offset, true, declick, meter_first);
1073 Route::passthru_silence (nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset, int declick, bool meter)
1075 process_output_buffers (_session.get_silent_buffers (n_process_buffers()), start_frame, end_frame, nframes, offset, true, declick, meter);
1079 Route::set_solo (bool yn, void *src)
1085 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
1086 _mix_group->apply (&Route::set_solo, yn, _mix_group);
1090 if (_soloed != yn) {
1092 solo_changed (src); /* EMIT SIGNAL */
1093 _solo_control->Changed (); /* EMIT SIGNAL */
1096 catch_up_on_solo_mute_override ();
1100 Route::catch_up_on_solo_mute_override ()
1102 if (Config->get_solo_model() != InverseMute) {
1108 Glib::Mutex::Lock lm (declick_lock);
1111 if (Config->get_solo_mute_override()) {
1112 desired_mute_gain = (_soloed?1.0:0.0);
1114 desired_mute_gain = 0.0;
1117 desired_mute_gain = 1.0;
1123 Route::set_solo_mute (bool yn)
1125 Glib::Mutex::Lock lm (declick_lock);
1127 /* Called by Session in response to another Route being soloed.
1130 desired_solo_gain = (yn?0.0:1.0);
1134 Route::set_solo_safe (bool yn, void *src)
1136 if (_solo_safe != yn) {
1138 solo_safe_changed (src); /* EMIT SIGNAL */
1143 Route::set_mute (bool yn, void *src)
1146 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
1147 _mix_group->apply (&Route::set_mute, yn, _mix_group);
1153 mute_changed (src); /* EMIT SIGNAL */
1155 _mute_control->Changed (); /* EMIT SIGNAL */
1157 Glib::Mutex::Lock lm (declick_lock);
1159 if (_soloed && Config->get_solo_mute_override()){
1160 desired_mute_gain = 1.0f;
1162 desired_mute_gain = (yn?0.0f:1.0f);
1168 Route::add_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err)
1170 ChanCount old_pmo = processor_max_outs;
1172 if (!_session.engine().connected()) {
1177 Glib::RWLock::WriterLock lm (_processor_lock);
1179 boost::shared_ptr<PluginInsert> pi;
1180 boost::shared_ptr<PortInsert> porti;
1182 //processor->set_default_type(_default_type);
1184 _processors.push_back (processor);
1186 // Set up processor list channels. This will set processor->[input|output]_streams(),
1187 // configure redirect ports properly, etc.
1188 if (_reset_processor_counts (err)) {
1189 _processors.pop_back ();
1190 _reset_processor_counts (0); // it worked before we tried to add it ...
1194 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
1196 if (pi->natural_input_streams() == ChanCount::ZERO) {
1197 /* generator plugin */
1198 _have_internal_generator = true;
1203 // Ensure peak vector sizes before the plugin is activated
1205 ChanCount potential_max_streams;
1207 potential_max_streams.set (DataType::AUDIO, max (processor->input_streams().n_audio(),
1208 processor->output_streams().n_audio()));
1209 potential_max_streams.set (DataType::MIDI, max (processor->input_streams().n_midi(),
1210 processor->output_streams().n_midi()));
1212 _meter->configure_io (potential_max_streams, potential_max_streams);
1214 // XXX: do we want to emit the signal here ? change call order.
1215 processor->activate ();
1216 processor->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
1221 if (processor_max_outs != old_pmo || old_pmo == ChanCount::ZERO) {
1225 processors_changed (); /* EMIT SIGNAL */
1231 Route::add_processors (const ProcessorList& others, ProcessorStreams* err)
1233 /* NOTE: this is intended to be used ONLY when copying
1234 processors from another Route. Hence the subtle
1235 differences between this and ::add_processor()
1238 ChanCount old_pmo = processor_max_outs;
1240 if (!_session.engine().connected()) {
1245 Glib::RWLock::WriterLock lm (_processor_lock);
1247 ProcessorList::iterator existing_end = _processors.end();
1250 ChanCount potential_max_streams;
1252 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1254 boost::shared_ptr<PluginInsert> pi;
1256 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1259 ChanCount m = max(pi->input_streams(), pi->output_streams());
1260 if (m > potential_max_streams)
1261 potential_max_streams = m;
1264 // Ensure peak vector sizes before the plugin is activated
1265 _meter->configure_io (potential_max_streams, potential_max_streams);
1267 _processors.push_back (*i);
1269 if (_reset_processor_counts (err)) {
1271 _processors.erase (existing_end, _processors.end());
1272 _reset_processor_counts (0); // it worked before we tried to add it ...
1276 (*i)->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
1282 if (processor_max_outs != old_pmo || old_pmo == ChanCount::ZERO) {
1286 processors_changed (); /* EMIT SIGNAL */
1290 /** Turn off all processors with a given placement
1291 * @param p Placement of processors to disable
1295 Route::disable_processors (Placement p)
1297 Glib::RWLock::ReaderLock lm (_processor_lock);
1299 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1300 if ((*i)->placement() == p) {
1301 (*i)->deactivate ();
1305 _session.set_dirty ();
1308 /** 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
1328 Route::disable_plugins (Placement p)
1330 Glib::RWLock::ReaderLock lm (_processor_lock);
1332 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1333 if (boost::dynamic_pointer_cast<PluginInsert> (*i) && (*i)->placement() == p) {
1334 (*i)->deactivate ();
1338 _session.set_dirty ();
1341 /** Turn off all plugins
1345 Route::disable_plugins ()
1347 Glib::RWLock::ReaderLock lm (_processor_lock);
1349 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1350 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1351 (*i)->deactivate ();
1355 _session.set_dirty ();
1360 Route::ab_plugins (bool forward)
1362 Glib::RWLock::ReaderLock lm (_processor_lock);
1366 /* forward = turn off all active redirects, and mark them so that the next time
1367 we go the other way, we will revert them
1370 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1371 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1375 if ((*i)->active()) {
1376 (*i)->deactivate ();
1377 (*i)->set_next_ab_is_active (true);
1379 (*i)->set_next_ab_is_active (false);
1385 /* backward = if the redirect was marked to go active on the next ab, do so */
1387 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1389 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1393 if ((*i)->get_next_ab_is_active()) {
1396 (*i)->deactivate ();
1401 _session.set_dirty ();
1405 /* Figure out the streams that will feed into PreFader */
1407 Route::pre_fader_streams() const
1409 boost::shared_ptr<Processor> processor;
1411 /* Find the last pre-fader redirect that isn't a send; sends don't affect the number
1413 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1414 if ((*i)->placement() == PreFader && boost::dynamic_pointer_cast<Send> (*i) == 0) {
1420 return processor->output_streams();
1427 /** Remove processors with a given placement.
1428 * @param p Placement of processors to remove.
1431 Route::clear_processors (Placement p)
1433 const ChanCount old_pmo = processor_max_outs;
1435 if (!_session.engine().connected()) {
1440 Glib::RWLock::WriterLock lm (_processor_lock);
1441 ProcessorList new_list;
1443 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1444 if ((*i)->placement() == p) {
1445 /* it's the placement we want to get rid of */
1446 (*i)->drop_references ();
1448 /* it's a different placement, so keep it */
1449 new_list.push_back (*i);
1453 _processors = new_list;
1456 /* FIXME: can't see how this test can ever fire */
1457 if (processor_max_outs != old_pmo) {
1461 processor_max_outs.reset();
1462 _have_internal_generator = false;
1463 processors_changed (); /* EMIT SIGNAL */
1467 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err)
1469 ChanCount old_pmo = processor_max_outs;
1471 if (!_session.engine().connected()) {
1475 processor_max_outs.reset();
1478 Glib::RWLock::WriterLock lm (_processor_lock);
1479 ProcessorList::iterator i;
1480 bool removed = false;
1482 for (i = _processors.begin(); i != _processors.end(); ++i) {
1483 if (*i == processor) {
1485 ProcessorList::iterator tmp;
1487 /* move along, see failure case for reset_processor_counts()
1488 where we may need to reprocessor the processor.
1494 /* stop redirects that send signals to JACK ports
1495 from causing noise as a result of no longer being
1499 boost::shared_ptr<IOProcessor> redirect;
1501 if ((redirect = boost::dynamic_pointer_cast<IOProcessor> (*i)) != 0) {
1502 redirect->io()->disconnect_inputs (this);
1503 redirect->io()->disconnect_outputs (this);
1506 _processors.erase (i);
1521 if (_reset_processor_counts (err)) {
1522 /* get back to where we where */
1523 _processors.insert (i, processor);
1524 /* we know this will work, because it worked before :) */
1525 _reset_processor_counts (0);
1529 _have_internal_generator = false;
1531 for (i = _processors.begin(); i != _processors.end(); ++i) {
1532 boost::shared_ptr<PluginInsert> pi;
1534 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1535 if (pi->is_generator()) {
1536 _have_internal_generator = true;
1543 if (old_pmo != processor_max_outs) {
1547 processor->drop_references ();
1549 processors_changed (); /* EMIT SIGNAL */
1554 Route::reset_processor_counts (ProcessorStreams* err)
1556 Glib::RWLock::WriterLock lm (_processor_lock);
1557 return _reset_processor_counts (err);
1562 Route::_reset_processor_counts (ProcessorStreams* err)
1564 ProcessorList::iterator r;
1565 uint32_t insert_cnt = 0;
1566 uint32_t send_cnt = 0;
1567 map<Placement,list<ProcessorCount> > proc_map;
1568 ProcessorList::iterator prev;
1569 ChanCount initial_streams = n_inputs ();
1570 ChanCount previous_initial_streams = n_inputs ();
1572 uint32_t max_audio = 0;
1573 uint32_t max_midi = 0;
1575 processor_max_outs.reset ();
1577 /* Step 1: build a map that links each insert to an in/out channel count
1579 Divide inserts up by placement so we get the signal flow
1580 properly modelled. we need to do this because the _processors
1581 list is not sorted by placement, and because other reasons may
1582 exist now or in the future for this separate treatment.
1585 /* ... but it should/will be... */
1587 for (r = _processors.begin(); r != _processors.end(); ++r) {
1589 boost::shared_ptr<PluginInsert> plugin_insert;
1590 boost::shared_ptr<PortInsert> port_insert;
1592 if ((plugin_insert = boost::dynamic_pointer_cast<PluginInsert>(*r)) != 0) {
1595 proc_map[(*r)->placement()].push_back (ProcessorCount (*r));
1597 /* reset plugin counts back to one for now so
1598 that we have a predictable, controlled
1599 state to try to configure.
1602 plugin_insert->set_count (1);
1604 } else if ((port_insert = boost::dynamic_pointer_cast<PortInsert>(*r)) != 0) {
1607 proc_map[(*r)->placement()].push_back (ProcessorCount (*r));
1609 } else if (boost::dynamic_pointer_cast<Send> (*r) != 0) {
1611 } else if (boost::dynamic_pointer_cast<InternalSend> (*r) != 0) {
1616 if (insert_cnt == 0) {
1625 /* Now process each placement in order, checking to see if we
1626 can really do what has been requested.
1631 if (check_some_processor_counts (proc_map[PreFader], n_inputs (), err)) {
1635 if (!proc_map[PreFader].empty()) {
1636 previous_initial_streams = n_inputs ();
1637 for (list<ProcessorCount>::iterator i = proc_map[PreFader].begin(); i != proc_map[PreFader].end(); i++) {
1638 if (i->processor->can_support_io_configuration (previous_initial_streams, initial_streams) < 0) {
1641 previous_initial_streams = initial_streams;
1647 if (check_some_processor_counts (proc_map[PostFader], initial_streams, err)) {
1651 if (!proc_map[PostFader].empty()) {
1652 for (list<ProcessorCount>::iterator i = proc_map[PostFader].begin(); i != proc_map[PostFader].end(); i++) {
1653 if (i->processor->can_support_io_configuration (previous_initial_streams, initial_streams) < 0) {
1656 previous_initial_streams = initial_streams;
1660 /* OK, everything can be set up correctly, so lets do it */
1662 apply_some_processor_counts (proc_map[PreFader]);
1663 apply_some_processor_counts (proc_map[PostFader]);
1665 /* recompute max outs of any processor */
1671 processor_max_outs.reset ();
1672 prev = _processors.end();
1674 for (r = _processors.begin(); r != _processors.end(); prev = r, ++r) {
1675 boost::shared_ptr<Send> s;
1676 boost::shared_ptr<InternalSend> is;
1678 if ((s = boost::dynamic_pointer_cast<Send> (*r)) != 0) {
1680 /* don't pay any attention to send output configuration, since it doesn't
1684 if (r == _processors.begin()) {
1685 s->expect_inputs (n_inputs());
1687 s->expect_inputs ((*prev)->output_streams());
1690 } else if ((is = boost::dynamic_pointer_cast<InternalSend> (*r)) != 0) {
1692 /* XXX ditto, but clean this inheritance pattern up someday soon */
1694 if (r == _processors.begin()) {
1695 is->expect_inputs (n_inputs());
1697 is->expect_inputs ((*prev)->output_streams());
1702 max_audio = max ((*r)->output_streams ().n_audio(), max_audio);
1703 max_midi = max ((*r)->output_streams ().n_midi(), max_midi);
1707 processor_max_outs.set (DataType::AUDIO, max_audio);
1708 processor_max_outs.set (DataType::MIDI, max_midi);
1714 for (r = _processors.begin(); r != _processors.end(); ++r) {
1715 max_audio = max ((*r)->output_streams ().n_audio(), max_audio);
1716 max_midi = max ((*r)->output_streams ().n_midi(), max_midi);
1719 processor_max_outs.set (DataType::AUDIO, max_audio);
1720 processor_max_outs.set (DataType::MIDI, max_midi);
1726 Route::apply_some_processor_counts (list<ProcessorCount>& iclist)
1728 list<ProcessorCount>::iterator i;
1730 for (i = iclist.begin(); i != iclist.end(); ++i) {
1732 ProcessorCount& pc (*i);
1734 if (pc.processor->configure_io (pc.in, pc.out)) {
1738 /* make sure that however many we have, they are all active */
1740 pc.processor->activate ();
1746 /** Returns whether \a iclist can be configured and run starting with
1747 * \a required_inputs at the first processor's inputs.
1748 * If false is returned, \a iclist can not be run with \a required_inputs, and \a err is set.
1749 * Otherwise, \a err is set to the output of the list.
1752 Route::check_some_processor_counts (list<ProcessorCount>& iclist, ChanCount required_inputs, ProcessorStreams* err)
1754 list<ProcessorCount>::iterator i;
1759 err->count = required_inputs;
1762 for (i = iclist.begin(); i != iclist.end(); ++i, ++index) {
1764 if (!(*i).processor->can_support_io_configuration (required_inputs, (*i).out)) {
1767 err->count = required_inputs;
1772 (*i).in = required_inputs;
1773 required_inputs = (*i).out;
1780 Route::copy_processors (const Route& other, Placement placement, ProcessorStreams* err)
1782 ChanCount old_pmo = processor_max_outs;
1784 ProcessorList to_be_deleted;
1787 Glib::RWLock::WriterLock lm (_processor_lock);
1788 ProcessorList::iterator tmp;
1789 ProcessorList the_copy;
1791 the_copy = _processors;
1793 /* remove all relevant processors */
1795 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ) {
1799 if ((*i)->placement() == placement) {
1800 to_be_deleted.push_back (*i);
1801 _processors.erase (i);
1807 /* now copy the relevant ones from "other" */
1809 for (ProcessorList::const_iterator i = other._processors.begin(); i != other._processors.end(); ++i) {
1810 if ((*i)->placement() == placement) {
1811 _processors.push_back (IOProcessor::clone (*i));
1815 /* reset plugin stream handling */
1817 if (_reset_processor_counts (err)) {
1819 /* FAILED COPY ATTEMPT: we have to restore order */
1821 /* delete all cloned processors */
1823 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ) {
1828 if ((*i)->placement() == placement) {
1829 _processors.erase (i);
1835 /* restore the natural order */
1837 _processors = the_copy;
1838 processor_max_outs = old_pmo;
1840 /* we failed, even though things are OK again */
1846 /* SUCCESSFUL COPY ATTEMPT: delete the processors we removed pre-copy */
1847 to_be_deleted.clear ();
1852 if (processor_max_outs != old_pmo || old_pmo == ChanCount::ZERO) {
1856 processors_changed (); /* EMIT SIGNAL */
1861 Route::all_processors_flip ()
1863 Glib::RWLock::ReaderLock lm (_processor_lock);
1865 if (_processors.empty()) {
1869 bool first_is_on = _processors.front()->active();
1871 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1873 (*i)->deactivate ();
1879 _session.set_dirty ();
1882 /** Set all processors with a given placement to a given active state.
1883 * @param p Placement of processors to change.
1884 * @param state New active state for those processors.
1887 Route::all_processors_active (Placement p, bool state)
1889 Glib::RWLock::ReaderLock lm (_processor_lock);
1891 if (_processors.empty()) {
1895 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1896 if ((*i)->placement() == p) {
1900 (*i)->deactivate ();
1905 _session.set_dirty ();
1908 struct ProcessorSorter {
1909 bool operator() (boost::shared_ptr<const Processor> a, boost::shared_ptr<const Processor> b) {
1910 return a->sort_key() < b->sort_key();
1915 Route::sort_processors (ProcessorStreams* err)
1918 ProcessorSorter comparator;
1919 Glib::RWLock::WriterLock lm (_processor_lock);
1920 ChanCount old_pmo = processor_max_outs;
1922 /* the sweet power of C++ ... */
1924 ProcessorList as_it_was_before = _processors;
1926 _processors.sort (comparator);
1928 if (_reset_processor_counts (err)) {
1929 _processors = as_it_was_before;
1930 processor_max_outs = old_pmo;
1936 processors_changed (); /* EMIT SIGNAL */
1948 Route::get_template()
1950 return state(false);
1954 Route::state(bool full_state)
1956 XMLNode *node = new XMLNode("Route");
1957 ProcessorList::iterator i;
1961 node->add_property("flags", enum_2_string (_flags));
1964 node->add_property("default-type", _default_type.to_string());
1966 node->add_property("active", _active?"yes":"no");
1967 node->add_property("muted", _muted?"yes":"no");
1968 node->add_property("soloed", _soloed?"yes":"no");
1969 node->add_property("phase-invert", _phase_invert?"yes":"no");
1970 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
1971 node->add_property("mute-affects-pre-fader", _mute_affects_pre_fader?"yes":"no");
1972 node->add_property("mute-affects-post-fader", _mute_affects_post_fader?"yes":"no");
1973 node->add_property("mute-affects-control-outs", _mute_affects_control_outs?"yes":"no");
1974 node->add_property("mute-affects-main-outs", _mute_affects_main_outs?"yes":"no");
1975 node->add_property("meter-point", enum_2_string (_meter_point));
1978 node->add_property("edit-group", _edit_group->name());
1981 node->add_property("mix-group", _mix_group->name());
1984 string order_string;
1985 OrderKeys::iterator x = order_keys.begin();
1987 while (x != order_keys.end()) {
1988 order_string += string ((*x).first);
1989 order_string += '=';
1990 snprintf (buf, sizeof(buf), "%ld", (*x).second);
1991 order_string += buf;
1995 if (x == order_keys.end()) {
1999 order_string += ':';
2001 node->add_property ("order-keys", order_string);
2003 node->add_child_nocopy (IO::state (full_state));
2004 node->add_child_nocopy (_solo_control->get_state ());
2005 node->add_child_nocopy (_mute_control->get_state ());
2007 XMLNode* remote_control_node = new XMLNode (X_("remote_control"));
2008 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
2009 remote_control_node->add_property (X_("id"), buf);
2010 node->add_child_nocopy (*remote_control_node);
2012 if (_control_outs) {
2013 XMLNode* cnode = new XMLNode (X_("ControlOuts"));
2014 cnode->add_child_nocopy (_control_outs->state (full_state));
2015 node->add_child_nocopy (*cnode);
2018 if (_comment.length()) {
2019 XMLNode *cmt = node->add_child ("Comment");
2020 cmt->add_content (_comment);
2023 for (i = _processors.begin(); i != _processors.end(); ++i) {
2024 node->add_child_nocopy((*i)->state (full_state));
2028 node->add_child_copy (*_extra_xml);
2035 Route::get_processor_state ()
2037 XMLNode* root = new XMLNode (X_("redirects"));
2038 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2039 root->add_child_nocopy ((*i)->state (true));
2046 Route::set_processor_state (const XMLNode& root)
2048 if (root.name() != X_("redirects")) {
2054 XMLNodeConstIterator iter;
2055 XMLNodeConstIterator niter;
2056 Glib::RWLock::ReaderLock lm (_processor_lock);
2058 nlist = root.children();
2060 for (iter = nlist.begin(); iter != nlist.end(); ++iter){
2062 /* iter now points to a IOProcessor state node */
2064 nnlist = (*iter)->children ();
2066 for (niter = nnlist.begin(); niter != nnlist.end(); ++niter) {
2068 /* find the IO child node, since it contains the ID we need */
2070 /* XXX OOP encapsulation violation, ugh */
2072 if ((*niter)->name() == IO::state_node_name) {
2074 XMLProperty* prop = (*niter)->property (X_("id"));
2077 warning << _("IOProcessor node has no ID, ignored") << endmsg;
2081 ID id = prop->value ();
2083 /* now look for a processor with that ID */
2085 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2086 if ((*i)->id() == id) {
2087 (*i)->set_state (**iter);
2103 Route::set_deferred_state ()
2106 XMLNodeConstIterator niter;
2108 if (!deferred_state) {
2112 nlist = deferred_state->children();
2114 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2115 add_processor_from_xml (**niter);
2118 delete deferred_state;
2123 Route::add_processor_from_xml (const XMLNode& node)
2125 const XMLProperty *prop;
2127 // legacy sessions use a different node name for sends
2128 if (node.name() == "Send") {
2131 boost::shared_ptr<Send> send (new Send (_session, node));
2132 add_processor (send);
2135 catch (failed_constructor &err) {
2136 error << _("Send construction failed") << endmsg;
2140 // use "Processor" in XML?
2141 } else if (node.name() == "Processor") {
2144 if ((prop = node.property ("type")) != 0) {
2146 boost::shared_ptr<Processor> processor;
2147 bool have_insert = false;
2149 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
2150 prop->value() == "lv2" ||
2151 prop->value() == "vst" ||
2152 prop->value() == "audiounit") {
2154 processor.reset (new PluginInsert(_session, node));
2157 } else if (prop->value() == "port") {
2159 processor.reset (new PortInsert (_session, node));
2161 } else if (prop->value() == "send") {
2163 processor.reset (new Send (_session, node));
2168 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
2171 add_processor (processor);
2174 error << _("Processor XML node has no type property") << endmsg;
2178 catch (failed_constructor &err) {
2179 warning << _("processor could not be created. Ignored.") << endmsg;
2186 Route::set_state (const XMLNode& node)
2188 return _set_state (node, true);
2192 Route::_set_state (const XMLNode& node, bool call_base)
2195 XMLNodeConstIterator niter;
2197 XMLPropertyList plist;
2198 const XMLProperty *prop;
2200 if (node.name() != "Route"){
2201 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2205 if ((prop = node.property (X_("flags"))) != 0) {
2206 _flags = Flag (string_2_enum (prop->value(), _flags));
2211 if ((prop = node.property (X_("default-type"))) != 0) {
2212 _default_type = DataType(prop->value());
2213 assert(_default_type != DataType::NIL);
2216 if ((prop = node.property (X_("phase-invert"))) != 0) {
2217 set_phase_invert (prop->value()=="yes"?true:false, this);
2220 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2221 set_denormal_protection (prop->value()=="yes"?true:false, this);
2225 if ((prop = node.property (X_("active"))) != 0) {
2226 set_active (prop->value() == "yes");
2229 if ((prop = node.property (X_("muted"))) != 0) {
2230 bool yn = prop->value()=="yes"?true:false;
2232 /* force reset of mute status */
2236 mute_gain = desired_mute_gain;
2239 if ((prop = node.property (X_("soloed"))) != 0) {
2240 bool yn = prop->value()=="yes"?true:false;
2242 /* force reset of solo status */
2245 set_solo (yn, this);
2246 solo_gain = desired_solo_gain;
2249 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2250 _mute_affects_pre_fader = (prop->value()=="yes")?true:false;
2253 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2254 _mute_affects_post_fader = (prop->value()=="yes")?true:false;
2257 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2258 _mute_affects_control_outs = (prop->value()=="yes")?true:false;
2261 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2262 _mute_affects_main_outs = (prop->value()=="yes")?true:false;
2265 if ((prop = node.property (X_("meter-point"))) != 0) {
2266 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2269 if ((prop = node.property (X_("edit-group"))) != 0) {
2270 RouteGroup* edit_group = _session.edit_group_by_name(prop->value());
2271 if(edit_group == 0) {
2272 error << string_compose(_("Route %1: unknown edit group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
2274 set_edit_group(edit_group, this);
2278 if ((prop = node.property (X_("order-keys"))) != 0) {
2282 string::size_type colon, equal;
2283 string remaining = prop->value();
2285 while (remaining.length()) {
2287 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2288 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2291 if (sscanf (remaining.substr (equal+1).c_str(), "%ld", &n) != 1) {
2292 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2295 set_order_key (remaining.substr (0, equal).c_str(), n);
2299 colon = remaining.find_first_of (':');
2301 if (colon != string::npos) {
2302 remaining = remaining.substr (colon+1);
2309 nlist = node.children();
2311 delete deferred_state;
2312 deferred_state = new XMLNode(X_("deferred state"));
2314 /* set parent class properties before anything else */
2316 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2320 if (child->name() == IO::state_node_name && call_base) {
2322 IO::set_state (*child);
2327 XMLNodeList processor_nodes;
2329 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2333 if (child->name() == X_("Send") || child->name() == X_("Processor")) {
2334 processor_nodes.push_back(child);
2339 _set_processor_states(processor_nodes);
2342 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2344 // All processors have been applied already
2346 if (child->name() == X_("Automation")) {
2348 if ((prop = child->property (X_("path"))) != 0) {
2349 load_automation (prop->value());
2352 } else if (child->name() == X_("ControlOuts")) {
2354 string coutname = _name;
2355 coutname += _("[control]");
2357 delete _control_outs;
2358 _control_outs = new IO (_session, coutname);
2359 _control_outs->set_state (**(child->children().begin()));
2361 } else if (child->name() == X_("Comment")) {
2363 /* XXX this is a terrible API design in libxml++ */
2365 XMLNode *cmt = *(child->children().begin());
2366 _comment = cmt->content();
2368 } else if (child->name() == X_("extra")) {
2370 _extra_xml = new XMLNode (*child);
2372 } else if (child->name() == X_("controllable") && (prop = child->property("name")) != 0) {
2374 if (prop->value() == "solo") {
2375 _solo_control->set_state (*child);
2376 _session.add_controllable (_solo_control);
2378 else if (prop->value() == "mute") {
2379 _mute_control->set_state (*child);
2380 _session.add_controllable (_mute_control);
2383 else if (child->name() == X_("remote_control")) {
2384 if ((prop = child->property (X_("id"))) != 0) {
2386 sscanf (prop->value().c_str(), "%d", &x);
2387 set_remote_control_id (x);
2392 if ((prop = node.property (X_("mix-group"))) != 0) {
2393 RouteGroup* mix_group = _session.mix_group_by_name(prop->value());
2394 if (mix_group == 0) {
2395 error << string_compose(_("Route %1: unknown mix group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
2397 set_mix_group(mix_group, this);
2405 Route::_set_processor_states(const XMLNodeList &nlist)
2407 XMLNodeConstIterator niter;
2410 ProcessorList::iterator i, o;
2412 // Iterate through existing processors, remove those which are not in the state list
2413 for (i = _processors.begin(); i != _processors.end(); ) {
2414 ProcessorList::iterator tmp = i;
2417 bool processorInStateList = false;
2419 (*i)->id().print (buf, sizeof (buf));
2422 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2424 // legacy sessions (IOProcessor as a child of Processor, both is-a IO)
2425 if (strncmp(buf,(*niter)->child(X_("IOProcessor"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf)) == 0) {
2426 processorInStateList = true;
2428 } else if (strncmp(buf,(*niter)->property(X_("id"))->value().c_str(), sizeof(buf)) == 0) {
2429 processorInStateList = true;
2434 if (!processorInStateList) {
2435 remove_processor (*i);
2443 // Iterate through state list and make sure all processors are on the track and in the correct order,
2444 // set the state of existing processors according to the new state on the same go
2445 i = _processors.begin();
2446 for (niter = nlist.begin(); niter != nlist.end(); ++niter, ++i) {
2448 // Check whether the next processor in the list
2451 while (o != _processors.end()) {
2452 (*o)->id().print (buf, sizeof (buf));
2453 if ( strncmp(buf, (*niter)->child(X_("IOProcessor"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf)) == 0)
2455 else if (strncmp(buf,(*niter)->property(X_("id"))->value().c_str(), sizeof(buf)) == 0)
2461 if (o == _processors.end()) {
2462 // If the processor (*niter) is not on the route, we need to create it
2463 // and move it to the correct location
2465 ProcessorList::iterator prev_last = _processors.end();
2466 --prev_last; // We need this to check whether adding succeeded
2468 add_processor_from_xml (**niter);
2470 ProcessorList::iterator last = _processors.end();
2473 if (prev_last == last) {
2474 cerr << "Could not fully restore state as some processors were not possible to create" << endl;
2479 boost::shared_ptr<Processor> tmp = (*last);
2480 // remove the processor from the wrong location
2481 _processors.erase(last);
2482 // processor the new processor at the current location
2483 _processors.insert(i, tmp);
2485 --i; // move pointer to the newly processored processor
2489 // We found the processor (*niter) on the route, first we must make sure the processor
2490 // is at the location provided in the XML state
2492 boost::shared_ptr<Processor> tmp = (*o);
2493 // remove the old copy
2494 _processors.erase(o);
2495 // processor the processor at the correct location
2496 _processors.insert(i, tmp);
2498 --i; // move pointer so it points to the right processor
2501 (*i)->set_state( (**niter) );
2504 processors_changed ();
2508 Route::curve_reallocate ()
2510 // _gain_automation_curve.finish_resize ();
2511 // _pan_automation_curve.finish_resize ();
2515 Route::silence (nframes_t nframes, nframes_t offset)
2519 IO::silence (nframes, offset);
2521 if (_control_outs) {
2522 _control_outs->silence (nframes, offset);
2526 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2529 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2530 boost::shared_ptr<PluginInsert> pi;
2531 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2532 // skip plugins, they don't need anything when we're not active
2536 (*i)->silence (nframes, offset);
2539 if (nframes == _session.get_block_size() && offset == 0) {
2549 Route::set_control_outs (const vector<string>& ports)
2551 Glib::Mutex::Lock lm (_control_outs_lock);
2552 vector<string>::const_iterator i;
2555 delete _control_outs;
2558 if (is_control() || is_master()) {
2559 /* no control outs for these two special busses */
2563 if (ports.empty()) {
2567 string coutname = _name;
2568 coutname += _("[control]");
2570 _control_outs = new IO (_session, coutname);
2572 /* our control outs need as many outputs as we
2573 have audio outputs. we track the changes in ::output_change_handler().
2576 // XXX its stupid that we have to get this value twice
2578 limit = n_outputs().n_audio();
2580 if (_control_outs->ensure_io (ChanCount::ZERO, ChanCount (DataType::AUDIO, n_outputs().get (DataType::AUDIO)), true, this)) {
2584 /* now connect to the named ports */
2586 for (size_t n = 0; n < limit; ++n) {
2587 if (_control_outs->connect_output (_control_outs->output (n), ports[n % ports.size()], this)) {
2588 error << string_compose (_("could not connect %1 to %2"), _control_outs->output(n)->name(), ports[n]) << endmsg;
2597 Route::set_edit_group (RouteGroup *eg, void *src)
2600 if (eg == _edit_group) {
2605 _edit_group->remove (this);
2608 if ((_edit_group = eg) != 0) {
2609 _edit_group->add (this);
2612 _session.set_dirty ();
2613 edit_group_changed (src); /* EMIT SIGNAL */
2617 Route::drop_edit_group (void *src)
2620 _session.set_dirty ();
2621 edit_group_changed (src); /* EMIT SIGNAL */
2625 Route::set_mix_group (RouteGroup *mg, void *src)
2628 if (mg == _mix_group) {
2633 _mix_group->remove (this);
2636 if ((_mix_group = mg) != 0) {
2637 _mix_group->add (this);
2640 _session.set_dirty ();
2641 mix_group_changed (src); /* EMIT SIGNAL */
2645 Route::drop_mix_group (void *src)
2648 _session.set_dirty ();
2649 mix_group_changed (src); /* EMIT SIGNAL */
2653 Route::set_comment (string cmt, void *src)
2656 comment_changed (src);
2657 _session.set_dirty ();
2661 Route::feeds (boost::shared_ptr<Route> other)
2666 uint32_t no = self.n_outputs().n_total();
2667 uint32_t ni = other->n_inputs ().n_total();
2669 for (i = 0; i < no; ++i) {
2670 for (j = 0; j < ni; ++j) {
2671 if (self.output(i)->connected_to (other->input(j)->name())) {
2677 /* check IOProcessors which may also interconnect Routes */
2679 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); r++) {
2681 boost::shared_ptr<IOProcessor> redirect = boost::dynamic_pointer_cast<IOProcessor>(*r);
2686 // TODO: support internal redirects here
2688 no = redirect->io()->n_outputs().n_total();
2690 for (i = 0; i < no; ++i) {
2691 for (j = 0; j < ni; ++j) {
2692 if (redirect->io()->output(i)->connected_to (other->input (j)->name())) {
2699 /* check for control room outputs which may also interconnect Routes */
2701 if (_control_outs) {
2703 no = _control_outs->n_outputs().n_total();
2705 for (i = 0; i < no; ++i) {
2706 for (j = 0; j < ni; ++j) {
2707 if (_control_outs->output(i)->connected_to (other->input (j)->name())) {
2718 Route::set_mute_config (mute_type t, bool onoff, void *src)
2722 _mute_affects_pre_fader = onoff;
2723 pre_fader_changed(src); /* EMIT SIGNAL */
2727 _mute_affects_post_fader = onoff;
2728 post_fader_changed(src); /* EMIT SIGNAL */
2732 _mute_affects_control_outs = onoff;
2733 control_outs_changed(src); /* EMIT SIGNAL */
2737 _mute_affects_main_outs = onoff;
2738 main_outs_changed(src); /* EMIT SIGNAL */
2744 Route::get_mute_config (mute_type t)
2750 onoff = _mute_affects_pre_fader;
2753 onoff = _mute_affects_post_fader;
2756 onoff = _mute_affects_control_outs;
2759 onoff = _mute_affects_main_outs;
2767 Route::handle_transport_stopped (bool abort_ignored, bool did_locate, bool can_flush_processors)
2769 nframes_t now = _session.transport_frame();
2772 Glib::RWLock::ReaderLock lm (_processor_lock);
2775 automation_snapshot (now, true);
2778 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2780 if (Config->get_plugins_stop_with_transport() && can_flush_processors) {
2781 (*i)->deactivate ();
2785 (*i)->transport_stopped (now);
2789 IO::transport_stopped (now);
2791 _roll_delay = _initial_delay;
2795 Route::input_change_handler (IOChange change, void *ignored)
2797 if (change & ConfigurationChanged) {
2798 reset_processor_counts (0);
2803 Route::output_change_handler (IOChange change, void *ignored)
2805 if (change & ConfigurationChanged) {
2806 if (_control_outs) {
2807 _control_outs->ensure_io (ChanCount::ZERO, ChanCount(DataType::AUDIO, n_outputs().n_audio()), true, this);
2810 reset_processor_counts (0);
2815 Route::pans_required () const
2817 if (n_outputs().n_audio() < 2) {
2821 return max (n_inputs ().n_audio(), processor_max_outs.n_audio());
2825 Route::no_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
2826 bool session_state_changing, bool can_record, bool rec_monitors_input)
2828 if (n_outputs().n_total() == 0) {
2832 if (session_state_changing || !_active) {
2833 silence (nframes, offset);
2837 apply_gain_automation = false;
2839 if (n_inputs().n_total()) {
2840 passthru (start_frame, end_frame, nframes, offset, 0, false);
2842 silence (nframes, offset);
2849 Route::check_initial_delay (nframes_t nframes, nframes_t& offset, nframes_t& transport_frame)
2851 if (_roll_delay > nframes) {
2853 _roll_delay -= nframes;
2854 silence (nframes, offset);
2855 /* transport frame is not legal for caller to use */
2858 } else if (_roll_delay > 0) {
2860 nframes -= _roll_delay;
2862 silence (_roll_delay, offset);
2864 offset += _roll_delay;
2865 transport_frame += _roll_delay;
2874 Route::roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset, int declick,
2875 bool can_record, bool rec_monitors_input)
2878 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2880 // automation snapshot can also be called from the non-rt context
2881 // and it uses the processor list, so we take the lock out here
2882 automation_snapshot (_session.transport_frame(), false);
2886 if ((n_outputs().n_total() == 0 && _processors.empty()) || n_inputs().n_total() == 0 || !_active) {
2887 silence (nframes, offset);
2891 nframes_t unused = 0;
2893 if ((nframes = check_initial_delay (nframes, offset, unused)) == 0) {
2899 apply_gain_automation = false;
2902 Glib::Mutex::Lock am (data().control_lock(), Glib::TRY_LOCK);
2904 if (am.locked() && _session.transport_rolling()) {
2906 if (_gain_control->automation_playback()) {
2907 apply_gain_automation = _gain_control->list()->curve().rt_safe_get_vector (
2908 start_frame, end_frame, _session.gain_automation_buffer(), nframes);
2913 passthru (start_frame, end_frame, nframes, offset, declick, false);
2919 Route::silent_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
2920 bool can_record, bool rec_monitors_input)
2922 silence (nframes, offset);
2927 Route::toggle_monitor_input ()
2929 for (PortSet::iterator i = _inputs.begin(); i != _inputs.end(); ++i) {
2930 i->ensure_monitor_input( ! i->monitoring_input());
2935 Route::has_external_redirects () const
2937 // FIXME: what about sends?
2939 boost::shared_ptr<const PortInsert> pi;
2941 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2942 if ((pi = boost::dynamic_pointer_cast<const PortInsert>(*i)) != 0) {
2944 for (PortSet::const_iterator port = pi->io()->outputs().begin();
2945 port != pi->io()->outputs().end(); ++port) {
2947 string port_name = port->name();
2948 string client_name = port_name.substr (0, port_name.find(':'));
2950 /* only say "yes" if the redirect is actually in use */
2952 if (client_name != "ardour" && pi->active()) {
2963 Route::flush_processors ()
2965 /* XXX shouldn't really try to take this lock, since
2966 this is called from the RT audio thread.
2969 Glib::RWLock::ReaderLock lm (_processor_lock);
2971 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2972 (*i)->deactivate ();
2978 Route::set_meter_point (MeterPoint p, void *src)
2980 if (_meter_point != p) {
2982 meter_change (src); /* EMIT SIGNAL */
2983 _session.set_dirty ();
2988 Route::update_total_latency ()
2990 nframes_t old = _own_latency;
2992 if (_user_latency) {
2993 _own_latency = _user_latency;
2997 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2998 if ((*i)->active ()) {
2999 _own_latency += (*i)->signal_latency ();
3004 #undef DEBUG_LATENCY
3005 #ifdef DEBUG_LATENCY
3006 cerr << _name << ": internal redirect latency = " << _own_latency << endl;
3009 set_port_latency (_own_latency);
3011 if (!_user_latency) {
3012 /* this (virtual) function is used for pure Routes,
3013 not derived classes like AudioTrack. this means
3014 that the data processed here comes from an input
3015 port, not prerecorded material, and therefore we
3016 have to take into account any input latency.
3020 _own_latency += input_latency ();
3023 if (old != _own_latency) {
3024 signal_latency_changed (); /* EMIT SIGNAL */
3027 #ifdef DEBUG_LATENCY
3028 cerr << _name << ": input latency = " << input_latency() << " total = "
3029 << _own_latency << endl;
3032 return _own_latency;
3036 Route::set_user_latency (nframes_t nframes)
3038 Latent::set_user_latency (nframes);
3039 _session.update_latency_compensation (false, false);
3043 Route::set_latency_delay (nframes_t longest_session_latency)
3045 nframes_t old = _initial_delay;
3047 if (_own_latency < longest_session_latency) {
3048 _initial_delay = longest_session_latency - _own_latency;
3053 if (_initial_delay != old) {
3054 initial_delay_changed (); /* EMIT SIGNAL */
3057 if (_session.transport_stopped()) {
3058 _roll_delay = _initial_delay;
3063 Route::automation_snapshot (nframes_t now, bool force)
3065 if (!force && !should_snapshot(now)) {
3069 IO::automation_snapshot (now, force);
3071 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3072 (*i)->automation_snapshot (now, force);
3076 Route::ToggleControllable::ToggleControllable (std::string name, Route& s, ToggleType tp)
3077 : Controllable (name), route (s), type(tp)
3083 Route::ToggleControllable::set_value (float val)
3085 bool bval = ((val >= 0.5f) ? true: false);
3089 route.set_mute (bval, this);
3092 route.set_solo (bval, this);
3100 Route::ToggleControllable::get_value (void) const
3106 val = route.muted() ? 1.0f : 0.0f;
3109 val = route.soloed() ? 1.0f : 0.0f;
3119 Route::set_block_size (nframes_t nframes)
3121 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3122 (*i)->set_block_size (nframes);
3127 Route::protect_automation ()
3129 Automatable::protect_automation();
3131 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
3132 (*i)->protect_automation();
3136 Route::set_pending_declick (int declick)
3139 /* this call is not allowed to turn off a pending declick unless "force" is true */
3141 _pending_declick = declick;
3143 // cerr << _name << ": after setting to " << declick << " pending declick = " << _pending_declick << endl;
3145 _pending_declick = 0;
3150 /** Shift automation forwards from a particular place, thereby inserting time.
3151 * Adds undo commands for any shifts that are performed.
3153 * @param pos Position to start shifting from.
3154 * @param frames Amount to shift forwards by.
3158 Route::shift (nframes64_t pos, nframes64_t frames)
3160 #ifdef THIS_NEEDS_FIXING_FOR_V3
3162 /* gain automation */
3163 XMLNode &before = _gain_control->get_state ();
3164 _gain_control->shift (pos, frames);
3165 XMLNode &after = _gain_control->get_state ();
3166 _session.add_command (new MementoCommand<AutomationList> (_gain_automation_curve, &before, &after));
3168 /* pan automation */
3169 for (std::vector<StreamPanner*>::iterator i = _panner->begin (); i != _panner->end (); ++i) {
3170 Curve & c = (*i)->automation ();
3171 XMLNode &before = c.get_state ();
3172 c.shift (pos, frames);
3173 XMLNode &after = c.get_state ();
3174 _session.add_command (new MementoCommand<AutomationList> (c, &before, &after));
3177 /* redirect automation */
3179 Glib::RWLock::ReaderLock lm (redirect_lock);
3180 for (RedirectList::iterator i = _redirects.begin (); i != _redirects.end (); ++i) {
3183 (*i)->what_has_automation (a);
3185 for (set<uint32_t>::const_iterator j = a.begin (); j != a.end (); ++j) {
3186 AutomationList & al = (*i)->automation_list (*j);
3187 XMLNode &before = al.get_state ();
3188 al.shift (pos, frames);
3189 XMLNode &after = al.get_state ();
3190 _session.add_command (new MementoCommand<AutomationList> (al, &before, &after));