Plans for Next Update/MIDI Fix


Among other updates to the ingame musical instrument, I wanted to talk about the method used for the polyphonic MIDI response, as this can be a tricky thing to figure out without dedicated polyphony handling on the midi side of things -- Godot provides access to an OS's MIDI devices, allowing scripts to make use of values like pitch, velocity, midi channel number, pressure, and some others.. but it doesn't have a built-in function for handling typical options that come up with MIDI inputs, like note priority, retriggering, and polyphonic voice assignment. So I had to make something that worked.


The earlier attempt (as is present in the v0.0.1.5 upload currently playable on here) used a noteCount parameter, which increased and decreased with note on and note off signals respectively by checking velocity values. The amount of held notes was used as the index for each of two arrays, one containing the MIDI pitch of the incoming note (from 1-127) and the other containing the unique integer identifier returned by the play_stream method of the polyphonic audio stream object. Then for notes with velocity = 0, the MIDI pitch value was used to get the integer identifier, which then was used with the stop_stream method to turn off the relevant voice,. This was an imperfect solution, as it could lead to notes being overwritten despite still being held, but it was close enough for the early versions.


Now, however, I think I've figured out a much more robust way to handle this, without any use of a noteCount variable. Instead, it checks through the array of unique integer identifiers and if the stored value is -1, it uses that index to store the incoming pitch and the returned identifier integer. Then when notes are released, it does roughly the same thing except it doesn't have to decrement any variable to keep track of the number of held notes.

In the prior implementation (as in v0.0.1.5), a note pressed before others and held while playing them will remain playing, but if it was pressed and held while other notes were already held and then those other notes were released, then it could be overwritten by subsequent notes if its voice slot was reached. In future updates, however, a note that remains held will keep playing until it is released (or until the player walks away from the keyboard), even if notes in voice slots below it are released and repressed in excess of that note's voice number... (if that makes sense).


Attached is a video of the new/improved behavior, with a view of the console printing the pitch and voice arrays with each MIDI note, and a screenshot of the new code.

Get Stumpville

Leave a comment

Log in with itch.io to leave a comment.