Last active
August 29, 2015 14:05
-
-
Save niusounds/476921c2880e7d93ca89 to your computer and use it in GitHub Desktop.
JavaのMidiChannelを参考にしたWebMIDIのラッパー
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
function MidiChannel(midiOutput, channel) { | |
this.output = midiOutput; | |
this.channel = channel; | |
} | |
MidiChannel.prototype = { | |
/* | |
* Channel voice messages | |
*/ | |
noteOff: function(noteNumber, velocity, timestamp) { | |
this.output.send([0x80 | this.channel, noteNumber, velocity], timestamp); | |
}, | |
noteOn: function(noteNumber, velocity, timestamp) { | |
this.output.send([0x90 | this.channel, noteNumber, velocity], timestamp); | |
}, | |
polyPressure: function(noteNumber, pressure, timestamp) { | |
this.output.send([0xA0 | this.channel, noteNumber, pressure], timestamp) | |
}, | |
controlChange: function(controller, value, timestamp) { | |
this.output.send([0xB0 | this.channel, controller, value], timestamp) | |
}, | |
programChange: function(program, timestamp) { | |
this.output.send([0xC0 | this.channel, program], timestamp) | |
}, | |
channelPressure: function(pressure, timestamp) { | |
this.output.send([0xD0 | this.channel, pressure], timestamp) | |
}, | |
pitchBend: function(bend, timestamp) { | |
this.output.send([0xE0 | this.channel, bend & 0x7F, bend >> 7 & 0x7F], timestamp); | |
}, | |
/* | |
* Channel mode messages | |
*/ | |
allSoundOff: function(timestamp) { | |
this.output.send([0xB0 | this.channel, 0x78, 0x00], timestamp) | |
}, | |
resetAllController: function(timestamp) { | |
this.output.send([0xB0 | this.channel, 0x79, 0x00], timestamp) | |
}, | |
localControl: function(on, timestamp) { | |
this.output.send([0xB0 | this.channel, 0x7A, on ? 0x7F : 0x00], timestamp) | |
}, | |
allNotesOff: function(timestamp) { | |
this.output.send([0xB0 | this.channel, 0x7B, 0x00], timestamp) | |
}, | |
omni: function(on, timestamp) { | |
this.output.send([0xB0 | this.channel, on ? 0x7C : 0x7D, 0x00], timestamp) | |
}, | |
poly: function(on, timestamp) { | |
this.output.send([0xB0 | this.channel, on ? 0x7E : 0x7F, 0x00], timestamp) | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment