Skip to content

Commit

Permalink
When refreshing MIDI ports, explicitly release existing ports
Browse files Browse the repository at this point in the history
On ALSA Linux, node-midi input and output objects hold onto resources that
eventually may run out causing the process to terminate. This change to
Flocking makes use of a work around added to a fork of node-midi which
adds a new explicit "release()" method to free the underlying RtMidi (and
corresponding ALSA) resources.

See: justinlatimer/node-midi#118
  • Loading branch information
simonbates committed Nov 18, 2016
1 parent 8f3674c commit 78a81eb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
"optionalDependencies": {
"speaker": "colinbdclark/node-speaker#mpg123-lower-latency",
"midi": "0.9.5"
"midi": "simonbates/node-midi#f00909dc1ba82e33fd86d5e52ebd092cab866744"
},
"engines": {
"node": ">=0.10.x"
Expand Down
11 changes: 11 additions & 0 deletions src/web/midi.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,17 @@ var fluid = fluid || require("infusion"),
};

flock.midi.system.refreshPorts = function (that, access, onPortsAvailable) {
// Delete existing RtMidiIn/RtMidiOut instances before refreshing
// to avoid running out of ALSA resources
// See https://github.com/justinlatimer/node-midi/issues/118
fluid.each(that.ports, function (portList) {
fluid.each(portList, function (port) {
if (port.midi && port.midi.release) {
port.midi.release();
}
});
});

that.ports = flock.midi.getPorts(access);
onPortsAvailable(that.ports);
};
Expand Down

0 comments on commit 78a81eb

Please sign in to comment.