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> 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 ()
176 if (order_keys.empty()) {
180 OrderKeys::iterator x = order_keys.begin();
184 for (; x != order_keys.end(); ++x) {
190 Route::ensure_track_or_route_name(string name, Session &session)
192 string newname = name;
194 while (session.route_by_name (newname)!=NULL)
196 newname = bump_name_once (newname);
204 Route::inc_gain (gain_t fraction, void *src)
206 IO::inc_gain (fraction, src);
210 Route::set_gain (gain_t val, void *src)
212 if (src != 0 && _mix_group && src != _mix_group && _mix_group->is_active()) {
214 if (_mix_group->is_relative()) {
217 gain_t usable_gain = gain();
218 if (usable_gain < 0.000001f) {
219 usable_gain=0.000001f;
223 if (delta < 0.000001f) {
227 delta -= usable_gain;
229 if (delta == 0.0f) return;
231 gain_t factor = delta / usable_gain;
234 factor = _mix_group->get_max_factor(factor);
235 if (factor == 0.0f) {
240 factor = _mix_group->get_min_factor(factor);
241 if (factor == 0.0f) {
247 _mix_group->apply (&Route::inc_gain, factor, _mix_group);
251 _mix_group->apply (&Route::set_gain, val, _mix_group);
261 IO::set_gain (val, src);
265 Route::process_output_buffers (vector<Sample*>& bufs, uint32_t nbufs,
266 nframes_t start_frame, nframes_t end_frame,
267 nframes_t nframes, nframes_t offset, bool with_redirects, int declick,
271 RedirectList::iterator i;
272 bool post_fader_work = false;
273 bool mute_declick_applied = false;
275 vector<Sample*>::iterator bufiter;
280 gain_t* gab = _session.gain_automation_buffer();
282 switch (Config->get_monitoring_model()) {
283 case HardwareMonitoring:
284 case ExternalMonitoring:
291 declick = _pending_declick;
294 Glib::Mutex::Lock cm (control_outs_lock, Glib::TRY_LOCK);
304 Glib::Mutex::Lock dm (declick_lock, Glib::TRY_LOCK);
307 dmg = desired_mute_gain;
308 dsg = desired_solo_gain;
317 /* ----------------------------------------------------------------------------------------------------
318 GLOBAL DECLICK (for transport changes etc.)
319 -------------------------------------------------------------------------------------------------- */
322 apply_declick (bufs, nbufs, nframes, 0.0, 1.0, false);
323 _pending_declick = 0;
324 } else if (declick < 0) {
325 apply_declick (bufs, nbufs, nframes, 1.0, 0.0, false);
326 _pending_declick = 0;
329 /* no global declick */
331 if (solo_gain != dsg) {
332 apply_declick (bufs, nbufs, nframes, solo_gain, dsg, false);
338 /* ----------------------------------------------------------------------------------------------------
339 INPUT METERING & MONITORING
340 -------------------------------------------------------------------------------------------------- */
342 if (meter && (_meter_point == MeterInput)) {
343 for (n = 0; n < nbufs; ++n) {
344 _peak_power[n] = Session::compute_peak (bufs[n], nframes, _peak_power[n]);
348 if (!_soloed && _mute_affects_pre_fader && (mute_gain != dmg)) {
349 apply_declick (bufs, nbufs, nframes, mute_gain, dmg, false);
351 mute_declick_applied = true;
354 if ((_meter_point == MeterInput) && co) {
356 solo_audible = dsg > 0;
357 mute_audible = dmg > 0;// || !_mute_affects_pre_fader;
359 if ( // muted by solo of another track
363 // muted by mute of this track
367 // rec-enabled but not s/w monitoring
369 // TODO: this is probably wrong
371 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
375 co->silence (nframes, offset);
379 co->deliver_output (bufs, nbufs, nframes, offset);
384 /* -----------------------------------------------------------------------------------------------------
386 -------------------------------------------------------------------------------------------------- */
388 if (_denormal_protection || Config->get_denormal_protection()) {
390 for (n = 0; n < nbufs; ++n) {
391 Sample *sp = bufs[n];
393 for (nframes_t nx = offset; nx < nframes + offset; ++nx) {
400 /* ----------------------------------------------------------------------------------------------------
402 -------------------------------------------------------------------------------------------------- */
404 if (with_redirects) {
405 Glib::RWLock::ReaderLock rm (redirect_lock, Glib::TRY_LOCK);
407 if (mute_gain > 0 || !_mute_affects_pre_fader) {
408 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
409 switch ((*i)->placement()) {
412 if (boost::dynamic_pointer_cast<Send>(*i) || boost::dynamic_pointer_cast<PortInsert>(*i)) {
413 (*i)->silence (nframes, offset);
416 (*i)->run (bufs, nbufs, nframes, offset);
420 post_fader_work = true;
425 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
426 switch ((*i)->placement()) {
428 (*i)->silence (nframes, offset);
431 post_fader_work = true;
440 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_post_fader) {
441 apply_declick (bufs, nbufs, nframes, mute_gain, dmg, false);
443 mute_declick_applied = true;
446 /* ----------------------------------------------------------------------------------------------------
447 PRE-FADER METERING & MONITORING
448 -------------------------------------------------------------------------------------------------- */
450 if (meter && (_meter_point == MeterPreFader)) {
451 for (n = 0; n < nbufs; ++n) {
452 _peak_power[n] = Session::compute_peak (bufs[n], nframes, _peak_power[n]);
457 if ((_meter_point == MeterPreFader) && co) {
459 solo_audible = dsg > 0;
460 mute_audible = dmg > 0 || !_mute_affects_pre_fader;
462 if ( // muted by solo of another track
466 // muted by mute of this track
470 // rec-enabled but not s/w monitoring
472 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
476 co->silence (nframes, offset);
480 co->deliver_output_no_pan (bufs, nbufs, nframes, offset);
485 /* ----------------------------------------------------------------------------------------------------
487 -------------------------------------------------------------------------------------------------- */
489 /* if not recording or recording and requiring any monitor signal, then apply gain */
491 if ( // not recording
493 !(record_enabled() && _session.actively_recording()) ||
497 // AND software monitoring required
499 (Config->get_monitoring_model() == SoftwareMonitoring)) {
501 if (apply_gain_automation) {
504 for (n = 0; n < nbufs; ++n) {
505 Sample *sp = bufs[n];
507 for (nframes_t nx = 0; nx < nframes; ++nx) {
512 for (n = 0; n < nbufs; ++n) {
513 Sample *sp = bufs[n];
515 for (nframes_t nx = 0; nx < nframes; ++nx) {
521 if (apply_gain_automation && _session.transport_rolling() && nframes > 0) {
522 _effective_gain = gab[nframes-1];
527 /* manual (scalar) gain */
531 apply_declick (bufs, nbufs, nframes, _gain, dg, _phase_invert);
534 } else if (_gain != 0 && (_phase_invert || _gain != 1.0)) {
536 /* no need to interpolate current gain value,
537 but its non-unity, so apply it. if the gain
538 is zero, do nothing because we'll ship silence
550 for (n = 0; n < nbufs; ++n) {
551 Sample *sp = bufs[n];
552 Session::apply_gain_to_buffer(sp,nframes,this_gain);
555 } else if (_gain == 0) {
556 for (n = 0; n < nbufs; ++n) {
557 memset (bufs[n], 0, sizeof (Sample) * nframes);
564 /* actively recording, no monitoring required; leave buffers as-is to save CPU cycles */
568 /* ----------------------------------------------------------------------------------------------------
570 -------------------------------------------------------------------------------------------------- */
572 /* note that post_fader_work cannot be true unless with_redirects was also true, so don't test both */
574 if (post_fader_work) {
576 Glib::RWLock::ReaderLock rm (redirect_lock, Glib::TRY_LOCK);
578 if (mute_gain > 0 || !_mute_affects_post_fader) {
579 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
580 switch ((*i)->placement()) {
585 if (boost::dynamic_pointer_cast<Send>(*i) || boost::dynamic_pointer_cast<PortInsert>(*i)) {
586 (*i)->silence (nframes, offset);
589 (*i)->run (bufs, nbufs, nframes, offset);
595 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
596 switch ((*i)->placement()) {
600 (*i)->silence (nframes, offset);
608 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_control_outs) {
609 apply_declick (bufs, nbufs, nframes, mute_gain, dmg, false);
611 mute_declick_applied = true;
614 /* ----------------------------------------------------------------------------------------------------
616 -------------------------------------------------------------------------------------------------- */
618 if ((_meter_point == MeterPostFader) && co) {
620 solo_audible = solo_gain > 0;
621 mute_audible = dmg > 0 || !_mute_affects_control_outs;
623 if ( // silent anyway
625 (_gain == 0 && !apply_gain_automation) ||
627 // muted by solo of another track
631 // muted by mute of this track
635 // recording but not s/w monitoring
637 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
641 co->silence (nframes, offset);
645 co->deliver_output_no_pan (bufs, nbufs, nframes, offset);
649 /* ----------------------------------------------------------------------
651 ----------------------------------------------------------------------*/
653 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_main_outs) {
654 apply_declick (bufs, nbufs, nframes, mute_gain, dmg, false);
656 mute_declick_applied = true;
659 /* ----------------------------------------------------------------------------------------------------
661 -------------------------------------------------------------------------------------------------- */
663 solo_audible = dsg > 0;
664 mute_audible = dmg > 0 || !_mute_affects_main_outs;
666 if (n_outputs() == 0) {
670 } else if (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording())) {
672 IO::silence (nframes, offset);
676 if ( // silent anyway
678 (_gain == 0 && !apply_gain_automation) ||
680 // muted by solo of another track, but not using control outs for solo
682 (!solo_audible && (Config->get_solo_model() != SoloBus)) ||
684 // muted by mute of this track
690 /* don't use Route::silence() here, because that causes
691 all outputs (sends, port inserts, etc. to be silent).
694 if (_meter_point == MeterPostFader) {
695 reset_peak_meters ();
698 IO::silence (nframes, offset);
702 if ((_session.transport_speed() > 1.5f ||
703 _session.transport_speed() < -1.5f) &&
704 Config->get_quieten_at_speed()) {
705 pan (bufs, nbufs, nframes, offset, speed_quietning);
707 // cerr << _name << " panner state = " << _panner->automation_state() << endl;
708 if (!_panner->empty() &&
709 (_panner->automation_state() & Play ||
710 ((_panner->automation_state() & Touch) && !_panner->touching()))) {
711 pan_automated (bufs, nbufs, start_frame, end_frame, nframes, offset);
713 pan (bufs, nbufs, nframes, offset, 1.0);
720 /* ----------------------------------------------------------------------------------------------------
722 -------------------------------------------------------------------------------------------------- */
724 if (meter && (_meter_point == MeterPostFader)) {
726 if ((_gain == 0 && !apply_gain_automation) || dmg == 0) {
727 uint32_t no = n_outputs();
728 for (n = 0; n < no; ++n) {
732 uint32_t no = n_outputs();
733 for (n = 0; n < no; ++n) {
734 _peak_power[n] = Session::compute_peak (output(n)->get_buffer (nframes) + offset, nframes, _peak_power[n]);
741 Route::n_process_buffers ()
743 return max (n_inputs(), redirect_max_outs);
748 Route::passthru (nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset, int declick, bool meter_first)
750 vector<Sample*>& bufs = _session.get_passthru_buffers();
751 uint32_t limit = n_process_buffers ();
755 collect_input (bufs, limit, nframes, offset);
757 #define meter_stream meter_first
760 for (uint32_t n = 0; n < limit; ++n) {
761 _peak_power[n] = Session::compute_peak (bufs[n], nframes, _peak_power[n]);
763 meter_stream = false;
768 process_output_buffers (bufs, limit, start_frame, end_frame, nframes, offset, true, declick, meter_stream);
774 Route::set_phase_invert (bool yn, void *src)
776 if (_phase_invert != yn) {
778 // phase_invert_changed (src); /* EMIT SIGNAL */
783 Route::set_denormal_protection (bool yn, void *src)
785 if (_denormal_protection != yn) {
786 _denormal_protection = yn;
787 // denormal_protection_changed (src); /* EMIT SIGNAL */
792 Route::set_solo (bool yn, void *src)
798 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
799 _mix_group->apply (&Route::set_solo, yn, _mix_group);
805 solo_changed (src); /* EMIT SIGNAL */
806 _solo_control.Changed (); /* EMIT SIGNAL */
811 Route::set_solo_mute (bool yn)
813 Glib::Mutex::Lock lm (declick_lock);
815 /* Called by Session in response to another Route being soloed.
818 desired_solo_gain = (yn?0.0:1.0);
822 Route::set_solo_safe (bool yn, void *src)
824 if (_solo_safe != yn) {
826 solo_safe_changed (src); /* EMIT SIGNAL */
831 Route::set_mute (bool yn, void *src)
834 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
835 _mix_group->apply (&Route::set_mute, yn, _mix_group);
841 mute_changed (src); /* EMIT SIGNAL */
843 _mute_control.Changed (); /* EMIT SIGNAL */
845 Glib::Mutex::Lock lm (declick_lock);
846 desired_mute_gain = (yn?0.0f:1.0f);
851 Route::add_redirect (boost::shared_ptr<Redirect> redirect, void *src, uint32_t* err_streams)
853 uint32_t old_rmo = redirect_max_outs;
855 if (!_session.engine().connected()) {
860 Glib::RWLock::WriterLock lm (redirect_lock);
862 boost::shared_ptr<PluginInsert> pi;
863 boost::shared_ptr<PortInsert> porti;
865 _redirects.push_back (redirect);
867 if (_reset_plugin_counts (err_streams)) {
868 _redirects.pop_back ();
869 _reset_plugin_counts (0); // it worked before we tried to add it ...
873 uint32_t potential_max_streams = 0;
875 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(redirect)) != 0) {
877 if (pi->input_streams() == 0) {
878 /* instrument plugin */
879 _have_internal_generator = true;
882 potential_max_streams = max(pi->input_streams(), pi->output_streams());
884 } else if ((porti = boost::dynamic_pointer_cast<PortInsert>(redirect)) != 0) {
886 /* force new port inserts to start out with an i/o configuration
887 that matches this route's i/o configuration.
889 the "inputs" for the port are supposed to match the output
892 the "outputs" of the route should match the inputs of this
893 route. XXX shouldn't they match the number of active signal
894 streams at the point of insertion?
898 porti->ensure_io (n_outputs (), n_inputs(), false, this);
901 // Ensure peak vector sizes before the plugin is activated
902 while (_peak_power.size() < potential_max_streams) {
903 _peak_power.push_back(0);
905 while (_visible_peak_power.size() < potential_max_streams) {
906 _visible_peak_power.push_back(-INFINITY);
908 while (_max_peak_power.size() < potential_max_streams) {
909 _max_peak_power.push_back(-INFINITY);
912 redirect->activate ();
913 redirect->active_changed.connect (mem_fun (*this, &Route::redirect_active_proxy));
916 if (redirect_max_outs != old_rmo || old_rmo == 0) {
920 redirects_changed (src); /* EMIT SIGNAL */
926 Route::add_redirects (const RedirectList& others, void *src, uint32_t* err_streams)
928 uint32_t old_rmo = redirect_max_outs;
930 assert (ports_legal);
932 if (!_session.engine().connected()) {
937 Glib::RWLock::WriterLock lm (redirect_lock);
939 RedirectList::iterator existing_end = _redirects.end();
942 uint32_t potential_max_streams = 0;
944 for (RedirectList::const_iterator i = others.begin(); i != others.end(); ++i) {
946 boost::shared_ptr<PluginInsert> pi;
948 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
951 uint32_t m = max(pi->input_streams(), pi->output_streams());
952 if (m > potential_max_streams)
953 potential_max_streams = m;
956 // Ensure peak vector sizes before the plugin is activated
957 while (_peak_power.size() < potential_max_streams) {
958 _peak_power.push_back(0);
960 while (_visible_peak_power.size() < potential_max_streams) {
961 _visible_peak_power.push_back(-INFINITY);
963 while (_max_peak_power.size() < potential_max_streams) {
964 _max_peak_power.push_back(-INFINITY);
967 _redirects.push_back (*i);
969 if (_reset_plugin_counts (err_streams)) {
971 _redirects.erase (existing_end, _redirects.end());
972 _reset_plugin_counts (0); // it worked before we tried to add it ...
977 (*i)->active_changed.connect (mem_fun (*this, &Route::redirect_active_proxy));
981 if (redirect_max_outs != old_rmo || old_rmo == 0) {
985 redirects_changed (src); /* EMIT SIGNAL */
989 /** Remove redirects with a given placement.
990 * @param p Placement of redirects to remove.
993 Route::clear_redirects (Placement p, void *src)
995 const uint32_t old_rmo = redirect_max_outs;
997 if (!_session.engine().connected()) {
1002 Glib::RWLock::WriterLock lm (redirect_lock);
1003 RedirectList new_list;
1005 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
1006 if ((*i)->placement() == p) {
1007 /* it's the placement we want to get rid of */
1008 (*i)->drop_references ();
1010 /* it's a different placement, so keep it */
1011 new_list.push_back (*i);
1015 _redirects = new_list;
1018 /* FIXME: can't see how this test can ever fire */
1019 if (redirect_max_outs != old_rmo) {
1023 redirect_max_outs = 0;
1024 _have_internal_generator = false;
1025 redirects_changed (src); /* EMIT SIGNAL */
1029 Route::remove_redirect (boost::shared_ptr<Redirect> redirect, void *src, uint32_t* err_streams)
1031 uint32_t old_rmo = redirect_max_outs;
1033 assert (ports_legal);
1035 if (!_session.engine().connected()) {
1039 redirect_max_outs = 0;
1042 Glib::RWLock::WriterLock lm (redirect_lock);
1043 RedirectList::iterator i;
1044 bool removed = false;
1046 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
1047 if (*i == redirect) {
1049 RedirectList::iterator tmp;
1051 /* move along, see failure case for reset_plugin_counts()
1052 where we may need to reinsert the redirect.
1058 /* stop redirects that send signals to JACK ports
1059 from causing noise as a result of no longer being
1063 boost::shared_ptr<Send> send;
1064 boost::shared_ptr<PortInsert> port_insert;
1066 if ((send = boost::dynamic_pointer_cast<Send> (*i)) != 0) {
1067 send->disconnect_inputs (this);
1068 send->disconnect_outputs (this);
1069 } else if ((port_insert = boost::dynamic_pointer_cast<PortInsert> (*i)) != 0) {
1070 port_insert->disconnect_inputs (this);
1071 port_insert->disconnect_outputs (this);
1074 _redirects.erase (i);
1087 if (_reset_plugin_counts (err_streams)) {
1088 /* get back to where we where */
1089 _redirects.insert (i, redirect);
1090 /* we know this will work, because it worked before :) */
1091 _reset_plugin_counts (0);
1097 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
1098 boost::shared_ptr<PluginInsert> pi;
1100 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1101 if (pi->is_generator()) {
1107 _have_internal_generator = foo;
1110 if (old_rmo != redirect_max_outs) {
1114 redirect->drop_references ();
1116 redirects_changed (src); /* EMIT SIGNAL */
1121 Route::reset_plugin_counts (uint32_t* lpc)
1123 Glib::RWLock::WriterLock lm (redirect_lock);
1124 return _reset_plugin_counts (lpc);
1129 Route::_reset_plugin_counts (uint32_t* err_streams)
1131 RedirectList::iterator r;
1132 uint32_t insert_cnt = 0;
1133 uint32_t send_cnt = 0;
1134 map<Placement,list<InsertCount> > insert_map;
1135 RedirectList::iterator prev;
1136 nframes_t initial_streams;
1139 redirect_max_outs = 0;
1141 /* divide inserts up by placement so we get the signal flow
1142 properly modelled. we need to do this because the _redirects
1143 list is not sorted by placement, and because other reasons may
1144 exist now or in the future for this separate treatment.
1147 for (r = _redirects.begin(); r != _redirects.end(); ++r) {
1149 boost::shared_ptr<Insert> insert;
1151 if ((insert = boost::dynamic_pointer_cast<Insert>(*r)) != 0) {
1153 insert_map[insert->placement()].push_back (InsertCount (insert));
1155 /* reset plugin counts back to one for now so
1156 that we have a predictable, controlled
1157 state to try to configure.
1160 boost::shared_ptr<PluginInsert> pi;
1162 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(insert)) != 0) {
1166 } else if (boost::dynamic_pointer_cast<Send> (*r) != 0) {
1171 if (insert_cnt == 0) {
1180 /* Now process each placement in order, checking to see if we
1181 can really do what has been requested.
1186 if (check_some_plugin_counts (insert_map[PreFader], n_inputs (), err_streams)) {
1190 /* figure out the streams that will feed into PreFader */
1192 if (!insert_map[PreFader].empty()) {
1193 InsertCount& ic (insert_map[PreFader].back());
1194 initial_streams = ic.insert->compute_output_streams (ic.cnt);
1196 initial_streams = n_inputs ();
1201 if (check_some_plugin_counts (insert_map[PostFader], initial_streams, err_streams)) {
1205 /* OK, everything can be set up correctly, so lets do it */
1207 apply_some_plugin_counts (insert_map[PreFader]);
1208 apply_some_plugin_counts (insert_map[PostFader]);
1210 /* recompute max outs of any redirect */
1214 redirect_max_outs = 0;
1215 prev = _redirects.end();
1217 for (r = _redirects.begin(); r != _redirects.end(); prev = r, ++r) {
1218 boost::shared_ptr<Send> s;
1220 if ((s = boost::dynamic_pointer_cast<Send> (*r)) != 0) {
1221 if (r == _redirects.begin()) {
1222 s->expect_inputs (n_inputs());
1224 s->expect_inputs ((*prev)->output_streams());
1229 /* don't pay any attention to send output configuration, since it doesn't
1233 redirect_max_outs = max ((*r)->output_streams (), redirect_max_outs);
1242 for (r = _redirects.begin(); r != _redirects.end(); ++r) {
1243 redirect_max_outs = max ((*r)->output_streams (), redirect_max_outs);
1249 Route::apply_some_plugin_counts (list<InsertCount>& iclist)
1251 list<InsertCount>::iterator i;
1253 for (i = iclist.begin(); i != iclist.end(); ++i) {
1255 if ((*i).insert->configure_io ((*i).cnt, (*i).in, (*i).out)) {
1258 /* make sure that however many we have, they are all active */
1259 (*i).insert->activate ();
1266 Route::check_some_plugin_counts (list<InsertCount>& iclist, int32_t required_inputs, uint32_t* err_streams)
1268 list<InsertCount>::iterator i;
1270 for (i = iclist.begin(); i != iclist.end(); ++i) {
1272 if (((*i).cnt = (*i).insert->can_support_input_configuration (required_inputs)) < 0) {
1274 *err_streams = required_inputs;
1279 (*i).in = required_inputs;
1281 if (((*i).out = (*i).insert->compute_output_streams ((*i).cnt)) < 0) {
1283 *err_streams = required_inputs;
1288 required_inputs = (*i).out;
1295 Route::copy_redirects (const Route& other, Placement placement, uint32_t* err_streams)
1297 uint32_t old_rmo = redirect_max_outs;
1303 RedirectList to_be_deleted;
1306 Glib::RWLock::WriterLock lm (redirect_lock);
1307 RedirectList::iterator tmp;
1308 RedirectList the_copy;
1310 the_copy = _redirects;
1312 /* remove all relevant redirects */
1314 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ) {
1318 if ((*i)->placement() == placement) {
1319 to_be_deleted.push_back (*i);
1320 _redirects.erase (i);
1326 /* now copy the relevant ones from "other" */
1328 for (RedirectList::const_iterator i = other._redirects.begin(); i != other._redirects.end(); ++i) {
1329 if ((*i)->placement() == placement) {
1330 _redirects.push_back (Redirect::clone (*i));
1334 /* reset plugin stream handling */
1336 if (_reset_plugin_counts (err_streams)) {
1338 /* FAILED COPY ATTEMPT: we have to restore order */
1340 /* delete all cloned redirects */
1342 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ) {
1347 if ((*i)->placement() == placement) {
1348 _redirects.erase (i);
1354 /* restore the natural order */
1356 _redirects = the_copy;
1357 redirect_max_outs = old_rmo;
1359 /* we failed, even though things are OK again */
1365 /* SUCCESSFUL COPY ATTEMPT: delete the redirects we removed pre-copy */
1366 to_be_deleted.clear ();
1370 if (redirect_max_outs != old_rmo || old_rmo == 0) {
1374 redirects_changed (this); /* EMIT SIGNAL */
1379 Route::all_redirects_flip ()
1381 Glib::RWLock::ReaderLock lm (redirect_lock);
1383 if (_redirects.empty()) {
1387 bool first_is_on = _redirects.front()->active();
1389 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
1390 (*i)->set_active (!first_is_on, this);
1394 /** Set all redirects with a given placement to a given active state.
1395 * @param p Placement of redirects to change.
1396 * @param state New active state for those redirects.
1399 Route::all_redirects_active (Placement p, bool state)
1401 Glib::RWLock::ReaderLock lm (redirect_lock);
1403 if (_redirects.empty()) {
1407 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
1408 if ((*i)->placement() == p) {
1409 (*i)->set_active (state, this);
1414 struct RedirectSorter {
1415 bool operator() (boost::shared_ptr<const Redirect> a, boost::shared_ptr<const Redirect> b) {
1416 return a->sort_key() < b->sort_key();
1421 Route::sort_redirects (uint32_t* err_streams)
1424 RedirectSorter comparator;
1425 Glib::RWLock::WriterLock lm (redirect_lock);
1426 uint32_t old_rmo = redirect_max_outs;
1428 /* the sweet power of C++ ... */
1430 RedirectList as_it_was_before = _redirects;
1432 _redirects.sort (comparator);
1434 if (_reset_plugin_counts (err_streams)) {
1435 _redirects = as_it_was_before;
1436 redirect_max_outs = old_rmo;
1442 redirects_changed (this); /* EMIT SIGNAL */
1454 Route::get_template()
1456 return state(false);
1460 Route::state(bool full_state)
1462 XMLNode *node = new XMLNode("Route");
1463 RedirectList:: iterator i;
1467 node->add_property("flags", enum_2_string (_flags));
1470 node->add_property("default-type", _default_type.to_string());
1472 node->add_property("muted", _muted?"yes":"no");
1473 node->add_property("soloed", _soloed?"yes":"no");
1474 node->add_property("phase-invert", _phase_invert?"yes":"no");
1475 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
1476 node->add_property("mute-affects-pre-fader", _mute_affects_pre_fader?"yes":"no");
1477 node->add_property("mute-affects-post-fader", _mute_affects_post_fader?"yes":"no");
1478 node->add_property("mute-affects-control-outs", _mute_affects_control_outs?"yes":"no");
1479 node->add_property("mute-affects-main-outs", _mute_affects_main_outs?"yes":"no");
1482 node->add_property("edit-group", _edit_group->name());
1485 node->add_property("mix-group", _mix_group->name());
1488 string order_string;
1489 OrderKeys::iterator x = order_keys.begin();
1491 while (x != order_keys.end()) {
1492 order_string += string ((*x).first);
1493 order_string += '=';
1494 snprintf (buf, sizeof(buf), "%ld", (*x).second);
1495 order_string += buf;
1499 if (x == order_keys.end()) {
1503 order_string += ':';
1505 node->add_property ("order-keys", order_string);
1507 node->add_child_nocopy (IO::state (full_state));
1508 node->add_child_nocopy (_solo_control.get_state ());
1509 node->add_child_nocopy (_mute_control.get_state ());
1511 XMLNode* remote_control_node = new XMLNode (X_("remote_control"));
1512 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
1513 remote_control_node->add_property (X_("id"), buf);
1514 node->add_child_nocopy (*remote_control_node);
1516 if (_control_outs) {
1517 XMLNode* cnode = new XMLNode (X_("ControlOuts"));
1518 cnode->add_child_nocopy (_control_outs->state (full_state));
1519 node->add_child_nocopy (*cnode);
1522 if (_comment.length()) {
1523 XMLNode *cmt = node->add_child ("Comment");
1524 cmt->add_content (_comment);
1527 for (i = _redirects.begin(); i != _redirects.end(); ++i) {
1528 node->add_child_nocopy((*i)->state (full_state));
1532 node->add_child_copy (*_extra_xml);
1539 Route::set_deferred_state ()
1542 XMLNodeConstIterator niter;
1544 if (!deferred_state) {
1548 nlist = deferred_state->children();
1550 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1551 add_redirect_from_xml (**niter);
1554 delete deferred_state;
1559 Route::add_redirect_from_xml (const XMLNode& node)
1561 const XMLProperty *prop;
1563 if (node.name() == "Send") {
1567 boost::shared_ptr<Send> send (new Send (_session, node));
1568 add_redirect (send, this);
1571 catch (failed_constructor &err) {
1572 error << _("Send construction failed") << endmsg;
1576 } else if (node.name() == "Insert") {
1579 if ((prop = node.property ("type")) != 0) {
1581 boost::shared_ptr<Insert> insert;
1582 bool have_insert = false;
1584 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
1585 prop->value() == "lv2" ||
1586 prop->value() == "vst" ||
1587 prop->value() == "audiounit") {
1589 insert.reset (new PluginInsert(_session, node));
1592 } else if (prop->value() == "port") {
1595 insert.reset (new PortInsert (_session, node));
1600 error << string_compose(_("unknown Insert type \"%1\"; ignored"), prop->value()) << endmsg;
1604 add_redirect (insert, this);
1608 error << _("Insert XML node has no type property") << endmsg;
1612 catch (failed_constructor &err) {
1613 warning << _("insert could not be created. Ignored.") << endmsg;
1620 Route::set_state (const XMLNode& node)
1622 return _set_state (node, true);
1626 Route::_set_state (const XMLNode& node, bool call_base)
1629 XMLNodeConstIterator niter;
1631 XMLPropertyList plist;
1632 const XMLProperty *prop;
1634 if (node.name() != "Route"){
1635 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
1639 if ((prop = node.property (X_("flags"))) != 0) {
1640 _flags = Flag (string_2_enum (prop->value(), _flags));
1645 if ((prop = node.property (X_("default-type"))) != 0) {
1646 _default_type = DataType(prop->value());
1647 assert(_default_type != DataType::NIL);
1650 if ((prop = node.property (X_("phase-invert"))) != 0) {
1651 set_phase_invert (prop->value()=="yes"?true:false, this);
1654 if ((prop = node.property (X_("denormal-protection"))) != 0) {
1655 set_denormal_protection (prop->value()=="yes"?true:false, this);
1658 if ((prop = node.property (X_("muted"))) != 0) {
1659 bool yn = prop->value()=="yes"?true:false;
1661 /* force reset of mute status */
1665 mute_gain = desired_mute_gain;
1668 if ((prop = node.property (X_("soloed"))) != 0) {
1669 bool yn = prop->value()=="yes"?true:false;
1671 /* force reset of solo status */
1674 set_solo (yn, this);
1675 solo_gain = desired_solo_gain;
1678 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
1679 _mute_affects_pre_fader = (prop->value()=="yes")?true:false;
1682 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
1683 _mute_affects_post_fader = (prop->value()=="yes")?true:false;
1686 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
1687 _mute_affects_control_outs = (prop->value()=="yes")?true:false;
1690 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
1691 _mute_affects_main_outs = (prop->value()=="yes")?true:false;
1694 if ((prop = node.property (X_("edit-group"))) != 0) {
1695 RouteGroup* edit_group = _session.edit_group_by_name(prop->value());
1696 if(edit_group == 0) {
1697 error << string_compose(_("Route %1: unknown edit group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
1699 set_edit_group(edit_group, this);
1703 if ((prop = node.property (X_("order-keys"))) != 0) {
1707 string::size_type colon, equal;
1708 string remaining = prop->value();
1710 while (remaining.length()) {
1712 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
1713 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1716 if (sscanf (remaining.substr (equal+1).c_str(), "%ld", &n) != 1) {
1717 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1720 set_order_key (remaining.substr (0, equal).c_str(), n);
1724 colon = remaining.find_first_of (':');
1726 if (colon != string::npos) {
1727 remaining = remaining.substr (colon+1);
1734 nlist = node.children();
1736 if (deferred_state) {
1737 delete deferred_state;
1740 deferred_state = new XMLNode(X_("deferred state"));
1742 /* set parent class properties before anything else */
1744 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1748 if (child->name() == IO::state_node_name && call_base) {
1750 IO::set_state (*child);
1756 XMLNodeList redirect_nodes;
1758 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1762 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
1763 redirect_nodes.push_back(child);
1768 _set_redirect_states (redirect_nodes);
1770 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1772 // All redirects (sends and inserts) have been applied already
1774 if (child->name() == X_("Automation")) {
1776 if ((prop = child->property (X_("path"))) != 0) {
1777 load_automation (prop->value());
1780 } else if (child->name() == X_("ControlOuts")) {
1782 string coutname = _name;
1783 coutname += _("[control]");
1785 _control_outs = new IO (_session, coutname);
1786 _control_outs->set_state (**(child->children().begin()));
1788 } else if (child->name() == X_("Comment")) {
1790 /* XXX this is a terrible API design in libxml++ */
1792 XMLNode *cmt = *(child->children().begin());
1793 _comment = cmt->content();
1795 } else if (child->name() == X_("extra")) {
1797 _extra_xml = new XMLNode (*child);
1799 } else if (child->name() == X_("controllable") && (prop = child->property("name")) != 0) {
1801 if (prop->value() == "solo") {
1802 _solo_control.set_state (*child);
1803 _session.add_controllable (&_solo_control);
1805 else if (prop->value() == "mute") {
1806 _mute_control.set_state (*child);
1807 _session.add_controllable (&_mute_control);
1810 else if (child->name() == X_("remote_control")) {
1811 if ((prop = child->property (X_("id"))) != 0) {
1813 sscanf (prop->value().c_str(), "%d", &x);
1814 set_remote_control_id (x);
1819 if ((prop = node.property (X_("mix-group"))) != 0) {
1820 RouteGroup* mix_group = _session.mix_group_by_name(prop->value());
1821 if (mix_group == 0) {
1822 error << string_compose(_("Route %1: unknown mix group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
1824 set_mix_group(mix_group, this);
1832 Route::_set_redirect_states(const XMLNodeList &nlist)
1834 XMLNodeConstIterator niter;
1837 RedirectList::iterator i, o;
1841 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1842 deferred_state->add_child_copy (**niter);
1848 // Iterate through existing redirects, remove those which are not in the state list
1849 for (i = _redirects.begin(); i != _redirects.end(); ) {
1850 RedirectList::iterator tmp = i;
1853 bool redirectInStateList = false;
1855 (*i)->id().print (buf, sizeof (buf));
1857 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1859 if (strncmp (buf,(*niter)->child(X_("Redirect"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf)) == 0) {
1860 redirectInStateList = true;
1865 if (!redirectInStateList) {
1866 remove_redirect ( *i, this);
1874 // Iterate through state list and make sure all redirects are on the track and in the correct order,
1875 // set the state of existing redirects according to the new state on the same go
1876 i = _redirects.begin();
1877 for (niter = nlist.begin(); niter != nlist.end(); ++niter, ++i) {
1879 // Check whether the next redirect in the list
1882 while (o != _redirects.end()) {
1883 (*o)->id().print (buf, sizeof (buf));
1884 if ( strncmp(buf, (*niter)->child(X_("Redirect"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf)) == 0)
1889 if (o == _redirects.end()) {
1890 // If the redirect (*niter) is not on the route, we need to create it
1891 // and move it to the correct location
1893 RedirectList::iterator prev_last = _redirects.end();
1894 --prev_last; // We need this to check whether adding succeeded
1896 add_redirect_from_xml (**niter);
1898 RedirectList::iterator last = _redirects.end();
1901 if (prev_last == last) {
1902 warning << _name << ": could not fully restore state as some redirects were not possible to create" << endmsg;
1907 boost::shared_ptr<Redirect> tmp = (*last);
1908 // remove the redirect from the wrong location
1909 _redirects.erase(last);
1910 // insert the new redirect at the current location
1911 _redirects.insert(i, tmp);
1913 --i; // move pointer to the newly inserted redirect
1917 // We found the redirect (*niter) on the route, first we must make sure the redirect
1918 // is at the location provided in the XML state
1920 boost::shared_ptr<Redirect> tmp = (*o);
1921 // remove the old copy
1922 _redirects.erase(o);
1923 // insert the redirect at the correct location
1924 _redirects.insert(i, tmp);
1926 --i; // move pointer so it points to the right redirect
1929 (*i)->set_state( (**niter) );
1932 redirects_changed(this);
1936 Route::curve_reallocate ()
1938 // _gain_automation_curve.finish_resize ();
1939 // _pan_automation_curve.finish_resize ();
1943 Route::silence (nframes_t nframes, nframes_t offset)
1947 // reset_peak_meters ();
1949 IO::silence (nframes, offset);
1951 if (_control_outs) {
1952 _control_outs->silence (nframes, offset);
1956 Glib::RWLock::ReaderLock lm (redirect_lock, Glib::TRY_LOCK);
1959 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
1960 boost::shared_ptr<PluginInsert> pi;
1961 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
1962 // skip plugins, they don't need anything when we're not active
1966 (*i)->silence (nframes, offset);
1969 if (nframes == _session.get_block_size() && offset == 0) {
1979 Route::set_control_outs (const vector<string>& ports)
1981 Glib::Mutex::Lock lm (control_outs_lock);
1982 vector<string>::const_iterator i;
1985 if (_control_outs) {
1986 delete _control_outs;
1990 if (control() || master()) {
1991 /* no control outs for these two special busses */
1995 if (ports.empty()) {
1999 string coutname = _name;
2000 coutname += _("[control]");
2002 _control_outs = new IO (_session, coutname);
2004 /* our control outs need as many outputs as we
2005 have outputs. we track the changes in ::output_change_handler().
2008 limit = n_outputs ();
2010 if (_control_outs->ensure_io (0, limit, true, this)) {
2014 /* now connect to the named ports */
2016 for (uint32_t n = 0; n < limit; ++n) {
2017 if (_control_outs->connect_output (_control_outs->output (n), ports[n % ports.size()], this)) {
2018 error << string_compose (_("could not connect %1 to %2"), _control_outs->output(n)->name(), ports[n]) << endmsg;
2027 Route::set_edit_group (RouteGroup *eg, void *src)
2030 if (eg == _edit_group) {
2035 _edit_group->remove (this);
2038 if ((_edit_group = eg) != 0) {
2039 _edit_group->add (this);
2042 _session.set_dirty ();
2043 edit_group_changed (src); /* EMIT SIGNAL */
2047 Route::drop_edit_group (void *src)
2050 _session.set_dirty ();
2051 edit_group_changed (src); /* EMIT SIGNAL */
2055 Route::set_mix_group (RouteGroup *mg, void *src)
2058 if (mg == _mix_group) {
2063 _mix_group->remove (this);
2066 if ((_mix_group = mg) != 0) {
2067 _mix_group->add (this);
2070 _session.set_dirty ();
2071 mix_group_changed (src); /* EMIT SIGNAL */
2075 Route::drop_mix_group (void *src)
2078 _session.set_dirty ();
2079 mix_group_changed (src); /* EMIT SIGNAL */
2083 Route::set_comment (string cmt, void *src)
2086 comment_changed (src);
2087 _session.set_dirty ();
2091 Route::feeds (boost::shared_ptr<Route> other)
2096 uint32_t no = self.n_outputs();
2097 uint32_t ni = other->n_inputs ();
2099 for (i = 0; i < no; ++i) {
2100 for (j = 0; j < ni; ++j) {
2101 if (self.output(i)->connected_to (other->input(j)->name())) {
2107 /* check Redirects which may also interconnect Routes */
2109 for (RedirectList::iterator r = _redirects.begin(); r != _redirects.end(); r++) {
2111 no = (*r)->n_outputs();
2113 for (i = 0; i < no; ++i) {
2114 for (j = 0; j < ni; ++j) {
2115 if ((*r)->output(i)->connected_to (other->input (j)->name())) {
2122 /* check for control room outputs which may also interconnect Routes */
2124 if (_control_outs) {
2126 no = _control_outs->n_outputs();
2128 for (i = 0; i < no; ++i) {
2129 for (j = 0; j < ni; ++j) {
2130 if (_control_outs->output(i)->connected_to (other->input (j)->name())) {
2141 Route::set_mute_config (mute_type t, bool onoff, void *src)
2145 _mute_affects_pre_fader = onoff;
2146 pre_fader_changed(src); /* EMIT SIGNAL */
2150 _mute_affects_post_fader = onoff;
2151 post_fader_changed(src); /* EMIT SIGNAL */
2155 _mute_affects_control_outs = onoff;
2156 control_outs_changed(src); /* EMIT SIGNAL */
2160 _mute_affects_main_outs = onoff;
2161 main_outs_changed(src); /* EMIT SIGNAL */
2167 Route::get_mute_config (mute_type t)
2173 onoff = _mute_affects_pre_fader;
2176 onoff = _mute_affects_post_fader;
2179 onoff = _mute_affects_control_outs;
2182 onoff = _mute_affects_main_outs;
2190 Route::handle_transport_stopped (bool abort_ignored, bool did_locate, bool can_flush_redirects)
2192 nframes_t now = _session.transport_frame();
2195 Glib::RWLock::ReaderLock lm (redirect_lock);
2198 automation_snapshot (now, true);
2201 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2203 if (Config->get_plugins_stop_with_transport() && can_flush_redirects) {
2204 (*i)->deactivate ();
2208 (*i)->transport_stopped (now);
2212 IO::transport_stopped (now);
2214 _roll_delay = _initial_delay;
2218 Route::input_change_handler (IOChange change, void *ignored)
2220 if (change & ConfigurationChanged) {
2221 reset_plugin_counts (0);
2226 Route::output_change_handler (IOChange change, void *ignored)
2228 if (change & ConfigurationChanged) {
2229 if (_control_outs) {
2230 _control_outs->ensure_io (0, n_outputs(), true, this);
2233 reset_plugin_counts (0);
2238 Route::pans_required () const
2240 if (n_outputs() < 2) {
2244 return max (n_inputs (), redirect_max_outs);
2248 Route::no_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
2249 bool session_state_changing, bool can_record, bool rec_monitors_input)
2251 if (n_outputs() == 0) {
2255 if (session_state_changing || !_active) {
2256 silence (nframes, offset);
2260 apply_gain_automation = false;
2263 passthru (start_frame, end_frame, nframes, offset, 0, false);
2265 silence (nframes, offset);
2272 Route::check_initial_delay (nframes_t nframes, nframes_t& offset, nframes_t& transport_frame)
2274 if (_roll_delay > nframes) {
2276 _roll_delay -= nframes;
2277 silence (nframes, offset);
2278 /* transport frame is not legal for caller to use */
2281 } else if (_roll_delay > 0) {
2283 nframes -= _roll_delay;
2285 silence (_roll_delay, offset);
2287 offset += _roll_delay;
2288 transport_frame += _roll_delay;
2297 Route::roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset, int declick,
2298 bool can_record, bool rec_monitors_input)
2301 Glib::RWLock::ReaderLock lm (redirect_lock, Glib::TRY_LOCK);
2303 // automation snapshot can also be called from the non-rt context
2304 // and it uses the redirect list, so we take the lock out here
2305 automation_snapshot (_session.transport_frame(), false);
2309 if ((n_outputs() == 0 && _redirects.empty()) || n_inputs() == 0 || !_active) {
2310 silence (nframes, offset);
2314 nframes_t unused = 0;
2316 if ((nframes = check_initial_delay (nframes, offset, unused)) == 0) {
2322 apply_gain_automation = false;
2325 Glib::Mutex::Lock am (automation_lock, Glib::TRY_LOCK);
2327 if (am.locked() && _session.transport_rolling()) {
2329 nframes_t start_frame = end_frame - nframes;
2331 if (gain_automation_playback()) {
2332 apply_gain_automation = _gain_automation_curve.rt_safe_get_vector (start_frame, end_frame, _session.gain_automation_buffer(), nframes);
2337 passthru (start_frame, end_frame, nframes, offset, declick, false);
2343 Route::silent_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
2344 bool can_record, bool rec_monitors_input)
2346 silence (nframes, offset);
2351 Route::toggle_monitor_input ()
2353 for (vector<Port*>::iterator i = _inputs.begin(); i != _inputs.end(); ++i) {
2354 (*i)->ensure_monitor_input(!(*i)->monitoring_input());
2359 Route::has_external_redirects () const
2361 boost::shared_ptr<const PortInsert> pi;
2363 for (RedirectList::const_iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2364 if ((pi = boost::dynamic_pointer_cast<const PortInsert>(*i)) != 0) {
2366 uint32_t no = pi->n_outputs();
2368 for (uint32_t n = 0; n < no; ++n) {
2370 string port_name = pi->output(n)->name();
2371 string client_name = port_name.substr (0, port_name.find(':'));
2373 /* only say "yes" if the redirect is actually in use */
2375 if (client_name != "ardour" && pi->active()) {
2386 Route::flush_redirects ()
2388 /* XXX shouldn't really try to take this lock, since
2389 this is called from the RT audio thread.
2392 Glib::RWLock::ReaderLock lm (redirect_lock);
2394 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2395 (*i)->deactivate ();
2401 Route::set_meter_point (MeterPoint p, void *src)
2403 if (_meter_point != p) {
2405 meter_change (src); /* EMIT SIGNAL */
2406 _session.set_dirty ();
2411 Route::update_total_latency ()
2415 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2416 if ((*i)->active ()) {
2417 _own_latency += (*i)->latency ();
2421 #undef DEBUG_LATENCY
2422 #ifdef DEBUG_LATENCY
2423 cerr << _name << ": internal redirect latency = " << _own_latency << endl;
2426 set_port_latency (_own_latency);
2428 /* this (virtual) function is used for pure Routes,
2429 not derived classes like AudioTrack. this means
2430 that the data processed here comes from an input
2431 port, not prerecorded material, and therefore we
2432 have to take into account any input latency.
2435 _own_latency += input_latency ();
2437 #ifdef DEBUG_LATENCY
2438 cerr << _name << ": input latency = " << input_latency() << " total = "
2439 << _own_latency << endl;
2442 return _own_latency;
2446 Route::set_latency_delay (nframes_t longest_session_latency)
2448 _initial_delay = longest_session_latency - _own_latency;
2450 if (_session.transport_stopped()) {
2451 _roll_delay = _initial_delay;
2456 Route::automation_snapshot (nframes_t now, bool force)
2458 if (!force && !should_snapshot(now)) {
2462 IO::automation_snapshot (now, force);
2464 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2465 (*i)->automation_snapshot (now, force);
2469 Route::ToggleControllable::ToggleControllable (std::string name, Route& s, ToggleType tp)
2470 : Controllable (name), route (s), type(tp)
2476 Route::ToggleControllable::set_value (float val)
2478 bool bval = ((val >= 0.5f) ? true: false);
2482 route.set_mute (bval, this);
2485 route.set_solo (bval, this);
2493 Route::ToggleControllable::get_value (void) const
2499 val = route.muted() ? 1.0f : 0.0f;
2502 val = route.soloed() ? 1.0f : 0.0f;
2512 Route::set_block_size (nframes_t nframes)
2514 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2515 (*i)->set_block_size (nframes);
2520 Route::redirect_active_proxy (Redirect* ignored, void* ignored_src)
2522 _session.update_latency_compensation (false, false);
2526 Route::protect_automation ()
2528 switch (gain_automation_state()) {
2530 set_gain_automation_state (Off);
2532 set_gain_automation_state (Play);
2538 switch (panner().automation_state ()) {
2540 panner().set_automation_state (Off);
2543 panner().set_automation_state (Play);
2549 for (RedirectList::iterator i = _redirects.begin(); i != _redirects.end(); ++i) {
2550 boost::shared_ptr<PluginInsert> pi;
2551 if ((pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2552 pi->protect_automation ();
2558 Route::set_pending_declick (int declick)
2561 /* this call is not allowed to turn off a pending declick unless "force" is true */
2563 _pending_declick = declick;
2565 // cerr << _name << ": after setting to " << declick << " pending declick = " << _pending_declick << endl;
2567 _pending_declick = 0;