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

MIDI out device missing from config in Linux host #267

Open
Jean-Lessa opened this issue Aug 2, 2024 · 0 comments
Open

MIDI out device missing from config in Linux host #267

Jean-Lessa opened this issue Aug 2, 2024 · 0 comments

Comments

@Jean-Lessa
Copy link

Describe the bug
When configuring a machine in a Linux host with a running MIDI client (e.g. Fluidsynth), there's no "MIDI out device" dropdown under Sound Devices > Device Configuration, which can (and will) cause a segfault when playing any kind of MIDI from inside the emulated OS. See "Additional context" for the full enchilada, it's deeper than it looks.

To Reproduce

  1. Install and run any MIDI client of your preference with any kind of soundfont (e.g. fluidsynth /path/to/gm.sf2)
  2. Configure a machine with any kind of sound card, then proceed to seek any "MIDI out device" dropdown there without success
  3. Start the emulated OS anyway, install drivers and etc., then try playing any .mid file, or playing a game that outputs MIDI (e.g. Gruntz, Time Commando, etc.)
  4. He's dead, Jim

Expected behavior
Being able to see and set the MIDI out device in the config while Fluidsynth is running in the background.

Emulator configuration
Any should do as this seems to be a machine-agnostic bug, but here's mine for reference:

  • MOBO: Gigabyte GA-686BX
  • CPU: Intel Pentium II/450
  • GPU: 3DFX Voodoo 3 3000
  • Sound: Sound Blaster 16 or AWE32
  • OS: Windows 98SE

Host machine

  • OS: Debian 12 Bookworm w/ all necessary dependencies to compile the project
  • PCem vNext, cloned directly from this repo, compiled from source, dev branch, commit 2e87d35, with the command cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Release -DUSE_ALSA=ON . && ninja

Additional context
This isn't a "new" issue but rather an extension of this specific post from user flk92, who kindly provided two very simple patches that solve the problem altogether - he was fixing something else but it turns out his patch (B) also fixes this. From what I could understand by reading the code, it goes more or less like this:

  • The pointer to the MIDI device in src/sound/midi_alsa.c (*current_output) is set to NULL by default
  • The dropdown seems to only appear when there's at least one MIDI client/sink available, but the current code can't find any for some reason
  • No MIDI clients/sinks found, no dropdown, pointer remains NULL and is never set
  • Emulated OS sends a MIDI out instruction, midi_write() is called, snd_rawmidi_write() is called with the NULL pointer passed to it
  • Aaaand there's your segfault (rawmidi.c: Assertion 'rawmidi' failed or something like that)

Since his patch properly exposes ALSA's MIDI interface, the dropdown appears again in the configs and you can properly set it, thus indirectly fixing the issue in a way. The patches themselves don't work as-is right now because they're pointing to the wrong file (src/midi_alsa.c when it should be src/sound/midi_alsa.c as per the current repo's structure), but I've manually applied both patches (as in literally copy-pasted the diff by hand), recompiled the project and it works fine for me now.

I believe this might also be the cause to #251, assuming the user who opened that issue doesn't know about any of this. I've decided to post this issue specifically because:

  1. It's a quite important fix from 3 years ago that is not that easily searchable and solves a real problem I had a couple days ago (playing games specifically with the Windows General MIDI due to nostalgia)
  2. I don't know if you accept PRs, and even if you did, it's not really my code but someone else's - I just wanted to bring attention to it again because the fix is already there, maybe it was just accidentally forgotten I guess
  3. I don't use forums so this is the closest and more fitting contact I can get IMO without resorting to a lengthy email
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant