mph

midi-port-holder

Bind to midi port by name and expose switchable duplex stream.

Showing:

Popularity

Downloads/wk

10

GitHub Stars

2

Maintenance

Last Commit

6yrs ago

Contributors

0

Package

Dependencies

6

Size (min+gzip)

3.1KB

License

ISC

Type Definitions

Tree-Shakeable

No?

Categories

Readme

midi-port-holder

Bind to midi port by name and expose switchable duplex stream.

When running in Node, uses midi-stream and when running in browser (via browserify) uses web-midi.

Follows the observ pattern.

Install via npm

$ npm install midi-port-holder

API

var PortHolder = require('midi-port-holder')

var portHolder = PortHolder(options)

options

  • global: bypass grab stack, just listen all the time until close

Returns an extended observ instance.

portHolder.set(portName)

Switch portHolder.stream to observe chosen portName

portHolder()

Returns the name of the current port.

portHolder(func(val))

func is called with the new portName any time it is changed.

portHolder.stream

A duplex stream that is connected to the midi port specified by set. If the specified port doesn't exist, written data is thrown away.

Emits 'switch' whenever the port is changed, and also 'connect' if the port exists.

portHolder.destroy

Disconnect from current midi port.

Computed Port Names helper

var computedPortNames = require('midi-port-holder/computed-port-names')
var watch = require('observ/watch')
watch(computedPortNames, function(names){
  console.log(names)
})

Example

var PortHolder = require('midi-port-holder')
var portHolder = PortHolder()
var duplexStream = portHolder.stream

duplexStream.on('switch', function(){
  duplexStream.write([176,0,0]) // turn off all lights on switch
})

portHolder.set('Launchpad Mini')
duplexStream.write([144,0,127]) // turn on light at [0,0]

portHolder.set('Launchpad Mini 2') // this will trigger 'switch' event on stream



Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100