Пример #1
0
void PerformOSCBundle(int inSize, char* inData, PyrObject *replyObj, int inPortNum)
{
	// convert all data to arrays

	int64 oscTime = OSCtime(inData + 8);
	double seconds = OSCToElapsedTime(oscTime);

	VMGlobals *g = gMainVMGlobals;
	char *data = inData + 16;
	char* dataEnd = inData + inSize;
	while (data < dataEnd) {
		int32 msgSize = OSCint(data);
		data += sizeof(int32);
		if (IsBundle(data))
		{
			PerformOSCBundle(msgSize, data, replyObj, inPortNum);
		}
		else // is a message
		{
			++g->sp; SetObject(g->sp, g->process);
			++g->sp; SetFloat(g->sp, seconds);
			++g->sp; SetObject(g->sp, replyObj);
			++g->sp; SetInt(g->sp, inPortNum);

			PyrObject *arrayObj = ConvertOSCMessage(msgSize, data);
			++g->sp; SetObject(g->sp, arrayObj);
			runInterpreter(g, s_recvoscmsg, 5);
		}
		data += msgSize;
	}
}
Пример #2
0
void PerformOSCBundle(int inSize, char* inData, PyrObject *replyObj)
{
    // convert all data to arrays

    int64 oscTime = OSCtime(inData + 8);
    double seconds = OSCToElapsedTime(oscTime);

    VMGlobals *g = gMainVMGlobals;
    ++g->sp; SetObject(g->sp, g->process);
    ++g->sp; SetFloat(g->sp, seconds);
    ++g->sp; SetObject(g->sp, replyObj);

    PyrSlot *stackBase = g->sp;
    char *data = inData + 16;
    char* dataEnd = inData + inSize;
    while (data < dataEnd) {
        int32 msgSize = OSCint(data);
        data += sizeof(int32);
        PyrObject *arrayObj = ConvertOSCMessage(msgSize, data);
        ++g->sp; SetObject(g->sp, arrayObj);
        data += msgSize;
    }

	int numMsgs = g->sp - stackBase;

    runInterpreter(g, s_recvoscbndl, 3+numMsgs);
}
Пример #3
0
PyrObject* ConvertOSCMessage(int inSize, char *inData)
{
	char *cmdName = inData;
	int cmdNameLen = OSCstrlen(cmdName);
	sc_msg_iter msg(inSize - cmdNameLen, inData + cmdNameLen);

	int numElems;
	if (inSize == cmdNameLen) {
		numElems = 0;
	} else {
		if (!msg.tags) {
			numElems = 0;
			error("OSC messages must have type tags.  %s\n", cmdName);
		} else {
			numElems = strlen(msg.tags);
		}
	}
	//post("tags %s %d\n", msg.tags, numElems);

	VMGlobals *g = gMainVMGlobals;
	PyrObject *obj = newPyrArray(g->gc, numElems + 1, 0, false);
	PyrSlot *slots = obj->slots;

	SetSymbol(slots+0, getsym(cmdName));

	for (int i=0; i<numElems; ++i) {
		char tag = msg.nextTag();
		//post("%d %c\n", i, tag);
		switch (tag) {
		case 'i' :
			SetInt(slots+i+1, msg.geti());
			break;
		case 'f' :
			SetFloat(slots+i+1, msg.getf());
			break;
		case 'd' :
			SetFloat(slots+i+1, msg.getd());
			break;
		case 's' :
			SetSymbol(slots+i+1, getsym(msg.gets()));
			//post("sym '%s'\n", slots[i+1].us->name);
			break;
		case 'b' : // fall through
		case 'm' :
			SetObject(slots+i+1, (PyrObject*)MsgToInt8Array(msg));
			break;
		case 'c':
			SetChar(slots+i+1, (char)msg.geti());
			break;
		case 't' :
			SetFloat(slots+i+1, OSCToElapsedTime(msg.gett()));
			break;

			// argument tags without any associated value
		case 'T' :
			SetTrue(slots+i+1);
			msg.count ++;
			break;
		case 'F' :
			SetFalse(slots+i+1);
			msg.count ++;
			break;
		case 'I' :
			SetFloat(slots+i+1, dInfinity);
			msg.count ++;
			break;
		case 'N' :
			SetNil(slots+i+1);
			msg.count ++;
			break;
			// else add the type tag as a char (jrhb 2009)
		default:
			SetChar(slots+i+1, tag);
			msg.gets();
		}
	}
	obj->size = numElems + 1;
	return obj;
}