fix: check that MIDI triggered instrument is within patch limits (#98)

This commit is contained in:
2023-08-27 11:10:54 +03:00
parent 33221b5203
commit a0bcac3904
+3
View File
@@ -328,6 +328,9 @@ func (p *Player) trySend(message interface{}) {
func (p *Player) triggerInstrument(instrument int, note byte) {
ID := idForInstrumentNote(instrument, note)
p.release(ID)
if p.patch == nil || instrument < 0 || instrument >= len(p.patch) {
return
}
voiceStart := p.patch.FirstVoiceForInstrument(instrument)
voiceEnd := voiceStart + p.patch[instrument].NumVoices
p.trigger(voiceStart, voiceEnd, note, ID)