Not logged inGosu Forums
Forum back to Help Search Register Login
Up Topic Gosu / Gosu Exchange / MIDI files
- By ? Date 2009-01-11 16:32

I'm developing small game using gosu with ruby and i can't play midi file. I get 'Unrecognized sound file type' whenever i try to load one. Is there any way to play them? Or maybe there are some ruby gems with that functionality?
- - By jlnr (dev) Date 2009-01-15 17:30
The problem is that FMOD seems to support MIDI only on Windows. On Linux I think it is in the hands of whoever installs SDL_mixer to enable MIDI support on the way, but contributions to show me otherwise are very welcome ;)

On OS X, I should implement support for MIDI files using the system APIs, but I have given that a low priority since you can just drag them into GarageBand and export them, then convert them into Ogg Vorbis files, which sound better or at least the same on all systems.

If you can find any Ruby libraries that can play MIDI files, please let us know. MIDI support is summarized in this issue tracker entry:
Parent - - By RunnerPack Date 2011-03-18 08:55
The gem "smf" seems to have a lot of midi-related functionality. It's probably not very useful to Gosu development, but I thought I'd mention it just in case... Here's the homepage:
Parent - - By Spooner Date 2011-03-18 15:57
Sadly, you still need to manage playing it in gosu, which you couldn't really do since you only start the individual sounds during updates, which would not be ideal; all that gem really seems to do is read/write the format, which, admittedly, is half the battle. I'm sure that the easiest way to play midi files would just be to play them in a desktop application and record them as a .ogg to load as a regular Song, which would probably not use a huge amount of file space. That method also gives support to Tracker and every other format around :P
Parent - - By RunnerPack Date 2011-03-19 19:45
Well, I think it does quite a bit more than just reading/writing MIDI files. From the description:

> Play with OSS drivers, play with spkr(4), Play on Windows, Export as .wav (very slow and very low-fi).

So it might at least have example code for accessing the MIDI interface in Linux (OSS) and Windows.
I agree, though, that the easiest method for most use cases is just to pre-synthesize, but if download size is a consideration, MIDI (MOD, IT, XM, etc.) playing would be nice. Then again, maybe some kind of installer that converts the MIDI, etc. files to OGG on the user's computer would be feasible...
Parent - By Spooner Date 2011-03-19 19:53
Ah, sorry, I didn't read far enough into the description of the library. Still, not sure it would play nicely with Gosu, though I hope to be proved wrong.

Ah yes, you could "unpack" the midi to wav to ogg, but it doesn't sound that feasible. Depends on what "very slow" actually means (it might even be as slow as conversion at playback-speed, which sort of doesn't work at all)!
Parent - By jlnr (dev) Date 2011-03-20 01:59 Edited 2011-03-20 02:52
Playing with spkr() sounds amazing and like the good old days of qbasic programming :D I think on Linux there is really only timidity because it comes with free samples for all possible MIDI instruments, and timidity is supported by SDL_mixer: (should be current for Linux unless they changed it back between Ubuntu releases, but definitely outdated on Windows—Windows played MIDI songs without error but they were just silent o_O)

Windows and Mac have better sounding system APIs. Windows I can easily add by supporting one more class in AudioAudiere.cpp. The only missing component is an implementation of Gosu::Song based on OS X' MIDI APIs.
Parent - By meustrus Date 2011-03-28 01:05
What if smf were combined with midiator:

If SMF loads the MIDI file and MIDIator creates an interface to whatever system API is present, all that's needed is a bridge. A MIDI playing engine based on these two gems could be a separate thread from Gosu as long as the interface is well thought out and the engine never makes calls to Gosu, only the other way around.
Up Topic Gosu / Gosu Exchange / MIDI files

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill