I'm out of ideas. In my test setup MidiKeys can play my external synth. No CoreMIDI code I've written can. The 'MIDI Out' led on my M-Audio Uno flashes at the right moments but no sound. Below is bare-bones code that cycles through the possible destinations and does a note down and an un-note down once a second. Can anyone see what I'm doing wrong?
Byte data_dn[] = { 0x90, 0x29, 0x80 };
Byte data_up[] = { 0x90, 0x29, 0x00 };
static OSStatus sendOnOff(MIDIEndpointRef endpointRef)
{
MIDITimeStamp timeStamp = 0; // AudioGetCurrentHostTime();
MIDIPacketList mpl;
MIDIPacket *mp;
OSStatus ret = 0;
struct timespec waitime = { 1, 0 };
mp = MIDIPacketListInit(&mpl);
mp = MIDIPacketListAdd(&mpl, sizeof(mpl), mp, timeStamp,
3, data_dn);
ret = MIDISend(gOutPort, endpointRef, &mpl);
nanosleep(&waitime, NULL);
waitime.tv_sec = 1;
mp = MIDIPacketListInit(&mpl);
mp = MIDIPacketListAdd(&mpl, sizeof(mpl), mp, timeStamp,
3, data_up);
ret = MIDISend(gOutPort, endpointRef, &mpl);
nanosleep(&waitime, NULL);
return ret;
}
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
MIDIClientRef client = 0;
MIDIClientCreate(CFSTR("MIDI Test"), NULL, NULL, &client);
MIDIOutputPortCreate(client, CFSTR("Output Port"), &gOutPort);
ItemCount count = MIDIGetNumberOfDestinations();
bool finished = NO;
MIDIEndpointRef dest;
CFStringRef pname;
char name[64];
while (!finished) {
for (int i = 0; i < count; i++) {
dest = MIDIGetDestination(i);
MIDIObjectGetStringProperty(dest, kMIDIPropertyName, &pname);
CFStringGetCString(pname, name, sizeof(name), 0);
printf("Dest Endpoint Ref = %u\n", dest);
printf("Sending note on/off to '%s'\n", name);
sendOnOff(dest);
}
}
[pool drain];
return 0;
}
FWIW Snow Leopard, 10.6.7.
Thanks
Eric