X-Git-Url: https://main.carlh.net/gitweb/?p=ardour.git;a=blobdiff_plain;f=libs%2Fardour%2Froute.cc;h=30e901cfba5900b54e8b3689f49576bbb89cf4d1;hp=74b3a87fcf96985adacca1b9981f8236f1cac14e;hb=e41d4e82480d993778a162cb9a76d2b41cbfc549;hpb=9d5738dc55b80d394f197318141ff6448c8bdd18 diff --git a/libs/ardour/route.cc b/libs/ardour/route.cc index 74b3a87fcf..30e901cfba 100644 --- a/libs/ardour/route.cc +++ b/libs/ardour/route.cc @@ -1813,6 +1813,92 @@ Route::remove_processor (boost::shared_ptr processor, ProcessorStream return 0; } +int +Route::replace_processor (boost::shared_ptr old, boost::shared_ptr sub, ProcessorStreams* err) +{ + /* these can never be removed */ + if (old == _amp || old == _meter || old == _main_outs || old == _delayline || old == _trim) { + return 1; + } + /* and can't be used as substitute, either */ + if (sub == _amp || sub == _meter || sub == _main_outs || sub == _delayline || sub == _trim) { + return 1; + } + + /* I/Os are out, too */ + if (boost::dynamic_pointer_cast (old) || boost::dynamic_pointer_cast (sub)) { + return 1; + } + + /* this function cannot be used to swap/reorder processors */ + if (find (_processors.begin(), _processors.end(), sub) != _processors.end ()) { + return 1; + } + + if (!AudioEngine::instance()->connected() || !old || !sub) { + return 1; + } + + { + Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ()); + Glib::Threads::RWLock::WriterLock lm (_processor_lock); + ProcessorState pstate (this); + + assert (find (_processors.begin(), _processors.end(), sub) == _processors.end ()); + + ProcessorList::iterator i; + bool replaced = false; + bool enable = old->active (); + + for (i = _processors.begin(); i != _processors.end(); ) { + if (*i == old) { + i = _processors.erase (i); + _processors.insert (i, sub); + sub->set_owner (this); + replaced = true; + break; + } else { + ++i; + } + } + + if (!replaced) { + return 1; + } + + if (configure_processors_unlocked (err)) { + pstate.restore (); + configure_processors_unlocked (0); + return -1; + } + + _have_internal_generator = false; + + for (i = _processors.begin(); i != _processors.end(); ++i) { + boost::shared_ptr pi; + if ((pi = boost::dynamic_pointer_cast(*i)) != 0) { + if (pi->has_no_inputs ()) { + _have_internal_generator = true; + break; + } + } + } + + if (enable) { + sub->activate (); + } + + sub->ActiveChanged.connect_same_thread (*this, boost::bind (&Session::update_latency_compensation, &_session, false)); + _output->set_user_latency (0); + } + + reset_instrument_info (); + old->drop_references (); + processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */ + set_processor_positions (); + return 0; +} + int Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* err) {