class_inputeventmidi.rst 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/InputEventMIDI.xml.
  6. .. _class_InputEventMIDI:
  7. InputEventMIDI
  8. ==============
  9. **Inherits:** :ref:`InputEvent<class_InputEvent>` **<** :ref:`Resource<class_Resource>` **<** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  10. Represents an input event from a MIDI device, such as a piano.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. InputEventMIDI allows receiving input events from MIDI (Musical Instrument Digital Interface) devices such as a piano.
  15. 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.
  16. 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>`.
  17. .. tabs::
  18. .. code-tab:: gdscript
  19. func _ready():
  20. OS.open_midi_inputs()
  21. print(OS.get_connected_midi_inputs())
  22. func _input(input_event):
  23. if input_event is InputEventMIDI:
  24. _print_midi_info(input_event)
  25. func _print_midi_info(midi_event: InputEventMIDI):
  26. print(midi_event)
  27. print("Channel " + str(midi_event.channel))
  28. print("Message " + str(midi_event.message))
  29. print("Pitch " + str(midi_event.pitch))
  30. print("Velocity " + str(midi_event.velocity))
  31. print("Instrument " + str(midi_event.instrument))
  32. print("Pressure " + str(midi_event.pressure))
  33. print("Controller number: " + str(midi_event.controller_number))
  34. print("Controller value: " + str(midi_event.controller_value))
  35. .. code-tab:: csharp
  36. public override void _Ready()
  37. {
  38. OS.OpenMidiInputs();
  39. GD.Print(OS.GetConnectedMidiInputs());
  40. }
  41. public override void _Input(InputEvent @event)
  42. {
  43. if (@event is InputEventMIDI midiEvent)
  44. {
  45. PrintMIDIInfo(midiEvent);
  46. }
  47. }
  48. private void PrintMIDIInfo(InputEventMIDI midiEvent)
  49. {
  50. GD.Print(midiEvent);
  51. GD.Print($"Channel {midiEvent.Channel}");
  52. GD.Print($"Message {midiEvent.Message}");
  53. GD.Print($"Pitch {midiEvent.Pitch}");
  54. GD.Print($"Velocity {midiEvent.Velocity}");
  55. GD.Print($"Instrument {midiEvent.Instrument}");
  56. GD.Print($"Pressure {midiEvent.Pressure}");
  57. GD.Print($"Controller number: {midiEvent.ControllerNumber}");
  58. GD.Print($"Controller value: {midiEvent.ControllerValue}");
  59. }
  60. Note that Godot does not currently support MIDI output, so there is no way to emit MIDI signals from Godot. Only MIDI input works.
  61. .. rst-class:: classref-introduction-group
  62. Tutorials
  63. ---------
  64. - `MIDI Message Status Byte List <https://www.midi.org/specifications-old/item/table-2-expanded-messages-list-status-bytes>`__
  65. - `Wikipedia General MIDI Instrument List <https://en.wikipedia.org/wiki/General_MIDI#Program_change_events>`__
  66. - `Wikipedia Piano Key Frequencies List <https://en.wikipedia.org/wiki/Piano_key_frequencies#List>`__
  67. .. rst-class:: classref-reftable-group
  68. Properties
  69. ----------
  70. .. table::
  71. :widths: auto
  72. +---------------------------------------------------+---------------------------------------------------------------------------+-------+
  73. | :ref:`int<class_int>` | :ref:`channel<class_InputEventMIDI_property_channel>` | ``0`` |
  74. +---------------------------------------------------+---------------------------------------------------------------------------+-------+
  75. | :ref:`int<class_int>` | :ref:`controller_number<class_InputEventMIDI_property_controller_number>` | ``0`` |
  76. +---------------------------------------------------+---------------------------------------------------------------------------+-------+
  77. | :ref:`int<class_int>` | :ref:`controller_value<class_InputEventMIDI_property_controller_value>` | ``0`` |
  78. +---------------------------------------------------+---------------------------------------------------------------------------+-------+
  79. | :ref:`int<class_int>` | :ref:`instrument<class_InputEventMIDI_property_instrument>` | ``0`` |
  80. +---------------------------------------------------+---------------------------------------------------------------------------+-------+
  81. | :ref:`MIDIMessage<enum_@GlobalScope_MIDIMessage>` | :ref:`message<class_InputEventMIDI_property_message>` | ``0`` |
  82. +---------------------------------------------------+---------------------------------------------------------------------------+-------+
  83. | :ref:`int<class_int>` | :ref:`pitch<class_InputEventMIDI_property_pitch>` | ``0`` |
  84. +---------------------------------------------------+---------------------------------------------------------------------------+-------+
  85. | :ref:`int<class_int>` | :ref:`pressure<class_InputEventMIDI_property_pressure>` | ``0`` |
  86. +---------------------------------------------------+---------------------------------------------------------------------------+-------+
  87. | :ref:`int<class_int>` | :ref:`velocity<class_InputEventMIDI_property_velocity>` | ``0`` |
  88. +---------------------------------------------------+---------------------------------------------------------------------------+-------+
  89. .. rst-class:: classref-section-separator
  90. ----
  91. .. rst-class:: classref-descriptions-group
  92. Property Descriptions
  93. ---------------------
  94. .. _class_InputEventMIDI_property_channel:
  95. .. rst-class:: classref-property
  96. :ref:`int<class_int>` **channel** = ``0``
  97. .. rst-class:: classref-property-setget
  98. - void **set_channel** **(** :ref:`int<class_int>` value **)**
  99. - :ref:`int<class_int>` **get_channel** **(** **)**
  100. 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.
  101. .. rst-class:: classref-item-separator
  102. ----
  103. .. _class_InputEventMIDI_property_controller_number:
  104. .. rst-class:: classref-property
  105. :ref:`int<class_int>` **controller_number** = ``0``
  106. .. rst-class:: classref-property-setget
  107. - void **set_controller_number** **(** :ref:`int<class_int>` value **)**
  108. - :ref:`int<class_int>` **get_controller_number** **(** **)**
  109. 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.
  110. .. rst-class:: classref-item-separator
  111. ----
  112. .. _class_InputEventMIDI_property_controller_value:
  113. .. rst-class:: classref-property
  114. :ref:`int<class_int>` **controller_value** = ``0``
  115. .. rst-class:: classref-property-setget
  116. - void **set_controller_value** **(** :ref:`int<class_int>` value **)**
  117. - :ref:`int<class_int>` **get_controller_value** **(** **)**
  118. 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.
  119. .. rst-class:: classref-item-separator
  120. ----
  121. .. _class_InputEventMIDI_property_instrument:
  122. .. rst-class:: classref-property
  123. :ref:`int<class_int>` **instrument** = ``0``
  124. .. rst-class:: classref-property-setget
  125. - void **set_instrument** **(** :ref:`int<class_int>` value **)**
  126. - :ref:`int<class_int>` **get_instrument** **(** **)**
  127. 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.
  128. .. rst-class:: classref-item-separator
  129. ----
  130. .. _class_InputEventMIDI_property_message:
  131. .. rst-class:: classref-property
  132. :ref:`MIDIMessage<enum_@GlobalScope_MIDIMessage>` **message** = ``0``
  133. .. rst-class:: classref-property-setget
  134. - void **set_message** **(** :ref:`MIDIMessage<enum_@GlobalScope_MIDIMessage>` value **)**
  135. - :ref:`MIDIMessage<enum_@GlobalScope_MIDIMessage>` **get_message** **(** **)**
  136. Returns a value indicating the type of message for this MIDI signal. This is a member of the :ref:`MIDIMessage<enum_@GlobalScope_MIDIMessage>` enum.
  137. 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.
  138. 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.
  139. 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>`.
  140. For more information, see the note in :ref:`velocity<class_InputEventMIDI_property_velocity>` and the MIDI message status byte list chart linked above.
  141. .. rst-class:: classref-item-separator
  142. ----
  143. .. _class_InputEventMIDI_property_pitch:
  144. .. rst-class:: classref-property
  145. :ref:`int<class_int>` **pitch** = ``0``
  146. .. rst-class:: classref-property-setget
  147. - void **set_pitch** **(** :ref:`int<class_int>` value **)**
  148. - :ref:`int<class_int>` **get_pitch** **(** **)**
  149. 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.
  150. .. rst-class:: classref-item-separator
  151. ----
  152. .. _class_InputEventMIDI_property_pressure:
  153. .. rst-class:: classref-property
  154. :ref:`int<class_int>` **pressure** = ``0``
  155. .. rst-class:: classref-property-setget
  156. - void **set_pressure** **(** :ref:`int<class_int>` value **)**
  157. - :ref:`int<class_int>` **get_pressure** **(** **)**
  158. The pressure of the MIDI signal. This value ranges from 0 to 127. For many devices, this value is always zero.
  159. .. rst-class:: classref-item-separator
  160. ----
  161. .. _class_InputEventMIDI_property_velocity:
  162. .. rst-class:: classref-property
  163. :ref:`int<class_int>` **velocity** = ``0``
  164. .. rst-class:: classref-property-setget
  165. - void **set_velocity** **(** :ref:`int<class_int>` value **)**
  166. - :ref:`int<class_int>` **get_velocity** **(** **)**
  167. 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.
  168. \ **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).
  169. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  170. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  171. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  172. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  173. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  174. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  175. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`