Table of Contents

Class InputEventMidi

Namespace
Godot
Assembly
GodotSharp.dll

InputEventMIDI stores information about messages from MIDI (Musical Instrument Digital Interface) devices. These may include musical keyboards, synthesizers, and drum machines.

MIDI messages can be received 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 is using.

By default, Godot does not detect MIDI devices. You need to call OpenMidiInputs(), first. You can check which devices are detected with GetConnectedMidiInputs(), and close the connection with CloseMidiInputs().

public override void _Ready()
  {
      OS.OpenMidiInputs();
      GD.Print(OS.GetConnectedMidiInputs());
  }

public override void _Input(InputEvent inputEvent) { if (inputEvent 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: Godot does not support MIDI output, so there is no way to emit MIDI messages from Godot. Only MIDI input is supported.

[GodotClassName("InputEventMIDI")]
public class InputEventMidi : InputEvent, IDisposable
Inheritance
InputEventMidi
Implements
Inherited Members

Constructors

InputEventMidi()

public InputEventMidi()

Properties

Channel

The MIDI channel of this message, ranging from 0 to 15. MIDI channel 9 is reserved for percussion instruments.

public int Channel { get; set; }

Property Value

int

ControllerNumber

The unique number of the controller, if Message is ControlChange, otherwise this is 0. This value can be used to identify sliders for volume, balance, and panning, as well as switches and pedals on the MIDI device. See the General MIDI specification for a small list.

public int ControllerNumber { get; set; }

Property Value

int

ControllerValue

The value applied to the controller. If Message is ControlChange, this value ranges from 0 to 127, otherwise it is 0. See also ControllerValue.

public int ControllerValue { get; set; }

Property Value

int

Instrument

The instrument (also called program or preset) used on this MIDI message. This value ranges from 0 to 127.

To see what each value means, refer to the General MIDI's instrument list. Keep in mind that the list is off by 1 because it does not begin from 0. A value of 0 corresponds to the acoustic grand piano.

public int Instrument { get; set; }

Property Value

int

Message

Represents the type of MIDI message (see the MidiMessage enum).

For more information, see the MIDI message status byte list chart.

public MidiMessage Message { get; set; }

Property Value

MidiMessage

Pitch

The pitch index number of this MIDI message. This value ranges from 0 to 127.

On a piano, the middle C is 60, followed by a C-sharp (61), then a D (62), and so on. Each octave is split in offsets of 12. See the "MIDI note number" column of the piano key frequency chart a full list.

public int Pitch { get; set; }

Property Value

int

Pressure

The strength of the key being pressed. This value ranges from 0 to 127.

Note: For many devices, this value is always 0. Other devices such as musical keyboards may simulate pressure by changing the Velocity, instead.

public int Pressure { get; set; }

Property Value

int

Velocity

The velocity of the MIDI message. This value ranges from 0 to 127. For a musical keyboard, this corresponds to how quickly the key was pressed, and is rarely above 110 in practice.

Note: Some MIDI devices may send a NoteOn message with 0 velocity and expect it to be treated the same as a NoteOff message. If necessary, this can be handled with a few lines of code:

func _input(event):
      if event is InputEventMIDI:
          if event.message == MIDI_MESSAGE_NOTE_ON and event.velocity > 0:
              print("Note pressed!")
public int Velocity { get; set; }

Property Value

int

Methods

HasGodotClassMethod(in godot_string_name)

Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.

protected override bool HasGodotClassMethod(in godot_string_name method)

Parameters

method godot_string_name

Name of the method to check for.

Returns

bool

HasGodotClassSignal(in godot_string_name)

Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.

protected override bool HasGodotClassSignal(in godot_string_name signal)

Parameters

signal godot_string_name

Name of the signal to check for.

Returns

bool

InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)

Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.

protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)

Parameters

method godot_string_name

Name of the method to invoke.

args NativeVariantPtrArgs

Arguments to use with the invoked method.

ret godot_variant

Value returned by the invoked method.

Returns

bool