MIDI メッセージを受け取った時の処理を付与する
MidiInputDevices.forEach(o => (o.onmidimessage = getMIDIMessage(synth)))import Synth from '/src/Synth'
import createAudioContext from '/src/WebAudioAPI/createAudioContext'
import getMIDIInputDevices from '/src/MIDI/getMIDIInputDevices'
import getMIDIMessage from '/src/MIDI/getMIDIMessage'
const audioContext = createAudioContext()
const destination = audioContext.destination
// synth インスタンスを作成
const synth = new Synth({
audioContext,
nextNode: destination,
})
// MIDI device にアクセスして、
// MIDI message を受け取った際に起動させるハンドラを登録する
const start = async () => {
// MIDI デバイスを取得する
const MidiInputDevices = await getMIDIInputDevices()
console.log({ MidiInputDevices })
if (MidiInputDevices) {
// 全ての MIDI デバイスへ
// MIDI メッセージを受け取った際に起動するハンドラを付与する
// getMIDIMessage がハンドラ
// ハンドラで使用する synth インスタンスを渡す
MidiInputDevices.forEach(o => (o.onmidimessage = getMIDIMessage(synth)))
}
}
start()
getMIDIMessage を作る
message で分岐する処理
Last updated