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/buffer.h>
32 #include <ardour/audioengine.h>
33 #include <ardour/route.h>
34 #include <ardour/insert.h>
35 #include <ardour/send.h>
36 #include <ardour/session.h>
37 #include <ardour/utils.h>
38 #include <ardour/configuration.h>
39 #include <ardour/cycle_timer.h>
40 #include <ardour/route_group.h>
41 #include <ardour/port.h>
42 #include <ardour/ladspa_plugin.h>
43 #include <ardour/panner.h>
44 #include <ardour/dB.h>
45 #include <ardour/mix.h>
46 #include <ardour/profile.h>
51 using namespace ARDOUR;
54 uint32_t Route::order_key_cnt = 0;
55 sigc::signal<void,const char*> Route::SyncOrderKeys;
57 Route::Route (Session& sess, string name, int input_min, int input_max, int output_min, int output_max, Flag flg, DataType default_type)
58 : IO (sess, name, input_min, input_max, output_min, output_max, default_type),
60 _solo_control (X_("solo"), *this, ToggleControllable::SoloControl),
61 _mute_control (X_("mute"), *this, ToggleControllable::MuteControl)
66 Route::Route (Session& sess, const XMLNode& node, DataType default_type)
67 : IO (sess, *node.child ("IO"), default_type),
68 _solo_control (X_("solo"), *this, ToggleControllable::SoloControl),
69 _mute_control (X_("mute"), *this, ToggleControllable::MuteControl)
72 _set_state (node, false);
78 redirect_max_outs = 0;
82 _phase_invert = false;
83 _denormal_protection = false;
84 order_keys[strdup (N_("signal"))] = order_key_cnt++;
86 _meter_point = MeterPostFader;
90 _have_internal_generator = false;
92 _pending_declick = true;
93 _remote_control_id = 0;
94 _ignore_gain_on_deliver = true;
99 _mute_affects_pre_fader = Config->get_mute_affects_pre_fader();
100 _mute_affects_post_fader = Config->get_mute_affects_post_fader();
101 _mute_affects_control_outs = Config->get_mute_affects_control_outs();
102 _mute_affects_main_outs = Config->get_mute_affects_main_outs();
105 desired_solo_gain = 1.0;
107 desired_mute_gain = 1.0;
111 input_changed.connect (mem_fun (this, &Route::input_change_handler));
112 output_changed.connect (mem_fun (this, &Route::output_change_handler));
117 clear_redirects (PreFader, this);
118 clear_redirects (PostFader, this);
120 for (OrderKeys::iterator i = order_keys.begin(); i != order_keys.end(); ++i) {
121 free ((void*)(i->first));
125 delete _control_outs;
130 Route::set_remote_control_id (uint32_t id)
132 if (id != _remote_control_id) {
133 _remote_control_id = id;
134 RemoteControlIDChanged ();
139 Route::remote_control_id() const
141 return _remote_control_id;
145 Route::order_key (const char* name) const
147 OrderKeys::const_iterator i;
149 for (i = order_keys.begin(); i != order_keys.end(); ++i) {
150 if (!strcmp (name, i->first)) {
159 Route::set_order_key (const char* name, long n)
161 order_keys[strdup(name)] = n;
163 if (Config->get_sync_all_route_ordering()) {
164 for (OrderKeys::iterator x = order_keys.begin(); x != order_keys.end(); ++x) {
169 _session.set_dirty ();
173 Route::sync_order_keys (const char* base)
175 if (order_keys.empty()) {
179 OrderKeys::iterator i;
182 if ((i = order_keys.find (base)) == order_keys.end()) {
183 /* key doesn't exist, use the first existing
184 key (this is done during session initialization)
186 i = order_keys.begin();
190 /* key exists - use it and reset all others
191 (actually, itself included)
193 i = order_keys.begin();
197 for (; i != order_keys.end(); ++i) {
203 Route::ensure_track_or_route_name(string name, Session &session)
205 string newname = name;
207 while (session.route_by_name (newname)!=NULL)
209 newname = bump_name_once (newname);
217 Route::inc_gain (gain_t fraction, void *src)
219 IO::inc_gain (fraction, src);
223 Route::set_gain (gain_t val, void *src)
225 if (src != 0 && _mix_group && src != _mix_group && _mix_group->is_active()) {
227 if (_mix_group->is_relative()) {
230 gain_t usable_gain = gain();
231 if (usable_gain < 0.000001f) {
232 usable_gain=0.000001f;
236 if (delta < 0.000001f) {
240 delta -= usable_gain;
242 if (delta == 0.0f) return;
244 gain_t factor = delta / usable_gain;
247 factor = _mix_group->get_max_factor(factor);
248 if (factor == 0.0f) {
253 factor = _mix_group->get_min_factor(factor);
254 if (factor == 0.0f) {
260 _mix_group->apply (&Route::inc_gain, factor, _mix_group);
264 _mix_group->apply (&Route::set_gain, val, _mix_group);
274 IO::set_gain (val, src);
278 Route::process_output_buffers (vector<Sample*>& bufs, uint32_t nbufs,
279 nframes_t start_frame, nframes_t end_frame,
280 nframes_t nframes, nframes_t offset, bool with_redirects, int declick,
284 RedirectList::iterator i;
285 bool post_fader_work = false;
286 bool mute_declick_applied = false;
288 vector<Sample*>::iterator bufiter;
293 gain_t* gab = _session.gain_automation_buffer();
295 switch (Config->get_monitoring_model()) {
296 case HardwareMonitoring:
297 case ExternalMonitoring:
304 declick = _pending_declick;
307 Glib::Mutex::Lock cm (control_outs_lock, Glib::TRY_LOCK);
317 Glib::Mutex::Lock dm (declick_lock, Glib::TRY_LOCK);
320 dmg = desired_mute_gain;
321 dsg = desired_solo_gain;
330 /* ----------------------------------------------------------------------------------------------------
331 GLOBAL DECLICK (for transport changes etc.)
332 -------------------------------------------------------------------------------------------------- */
335 apply_declick (bufs, nbufs, nframes, 0.0, 1.0, false);
336 _pending_declick = 0;
337 } else if (declick < 0) {
338 apply_declick (bufs, nbufs, nframes, 1.0, 0.0, false);
339 _pending_declick = 0;
342 /* no global declick */
344 if (solo_gain != dsg) {
345 apply_declick (bufs, nbufs, nframes, solo_gain, dsg, false);
351 /* ----------------------------------------------------------------------------------------------------
352 INPUT METERING & MONITORING
353 -------------------------------------------------------------------------------------------------- */
355 if (meter && (_meter_point == MeterInput)) {
356 for (n = 0; n < nbufs; ++n) {
357 _peak_power[n] = Session::compute_peak (bufs[n], nframes, _peak_power[n]);
361 if (!_soloed && _mute_affects_pre_fader && (mute_gain != dmg)) {
362 apply_declick (bufs, nbufs, nframes, mute_gain, dmg, false);
364 mute_declick_applied = true;
367 if ((_meter_point == MeterInput) && co) {
369 solo_audible = dsg > 0;
370 mute_audible = dmg > 0;// || !_mute_affects_pre_fader;
372 if ( // muted by solo of another track
376 // muted by mute of this track
380 // rec-enabled but not s/w monitoring
382 // TODO: this is probably wrong
384 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
388 co->silence (nframes, offset);
392 co->deliver_output (bufs, nbufs, nframes, offset);
397 /* -----------------------------------------------------------------------------------------------------
399 -------------------------------------------------------------------------------------------------- */
401 if (_denormal_protection || Config->get_denormal_protection()) {
403 for (n = 0; n < nbufs; ++n) {
404 Sample *sp = bufs[n];
406 for (nframes_t nx = offset; nx < nframes + offset; ++nx) {
413 /* ----------------------------------------------------------------------------------------------------
415 -------------------------------------------------------------------------------------------------- */
417 if (with_redirects) {
418 Glib::RWLock::ReaderLock rm (redirect_lock, Glib::TRY_LOCK);
420 if (mute_gain > 0 || !_mute_affects_pre_fader) {
421 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
422 switch ((*i)->placement()) {
425 if (boost::dynamic_pointer_cast<Send>(*i) || boost::dynamic_pointer_cast<PortInsert>(*i)) {
426 (*i)->silence (nframes, offset);
429 (*i)->run (bufs, nbufs, nframes, offset);
433 post_fader_work = true;
438 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
439 switch ((*i)->placement()) {
441 (*i)->silence (nframes, offset);
444 post_fader_work = true;
453 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_post_fader) {
454 apply_declick (bufs, nbufs, nframes, mute_gain, dmg, false);
456 mute_declick_applied = true;
459 /* ----------------------------------------------------------------------------------------------------
460 PRE-FADER METERING & MONITORING
461 -------------------------------------------------------------------------------------------------- */
463 if (meter && (_meter_point == MeterPreFader)) {
464 for (n = 0; n < nbufs; ++n) {
465 _peak_power[n] = Session::compute_peak (bufs[n], nframes, _peak_power[n]);
470 if ((_meter_point == MeterPreFader) && co) {
472 solo_audible = dsg > 0;
473 mute_audible = dmg > 0 || !_mute_affects_pre_fader;
475 if ( // muted by solo of another track
479 // muted by mute of this track
483 // rec-enabled but not s/w monitoring
485 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
489 co->silence (nframes, offset);
493 co->deliver_output_no_pan (bufs, nbufs, nframes, offset);
498 /* ----------------------------------------------------------------------------------------------------
500 -------------------------------------------------------------------------------------------------- */
502 /* if not recording or recording and requiring any monitor signal, then apply gain */
504 if ( // not recording
506 !(record_enabled() && _session.actively_recording()) ||
510 // AND software monitoring required
512 (Config->get_monitoring_model() == SoftwareMonitoring)) {
514 if (apply_gain_automation) {
517 for (n = 0; n < nbufs; ++n) {
518 Sample *sp = bufs[n];
520 for (nframes_t nx = 0; nx < nframes; ++nx) {
525 for (n = 0; n < nbufs; ++n) {
526 Sample *sp = bufs[n];
528 for (nframes_t nx = 0; nx < nframes; ++nx) {
534 if (apply_gain_automation && _session.transport_rolling() && nframes > 0) {
535 _effective_gain = gab[nframes-1];
540 /* manual (scalar) gain */
544 apply_declick (bufs, nbufs, nframes, _gain, dg, _phase_invert);
547 } else if (_gain != 0 && (_phase_invert || _gain != 1.0)) {
549 /* no need to interpolate current gain value,
550 but its non-unity, so apply it. if the gain
551 is zero, do nothing because we'll ship silence
563 for (n = 0; n < nbufs; ++n) {
564 Sample *sp = bufs[n];
565 Session::apply_gain_to_buffer(sp,nframes,this_gain);
568 } else if (_gain == 0) {
569 for (n = 0; n < nbufs; ++n) {
570 memset (bufs[n], 0, sizeof (Sample) * nframes);
577 /* actively recording, no monitoring required; leave buffers as-is to save CPU cycles */
581 /* ----------------------------------------------------------------------------------------------------
583 -------------------------------------------------------------------------------------------------- */
585 /* note that post_fader_work cannot be true unless with_redirects was also true, so don't test both */
587 if (post_fader_work) {
589 Glib::RWLock::ReaderLock rm (redirect_lock, Glib::TRY_LOCK);
591 if (mute_gain > 0 || !_mute_affects_post_fader) {
592 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
593 switch ((*i)->placement()) {
598 if (boost::dynamic_pointer_cast<Send>(*i) || boost::dynamic_pointer_cast<PortInsert>(*i)) {
599 (*i)->silence (nframes, offset);
602 (*i)->run (bufs, nbufs, nframes, offset);
608 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
609 switch ((*i)->placement()) {
613 (*i)->silence (nframes, offset);
621 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_control_outs) {
622 apply_declick (bufs, nbufs, nframes, mute_gain, dmg, false);
624 mute_declick_applied = true;
627 /* ----------------------------------------------------------------------------------------------------
629 -------------------------------------------------------------------------------------------------- */
631 if ((_meter_point == MeterPostFader) && co) {
633 solo_audible = solo_gain > 0;
634 mute_audible = dmg > 0 || !_mute_affects_control_outs;
636 if ( // silent anyway
638 (_gain == 0 && !apply_gain_automation) ||
640 // muted by solo of another track
644 // muted by mute of this track
648 // recording but not s/w monitoring
650 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
654 co->silence (nframes, offset);
658 co->deliver_output_no_pan (bufs, nbufs, nframes, offset);
662 /* ----------------------------------------------------------------------
664 ----------------------------------------------------------------------*/
666 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_main_outs) {
667 apply_declick (bufs, nbufs, nframes, mute_gain, dmg, false);
669 mute_declick_applied = true;
672 /* ----------------------------------------------------------------------------------------------------
674 -------------------------------------------------------------------------------------------------- */
676 solo_audible = dsg > 0;
677 mute_audible = dmg > 0 || !_mute_affects_main_outs;
679 if (n_outputs() == 0) {
683 } else if (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording())) {
685 IO::silence (nframes, offset);
689 if ( // silent anyway
691 (_gain == 0 && !apply_gain_automation) ||
693 // muted by solo of another track, but not using control outs for solo
695 (!solo_audible && (Config->get_solo_model() != SoloBus)) ||
697 // muted by mute of this track
703 /* don't use Route::silence() here, because that causes
704 all outputs (sends, port inserts, etc. to be silent).
707 if (_meter_point == MeterPostFader) {
708 reset_peak_meters ();
711 IO::silence (nframes, offset);
715 if ((_session.transport_speed() > 1.5f ||
716 _session.transport_speed() < -1.5f) &&
717 Config->get_quieten_at_speed()) {
718 pan (bufs, nbufs, nframes, offset, speed_quietning);
720 // cerr << _name << " panner state = " << _panner->automation_state() << endl;
721 if (!_panner->empty() &&
722 (_panner->automation_state() & Play ||
723 ((_panner->automation_state() & Touch) && !_panner->touching()))) {
724 pan_automated (bufs, nbufs, start_frame, end_frame, nframes, offset);
726 pan (bufs, nbufs, nframes, offset, 1.0);
733 /* ----------------------------------------------------------------------------------------------------
735 -------------------------------------------------------------------------------------------------- */
737 if (meter && (_meter_point == MeterPostFader)) {
739 if ((_gain == 0 && !apply_gain_automation) || dmg == 0) {
740 uint32_t no = n_outputs();
741 for (n = 0; n < no; ++n) {
745 uint32_t no = n_outputs();
746 for (n = 0; n < no; ++n) {
747 _peak_power[n] = Session::compute_peak (output(n)->get_buffer (nframes) + offset, nframes, _peak_power[n]);
754 Route::n_process_buffers ()
756 return max (n_inputs(), redirect_max_outs);
761 Route::passthru (nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset, int declick, bool meter_first)
763 vector<Sample*>& bufs = _session.get_passthru_buffers();
764 uint32_t limit = n_process_buffers ();
768 collect_input (bufs, limit, nframes, offset);
770 #define meter_stream meter_first
773 for (uint32_t n = 0; n < limit; ++n) {
774 _peak_power[n] = Session::compute_peak (bufs[n], nframes, _peak_power[n]);
776 meter_stream = false;
781 process_output_buffers (bufs, limit, start_frame, end_frame, nframes, offset, true, declick, meter_stream);
787 Route::set_phase_invert (bool yn, void *src)
789 if (_phase_invert != yn) {
791 // phase_invert_changed (src); /* EMIT SIGNAL */
796 Route::set_denormal_protection (bool yn, void *src)
798 if (_denormal_protection != yn) {
799 _denormal_protection = yn;
800 // denormal_protection_changed (src); /* EMIT SIGNAL */
805 Route::set_solo (bool yn, void *src)
811 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
812 _mix_group->apply (&Route::set_solo, yn, _mix_group);
818 solo_changed (src); /* EMIT SIGNAL */
819 _solo_control.Changed (); /* EMIT SIGNAL */
822 catch_up_on_solo_mute_override ();
826 Route::catch_up_on_solo_mute_override ()
828 if (Config->get_solo_model() != InverseMute) {
834 Glib::Mutex::Lock lm (declick_lock);
837 if (Config->get_solo_mute_override()) {
838 desired_mute_gain = (_soloed?1.0:0.0);
840 desired_mute_gain = 0.0;
843 desired_mute_gain = 1.0;
849 Route::set_solo_mute (bool yn)
851 Glib::Mutex::Lock lm (declick_lock);
853 /* Called by Session in response to another Route being soloed.
856 desired_solo_gain = (yn?0.0:1.0);
860 Route::set_solo_safe (bool yn, void *src)
862 if (_solo_safe != yn) {
864 solo_safe_changed (src); /* EMIT SIGNAL */
869 Route::set_mute (bool yn, void *src)
872 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
873 _mix_group->apply (&Route::set_mute, yn, _mix_group);
879 mute_changed (src); /* EMIT SIGNAL */
881 _mute_control.Changed (); /* EMIT SIGNAL */
883 Glib::Mutex::Lock lm (declick_lock);
885 if (_soloed && Config->get_solo_mute_override()){
886 desired_mute_gain = 1.0f;
888 desired_mute_gain = (yn?0.0f:1.0f);
894 Route::add_redirect (boost::shared_ptr<Redirect> redirect, void *src, uint32_t* err_streams)
896 uint32_t old_rmo = redirect_max_outs;
898 if (!_session.engine().connected()) {
903 Glib::RWLock::WriterLock lm (redirect_lock);
905 boost::shared_ptr<PluginInsert> pi;
906 boost::shared_ptr<PortInsert> porti;
908 _redirects.push_back (redirect);
910 if (_reset_plugin_counts (err_streams)) {
911 _redirects.pop_back ();
912 _reset_plugin_counts (0); // it worked before we tried to add it ...
916 uint32_t potential_max_streams = 0;
918 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(redirect)) != 0) {
920 if (pi->input_streams() == 0) {
921 /* instrument plugin */
922 _have_internal_generator = true;
925 potential_max_streams = max(pi->input_streams(), pi->output_streams());
927 } else if ((porti = boost::dynamic_pointer_cast<PortInsert>(redirect)) != 0) {
929 /* force new port inserts to start out with an i/o configuration
930 that matches this route's i/o configuration.
932 the "inputs" for the port are supposed to match the output
935 the "outputs" of the route should match the inputs of this
936 route. XXX shouldn't they match the number of active signal
937 streams at the point of insertion?
941 porti->ensure_io (n_outputs (), n_inputs(), false, this);
944 // Ensure peak vector sizes before the plugin is activated
945 while (_peak_power.size() < potential_max_streams) {
946 _peak_power.push_back(0);
948 while (_visible_peak_power.size() < potential_max_streams) {
949 _visible_peak_power.push_back(-INFINITY);
951 while (_max_peak_power.size() < potential_max_streams) {
952 _max_peak_power.push_back(-INFINITY);
955 redirect->active_changed.connect (mem_fun (*this, &Route::redirect_active_proxy));
958 if (redirect_max_outs != old_rmo || old_rmo == 0) {
962 redirects_changed (src); /* EMIT SIGNAL */
968 Route::add_redirects (const RedirectList& others, void *src, uint32_t* err_streams)
970 uint32_t old_rmo = redirect_max_outs;
972 assert (ports_legal);
974 if (!_session.engine().connected()) {
979 Glib::RWLock::WriterLock lm (redirect_lock);
981 RedirectList::iterator existing_end = _redirects.end();
984 uint32_t potential_max_streams = 0;
986 for (RedirectList::const_iterator i = others.begin(); i != others.end(); ++i) {
988 boost::shared_ptr<PluginInsert> pi;
990 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
993 uint32_t m = max(pi->input_streams(), pi->output_streams());
994 if (m > potential_max_streams)
995 potential_max_streams = m;
998 // Ensure peak vector sizes before the plugin is activated
999 while (_peak_power.size() < potential_max_streams) {
1000 _peak_power.push_back(0);
1002 while (_visible_peak_power.size() < potential_max_streams) {
1003 _visible_peak_power.push_back(-INFINITY);
1005 while (_max_peak_power.size() < potential_max_streams) {
1006 _max_peak_power.push_back(-INFINITY);
1009 _redirects.push_back (*i);
1011 if (_reset_plugin_counts (err_streams)) {
1013 _redirects.erase (existing_end, _redirects.end());
1014 _reset_plugin_counts (0); // it worked before we tried to add it ...
1018 (*i)->active_changed.connect (mem_fun (*this, &Route::redirect_active_proxy));
1022 if (redirect_max_outs != old_rmo || old_rmo == 0) {
1026 redirects_changed (src); /* EMIT SIGNAL */
1030 /** Remove redirects with a given placement.
1031 * @param p Placement of redirects to remove.
1034 Route::clear_redirects (Placement p, void *src)
1036 const uint32_t old_rmo = redirect_max_outs;
1038 if (!_session.engine().connected()) {
1043 Glib::RWLock::WriterLock lm (redirect_lock);
1044 RedirectList new_list;
1046 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
1047 if ((*i)->placement() == p) {
1048 /* it's the placement we want to get rid of */
1049 (*i)->drop_references ();
1051 /* it's a different placement, so keep it */
1052 new_list.push_back (*i);
1056 _redirects = new_list;
1059 /* FIXME: can't see how this test can ever fire */
1060 if (redirect_max_outs != old_rmo) {
1064 redirect_max_outs = 0;
1065 _have_internal_generator = false;
1066 redirects_changed (src); /* EMIT SIGNAL */
1070 Route::remove_redirect (boost::shared_ptr<Redirect> redirect, void *src, uint32_t* err_streams)
1072 uint32_t old_rmo = redirect_max_outs;
1074 assert (ports_legal);
1076 if (!_session.engine().connected()) {
1080 redirect_max_outs = 0;
1083 Glib::RWLock::WriterLock lm (redirect_lock);
1084 RedirectList::iterator i;
1085 bool removed = false;
1087 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
1088 if (*i == redirect) {
1090 RedirectList::iterator tmp;
1092 /* move along, see failure case for reset_plugin_counts()
1093 where we may need to reinsert the redirect.
1099 /* stop redirects that send signals to JACK ports
1100 from causing noise as a result of no longer being
1104 boost::shared_ptr<Send> send;
1105 boost::shared_ptr<PortInsert> port_insert;
1107 if ((send = boost::dynamic_pointer_cast<Send> (*i)) != 0) {
1108 send->disconnect_inputs (this);
1109 send->disconnect_outputs (this);
1110 } else if ((port_insert = boost::dynamic_pointer_cast<PortInsert> (*i)) != 0) {
1111 port_insert->disconnect_inputs (this);
1112 port_insert->disconnect_outputs (this);
1115 _redirects.erase (i);
1128 if (_reset_plugin_counts (err_streams)) {
1129 /* get back to where we where */
1130 _redirects.insert (i, redirect);
1131 /* we know this will work, because it worked before :) */
1132 _reset_plugin_counts (0);
1136 _have_internal_generator = false;
1138 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
1139 boost::shared_ptr<PluginInsert> pi;
1141 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1142 if (pi->is_generator()) {
1143 _have_internal_generator = true;
1150 if (old_rmo != redirect_max_outs) {
1154 redirect->drop_references ();
1156 redirects_changed (src); /* EMIT SIGNAL */
1161 Route::reset_plugin_counts (uint32_t* lpc)
1163 Glib::RWLock::WriterLock lm (redirect_lock);
1164 return _reset_plugin_counts (lpc);
1169 Route::_reset_plugin_counts (uint32_t* err_streams)
1171 RedirectList::iterator r;
1172 uint32_t insert_cnt = 0;
1173 uint32_t send_cnt = 0;
1174 map<Placement,list<InsertCount> > insert_map;
1175 RedirectList::iterator prev;
1176 int32_t initial_streams = n_inputs ();;
1177 int32_t previous_initial_streams = n_inputs ();
1180 redirect_max_outs = 0;
1182 /* Step 1: build a map that links each insert to an in/out channel count
1184 Divide inserts up by placement so we get the signal flow
1185 properly modelled. we need to do this because the _redirects
1186 list is not sorted by placement, and because other reasons may
1187 exist now or in the future for this separate treatment.
1190 for (r = _redirects.begin(); r != _redirects.end(); ++r) {
1192 boost::shared_ptr<Insert> insert;
1194 if ((insert = boost::dynamic_pointer_cast<Insert>(*r)) != 0) {
1196 insert_map[insert->placement()].push_back (InsertCount (insert));
1198 /* reset plugin counts back to one for now so
1199 that we have a predictable, controlled
1200 state to try to configure.
1203 boost::shared_ptr<PluginInsert> pi;
1205 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(insert)) != 0) {
1209 } else if (boost::dynamic_pointer_cast<Send> (*r) != 0) {
1214 if (insert_cnt == 0) {
1223 /* Now process each placement in order, checking to see if we
1224 can really do what has been requested.
1229 if (check_some_plugin_counts (insert_map[PreFader], n_inputs (), err_streams)) {
1233 /* figure out the streams that will feed into PreFader */
1235 if (!insert_map[PreFader].empty()) {
1236 previous_initial_streams = n_inputs ();
1237 for (list<InsertCount>::iterator i = insert_map[PreFader].begin(); i != insert_map[PreFader].end(); i++) {
1238 if (i->insert->can_do (previous_initial_streams, initial_streams) < 0) {
1241 previous_initial_streams = initial_streams;
1247 if (check_some_plugin_counts (insert_map[PostFader], initial_streams, err_streams)) {
1251 if (!insert_map[PostFader].empty()) {
1252 for (list<InsertCount>::iterator i = insert_map[PostFader].begin(); i != insert_map[PostFader].end(); i++) {
1253 if (i->insert->can_do (previous_initial_streams, initial_streams) < 0) {
1256 previous_initial_streams = initial_streams;
1260 /* OK, everything can be set up correctly, so lets do it */
1262 apply_some_plugin_counts (insert_map[PreFader]);
1263 apply_some_plugin_counts (insert_map[PostFader]);
1265 /* recompute max outs of any redirect */
1269 redirect_max_outs = 0;
1270 prev = _redirects.end();
1272 for (r = _redirects.begin(); r != _redirects.end(); prev = r, ++r) {
1273 boost::shared_ptr<Send> s;
1275 if ((s = boost::dynamic_pointer_cast<Send> (*r)) != 0) {
1276 if (r == _redirects.begin()) {
1277 s->expect_inputs (n_inputs());
1279 s->expect_inputs ((*prev)->output_streams());
1284 /* don't pay any attention to send output configuration, since it doesn't
1288 redirect_max_outs = max ((*r)->output_streams (), redirect_max_outs);
1297 for (r = _redirects.begin(); r != _redirects.end(); ++r) {
1298 redirect_max_outs = max ((*r)->output_streams (), redirect_max_outs);
1304 Route::apply_some_plugin_counts (list<InsertCount>& iclist)
1306 list<InsertCount>::iterator i;
1308 for (i = iclist.begin(); i != iclist.end(); ++i) {
1310 if ((*i).insert->configure_io ((*i).cnt, (*i).in, (*i).out)) {
1313 /* make sure that however many we have, they are all active */
1314 (*i).insert->activate ();
1321 Route::check_some_plugin_counts (list<InsertCount>& iclist, int32_t required_inputs, uint32_t* err_streams)
1323 list<InsertCount>::iterator i;
1325 for (i = iclist.begin(); i != iclist.end(); ++i) {
1327 if (((*i).cnt = (*i).insert->can_do (required_inputs, (*i).out)) < 0) {
1329 *err_streams = required_inputs;
1334 (*i).in = required_inputs;
1335 required_inputs = (*i).out;
1342 Route::copy_redirects (const Route& other, Placement placement, uint32_t* err_streams)
1344 uint32_t old_rmo = redirect_max_outs;
1350 RedirectList to_be_deleted;
1353 Glib::RWLock::WriterLock lm (redirect_lock);
1354 RedirectList::iterator tmp;
1355 RedirectList the_copy;
1357 the_copy = _redirects;
1359 /* remove all relevant redirects */
1361 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ) {
1365 if ((*i)->placement() == placement) {
1366 to_be_deleted.push_back (*i);
1367 _redirects.erase (i);
1373 /* now copy the relevant ones from "other" */
1375 for (RedirectList::const_iterator i = other._redirects.begin(); i != other._redirects.end(); ++i) {
1376 if ((*i)->placement() == placement) {
1377 _redirects.push_back (Redirect::clone (*i));
1381 /* reset plugin stream handling */
1383 if (_reset_plugin_counts (err_streams)) {
1385 /* FAILED COPY ATTEMPT: we have to restore order */
1387 /* delete all cloned redirects */
1389 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ) {
1394 if ((*i)->placement() == placement) {
1395 _redirects.erase (i);
1401 /* restore the natural order */
1403 _redirects = the_copy;
1404 redirect_max_outs = old_rmo;
1406 /* we failed, even though things are OK again */
1412 /* SUCCESSFUL COPY ATTEMPT: delete the redirects we removed pre-copy */
1413 to_be_deleted.clear ();
1417 if (redirect_max_outs != old_rmo || old_rmo == 0) {
1421 redirects_changed (this); /* EMIT SIGNAL */
1426 Route::all_redirects_flip ()
1428 Glib::RWLock::ReaderLock lm (redirect_lock);
1430 if (_redirects.empty()) {
1434 bool first_is_on = _redirects.front()->active();
1436 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
1437 (*i)->set_active (!first_is_on, this);
1441 /** Set all redirects with a given placement to a given active state.
1442 * @param p Placement of redirects to change.
1443 * @param state New active state for those redirects.
1446 Route::all_redirects_active (Placement p, bool state)
1448 Glib::RWLock::ReaderLock lm (redirect_lock);
1450 if (_redirects.empty()) {
1454 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
1455 if ((*i)->placement() == p) {
1456 (*i)->set_active (state, this);
1461 struct RedirectSorter {
1462 bool operator() (boost::shared_ptr<const Redirect> a, boost::shared_ptr<const Redirect> b) {
1463 return a->sort_key() < b->sort_key();
1468 Route::sort_redirects (uint32_t* err_streams)
1471 RedirectSorter comparator;
1472 Glib::RWLock::WriterLock lm (redirect_lock);
1473 uint32_t old_rmo = redirect_max_outs;
1475 /* the sweet power of C++ ... */
1477 RedirectList as_it_was_before = _redirects;
1479 _redirects.sort (comparator);
1481 if (_reset_plugin_counts (err_streams)) {
1482 _redirects = as_it_was_before;
1483 redirect_max_outs = old_rmo;
1489 redirects_changed (this); /* EMIT SIGNAL */
1501 Route::get_template()
1503 return state(false);
1507 Route::state(bool full_state)
1509 XMLNode *node = new XMLNode("Route");
1510 RedirectList:: iterator i;
1514 node->add_property("flags", enum_2_string (_flags));
1517 node->add_property("default-type", _default_type.to_string());
1519 node->add_property("muted", _muted?"yes":"no");
1520 node->add_property("soloed", _soloed?"yes":"no");
1521 node->add_property("phase-invert", _phase_invert?"yes":"no");
1522 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
1523 node->add_property("mute-affects-pre-fader", _mute_affects_pre_fader?"yes":"no");
1524 node->add_property("mute-affects-post-fader", _mute_affects_post_fader?"yes":"no");
1525 node->add_property("mute-affects-control-outs", _mute_affects_control_outs?"yes":"no");
1526 node->add_property("mute-affects-main-outs", _mute_affects_main_outs?"yes":"no");
1527 node->add_property("meter-point", enum_2_string (_meter_point));
1530 node->add_property("edit-group", _edit_group->name());
1533 node->add_property("mix-group", _mix_group->name());
1536 string order_string;
1537 OrderKeys::iterator x = order_keys.begin();
1539 while (x != order_keys.end()) {
1540 order_string += string ((*x).first);
1541 order_string += '=';
1542 snprintf (buf, sizeof(buf), "%ld", (*x).second);
1543 order_string += buf;
1547 if (x == order_keys.end()) {
1551 order_string += ':';
1553 node->add_property ("order-keys", order_string);
1555 node->add_child_nocopy (IO::state (full_state));
1556 node->add_child_nocopy (_solo_control.get_state ());
1557 node->add_child_nocopy (_mute_control.get_state ());
1559 XMLNode* remote_control_node = new XMLNode (X_("remote_control"));
1560 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
1561 remote_control_node->add_property (X_("id"), buf);
1562 node->add_child_nocopy (*remote_control_node);
1564 if (_control_outs) {
1565 XMLNode* cnode = new XMLNode (X_("ControlOuts"));
1566 cnode->add_child_nocopy (_control_outs->state (full_state));
1567 node->add_child_nocopy (*cnode);
1570 if (_comment.length()) {
1571 XMLNode *cmt = node->add_child ("Comment");
1572 cmt->add_content (_comment);
1575 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
1576 node->add_child_nocopy((*i)->state (full_state));
1580 node->add_child_copy (*_extra_xml);
1587 Route::set_deferred_state ()
1590 XMLNodeConstIterator niter;
1592 if (!deferred_state) {
1596 nlist = deferred_state->children();
1598 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1599 add_redirect_from_xml (**niter);
1602 delete deferred_state;
1607 Route::add_redirect_from_xml (const XMLNode& node)
1609 const XMLProperty *prop;
1611 if (node.name() == "Send") {
1615 boost::shared_ptr<Send> send (new Send (_session, node));
1616 add_redirect (send, this);
1619 catch (failed_constructor &err) {
1620 error << _("Send construction failed") << endmsg;
1624 } else if (node.name() == "Insert") {
1627 if ((prop = node.property ("type")) != 0) {
1629 boost::shared_ptr<Insert> insert;
1630 bool have_insert = false;
1632 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
1633 prop->value() == "lv2" ||
1634 prop->value() == "vst" ||
1635 prop->value() == "audiounit") {
1637 insert.reset (new PluginInsert(_session, node));
1640 } else if (prop->value() == "port") {
1643 insert.reset (new PortInsert (_session, node));
1648 error << string_compose(_("unknown Insert type \"%1\"; ignored"), prop->value()) << endmsg;
1652 add_redirect (insert, this);
1656 error << _("Insert XML node has no type property") << endmsg;
1660 catch (failed_constructor &err) {
1661 warning << _("insert could not be created. Ignored.") << endmsg;
1668 Route::set_state (const XMLNode& node)
1670 return _set_state (node, true);
1674 Route::_set_state (const XMLNode& node, bool call_base)
1677 XMLNodeConstIterator niter;
1679 XMLPropertyList plist;
1680 const XMLProperty *prop;
1682 if (node.name() != "Route"){
1683 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
1687 if ((prop = node.property (X_("flags"))) != 0) {
1688 _flags = Flag (string_2_enum (prop->value(), _flags));
1693 if ((prop = node.property (X_("default-type"))) != 0) {
1694 _default_type = DataType(prop->value());
1695 assert(_default_type != DataType::NIL);
1698 if ((prop = node.property (X_("phase-invert"))) != 0) {
1699 set_phase_invert (prop->value()=="yes"?true:false, this);
1702 if ((prop = node.property (X_("denormal-protection"))) != 0) {
1703 set_denormal_protection (prop->value()=="yes"?true:false, this);
1706 if ((prop = node.property (X_("muted"))) != 0) {
1707 bool yn = prop->value()=="yes"?true:false;
1709 /* force reset of mute status */
1713 mute_gain = desired_mute_gain;
1716 if ((prop = node.property (X_("soloed"))) != 0) {
1717 bool yn = prop->value()=="yes"?true:false;
1719 /* force reset of solo status */
1722 set_solo (yn, this);
1723 solo_gain = desired_solo_gain;
1726 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
1727 _mute_affects_pre_fader = (prop->value()=="yes")?true:false;
1730 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
1731 _mute_affects_post_fader = (prop->value()=="yes")?true:false;
1734 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
1735 _mute_affects_control_outs = (prop->value()=="yes")?true:false;
1738 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
1739 _mute_affects_main_outs = (prop->value()=="yes")?true:false;
1742 if ((prop = node.property (X_("meter-point"))) != 0) {
1743 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
1746 if ((prop = node.property (X_("edit-group"))) != 0) {
1747 RouteGroup* edit_group = _session.edit_group_by_name(prop->value());
1748 if(edit_group == 0) {
1749 error << string_compose(_("Route %1: unknown edit group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
1751 set_edit_group(edit_group, this);
1755 if ((prop = node.property (X_("order-keys"))) != 0) {
1759 string::size_type colon, equal;
1760 string remaining = prop->value();
1762 while (remaining.length()) {
1764 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
1765 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1768 if (sscanf (remaining.substr (equal+1).c_str(), "%ld", &n) != 1) {
1769 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1772 set_order_key (remaining.substr (0, equal).c_str(), n);
1776 colon = remaining.find_first_of (':');
1778 if (colon != string::npos) {
1779 remaining = remaining.substr (colon+1);
1786 nlist = node.children();
1788 if (deferred_state) {
1789 delete deferred_state;
1792 deferred_state = new XMLNode(X_("deferred state"));
1794 /* set parent class properties before anything else */
1796 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1800 if (child->name() == IO::state_node_name && call_base) {
1802 IO::set_state (*child);
1808 XMLNodeList redirect_nodes;
1810 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1814 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
1815 redirect_nodes.push_back(child);
1820 _set_redirect_states (redirect_nodes);
1822 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1824 // All redirects (sends and inserts) have been applied already
1826 if (child->name() == X_("Automation")) {
1828 if ((prop = child->property (X_("path"))) != 0) {
1829 load_automation (prop->value());
1832 } else if (child->name() == X_("ControlOuts")) {
1834 string coutname = _name;
1835 coutname += _("[control]");
1837 _control_outs = new IO (_session, coutname);
1838 _control_outs->set_state (**(child->children().begin()));
1840 } else if (child->name() == X_("Comment")) {
1842 /* XXX this is a terrible API design in libxml++ */
1844 XMLNode *cmt = *(child->children().begin());
1845 _comment = cmt->content();
1847 } else if (child->name() == X_("extra")) {
1849 _extra_xml = new XMLNode (*child);
1851 } else if (child->name() == X_("controllable") && (prop = child->property("name")) != 0) {
1853 if (prop->value() == "solo") {
1854 _solo_control.set_state (*child);
1855 _session.add_controllable (&_solo_control);
1857 else if (prop->value() == "mute") {
1858 _mute_control.set_state (*child);
1859 _session.add_controllable (&_mute_control);
1862 else if (child->name() == X_("remote_control")) {
1863 if ((prop = child->property (X_("id"))) != 0) {
1865 sscanf (prop->value().c_str(), "%d", &x);
1866 set_remote_control_id (x);
1871 if ((prop = node.property (X_("mix-group"))) != 0) {
1872 RouteGroup* mix_group = _session.mix_group_by_name(prop->value());
1873 if (mix_group == 0) {
1874 error << string_compose(_("Route %1: unknown mix group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
1876 set_mix_group(mix_group, this);
1884 Route::_set_redirect_states(const XMLNodeList &nlist)
1886 XMLNodeConstIterator niter;
1889 RedirectList::iterator i, o;
1893 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1894 deferred_state->add_child_copy (**niter);
1900 // Iterate through existing redirects, remove those which are not in the state list
1901 for (i = _redirects.begin(); i != _redirects.end(); ) {
1902 RedirectList::iterator tmp = i;
1905 bool redirectInStateList = false;
1907 (*i)->id().print (buf, sizeof (buf));
1909 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1911 if (strncmp (buf,(*niter)->child(X_("Redirect"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf)) == 0) {
1912 redirectInStateList = true;
1917 if (!redirectInStateList) {
1918 remove_redirect ( *i, this);
1926 // Iterate through state list and make sure all redirects are on the track and in the correct order,
1927 // set the state of existing redirects according to the new state on the same go
1928 i = _redirects.begin();
1929 for (niter = nlist.begin(); niter != nlist.end(); ++niter, ++i) {
1931 // Check whether the next redirect in the list
1934 while (o != _redirects.end()) {
1935 (*o)->id().print (buf, sizeof (buf));
1936 if ( strncmp(buf, (*niter)->child(X_("Redirect"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf)) == 0)
1941 if (o == _redirects.end()) {
1942 // If the redirect (*niter) is not on the route, we need to create it
1943 // and move it to the correct location
1945 RedirectList::iterator prev_last = _redirects.end();
1946 --prev_last; // We need this to check whether adding succeeded
1948 add_redirect_from_xml (**niter);
1950 RedirectList::iterator last = _redirects.end();
1953 if (prev_last == last) {
1954 warning << _name << ": could not fully restore state as some redirects were not possible to create" << endmsg;
1959 boost::shared_ptr<Redirect> tmp = (*last);
1960 // remove the redirect from the wrong location
1961 _redirects.erase(last);
1962 // insert the new redirect at the current location
1963 _redirects.insert(i, tmp);
1965 --i; // move pointer to the newly inserted redirect
1969 // We found the redirect (*niter) on the route, first we must make sure the redirect
1970 // is at the location provided in the XML state
1972 boost::shared_ptr<Redirect> tmp = (*o);
1973 // remove the old copy
1974 _redirects.erase(o);
1975 // insert the redirect at the correct location
1976 _redirects.insert(i, tmp);
1978 --i; // move pointer so it points to the right redirect
1981 (*i)->set_state( (**niter) );
1984 redirects_changed(this);
1988 Route::curve_reallocate ()
1990 // _gain_automation_curve.finish_resize ();
1991 // _pan_automation_curve.finish_resize ();
1995 Route::silence (nframes_t nframes, nframes_t offset)
1999 // reset_peak_meters ();
2001 IO::silence (nframes, offset);
2003 if (_control_outs) {
2004 _control_outs->silence (nframes, offset);
2008 Glib::RWLock::ReaderLock lm (redirect_lock, Glib::TRY_LOCK);
2011 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2012 boost::shared_ptr<PluginInsert> pi;
2013 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2014 // skip plugins, they don't need anything when we're not active
2018 (*i)->silence (nframes, offset);
2021 if (nframes == _session.get_block_size() && offset == 0) {
2031 Route::set_control_outs (const vector<string>& ports)
2033 Glib::Mutex::Lock lm (control_outs_lock);
2034 vector<string>::const_iterator i;
2037 if (_control_outs) {
2038 delete _control_outs;
2042 if (control() || master()) {
2043 /* no control outs for these two special busses */
2047 if (ports.empty()) {
2051 string coutname = _name;
2052 coutname += _("[control]");
2054 _control_outs = new IO (_session, coutname);
2056 /* our control outs need as many outputs as we
2057 have outputs. we track the changes in ::output_change_handler().
2060 limit = n_outputs ();
2062 if (_control_outs->ensure_io (0, limit, true, this)) {
2066 /* now connect to the named ports */
2068 for (uint32_t n = 0; n < limit; ++n) {
2069 if (_control_outs->connect_output (_control_outs->output (n), ports[n % ports.size()], this)) {
2070 error << string_compose (_("could not connect %1 to %2"), _control_outs->output(n)->name(), ports[n]) << endmsg;
2079 Route::set_edit_group (RouteGroup *eg, void *src)
2082 if (eg == _edit_group) {
2087 _edit_group->remove (this);
2090 if ((_edit_group = eg) != 0) {
2091 _edit_group->add (this);
2094 _session.set_dirty ();
2095 edit_group_changed (src); /* EMIT SIGNAL */
2099 Route::drop_edit_group (void *src)
2102 _session.set_dirty ();
2103 edit_group_changed (src); /* EMIT SIGNAL */
2107 Route::set_mix_group (RouteGroup *mg, void *src)
2110 if (mg == _mix_group) {
2115 _mix_group->remove (this);
2118 if ((_mix_group = mg) != 0) {
2119 _mix_group->add (this);
2122 _session.set_dirty ();
2123 mix_group_changed (src); /* EMIT SIGNAL */
2127 Route::drop_mix_group (void *src)
2130 _session.set_dirty ();
2131 mix_group_changed (src); /* EMIT SIGNAL */
2135 Route::set_comment (string cmt, void *src)
2138 comment_changed (src);
2139 _session.set_dirty ();
2143 Route::feeds (boost::shared_ptr<Route> other)
2148 uint32_t no = self.n_outputs();
2149 uint32_t ni = other->n_inputs ();
2151 for (i = 0; i < no; ++i) {
2152 for (j = 0; j < ni; ++j) {
2153 if (self.output(i)->connected_to (other->input(j)->name())) {
2159 /* check Redirects which may also interconnect Routes */
2161 for (RedirectList::iterator r = _redirects.begin(); r != _redirects.end(); r++) {
2163 no = (*r)->n_outputs();
2165 for (i = 0; i < no; ++i) {
2166 for (j = 0; j < ni; ++j) {
2167 if ((*r)->output(i)->connected_to (other->input (j)->name())) {
2174 /* check for control room outputs which may also interconnect Routes */
2176 if (_control_outs) {
2178 no = _control_outs->n_outputs();
2180 for (i = 0; i < no; ++i) {
2181 for (j = 0; j < ni; ++j) {
2182 if (_control_outs->output(i)->connected_to (other->input (j)->name())) {
2193 Route::set_mute_config (mute_type t, bool onoff, void *src)
2197 _mute_affects_pre_fader = onoff;
2198 pre_fader_changed(src); /* EMIT SIGNAL */
2202 _mute_affects_post_fader = onoff;
2203 post_fader_changed(src); /* EMIT SIGNAL */
2207 _mute_affects_control_outs = onoff;
2208 control_outs_changed(src); /* EMIT SIGNAL */
2212 _mute_affects_main_outs = onoff;
2213 main_outs_changed(src); /* EMIT SIGNAL */
2219 Route::get_mute_config (mute_type t)
2225 onoff = _mute_affects_pre_fader;
2228 onoff = _mute_affects_post_fader;
2231 onoff = _mute_affects_control_outs;
2234 onoff = _mute_affects_main_outs;
2242 Route::handle_transport_stopped (bool abort_ignored, bool did_locate, bool can_flush_redirects)
2244 nframes_t now = _session.transport_frame();
2247 Glib::RWLock::ReaderLock lm (redirect_lock);
2250 automation_snapshot (now, true);
2253 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2255 if (Config->get_plugins_stop_with_transport() && can_flush_redirects) {
2256 (*i)->deactivate ();
2260 (*i)->transport_stopped (now);
2264 IO::transport_stopped (now);
2266 _roll_delay = _initial_delay;
2270 Route::input_change_handler (IOChange change, void *ignored)
2272 if (change & ConfigurationChanged) {
2273 reset_plugin_counts (0);
2278 Route::output_change_handler (IOChange change, void *ignored)
2280 if (change & ConfigurationChanged) {
2281 if (_control_outs) {
2282 _control_outs->ensure_io (0, n_outputs(), true, this);
2285 reset_plugin_counts (0);
2290 Route::pans_required () const
2292 if (n_outputs() < 2) {
2296 return max (n_inputs (), redirect_max_outs);
2300 Route::no_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
2301 bool session_state_changing, bool can_record, bool rec_monitors_input)
2303 if (n_outputs() == 0) {
2307 if (session_state_changing || !_active) {
2308 silence (nframes, offset);
2312 apply_gain_automation = false;
2315 passthru (start_frame, end_frame, nframes, offset, 0, false);
2317 silence (nframes, offset);
2324 Route::check_initial_delay (nframes_t nframes, nframes_t& offset, nframes_t& transport_frame)
2326 if (_roll_delay > nframes) {
2328 _roll_delay -= nframes;
2329 silence (nframes, offset);
2330 /* transport frame is not legal for caller to use */
2333 } else if (_roll_delay > 0) {
2335 nframes -= _roll_delay;
2337 silence (_roll_delay, offset);
2339 offset += _roll_delay;
2340 transport_frame += _roll_delay;
2349 Route::roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset, int declick,
2350 bool can_record, bool rec_monitors_input)
2353 Glib::RWLock::ReaderLock lm (redirect_lock, Glib::TRY_LOCK);
2355 // automation snapshot can also be called from the non-rt context
2356 // and it uses the redirect list, so we take the lock out here
2357 automation_snapshot (_session.transport_frame(), false);
2361 if ((n_outputs() == 0 && _redirects.empty()) || n_inputs() == 0 || !_active) {
2362 silence (nframes, offset);
2366 nframes_t unused = 0;
2368 if ((nframes = check_initial_delay (nframes, offset, unused)) == 0) {
2374 apply_gain_automation = false;
2377 Glib::Mutex::Lock am (automation_lock, Glib::TRY_LOCK);
2379 if (am.locked() && _session.transport_rolling()) {
2381 nframes_t start_frame = end_frame - nframes;
2383 if (gain_automation_playback()) {
2384 apply_gain_automation = _gain_automation_curve.rt_safe_get_vector (start_frame, end_frame, _session.gain_automation_buffer(), nframes);
2389 passthru (start_frame, end_frame, nframes, offset, declick, false);
2395 Route::silent_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
2396 bool can_record, bool rec_monitors_input)
2398 silence (nframes, offset);
2403 Route::toggle_monitor_input ()
2405 for (vector<Port*>::iterator i = _inputs.begin(); i != _inputs.end(); ++i) {
2406 (*i)->ensure_monitor_input(!(*i)->monitoring_input());
2411 Route::has_external_redirects () const
2413 boost::shared_ptr<const PortInsert> pi;
2415 for (RedirectList::const_iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2416 if ((pi = boost::dynamic_pointer_cast<const PortInsert>(*i)) != 0) {
2418 uint32_t no = pi->n_outputs();
2420 for (uint32_t n = 0; n < no; ++n) {
2422 string port_name = pi->output(n)->name();
2423 string client_name = port_name.substr (0, port_name.find(':'));
2425 /* only say "yes" if the redirect is actually in use */
2427 if (client_name != "ardour" && pi->active()) {
2438 Route::flush_redirects ()
2440 /* XXX shouldn't really try to take this lock, since
2441 this is called from the RT audio thread.
2444 Glib::RWLock::ReaderLock lm (redirect_lock);
2446 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2447 (*i)->deactivate ();
2453 Route::set_meter_point (MeterPoint p, void *src)
2455 if (_meter_point != p) {
2457 meter_change (src); /* EMIT SIGNAL */
2458 _session.set_dirty ();
2463 Route::update_total_latency ()
2467 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2468 if ((*i)->active ()) {
2469 _own_latency += (*i)->latency ();
2473 #undef DEBUG_LATENCY
2474 #ifdef DEBUG_LATENCY
2475 cerr << _name << ": internal redirect latency = " << _own_latency << endl;
2478 set_port_latency (_own_latency);
2480 /* this (virtual) function is used for pure Routes,
2481 not derived classes like AudioTrack. this means
2482 that the data processed here comes from an input
2483 port, not prerecorded material, and therefore we
2484 have to take into account any input latency.
2487 _own_latency += input_latency ();
2489 #ifdef DEBUG_LATENCY
2490 cerr << _name << ": input latency = " << input_latency() << " total = "
2491 << _own_latency << endl;
2494 return _own_latency;
2498 Route::set_latency_delay (nframes_t longest_session_latency)
2500 _initial_delay = longest_session_latency - _own_latency;
2502 if (_session.transport_stopped()) {
2503 _roll_delay = _initial_delay;
2508 Route::automation_snapshot (nframes_t now, bool force)
2510 if (!force && !should_snapshot(now)) {
2514 IO::automation_snapshot (now, force);
2516 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2517 (*i)->automation_snapshot (now, force);
2521 Route::ToggleControllable::ToggleControllable (std::string name, Route& s, ToggleType tp)
2522 : Controllable (name), route (s), type(tp)
2528 Route::ToggleControllable::set_value (float val)
2530 bool bval = ((val >= 0.5f) ? true: false);
2534 route.set_mute (bval, this);
2537 route.set_solo (bval, this);
2545 Route::ToggleControllable::get_value (void) const
2551 val = route.muted() ? 1.0f : 0.0f;
2554 val = route.soloed() ? 1.0f : 0.0f;
2564 Route::set_block_size (nframes_t nframes)
2566 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2567 (*i)->set_block_size (nframes);
2572 Route::redirect_active_proxy (Redirect* ignored, void* ignored_src)
2574 _session.update_latency_compensation (false, false);
2578 Route::protect_automation ()
2580 switch (gain_automation_state()) {
2582 set_gain_automation_state (Off);
2584 set_gain_automation_state (Play);
2590 switch (panner().automation_state ()) {
2592 panner().set_automation_state (Off);
2595 panner().set_automation_state (Play);
2601 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2602 boost::shared_ptr<PluginInsert> pi;
2603 if ((pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2604 pi->protect_automation ();
2610 Route::set_pending_declick (int declick)
2613 /* this call is not allowed to turn off a pending declick unless "force" is true */
2615 _pending_declick = declick;
2617 // cerr << _name << ": after setting to " << declick << " pending declick = " << _pending_declick << endl;
2619 _pending_declick = 0;
2624 /** Shift automation forwards from a particular place, thereby inserting time.
2625 * Adds undo commands for any shifts that are performed.
2627 * @param pos Position to start shifting from.
2628 * @param frames Amount to shift forwards by.
2632 Route::shift (nframes64_t pos, nframes64_t frames)
2634 /* gain automation */
2635 XMLNode &before = _gain_automation_curve.get_state ();
2636 _gain_automation_curve.shift (pos, frames);
2637 XMLNode &after = _gain_automation_curve.get_state ();
2638 _session.add_command (new MementoCommand<AutomationList> (_gain_automation_curve, &before, &after));
2640 /* pan automation */
2641 for (std::vector<StreamPanner*>::iterator i = _panner->begin (); i != _panner->end (); ++i) {
2642 Curve & c = (*i)->automation ();
2643 XMLNode &before = c.get_state ();
2644 c.shift (pos, frames);
2645 XMLNode &after = c.get_state ();
2646 _session.add_command (new MementoCommand<AutomationList> (c, &before, &after));
2649 /* redirect automation */
2651 Glib::RWLock::ReaderLock lm (redirect_lock);
2652 for (RedirectList::iterator i = _redirects.begin (); i != _redirects.end (); ++i) {
2655 (*i)->what_has_automation (a);
2657 for (set<uint32_t>::const_iterator j = a.begin (); j != a.end (); ++j) {
2658 AutomationList & al = (*i)->automation_list (*j);
2659 XMLNode &before = al.get_state ();
2660 al.shift (pos, frames);
2661 XMLNode &after = al.get_state ();
2662 _session.add_command (new MementoCommand<AutomationList> (al, &before, &after));
2669 Route::save_as_template (const string& path, const string& name)
2671 XMLNode& node (state (false));
2674 IO::set_name_in_state (*node.children().front(), name);
2676 tree.set_root (&node);
2677 return tree.write (path.c_str());