Skip to content

Instantly share code, notes, and snippets.

@Lokua
Created March 18, 2018 05:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lokua/327ad141e69d9710293f855b88ce6399 to your computer and use it in GitHub Desktop.
Save Lokua/327ad141e69d9710293f855b88ce6399 to your computer and use it in GitHub Desktop.
export function listNodeMidiPorts(portType) {
const io = new require('midi')[portType]()
return Array(io.getPortCount())
.fill(null)
.map((_, index) => io.getPortName(index))
}
export function getNodeMidiPortNumberByName(portType, name) {
const io = new require('midi')[portType]()
const matches = str =>
name instanceof RegExp ? name.test(str) : str === name
for (let i = 0; i < io.getPortCount(); i++) {
if (matches(io.getPortName(i))) {
return i
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment