구문 분석하고 해석 웹 MIDI API 입력 메시지 데이터
ES6 작성 예.
MIDIMessageEvent
의 data
이 같은 분석 기능로 분할 될 수있다 :
/**
* Parse basic information out of a MIDI message.
*/
function parseMidiMessage(message) {
return {
command: message.data[0] >> 4,
channel: message.data[0] & 0xf,
note: message.data[1],
velocity: message.data[2]/127
}
}
취급 기본적인 MIDI 이벤트를 일부 이벤트 함수을 감안할 때 :
function onNote(note, velocity) {}
function onPad(pad, velocity) {}
function onPitchBend(value) {}
function onModWheel(value) {}
우리 위에서 파싱 함수를 사용하여 MIDI 메시지를 통해 해석 할 수 있습니다. 상기 이벤트 기능 및 통화 :
midiInput.onmidimessage = handleMidiMessage
자원 :
핸들러 올바른 MIDI 입력 (S)에 부착 된
/**
* Handle a MIDI message from a MIDI input.
*/
function handleMidiMessage(message) {
// Parse the MIDIMessageEvent.
const {command, channel, note, velocity} = parseMidiMessage(message)
// Stop command.
// Negative velocity is an upward release rather than a downward press.
if (command === 8) {
if (channel === 0) onNote(note, -velocity)
else if (channel === 9) onPad(note, -velocity)
}
// Start command.
else if (command === 9) {
if (channel === 0) onNote(note, velocity)
else if (channel === 9) onPad(note, velocity)
}
// Knob command.
else if (command === 11) {
if (note === 1) onModWheel(velocity)
}
// Pitch bend command.
else if (command === 14) {
onPitchBend(velocity)
}
}
Web MIDI API
MIDI message data summary
Script by cwilso
Script by cotejp