From da88e42f164740ca04fd2d5f8c1b4929c935c07e Mon Sep 17 00:00:00 2001 From: Aaron Franke Date: Fri, 31 Dec 2021 13:07:03 -0800 Subject: [PATCH] [3.x] Document InputEventMIDI and add some missing 0xF MIDI messages --- core/global_constants.cpp | 11 ++++++++ core/os/input_event.h | 11 ++++++++ doc/classes/@GlobalScope.xml | 47 +++++++++++++++++++++++++++++----- doc/classes/InputEventMIDI.xml | 19 ++++++++++++++ 4 files changed, 81 insertions(+), 7 deletions(-) diff --git a/core/global_constants.cpp b/core/global_constants.cpp index e749dc7423f..6fefa919752 100644 --- a/core/global_constants.cpp +++ b/core/global_constants.cpp @@ -516,6 +516,17 @@ void register_global_constants() { BIND_GLOBAL_ENUM_CONSTANT(MIDI_MESSAGE_PROGRAM_CHANGE); BIND_GLOBAL_ENUM_CONSTANT(MIDI_MESSAGE_CHANNEL_PRESSURE); BIND_GLOBAL_ENUM_CONSTANT(MIDI_MESSAGE_PITCH_BEND); + BIND_GLOBAL_ENUM_CONSTANT(MIDI_MESSAGE_SYSTEM_EXCLUSIVE); + BIND_GLOBAL_ENUM_CONSTANT(MIDI_MESSAGE_QUARTER_FRAME); + BIND_GLOBAL_ENUM_CONSTANT(MIDI_MESSAGE_SONG_POSITION_POINTER); + BIND_GLOBAL_ENUM_CONSTANT(MIDI_MESSAGE_SONG_SELECT); + BIND_GLOBAL_ENUM_CONSTANT(MIDI_MESSAGE_TUNE_REQUEST); + BIND_GLOBAL_ENUM_CONSTANT(MIDI_MESSAGE_TIMING_CLOCK); + BIND_GLOBAL_ENUM_CONSTANT(MIDI_MESSAGE_START); + BIND_GLOBAL_ENUM_CONSTANT(MIDI_MESSAGE_CONTINUE); + BIND_GLOBAL_ENUM_CONSTANT(MIDI_MESSAGE_STOP); + BIND_GLOBAL_ENUM_CONSTANT(MIDI_MESSAGE_ACTIVE_SENSING); + BIND_GLOBAL_ENUM_CONSTANT(MIDI_MESSAGE_SYSTEM_RESET); // error list diff --git a/core/os/input_event.h b/core/os/input_event.h index 6f5f2dc80d9..4b202407978 100644 --- a/core/os/input_event.h +++ b/core/os/input_event.h @@ -176,6 +176,17 @@ enum MidiMessageList { MIDI_MESSAGE_PROGRAM_CHANGE = 0xC, MIDI_MESSAGE_CHANNEL_PRESSURE = 0xD, MIDI_MESSAGE_PITCH_BEND = 0xE, + MIDI_MESSAGE_SYSTEM_EXCLUSIVE = 0xF0, + MIDI_MESSAGE_QUARTER_FRAME = 0xF1, + MIDI_MESSAGE_SONG_POSITION_POINTER = 0xF2, + MIDI_MESSAGE_SONG_SELECT = 0xF3, + MIDI_MESSAGE_TUNE_REQUEST = 0xF6, + MIDI_MESSAGE_TIMING_CLOCK = 0xF8, + MIDI_MESSAGE_START = 0xFA, + MIDI_MESSAGE_CONTINUE = 0xFB, + MIDI_MESSAGE_STOP = 0xFC, + MIDI_MESSAGE_ACTIVE_SENSING = 0xFE, + MIDI_MESSAGE_SYSTEM_RESET = 0xFF, }; /** diff --git a/doc/classes/@GlobalScope.xml b/doc/classes/@GlobalScope.xml index 6a80f10526d..9cc4f687085 100644 --- a/doc/classes/@GlobalScope.xml +++ b/doc/classes/@GlobalScope.xml @@ -1190,25 +1190,58 @@ OpenVR touchpad Y axis (Joystick axis on Oculus Touch and Windows MR controllers). - MIDI note OFF message. + MIDI note OFF message. See the documentation of [InputEventMIDI] for information of how to use MIDI inputs. - MIDI note ON message. + MIDI note ON message. See the documentation of [InputEventMIDI] for information of how to use MIDI inputs. - MIDI aftertouch message. + MIDI aftertouch message. This message is most often sent by pressing down on the key after it "bottoms out". - MIDI control change message. + MIDI control change message. This message is sent when a controller value changes. Controllers include devices such as pedals and levers. - MIDI program change message. + MIDI program change message. This message sent when the program patch number changes. - MIDI channel pressure message. + MIDI channel pressure message. This message is most often sent by pressing down on the key after it "bottoms out". This message is different from polyphonic after-touch as it indicates the highest pressure across all keys. - MIDI pitch bend message. + MIDI pitch bend message. This message is sent to indicate a change in the pitch bender (wheel or lever, typically). + + + MIDI system exclusive message. This has behavior exclusive to the device you're receiving input from. Getting this data is not implemented in Godot. + + + MIDI quarter frame message. Contains timing information that is used to synchronize MIDI devices. Getting this data is not implemented in Godot. + + + MIDI song position pointer message. Gives the number of 16th notes since the start of the song. Getting this data is not implemented in Godot. + + + MIDI song select message. Specifies which sequence or song is to be played. Getting this data is not implemented in Godot. + + + MIDI tune request message. Upon receiving a tune request, all analog synthesizers should tune their oscillators. + + + MIDI timing clock message. Sent 24 times per quarter note when synchronization is required. + + + MIDI start message. Start the current sequence playing. This message will be followed with Timing Clocks. + + + MIDI continue message. Continue at the point the sequence was stopped. + + + MIDI stop message. Stop the current sequence. + + + MIDI active sensing message. This message is intended to be sent repeatedly to tell the receiver that a connection is alive. + + + MIDI system reset message. Reset all receivers in the system to power-up status. It should not be sent on power-up itself. Methods that return [enum Error] return [constant OK] when no error occurred. Note that many functions don't return an error code but will print error messages to standard output. diff --git a/doc/classes/InputEventMIDI.xml b/doc/classes/InputEventMIDI.xml index 6f8d8e0eca8..132936b8cc3 100644 --- a/doc/classes/InputEventMIDI.xml +++ b/doc/classes/InputEventMIDI.xml @@ -1,29 +1,48 @@ + Input event for MIDI inputs. + 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]. + Note that Godot does not currently support MIDI output, so there is no way to emit MIDI signals from Godot. Only MIDI input works. + https://www.midi.org/specifications-old/item/table-2-expanded-messages-list-status-bytes + https://en.wikipedia.org/wiki/General_MIDI#Program_change_events + https://en.wikipedia.org/wiki/Piano_key_frequencies#List + 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. + 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. + 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. + 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. + Returns a value indicating the type of message for this MIDI signal. This is a member of the MidiMessageList 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. + 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. + The pressure of the MIDI signal. This value ranges from 0 to 127. For many devices, this value is always zero. + 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.