Skip to content

Instantly share code, notes, and snippets.

@nickdowell
Created January 23, 2013 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickdowell/4612285 to your computer and use it in GitHub Desktop.
Save nickdowell/4612285 to your computer and use it in GitHub Desktop.
#include <assert.h>
#include <CoreMIDI/CoreMIDI.h>
char buffer[1024];
MIDIClientRef client = 0;
MIDIEndpointRef endpoint = 0;
MIDIPacketList *packetList = (void *)buffer;
MIDIPacket *packet = 0;
MIDIPortRef port = 0;
void timer_callback(CFRunLoopTimerRef timer, void *info)
{
OSStatus status;
unsigned char msg[3];
MIDIPacket *packet = MIDIPacketListInit(packetList);
msg[0] = 0xb0; msg[1] = 101; msg[2] = 0; packet = MIDIPacketListAdd(packetList, sizeof(buffer), packet, 0, sizeof(msg), msg);
msg[0] = 0xb0; msg[1] = 100; msg[2] = 0; packet = MIDIPacketListAdd(packetList, sizeof(buffer), packet, 0, sizeof(msg), msg);
msg[0] = 0xb0; msg[1] = 6; msg[2] = 24; packet = MIDIPacketListAdd(packetList, sizeof(buffer), packet, 0, sizeof(msg), msg);
status = MIDIReceived(endpoint, packetList); assert(status == noErr);
}
int main(int argc, const char * argv[])
{
OSStatus status;
status = MIDIClientCreate(CFSTR("Virtual MIDI Source"), NULL, NULL, &client); assert(status == noErr);
status = MIDISourceCreate(client, CFSTR("Virtual MIDI Source"), &endpoint); assert(status == noErr);
status = MIDIOutputPortCreate(client, CFSTR("Virtual MIDI Source"), &port); assert(status == noErr);
CFRunLoopTimerRef timer = CFRunLoopTimerCreate(0, 0, 5, 0, 0, &timer_callback, 0);
CFRunLoopAddTimer(CFRunLoopGetCurrent(), timer, kCFRunLoopCommonModes);
CFRunLoopRun();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment