mirror of
https://github.com/godotengine/godot-docs.git
synced 2025-12-31 17:49:03 +03:00
279 lines
12 KiB
ReStructuredText
279 lines
12 KiB
ReStructuredText
:github_url: hide
|
|
|
|
.. DO NOT EDIT THIS FILE!!!
|
|
.. Generated automatically from Godot engine sources.
|
|
.. Generator: https://github.com/godotengine/godot/tree/4.0/doc/tools/make_rst.py.
|
|
.. XML source: https://github.com/godotengine/godot/tree/4.0/doc/classes/InputEventMIDI.xml.
|
|
|
|
.. _class_InputEventMIDI:
|
|
|
|
InputEventMIDI
|
|
==============
|
|
|
|
**Inherits:** :ref:`InputEvent<class_InputEvent>` **<** :ref:`Resource<class_Resource>` **<** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
|
|
|
|
Represents an input event from a MIDI device, such as a piano.
|
|
|
|
.. rst-class:: classref-introduction-group
|
|
|
|
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 :ref:`OS.open_midi_inputs<class_OS_method_open_midi_inputs>`. You can check which devices are detected using :ref:`OS.get_connected_midi_inputs<class_OS_method_get_connected_midi_inputs>`.
|
|
|
|
|
|
.. tabs::
|
|
|
|
.. code-tab:: 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))
|
|
|
|
.. code-tab:: csharp
|
|
|
|
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.
|
|
|
|
.. rst-class:: classref-introduction-group
|
|
|
|
Tutorials
|
|
---------
|
|
|
|
- `MIDI Message Status Byte List <https://www.midi.org/specifications-old/item/table-2-expanded-messages-list-status-bytes>`__
|
|
|
|
- `Wikipedia General MIDI Instrument List <https://en.wikipedia.org/wiki/General_MIDI#Program_change_events>`__
|
|
|
|
- `Wikipedia Piano Key Frequencies List <https://en.wikipedia.org/wiki/Piano_key_frequencies#List>`__
|
|
|
|
.. rst-class:: classref-reftable-group
|
|
|
|
Properties
|
|
----------
|
|
|
|
.. table::
|
|
:widths: auto
|
|
|
|
+---------------------------------------------------+---------------------------------------------------------------------------+-------+
|
|
| :ref:`int<class_int>` | :ref:`channel<class_InputEventMIDI_property_channel>` | ``0`` |
|
|
+---------------------------------------------------+---------------------------------------------------------------------------+-------+
|
|
| :ref:`int<class_int>` | :ref:`controller_number<class_InputEventMIDI_property_controller_number>` | ``0`` |
|
|
+---------------------------------------------------+---------------------------------------------------------------------------+-------+
|
|
| :ref:`int<class_int>` | :ref:`controller_value<class_InputEventMIDI_property_controller_value>` | ``0`` |
|
|
+---------------------------------------------------+---------------------------------------------------------------------------+-------+
|
|
| :ref:`int<class_int>` | :ref:`instrument<class_InputEventMIDI_property_instrument>` | ``0`` |
|
|
+---------------------------------------------------+---------------------------------------------------------------------------+-------+
|
|
| :ref:`MIDIMessage<enum_@GlobalScope_MIDIMessage>` | :ref:`message<class_InputEventMIDI_property_message>` | ``0`` |
|
|
+---------------------------------------------------+---------------------------------------------------------------------------+-------+
|
|
| :ref:`int<class_int>` | :ref:`pitch<class_InputEventMIDI_property_pitch>` | ``0`` |
|
|
+---------------------------------------------------+---------------------------------------------------------------------------+-------+
|
|
| :ref:`int<class_int>` | :ref:`pressure<class_InputEventMIDI_property_pressure>` | ``0`` |
|
|
+---------------------------------------------------+---------------------------------------------------------------------------+-------+
|
|
| :ref:`int<class_int>` | :ref:`velocity<class_InputEventMIDI_property_velocity>` | ``0`` |
|
|
+---------------------------------------------------+---------------------------------------------------------------------------+-------+
|
|
|
|
.. rst-class:: classref-section-separator
|
|
|
|
----
|
|
|
|
.. rst-class:: classref-descriptions-group
|
|
|
|
Property Descriptions
|
|
---------------------
|
|
|
|
.. _class_InputEventMIDI_property_channel:
|
|
|
|
.. rst-class:: classref-property
|
|
|
|
:ref:`int<class_int>` **channel** = ``0``
|
|
|
|
.. rst-class:: classref-property-setget
|
|
|
|
- void **set_channel** **(** :ref:`int<class_int>` value **)**
|
|
- :ref:`int<class_int>` **get_channel** **(** **)**
|
|
|
|
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.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_InputEventMIDI_property_controller_number:
|
|
|
|
.. rst-class:: classref-property
|
|
|
|
:ref:`int<class_int>` **controller_number** = ``0``
|
|
|
|
.. rst-class:: classref-property-setget
|
|
|
|
- void **set_controller_number** **(** :ref:`int<class_int>` value **)**
|
|
- :ref:`int<class_int>` **get_controller_number** **(** **)**
|
|
|
|
If the message is :ref:`@GlobalScope.MIDI_MESSAGE_CONTROL_CHANGE<class_@GlobalScope_constant_MIDI_MESSAGE_CONTROL_CHANGE>`, this indicates the controller number, otherwise this is zero. Controllers include devices such as pedals and levers.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_InputEventMIDI_property_controller_value:
|
|
|
|
.. rst-class:: classref-property
|
|
|
|
:ref:`int<class_int>` **controller_value** = ``0``
|
|
|
|
.. rst-class:: classref-property-setget
|
|
|
|
- void **set_controller_value** **(** :ref:`int<class_int>` value **)**
|
|
- :ref:`int<class_int>` **get_controller_value** **(** **)**
|
|
|
|
If the message is :ref:`@GlobalScope.MIDI_MESSAGE_CONTROL_CHANGE<class_@GlobalScope_constant_MIDI_MESSAGE_CONTROL_CHANGE>`, this indicates the controller value, otherwise this is zero. Controllers include devices such as pedals and levers.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_InputEventMIDI_property_instrument:
|
|
|
|
.. rst-class:: classref-property
|
|
|
|
:ref:`int<class_int>` **instrument** = ``0``
|
|
|
|
.. rst-class:: classref-property-setget
|
|
|
|
- void **set_instrument** **(** :ref:`int<class_int>` value **)**
|
|
- :ref:`int<class_int>` **get_instrument** **(** **)**
|
|
|
|
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.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_InputEventMIDI_property_message:
|
|
|
|
.. rst-class:: classref-property
|
|
|
|
:ref:`MIDIMessage<enum_@GlobalScope_MIDIMessage>` **message** = ``0``
|
|
|
|
.. rst-class:: classref-property-setget
|
|
|
|
- void **set_message** **(** :ref:`MIDIMessage<enum_@GlobalScope_MIDIMessage>` value **)**
|
|
- :ref:`MIDIMessage<enum_@GlobalScope_MIDIMessage>` **get_message** **(** **)**
|
|
|
|
Returns a value indicating the type of message for this MIDI signal. This is a member of the :ref:`MIDIMessage<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 :ref:`@GlobalScope.MIDI_MESSAGE_NOTE_ON<class_@GlobalScope_constant_MIDI_MESSAGE_NOTE_ON>` when activated, but they might not always return :ref:`@GlobalScope.MIDI_MESSAGE_NOTE_OFF<class_@GlobalScope_constant_MIDI_MESSAGE_NOTE_OFF>` when deactivated, therefore your code should treat the input as stopped if some period of time has passed.
|
|
|
|
Some MIDI devices may send :ref:`@GlobalScope.MIDI_MESSAGE_NOTE_ON<class_@GlobalScope_constant_MIDI_MESSAGE_NOTE_ON>` with zero velocity instead of :ref:`@GlobalScope.MIDI_MESSAGE_NOTE_OFF<class_@GlobalScope_constant_MIDI_MESSAGE_NOTE_OFF>`.
|
|
|
|
For more information, see the note in :ref:`velocity<class_InputEventMIDI_property_velocity>` and the MIDI message status byte list chart linked above.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_InputEventMIDI_property_pitch:
|
|
|
|
.. rst-class:: classref-property
|
|
|
|
:ref:`int<class_int>` **pitch** = ``0``
|
|
|
|
.. rst-class:: classref-property-setget
|
|
|
|
- void **set_pitch** **(** :ref:`int<class_int>` value **)**
|
|
- :ref:`int<class_int>` **get_pitch** **(** **)**
|
|
|
|
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.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_InputEventMIDI_property_pressure:
|
|
|
|
.. rst-class:: classref-property
|
|
|
|
:ref:`int<class_int>` **pressure** = ``0``
|
|
|
|
.. rst-class:: classref-property-setget
|
|
|
|
- void **set_pressure** **(** :ref:`int<class_int>` value **)**
|
|
- :ref:`int<class_int>` **get_pressure** **(** **)**
|
|
|
|
The pressure of the MIDI signal. This value ranges from 0 to 127. For many devices, this value is always zero.
|
|
|
|
.. rst-class:: classref-item-separator
|
|
|
|
----
|
|
|
|
.. _class_InputEventMIDI_property_velocity:
|
|
|
|
.. rst-class:: classref-property
|
|
|
|
:ref:`int<class_int>` **velocity** = ``0``
|
|
|
|
.. rst-class:: classref-property-setget
|
|
|
|
- void **set_velocity** **(** :ref:`int<class_int>` value **)**
|
|
- :ref:`int<class_int>` **get_velocity** **(** **)**
|
|
|
|
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:** Some MIDI devices may send a :ref:`@GlobalScope.MIDI_MESSAGE_NOTE_ON<class_@GlobalScope_constant_MIDI_MESSAGE_NOTE_ON>` message with zero velocity and expect this to be treated the same as a :ref:`@GlobalScope.MIDI_MESSAGE_NOTE_OFF<class_@GlobalScope_constant_MIDI_MESSAGE_NOTE_OFF>` message, but device implementations vary so Godot reports event data exactly as received. Depending on the hardware and the needs of the game/app, this MIDI quirk can be handled robustly with a couple lines of script (check for :ref:`@GlobalScope.MIDI_MESSAGE_NOTE_ON<class_@GlobalScope_constant_MIDI_MESSAGE_NOTE_ON>` with velocity zero).
|
|
|
|
.. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
|
|
.. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
|
|
.. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
|
|
.. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
|
|
.. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
|
|
.. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
|