+
+
+int
+Route::save_as_template (const string& path, const string& name)
+{
+ XMLNode& node (state (false));
+ XMLTree tree;
+
+ IO::set_name_in_state (*node.children().front(), name);
+
+ tree.set_root (&node);
+ return tree.write (path.c_str());
+}
+
+
+bool
+Route::set_name (const string& str)
+{
+ bool ret;
+ string ioproc_name;
+ string name;
+
+ name = Route::ensure_track_or_route_name (str, _session);
+ SessionObject::set_name (name);
+
+ ret = (_input->set_name(name) && _output->set_name(name));
+
+ if (ret) {
+
+ Glib::RWLock::ReaderLock lm (_processor_lock);
+
+ for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
+
+ /* rename all I/O processors that have inputs or outputs */
+
+ boost::shared_ptr<IOProcessor> iop = boost::dynamic_pointer_cast<IOProcessor> (*i);
+
+ if (iop && (iop->output() || iop->input())) {
+ if (!iop->set_name (name)) {
+ ret = false;
+ }
+ }
+ }
+
+ }
+
+ return ret;
+}
+
+boost::shared_ptr<Send>
+Route::internal_send_for (boost::shared_ptr<const Route> target) const
+{
+ Glib::RWLock::ReaderLock lm (_processor_lock);
+
+ for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) {
+ boost::shared_ptr<InternalSend> send;
+
+ if ((send = boost::dynamic_pointer_cast<InternalSend>(*i)) != 0) {
+ if (send->target_route() == target) {
+ return send;
+ }
+ }
+ }
+
+ return boost::shared_ptr<Send>();
+}
+
+void
+Route::set_phase_invert (bool yn)
+{
+ if (_phase_invert != yn) {
+ _phase_invert = 0xffff; // XXX all channels
+ phase_invert_changed (); /* EMIT SIGNAL */
+ }
+}
+
+bool
+Route::phase_invert () const
+{
+ return _phase_invert != 0;
+}
+
+void
+Route::set_denormal_protection (bool yn)
+{
+ if (_denormal_protection != yn) {
+ _denormal_protection = yn;
+ denormal_protection_changed (); /* EMIT SIGNAL */
+ }
+}
+
+bool
+Route::denormal_protection () const
+{
+ return _denormal_protection;
+}
+
+void
+Route::set_active (bool yn)
+{
+ if (_active != yn) {
+ _active = yn;
+ _input->set_active (yn);
+ _output->set_active (yn);
+ active_changed (); // EMIT SIGNAL
+ }
+}
+
+void
+Route::meter ()
+{
+ Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
+
+ assert (_meter);
+
+ _meter->meter ();
+
+ for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
+
+ boost::shared_ptr<Send> s;
+ boost::shared_ptr<Return> r;
+
+ if ((s = boost::dynamic_pointer_cast<Send> (*i)) != 0) {
+ s->meter()->meter();
+ } else if ((r = boost::dynamic_pointer_cast<Return> (*i)) != 0) {
+ r->meter()->meter ();
+ }
+ }
+}
+
+boost::shared_ptr<Panner>
+Route::panner() const
+{
+
+ return _main_outs->panner();
+}
+
+boost::shared_ptr<AutomationControl>
+Route::gain_control() const
+{
+
+ return _amp->gain_control();
+}
+
+boost::shared_ptr<AutomationControl>
+Route::get_control (const Evoral::Parameter& param)
+{
+ /* either we own the control or .... */
+
+ boost::shared_ptr<AutomationControl> c = boost::dynamic_pointer_cast<AutomationControl>(data().control (param));
+
+ if (!c) {
+
+ /* maybe one of our processors does or ... */
+
+ Glib::RWLock::ReaderLock rm (_processor_lock, Glib::TRY_LOCK);
+ for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
+ if ((c = boost::dynamic_pointer_cast<AutomationControl>((*i)->data().control (param))) != 0) {
+ break;
+ }
+ }
+ }
+
+ if (!c) {
+
+ /* nobody does so we'll make a new one */
+
+ c = boost::dynamic_pointer_cast<AutomationControl>(control_factory(param));
+ add_control(c);
+ }
+
+ return c;
+}
+
+boost::shared_ptr<Processor>
+Route::nth_plugin (uint32_t n)
+{
+ Glib::RWLock::ReaderLock lm (_processor_lock);
+ ProcessorList::iterator i;
+
+ for (i = _processors.begin(); i != _processors.end(); ++i) {
+ if (boost::dynamic_pointer_cast<PluginInsert> (*i)) {
+ if (n-- == 0) {
+ return *i;
+ }
+ }
+ }
+
+ return boost::shared_ptr<Processor> ();
+}
+
+boost::shared_ptr<Processor>
+Route::nth_send (uint32_t n)
+{
+ Glib::RWLock::ReaderLock lm (_processor_lock);
+ ProcessorList::iterator i;
+
+ for (i = _processors.begin(); i != _processors.end(); ++i) {
+ cerr << "check " << (*i)->name() << endl;
+ if (boost::dynamic_pointer_cast<Send> (*i)) {
+ if (n-- == 0) {
+ return *i;
+ }
+ } else {
+ cerr << "\tnot a send\n";
+ }
+ }
+
+ return boost::shared_ptr<Processor> ();
+}