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));
133 delete _control_outs;
138 Route::set_remote_control_id (uint32_t id)
140 if (id != _remote_control_id) {
141 _remote_control_id = id;
142 RemoteControlIDChanged ();
147 Route::remote_control_id() const
149 return _remote_control_id;
153 Route::order_key (const char* name) const
155 OrderKeys::const_iterator i;
157 for (i = order_keys.begin(); i != order_keys.end(); ++i) {
158 if (!strcmp (name, i->first)) {
167 Route::set_order_key (const char* name, long n)
169 order_keys[strdup(name)] = n;
171 if (Config->get_sync_all_route_ordering()) {
172 for (OrderKeys::iterator x = order_keys.begin(); x != order_keys.end(); ++x) {
177 _session.set_dirty ();
181 Route::sync_order_keys (const char* base)
183 if (order_keys.empty()) {
187 OrderKeys::iterator i;
190 if ((i = order_keys.find (base)) == order_keys.end()) {
191 /* key doesn't exist, use the first existing
192 key (this is done during session initialization)
194 i = order_keys.begin();
198 /* key exists - use it and reset all others
199 (actually, itself included)
201 i = order_keys.begin();
205 for (; i != order_keys.end(); ++i) {
211 Route::ensure_track_or_route_name(string name, Session &session)
213 string newname = name;
215 while (session.route_by_name (newname)!=NULL)
217 newname = bump_name_once (newname);
225 Route::inc_gain (gain_t fraction, void *src)
227 IO::inc_gain (fraction, src);
231 Route::set_gain (gain_t val, void *src)
233 if (src != 0 && _mix_group && src != _mix_group && _mix_group->is_active()) {
235 if (_mix_group->is_relative()) {
237 gain_t usable_gain = gain();
238 if (usable_gain < 0.000001f) {
239 usable_gain = 0.000001f;
243 if (delta < 0.000001f) {
247 delta -= usable_gain;
252 gain_t factor = delta / usable_gain;
255 factor = _mix_group->get_max_factor(factor);
256 if (factor == 0.0f) {
257 _gain_control->Changed(); /* EMIT SIGNAL */
261 factor = _mix_group->get_min_factor(factor);
262 if (factor == 0.0f) {
263 _gain_control->Changed(); /* EMIT SIGNAL */
268 _mix_group->apply (&Route::inc_gain, factor, _mix_group);
272 _mix_group->apply (&Route::set_gain, val, _mix_group);
282 IO::set_gain (val, src);
285 /** Process this route for one (sub) cycle (process thread)
287 * @param bufs Scratch buffers to use for the signal path
288 * @param start_frame Initial transport frame
289 * @param end_frame Final transport frame
290 * @param nframes Number of frames to output (to ports)
291 * @param offset Output offset (of port buffers, for split cycles)
293 * Note that (end_frame - start_frame) may not be equal to nframes when the
294 * transport speed isn't 1.0 (eg varispeed).
297 Route::process_output_buffers (BufferSet& bufs,
298 nframes_t start_frame, nframes_t end_frame,
299 nframes_t nframes, nframes_t offset, bool with_processors, int declick,
302 // This is definitely very audio-only for now
303 assert(_default_type == DataType::AUDIO);
305 ProcessorList::iterator i;
306 bool post_fader_work = false;
307 bool mute_declick_applied = false;
313 gain_t* gab = _session.gain_automation_buffer();
315 switch (Config->get_monitoring_model()) {
316 case HardwareMonitoring:
317 case ExternalMonitoring:
324 declick = _pending_declick;
327 Glib::Mutex::Lock cm (_control_outs_lock, Glib::TRY_LOCK);
337 Glib::Mutex::Lock dm (declick_lock, Glib::TRY_LOCK);
340 dmg = desired_mute_gain;
341 dsg = desired_solo_gain;
350 /* ----------------------------------------------------------------------------------------------------
351 GLOBAL DECLICK (for transport changes etc.)
352 -------------------------------------------------------------------------------------------------- */
355 Amp::run_in_place (bufs, nframes, 0.0, 1.0, false);
356 _pending_declick = 0;
357 } else if (declick < 0) {
358 Amp::run_in_place (bufs, nframes, 1.0, 0.0, false);
359 _pending_declick = 0;
362 /* no global declick */
364 if (solo_gain != dsg) {
365 Amp::run_in_place (bufs, nframes, solo_gain, dsg, false);
371 /* ----------------------------------------------------------------------------------------------------
372 INPUT METERING & MONITORING
373 -------------------------------------------------------------------------------------------------- */
375 if (meter && (_meter_point == MeterInput)) {
376 _meter->run_in_place(bufs, start_frame, end_frame, nframes, offset);
379 if (!_soloed && _mute_affects_pre_fader && (mute_gain != dmg)) {
380 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
382 mute_declick_applied = true;
385 if ((_meter_point == MeterInput) && co) {
387 solo_audible = dsg > 0;
388 mute_audible = dmg > 0;// || !_mute_affects_pre_fader;
390 if ( // muted by solo of another track
394 // muted by mute of this track
398 // rec-enabled but not s/w monitoring
400 // TODO: this is probably wrong
402 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
406 co->silence (nframes, offset);
410 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
415 /* -----------------------------------------------------------------------------------------------------
417 -------------------------------------------------------------------------------------------------- */
419 if (_denormal_protection || Config->get_denormal_protection()) {
421 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
422 Sample* const sp = i->data();
424 for (nframes_t nx = offset; nx < nframes + offset; ++nx) {
430 /* ----------------------------------------------------------------------------------------------------
432 -------------------------------------------------------------------------------------------------- */
434 if (with_processors) {
435 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
437 if (mute_gain > 0 || !_mute_affects_pre_fader) {
438 for (i = _processors.begin(); i != _processors.end(); ++i) {
439 switch ((*i)->placement()) {
441 (*i)->run_in_place (bufs, start_frame, end_frame, nframes, offset);
444 post_fader_work = true;
449 for (i = _processors.begin(); i != _processors.end(); ++i) {
450 switch ((*i)->placement()) {
452 (*i)->silence (nframes, offset);
455 post_fader_work = true;
463 // This really should already be true...
464 bufs.set_count(pre_fader_streams());
466 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_post_fader) {
467 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
469 mute_declick_applied = true;
472 /* ----------------------------------------------------------------------------------------------------
473 PRE-FADER METERING & MONITORING
474 -------------------------------------------------------------------------------------------------- */
476 if (meter && (_meter_point == MeterPreFader)) {
477 _meter->run_in_place(bufs, start_frame, end_frame, nframes, offset);
481 if ((_meter_point == MeterPreFader) && co) {
483 solo_audible = dsg > 0;
484 mute_audible = dmg > 0 || !_mute_affects_pre_fader;
486 if ( // muted by solo of another track
490 // muted by mute of this track
494 // rec-enabled but not s/w monitoring
496 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
500 co->silence (nframes, offset);
504 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
508 /* ----------------------------------------------------------------------------------------------------
510 -------------------------------------------------------------------------------------------------- */
512 /* if not recording or recording and requiring any monitor signal, then apply gain */
514 if ( // not recording
516 !(record_enabled() && _session.actively_recording()) ||
520 // AND software monitoring required
522 Config->get_monitoring_model() == SoftwareMonitoring) {
524 if (apply_gain_automation) {
527 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
528 Sample* const sp = i->data();
530 for (nframes_t nx = 0; nx < nframes; ++nx) {
535 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
536 Sample* const sp = i->data();
538 for (nframes_t nx = 0; nx < nframes; ++nx) {
544 if (apply_gain_automation && _session.transport_rolling() && nframes > 0) {
545 _effective_gain = gab[nframes-1];
550 /* manual (scalar) gain */
554 Amp::run_in_place (bufs, nframes, _gain, dg, _phase_invert);
557 } else if (_gain != 0 && (_phase_invert || _gain != 1.0)) {
559 /* no need to interpolate current gain value,
560 but its non-unity, so apply it. if the gain
561 is zero, do nothing because we'll ship silence
573 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
574 Sample* const sp = i->data();
575 apply_gain_to_buffer(sp,nframes,this_gain);
578 } else if (_gain == 0) {
579 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
587 /* actively recording, no monitoring required; leave buffers as-is to save CPU cycles */
591 /* ----------------------------------------------------------------------------------------------------
593 -------------------------------------------------------------------------------------------------- */
595 /* note that post_fader_work cannot be true unless with_processors was also true, so don't test both */
597 if (post_fader_work) {
599 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
601 if (mute_gain > 0 || !_mute_affects_post_fader) {
602 for (i = _processors.begin(); i != _processors.end(); ++i) {
603 switch ((*i)->placement()) {
607 (*i)->run_in_place (bufs, start_frame, end_frame, nframes, offset);
612 for (i = _processors.begin(); i != _processors.end(); ++i) {
613 switch ((*i)->placement()) {
617 (*i)->silence (nframes, offset);
625 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_control_outs) {
626 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
628 mute_declick_applied = true;
631 /* ----------------------------------------------------------------------------------------------------
633 -------------------------------------------------------------------------------------------------- */
635 if ((_meter_point == MeterPostFader) && co) {
637 solo_audible = solo_gain > 0;
638 mute_audible = dmg > 0 || !_mute_affects_control_outs;
640 if ( // silent anyway
642 (_gain == 0 && !apply_gain_automation) ||
644 // muted by solo of another track
648 // muted by mute of this track
652 // recording but not s/w monitoring
654 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
658 co->silence (nframes, offset);
662 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
666 /* ----------------------------------------------------------------------
668 ----------------------------------------------------------------------*/
670 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_main_outs) {
671 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
673 mute_declick_applied = true;
676 /* ----------------------------------------------------------------------------------------------------
678 -------------------------------------------------------------------------------------------------- */
680 solo_audible = dsg > 0;
681 mute_audible = dmg > 0 || !_mute_affects_main_outs;
683 if (n_outputs().get(_default_type) == 0) {
687 } else if (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording())) {
689 IO::silence (nframes, offset);
693 if ( // silent anyway
695 (_gain == 0 && !apply_gain_automation) ||
697 // muted by solo of another track, but not using control outs for solo
699 (!solo_audible && (Config->get_solo_model() != SoloBus)) ||
701 // muted by mute of this track
707 /* don't use Route::silence() here, because that causes
708 all outputs (sends, port processors, etc. to be silent).
711 if (_meter_point == MeterPostFader) {
712 peak_meter().reset();
715 IO::silence (nframes, offset);
719 deliver_output(bufs, start_frame, end_frame, nframes, offset);
725 /* ----------------------------------------------------------------------------------------------------
727 -------------------------------------------------------------------------------------------------- */
729 if (meter && (_meter_point == MeterPostFader)) {
730 if ((_gain == 0 && !apply_gain_automation) || dmg == 0) {
733 _meter->run_in_place(output_buffers(), start_frame, end_frame, nframes, offset);
739 /** Process this route for one (sub) cycle (process thread)
741 * @param bufs Scratch buffers to use for the signal path
742 * @param start_frame Initial transport frame
743 * @param end_frame Final transport frame
744 * @param nframes Number of frames to output (to ports)
745 * @param offset Output offset (of port buffers, for split cycles)
747 * Note that (end_frame - start_frame) may not be equal to nframes when the
748 * transport speed isn't 1.0 (eg varispeed).
751 Route::process_output_buffers (BufferSet& bufs,
752 nframes_t start_frame, nframes_t end_frame,
753 nframes_t nframes, nframes_t offset, bool with_processors, int declick,
756 // This is definitely very audio-only for now
757 assert(_default_type == DataType::AUDIO);
759 ProcessorList::iterator i;
760 bool post_fader_work = false;
761 bool mute_declick_applied = false;
767 gain_t* gab = _session.gain_automation_buffer();
769 switch (Config->get_monitoring_model()) {
770 case HardwareMonitoring:
771 case ExternalMonitoring:
778 declick = _pending_declick;
781 Glib::Mutex::Lock cm (_control_outs_lock, Glib::TRY_LOCK);
791 Glib::Mutex::Lock dm (declick_lock, Glib::TRY_LOCK);
794 dmg = desired_mute_gain;
795 dsg = desired_solo_gain;
804 /* ----------------------------------------------------------------------------------------------------
805 GLOBAL DECLICK (for transport changes etc.)
806 input metering & monitoring (control outs)
809 pre-fader metering & monitoring (control outs)
814 post-fader metering & monitoring (control outs)
818 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
819 for (i = processors.begin(); i != processors.end(); ++i) {
820 (*i)->run_in_place (bufs, start_frame, end_frame, nframes, offset);
824 /* ----------------------------------------------------------------------------------------------------
825 INPUT METERING & MONITORING
826 -------------------------------------------------------------------------------------------------- */
828 if (meter && (_meter_point == MeterInput)) {
829 _meter->run_in_place(bufs, start_frame, end_frame, nframes, offset);
832 if (!_soloed && _mute_affects_pre_fader && (mute_gain != dmg)) {
833 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
835 mute_declick_applied = true;
838 /* ----------------------------------------------------------------------------------------------------
840 -------------------------------------------------------------------------------------------------- */
842 // This really should already be true...
843 bufs.set_count(pre_fader_streams());
846 if ((_meter_point == MeterPreFader) && co) {
848 solo_audible = dsg > 0;
849 mute_audible = dmg > 0 || !_mute_affects_pre_fader;
851 if ( // muted by solo of another track
855 // muted by mute of this track
859 // rec-enabled but not s/w monitoring
861 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
865 co->silence (nframes, offset);
869 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
873 /* ----------------------------------------------------------------------------------------------------
875 -------------------------------------------------------------------------------------------------- */
877 /* if not recording or recording and requiring any monitor signal, then apply gain */
879 if ( // not recording
881 !(record_enabled() && _session.actively_recording()) ||
885 // AND software monitoring required
887 Config->get_monitoring_model() == SoftwareMonitoring) {
889 if (apply_gain_automation) {
892 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
893 Sample* const sp = i->data();
895 for (nframes_t nx = 0; nx < nframes; ++nx) {
900 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
901 Sample* const sp = i->data();
903 for (nframes_t nx = 0; nx < nframes; ++nx) {
909 if (apply_gain_automation && _session.transport_rolling() && nframes > 0) {
910 _effective_gain = gab[nframes-1];
915 /* manual (scalar) gain */
919 Amp::run_in_place (bufs, nframes, _gain, dg, _phase_invert);
922 } else if (_gain != 0 && (_phase_invert || _gain != 1.0)) {
924 /* no need to interpolate current gain value,
925 but its non-unity, so apply it. if the gain
926 is zero, do nothing because we'll ship silence
938 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
939 Sample* const sp = i->data();
940 apply_gain_to_buffer(sp,nframes,this_gain);
943 } else if (_gain == 0) {
944 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
952 /* actively recording, no monitoring required; leave buffers as-is to save CPU cycles */
957 /* ----------------------------------------------------------------------------------------------------
959 -------------------------------------------------------------------------------------------------- */
961 if ((_meter_point == MeterPostFader) && co) {
963 solo_audible = solo_gain > 0;
964 mute_audible = dmg > 0 || !_mute_affects_control_outs;
966 if ( // silent anyway
968 (_gain == 0 && !apply_gain_automation) ||
970 // muted by solo of another track
974 // muted by mute of this track
978 // recording but not s/w monitoring
980 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
984 co->silence (nframes, offset);
988 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
992 /* ----------------------------------------------------------------------------------------------------
994 -------------------------------------------------------------------------------------------------- */
996 solo_audible = dsg > 0;
997 mute_audible = dmg > 0 || !_mute_affects_main_outs;
999 if (n_outputs().get(_default_type) == 0) {
1003 } else if (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording())) {
1005 IO::silence (nframes, offset);
1009 if ( // silent anyway
1011 (_gain == 0 && !apply_gain_automation) ||
1013 // muted by solo of another track, but not using control outs for solo
1015 (!solo_audible && (Config->get_solo_model() != SoloBus)) ||
1017 // muted by mute of this track
1023 /* don't use Route::silence() here, because that causes
1024 all outputs (sends, port processors, etc. to be silent).
1027 if (_meter_point == MeterPostFader) {
1028 peak_meter().reset();
1031 IO::silence (nframes, offset);
1035 deliver_output(bufs, start_frame, end_frame, nframes, offset);
1042 #endif /* NEW_POB */
1045 Route::n_process_buffers ()
1047 return max (n_inputs(), processor_max_outs);
1051 Route::passthru (nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset, int declick, bool meter_first)
1053 BufferSet& bufs = _session.get_scratch_buffers(n_process_buffers());
1057 collect_input (bufs, nframes, offset);
1060 _meter->run_in_place(bufs, start_frame, end_frame, nframes, offset);
1061 meter_first = false;
1066 process_output_buffers (bufs, start_frame, end_frame, nframes, offset, true, declick, meter_first);
1070 Route::passthru_silence (nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset, int declick, bool meter)
1072 process_output_buffers (_session.get_silent_buffers (n_process_buffers()), start_frame, end_frame, nframes, offset, true, declick, meter);
1076 Route::set_solo (bool yn, void *src)
1082 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
1083 _mix_group->apply (&Route::set_solo, yn, _mix_group);
1087 if (_soloed != yn) {
1089 solo_changed (src); /* EMIT SIGNAL */
1090 _solo_control->Changed (); /* EMIT SIGNAL */
1093 catch_up_on_solo_mute_override ();
1097 Route::catch_up_on_solo_mute_override ()
1099 if (Config->get_solo_model() != InverseMute) {
1105 Glib::Mutex::Lock lm (declick_lock);
1108 if (Config->get_solo_mute_override()) {
1109 desired_mute_gain = (_soloed?1.0:0.0);
1111 desired_mute_gain = 0.0;
1114 desired_mute_gain = 1.0;
1120 Route::set_solo_mute (bool yn)
1122 Glib::Mutex::Lock lm (declick_lock);
1124 /* Called by Session in response to another Route being soloed.
1127 desired_solo_gain = (yn?0.0:1.0);
1131 Route::set_solo_safe (bool yn, void *src)
1133 if (_solo_safe != yn) {
1135 solo_safe_changed (src); /* EMIT SIGNAL */
1140 Route::set_mute (bool yn, void *src)
1143 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
1144 _mix_group->apply (&Route::set_mute, yn, _mix_group);
1150 mute_changed (src); /* EMIT SIGNAL */
1152 _mute_control->Changed (); /* EMIT SIGNAL */
1154 Glib::Mutex::Lock lm (declick_lock);
1156 if (_soloed && Config->get_solo_mute_override()){
1157 desired_mute_gain = 1.0f;
1159 desired_mute_gain = (yn?0.0f:1.0f);
1165 Route::add_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err)
1167 ChanCount old_pmo = processor_max_outs;
1169 if (!_session.engine().connected()) {
1174 Glib::RWLock::WriterLock lm (_processor_lock);
1176 boost::shared_ptr<PluginInsert> pi;
1177 boost::shared_ptr<PortInsert> porti;
1179 //processor->set_default_type(_default_type);
1181 _processors.push_back (processor);
1183 // Set up processor list channels. This will set processor->[input|output]_streams(),
1184 // configure redirect ports properly, etc.
1185 if (_reset_processor_counts (err)) {
1186 _processors.pop_back ();
1187 _reset_processor_counts (0); // it worked before we tried to add it ...
1191 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
1193 if (pi->natural_input_streams() == ChanCount::ZERO) {
1194 /* generator plugin */
1195 _have_internal_generator = true;
1200 // Ensure peak vector sizes before the plugin is activated
1202 ChanCount potential_max_streams;
1204 potential_max_streams.set (DataType::AUDIO, max (processor->input_streams().n_audio(),
1205 processor->output_streams().n_audio()));
1206 potential_max_streams.set (DataType::MIDI, max (processor->input_streams().n_midi(),
1207 processor->output_streams().n_midi()));
1209 _meter->configure_io (potential_max_streams, potential_max_streams);
1211 // XXX: do we want to emit the signal here ? change call order.
1212 processor->activate ();
1213 processor->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
1218 if (processor_max_outs != old_pmo || old_pmo == ChanCount::ZERO) {
1222 processors_changed (); /* EMIT SIGNAL */
1228 Route::add_processors (const ProcessorList& others, ProcessorStreams* err)
1230 ChanCount old_pmo = processor_max_outs;
1232 if (!_session.engine().connected()) {
1237 Glib::RWLock::WriterLock lm (_processor_lock);
1239 ProcessorList::iterator existing_end = _processors.end();
1242 ChanCount potential_max_streams;
1244 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
1246 boost::shared_ptr<PluginInsert> pi;
1248 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1251 ChanCount m = max(pi->input_streams(), pi->output_streams());
1252 if (m > potential_max_streams)
1253 potential_max_streams = m;
1256 // Ensure peak vector sizes before the plugin is activated
1257 _meter->configure_io (potential_max_streams, potential_max_streams);
1259 _processors.push_back (*i);
1261 if (_reset_processor_counts (err)) {
1263 _processors.erase (existing_end, _processors.end());
1264 _reset_processor_counts (0); // it worked before we tried to add it ...
1268 (*i)->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
1274 if (processor_max_outs != old_pmo || old_pmo == ChanCount::ZERO) {
1278 processors_changed (); /* EMIT SIGNAL */
1282 /** Turn off all processors with a given placement
1283 * @param p Placement of processors to disable
1287 Route::disable_processors (Placement p)
1289 Glib::RWLock::ReaderLock lm (_processor_lock);
1291 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1292 if ((*i)->placement() == p) {
1293 (*i)->set_active (false);
1297 _session.set_dirty ();
1300 /** Turn off all redirects
1304 Route::disable_processors ()
1306 Glib::RWLock::ReaderLock lm (_processor_lock);
1308 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1309 (*i)->set_active (false);
1312 _session.set_dirty ();
1315 /** Turn off all redirects with a given placement
1316 * @param p Placement of redirects to disable
1320 Route::disable_plugins (Placement p)
1322 Glib::RWLock::ReaderLock lm (_processor_lock);
1324 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1325 if (boost::dynamic_pointer_cast<PluginInsert> (*i) && (*i)->placement() == p) {
1326 (*i)->set_active (false);
1330 _session.set_dirty ();
1333 /** Turn off all plugins
1337 Route::disable_plugins ()
1339 Glib::RWLock::ReaderLock lm (_processor_lock);
1341 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1342 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1343 (*i)->set_active (false);
1347 _session.set_dirty ();
1352 Route::ab_plugins (bool forward)
1354 Glib::RWLock::ReaderLock lm (_processor_lock);
1358 /* forward = turn off all active redirects, and mark them so that the next time
1359 we go the other way, we will revert them
1362 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1363 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1367 if ((*i)->active()) {
1368 (*i)->set_active (false);
1369 (*i)->set_next_ab_is_active (true);
1371 (*i)->set_next_ab_is_active (false);
1377 /* backward = if the redirect was marked to go active on the next ab, do so */
1379 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1381 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
1385 if ((*i)->get_next_ab_is_active()) {
1386 (*i)->set_active (true);
1388 (*i)->set_active (false);
1393 _session.set_dirty ();
1397 /* Figure out the streams that will feed into PreFader */
1399 Route::pre_fader_streams() const
1401 boost::shared_ptr<Processor> processor;
1403 // Find the last pre-fader redirect
1404 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1405 if ((*i)->placement() == PreFader) {
1411 return processor->output_streams();
1418 /** Remove processors with a given placement.
1419 * @param p Placement of processors to remove.
1422 Route::clear_processors (Placement p)
1424 const ChanCount old_pmo = processor_max_outs;
1426 if (!_session.engine().connected()) {
1431 Glib::RWLock::WriterLock lm (_processor_lock);
1432 ProcessorList new_list;
1434 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1435 if ((*i)->placement() == p) {
1436 /* it's the placement we want to get rid of */
1437 (*i)->drop_references ();
1439 /* it's a different placement, so keep it */
1440 new_list.push_back (*i);
1444 _processors = new_list;
1447 /* FIXME: can't see how this test can ever fire */
1448 if (processor_max_outs != old_pmo) {
1452 processor_max_outs.reset();
1453 _have_internal_generator = false;
1454 processors_changed (); /* EMIT SIGNAL */
1458 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err)
1460 ChanCount old_pmo = processor_max_outs;
1462 if (!_session.engine().connected()) {
1466 processor_max_outs.reset();
1469 Glib::RWLock::WriterLock lm (_processor_lock);
1470 ProcessorList::iterator i;
1471 bool removed = false;
1473 for (i = _processors.begin(); i != _processors.end(); ++i) {
1474 if (*i == processor) {
1476 ProcessorList::iterator tmp;
1478 /* move along, see failure case for reset_processor_counts()
1479 where we may need to reprocessor the processor.
1485 /* stop redirects that send signals to JACK ports
1486 from causing noise as a result of no longer being
1490 boost::shared_ptr<IOProcessor> redirect;
1492 if ((redirect = boost::dynamic_pointer_cast<IOProcessor> (*i)) != 0) {
1493 redirect->io()->disconnect_inputs (this);
1494 redirect->io()->disconnect_outputs (this);
1497 _processors.erase (i);
1512 if (_reset_processor_counts (err)) {
1513 /* get back to where we where */
1514 _processors.insert (i, processor);
1515 /* we know this will work, because it worked before :) */
1516 _reset_processor_counts (0);
1520 _have_internal_generator = false;
1522 for (i = _processors.begin(); i != _processors.end(); ++i) {
1523 boost::shared_ptr<PluginInsert> pi;
1525 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1526 if (pi->is_generator()) {
1527 _have_internal_generator = true;
1534 if (old_pmo != processor_max_outs) {
1538 processor->drop_references ();
1540 processors_changed (); /* EMIT SIGNAL */
1545 Route::reset_processor_counts (ProcessorStreams* err)
1547 Glib::RWLock::WriterLock lm (_processor_lock);
1548 return _reset_processor_counts (err);
1553 Route::_reset_processor_counts (ProcessorStreams* err)
1555 ProcessorList::iterator r;
1556 uint32_t insert_cnt = 0;
1557 uint32_t send_cnt = 0;
1558 map<Placement,list<ProcessorCount> > proc_map;
1559 ProcessorList::iterator prev;
1560 ChanCount initial_streams = n_inputs ();
1561 ChanCount previous_initial_streams = n_inputs ();
1563 uint32_t max_audio = 0;
1564 uint32_t max_midi = 0;
1566 processor_max_outs.reset ();
1568 /* Step 1: build a map that links each insert to an in/out channel count
1570 Divide inserts up by placement so we get the signal flow
1571 properly modelled. we need to do this because the _processors
1572 list is not sorted by placement, and because other reasons may
1573 exist now or in the future for this separate treatment.
1576 /* ... but it should/will be... */
1578 for (r = _processors.begin(); r != _processors.end(); ++r) {
1580 boost::shared_ptr<PluginInsert> plugin_insert;
1581 boost::shared_ptr<PortInsert> port_insert;
1583 if ((plugin_insert = boost::dynamic_pointer_cast<PluginInsert>(*r)) != 0) {
1586 proc_map[(*r)->placement()].push_back (ProcessorCount (*r));
1588 /* reset plugin counts back to one for now so
1589 that we have a predictable, controlled
1590 state to try to configure.
1593 plugin_insert->set_count (1);
1595 } else if ((port_insert = boost::dynamic_pointer_cast<PortInsert>(*r)) != 0) {
1598 proc_map[(*r)->placement()].push_back (ProcessorCount (*r));
1600 } else if (boost::dynamic_pointer_cast<Send> (*r) != 0) {
1605 if (insert_cnt == 0) {
1614 /* Now process each placement in order, checking to see if we
1615 can really do what has been requested.
1620 if (check_some_processor_counts (proc_map[PreFader], n_inputs (), err)) {
1624 if (!proc_map[PreFader].empty()) {
1625 previous_initial_streams = n_inputs ();
1626 for (list<ProcessorCount>::iterator i = proc_map[PreFader].begin(); i != proc_map[PreFader].end(); i++) {
1627 if (i->processor->can_support_io_configuration (previous_initial_streams, initial_streams) < 0) {
1630 previous_initial_streams = initial_streams;
1636 if (check_some_processor_counts (proc_map[PostFader], initial_streams, err)) {
1640 if (!proc_map[PostFader].empty()) {
1641 for (list<ProcessorCount>::iterator i = proc_map[PostFader].begin(); i != proc_map[PostFader].end(); i++) {
1642 if (i->processor->can_support_io_configuration (previous_initial_streams, initial_streams) < 0) {
1645 previous_initial_streams = initial_streams;
1649 /* OK, everything can be set up correctly, so lets do it */
1651 apply_some_processor_counts (proc_map[PreFader]);
1652 apply_some_processor_counts (proc_map[PostFader]);
1654 /* recompute max outs of any processor */
1660 processor_max_outs.reset ();
1661 prev = _processors.end();
1663 for (r = _processors.begin(); r != _processors.end(); prev = r, ++r) {
1664 boost::shared_ptr<Send> s;
1666 if ((s = boost::dynamic_pointer_cast<Send> (*r)) != 0) {
1667 if (r == _processors.begin()) {
1668 s->expect_inputs (n_inputs());
1670 s->expect_inputs ((*prev)->output_streams());
1675 /* don't pay any attention to send output configuration, since it doesn't
1679 max_audio = max ((*r)->output_streams ().n_audio(), max_audio);
1680 max_midi = max ((*r)->output_streams ().n_midi(), max_midi);
1684 processor_max_outs.set (DataType::AUDIO, max_audio);
1685 processor_max_outs.set (DataType::MIDI, max_midi);
1691 for (r = _processors.begin(); r != _processors.end(); ++r) {
1692 max_audio = max ((*r)->output_streams ().n_audio(), max_audio);
1693 max_midi = max ((*r)->output_streams ().n_midi(), max_midi);
1696 processor_max_outs.set (DataType::AUDIO, max_audio);
1697 processor_max_outs.set (DataType::MIDI, max_midi);
1703 Route::apply_some_processor_counts (list<ProcessorCount>& iclist)
1705 list<ProcessorCount>::iterator i;
1707 for (i = iclist.begin(); i != iclist.end(); ++i) {
1709 ProcessorCount& pc (*i);
1711 cerr << "now applying for " << (*i).processor->name() << " in = " << pc.in.n_audio() << " out = " << pc.out.n_audio() << endl;
1713 if (pc.processor->configure_io (pc.in, pc.out)) {
1717 /* make sure that however many we have, they are all active */
1719 pc.processor->activate ();
1725 /** Returns whether \a iclist can be configured and run starting with
1726 * \a required_inputs at the first processor's inputs.
1727 * If false is returned, \a iclist can not be run with \a required_inputs, and \a err is set.
1728 * Otherwise, \a err is set to the output of the list.
1731 Route::check_some_processor_counts (list<ProcessorCount>& iclist, ChanCount required_inputs, ProcessorStreams* err)
1733 list<ProcessorCount>::iterator i;
1738 err->count = required_inputs;
1741 for (i = iclist.begin(); i != iclist.end(); ++i, ++index) {
1743 cerr << "Checking whether " << (*i).processor->name() << " can support " << required_inputs.n_audio() << " inputs\n";
1745 if (!(*i).processor->can_support_io_configuration (required_inputs, (*i).out)) {
1748 err->count = required_inputs;
1753 (*i).in = required_inputs;
1754 required_inputs = (*i).out;
1761 Route::copy_processors (const Route& other, Placement placement, ProcessorStreams* err)
1763 ChanCount old_pmo = processor_max_outs;
1765 ProcessorList to_be_deleted;
1768 Glib::RWLock::WriterLock lm (_processor_lock);
1769 ProcessorList::iterator tmp;
1770 ProcessorList the_copy;
1772 the_copy = _processors;
1774 /* remove all relevant processors */
1776 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ) {
1780 if ((*i)->placement() == placement) {
1781 to_be_deleted.push_back (*i);
1782 _processors.erase (i);
1788 /* now copy the relevant ones from "other" */
1790 for (ProcessorList::const_iterator i = other._processors.begin(); i != other._processors.end(); ++i) {
1791 if ((*i)->placement() == placement) {
1792 _processors.push_back (IOProcessor::clone (*i));
1796 /* reset plugin stream handling */
1798 if (_reset_processor_counts (err)) {
1800 /* FAILED COPY ATTEMPT: we have to restore order */
1802 /* delete all cloned processors */
1804 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ) {
1809 if ((*i)->placement() == placement) {
1810 _processors.erase (i);
1816 /* restore the natural order */
1818 _processors = the_copy;
1819 processor_max_outs = old_pmo;
1821 /* we failed, even though things are OK again */
1827 /* SUCCESSFUL COPY ATTEMPT: delete the processors we removed pre-copy */
1828 to_be_deleted.clear ();
1833 if (processor_max_outs != old_pmo || old_pmo == ChanCount::ZERO) {
1837 processors_changed (); /* EMIT SIGNAL */
1842 Route::all_processors_flip ()
1844 Glib::RWLock::ReaderLock lm (_processor_lock);
1846 if (_processors.empty()) {
1850 bool first_is_on = _processors.front()->active();
1852 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1853 (*i)->set_active (!first_is_on);
1856 _session.set_dirty ();
1859 /** Set all processors with a given placement to a given active state.
1860 * @param p Placement of processors to change.
1861 * @param state New active state for those processors.
1864 Route::all_processors_active (Placement p, bool state)
1866 Glib::RWLock::ReaderLock lm (_processor_lock);
1868 if (_processors.empty()) {
1872 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1873 if ((*i)->placement() == p) {
1874 (*i)->set_active (state);
1878 _session.set_dirty ();
1881 struct ProcessorSorter {
1882 bool operator() (boost::shared_ptr<const Processor> a, boost::shared_ptr<const Processor> b) {
1883 return a->sort_key() < b->sort_key();
1888 Route::sort_processors (ProcessorStreams* err)
1891 ProcessorSorter comparator;
1892 Glib::RWLock::WriterLock lm (_processor_lock);
1893 ChanCount old_pmo = processor_max_outs;
1895 /* the sweet power of C++ ... */
1897 ProcessorList as_it_was_before = _processors;
1899 _processors.sort (comparator);
1901 if (_reset_processor_counts (err)) {
1902 _processors = as_it_was_before;
1903 processor_max_outs = old_pmo;
1909 processors_changed (); /* EMIT SIGNAL */
1921 Route::get_template()
1923 return state(false);
1927 Route::state(bool full_state)
1929 XMLNode *node = new XMLNode("Route");
1930 ProcessorList::iterator i;
1934 node->add_property("flags", enum_2_string (_flags));
1937 node->add_property("default-type", _default_type.to_string());
1939 node->add_property("active", _active?"yes":"no");
1940 node->add_property("muted", _muted?"yes":"no");
1941 node->add_property("soloed", _soloed?"yes":"no");
1942 node->add_property("phase-invert", _phase_invert?"yes":"no");
1943 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
1944 node->add_property("mute-affects-pre-fader", _mute_affects_pre_fader?"yes":"no");
1945 node->add_property("mute-affects-post-fader", _mute_affects_post_fader?"yes":"no");
1946 node->add_property("mute-affects-control-outs", _mute_affects_control_outs?"yes":"no");
1947 node->add_property("mute-affects-main-outs", _mute_affects_main_outs?"yes":"no");
1950 node->add_property("edit-group", _edit_group->name());
1953 node->add_property("mix-group", _mix_group->name());
1956 string order_string;
1957 OrderKeys::iterator x = order_keys.begin();
1959 while (x != order_keys.end()) {
1960 order_string += string ((*x).first);
1961 order_string += '=';
1962 snprintf (buf, sizeof(buf), "%ld", (*x).second);
1963 order_string += buf;
1967 if (x == order_keys.end()) {
1971 order_string += ':';
1973 node->add_property ("order-keys", order_string);
1975 node->add_child_nocopy (IO::state (full_state));
1976 node->add_child_nocopy (_solo_control->get_state ());
1977 node->add_child_nocopy (_mute_control->get_state ());
1979 XMLNode* remote_control_node = new XMLNode (X_("remote_control"));
1980 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
1981 remote_control_node->add_property (X_("id"), buf);
1982 node->add_child_nocopy (*remote_control_node);
1984 if (_control_outs) {
1985 XMLNode* cnode = new XMLNode (X_("ControlOuts"));
1986 cnode->add_child_nocopy (_control_outs->state (full_state));
1987 node->add_child_nocopy (*cnode);
1990 if (_comment.length()) {
1991 XMLNode *cmt = node->add_child ("Comment");
1992 cmt->add_content (_comment);
1995 for (i = _processors.begin(); i != _processors.end(); ++i) {
1996 node->add_child_nocopy((*i)->state (full_state));
2000 node->add_child_copy (*_extra_xml);
2007 Route::get_processor_state ()
2009 XMLNode* root = new XMLNode (X_("redirects"));
2010 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2011 root->add_child_nocopy ((*i)->state (true));
2018 Route::set_processor_state (const XMLNode& root)
2020 if (root.name() != X_("redirects")) {
2026 XMLNodeConstIterator iter;
2027 XMLNodeConstIterator niter;
2028 Glib::RWLock::ReaderLock lm (_processor_lock);
2030 nlist = root.children();
2032 for (iter = nlist.begin(); iter != nlist.end(); ++iter){
2034 /* iter now points to a IOProcessor state node */
2036 nnlist = (*iter)->children ();
2038 for (niter = nnlist.begin(); niter != nnlist.end(); ++niter) {
2040 /* find the IO child node, since it contains the ID we need */
2042 /* XXX OOP encapsulation violation, ugh */
2044 if ((*niter)->name() == IO::state_node_name) {
2046 XMLProperty* prop = (*niter)->property (X_("id"));
2049 warning << _("IOProcessor node has no ID, ignored") << endmsg;
2053 ID id = prop->value ();
2055 /* now look for a processor with that ID */
2057 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2058 if ((*i)->id() == id) {
2059 (*i)->set_state (**iter);
2075 Route::set_deferred_state ()
2078 XMLNodeConstIterator niter;
2080 if (!deferred_state) {
2084 nlist = deferred_state->children();
2086 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
2087 add_processor_from_xml (**niter);
2090 delete deferred_state;
2095 Route::add_processor_from_xml (const XMLNode& node)
2097 const XMLProperty *prop;
2099 // legacy sessions use a different node name for sends
2100 if (node.name() == "Send") {
2103 boost::shared_ptr<Send> send (new Send (_session, node));
2104 add_processor (send);
2107 catch (failed_constructor &err) {
2108 error << _("Send construction failed") << endmsg;
2112 // use "Processor" in XML?
2113 } else if (node.name() == "Processor") {
2116 if ((prop = node.property ("type")) != 0) {
2118 boost::shared_ptr<Processor> processor;
2119 bool have_insert = false;
2121 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
2122 prop->value() == "lv2" ||
2123 prop->value() == "vst" ||
2124 prop->value() == "audiounit") {
2126 processor.reset (new PluginInsert(_session, node));
2129 } else if (prop->value() == "port") {
2131 processor.reset (new PortInsert (_session, node));
2133 } else if (prop->value() == "send") {
2135 processor.reset (new Send (_session, node));
2140 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
2143 add_processor (processor);
2146 error << _("Processor XML node has no type property") << endmsg;
2150 catch (failed_constructor &err) {
2151 warning << _("processor could not be created. Ignored.") << endmsg;
2158 Route::set_state (const XMLNode& node)
2160 return _set_state (node, true);
2164 Route::_set_state (const XMLNode& node, bool call_base)
2167 XMLNodeConstIterator niter;
2169 XMLPropertyList plist;
2170 const XMLProperty *prop;
2172 if (node.name() != "Route"){
2173 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
2177 if ((prop = node.property (X_("flags"))) != 0) {
2178 _flags = Flag (string_2_enum (prop->value(), _flags));
2183 if ((prop = node.property (X_("default-type"))) != 0) {
2184 _default_type = DataType(prop->value());
2185 assert(_default_type != DataType::NIL);
2188 if ((prop = node.property (X_("phase-invert"))) != 0) {
2189 set_phase_invert (prop->value()=="yes"?true:false, this);
2192 if ((prop = node.property (X_("denormal-protection"))) != 0) {
2193 set_denormal_protection (prop->value()=="yes"?true:false, this);
2197 if ((prop = node.property (X_("active"))) != 0) {
2198 set_active (prop->value() == "yes");
2201 if ((prop = node.property (X_("muted"))) != 0) {
2202 bool yn = prop->value()=="yes"?true:false;
2204 /* force reset of mute status */
2208 mute_gain = desired_mute_gain;
2211 if ((prop = node.property (X_("soloed"))) != 0) {
2212 bool yn = prop->value()=="yes"?true:false;
2214 /* force reset of solo status */
2217 set_solo (yn, this);
2218 solo_gain = desired_solo_gain;
2221 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
2222 _mute_affects_pre_fader = (prop->value()=="yes")?true:false;
2225 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
2226 _mute_affects_post_fader = (prop->value()=="yes")?true:false;
2229 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
2230 _mute_affects_control_outs = (prop->value()=="yes")?true:false;
2233 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
2234 _mute_affects_main_outs = (prop->value()=="yes")?true:false;
2237 if ((prop = node.property (X_("edit-group"))) != 0) {
2238 RouteGroup* edit_group = _session.edit_group_by_name(prop->value());
2239 if(edit_group == 0) {
2240 error << string_compose(_("Route %1: unknown edit group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
2242 set_edit_group(edit_group, this);
2246 if ((prop = node.property (X_("order-keys"))) != 0) {
2250 string::size_type colon, equal;
2251 string remaining = prop->value();
2253 while (remaining.length()) {
2255 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
2256 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2259 if (sscanf (remaining.substr (equal+1).c_str(), "%ld", &n) != 1) {
2260 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
2263 set_order_key (remaining.substr (0, equal).c_str(), n);
2267 colon = remaining.find_first_of (':');
2269 if (colon != string::npos) {
2270 remaining = remaining.substr (colon+1);
2277 nlist = node.children();
2279 if (deferred_state) {
2280 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 _control_outs = new IO (_session, coutname);
2329 _control_outs->set_state (**(child->children().begin()));
2331 } else if (child->name() == X_("Comment")) {
2333 /* XXX this is a terrible API design in libxml++ */
2335 XMLNode *cmt = *(child->children().begin());
2336 _comment = cmt->content();
2338 } else if (child->name() == X_("extra")) {
2340 _extra_xml = new XMLNode (*child);
2342 } else if (child->name() == X_("controllable") && (prop = child->property("name")) != 0) {
2344 if (prop->value() == "solo") {
2345 _solo_control->set_state (*child);
2346 _session.add_controllable (_solo_control);
2348 else if (prop->value() == "mute") {
2349 _mute_control->set_state (*child);
2350 _session.add_controllable (_mute_control);
2353 else if (child->name() == X_("remote_control")) {
2354 if ((prop = child->property (X_("id"))) != 0) {
2356 sscanf (prop->value().c_str(), "%d", &x);
2357 set_remote_control_id (x);
2362 if ((prop = node.property (X_("mix-group"))) != 0) {
2363 RouteGroup* mix_group = _session.mix_group_by_name(prop->value());
2364 if (mix_group == 0) {
2365 error << string_compose(_("Route %1: unknown mix group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
2367 set_mix_group(mix_group, this);
2375 Route::_set_processor_states(const XMLNodeList &nlist)
2377 XMLNodeConstIterator niter;
2380 ProcessorList::iterator i, o;
2382 // Iterate through existing processors, remove those which are not in the state list
2383 for (i = _processors.begin(); i != _processors.end(); ) {
2384 ProcessorList::iterator tmp = i;
2387 bool processorInStateList = false;
2389 (*i)->id().print (buf, sizeof (buf));
2392 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
2394 // legacy sessions (IOProcessor as a child of Processor, both is-a IO)
2395 if (strncmp(buf,(*niter)->child(X_("IOProcessor"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf)) == 0) {
2396 processorInStateList = true;
2398 } else if (strncmp(buf,(*niter)->property(X_("id"))->value().c_str(), sizeof(buf)) == 0) {
2399 processorInStateList = true;
2404 if (!processorInStateList) {
2405 remove_processor (*i);
2413 // Iterate through state list and make sure all processors are on the track and in the correct order,
2414 // set the state of existing processors according to the new state on the same go
2415 i = _processors.begin();
2416 for (niter = nlist.begin(); niter != nlist.end(); ++niter, ++i) {
2418 // Check whether the next processor in the list
2421 while (o != _processors.end()) {
2422 (*o)->id().print (buf, sizeof (buf));
2423 if ( strncmp(buf, (*niter)->child(X_("IOProcessor"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf)) == 0)
2425 else if (strncmp(buf,(*niter)->property(X_("id"))->value().c_str(), sizeof(buf)) == 0)
2431 if (o == _processors.end()) {
2432 // If the processor (*niter) is not on the route, we need to create it
2433 // and move it to the correct location
2435 ProcessorList::iterator prev_last = _processors.end();
2436 --prev_last; // We need this to check whether adding succeeded
2438 add_processor_from_xml (**niter);
2440 ProcessorList::iterator last = _processors.end();
2443 if (prev_last == last) {
2444 cerr << "Could not fully restore state as some processors were not possible to create" << endl;
2449 boost::shared_ptr<Processor> tmp = (*last);
2450 // remove the processor from the wrong location
2451 _processors.erase(last);
2452 // processor the new processor at the current location
2453 _processors.insert(i, tmp);
2455 --i; // move pointer to the newly processored processor
2459 // We found the processor (*niter) on the route, first we must make sure the processor
2460 // is at the location provided in the XML state
2462 boost::shared_ptr<Processor> tmp = (*o);
2463 // remove the old copy
2464 _processors.erase(o);
2465 // processor the processor at the correct location
2466 _processors.insert(i, tmp);
2468 --i; // move pointer so it points to the right processor
2471 (*i)->set_state( (**niter) );
2474 processors_changed ();
2478 Route::curve_reallocate ()
2480 // _gain_automation_curve.finish_resize ();
2481 // _pan_automation_curve.finish_resize ();
2485 Route::silence (nframes_t nframes, nframes_t offset)
2489 IO::silence (nframes, offset);
2491 if (_control_outs) {
2492 _control_outs->silence (nframes, offset);
2496 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2499 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2500 boost::shared_ptr<PluginInsert> pi;
2501 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2502 // skip plugins, they don't need anything when we're not active
2506 (*i)->silence (nframes, offset);
2509 if (nframes == _session.get_block_size() && offset == 0) {
2519 Route::set_control_outs (const vector<string>& ports)
2521 Glib::Mutex::Lock lm (_control_outs_lock);
2522 vector<string>::const_iterator i;
2525 if (_control_outs) {
2526 delete _control_outs;
2530 if (is_control() || is_master()) {
2531 /* no control outs for these two special busses */
2535 if (ports.empty()) {
2539 string coutname = _name;
2540 coutname += _("[control]");
2542 _control_outs = new IO (_session, coutname);
2544 /* our control outs need as many outputs as we
2545 have audio outputs. we track the changes in ::output_change_handler().
2548 // XXX its stupid that we have to get this value twice
2550 limit = n_outputs().n_audio();
2552 if (_control_outs->ensure_io (ChanCount::ZERO, ChanCount (DataType::AUDIO, n_outputs().get (DataType::AUDIO)), true, this)) {
2556 /* now connect to the named ports */
2558 for (size_t n = 0; n < limit; ++n) {
2559 if (_control_outs->connect_output (_control_outs->output (n), ports[n % ports.size()], this)) {
2560 error << string_compose (_("could not connect %1 to %2"), _control_outs->output(n)->name(), ports[n]) << endmsg;
2569 Route::set_edit_group (RouteGroup *eg, void *src)
2572 if (eg == _edit_group) {
2577 _edit_group->remove (this);
2580 if ((_edit_group = eg) != 0) {
2581 _edit_group->add (this);
2584 _session.set_dirty ();
2585 edit_group_changed (src); /* EMIT SIGNAL */
2589 Route::drop_edit_group (void *src)
2592 _session.set_dirty ();
2593 edit_group_changed (src); /* EMIT SIGNAL */
2597 Route::set_mix_group (RouteGroup *mg, void *src)
2600 if (mg == _mix_group) {
2605 _mix_group->remove (this);
2608 if ((_mix_group = mg) != 0) {
2609 _mix_group->add (this);
2612 _session.set_dirty ();
2613 mix_group_changed (src); /* EMIT SIGNAL */
2617 Route::drop_mix_group (void *src)
2620 _session.set_dirty ();
2621 mix_group_changed (src); /* EMIT SIGNAL */
2625 Route::set_comment (string cmt, void *src)
2628 comment_changed (src);
2629 _session.set_dirty ();
2633 Route::feeds (boost::shared_ptr<Route> other)
2638 uint32_t no = self.n_outputs().n_total();
2639 uint32_t ni = other->n_inputs ().n_total();
2641 for (i = 0; i < no; ++i) {
2642 for (j = 0; j < ni; ++j) {
2643 if (self.output(i)->connected_to (other->input(j)->name())) {
2649 /* check IOProcessors which may also interconnect Routes */
2651 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); r++) {
2653 boost::shared_ptr<IOProcessor> redirect = boost::dynamic_pointer_cast<IOProcessor>(*r);
2658 // TODO: support internal redirects here
2660 no = redirect->io()->n_outputs().n_total();
2662 for (i = 0; i < no; ++i) {
2663 for (j = 0; j < ni; ++j) {
2664 if (redirect->io()->output(i)->connected_to (other->input (j)->name())) {
2671 /* check for control room outputs which may also interconnect Routes */
2673 if (_control_outs) {
2675 no = _control_outs->n_outputs().n_total();
2677 for (i = 0; i < no; ++i) {
2678 for (j = 0; j < ni; ++j) {
2679 if (_control_outs->output(i)->connected_to (other->input (j)->name())) {
2690 Route::set_mute_config (mute_type t, bool onoff, void *src)
2694 _mute_affects_pre_fader = onoff;
2695 pre_fader_changed(src); /* EMIT SIGNAL */
2699 _mute_affects_post_fader = onoff;
2700 post_fader_changed(src); /* EMIT SIGNAL */
2704 _mute_affects_control_outs = onoff;
2705 control_outs_changed(src); /* EMIT SIGNAL */
2709 _mute_affects_main_outs = onoff;
2710 main_outs_changed(src); /* EMIT SIGNAL */
2716 Route::get_mute_config (mute_type t)
2722 onoff = _mute_affects_pre_fader;
2725 onoff = _mute_affects_post_fader;
2728 onoff = _mute_affects_control_outs;
2731 onoff = _mute_affects_main_outs;
2739 Route::handle_transport_stopped (bool abort_ignored, bool did_locate, bool can_flush_processors)
2741 nframes_t now = _session.transport_frame();
2744 Glib::RWLock::ReaderLock lm (_processor_lock);
2747 automation_snapshot (now, true);
2750 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2752 if (Config->get_plugins_stop_with_transport() && can_flush_processors) {
2753 (*i)->deactivate ();
2757 (*i)->transport_stopped (now);
2761 IO::transport_stopped (now);
2763 _roll_delay = _initial_delay;
2767 Route::input_change_handler (IOChange change, void *ignored)
2769 if (change & ConfigurationChanged) {
2770 reset_processor_counts (0);
2775 Route::output_change_handler (IOChange change, void *ignored)
2777 if (change & ConfigurationChanged) {
2778 if (_control_outs) {
2779 _control_outs->ensure_io (ChanCount::ZERO, ChanCount(DataType::AUDIO, n_outputs().n_audio()), true, this);
2782 reset_processor_counts (0);
2787 Route::pans_required () const
2789 if (n_outputs().n_audio() < 2) {
2793 return max (n_inputs ().n_audio(), processor_max_outs.n_audio());
2797 Route::no_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
2798 bool session_state_changing, bool can_record, bool rec_monitors_input)
2800 if (n_outputs().n_total() == 0) {
2804 if (session_state_changing || !_active) {
2805 silence (nframes, offset);
2809 apply_gain_automation = false;
2811 if (n_inputs().n_total()) {
2812 passthru (start_frame, end_frame, nframes, offset, 0, false);
2814 silence (nframes, offset);
2821 Route::check_initial_delay (nframes_t nframes, nframes_t& offset, nframes_t& transport_frame)
2823 if (_roll_delay > nframes) {
2825 _roll_delay -= nframes;
2826 silence (nframes, offset);
2827 /* transport frame is not legal for caller to use */
2830 } else if (_roll_delay > 0) {
2832 nframes -= _roll_delay;
2834 silence (_roll_delay, offset);
2836 offset += _roll_delay;
2837 transport_frame += _roll_delay;
2846 Route::roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset, int declick,
2847 bool can_record, bool rec_monitors_input)
2850 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2852 // automation snapshot can also be called from the non-rt context
2853 // and it uses the processor list, so we take the lock out here
2854 automation_snapshot (_session.transport_frame(), false);
2858 if ((n_outputs().n_total() == 0 && _processors.empty()) || n_inputs().n_total() == 0 || !_active) {
2859 silence (nframes, offset);
2863 nframes_t unused = 0;
2865 if ((nframes = check_initial_delay (nframes, offset, unused)) == 0) {
2871 apply_gain_automation = false;
2874 Glib::Mutex::Lock am (data().control_lock(), Glib::TRY_LOCK);
2876 if (am.locked() && _session.transport_rolling()) {
2878 if (_gain_control->automation_playback()) {
2879 apply_gain_automation = _gain_control->list()->curve().rt_safe_get_vector (
2880 start_frame, end_frame, _session.gain_automation_buffer(), nframes);
2885 passthru (start_frame, end_frame, nframes, offset, declick, false);
2891 Route::silent_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
2892 bool can_record, bool rec_monitors_input)
2894 silence (nframes, offset);
2899 Route::toggle_monitor_input ()
2901 for (PortSet::iterator i = _inputs.begin(); i != _inputs.end(); ++i) {
2902 i->ensure_monitor_input( ! i->monitoring_input());
2907 Route::has_external_redirects () const
2909 // FIXME: what about sends?
2911 boost::shared_ptr<const PortInsert> pi;
2913 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2914 if ((pi = boost::dynamic_pointer_cast<const PortInsert>(*i)) != 0) {
2916 for (PortSet::const_iterator port = pi->io()->outputs().begin();
2917 port != pi->io()->outputs().end(); ++port) {
2919 string port_name = port->name();
2920 string client_name = port_name.substr (0, port_name.find(':'));
2922 /* only say "yes" if the redirect is actually in use */
2924 if (client_name != "ardour" && pi->active()) {
2935 Route::flush_processors ()
2937 /* XXX shouldn't really try to take this lock, since
2938 this is called from the RT audio thread.
2941 Glib::RWLock::ReaderLock lm (_processor_lock);
2943 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2944 (*i)->deactivate ();
2950 Route::set_meter_point (MeterPoint p, void *src)
2952 if (_meter_point != p) {
2954 meter_change (src); /* EMIT SIGNAL */
2955 _session.set_dirty ();
2960 Route::update_total_latency ()
2962 nframes_t old = _own_latency;
2964 if (_user_latency) {
2965 _own_latency = _user_latency;
2969 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2970 if ((*i)->active ()) {
2971 _own_latency += (*i)->signal_latency ();
2976 #undef DEBUG_LATENCY
2977 #ifdef DEBUG_LATENCY
2978 cerr << _name << ": internal redirect latency = " << _own_latency << endl;
2981 set_port_latency (_own_latency);
2983 if (!_user_latency) {
2984 /* this (virtual) function is used for pure Routes,
2985 not derived classes like AudioTrack. this means
2986 that the data processed here comes from an input
2987 port, not prerecorded material, and therefore we
2988 have to take into account any input latency.
2992 _own_latency += input_latency ();
2995 if (old != _own_latency) {
2996 signal_latency_changed (); /* EMIT SIGNAL */
2999 #ifdef DEBUG_LATENCY
3000 cerr << _name << ": input latency = " << input_latency() << " total = "
3001 << _own_latency << endl;
3004 return _own_latency;
3008 Route::set_user_latency (nframes_t nframes)
3010 Latent::set_user_latency (nframes);
3011 _session.update_latency_compensation (false, false);
3015 Route::set_latency_delay (nframes_t longest_session_latency)
3017 nframes_t old = _initial_delay;
3019 if (_own_latency < longest_session_latency) {
3020 _initial_delay = longest_session_latency - _own_latency;
3025 if (_initial_delay != old) {
3026 initial_delay_changed (); /* EMIT SIGNAL */
3029 if (_session.transport_stopped()) {
3030 _roll_delay = _initial_delay;
3035 Route::automation_snapshot (nframes_t now, bool force)
3037 if (!force && !should_snapshot(now)) {
3041 IO::automation_snapshot (now, force);
3043 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3044 (*i)->automation_snapshot (now, force);
3048 Route::ToggleControllable::ToggleControllable (std::string name, Route& s, ToggleType tp)
3049 : Controllable (name), route (s), type(tp)
3055 Route::ToggleControllable::set_value (float val)
3057 bool bval = ((val >= 0.5f) ? true: false);
3061 route.set_mute (bval, this);
3064 route.set_solo (bval, this);
3072 Route::ToggleControllable::get_value (void) const
3078 val = route.muted() ? 1.0f : 0.0f;
3081 val = route.soloed() ? 1.0f : 0.0f;
3091 Route::set_block_size (nframes_t nframes)
3093 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
3094 (*i)->set_block_size (nframes);
3099 Route::protect_automation ()
3101 Automatable::protect_automation();
3103 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
3104 (*i)->protect_automation();
3108 Route::set_pending_declick (int declick)
3111 /* this call is not allowed to turn off a pending declick unless "force" is true */
3113 _pending_declick = declick;
3115 // cerr << _name << ": after setting to " << declick << " pending declick = " << _pending_declick << endl;
3117 _pending_declick = 0;
3122 /** Shift automation forwards from a particular place, thereby inserting time.
3123 * Adds undo commands for any shifts that are performed.
3125 * @param pos Position to start shifting from.
3126 * @param frames Amount to shift forwards by.
3130 Route::shift (nframes64_t pos, nframes64_t frames)
3132 #ifdef THIS_NEEDS_FIXING_FOR_V3
3134 /* gain automation */
3135 XMLNode &before = _gain_control->get_state ();
3136 _gain_control->shift (pos, frames);
3137 XMLNode &after = _gain_control->get_state ();
3138 _session.add_command (new MementoCommand<AutomationList> (_gain_automation_curve, &before, &after));
3140 /* pan automation */
3141 for (std::vector<StreamPanner*>::iterator i = _panner->begin (); i != _panner->end (); ++i) {
3142 Curve & c = (*i)->automation ();
3143 XMLNode &before = c.get_state ();
3144 c.shift (pos, frames);
3145 XMLNode &after = c.get_state ();
3146 _session.add_command (new MementoCommand<AutomationList> (c, &before, &after));
3149 /* redirect automation */
3151 Glib::RWLock::ReaderLock lm (redirect_lock);
3152 for (RedirectList::iterator i = _redirects.begin (); i != _redirects.end (); ++i) {
3155 (*i)->what_has_automation (a);
3157 for (set<uint32_t>::const_iterator j = a.begin (); j != a.end (); ++j) {
3158 AutomationList & al = (*i)->automation_list (*j);
3159 XMLNode &before = al.get_state ();
3160 al.shift (pos, frames);
3161 XMLNode &after = al.get_state ();
3162 _session.add_command (new MementoCommand<AutomationList> (al, &before, &after));