summaryrefslogtreecommitdiffstats
path: root/src/engine/JackMidiDriver.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2008-12-20 20:28:04 +0000
committerDavid Robillard <d@drobilla.net>2008-12-20 20:28:04 +0000
commit76f6fcfad68d88728bb1a04b193029aa9e46e976 (patch)
tree271ca830393f9b6dc5241b1ff152905902aaeced /src/engine/JackMidiDriver.cpp
parent72c6d069df26396436c653532702a4f96f901fba (diff)
downloadingen-76f6fcfad68d88728bb1a04b193029aa9e46e976.tar.gz
ingen-76f6fcfad68d88728bb1a04b193029aa9e46e976.tar.bz2
ingen-76f6fcfad68d88728bb1a04b193029aa9e46e976.zip
Fix deregistration of Jack ports, associated memory leaks. Hopefully a fix for #294 and #305).
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@1877 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/engine/JackMidiDriver.cpp')
-rw-r--r--src/engine/JackMidiDriver.cpp55
1 files changed, 26 insertions, 29 deletions
diff --git a/src/engine/JackMidiDriver.cpp b/src/engine/JackMidiDriver.cpp
index d95f30ff..9f2f25d5 100644
--- a/src/engine/JackMidiDriver.cpp
+++ b/src/engine/JackMidiDriver.cpp
@@ -63,7 +63,18 @@ JackMidiPort::JackMidiPort(JackMidiDriver* driver, DuplexPort* patch_port)
JackMidiPort::~JackMidiPort()
{
- jack_port_unregister(_driver->jack_client(), _jack_port);
+ assert(_jack_port == NULL);
+}
+
+
+void
+JackMidiPort::unregister()
+{
+ assert(_jack_port);
+ if (jack_port_unregister(_driver->jack_client(), _jack_port))
+ cerr << "[JackMidiPort] ERROR: Unable to unregister port" << endl;
+
+ _jack_port = NULL;
}
@@ -187,8 +198,9 @@ JackMidiDriver::deactivate()
void
JackMidiDriver::pre_process(ProcessContext& context)
{
- for (Raul::List<JackMidiPort*>::iterator i = _in_ports.begin(); i != _in_ports.end(); ++i)
- (*i)->pre_process(context);
+ for (Raul::List<JackMidiPort*>::iterator i = _ports.begin(); i != _ports.end(); ++i)
+ if ((*i)->is_input())
+ (*i)->pre_process(context);
}
@@ -197,8 +209,9 @@ JackMidiDriver::pre_process(ProcessContext& context)
void
JackMidiDriver::post_process(ProcessContext& context)
{
- for (Raul::List<JackMidiPort*>::iterator i = _out_ports.begin(); i != _out_ports.end(); ++i)
- (*i)->post_process(context);
+ for (Raul::List<JackMidiPort*>::iterator i = _ports.begin(); i != _ports.end(); ++i)
+ if (!(*i)->is_input())
+ (*i)->post_process(context);
}
@@ -214,15 +227,11 @@ JackMidiDriver::add_port(DriverPort* port)
{
assert(ThreadManager::current_thread_id() == THREAD_PROCESS);
assert(dynamic_cast<JackMidiPort*>(port));
-
- if (port->is_input())
- _in_ports.push_back((JackMidiPort*)port);
- else
- _out_ports.push_back((JackMidiPort*)port);
+ _ports.push_back((JackMidiPort*)port);
}
-/** Remove an Jack MIDI port.
+/** Remove a Jack MIDI port.
*
* Realtime safe. This is to be called at the beginning of a process cycle to
* remove the port from the lists read by the audio thread, so the port
@@ -230,22 +239,16 @@ JackMidiDriver::add_port(DriverPort* port)
*
* It is the callers responsibility to delete the returned port.
*/
-DriverPort*
+Raul::List<DriverPort*>::Node*
JackMidiDriver::remove_port(const Path& path)
{
assert(ThreadManager::current_thread_id() == THREAD_PROCESS);
- // FIXME: duplex?
-
- for (Raul::List<JackMidiPort*>::iterator i = _in_ports.begin(); i != _in_ports.end(); ++i)
+ for (Raul::List<JackMidiPort*>::iterator i = _ports.begin(); i != _ports.end(); ++i)
if ((*i)->patch_port()->path() == path)
- return _in_ports.erase(i)->elem(); // FIXME: LEAK
-
- for (Raul::List<JackMidiPort*>::iterator i = _out_ports.begin(); i != _out_ports.end(); ++i)
- if ((*i)->patch_port()->path() == path)
- return _out_ports.erase(i)->elem(); // FIXME: LEAK
-
- cerr << "[JackMidiDriver::remove_input] WARNING: Unable to find Jack port " << path << endl;
+ return (Raul::List<DriverPort*>::Node*)_ports.erase(i);
+
+ cerr << "[JackMidiDriver::remove_port] WARNING: Unable to find port " << path << endl;
return NULL;
}
@@ -255,13 +258,7 @@ JackMidiDriver::driver_port(const Path& path)
{
assert(ThreadManager::current_thread_id() == THREAD_PROCESS);
- // FIXME: duplex?
-
- for (Raul::List<JackMidiPort*>::iterator i = _in_ports.begin(); i != _in_ports.end(); ++i)
- if ((*i)->patch_port()->path() == path)
- return (*i);
-
- for (Raul::List<JackMidiPort*>::iterator i = _out_ports.begin(); i != _out_ports.end(); ++i)
+ for (Raul::List<JackMidiPort*>::iterator i = _ports.begin(); i != _ports.end(); ++i)
if ((*i)->patch_port()->path() == path)
return (*i);