djipco / webmidi

Tame the Web MIDI API. Send and receive MIDI messages with ease. Control instruments with user-friendly functions (playNote, sendPitchBend, etc.). React to MIDI input with simple event listeners (noteon, pitchbend, controlchange, etc.).
Apache License 2.0
1.54k stars 115 forks source link

port information on midi message event data #4

Closed darkomenx closed 8 years ago

darkomenx commented 8 years ago

Hi cotejp,

thank you for your sharing code about Web MIDI API. I don't see (or understand) if your library get the port information on the midi message event ? I would like to know where do the midi message from. If I have 4 midi port activate with eventListener for catch midi message I would like to know (and see in console.log) which device I have send a midi message not just the midi message.

Your libray do that ? If no do you think that is possible dealing with Web MIDI API ?

thank for your advice

djipco commented 8 years ago

It is possible to retrieve information about the Input by looking at the target property of the event object. For example, to get the name of the device that triggered the event, you can use:

WebMidi
    .getInputByName("_some-device_")
    .addListener("noteon", "all", function (e) {
      console.log(e.target.name);
    });