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");
1946 node->add_property("meter-point", enum_2_string (_meter_point));
1949 node->add_property("edit-group", _edit_group->name());
1952 node->add_property("mix-group", _mix_group->name());
1955 string order_string;
1956 OrderKeys::iterator x = order_keys.begin();
1958 while (x != order_keys.end()) {
1959 order_string += string ((*x).first);
1960 order_string += '=';
1961 snprintf (buf, sizeof(buf), "%ld", (*x).second);
1962 order_string += buf;
1966 if (x == order_keys.end()) {
1970 order_string += ':';
1972 node->add_property ("order-keys", order_string);
1974 node->add_child_nocopy (IO::state (full_state));
1975 node->add_child_nocopy (_solo_control->get_state ());
1976 node->add_child_nocopy (_mute_control->get_state ());
1978 XMLNode* remote_control_node = new XMLNode (X_("remote_control"));
1979 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
1980 remote_control_node->add_property (X_("id"), buf);
1981 node->add_child_nocopy (*remote_control_node);
1983 if (_control_outs) {
1984 XMLNode* cnode = new XMLNode (X_("ControlOuts"));
1985 cnode->add_child_nocopy (_control_outs->state (full_state));
1986 node->add_child_nocopy (*cnode);
1989 if (_comment.length()) {
1990 XMLNode *cmt = node->add_child ("Comment");
1991 cmt->add_content (_comment);
1994 for (i = _processors.begin(); i != _processors.end(); ++i) {
1995 node->add_child_nocopy((*i)->state (full_state));
1999 node->add_child_copy (*_extra_xml);
2006 Route::get_processor_state ()
2008 XMLNode* root = new XMLNode (X_("redirects"));
2009 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2010 root->add_child_nocopy ((*i)->state (true));
2017 Route::set_processor_state (const XMLNode& root)
2019 if (root.name() != X_("redirects")) {
2025 XMLNodeConstIterator iter;
2026 XMLNodeConstIterator niter;
2027 Glib::RWLock::ReaderLock lm (_processor_lock);
2029 nlist = root.children();
2031 for (iter = nlist.begin(); iter != nlist.end(); ++iter){
2033 /* iter now points to a IOProcessor state node */
2035 nnlist = (*iter)->children ();
2037 for (niter = nnlist.begin(); niter != nnlist.end(); ++niter) {
2039 /* find the IO child node, since it contains the ID we need */
2041 /* XXX OOP encapsulation violation, ugh */
2043 if ((*niter)->name() == IO::state_node_name) {
2045 XMLProperty* prop = (*niter)->property (X_("id"));
2048 warning << _("IOProcessor node has no ID, ignored") << endmsg;
2052 ID id = prop->value ();
2054 /* now look for a processor with that ID */
2056 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2057 if ((*i)->id() == id) {
2058 (*i)->set_state (**iter);
2074 Route::set_deferred_state ()
2077 XMLNodeConstIterator niter;
2079 if (!deferred_state) {
2083 nlist = deferred_state->children();
2085 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2086 add_processor_from_xml (**niter);
2089 delete deferred_state;
2094 Route::add_processor_from_xml (const XMLNode& node)
2096 const XMLProperty *prop;
2098 // legacy sessions use a different node name for sends
2099 if (node.name() == "Send") {
2102 boost::shared_ptr<Send> send (new Send (_session, node));
2103 add_processor (send);
2106 catch (failed_constructor &err) {
2107 error << _("Send construction failed") << endmsg;
2111 // use "Processor" in XML?
2112 } else if (node.name() == "Processor") {
2115 if ((prop = node.property ("type")) != 0) {
2117 boost::shared_ptr<Processor> processor;
2118 bool have_insert = false;
2120 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
2121 prop->value() == "lv2" ||
2122 prop->value() == "vst" ||
2123 prop->value() == "audiounit") {
2125 processor.reset (new PluginInsert(_session, node));
2128 } else if (prop->value() == "port") {
2130 processor.reset (new PortInsert (_session, node));
2132 } else if (prop->value() == "send") {
2134 processor.reset (new Send (_session, node));
2139 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
2142 add_processor (processor);
2145 error << _("Processor XML node has no type property") << endmsg;
2149 catch (failed_constructor &err) {
2150 warning << _("processor could not be created. Ignored.") << endmsg;
2157 Route::set_state (const XMLNode& node)
2159 return _set_state (node, true);
2163 Route::_set_state (const XMLNode& node, bool call_base)
2166 XMLNodeConstIterator niter;
2168 XMLPropertyList plist;
2169 const XMLProperty *prop;
2171 if (node.name() != "Route"){
2172 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2176 if ((prop = node.property (X_("flags"))) != 0) {
2177 _flags = Flag (string_2_enum (prop->value(), _flags));
2182 if ((prop = node.property (X_("default-type"))) != 0) {
2183 _default_type = DataType(prop->value());
2184 assert(_default_type != DataType::NIL);
2187 if ((prop = node.property (X_("phase-invert"))) != 0) {
2188 set_phase_invert (prop->value()=="yes"?true:false, this);
2191 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2192 set_denormal_protection (prop->value()=="yes"?true:false, this);
2196 if ((prop = node.property (X_("active"))) != 0) {
2197 set_active (prop->value() == "yes");
2200 if ((prop = node.property (X_("muted"))) != 0) {
2201 bool yn = prop->value()=="yes"?true:false;
2203 /* force reset of mute status */
2207 mute_gain = desired_mute_gain;
2210 if ((prop = node.property (X_("soloed"))) != 0) {
2211 bool yn = prop->value()=="yes"?true:false;
2213 /* force reset of solo status */
2216 set_solo (yn, this);
2217 solo_gain = desired_solo_gain;
2220 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2221 _mute_affects_pre_fader = (prop->value()=="yes")?true:false;
2224 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2225 _mute_affects_post_fader = (prop->value()=="yes")?true:false;
2228 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2229 _mute_affects_control_outs = (prop->value()=="yes")?true:false;
2232 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2233 _mute_affects_main_outs = (prop->value()=="yes")?true:false;
2236 if ((prop = node.property (X_("meter-point"))) != 0) {
2237 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
2240 if ((prop = node.property (X_("edit-group"))) != 0) {
2241 RouteGroup* edit_group = _session.edit_group_by_name(prop->value());
2242 if(edit_group == 0) {
2243 error << string_compose(_("Route %1: unknown edit group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
2245 set_edit_group(edit_group, this);
2249 if ((prop = node.property (X_("order-keys"))) != 0) {
2253 string::size_type colon, equal;
2254 string remaining = prop->value();
2256 while (remaining.length()) {
2258 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2259 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2262 if (sscanf (remaining.substr (equal+1).c_str(), "%ld", &n) != 1) {
2263 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2266 set_order_key (remaining.substr (0, equal).c_str(), n);
2270 colon = remaining.find_first_of (':');
2272 if (colon != string::npos) {
2273 remaining = remaining.substr (colon+1);
2280 nlist = node.children();
2282 delete deferred_state;
2283 deferred_state = new XMLNode(X_("deferred state"));
2285 /* set parent class properties before anything else */
2287 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2291 if (child->name() == IO::state_node_name && call_base) {
2293 IO::set_state (*child);
2298 XMLNodeList processor_nodes;
2300 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2304 if (child->name() == X_("Send") || child->name() == X_("Processor")) {
2305 processor_nodes.push_back(child);
2310 _set_processor_states(processor_nodes);
2313 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2315 // All processors have been applied already
2317 if (child->name() == X_("Automation")) {
2319 if ((prop = child->property (X_("path"))) != 0) {
2320 load_automation (prop->value());
2323 } else if (child->name() == X_("ControlOuts")) {
2325 string coutname = _name;
2326 coutname += _("[control]");
2328 delete _control_outs;
2329 _control_outs = new IO (_session, coutname);
2330 _control_outs->set_state (**(child->children().begin()));
2332 } else if (child->name() == X_("Comment")) {
2334 /* XXX this is a terrible API design in libxml++ */
2336 XMLNode *cmt = *(child->children().begin());
2337 _comment = cmt->content();
2339 } else if (child->name() == X_("extra")) {
2341 _extra_xml = new XMLNode (*child);
2343 } else if (child->name() == X_("controllable") && (prop = child->property("name")) != 0) {
2345 if (prop->value() == "solo") {
2346 _solo_control->set_state (*child);
2347 _session.add_controllable (_solo_control);
2349 else if (prop->value() == "mute") {
2350 _mute_control->set_state (*child);
2351 _session.add_controllable (_mute_control);
2354 else if (child->name() == X_("remote_control")) {
2355 if ((prop = child->property (X_("id"))) != 0) {
2357 sscanf (prop->value().c_str(), "%d", &x);
2358 set_remote_control_id (x);
2363 if ((prop = node.property (X_("mix-group"))) != 0) {
2364 RouteGroup* mix_group = _session.mix_group_by_name(prop->value());
2365 if (mix_group == 0) {
2366 error << string_compose(_("Route %1: unknown mix group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
2368 set_mix_group(mix_group, this);
2376 Route::_set_processor_states(const XMLNodeList &nlist)
2378 XMLNodeConstIterator niter;
2381 ProcessorList::iterator i, o;
2383 // Iterate through existing processors, remove those which are not in the state list
2384 for (i = _processors.begin(); i != _processors.end(); ) {
2385 ProcessorList::iterator tmp = i;
2388 bool processorInStateList = false;
2390 (*i)->id().print (buf, sizeof (buf));
2393 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2395 // legacy sessions (IOProcessor as a child of Processor, both is-a IO)
2396 if (strncmp(buf,(*niter)->child(X_("IOProcessor"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf)) == 0) {
2397 processorInStateList = true;
2399 } else if (strncmp(buf,(*niter)->property(X_("id"))->value().c_str(), sizeof(buf)) == 0) {
2400 processorInStateList = true;
2405 if (!processorInStateList) {
2406 remove_processor (*i);
2414 // Iterate through state list and make sure all processors are on the track and in the correct order,
2415 // set the state of existing processors according to the new state on the same go
2416 i = _processors.begin();
2417 for (niter = nlist.begin(); niter != nlist.end(); ++niter, ++i) {
2419 // Check whether the next processor in the list
2422 while (o != _processors.end()) {
2423 (*o)->id().print (buf, sizeof (buf));
2424 if ( strncmp(buf, (*niter)->child(X_("IOProcessor"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf)) == 0)
2426 else if (strncmp(buf,(*niter)->property(X_("id"))->value().c_str(), sizeof(buf)) == 0)
2432 if (o == _processors.end()) {
2433 // If the processor (*niter) is not on the route, we need to create it
2434 // and move it to the correct location
2436 ProcessorList::iterator prev_last = _processors.end();
2437 --prev_last; // We need this to check whether adding succeeded
2439 add_processor_from_xml (**niter);
2441 ProcessorList::iterator last = _processors.end();
2444 if (prev_last == last) {
2445 cerr << "Could not fully restore state as some processors were not possible to create" << endl;
2450 boost::shared_ptr<Processor> tmp = (*last);
2451 // remove the processor from the wrong location
2452 _processors.erase(last);
2453 // processor the new processor at the current location
2454 _processors.insert(i, tmp);
2456 --i; // move pointer to the newly processored processor
2460 // We found the processor (*niter) on the route, first we must make sure the processor
2461 // is at the location provided in the XML state
2463 boost::shared_ptr<Processor> tmp = (*o);
2464 // remove the old copy
2465 _processors.erase(o);
2466 // processor the processor at the correct location
2467 _processors.insert(i, tmp);
2469 --i; // move pointer so it points to the right processor
2472 (*i)->set_state( (**niter) );
2475 processors_changed ();
2479 Route::curve_reallocate ()
2481 // _gain_automation_curve.finish_resize ();
2482 // _pan_automation_curve.finish_resize ();
2486 Route::silence (nframes_t nframes, nframes_t offset)
2490 IO::silence (nframes, offset);
2492 if (_control_outs) {
2493 _control_outs->silence (nframes, offset);
2497 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2500 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2501 boost::shared_ptr<PluginInsert> pi;
2502 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2503 // skip plugins, they don't need anything when we're not active
2507 (*i)->silence (nframes, offset);
2510 if (nframes == _session.get_block_size() && offset == 0) {
2520 Route::set_control_outs (const vector<string>& ports)
2522 Glib::Mutex::Lock lm (_control_outs_lock);
2523 vector<string>::const_iterator i;
2526 delete _control_outs;
2529 if (is_control() || is_master()) {
2530 /* no control outs for these two special busses */
2534 if (ports.empty()) {
2538 string coutname = _name;
2539 coutname += _("[control]");
2541 _control_outs = new IO (_session, coutname);
2543 /* our control outs need as many outputs as we
2544 have audio outputs. we track the changes in ::output_change_handler().
2547 // XXX its stupid that we have to get this value twice
2549 limit = n_outputs().n_audio();
2551 if (_control_outs->ensure_io (ChanCount::ZERO, ChanCount (DataType::AUDIO, n_outputs().get (DataType::AUDIO)), true, this)) {
2555 /* now connect to the named ports */
2557 for (size_t n = 0; n < limit; ++n) {
2558 if (_control_outs->connect_output (_control_outs->output (n), ports[n % ports.size()], this)) {
2559 error << string_compose (_("could not connect %1 to %2"), _control_outs->output(n)->name(), ports[n]) << endmsg;
2568 Route::set_edit_group (RouteGroup *eg, void *src)
2571 if (eg == _edit_group) {
2576 _edit_group->remove (this);
2579 if ((_edit_group = eg) != 0) {
2580 _edit_group->add (this);
2583 _session.set_dirty ();
2584 edit_group_changed (src); /* EMIT SIGNAL */
2588 Route::drop_edit_group (void *src)
2591 _session.set_dirty ();
2592 edit_group_changed (src); /* EMIT SIGNAL */
2596 Route::set_mix_group (RouteGroup *mg, void *src)
2599 if (mg == _mix_group) {
2604 _mix_group->remove (this);
2607 if ((_mix_group = mg) != 0) {
2608 _mix_group->add (this);
2611 _session.set_dirty ();
2612 mix_group_changed (src); /* EMIT SIGNAL */
2616 Route::drop_mix_group (void *src)
2619 _session.set_dirty ();
2620 mix_group_changed (src); /* EMIT SIGNAL */
2624 Route::set_comment (string cmt, void *src)
2627 comment_changed (src);
2628 _session.set_dirty ();
2632 Route::feeds (boost::shared_ptr<Route> other)
2637 uint32_t no = self.n_outputs().n_total();
2638 uint32_t ni = other->n_inputs ().n_total();
2640 for (i = 0; i < no; ++i) {
2641 for (j = 0; j < ni; ++j) {
2642 if (self.output(i)->connected_to (other->input(j)->name())) {
2648 /* check IOProcessors which may also interconnect Routes */
2650 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); r++) {
2652 boost::shared_ptr<IOProcessor> redirect = boost::dynamic_pointer_cast<IOProcessor>(*r);
2657 // TODO: support internal redirects here
2659 no = redirect->io()->n_outputs().n_total();
2661 for (i = 0; i < no; ++i) {
2662 for (j = 0; j < ni; ++j) {
2663 if (redirect->io()->output(i)->connected_to (other->input (j)->name())) {
2670 /* check for control room outputs which may also interconnect Routes */
2672 if (_control_outs) {
2674 no = _control_outs->n_outputs().n_total();
2676 for (i = 0; i < no; ++i) {
2677 for (j = 0; j < ni; ++j) {
2678 if (_control_outs->output(i)->connected_to (other->input (j)->name())) {
2689 Route::set_mute_config (mute_type t, bool onoff, void *src)
2693 _mute_affects_pre_fader = onoff;
2694 pre_fader_changed(src); /* EMIT SIGNAL */
2698 _mute_affects_post_fader = onoff;
2699 post_fader_changed(src); /* EMIT SIGNAL */
2703 _mute_affects_control_outs = onoff;
2704 control_outs_changed(src); /* EMIT SIGNAL */
2708 _mute_affects_main_outs = onoff;
2709 main_outs_changed(src); /* EMIT SIGNAL */
2715 Route::get_mute_config (mute_type t)
2721 onoff = _mute_affects_pre_fader;
2724 onoff = _mute_affects_post_fader;
2727 onoff = _mute_affects_control_outs;
2730 onoff = _mute_affects_main_outs;
2738 Route::handle_transport_stopped (bool abort_ignored, bool did_locate, bool can_flush_processors)
2740 nframes_t now = _session.transport_frame();
2743 Glib::RWLock::ReaderLock lm (_processor_lock);
2746 automation_snapshot (now, true);
2749 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2751 if (Config->get_plugins_stop_with_transport() && can_flush_processors) {
2752 (*i)->deactivate ();
2756 (*i)->transport_stopped (now);
2760 IO::transport_stopped (now);
2762 _roll_delay = _initial_delay;
2766 Route::input_change_handler (IOChange change, void *ignored)
2768 if (change & ConfigurationChanged) {
2769 reset_processor_counts (0);
2774 Route::output_change_handler (IOChange change, void *ignored)
2776 if (change & ConfigurationChanged) {
2777 if (_control_outs) {
2778 _control_outs->ensure_io (ChanCount::ZERO, ChanCount(DataType::AUDIO, n_outputs().n_audio()), true, this);
2781 reset_processor_counts (0);
2786 Route::pans_required () const
2788 if (n_outputs().n_audio() < 2) {
2792 return max (n_inputs ().n_audio(), processor_max_outs.n_audio());
2796 Route::no_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
2797 bool session_state_changing, bool can_record, bool rec_monitors_input)
2799 if (n_outputs().n_total() == 0) {
2803 if (session_state_changing || !_active) {
2804 silence (nframes, offset);
2808 apply_gain_automation = false;
2810 if (n_inputs().n_total()) {
2811 passthru (start_frame, end_frame, nframes, offset, 0, false);
2813 silence (nframes, offset);
2820 Route::check_initial_delay (nframes_t nframes, nframes_t& offset, nframes_t& transport_frame)
2822 if (_roll_delay > nframes) {
2824 _roll_delay -= nframes;
2825 silence (nframes, offset);
2826 /* transport frame is not legal for caller to use */
2829 } else if (_roll_delay > 0) {
2831 nframes -= _roll_delay;
2833 silence (_roll_delay, offset);
2835 offset += _roll_delay;
2836 transport_frame += _roll_delay;
2845 Route::roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset, int declick,
2846 bool can_record, bool rec_monitors_input)
2849 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2851 // automation snapshot can also be called from the non-rt context
2852 // and it uses the processor list, so we take the lock out here
2853 automation_snapshot (_session.transport_frame(), false);
2857 if ((n_outputs().n_total() == 0 && _processors.empty()) || n_inputs().n_total() == 0 || !_active) {
2858 silence (nframes, offset);
2862 nframes_t unused = 0;
2864 if ((nframes = check_initial_delay (nframes, offset, unused)) == 0) {
2870 apply_gain_automation = false;
2873 Glib::Mutex::Lock am (data().control_lock(), Glib::TRY_LOCK);
2875 if (am.locked() && _session.transport_rolling()) {
2877 if (_gain_control->automation_playback()) {
2878 apply_gain_automation = _gain_control->list()->curve().rt_safe_get_vector (
2879 start_frame, end_frame, _session.gain_automation_buffer(), nframes);
2884 passthru (start_frame, end_frame, nframes, offset, declick, false);
2890 Route::silent_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
2891 bool can_record, bool rec_monitors_input)
2893 silence (nframes, offset);
2898 Route::toggle_monitor_input ()
2900 for (PortSet::iterator i = _inputs.begin(); i != _inputs.end(); ++i) {
2901 i->ensure_monitor_input( ! i->monitoring_input());
2906 Route::has_external_redirects () const
2908 // FIXME: what about sends?
2910 boost::shared_ptr<const PortInsert> pi;
2912 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2913 if ((pi = boost::dynamic_pointer_cast<const PortInsert>(*i)) != 0) {
2915 for (PortSet::const_iterator port = pi->io()->outputs().begin();
2916 port != pi->io()->outputs().end(); ++port) {
2918 string port_name = port->name();
2919 string client_name = port_name.substr (0, port_name.find(':'));
2921 /* only say "yes" if the redirect is actually in use */
2923 if (client_name != "ardour" && pi->active()) {
2934 Route::flush_processors ()
2936 /* XXX shouldn't really try to take this lock, since
2937 this is called from the RT audio thread.
2940 Glib::RWLock::ReaderLock lm (_processor_lock);
2942 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2943 (*i)->deactivate ();
2949 Route::set_meter_point (MeterPoint p, void *src)
2951 if (_meter_point != p) {
2953 meter_change (src); /* EMIT SIGNAL */
2954 _session.set_dirty ();
2959 Route::update_total_latency ()
2961 nframes_t old = _own_latency;
2963 if (_user_latency) {
2964 _own_latency = _user_latency;
2968 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2969 if ((*i)->active ()) {
2970 _own_latency += (*i)->signal_latency ();
2975 #undef DEBUG_LATENCY
2976 #ifdef DEBUG_LATENCY
2977 cerr << _name << ": internal redirect latency = " << _own_latency << endl;
2980 set_port_latency (_own_latency);
2982 if (!_user_latency) {
2983 /* this (virtual) function is used for pure Routes,
2984 not derived classes like AudioTrack. this means
2985 that the data processed here comes from an input
2986 port, not prerecorded material, and therefore we
2987 have to take into account any input latency.
2991 _own_latency += input_latency ();
2994 if (old != _own_latency) {
2995 signal_latency_changed (); /* EMIT SIGNAL */
2998 #ifdef DEBUG_LATENCY
2999 cerr << _name << ": input latency = " << input_latency() << " total = "
3000 << _own_latency << endl;
3003 return _own_latency;
3007 Route::set_user_latency (nframes_t nframes)
3009 Latent::set_user_latency (nframes);
3010 _session.update_latency_compensation (false, false);
3014 Route::set_latency_delay (nframes_t longest_session_latency)
3016 nframes_t old = _initial_delay;
3018 if (_own_latency < longest_session_latency) {
3019 _initial_delay = longest_session_latency - _own_latency;
3024 if (_initial_delay != old) {
3025 initial_delay_changed (); /* EMIT SIGNAL */
3028 if (_session.transport_stopped()) {
3029 _roll_delay = _initial_delay;
3034 Route::automation_snapshot (nframes_t now, bool force)
3036 if (!force && !should_snapshot(now)) {
3040 IO::automation_snapshot (now, force);
3042 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3043 (*i)->automation_snapshot (now, force);
3047 Route::ToggleControllable::ToggleControllable (std::string name, Route& s, ToggleType tp)
3048 : Controllable (name), route (s), type(tp)
3054 Route::ToggleControllable::set_value (float val)
3056 bool bval = ((val >= 0.5f) ? true: false);
3060 route.set_mute (bval, this);
3063 route.set_solo (bval, this);
3071 Route::ToggleControllable::get_value (void) const
3077 val = route.muted() ? 1.0f : 0.0f;
3080 val = route.soloed() ? 1.0f : 0.0f;
3090 Route::set_block_size (nframes_t nframes)
3092 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3093 (*i)->set_block_size (nframes);
3098 Route::protect_automation ()
3100 Automatable::protect_automation();
3102 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
3103 (*i)->protect_automation();
3107 Route::set_pending_declick (int declick)
3110 /* this call is not allowed to turn off a pending declick unless "force" is true */
3112 _pending_declick = declick;
3114 // cerr << _name << ": after setting to " << declick << " pending declick = " << _pending_declick << endl;
3116 _pending_declick = 0;
3121 /** Shift automation forwards from a particular place, thereby inserting time.
3122 * Adds undo commands for any shifts that are performed.
3124 * @param pos Position to start shifting from.
3125 * @param frames Amount to shift forwards by.
3129 Route::shift (nframes64_t pos, nframes64_t frames)
3131 #ifdef THIS_NEEDS_FIXING_FOR_V3
3133 /* gain automation */
3134 XMLNode &before = _gain_control->get_state ();
3135 _gain_control->shift (pos, frames);
3136 XMLNode &after = _gain_control->get_state ();
3137 _session.add_command (new MementoCommand<AutomationList> (_gain_automation_curve, &before, &after));
3139 /* pan automation */
3140 for (std::vector<StreamPanner*>::iterator i = _panner->begin (); i != _panner->end (); ++i) {
3141 Curve & c = (*i)->automation ();
3142 XMLNode &before = c.get_state ();
3143 c.shift (pos, frames);
3144 XMLNode &after = c.get_state ();
3145 _session.add_command (new MementoCommand<AutomationList> (c, &before, &after));
3148 /* redirect automation */
3150 Glib::RWLock::ReaderLock lm (redirect_lock);
3151 for (RedirectList::iterator i = _redirects.begin (); i != _redirects.end (); ++i) {
3154 (*i)->what_has_automation (a);
3156 for (set<uint32_t>::const_iterator j = a.begin (); j != a.end (); ++j) {
3157 AutomationList & al = (*i)->automation_list (*j);
3158 XMLNode &before = al.get_state ();
3159 al.shift (pos, frames);
3160 XMLNode &after = al.get_state ();
3161 _session.add_command (new MementoCommand<AutomationList> (al, &before, &after));