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.52k stars 115 forks source link

Accidental note names returned incorrectly in #351

Closed DataGreed closed 1 year ago

DataGreed commented 1 year ago

Description

  1. Follow the quickstart guide at https://webmidijs.org/docs/
  2. Implement listening to MIDI events like this:
    addListener("noteon", e => {
    document.body.innerHTML+= `${e.note.name} <br>`;
    });
  3. Press F# on keyboard

Expected result

F# will appear on the page

Actual result

F appears on the page.

Environment: Tested on mac in chrome with Korg Nanokey.

Details Same happens with every accidental.

tobyhede commented 1 year ago

This confused me as well. The note has a separate accidental property.

You should be able to use:

addListener("noteon", e => {
    document.body.innerHTML+= `${e.note.name}${e.note.accidental} <br>`;
});

Might be worth adding a property that is the "full name" and includes octave, note and accidental.

djipco commented 1 year ago

As @tobyhede remarked, the name property is only for the letter part. I made it granular so it would be easier to parse (together with octave and accidental). There is no need for a "full name" property because it already exists in the form of the identifier property.

Having said that, to prevent the confusion you experienced, I updated the documentation for the Note.name property to make it clearer that it only returns the letter (it should show up on the website soon).

Hope this helps!

DataGreed commented 1 year ago

Thanks!