MidiPlayer not playing certain notes when loading a drum track

Issue #62 resolved
Pooh C. created an issue

The kick, snare, and certain other sounds would not play when loading a midi file with a drum track.

Reproduction

  1. Insert a MidiPlayer node
  2. Add a drum MIDI file as the midi file (tested on files from this site)
  3. Play the MIDI

Possible Solution

Upon checking the source code, I’ve found that the culprit are these lines in MidiPlayer.gd’s _process_track_event_note_on method:

# Line 705
    var polyphony_count:int = 0
    for instrument in instruments:
        if instrument.vel_range_min <= key_number and key_number <= instrument.vel_range_max:
            polyphony_count += 1

    for instrument in instruments:
        if instrument.vel_range_min <= key_number and key_number <= instrument.vel_range_max:
            var note_player:AudioStreamPlayerADSR = self._get_idle_player( )

I’m not sure how the velocity range is being set, but for the kick, snare, and other tracks they end up being 101 for some reason, making the second if condition fail and the note not playing.

I’m not aware of how the entire system works, but I think key_number shouldn’t probably be checked against vel_range_min and vel_range_max, which I assume refer to the velocity and not the number. I’ve changed key_number in the conditions to velocity and the sound plays fine now, but I’m not sure if there would be issues elsewhere.

Comments (5)

  1. Pooh C. reporter

    Thanks! Really great addon btw, I’ve been using it for a rhythm game and it’s very flexible.

  2. Log in to comment