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>
28 #include <ardour/timestamps.h>
29 #include <ardour/audioengine.h>
30 #include <ardour/route.h>
31 #include <ardour/buffer.h>
32 #include <ardour/insert.h>
33 #include <ardour/plugin_insert.h>
34 #include <ardour/port_insert.h>
35 #include <ardour/send.h>
36 #include <ardour/session.h>
37 #include <ardour/utils.h>
38 #include <ardour/configuration.h>
39 #include <ardour/cycle_timer.h>
40 #include <ardour/route_group.h>
41 #include <ardour/port.h>
42 #include <ardour/audio_port.h>
43 #include <ardour/ladspa_plugin.h>
44 #include <ardour/panner.h>
45 #include <ardour/dB.h>
46 #include <ardour/amp.h>
47 #include <ardour/meter.h>
48 #include <ardour/buffer_set.h>
52 using namespace ARDOUR;
55 uint32_t Route::order_key_cnt = 0;
58 Route::Route (Session& sess, string name, int input_min, int input_max, int output_min, int output_max, Flag flg, DataType default_type)
59 : IO (sess, name, input_min, input_max, output_min, output_max, default_type),
61 _solo_control (X_("solo"), *this, ToggleControllable::SoloControl),
62 _mute_control (X_("mute"), *this, ToggleControllable::MuteControl)
67 Route::Route (Session& sess, const XMLNode& node, DataType default_type)
68 : IO (sess, *node.child ("IO"), default_type),
69 _solo_control (X_("solo"), *this, ToggleControllable::SoloControl),
70 _mute_control (X_("mute"), *this, ToggleControllable::MuteControl)
73 _set_state (node, false);
79 insert_max_outs.reset();
83 _phase_invert = false;
84 _denormal_protection = false;
85 order_keys[strdup (N_("signal"))] = order_key_cnt++;
88 _meter_point = MeterPostFader;
92 _have_internal_generator = false;
94 _pending_declick = true;
95 _remote_control_id = 0;
100 _mute_affects_pre_fader = Config->get_mute_affects_pre_fader();
101 _mute_affects_post_fader = Config->get_mute_affects_post_fader();
102 _mute_affects_control_outs = Config->get_mute_affects_control_outs();
103 _mute_affects_main_outs = Config->get_mute_affects_main_outs();
106 desired_solo_gain = 1.0;
108 desired_mute_gain = 1.0;
112 input_changed.connect (mem_fun (this, &Route::input_change_handler));
113 output_changed.connect (mem_fun (this, &Route::output_change_handler));
118 clear_inserts (PreFader);
119 clear_inserts (PostFader);
121 for (OrderKeys::iterator i = order_keys.begin(); i != order_keys.end(); ++i) {
122 free ((void*)(i->first));
126 delete _control_outs;
131 Route::set_remote_control_id (uint32_t id)
133 if (id != _remote_control_id) {
134 _remote_control_id = id;
135 RemoteControlIDChanged ();
140 Route::remote_control_id() const
142 return _remote_control_id;
146 Route::order_key (const char* name) const
148 OrderKeys::const_iterator i;
150 for (i = order_keys.begin(); i != order_keys.end(); ++i) {
151 if (!strcmp (name, i->first)) {
160 Route::set_order_key (const char* name, long n)
162 order_keys[strdup(name)] = n;
163 _session.set_dirty ();
167 Route::inc_gain (gain_t fraction, void *src)
169 IO::inc_gain (fraction, src);
173 Route::set_gain (gain_t val, void *src)
175 if (src != 0 && _mix_group && src != _mix_group && _mix_group->is_active()) {
177 if (_mix_group->is_relative()) {
180 gain_t usable_gain = gain();
181 if (usable_gain < 0.000001f) {
182 usable_gain=0.000001f;
186 if (delta < 0.000001f) {
190 delta -= usable_gain;
192 if (delta == 0.0f) return;
194 gain_t factor = delta / usable_gain;
197 factor = _mix_group->get_max_factor(factor);
198 if (factor == 0.0f) {
203 factor = _mix_group->get_min_factor(factor);
204 if (factor == 0.0f) {
210 _mix_group->apply (&Route::inc_gain, factor, _mix_group);
214 _mix_group->apply (&Route::set_gain, val, _mix_group);
224 IO::set_gain (val, src);
227 /** Process this route for one (sub) cycle (process thread)
229 * @param bufs Scratch buffers to use for the signal path
230 * @param start_frame Initial transport frame
231 * @param end_frame Final transport frame
232 * @param nframes Number of frames to output (to ports)
233 * @param offset Output offset (of port buffers, for split cycles)
235 * Note that (end_frame - start_frame) may not be equal to nframes when the
236 * transport speed isn't 1.0 (eg varispeed).
239 Route::process_output_buffers (BufferSet& bufs,
240 nframes_t start_frame, nframes_t end_frame,
241 nframes_t nframes, nframes_t offset, bool with_inserts, int declick,
244 // This is definitely very audio-only for now
245 assert(_default_type == DataType::AUDIO);
247 InsertList::iterator i;
248 bool post_fader_work = false;
249 bool mute_declick_applied = false;
255 gain_t* gab = _session.gain_automation_buffer();
257 switch (Config->get_monitoring_model()) {
258 case HardwareMonitoring:
259 case ExternalMonitoring:
266 declick = _pending_declick;
269 Glib::Mutex::Lock cm (control_outs_lock, Glib::TRY_LOCK);
279 Glib::Mutex::Lock dm (declick_lock, Glib::TRY_LOCK);
282 dmg = desired_mute_gain;
283 dsg = desired_solo_gain;
292 /* ----------------------------------------------------------------------------------------------------
293 GLOBAL DECLICK (for transport changes etc.)
294 -------------------------------------------------------------------------------------------------- */
297 Amp::run (bufs, nframes, 0.0, 1.0, false);
298 _pending_declick = 0;
299 } else if (declick < 0) {
300 Amp::run (bufs, nframes, 1.0, 0.0, false);
301 _pending_declick = 0;
304 /* no global declick */
306 if (solo_gain != dsg) {
307 Amp::run (bufs, nframes, solo_gain, dsg, false);
313 /* ----------------------------------------------------------------------------------------------------
314 INPUT METERING & MONITORING
315 -------------------------------------------------------------------------------------------------- */
317 if (meter && (_meter_point == MeterInput)) {
318 _meter->run(bufs, start_frame, end_frame, nframes, offset);
321 if (!_soloed && _mute_affects_pre_fader && (mute_gain != dmg)) {
322 Amp::run (bufs, nframes, mute_gain, dmg, false);
324 mute_declick_applied = true;
327 if ((_meter_point == MeterInput) && co) {
329 solo_audible = dsg > 0;
330 mute_audible = dmg > 0;// || !_mute_affects_pre_fader;
332 if ( // muted by solo of another track
336 // muted by mute of this track
340 // rec-enabled but not s/w monitoring
342 // TODO: this is probably wrong
344 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
348 co->silence (nframes, offset);
352 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
357 /* -----------------------------------------------------------------------------------------------------
359 -------------------------------------------------------------------------------------------------- */
361 if (_denormal_protection || Config->get_denormal_protection()) {
363 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
364 Sample* const sp = i->data();
366 for (nframes_t nx = offset; nx < nframes + offset; ++nx) {
372 /* ----------------------------------------------------------------------------------------------------
374 -------------------------------------------------------------------------------------------------- */
377 Glib::RWLock::ReaderLock rm (insert_lock, Glib::TRY_LOCK);
379 if (mute_gain > 0 || !_mute_affects_pre_fader) {
380 for (i = _inserts.begin(); i != _inserts.end(); ++i) {
381 switch ((*i)->placement()) {
383 (*i)->run (bufs, start_frame, end_frame, nframes, offset);
386 post_fader_work = true;
391 for (i = _inserts.begin(); i != _inserts.end(); ++i) {
392 switch ((*i)->placement()) {
394 (*i)->silence (nframes, offset);
397 post_fader_work = true;
405 // This really should already be true...
406 bufs.set_count(pre_fader_streams());
408 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_post_fader) {
409 Amp::run (bufs, nframes, mute_gain, dmg, false);
411 mute_declick_applied = true;
414 /* ----------------------------------------------------------------------------------------------------
415 PRE-FADER METERING & MONITORING
416 -------------------------------------------------------------------------------------------------- */
418 if (meter && (_meter_point == MeterPreFader)) {
419 _meter->run(bufs, start_frame, end_frame, nframes, offset);
423 if ((_meter_point == MeterPreFader) && co) {
425 solo_audible = dsg > 0;
426 mute_audible = dmg > 0 || !_mute_affects_pre_fader;
428 if ( // muted by solo of another track
432 // muted by mute of this track
436 // rec-enabled but not s/w monitoring
438 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
442 co->silence (nframes, offset);
446 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
450 /* ----------------------------------------------------------------------------------------------------
452 -------------------------------------------------------------------------------------------------- */
454 /* if not recording or recording and requiring any monitor signal, then apply gain */
456 if ( // not recording
458 !(record_enabled() && _session.actively_recording()) ||
462 // h/w monitoring not in use
464 (!Config->get_monitoring_model() == HardwareMonitoring &&
466 // AND software monitoring required
468 Config->get_monitoring_model() == SoftwareMonitoring)) {
470 if (apply_gain_automation) {
473 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
474 Sample* const sp = i->data();
476 for (nframes_t nx = 0; nx < nframes; ++nx) {
481 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
482 Sample* const sp = i->data();
484 for (nframes_t nx = 0; nx < nframes; ++nx) {
490 if (apply_gain_automation && _session.transport_rolling() && nframes > 0) {
491 _effective_gain = gab[nframes-1];
496 /* manual (scalar) gain */
500 Amp::run (bufs, nframes, _gain, dg, _phase_invert);
503 } else if (_gain != 0 && (_phase_invert || _gain != 1.0)) {
505 /* no need to interpolate current gain value,
506 but its non-unity, so apply it. if the gain
507 is zero, do nothing because we'll ship silence
519 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
520 Sample* const sp = i->data();
521 apply_gain_to_buffer(sp,nframes,this_gain);
524 } else if (_gain == 0) {
525 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
533 /* actively recording, no monitoring required; leave buffers as-is to save CPU cycles */
537 /* ----------------------------------------------------------------------------------------------------
539 -------------------------------------------------------------------------------------------------- */
541 /* note that post_fader_work cannot be true unless with_inserts was also true, so don't test both */
543 if (post_fader_work) {
545 Glib::RWLock::ReaderLock rm (insert_lock, Glib::TRY_LOCK);
547 if (mute_gain > 0 || !_mute_affects_post_fader) {
548 for (i = _inserts.begin(); i != _inserts.end(); ++i) {
549 switch ((*i)->placement()) {
553 (*i)->run (bufs, start_frame, end_frame, nframes, offset);
558 for (i = _inserts.begin(); i != _inserts.end(); ++i) {
559 switch ((*i)->placement()) {
563 (*i)->silence (nframes, offset);
571 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_control_outs) {
572 Amp::run (bufs, nframes, mute_gain, dmg, false);
574 mute_declick_applied = true;
577 /* ----------------------------------------------------------------------------------------------------
579 -------------------------------------------------------------------------------------------------- */
581 if ((_meter_point == MeterPostFader) && co) {
583 solo_audible = solo_gain > 0;
584 mute_audible = dmg > 0 || !_mute_affects_control_outs;
586 if ( // silent anyway
588 (_gain == 0 && !apply_gain_automation) ||
590 // muted by solo of another track
594 // muted by mute of this track
598 // recording but not s/w monitoring
600 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
604 co->silence (nframes, offset);
608 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
612 /* ----------------------------------------------------------------------
614 ----------------------------------------------------------------------*/
616 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_main_outs) {
617 Amp::run (bufs, nframes, mute_gain, dmg, false);
619 mute_declick_applied = true;
622 /* ----------------------------------------------------------------------------------------------------
624 -------------------------------------------------------------------------------------------------- */
626 solo_audible = dsg > 0;
627 mute_audible = dmg > 0 || !_mute_affects_main_outs;
629 if (n_outputs().get(_default_type) == 0) {
633 } else if (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording())) {
635 IO::silence (nframes, offset);
639 if ( // silent anyway
641 (_gain == 0 && !apply_gain_automation) ||
643 // muted by solo of another track, but not using control outs for solo
645 (!solo_audible && (Config->get_solo_model() != SoloBus)) ||
647 // muted by mute of this track
653 /* don't use Route::silence() here, because that causes
654 all outputs (sends, port inserts, etc. to be silent).
657 if (_meter_point == MeterPostFader) {
658 peak_meter().reset();
661 IO::silence (nframes, offset);
665 deliver_output(bufs, start_frame, end_frame, nframes, offset);
671 /* ----------------------------------------------------------------------------------------------------
673 -------------------------------------------------------------------------------------------------- */
675 if (meter && (_meter_point == MeterPostFader)) {
676 if ((_gain == 0 && !apply_gain_automation) || dmg == 0) {
679 _meter->run(output_buffers(), start_frame, end_frame, nframes, offset);
685 Route::n_process_buffers ()
687 return max (n_inputs(), insert_max_outs);
691 Route::passthru (nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset, int declick, bool meter_first)
693 BufferSet& bufs = _session.get_scratch_buffers(n_process_buffers());
697 collect_input (bufs, nframes, offset);
700 _meter->run(bufs, start_frame, end_frame, nframes, offset);
704 process_output_buffers (bufs, start_frame, end_frame, nframes, offset, true, declick, meter_first);
708 Route::passthru_silence (nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset, int declick, bool meter)
710 process_output_buffers (_session.get_silent_buffers (n_process_buffers()), start_frame, end_frame, nframes, offset, true, declick, meter);
714 Route::set_solo (bool yn, void *src)
720 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
721 _mix_group->apply (&Route::set_solo, yn, _mix_group);
727 solo_changed (src); /* EMIT SIGNAL */
728 _solo_control.Changed (); /* EMIT SIGNAL */
733 Route::set_solo_mute (bool yn)
735 Glib::Mutex::Lock lm (declick_lock);
737 /* Called by Session in response to another Route being soloed.
740 desired_solo_gain = (yn?0.0:1.0);
744 Route::set_solo_safe (bool yn, void *src)
746 if (_solo_safe != yn) {
748 solo_safe_changed (src); /* EMIT SIGNAL */
753 Route::set_mute (bool yn, void *src)
756 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
757 _mix_group->apply (&Route::set_mute, yn, _mix_group);
763 mute_changed (src); /* EMIT SIGNAL */
765 _mute_control.Changed (); /* EMIT SIGNAL */
767 Glib::Mutex::Lock lm (declick_lock);
768 desired_mute_gain = (yn?0.0f:1.0f);
773 Route::add_insert (boost::shared_ptr<Insert> insert, InsertStreams* err)
775 ChanCount old_rmo = insert_max_outs;
777 if (!_session.engine().connected()) {
782 Glib::RWLock::WriterLock lm (insert_lock);
784 boost::shared_ptr<PluginInsert> pi;
785 boost::shared_ptr<PortInsert> porti;
787 //insert->set_default_type(_default_type);
789 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(insert)) != 0) {
792 if (pi->natural_input_streams() == ChanCount::ZERO) {
793 /* generator plugin */
794 _have_internal_generator = true;
799 _inserts.push_back (insert);
801 // Set up insert list channels. This will set insert->[input|output]_streams(),
802 // configure redirect ports properly, etc.
803 if (_reset_plugin_counts (err)) {
804 _inserts.pop_back ();
805 _reset_plugin_counts (0); // it worked before we tried to add it ...
809 // Ensure peak vector sizes before the plugin is activated
810 ChanCount potential_max_streams = max(insert->input_streams(), insert->output_streams());
811 _meter->configure_io(potential_max_streams, potential_max_streams);
814 insert->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
817 if (insert_max_outs != old_rmo || old_rmo == ChanCount::ZERO) {
822 inserts_changed (); /* EMIT SIGNAL */
827 Route::add_inserts (const InsertList& others, InsertStreams* err)
829 ChanCount old_rmo = insert_max_outs;
831 if (!_session.engine().connected()) {
836 Glib::RWLock::WriterLock lm (insert_lock);
838 InsertList::iterator existing_end = _inserts.end();
841 ChanCount potential_max_streams;
843 for (InsertList::const_iterator i = others.begin(); i != others.end(); ++i) {
845 boost::shared_ptr<PluginInsert> pi;
847 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
850 ChanCount m = max(pi->input_streams(), pi->output_streams());
851 if (m > potential_max_streams)
852 potential_max_streams = m;
855 // Ensure peak vector sizes before the plugin is activated
856 _meter->configure_io(potential_max_streams, potential_max_streams);
858 _inserts.push_back (*i);
860 if (_reset_plugin_counts (err)) {
862 _inserts.erase (existing_end, _inserts.end());
863 _reset_plugin_counts (0); // it worked before we tried to add it ...
868 (*i)->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
872 if (insert_max_outs != old_rmo || old_rmo == ChanCount::ZERO) {
876 inserts_changed (); /* EMIT SIGNAL */
880 /** Turn off all inserts with a given placement
881 * @param p Placement of inserts to disable
885 Route::disable_inserts (Placement p)
887 Glib::RWLock::ReaderLock lm (insert_lock);
889 for (InsertList::iterator i = _inserts.begin(); i != _inserts.end(); ++i) {
890 if ((*i)->placement() == p) {
891 (*i)->set_active (false);
895 _session.set_dirty ();
898 /** Turn off all redirects
902 Route::disable_inserts ()
904 Glib::RWLock::ReaderLock lm (insert_lock);
906 for (InsertList::iterator i = _inserts.begin(); i != _inserts.end(); ++i) {
907 (*i)->set_active (false);
910 _session.set_dirty ();
913 /** Turn off all redirects with a given placement
914 * @param p Placement of redirects to disable
918 Route::disable_plugins (Placement p)
920 Glib::RWLock::ReaderLock lm (insert_lock);
922 for (InsertList::iterator i = _inserts.begin(); i != _inserts.end(); ++i) {
923 if (boost::dynamic_pointer_cast<PluginInsert> (*i) && (*i)->placement() == p) {
924 (*i)->set_active (false);
928 _session.set_dirty ();
931 /** Turn off all plugins
935 Route::disable_plugins ()
937 Glib::RWLock::ReaderLock lm (insert_lock);
939 for (InsertList::iterator i = _inserts.begin(); i != _inserts.end(); ++i) {
940 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
941 (*i)->set_active (false);
945 _session.set_dirty ();
950 Route::ab_plugins (bool forward)
952 Glib::RWLock::ReaderLock lm (insert_lock);
956 /* forward = turn off all active redirects, and mark them so that the next time
957 we go the other way, we will revert them
960 for (InsertList::iterator i = _inserts.begin(); i != _inserts.end(); ++i) {
961 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
965 if ((*i)->active()) {
966 (*i)->set_active (false);
967 (*i)->set_next_ab_is_active (true);
969 (*i)->set_next_ab_is_active (false);
975 /* backward = if the redirect was marked to go active on the next ab, do so */
977 for (InsertList::iterator i = _inserts.begin(); i != _inserts.end(); ++i) {
979 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
983 if ((*i)->get_next_ab_is_active()) {
984 (*i)->set_active (true);
986 (*i)->set_active (false);
991 _session.set_dirty ();
995 /* Figure out the streams that will feed into PreFader */
997 Route::pre_fader_streams() const
999 boost::shared_ptr<Insert> insert;
1001 // Find the last pre-fader redirect
1002 for (InsertList::const_iterator i = _inserts.begin(); i != _inserts.end(); ++i) {
1003 if ((*i)->placement() == PreFader) {
1009 return insert->output_streams();
1016 /** Remove inserts with a given placement.
1017 * @param p Placement of inserts to remove.
1020 Route::clear_inserts (Placement p)
1022 const ChanCount old_rmo = insert_max_outs;
1024 if (!_session.engine().connected()) {
1029 Glib::RWLock::WriterLock lm (insert_lock);
1030 InsertList new_list;
1032 for (InsertList::iterator i = _inserts.begin(); i != _inserts.end(); ++i) {
1033 if ((*i)->placement() == p) {
1034 /* it's the placement we want to get rid of */
1035 (*i)->drop_references ();
1037 /* it's a different placement, so keep it */
1038 new_list.push_back (*i);
1042 _inserts = new_list;
1045 /* FIXME: can't see how this test can ever fire */
1046 if (insert_max_outs != old_rmo) {
1050 insert_max_outs.reset();
1051 _have_internal_generator = false;
1052 inserts_changed (); /* EMIT SIGNAL */
1056 Route::remove_insert (boost::shared_ptr<Insert> insert, InsertStreams* err)
1058 ChanCount old_rmo = insert_max_outs;
1060 if (!_session.engine().connected()) {
1064 insert_max_outs.reset();
1067 Glib::RWLock::WriterLock lm (insert_lock);
1068 InsertList::iterator i;
1069 bool removed = false;
1071 for (i = _inserts.begin(); i != _inserts.end(); ++i) {
1074 InsertList::iterator tmp;
1076 /* move along, see failure case for reset_plugin_counts()
1077 where we may need to reinsert the insert.
1083 /* stop redirects that send signals to JACK ports
1084 from causing noise as a result of no longer being
1088 boost::shared_ptr<Redirect> redirect;
1090 if ((redirect = boost::dynamic_pointer_cast<Redirect> (*i)) != 0) {
1091 redirect->io()->disconnect_inputs (this);
1092 redirect->io()->disconnect_outputs (this);
1108 if (_reset_plugin_counts (err)) {
1109 /* get back to where we where */
1110 _inserts.insert (i, insert);
1111 /* we know this will work, because it worked before :) */
1112 _reset_plugin_counts (0);
1118 for (i = _inserts.begin(); i != _inserts.end(); ++i) {
1119 boost::shared_ptr<PluginInsert> pi;
1121 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1122 if (pi->is_generator()) {
1128 _have_internal_generator = foo;
1131 if (old_rmo != insert_max_outs) {
1135 insert->drop_references ();
1137 inserts_changed (); /* EMIT SIGNAL */
1142 Route::reset_plugin_counts (InsertStreams* err)
1144 Glib::RWLock::WriterLock lm (insert_lock);
1145 return _reset_plugin_counts (err);
1150 Route::_reset_plugin_counts (InsertStreams* err)
1152 InsertList::iterator r;
1153 map<Placement,list<InsertCount> > insert_map;
1154 ChanCount initial_streams;
1156 /* Process each placement in order, checking to see if we
1157 can really do what has been requested.
1160 /* divide inserts up by placement so we get the signal flow
1161 properly modelled. we need to do this because the _inserts
1162 list is not sorted by placement
1165 /* ... but it should/will be... */
1167 for (r = _inserts.begin(); r != _inserts.end(); ++r) {
1169 boost::shared_ptr<Insert> insert;
1171 if ((insert = boost::dynamic_pointer_cast<Insert>(*r)) != 0) {
1172 insert_map[insert->placement()].push_back (InsertCount (insert));
1179 if ( ! check_some_plugin_counts (insert_map[PreFader], n_inputs (), err)) {
1183 ChanCount post_fader_input = (err ? err->count : n_inputs());
1187 if ( ! check_some_plugin_counts (insert_map[PostFader], post_fader_input, err)) {
1191 /* OK, everything can be set up correctly, so lets do it */
1193 apply_some_plugin_counts (insert_map[PreFader]);
1194 apply_some_plugin_counts (insert_map[PostFader]);
1196 /* recompute max outs of any insert */
1198 insert_max_outs.reset();
1199 InsertList::iterator prev = _inserts.end();
1201 for (r = _inserts.begin(); r != _inserts.end(); prev = r, ++r) {
1202 insert_max_outs = max ((*r)->output_streams (), insert_max_outs);
1211 Route::apply_some_plugin_counts (list<InsertCount>& iclist)
1213 list<InsertCount>::iterator i;
1215 for (i = iclist.begin(); i != iclist.end(); ++i) {
1217 if ((*i).insert->configure_io ((*i).in, (*i).out)) {
1220 /* make sure that however many we have, they are all active */
1221 (*i).insert->activate ();
1227 /** Returns whether \a iclist can be configured and run starting with
1228 * \a required_inputs at the first insert's inputs.
1229 * If false is returned, \a iclist can not be run with \a required_inputs, and \a err is set.
1230 * Otherwise, \a err is set to the output of the list.
1233 Route::check_some_plugin_counts (list<InsertCount>& iclist, ChanCount required_inputs, InsertStreams* err)
1235 list<InsertCount>::iterator i;
1240 err->count = required_inputs;
1243 for (i = iclist.begin(); i != iclist.end(); ++i) {
1245 if ((*i).insert->can_support_input_configuration (required_inputs) < 0) {
1248 err->count = required_inputs;
1253 (*i).in = required_inputs;
1254 (*i).out = (*i).insert->output_for_input_configuration (required_inputs);
1256 required_inputs = (*i).out;
1262 if (!iclist.empty()) {
1264 err->count = iclist.back().insert->output_for_input_configuration(required_inputs);
1272 Route::copy_inserts (const Route& other, Placement placement, InsertStreams* err)
1274 ChanCount old_rmo = insert_max_outs;
1276 InsertList to_be_deleted;
1279 Glib::RWLock::WriterLock lm (insert_lock);
1280 InsertList::iterator tmp;
1281 InsertList the_copy;
1283 the_copy = _inserts;
1285 /* remove all relevant inserts */
1287 for (InsertList::iterator i = _inserts.begin(); i != _inserts.end(); ) {
1291 if ((*i)->placement() == placement) {
1292 to_be_deleted.push_back (*i);
1299 /* now copy the relevant ones from "other" */
1301 for (InsertList::const_iterator i = other._inserts.begin(); i != other._inserts.end(); ++i) {
1302 if ((*i)->placement() == placement) {
1303 _inserts.push_back (Redirect::clone (*i));
1307 /* reset plugin stream handling */
1309 if (_reset_plugin_counts (err)) {
1311 /* FAILED COPY ATTEMPT: we have to restore order */
1313 /* delete all cloned inserts */
1315 for (InsertList::iterator i = _inserts.begin(); i != _inserts.end(); ) {
1320 if ((*i)->placement() == placement) {
1327 /* restore the natural order */
1329 _inserts = the_copy;
1330 insert_max_outs = old_rmo;
1332 /* we failed, even though things are OK again */
1338 /* SUCCESSFUL COPY ATTEMPT: delete the inserts we removed pre-copy */
1339 to_be_deleted.clear ();
1343 if (insert_max_outs != old_rmo || old_rmo == ChanCount::ZERO) {
1347 inserts_changed (); /* EMIT SIGNAL */
1352 Route::all_inserts_flip ()
1354 Glib::RWLock::ReaderLock lm (insert_lock);
1356 if (_inserts.empty()) {
1360 bool first_is_on = _inserts.front()->active();
1362 for (InsertList::iterator i = _inserts.begin(); i != _inserts.end(); ++i) {
1363 (*i)->set_active (!first_is_on);
1366 _session.set_dirty ();
1369 /** Set all inserts with a given placement to a given active state.
1370 * @param p Placement of inserts to change.
1371 * @param state New active state for those inserts.
1374 Route::all_inserts_active (Placement p, bool state)
1376 Glib::RWLock::ReaderLock lm (insert_lock);
1378 if (_inserts.empty()) {
1382 for (InsertList::iterator i = _inserts.begin(); i != _inserts.end(); ++i) {
1383 if ((*i)->placement() == p) {
1384 (*i)->set_active (state);
1388 _session.set_dirty ();
1391 struct InsertSorter {
1392 bool operator() (boost::shared_ptr<const Insert> a, boost::shared_ptr<const Insert> b) {
1393 return a->sort_key() < b->sort_key();
1398 Route::sort_inserts (InsertStreams* err)
1401 InsertSorter comparator;
1402 Glib::RWLock::WriterLock lm (insert_lock);
1403 ChanCount old_rmo = insert_max_outs;
1405 /* the sweet power of C++ ... */
1407 InsertList as_it_was_before = _inserts;
1409 _inserts.sort (comparator);
1411 if (_reset_plugin_counts (err)) {
1412 _inserts = as_it_was_before;
1413 insert_max_outs = old_rmo;
1419 inserts_changed (); /* EMIT SIGNAL */
1431 Route::get_template()
1433 return state(false);
1437 Route::state(bool full_state)
1439 XMLNode *node = new XMLNode("Route");
1440 InsertList:: iterator i;
1444 node->add_property("flags", enum_2_string (_flags));
1447 node->add_property("default-type", _default_type.to_string());
1449 node->add_property("active", _active?"yes":"no");
1450 node->add_property("muted", _muted?"yes":"no");
1451 node->add_property("soloed", _soloed?"yes":"no");
1452 node->add_property("phase-invert", _phase_invert?"yes":"no");
1453 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
1454 node->add_property("mute-affects-pre-fader", _mute_affects_pre_fader?"yes":"no");
1455 node->add_property("mute-affects-post-fader", _mute_affects_post_fader?"yes":"no");
1456 node->add_property("mute-affects-control-outs", _mute_affects_control_outs?"yes":"no");
1457 node->add_property("mute-affects-main-outs", _mute_affects_main_outs?"yes":"no");
1460 node->add_property("edit-group", _edit_group->name());
1463 node->add_property("mix-group", _mix_group->name());
1466 string order_string;
1467 OrderKeys::iterator x = order_keys.begin();
1469 while (x != order_keys.end()) {
1470 order_string += string ((*x).first);
1471 order_string += '=';
1472 snprintf (buf, sizeof(buf), "%ld", (*x).second);
1473 order_string += buf;
1477 if (x == order_keys.end()) {
1481 order_string += ':';
1483 node->add_property ("order-keys", order_string);
1485 node->add_child_nocopy (IO::state (full_state));
1486 node->add_child_nocopy (_solo_control.get_state ());
1487 node->add_child_nocopy (_mute_control.get_state ());
1489 XMLNode* remote_control_node = new XMLNode (X_("remote_control"));
1490 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
1491 remote_control_node->add_property (X_("id"), buf);
1492 node->add_child_nocopy (*remote_control_node);
1494 if (_control_outs) {
1495 XMLNode* cnode = new XMLNode (X_("ControlOuts"));
1496 cnode->add_child_nocopy (_control_outs->state (full_state));
1497 node->add_child_nocopy (*cnode);
1500 if (_comment.length()) {
1501 XMLNode *cmt = node->add_child ("Comment");
1502 cmt->add_content (_comment);
1505 for (i = _inserts.begin(); i != _inserts.end(); ++i) {
1506 node->add_child_nocopy((*i)->state (full_state));
1510 node->add_child_copy (*_extra_xml);
1517 Route::get_insert_state ()
1519 XMLNode* root = new XMLNode (X_("redirects"));
1520 for (InsertList::iterator i = _inserts.begin(); i != _inserts.end(); ++i) {
1521 root->add_child_nocopy ((*i)->state (true));
1528 Route::set_insert_state (const XMLNode& root)
1530 if (root.name() != X_("redirects")) {
1536 XMLNodeConstIterator iter;
1537 XMLNodeConstIterator niter;
1538 Glib::RWLock::ReaderLock lm (insert_lock);
1540 nlist = root.children();
1542 for (iter = nlist.begin(); iter != nlist.end(); ++iter){
1544 /* iter now points to a Redirect state node */
1546 nnlist = (*iter)->children ();
1548 for (niter = nnlist.begin(); niter != nnlist.end(); ++niter) {
1550 /* find the IO child node, since it contains the ID we need */
1552 /* XXX OOP encapsulation violation, ugh */
1554 if ((*niter)->name() == IO::state_node_name) {
1556 XMLProperty* prop = (*niter)->property (X_("id"));
1559 warning << _("Redirect node has no ID, ignored") << endmsg;
1563 ID id = prop->value ();
1565 /* now look for a insert with that ID */
1567 for (InsertList::iterator i = _inserts.begin(); i != _inserts.end(); ++i) {
1568 if ((*i)->id() == id) {
1569 (*i)->set_state (**iter);
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_insert_from_xml (**niter);
1600 delete deferred_state;
1605 Route::add_insert_from_xml (const XMLNode& node)
1607 const XMLProperty *prop;
1609 // legacy sessions use a different node name for sends
1610 if (node.name() == "Send") {
1613 boost::shared_ptr<Send> send (new Send (_session, node));
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;
1629 if (prop->value() == "ladspa" || prop->value() == "Ladspa" || prop->value() == "vst") {
1631 insert.reset (new PluginInsert(_session, node));
1633 } else if (prop->value() == "port") {
1635 insert.reset (new PortInsert (_session, node));
1637 } else if (prop->value() == "send") {
1639 insert.reset (new Send (_session, node));
1643 error << string_compose(_("unknown Insert type \"%1\"; ignored"), prop->value()) << endmsg;
1646 add_insert (insert);
1649 error << _("Insert XML node has no type property") << endmsg;
1653 catch (failed_constructor &err) {
1654 warning << _("insert could not be created. Ignored.") << endmsg;
1661 Route::set_state (const XMLNode& node)
1663 return _set_state (node, true);
1667 Route::_set_state (const XMLNode& node, bool call_base)
1670 XMLNodeConstIterator niter;
1672 XMLPropertyList plist;
1673 const XMLProperty *prop;
1675 if (node.name() != "Route"){
1676 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
1680 if ((prop = node.property (X_("flags"))) != 0) {
1681 _flags = Flag (string_2_enum (prop->value(), _flags));
1686 if ((prop = node.property (X_("default-type"))) != 0) {
1687 _default_type = DataType(prop->value());
1688 assert(_default_type != DataType::NIL);
1691 if ((prop = node.property (X_("phase-invert"))) != 0) {
1692 set_phase_invert (prop->value()=="yes"?true:false, this);
1695 if ((prop = node.property (X_("denormal-protection"))) != 0) {
1696 set_denormal_protection (prop->value()=="yes"?true:false, this);
1699 if ((prop = node.property (X_("active"))) != 0) {
1700 set_active (prop->value() == "yes");
1703 if ((prop = node.property (X_("muted"))) != 0) {
1704 bool yn = prop->value()=="yes"?true:false;
1706 /* force reset of mute status */
1710 mute_gain = desired_mute_gain;
1713 if ((prop = node.property (X_("soloed"))) != 0) {
1714 bool yn = prop->value()=="yes"?true:false;
1716 /* force reset of solo status */
1719 set_solo (yn, this);
1720 solo_gain = desired_solo_gain;
1723 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
1724 _mute_affects_pre_fader = (prop->value()=="yes")?true:false;
1727 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
1728 _mute_affects_post_fader = (prop->value()=="yes")?true:false;
1731 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
1732 _mute_affects_control_outs = (prop->value()=="yes")?true:false;
1735 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
1736 _mute_affects_main_outs = (prop->value()=="yes")?true:false;
1739 if ((prop = node.property (X_("edit-group"))) != 0) {
1740 RouteGroup* edit_group = _session.edit_group_by_name(prop->value());
1741 if(edit_group == 0) {
1742 error << string_compose(_("Route %1: unknown edit group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
1744 set_edit_group(edit_group, this);
1748 if ((prop = node.property (X_("order-keys"))) != 0) {
1752 string::size_type colon, equal;
1753 string remaining = prop->value();
1755 while (remaining.length()) {
1757 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
1758 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1761 if (sscanf (remaining.substr (equal+1).c_str(), "%ld", &n) != 1) {
1762 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1765 set_order_key (remaining.substr (0, equal).c_str(), n);
1769 colon = remaining.find_first_of (':');
1771 if (colon != string::npos) {
1772 remaining = remaining.substr (colon+1);
1779 nlist = node.children();
1781 if (deferred_state) {
1782 delete deferred_state;
1785 deferred_state = new XMLNode(X_("deferred state"));
1787 /* set parent class properties before anything else */
1789 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1793 if (child->name() == IO::state_node_name && call_base) {
1795 IO::set_state (*child);
1800 XMLNodeList insert_nodes;
1802 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1806 if (child->name() == X_("Send") || child->name() == X_("Insert")) {
1807 insert_nodes.push_back(child);
1812 _set_insert_states(insert_nodes);
1815 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1817 // All inserts have been applied already
1819 if (child->name() == X_("Automation")) {
1821 if ((prop = child->property (X_("path"))) != 0) {
1822 load_automation (prop->value());
1825 } else if (child->name() == X_("ControlOuts")) {
1827 string coutname = _name;
1828 coutname += _("[control]");
1830 _control_outs = new IO (_session, coutname);
1831 _control_outs->set_state (**(child->children().begin()));
1833 } else if (child->name() == X_("Comment")) {
1835 /* XXX this is a terrible API design in libxml++ */
1837 XMLNode *cmt = *(child->children().begin());
1838 _comment = cmt->content();
1840 } else if (child->name() == X_("extra")) {
1842 _extra_xml = new XMLNode (*child);
1844 } else if (child->name() == X_("controllable") && (prop = child->property("name")) != 0) {
1846 if (prop->value() == "solo") {
1847 _solo_control.set_state (*child);
1848 _session.add_controllable (&_solo_control);
1850 else if (prop->value() == "mute") {
1851 _mute_control.set_state (*child);
1852 _session.add_controllable (&_mute_control);
1855 else if (child->name() == X_("remote_control")) {
1856 if ((prop = child->property (X_("id"))) != 0) {
1858 sscanf (prop->value().c_str(), "%d", &x);
1859 set_remote_control_id (x);
1864 if ((prop = node.property (X_("mix-group"))) != 0) {
1865 RouteGroup* mix_group = _session.mix_group_by_name(prop->value());
1866 if (mix_group == 0) {
1867 error << string_compose(_("Route %1: unknown mix group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
1869 set_mix_group(mix_group, this);
1877 Route::_set_insert_states(const XMLNodeList &nlist)
1879 XMLNodeConstIterator niter;
1882 InsertList::iterator i, o;
1884 // Iterate through existing inserts, remove those which are not in the state list
1885 for (i = _inserts.begin(); i != _inserts.end(); ) {
1886 InsertList::iterator tmp = i;
1889 bool insertInStateList = false;
1891 (*i)->id().print (buf, sizeof (buf));
1894 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1896 // legacy sessions (Redirect as a child of Insert, both is-a IO)
1897 if (strncmp(buf,(*niter)->child(X_("Redirect"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf)) == 0) {
1898 insertInStateList = true;
1900 } else if (strncmp(buf,(*niter)->property(X_("id"))->value().c_str(), sizeof(buf)) == 0) {
1901 insertInStateList = true;
1906 if (!insertInStateList) {
1915 // Iterate through state list and make sure all inserts are on the track and in the correct order,
1916 // set the state of existing inserts according to the new state on the same go
1917 i = _inserts.begin();
1918 for (niter = nlist.begin(); niter != nlist.end(); ++niter, ++i) {
1920 // Check whether the next insert in the list
1923 while (o != _inserts.end()) {
1924 (*o)->id().print (buf, sizeof (buf));
1925 if ( strncmp(buf, (*niter)->child(X_("Redirect"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf)) == 0)
1927 else if (strncmp(buf,(*niter)->property(X_("id"))->value().c_str(), sizeof(buf)) == 0)
1933 if (o == _inserts.end()) {
1934 // If the insert (*niter) is not on the route, we need to create it
1935 // and move it to the correct location
1937 InsertList::iterator prev_last = _inserts.end();
1938 --prev_last; // We need this to check whether adding succeeded
1940 add_insert_from_xml (**niter);
1942 InsertList::iterator last = _inserts.end();
1945 if (prev_last == last) {
1946 cerr << "Could not fully restore state as some inserts were not possible to create" << endl;
1951 boost::shared_ptr<Insert> tmp = (*last);
1952 // remove the insert from the wrong location
1953 _inserts.erase(last);
1954 // insert the new insert at the current location
1955 _inserts.insert(i, tmp);
1957 --i; // move pointer to the newly inserted insert
1961 // We found the insert (*niter) on the route, first we must make sure the insert
1962 // is at the location provided in the XML state
1964 boost::shared_ptr<Insert> tmp = (*o);
1965 // remove the old copy
1967 // insert the insert at the correct location
1968 _inserts.insert(i, tmp);
1970 --i; // move pointer so it points to the right insert
1973 (*i)->set_state( (**niter) );
1980 Route::curve_reallocate ()
1982 // _gain_automation_curve.finish_resize ();
1983 // _pan_automation_curve.finish_resize ();
1987 Route::silence (nframes_t nframes, nframes_t offset)
1991 IO::silence (nframes, offset);
1993 if (_control_outs) {
1994 _control_outs->silence (nframes, offset);
1998 Glib::RWLock::ReaderLock lm (insert_lock, Glib::TRY_LOCK);
2001 for (InsertList::iterator i = _inserts.begin(); i != _inserts.end(); ++i) {
2002 boost::shared_ptr<PluginInsert> pi;
2003 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2004 // skip plugins, they don't need anything when we're not active
2008 (*i)->silence (nframes, offset);
2011 if (nframes == _session.get_block_size() && offset == 0) {
2021 Route::set_control_outs (const vector<string>& ports)
2023 Glib::Mutex::Lock lm (control_outs_lock);
2024 vector<string>::const_iterator i;
2027 if (_control_outs) {
2028 delete _control_outs;
2032 if (control() || master()) {
2033 /* no control outs for these two special busses */
2037 if (ports.empty()) {
2041 string coutname = _name;
2042 coutname += _("[control]");
2044 _control_outs = new IO (_session, coutname);
2046 /* our control outs need as many outputs as we
2047 have audio outputs. we track the changes in ::output_change_handler().
2050 // XXX its stupid that we have to get this value twice
2052 limit = n_outputs().n_audio();
2054 if (_control_outs->ensure_io (ChanCount::ZERO, ChanCount (DataType::AUDIO, n_outputs().get (DataType::AUDIO)), true, this)) {
2058 /* now connect to the named ports */
2060 for (size_t n = 0; n < limit; ++n) {
2061 if (_control_outs->connect_output (_control_outs->output (n), ports[n], this)) {
2062 error << string_compose (_("could not connect %1 to %2"), _control_outs->output(n)->name(), ports[n]) << endmsg;
2071 Route::set_edit_group (RouteGroup *eg, void *src)
2074 if (eg == _edit_group) {
2079 _edit_group->remove (this);
2082 if ((_edit_group = eg) != 0) {
2083 _edit_group->add (this);
2086 _session.set_dirty ();
2087 edit_group_changed (src); /* EMIT SIGNAL */
2091 Route::drop_edit_group (void *src)
2094 _session.set_dirty ();
2095 edit_group_changed (src); /* EMIT SIGNAL */
2099 Route::set_mix_group (RouteGroup *mg, void *src)
2102 if (mg == _mix_group) {
2107 _mix_group->remove (this);
2110 if ((_mix_group = mg) != 0) {
2111 _mix_group->add (this);
2114 _session.set_dirty ();
2115 mix_group_changed (src); /* EMIT SIGNAL */
2119 Route::drop_mix_group (void *src)
2122 _session.set_dirty ();
2123 mix_group_changed (src); /* EMIT SIGNAL */
2127 Route::set_comment (string cmt, void *src)
2130 comment_changed (src);
2131 _session.set_dirty ();
2135 Route::feeds (boost::shared_ptr<Route> other)
2140 uint32_t no = self.n_outputs().n_total();
2141 uint32_t ni = other->n_inputs ().n_total();
2143 for (i = 0; i < no; ++i) {
2144 for (j = 0; j < ni; ++j) {
2145 if (self.output(i)->connected_to (other->input(j)->name())) {
2151 /* check Redirects which may also interconnect Routes */
2153 for (InsertList::iterator r = _inserts.begin(); r != _inserts.end(); r++) {
2155 boost::shared_ptr<Redirect> redirect = boost::dynamic_pointer_cast<Redirect>(*r);
2160 // TODO: support internal redirects here
2162 no = redirect->io()->n_outputs().n_total();
2164 for (i = 0; i < no; ++i) {
2165 for (j = 0; j < ni; ++j) {
2166 if (redirect->io()->output(i)->connected_to (other->input (j)->name())) {
2173 /* check for control room outputs which may also interconnect Routes */
2175 if (_control_outs) {
2177 no = _control_outs->n_outputs().n_total();
2179 for (i = 0; i < no; ++i) {
2180 for (j = 0; j < ni; ++j) {
2181 if (_control_outs->output(i)->connected_to (other->input (j)->name())) {
2192 Route::set_mute_config (mute_type t, bool onoff, void *src)
2196 _mute_affects_pre_fader = onoff;
2197 pre_fader_changed(src); /* EMIT SIGNAL */
2201 _mute_affects_post_fader = onoff;
2202 post_fader_changed(src); /* EMIT SIGNAL */
2206 _mute_affects_control_outs = onoff;
2207 control_outs_changed(src); /* EMIT SIGNAL */
2211 _mute_affects_main_outs = onoff;
2212 main_outs_changed(src); /* EMIT SIGNAL */
2218 Route::get_mute_config (mute_type t)
2224 onoff = _mute_affects_pre_fader;
2227 onoff = _mute_affects_post_fader;
2230 onoff = _mute_affects_control_outs;
2233 onoff = _mute_affects_main_outs;
2241 Route::set_active (bool yn)
2244 active_changed(); /* EMIT SIGNAL */
2248 Route::handle_transport_stopped (bool abort_ignored, bool did_locate, bool can_flush_inserts)
2250 nframes_t now = _session.transport_frame();
2253 Glib::RWLock::ReaderLock lm (insert_lock);
2256 automation_snapshot (now);
2259 for (InsertList::iterator i = _inserts.begin(); i != _inserts.end(); ++i) {
2261 if (Config->get_plugins_stop_with_transport() && can_flush_inserts) {
2262 (*i)->deactivate ();
2266 (*i)->transport_stopped (now);
2270 IO::transport_stopped (now);
2272 _roll_delay = _initial_delay;
2276 Route::input_change_handler (IOChange change, void *ignored)
2278 if (change & ConfigurationChanged) {
2279 reset_plugin_counts (0);
2284 Route::output_change_handler (IOChange change, void *ignored)
2286 if (change & ConfigurationChanged) {
2287 if (_control_outs) {
2288 _control_outs->ensure_io (ChanCount::ZERO, ChanCount(DataType::AUDIO, n_outputs().n_audio()), true, this);
2291 reset_plugin_counts (0);
2296 Route::pans_required () const
2298 if (n_outputs().n_audio() < 2) {
2302 return max (n_inputs ().n_audio(), static_cast<size_t>(insert_max_outs.n_audio()));
2306 Route::no_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
2307 bool session_state_changing, bool can_record, bool rec_monitors_input)
2309 if (n_outputs().n_total() == 0) {
2313 if (session_state_changing || !_active) {
2314 silence (nframes, offset);
2318 apply_gain_automation = false;
2320 if (n_inputs().n_total()) {
2321 passthru (start_frame, end_frame, nframes, offset, 0, false);
2323 silence (nframes, offset);
2330 Route::check_initial_delay (nframes_t nframes, nframes_t& offset, nframes_t& transport_frame)
2332 if (_roll_delay > nframes) {
2334 _roll_delay -= nframes;
2335 silence (nframes, offset);
2336 /* transport frame is not legal for caller to use */
2339 } else if (_roll_delay > 0) {
2341 nframes -= _roll_delay;
2343 silence (_roll_delay, offset);
2345 offset += _roll_delay;
2346 transport_frame += _roll_delay;
2355 Route::roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset, int declick,
2356 bool can_record, bool rec_monitors_input)
2359 Glib::RWLock::ReaderLock lm (insert_lock, Glib::TRY_LOCK);
2361 // automation snapshot can also be called from the non-rt context
2362 // and it uses the insert list, so we take the lock out here
2363 automation_snapshot (_session.transport_frame());
2367 if ((n_outputs().n_total() == 0 && _inserts.empty()) || n_inputs().n_total() == 0 || !_active) {
2368 silence (nframes, offset);
2372 nframes_t unused = 0;
2374 if ((nframes = check_initial_delay (nframes, offset, unused)) == 0) {
2380 apply_gain_automation = false;
2383 Glib::Mutex::Lock am (automation_lock, Glib::TRY_LOCK);
2385 if (am.locked() && _session.transport_rolling()) {
2387 if (_gain_automation_curve.automation_playback()) {
2388 apply_gain_automation = _gain_automation_curve.rt_safe_get_vector (start_frame, end_frame, _session.gain_automation_buffer(), nframes);
2393 passthru (start_frame, end_frame, nframes, offset, declick, false);
2399 Route::silent_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
2400 bool can_record, bool rec_monitors_input)
2402 silence (nframes, offset);
2407 Route::toggle_monitor_input ()
2409 for (PortSet::iterator i = _inputs.begin(); i != _inputs.end(); ++i) {
2410 i->ensure_monitor_input( ! i->monitoring_input());
2415 Route::has_external_redirects () const
2417 // FIXME: what about sends?
2419 boost::shared_ptr<const PortInsert> pi;
2421 for (InsertList::const_iterator i = _inserts.begin(); i != _inserts.end(); ++i) {
2422 if ((pi = boost::dynamic_pointer_cast<const PortInsert>(*i)) != 0) {
2424 for (PortSet::const_iterator port = pi->io()->outputs().begin();
2425 port != pi->io()->outputs().end(); ++port) {
2427 string port_name = port->name();
2428 string client_name = port_name.substr (0, port_name.find(':'));
2430 /* only say "yes" if the redirect is actually in use */
2432 if (client_name != "ardour" && pi->active()) {
2443 Route::flush_inserts ()
2445 /* XXX shouldn't really try to take this lock, since
2446 this is called from the RT audio thread.
2449 Glib::RWLock::ReaderLock lm (insert_lock);
2451 for (InsertList::iterator i = _inserts.begin(); i != _inserts.end(); ++i) {
2452 (*i)->deactivate ();
2458 Route::set_meter_point (MeterPoint p, void *src)
2460 if (_meter_point != p) {
2462 meter_change (src); /* EMIT SIGNAL */
2463 _session.set_dirty ();
2468 Route::update_total_latency ()
2472 for (InsertList::iterator i = _inserts.begin(); i != _inserts.end(); ++i) {
2473 if ((*i)->active ()) {
2474 _own_latency += (*i)->latency ();
2478 set_port_latency (_own_latency);
2480 /* this (virtual) function is used for pure Routes,
2481 not derived classes like AudioTrack. this means
2482 that the data processed here comes from an input
2483 port, not prerecorded material, and therefore we
2484 have to take into account any input latency.
2487 _own_latency += input_latency ();
2489 return _own_latency;
2493 Route::set_latency_delay (nframes_t longest_session_latency)
2495 _initial_delay = longest_session_latency - _own_latency;
2497 if (_session.transport_stopped()) {
2498 _roll_delay = _initial_delay;
2503 Route::automation_snapshot (nframes_t now)
2505 IO::automation_snapshot (now);
2507 for (InsertList::iterator i = _inserts.begin(); i != _inserts.end(); ++i) {
2508 (*i)->automation_snapshot (now);
2512 Route::ToggleControllable::ToggleControllable (std::string name, Route& s, ToggleType tp)
2513 : Controllable (name), route (s), type(tp)
2519 Route::ToggleControllable::set_value (float val)
2521 bool bval = ((val >= 0.5f) ? true: false);
2525 route.set_mute (bval, this);
2528 route.set_solo (bval, this);
2536 Route::ToggleControllable::get_value (void) const
2542 val = route.muted() ? 1.0f : 0.0f;
2545 val = route.soloed() ? 1.0f : 0.0f;
2555 Route::set_block_size (nframes_t nframes)
2557 for (InsertList::iterator i = _inserts.begin(); i != _inserts.end(); ++i) {
2558 (*i)->set_block_size (nframes);
2563 Route::protect_automation ()
2565 switch (gain_automation_state()) {
2567 set_gain_automation_state (Off);
2569 set_gain_automation_state (Play);
2575 switch (panner().automation_state ()) {
2577 panner().set_automation_state (Off);
2580 panner().set_automation_state (Play);
2586 for (InsertList::iterator i = _inserts.begin(); i != _inserts.end(); ++i) {
2587 boost::shared_ptr<PluginInsert> pi;
2588 if ((pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2589 pi->protect_automation ();
2595 Route::set_pending_declick (int declick)
2598 /* this call is not allowed to turn off a pending declick unless "force" is true */
2600 _pending_declick = declick;
2602 // cerr << _name << ": after setting to " << declick << " pending declick = " << _pending_declick << endl;
2604 _pending_declick = 0;