Re: need some MIDI communication clarification please
Re: need some MIDI communication clarification please
- Subject: Re: need some MIDI communication clarification please
- From: Doug Wyatt <email@hidden>
- Date: Tue, 25 May 2004 11:50:42 -0700
You can't do I/O to external devices; think of them as purely
informational objects. You do I/O with the sources and destination
MIDIEndpointRefs returned by MIDIGetSource(), MIDIGetDestination(),
etc.
CAMIDIEndpoints.cpp in our latest SDK illustrates techniques for
traversing I/O endpoints and associating them with the names of the the
external devices and their endpoints.
Doug
On May 24, 2004, at 8:32, Ken Hawkins wrote:
ok i am trying to find and talk to an external MIDI device.
i can find the correct device name by iterating i.e.
MIDIGetExternalDevices. from there i can get Sources and Endpoints via
a call to GetyMIDIEntity(...). however if i run my code i do not
recieve nor see anything sent out (using the MIDI monitor <via
xmidi.com>. can you not call work in this level? if not how can you get
the ExternalDevice names from the GetMIDIDevice(...) call? i am a bit
confused. i am also adding this snip of code:
MIDIPortRef gOutPort = NULL;
MIDIEndpointRef gDest = NULL;
int gChannel = 0;
static void processMIDIPacket(const MIDIPacketList *pktlist, void
*refCon, void *connRefCon)
{
if (gOutPort != NULL && gDest != NULL) {
MIDIPacket *packet = (MIDIPacket *)pktlist->packet; // remove const
(!)
for (int j = 0; j < pktlist->numPackets; ++j) {
for (int i = 0; i < packet->length; ++i) {
printf("X ", packet->data[i]);
// rechannelize status bytes
if (packet->data[i] >= 0x80 && packet->data[i] < 0xF0)
packet->data[i] = (packet->data[i] & 0xF0) | gChannel;
}
printf("\n");
packet = MIDIPacketNext(packet);
}
MIDISend(gOutPort, gDest, pktlist);
}
}
...
int test(int argc, char *argv[])
{
OSStatus status = -1;
// create client and ports
MIDIClientRef client = NULL;
MIDIClientCreate(CFSTR("Echodev"), NULL, NULL, &client);
NSString * externalDevName = [NSString stringWithFormat:@"%s",
argv[1]]; // hardcoded to be the first arg (TEMP)
MIDIPortRef inPort = NULL;
MIDIInputPortCreate(client, CFSTR("Input port"), processMIDIPacket,
NULL, &inPort);
MIDIOutputPortCreate(client, CFSTR("Output port"), &gOutPort);
// enumerate devices (not really related to purpose of the echo
program
// but shows how to get information about devices)
int n;
CFStringRef pname, pmanuf, pmodel;
char name[64], manuf[64], model[64];
n = MIDIGetNumberOfExternalDevices();
MIDIEntityRef entity = NULL;
for (int i = 0; i < n; ++i) {
MIDIDeviceRef dev = MIDIGetExternalDevice(i);
MIDIObjectGetStringProperty(dev, kMIDIPropertyName, &pname);
MIDIObjectGetStringProperty(dev, kMIDIPropertyManufacturer, &pmanuf);
MIDIObjectGetStringProperty(dev, kMIDIPropertyModel, &pmodel);
CFStringGetCString(pname, name, sizeof(name), 0);
CFStringGetCString(pmanuf, manuf, sizeof(manuf), 0);
CFStringGetCString(pmodel, model, sizeof(model), 0);
CFRelease(pname);
CFRelease(pmanuf);
CFRelease(pmodel);
printf("name=%s, manuf=%s, model=%s\n", name, manuf, model);
if([externalDevName isEqualToString:[NSString stringWithFormat:@"%s",
name]] == YES)
{
int entNum = MIDIDeviceGetNumberOfEntities(dev);
for (int j = 0; j < entNum; ++j) {
entity = MIDIDeviceGetEntity(dev, j);
if(entity != NULL)
{
int destNum = MIDIEntityGetNumberOfDestinations(entity);
for (int k = 0; k < destNum; ++k)
{
gDest = MIDIEntityGetDestination( entity, k);
}
int srcNum = MIDIEntityGetNumberOfSources(entity);
for (int l = 0; l < srcNum; ++l)
{
MIDIEndpointRef src = MIDIEntityGetSource( entity, l);
if(src != NULL)
{
status = MIDIPortConnectSource(inPort, src, NULL);
if (status != noErr) {
gDest = NULL;
}
}
}
}
}
}
}
if(gDest != NULL)
{
Byte buffer[1024];
for(int i = 0; i < 1024; ++i) buffer[i] = 0x00;
MIDIPacketList *pktlist = (MIDIPacketList *)buffer;
MIDIPacket *curPacket = MIDIPacketListInit(pktlist);
Byte infoRequest[] = { 0xF0, 0x00, 0x01, 0x30, 0x0B, 36, 0, 0, 0xF7
};
curPacket = MIDIPacketListAdd(pktlist, sizeof(buffer), curPacket,
time(NULL), 9, infoRequest);
status = MIDISend(gOutPort, gDest, pktlist);
}
[externalDevName release];
return status;
}
...
int main(int argc, char *argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
if( test(argc, argv) == noErr )
{
CFRunLoopRun();
}
[pool release];
return 0;
}
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.