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

Detecting chords using WebMIDI #25

Closed antonioaguilar closed 6 years ago

antonioaguilar commented 6 years ago

I have a general question. How would you detect a chord using WebMIDI? From what I read in the API docs, you can use the noteon for single note/key events. If I want to detect a chord event, say when 3 or more notes are played together. Do I have to detect separate events for each note? Any suggestions?

djipco commented 6 years ago

There is nothing in the library to let you do that automatically. You would have to listen for noteon events triggered within a certain time frame. Or, you could also save the state of all notes in your app. This way, when a noteon is triggered you could check if other notes are currently played.