• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Using MIDIThruConnection.h
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using MIDIThruConnection.h


  • Subject: Re: Using MIDIThruConnection.h
  • From: Doug Wyatt <email@hidden>
  • Date: Wed, 24 Sep 2003 09:19:44 -0700

That's almost exactly what my test tool does and it works. Odd.

Source below.

Doug

__________________________

#include <stdio.h>
#include <unistd.h>
#include <CoreMIDI/CoreMIDI.h>

static char gUsage[] =
"usage: thrutest [-s source] [-d dest] [-c channelmap] [-r lownote:highnote]\n"
" [-x events:action:param] [-p]\n"
" -s source specify source by name\n"
" -d dest specify destination by name\n"
" -c channelmap 16-char string mapping MIDI channels; \n"
" 0=channel 1...F=channel 16; any other char filters out\n"
" -r lo:hi specify range of notes to pass\n"
" -p make connection persistent\n\n";

MIDIEndpointRef FindDestinationByName(char *destName)
{
CFStringRef pname;
char name[64];
int n = MIDIGetNumberOfDestinations();

for (int i = 0; i < n; ++i) {
MIDIEndpointRef dest = MIDIGetDestination(i);
MIDIObjectGetStringProperty(dest, kMIDIPropertyName, &pname);
CFStringGetCString(pname, name, sizeof(name), 0);
CFRelease(pname);
if (!strcmp(name, destName))
return dest;
}
return NULL;
}

MIDIEndpointRef FindSourceByName(char *destName)
{
CFStringRef pname;
char name[64];
int n = MIDIGetNumberOfSources();

for (int i = 0; i < n; ++i) {
MIDIEndpointRef dest = MIDIGetSource(i);
MIDIObjectGetStringProperty(dest, kMIDIPropertyName, &pname);
CFStringGetCString(pname, name, sizeof(name), 0);
CFRelease(pname);
if (!strcmp(name, destName))
return dest;
}
return NULL;
}

void usage()
{
fprintf(stderr, gUsage);
exit(1);
}

int main(int argc, char *argv[])
{
int ch;
MIDIThruConnectionRef connRef;
MIDIThruConnectionParams params;
CFDataRef data;
MIDIEndpointRef endpt;
bool persist = false;

MIDIThruConnectionParamsInitialize(&params);

while ((ch = getopt(argc, argv, "s:d:c:r:p")) != -1) {
switch (ch) {
case 's':
endpt = FindSourceByName(optarg);
if (endpt == NULL)
fprintf(stderr, "warning: source %s not found\n", optarg);
else if (params.numSources == kMIDIThruConnection_MaxEndpoints)
fprintf(stderr, "warning: too many sources; %s ignored\n", optarg);
else
params.sources[params.numSources++].endpointRef = endpt;
break;
case 'd':
endpt = FindDestinationByName(optarg);
if (endpt == NULL)
fprintf(stderr, "warning: destination %s not found\n", optarg);
else if (params.numDestinations == kMIDIThruConnection_MaxEndpoints)
fprintf(stderr, "warning: too many destinations; %s ignored\n", optarg);
else
params.destinations[params.numDestinations++].endpointRef = endpt;
break;
case 'c':
{
char *p = optarg;
while (*p) {
Byte ch;
if (isdigit(*p))
ch = *p - '0';
else if (*p >= 'A' && *p <= 'F')
ch = *p - 'A' + 10;
else if (*p >= 'a' && *p <= 'f')
ch = *p - 'a' + 10;
else
ch = 0xFF;
params.channelMap[p-optarg] = ch;
++p;
}
}
break;
case 'r':
{
int low = 0, high = 127;
sscanf(optarg, "%d:%d", &low, &high);
params.lowNote = low;
params.highNote = high;
}
break;
case 'x':
{

}
break;
case 'p':
persist = true;
break;
case '?':
default:
usage();
}
}
argc -= optind;
argv += optind;

if (params.numSources == 0) {
params.numSources = 1;
params.sources[0].endpointRef = MIDIGetSource(0);
}
if (params.numDestinations == 0) {
params.numDestinations = 1;
params.destinations[0].endpointRef = MIDIGetDestination(0);
}

CFStringRef owner = persist ? CFSTR("com.apple.thrutest") : NULL;

data = CFDataCreate(NULL, (Byte *)&params, sizeof(MIDIThruConnectionParams));
MIDIThruConnectionCreate(owner, data, &connRef);

CFRunLoopRun();

return 0;
}


On Sep 23, 2003, at 21:42, Geoff wrote:
I'm trying to make use of MIDIThruConnection.h. I can't find any documentation that says more than the header file itself. The following function is a result of my stumbling in the dark and even though I don't get an error when it runs I don't get any thruing happening.

I can still get MIDI from the source and send MIDI to the destination successfully. Perhaps there's something I'm missing? Does anybody out there know how this works?

OSStatus SetThroughConnect(MIDIEndpointRef iFromRef, MIDIEndpointRef iToRef, MIDIThruConnectionRef* oThroughRef)
{
OSStatus vError;
MIDIThruConnectionParams* vParams;
CFDataRef vDataRef;

vParams = new MIDIThruConnectionParams;
MIDIThruConnectionParamsInitialize(vParams);
vParams->numSources = one;
vParams->sources[zero].endpointRef = iFromRef;
vParams->numDestinations = one;
vParams->destinations[zero].endpointRef = iToRef;
vDataRef = CFDataCreate(NULL, (byte*)vParams, sizeof(MIDIThruConnectionParams));
vError = MIDIThruConnectionCreate(NULL, vDataRef, oThroughRef);
CFRelease(vDataRef);
delete vParams;

return vError;
}

Cheers Geoff %^>
_______________________________________________
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.

  • Follow-Ups:
    • Re: Using MIDIThruConnection.h
      • From: Geoff <email@hidden>
References: 
 >Using MIDIThruConnection.h (From: Geoff <email@hidden>)

  • Prev by Date: MTCoreAudio quickie
  • Next by Date: Audio MIDI setup
  • Previous by thread: Using MIDIThruConnection.h
  • Next by thread: Re: Using MIDIThruConnection.h
  • Index(es):
    • Date
    • Thread