Cleanup previous commit.
[ardour.git] / libs / ardour / io_processor.cc
index 7e0d4a771cb04a739040e09d7f2cf6b700d65f25..21a2b10313d4be15afcdf727b0f227669aa90508 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2001 Paul Davis 
+    Copyright (C) 2001 Paul Davis
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -68,14 +68,23 @@ IOProcessor::IOProcessor (Session& s, bool with_input, bool with_output,
 
 /* create an IOProcessor that proxies to an existing IO object */
 
-IOProcessor::IOProcessor (Session& s, boost::shared_ptr<IO> in, boost::shared_ptr<IO> out, 
-                         const string& proc_name, DataType dtype)
+IOProcessor::IOProcessor (Session& s, boost::shared_ptr<IO> in, boost::shared_ptr<IO> out,
+                         const string& proc_name, DataType /*dtype*/)
        : Processor(s, proc_name)
        , _input (in)
        , _output (out)
 {
-       _own_input = false;
-       _own_output = false;
+       if (in) {
+               _own_input = false;
+       } else {
+               _own_input = true;
+       }
+
+       if (out) {
+               _own_output = false;
+       } else {
+               _own_output = true;
+       }
 }
 
 IOProcessor::~IOProcessor ()
@@ -105,24 +114,28 @@ XMLNode&
 IOProcessor::state (bool full_state)
 {
        XMLNode& node (Processor::state (full_state));
-       
+
        if (_own_input) {
-               XMLNode& i (_input->state (full_state));
-               // i.name() = X_("output");
-               node.add_child_nocopy (i);
                node.add_property ("own-input", "yes");
+               if (_input) {
+                       XMLNode& i (_input->state (full_state));
+                       // i.name() = X_("output");
+                       node.add_child_nocopy (i);
+               }
        } else {
                node.add_property ("own-input", "no");
                if (_input) {
                        node.add_property ("input", _input->name());
                }
        }
-       
+
        if (_own_output) {
-               XMLNode& o (_output->state (full_state));
-               // o.name() = X_("output");
-               node.add_child_nocopy (o);
                node.add_property ("own-output", "yes");
+               if (_output) {
+                       XMLNode& o (_output->state (full_state));
+                       // o.name() = X_("output");
+                       node.add_child_nocopy (o);
+               }
        } else {
                node.add_property ("own-output", "no");
                if (_output) {
@@ -134,28 +147,26 @@ IOProcessor::state (bool full_state)
 }
 
 int
-IOProcessor::set_state (const XMLNode& node)
+IOProcessor::set_state (const XMLNode& node, int version)
 {
        const XMLProperty *prop;
        const XMLNode *io_node = 0;
 
-       Processor::set_state(node);
+       Processor::set_state(node, version);
 
        if ((prop = node.property ("own-input")) != 0) {
-               _own_input = (prop->value() == "yes");
+               _own_input = string_is_affirmative (prop->value());
        }
 
        if ((prop = node.property ("own-output")) != 0) {
-               _own_output = (prop->value() == "yes");
+               _own_output = string_is_affirmative (prop->value());
        }
 
-       cerr << _name << " own input = " << _own_input << " output = " << _own_output << endl;
-       
        /* don't attempt to set state for a proxied IO that we don't own */
 
        XMLNodeList nlist = node.children();
        XMLNodeIterator niter;
-       
+
        if (_own_input) {
                for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
                        if ((*niter)->name() == "input") {
@@ -163,21 +174,21 @@ IOProcessor::set_state (const XMLNode& node)
                                break;
                        }
                }
-               
+
                if (io_node) {
-                       _input->set_state(*io_node);
-                       
+                       _input->set_state(*io_node, version);
+
                        // legacy sessions: use IO name
                        if ((prop = node.property ("name")) == 0) {
                                set_name (_input->name());
                        }
-                       
+
                } else {
-                       error << _("XML node describing an IOProcessor is missing an IO node") << endmsg;
-                       return -1;
+                       /* no input */
                }
+
        }
-       
+
        if (_own_output) {
                for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
                        if ((*niter)->name() == "output") {
@@ -185,15 +196,17 @@ IOProcessor::set_state (const XMLNode& node)
                                break;
                        }
                }
-               
+
                if (io_node) {
-                       _output->set_state(*io_node);
-                       
+                       _output->set_state(*io_node, version);
+
                        // legacy sessions: use IO name
                        if ((prop = node.property ("name")) == 0) {
                                set_name (_output->name());
                        }
-               } 
+               } else {
+                       /* no output */
+               }
        }
 
        return 0;
@@ -207,18 +220,6 @@ IOProcessor::silence (nframes_t nframes)
        }
 }
 
-ChanCount
-IOProcessor::output_streams() const
-{
-       return _output ? _output->n_ports() : ChanCount::ZERO;
-}
-
-ChanCount
-IOProcessor::input_streams () const
-{
-       return _input ? _input->n_ports() : ChanCount::ZERO;
-}
-
 ChanCount
 IOProcessor::natural_output_streams() const
 {
@@ -246,3 +247,21 @@ IOProcessor::set_name (const std::string& name)
 
        return ret;
 }
+
+bool
+IOProcessor::feeds (boost::shared_ptr<Route> other) const
+{
+       return _output && _output->connected_to (other->input());
+}
+
+void
+IOProcessor::disconnect ()
+{
+       if (_input) {
+               _input->disconnect (this);
+       }
+
+       if (_output) {
+               _output->disconnect (this);
+       }
+}