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.
25 #include <sigc++/bind.h>
26 #include "pbd/xml++.h"
27 #include "pbd/enumwriter.h"
28 #include "pbd/stacktrace.h"
29 #include "pbd/memento_command.h"
31 #include "evoral/Curve.hpp"
33 #include "ardour/amp.h"
34 #include "ardour/audio_port.h"
35 #include "ardour/audioengine.h"
36 #include "ardour/buffer.h"
37 #include "ardour/buffer_set.h"
38 #include "ardour/configuration.h"
39 #include "ardour/cycle_timer.h"
40 #include "ardour/dB.h"
41 #include "ardour/ladspa_plugin.h"
42 #include "ardour/meter.h"
43 #include "ardour/mix.h"
44 #include "ardour/panner.h"
45 #include "ardour/plugin_insert.h"
46 #include "ardour/port.h"
47 #include "ardour/port_insert.h"
48 #include "ardour/processor.h"
49 #include "ardour/profile.h"
50 #include "ardour/route.h"
51 #include "ardour/route_group.h"
52 #include "ardour/send.h"
53 #include "ardour/session.h"
54 #include "ardour/timestamps.h"
55 #include "ardour/utils.h"
60 using namespace ARDOUR;
63 uint32_t Route::order_key_cnt = 0;
64 sigc::signal<void,const char*> Route::SyncOrderKeys;
66 Route::Route (Session& sess, string name, Flag flg, DataType default_type)
67 : SessionObject (sess, name)
68 , AutomatableControls (sess)
70 , _solo_control (new SoloControllable (X_("solo"), *this))
71 , _mute_master (new MuteMaster (sess, name))
72 , _default_type (default_type)
78 Route::Route (Session& sess, const XMLNode& node, DataType default_type)
79 : SessionObject (sess, "toBeReset")
80 , AutomatableControls (sess)
81 , _solo_control (new SoloControllable (X_("solo"), *this))
82 , _mute_master (new MuteMaster (sess, "toBeReset"))
83 , _default_type (default_type)
86 _set_state (node, false);
93 processor_max_streams.reset();
96 order_keys[strdup (N_("signal"))] = order_key_cnt++;
98 _meter_point = MeterPostFader;
101 _have_internal_generator = false;
102 _declickable = false;
103 _pending_declick = true;
104 _remote_control_id = 0;
105 _in_configure_processors = false;
111 _denormal_protection = false;
113 /* add standard controls */
115 add_control (_solo_control);
116 add_control (_mute_master);
118 /* input and output objects */
120 _input.reset (new IO (_session, _name, IO::Input, _default_type));
121 _output.reset (new IO (_session, _name, IO::Output, _default_type));
123 _input->changed.connect (mem_fun (this, &Route::input_change_handler));
124 _output->changed.connect (mem_fun (this, &Route::output_change_handler));
126 /* add standard processors */
128 _amp.reset (new Amp (_session, _mute_master));
129 add_processor (_amp, PostFader);
131 _meter.reset (new PeakMeter (_session));
132 add_processor (_meter, PreFader);
134 _main_outs.reset (new Delivery (_session, _output, _mute_master, _name, Delivery::Main));
135 add_processor (_main_outs, PostFader);
137 /* now we can meter */
139 _meter_connection = Metering::connect (mem_fun (*this, &Route::meter));
144 Metering::disconnect (_meter_connection);
146 clear_processors (PreFader);
147 clear_processors (PostFader);
149 for (OrderKeys::iterator i = order_keys.begin(); i != order_keys.end(); ++i) {
150 free ((void*)(i->first));
155 Route::set_remote_control_id (uint32_t id)
157 if (id != _remote_control_id) {
158 _remote_control_id = id;
159 RemoteControlIDChanged ();
164 Route::remote_control_id() const
166 return _remote_control_id;
170 Route::order_key (const char* name) const
172 OrderKeys::const_iterator i;
174 for (i = order_keys.begin(); i != order_keys.end(); ++i) {
175 if (!strcmp (name, i->first)) {
184 Route::set_order_key (const char* name, long n)
186 order_keys[strdup(name)] = n;
188 if (Config->get_sync_all_route_ordering()) {
189 for (OrderKeys::iterator x = order_keys.begin(); x != order_keys.end(); ++x) {
194 _session.set_dirty ();
198 Route::sync_order_keys (const char* base)
200 if (order_keys.empty()) {
204 OrderKeys::iterator i;
207 if ((i = order_keys.find (base)) == order_keys.end()) {
208 /* key doesn't exist, use the first existing key (during session initialization) */
209 i = order_keys.begin();
213 /* key exists - use it and reset all others (actually, itself included) */
215 i = order_keys.begin();
218 for (; i != order_keys.end(); ++i) {
224 Route::ensure_track_or_route_name(string name, Session &session)
226 string newname = name;
228 while (session.route_by_name (newname) != NULL) {
229 newname = bump_name_once (newname);
237 Route::inc_gain (gain_t fraction, void *src)
239 _amp->inc_gain (fraction, src);
243 Route::set_gain (gain_t val, void *src)
245 if (src != 0 && _mix_group && src != _mix_group && _mix_group->is_active()) {
247 if (_mix_group->is_relative()) {
249 gain_t usable_gain = _amp->gain();
250 if (usable_gain < 0.000001f) {
251 usable_gain = 0.000001f;
255 if (delta < 0.000001f) {
259 delta -= usable_gain;
264 gain_t factor = delta / usable_gain;
267 factor = _mix_group->get_max_factor(factor);
268 if (factor == 0.0f) {
269 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
273 factor = _mix_group->get_min_factor(factor);
274 if (factor == 0.0f) {
275 _amp->gain_control()->Changed(); /* EMIT SIGNAL */
280 _mix_group->apply (&Route::inc_gain, factor, _mix_group);
284 _mix_group->apply (&Route::set_gain, val, _mix_group);
290 if (val == _amp->gain()) {
294 _amp->set_gain (val, src);
297 /** Process this route for one (sub) cycle (process thread)
299 * @param bufs Scratch buffers to use for the signal path
300 * @param start_frame Initial transport frame
301 * @param end_frame Final transport frame
302 * @param nframes Number of frames to output (to ports)
304 * Note that (end_frame - start_frame) may not be equal to nframes when the
305 * transport speed isn't 1.0 (eg varispeed).
308 Route::process_output_buffers (BufferSet& bufs,
309 sframes_t start_frame, sframes_t end_frame, nframes_t nframes,
310 bool with_processors, int declick)
314 bufs.is_silent (false);
316 switch (Config->get_monitoring_model()) {
317 case HardwareMonitoring:
318 case ExternalMonitoring:
319 monitor = record_enabled() && (_session.config.get_auto_input() || _session.actively_recording());
326 declick = _pending_declick;
329 /* figure out if we're going to use gain automation */
331 _amp->setup_gain_automation (start_frame, end_frame, nframes);
333 /* tell main outs what to do about monitoring */
335 _main_outs->no_outs_cuz_we_no_monitor (!monitor);
337 /* -------------------------------------------------------------------------------------------
338 GLOBAL DECLICK (for transport changes etc.)
339 ----------------------------------------------------------------------------------------- */
342 Amp::apply_gain (bufs, nframes, 0.0, 1.0);
343 } else if (declick < 0) {
344 Amp::apply_gain (bufs, nframes, 1.0, 0.0);
347 _pending_declick = 0;
349 /* -------------------------------------------------------------------------------------------
350 DENORMAL CONTROL/PHASE INVERT
351 ----------------------------------------------------------------------------------------- */
357 if (_denormal_protection || Config->get_denormal_protection()) {
359 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
360 Sample* const sp = i->data();
362 if (_phase_invert & chn) {
363 for (nframes_t nx = 0; nx < nframes; ++nx) {
368 for (nframes_t nx = 0; nx < nframes; ++nx) {
376 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
377 Sample* const sp = i->data();
379 if (_phase_invert & chn) {
380 for (nframes_t nx = 0; nx < nframes; ++nx) {
389 if (_denormal_protection || Config->get_denormal_protection()) {
391 for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i) {
392 Sample* const sp = i->data();
393 for (nframes_t nx = 0; nx < nframes; ++nx) {
401 /* -------------------------------------------------------------------------------------------
403 ----------------------------------------------------------------------------------------- */
405 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
408 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
409 bufs.set_count (ChanCount::max(bufs.count(), (*i)->input_streams()));
410 (*i)->run (bufs, start_frame, end_frame, nframes);
411 bufs.set_count (ChanCount::max(bufs.count(), (*i)->output_streams()));
414 if (!_processors.empty()) {
415 bufs.set_count (ChanCount::max (bufs.count(), _processors.back()->output_streams()));
421 Route::n_process_buffers ()
423 return max (_input->n_ports(), processor_max_streams);
427 Route::passthru (sframes_t start_frame, sframes_t end_frame, nframes_t nframes, int declick)
429 BufferSet& bufs = _session.get_scratch_buffers (n_process_buffers());
433 assert (bufs.available() >= _input->n_ports());
435 if (_input->n_ports() == ChanCount::ZERO) {
439 bufs.set_count (_input->n_ports());
441 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
443 BufferSet::iterator o = bufs.begin(*t);
444 PortSet& ports (_input->ports());
446 for (PortSet::iterator i = ports.begin(*t); i != ports.end(*t); ++i, ++o) {
447 o->read_from (i->get_buffer(nframes), nframes);
451 process_output_buffers (bufs, start_frame, end_frame, nframes, true, declick);
455 Route::passthru_silence (sframes_t start_frame, sframes_t end_frame, nframes_t nframes, int declick)
457 process_output_buffers (_session.get_silent_buffers (n_process_buffers()), start_frame, end_frame, nframes, true, declick);
461 Route::set_solo (bool yn, void *src)
467 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
468 _mix_group->apply (&Route::set_solo, yn, _mix_group);
472 if (_main_outs->soloed() != yn) {
473 _main_outs->mod_solo_level (yn ? 1 : -1);
474 solo_changed (src); /* EMIT SIGNAL */
475 _solo_control->Changed (); /* EMIT SIGNAL */
480 Route::soloed() const
482 return _main_outs->soloed ();
486 Route::set_solo_isolated (bool yn, void *src)
488 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
489 _mix_group->apply (&Route::set_solo_isolated, yn, _mix_group);
493 _main_outs->set_solo_isolated (yn);
494 solo_isolated_changed (src);
498 Route::solo_isolated () const
500 return _main_outs->solo_isolated();
504 Route::set_mute (bool yn, void *src)
506 if (_mix_group && src != _mix_group && _mix_group->is_active()) {
507 _mix_group->apply (&Route::set_mute, yn, _mix_group);
512 _mute_master->mute (yn);
520 return _mute_master->muted ();
523 #if DEFINE_IF_YOU_NEED_THIS
525 dump_processors(const string& name, const list<boost::shared_ptr<Processor> >& procs)
527 cerr << name << " {" << endl;
528 for (list<boost::shared_ptr<Processor> >::const_iterator p = procs.begin();
529 p != procs.end(); ++p) {
530 cerr << "\t" << (*p)->name() << endl;
536 Route::ProcessorList::iterator
537 Route::prefader_iterator()
539 Glib::RWLock::ReaderLock lm (_processor_lock);
540 return find (_processors.begin(), _processors.end(), _amp);
544 Route::add_processor (boost::shared_ptr<Processor> processor, Placement placement, ProcessorStreams* err)
546 ProcessorList::iterator loc;
548 /* XXX this is not thread safe - we don't hold the lock across determining the iter
549 to add before and actually doing the insertion. dammit.
552 if (placement == PreFader) {
553 /* generic pre-fader: insert immediately before the amp */
554 loc = find(_processors.begin(), _processors.end(), _amp);
556 /* generic post-fader: insert at end */
557 loc = _processors.end();
559 if (processor->visible() && !_processors.empty()) {
560 /* check for invisible processors stacked at the end and leave them there */
561 ProcessorList::iterator p;
562 p = _processors.end();
564 cerr << "Let's check " << (*p)->name() << " vis ? " << (*p)->visible() << endl;
565 while (!(*p)->visible() && p != _processors.begin()) {
573 return add_processor (processor, loc, err);
577 /** Add a processor to the route.
578 * If @a iter is not NULL, it must point to an iterator in _processors and the new
579 * processor will be inserted immediately before this location. Otherwise,
580 * @a position is used.
583 Route::add_processor (boost::shared_ptr<Processor> processor, ProcessorList::iterator iter, ProcessorStreams* err)
585 ChanCount old_pms = processor_max_streams;
587 if (!_session.engine().connected() || !processor) {
592 Glib::RWLock::WriterLock lm (_processor_lock);
594 boost::shared_ptr<PluginInsert> pi;
595 boost::shared_ptr<PortInsert> porti;
597 ProcessorList::iterator loc = find(_processors.begin(), _processors.end(), processor);
599 if (processor == _amp || processor == _meter || processor == _main_outs) {
600 // Ensure only one of these are in the list at any time
601 if (loc != _processors.end()) {
602 if (iter == loc) { // Already in place, do nothing
604 } else { // New position given, relocate
605 _processors.erase (loc);
610 if (loc != _processors.end()) {
611 cerr << "ERROR: Processor added to route twice!" << endl;
618 _processors.insert (loc, processor);
620 // Set up processor list channels. This will set processor->[input|output]_streams(),
621 // configure redirect ports properly, etc.
624 if (configure_processors_unlocked (err)) {
625 ProcessorList::iterator ploc = loc;
627 _processors.erase(ploc);
628 configure_processors_unlocked (0); // it worked before we tried to add it ...
632 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
634 if (pi->natural_input_streams() == ChanCount::ZERO) {
635 /* generator plugin */
636 _have_internal_generator = true;
642 // Ensure peak vector sizes before the plugin is activated
643 ChanCount potential_max_streams = ChanCount::max (processor->input_streams(), processor->output_streams());
644 _meter->configure_io (potential_max_streams, potential_max_streams);
647 // XXX: do we want to emit the signal here ? change call order.
648 processor->activate ();
649 processor->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
651 _output->set_user_latency (0);
654 processors_changed (); /* EMIT SIGNAL */
660 Route::add_processor_from_xml (const XMLNode& node, Placement placement)
662 ProcessorList::iterator loc;
663 if (placement == PreFader) {
664 /* generic pre-fader: insert immediately before the amp */
665 loc = find(_processors.begin(), _processors.end(), _amp);
667 /* generic post-fader: insert at end */
668 loc = _processors.end();
671 return add_processor_from_xml (node, loc);
675 Route::add_processor_from_xml (const XMLNode& node, ProcessorList::iterator iter)
677 const XMLProperty *prop;
679 // legacy sessions use a different node name for sends
680 if (node.name() == "Send") {
683 boost::shared_ptr<Send> send (new Send (_session, _mute_master, node));
684 add_processor (send, iter);
688 catch (failed_constructor &err) {
689 error << _("Send construction failed") << endmsg;
693 } else if (node.name() == "Processor") {
696 if ((prop = node.property ("type")) != 0) {
699 cerr << _name << " : got processor type " << prop->value() << endl;
701 boost::shared_ptr<Processor> processor;
702 bool have_insert = false;
704 if (prop->value() == "ladspa" || prop->value() == "Ladspa" ||
705 prop->value() == "lv2" ||
706 prop->value() == "vst" ||
707 prop->value() == "audiounit") {
709 processor.reset (new PluginInsert(_session, node));
712 } else if (prop->value() == "port") {
714 processor.reset (new PortInsert (_session, _mute_master, node));
716 } else if (prop->value() == "send") {
718 processor.reset (new Send (_session, _mute_master, node));
721 } else if (prop->value() == "meter") {
724 processor->set_state (node);
726 } else if (prop->value() == "amp") {
729 processor->set_state (node);
731 } else if (prop->value() == "listen" || prop->value() == "deliver") {
733 /* XXX need to generalize */
735 processor = _control_outs;
736 processor->set_state (node);
738 } else if (prop->value() == "main-outs") {
740 processor = _main_outs;
741 processor->set_state (node);
745 error << string_compose(_("unknown Processor type \"%1\"; ignored"), prop->value()) << endmsg;
748 if (iter == _processors.end() && processor->visible() && !_processors.empty()) {
749 /* check for invisible processors stacked at the end and leave them there */
750 ProcessorList::iterator p;
751 p = _processors.end();
753 cerr << "Let's check " << (*p)->name() << " vis ? " << (*p)->visible() << endl;
754 while (!(*p)->visible() && p != _processors.begin()) {
761 return (add_processor (processor, iter) == 0);
764 error << _("Processor XML node has no type property") << endmsg;
768 catch (failed_constructor &err) {
769 warning << _("processor could not be created. Ignored.") << endmsg;
777 Route::add_processors (const ProcessorList& others, Placement placement, ProcessorStreams* err)
779 ProcessorList::iterator loc;
780 if (placement == PreFader) {
781 /* generic pre-fader: insert immediately before the amp */
782 loc = find(_processors.begin(), _processors.end(), _amp);
784 /* generic post-fader: insert at end */
785 loc = _processors.end();
787 if (!_processors.empty()) {
788 /* check for invisible processors stacked at the end and leave them there */
789 ProcessorList::iterator p;
790 p = _processors.end();
792 cerr << "Let's check " << (*p)->name() << " vis ? " << (*p)->visible() << endl;
793 while (!(*p)->visible() && p != _processors.begin()) {
801 return add_processors (others, loc, err);
805 Route::add_processors (const ProcessorList& others, ProcessorList::iterator iter, ProcessorStreams* err)
807 /* NOTE: this is intended to be used ONLY when copying
808 processors from another Route. Hence the subtle
809 differences between this and ::add_processor()
812 ChanCount old_pms = processor_max_streams;
814 if (!_session.engine().connected()) {
818 if (others.empty()) {
823 Glib::RWLock::WriterLock lm (_processor_lock);
824 ProcessorList::iterator existing_end = _processors.end();
827 ChanCount potential_max_streams = ChanCount::max (_input->n_ports(), _output->n_ports());
829 for (ProcessorList::const_iterator i = others.begin(); i != others.end(); ++i) {
831 // Ensure meter only appears in the list once
833 ProcessorList::iterator m = find(_processors.begin(), _processors.end(), *i);
834 if (m != _processors.end()) {
835 _processors.erase(m);
839 boost::shared_ptr<PluginInsert> pi;
841 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
844 ChanCount m = max(pi->input_streams(), pi->output_streams());
845 if (m > potential_max_streams)
846 potential_max_streams = m;
849 // Ensure peak vector sizes before the plugin is activated
850 _meter->configure_io (potential_max_streams, potential_max_streams);
852 _processors.insert (iter, *i);
854 if (configure_processors_unlocked (err)) {
856 _processors.erase (existing_end, _processors.end());
857 configure_processors_unlocked (0); // it worked before we tried to add it ...
861 (*i)->ActiveChanged.connect (bind (mem_fun (_session, &Session::update_latency_compensation), false, false));
864 _output->set_user_latency (0);
867 processors_changed (); /* EMIT SIGNAL */
873 Route::placement_range(Placement p, ProcessorList::iterator& start, ProcessorList::iterator& end)
876 start = _processors.begin();
877 end = find(_processors.begin(), _processors.end(), _amp);
879 start = find(_processors.begin(), _processors.end(), _amp);
881 end = _processors.end();
885 /** Turn off all processors with a given placement
886 * @param p Placement of processors to disable
889 Route::disable_processors (Placement p)
891 Glib::RWLock::ReaderLock lm (_processor_lock);
893 ProcessorList::iterator start, end;
894 placement_range(p, start, end);
896 for (ProcessorList::iterator i = start; i != end; ++i) {
900 _session.set_dirty ();
903 /** Turn off all redirects
906 Route::disable_processors ()
908 Glib::RWLock::ReaderLock lm (_processor_lock);
910 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
914 _session.set_dirty ();
917 /** Turn off all redirects with a given placement
918 * @param p Placement of redirects to disable
921 Route::disable_plugins (Placement p)
923 Glib::RWLock::ReaderLock lm (_processor_lock);
925 ProcessorList::iterator start, end;
926 placement_range(p, start, end);
928 for (ProcessorList::iterator i = start; i != end; ++i) {
929 if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
934 _session.set_dirty ();
937 /** 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)) {
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()) {
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()) {
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 that isn't a send; sends don't affect the number
1008 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
1012 if (boost::dynamic_pointer_cast<Send> (*i) == 0) {
1018 return processor->output_streams();
1020 return _input->n_ports ();
1025 /** Remove processors with a given placement.
1026 * @param p Placement of processors to remove.
1029 Route::clear_processors (Placement p)
1031 const ChanCount old_pms = processor_max_streams;
1033 if (!_session.engine().connected()) {
1037 bool already_deleting = _session.deletion_in_progress();
1038 if (!already_deleting) {
1039 _session.set_deletion_in_progress();
1043 Glib::RWLock::WriterLock lm (_processor_lock);
1044 ProcessorList new_list;
1045 ProcessorStreams err;
1047 ProcessorList::iterator amp_loc = find(_processors.begin(), _processors.end(), _amp);
1048 if (p == PreFader) {
1049 // Get rid of PreFader processors
1050 for (ProcessorList::iterator i = _processors.begin(); i != amp_loc; ++i) {
1051 (*i)->drop_references ();
1054 for (ProcessorList::iterator i = amp_loc; i != _processors.end(); ++i) {
1055 new_list.push_back (*i);
1058 // Keep PreFader processors
1059 for (ProcessorList::iterator i = _processors.begin(); i != amp_loc; ++i) {
1060 new_list.push_back (*i);
1062 new_list.push_back (_amp);
1063 // Get rid of PostFader processors
1064 for (ProcessorList::iterator i = amp_loc; i != _processors.end(); ++i) {
1065 (*i)->drop_references ();
1069 _processors = new_list;
1070 configure_processors_unlocked (&err); // this can't fail
1073 processor_max_streams.reset();
1074 _have_internal_generator = false;
1075 processors_changed (); /* EMIT SIGNAL */
1077 if (!already_deleting) {
1078 _session.clear_deletion_in_progress();
1083 Route::remove_processor (boost::shared_ptr<Processor> processor, ProcessorStreams* err)
1085 /* these can never be removed */
1087 if (processor == _amp || processor == _meter || processor == _main_outs) {
1091 ChanCount old_pms = processor_max_streams;
1093 if (!_session.engine().connected()) {
1097 processor_max_streams.reset();
1100 Glib::RWLock::WriterLock lm (_processor_lock);
1101 ProcessorList::iterator i;
1102 bool removed = false;
1104 for (i = _processors.begin(); i != _processors.end(); ) {
1105 if (*i == processor) {
1107 /* move along, see failure case for configure_processors()
1108 where we may need to reconfigure the processor.
1111 /* stop redirects that send signals to JACK ports
1112 from causing noise as a result of no longer being
1116 boost::shared_ptr<IOProcessor> iop;
1118 if ((iop = boost::dynamic_pointer_cast<IOProcessor> (*i)) != 0) {
1120 iop->input()->disconnect (this);
1122 if (iop->output()) {
1123 iop->output()->disconnect (this);
1127 i = _processors.erase (i);
1135 _output->set_user_latency (0);
1143 if (configure_processors_unlocked (err)) {
1144 /* get back to where we where */
1145 _processors.insert (i, processor);
1146 /* we know this will work, because it worked before :) */
1147 configure_processors_unlocked (0);
1151 _have_internal_generator = false;
1153 for (i = _processors.begin(); i != _processors.end(); ++i) {
1154 boost::shared_ptr<PluginInsert> pi;
1156 if ((pi = boost::dynamic_pointer_cast<PluginInsert>(*i)) != 0) {
1157 if (pi->is_generator()) {
1158 _have_internal_generator = true;
1165 processor->drop_references ();
1166 processors_changed (); /* EMIT SIGNAL */
1172 Route::configure_processors (ProcessorStreams* err)
1174 if (!_in_configure_processors) {
1175 Glib::RWLock::WriterLock lm (_processor_lock);
1176 return configure_processors_unlocked (err);
1181 /** Configure the input/output configuration of each processor in the processors list.
1182 * Return 0 on success, otherwise configuration is impossible.
1185 Route::configure_processors_unlocked (ProcessorStreams* err)
1187 if (_in_configure_processors) {
1191 _in_configure_processors = true;
1193 // Check each processor in order to see if we can configure as requested
1194 ChanCount in = _input->n_ports ();
1196 list< pair<ChanCount,ChanCount> > configuration;
1198 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++index) {
1199 if ((*p)->can_support_io_configuration(in, out)) {
1200 configuration.push_back(make_pair(in, out));
1207 _in_configure_processors = false;
1212 // We can, so configure everything
1213 list< pair<ChanCount,ChanCount> >::iterator c = configuration.begin();
1214 for (ProcessorList::iterator p = _processors.begin(); p != _processors.end(); ++p, ++c) {
1215 (*p)->configure_io(c->first, c->second);
1217 processor_max_streams = ChanCount::max(processor_max_streams, c->first);
1218 processor_max_streams = ChanCount::max(processor_max_streams, c->second);
1222 // Ensure route outputs match last processor's outputs
1223 if (out != _output->n_ports ()) {
1224 _output->ensure_io (out, false, this);
1227 _in_configure_processors = false;
1232 Route::all_processors_flip ()
1234 Glib::RWLock::ReaderLock lm (_processor_lock);
1236 if (_processors.empty()) {
1240 bool first_is_on = _processors.front()->active();
1242 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1244 (*i)->deactivate ();
1250 _session.set_dirty ();
1253 /** Set all processors with a given placement to a given active state.
1254 * @param p Placement of processors to change.
1255 * @param state New active state for those processors.
1258 Route::all_processors_active (Placement p, bool state)
1260 Glib::RWLock::ReaderLock lm (_processor_lock);
1262 if (_processors.empty()) {
1265 ProcessorList::iterator start, end;
1266 placement_range(p, start, end);
1268 bool before_amp = true;
1269 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1274 if (p == PreFader && before_amp) {
1278 (*i)->deactivate ();
1283 _session.set_dirty ();
1287 Route::reorder_processors (const ProcessorList& new_order, Placement placement, ProcessorStreams* err)
1289 /* "new_order" is an ordered list of processors to be positioned according to "placement".
1290 NOTE: all processors in "new_order" MUST be marked as visible. There maybe additional
1291 processors in the current actual processor list that are hidden. Any visible processors
1292 in the current list but not in "new_order" will be assumed to be deleted.
1296 Glib::RWLock::WriterLock lm (_processor_lock);
1297 ChanCount old_pms = processor_max_streams;
1298 ProcessorList::iterator oiter;
1299 ProcessorList::const_iterator niter;
1300 ProcessorList as_it_was_before = _processors;
1301 ProcessorList as_it_will_be;
1302 ProcessorList::iterator start, end;
1304 placement_range (placement, start, end);
1307 niter = new_order.begin();
1309 while (niter != new_order.end()) {
1311 /* if the next processor in the old list is invisible (i.e. should not be in the new order)
1312 then append it to the temp list.
1314 Otherwise, see if the next processor in the old list is in the new list. if not,
1315 its been deleted. If its there, append it to the temp list.
1320 /* no more elements in the old list, so just stick the rest of
1321 the new order onto the temp list.
1324 as_it_will_be.insert (as_it_will_be.end(), niter, new_order.end());
1325 while (niter != new_order.end()) {
1326 (*niter)->set_placement (placement);
1333 if (!(*oiter)->visible()) {
1335 as_it_will_be.push_back (*oiter);
1336 (*oiter)->set_placement (placement);
1340 /* visible processor: check that its in the new order */
1342 if (find (new_order.begin(), new_order.end(), (*oiter)) == new_order.end()) {
1343 /* deleted: do nothing, shared_ptr<> will clean up */
1345 /* ignore this one, and add the next item from the new order instead */
1346 as_it_will_be.push_back (*niter);
1347 (*niter)->set_placement (placement);
1352 /* now remove from old order - its taken care of no matter what */
1353 oiter = _processors.erase (oiter);
1358 _processors.insert (oiter, as_it_will_be.begin(), as_it_will_be.end());
1360 if (configure_processors_unlocked (err)) {
1361 _processors = as_it_was_before;
1362 processor_max_streams = old_pms;
1367 processors_changed (); /* EMIT SIGNAL */
1379 Route::get_template()
1381 return state(false);
1385 Route::state(bool full_state)
1387 XMLNode *node = new XMLNode("Route");
1388 ProcessorList::iterator i;
1391 node->add_property ("name", _name);
1392 node->add_property("default-type", _default_type.to_string());
1395 node->add_property("flags", enum_2_string (_flags));
1398 node->add_property("active", _active?"yes":"no");
1399 node->add_property("phase-invert", _phase_invert?"yes":"no");
1400 node->add_property("denormal-protection", _denormal_protection?"yes":"no");
1401 node->add_property("meter-point", enum_2_string (_meter_point));
1404 node->add_property("edit-group", _edit_group->name());
1407 node->add_property("mix-group", _mix_group->name());
1410 string order_string;
1411 OrderKeys::iterator x = order_keys.begin();
1413 while (x != order_keys.end()) {
1414 order_string += string ((*x).first);
1415 order_string += '=';
1416 snprintf (buf, sizeof(buf), "%ld", (*x).second);
1417 order_string += buf;
1421 if (x == order_keys.end()) {
1425 order_string += ':';
1427 node->add_property ("order-keys", order_string);
1429 node->add_child_nocopy (_input->state (full_state));
1430 node->add_child_nocopy (_output->state (full_state));
1431 node->add_child_nocopy (_solo_control->get_state ());
1432 node->add_child_nocopy (_mute_master->get_state ());
1434 XMLNode* remote_control_node = new XMLNode (X_("RemoteControl"));
1435 snprintf (buf, sizeof (buf), "%d", _remote_control_id);
1436 remote_control_node->add_property (X_("id"), buf);
1437 node->add_child_nocopy (*remote_control_node);
1439 if (_comment.length()) {
1440 XMLNode *cmt = node->add_child ("Comment");
1441 cmt->add_content (_comment);
1444 for (i = _processors.begin(); i != _processors.end(); ++i) {
1445 node->add_child_nocopy((*i)->state (full_state));
1449 node->add_child_copy (*_extra_xml);
1456 Route::set_state (const XMLNode& node)
1458 return _set_state (node, true);
1462 Route::_set_state (const XMLNode& node, bool call_base)
1466 XMLNodeConstIterator niter;
1468 XMLPropertyList plist;
1469 const XMLProperty *prop;
1471 if (node.name() != "Route"){
1472 error << string_compose(_("Bad node sent to Route::set_state() [%1]"), node.name()) << endmsg;
1476 if ((prop = node.property (X_("name"))) != 0) {
1477 Route::set_name (prop->value());
1480 if ((prop = node.property (X_("flags"))) != 0) {
1481 _flags = Flag (string_2_enum (prop->value(), _flags));
1486 if ((prop = node.property (X_("phase-invert"))) != 0) {
1487 set_phase_invert (prop->value()=="yes"?true:false);
1490 if ((prop = node.property (X_("denormal-protection"))) != 0) {
1491 set_denormal_protection (prop->value()=="yes"?true:false);
1494 if ((prop = node.property (X_("active"))) != 0) {
1495 bool yn = (prop->value() == "yes");
1496 _active = !yn; // force switch
1500 if ((prop = node.property (X_("soloed"))) != 0) {
1501 bool yn = (prop->value()=="yes");
1503 /* XXX force reset of solo status */
1505 set_solo (yn, this);
1508 if ((prop = node.property (X_("meter-point"))) != 0) {
1509 _meter_point = MeterPoint (string_2_enum (prop->value (), _meter_point));
1512 if ((prop = node.property (X_("edit-group"))) != 0) {
1513 RouteGroup* edit_group = _session.edit_group_by_name(prop->value());
1514 if(edit_group == 0) {
1515 error << string_compose(_("Route %1: unknown edit group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
1517 set_edit_group(edit_group, this);
1521 if ((prop = node.property (X_("order-keys"))) != 0) {
1525 string::size_type colon, equal;
1526 string remaining = prop->value();
1528 while (remaining.length()) {
1530 if ((equal = remaining.find_first_of ('=')) == string::npos || equal == remaining.length()) {
1531 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1534 if (sscanf (remaining.substr (equal+1).c_str(), "%ld", &n) != 1) {
1535 error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
1538 set_order_key (remaining.substr (0, equal).c_str(), n);
1542 colon = remaining.find_first_of (':');
1544 if (colon != string::npos) {
1545 remaining = remaining.substr (colon+1);
1552 nlist = node.children();
1553 XMLNode processor_state (X_("processor_state"));
1555 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1559 if (child->name() == IO::state_node_name) {
1560 if ((prop = child->property (X_("direction"))) == 0) {
1564 if (prop->value() == "Input") {
1565 _input->set_state (*child);
1566 } else if (prop->value() == "Output") {
1567 _output->set_state (*child);
1571 if (child->name() == X_("Processor")) {
1572 processor_state.add_child_copy (*child);
1576 set_processor_state (processor_state);
1578 for (niter = nlist.begin(); niter != nlist.end(); ++niter){
1581 if (child->name() == X_("Comment")) {
1583 /* XXX this is a terrible API design in libxml++ */
1585 XMLNode *cmt = *(child->children().begin());
1586 _comment = cmt->content();
1588 } else if (child->name() == X_("Extra")) {
1590 _extra_xml = new XMLNode (*child);
1592 } else if (child->name() == X_("Controllable") && (prop = child->property("name")) != 0) {
1594 if (prop->value() == "solo") {
1595 _solo_control->set_state (*child);
1596 _session.add_controllable (_solo_control);
1599 } else if (child->name() == X_("RemoteControl")) {
1600 if ((prop = child->property (X_("id"))) != 0) {
1602 sscanf (prop->value().c_str(), "%d", &x);
1603 set_remote_control_id (x);
1606 } else if (child->name() == X_("MuteMaster")) {
1607 _mute_master->set_state (*child);
1611 if ((prop = node.property (X_("mix-group"))) != 0) {
1612 RouteGroup* mix_group = _session.mix_group_by_name(prop->value());
1613 if (mix_group == 0) {
1614 error << string_compose(_("Route %1: unknown mix group \"%2 in saved state (ignored)"), _name, prop->value()) << endmsg;
1616 set_mix_group(mix_group, this);
1624 Route::get_processor_state ()
1626 XMLNode* root = new XMLNode (X_("redirects"));
1627 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1628 root->add_child_nocopy ((*i)->state (true));
1635 Route::set_processor_state (const XMLNode& node)
1637 const XMLNodeList &nlist = node.children();
1638 XMLNodeConstIterator niter;
1639 bool has_meter_processor = false; // legacy sessions don't
1640 ProcessorList::iterator i, o;
1642 cerr << _name << " _set_processor_states\n";
1644 // Iterate through existing processors, remove those which are not in the state list
1645 for (i = _processors.begin(); i != _processors.end(); ) {
1646 ProcessorList::iterator tmp = i;
1649 bool processorInStateList = false;
1651 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
1653 XMLProperty* id_prop = (*niter)->property(X_("id"));
1654 if (id_prop && (*i)->id() == id_prop->value()) {
1655 processorInStateList = true;
1660 if (!processorInStateList) {
1661 remove_processor (*i);
1667 // Iterate through state list and make sure all processors are on the track and in the correct order,
1668 // set the state of existing processors according to the new state on the same go
1669 i = _processors.begin();
1671 for (niter = nlist.begin(); niter != nlist.end(); ++niter, ++i) {
1673 XMLProperty* prop = (*niter)->property ("type");
1675 if (prop && prop->value() == "meter") {
1676 has_meter_processor = true;
1681 if (prop->value() != "meter" && prop->value() != "amp" && prop->value() != "main-outs") {
1683 // Check whether the next processor in the list
1685 while (o != _processors.end()) {
1686 XMLProperty* id_prop = (*niter)->property(X_("id"));
1687 if (id_prop && (*o)->id() == id_prop->value()) {
1695 // If the processor (*niter) is not on the route,
1696 // create it and move it to the correct location
1697 if (o == _processors.end()) {
1699 if (add_processor_from_xml (**niter, i)) {
1700 --i; // move iterator to the newly inserted processor
1702 cerr << "Error restoring route: unable to restore processor" << endl;
1705 // Otherwise, the processor already exists; just
1706 // ensure it is at the location provided in the XML state
1710 boost::shared_ptr<Processor> tmp = (*o);
1711 _processors.erase (o); // remove the old copy
1712 _processors.insert (i, tmp); // insert the processor at the correct location
1713 --i; // move iterator to the correct processor
1716 (*i)->set_state (**niter);
1720 /* note: there is no configure_processors() call because we figure that
1721 the XML state represents a working signal route.
1724 if (!has_meter_processor) {
1725 set_meter_point (_meter_point, NULL);
1728 processors_changed ();
1732 Route::curve_reallocate ()
1734 // _gain_automation_curve.finish_resize ();
1735 // _pan_automation_curve.finish_resize ();
1739 Route::silence (nframes_t nframes)
1743 _output->silence (nframes);
1746 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
1749 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1750 boost::shared_ptr<PluginInsert> pi;
1752 if (!_active && (pi = boost::dynamic_pointer_cast<PluginInsert> (*i)) != 0) {
1753 // skip plugins, they don't need anything when we're not active
1757 (*i)->silence (nframes);
1760 if (nframes == _session.get_block_size()) {
1769 boost::shared_ptr<Delivery>
1770 Route::add_listener (boost::shared_ptr<IO> io, const string& listen_name)
1772 string name = _name;
1774 name += listen_name;
1777 boost::shared_ptr<Delivery> listener (new Delivery (_session, _mute_master, name, Delivery::Listen));
1779 /* As an IO, our control outs need as many IO outputs as we have outputs
1780 * (we track the changes in ::output_change_handler()).
1781 * As a processor, the listener is an identity processor
1782 * (i.e. it does not modify its input buffers whatsoever)
1785 if (listener->output()->ensure_io (n_outputs(), true, this)) {
1786 return boost::shared_ptr<Delivery>();
1789 add_processor (listener, PostFader);
1795 Route::listen_via (boost::shared_ptr<IO> io, const string& listen_name)
1797 vector<string> ports;
1798 vector<string>::const_iterator i;
1801 Glib::RWLock::ReaderLock rm (_processor_lock);
1803 for (ProcessorList::const_iterator x = _processors.begin(); x != _processors.end(); ++x) {
1804 boost::shared_ptr<const Delivery> d = boost::dynamic_pointer_cast<const Delivery>(*x);
1806 if (d && d->output() == io) {
1807 /* already listening via the specified IO: do nothing */
1813 uint32_t ni = io->n_ports().n_total();
1815 for (uint32_t n = 0; n < ni; ++n) {
1816 ports.push_back (io->nth (n)->name());
1819 if (ports.empty()) {
1823 boost::shared_ptr<Delivery> listen_point = add_listener (io, listen_name);
1825 /* XXX hack for now .... until we can generalize listen points */
1827 _control_outs = listen_point;
1829 /* now connect to the named ports */
1831 ni = listen_point->output()->n_ports().n_total();
1832 size_t psize = ports.size();
1834 for (size_t n = 0; n < ni; ++n) {
1835 if (listen_point->output()->connect (listen_point->output()->nth (n), ports[n % psize], this)) {
1836 error << string_compose (_("could not connect %1 to %2"),
1837 listen_point->output()->nth (n)->name(), ports[n % psize]) << endmsg;
1847 Route::drop_listen (boost::shared_ptr<IO> io)
1849 ProcessorStreams err;
1850 ProcessorList::iterator tmp;
1852 Glib::RWLock::ReaderLock rm (_processor_lock);
1854 for (ProcessorList::iterator x = _processors.begin(); x != _processors.end(); ) {
1859 boost::shared_ptr<Delivery> d = boost::dynamic_pointer_cast<Delivery>(*x);
1861 if (d && d->output() == io) {
1862 /* already listening via the specified IO: do nothing */
1863 remove_processor (*x, &err);
1872 Route::set_edit_group (RouteGroup *eg, void *src)
1875 if (eg == _edit_group) {
1880 _edit_group->remove (this);
1883 if ((_edit_group = eg) != 0) {
1884 _edit_group->add (this);
1887 _session.set_dirty ();
1888 edit_group_changed (src); /* EMIT SIGNAL */
1892 Route::drop_edit_group (void *src)
1895 _session.set_dirty ();
1896 edit_group_changed (src); /* EMIT SIGNAL */
1900 Route::set_mix_group (RouteGroup *mg, void *src)
1903 if (mg == _mix_group) {
1908 _mix_group->remove (this);
1911 if ((_mix_group = mg) != 0) {
1912 _mix_group->add (this);
1915 _session.set_dirty ();
1916 mix_group_changed (src); /* EMIT SIGNAL */
1920 Route::drop_mix_group (void *src)
1923 _session.set_dirty ();
1924 mix_group_changed (src); /* EMIT SIGNAL */
1928 Route::set_comment (string cmt, void *src)
1931 comment_changed (src);
1932 _session.set_dirty ();
1936 Route::feeds (boost::shared_ptr<IO> other)
1938 if (_output->connected_to (other)) {
1942 /* check IOProcessors which may also interconnect Routes */
1944 for (ProcessorList::iterator r = _processors.begin(); r != _processors.end(); r++) {
1946 boost::shared_ptr<IOProcessor> iop;
1948 if ((iop = boost::dynamic_pointer_cast<IOProcessor>(*r)) != 0) {
1949 if (iop->output() && iop->output()->connected_to (other)) {
1959 Route::handle_transport_stopped (bool abort_ignored, bool did_locate, bool can_flush_processors)
1961 nframes_t now = _session.transport_frame();
1964 Glib::RWLock::ReaderLock lm (_processor_lock);
1967 automation_snapshot (now, true);
1970 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
1972 if (Config->get_plugins_stop_with_transport() && can_flush_processors) {
1973 (*i)->deactivate ();
1977 (*i)->transport_stopped (now);
1981 _roll_delay = _initial_delay;
1985 Route::input_change_handler (IOChange change, void *src)
1987 if ((change & ConfigurationChanged)) {
1988 configure_processors (0);
1993 Route::output_change_handler (IOChange change, void *src)
1995 if ((change & ConfigurationChanged)) {
1997 /* XXX resize all listeners to match _main_outs? */
1999 // configure_processors (0);
2004 Route::pans_required () const
2006 if (n_outputs().n_audio() < 2) {
2010 return max (n_inputs ().n_audio(), processor_max_streams.n_audio());
2014 Route::no_roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame,
2015 bool session_state_changing, bool can_record, bool rec_monitors_input)
2017 if (n_outputs().n_total() == 0) {
2021 if (session_state_changing || !_active || n_inputs() == ChanCount::ZERO) {
2026 _amp->apply_gain_automation (false);
2027 passthru (start_frame, end_frame, nframes, 0);
2033 Route::check_initial_delay (nframes_t nframes, nframes_t& transport_frame)
2035 if (_roll_delay > nframes) {
2037 _roll_delay -= nframes;
2039 /* transport frame is not legal for caller to use */
2042 } else if (_roll_delay > 0) {
2044 nframes -= _roll_delay;
2045 silence (_roll_delay);
2046 /* we've written _roll_delay of samples into the
2047 output ports, so make a note of that for
2050 _main_outs->increment_output_offset (_roll_delay);
2051 transport_frame += _roll_delay;
2060 Route::roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame, int declick,
2061 bool can_record, bool rec_monitors_input)
2064 // automation snapshot can also be called from the non-rt context
2065 // and it uses the processor list, so we try to acquire the lock here
2066 Glib::RWLock::ReaderLock lm (_processor_lock, Glib::TRY_LOCK);
2069 automation_snapshot (_session.transport_frame(), false);
2073 if (n_outputs().n_total() == 0) {
2077 if (!_active || n_inputs().n_total() == 0) {
2082 nframes_t unused = 0;
2084 if ((nframes = check_initial_delay (nframes, unused)) == 0) {
2090 passthru (start_frame, end_frame, nframes, declick);
2096 Route::silent_roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame,
2097 bool can_record, bool rec_monitors_input)
2104 Route::toggle_monitor_input ()
2106 for (PortSet::iterator i = _input->ports().begin(); i != _input->ports().end(); ++i) {
2107 i->ensure_monitor_input( ! i->monitoring_input());
2112 Route::has_external_redirects () const
2114 // FIXME: what about sends? - they don't return a signal back to ardour?
2116 boost::shared_ptr<const PortInsert> pi;
2118 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2120 if ((pi = boost::dynamic_pointer_cast<const PortInsert>(*i)) != 0) {
2122 for (PortSet::const_iterator port = pi->output()->ports().begin(); port != pi->output()->ports().end(); ++port) {
2124 string port_name = port->name();
2125 string client_name = port_name.substr (0, port_name.find(':'));
2127 /* only say "yes" if the redirect is actually in use */
2129 if (client_name != "ardour" && pi->active()) {
2140 Route::flush_processors ()
2142 /* XXX shouldn't really try to take this lock, since
2143 this is called from the RT audio thread.
2146 Glib::RWLock::ReaderLock lm (_processor_lock);
2148 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2149 (*i)->deactivate ();
2155 Route::set_meter_point (MeterPoint p, void *src)
2157 if (_meter_point != p) {
2160 // Move meter in the processors list
2161 ProcessorList::iterator loc = find(_processors.begin(), _processors.end(), _meter);
2162 _processors.erase(loc);
2165 loc = _processors.begin();
2168 loc = find(_processors.begin(), _processors.end(), _amp);
2170 case MeterPostFader:
2171 loc = _processors.end();
2174 _processors.insert(loc, _meter);
2176 meter_change (src); /* EMIT SIGNAL */
2177 processors_changed (); /* EMIT SIGNAL */
2178 _session.set_dirty ();
2183 Route::update_total_latency ()
2185 nframes_t old = _output->effective_latency();
2186 nframes_t own_latency = _output->user_latency();
2188 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2189 if ((*i)->active ()) {
2190 own_latency += (*i)->signal_latency ();
2194 #undef DEBUG_LATENCY
2195 #ifdef DEBUG_LATENCY
2196 cerr << _name << ": internal redirect latency = " << own_latency << endl;
2199 _output->set_port_latency (own_latency);
2201 if (_output->user_latency() == 0) {
2203 /* this (virtual) function is used for pure Routes,
2204 not derived classes like AudioTrack. this means
2205 that the data processed here comes from an input
2206 port, not prerecorded material, and therefore we
2207 have to take into account any input latency.
2210 own_latency += _input->signal_latency ();
2213 if (old != own_latency) {
2214 _output->set_latency_delay (own_latency);
2215 signal_latency_changed (); /* EMIT SIGNAL */
2218 #ifdef DEBUG_LATENCY
2219 cerr << _name << ": input latency = " << _input->signal_latency() << " total = "
2220 << own_latency << endl;
2223 return _output->effective_latency ();
2227 Route::set_user_latency (nframes_t nframes)
2229 _output->set_user_latency (nframes);
2230 _session.update_latency_compensation (false, false);
2234 Route::set_latency_delay (nframes_t longest_session_latency)
2236 nframes_t old = _initial_delay;
2238 if (_output->effective_latency() < longest_session_latency) {
2239 _initial_delay = longest_session_latency - _output->effective_latency();
2244 if (_initial_delay != old) {
2245 initial_delay_changed (); /* EMIT SIGNAL */
2248 if (_session.transport_stopped()) {
2249 _roll_delay = _initial_delay;
2254 Route::automation_snapshot (nframes_t now, bool force)
2256 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2257 (*i)->automation_snapshot (now, force);
2261 Route::SoloControllable::SoloControllable (std::string name, Route& r)
2262 : AutomationControl (r.session(), Evoral::Parameter (SoloAutomation),
2263 boost::shared_ptr<AutomationList>(), name)
2266 boost::shared_ptr<AutomationList> gl(new AutomationList(Evoral::Parameter(SoloAutomation)));
2271 Route::SoloControllable::set_value (float val)
2273 bool bval = ((val >= 0.5f) ? true: false);
2275 route.set_solo (bval, this);
2279 Route::SoloControllable::get_value (void) const
2281 return route.soloed() ? 1.0f : 0.0f;
2285 Route::set_block_size (nframes_t nframes)
2287 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2288 (*i)->set_block_size (nframes);
2290 _session.ensure_buffers(processor_max_streams);
2294 Route::protect_automation ()
2296 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i)
2297 (*i)->protect_automation();
2301 Route::set_pending_declick (int declick)
2304 /* this call is not allowed to turn off a pending declick unless "force" is true */
2306 _pending_declick = declick;
2308 // cerr << _name << ": after setting to " << declick << " pending declick = " << _pending_declick << endl;
2310 _pending_declick = 0;
2315 /** Shift automation forwards from a particular place, thereby inserting time.
2316 * Adds undo commands for any shifts that are performed.
2318 * @param pos Position to start shifting from.
2319 * @param frames Amount to shift forwards by.
2323 Route::shift (nframes64_t pos, nframes64_t frames)
2325 #ifdef THIS_NEEDS_FIXING_FOR_V3
2327 /* gain automation */
2328 XMLNode &before = _gain_control->get_state ();
2329 _gain_control->shift (pos, frames);
2330 XMLNode &after = _gain_control->get_state ();
2331 _session.add_command (new MementoCommand<AutomationList> (_gain_automation_curve, &before, &after));
2333 /* pan automation */
2334 for (std::vector<StreamPanner*>::iterator i = _panner->begin (); i != _panner->end (); ++i) {
2335 Curve & c = (*i)->automation ();
2336 XMLNode &before = c.get_state ();
2337 c.shift (pos, frames);
2338 XMLNode &after = c.get_state ();
2339 _session.add_command (new MementoCommand<AutomationList> (c, &before, &after));
2342 /* redirect automation */
2344 Glib::RWLock::ReaderLock lm (redirect_lock);
2345 for (RedirectList::iterator i = _redirects.begin (); i != _redirects.end (); ++i) {
2348 (*i)->what_has_automation (a);
2350 for (set<uint32_t>::const_iterator j = a.begin (); j != a.end (); ++j) {
2351 AutomationList & al = (*i)->automation_list (*j);
2352 XMLNode &before = al.get_state ();
2353 al.shift (pos, frames);
2354 XMLNode &after = al.get_state ();
2355 _session.add_command (new MementoCommand<AutomationList> (al, &before, &after));
2365 Route::save_as_template (const string& path, const string& name)
2367 XMLNode& node (state (false));
2370 IO::set_name_in_state (*node.children().front(), name);
2372 tree.set_root (&node);
2373 return tree.write (path.c_str());
2378 Route::set_name (const string& str)
2383 SessionObject::set_name (str);
2385 ret = (_input->set_name(str) && _output->set_name(str));
2389 Glib::RWLock::ReaderLock lm (_processor_lock);
2391 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2393 /* rename all processors with outputs to reflect our new name */
2395 boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor> (*i);
2398 string iop_name = str;
2400 iop_name += "XXX FIX ME XXX";
2403 if (!iop->set_name (iop_name)) {
2414 boost::shared_ptr<Send>
2415 Route::send_for (boost::shared_ptr<const IO> target) const
2417 Glib::RWLock::ReaderLock lm (_processor_lock);
2419 for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
2420 boost::shared_ptr<Send> send;
2422 if ((send = boost::dynamic_pointer_cast<Send>(*i)) != 0) {
2423 if (send->output()->connected_to (target)) {
2429 return boost::shared_ptr<Send>();
2433 Route::set_phase_invert (bool yn)
2435 if (_phase_invert != yn) {
2436 _phase_invert = 0xffff; // XXX all channels
2437 phase_invert_changed (); /* EMIT SIGNAL */
2442 Route::phase_invert () const
2444 return _phase_invert != 0;
2448 Route::set_denormal_protection (bool yn)
2450 if (_denormal_protection != yn) {
2451 _denormal_protection = yn;
2452 denormal_protection_changed (); /* EMIT SIGNAL */
2457 Route::denormal_protection () const
2459 return _denormal_protection;
2463 Route::set_active (bool yn)
2465 if (_active != yn) {
2467 _input->set_active (yn);
2468 _output->set_active (yn);
2469 active_changed (); // EMIT SIGNAL
2476 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
2480 boost::shared_ptr<Panner>
2481 Route::panner() const
2484 return _main_outs->panner();
2487 boost::shared_ptr<AutomationControl>
2488 Route::gain_control() const
2491 return _amp->gain_control();
2494 boost::shared_ptr<AutomationControl>
2495 Route::get_control (const Evoral::Parameter& param)
2497 /* either we own the control or .... */
2499 boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(data().control (param));
2503 /* maybe one of our processors does or ... */
2505 Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
2506 for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
2507 if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->data().control (param))) != 0) {
2515 /* nobody does so we'll make a new one */
2517 c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));