Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.0, MIDI input: releasing key on MIDI device returns event.message 0x9 (MIDI_MESSAGE_NOTE_ON); should be 0x8 (MIDI_MESSAGE_NOTE_OFF) #76678

Closed
freswinn opened this issue May 2, 2023 · 4 comments · Fixed by #77103

Comments

@freswinn
Copy link

freswinn commented May 2, 2023

Godot version

4.0.2.stable.mono

System information

Windows 10

Issue description

Hello! I'm playing around with the MIDI input in Godot 4, and I've run into the issue where releasing a key on my MIDI keyboard does not return event.message 0x8, MIDI_MESSAGE_NOTE_OFF, but rather 0x9, which is MIDI_MESSAGE_NOTE_ON.

This is not the case in Godot 3. I created an identical script in each to test this out, and releasing the key in 3.x always returns 0x8, whereas releasing the key in 4 always returns 0x9.

Steps to reproduce

func _ready():
    OS.open_midi_inputs()

func _input(event):
    if event is InputEventMIDI:
        print(event.message)

Minimal reproduction project

N/A

@ashih42
Copy link

ashih42 commented May 13, 2023

I experienced the same situation recently. When I release a key on my MIDI device, a NOTE OFF message is received (observed with MIDI Monitor on macOS), but Godot would report it as a MIDI_MESSAGE_NOTE_ON message with velocity=0. This behavior is still within the MIDI spec, where a NOTE ON with velocity=0 means NOTE OFF. (I think this was a strategy used by some old synthesizers to send a sequence of NOTE ON, NOTE OFF messages as a stream of NOTE ON messages in a more compressed format, back when hardware throughput was a limiting factor. If your synth is connected with USB, it probably sends NOTE OFF messages... I don't know why Godot does this conversion when the MIDI device actually sent it NOTE OFF messages.)

@akien-mga
Copy link
Member

See #66003 - cc @voidshine.

Seems like nobody agrees on whether to follow the spec, or the common usage.

@voidshine
Copy link
Contributor

Right, some devices send NOTE_ON with velocity=0 when a key is released, but other devices send NOTE_ON with velocity=0 when a key is pressed very gently. It depends on the devices, and Godot itself should not interfere with the MIDI data. The application developer (i.e. script writer) must be wary of NOTE_ON events with velocity 0 and convert them manually if appropriate for the game/application (it's very easy, just a couple lines of code).

Thanks @akien-mga for upholding my fix -- it's bound to confuse some folks from time to time, but then MIDI implementations have always had their quirks.

@akien-mga
Copy link
Member

I see that this is properly documented in the description of the velocity property: https://docs.godotengine.org/en/latest/classes/class_inputeventmidi.html#class-inputeventmidi-property-velocity

I think we should maybe add a mention to this in the message description too, and possibly in the description of NOTE_ON and/or NOTE_OFF?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants