npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

generic-midi-controller

v1.0.3

Published

A common interface for handling different MIDI controller input/output devices

Readme

generic-midi-controller

A common interface for handling different MIDI controller input/output devices using the Web MIDI API.

Usage

NPM

controller = GenericMIDI(input, output)

Creates a Controller instance. Input/output handling is customizable using the input and output functions:

input

An object where each property contains an array of functions for determining updated values on receiving MIDI input messages. Optional.

const controller = GenericMIDI({
  buttons: [
    msg => msg[1] === 72 ? msg[2] : null,
    msg => msg[1] === 73 ? msg[2] : null,
    msg => msg[1] === 74 ? msg[2] : null,
    msg => msg[1] === 75 ? msg[2] : null
  ]
})

The above controller listens to events for value changes on inputs 72 through 75. Note that null is returned when a value should not be updated.

Once set up as such, the following should be possible:

controller.setInput(midiInput)

// ...after receiving some MIDI messages:
controller.inputs.buttons[0] // 127
controller.inputs.buttons[1] // 24
controller.inputs.buttons[2] // 0
controller.inputs.buttons[3] // 38

output

An object where each property contains an array of functions for triggering output MIDI messages using send. Optional.

const controller = GenericMIDI(null, {
  buttons: [
    (value, send) => send([152, 72, value]),
    (value, send) => send([152, 73, value]),
    (value, send) => send([152, 74, value]),
    (value, send) => send([152, 75, value])
  ]
})

Once set up as such, the following should be possible:

controller.setOutput(midiOutput)

controller.outputs.buttons[0] = 127 // sends "127" to button 0
controller.outputs.buttons[1] = 24  // sends "24" to button 1
controller.outputs.buttons[2] = 0   // sends "0" to button 2
controller.outputs.buttons[3] = 38  // sends "38" to button 3

controller.setInput(input)

Sets the input MIDI device.

controller.setOutput(output)

Sets the output MIDI device.

navigator.requestMIDIAccess({
  sysex: true
}).then(function (midi) {
  var outputs = []
  var inputs = []

  for (var input of midi.inputs.values()) {
    inputs.push(input)
  }
  for (var output of midi.outputs.values()) {
    outputs.push(output)
  }

  controller.setInput(inputs[0])
  controller.setOutput(outputs[0])
})

controller.on('input', fn(group, i, value))

Fired whenever an input message is received and handled:

controller.on('input', (group, id, value) => {
  console.log(`${group} #${id} has been set to ${value}`)
})

controller.on('output', fn(group, i, value))

Fired whenever an output update is triggered:

controller.on('input', (group, id, value) => {
  console.log(`${group} #${id} has been set to ${value}`)
})

See Also

License

MIT. See LICENSE.md for details.