Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
InputEventMIDI¶
Inherits: InputEvent < Resource < RefCounted < Object
Represents an input event from a MIDI device, such as a piano.
Description¶
InputEventMIDI allows receiving input events from MIDI (Musical Instrument Digital Interface) devices such as a piano.
MIDI signals can be sent over a 5-pin MIDI connector or over USB, if your device supports both be sure to check the settings in the device to see which output it's using.
To receive input events from MIDI devices, you need to call OS.open_midi_inputs. You can check which devices are detected using OS.get_connected_midi_inputs.
func _ready():
OS.open_midi_inputs()
print(OS.get_connected_midi_inputs())
func _input(input_event):
if input_event is InputEventMIDI:
_print_midi_info(input_event)
func _print_midi_info(midi_event: InputEventMIDI):
print(midi_event)
print("Channel " + str(midi_event.channel))
print("Message " + str(midi_event.message))
print("Pitch " + str(midi_event.pitch))
print("Velocity " + str(midi_event.velocity))
print("Instrument " + str(midi_event.instrument))
print("Pressure " + str(midi_event.pressure))
print("Controller number: " + str(midi_event.controller_number))
print("Controller value: " + str(midi_event.controller_value))
public override void _Ready()
{
OS.OpenMidiInputs();
GD.Print(OS.GetConnectedMidiInputs());
}
public override void _Input(InputEvent @event)
{
if (@event is InputEventMIDI midiEvent)
{
PrintMIDIInfo(midiEvent);
}
}
private void PrintMIDIInfo(InputEventMIDI midiEvent)
{
GD.Print(midiEvent);
GD.Print($"Channel {midiEvent.Channel}");
GD.Print($"Message {midiEvent.Message}");
GD.Print($"Pitch {midiEvent.Pitch}");
GD.Print($"Velocity {midiEvent.Velocity}");
GD.Print($"Instrument {midiEvent.Instrument}");
GD.Print($"Pressure {midiEvent.Pressure}");
GD.Print($"Controller number: {midiEvent.ControllerNumber}");
GD.Print($"Controller value: {midiEvent.ControllerValue}");
}
Note that Godot does not currently support MIDI output, so there is no way to emit MIDI signals from Godot. Only MIDI input works.
Tutorials¶
Properties¶
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
Property Descriptions¶
int channel = 0
The MIDI channel of this input event. There are 16 channels, so this value ranges from 0 to 15. MIDI channel 9 is reserved for the use with percussion instruments, the rest of the channels are for non-percussion instruments.
int controller_number = 0