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

[sc-dev] safe communication between primitives and interpreter



Hi everyone,

I don't know if anyone is using the MIDI services, below is code to return
the list of MIDIendpoints as an interpretable string.  
In particular, MIDIClient.list returns a string like:
[ [  'FastLane USB Port A', 100723893,  'FastLane USB Port B', 100723896 ], 
[  'FastLane USB Port A', 100723894,  'FastLane USB Port B', 100723897 ] ] 
Which can be interpreted and used to configure any MIDI code running in
the interpreter.

May I make this change to the main source?

RJK

#include "PyrKernel.h"
int prListMIDIEndpoints(struct VMGlobals *g, int numArgsPushed);
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;
}