class_inputeventmidi.rst 12 KB

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