From a7dc433498d712b908c429761a4c3f9ea24ce440 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 26 Sep 2011 20:35:16 +0000 Subject: [PATCH] Delete MIDI port objects when the MackieControlProtocol is torn down, so that it can be recreated without attempting to create duplicate JACK port names. Should fix #3886. git-svn-id: svn://localhost/ardour2/branches/3.0@10129 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/midi++2/manager.cc | 10 ++++++++++ libs/midi++2/midi++/manager.h | 1 + libs/surfaces/mackie/surface_port.cc | 22 ++++++++++++++++++++-- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/libs/midi++2/manager.cc b/libs/midi++2/manager.cc index 8aa89c7a99..b411a1ddad 100644 --- a/libs/midi++2/manager.cc +++ b/libs/midi++2/manager.cc @@ -76,6 +76,16 @@ Manager::add_port (Port* p) return p; } +void +Manager::remove_port (Port* p) +{ + RCUWriter writer (_ports); + boost::shared_ptr pw = writer.get_copy (); + pw->remove (p); + + PortsChanged (); /* EMIT SIGNAL */ +} + void Manager::cycle_start (pframes_t nframes) { diff --git a/libs/midi++2/midi++/manager.h b/libs/midi++2/midi++/manager.h index 75b0cb4864..ecfd7a0111 100644 --- a/libs/midi++2/midi++/manager.h +++ b/libs/midi++2/midi++/manager.h @@ -59,6 +59,7 @@ class Manager { Port *midi_clock_output_port() const { return _midi_clock_output_port; } Port* add_port (Port *); + void remove_port (Port *); Port* port (std::string const &); diff --git a/libs/surfaces/mackie/surface_port.cc b/libs/surfaces/mackie/surface_port.cc index 3e10fa7b36..031009cd3d 100644 --- a/libs/surfaces/mackie/surface_port.cc +++ b/libs/surfaces/mackie/surface_port.cc @@ -20,8 +20,9 @@ #include "mackie_control_exception.h" #include "controls.h" -#include -#include +#include "midi++/types.h" +#include "midi++/port.h" +#include "midi++/manager.h" #include #include @@ -40,6 +41,10 @@ SurfacePort::SurfacePort() { } +/** @param input_port Input MIDI::Port; this object takes responsibility for removing it from + * the MIDI::Manager and destroying it. + * @param output_port Output MIDI::Port; responsibility similarly taken. + */ SurfacePort::SurfacePort (MIDI::Port & input_port, MIDI::Port & output_port, int number) : _input_port (&input_port), _output_port (&output_port), _number (number), _active (false) { @@ -53,6 +58,19 @@ SurfacePort::~SurfacePort() // make sure another thread isn't reading or writing as we close the port Glib::RecMutex::Lock lock( _rwlock ); _active = false; + + MIDI::Manager* mm = MIDI::Manager::instance (); + + if (_input_port) { + mm->remove_port (_input_port); + delete _input_port; + } + + if (_output_port) { + mm->remove_port (_output_port); + delete _output_port; + } + #ifdef PORT_DEBUG cout << "~SurfacePort::SurfacePort() finished" << endl; #endif