godot icon indicating copy to clipboard operation
godot copied to clipboard

[WIP] implement ALSA seq driver

Open alcomposer opened this issue 1 year ago • 0 comments

`Regarding: https://github.com/godotengine/godot-proposals/discussions/5805

This replaces the Linux MIDI ALSA raw driver with ALSA sequencer.

Benefits of using ALSA sequencer:

  • MIDI ports are not bound, other apps can use them

  • allow timestamped midi output (when output is implemented, this makes playback of MIDI output trivial)

  • events are already in the correct MIDI event format, just send them to Godot MIDI driver

  • no need for a read loop running at 1000 fps (no mutex for reading in), we use poll(2) for events

  • able to see and patch inputs into generated Godot apps dynamically with ALSA CLI utilities, or GUI patchbay :warning: This feature is an added bonus. :pushpin: possibly a future PR should deal with naming client after project name - to be consistent with pulseaudio naming? Godot_ALSA_seq_qpwgraph_view ^ qpwgraph showing port connections.

Implementation discussion:

This driver acts identical to ALSA raw inside Godot. No change in API, or behaviour:

  • OS.open_midi_inputs() open & connect to all MIDI input devices & virtual midi ports
  • OS.get_connected_midi_inputs() discover the currently available MIDI ports. :warning: this may be different to the initial state when MIDI is opened if a device is unplugged, or added.
  • If the connected inputs are different, calling open_midi_inputs() again will add all inputs again. A game developer can make an auto-reconnect thread by watching the connected inputs manually. We may want to think about adding a signal from inside the MIDI Driver that watches inputs itself, and emits a signal when port topology has changed.

Example of connected device watcher in GDScript:

func check_inputs():
	while(running):
		var new_connected_devices = OS.get_connected_midi_inputs()
		if connected_devices != new_connected_devices:
			connected_devices = new_connected_devices
			OS.open_midi_inputs()
		print(connected_devices)
		OS.delay_msec(100)

alcomposer avatar Nov 25 '22 03:11 alcomposer