Last active
August 29, 2015 14:00
-
-
Save geta6/11200195 to your computer and use it in GitHub Desktop.
for NSX-39
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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