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

If a midi device is in use, subsequent midi devices will not be listed in OS.get_connected_midi_inputs() #79811

Closed
Tracked by #76797
jitspoe opened this issue Jul 23, 2023 · 0 comments · Fixed by #90485

Comments

@jitspoe
Copy link
Contributor

jitspoe commented Jul 23, 2023

Godot version

4.1.stable

System information

Windows 10

Issue description

When attempting to open midi devices, if a device is in use with a lower index than one that's not in use, the list of devices will not show the second device.

E 0:00:00:0874   Gift.gd:9 @ handle_midi(): midiInOpen error: There is not enough memory available for this task.  Quit one or more applications to increase available memory, and then try again.
  <C++ Source>   drivers/winmidi/midi_driver_winmidi.cpp:54 @ open()
  <Stack Trace>  Gift.gd:9 @ handle_midi()
                 Gift.gd:62 @ _ready()
E 0:00:00:0874   Gift.gd:9 @ handle_midi(): Can't open MIDI device "Impact GX61", is it being used by another application?
  <C++ Source>   drivers/winmidi/midi_driver_winmidi.cpp:59 @ open()
  <Stack Trace>  Gift.gd:9 @ handle_midi()
                 Gift.gd:62 @ _ready()
E 0:00:00:0875   Gift.gd:9 @ handle_midi(): Index p_pos = 1 is out of bounds (size() + 1 = 1).
  <C++ Source>   ./core/templates/cowdata.h:175 @ insert()
  <Stack Trace>  Gift.gd:9 @ handle_midi()
                 Gift.gd:62 @ _ready()
E 0:00:00:0875   Gift.gd:9 @ handle_midi(): Index p_pos = 2 is out of bounds (size() + 1 = 1).
  <C++ Source>   ./core/templates/cowdata.h:175 @ insert()
  <Stack Trace>  Gift.gd:9 @ handle_midi()
                 Gift.gd:62 @ _ready()

Not sure why the error says there's not enough memory. The device is simply in use (and for some dumb reason, Windows won't allow more than one application use midi devices).

Problem code:


Error MIDIDriverWinMidi::open() {
	for (UINT i = 0; i < midiInGetNumDevs(); i++) {
		HMIDIIN midi_in;

		MMRESULT res = midiInOpen(&midi_in, i, (DWORD_PTR)read, (DWORD_PTR)this, CALLBACK_FUNCTION);
		if (res == MMSYSERR_NOERROR) {
			midiInStart(midi_in);
			connected_sources.insert(i, midi_in);
		} else {
			char err[256];
			midiInGetErrorText(res, err, 256);
			ERR_PRINT("midiInOpen error: " + String(err));

			MIDIINCAPS caps;
			res = midiInGetDevCaps(i, &caps, sizeof(MIDIINCAPS));
			if (res == MMSYSERR_NOERROR) {
				ERR_PRINT("Can't open MIDI device \"" + String(caps.szPname) + "\", is it being used by another application?");
			}
		}
	}

	return OK;
}

Note that the connected_sources only has the midi device added if there are no errors opening it, which means the device at index 0 gets skipped and inserting at index 1 or higher gives errors. The midi device still functions, but it's not possible to get the name of it.

Side note: It would be good to be able to get the list of midi devices without opening all of them, then explicitly open the desired one. In my case, I only want to listen to 1 specific device.

Steps to reproduce

In Windows, have 2 midi devices plugged in, such as keyboards. Using a DAW, such as Reaper, have the first midi device in use. Run Godot with the below script to open the and print devices. Note that the list is empty and there are errors.

Minimal reproduction project

func _ready():
	OS.open_midi_inputs()
	var midi_inputs := OS.get_connected_midi_inputs()
	print(midi_inputs)
@akien-mga akien-mga added this to the 4.3 milestone Jun 26, 2024
vgezer pushed a commit to vgezer/godot that referenced this issue Jun 27, 2024
Aims for more consistent MIDI support across Windows, MacOS, Linux and
to provide a base for adding MIDI drivers for other platforms.
Reworks the MIDIDriverALSAMidi MIDI parsing implementation as a platform
independent version in MIDIDriver::Parser.
Uses MIDIDriver::Parser to provide running status support in MacOS
MIDIDriverCoreMidi.
Collects connected input names at open, ensuring devices indices reported
in events match names in array returned from get_connected_inputs.

Fixes godotengine#77035.
Fixes godotengine#79811.

With code review changes by: A Thousand Ships (she/her)
<[email protected]>
sorascode pushed a commit to sorascode/godot-soras-version that referenced this issue Jul 22, 2024
Aims for more consistent MIDI support across Windows, MacOS, Linux and
to provide a base for adding MIDI drivers for other platforms.
Reworks the MIDIDriverALSAMidi MIDI parsing implementation as a platform
independent version in MIDIDriver::Parser.
Uses MIDIDriver::Parser to provide running status support in MacOS
MIDIDriverCoreMidi.
Collects connected input names at open, ensuring devices indices reported
in events match names in array returned from get_connected_inputs.

Fixes godotengine#77035.
Fixes godotengine#79811.

With code review changes by: A Thousand Ships (she/her)
<[email protected]>
Luis-Wong pushed a commit to Luis-Wong/godot that referenced this issue Jul 26, 2024
Aims for more consistent MIDI support across Windows, MacOS, Linux and
to provide a base for adding MIDI drivers for other platforms.
Reworks the MIDIDriverALSAMidi MIDI parsing implementation as a platform
independent version in MIDIDriver::Parser.
Uses MIDIDriver::Parser to provide running status support in MacOS
MIDIDriverCoreMidi.
Collects connected input names at open, ensuring devices indices reported
in events match names in array returned from get_connected_inputs.

Fixes godotengine#77035.
Fixes godotengine#79811.

With code review changes by: A Thousand Ships (she/her)
<[email protected]>
2nafish117 pushed a commit to 2nafish117/godot that referenced this issue Aug 5, 2024
Aims for more consistent MIDI support across Windows, MacOS, Linux and
to provide a base for adding MIDI drivers for other platforms.
Reworks the MIDIDriverALSAMidi MIDI parsing implementation as a platform
independent version in MIDIDriver::Parser.
Uses MIDIDriver::Parser to provide running status support in MacOS
MIDIDriverCoreMidi.
Collects connected input names at open, ensuring devices indices reported
in events match names in array returned from get_connected_inputs.

Fixes godotengine#77035.
Fixes godotengine#79811.

With code review changes by: A Thousand Ships (she/her)
<[email protected]>
chryan pushed a commit to chryan/godot that referenced this issue Aug 6, 2024
Aims for more consistent MIDI support across Windows, MacOS, Linux and
to provide a base for adding MIDI drivers for other platforms.
Reworks the MIDIDriverALSAMidi MIDI parsing implementation as a platform
independent version in MIDIDriver::Parser.
Uses MIDIDriver::Parser to provide running status support in MacOS
MIDIDriverCoreMidi.
Collects connected input names at open, ensuring devices indices reported
in events match names in array returned from get_connected_inputs.

Fixes godotengine#77035.
Fixes godotengine#79811.

With code review changes by: A Thousand Ships (she/her)
<[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants