Context aware MIDI event printing #68820
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What this adds
Adds Human readable MIDI event context aware printing, typical use case in GDScript:
print(midi_event)
output for note-on message:
InputEventMIDI - Note On: channel=0, pitch=1, velocity=127
I also added missing
instrument
printing. However keep in mind outputting a valid program-change is a multi-step process.Whats the current problem
Currently printing a MIDI event results in all InputMIDIEvent variables being listed:
InputEventMIDI: channel=0, message=9, pitch=1, velocity=127, pressure=0, controller_number=0, controller_value=0
However, the problem is that each MIDI event only contains specific variables. There is no controller_number in a MIDI-Note-On message.
This makes it confusing to understand the MIDI events, and clutters the output console. We are also listing the MIDI message raw number, as opposed to the enum, which is already present in Godot.
Discussion
I have chosen to omit the
message=
as we now know what the message is, and Godot already has helpful enums to deal with messages anyway:if event.message == MIDI_MESSAGE_NOTE_ON
etc.Improvement in the future can occur with SYSEX printing added, along with other event types. However this PR provides the vast majority of use cases.
NOTE: Many MIDI devices use NOTE-ON with velocity 0 to signify NOTE-OFF. As Godot's MIDI system is intended to allow developers to use MIDI in their own software we shouldn't deal with this. Rather provide the data as it comes from the MIDI input, and allow the end developer to deal with it how they choose.
MIDI events printed in this PR:
NOTE_ON
NOTE_OFF
PITCH_BEND
CHANNEL_PRESSURE
CONTROL_CHANGE
For all other message types this PR defaults to the old way of displaying MIDI events. This can be the topic of future PRs.
NOTE: Pitch Bend event is currently being saved in pitch, whereas it should be saved into it's own variable: pitch_bend for consistency. This will break current API, so will be subject to another PR for 4.x
See godotengine/godot-proposals#5805 for more info