diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp index e99dd0459945..73ede36a8c86 100644 --- a/core/input/input_event.cpp +++ b/core/input/input_event.cpp @@ -1717,6 +1717,18 @@ int InputEventMIDI::get_controller_value() const { return controller_value; } +void InputEventMIDI::open_inputs() { + OS::get_singleton()->open_midi_inputs(); +} + +void InputEventMIDI::close_inputs() { + OS::get_singleton()->close_midi_inputs(); +} + +PackedStringArray InputEventMIDI::get_connected_inputs() { + return OS::get_singleton()->get_connected_midi_inputs(); +} + String InputEventMIDI::as_text() const { return vformat(RTR("MIDI Input on Channel=%s Message=%s"), itos(channel), itos((int64_t)message)); } @@ -1763,6 +1775,10 @@ void InputEventMIDI::_bind_methods() { ClassDB::bind_method(D_METHOD("set_controller_value", "controller_value"), &InputEventMIDI::set_controller_value); ClassDB::bind_method(D_METHOD("get_controller_value"), &InputEventMIDI::get_controller_value); + ClassDB::bind_static_method("InputEventMIDI", D_METHOD("open_inputs"), &InputEventMIDI::open_inputs); + ClassDB::bind_static_method("InputEventMIDI", D_METHOD("close_inputs"), &InputEventMIDI::close_inputs); + ClassDB::bind_static_method("InputEventMIDI", D_METHOD("get_connected_inputs"), &InputEventMIDI::get_connected_inputs); + ADD_PROPERTY(PropertyInfo(Variant::INT, "channel"), "set_channel", "get_channel"); ADD_PROPERTY(PropertyInfo(Variant::INT, "message"), "set_message", "get_message"); ADD_PROPERTY(PropertyInfo(Variant::INT, "pitch"), "set_pitch", "get_pitch"); diff --git a/core/input/input_event.h b/core/input/input_event.h index ed7ccf0a9f1b..bc13236b1d4e 100644 --- a/core/input/input_event.h +++ b/core/input/input_event.h @@ -547,6 +547,10 @@ class InputEventMIDI : public InputEvent { void set_controller_value(const int p_controller_value); int get_controller_value() const; + static void open_inputs(); + static void close_inputs(); + static PackedStringArray get_connected_inputs(); + virtual String as_text() const override; virtual String to_string() override; diff --git a/doc/classes/InputEventMIDI.xml b/doc/classes/InputEventMIDI.xml index 8e2ad5280184..6cb3f3da11a3 100644 --- a/doc/classes/InputEventMIDI.xml +++ b/doc/classes/InputEventMIDI.xml @@ -6,12 +6,12 @@ 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 [method OS.open_midi_inputs]. You can check which devices are detected using [method OS.get_connected_midi_inputs]. + To receive input events from MIDI devices, you need to call [method InputEventMIDI.open_inputs]. You can check which devices are detected using [method InputEventMIDI.get_connected_inputs]. [codeblocks] [gdscript] func _ready(): - OS.open_midi_inputs() - print(OS.get_connected_midi_inputs()) + InputEventMIDI.open_inputs() + print(InputEventMIDI.get_connected_inputs()) func _input(input_event): if input_event is InputEventMIDI: @@ -31,8 +31,8 @@ [csharp] public override void _Ready() { - OS.OpenMidiInputs(); - GD.Print(OS.GetConnectedMidiInputs()); + InputEventMIDI.OpenInputs(); + GD.Print(InputEventMIDI.GetConnectedInputs()); } public override void _Input(InputEvent @event) @@ -64,6 +64,30 @@ https://en.wikipedia.org/wiki/General_MIDI#Program_change_events https://en.wikipedia.org/wiki/Piano_key_frequencies#List + + + + + Shuts down system MIDI driver. + [b]Note:[/b] This method is implemented on Linux, macOS and Windows. + + + + + + Returns an array of MIDI device names. + The returned array will be empty if the system MIDI driver has not previously been initialized with [method open_inputs]. + [b]Note:[/b] This method is implemented on Linux, macOS and Windows. + + + + + + Initializes the singleton for the system MIDI driver. + [b]Note:[/b] This method is implemented on Linux, macOS and Windows. + + + 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. diff --git a/doc/classes/OS.xml b/doc/classes/OS.xml index 188e846f5e87..c02642e90cf6 100644 --- a/doc/classes/OS.xml +++ b/doc/classes/OS.xml @@ -19,11 +19,11 @@ Displays a modal dialog box using the host platform's implementation. The engine execution is blocked until the dialog is closed. - + Shuts down the system MIDI driver. Godot will no longer receive [InputEventMIDI]. See also [method open_midi_inputs] and [method get_connected_midi_inputs]. - [b]Note:[/b] This method is implemented on Linux, macOS and Windows. + [i]Deprecated.[/i] Use [method InputEventMIDI.close_inputs]. @@ -220,11 +220,11 @@ Not to be confused with [method get_user_data_dir], which returns the [i]project-specific[/i] user data path. - + Returns an array of connected MIDI device names, if they exist. Returns an empty array if the system MIDI driver has not previously been initialized with [method open_midi_inputs]. See also [method close_midi_inputs]. - [b]Note:[/b] This method is implemented on Linux, macOS and Windows. + [i]Deprecated.[/i] Use [method InputEventMIDI.get_connected_inputs]. @@ -632,11 +632,11 @@ [b]Note:[/b] If the user has disabled the recycle bin on their system, the file will be permanently deleted instead. - + Initializes the singleton for the system MIDI driver, allowing Godot to receive [InputEventMIDI]. See also [method get_connected_midi_inputs] and [method close_midi_inputs]. - [b]Note:[/b] This method is implemented on Linux, macOS and Windows. + [i]Deprecated.[/i] Use [method InputEventMIDI.open_inputs].