Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move MIDI's methods and constants into InputEventMIDI #86708

Closed

Conversation

Mickeon
Copy link
Contributor

@Mickeon Mickeon commented Jan 2, 2024

Superseded by #86713 and #86716.

This PR moves OS' methods about MIDI, and the global constants into the InputEventMIDI. The new methods are static.
The previous methods and constants still exist, but are marked as deprecated.
This means the following:


Edit: These methods are currently commented out, because they refuse to compile. Will ask for help later.

Currently This PR
OS.open_midi_inputs() InputEventMIDI.open_inputs()
OS.get_connected_midi_inputs() InputEventMIDI.get_connected_inputs()
OS.close_midi_inputs() InputEventMIDI.close_inputs()
Currently This PR
MIDI_MESSAGE_NONE InputEventMIDI.MESSAGE_NONE
MIDI_MESSAGE_NOTE_ON InputEventMIDI.MESSAGE_NOTE_ON
MIDI_MESSAGE_NOTE_OFF InputEventMIDI.MESSAGE_NOTE_OFF
MIDI_MESSAGE_AFTERTOUCH InputEventMIDI.MESSAGE_AFTERTOUCH
MIDI_MESSAGE_CONTROL_CHANGE InputEventMIDI.MESSAGE_CONTROL_CHANGE
MIDI_MESSAGE_PROGRAM_CHANGE InputEventMIDI.MESSAGE_PROGRAM_CHANGE
MIDI_MESSAGE_CHANNEL_PRESSURE InputEventMIDI.MESSAGE_CHANNEL_PRESSURE
MIDI_MESSAGE_PITCH_BEND InputEventMIDI.MESSAGE_PITCH_BEND
MIDI_MESSAGE_SYSTEM_EXCLUSIVE InputEventMIDI.MESSAGE_SYSTEM_EXCLUSIVE
MIDI_MESSAGE_QUARTER_FRAME InputEventMIDI.MESSAGE_QUARTER_FRAME
MIDI_MESSAGE_SONG_POSITION_POINTER InputEventMIDI.MESSAGE_SONG_POSITION_POINTER
MIDI_MESSAGE_SONG_SELECT InputEventMIDI.MESSAGE_SONG_SELECT
MIDI_MESSAGE_TUNE_REQUEST InputEventMIDI.MESSAGE_TUNE_REQUEST
MIDI_MESSAGE_TIMING_CLOCK InputEventMIDI.MESSAGE_TIMING_CLOCK
MIDI_MESSAGE_START InputEventMIDI.MESSAGE_START
MIDI_MESSAGE_CONTINUE InputEventMIDI.MESSAGE_CONTINUE
MIDI_MESSAGE_STOP InputEventMIDI.MESSAGE_STOP
MIDI_MESSAGE_ACTIVE_SENSING InputEventMIDI.MESSAGE_ACTIVE_SENSING
MIDI_MESSAGE_SYSTEM_RESET InputEventMIDI.MESSAGE_SYSTEM_RESET

core/input/input_event.cpp Outdated Show resolved Hide resolved
core/input/input_event.h Outdated Show resolved Hide resolved
core/input/input_event.h Outdated Show resolved Hide resolved
@@ -526,8 +549,8 @@ class InputEventMIDI : public InputEvent {
void set_channel(const int p_channel);
int get_channel() const;

void set_message(const MIDIMessage p_message);
MIDIMessage get_message() const;
void set_message(const Message p_message);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this actually work? The enum values are the same but it's a different enum so it shouldn't match in GDScript and elsewhere, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean by "work". When I excluded static methods, the engine seems to compile just fine when replacing the MIDIMessage enum with Message all throughout.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So doing event.message = MIDI_MESSAGE_NONE works?

Copy link
Contributor Author

@Mickeon Mickeon Jan 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just verified in my current build (without the static methods because I must reiterate, do not compile). Yes, you can receive MIDI input, get and set the event's message just fine.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's strange, because assigning other, matching valued, enums in GDScript like that doesn't work correctly, like doing:

event.messsage = TEXTURE_REPEAT_PARENT_NODE

Throws an error as the result type is not the correct enum

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it's directly related, but I forgot to change it in the class reference XML file (message's associated enum is still MIDIMessage). I will see.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure changing the enum here preserves compatibility, we'll see what the CI says

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed up and built your code and can confirm that this does indeed not work:

event.message = MIDI_MESSAGE_NONE

It has to be:

event.message = InputEventMIDI.MESSAGE_NONE

This breaks compatibility unless you change the bound method to take the original type

@Mickeon Mickeon force-pushed the all-midi-to-InputEventMIDI branch 2 times, most recently from 5e60696 to 775e18f Compare January 2, 2024 15:12
core/input/input_event.h Outdated Show resolved Hide resolved
core/os/midi_driver.cpp Outdated Show resolved Hide resolved
@Mickeon
Copy link
Contributor Author

Mickeon commented Jan 2, 2024

I apologize for the many, many incoming merge pushes that will ensue.

@AThousandShips
Copy link
Member

Given the above issues with the property I'd suggest removing the enum related changes and keep just the moving of the MIDI driver management, that part I think makes a lot of sense to move out of OS, and is smooth to do and doesn't break anything

@Mickeon Mickeon force-pushed the all-midi-to-InputEventMIDI branch from 775e18f to a79c7c4 Compare January 2, 2024 15:25
@Mickeon Mickeon force-pushed the all-midi-to-InputEventMIDI branch from a79c7c4 to 773c608 Compare January 2, 2024 15:28
@Mickeon
Copy link
Contributor Author

Mickeon commented Jan 2, 2024

I could split the PRs in two and keep this one for the Messages. They took me way longer than the methods to transfer over, and there's some discussion to be had for how useful some of them are.

@AThousandShips
Copy link
Member

Sounds like a good idea, but unsure how to handle that one without breaking compat at all, so wouldn't be feasible for the short term or even the medium term, but worth saving it

@Mickeon
Copy link
Contributor Author

Mickeon commented Jan 2, 2024

As of currently, this does not compile specifically because of the enum referencing the other enum. So indeed, they are being problematic.

@Mickeon Mickeon closed this Jan 2, 2024
@Mickeon Mickeon deleted the all-midi-to-InputEventMIDI branch January 2, 2024 15:45
@AThousandShips
Copy link
Member

Oh yes that's because of the difference in class-ness, should be solved by just doing MESSAGE_NONE = (int)MIDIMessage::NONE,, but that does have some consequences

@AThousandShips AThousandShips removed this from the 4.x milestone Jan 2, 2024
@Mickeon
Copy link
Contributor Author

Mickeon commented Jan 2, 2024

This was an accidental removal of a branch but it's no big deal, we are splitting it in two anyway.

@Mickeon Mickeon restored the all-midi-to-InputEventMIDI branch January 2, 2024 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants