tags:

views:

213

answers:

1

How can I send MIDI messages out from a C++ program and have them play the sound from the General MIDI bank?

I've looked around and there doesn't seem to be a simple answer, and my brain starts to melt after reading long manuals about CoreMIDI and things like that.

I have a simple C++ game/synthesizer project, and all I want to do is, for example, when this ball hits the floor, trigger a C4 from the Grand Piano bank. I'm fine with the majority of the program, but the integral MIDI part has so far been utterly opaque to me.

I'd like to use CoreMIDI, because it seems like it might be simplest, but something multi-platform would be a bonus.

Thank you very much for any help!

+1  A: 

Another option would be rtmidi

It's aimed to be simple and crossplatform

I've used the similar rtaudio for realtime audio i/o, and it was relatively easy to use.

You should be able to list all midi devices with the example code, then select the GM bank, and send the appropriate MIDI message (note on/off message), after you select the piano with a program change message. Wikipedia has a helpful page to get started

Emile Vrijdags
rtmidi looks perfect, but, it won't compile. I get an error about vtables. I haven't dug very deep o it but it seems to be something about compiler flags, so thank you anyway.
BonzaiRob
http://www.music.mcgill.ca/~gary/rtmidi/index.html#compiling should explain everything you need, I tried the midiprobe example code on win32 and compiled without trouble.If you ever need help from it's developer, you could try the mailinglist of the Synthesis Tool Kit (https://ccrma.stanford.edu/software/stk/) it includes this rtmidi class plus a lot of other functionality. It is also built by the same developer.
Emile Vrijdags
I used the flags, and it compiled fine, but then wouldn't link. If I included rtmidi.h in my main file, I was back to the vtables error.So I ended up #ifndef'ing more or less the whole two files, which now compiles. I'm sure there are lots of reasons that this is a bad idea.
BonzaiRob
Ok, all working now, other than actually playing sound out, so thank you.
BonzaiRob