int32_t krdsset_p(CSOUND *csound, KREADS *p) { /* open in curdir or pathname */ char soundiname[1024]; if (csound->ISSTRCOD(*p->ifilcod)) strNcpy(soundiname, get_arg_string(csound, *p->ifilcod), 1023); else csound->strarg2name(csound, soundiname, p->ifilcod, "readk.", 0); if (p->fdch.fd != NULL) fdclose(csound, &(p->fdch)); p->fdch.fd = csound->FileOpen2(csound, &(p->f), CSFILE_STD, soundiname, "rb", "SFDIR;SSDIR", 0, 0); if (UNLIKELY(p->fdch.fd == NULL)) return csound->InitError(csound, Str("Cannot open %s"), soundiname); fdrecord(csound, &p->fdch); if ((p->timcount = (int32_t)(*p->iprd * CS_EKR)) <= 0) p->timcount = 1; p->countdown = 0; p->lasts = (char*)csound->Malloc(csound, INITSIZE); p->lasts[0] = '\0'; if (p->str->data == NULL) { p->str->data = csound->Calloc(csound, INITSIZE); p->str->size = INITSIZE; } return OK; }
int instanceOpcode_(CSOUND *csound, LINEVENT2 *p, int insname) { EVTBLK evt; int i; evt.strarg = NULL; evt.scnt = 0; evt.opcod = 'i'; evt.pcnt = p->INOCOUNT; /* pass in the memory to hold the instance after insertion */ evt.pinstance = (void *) p->inst; /* IV - Oct 31 2002: allow string argument */ if (evt.pcnt > 0) { if (insname) { evt.p[1] = csound->strarg2insno(csound, ((STRINGDAT*) p->args[0])->data, 1); evt.strarg = NULL; evt.scnt = 0; } else { if (ISSTRCOD(*p->args[0])) { evt.p[1] = csound->strarg2insno(csound, get_arg_string(csound, *p->args[0]), 1); } else evt.p[1] = *p->args[0]; evt.strarg = NULL; evt.scnt = 0; } for (i = 2; i <= evt.pcnt; i++) evt.p[i] = *p->args[i-1]; } if (insert_score_event_at_sample(csound, &evt, csound->icurTime) != 0) return csound->PerfError(csound, p->h.insdshead, Str("instance: error creating event")); return OK; }
int32_t kdmpset_p(CSOUND *csound, KDUMP *p) { /* open in curdir or pathname */ char soundoname[1024]; if (UNLIKELY((p->format = (int32_t)*p->iformat) < 1 || p->format > 8)) { return csound->InitError(csound, Str("unknown format request")); } if (UNLIKELY(p->format == 2 || p->format == 3)) { return csound->InitError(csound, Str("alaw and ulaw not implemented here")); } if (csound->ISSTRCOD(*p->ifilcod)) strNcpy(soundoname, get_arg_string(csound, *p->ifilcod), 1023); else csound->strarg2name(csound, soundoname, p->ifilcod, "dumpk.", 0); if (p->fdch.fd != NULL) fdclose(csound, &(p->fdch)); p->fdch.fd = csound->FileOpen2(csound, &(p->f), CSFILE_STD, soundoname, "wb", "", dumpf_format_table[p->format], 0); if (UNLIKELY(p->fdch.fd == NULL)) return csound->InitError(csound, Str("Cannot open %s"), soundoname); fdrecord(csound, &p->fdch); if ((p->timcount = (int32_t)(*p->iprd * CS_EKR)) <= 0) p->timcount = 1; p->countdown = p->timcount; return OK; }
int eventOpcodeI_(CSOUND *csound, LINEVENT *p, int insname, char p1) { EVTBLK evt; int i, err = 0; char opcod; memset(&evt, 0, sizeof(EVTBLK)); if(p1==0) opcod = *((STRINGDAT*) p->args[0])->data; else opcod = p1; if (UNLIKELY((opcod != 'a' && opcod != 'i' && opcod != 'q' && opcod != 'f' && opcod != 'e') /*|| ((STRINGDAT*) p->args[0])->data[1] != '\0'*/)) return csound->InitError(csound, Str(errmsg_1)); evt.strarg = NULL; evt.scnt = 0; evt.opcod = opcod; if(p->flag==1) evt.pcnt = p->argno-1; else evt.pcnt = p->INOCOUNT - 1; /* IV - Oct 31 2002: allow string argument */ if (evt.pcnt > 0) { if (insname) { if (UNLIKELY(evt.opcod != 'i' && evt.opcod != 'q')) return csound->InitError(csound, Str(errmsg_2)); evt.p[1] = csound->strarg2insno(csound,((STRINGDAT *)p->args[1])->data, 1); evt.strarg = NULL; evt.scnt = 0; for (i = 2; i <= evt.pcnt; i++) evt.p[i] = *p->args[i]; } else { evt.strarg = NULL; evt.scnt = 0; if (ISSTRCOD(*p->args[1])) { evt.p[1] = csound->strarg2insno(csound, get_arg_string(csound, *p->args[1]), 1); } else evt.p[1] = *p->args[1]; for (i = 2; i <= evt.pcnt; i++) evt.p[i] = *p->args[i]; } } if (opcod == 'f' && (int) evt.pcnt >= 2 && evt.p[2] <= FL(0.0)) { FUNC *dummyftp; err = csound->hfgens(csound, &dummyftp, &evt, 0); } else err = insert_score_event_at_sample(csound, &evt, csound->icurTime); if (UNLIKELY(err)) csound->InitError(csound, Str("event_i: error creating '%c' event"), opcod); return (err == 0 ? OK : NOTOK); }
int eventOpcode_(CSOUND *csound, LINEVENT *p, int insname, char p1) { EVTBLK evt; int i; char opcod; memset(&evt, 0, sizeof(EVTBLK)); if (p1==0) opcod = *((STRINGDAT*) p->args[0])->data; else opcod = p1; if (UNLIKELY((opcod != 'a' && opcod != 'i' && opcod != 'q' && opcod != 'f' && opcod != 'e') /*|| ((STRINGDAT*) p->args[0])->data[1] != '\0'*/)) return csound->PerfError(csound, p->h.insdshead,Str(errmsg_1)); evt.strarg = NULL; evt.scnt = 0; evt.opcod = opcod; if (p->flag==1) evt.pcnt = p->argno-2; else evt.pcnt = p->INOCOUNT - 1; /* IV - Oct 31 2002: allow string argument */ if (evt.pcnt > 0) { if (insname) { if (UNLIKELY(evt.opcod != 'i' && evt.opcod != 'q')) return csound->PerfError(csound, p->h.insdshead,Str(errmsg_2)); evt.p[1] = csound->strarg2insno(csound, ((STRINGDAT*) p->args[1])->data, 1); evt.strarg = NULL; evt.scnt = 0; } else { if (ISSTRCOD(*p->args[1])) { evt.p[1] = csound->strarg2insno(csound, get_arg_string(csound, *p->args[1]), 1); } else evt.p[1] = *p->args[1]; evt.strarg = NULL; evt.scnt = 0; } for (i = 2; i <= evt.pcnt; i++) evt.p[i] = *p->args[i]; } if (insert_score_event_at_sample(csound, &evt, csound->icurTime) != 0) return csound->PerfError(csound, p->h.insdshead, Str("event: error creating '%c' event"), opcod); return OK; }
int32_t pvreadset_(CSOUND *csound, PVREAD *p, int32_t stringname) { char pvfilnam[256]; if (stringname==0){ if (csound->ISSTRCOD(*p->ifilno)) strNcpy(pvfilnam,get_arg_string(csound, *p->ifilno), MAXNAME); else csound->strarg2name(csound, pvfilnam, p->ifilno, "pvoc.",0); } else strNcpy(pvfilnam, ((STRINGDAT *)p->ifilno)->data, MAXNAME); if (pvocex_loadfile(csound, pvfilnam, p) == OK) { p->prFlg = 1; p->mybin = MYFLT2LRND(*p->ibin); return OK; } return NOTOK; }
char *strarg2name(CSOUND *csound, char *s, void *p, const char *baseName, int is_string) { if (is_string) { /* opcode string argument */ if (s == NULL) s = csound->Malloc(csound, strlen((char*) p) + 1); strcpy(s, (char*) p); } else if (csound->ISSTRCOD(*((MYFLT*) p))) { /* p-field string, unquote and copy */ char *s2 = get_arg_string(csound, *((MYFLT*)p)); int i = 0; //printf("strarg2name: %g %s\n", *((MYFLT*)p), s2); if (s == NULL) s = csound->Malloc(csound, strlen(s2) + 1); if (*s2 == '"') s2++; while (*s2 != '"' && *s2 != '\0') s[i++] = *(s2++); s[i] = '\0'; } else { int i = (int) ((double) *((MYFLT*) p) + (*((MYFLT*) p) >= FL(0.0) ? 0.5 : -0.5)); if (i >= 0 && i <= (int) csound->strsmax && csound->strsets != NULL && csound->strsets[i] != NULL) { if (s == NULL) s = csound->Malloc(csound, strlen(csound->strsets[i]) + 1); strcpy(s, csound->strsets[i]); } else { int n; if (s == NULL) { /* allocate +20 characters, assuming sizeof(int) <= 8 */ s = csound->Malloc(csound, n = strlen(baseName) + 21); snprintf(s, n, "%s%d", baseName, i); } else sprintf(s, "%s%d", baseName, i); /* dubious */ } } return s; }
int32_t pinit(CSOUND *csound, PINIT *p) { int32_t n; int32_t x = 1; int32_t nargs = p->OUTOCOUNT; int32_t pargs = csound->init_event->pcnt; int32_t start = (int32_t)(*p->start); /* Should check that inits exist> */ if (UNLIKELY(nargs>pargs)) csound->Warning(csound, Str("More arguments than p fields")); for (n=0; (n<nargs) && (n<=pargs-start); n++) { if (csound->ISSTRCOD(csound->init_event->p[n+start])) { ((STRINGDAT *)p->inits[n])->data = cs_strdup(csound, get_arg_string(csound, csound->init_event->p[n+start])); ((STRINGDAT *)p->inits[n])->size = strlen(((STRINGDAT *)p->inits[n])->data)+1; } else *p->inits[n] = csound->init_event->p[n+start]; x <<= 1; } return OK; }
static int get_absinsno(CSOUND *csound, TRIGINSTR *p, int stringname) { int insno; /* Get absolute instr num */ /* IV - Oct 31 2002: allow string argument for named instruments */ if (stringname) insno = (int)strarg2insno_p(csound, ((STRINGDAT*)p->args[0])->data); else if (ISSTRCOD(*p->args[0])) { char *ss = get_arg_string(csound, *p->args[0]); insno = (int)strarg2insno_p(csound, ss); } else insno = (int)FABS(*p->args[0]); /* Check that instrument is defined */ if (UNLIKELY(insno < 1 || insno > csound->engineState.maxinsno || csound->engineState.instrtxtp[insno] == NULL)) { csound->Warning(csound, Str("schedkwhen ignored. " "Instrument %d undefined\n"), insno); csound->perferrcnt++; return -1; } return insno; }
static int pconvset_(CSOUND *csound, PCONVOLVE *p, int stringname) { int channel = (*(p->channel) <= 0 ? ALLCHNLS : (int) *(p->channel)); SNDFILE *infd; SOUNDIN IRfile; MYFLT *inbuf, *fp1,*fp2; int32 i, j, read_in, part; MYFLT *IRblock; MYFLT ainput_dur, scaleFac; MYFLT partitionSize; /* IV - 2005-04-06: fixed bug: was uninitialised */ memset(&IRfile, 0, sizeof(SOUNDIN)); /* open impulse response soundfile [code derived from SAsndgetset()] */ IRfile.skiptime = FL(0.0); if (stringname==0){ if (csound->ISSTRCOD(*p->ifilno)) strncpy(IRfile.sfname,get_arg_string(csound, *p->ifilno), 511); else csound->strarg2name(csound, IRfile.sfname, p->ifilno, "soundin.",0); } else strncpy(IRfile.sfname, ((STRINGDAT *)p->ifilno)->data, 511); IRfile.sr = 0; if (UNLIKELY(channel < 1 || ((channel > 4) && (channel != ALLCHNLS)))) { return csound->InitError(csound, Str("channel request %d illegal"), channel); } IRfile.channel = channel; IRfile.analonly = 1; if (UNLIKELY((infd = csound->sndgetset(csound, &IRfile)) == NULL)) { return csound->InitError(csound, Str("pconvolve: error while impulse file")); } if (UNLIKELY(IRfile.framesrem < 0)) { csound->Warning(csound, Str("undetermined file length, " "will attempt requested duration")); ainput_dur = FL(0.0); /* This is probably wrong -- JPff */ } else { IRfile.getframes = IRfile.framesrem; if (UNLIKELY(IRfile.sr==0)) return csound->InitError(csound, Str("SR zero")); ainput_dur = (MYFLT) IRfile.getframes / IRfile.sr; } csound->Warning(csound, Str("analyzing %ld sample frames (%3.1f secs)\n"), (long) IRfile.getframes, ainput_dur); p->nchanls = (channel != ALLCHNLS ? 1 : IRfile.nchanls); if (UNLIKELY(p->nchanls != (int)p->OUTOCOUNT)) { return csound->InitError(csound, Str("PCONVOLVE: number of output channels " "not equal to input channels")); } if (UNLIKELY(IRfile.sr != CS_ESR)) { /* ## RWD suggests performing sr conversion here! */ csound->Warning(csound, Str("IR srate != orch's srate")); } /* make sure the partition size is nonzero and a power of 2 */ if (*p->partitionSize <= 0) partitionSize = csound->oparms->outbufsamps / csound->GetNchnls(csound); else partitionSize = *p->partitionSize; p->Hlen = 1; while (p->Hlen < partitionSize) p->Hlen <<= 1; p->Hlenpadded = 2*p->Hlen; /* determine the number of partitions */ p->numPartitions = CEIL((MYFLT)(IRfile.getframes) / (MYFLT)p->Hlen); /* set up FFT tables */ inbuf = (MYFLT *) csound->Malloc(csound, p->Hlen * p->nchanls * sizeof(MYFLT)); csound->AuxAlloc(csound, p->numPartitions * (p->Hlenpadded + 2) * sizeof(MYFLT) * p->nchanls, &p->H); IRblock = (MYFLT *)p->H.auxp; p->fwdsetup = csound->RealFFT2Setup(csound,p->Hlenpadded, FFT_FWD); p->invsetup = csound->RealFFT2Setup(csound,p->Hlenpadded, FFT_INV); /* form each partition and take its FFT */ for (part = 0; part < p->numPartitions; part++) { /* get the block of input samples and normalize -- soundin code handles finding the right channel */ if (UNLIKELY((read_in = csound->getsndin(csound, infd, inbuf, p->Hlen*p->nchanls, &IRfile)) <= 0)) return csound->InitError(csound, Str("PCONVOLVE: less sound than expected!")); /* take FFT of each channel */ scaleFac = csound->dbfs_to_float * csound->GetInverseRealFFTScale(csound, (int) p->Hlenpadded); for (i = 0; i < p->nchanls; i++) { fp1 = inbuf + i; fp2 = IRblock; for (j = 0; j < read_in/p->nchanls; j++) { *fp2++ = *fp1 * scaleFac; fp1 += p->nchanls; } csound->RealFFT2(csound, p->fwdsetup, IRblock); IRblock[p->Hlenpadded] = IRblock[1]; IRblock[1] = IRblock[p->Hlenpadded + 1L] = FL(0.0); IRblock += (p->Hlenpadded + 2); } } csound->Free(csound, inbuf); csound->FileClose(csound, IRfile.fd); /* allocate the buffer saving recent input samples */ csound->AuxAlloc(csound, p->Hlen * sizeof(MYFLT), &p->savedInput); p->inCount = 0; /* allocate the convolution work buffer */ csound->AuxAlloc(csound, (p->Hlenpadded+2) * sizeof(MYFLT), &p->workBuf); p->workWrite = (MYFLT *)p->workBuf.auxp + p->Hlen; /* allocate the buffer holding recent past convolutions */ csound->AuxAlloc(csound, (p->Hlenpadded+2) * p->numPartitions * p->nchanls * sizeof(MYFLT), &p->convBuf); p->curPart = 0; /* allocate circular output sample buffer */ p->outBufSiz = sizeof(MYFLT) * p->nchanls * (p->Hlen >= (int)CS_KSMPS ? p->Hlenpadded : 2*(int)CS_KSMPS); csound->AuxAlloc(csound, p->outBufSiz, &p->output); p->outRead = (MYFLT *)p->output.auxp; /* if ksmps < hlen, we have to pad initial output to prevent a possible empty ksmps pass after a few initial generated buffers. There is probably an equation to figure this out to reduce the delay, but I can't seem to figure it out */ if (p->Hlen > (int)CS_KSMPS) { p->outCount = p->Hlen + CS_KSMPS; p->outWrite = p->outRead + (p->nchanls * p->outCount); } else { p->outCount = 0; p->outWrite = p->outRead; } return OK; }
static int cvset_(CSOUND *csound, CONVOLVE *p, int stringname) { char cvfilnam[MAXNAME]; MEMFIL *mfp; MYFLT *fltp; CVSTRUCT *cvh; int siz; int32 Hlenpadded = 1, obufsiz, Hlen; uint32_t nchanls; uint32_t nsmps = CS_KSMPS; if (UNLIKELY(csound->oparms->odebug)) csound->Message(csound, CONVOLVE_VERSION_STRING); if (stringname==0){ if (csound->ISSTRCOD(*p->ifilno)) strncpy(cvfilnam,get_arg_string(csound, *p->ifilno), MAXNAME-1); else csound->strarg2name(csound, cvfilnam,p->ifilno, "convolve.",0); } else strncpy(cvfilnam, ((STRINGDAT *)p->ifilno)->data, MAXNAME-1); if ((mfp = p->mfp) == NULL || strcmp(mfp->filename, cvfilnam) != 0) { /* if file not already readin */ if (UNLIKELY((mfp = csound->ldmemfile2withCB(csound, cvfilnam, CSFTYPE_CVANAL,NULL)) == NULL)) { return csound->InitError(csound, Str("CONVOLVE cannot load %s"), cvfilnam); } } cvh = (CVSTRUCT *)mfp->beginp; if (UNLIKELY(cvh->magic != CVMAGIC)) { return csound->InitError(csound, Str("%s not a CONVOLVE file (magic %ld)"), cvfilnam, cvh->magic); } nchanls = (cvh->channel == ALLCHNLS ? cvh->src_chnls : 1); if (*p->channel == FL(0.0)) { if (LIKELY(p->OUTOCOUNT == nchanls)) p->nchanls = nchanls; else { return csound->InitError(csound, Str("CONVOLVE: output channels not equal " "to number of channels in source")); } } else { if (*p->channel <= nchanls) { if (UNLIKELY(p->OUTOCOUNT != 1)) { return csound->InitError(csound, Str("CONVOLVE: output channels not equal " "to number of channels in source")); } else p->nchanls = 1; } else { return csound->InitError(csound, Str("CONVOLVE: channel number greater than " "number of channels in source")); } } Hlen = p->Hlen = cvh->Hlen; while (Hlenpadded < 2*Hlen-1) Hlenpadded <<= 1; p->Hlenpadded = Hlenpadded; p->H = (MYFLT *) ((char *)cvh+cvh->headBsize); if ((p->nchanls == 1) && (*p->channel > 0)) p->H += (Hlenpadded + 2) * (int)(*p->channel - 1); if (UNLIKELY(cvh->samplingRate != CS_ESR)) { /* & chk the data */ csound->Warning(csound, Str("%s's srate = %8.0f, orch's srate = %8.0f"), cvfilnam, cvh->samplingRate, CS_ESR); } if (UNLIKELY(cvh->dataFormat != CVMYFLT)) { return csound->InitError(csound, Str("unsupported CONVOLVE data " "format %ld in %s"), cvh->dataFormat, cvfilnam); } /* Determine size of circular output buffer */ if (Hlen >= (int32)nsmps) obufsiz = (int32) CEIL((MYFLT) Hlen / nsmps) * nsmps; else obufsiz = (int32) CEIL(CS_KSMPS / (MYFLT) Hlen) * Hlen; siz = ((Hlenpadded + 2) + p->nchanls * ((Hlen - 1) + obufsiz) + (p->nchanls > 1 ? (Hlenpadded + 2) : 0)); if (p->auxch.auxp == NULL || p->auxch.size < siz*sizeof(MYFLT)) { /* if no buffers yet, alloc now */ csound->AuxAlloc(csound, (size_t) siz*sizeof(MYFLT), &p->auxch); fltp = (MYFLT *) p->auxch.auxp; p->fftbuf = fltp; fltp += (Hlenpadded + 2); /* and insert addresses */ p->olap = fltp; fltp += p->nchanls*(Hlen - 1); p->outbuf = fltp; fltp += p->nchanls*obufsiz; p->X = fltp; } else { fltp = (MYFLT *) p->auxch.auxp; memset(fltp, 0, sizeof(MYFLT)*siz); /* for(i=0; i < siz; i++) fltp[i] = FL(0.0); */ } p->obufsiz = obufsiz; p->outcnt = obufsiz; p->incount = 0; p->obufend = p->outbuf + obufsiz - 1; p->outhead = p->outail = p->outbuf; p->fwdsetup = csound->RealFFT2Setup(csound, Hlenpadded, FFT_FWD); p->invsetup = csound->RealFFT2Setup(csound, Hlenpadded, FFT_INV); return OK; }
int printksset(CSOUND *csound, PRINTKS *p){ return printksset_(csound, p, get_arg_string(csound, *p->ifilcod)); }
static int32_t pvsfreadset_(CSOUND *csound, PVSFREAD *p, int32_t stringname) { PVOCEX_MEMFILE pp; uint32 N; char pvfilnam[MAXNAME]; if (stringname) strNcpy(pvfilnam, ((STRINGDAT*)p->ifilno)->data, MAXNAME-1); else if (csound->ISSTRCOD(*p->ifilno)) strNcpy(pvfilnam, get_arg_string(csound, *p->ifilno), MAXNAME-1); else csound->strarg2name(csound, pvfilnam, p->ifilno, "pvoc.", 0); if (UNLIKELY(PVOCEX_LoadFile(csound, pvfilnam, &pp) != 0)) { return csound->InitError(csound, Str("Failed to load PVOC-EX file")); } p->ptr = 0; p->overlap = pp.overlap; p->winsize = pp.winsize; p->fftsize = pp.fftsize; p->wintype = pp.wintype; p->format = pp.format; p->chans = pp.chans; p->nframes = pp.nframes; p->arate = csound->esr / (MYFLT) pp.overlap; p->membase = (float*) pp.data; if (UNLIKELY(p->overlap < (int32_t)CS_KSMPS || p->overlap < 10)) return csound->InitError(csound, Str("Sliding version not yet available")); if (UNLIKELY(p->nframes <= 0)) return csound->InitError(csound, Str("pvsfread: file is empty!\n")); /* special case if only one frame - it is an impulse response */ if (UNLIKELY(p->nframes == 1)) return csound->InitError(csound, Str("pvsfread: file has only one frame " "(= impulse response).\n")); if (UNLIKELY(p->overlap < (int32_t)CS_KSMPS)) return csound->InitError(csound, Str("pvsfread: analysis frame overlap " "must be >= ksmps\n")); p->blockalign = (p->fftsize+2) * p->chans; if (UNLIKELY((*p->ichan) >= p->chans)) return csound->InitError(csound, Str("pvsfread: ichan value exceeds " "file channel count.\n")); if (UNLIKELY((int32_t) (*p->ichan) < 0)) return csound->InitError(csound, Str("pvsfread: ichan cannot be negative.\n")); N = p->fftsize; /* setup output signal */ csound->AuxAlloc(csound, (N + 2) * sizeof(float), &p->fout->frame); /* init sig with first frame from file, regardless (always zero amps, but with bin freqs) */ p->chanoffset = (int32_t) MYFLT2LRND(*p->ichan) * (N + 2); memcpy((float *) p->fout->frame.auxp, /* RWD MUST be 32bit */ (float *) pp.data + (int32_t) p->chanoffset, /* RWD MUST be 32bit */ (size_t) ((int32_t) (N + 2) * (int32_t) sizeof(float))); p->membase += p->blockalign; /* move to 2nd frame in file, as startpoint */ p->nframes--; p->fout->N = N; p->fout->overlap = p->overlap; p->fout->winsize = p->winsize; p->fout->wintype = p->wintype; p->fout->format = p->format; p->fout->framecount = 1; p->lastframe = 0; return OK; }
static int ktriginstr_(CSOUND *csound, TRIGINSTR *p, int stringname) { /* k-rate event generator */ long starttime; int i, argnum; EVTBLK evt; char name[512]; memset(&evt, 0, sizeof(EVTBLK)); if (p->timrem > 0) p->timrem--; if (*p->trigger == FL(0.0)) /* Only do something if triggered */ return OK; /* Check if mintime has changed */ if (p->prvmintim != *p->mintime) { int32 timrem = (int32) (*p->mintime * CS_EKR + FL(0.5)); if (timrem > 0) { /* Adjust countdown for new mintime */ p->timrem += timrem - p->prvktim; p->prvktim = timrem; } else p->timrem = 0; p->prvmintim = *p->mintime; } if (*p->args[0] >= FL(0.0) || ISSTRCOD(*p->args[0])) { /* Check for rate limit on event generation */ if (*p->mintime > FL(0.0) && p->timrem > 0) return OK; /* See if there are too many instances already */ if (*p->maxinst >= FL(1.0)) { INSDS *ip; int absinsno, numinst = 0; /* Count active instr instances */ absinsno = get_absinsno(csound, p, stringname); if (UNLIKELY(absinsno < 1)) return NOTOK; ip = &(csound->actanchor); while ((ip = ip->nxtact) != NULL) if (ip->insno == absinsno) numinst++; if (numinst >= (int) *p->maxinst) return OK; } } /* Create the new event */ if (stringname) { evt.p[1] = csound->strarg2insno(csound,((STRINGDAT *)p->args[0])->data, 1); evt.strarg = NULL; evt.scnt = 0; /*evt.strarg = ((STRINGDAT*)p->args[0])->data; evt.p[1] = SSTRCOD;*/ } else if (ISSTRCOD(*p->args[0])) { unquote(name, get_arg_string(csound, *p->args[0]), 512); evt.p[1] = csound->strarg2insno(csound,name, 1); evt.strarg = NULL; /* evt.strarg = name; */ evt.scnt = 0; /* evt.p[1] = SSTRCOD; */ } else { evt.strarg = NULL; evt.scnt = 0; evt.p[1] = *p->args[0]; } evt.opcod = 'i'; evt.pcnt = argnum = p->INOCOUNT - 3; /* Add current time (see note about kadjust in triginset() above) */ starttime = CS_KSMPS*(csound->global_kcounter + p->kadjust); /* Copy all arguments to the new event */ for (i = 1; i < argnum; i++) evt.p[i + 1] = *p->args[i]; /* Set start time from kwhen */ if (UNLIKELY(evt.p[2] < FL(0.0))) { evt.p[2] = FL(0.0); csound->Warning(csound, Str("schedkwhen warning: negative kwhen reset to zero")); } /* Reset min pause counter */ if (*p->mintime > FL(0.0)) p->timrem = (int32) (*p->mintime * CS_EKR + FL(0.5)); else p->timrem = 0; return (insert_score_event_at_sample(csound, &evt, starttime) == 0 ? OK : NOTOK); }