[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[sc-dev] MIDIClient.list



Hi all,

 Here is a modified version of prListMIDIEndpoints that returns a
string with the relevant information.  I would like to include it
in the current image, unless someone has a better way to do this.
The SC side changes to MIDIClient are further below.

RJK


// altered version of function in MIDIOut.sc <thanks Jan!>
int prListMIDIEndpoints(struct VMGlobals *g, int numArgsPushed)
{ char *x, *y;
    x = (char*) malloc(1280);
    y = (char *)malloc(1280);
    sprintf(x, "");
    int numSrc = MIDIGetNumberOfSources();
//	post("numSrc %d\n",  numSrc);

        sprintf(y, "[ [ ");
        strcat(x,y);

    for (int i=0; i<numSrc; ++i) {
        MIDIEndpointRef src = MIDIGetSource(i);
		MIDIEntityRef ent;
		MIDIEndpointGetEntity(src, &ent);
		MIDIDeviceRef dev;
		MIDIEntityGetDevice(ent, &dev);

        CFStringRef devname, endname;
        MIDIObjectGetStringProperty(dev, kMIDIPropertyName, &devname);
        MIDIObjectGetStringProperty(src, kMIDIPropertyName, &endname);
        SInt32 id;
        MIDIObjectGetIntegerProperty(src, kMIDIPropertyUniqueID, &id);
		char cendname[1024], cdevname[1024];
		CFStringGetCString(devname, cdevname, 1024, kCFStringEncodingUTF8);
		CFStringGetCString(endname, cendname, 1024, kCFStringEncodingUTF8);
  //             post("in %3d   uid %8d   dev '%s'   endpt '%s'\n", i, id, cdevname, cendname);
        CFRelease(devname);
        CFRelease(endname);
        if (i + 1 == numSrc) sprintf(y," '%s %s', %8d ", cdevname, cendname,id);
        else sprintf(y," '%s %s', %8d, ", cdevname, cendname, id);
        strcat(x,y);
    }
        sprintf(y, "], [ ");
        strcat(x,y);


        int numDst = MIDIGetNumberOfDestinations();

//	post("numDst %d\n",  numDst);

    for (int i=0; i<numDst; ++i) {
        MIDIEndpointRef dst = MIDIGetDestination(i);
		MIDIEntityRef ent;
		MIDIEndpointGetEntity(dst, &ent);
		MIDIDeviceRef dev;
		MIDIEntityGetDevice(ent, &dev);

        CFStringRef devname, endname;
        MIDIObjectGetStringProperty(dev, kMIDIPropertyName, &devname);
        MIDIObjectGetStringProperty(dst, kMIDIPropertyName, &endname);
        SInt32 id;
        MIDIObjectGetIntegerProperty(dst, kMIDIPropertyUniqueID, &id);
		char cendname[1024], cdevname[1024];
		CFStringGetCString(devname, cdevname, 1024, kCFStringEncodingUTF8);
		CFStringGetCString(endname, cendname, 1024, kCFStringEncodingUTF8);
//		post("out %3d   uid %8d   dev '%s'   endpt '%s'\n", i, id, cdevname, cendname);
        CFRelease(devname);
        CFRelease(endname);
        if (i + 1 == numDst) sprintf(y," '%s %s', %8d ", cdevname, cendname,id);
        else sprintf(y," '%s %s', %8d, ", cdevname, cendname, id);
         strcat(x,y);
     }
        sprintf(y, "] ] ");
        strcat(x,y);
       ++g->sp; SetObject(g->sp,newPyrString(g->gc, x, 0, true) ); // push string onto return stack

        free(x);
        free(y);
	return errNone;
}

// now, on the language side:
+ MIDIClient {
	classvar <>sources;
	classvar <>destinations;

	*prList {
		_ListMIDIEndpoints
	}

	*list { var out;
		out = this.prList;
		out = out.interpret;
		MIDIClient.sources = out.at(0);
		MIDIClient.destinations = out.at(1);
	}
}