JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 14
  • Score
    100M100P100Q56128F
  • License ISC

Duplex stream wrapper around 'midi' module

Package Exports

  • midi-stream

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (midi-stream) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

midi-stream

Duplex stream wrapper around midi module.

When required from the browser (using browserify) web-midi is returned instead.

Install

$ npm install midi-stream

Example

var MidiStream = require('midi-stream')

var duplex = MidiStream('Launchpad', 0)

// clear lights
duplex.write([176, 0, 0])

// echo back the message to launchpad
duplex.pipe(duplex) 

// write buttons pressed to console
duplex.on('data', function(data){
  console.log(data)
})

// paint a face after 10 seconds :)
var faceCoords = [
  [1,1], [2,1], [5,1], [6,1],
  [1,2], [2,2], [5,2], [6,2],
  [2,4], [5,4],
  [2,5], [3,5], [4,5], [5,5]
]

setTimeout(function(){
  faceCoords.forEach(function(xy){
    var id = xy[1] * 16 + xy[0] // convert coords to midi note
    duplex.write([144, id, 60])
  })
}, 10000)

// wait 20 seconds then close the port
setTimeout(function(){
  duplex.end()
}, 20000)


///// bonus round, second launchpad! ////
var bonus = MidiStream('Launchpad', 1)
faceCoords.forEach(function(xy){
  var id = xy[1] * 16 + xy[0] // convert coords to midi note
  bonus.write([144, id, 60])
})