Question

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!

Was it helpful?

Solution

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

OTHER TIPS

I've written a tutorial which might help someone who comes across the same problem using CoreMIDI. It explains how to read a MIDI file and output the through an AUGraph using sound effects from a Sound Font file. It also explains how to use a virtual end point to get access to the midi messages in real-time. Here.

To do what you're looking to do you could modify the sample project I provide with the following:

result = MusicDeviceMIDIEvent ([AUSampler], midiStatus, note, velocity, 0);

Where AUSampler is a pointer to the AUSampler i.e. the start point in the AUGraph. Rather than reading from a file you could use the following command to send one MIDI note to be played.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top