f0f72b3132
Update documentation with note about MIDI velocity interpretation
97 lines
6.1 KiB
XML
97 lines
6.1 KiB
XML
<?xml version="1.0" encoding="UTF-8" ?>
|
|
<class name="InputEventMIDI" inherits="InputEvent" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
|
|
<brief_description>
|
|
Input event for MIDI inputs.
|
|
</brief_description>
|
|
<description>
|
|
InputEventMIDI allows receiving input events from MIDI devices such as a piano. MIDI stands for Musical Instrument Digital Interface.
|
|
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 [method OS.open_midi_inputs]. You can check which devices are detected using [method OS.get_connected_midi_inputs].
|
|
[codeblocks]
|
|
[gdscript]
|
|
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))
|
|
[/gdscript]
|
|
[csharp]
|
|
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);
|
|
}
|
|
[/csharp]
|
|
[/codeblocks]
|
|
Note that Godot does not currently support MIDI output, so there is no way to emit MIDI signals from Godot. Only MIDI input works.
|
|
</description>
|
|
<tutorials>
|
|
<link title="MIDI Message Status Byte List">https://www.midi.org/specifications-old/item/table-2-expanded-messages-list-status-bytes</link>
|
|
<link title="Wikipedia General MIDI Instrument List">https://en.wikipedia.org/wiki/General_MIDI#Program_change_events</link>
|
|
<link title="Wikipedia Piano Key Frequencies List">https://en.wikipedia.org/wiki/Piano_key_frequencies#List</link>
|
|
</tutorials>
|
|
<members>
|
|
<member name="channel" type="int" setter="set_channel" getter="get_channel" default="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.
|
|
</member>
|
|
<member name="controller_number" type="int" setter="set_controller_number" getter="get_controller_number" default="0">
|
|
If the message is [code]MIDI_MESSAGE_CONTROL_CHANGE[/code], this indicates the controller number, otherwise this is zero. Controllers include devices such as pedals and levers.
|
|
</member>
|
|
<member name="controller_value" type="int" setter="set_controller_value" getter="get_controller_value" default="0">
|
|
If the message is [code]MIDI_MESSAGE_CONTROL_CHANGE[/code], this indicates the controller value, otherwise this is zero. Controllers include devices such as pedals and levers.
|
|
</member>
|
|
<member name="instrument" type="int" setter="set_instrument" getter="get_instrument" default="0">
|
|
The instrument of this input event. This value ranges from 0 to 127. Refer to the instrument list on the General MIDI wikipedia article to see a list of instruments, except that this value is 0-index, so subtract one from every number on that chart. A standard piano will have an instrument number of 0.
|
|
</member>
|
|
<member name="message" type="int" setter="set_message" getter="get_message" enum="MIDIMessage" default="0">
|
|
Returns a value indicating the type of message for this MIDI signal. This is a member of the [enum @GlobalScope.MIDIMessage] enum.
|
|
For MIDI messages between 0x80 and 0xEF, only the left half of the bits are returned as this value, as the other part is the channel (ex: 0x94 becomes 0x9). For MIDI messages from 0xF0 to 0xFF, the value is returned as-is.
|
|
Notes will return [code]MIDI_MESSAGE_NOTE_ON[/code] when activated, but they might not always return [code]MIDI_MESSAGE_NOTE_OFF[/code] when deactivated, therefore your code should treat the input as stopped if some period of time has passed.
|
|
For more information, see the MIDI message status byte list chart linked above.
|
|
</member>
|
|
<member name="pitch" type="int" setter="set_pitch" getter="get_pitch" default="0">
|
|
The pitch index number of this MIDI signal. This value ranges from 0 to 127. On a piano, middle C is 60, and A440 is 69, see the "MIDI note" column of the piano key frequency chart on Wikipedia for more information.
|
|
</member>
|
|
<member name="pressure" type="int" setter="set_pressure" getter="get_pressure" default="0">
|
|
The pressure of the MIDI signal. This value ranges from 0 to 127. For many devices, this value is always zero.
|
|
</member>
|
|
<member name="velocity" type="int" setter="set_velocity" getter="get_velocity" default="0">
|
|
The velocity of the MIDI signal. This value ranges from 0 to 127. For a piano, this corresponds to how quickly the key was pressed, and is rarely above about 110 in practice. Note that some MIDI devices may send a [constant MIDI_MESSAGE_NOTE_ON] message with zero velocity and expect this to be treated the same as a [constant MIDI_MESSAGE_NOTE_OFF] message, but device implementations vary so Godot reports event data exactly as received.
|
|
</member>
|
|
</members>
|
|
</class>
|