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, int input_min, int input_max, int output_min, int output_max, Flag flg, DataType default_type)
64 : IO (sess, name, input_min, input_max, output_min, output_max, default_type),
66 _solo_control (new ToggleControllable (X_("solo"), *this, ToggleControllable::SoloControl)),
67 _mute_control (new ToggleControllable (X_("mute"), *this, ToggleControllable::MuteControl))
72 Route::Route (Session& sess, const XMLNode& node, DataType default_type)
73 : IO (sess, *node.child ("IO"), default_type),
74 _solo_control (new ToggleControllable (X_("solo"), *this, ToggleControllable::SoloControl)),
75 _mute_control (new ToggleControllable (X_("mute"), *this, ToggleControllable::MuteControl))
78 _set_state (node, false);
84 processor_max_outs.reset();
90 _phase_invert = false;
91 _denormal_protection = false;
92 order_keys[strdup (N_("signal"))] = order_key_cnt++;
94 _meter_point = MeterPostFader;
99 _have_internal_generator = false;
100 _declickable = false;
101 _pending_declick = true;
102 _remote_control_id = 0;
107 _mute_affects_pre_fader = Config->get_mute_affects_pre_fader();
108 _mute_affects_post_fader = Config->get_mute_affects_post_fader();
109 _mute_affects_control_outs = Config->get_mute_affects_control_outs();
110 _mute_affects_main_outs = Config->get_mute_affects_main_outs();
113 desired_solo_gain = 1.0;
115 desired_mute_gain = 1.0;
119 input_changed.connect (mem_fun (this, &Route::input_change_handler));
120 output_changed.connect (mem_fun (this, &Route::output_change_handler));
125 clear_processors (PreFader);
126 clear_processors (PostFader);
128 for (OrderKeys::iterator i = order_keys.begin(); i != order_keys.end(); ++i) {
129 free ((void*)(i->first));
132 delete _control_outs;
136 Route::set_remote_control_id (uint32_t id)
138 if (id != _remote_control_id) {
139 _remote_control_id = id;
140 RemoteControlIDChanged ();
145 Route::remote_control_id() const
147 return _remote_control_id;
151 Route::order_key (const char* name) const
153 OrderKeys::const_iterator i;
155 for (i = order_keys.begin(); i != order_keys.end(); ++i) {
156 if (!strcmp (name, i->first)) {
165 Route::set_order_key (const char* name, long n)
167 order_keys[strdup(name)] = n;
169 if (Config->get_sync_all_route_ordering()) {
170 for (OrderKeys::iterator x = order_keys.begin(); x != order_keys.end(); ++x) {
175 _session.set_dirty ();
179 Route::sync_order_keys (const char* base)
181 if (order_keys.empty()) {
185 OrderKeys::iterator i;
188 if ((i = order_keys.find (base)) == order_keys.end()) {
189 /* key doesn't exist, use the first existing
190 key (this is done during session initialization)
192 i = order_keys.begin();
196 /* key exists - use it and reset all others
197 (actually, itself included)
199 i = order_keys.begin();
203 for (; i != order_keys.end(); ++i) {
209 Route::ensure_track_or_route_name(string name, Session &session)
211 string newname = name;
213 while (session.route_by_name (newname)!=NULL)
215 newname = bump_name_once (newname);
223 Route::inc_gain (gain_t fraction, void *src)
225 IO::inc_gain (fraction, src);
229 Route::set_gain (gain_t val, void *src)
231 if (src != 0 && _mix_group && src != _mix_group && _mix_group->is_active()) {
233 if (_mix_group->is_relative()) {
235 gain_t usable_gain = gain();
236 if (usable_gain < 0.000001f) {
237 usable_gain = 0.000001f;
241 if (delta < 0.000001f) {
245 delta -= usable_gain;
250 gain_t factor = delta / usable_gain;
253 factor = _mix_group->get_max_factor(factor);
254 if (factor == 0.0f) {
255 _gain_control->Changed(); /* EMIT SIGNAL */
259 factor = _mix_group->get_min_factor(factor);
260 if (factor == 0.0f) {
261 _gain_control->Changed(); /* EMIT SIGNAL */
266 _mix_group->apply (&Route::inc_gain, factor, _mix_group);
270 _mix_group->apply (&Route::set_gain, val, _mix_group);
280 IO::set_gain (val, src);
283 /** Process this route for one (sub) cycle (process thread)
285 * @param bufs Scratch buffers to use for the signal path
286 * @param start_frame Initial transport frame
287 * @param end_frame Final transport frame
288 * @param nframes Number of frames to output (to ports)
289 * @param offset Output offset (of port buffers, for split cycles)
291 * Note that (end_frame - start_frame) may not be equal to nframes when the
292 * transport speed isn't 1.0 (eg varispeed).
295 Route::process_output_buffers (BufferSet& bufs,
296 nframes_t start_frame, nframes_t end_frame,
297 nframes_t nframes, nframes_t offset, bool with_processors, int declick,
300 // This is definitely very audio-only for now
301 assert(_default_type == DataType::AUDIO);
303 ProcessorList::iterator i;
304 bool post_fader_work = false;
305 bool mute_declick_applied = false;
311 gain_t* gab = _session.gain_automation_buffer();
313 switch (Config->get_monitoring_model()) {
314 case HardwareMonitoring:
315 case ExternalMonitoring:
322 declick = _pending_declick;
325 Glib::Mutex::Lock cm (_control_outs_lock, Glib::TRY_LOCK);
335 Glib::Mutex::Lock dm (declick_lock, Glib::TRY_LOCK);
338 dmg = desired_mute_gain;
339 dsg = desired_solo_gain;
348 /* ----------------------------------------------------------------------------------------------------
349 GLOBAL DECLICK (for transport changes etc.)
350 -------------------------------------------------------------------------------------------------- */
353 Amp::run_in_place (bufs, nframes, 0.0, 1.0, false);
354 _pending_declick = 0;
355 } else if (declick < 0) {
356 Amp::run_in_place (bufs, nframes, 1.0, 0.0, false);
357 _pending_declick = 0;
360 /* no global declick */
362 if (solo_gain != dsg) {
363 Amp::run_in_place (bufs, nframes, solo_gain, dsg, false);
369 /* ----------------------------------------------------------------------------------------------------
370 INPUT METERING & MONITORING
371 -------------------------------------------------------------------------------------------------- */
373 if (meter && (_meter_point == MeterInput)) {
374 _meter->run_in_place(bufs, start_frame, end_frame, nframes, offset);
377 if (!_soloed && _mute_affects_pre_fader && (mute_gain != dmg)) {
378 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
380 mute_declick_applied = true;
383 if ((_meter_point == MeterInput) && co) {
385 solo_audible = dsg > 0;
386 mute_audible = dmg > 0;// || !_mute_affects_pre_fader;
388 if ( // muted by solo of another track
392 // muted by mute of this track
396 // rec-enabled but not s/w monitoring
398 // TODO: this is probably wrong
400 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
404 co->silence (nframes, offset);
408 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
413 /* -----------------------------------------------------------------------------------------------------
415 -------------------------------------------------------------------------------------------------- */
417 if (_denormal_protection || Config->get_denormal_protection()) {
419 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
420 Sample* const sp = i->data();
422 for (nframes_t nx = offset; nx < nframes + offset; ++nx) {
428 /* ----------------------------------------------------------------------------------------------------
430 -------------------------------------------------------------------------------------------------- */
432 if (with_processors) {
433 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
435 if (mute_gain > 0 || !_mute_affects_pre_fader) {
436 for (i = _processors.begin(); i != _processors.end(); ++i) {
437 switch ((*i)->placement()) {
439 (*i)->run_in_place (bufs, start_frame, end_frame, nframes, offset);
442 post_fader_work = true;
447 for (i = _processors.begin(); i != _processors.end(); ++i) {
448 switch ((*i)->placement()) {
450 (*i)->silence (nframes, offset);
453 post_fader_work = true;
461 // This really should already be true...
462 bufs.set_count(pre_fader_streams());
464 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_post_fader) {
465 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
467 mute_declick_applied = true;
470 /* ----------------------------------------------------------------------------------------------------
471 PRE-FADER METERING & MONITORING
472 -------------------------------------------------------------------------------------------------- */
474 if (meter && (_meter_point == MeterPreFader)) {
475 _meter->run_in_place(bufs, start_frame, end_frame, nframes, offset);
479 if ((_meter_point == MeterPreFader) && co) {
481 solo_audible = dsg > 0;
482 mute_audible = dmg > 0 || !_mute_affects_pre_fader;
484 if ( // muted by solo of another track
488 // muted by mute of this track
492 // rec-enabled but not s/w monitoring
494 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
498 co->silence (nframes, offset);
502 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
506 /* ----------------------------------------------------------------------------------------------------
508 -------------------------------------------------------------------------------------------------- */
510 /* if not recording or recording and requiring any monitor signal, then apply gain */
512 if ( // not recording
514 !(record_enabled() && _session.actively_recording()) ||
518 // AND software monitoring required
520 Config->get_monitoring_model() == SoftwareMonitoring) {
522 if (apply_gain_automation) {
525 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
526 Sample* const sp = i->data();
528 for (nframes_t nx = 0; nx < nframes; ++nx) {
533 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
534 Sample* const sp = i->data();
536 for (nframes_t nx = 0; nx < nframes; ++nx) {
542 if (apply_gain_automation && _session.transport_rolling() && nframes > 0) {
543 _effective_gain = gab[nframes-1];
548 /* manual (scalar) gain */
552 Amp::run_in_place (bufs, nframes, _gain, dg, _phase_invert);
555 } else if (_gain != 0 && (_phase_invert || _gain != 1.0)) {
557 /* no need to interpolate current gain value,
558 but its non-unity, so apply it. if the gain
559 is zero, do nothing because we'll ship silence
571 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
572 Sample* const sp = i->data();
573 apply_gain_to_buffer(sp,nframes,this_gain);
576 } else if (_gain == 0) {
577 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
585 /* actively recording, no monitoring required; leave buffers as-is to save CPU cycles */
589 /* ----------------------------------------------------------------------------------------------------
591 -------------------------------------------------------------------------------------------------- */
593 /* note that post_fader_work cannot be true unless with_processors was also true, so don't test both */
595 if (post_fader_work) {
597 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
599 if (mute_gain > 0 || !_mute_affects_post_fader) {
600 for (i = _processors.begin(); i != _processors.end(); ++i) {
601 switch ((*i)->placement()) {
605 (*i)->run_in_place (bufs, start_frame, end_frame, nframes, offset);
610 for (i = _processors.begin(); i != _processors.end(); ++i) {
611 switch ((*i)->placement()) {
615 (*i)->silence (nframes, offset);
623 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_control_outs) {
624 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
626 mute_declick_applied = true;
629 /* ----------------------------------------------------------------------------------------------------
631 -------------------------------------------------------------------------------------------------- */
633 if ((_meter_point == MeterPostFader) && co) {
635 solo_audible = solo_gain > 0;
636 mute_audible = dmg > 0 || !_mute_affects_control_outs;
638 if ( // silent anyway
640 (_gain == 0 && !apply_gain_automation) ||
642 // muted by solo of another track
646 // muted by mute of this track
650 // recording but not s/w monitoring
652 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
656 co->silence (nframes, offset);
660 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
664 /* ----------------------------------------------------------------------
666 ----------------------------------------------------------------------*/
668 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_main_outs) {
669 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
671 mute_declick_applied = true;
674 /* ----------------------------------------------------------------------------------------------------
676 -------------------------------------------------------------------------------------------------- */
678 solo_audible = dsg > 0;
679 mute_audible = dmg > 0 || !_mute_affects_main_outs;
681 if (n_outputs().get(_default_type) == 0) {
685 } else if (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording())) {
687 IO::silence (nframes, offset);
691 if ( // silent anyway
693 (_gain == 0 && !apply_gain_automation) ||
695 // muted by solo of another track, but not using control outs for solo
697 (!solo_audible && (Config->get_solo_model() != SoloBus)) ||
699 // muted by mute of this track
705 /* don't use Route::silence() here, because that causes
706 all outputs (sends, port processors, etc. to be silent).
709 if (_meter_point == MeterPostFader) {
710 peak_meter().reset();
713 IO::silence (nframes, offset);
717 deliver_output(bufs, start_frame, end_frame, nframes, offset);
723 /* ----------------------------------------------------------------------------------------------------
725 -------------------------------------------------------------------------------------------------- */
727 if (meter && (_meter_point == MeterPostFader)) {
728 if ((_gain == 0 && !apply_gain_automation) || dmg == 0) {
731 _meter->run_in_place(output_buffers(), start_frame, end_frame, nframes, offset);
737 /** Process this route for one (sub) cycle (process thread)
739 * @param bufs Scratch buffers to use for the signal path
740 * @param start_frame Initial transport frame
741 * @param end_frame Final transport frame
742 * @param nframes Number of frames to output (to ports)
743 * @param offset Output offset (of port buffers, for split cycles)
745 * Note that (end_frame - start_frame) may not be equal to nframes when the
746 * transport speed isn't 1.0 (eg varispeed).
749 Route::process_output_buffers (BufferSet& bufs,
750 nframes_t start_frame, nframes_t end_frame,
751 nframes_t nframes, nframes_t offset, bool with_processors, int declick,
754 // This is definitely very audio-only for now
755 assert(_default_type == DataType::AUDIO);
757 ProcessorList::iterator i;
758 bool post_fader_work = false;
759 bool mute_declick_applied = false;
765 gain_t* gab = _session.gain_automation_buffer();
767 switch (Config->get_monitoring_model()) {
768 case HardwareMonitoring:
769 case ExternalMonitoring:
776 declick = _pending_declick;
779 Glib::Mutex::Lock cm (_control_outs_lock, Glib::TRY_LOCK);
789 Glib::Mutex::Lock dm (declick_lock, Glib::TRY_LOCK);
792 dmg = desired_mute_gain;
793 dsg = desired_solo_gain;
802 /* ----------------------------------------------------------------------------------------------------
803 GLOBAL DECLICK (for transport changes etc.)
804 input metering & monitoring (control outs)
807 pre-fader metering & monitoring (control outs)
812 post-fader metering & monitoring (control outs)
816 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
817 for (i = processors.begin(); i != processors.end(); ++i) {
818 (*i)->run_in_place (bufs, start_frame, end_frame, nframes, offset);
822 /* ----------------------------------------------------------------------------------------------------
823 INPUT METERING & MONITORING
824 -------------------------------------------------------------------------------------------------- */
826 if (meter && (_meter_point == MeterInput)) {
827 _meter->run_in_place(bufs, start_frame, end_frame, nframes, offset);
830 if (!_soloed && _mute_affects_pre_fader && (mute_gain != dmg)) {
831 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
833 mute_declick_applied = true;
836 /* ----------------------------------------------------------------------------------------------------
838 -------------------------------------------------------------------------------------------------- */
840 // This really should already be true...
841 bufs.set_count(pre_fader_streams());
844 if ((_meter_point == MeterPreFader) && co) {
846 solo_audible = dsg > 0;
847 mute_audible = dmg > 0 || !_mute_affects_pre_fader;
849 if ( // muted by solo of another track
853 // muted by mute of this track
857 // rec-enabled but not s/w monitoring
859 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
863 co->silence (nframes, offset);
867 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
871 /* ----------------------------------------------------------------------------------------------------
873 -------------------------------------------------------------------------------------------------- */
875 /* if not recording or recording and requiring any monitor signal, then apply gain */
877 if ( // not recording
879 !(record_enabled() && _session.actively_recording()) ||
883 // AND software monitoring required
885 Config->get_monitoring_model() == SoftwareMonitoring) {
887 if (apply_gain_automation) {
890 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
891 Sample* const sp = i->data();
893 for (nframes_t nx = 0; nx < nframes; ++nx) {
898 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
899 Sample* const sp = i->data();
901 for (nframes_t nx = 0; nx < nframes; ++nx) {
907 if (apply_gain_automation && _session.transport_rolling() && nframes > 0) {
908 _effective_gain = gab[nframes-1];
913 /* manual (scalar) gain */
917 Amp::run_in_place (bufs, nframes, _gain, dg, _phase_invert);
920 } else if (_gain != 0 && (_phase_invert || _gain != 1.0)) {
922 /* no need to interpolate current gain value,
923 but its non-unity, so apply it. if the gain
924 is zero, do nothing because we'll ship silence
936 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
937 Sample* const sp = i->data();
938 apply_gain_to_buffer(sp,nframes,this_gain);
941 } else if (_gain == 0) {
942 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
950 /* actively recording, no monitoring required; leave buffers as-is to save CPU cycles */
955 /* ----------------------------------------------------------------------------------------------------
957 -------------------------------------------------------------------------------------------------- */
959 if ((_meter_point == MeterPostFader) && co) {
961 solo_audible = solo_gain > 0;
962 mute_audible = dmg > 0 || !_mute_affects_control_outs;
964 if ( // silent anyway
966 (_gain == 0 && !apply_gain_automation) ||
968 // muted by solo of another track
972 // muted by mute of this track
976 // recording but not s/w monitoring
978 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
982 co->silence (nframes, offset);
986 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
990 /* ----------------------------------------------------------------------------------------------------
992 -------------------------------------------------------------------------------------------------- */
994 solo_audible = dsg > 0;
995 mute_audible = dmg > 0 || !_mute_affects_main_outs;
997 if (n_outputs().get(_default_type) == 0) {
1001 } else if (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording())) {
1003 IO::silence (nframes, offset);
1007 if ( // silent anyway
1009 (_gain == 0 && !apply_gain_automation) ||
1011 // muted by solo of another track, but not using control outs for solo
1013 (!solo_audible && (Config->get_solo_model() != SoloBus)) ||
1015 // muted by mute of this track
1021 /* don't use Route::silence() here, because that causes
1022 all outputs (sends, port processors, etc. to be silent).
1025 if (_meter_point == MeterPostFader) {
1026 peak_meter().reset();
1029 IO::silence (nframes, offset);
1033 deliver_output(bufs, start_frame, end_frame, nframes, offset);
1040 #endif /* NEW_POB */
1043 Route::n_process_buffers ()
1045 return max (n_inputs(), processor_max_outs);
1049 Route::passthru (nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset, int declick, bool meter_first)
1051 BufferSet& bufs = _session.get_scratch_buffers(n_process_buffers());
1055 collect_input (bufs, nframes, offset);
1058 _meter->run_in_place(bufs, start_frame, end_frame, nframes, offset);
1059 meter_first = false;
1064 process_output_buffers (bufs, start_frame, end_frame, nframes, offset, true, declick, meter_first);
1068 Route::passthru_silence (nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset, int declick, bool meter)
1070 process_output_buffers (_session.get_silent_buffers (n_process_buffers()), start_frame, end_frame, nframes, offset, true, declick, meter);
1074 Route::set_solo (bool yn, void *src)
1080 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
1081 _mix_group->apply (&Route::set_solo, yn, _mix_group);
1085 if (_soloed != yn) {
1087 solo_changed (src); /* EMIT SIGNAL */
1088 _solo_control->Changed (); /* EMIT SIGNAL */
1091 catch_up_on_solo_mute_override ();
1095 Route::catch_up_on_solo_mute_override ()
1097 if (Config->get_solo_model() != InverseMute) {
1103 Glib::Mutex::Lock lm (declick_lock);
1106 if (Config->get_solo_mute_override()) {
1107 desired_mute_gain = (_soloed?1.0:0.0);
1109 desired_mute_gain = 0.0;
1112 desired_mute_gain = 1.0;
1118 Route::set_solo_mute (bool yn)
1120 Glib::Mutex::Lock lm (declick_lock);
1122 /* Called by Session in response to another Route being soloed.
1125 desired_solo_gain = (yn?0.0:1.0);
1129 Route::set_solo_safe (bool yn, void *src)
1131 if (_solo_safe != yn) {
1133 solo_safe_changed (src); /* EMIT SIGNAL */
1138 Route::set_mute (bool yn, void *src)
1141 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
1142 _mix_group->apply (&Route::set_mute, yn, _mix_group);
1148 mute_changed (src); /* EMIT SIGNAL */
1150 _mute_control->Changed (); /* EMIT SIGNAL */
1152 Glib::Mutex::Lock lm (declick_lock);
1154 if (_soloed && Config->get_solo_mute_override()){
1155 desired_mute_gain = 1.0f;
1157 desired_mute_gain = (yn?0.0f:1.0f);
1163 Route::add_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err)
1165 ChanCount old_pmo = processor_max_outs;
1167 if (!_session.engine().connected()) {
1172 Glib::RWLock::WriterLock lm (_processor_lock);
1174 boost::shared_ptr<PluginInsert> pi;
1175 boost::shared_ptr<PortInsert> porti;
1177 //processor->set_default_type(_default_type);
1179 _processors.push_back (processor);
1181 // Set up processor list channels. This will set processor->[input|output]_streams(),
1182 // configure redirect ports properly, etc.
1183 if (_reset_processor_counts (err)) {
1184 _processors.pop_back ();
1185 _reset_processor_counts (0); // it worked before we tried to add it ...
1189 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
1191 if (pi->natural_input_streams() == ChanCount::ZERO) {
1192 /* generator plugin */
1193 _have_internal_generator = true;
1198 // Ensure peak vector sizes before the plugin is activated
1200 ChanCount potential_max_streams;
1202 potential_max_streams.set (DataType::AUDIO, max (processor->input_streams().n_audio(),
1203 processor->output_streams().n_audio()));
1204 potential_max_streams.set (DataType::MIDI, max (processor->input_streams().n_midi(),
1205 processor->output_streams().n_midi()));
1207 _meter->configure_io (potential_max_streams, potential_max_streams);
1209 // XXX: do we want to emit the signal here ? change call order.
1210 processor->activate ();
1211 processor->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
1216 if (processor_max_outs != old_pmo || old_pmo == ChanCount::ZERO) {
1220 processors_changed (); /* EMIT SIGNAL */
1226 Route::add_processors (const ProcessorList& others, ProcessorStreams* err)
1228 ChanCount old_pmo = processor_max_outs;
1230 if (!_session.engine().connected()) {
1235 Glib::RWLock::WriterLock lm (_processor_lock);
1237 ProcessorList::iterator existing_end = _processors.end();
1240 ChanCount potential_max_streams;
1242 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1244 boost::shared_ptr<PluginInsert> pi;
1246 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1249 ChanCount m = max(pi->input_streams(), pi->output_streams());
1250 if (m > potential_max_streams)
1251 potential_max_streams = m;
1254 // Ensure peak vector sizes before the plugin is activated
1255 _meter->configure_io (potential_max_streams, potential_max_streams);
1257 _processors.push_back (*i);
1259 if (_reset_processor_counts (err)) {
1261 _processors.erase (existing_end, _processors.end());
1262 _reset_processor_counts (0); // it worked before we tried to add it ...
1266 (*i)->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
1272 if (processor_max_outs != old_pmo || old_pmo == ChanCount::ZERO) {
1276 processors_changed (); /* EMIT SIGNAL */
1280 /** Turn off all processors with a given placement
1281 * @param p Placement of processors to disable
1285 Route::disable_processors (Placement p)
1287 Glib::RWLock::ReaderLock lm (_processor_lock);
1289 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1290 if ((*i)->placement() == p) {
1291 (*i)->set_active (false);
1295 _session.set_dirty ();
1298 /** Turn off all redirects
1302 Route::disable_processors ()
1304 Glib::RWLock::ReaderLock lm (_processor_lock);
1306 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1307 (*i)->set_active (false);
1310 _session.set_dirty ();
1313 /** Turn off all redirects with a given placement
1314 * @param p Placement of redirects to disable
1318 Route::disable_plugins (Placement p)
1320 Glib::RWLock::ReaderLock lm (_processor_lock);
1322 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1323 if (boost::dynamic_pointer_cast<PluginInsert> (*i) && (*i)->placement() == p) {
1324 (*i)->set_active (false);
1328 _session.set_dirty ();
1331 /** Turn off all plugins
1335 Route::disable_plugins ()
1337 Glib::RWLock::ReaderLock lm (_processor_lock);
1339 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1340 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1341 (*i)->set_active (false);
1345 _session.set_dirty ();
1350 Route::ab_plugins (bool forward)
1352 Glib::RWLock::ReaderLock lm (_processor_lock);
1356 /* forward = turn off all active redirects, and mark them so that the next time
1357 we go the other way, we will revert them
1360 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1361 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1365 if ((*i)->active()) {
1366 (*i)->set_active (false);
1367 (*i)->set_next_ab_is_active (true);
1369 (*i)->set_next_ab_is_active (false);
1375 /* backward = if the redirect was marked to go active on the next ab, do so */
1377 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1379 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1383 if ((*i)->get_next_ab_is_active()) {
1384 (*i)->set_active (true);
1386 (*i)->set_active (false);
1391 _session.set_dirty ();
1395 /* Figure out the streams that will feed into PreFader */
1397 Route::pre_fader_streams() const
1399 boost::shared_ptr<Processor> processor;
1401 // Find the last pre-fader redirect
1402 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1403 if ((*i)->placement() == PreFader) {
1409 return processor->output_streams();
1416 /** Remove processors with a given placement.
1417 * @param p Placement of processors to remove.
1420 Route::clear_processors (Placement p)
1422 const ChanCount old_pmo = processor_max_outs;
1424 if (!_session.engine().connected()) {
1429 Glib::RWLock::WriterLock lm (_processor_lock);
1430 ProcessorList new_list;
1432 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1433 if ((*i)->placement() == p) {
1434 /* it's the placement we want to get rid of */
1435 (*i)->drop_references ();
1437 /* it's a different placement, so keep it */
1438 new_list.push_back (*i);
1442 _processors = new_list;
1445 /* FIXME: can't see how this test can ever fire */
1446 if (processor_max_outs != old_pmo) {
1450 processor_max_outs.reset();
1451 _have_internal_generator = false;
1452 processors_changed (); /* EMIT SIGNAL */
1456 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err)
1458 ChanCount old_pmo = processor_max_outs;
1460 if (!_session.engine().connected()) {
1464 processor_max_outs.reset();
1467 Glib::RWLock::WriterLock lm (_processor_lock);
1468 ProcessorList::iterator i;
1469 bool removed = false;
1471 for (i = _processors.begin(); i != _processors.end(); ++i) {
1472 if (*i == processor) {
1474 ProcessorList::iterator tmp;
1476 /* move along, see failure case for reset_processor_counts()
1477 where we may need to reprocessor the processor.
1483 /* stop redirects that send signals to JACK ports
1484 from causing noise as a result of no longer being
1488 boost::shared_ptr<IOProcessor> redirect;
1490 if ((redirect = boost::dynamic_pointer_cast<IOProcessor> (*i)) != 0) {
1491 redirect->io()->disconnect_inputs (this);
1492 redirect->io()->disconnect_outputs (this);
1495 _processors.erase (i);
1510 if (_reset_processor_counts (err)) {
1511 /* get back to where we where */
1512 _processors.insert (i, processor);
1513 /* we know this will work, because it worked before :) */
1514 _reset_processor_counts (0);
1518 _have_internal_generator = false;
1520 for (i = _processors.begin(); i != _processors.end(); ++i) {
1521 boost::shared_ptr<PluginInsert> pi;
1523 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1524 if (pi->is_generator()) {
1525 _have_internal_generator = true;
1532 if (old_pmo != processor_max_outs) {
1536 processor->drop_references ();
1538 processors_changed (); /* EMIT SIGNAL */
1543 Route::reset_processor_counts (ProcessorStreams* err)
1545 Glib::RWLock::WriterLock lm (_processor_lock);
1546 return _reset_processor_counts (err);
1551 Route::_reset_processor_counts (ProcessorStreams* err)
1553 ProcessorList::iterator r;
1554 uint32_t insert_cnt = 0;
1555 uint32_t send_cnt = 0;
1556 map<Placement,list<ProcessorCount> > proc_map;
1557 ProcessorList::iterator prev;
1558 ChanCount initial_streams = n_inputs ();
1559 ChanCount previous_initial_streams = n_inputs ();
1561 uint32_t max_audio = 0;
1562 uint32_t max_midi = 0;
1564 processor_max_outs.reset ();
1566 /* Step 1: build a map that links each insert to an in/out channel count
1568 Divide inserts up by placement so we get the signal flow
1569 properly modelled. we need to do this because the _processors
1570 list is not sorted by placement, and because other reasons may
1571 exist now or in the future for this separate treatment.
1574 /* ... but it should/will be... */
1576 for (r = _processors.begin(); r != _processors.end(); ++r) {
1578 boost::shared_ptr<PluginInsert> plugin_insert;
1579 boost::shared_ptr<PortInsert> port_insert;
1581 if ((plugin_insert = boost::dynamic_pointer_cast<PluginInsert>(*r)) != 0) {
1584 proc_map[(*r)->placement()].push_back (ProcessorCount (*r));
1586 /* reset plugin counts back to one for now so
1587 that we have a predictable, controlled
1588 state to try to configure.
1591 plugin_insert->set_count (1);
1593 } else if ((port_insert = boost::dynamic_pointer_cast<PortInsert>(*r)) != 0) {
1596 proc_map[(*r)->placement()].push_back (ProcessorCount (*r));
1598 } else if (boost::dynamic_pointer_cast<Send> (*r) != 0) {
1603 if (insert_cnt == 0) {
1612 /* Now process each placement in order, checking to see if we
1613 can really do what has been requested.
1618 if (check_some_processor_counts (proc_map[PreFader], n_inputs (), err)) {
1622 if (!proc_map[PreFader].empty()) {
1623 previous_initial_streams = n_inputs ();
1624 for (list<ProcessorCount>::iterator i = proc_map[PreFader].begin(); i != proc_map[PreFader].end(); i++) {
1625 if (i->processor->can_support_io_configuration (previous_initial_streams, initial_streams) < 0) {
1628 previous_initial_streams = initial_streams;
1634 if (check_some_processor_counts (proc_map[PostFader], initial_streams, err)) {
1638 if (!proc_map[PostFader].empty()) {
1639 for (list<ProcessorCount>::iterator i = proc_map[PostFader].begin(); i != proc_map[PostFader].end(); i++) {
1640 if (i->processor->can_support_io_configuration (previous_initial_streams, initial_streams) < 0) {
1643 previous_initial_streams = initial_streams;
1647 /* OK, everything can be set up correctly, so lets do it */
1649 apply_some_processor_counts (proc_map[PreFader]);
1650 apply_some_processor_counts (proc_map[PostFader]);
1652 /* recompute max outs of any processor */
1658 processor_max_outs.reset ();
1659 prev = _processors.end();
1661 for (r = _processors.begin(); r != _processors.end(); prev = r, ++r) {
1662 boost::shared_ptr<Send> s;
1664 if ((s = boost::dynamic_pointer_cast<Send> (*r)) != 0) {
1665 if (r == _processors.begin()) {
1666 s->expect_inputs (n_inputs());
1668 s->expect_inputs ((*prev)->output_streams());
1673 /* don't pay any attention to send output configuration, since it doesn't
1677 max_audio = max ((*r)->output_streams ().n_audio(), max_audio);
1678 max_midi = max ((*r)->output_streams ().n_midi(), max_midi);
1682 processor_max_outs.set (DataType::AUDIO, max_audio);
1683 processor_max_outs.set (DataType::MIDI, max_midi);
1689 for (r = _processors.begin(); r != _processors.end(); ++r) {
1690 max_audio = max ((*r)->output_streams ().n_audio(), max_audio);
1691 max_midi = max ((*r)->output_streams ().n_midi(), max_midi);
1694 processor_max_outs.set (DataType::AUDIO, max_audio);
1695 processor_max_outs.set (DataType::MIDI, max_midi);
1701 Route::apply_some_processor_counts (list<ProcessorCount>& iclist)
1703 list<ProcessorCount>::iterator i;
1705 for (i = iclist.begin(); i != iclist.end(); ++i) {
1707 ProcessorCount& pc (*i);
1709 cerr << "now applying for " << (*i).processor->name() << " in = " << pc.in.n_audio() << " out = " << pc.out.n_audio() << endl;
1711 if (pc.processor->configure_io (pc.in, pc.out)) {
1715 /* make sure that however many we have, they are all active */
1717 pc.processor->activate ();
1723 /** Returns whether \a iclist can be configured and run starting with
1724 * \a required_inputs at the first processor's inputs.
1725 * If false is returned, \a iclist can not be run with \a required_inputs, and \a err is set.
1726 * Otherwise, \a err is set to the output of the list.
1729 Route::check_some_processor_counts (list<ProcessorCount>& iclist, ChanCount required_inputs, ProcessorStreams* err)
1731 list<ProcessorCount>::iterator i;
1736 err->count = required_inputs;
1739 for (i = iclist.begin(); i != iclist.end(); ++i, ++index) {
1741 cerr << "Checking whether " << (*i).processor->name() << " can support " << required_inputs.n_audio() << " inputs\n";
1743 if (!(*i).processor->can_support_io_configuration (required_inputs, (*i).out)) {
1746 err->count = required_inputs;
1751 (*i).in = required_inputs;
1752 required_inputs = (*i).out;
1759 Route::copy_processors (const Route& other, Placement placement, ProcessorStreams* err)
1761 ChanCount old_pmo = processor_max_outs;
1763 ProcessorList to_be_deleted;
1766 Glib::RWLock::WriterLock lm (_processor_lock);
1767 ProcessorList::iterator tmp;
1768 ProcessorList the_copy;
1770 the_copy = _processors;
1772 /* remove all relevant processors */
1774 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ) {
1778 if ((*i)->placement() == placement) {
1779 to_be_deleted.push_back (*i);
1780 _processors.erase (i);
1786 /* now copy the relevant ones from "other" */
1788 for (ProcessorList::const_iterator i = other._processors.begin(); i != other._processors.end(); ++i) {
1789 if ((*i)->placement() == placement) {
1790 _processors.push_back (IOProcessor::clone (*i));
1794 /* reset plugin stream handling */
1796 if (_reset_processor_counts (err)) {
1798 /* FAILED COPY ATTEMPT: we have to restore order */
1800 /* delete all cloned processors */
1802 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ) {
1807 if ((*i)->placement() == placement) {
1808 _processors.erase (i);
1814 /* restore the natural order */
1816 _processors = the_copy;
1817 processor_max_outs = old_pmo;
1819 /* we failed, even though things are OK again */
1825 /* SUCCESSFUL COPY ATTEMPT: delete the processors we removed pre-copy */
1826 to_be_deleted.clear ();
1831 if (processor_max_outs != old_pmo || old_pmo == ChanCount::ZERO) {
1835 processors_changed (); /* EMIT SIGNAL */
1840 Route::all_processors_flip ()
1842 Glib::RWLock::ReaderLock lm (_processor_lock);
1844 if (_processors.empty()) {
1848 bool first_is_on = _processors.front()->active();
1850 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1851 (*i)->set_active (!first_is_on);
1854 _session.set_dirty ();
1857 /** Set all processors with a given placement to a given active state.
1858 * @param p Placement of processors to change.
1859 * @param state New active state for those processors.
1862 Route::all_processors_active (Placement p, bool state)
1864 Glib::RWLock::ReaderLock lm (_processor_lock);
1866 if (_processors.empty()) {
1870 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1871 if ((*i)->placement() == p) {
1872 (*i)->set_active (state);
1876 _session.set_dirty ();
1879 struct ProcessorSorter {
1880 bool operator() (boost::shared_ptr<const Processor> a, boost::shared_ptr<const Processor> b) {
1881 return a->sort_key() < b->sort_key();
1886 Route::sort_processors (ProcessorStreams* err)
1889 ProcessorSorter comparator;
1890 Glib::RWLock::WriterLock lm (_processor_lock);
1891 ChanCount old_pmo = processor_max_outs;
1893 /* the sweet power of C++ ... */
1895 ProcessorList as_it_was_before = _processors;
1897 _processors.sort (comparator);
1899 if (_reset_processor_counts (err)) {
1900 _processors = as_it_was_before;
1901 processor_max_outs = old_pmo;
1907 processors_changed (); /* EMIT SIGNAL */
1919 Route::get_template()
1921 return state(false);
1925 Route::state(bool full_state)
1927 XMLNode *node = new XMLNode("Route");
1928 ProcessorList::iterator i;
1932 node->add_property("flags", enum_2_string (_flags));
1935 node->add_property("default-type", _default_type.to_string());
1937 node->add_property("active", _active?"yes":"no");
1938 node->add_property("muted", _muted?"yes":"no");
1939 node->add_property("soloed", _soloed?"yes":"no");
1940 node->add_property("phase-invert", _phase_invert?"yes":"no");
1941 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
1942 node->add_property("mute-affects-pre-fader", _mute_affects_pre_fader?"yes":"no");
1943 node->add_property("mute-affects-post-fader", _mute_affects_post_fader?"yes":"no");
1944 node->add_property("mute-affects-control-outs", _mute_affects_control_outs?"yes":"no");
1945 node->add_property("mute-affects-main-outs", _mute_affects_main_outs?"yes":"no");
1948 node->add_property("edit-group", _edit_group->name());
1951 node->add_property("mix-group", _mix_group->name());
1954 string order_string;
1955 OrderKeys::iterator x = order_keys.begin();
1957 while (x != order_keys.end()) {
1958 order_string += string ((*x).first);
1959 order_string += '=';
1960 snprintf (buf, sizeof(buf), "%ld", (*x).second);
1961 order_string += buf;
1965 if (x == order_keys.end()) {
1969 order_string += ':';
1971 node->add_property ("order-keys", order_string);
1973 node->add_child_nocopy (IO::state (full_state));
1974 node->add_child_nocopy (_solo_control->get_state ());
1975 node->add_child_nocopy (_mute_control->get_state ());
1977 XMLNode* remote_control_node = new XMLNode (X_("remote_control"));
1978 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
1979 remote_control_node->add_property (X_("id"), buf);
1980 node->add_child_nocopy (*remote_control_node);
1982 if (_control_outs) {
1983 XMLNode* cnode = new XMLNode (X_("ControlOuts"));
1984 cnode->add_child_nocopy (_control_outs->state (full_state));
1985 node->add_child_nocopy (*cnode);
1988 if (_comment.length()) {
1989 XMLNode *cmt = node->add_child ("Comment");
1990 cmt->add_content (_comment);
1993 for (i = _processors.begin(); i != _processors.end(); ++i) {
1994 node->add_child_nocopy((*i)->state (full_state));
1998 node->add_child_copy (*_extra_xml);
2005 Route::get_processor_state ()
2007 XMLNode* root = new XMLNode (X_("redirects"));
2008 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2009 root->add_child_nocopy ((*i)->state (true));
2016 Route::set_processor_state (const XMLNode& root)
2018 if (root.name() != X_("redirects")) {
2024 XMLNodeConstIterator iter;
2025 XMLNodeConstIterator niter;
2026 Glib::RWLock::ReaderLock lm (_processor_lock);
2028 nlist = root.children();
2030 for (iter = nlist.begin(); iter != nlist.end(); ++iter){
2032 /* iter now points to a IOProcessor state node */
2034 nnlist = (*iter)->children ();
2036 for (niter = nnlist.begin(); niter != nnlist.end(); ++niter) {
2038 /* find the IO child node, since it contains the ID we need */
2040 /* XXX OOP encapsulation violation, ugh */
2042 if ((*niter)->name() == IO::state_node_name) {
2044 XMLProperty* prop = (*niter)->property (X_("id"));
2047 warning << _("IOProcessor node has no ID, ignored") << endmsg;
2051 ID id = prop->value ();
2053 /* now look for a processor with that ID */
2055 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2056 if ((*i)->id() == id) {
2057 (*i)->set_state (**iter);
2073 Route::set_deferred_state ()
2076 XMLNodeConstIterator niter;
2078 if (!deferred_state) {
2082 nlist = deferred_state->children();
2084 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2085 add_processor_from_xml (**niter);
2088 delete deferred_state;
2093 Route::add_processor_from_xml (const XMLNode& node)
2095 const XMLProperty *prop;
2097 // legacy sessions use a different node name for sends
2098 if (node.name() == "Send") {
2101 boost::shared_ptr<Send> send (new Send (_session, node));
2102 add_processor (send);
2105 catch (failed_constructor &err) {
2106 error << _("Send construction failed") << endmsg;
2110 // use "Processor" in XML?
2111 } else if (node.name() == "Processor") {
2114 if ((prop = node.property ("type")) != 0) {
2116 boost::shared_ptr<Processor> processor;
2117 bool have_insert = false;
2119 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
2120 prop->value() == "lv2" ||
2121 prop->value() == "vst" ||
2122 prop->value() == "audiounit") {
2124 processor.reset (new PluginInsert(_session, node));
2127 } else if (prop->value() == "port") {
2129 processor.reset (new PortInsert (_session, node));
2131 } else if (prop->value() == "send") {
2133 processor.reset (new Send (_session, node));
2138 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
2141 add_processor (processor);
2144 error << _("Processor XML node has no type property") << endmsg;
2148 catch (failed_constructor &err) {
2149 warning << _("processor could not be created. Ignored.") << endmsg;
2156 Route::set_state (const XMLNode& node)
2158 return _set_state (node, true);
2162 Route::_set_state (const XMLNode& node, bool call_base)
2165 XMLNodeConstIterator niter;
2167 XMLPropertyList plist;
2168 const XMLProperty *prop;
2170 if (node.name() != "Route"){
2171 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2175 if ((prop = node.property (X_("flags"))) != 0) {
2176 _flags = Flag (string_2_enum (prop->value(), _flags));
2181 if ((prop = node.property (X_("default-type"))) != 0) {
2182 _default_type = DataType(prop->value());
2183 assert(_default_type != DataType::NIL);
2186 if ((prop = node.property (X_("phase-invert"))) != 0) {
2187 set_phase_invert (prop->value()=="yes"?true:false, this);
2190 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2191 set_denormal_protection (prop->value()=="yes"?true:false, this);
2195 if ((prop = node.property (X_("active"))) != 0) {
2196 set_active (prop->value() == "yes");
2199 if ((prop = node.property (X_("muted"))) != 0) {
2200 bool yn = prop->value()=="yes"?true:false;
2202 /* force reset of mute status */
2206 mute_gain = desired_mute_gain;
2209 if ((prop = node.property (X_("soloed"))) != 0) {
2210 bool yn = prop->value()=="yes"?true:false;
2212 /* force reset of solo status */
2215 set_solo (yn, this);
2216 solo_gain = desired_solo_gain;
2219 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2220 _mute_affects_pre_fader = (prop->value()=="yes")?true:false;
2223 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2224 _mute_affects_post_fader = (prop->value()=="yes")?true:false;
2227 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2228 _mute_affects_control_outs = (prop->value()=="yes")?true:false;
2231 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2232 _mute_affects_main_outs = (prop->value()=="yes")?true:false;
2235 if ((prop = node.property (X_("edit-group"))) != 0) {
2236 RouteGroup* edit_group = _session.edit_group_by_name(prop->value());
2237 if(edit_group == 0) {
2238 error << string_compose(_("Route %1: unknown edit group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
2240 set_edit_group(edit_group, this);
2244 if ((prop = node.property (X_("order-keys"))) != 0) {
2248 string::size_type colon, equal;
2249 string remaining = prop->value();
2251 while (remaining.length()) {
2253 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2254 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2257 if (sscanf (remaining.substr (equal+1).c_str(), "%ld", &n) != 1) {
2258 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2261 set_order_key (remaining.substr (0, equal).c_str(), n);
2265 colon = remaining.find_first_of (':');
2267 if (colon != string::npos) {
2268 remaining = remaining.substr (colon+1);
2275 nlist = node.children();
2277 delete deferred_state;
2278 deferred_state = new XMLNode(X_("deferred state"));
2280 /* set parent class properties before anything else */
2282 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2286 if (child->name() == IO::state_node_name && call_base) {
2288 IO::set_state (*child);
2293 XMLNodeList processor_nodes;
2295 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2299 if (child->name() == X_("Send") || child->name() == X_("Processor")) {
2300 processor_nodes.push_back(child);
2305 _set_processor_states(processor_nodes);
2308 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2310 // All processors have been applied already
2312 if (child->name() == X_("Automation")) {
2314 if ((prop = child->property (X_("path"))) != 0) {
2315 load_automation (prop->value());
2318 } else if (child->name() == X_("ControlOuts")) {
2320 string coutname = _name;
2321 coutname += _("[control]");
2323 delete _control_outs;
2324 _control_outs = new IO (_session, coutname);
2325 _control_outs->set_state (**(child->children().begin()));
2327 } else if (child->name() == X_("Comment")) {
2329 /* XXX this is a terrible API design in libxml++ */
2331 XMLNode *cmt = *(child->children().begin());
2332 _comment = cmt->content();
2334 } else if (child->name() == X_("extra")) {
2336 _extra_xml = new XMLNode (*child);
2338 } else if (child->name() == X_("controllable") && (prop = child->property("name")) != 0) {
2340 if (prop->value() == "solo") {
2341 _solo_control->set_state (*child);
2342 _session.add_controllable (_solo_control);
2344 else if (prop->value() == "mute") {
2345 _mute_control->set_state (*child);
2346 _session.add_controllable (_mute_control);
2349 else if (child->name() == X_("remote_control")) {
2350 if ((prop = child->property (X_("id"))) != 0) {
2352 sscanf (prop->value().c_str(), "%d", &x);
2353 set_remote_control_id (x);
2358 if ((prop = node.property (X_("mix-group"))) != 0) {
2359 RouteGroup* mix_group = _session.mix_group_by_name(prop->value());
2360 if (mix_group == 0) {
2361 error << string_compose(_("Route %1: unknown mix group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
2363 set_mix_group(mix_group, this);
2371 Route::_set_processor_states(const XMLNodeList &nlist)
2373 XMLNodeConstIterator niter;
2376 ProcessorList::iterator i, o;
2378 // Iterate through existing processors, remove those which are not in the state list
2379 for (i = _processors.begin(); i != _processors.end(); ) {
2380 ProcessorList::iterator tmp = i;
2383 bool processorInStateList = false;
2385 (*i)->id().print (buf, sizeof (buf));
2388 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2390 // legacy sessions (IOProcessor as a child of Processor, both is-a IO)
2391 if (strncmp(buf,(*niter)->child(X_("IOProcessor"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf)) == 0) {
2392 processorInStateList = true;
2394 } else if (strncmp(buf,(*niter)->property(X_("id"))->value().c_str(), sizeof(buf)) == 0) {
2395 processorInStateList = true;
2400 if (!processorInStateList) {
2401 remove_processor (*i);
2409 // Iterate through state list and make sure all processors are on the track and in the correct order,
2410 // set the state of existing processors according to the new state on the same go
2411 i = _processors.begin();
2412 for (niter = nlist.begin(); niter != nlist.end(); ++niter, ++i) {
2414 // Check whether the next processor in the list
2417 while (o != _processors.end()) {
2418 (*o)->id().print (buf, sizeof (buf));
2419 if ( strncmp(buf, (*niter)->child(X_("IOProcessor"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf)) == 0)
2421 else if (strncmp(buf,(*niter)->property(X_("id"))->value().c_str(), sizeof(buf)) == 0)
2427 if (o == _processors.end()) {
2428 // If the processor (*niter) is not on the route, we need to create it
2429 // and move it to the correct location
2431 ProcessorList::iterator prev_last = _processors.end();
2432 --prev_last; // We need this to check whether adding succeeded
2434 add_processor_from_xml (**niter);
2436 ProcessorList::iterator last = _processors.end();
2439 if (prev_last == last) {
2440 cerr << "Could not fully restore state as some processors were not possible to create" << endl;
2445 boost::shared_ptr<Processor> tmp = (*last);
2446 // remove the processor from the wrong location
2447 _processors.erase(last);
2448 // processor the new processor at the current location
2449 _processors.insert(i, tmp);
2451 --i; // move pointer to the newly processored processor
2455 // We found the processor (*niter) on the route, first we must make sure the processor
2456 // is at the location provided in the XML state
2458 boost::shared_ptr<Processor> tmp = (*o);
2459 // remove the old copy
2460 _processors.erase(o);
2461 // processor the processor at the correct location
2462 _processors.insert(i, tmp);
2464 --i; // move pointer so it points to the right processor
2467 (*i)->set_state( (**niter) );
2470 processors_changed ();
2474 Route::curve_reallocate ()
2476 // _gain_automation_curve.finish_resize ();
2477 // _pan_automation_curve.finish_resize ();
2481 Route::silence (nframes_t nframes, nframes_t offset)
2485 IO::silence (nframes, offset);
2487 if (_control_outs) {
2488 _control_outs->silence (nframes, offset);
2492 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2495 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2496 boost::shared_ptr<PluginInsert> pi;
2497 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2498 // skip plugins, they don't need anything when we're not active
2502 (*i)->silence (nframes, offset);
2505 if (nframes == _session.get_block_size() && offset == 0) {
2515 Route::set_control_outs (const vector<string>& ports)
2517 Glib::Mutex::Lock lm (_control_outs_lock);
2518 vector<string>::const_iterator i;
2521 delete _control_outs;
2524 if (is_control() || is_master()) {
2525 /* no control outs for these two special busses */
2529 if (ports.empty()) {
2533 string coutname = _name;
2534 coutname += _("[control]");
2536 _control_outs = new IO (_session, coutname);
2538 /* our control outs need as many outputs as we
2539 have audio outputs. we track the changes in ::output_change_handler().
2542 // XXX its stupid that we have to get this value twice
2544 limit = n_outputs().n_audio();
2546 if (_control_outs->ensure_io (ChanCount::ZERO, ChanCount (DataType::AUDIO, n_outputs().get (DataType::AUDIO)), true, this)) {
2550 /* now connect to the named ports */
2552 for (size_t n = 0; n < limit; ++n) {
2553 if (_control_outs->connect_output (_control_outs->output (n), ports[n % ports.size()], this)) {
2554 error << string_compose (_("could not connect %1 to %2"), _control_outs->output(n)->name(), ports[n]) << endmsg;
2563 Route::set_edit_group (RouteGroup *eg, void *src)
2566 if (eg == _edit_group) {
2571 _edit_group->remove (this);
2574 if ((_edit_group = eg) != 0) {
2575 _edit_group->add (this);
2578 _session.set_dirty ();
2579 edit_group_changed (src); /* EMIT SIGNAL */
2583 Route::drop_edit_group (void *src)
2586 _session.set_dirty ();
2587 edit_group_changed (src); /* EMIT SIGNAL */
2591 Route::set_mix_group (RouteGroup *mg, void *src)
2594 if (mg == _mix_group) {
2599 _mix_group->remove (this);
2602 if ((_mix_group = mg) != 0) {
2603 _mix_group->add (this);
2606 _session.set_dirty ();
2607 mix_group_changed (src); /* EMIT SIGNAL */
2611 Route::drop_mix_group (void *src)
2614 _session.set_dirty ();
2615 mix_group_changed (src); /* EMIT SIGNAL */
2619 Route::set_comment (string cmt, void *src)
2622 comment_changed (src);
2623 _session.set_dirty ();
2627 Route::feeds (boost::shared_ptr<Route> other)
2632 uint32_t no = self.n_outputs().n_total();
2633 uint32_t ni = other->n_inputs ().n_total();
2635 for (i = 0; i < no; ++i) {
2636 for (j = 0; j < ni; ++j) {
2637 if (self.output(i)->connected_to (other->input(j)->name())) {
2643 /* check IOProcessors which may also interconnect Routes */
2645 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); r++) {
2647 boost::shared_ptr<IOProcessor> redirect = boost::dynamic_pointer_cast<IOProcessor>(*r);
2652 // TODO: support internal redirects here
2654 no = redirect->io()->n_outputs().n_total();
2656 for (i = 0; i < no; ++i) {
2657 for (j = 0; j < ni; ++j) {
2658 if (redirect->io()->output(i)->connected_to (other->input (j)->name())) {
2665 /* check for control room outputs which may also interconnect Routes */
2667 if (_control_outs) {
2669 no = _control_outs->n_outputs().n_total();
2671 for (i = 0; i < no; ++i) {
2672 for (j = 0; j < ni; ++j) {
2673 if (_control_outs->output(i)->connected_to (other->input (j)->name())) {
2684 Route::set_mute_config (mute_type t, bool onoff, void *src)
2688 _mute_affects_pre_fader = onoff;
2689 pre_fader_changed(src); /* EMIT SIGNAL */
2693 _mute_affects_post_fader = onoff;
2694 post_fader_changed(src); /* EMIT SIGNAL */
2698 _mute_affects_control_outs = onoff;
2699 control_outs_changed(src); /* EMIT SIGNAL */
2703 _mute_affects_main_outs = onoff;
2704 main_outs_changed(src); /* EMIT SIGNAL */
2710 Route::get_mute_config (mute_type t)
2716 onoff = _mute_affects_pre_fader;
2719 onoff = _mute_affects_post_fader;
2722 onoff = _mute_affects_control_outs;
2725 onoff = _mute_affects_main_outs;
2733 Route::handle_transport_stopped (bool abort_ignored, bool did_locate, bool can_flush_processors)
2735 nframes_t now = _session.transport_frame();
2738 Glib::RWLock::ReaderLock lm (_processor_lock);
2741 automation_snapshot (now, true);
2744 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2746 if (Config->get_plugins_stop_with_transport() && can_flush_processors) {
2747 (*i)->deactivate ();
2751 (*i)->transport_stopped (now);
2755 IO::transport_stopped (now);
2757 _roll_delay = _initial_delay;
2761 Route::input_change_handler (IOChange change, void *ignored)
2763 if (change & ConfigurationChanged) {
2764 reset_processor_counts (0);
2769 Route::output_change_handler (IOChange change, void *ignored)
2771 if (change & ConfigurationChanged) {
2772 if (_control_outs) {
2773 _control_outs->ensure_io (ChanCount::ZERO, ChanCount(DataType::AUDIO, n_outputs().n_audio()), true, this);
2776 reset_processor_counts (0);
2781 Route::pans_required () const
2783 if (n_outputs().n_audio() < 2) {
2787 return max (n_inputs ().n_audio(), processor_max_outs.n_audio());
2791 Route::no_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
2792 bool session_state_changing, bool can_record, bool rec_monitors_input)
2794 if (n_outputs().n_total() == 0) {
2798 if (session_state_changing || !_active) {
2799 silence (nframes, offset);
2803 apply_gain_automation = false;
2805 if (n_inputs().n_total()) {
2806 passthru (start_frame, end_frame, nframes, offset, 0, false);
2808 silence (nframes, offset);
2815 Route::check_initial_delay (nframes_t nframes, nframes_t& offset, nframes_t& transport_frame)
2817 if (_roll_delay > nframes) {
2819 _roll_delay -= nframes;
2820 silence (nframes, offset);
2821 /* transport frame is not legal for caller to use */
2824 } else if (_roll_delay > 0) {
2826 nframes -= _roll_delay;
2828 silence (_roll_delay, offset);
2830 offset += _roll_delay;
2831 transport_frame += _roll_delay;
2840 Route::roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset, int declick,
2841 bool can_record, bool rec_monitors_input)
2844 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2846 // automation snapshot can also be called from the non-rt context
2847 // and it uses the processor list, so we take the lock out here
2848 automation_snapshot (_session.transport_frame(), false);
2852 if ((n_outputs().n_total() == 0 && _processors.empty()) || n_inputs().n_total() == 0 || !_active) {
2853 silence (nframes, offset);
2857 nframes_t unused = 0;
2859 if ((nframes = check_initial_delay (nframes, offset, unused)) == 0) {
2865 apply_gain_automation = false;
2868 Glib::Mutex::Lock am (data().control_lock(), Glib::TRY_LOCK);
2870 if (am.locked() && _session.transport_rolling()) {
2872 if (_gain_control->automation_playback()) {
2873 apply_gain_automation = _gain_control->list()->curve().rt_safe_get_vector (
2874 start_frame, end_frame, _session.gain_automation_buffer(), nframes);
2879 passthru (start_frame, end_frame, nframes, offset, declick, false);
2885 Route::silent_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
2886 bool can_record, bool rec_monitors_input)
2888 silence (nframes, offset);
2893 Route::toggle_monitor_input ()
2895 for (PortSet::iterator i = _inputs.begin(); i != _inputs.end(); ++i) {
2896 i->ensure_monitor_input( ! i->monitoring_input());
2901 Route::has_external_redirects () const
2903 // FIXME: what about sends?
2905 boost::shared_ptr<const PortInsert> pi;
2907 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2908 if ((pi = boost::dynamic_pointer_cast<const PortInsert>(*i)) != 0) {
2910 for (PortSet::const_iterator port = pi->io()->outputs().begin();
2911 port != pi->io()->outputs().end(); ++port) {
2913 string port_name = port->name();
2914 string client_name = port_name.substr (0, port_name.find(':'));
2916 /* only say "yes" if the redirect is actually in use */
2918 if (client_name != "ardour" && pi->active()) {
2929 Route::flush_processors ()
2931 /* XXX shouldn't really try to take this lock, since
2932 this is called from the RT audio thread.
2935 Glib::RWLock::ReaderLock lm (_processor_lock);
2937 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2938 (*i)->deactivate ();
2944 Route::set_meter_point (MeterPoint p, void *src)
2946 if (_meter_point != p) {
2948 meter_change (src); /* EMIT SIGNAL */
2949 _session.set_dirty ();
2954 Route::update_total_latency ()
2956 nframes_t old = _own_latency;
2958 if (_user_latency) {
2959 _own_latency = _user_latency;
2963 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2964 if ((*i)->active ()) {
2965 _own_latency += (*i)->signal_latency ();
2970 #undef DEBUG_LATENCY
2971 #ifdef DEBUG_LATENCY
2972 cerr << _name << ": internal redirect latency = " << _own_latency << endl;
2975 set_port_latency (_own_latency);
2977 if (!_user_latency) {
2978 /* this (virtual) function is used for pure Routes,
2979 not derived classes like AudioTrack. this means
2980 that the data processed here comes from an input
2981 port, not prerecorded material, and therefore we
2982 have to take into account any input latency.
2986 _own_latency += input_latency ();
2989 if (old != _own_latency) {
2990 signal_latency_changed (); /* EMIT SIGNAL */
2993 #ifdef DEBUG_LATENCY
2994 cerr << _name << ": input latency = " << input_latency() << " total = "
2995 << _own_latency << endl;
2998 return _own_latency;
3002 Route::set_user_latency (nframes_t nframes)
3004 Latent::set_user_latency (nframes);
3005 _session.update_latency_compensation (false, false);
3009 Route::set_latency_delay (nframes_t longest_session_latency)
3011 nframes_t old = _initial_delay;
3013 if (_own_latency < longest_session_latency) {
3014 _initial_delay = longest_session_latency - _own_latency;
3019 if (_initial_delay != old) {
3020 initial_delay_changed (); /* EMIT SIGNAL */
3023 if (_session.transport_stopped()) {
3024 _roll_delay = _initial_delay;
3029 Route::automation_snapshot (nframes_t now, bool force)
3031 if (!force && !should_snapshot(now)) {
3035 IO::automation_snapshot (now, force);
3037 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3038 (*i)->automation_snapshot (now, force);
3042 Route::ToggleControllable::ToggleControllable (std::string name, Route& s, ToggleType tp)
3043 : Controllable (name), route (s), type(tp)
3049 Route::ToggleControllable::set_value (float val)
3051 bool bval = ((val >= 0.5f) ? true: false);
3055 route.set_mute (bval, this);
3058 route.set_solo (bval, this);
3066 Route::ToggleControllable::get_value (void) const
3072 val = route.muted() ? 1.0f : 0.0f;
3075 val = route.soloed() ? 1.0f : 0.0f;
3085 Route::set_block_size (nframes_t nframes)
3087 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3088 (*i)->set_block_size (nframes);
3093 Route::protect_automation ()
3095 Automatable::protect_automation();
3097 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
3098 (*i)->protect_automation();
3102 Route::set_pending_declick (int declick)
3105 /* this call is not allowed to turn off a pending declick unless "force" is true */
3107 _pending_declick = declick;
3109 // cerr << _name << ": after setting to " << declick << " pending declick = " << _pending_declick << endl;
3111 _pending_declick = 0;
3116 /** Shift automation forwards from a particular place, thereby inserting time.
3117 * Adds undo commands for any shifts that are performed.
3119 * @param pos Position to start shifting from.
3120 * @param frames Amount to shift forwards by.
3124 Route::shift (nframes64_t pos, nframes64_t frames)
3126 #ifdef THIS_NEEDS_FIXING_FOR_V3
3128 /* gain automation */
3129 XMLNode &before = _gain_control->get_state ();
3130 _gain_control->shift (pos, frames);
3131 XMLNode &after = _gain_control->get_state ();
3132 _session.add_command (new MementoCommand<AutomationList> (_gain_automation_curve, &before, &after));
3134 /* pan automation */
3135 for (std::vector<StreamPanner*>::iterator i = _panner->begin (); i != _panner->end (); ++i) {
3136 Curve & c = (*i)->automation ();
3137 XMLNode &before = c.get_state ();
3138 c.shift (pos, frames);
3139 XMLNode &after = c.get_state ();
3140 _session.add_command (new MementoCommand<AutomationList> (c, &before, &after));
3143 /* redirect automation */
3145 Glib::RWLock::ReaderLock lm (redirect_lock);
3146 for (RedirectList::iterator i = _redirects.begin (); i != _redirects.end (); ++i) {
3149 (*i)->what_has_automation (a);
3151 for (set<uint32_t>::const_iterator j = a.begin (); j != a.end (); ++j) {
3152 AutomationList & al = (*i)->automation_list (*j);
3153 XMLNode &before = al.get_state ();
3154 al.shift (pos, frames);
3155 XMLNode &after = al.get_state ();
3156 _session.add_command (new MementoCommand<AutomationList> (al, &before, &after));