2016-12-01 21 views
1

Web MIDI APIを使用してメッセージのMIDI入力を待ち受けているとしたら、データを理解して利用しようとしています受信する。Web MIDI APIの入力メッセージ(onmidimessage)を解析する方法

MIDIMessageEventの基本情報を解析するにはどうすればよいですか?

  • コマンド
  • チャネル
  • ノート
  • 速度

どのように私はいくつかの基本的なMIDIイベントのために解析された情報を解釈するのでしょうか?

  • はonNote
  • onPad
  • onPitchBend
  • onModWheel

答えて

3

解析と解釈したWeb MIDI API入力メッセージデータ

ES6で書かれた例。

MIDIMessageEventdataは、このようなの解析機能に分割することができます。

/** 
* 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メッセージを解釈することがあります上記イベント関数のとコール:

​​

資源:

    ハンドラが正しいMIDI入力(複数可)にが取り付けられ

    /** 
    * 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) 
        } 
    } 
    

  • ​​
  • MIDI message data summary
  • Script by cwilso
  • Script by cotejp
関連する問題