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>
29 #include <ardour/timestamps.h>
30 #include <ardour/buffer.h>
31 #include <ardour/audioengine.h>
32 #include <ardour/route.h>
33 #include <ardour/insert.h>
34 #include <ardour/send.h>
35 #include <ardour/session.h>
36 #include <ardour/utils.h>
37 #include <ardour/configuration.h>
38 #include <ardour/cycle_timer.h>
39 #include <ardour/route_group.h>
40 #include <ardour/port.h>
41 #include <ardour/ladspa_plugin.h>
42 #include <ardour/panner.h>
43 #include <ardour/dB.h>
44 #include <ardour/mix.h>
45 #include <ardour/profile.h>
50 using namespace ARDOUR;
53 uint32_t Route::order_key_cnt = 0;
54 sigc::signal<void,const char*> Route::SyncOrderKeys;
56 Route::Route (Session& sess, string name, int input_min, int input_max, int output_min, int output_max, Flag flg, DataType default_type)
57 : IO (sess, name, input_min, input_max, output_min, output_max, default_type),
59 _solo_control (X_("solo"), *this, ToggleControllable::SoloControl),
60 _mute_control (X_("mute"), *this, ToggleControllable::MuteControl)
65 Route::Route (Session& sess, const XMLNode& node, DataType default_type)
66 : IO (sess, *node.child ("IO"), default_type),
67 _solo_control (X_("solo"), *this, ToggleControllable::SoloControl),
68 _mute_control (X_("mute"), *this, ToggleControllable::MuteControl)
71 _set_state (node, false);
77 redirect_max_outs = 0;
81 _phase_invert = false;
82 _denormal_protection = false;
83 order_keys[strdup (N_("signal"))] = order_key_cnt++;
85 _meter_point = MeterPostFader;
89 _have_internal_generator = false;
91 _pending_declick = true;
92 _remote_control_id = 0;
93 _ignore_gain_on_deliver = true;
98 _mute_affects_pre_fader = Config->get_mute_affects_pre_fader();
99 _mute_affects_post_fader = Config->get_mute_affects_post_fader();
100 _mute_affects_control_outs = Config->get_mute_affects_control_outs();
101 _mute_affects_main_outs = Config->get_mute_affects_main_outs();
104 desired_solo_gain = 1.0;
106 desired_mute_gain = 1.0;
110 input_changed.connect (mem_fun (this, &Route::input_change_handler));
111 output_changed.connect (mem_fun (this, &Route::output_change_handler));
116 clear_redirects (PreFader, this);
117 clear_redirects (PostFader, this);
119 for (OrderKeys::iterator i = order_keys.begin(); i != order_keys.end(); ++i) {
120 free ((void*)(i->first));
124 delete _control_outs;
129 Route::set_remote_control_id (uint32_t id)
131 if (id != _remote_control_id) {
132 _remote_control_id = id;
133 RemoteControlIDChanged ();
138 Route::remote_control_id() const
140 return _remote_control_id;
144 Route::order_key (const char* name) const
146 OrderKeys::const_iterator i;
148 for (i = order_keys.begin(); i != order_keys.end(); ++i) {
149 if (!strcmp (name, i->first)) {
158 Route::set_order_key (const char* name, long n)
160 order_keys[strdup(name)] = n;
162 if (Config->get_sync_all_route_ordering()) {
163 for (OrderKeys::iterator x = order_keys.begin(); x != order_keys.end(); ++x) {
168 _session.set_dirty ();
172 Route::sync_order_keys (const char* base)
174 if (order_keys.empty()) {
178 OrderKeys::iterator i;
181 if ((i = order_keys.find (base)) == order_keys.end()) {
182 /* key doesn't exist, use the first existing
183 key (this is done during session initialization)
185 i = order_keys.begin();
189 /* key exists - use it and reset all others
190 (actually, itself included)
192 i = order_keys.begin();
196 for (; i != order_keys.end(); ++i) {
202 Route::ensure_track_or_route_name(string name, Session &session)
204 string newname = name;
206 while (session.route_by_name (newname)!=NULL)
208 newname = bump_name_once (newname);
216 Route::inc_gain (gain_t fraction, void *src)
218 IO::inc_gain (fraction, src);
222 Route::set_gain (gain_t val, void *src)
224 if (src != 0 && _mix_group && src != _mix_group && _mix_group->is_active()) {
226 if (_mix_group->is_relative()) {
229 gain_t usable_gain = gain();
230 if (usable_gain < 0.000001f) {
231 usable_gain=0.000001f;
235 if (delta < 0.000001f) {
239 delta -= usable_gain;
241 if (delta == 0.0f) return;
243 gain_t factor = delta / usable_gain;
246 factor = _mix_group->get_max_factor(factor);
247 if (factor == 0.0f) {
252 factor = _mix_group->get_min_factor(factor);
253 if (factor == 0.0f) {
259 _mix_group->apply (&Route::inc_gain, factor, _mix_group);
263 _mix_group->apply (&Route::set_gain, val, _mix_group);
273 IO::set_gain (val, src);
277 Route::process_output_buffers (vector<Sample*>& bufs, uint32_t nbufs,
278 nframes_t start_frame, nframes_t end_frame,
279 nframes_t nframes, nframes_t offset, bool with_redirects, int declick,
283 RedirectList::iterator i;
284 bool post_fader_work = false;
285 bool mute_declick_applied = false;
287 vector<Sample*>::iterator bufiter;
292 gain_t* gab = _session.gain_automation_buffer();
294 switch (Config->get_monitoring_model()) {
295 case HardwareMonitoring:
296 case ExternalMonitoring:
303 declick = _pending_declick;
306 Glib::Mutex::Lock cm (control_outs_lock, Glib::TRY_LOCK);
316 Glib::Mutex::Lock dm (declick_lock, Glib::TRY_LOCK);
319 dmg = desired_mute_gain;
320 dsg = desired_solo_gain;
329 /* ----------------------------------------------------------------------------------------------------
330 GLOBAL DECLICK (for transport changes etc.)
331 -------------------------------------------------------------------------------------------------- */
334 apply_declick (bufs, nbufs, nframes, 0.0, 1.0, false);
335 _pending_declick = 0;
336 } else if (declick < 0) {
337 apply_declick (bufs, nbufs, nframes, 1.0, 0.0, false);
338 _pending_declick = 0;
341 /* no global declick */
343 if (solo_gain != dsg) {
344 apply_declick (bufs, nbufs, nframes, solo_gain, dsg, false);
350 /* ----------------------------------------------------------------------------------------------------
351 INPUT METERING & MONITORING
352 -------------------------------------------------------------------------------------------------- */
354 if (meter && (_meter_point == MeterInput)) {
355 for (n = 0; n < nbufs; ++n) {
356 _peak_power[n] = Session::compute_peak (bufs[n], nframes, _peak_power[n]);
360 if (!_soloed && _mute_affects_pre_fader && (mute_gain != dmg)) {
361 apply_declick (bufs, nbufs, nframes, mute_gain, dmg, false);
363 mute_declick_applied = true;
366 if ((_meter_point == MeterInput) && co) {
368 solo_audible = dsg > 0;
369 mute_audible = dmg > 0;// || !_mute_affects_pre_fader;
371 if ( // muted by solo of another track
375 // muted by mute of this track
379 // rec-enabled but not s/w monitoring
381 // TODO: this is probably wrong
383 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
387 co->silence (nframes, offset);
391 co->deliver_output (bufs, nbufs, nframes, offset);
396 /* -----------------------------------------------------------------------------------------------------
398 -------------------------------------------------------------------------------------------------- */
400 if (_denormal_protection || Config->get_denormal_protection()) {
402 for (n = 0; n < nbufs; ++n) {
403 Sample *sp = bufs[n];
405 for (nframes_t nx = offset; nx < nframes + offset; ++nx) {
412 /* ----------------------------------------------------------------------------------------------------
414 -------------------------------------------------------------------------------------------------- */
416 if (with_redirects) {
417 Glib::RWLock::ReaderLock rm (redirect_lock, Glib::TRY_LOCK);
419 if (mute_gain > 0 || !_mute_affects_pre_fader) {
420 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
421 switch ((*i)->placement()) {
424 if (boost::dynamic_pointer_cast<Send>(*i) || boost::dynamic_pointer_cast<PortInsert>(*i)) {
425 (*i)->silence (nframes, offset);
428 (*i)->run (bufs, nbufs, nframes, offset);
432 post_fader_work = true;
437 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
438 switch ((*i)->placement()) {
440 (*i)->silence (nframes, offset);
443 post_fader_work = true;
452 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_post_fader) {
453 apply_declick (bufs, nbufs, nframes, mute_gain, dmg, false);
455 mute_declick_applied = true;
458 /* ----------------------------------------------------------------------------------------------------
459 PRE-FADER METERING & MONITORING
460 -------------------------------------------------------------------------------------------------- */
462 if (meter && (_meter_point == MeterPreFader)) {
463 for (n = 0; n < nbufs; ++n) {
464 _peak_power[n] = Session::compute_peak (bufs[n], nframes, _peak_power[n]);
469 if ((_meter_point == MeterPreFader) && co) {
471 solo_audible = dsg > 0;
472 mute_audible = dmg > 0 || !_mute_affects_pre_fader;
474 if ( // muted by solo of another track
478 // muted by mute of this track
482 // rec-enabled but not s/w monitoring
484 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
488 co->silence (nframes, offset);
492 co->deliver_output_no_pan (bufs, nbufs, nframes, offset);
497 /* ----------------------------------------------------------------------------------------------------
499 -------------------------------------------------------------------------------------------------- */
501 /* if not recording or recording and requiring any monitor signal, then apply gain */
503 if ( // not recording
505 !(record_enabled() && _session.actively_recording()) ||
509 // AND software monitoring required
511 (Config->get_monitoring_model() == SoftwareMonitoring)) {
513 if (apply_gain_automation) {
516 for (n = 0; n < nbufs; ++n) {
517 Sample *sp = bufs[n];
519 for (nframes_t nx = 0; nx < nframes; ++nx) {
524 for (n = 0; n < nbufs; ++n) {
525 Sample *sp = bufs[n];
527 for (nframes_t nx = 0; nx < nframes; ++nx) {
533 if (apply_gain_automation && _session.transport_rolling() && nframes > 0) {
534 _effective_gain = gab[nframes-1];
539 /* manual (scalar) gain */
543 apply_declick (bufs, nbufs, nframes, _gain, dg, _phase_invert);
546 } else if (_gain != 0 && (_phase_invert || _gain != 1.0)) {
548 /* no need to interpolate current gain value,
549 but its non-unity, so apply it. if the gain
550 is zero, do nothing because we'll ship silence
562 for (n = 0; n < nbufs; ++n) {
563 Sample *sp = bufs[n];
564 Session::apply_gain_to_buffer(sp,nframes,this_gain);
567 } else if (_gain == 0) {
568 for (n = 0; n < nbufs; ++n) {
569 memset (bufs[n], 0, sizeof (Sample) * nframes);
576 /* actively recording, no monitoring required; leave buffers as-is to save CPU cycles */
580 /* ----------------------------------------------------------------------------------------------------
582 -------------------------------------------------------------------------------------------------- */
584 /* note that post_fader_work cannot be true unless with_redirects was also true, so don't test both */
586 if (post_fader_work) {
588 Glib::RWLock::ReaderLock rm (redirect_lock, Glib::TRY_LOCK);
590 if (mute_gain > 0 || !_mute_affects_post_fader) {
591 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
592 switch ((*i)->placement()) {
597 if (boost::dynamic_pointer_cast<Send>(*i) || boost::dynamic_pointer_cast<PortInsert>(*i)) {
598 (*i)->silence (nframes, offset);
601 (*i)->run (bufs, nbufs, nframes, offset);
607 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
608 switch ((*i)->placement()) {
612 (*i)->silence (nframes, offset);
620 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_control_outs) {
621 apply_declick (bufs, nbufs, nframes, mute_gain, dmg, false);
623 mute_declick_applied = true;
626 /* ----------------------------------------------------------------------------------------------------
628 -------------------------------------------------------------------------------------------------- */
630 if ((_meter_point == MeterPostFader) && co) {
632 solo_audible = solo_gain > 0;
633 mute_audible = dmg > 0 || !_mute_affects_control_outs;
635 if ( // silent anyway
637 (_gain == 0 && !apply_gain_automation) ||
639 // muted by solo of another track
643 // muted by mute of this track
647 // recording but not s/w monitoring
649 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
653 co->silence (nframes, offset);
657 co->deliver_output_no_pan (bufs, nbufs, nframes, offset);
661 /* ----------------------------------------------------------------------
663 ----------------------------------------------------------------------*/
665 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_main_outs) {
666 apply_declick (bufs, nbufs, nframes, mute_gain, dmg, false);
668 mute_declick_applied = true;
671 /* ----------------------------------------------------------------------------------------------------
673 -------------------------------------------------------------------------------------------------- */
675 solo_audible = dsg > 0;
676 mute_audible = dmg > 0 || !_mute_affects_main_outs;
678 if (n_outputs() == 0) {
682 } else if (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording())) {
684 IO::silence (nframes, offset);
688 if ( // silent anyway
690 (_gain == 0 && !apply_gain_automation) ||
692 // muted by solo of another track, but not using control outs for solo
694 (!solo_audible && (Config->get_solo_model() != SoloBus)) ||
696 // muted by mute of this track
702 /* don't use Route::silence() here, because that causes
703 all outputs (sends, port inserts, etc. to be silent).
706 if (_meter_point == MeterPostFader) {
707 reset_peak_meters ();
710 IO::silence (nframes, offset);
714 if ((_session.transport_speed() > 1.5f ||
715 _session.transport_speed() < -1.5f) &&
716 Config->get_quieten_at_speed()) {
717 pan (bufs, nbufs, nframes, offset, speed_quietning);
719 // cerr << _name << " panner state = " << _panner->automation_state() << endl;
720 if (!_panner->empty() &&
721 (_panner->automation_state() & Play ||
722 ((_panner->automation_state() & Touch) && !_panner->touching()))) {
723 pan_automated (bufs, nbufs, start_frame, end_frame, nframes, offset);
725 pan (bufs, nbufs, nframes, offset, 1.0);
732 /* ----------------------------------------------------------------------------------------------------
734 -------------------------------------------------------------------------------------------------- */
736 if (meter && (_meter_point == MeterPostFader)) {
738 if ((_gain == 0 && !apply_gain_automation) || dmg == 0) {
739 uint32_t no = n_outputs();
740 for (n = 0; n < no; ++n) {
744 uint32_t no = n_outputs();
745 for (n = 0; n < no; ++n) {
746 _peak_power[n] = Session::compute_peak (output(n)->get_buffer (nframes) + offset, nframes, _peak_power[n]);
753 Route::n_process_buffers ()
755 return max (n_inputs(), redirect_max_outs);
760 Route::passthru (nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset, int declick, bool meter_first)
762 vector<Sample*>& bufs = _session.get_passthru_buffers();
763 uint32_t limit = n_process_buffers ();
767 collect_input (bufs, limit, nframes, offset);
769 #define meter_stream meter_first
772 for (uint32_t n = 0; n < limit; ++n) {
773 _peak_power[n] = Session::compute_peak (bufs[n], nframes, _peak_power[n]);
775 meter_stream = false;
780 process_output_buffers (bufs, limit, start_frame, end_frame, nframes, offset, true, declick, meter_stream);
786 Route::set_phase_invert (bool yn, void *src)
788 if (_phase_invert != yn) {
790 // phase_invert_changed (src); /* EMIT SIGNAL */
795 Route::set_denormal_protection (bool yn, void *src)
797 if (_denormal_protection != yn) {
798 _denormal_protection = yn;
799 // denormal_protection_changed (src); /* EMIT SIGNAL */
804 Route::set_solo (bool yn, void *src)
810 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
811 _mix_group->apply (&Route::set_solo, yn, _mix_group);
817 solo_changed (src); /* EMIT SIGNAL */
818 _solo_control.Changed (); /* EMIT SIGNAL */
821 catch_up_on_solo_mute_override ();
825 Route::catch_up_on_solo_mute_override ()
827 if (Config->get_solo_model() != InverseMute) {
833 Glib::Mutex::Lock lm (declick_lock);
836 if (Config->get_solo_mute_override()) {
837 desired_mute_gain = (_soloed?1.0:0.0);
839 desired_mute_gain = 0.0;
842 desired_mute_gain = 1.0;
848 Route::set_solo_mute (bool yn)
850 Glib::Mutex::Lock lm (declick_lock);
852 /* Called by Session in response to another Route being soloed.
855 desired_solo_gain = (yn?0.0:1.0);
859 Route::set_solo_safe (bool yn, void *src)
861 if (_solo_safe != yn) {
863 solo_safe_changed (src); /* EMIT SIGNAL */
868 Route::set_mute (bool yn, void *src)
871 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
872 _mix_group->apply (&Route::set_mute, yn, _mix_group);
878 mute_changed (src); /* EMIT SIGNAL */
880 _mute_control.Changed (); /* EMIT SIGNAL */
882 Glib::Mutex::Lock lm (declick_lock);
884 if (_soloed && Config->get_solo_mute_override()){
885 desired_mute_gain = 1.0f;
887 desired_mute_gain = (yn?0.0f:1.0f);
893 Route::add_redirect (boost::shared_ptr<Redirect> redirect, void *src, uint32_t* err_streams)
895 uint32_t old_rmo = redirect_max_outs;
897 if (!_session.engine().connected()) {
902 Glib::RWLock::WriterLock lm (redirect_lock);
904 boost::shared_ptr<PluginInsert> pi;
905 boost::shared_ptr<PortInsert> porti;
907 _redirects.push_back (redirect);
909 if (_reset_plugin_counts (err_streams)) {
910 _redirects.pop_back ();
911 _reset_plugin_counts (0); // it worked before we tried to add it ...
915 uint32_t potential_max_streams = 0;
917 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(redirect)) != 0) {
919 if (pi->input_streams() == 0) {
920 /* instrument plugin */
921 _have_internal_generator = true;
924 potential_max_streams = max(pi->input_streams(), pi->output_streams());
926 } else if ((porti = boost::dynamic_pointer_cast<PortInsert>(redirect)) != 0) {
928 /* force new port inserts to start out with an i/o configuration
929 that matches this route's i/o configuration.
931 the "inputs" for the port are supposed to match the output
934 the "outputs" of the route should match the inputs of this
935 route. XXX shouldn't they match the number of active signal
936 streams at the point of insertion?
940 porti->ensure_io (n_outputs (), n_inputs(), false, this);
943 // Ensure peak vector sizes before the plugin is activated
944 while (_peak_power.size() < potential_max_streams) {
945 _peak_power.push_back(0);
947 while (_visible_peak_power.size() < potential_max_streams) {
948 _visible_peak_power.push_back(-INFINITY);
950 while (_max_peak_power.size() < potential_max_streams) {
951 _max_peak_power.push_back(-INFINITY);
954 redirect->active_changed.connect (mem_fun (*this, &Route::redirect_active_proxy));
957 if (redirect_max_outs != old_rmo || old_rmo == 0) {
961 redirects_changed (src); /* EMIT SIGNAL */
967 Route::add_redirects (const RedirectList& others, void *src, uint32_t* err_streams)
969 uint32_t old_rmo = redirect_max_outs;
971 assert (ports_legal);
973 if (!_session.engine().connected()) {
978 Glib::RWLock::WriterLock lm (redirect_lock);
980 RedirectList::iterator existing_end = _redirects.end();
983 uint32_t potential_max_streams = 0;
985 for (RedirectList::const_iterator i = others.begin(); i != others.end(); ++i) {
987 boost::shared_ptr<PluginInsert> pi;
989 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
992 uint32_t m = max(pi->input_streams(), pi->output_streams());
993 if (m > potential_max_streams)
994 potential_max_streams = m;
997 // Ensure peak vector sizes before the plugin is activated
998 while (_peak_power.size() < potential_max_streams) {
999 _peak_power.push_back(0);
1001 while (_visible_peak_power.size() < potential_max_streams) {
1002 _visible_peak_power.push_back(-INFINITY);
1004 while (_max_peak_power.size() < potential_max_streams) {
1005 _max_peak_power.push_back(-INFINITY);
1008 _redirects.push_back (*i);
1010 if (_reset_plugin_counts (err_streams)) {
1012 _redirects.erase (existing_end, _redirects.end());
1013 _reset_plugin_counts (0); // it worked before we tried to add it ...
1017 (*i)->active_changed.connect (mem_fun (*this, &Route::redirect_active_proxy));
1021 if (redirect_max_outs != old_rmo || old_rmo == 0) {
1025 redirects_changed (src); /* EMIT SIGNAL */
1029 /** Remove redirects with a given placement.
1030 * @param p Placement of redirects to remove.
1033 Route::clear_redirects (Placement p, void *src)
1035 const uint32_t old_rmo = redirect_max_outs;
1037 if (!_session.engine().connected()) {
1042 Glib::RWLock::WriterLock lm (redirect_lock);
1043 RedirectList new_list;
1045 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
1046 if ((*i)->placement() == p) {
1047 /* it's the placement we want to get rid of */
1048 (*i)->drop_references ();
1050 /* it's a different placement, so keep it */
1051 new_list.push_back (*i);
1055 _redirects = new_list;
1058 /* FIXME: can't see how this test can ever fire */
1059 if (redirect_max_outs != old_rmo) {
1063 redirect_max_outs = 0;
1064 _have_internal_generator = false;
1065 redirects_changed (src); /* EMIT SIGNAL */
1069 Route::remove_redirect (boost::shared_ptr<Redirect> redirect, void *src, uint32_t* err_streams)
1071 uint32_t old_rmo = redirect_max_outs;
1073 assert (ports_legal);
1075 if (!_session.engine().connected()) {
1079 redirect_max_outs = 0;
1082 Glib::RWLock::WriterLock lm (redirect_lock);
1083 RedirectList::iterator i;
1084 bool removed = false;
1086 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
1087 if (*i == redirect) {
1089 RedirectList::iterator tmp;
1091 /* move along, see failure case for reset_plugin_counts()
1092 where we may need to reinsert the redirect.
1098 /* stop redirects that send signals to JACK ports
1099 from causing noise as a result of no longer being
1103 boost::shared_ptr<Send> send;
1104 boost::shared_ptr<PortInsert> port_insert;
1106 if ((send = boost::dynamic_pointer_cast<Send> (*i)) != 0) {
1107 send->disconnect_inputs (this);
1108 send->disconnect_outputs (this);
1109 } else if ((port_insert = boost::dynamic_pointer_cast<PortInsert> (*i)) != 0) {
1110 port_insert->disconnect_inputs (this);
1111 port_insert->disconnect_outputs (this);
1114 _redirects.erase (i);
1127 if (_reset_plugin_counts (err_streams)) {
1128 /* get back to where we where */
1129 _redirects.insert (i, redirect);
1130 /* we know this will work, because it worked before :) */
1131 _reset_plugin_counts (0);
1135 _have_internal_generator = false;
1137 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
1138 boost::shared_ptr<PluginInsert> pi;
1140 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1141 if (pi->is_generator()) {
1142 _have_internal_generator = true;
1149 if (old_rmo != redirect_max_outs) {
1153 redirect->drop_references ();
1155 redirects_changed (src); /* EMIT SIGNAL */
1160 Route::reset_plugin_counts (uint32_t* lpc)
1162 Glib::RWLock::WriterLock lm (redirect_lock);
1163 return _reset_plugin_counts (lpc);
1168 Route::_reset_plugin_counts (uint32_t* err_streams)
1170 RedirectList::iterator r;
1171 uint32_t insert_cnt = 0;
1172 uint32_t send_cnt = 0;
1173 map<Placement,list<InsertCount> > insert_map;
1174 RedirectList::iterator prev;
1175 int32_t initial_streams = n_inputs ();;
1176 int32_t previous_initial_streams = n_inputs ();
1179 redirect_max_outs = 0;
1181 /* Step 1: build a map that links each insert to an in/out channel count
1183 Divide inserts up by placement so we get the signal flow
1184 properly modelled. we need to do this because the _redirects
1185 list is not sorted by placement, and because other reasons may
1186 exist now or in the future for this separate treatment.
1189 for (r = _redirects.begin(); r != _redirects.end(); ++r) {
1191 boost::shared_ptr<Insert> insert;
1193 if ((insert = boost::dynamic_pointer_cast<Insert>(*r)) != 0) {
1195 insert_map[insert->placement()].push_back (InsertCount (insert));
1197 /* reset plugin counts back to one for now so
1198 that we have a predictable, controlled
1199 state to try to configure.
1202 boost::shared_ptr<PluginInsert> pi;
1204 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(insert)) != 0) {
1208 } else if (boost::dynamic_pointer_cast<Send> (*r) != 0) {
1213 if (insert_cnt == 0) {
1222 /* Now process each placement in order, checking to see if we
1223 can really do what has been requested.
1228 if (check_some_plugin_counts (insert_map[PreFader], n_inputs (), err_streams)) {
1232 /* figure out the streams that will feed into PreFader */
1234 if (!insert_map[PreFader].empty()) {
1235 previous_initial_streams = n_inputs ();
1236 for (list<InsertCount>::iterator i = insert_map[PreFader].begin(); i != insert_map[PreFader].end(); i++) {
1237 if (i->insert->can_do (previous_initial_streams, initial_streams) < 0) {
1240 previous_initial_streams = initial_streams;
1246 if (check_some_plugin_counts (insert_map[PostFader], initial_streams, err_streams)) {
1250 if (!insert_map[PostFader].empty()) {
1251 for (list<InsertCount>::iterator i = insert_map[PostFader].begin(); i != insert_map[PostFader].end(); i++) {
1252 if (i->insert->can_do (previous_initial_streams, initial_streams) < 0) {
1255 previous_initial_streams = initial_streams;
1259 /* OK, everything can be set up correctly, so lets do it */
1261 apply_some_plugin_counts (insert_map[PreFader]);
1262 apply_some_plugin_counts (insert_map[PostFader]);
1264 /* recompute max outs of any redirect */
1268 redirect_max_outs = 0;
1269 prev = _redirects.end();
1271 for (r = _redirects.begin(); r != _redirects.end(); prev = r, ++r) {
1272 boost::shared_ptr<Send> s;
1274 if ((s = boost::dynamic_pointer_cast<Send> (*r)) != 0) {
1275 if (r == _redirects.begin()) {
1276 s->expect_inputs (n_inputs());
1278 s->expect_inputs ((*prev)->output_streams());
1283 /* don't pay any attention to send output configuration, since it doesn't
1287 redirect_max_outs = max ((*r)->output_streams (), redirect_max_outs);
1296 for (r = _redirects.begin(); r != _redirects.end(); ++r) {
1297 redirect_max_outs = max ((*r)->output_streams (), redirect_max_outs);
1303 Route::apply_some_plugin_counts (list<InsertCount>& iclist)
1305 list<InsertCount>::iterator i;
1307 for (i = iclist.begin(); i != iclist.end(); ++i) {
1309 if ((*i).insert->configure_io ((*i).cnt, (*i).in, (*i).out)) {
1312 /* make sure that however many we have, they are all active */
1313 (*i).insert->activate ();
1320 Route::check_some_plugin_counts (list<InsertCount>& iclist, int32_t required_inputs, uint32_t* err_streams)
1322 list<InsertCount>::iterator i;
1324 for (i = iclist.begin(); i != iclist.end(); ++i) {
1326 if (((*i).cnt = (*i).insert->can_do (required_inputs, (*i).out)) < 0) {
1328 *err_streams = required_inputs;
1333 (*i).in = required_inputs;
1334 required_inputs = (*i).out;
1341 Route::copy_redirects (const Route& other, Placement placement, uint32_t* err_streams)
1343 uint32_t old_rmo = redirect_max_outs;
1349 RedirectList to_be_deleted;
1352 Glib::RWLock::WriterLock lm (redirect_lock);
1353 RedirectList::iterator tmp;
1354 RedirectList the_copy;
1356 the_copy = _redirects;
1358 /* remove all relevant redirects */
1360 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ) {
1364 if ((*i)->placement() == placement) {
1365 to_be_deleted.push_back (*i);
1366 _redirects.erase (i);
1372 /* now copy the relevant ones from "other" */
1374 for (RedirectList::const_iterator i = other._redirects.begin(); i != other._redirects.end(); ++i) {
1375 if ((*i)->placement() == placement) {
1376 _redirects.push_back (Redirect::clone (*i));
1380 /* reset plugin stream handling */
1382 if (_reset_plugin_counts (err_streams)) {
1384 /* FAILED COPY ATTEMPT: we have to restore order */
1386 /* delete all cloned redirects */
1388 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ) {
1393 if ((*i)->placement() == placement) {
1394 _redirects.erase (i);
1400 /* restore the natural order */
1402 _redirects = the_copy;
1403 redirect_max_outs = old_rmo;
1405 /* we failed, even though things are OK again */
1411 /* SUCCESSFUL COPY ATTEMPT: delete the redirects we removed pre-copy */
1412 to_be_deleted.clear ();
1416 if (redirect_max_outs != old_rmo || old_rmo == 0) {
1420 redirects_changed (this); /* EMIT SIGNAL */
1425 Route::all_redirects_flip ()
1427 Glib::RWLock::ReaderLock lm (redirect_lock);
1429 if (_redirects.empty()) {
1433 bool first_is_on = _redirects.front()->active();
1435 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
1436 (*i)->set_active (!first_is_on, this);
1440 /** Set all redirects with a given placement to a given active state.
1441 * @param p Placement of redirects to change.
1442 * @param state New active state for those redirects.
1445 Route::all_redirects_active (Placement p, bool state)
1447 Glib::RWLock::ReaderLock lm (redirect_lock);
1449 if (_redirects.empty()) {
1453 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
1454 if ((*i)->placement() == p) {
1455 (*i)->set_active (state, this);
1460 struct RedirectSorter {
1461 bool operator() (boost::shared_ptr<const Redirect> a, boost::shared_ptr<const Redirect> b) {
1462 return a->sort_key() < b->sort_key();
1467 Route::sort_redirects (uint32_t* err_streams)
1470 RedirectSorter comparator;
1471 Glib::RWLock::WriterLock lm (redirect_lock);
1472 uint32_t old_rmo = redirect_max_outs;
1474 /* the sweet power of C++ ... */
1476 RedirectList as_it_was_before = _redirects;
1478 _redirects.sort (comparator);
1480 if (_reset_plugin_counts (err_streams)) {
1481 _redirects = as_it_was_before;
1482 redirect_max_outs = old_rmo;
1488 redirects_changed (this); /* EMIT SIGNAL */
1500 Route::get_template()
1502 return state(false);
1506 Route::state(bool full_state)
1508 XMLNode *node = new XMLNode("Route");
1509 RedirectList:: iterator i;
1513 node->add_property("flags", enum_2_string (_flags));
1516 node->add_property("default-type", _default_type.to_string());
1518 node->add_property("muted", _muted?"yes":"no");
1519 node->add_property("soloed", _soloed?"yes":"no");
1520 node->add_property("phase-invert", _phase_invert?"yes":"no");
1521 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
1522 node->add_property("mute-affects-pre-fader", _mute_affects_pre_fader?"yes":"no");
1523 node->add_property("mute-affects-post-fader", _mute_affects_post_fader?"yes":"no");
1524 node->add_property("mute-affects-control-outs", _mute_affects_control_outs?"yes":"no");
1525 node->add_property("mute-affects-main-outs", _mute_affects_main_outs?"yes":"no");
1528 node->add_property("edit-group", _edit_group->name());
1531 node->add_property("mix-group", _mix_group->name());
1534 string order_string;
1535 OrderKeys::iterator x = order_keys.begin();
1537 while (x != order_keys.end()) {
1538 order_string += string ((*x).first);
1539 order_string += '=';
1540 snprintf (buf, sizeof(buf), "%ld", (*x).second);
1541 order_string += buf;
1545 if (x == order_keys.end()) {
1549 order_string += ':';
1551 node->add_property ("order-keys", order_string);
1553 node->add_child_nocopy (IO::state (full_state));
1554 node->add_child_nocopy (_solo_control.get_state ());
1555 node->add_child_nocopy (_mute_control.get_state ());
1557 XMLNode* remote_control_node = new XMLNode (X_("remote_control"));
1558 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
1559 remote_control_node->add_property (X_("id"), buf);
1560 node->add_child_nocopy (*remote_control_node);
1562 if (_control_outs) {
1563 XMLNode* cnode = new XMLNode (X_("ControlOuts"));
1564 cnode->add_child_nocopy (_control_outs->state (full_state));
1565 node->add_child_nocopy (*cnode);
1568 if (_comment.length()) {
1569 XMLNode *cmt = node->add_child ("Comment");
1570 cmt->add_content (_comment);
1573 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
1574 node->add_child_nocopy((*i)->state (full_state));
1578 node->add_child_copy (*_extra_xml);
1585 Route::set_deferred_state ()
1588 XMLNodeConstIterator niter;
1590 if (!deferred_state) {
1594 nlist = deferred_state->children();
1596 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1597 add_redirect_from_xml (**niter);
1600 delete deferred_state;
1605 Route::add_redirect_from_xml (const XMLNode& node)
1607 const XMLProperty *prop;
1609 if (node.name() == "Send") {
1613 boost::shared_ptr<Send> send (new Send (_session, node));
1614 add_redirect (send, this);
1617 catch (failed_constructor &err) {
1618 error << _("Send construction failed") << endmsg;
1622 } else if (node.name() == "Insert") {
1625 if ((prop = node.property ("type")) != 0) {
1627 boost::shared_ptr<Insert> insert;
1628 bool have_insert = false;
1630 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
1631 prop->value() == "lv2" ||
1632 prop->value() == "vst" ||
1633 prop->value() == "audiounit") {
1635 insert.reset (new PluginInsert(_session, node));
1638 } else if (prop->value() == "port") {
1641 insert.reset (new PortInsert (_session, node));
1646 error << string_compose(_("unknown Insert type \"%1\"; ignored"), prop->value()) << endmsg;
1650 add_redirect (insert, this);
1654 error << _("Insert XML node has no type property") << endmsg;
1658 catch (failed_constructor &err) {
1659 warning << _("insert could not be created. Ignored.") << endmsg;
1666 Route::set_state (const XMLNode& node)
1668 return _set_state (node, true);
1672 Route::_set_state (const XMLNode& node, bool call_base)
1675 XMLNodeConstIterator niter;
1677 XMLPropertyList plist;
1678 const XMLProperty *prop;
1680 if (node.name() != "Route"){
1681 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
1685 if ((prop = node.property (X_("flags"))) != 0) {
1686 _flags = Flag (string_2_enum (prop->value(), _flags));
1691 if ((prop = node.property (X_("default-type"))) != 0) {
1692 _default_type = DataType(prop->value());
1693 assert(_default_type != DataType::NIL);
1696 if ((prop = node.property (X_("phase-invert"))) != 0) {
1697 set_phase_invert (prop->value()=="yes"?true:false, this);
1700 if ((prop = node.property (X_("denormal-protection"))) != 0) {
1701 set_denormal_protection (prop->value()=="yes"?true:false, this);
1704 if ((prop = node.property (X_("muted"))) != 0) {
1705 bool yn = prop->value()=="yes"?true:false;
1707 /* force reset of mute status */
1711 mute_gain = desired_mute_gain;
1714 if ((prop = node.property (X_("soloed"))) != 0) {
1715 bool yn = prop->value()=="yes"?true:false;
1717 /* force reset of solo status */
1720 set_solo (yn, this);
1721 solo_gain = desired_solo_gain;
1724 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
1725 _mute_affects_pre_fader = (prop->value()=="yes")?true:false;
1728 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
1729 _mute_affects_post_fader = (prop->value()=="yes")?true:false;
1732 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
1733 _mute_affects_control_outs = (prop->value()=="yes")?true:false;
1736 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
1737 _mute_affects_main_outs = (prop->value()=="yes")?true:false;
1740 if ((prop = node.property (X_("edit-group"))) != 0) {
1741 RouteGroup* edit_group = _session.edit_group_by_name(prop->value());
1742 if(edit_group == 0) {
1743 error << string_compose(_("Route %1: unknown edit group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
1745 set_edit_group(edit_group, this);
1749 if ((prop = node.property (X_("order-keys"))) != 0) {
1753 string::size_type colon, equal;
1754 string remaining = prop->value();
1756 while (remaining.length()) {
1758 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
1759 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1762 if (sscanf (remaining.substr (equal+1).c_str(), "%ld", &n) != 1) {
1763 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1766 set_order_key (remaining.substr (0, equal).c_str(), n);
1770 colon = remaining.find_first_of (':');
1772 if (colon != string::npos) {
1773 remaining = remaining.substr (colon+1);
1780 nlist = node.children();
1782 if (deferred_state) {
1783 delete deferred_state;
1786 deferred_state = new XMLNode(X_("deferred state"));
1788 /* set parent class properties before anything else */
1790 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1794 if (child->name() == IO::state_node_name && call_base) {
1796 IO::set_state (*child);
1802 XMLNodeList redirect_nodes;
1804 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1808 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
1809 redirect_nodes.push_back(child);
1814 _set_redirect_states (redirect_nodes);
1816 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1818 // All redirects (sends and inserts) have been applied already
1820 if (child->name() == X_("Automation")) {
1822 if ((prop = child->property (X_("path"))) != 0) {
1823 load_automation (prop->value());
1826 } else if (child->name() == X_("ControlOuts")) {
1828 string coutname = _name;
1829 coutname += _("[control]");
1831 _control_outs = new IO (_session, coutname);
1832 _control_outs->set_state (**(child->children().begin()));
1834 } else if (child->name() == X_("Comment")) {
1836 /* XXX this is a terrible API design in libxml++ */
1838 XMLNode *cmt = *(child->children().begin());
1839 _comment = cmt->content();
1841 } else if (child->name() == X_("extra")) {
1843 _extra_xml = new XMLNode (*child);
1845 } else if (child->name() == X_("controllable") && (prop = child->property("name")) != 0) {
1847 if (prop->value() == "solo") {
1848 _solo_control.set_state (*child);
1849 _session.add_controllable (&_solo_control);
1851 else if (prop->value() == "mute") {
1852 _mute_control.set_state (*child);
1853 _session.add_controllable (&_mute_control);
1856 else if (child->name() == X_("remote_control")) {
1857 if ((prop = child->property (X_("id"))) != 0) {
1859 sscanf (prop->value().c_str(), "%d", &x);
1860 set_remote_control_id (x);
1865 if ((prop = node.property (X_("mix-group"))) != 0) {
1866 RouteGroup* mix_group = _session.mix_group_by_name(prop->value());
1867 if (mix_group == 0) {
1868 error << string_compose(_("Route %1: unknown mix group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
1870 set_mix_group(mix_group, this);
1878 Route::_set_redirect_states(const XMLNodeList &nlist)
1880 XMLNodeConstIterator niter;
1883 RedirectList::iterator i, o;
1887 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1888 deferred_state->add_child_copy (**niter);
1894 // Iterate through existing redirects, remove those which are not in the state list
1895 for (i = _redirects.begin(); i != _redirects.end(); ) {
1896 RedirectList::iterator tmp = i;
1899 bool redirectInStateList = false;
1901 (*i)->id().print (buf, sizeof (buf));
1903 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1905 if (strncmp (buf,(*niter)->child(X_("Redirect"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf)) == 0) {
1906 redirectInStateList = true;
1911 if (!redirectInStateList) {
1912 remove_redirect ( *i, this);
1920 // Iterate through state list and make sure all redirects are on the track and in the correct order,
1921 // set the state of existing redirects according to the new state on the same go
1922 i = _redirects.begin();
1923 for (niter = nlist.begin(); niter != nlist.end(); ++niter, ++i) {
1925 // Check whether the next redirect in the list
1928 while (o != _redirects.end()) {
1929 (*o)->id().print (buf, sizeof (buf));
1930 if ( strncmp(buf, (*niter)->child(X_("Redirect"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf)) == 0)
1935 if (o == _redirects.end()) {
1936 // If the redirect (*niter) is not on the route, we need to create it
1937 // and move it to the correct location
1939 RedirectList::iterator prev_last = _redirects.end();
1940 --prev_last; // We need this to check whether adding succeeded
1942 add_redirect_from_xml (**niter);
1944 RedirectList::iterator last = _redirects.end();
1947 if (prev_last == last) {
1948 warning << _name << ": could not fully restore state as some redirects were not possible to create" << endmsg;
1953 boost::shared_ptr<Redirect> tmp = (*last);
1954 // remove the redirect from the wrong location
1955 _redirects.erase(last);
1956 // insert the new redirect at the current location
1957 _redirects.insert(i, tmp);
1959 --i; // move pointer to the newly inserted redirect
1963 // We found the redirect (*niter) on the route, first we must make sure the redirect
1964 // is at the location provided in the XML state
1966 boost::shared_ptr<Redirect> tmp = (*o);
1967 // remove the old copy
1968 _redirects.erase(o);
1969 // insert the redirect at the correct location
1970 _redirects.insert(i, tmp);
1972 --i; // move pointer so it points to the right redirect
1975 (*i)->set_state( (**niter) );
1978 redirects_changed(this);
1982 Route::curve_reallocate ()
1984 // _gain_automation_curve.finish_resize ();
1985 // _pan_automation_curve.finish_resize ();
1989 Route::silence (nframes_t nframes, nframes_t offset)
1993 // reset_peak_meters ();
1995 IO::silence (nframes, offset);
1997 if (_control_outs) {
1998 _control_outs->silence (nframes, offset);
2002 Glib::RWLock::ReaderLock lm (redirect_lock, Glib::TRY_LOCK);
2005 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2006 boost::shared_ptr<PluginInsert> pi;
2007 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2008 // skip plugins, they don't need anything when we're not active
2012 (*i)->silence (nframes, offset);
2015 if (nframes == _session.get_block_size() && offset == 0) {
2025 Route::set_control_outs (const vector<string>& ports)
2027 Glib::Mutex::Lock lm (control_outs_lock);
2028 vector<string>::const_iterator i;
2031 if (_control_outs) {
2032 delete _control_outs;
2036 if (control() || master()) {
2037 /* no control outs for these two special busses */
2041 if (ports.empty()) {
2045 string coutname = _name;
2046 coutname += _("[control]");
2048 _control_outs = new IO (_session, coutname);
2050 /* our control outs need as many outputs as we
2051 have outputs. we track the changes in ::output_change_handler().
2054 limit = n_outputs ();
2056 if (_control_outs->ensure_io (0, limit, true, this)) {
2060 /* now connect to the named ports */
2062 for (uint32_t n = 0; n < limit; ++n) {
2063 if (_control_outs->connect_output (_control_outs->output (n), ports[n % ports.size()], this)) {
2064 error << string_compose (_("could not connect %1 to %2"), _control_outs->output(n)->name(), ports[n]) << endmsg;
2073 Route::set_edit_group (RouteGroup *eg, void *src)
2076 if (eg == _edit_group) {
2081 _edit_group->remove (this);
2084 if ((_edit_group = eg) != 0) {
2085 _edit_group->add (this);
2088 _session.set_dirty ();
2089 edit_group_changed (src); /* EMIT SIGNAL */
2093 Route::drop_edit_group (void *src)
2096 _session.set_dirty ();
2097 edit_group_changed (src); /* EMIT SIGNAL */
2101 Route::set_mix_group (RouteGroup *mg, void *src)
2104 if (mg == _mix_group) {
2109 _mix_group->remove (this);
2112 if ((_mix_group = mg) != 0) {
2113 _mix_group->add (this);
2116 _session.set_dirty ();
2117 mix_group_changed (src); /* EMIT SIGNAL */
2121 Route::drop_mix_group (void *src)
2124 _session.set_dirty ();
2125 mix_group_changed (src); /* EMIT SIGNAL */
2129 Route::set_comment (string cmt, void *src)
2132 comment_changed (src);
2133 _session.set_dirty ();
2137 Route::feeds (boost::shared_ptr<Route> other)
2142 uint32_t no = self.n_outputs();
2143 uint32_t ni = other->n_inputs ();
2145 for (i = 0; i < no; ++i) {
2146 for (j = 0; j < ni; ++j) {
2147 if (self.output(i)->connected_to (other->input(j)->name())) {
2153 /* check Redirects which may also interconnect Routes */
2155 for (RedirectList::iterator r = _redirects.begin(); r != _redirects.end(); r++) {
2157 no = (*r)->n_outputs();
2159 for (i = 0; i < no; ++i) {
2160 for (j = 0; j < ni; ++j) {
2161 if ((*r)->output(i)->connected_to (other->input (j)->name())) {
2168 /* check for control room outputs which may also interconnect Routes */
2170 if (_control_outs) {
2172 no = _control_outs->n_outputs();
2174 for (i = 0; i < no; ++i) {
2175 for (j = 0; j < ni; ++j) {
2176 if (_control_outs->output(i)->connected_to (other->input (j)->name())) {
2187 Route::set_mute_config (mute_type t, bool onoff, void *src)
2191 _mute_affects_pre_fader = onoff;
2192 pre_fader_changed(src); /* EMIT SIGNAL */
2196 _mute_affects_post_fader = onoff;
2197 post_fader_changed(src); /* EMIT SIGNAL */
2201 _mute_affects_control_outs = onoff;
2202 control_outs_changed(src); /* EMIT SIGNAL */
2206 _mute_affects_main_outs = onoff;
2207 main_outs_changed(src); /* EMIT SIGNAL */
2213 Route::get_mute_config (mute_type t)
2219 onoff = _mute_affects_pre_fader;
2222 onoff = _mute_affects_post_fader;
2225 onoff = _mute_affects_control_outs;
2228 onoff = _mute_affects_main_outs;
2236 Route::handle_transport_stopped (bool abort_ignored, bool did_locate, bool can_flush_redirects)
2238 nframes_t now = _session.transport_frame();
2241 Glib::RWLock::ReaderLock lm (redirect_lock);
2244 automation_snapshot (now, true);
2247 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2249 if (Config->get_plugins_stop_with_transport() && can_flush_redirects) {
2250 (*i)->deactivate ();
2254 (*i)->transport_stopped (now);
2258 IO::transport_stopped (now);
2260 _roll_delay = _initial_delay;
2264 Route::input_change_handler (IOChange change, void *ignored)
2266 if (change & ConfigurationChanged) {
2267 reset_plugin_counts (0);
2272 Route::output_change_handler (IOChange change, void *ignored)
2274 if (change & ConfigurationChanged) {
2275 if (_control_outs) {
2276 _control_outs->ensure_io (0, n_outputs(), true, this);
2279 reset_plugin_counts (0);
2284 Route::pans_required () const
2286 if (n_outputs() < 2) {
2290 return max (n_inputs (), redirect_max_outs);
2294 Route::no_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
2295 bool session_state_changing, bool can_record, bool rec_monitors_input)
2297 if (n_outputs() == 0) {
2301 if (session_state_changing || !_active) {
2302 silence (nframes, offset);
2306 apply_gain_automation = false;
2309 passthru (start_frame, end_frame, nframes, offset, 0, false);
2311 silence (nframes, offset);
2318 Route::check_initial_delay (nframes_t nframes, nframes_t& offset, nframes_t& transport_frame)
2320 if (_roll_delay > nframes) {
2322 _roll_delay -= nframes;
2323 silence (nframes, offset);
2324 /* transport frame is not legal for caller to use */
2327 } else if (_roll_delay > 0) {
2329 nframes -= _roll_delay;
2331 silence (_roll_delay, offset);
2333 offset += _roll_delay;
2334 transport_frame += _roll_delay;
2343 Route::roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset, int declick,
2344 bool can_record, bool rec_monitors_input)
2347 Glib::RWLock::ReaderLock lm (redirect_lock, Glib::TRY_LOCK);
2349 // automation snapshot can also be called from the non-rt context
2350 // and it uses the redirect list, so we take the lock out here
2351 automation_snapshot (_session.transport_frame(), false);
2355 if ((n_outputs() == 0 && _redirects.empty()) || n_inputs() == 0 || !_active) {
2356 silence (nframes, offset);
2360 nframes_t unused = 0;
2362 if ((nframes = check_initial_delay (nframes, offset, unused)) == 0) {
2368 apply_gain_automation = false;
2371 Glib::Mutex::Lock am (automation_lock, Glib::TRY_LOCK);
2373 if (am.locked() && _session.transport_rolling()) {
2375 nframes_t start_frame = end_frame - nframes;
2377 if (gain_automation_playback()) {
2378 apply_gain_automation = _gain_automation_curve.rt_safe_get_vector (start_frame, end_frame, _session.gain_automation_buffer(), nframes);
2383 passthru (start_frame, end_frame, nframes, offset, declick, false);
2389 Route::silent_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
2390 bool can_record, bool rec_monitors_input)
2392 silence (nframes, offset);
2397 Route::toggle_monitor_input ()
2399 for (vector<Port*>::iterator i = _inputs.begin(); i != _inputs.end(); ++i) {
2400 (*i)->ensure_monitor_input(!(*i)->monitoring_input());
2405 Route::has_external_redirects () const
2407 boost::shared_ptr<const PortInsert> pi;
2409 for (RedirectList::const_iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2410 if ((pi = boost::dynamic_pointer_cast<const PortInsert>(*i)) != 0) {
2412 uint32_t no = pi->n_outputs();
2414 for (uint32_t n = 0; n < no; ++n) {
2416 string port_name = pi->output(n)->name();
2417 string client_name = port_name.substr (0, port_name.find(':'));
2419 /* only say "yes" if the redirect is actually in use */
2421 if (client_name != "ardour" && pi->active()) {
2432 Route::flush_redirects ()
2434 /* XXX shouldn't really try to take this lock, since
2435 this is called from the RT audio thread.
2438 Glib::RWLock::ReaderLock lm (redirect_lock);
2440 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2441 (*i)->deactivate ();
2447 Route::set_meter_point (MeterPoint p, void *src)
2449 if (_meter_point != p) {
2451 meter_change (src); /* EMIT SIGNAL */
2452 _session.set_dirty ();
2457 Route::update_total_latency ()
2461 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2462 if ((*i)->active ()) {
2463 _own_latency += (*i)->latency ();
2467 #undef DEBUG_LATENCY
2468 #ifdef DEBUG_LATENCY
2469 cerr << _name << ": internal redirect latency = " << _own_latency << endl;
2472 set_port_latency (_own_latency);
2474 /* this (virtual) function is used for pure Routes,
2475 not derived classes like AudioTrack. this means
2476 that the data processed here comes from an input
2477 port, not prerecorded material, and therefore we
2478 have to take into account any input latency.
2481 _own_latency += input_latency ();
2483 #ifdef DEBUG_LATENCY
2484 cerr << _name << ": input latency = " << input_latency() << " total = "
2485 << _own_latency << endl;
2488 return _own_latency;
2492 Route::set_latency_delay (nframes_t longest_session_latency)
2494 _initial_delay = longest_session_latency - _own_latency;
2496 if (_session.transport_stopped()) {
2497 _roll_delay = _initial_delay;
2502 Route::automation_snapshot (nframes_t now, bool force)
2504 if (!force && !should_snapshot(now)) {
2508 IO::automation_snapshot (now, force);
2510 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2511 (*i)->automation_snapshot (now, force);
2515 Route::ToggleControllable::ToggleControllable (std::string name, Route& s, ToggleType tp)
2516 : Controllable (name), route (s), type(tp)
2522 Route::ToggleControllable::set_value (float val)
2524 bool bval = ((val >= 0.5f) ? true: false);
2528 route.set_mute (bval, this);
2531 route.set_solo (bval, this);
2539 Route::ToggleControllable::get_value (void) const
2545 val = route.muted() ? 1.0f : 0.0f;
2548 val = route.soloed() ? 1.0f : 0.0f;
2558 Route::set_block_size (nframes_t nframes)
2560 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2561 (*i)->set_block_size (nframes);
2566 Route::redirect_active_proxy (Redirect* ignored, void* ignored_src)
2568 _session.update_latency_compensation (false, false);
2572 Route::protect_automation ()
2574 switch (gain_automation_state()) {
2576 set_gain_automation_state (Off);
2578 set_gain_automation_state (Play);
2584 switch (panner().automation_state ()) {
2586 panner().set_automation_state (Off);
2589 panner().set_automation_state (Play);
2595 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2596 boost::shared_ptr<PluginInsert> pi;
2597 if ((pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2598 pi->protect_automation ();
2604 Route::set_pending_declick (int declick)
2607 /* this call is not allowed to turn off a pending declick unless "force" is true */
2609 _pending_declick = declick;
2611 // cerr << _name << ": after setting to " << declick << " pending declick = " << _pending_declick << endl;
2613 _pending_declick = 0;