int prTempoClock_SetTempoAtBeat(struct VMGlobals *g, int numArgsPushed) { PyrSlot *a = g->sp - 2; PyrSlot *b = g->sp - 1; PyrSlot *c = g->sp; TempoClock *clock = (TempoClock*)slotRawPtr(&slotRawObject(a)->slots[1]); if (!clock) { error("clock is not running.\n"); return errFailed; } double tempo, beat; int err = slotDoubleVal(b, &tempo); if (err) return errFailed; if (tempo <= 0.) { error("invalid tempo %g\n", tempo); return errFailed; } err = slotDoubleVal(c, &beat); if (err) return errFailed; clock->SetTempoAtBeat(tempo, beat); return errNone; }
int prFilePutFloatLE(struct VMGlobals *g, int numArgsPushed) { PyrSlot *a, *b; PyrFile *pfile; FILE *file; a = g->sp - 1; b = g->sp; pfile = (PyrFile*)slotRawObject(a); file = (FILE*)slotRawPtr(&pfile->fileptr); if (file == NULL) { dumpObjectSlot(a); return errFailed; } float val; int err = slotFloatVal(b, &val); if (err) return err; SC_IOStream<FILE*> scio(file); scio.writeFloat_le(val); return errNone; }
int prTempoClock_SetAll(struct VMGlobals *g, int numArgsPushed) { PyrSlot *a = g->sp - 3; PyrSlot *b = g->sp - 2; PyrSlot *c = g->sp - 1; PyrSlot *d = g->sp; TempoClock *clock = (TempoClock*)slotRawPtr(&slotRawObject(a)->slots[1]); if (!clock) { error("clock is not running.\n"); return errFailed; } double tempo, beat, secs; int err = slotDoubleVal(b, &tempo); if (err) return errFailed; err = slotDoubleVal(c, &beat); if (err) return errFailed; err = slotDoubleVal(d, &secs); if (err) return errFailed; clock->SetAll(tempo, beat, secs); return errNone; }
int prSFWrite(struct VMGlobals *g, int numArgsPushed) { PyrSlot *a, *b; a = g->sp - 1; b = g->sp; SNDFILE *file = (SNDFILE*)slotRawPtr(&slotRawObject(a)->slots[0]); if (!isKindOfSlot(b, class_rawarray)) return errWrongType; switch (slotRawObject(b)->obj_format) { case obj_int16 : sf_write_short(file, (short*)slotRawInt8Array(b)->b, slotRawObject(b)->size); break; case obj_int32 : sf_write_int(file, (int*)slotRawInt8Array(b)->b, slotRawObject(b)->size); break; case obj_float : sf_write_float(file, (float*)slotRawInt8Array(b)->b, slotRawObject(b)->size); break; case obj_double : sf_write_double(file, (double*)slotRawInt8Array(b)->b, slotRawObject(b)->size); break; default: error("sample format not supported.\n"); return errFailed; } return errNone; }
int prSetControlBusValues(VMGlobals *g, int numArgsPushed) { PyrSlot *a = g->sp - 2; PyrSlot *b = g->sp - 1; PyrSlot *c = g->sp; assert(IsObj(a)); PyrObject * self = slotRawObject(a); int ptrIndex = 0; PyrSlot * ptrSlot = self->slots + ptrIndex; if (NotPtr(ptrSlot)) return errFailed; if (!IsInt(b)) return errFailed; int busIndex = slotRawInt(b); if (!IsObj(c)) return errFailed; PyrObject * values = slotRawObject(c); server_shared_memory_client * client = (server_shared_memory_client*)slotRawPtr(ptrSlot); float * control_busses = client->get_control_busses() + busIndex; for (int i = 0; i != values->size; ++i) { float value; int error = slotFloatVal(values->slots + i, &value); if (error != errNone) return error; control_busses[i] = value; } return errNone; }
int prSetControlBusValue(VMGlobals *g, int numArgsPushed) { PyrSlot *a = g->sp - 2; PyrSlot *b = g->sp - 1; PyrSlot *c = g->sp; assert(IsObj(a)); PyrObject * self = slotRawObject(a); int ptrIndex = 0; PyrSlot * ptrSlot = self->slots + ptrIndex; if (NotPtr(ptrSlot)) return errFailed; if (!IsInt(b)) return errFailed; int busIndex = slotRawInt(b); if (NotPtr(ptrSlot)) return errFailed; float value; int error = slotFloatVal(c, &value); if (error != errNone) return error; server_shared_memory_client * client = (server_shared_memory_client*)slotRawPtr(ptrSlot); client->get_control_busses()[busIndex] = value; return errNone; }
int prTempoClock_Sched(struct VMGlobals *g, int numArgsPushed) { PyrSlot *a = g->sp - 2; PyrSlot *b = g->sp - 1; PyrSlot *c = g->sp; double delta, beats; int err; TempoClock *clock = (TempoClock*)slotRawPtr(&slotRawObject(a)->slots[1]); if (!clock) { error("clock is not running.\n"); return errFailed; } if (!SlotEq(&g->thread->clock, a)) { beats = clock->ElapsedBeats(); //post("shouldn't call TempoClock-sched from a different clock. Use schedAbs.\n"); //return errFailed; } else { err = slotDoubleVal(&g->thread->beats, &beats); if (err) return errNone; // return nil OK, just don't schedule } err = slotDoubleVal(b, &delta); if (err) return errNone; // return nil OK, just don't schedule beats += delta; if (beats == dInfinity) return errNone; // return nil OK, just don't schedule clock->Add(beats, c); return errNone; }
int prTempoClock_Dump(struct VMGlobals *g, int numArgsPushed) { PyrSlot *a = g->sp; TempoClock *clock = (TempoClock*)slotRawPtr(&slotRawObject(a)->slots[1]); if (clock) clock->Dump(); return errNone; }
int finalize_image_object( struct VMGlobals *g, struct PyrObject *obj ) { SharedImage *shared_image_ptr = reinterpret_cast<SharedImage*>( slotRawPtr(obj->slots) ); delete shared_image_ptr; SetNil( obj->slots+0 ); return errNone; }
static QObjectProxy* read( PyrSlot *slot ) { PyrSlot *proxySlot = slotRawObject( slot )->slots; if( IsPtr( proxySlot ) ) return (QObjectProxy*) slotRawPtr( proxySlot ); else return 0; }
int QcTreeWidget::Item::finalize( VMGlobals *g, PyrObject *obj ) { qcDebugMsg(1,"finalizing QTreeViewItem!"); if( IsPtr( obj->slots+0 ) ) { QcTreeWidget::ItemPtr *ptr = static_cast<QcTreeWidget::ItemPtr*>( slotRawPtr(obj->slots+0) ); delete ptr; } return errNone; }
HOT void returnFromBlock(VMGlobals *g) { PyrFrame *curframe; PyrFrame *returnFrame; PyrFrame *homeContext; PyrBlock *block; PyrMethod *meth; PyrMethodRaw *methraw; PyrMethodRaw *blockraw; //if (gTraceInterpreter) postfl("->returnFromBlock\n"); //printf("->returnFromBlock\n"); #ifdef GC_SANITYCHECK g->gc->SanityCheck(); CallStackSanity(g, "returnFromBlock"); #endif curframe = g->frame; //again: returnFrame = slotRawFrame(&curframe->caller); if (returnFrame) { block = slotRawBlock(&curframe->method); blockraw = METHRAW(block); g->frame = returnFrame; g->ip = (unsigned char *)slotRawPtr(&returnFrame->ip); g->block = slotRawBlock(&returnFrame->method); homeContext = slotRawFrame(&returnFrame->homeContext); meth = slotRawMethod(&homeContext->method); methraw = METHRAW(meth); slotCopy(&g->receiver, &homeContext->vars[0]); //?? g->method = meth; meth = slotRawMethod(&curframe->method); methraw = METHRAW(meth); if (!methraw->needsHeapContext) { g->gc->Free(curframe); } else { SetInt(&curframe->caller, 0); } } else { ////// this should never happen . error("return from Function at top of call stack.\n"); g->method = NULL; g->block = NULL; g->frame = NULL; g->sp = g->gc->Stack()->slots - 1; longjmp(g->escapeInterpreter, 1); } //if (gTraceInterpreter) postfl("<-returnFromBlock\n"); #ifdef GC_SANITYCHECK g->gc->SanityCheck(); CallStackSanity(g, "returnFromBlock"); #endif }
static int prNetAddr_Disconnect(VMGlobals *g, int numArgsPushed) { PyrSlot* netAddrSlot = g->sp; PyrObject* netAddrObj = slotRawObject(netAddrSlot); SC_TcpClientPort *comPort = (SC_TcpClientPort*)slotRawPtr(netAddrObj->slots + ivxNetAddr_Socket); if (comPort) comPort->Close(); return errNone; }
int prTempoClock_Free(struct VMGlobals *g, int numArgsPushed) { PyrSlot *a = g->sp; TempoClock *clock = (TempoClock*)slotRawPtr(&slotRawObject(a)->slots[1]); if (!clock) return errNone; // not running SetNil(slotRawObject(a)->slots + 1); clock->StopReq(); return errNone; }
int prFileFlush(struct VMGlobals *g, int numArgsPushed) { PyrSlot *a; PyrFile *pfile; FILE *file; a = g->sp; pfile = (PyrFile*)slotRawObject(a); file = (FILE*)slotRawPtr(&pfile->fileptr); if (file != NULL) fflush(file); return errNone; }
void PyrGC::Finalize(PyrObject *finalizer) { if (!IsPtr(finalizer->slots+0)) return; if (!IsObj(finalizer->slots+1)) return; ObjFuncPtr func = (ObjFuncPtr)slotRawPtr(&finalizer->slots[0]); PyrObject *obj = slotRawObject(&finalizer->slots[1]); //post("FINALIZE %s %p\n", slotRawSymbol(&obj->classptr->name)->name, obj); (func)(mVMGlobals, obj); SetNil(obj->slots+0); SetNil(obj->slots+1); }
int prTempoClock_ElapsedBeats(struct VMGlobals *g, int numArgsPushed) { PyrSlot *a = g->sp; TempoClock *clock = (TempoClock*)slotRawPtr(&slotRawObject(a)->slots[1]); if (!clock) { error("clock is not running.\n"); return errFailed; } SetFloat(a, clock->ElapsedBeats()); return errNone; }
int prSFClose(struct VMGlobals *g, int numArgsPushed) { PyrSlot *a; a = g->sp; SNDFILE *file = (SNDFILE*)slotRawPtr(&slotRawObject(a)->slots[0]); if (file) { sf_close(file); SetNil(slotRawObject(a)->slots + 0); } return errNone; }
int prFileClose(struct VMGlobals *g, int numArgsPushed) { PyrSlot *a; PyrFile *pfile; FILE *file; a = g->sp; pfile = (PyrFile*)slotRawObject(a); file = (FILE*)slotRawPtr(&pfile->fileptr); if (file == NULL) return errNone; SetPtr(&pfile->fileptr, NULL); if (fclose(file)) return errFailed; return errNone; }
int prSFHeaderInfoString(struct VMGlobals *g, int numArgsPushed) { PyrSlot *a; a = g->sp; SNDFILE *file = (SNDFILE*)slotRawPtr(&slotRawObject(a)->slots[0]); if(file){ static char strbuffer [(1 << 16)] ; sf_command (file, SFC_GET_LOG_INFO, strbuffer, (1 << 16)) ; PyrString *pstring = newPyrString(g->gc, strbuffer, 0, true); // post(strbuffer); SetObject(a, pstring); return errNone; } return errFailed; }
static int disconnectSharedMem(VMGlobals *g, PyrObject * object) { int ptrIndex = 0; PyrSlot * ptrSlot = object->slots + ptrIndex; if (IsNil(ptrSlot)) // already disconnected return errNone; assert(IsPtr(ptrSlot)); server_shared_memory_client * client = (server_shared_memory_client*)slotRawPtr(ptrSlot); delete client; SetNil(ptrSlot); return errNone; }
int prFilePos(struct VMGlobals *g, int numArgsPushed) { PyrSlot *a; PyrFile *pfile; FILE *file; long length; a = g->sp; pfile = (PyrFile*)slotRawObject(a); file = (FILE*)slotRawPtr(&pfile->fileptr); if (file == NULL) return errFailed; if ((length=ftell(file)) == -1) return errFailed; SetInt(a, (int)length); return errNone; }
int netAddrSend(PyrObject *netAddrObj, int msglen, char *bufptr, bool sendMsgLen) { int err, port, addr; if (IsPtr(netAddrObj->slots + ivxNetAddr_Socket)) { SC_TcpClientPort* comPort = (SC_TcpClientPort*)slotRawPtr(netAddrObj->slots + ivxNetAddr_Socket); // send TCP int tcpSocket = comPort->Socket(); if (sendMsgLen) { // send length of message in network byte-order int32 sizebuf = sc_htonl(msglen); sendall(tcpSocket, (char*)&sizebuf, sizeof(int32)); } sendall(tcpSocket, bufptr, msglen); } else { if (gUDPport == 0) return errFailed; // send UDP err = slotIntVal(netAddrObj->slots + ivxNetAddr_Hostaddr, &addr); if (err) return err; if (addr == 0) { #ifndef NO_INTERNAL_SERVER if (gInternalSynthServer.mWorld) { World_SendPacket(gInternalSynthServer.mWorld, msglen, bufptr, &localServerReplyFunc); } #endif return errNone; } err = slotIntVal(netAddrObj->slots + ivxNetAddr_PortID, &port); if (err) return err; struct sockaddr_in toaddr; makeSockAddr(toaddr, addr, port); sendallto(gUDPport->Socket(), bufptr, msglen, (sockaddr*)&toaddr, sizeof(toaddr)); } return errNone; }
int prFileGetInt8(struct VMGlobals *g, int numArgsPushed) { PyrSlot *a; PyrFile *pfile; FILE *file; int8 z; a = g->sp; pfile = (PyrFile*)slotRawObject(a); file = (FILE*)slotRawPtr(&pfile->fileptr); if (file == NULL) return errFailed; int count = (int)fread(&z, sizeof(int8), 1, file); if (count==0) SetNil(a); else SetInt(a, z); return errNone; }
int prFilePutString(struct VMGlobals *g, int numArgsPushed) { PyrSlot *a, *b; PyrFile *pfile; FILE *file; PyrString *string; a = g->sp - 1; b = g->sp; pfile = (PyrFile*)slotRawObject(a); file = (FILE*)slotRawPtr(&pfile->fileptr); if (file == NULL) return errFailed; if (NotObj(b) || slotRawObject(b)->classptr != class_string) return errWrongType; string = slotRawString(b); if (string->size) { fwrite(string->s, 1, string->size, file); } return errNone; }
int prTempoClock_SecsToBeats(struct VMGlobals *g, int numArgsPushed) { PyrSlot *a = g->sp - 1; PyrSlot *b = g->sp; TempoClock *clock = (TempoClock*)slotRawPtr(&slotRawObject(a)->slots[1]); if (!clock) { error("clock is not running.\n"); return errFailed; } double secs; int err = slotDoubleVal(b, &secs); if (err) return errFailed; SetFloat(a, clock->SecsToBeats(secs)); return errNone; }
int prFileLength(struct VMGlobals *g, int numArgsPushed) { PyrSlot * a = g->sp; PyrFile *pfile = (PyrFile*)slotRawObject(a); FILE *file = (FILE*)slotRawPtr(&pfile->fileptr); if (file == NULL) return errFailed; // preserve file position fpos_t pos; if (fgetpos(file, &pos)) return errFailed; if (fseek(file, 0, SEEK_END)) return errFailed; size_t length; length = ftell(file); if (fsetpos(file, &pos)) return errFailed; SetInt(a, (int)length); // kengo: return errNone; }
int prFileGetFloatLE(struct VMGlobals *g, int numArgsPushed) { PyrSlot *a; PyrFile *pfile; FILE *file; a = g->sp; pfile = (PyrFile*)slotRawObject(a); file = (FILE*)slotRawPtr(&pfile->fileptr); if (file == NULL) return errFailed; if (feof(file)) SetNil(a); else { SC_IOStream<FILE*> scio(file); SetFloat(a, scio.readFloat_le()); } return errNone; }
int prTempoClock_SchedAbs(struct VMGlobals *g, int numArgsPushed) { PyrSlot *a = g->sp - 2; PyrSlot *b = g->sp - 1; PyrSlot *c = g->sp; TempoClock *clock = (TempoClock*)slotRawPtr(&slotRawObject(a)->slots[1]); if (!clock) { error("clock is not running.\n"); return errFailed; } double beats; int err = slotDoubleVal(b, &beats) || (beats == dInfinity); if (err) return errNone; // return nil OK, just don't schedule clock->Add(beats, c); return errNone; }
int prSFSeek(struct VMGlobals *g, int numArgsPushed) { PyrSlot *a, *b, *c; a = g->sp - 2; b = g->sp - 1; c = g->sp; SNDFILE *file = (SNDFILE*)slotRawPtr(&slotRawObject(a)->slots[0]); int origin, offset; int err = slotIntVal(b, &offset); if (err) return err; err = slotIntVal(c, &origin); if (err) return err; sf_seek(file, offset, origin); return errNone; }