[SDL_mix 3.x] play *.mid

If I load a *.wav with Mix_LoadMUS, it works fine, but if I want to open a *.mid, the following error occurs when I check it with Mix_GerError.

Couldn't open timidity.cfg

How can I solve the problem?

The VLC player doesn’t work either.
But an older SDL2 program works, with exactly the same midi file

OS: Linux 64Bit

https://github.com/libsdl-org/SDL_mixer
Support for software MIDI, MOD, and Opus are not included by default because of the size of the decode libraries

1 Like

I just installed timidity.

sudo apt-get install timidity

I can now play midi with this tool.
But my SDL program still gives the error.
What still surprises me is why I can play the midis with an old SDL2_mix program.

Timidity is also activated in the CMakeCache.txt.

README says:

To play MIDI files using Timidity, you'll need to get a complete set of GUS patches from:
http://www.libsdl.org/projects/mixer/timidity/timidity.tar.gz
and unpack them in /usr/local/lib under UNIX, and C:\ under Win32.

But actually SDL_Mixer uses these paths:

#if defined(SDL_PLATFORM_WIN32)
# define TIMIDITY_CFG           "C:\\TIMIDITY\\TIMIDITY.CFG"
#else  /* unix: */
# define TIMIDITY_CFG_ETC       "/etc/timidity.cfg"
# define TIMIDITY_CFG_FREEPATS  "/etc/timidity/freepats.cfg"
#endif

and

cfg = SDL_getenv("TIMIDITY_CFG");
if(!cfg) cfg = Mix_GetTimidityCfg();

Set the path to the installed patched timidity’s cfg using the Mix_SetTimidityCfg or TIMIDITY_CFG environment variable.

It looks like the OS and SDL_mix need to be adjusted.
You wrote above that this was removed for resource reasons.
I can’t really imagine this happening, a modern PC should have enough power.
After all, Win31 already had *.mid support. And this was the case at least from the 386 onwards.

1 Like

17 MB extra is quite a bit if you consider the current size of the SDL_mixer library.

I have zero experience with midi but I noticed that the “GUS patches” has a copyright.txt that says some of the patches are only “for non-commercial use” which might be another reason why they’re not included by default.

Freepats seem to be a free alternative to the other “GUS patches” but it’s released under the GNU GPL so if it was included in SDL_mixer it would force all of SDL_mixer, and all projects that use it, to be released under the GNU GPL.

If it’s 17 MB, why is it libSDL_mixer.so and libSDL2_mixer.so and 200KB even though MIDI works there?
Or do they include something else?

You shouldn’t need anything like that just to play MIDI. Obviously the quality of the resulting synthesis will depend on the size of the wavetables, the complexity of the ADSR envelopes etc., and for the very best results it’s going to be large. But a library to play MIDI with what many would call ‘acceptable’ quality should be small enough to be included as standard, I would have thought.

I got the figure “17 MB” from looking at the uncompressed size of the “GUS patches” that the SDL_mixer page said needed to be installed.

‘GUS patches’ sounds like it’s referring to Gravis UltraSound, but whilst they may be desirable for accurate emulation of the Gravis UltraSound hardware for the IBM PC, they’re not necessary simply to play MIDI files.