int prArray_OSCBytes(VMGlobals *g, int numArgsPushed) { PyrSlot* a = g->sp; PyrObject *array = a->uo; PyrSlot* args = array->slots; int numargs = array->size; if (numargs < 1) return errFailed; big_scpacket packet; if (IsFloat(args) || IsNil(args) || IsInt(args)) { makeSynthBundle(&packet, args, numargs, false); } else if (IsSym(args) || isKindOfSlot(args, class_string)) { makeSynthMsgWithTags(&packet, args, numargs); } else { return errWrongType; } int size = packet.size(); PyrInt8Array* obj = newPyrInt8Array(g->gc, size, 0, true); obj->size = size; memcpy(obj->b, packet.data(), size); SetObject(a, (PyrObject*)obj); //for (int i=0; i<packet.size()/4; i++) post("%d %08X\n", i, packet.buf[i]); return errNone; }
int makeSynthBundle(big_scpacket *packet, PyrSlot *slots, int size, bool useElapsed) { double time; int err; int64 oscTime; err = slotDoubleVal(slots, &time); if (!err) { if (useElapsed) { oscTime = ElapsedTimeToOSC(time); } else { oscTime = (int64)(time * kSecondsToOSC); } } else { oscTime = 1; // immediate } packet->OpenBundle(oscTime); for (int i=1; i<size; ++i) { if (isKindOfSlot(slots+i, class_array)) { PyrObject *obj = slots[i].uo; makeSynthMsgWithTags(packet, obj->slots, obj->size); } } packet->CloseBundle(); return errNone; }
int prNetAddr_MsgSize(VMGlobals *g, int numArgsPushed) { PyrSlot* args = g->sp; big_scpacket packet; int numargs = args->uo->size; if (numargs < 1) return errFailed; makeSynthMsgWithTags(&packet, args->uo->slots, numargs); SetInt(args, packet.size()); return errNone; }
int prNetAddr_SendMsg(VMGlobals *g, int numArgsPushed) { PyrSlot* netAddrSlot = g->sp - numArgsPushed + 1; PyrSlot* args = netAddrSlot + 1; big_scpacket packet; int numargs = numArgsPushed - 1; makeSynthMsgWithTags(&packet, args, numargs); //for (int i=0; i<packet.size()/4; i++) post("%d %08X\n", i, packet.buf[i]); return netAddrSend(netAddrSlot->uo, packet.size(), (char*)packet.buf); }
int prNetAddr_MsgSize(VMGlobals *g, int numArgsPushed) { PyrSlot* args = g->sp; big_scpacket packet; int numargs = slotRawObject(args)->size; if (numargs < 1) return errFailed; int error = makeSynthMsgWithTags(&packet, slotRawObject(args)->slots, numargs); if (error != errNone) return error; SetInt(args, packet.size()); return errNone; }
int prNetAddr_SendMsg(VMGlobals *g, int numArgsPushed) { PyrSlot* netAddrSlot = g->sp - numArgsPushed + 1; PyrSlot* args = netAddrSlot + 1; big_scpacket packet; int numargs = numArgsPushed - 1; int error = makeSynthMsgWithTags(&packet, args, numargs); if (error != errNone) return error; //for (int i=0; i<packet.size()/4; i++) post("%d %p\n", i, packet.buf[i]); return netAddrSend(slotRawObject(netAddrSlot), packet.size(), (char*)packet.buf); }
static int addMsgSlot(big_scpacket *packet, PyrSlot *slot) { switch (GetTag(slot)) { case tagInt : packet->addi(slotRawInt(slot)); break; case tagSym : packet->adds(slotRawSymbol(slot)->name); break; case tagObj : if (isKindOf(slotRawObject(slot), class_string)) { PyrString *stringObj = slotRawString(slot); packet->adds(stringObj->s, stringObj->size); } else if (isKindOf(slotRawObject(slot), class_int8array)) { PyrInt8Array *arrayObj = slotRawInt8Array(slot); packet->addb(arrayObj->b, arrayObj->size); } else if (isKindOf(slotRawObject(slot), class_array)) { PyrObject *arrayObj = slotRawObject(slot); big_scpacket packet2; if (arrayObj->size > 1 && isKindOfSlot(arrayObj->slots+1, class_array)) { makeSynthBundle(&packet2, arrayObj->slots, arrayObj->size, true); } else { int error = makeSynthMsgWithTags(&packet2, arrayObj->slots, arrayObj->size); if (error != errNone) return error; } packet->addb((uint8*)packet2.data(), packet2.size()); } break; case tagNil : case tagTrue : case tagFalse : case tagChar : case tagPtr : break; default : if (gUseDoubles) packet->addd(slotRawFloat(slot)); else packet->addf(slotRawFloat(slot)); break; } return errNone; }
void addMsgSlot(big_scpacket *packet, PyrSlot *slot) { switch (slot->utag) { case tagInt : packet->addi(slot->ui); break; case tagSym : packet->adds(slot->us->name); break; case tagObj : if (isKindOf(slot->uo, class_string)) { PyrString *stringObj = slot->uos; packet->adds(stringObj->s, stringObj->size); } else if (isKindOf(slot->uo, class_int8array)) { PyrInt8Array *arrayObj = slot->uob; packet->addb(arrayObj->b, arrayObj->size); } else if (isKindOf(slot->uo, class_array)) { PyrObject *arrayObj = slot->uo; big_scpacket packet2; if (arrayObj->size > 1 && isKindOfSlot(arrayObj->slots+1, class_array)) { makeSynthBundle(&packet2, arrayObj->slots, arrayObj->size, true); } else { makeSynthMsgWithTags(&packet2, arrayObj->slots, arrayObj->size); } packet->addb((uint8*)packet2.data(), packet2.size()); } break; case tagNil : case tagTrue : case tagFalse : case tagChar : case tagPtr : break; default : if (gUseDoubles) packet->addd(slot->uf); else packet->addf(slot->uf); break; } }