summaryrefslogtreecommitdiff
path: root/libs/ardour/route.cc
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2016-05-19 01:44:44 +0200
committerRobin Gareus <robin@gareus.org>2016-05-19 01:44:44 +0200
commit7e463bab6eb5a733c507c90cd4cb554b1ca1c34f (patch)
tree89d382445e16829a2aa6e0a8e735fb73e9cace84 /libs/ardour/route.cc
parenta7d03731a21e5ba92226233a0c08f1aa8019b50b (diff)
consolidate add_processor code
* fixes drag/copy'ing sidechain sends (autodestruct) * reduce duplicated code * prepare for instrument replacement
Diffstat (limited to 'libs/ardour/route.cc')
-rw-r--r--libs/ardour/route.cc130
1 files changed, 36 insertions, 94 deletions
diff --git a/libs/ardour/route.cc b/libs/ardour/route.cc
index 1e9f0ee3a9..8a98149fa0 100644
--- a/libs/ardour/route.cc
+++ b/libs/ardour/route.cc
@@ -1257,93 +1257,17 @@ Route::add_processor (boost::shared_ptr<Processor> processor, boost::shared_ptr<
DEBUG_TRACE (DEBUG::Processors, string_compose (
"%1 adding processor %2\n", name(), processor->name()));
- if (!AudioEngine::instance()->connected() || !processor) {
- return 1;
- }
-
- if (_strict_io) {
- boost::shared_ptr<PluginInsert> pi;
- if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
- pi->set_strict_io (true);
- }
- }
-
- {
- Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ());
- Glib::Threads::RWLock::WriterLock lm (_processor_lock);
- ProcessorState pstate (this);
-
- boost::shared_ptr<PluginInsert> pi;
- boost::shared_ptr<PortInsert> porti;
-
- if (processor == _amp) {
- /* Ensure that only one amp is in the list at any time */
- ProcessorList::iterator check = find (_processors.begin(), _processors.end(), processor);
- if (check != _processors.end()) {
- if (before == _amp) {
- /* Already in position; all is well */
- return 0;
- } else {
- _processors.erase (check);
- }
- }
- }
-
- assert (find (_processors.begin(), _processors.end(), processor) == _processors.end ());
-
- ProcessorList::iterator loc;
- if (before) {
- /* inserting before a processor; find it */
- loc = find (_processors.begin(), _processors.end(), before);
- if (loc == _processors.end ()) {
- /* Not found */
- return 1;
- }
- } else {
- /* inserting at end */
- loc = _processors.end ();
- }
-
- _processors.insert (loc, processor);
- processor->set_owner (this);
-
- // Set up processor list channels. This will set processor->[input|output]_streams(),
- // configure redirect ports properly, etc.
-
- {
- if (configure_processors_unlocked (err, &lm)) {
- pstate.restore ();
- configure_processors_unlocked (0, &lm); // it worked before we tried to add it ...
- return -1;
- }
- }
-
- if ((pi = boost::dynamic_pointer_cast<PluginInsert>(processor)) != 0) {
-
- if (pi->has_no_inputs ()) {
- /* generator plugin */
- _have_internal_generator = true;
- }
+ ProcessorList pl;
- }
-
- if (activation_allowed && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user ())) {
- processor->activate ();
- }
-
- processor->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
+ pl.push_back (processor);
+ int rv = add_processors (pl, before, err);
- _output->set_user_latency (0);
+ if (rv) {
+ return rv;
}
- reset_instrument_info ();
- processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */
- set_processor_positions ();
-
- boost::shared_ptr<Send> send;
- if ((send = boost::dynamic_pointer_cast<Send> (processor))) {
- send->SelfDestruct.connect_same_thread (*this,
- boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (processor)));
+ if (activation_allowed && (!_session.get_bypass_all_loaded_plugins () || !processor->display_to_user ())) {
+ processor->activate ();
}
return 0;
@@ -1448,21 +1372,19 @@ Route::add_processor_from_xml_2X (const XMLNode& node, int version)
int
Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor> before, ProcessorStreams* err)
{
- /* NOTE: this is intended to be used ONLY when copying
- processors from another Route. Hence the subtle
- differences between this and ::add_processor()
- */
-
ProcessorList::iterator loc;
if (before) {
loc = find(_processors.begin(), _processors.end(), before);
+ if (loc == _processors.end ()) {
+ return 1;
+ }
} else {
/* nothing specified - at end */
loc = _processors.end ();
}
- if (!_session.engine().connected()) {
+ if (!AudioEngine::instance()->connected()) {
return 1;
}
@@ -1487,14 +1409,24 @@ Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor>
pi->set_strict_io (_strict_io);
}
+ if (*i == _amp) {
+ /* Ensure that only one amp is in the list at any time */
+ ProcessorList::iterator check = find (_processors.begin(), _processors.end(), *i);
+ if (check != _processors.end()) {
+ if (before == _amp) {
+ /* Already in position; all is well */
+ continue;
+ } else {
+ _processors.erase (check);
+ }
+ }
+ }
+
+ assert (find (_processors.begin(), _processors.end(), *i) == _processors.end ());
+
_processors.insert (loc, *i);
(*i)->set_owner (this);
- if ((*i)->active()) {
- (*i)->activate ();
- }
-
- /* Think: does this really need to be called for every processor in the loop? */
{
if (configure_processors_unlocked (err, &lm)) {
pstate.restore ();
@@ -1503,7 +1435,17 @@ Route::add_processors (const ProcessorList& others, boost::shared_ptr<Processor>
}
}
+ if ((*i)->active()) {
+ (*i)->activate ();
+ }
+
(*i)->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false));
+
+ boost::shared_ptr<Send> send;
+ if ((send = boost::dynamic_pointer_cast<Send> (*i))) {
+ send->SelfDestruct.connect_same_thread (*this,
+ boost::bind (&Route::processor_selfdestruct, this, boost::weak_ptr<Processor> (*i)));
+ }
}
for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {