Skip to content

Instantly share code, notes, and snippets.

@geta6
Last active August 29, 2015 14:00
Show Gist options
  • Save geta6/11200195 to your computer and use it in GitHub Desktop.
Save geta6/11200195 to your computer and use it in GitHub Desktop.
for NSX-39
class NSX39
midi = require 'midi'
buffer =
key: 0
vel: 0
device: new midi.output()
constructor: (pattern = /NSX-39/gi)->
for i in [[email protected]()]
if pattern.test @device.getPortName i
return @device.openPort i
throw new Error 'NSX-39 not found.'
note: (start, key, vel, gm = no) ->
if start
@device.sendMessage [
(if gm then 0x91 else 0x90)
(buffer.key = key)
(buffer.vel = vel)
]
else
@device.sendMessage [
0x80
buffer.key
buffer.vel
]
talk: (byte) ->
@device.sendMessage [
0xF0
0x43
0x79
0x09
0x11
0x0A
0x00
byte
0xF7
]
nsx = new NSX39()
nsx.note on, 80, 100 # key, velocity
nsx.talk 0x00 # 巻末参照
setTimeout ->
nsx.note off
, 1000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment