X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=libs%2Fsurfaces%2Fmackie%2Fsurface_port.cc;h=013a0019c7e797ef9982df56412a07cd8a7fbc94;hb=316973d7c7bc99bfef6367d42009883d0de2abbd;hp=6583f3307fe127b0fcefdfbf1504b8926fe780f6;hpb=d074bc586e494d7dd83d415a487195a477095a4f;p=ardour.git diff --git a/libs/surfaces/mackie/surface_port.cc b/libs/surfaces/mackie/surface_port.cc index 6583f3307f..013a0019c7 100644 --- a/libs/surfaces/mackie/surface_port.cc +++ b/libs/surfaces/mackie/surface_port.cc @@ -23,6 +23,8 @@ #include #include +#include "pbd/failed_constructor.h" + #include "midi++/types.h" #include "midi++/ipmidi_port.h" @@ -52,10 +54,16 @@ SurfacePort::SurfacePort (Surface& s) if (_surface->mcp().device_info().uses_ipmidi()) { _input_port = new MIDI::IPMIDIPort (_surface->mcp().ipmidi_base() +_surface->number()); _output_port = _input_port; + } else { + _async_in = AudioEngine::instance()->register_input_port (DataType::MIDI, string_compose (_("%1 in"), _surface->name()), true); _async_out = AudioEngine::instance()->register_output_port (DataType::MIDI, string_compose (_("%1 out"), _surface->name()), true); + if (_async_in == 0 || _async_out == 0) { + throw failed_constructor(); + } + _input_port = boost::dynamic_pointer_cast(_async_in).get(); _output_port = boost::dynamic_pointer_cast(_async_out).get(); } @@ -63,21 +71,71 @@ SurfacePort::SurfacePort (Surface& s) SurfacePort::~SurfacePort() { - if (_surface->mcp().device_info().uses_ipmidi()) { + if (dynamic_cast(_input_port)) { delete _input_port; } else { if (_async_in) { AudioEngine::instance()->unregister_port (_async_in); - _async_in.reset (); + _async_in.reset ((ARDOUR::Port*) 0); } if (_async_out) { _output_port->drain (10000); AudioEngine::instance()->unregister_port (_async_out); - _async_out.reset (); + _async_out.reset ((ARDOUR::Port*) 0); + } + } +} + +XMLNode& +SurfacePort::get_state () +{ + XMLNode* node = new XMLNode (X_("Port")); + + if (dynamic_cast(_input_port)) { + /* no state required for IPMidi ports */ + return *node; + } + + XMLNode* child; + + child = new XMLNode (X_("Input")); + child->add_child_nocopy (_async_in->get_state()); + node->add_child_nocopy (*child); + + + child = new XMLNode (X_("Output")); + child->add_child_nocopy (_async_out->get_state()); + node->add_child_nocopy (*child); + + return *node; +} + +int +SurfacePort::set_state (const XMLNode& node, int version) +{ + if (dynamic_cast(_input_port)) { + return 0; + } + + XMLNode* child; + + if ((child = node.child (X_("Input"))) != 0) { + XMLNode* portnode = child->child (Port::state_node_name.c_str()); + if (portnode) { + _async_in->set_state (*portnode, version); } } + + if ((child = node.child (X_("Output"))) != 0) { + XMLNode* portnode = child->child (Port::state_node_name.c_str()); + if (portnode) { + _async_out->set_state (*portnode, version); + } + } + + return 0; } // wrapper for one day when strerror_r is working properly