Have you added a print statements to check if the rest of the code is working? Something like the following should tell you if the MIDI events are being picked up correctly by the code (untested):
func _unhandled_input(event):
if (event is InputEventMIDI):
var key_index = event.pitch
print ("MIDI key index: ", key_index)
if (key_index == 30):
print ("Code recognized key index 30")
match event.message:
MIDI_MASSAGE_NOTE_ON:
print ("Code recognized MIDI message note on")
get_node("pad1").set_pressed(true)
That way you should be able to look at the debugger and ensure the code its working. Looking at the code, I think it is probably working, but I have found that double checking never hurts and sometimes can save lots of debugging time.
Is pad1 a button node? If so, the issue could be that the button is being pressed only for a single frame rather than for the duration of the MIDI note being held. Theoretically, something like this might work around that issue:
var midi_index_30_held = false
func _unhandled_input(event):
if (event is InputEventMIDI):
var key_index = event.pitch
if (key_index == 30):
match event.message:
MIDI_MESSAGE_NOTE_ON:
if (midi_index_30_held == false):
midi_index_30_held = true
print ("MIDI 30 was just pressed")
MIDI_MESSAGE_NOTE_OFF:
if (midi_index_30_held == true):
midi_index_30_held = false
print ("MIDI 30 was just released")
func _process(_delta):
get_node("pad1").set_pressed(midi_index_30_held)
I have no idea if that will fix the issue, but it might be worth a shot. The code above should keep the pressed property of the node set to true when the MIDI button is held, and false when the MIDI button is no longer held.
Hopefully this helps a bit :smile: