Playing MIDI files?

I browsed the documentation but could not find any mention of playing MIDI files using CGE (only .wav and .ogg). Is it possible?

I know that other audio libraries can be used instead of OpenAL, but not what would be gained from that.

It must be possible to play MIDI using Pascal, as TERRA Game Engine lists that as a feature.

MIDI files are just a set of notes pitch and duration plus some additional settings or instructions. Technically speaking one can’t “play a midi file” one can read it and synthesize sound based on it. This is covered by stuff called Software Synthesizers (we aren’t speaking of Hardware Synthesizers, most of which use Software Synthesizers inside anyway nowadays :D). That means that if you play your midi file in different Software Synthesizer it would sound differently, or may not play at all. Moreover, Linux/Android don’t have a Soft Synth preinstalled by default - it should be installed manually by the user.

So the only solution to is to integrate a software synthesizer into Castle Game Engine or your specific game project. This is not something impossible. There are opensource midi synthesizers like Timidity or FluidSynth.

However, you should notice, that those are of relatively poor quality, even compared to trashy GM Microsoft Wavetable Synth. Therefore, a much, much better idea would be to use free (as in free candy) or even paid synthesizers (like trash-but-has-everything Vir2One VSTi) to convert your midi file to WAV/OGG and play it from there. We are not in 20th century anymore - we can afford 5-10 additional megabytes of HDD space to provide a (much) better sound quality. Yes, it’ll take some time to get used to some music software (like LMMS), but it dramatically pays off in quality. And, yes, I couldn’t find a proper free soft synth for myself, not even a chiptune - still my trash Yamaha PSR230 sounds better than that, I miss Korg PA80 badly :smiley:

It’s also possible to create a soft synth based on “pure CGE” - it’ll be tricky to get proper polyphony (at least 32 voices) though. Plus I’m afraid of possible memory implications, e.g. one of my favorite Native Instruments Concert Piano VSTi was a few (dozens?) Gb. This looks like a good solution for “Android virtual piano keyboard” but not for real-time synthesis inside a game.

1 Like

I didn’t realise that Linux/Android has no MIDI synth support by default. That seems like a major oversight to me.

As you’ve guessed, the main reason for using MIDI files is to keep the download and installation sizes down. I will be creating retro style games in the beginning, so multiple WAV/OGG files would likely take up more drive space than all the other files put together.

Another reason for wanting to use MIDI creation software is that it is generally more likely to include a score editor instead having piano roll style editing. I was hoping to convert classical public domain sheet music.

I used Cubasis to do this back in the 20th century, but haven’t done anything similar since. I also tried Scream Tracker and similar software around the same time but found it much harder to convert the notes to values for the event editor.

I guess I’ll have to look into MIDI to OGG conversion software and try to stick to low sample rates and mono tracks to keep the file sizes down.

Yes, that’s always happens for me. Largest is the music, then graphics, then sound, and then everything else :smiley:

If you aren’t in a rush, ping me some time later. I wanted to look into that issue (to jump off proprietary Cakewalk Sonar + proprietary VSTis into free or at least cheap tools) and I’m half-into-it, but at the moment I don’t have time to compile a guide/tutorial and to properly test the free synths I’ve downloaded.

Also don’t forget about OpenGameArt.org - they have a lot of nice resources there at free licenses.

I just purchased a license for Crescendo, as that seems to have most of the features I was looking for and is on sale until the end of the month.

I did have it on my Steam wishlist, but it never seemed to have much of a discount there. Luckily, their site came up in a Yahoo search and it is 50% off right now at $40.

It has a score editor and can export to MIDI, WAV and MP3 formats. It also supports VSTi instruments, which I’m hoping will improve the sound quality I can produce with a laptop.