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/processor.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 (new ToggleControllable (X_("solo"), *this, ToggleControllable::SoloControl)),
62 _mute_control (new ToggleControllable (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 (new ToggleControllable (X_("solo"), *this, ToggleControllable::SoloControl)),
70 _mute_control (new ToggleControllable (X_("mute"), *this, ToggleControllable::MuteControl))
73 _set_state (node, false);
79 processor_max_outs.reset();
83 _phase_invert = false;
84 _denormal_protection = false;
85 order_keys[strdup (N_("signal"))] = order_key_cnt++;
88 _meter_point = MeterPostFader;
93 _have_internal_generator = false;
95 _pending_declick = true;
96 _remote_control_id = 0;
101 _mute_affects_pre_fader = Config->get_mute_affects_pre_fader();
102 _mute_affects_post_fader = Config->get_mute_affects_post_fader();
103 _mute_affects_control_outs = Config->get_mute_affects_control_outs();
104 _mute_affects_main_outs = Config->get_mute_affects_main_outs();
107 desired_solo_gain = 1.0;
109 desired_mute_gain = 1.0;
113 input_changed.connect (mem_fun (this, &Route::input_change_handler));
114 output_changed.connect (mem_fun (this, &Route::output_change_handler));
119 clear_processors (PreFader);
120 clear_processors (PostFader);
122 for (OrderKeys::iterator i = order_keys.begin(); i != order_keys.end(); ++i) {
123 free ((void*)(i->first));
127 delete _control_outs;
132 Route::set_remote_control_id (uint32_t id)
134 if (id != _remote_control_id) {
135 _remote_control_id = id;
136 RemoteControlIDChanged ();
141 Route::remote_control_id() const
143 return _remote_control_id;
147 Route::order_key (const char* name) const
149 OrderKeys::const_iterator i;
151 for (i = order_keys.begin(); i != order_keys.end(); ++i) {
152 if (!strcmp (name, i->first)) {
161 Route::set_order_key (const char* name, long n)
163 order_keys[strdup(name)] = n;
164 _session.set_dirty ();
168 Route::inc_gain (gain_t fraction, void *src)
170 IO::inc_gain (fraction, src);
174 Route::set_gain (gain_t val, void *src)
176 if (src != 0 && _mix_group && src != _mix_group && _mix_group->is_active()) {
178 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;
195 gain_t factor = delta / usable_gain;
198 factor = _mix_group->get_max_factor(factor);
199 if (factor == 0.0f) {
200 _gain_control->Changed(); /* EMIT SIGNAL */
204 factor = _mix_group->get_min_factor(factor);
205 if (factor == 0.0f) {
206 _gain_control->Changed(); /* EMIT SIGNAL */
211 _mix_group->apply (&Route::inc_gain, factor, _mix_group);
215 _mix_group->apply (&Route::set_gain, val, _mix_group);
225 IO::set_gain (val, src);
228 /** Process this route for one (sub) cycle (process thread)
230 * @param bufs Scratch buffers to use for the signal path
231 * @param start_frame Initial transport frame
232 * @param end_frame Final transport frame
233 * @param nframes Number of frames to output (to ports)
234 * @param offset Output offset (of port buffers, for split cycles)
236 * Note that (end_frame - start_frame) may not be equal to nframes when the
237 * transport speed isn't 1.0 (eg varispeed).
240 Route::process_output_buffers (BufferSet& bufs,
241 nframes_t start_frame, nframes_t end_frame,
242 nframes_t nframes, nframes_t offset, bool with_processors, int declick,
245 // This is definitely very audio-only for now
246 assert(_default_type == DataType::AUDIO);
248 ProcessorList::iterator i;
249 bool post_fader_work = false;
250 bool mute_declick_applied = false;
256 gain_t* gab = _session.gain_automation_buffer();
258 switch (Config->get_monitoring_model()) {
259 case HardwareMonitoring:
260 case ExternalMonitoring:
267 declick = _pending_declick;
270 Glib::Mutex::Lock cm (_control_outs_lock, Glib::TRY_LOCK);
280 Glib::Mutex::Lock dm (declick_lock, Glib::TRY_LOCK);
283 dmg = desired_mute_gain;
284 dsg = desired_solo_gain;
293 /* ----------------------------------------------------------------------------------------------------
294 GLOBAL DECLICK (for transport changes etc.)
295 -------------------------------------------------------------------------------------------------- */
298 Amp::run_in_place (bufs, nframes, 0.0, 1.0, false);
299 _pending_declick = 0;
300 } else if (declick < 0) {
301 Amp::run_in_place (bufs, nframes, 1.0, 0.0, false);
302 _pending_declick = 0;
305 /* no global declick */
307 if (solo_gain != dsg) {
308 Amp::run_in_place (bufs, nframes, solo_gain, dsg, false);
314 /* ----------------------------------------------------------------------------------------------------
315 INPUT METERING & MONITORING
316 -------------------------------------------------------------------------------------------------- */
318 if (meter && (_meter_point == MeterInput)) {
319 _meter->run(bufs, start_frame, end_frame, nframes, offset);
322 if (!_soloed && _mute_affects_pre_fader && (mute_gain != dmg)) {
323 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
325 mute_declick_applied = true;
328 if ((_meter_point == MeterInput) && co) {
330 solo_audible = dsg > 0;
331 mute_audible = dmg > 0;// || !_mute_affects_pre_fader;
333 if ( // muted by solo of another track
337 // muted by mute of this track
341 // rec-enabled but not s/w monitoring
343 // TODO: this is probably wrong
345 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
349 co->silence (nframes, offset);
353 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
358 /* -----------------------------------------------------------------------------------------------------
360 -------------------------------------------------------------------------------------------------- */
362 if (_denormal_protection || Config->get_denormal_protection()) {
364 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
365 Sample* const sp = i->data();
367 for (nframes_t nx = offset; nx < nframes + offset; ++nx) {
373 /* ----------------------------------------------------------------------------------------------------
375 -------------------------------------------------------------------------------------------------- */
377 if (with_processors) {
378 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
380 if (mute_gain > 0 || !_mute_affects_pre_fader) {
381 for (i = _processors.begin(); i != _processors.end(); ++i) {
382 switch ((*i)->placement()) {
384 (*i)->run_in_place (bufs, start_frame, end_frame, nframes, offset);
387 post_fader_work = true;
392 for (i = _processors.begin(); i != _processors.end(); ++i) {
393 switch ((*i)->placement()) {
395 (*i)->silence (nframes, offset);
398 post_fader_work = true;
406 // This really should already be true...
407 bufs.set_count(pre_fader_streams());
409 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_post_fader) {
410 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
412 mute_declick_applied = true;
415 /* ----------------------------------------------------------------------------------------------------
416 PRE-FADER METERING & MONITORING
417 -------------------------------------------------------------------------------------------------- */
419 if (meter && (_meter_point == MeterPreFader)) {
420 _meter->run_in_place(bufs, start_frame, end_frame, nframes, offset);
424 if ((_meter_point == MeterPreFader) && co) {
426 solo_audible = dsg > 0;
427 mute_audible = dmg > 0 || !_mute_affects_pre_fader;
429 if ( // muted by solo of another track
433 // muted by mute of this track
437 // rec-enabled but not s/w monitoring
439 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
443 co->silence (nframes, offset);
447 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
451 /* ----------------------------------------------------------------------------------------------------
453 -------------------------------------------------------------------------------------------------- */
455 /* if not recording or recording and requiring any monitor signal, then apply gain */
457 if ( // not recording
459 !(record_enabled() && _session.actively_recording()) ||
463 // h/w monitoring not in use
465 (!Config->get_monitoring_model() == HardwareMonitoring &&
467 // AND software monitoring required
469 Config->get_monitoring_model() == SoftwareMonitoring)) {
471 if (apply_gain_automation) {
474 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
475 Sample* const sp = i->data();
477 for (nframes_t nx = 0; nx < nframes; ++nx) {
482 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
483 Sample* const sp = i->data();
485 for (nframes_t nx = 0; nx < nframes; ++nx) {
491 if (apply_gain_automation && _session.transport_rolling() && nframes > 0) {
492 _effective_gain = gab[nframes-1];
497 /* manual (scalar) gain */
501 Amp::run_in_place (bufs, nframes, _gain, dg, _phase_invert);
504 } else if (_gain != 0 && (_phase_invert || _gain != 1.0)) {
506 /* no need to interpolate current gain value,
507 but its non-unity, so apply it. if the gain
508 is zero, do nothing because we'll ship silence
520 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
521 Sample* const sp = i->data();
522 apply_gain_to_buffer(sp,nframes,this_gain);
525 } else if (_gain == 0) {
526 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
534 /* actively recording, no monitoring required; leave buffers as-is to save CPU cycles */
538 /* ----------------------------------------------------------------------------------------------------
540 -------------------------------------------------------------------------------------------------- */
542 /* note that post_fader_work cannot be true unless with_processors was also true, so don't test both */
544 if (post_fader_work) {
546 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
548 if (mute_gain > 0 || !_mute_affects_post_fader) {
549 for (i = _processors.begin(); i != _processors.end(); ++i) {
550 switch ((*i)->placement()) {
554 (*i)->run_in_place (bufs, start_frame, end_frame, nframes, offset);
559 for (i = _processors.begin(); i != _processors.end(); ++i) {
560 switch ((*i)->placement()) {
564 (*i)->silence (nframes, offset);
572 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_control_outs) {
573 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
575 mute_declick_applied = true;
578 /* ----------------------------------------------------------------------------------------------------
580 -------------------------------------------------------------------------------------------------- */
582 if ((_meter_point == MeterPostFader) && co) {
584 solo_audible = solo_gain > 0;
585 mute_audible = dmg > 0 || !_mute_affects_control_outs;
587 if ( // silent anyway
589 (_gain == 0 && !apply_gain_automation) ||
591 // muted by solo of another track
595 // muted by mute of this track
599 // recording but not s/w monitoring
601 (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording()))
605 co->silence (nframes, offset);
609 co->deliver_output (bufs, start_frame, end_frame, nframes, offset);
613 /* ----------------------------------------------------------------------
615 ----------------------------------------------------------------------*/
617 if (!_soloed && (mute_gain != dmg) && !mute_declick_applied && _mute_affects_main_outs) {
618 Amp::run_in_place (bufs, nframes, mute_gain, dmg, false);
620 mute_declick_applied = true;
623 /* ----------------------------------------------------------------------------------------------------
625 -------------------------------------------------------------------------------------------------- */
627 solo_audible = dsg > 0;
628 mute_audible = dmg > 0 || !_mute_affects_main_outs;
630 if (n_outputs().get(_default_type) == 0) {
634 } else if (no_monitor && record_enabled() && (!Config->get_auto_input() || _session.actively_recording())) {
636 IO::silence (nframes, offset);
640 if ( // silent anyway
642 (_gain == 0 && !apply_gain_automation) ||
644 // muted by solo of another track, but not using control outs for solo
646 (!solo_audible && (Config->get_solo_model() != SoloBus)) ||
648 // muted by mute of this track
654 /* don't use Route::silence() here, because that causes
655 all outputs (sends, port processors, etc. to be silent).
658 if (_meter_point == MeterPostFader) {
659 peak_meter().reset();
662 IO::silence (nframes, offset);
666 deliver_output(bufs, start_frame, end_frame, nframes, offset);
672 /* ----------------------------------------------------------------------------------------------------
674 -------------------------------------------------------------------------------------------------- */
676 if (meter && (_meter_point == MeterPostFader)) {
677 if ((_gain == 0 && !apply_gain_automation) || dmg == 0) {
680 _meter->run_in_place(output_buffers(), start_frame, end_frame, nframes, offset);
686 Route::n_process_buffers ()
688 return max (n_inputs(), processor_max_outs);
692 Route::passthru (nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset, int declick, bool meter_first)
694 BufferSet& bufs = _session.get_scratch_buffers(n_process_buffers());
698 collect_input (bufs, nframes, offset);
701 _meter->run_in_place(bufs, start_frame, end_frame, nframes, offset);
705 process_output_buffers (bufs, start_frame, end_frame, nframes, offset, true, declick, meter_first);
709 Route::passthru_silence (nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset, int declick, bool meter)
711 process_output_buffers (_session.get_silent_buffers (n_process_buffers()), start_frame, end_frame, nframes, offset, true, declick, meter);
715 Route::set_solo (bool yn, void *src)
721 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
722 _mix_group->apply (&Route::set_solo, yn, _mix_group);
728 solo_changed (src); /* EMIT SIGNAL */
729 _solo_control->Changed (); /* EMIT SIGNAL */
734 Route::set_solo_mute (bool yn)
736 Glib::Mutex::Lock lm (declick_lock);
738 /* Called by Session in response to another Route being soloed.
741 desired_solo_gain = (yn?0.0:1.0);
745 Route::set_solo_safe (bool yn, void *src)
747 if (_solo_safe != yn) {
749 solo_safe_changed (src); /* EMIT SIGNAL */
754 Route::set_mute (bool yn, void *src)
757 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
758 _mix_group->apply (&Route::set_mute, yn, _mix_group);
764 mute_changed (src); /* EMIT SIGNAL */
766 _mute_control->Changed (); /* EMIT SIGNAL */
768 Glib::Mutex::Lock lm (declick_lock);
769 desired_mute_gain = (yn?0.0f:1.0f);
774 Route::add_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err)
776 ChanCount old_rmo = processor_max_outs;
778 if (!_session.engine().connected()) {
783 Glib::RWLock::WriterLock lm (_processor_lock);
785 boost::shared_ptr<PluginInsert> pi;
786 boost::shared_ptr<PortInsert> porti;
788 //processor->set_default_type(_default_type);
790 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
793 if (pi->natural_input_streams() == ChanCount::ZERO) {
794 /* generator plugin */
795 _have_internal_generator = true;
800 _processors.push_back (processor);
802 // Set up processor list channels. This will set processor->[input|output]_streams(),
803 // configure redirect ports properly, etc.
804 if (_reset_plugin_counts (err)) {
805 _processors.pop_back ();
806 _reset_plugin_counts (0); // it worked before we tried to add it ...
810 // Ensure peak vector sizes before the plugin is activated
811 ChanCount potential_max_streams = max(processor->input_streams(), processor->output_streams());
812 _meter->configure_io(potential_max_streams, potential_max_streams);
814 processor->activate ();
815 processor->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
820 if (processor_max_outs != old_rmo || old_rmo == ChanCount::ZERO) {
825 processors_changed (); /* EMIT SIGNAL */
830 Route::add_processors (const ProcessorList& others, ProcessorStreams* err)
832 ChanCount old_rmo = processor_max_outs;
834 if (!_session.engine().connected()) {
839 Glib::RWLock::WriterLock lm (_processor_lock);
841 ProcessorList::iterator existing_end = _processors.end();
844 ChanCount potential_max_streams;
846 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
848 boost::shared_ptr<PluginInsert> pi;
850 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
853 ChanCount m = max(pi->input_streams(), pi->output_streams());
854 if (m > potential_max_streams)
855 potential_max_streams = m;
858 // Ensure peak vector sizes before the plugin is activated
859 _meter->configure_io(potential_max_streams, potential_max_streams);
861 _processors.push_back (*i);
863 if (_reset_plugin_counts (err)) {
865 _processors.erase (existing_end, _processors.end());
866 _reset_plugin_counts (0); // it worked before we tried to add it ...
871 (*i)->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
877 if (processor_max_outs != old_rmo || old_rmo == ChanCount::ZERO) {
881 processors_changed (); /* EMIT SIGNAL */
885 /** Turn off all processors with a given placement
886 * @param p Placement of processors to disable
890 Route::disable_processors (Placement p)
892 Glib::RWLock::ReaderLock lm (_processor_lock);
894 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
895 if ((*i)->placement() == p) {
896 (*i)->set_active (false);
900 _session.set_dirty ();
903 /** Turn off all redirects
907 Route::disable_processors ()
909 Glib::RWLock::ReaderLock lm (_processor_lock);
911 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
912 (*i)->set_active (false);
915 _session.set_dirty ();
918 /** Turn off all redirects with a given placement
919 * @param p Placement of redirects to disable
923 Route::disable_plugins (Placement p)
925 Glib::RWLock::ReaderLock lm (_processor_lock);
927 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
928 if (boost::dynamic_pointer_cast<PluginInsert> (*i) && (*i)->placement() == p) {
929 (*i)->set_active (false);
933 _session.set_dirty ();
936 /** Turn off all plugins
940 Route::disable_plugins ()
942 Glib::RWLock::ReaderLock lm (_processor_lock);
944 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
945 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
946 (*i)->set_active (false);
950 _session.set_dirty ();
955 Route::ab_plugins (bool forward)
957 Glib::RWLock::ReaderLock lm (_processor_lock);
961 /* forward = turn off all active redirects, and mark them so that the next time
962 we go the other way, we will revert them
965 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
966 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
970 if ((*i)->active()) {
971 (*i)->set_active (false);
972 (*i)->set_next_ab_is_active (true);
974 (*i)->set_next_ab_is_active (false);
980 /* backward = if the redirect was marked to go active on the next ab, do so */
982 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
984 if (!boost::dynamic_pointer_cast<PluginInsert> (*i)) {
988 if ((*i)->get_next_ab_is_active()) {
989 (*i)->set_active (true);
991 (*i)->set_active (false);
996 _session.set_dirty ();
1000 /* Figure out the streams that will feed into PreFader */
1002 Route::pre_fader_streams() const
1004 boost::shared_ptr<Processor> processor;
1006 // Find the last pre-fader redirect
1007 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1008 if ((*i)->placement() == PreFader) {
1014 return processor->output_streams();
1021 /** Remove processors with a given placement.
1022 * @param p Placement of processors to remove.
1025 Route::clear_processors (Placement p)
1027 const ChanCount old_rmo = processor_max_outs;
1029 if (!_session.engine().connected()) {
1034 Glib::RWLock::WriterLock lm (_processor_lock);
1035 ProcessorList new_list;
1037 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1038 if ((*i)->placement() == p) {
1039 /* it's the placement we want to get rid of */
1040 (*i)->drop_references ();
1042 /* it's a different placement, so keep it */
1043 new_list.push_back (*i);
1047 _processors = new_list;
1050 /* FIXME: can't see how this test can ever fire */
1051 if (processor_max_outs != old_rmo) {
1055 processor_max_outs.reset();
1056 _have_internal_generator = false;
1057 processors_changed (); /* EMIT SIGNAL */
1061 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err)
1063 ChanCount old_rmo = processor_max_outs;
1065 if (!_session.engine().connected()) {
1069 processor_max_outs.reset();
1072 Glib::RWLock::WriterLock lm (_processor_lock);
1073 ProcessorList::iterator i;
1074 bool removed = false;
1076 for (i = _processors.begin(); i != _processors.end(); ++i) {
1077 if (*i == processor) {
1079 ProcessorList::iterator tmp;
1081 /* move along, see failure case for reset_plugin_counts()
1082 where we may need to reprocessor the processor.
1088 /* stop redirects that send signals to JACK ports
1089 from causing noise as a result of no longer being
1093 boost::shared_ptr<IOProcessor> redirect;
1095 if ((redirect = boost::dynamic_pointer_cast<IOProcessor> (*i)) != 0) {
1096 redirect->io()->disconnect_inputs (this);
1097 redirect->io()->disconnect_outputs (this);
1100 _processors.erase (i);
1115 if (_reset_plugin_counts (err)) {
1116 /* get back to where we where */
1117 _processors.insert (i, processor);
1118 /* we know this will work, because it worked before :) */
1119 _reset_plugin_counts (0);
1125 for (i = _processors.begin(); i != _processors.end(); ++i) {
1126 boost::shared_ptr<PluginInsert> pi;
1128 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1129 if (pi->is_generator()) {
1135 _have_internal_generator = foo;
1138 if (old_rmo != processor_max_outs) {
1142 processor->drop_references ();
1144 processors_changed (); /* EMIT SIGNAL */
1149 Route::reset_plugin_counts (ProcessorStreams* err)
1151 Glib::RWLock::WriterLock lm (_processor_lock);
1152 return _reset_plugin_counts (err);
1157 Route::_reset_plugin_counts (ProcessorStreams* err)
1159 ProcessorList::iterator r;
1160 map<Placement,list<ProcessorCount> > processor_map;
1161 ChanCount initial_streams;
1163 /* Process each placement in order, checking to see if we
1164 can really do what has been requested.
1167 /* divide processors up by placement so we get the signal flow
1168 properly modelled. we need to do this because the _processors
1169 list is not sorted by placement
1172 /* ... but it should/will be... */
1174 for (r = _processors.begin(); r != _processors.end(); ++r) {
1176 boost::shared_ptr<Processor> processor;
1178 if ((processor = boost::dynamic_pointer_cast<Processor>(*r)) != 0) {
1179 processor_map[processor->placement()].push_back (ProcessorCount (processor));
1186 if ( ! check_some_plugin_counts (processor_map[PreFader], n_inputs (), err)) {
1190 ChanCount post_fader_input = (err ? err->count : n_inputs());
1194 if ( ! check_some_plugin_counts (processor_map[PostFader], post_fader_input, err)) {
1198 /* OK, everything can be set up correctly, so lets do it */
1200 apply_some_plugin_counts (processor_map[PreFader]);
1201 apply_some_plugin_counts (processor_map[PostFader]);
1203 /* recompute max outs of any processor */
1205 processor_max_outs.reset();
1206 ProcessorList::iterator prev = _processors.end();
1208 for (r = _processors.begin(); r != _processors.end(); prev = r, ++r) {
1209 processor_max_outs = max ((*r)->output_streams (), processor_max_outs);
1218 Route::apply_some_plugin_counts (list<ProcessorCount>& iclist)
1220 list<ProcessorCount>::iterator i;
1222 for (i = iclist.begin(); i != iclist.end(); ++i) {
1224 if ((*i).processor->configure_io ((*i).in, (*i).out)) {
1227 /* make sure that however many we have, they are all active */
1228 (*i).processor->activate ();
1234 /** Returns whether \a iclist can be configured and run starting with
1235 * \a required_inputs at the first processor's inputs.
1236 * If false is returned, \a iclist can not be run with \a required_inputs, and \a err is set.
1237 * Otherwise, \a err is set to the output of the list.
1240 Route::check_some_plugin_counts (list<ProcessorCount>& iclist, ChanCount required_inputs, ProcessorStreams* err)
1242 list<ProcessorCount>::iterator i;
1247 err->count = required_inputs;
1250 for (i = iclist.begin(); i != iclist.end(); ++i) {
1252 if ((*i).processor->can_support_input_configuration (required_inputs) < 0) {
1255 err->count = required_inputs;
1260 (*i).in = required_inputs;
1261 (*i).out = (*i).processor->output_for_input_configuration (required_inputs);
1263 required_inputs = (*i).out;
1269 if (!iclist.empty()) {
1271 err->count = iclist.back().processor->output_for_input_configuration(required_inputs);
1279 Route::copy_processors (const Route& other, Placement placement, ProcessorStreams* err)
1281 ChanCount old_rmo = processor_max_outs;
1283 ProcessorList to_be_deleted;
1286 Glib::RWLock::WriterLock lm (_processor_lock);
1287 ProcessorList::iterator tmp;
1288 ProcessorList the_copy;
1290 the_copy = _processors;
1292 /* remove all relevant processors */
1294 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ) {
1298 if ((*i)->placement() == placement) {
1299 to_be_deleted.push_back (*i);
1300 _processors.erase (i);
1306 /* now copy the relevant ones from "other" */
1308 for (ProcessorList::const_iterator i = other._processors.begin(); i != other._processors.end(); ++i) {
1309 if ((*i)->placement() == placement) {
1310 _processors.push_back (IOProcessor::clone (*i));
1314 /* reset plugin stream handling */
1316 if (_reset_plugin_counts (err)) {
1318 /* FAILED COPY ATTEMPT: we have to restore order */
1320 /* delete all cloned processors */
1322 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ) {
1327 if ((*i)->placement() == placement) {
1328 _processors.erase (i);
1334 /* restore the natural order */
1336 _processors = the_copy;
1337 processor_max_outs = old_rmo;
1339 /* we failed, even though things are OK again */
1345 /* SUCCESSFUL COPY ATTEMPT: delete the processors we removed pre-copy */
1346 to_be_deleted.clear ();
1351 if (processor_max_outs != old_rmo || old_rmo == ChanCount::ZERO) {
1355 processors_changed (); /* EMIT SIGNAL */
1360 Route::all_processors_flip ()
1362 Glib::RWLock::ReaderLock lm (_processor_lock);
1364 if (_processors.empty()) {
1368 bool first_is_on = _processors.front()->active();
1370 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1371 (*i)->set_active (!first_is_on);
1374 _session.set_dirty ();
1377 /** Set all processors with a given placement to a given active state.
1378 * @param p Placement of processors to change.
1379 * @param state New active state for those processors.
1382 Route::all_processors_active (Placement p, bool state)
1384 Glib::RWLock::ReaderLock lm (_processor_lock);
1386 if (_processors.empty()) {
1390 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1391 if ((*i)->placement() == p) {
1392 (*i)->set_active (state);
1396 _session.set_dirty ();
1399 struct ProcessorSorter {
1400 bool operator() (boost::shared_ptr<const Processor> a, boost::shared_ptr<const Processor> b) {
1401 return a->sort_key() < b->sort_key();
1406 Route::sort_processors (ProcessorStreams* err)
1409 ProcessorSorter comparator;
1410 Glib::RWLock::WriterLock lm (_processor_lock);
1411 ChanCount old_rmo = processor_max_outs;
1413 /* the sweet power of C++ ... */
1415 ProcessorList as_it_was_before = _processors;
1417 _processors.sort (comparator);
1419 if (_reset_plugin_counts (err)) {
1420 _processors = as_it_was_before;
1421 processor_max_outs = old_rmo;
1427 processors_changed (); /* EMIT SIGNAL */
1439 Route::get_template()
1441 return state(false);
1445 Route::state(bool full_state)
1447 XMLNode *node = new XMLNode("Route");
1448 ProcessorList:: iterator i;
1452 node->add_property("flags", enum_2_string (_flags));
1455 node->add_property("default-type", _default_type.to_string());
1457 node->add_property("active", _active?"yes":"no");
1458 node->add_property("muted", _muted?"yes":"no");
1459 node->add_property("soloed", _soloed?"yes":"no");
1460 node->add_property("phase-invert", _phase_invert?"yes":"no");
1461 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
1462 node->add_property("mute-affects-pre-fader", _mute_affects_pre_fader?"yes":"no");
1463 node->add_property("mute-affects-post-fader", _mute_affects_post_fader?"yes":"no");
1464 node->add_property("mute-affects-control-outs", _mute_affects_control_outs?"yes":"no");
1465 node->add_property("mute-affects-main-outs", _mute_affects_main_outs?"yes":"no");
1468 node->add_property("edit-group", _edit_group->name());
1471 node->add_property("mix-group", _mix_group->name());
1474 string order_string;
1475 OrderKeys::iterator x = order_keys.begin();
1477 while (x != order_keys.end()) {
1478 order_string += string ((*x).first);
1479 order_string += '=';
1480 snprintf (buf, sizeof(buf), "%ld", (*x).second);
1481 order_string += buf;
1485 if (x == order_keys.end()) {
1489 order_string += ':';
1491 node->add_property ("order-keys", order_string);
1493 node->add_child_nocopy (IO::state (full_state));
1494 node->add_child_nocopy (_solo_control->get_state ());
1495 node->add_child_nocopy (_mute_control->get_state ());
1497 XMLNode* remote_control_node = new XMLNode (X_("remote_control"));
1498 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
1499 remote_control_node->add_property (X_("id"), buf);
1500 node->add_child_nocopy (*remote_control_node);
1502 if (_control_outs) {
1503 XMLNode* cnode = new XMLNode (X_("ControlOuts"));
1504 cnode->add_child_nocopy (_control_outs->state (full_state));
1505 node->add_child_nocopy (*cnode);
1508 if (_comment.length()) {
1509 XMLNode *cmt = node->add_child ("Comment");
1510 cmt->add_content (_comment);
1513 for (i = _processors.begin(); i != _processors.end(); ++i) {
1514 node->add_child_nocopy((*i)->state (full_state));
1518 node->add_child_copy (*_extra_xml);
1525 Route::get_processor_state ()
1527 XMLNode* root = new XMLNode (X_("redirects"));
1528 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1529 root->add_child_nocopy ((*i)->state (true));
1536 Route::set_processor_state (const XMLNode& root)
1538 if (root.name() != X_("redirects")) {
1544 XMLNodeConstIterator iter;
1545 XMLNodeConstIterator niter;
1546 Glib::RWLock::ReaderLock lm (_processor_lock);
1548 nlist = root.children();
1550 for (iter = nlist.begin(); iter != nlist.end(); ++iter){
1552 /* iter now points to a IOProcessor state node */
1554 nnlist = (*iter)->children ();
1556 for (niter = nnlist.begin(); niter != nnlist.end(); ++niter) {
1558 /* find the IO child node, since it contains the ID we need */
1560 /* XXX OOP encapsulation violation, ugh */
1562 if ((*niter)->name() == IO::state_node_name) {
1564 XMLProperty* prop = (*niter)->property (X_("id"));
1567 warning << _("IOProcessor node has no ID, ignored") << endmsg;
1571 ID id = prop->value ();
1573 /* now look for a processor with that ID */
1575 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1576 if ((*i)->id() == id) {
1577 (*i)->set_state (**iter);
1593 Route::set_deferred_state ()
1596 XMLNodeConstIterator niter;
1598 if (!deferred_state) {
1602 nlist = deferred_state->children();
1604 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1605 add_processor_from_xml (**niter);
1608 delete deferred_state;
1613 Route::add_processor_from_xml (const XMLNode& node)
1615 const XMLProperty *prop;
1617 // legacy sessions use a different node name for sends
1618 if (node.name() == "Send") {
1621 boost::shared_ptr<Send> send (new Send (_session, node));
1622 add_processor (send);
1625 catch (failed_constructor &err) {
1626 error << _("Send construction failed") << endmsg;
1630 // use "Processor" in XML?
1631 } else if (node.name() == "Processor") {
1634 if ((prop = node.property ("type")) != 0) {
1636 boost::shared_ptr<Processor> processor;
1638 if (prop->value() == "ladspa" || prop->value() == "Ladspa" || prop->value() == "vst") {
1640 processor.reset (new PluginInsert(_session, node));
1642 } else if (prop->value() == "port") {
1644 processor.reset (new PortInsert (_session, node));
1646 } else if (prop->value() == "send") {
1648 processor.reset (new Send (_session, node));
1652 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
1655 add_processor (processor);
1658 error << _("Processor XML node has no type property") << endmsg;
1662 catch (failed_constructor &err) {
1663 warning << _("processor could not be created. Ignored.") << endmsg;
1670 Route::set_state (const XMLNode& node)
1672 return _set_state (node, true);
1676 Route::_set_state (const XMLNode& node, bool call_base)
1679 XMLNodeConstIterator niter;
1681 XMLPropertyList plist;
1682 const XMLProperty *prop;
1684 if (node.name() != "Route"){
1685 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
1689 if ((prop = node.property (X_("flags"))) != 0) {
1690 _flags = Flag (string_2_enum (prop->value(), _flags));
1695 if ((prop = node.property (X_("default-type"))) != 0) {
1696 _default_type = DataType(prop->value());
1697 assert(_default_type != DataType::NIL);
1700 if ((prop = node.property (X_("phase-invert"))) != 0) {
1701 set_phase_invert (prop->value()=="yes"?true:false, this);
1704 if ((prop = node.property (X_("denormal-protection"))) != 0) {
1705 set_denormal_protection (prop->value()=="yes"?true:false, this);
1708 if ((prop = node.property (X_("active"))) != 0) {
1709 set_active (prop->value() == "yes");
1712 if ((prop = node.property (X_("muted"))) != 0) {
1713 bool yn = prop->value()=="yes"?true:false;
1715 /* force reset of mute status */
1719 mute_gain = desired_mute_gain;
1722 if ((prop = node.property (X_("soloed"))) != 0) {
1723 bool yn = prop->value()=="yes"?true:false;
1725 /* force reset of solo status */
1728 set_solo (yn, this);
1729 solo_gain = desired_solo_gain;
1732 if ((prop = node.property (X_("mute-affects-pre-fader"))) != 0) {
1733 _mute_affects_pre_fader = (prop->value()=="yes")?true:false;
1736 if ((prop = node.property (X_("mute-affects-post-fader"))) != 0) {
1737 _mute_affects_post_fader = (prop->value()=="yes")?true:false;
1740 if ((prop = node.property (X_("mute-affects-control-outs"))) != 0) {
1741 _mute_affects_control_outs = (prop->value()=="yes")?true:false;
1744 if ((prop = node.property (X_("mute-affects-main-outs"))) != 0) {
1745 _mute_affects_main_outs = (prop->value()=="yes")?true:false;
1748 if ((prop = node.property (X_("edit-group"))) != 0) {
1749 RouteGroup* edit_group = _session.edit_group_by_name(prop->value());
1750 if(edit_group == 0) {
1751 error << string_compose(_("Route %1: unknown edit group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
1753 set_edit_group(edit_group, this);
1757 if ((prop = node.property (X_("order-keys"))) != 0) {
1761 string::size_type colon, equal;
1762 string remaining = prop->value();
1764 while (remaining.length()) {
1766 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
1767 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1770 if (sscanf (remaining.substr (equal+1).c_str(), "%ld", &n) != 1) {
1771 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1774 set_order_key (remaining.substr (0, equal).c_str(), n);
1778 colon = remaining.find_first_of (':');
1780 if (colon != string::npos) {
1781 remaining = remaining.substr (colon+1);
1788 nlist = node.children();
1790 if (deferred_state) {
1791 delete deferred_state;
1794 deferred_state = new XMLNode(X_("deferred state"));
1796 /* set parent class properties before anything else */
1798 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1802 if (child->name() == IO::state_node_name && call_base) {
1804 IO::set_state (*child);
1809 XMLNodeList processor_nodes;
1811 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1815 if (child->name() == X_("Send") || child->name() == X_("Processor")) {
1816 processor_nodes.push_back(child);
1821 _set_processor_states(processor_nodes);
1824 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1826 // All processors have been applied already
1828 if (child->name() == X_("Automation")) {
1830 if ((prop = child->property (X_("path"))) != 0) {
1831 load_automation (prop->value());
1834 } else if (child->name() == X_("ControlOuts")) {
1836 string coutname = _name;
1837 coutname += _("[control]");
1839 _control_outs = new IO (_session, coutname);
1840 _control_outs->set_state (**(child->children().begin()));
1842 } else if (child->name() == X_("Comment")) {
1844 /* XXX this is a terrible API design in libxml++ */
1846 XMLNode *cmt = *(child->children().begin());
1847 _comment = cmt->content();
1849 } else if (child->name() == X_("extra")) {
1851 _extra_xml = new XMLNode (*child);
1853 } else if (child->name() == X_("controllable") && (prop = child->property("name")) != 0) {
1855 if (prop->value() == "solo") {
1856 _solo_control->set_state (*child);
1857 _session.add_controllable (_solo_control);
1859 else if (prop->value() == "mute") {
1860 _mute_control->set_state (*child);
1861 _session.add_controllable (_mute_control);
1864 else if (child->name() == X_("remote_control")) {
1865 if ((prop = child->property (X_("id"))) != 0) {
1867 sscanf (prop->value().c_str(), "%d", &x);
1868 set_remote_control_id (x);
1873 if ((prop = node.property (X_("mix-group"))) != 0) {
1874 RouteGroup* mix_group = _session.mix_group_by_name(prop->value());
1875 if (mix_group == 0) {
1876 error << string_compose(_("Route %1: unknown mix group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
1878 set_mix_group(mix_group, this);
1886 Route::_set_processor_states(const XMLNodeList &nlist)
1888 XMLNodeConstIterator niter;
1891 ProcessorList::iterator i, o;
1893 // Iterate through existing processors, remove those which are not in the state list
1894 for (i = _processors.begin(); i != _processors.end(); ) {
1895 ProcessorList::iterator tmp = i;
1898 bool processorInStateList = false;
1900 (*i)->id().print (buf, sizeof (buf));
1903 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1905 // legacy sessions (IOProcessor as a child of Processor, both is-a IO)
1906 if (strncmp(buf,(*niter)->child(X_("IOProcessor"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf)) == 0) {
1907 processorInStateList = true;
1909 } else if (strncmp(buf,(*niter)->property(X_("id"))->value().c_str(), sizeof(buf)) == 0) {
1910 processorInStateList = true;
1915 if (!processorInStateList) {
1916 remove_processor (*i);
1924 // Iterate through state list and make sure all processors are on the track and in the correct order,
1925 // set the state of existing processors according to the new state on the same go
1926 i = _processors.begin();
1927 for (niter = nlist.begin(); niter != nlist.end(); ++niter, ++i) {
1929 // Check whether the next processor in the list
1932 while (o != _processors.end()) {
1933 (*o)->id().print (buf, sizeof (buf));
1934 if ( strncmp(buf, (*niter)->child(X_("IOProcessor"))->child(X_("IO"))->property(X_("id"))->value().c_str(), sizeof(buf)) == 0)
1936 else if (strncmp(buf,(*niter)->property(X_("id"))->value().c_str(), sizeof(buf)) == 0)
1942 if (o == _processors.end()) {
1943 // If the processor (*niter) is not on the route, we need to create it
1944 // and move it to the correct location
1946 ProcessorList::iterator prev_last = _processors.end();
1947 --prev_last; // We need this to check whether adding succeeded
1949 add_processor_from_xml (**niter);
1951 ProcessorList::iterator last = _processors.end();
1954 if (prev_last == last) {
1955 cerr << "Could not fully restore state as some processors were not possible to create" << endl;
1960 boost::shared_ptr<Processor> tmp = (*last);
1961 // remove the processor from the wrong location
1962 _processors.erase(last);
1963 // processor the new processor at the current location
1964 _processors.insert(i, tmp);
1966 --i; // move pointer to the newly processored processor
1970 // We found the processor (*niter) on the route, first we must make sure the processor
1971 // is at the location provided in the XML state
1973 boost::shared_ptr<Processor> tmp = (*o);
1974 // remove the old copy
1975 _processors.erase(o);
1976 // processor the processor at the correct location
1977 _processors.insert(i, tmp);
1979 --i; // move pointer so it points to the right processor
1982 (*i)->set_state( (**niter) );
1985 processors_changed ();
1989 Route::curve_reallocate ()
1991 // _gain_automation_curve.finish_resize ();
1992 // _pan_automation_curve.finish_resize ();
1996 Route::silence (nframes_t nframes, nframes_t offset)
2000 IO::silence (nframes, offset);
2002 if (_control_outs) {
2003 _control_outs->silence (nframes, offset);
2007 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2010 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2011 boost::shared_ptr<PluginInsert> pi;
2012 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
2013 // skip plugins, they don't need anything when we're not active
2017 (*i)->silence (nframes, offset);
2020 if (nframes == _session.get_block_size() && offset == 0) {
2030 Route::set_control_outs (const vector<string>& ports)
2032 Glib::Mutex::Lock lm (_control_outs_lock);
2033 vector<string>::const_iterator i;
2036 if (_control_outs) {
2037 delete _control_outs;
2041 if (is_control() || is_master()) {
2042 /* no control outs for these two special busses */
2046 if (ports.empty()) {
2050 string coutname = _name;
2051 coutname += _("[control]");
2053 _control_outs = new IO (_session, coutname);
2055 /* our control outs need as many outputs as we
2056 have audio outputs. we track the changes in ::output_change_handler().
2059 // XXX its stupid that we have to get this value twice
2061 limit = n_outputs().n_audio();
2063 if (_control_outs->ensure_io (ChanCount::ZERO, ChanCount (DataType::AUDIO, n_outputs().get (DataType::AUDIO)), true, this)) {
2067 /* now connect to the named ports */
2069 for (size_t n = 0; n < limit; ++n) {
2070 if (_control_outs->connect_output (_control_outs->output (n), ports[n], this)) {
2071 error << string_compose (_("could not connect %1 to %2"), _control_outs->output(n)->name(), ports[n]) << endmsg;
2080 Route::set_edit_group (RouteGroup *eg, void *src)
2083 if (eg == _edit_group) {
2088 _edit_group->remove (this);
2091 if ((_edit_group = eg) != 0) {
2092 _edit_group->add (this);
2095 _session.set_dirty ();
2096 edit_group_changed (src); /* EMIT SIGNAL */
2100 Route::drop_edit_group (void *src)
2103 _session.set_dirty ();
2104 edit_group_changed (src); /* EMIT SIGNAL */
2108 Route::set_mix_group (RouteGroup *mg, void *src)
2111 if (mg == _mix_group) {
2116 _mix_group->remove (this);
2119 if ((_mix_group = mg) != 0) {
2120 _mix_group->add (this);
2123 _session.set_dirty ();
2124 mix_group_changed (src); /* EMIT SIGNAL */
2128 Route::drop_mix_group (void *src)
2131 _session.set_dirty ();
2132 mix_group_changed (src); /* EMIT SIGNAL */
2136 Route::set_comment (string cmt, void *src)
2139 comment_changed (src);
2140 _session.set_dirty ();
2144 Route::feeds (boost::shared_ptr<Route> other)
2149 uint32_t no = self.n_outputs().n_total();
2150 uint32_t ni = other->n_inputs ().n_total();
2152 for (i = 0; i < no; ++i) {
2153 for (j = 0; j < ni; ++j) {
2154 if (self.output(i)->connected_to (other->input(j)->name())) {
2160 /* check IOProcessors which may also interconnect Routes */
2162 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); r++) {
2164 boost::shared_ptr<IOProcessor> redirect = boost::dynamic_pointer_cast<IOProcessor>(*r);
2169 // TODO: support internal redirects here
2171 no = redirect->io()->n_outputs().n_total();
2173 for (i = 0; i < no; ++i) {
2174 for (j = 0; j < ni; ++j) {
2175 if (redirect->io()->output(i)->connected_to (other->input (j)->name())) {
2182 /* check for control room outputs which may also interconnect Routes */
2184 if (_control_outs) {
2186 no = _control_outs->n_outputs().n_total();
2188 for (i = 0; i < no; ++i) {
2189 for (j = 0; j < ni; ++j) {
2190 if (_control_outs->output(i)->connected_to (other->input (j)->name())) {
2201 Route::set_mute_config (mute_type t, bool onoff, void *src)
2205 _mute_affects_pre_fader = onoff;
2206 pre_fader_changed(src); /* EMIT SIGNAL */
2210 _mute_affects_post_fader = onoff;
2211 post_fader_changed(src); /* EMIT SIGNAL */
2215 _mute_affects_control_outs = onoff;
2216 control_outs_changed(src); /* EMIT SIGNAL */
2220 _mute_affects_main_outs = onoff;
2221 main_outs_changed(src); /* EMIT SIGNAL */
2227 Route::get_mute_config (mute_type t)
2233 onoff = _mute_affects_pre_fader;
2236 onoff = _mute_affects_post_fader;
2239 onoff = _mute_affects_control_outs;
2242 onoff = _mute_affects_main_outs;
2250 Route::set_active (bool yn)
2253 active_changed(); /* EMIT SIGNAL */
2257 Route::handle_transport_stopped (bool abort_ignored, bool did_locate, bool can_flush_processors)
2259 nframes_t now = _session.transport_frame();
2262 Glib::RWLock::ReaderLock lm (_processor_lock);
2265 automation_snapshot (now);
2268 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2270 if (Config->get_plugins_stop_with_transport() && can_flush_processors) {
2271 (*i)->deactivate ();
2275 (*i)->transport_stopped (now);
2279 IO::transport_stopped (now);
2281 _roll_delay = _initial_delay;
2285 Route::input_change_handler (IOChange change, void *ignored)
2287 if (change & ConfigurationChanged) {
2288 reset_plugin_counts (0);
2293 Route::output_change_handler (IOChange change, void *ignored)
2295 if (change & ConfigurationChanged) {
2296 if (_control_outs) {
2297 _control_outs->ensure_io (ChanCount::ZERO, ChanCount(DataType::AUDIO, n_outputs().n_audio()), true, this);
2300 reset_plugin_counts (0);
2305 Route::pans_required () const
2307 if (n_outputs().n_audio() < 2) {
2311 return max (n_inputs ().n_audio(), processor_max_outs.n_audio());
2315 Route::no_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
2316 bool session_state_changing, bool can_record, bool rec_monitors_input)
2318 if (n_outputs().n_total() == 0) {
2322 if (session_state_changing || !_active) {
2323 silence (nframes, offset);
2327 apply_gain_automation = false;
2329 if (n_inputs().n_total()) {
2330 passthru (start_frame, end_frame, nframes, offset, 0, false);
2332 silence (nframes, offset);
2339 Route::check_initial_delay (nframes_t nframes, nframes_t& offset, nframes_t& transport_frame)
2341 if (_roll_delay > nframes) {
2343 _roll_delay -= nframes;
2344 silence (nframes, offset);
2345 /* transport frame is not legal for caller to use */
2348 } else if (_roll_delay > 0) {
2350 nframes -= _roll_delay;
2352 silence (_roll_delay, offset);
2354 offset += _roll_delay;
2355 transport_frame += _roll_delay;
2364 Route::roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset, int declick,
2365 bool can_record, bool rec_monitors_input)
2368 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2370 // automation snapshot can also be called from the non-rt context
2371 // and it uses the processor list, so we take the lock out here
2372 automation_snapshot (_session.transport_frame());
2376 if ((n_outputs().n_total() == 0 && _processors.empty()) || n_inputs().n_total() == 0 || !_active) {
2377 silence (nframes, offset);
2381 nframes_t unused = 0;
2383 if ((nframes = check_initial_delay (nframes, offset, unused)) == 0) {
2389 apply_gain_automation = false;
2392 Glib::Mutex::Lock am (_automation_lock, Glib::TRY_LOCK);
2394 if (am.locked() && _session.transport_rolling()) {
2396 if (_gain_control->list()->automation_playback()) {
2397 apply_gain_automation = _gain_control->list()->curve().rt_safe_get_vector (
2398 start_frame, end_frame, _session.gain_automation_buffer(), nframes);
2403 passthru (start_frame, end_frame, nframes, offset, declick, false);
2409 Route::silent_roll (nframes_t nframes, nframes_t start_frame, nframes_t end_frame, nframes_t offset,
2410 bool can_record, bool rec_monitors_input)
2412 silence (nframes, offset);
2417 Route::toggle_monitor_input ()
2419 for (PortSet::iterator i = _inputs.begin(); i != _inputs.end(); ++i) {
2420 i->ensure_monitor_input( ! i->monitoring_input());
2425 Route::has_external_redirects () const
2427 // FIXME: what about sends?
2429 boost::shared_ptr<const PortInsert> pi;
2431 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2432 if ((pi = boost::dynamic_pointer_cast<const PortInsert>(*i)) != 0) {
2434 for (PortSet::const_iterator port = pi->io()->outputs().begin();
2435 port != pi->io()->outputs().end(); ++port) {
2437 string port_name = port->name();
2438 string client_name = port_name.substr (0, port_name.find(':'));
2440 /* only say "yes" if the redirect is actually in use */
2442 if (client_name != "ardour" && pi->active()) {
2453 Route::flush_processors ()
2455 /* XXX shouldn't really try to take this lock, since
2456 this is called from the RT audio thread.
2459 Glib::RWLock::ReaderLock lm (_processor_lock);
2461 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2462 (*i)->deactivate ();
2468 Route::set_meter_point (MeterPoint p, void *src)
2470 if (_meter_point != p) {
2472 meter_change (src); /* EMIT SIGNAL */
2473 _session.set_dirty ();
2478 Route::update_total_latency ()
2480 nframes_t old = _own_latency;
2482 if (_user_latency) {
2483 _own_latency = _user_latency;
2487 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2488 if ((*i)->active ()) {
2489 _own_latency += (*i)->signal_latency ();
2494 set_port_latency (_own_latency);
2496 if (!_user_latency) {
2497 /* this (virtual) function is used for pure Routes,
2498 not derived classes like AudioTrack. this means
2499 that the data processed here comes from an input
2500 port, not prerecorded material, and therefore we
2501 have to take into account any input latency.
2505 _own_latency += input_latency ();
2508 if (old != _own_latency) {
2509 signal_latency_changed (); /* EMIT SIGNAL */
2512 return _own_latency;
2516 Route::set_user_latency (nframes_t nframes)
2518 Latent::set_user_latency (nframes);
2519 _session.update_latency_compensation (false, false);
2523 Route::set_latency_delay (nframes_t longest_session_latency)
2525 nframes_t old = _initial_delay;
2527 if (_own_latency < longest_session_latency) {
2528 _initial_delay = longest_session_latency - _own_latency;
2533 if (_initial_delay != old) {
2534 initial_delay_changed (); /* EMIT SIGNAL */
2537 if (_session.transport_stopped()) {
2538 _roll_delay = _initial_delay;
2543 Route::automation_snapshot (nframes_t now)
2545 IO::automation_snapshot (now);
2547 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2548 (*i)->automation_snapshot (now);
2552 Route::ToggleControllable::ToggleControllable (std::string name, Route& s, ToggleType tp)
2553 : Controllable (name), route (s), type(tp)
2559 Route::ToggleControllable::set_value (float val)
2561 bool bval = ((val >= 0.5f) ? true: false);
2565 route.set_mute (bval, this);
2568 route.set_solo (bval, this);
2576 Route::ToggleControllable::get_value (void) const
2582 val = route.muted() ? 1.0f : 0.0f;
2585 val = route.soloed() ? 1.0f : 0.0f;
2595 Route::set_block_size (nframes_t nframes)
2597 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2598 (*i)->set_block_size (nframes);
2603 Route::protect_automation ()
2605 Automatable::protect_automation();
2607 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
2608 (*i)->protect_automation();
2612 Route::set_pending_declick (int declick)
2615 /* this call is not allowed to turn off a pending declick unless "force" is true */
2617 _pending_declick = declick;
2619 // cerr << _name << ": after setting to " << declick << " pending declick = " << _pending_declick << endl;
2621 _pending_declick = 0;