static int Load_LP_File_(CSOUND *csound, const char *filnam, char **allocp, int32 *len) { FILE *f; int length = 4096; unsigned int i = 0; int j = 0; MYFLT x; char *all, *p; LPHEADER lph = {0,0,0,0,0.0,0.0,0.0,{0}}; char buff[120]; f = fopen(filnam, "r"); csoundNotifyFileOpened(csound, filnam, CSFTYPE_LPC, 0, 0); all = (char *)csound->Malloc(csound, (size_t) length); for (i=0; i<6; i++) fgetc(f); /* Skip LPANAL */ if (4!=fscanf(f, "%d %d %d %d\n", &lph.headersize, &lph.lpmagic, &lph.npoles, &lph.nvals)) return csound->InitError(csound, Str("Ill-formed LPC file\n")); fgets(buff, 120, f); lph.framrate = (MYFLT)cs_strtod(buff, &p); lph.srate = (MYFLT)cs_strtod(p, &p); lph.duration = (MYFLT)cs_strtod(p, &p); /* lph.text[0] = (char)strtol(p, &p, 0); */ /* lph.text[1] = (char)strtol(p, &p, 0); */ /* lph.text[2] = (char)strtol(p, &p, 0); */ /* lph.text[3] = (char)strtol(p, &p, 0); */ /* printf("LPHeader %d %d %d %d\n%f %f %f\n", */ /* lph.headersize, lph.lpmagic, lph.npoles, lph.nvals, */ /* lph.framrate, lph.srate, lph.duration); */ /* fscanf(f, "%f %f %f %.2x %.2x %.2x %.2x\n", */ /* &lph.framrate, &lph.srate, &lph.duration, */ /* &lph.text[0], &lph.text[1], &lph.text[2], &lph.text[3]); */ // This needs surgery if in/out different MYFLT sizes *** FIX ME *** lph.headersize = sizeof(int32)*4+sizeof(MYFLT)*3; memcpy(&all[0], &lph, lph.headersize); /* Read data until end, pack as MYFLTs */ for (i=lph.headersize;;i+=sizeof(MYFLT)) { /* Expand as necessary */ if (i>=length-sizeof(MYFLT)-8) { //printf("expanding from %p[%d] to\n", all, length); all = csound->ReAlloc(csound, all, length+=4096); //printf("i=%d %p[%d]\n", i, all, length); } x = read_ieee(f, &j); if (j) break; memcpy(&all[i], &x, sizeof(MYFLT)); } fclose(f); /* and close it */ printf("length=%d i=%u\n", length, i); *len = i; all = csound->ReAlloc(csound, all, i); *allocp = all; return 0; /* return 0 for OK */ }
static int Load_File_(CSOUND *csound, const char *filnam, char **allocp, int32 *len, int csFileType) { FILE *f; *allocp = NULL; f = fopen(filnam, "rb"); if (UNLIKELY(f == NULL)) /* if cannot open the file */ return 1; /* return 1 */ if (csFileType==CSFTYPE_HETRO) { char buff[8]; fgets(buff, 6, f); if (strcmp(buff, "HETRO")==0) { fclose(f); return Load_Het_File_(csound, filnam, allocp, len); } } else if (csFileType==CSFTYPE_CVANAL) { char buff[8]; fgets(buff, 7, f); if (strcmp(buff, "CVANAL")==0) { fclose(f); return Load_CV_File_(csound, filnam, allocp, len); } } else if (csFileType==CSFTYPE_LPC) { char buff[8]; fgets(buff, 7, f); if (strcmp(buff, "LPANAL")==0) { fclose(f); return Load_LP_File_(csound, filnam, allocp, len); } } /* notify the host if it asked */ csoundNotifyFileOpened(csound, filnam, csFileType, 0, 0); fseek(f, 0L, SEEK_END); /* then get its length */ *len = (int32) ftell(f); fseek(f, 0L, SEEK_SET); if (UNLIKELY(*len < 1L)) goto err_return; *allocp = csound->Malloc(csound, (size_t) (*len)); /* alloc as reqd */ if (UNLIKELY(fread(*allocp, (size_t) 1, /* read file in */ (size_t) (*len), f) != (size_t) (*len))) goto err_return; fclose(f); /* and close it */ return 0; /* return 0 for OK */ err_return: if (*allocp != NULL) { csound->Free(csound, *allocp); *allocp = NULL; } fclose(f); return 1; }
static int Load_CV_File_(CSOUND *csound, const char *filnam, char **allocp, int32 *len) { FILE *f; int length = 4096; unsigned int i = 0; int j = 0; MYFLT x; char *all; CVSTRUCT cvh = {0,0,0,0,0.0,0,0,0,0,{0}}; char buff[120]; char *p; f = fopen(filnam, "r"); csoundNotifyFileOpened(csound, filnam, CSFTYPE_CVANAL, 0, 0); all = (char *)csound->Malloc(csound, (size_t) length); (void)fgets(buff, 120, f); /* Skip CVANAL */ cvh.magic = CVMAGIC; p = fgets(buff, 120, f); if (p==NULL) return csoundInitError(csound, Str("Ill-formed CV file\n")); cvh.headBsize = strtol(p, &p, 10); cvh.dataBsize = strtol(p, &p, 10); cvh.dataFormat = strtol(p, &p, 10); cvh.samplingRate = (MYFLT)cs_strtod(p, &p); cvh.src_chnls = strtol(p, &p, 10); cvh.channel = strtol(p, &p, 10); cvh.Hlen = strtol(p, &p, 10); cvh.Format = strtol(p, &p, 10); /* fscanf(f, "%d %d %d %g %d %d %d %d\n", */ /* &cvh.headBsize, &cvh.dataBsize, &cvh.dataFormat, */ /* &cvh.samplingRate, &cvh.src_chnls, &cvh.channel, */ /* &cvh.Hlen, &cvh.Format); */ cvh.headBsize = sizeof(int32)*8 + sizeof(MYFLT); memcpy(&all[0], &cvh, sizeof(CVSTRUCT)); /* Read data until end, pack as MYFLTs */ for (i=sizeof(CVSTRUCT);;i+=sizeof(MYFLT)) { /* Expand as necessary */ if (i>=length-sizeof(MYFLT)-4) { //printf("expanding from %p[%d] to\n", all, length); all = csound->ReAlloc(csound, all, length+=4096); //printf("i=%d %p[%d]\n", i, all, length); } x = read_ieee(f, &j); if (j) break; memcpy(&all[i], &x, sizeof(MYFLT)); } fclose(f); /* and close it */ //printf("length=%d i=%d\n", length, i); *len = i; all = csound->ReAlloc(csound, all, i); *allocp = all; return 0; /* return 0 for OK */ }
static int Load_Het_File_(CSOUND *csound, const char *filnam, char **allocp, int32 *len) { FILE *f; int length = 1024; int i = 0; int cc; int16 x; char *all; char buffer[16]; f = fopen(filnam, "r"); csoundNotifyFileOpened(csound, filnam, CSFTYPE_HETRO, 0, 0); all = (char *)csound->Malloc(csound, (size_t) length); for (i=0; i<6; i++) fgetc(f); /* Skip HETRO */ fgets(buffer, 10, f); /* number of partials */ x = atoi(buffer); memcpy(&all[0], &x, sizeof(int16)); /* Read data until end, pack as int16 */ for (i=sizeof(int16);;i+=sizeof(int16)) { int p = 0; while ((cc=getc(f))!=',' && cc!='\n' && p<15) { if (cc == EOF) { goto out; } buffer[p++] = cc; } buffer[p]='\0'; /* Expand as necessary */ if (i>=length-4) all = csound->ReAlloc(csound, all, length+=1024); x = atoi(buffer); memcpy(&all[i], &x, sizeof(int16)); } out: fclose(f); /* and close it */ *len = i; all = csound->ReAlloc(csound, all, i); *allocp = all; return 0; /* return 0 for OK */ }
void sfopenout(CSOUND *csound) /* init for sound out */ { /* (not called if nosound) */ OPARMS *O = csound->oparms; char *s, *fName, *fullName; SF_INFO sfinfo; int osfd = 1; /* stdout */ alloc_globals(csound); if (O->outfilename == NULL) { switch (O->filetyp) { case TYP_WAV: case TYP_W64: case TYP_WAVEX: case TYP_RF64: O->outfilename = "test.wav"; break; case TYP_AIFF: O->outfilename = "test.aif"; break; case TYP_AU: O->outfilename = "test.au"; break; case TYP_PAF: O->outfilename = "test.paf"; break; case TYP_SVX: O->outfilename = "test.svx"; break; case TYP_NIST: O->outfilename = "test.sph"; break; case TYP_VOC: O->outfilename = "test.voc"; break; /* case TYP_IRCAM: */ /* O->outfilename = ""; */ /* break; */ /* case TYP_MAT4: */ /* O->outfilename = ""; */ /* break; */ /* case TYP_MAT5: */ /* O->outfilename = ""; */ /* break; */ /* case TYP_PVF: */ /* O->outfilename = ""; */ /* break; */ case TYP_XI: O->outfilename = "test.xi"; break; /* case TYP_HTK: */ /* O->outfilename = ""; */ /* break; */ /* case TYP_SDS: */ /* O->outfilename = "test.sds"; */ /* break; */ case TYP_AVR: O->outfilename = "test.avr"; break; case TYP_SD2: O->outfilename = "test.sd2"; break; case TYP_FLAC: O->outfilename = "test.flac"; break; case TYP_CAF: O->outfilename = "test.caf"; break; case TYP_OGG: O->outfilename = "test.ogg"; break; /* case TYP_MPC2K: */ /* O->outfilename = ""; */ /* break; */ default: O->outfilename = "test"; break; } } STA(sfoutname) = fName = O->outfilename; if (strcmp(fName, "stdout") == 0) { STA(pipdevout) = 1; } #ifdef PIPES else if (fName[0] == '|') { STA(pout) = _popen(fName+1, "w"); osfd = fileno(STA(pout)); STA(pipdevout) = 1; if (O->filetyp == TYP_AIFF || O->filetyp == TYP_WAV) { char fmt_name[6]; if (O->sfsampsize == 8) { strcpy(fmt_name, "AU"); O->filetyp = TYP_AU; } else { strcpy(fmt_name, "IRCAM"); O->filetyp = TYP_IRCAM; } csound->Message(csound, Str("Output file type changed to %s " "for use in pipe\n"), fmt_name); } } #endif else { csRtAudioParams parm; /* check for real time audio output, and get device name/number */ parm.devNum = check_rtaudio_name(fName, &(parm.devName), 1); if (parm.devNum >= 0) { /* set device parameters */ parm.bufSamp_SW = (unsigned int) O->outbufsamps / csound->nchnls; parm.bufSamp_HW = O->oMaxLag; parm.nChannels = csound->nchnls; parm.sampleFormat = O->outformat; parm.sampleRate = (float) csound->esr; csound->spoutran = spoutsf; /* open devaudio for output */ if (UNLIKELY(csound->playopen_callback(csound, &parm) != 0)) csoundDie(csound, Str("Failed to initialise real time audio output")); /* & redirect audio puts */ csound->audtran = csound->rtplay_callback; STA(outbufrem) = parm.bufSamp_SW * parm.nChannels; STA(pipdevout) = 2; /* no backward seeks ! */ if (O->realtime == 1) /* set realtime priority mode */ csound->realtime_audio_flag = 1; goto outset; /* no header needed */ } else if (strcmp(fName, "null") == 0) { STA(outfile) = NULL; if (csound->dither_output && csound->oparms->outformat!=AE_FLOAT && csound->oparms->outformat!=AE_DOUBLE) { if (csound->oparms->outformat==AE_SHORT) if (csound->dither_output==1) csound->audtran = writesf_dither_16; else csound->audtran = writesf_dither_u16; else if (csound->oparms->outformat==AE_CHAR) if (csound->dither_output==1) csound->audtran = writesf_dither_8; else csound->audtran = writesf_dither_u8; else csound->audtran = writesf; } else csound->audtran = writesf; goto outset; } } /* set format parameters */ memset(&sfinfo, 0, sizeof(SF_INFO)); //sfinfo.frames = 0; sfinfo.samplerate = (int) MYFLT2LRND(csound->esr); sfinfo.channels = csound->nchnls; sfinfo.format = TYPE2SF(O->filetyp) | FORMAT2SF(O->outformat); /* open file */ if (STA(pipdevout)) { STA(outfile) = sf_open_fd(osfd, SFM_WRITE, &sfinfo, 0); #ifdef PIPES if (STA(outfile) == NULL) { char fmt_name[6]; if (O->sfsampsize == 8) { if (UNLIKELY(O->filetyp == TYP_AU)) csoundDie(csound, Str("sfinit: cannot open fd %d\n%s"), osfd, Str(sf_strerror(NULL))); strcpy(fmt_name, "AU"); O->filetyp = TYP_AU; } else { if (UNLIKELY(O->filetyp == TYP_IRCAM)) csoundDie(csound, Str("sfinit: cannot open fd %d\n%s"), osfd, Str(sf_strerror(NULL))); strcpy(fmt_name, "IRCAM"); O->filetyp = TYP_IRCAM; } csound->Message(csound, Str("Output file type changed to %s " "for use in pipe\n"), fmt_name); sfinfo.format = TYPE2SF(O->filetyp) | FORMAT2SF(O->outformat); STA(outfile) = sf_open_fd(osfd, SFM_WRITE, &sfinfo, 0); } #endif if (UNLIKELY(STA(outfile) == NULL)) csoundDie(csound, Str("sfinit: cannot open fd %d\n%s"), osfd, Str(sf_strerror(NULL))); sf_command(STA(outfile), SFC_SET_VBR_ENCODING_QUALITY, &O->quality, sizeof(double)); } else { fullName = csoundFindOutputFile(csound, fName, "SFDIR"); if (UNLIKELY(fullName == NULL)) csoundDie(csound, Str("sfinit: cannot open %s"), fName); STA(sfoutname) = fullName; STA(outfile) = sf_open(fullName, SFM_WRITE, &sfinfo); if (UNLIKELY(STA(outfile) == NULL)) csoundDie(csound, Str("sfinit: cannot open %s\n%s"), fullName, sf_strerror (NULL)); sf_command(STA(outfile), SFC_SET_VBR_ENCODING_QUALITY, &O->quality, sizeof(double)); /* only notify the host if we opened a real file, not stdout or a pipe */ csoundNotifyFileOpened(csound, fullName, type2csfiletype(O->filetyp, O->outformat), 1, 0); } /* IV - Feb 22 2005: clip integer formats */ if (O->outformat != AE_FLOAT && O->outformat != AE_DOUBLE) sf_command(STA(outfile), SFC_SET_CLIPPING, NULL, SF_TRUE); sf_command(STA(outfile), SFC_SET_ADD_PEAK_CHUNK, NULL, (csound->peakchunks ? SF_TRUE : SF_FALSE)); #ifdef SOME_FINE_DAY if (csound->dither_output) { /* This may not be written yet!! */ SF_DITHER_INFO ditherInfo; memset(&ditherInfo, 0, sizeof(SF_DITHER_INFO)); ditherInfo.type = SFD_TRIANGULAR_PDF | SFD_DEFAULT_LEVEL; ditherInfo.level = 1.0; ditherInfo.name = (char*) NULL; sf_command(STA(outfile), SFC_SET_DITHER_ON_WRITE, &ditherInfo, sizeof(SF_DITHER_INFO)); } #endif if (!(O->outformat == AE_FLOAT || O->outformat == AE_DOUBLE) || (O->filetyp == TYP_WAV || O->filetyp == TYP_AIFF || O->filetyp == TYP_W64)) csound->spoutran = spoutsf; /* accumulate output */ else csound->spoutran = spoutsf_noscale; if (csound->dither_output && csound->oparms->outformat!=AE_FLOAT && csound->oparms->outformat!=AE_DOUBLE) { if (csound->oparms->outformat==AE_SHORT) csound->audtran = writesf_dither_16; else if (csound->oparms->outformat==AE_CHAR) csound->audtran = writesf_dither_8; else csound->audtran = writesf; } else csound->audtran = writesf; /* Write any tags. */ if ((s = csound->SF_id_title) != NULL && *s != '\0') sf_set_string(STA(outfile), SF_STR_TITLE, s); if ((s = csound->SF_csd_licence) == NULL || *s == '\0') s = csound->SF_id_copyright; if (s != NULL && *s != '\0') sf_set_string(STA(outfile), SF_STR_COPYRIGHT, s); else if (csound->SF_id_scopyright>=0) { char buff[256]; time_t tt = time(NULL); strftime(buff, 256, "Copyright %Y: ", gmtime(&tt)); strncat(buff,copyrightcode(csound->SF_id_scopyright), 255); buff[255] = '\0'; sf_set_string(STA(outfile), SF_STR_COPYRIGHT, buff); } if ((s = csound->SF_id_software) != NULL && *s != '\0') sf_set_string(STA(outfile), SF_STR_SOFTWARE, s); if ((s = csound->SF_id_artist) != NULL && *s != '\0') sf_set_string(STA(outfile), SF_STR_ARTIST, s); if ((s = csound->SF_id_comment) != NULL && *s != '\0') sf_set_string(STA(outfile), SF_STR_COMMENT, s); if ((s = csound->SF_id_date) != NULL && *s != '\0') sf_set_string(STA(outfile), SF_STR_DATE, s); /* file is now open */ STA(osfopen) = 1; outset: O->sfsampsize = (int) sfsampsize(FORMAT2SF(O->outformat)); /* calc outbuf size & alloc bufspace */ STA(outbufsiz) = O->outbufsamps * sizeof(MYFLT); STA(outbufp) = STA(outbuf) = csound->Malloc(csound, STA(outbufsiz)); if (STA(pipdevout) == 2) csound->Message(csound, Str("writing %d sample blks of %lu-bit floats to %s\n"), O->outbufsamps, (unsigned long) sizeof(MYFLT)*8, STA(sfoutname)); else { csound->Message(csound, Str("writing %d-byte blks of %s to %s"), O->outbufsamps * O->sfsampsize, getstrformat(O->outformat), STA(sfoutname)); if (O->sfheader == 0) csound->Message(csound, Str(" (raw)\n")); else csound->Message(csound, " (%s)\n", type2string(O->filetyp)); } STA(osfopen) = 1; STA(outbufrem) = O->outbufsamps; }
void sfopenin(CSOUND *csound) /* init for continuous soundin */ { OPARMS *O = csound->oparms; char *sfname, *fullName; SF_INFO sfinfo; int fileType = (int) TYP_RAW; int isfd = 0; /* stdin */ alloc_globals(csound); STA(inbufrem) = (uint32) 0; /* start with empty buffer */ sfname = O->infilename; if (UNLIKELY(sfname == NULL || sfname[0] == '\0')) csound->Die(csound, Str("error: no input file name")); if (strcmp(sfname, "stdin") == 0) { STA(pipdevin) = 1; } #ifdef PIPES else if (sfname[0] == '|') { STA(pin) = _popen(sfname + 1, "r"); isfd = fileno(STA(pin)); STA(pipdevin) = 1; } #endif else { csRtAudioParams parm; /* check for real time audio input, and get device name/number */ parm.devNum = check_rtaudio_name(sfname, &(parm.devName), 0); if (parm.devNum >= 0) { /* set device parameters */ parm.bufSamp_SW = (unsigned int) O->inbufsamps / (unsigned int) csound->inchnls; parm.bufSamp_HW = O->oMaxLag; parm.nChannels = csound->inchnls; parm.sampleFormat = O->informat; parm.sampleRate = (float) csound->esr; /* open devaudio for input */ if (UNLIKELY(csound->recopen_callback(csound, &parm) != 0)) csoundDie(csound, Str("Failed to initialise real time audio input")); /* & redirect audio gets */ csound->audrecv = csound->rtrecord_callback; STA(pipdevin) = 2; /* no backward seeks ! */ goto inset; /* no header processing */ } } /* open file */ memset(&sfinfo, 0, sizeof(SF_INFO)); if (STA(pipdevin)) { STA(infile) = sf_open_fd(isfd, SFM_READ, &sfinfo, 0); if (UNLIKELY(STA(infile) == NULL)) { /* open failed: possibly raw file, but cannot seek back to try again */ const char *sfError = Str(sf_strerror(NULL)); csoundDie(csound, Str("isfinit: cannot open %s -- %s"), sfname, sfError); } } else { fullName = csoundFindInputFile(csound, sfname, "SFDIR;SSDIR"); if (UNLIKELY(fullName == NULL)) /* if not found */ csoundDie(csound, Str("isfinit: cannot open %s"), sfname); STA(infile) = sf_open(fullName, SFM_READ, &sfinfo); if (STA(infile) == NULL) { /* open failed: maybe raw file ? */ memset(&sfinfo, 0, sizeof(SF_INFO)); sfinfo.samplerate = (int) MYFLT2LRND(csound->esr); sfinfo.channels = csound->nchnls; /* FIXME: assumes input sample format is same as output */ sfinfo.format = TYPE2SF(TYP_RAW) | FORMAT2SF(O->outformat); STA(infile) = sf_open(fullName, SFM_READ, &sfinfo); /* try again */ } if (UNLIKELY(STA(infile) == NULL)) { const char *sfError = Str(sf_strerror(NULL)); csoundDie(csound, Str("isfinit: cannot open %s -- %s"), fullName, sfError); } /* only notify the host if we opened a real file, not stdin or a pipe */ csoundNotifyFileOpened(csound, fullName, sftype2csfiletype(sfinfo.format), 0, 0); sfname = fullName; } /* chk the hdr codes */ if (sfinfo.samplerate != (int) MYFLT2LRND(csound->esr)) { csound->Warning(csound, Str("audio_in %s has sr = %d, orch sr = %d"), sfname, (int) sfinfo.samplerate, (int) MYFLT2LRND(csound->esr)); } if (sfinfo.channels != csound->inchnls) { csound->Warning(csound, Str("audio_in %s has %d chnls, orch %d chnls_i"), sfname, (int) sfinfo.channels, csound->inchnls); } /* Do we care about the format? Can assume float?? */ O->informat = SF2FORMAT(sfinfo.format); fileType = (int) SF2TYPE(sfinfo.format); csound->audrecv = readsf; /* will use standard audio gets */ if ((O->informat == AE_FLOAT || O->informat == AE_DOUBLE) && !(fileType == TYP_WAV || fileType == TYP_AIFF || fileType == TYP_W64)) { /* do not scale "raw" floating point files */ csound->spinrecv = sndfilein_noscale; } inset: /* calc inbufsize reqd */ STA(inbufsiz) = (unsigned) (O->inbufsamps * sizeof(MYFLT)); STA(inbuf) = (MYFLT*) csound->Calloc(csound, STA(inbufsiz)); /* alloc inbuf space */ if (STA(pipdevout) == 2) csound->Message(csound, Str("reading %d sample blks of %lu-bit floats from %s\n"), O->inbufsamps * O->sfsampsize, (unsigned long) sizeof(MYFLT)*8, sfname); else { csound->Message(csound, Str("reading %d-byte blks of %s from %s (%s)\n"), O->inbufsamps * (int) sfsampsize(FORMAT2SF(O->informat)), getstrformat(O->informat), sfname, type2string(fileType)); } STA(isfopen) = 1; }
PUBLIC int csoundCompileArgs(CSOUND *csound, int argc, char **argv) { OPARMS *O = csound->oparms; char *s; FILE *xfile = NULL; int n; int csdFound = 0; char *fileDir; if ((n = setjmp(csound->exitjmp)) != 0) { return ((n - CSOUND_EXITJMP_SUCCESS) | CSOUND_EXITJMP_SUCCESS); } if(csound->engineStatus & CS_STATE_COMP){ csound->Message(csound, Str("Csound is already started, call csoundReset()\n" "before starting again \n")); return CSOUND_ERROR; } if (--argc <= 0) { dieu(csound, Str("insufficient arguments")); } /* command line: allow orc/sco/csd name */ csound->orcname_mode = 0; /* 0: normal, 1: ignore, 2: fail */ if (argdecode(csound, argc, argv) == 0) csound->LongJmp(csound, 1); /* do not allow orc/sco/csd name in .csound6rc */ csound->orcname_mode = 2; checkOptions(csound); if (csound->delayederrormessages) { if (O->msglevel>8) csound->Warning(csound, csound->delayederrormessages); free(csound->delayederrormessages); csound->delayederrormessages = NULL; } /* check for CSD file */ if (csound->orchname == NULL) { if(csound->info_message_request) { csound->info_message_request = 0; csound->LongJmp(csound, 1); } else if(csound->oparms->daemon == 0) dieu(csound, Str("no orchestra name")); } else if (csound->use_only_orchfile == 0 && (csound->scorename == NULL || csound->scorename[0] == (char) 0) && csound->orchname[0] != '\0') { /* FIXME: allow orc/sco/csd name in CSD file: does this work ? */ csound->orcname_mode = 0; csound->Message(csound, "UnifiedCSD: %s\n", csound->orchname); /* Add directory of CSD file to search paths before orchname gets * replaced with temp orch name if default paths is enabled */ if (!O->noDefaultPaths) { fileDir = csoundGetDirectoryForPath(csound, csound->orchname); csoundAppendEnv(csound, "SADIR", fileDir); csoundAppendEnv(csound, "SSDIR", fileDir); csoundAppendEnv(csound, "INCDIR", fileDir); csoundAppendEnv(csound, "MFDIR", fileDir); csound->Free(csound, fileDir); } if(csound->orchname != NULL) { csound->csdname = csound->orchname; /* save original CSD name */ if (!read_unified_file(csound, &(csound->orchname), &(csound->scorename))) { csound->Die(csound, Str("Reading CSD failed ... stopping")); } csdFound = 1; } } /* IV - Feb 19 2005: run a second pass of argdecode so that */ /* command line options override CSD options */ /* this assumes that argdecode is safe to run multiple times */ csound->orcname_mode = 1; /* ignore orc/sco name */ argdecode(csound, argc, argv); /* should not fail this time */ /* some error checking */ if (csound->stdin_assign_flg && (csound->stdin_assign_flg & (csound->stdin_assign_flg - 1)) != 0) { csound->Die(csound, Str("error: multiple uses of stdin")); } if (csound->stdout_assign_flg && (csound->stdout_assign_flg & (csound->stdout_assign_flg - 1)) != 0) { csound->Die(csound, Str("error: multiple uses of stdout")); } /* done parsing csound6rc, CSD, and command line options */ if (csound->scorename == NULL && csound->scorestr==NULL) { /* No scorename yet */ csound->scorestr = corfile_create_r("f0 800000000000.0\n"); corfile_flush(csound->scorestr); if (O->RTevents) csound->Message(csound, Str("realtime performance using dummy " "numeric scorefile\n")); } else if (!csdFound && !O->noDefaultPaths){ /* Add directory of SCO file to search paths*/ fileDir = csoundGetDirectoryForPath(csound, csound->scorename); csoundAppendEnv(csound, "SADIR", fileDir); csoundAppendEnv(csound, "SSDIR", fileDir); csoundAppendEnv(csound, "MFDIR", fileDir); csound->Free(csound, fileDir); } /* Add directory of ORC file to search paths*/ if (!csdFound && !O->noDefaultPaths) { fileDir = csoundGetDirectoryForPath(csound, csound->orchname); csoundAppendEnv(csound, "SADIR", fileDir); csoundAppendEnv(csound, "SSDIR", fileDir); csoundAppendEnv(csound, "MFDIR", fileDir); csound->Free(csound, fileDir); } if (csound->orchstr==NULL && csound->orchname) { /* does not deal with search paths */ csound->Message(csound, Str("orchname: %s\n"), csound->orchname); csound->orchstr = copy_to_corefile(csound, csound->orchname, NULL, 0); if (csound->orchstr==NULL) csound->Die(csound, Str("Failed to open input file - %s\n"), csound->orchname); corfile_puts("\n#exit\n", csound->orchstr); corfile_putc('\0', csound->orchstr); corfile_putc('\0', csound->orchstr); //csound->orchname = NULL; } if (csound->xfilename != NULL) csound->Message(csound, "xfilename: %s\n", csound->xfilename); csoundLoadExternals(csound); /* load plugin opcodes */ /* VL: added this also to csoundReset() in csound.c */ if (csoundInitModules(csound) != 0) csound->LongJmp(csound, 1); if(csoundCompileOrc(csound, NULL) != 0){ if(csound->oparms->daemon == 0) csoundDie(csound, Str("cannot compile orchestra")); else { /* VL -- 21-10-13 Csound does not need to die on failure to compile. It can carry on, because new instruments can be compiled again */ csound->Warning(csound, Str("cannot compile orchestra.")); csound->Warning(csound, Str("Csound will start with no instruments")); } } csound->modules_loaded = 1; s = csoundQueryGlobalVariable(csound, "_RTMIDI"); if (csound->enableHostImplementedMIDIIO == 1) { if (s == NULL) { s = "hostbased"; } else { strcpy(s, "hostbased"); } csoundSetConfigurationVariable(csound,"rtmidi", s); } /* IV - Jan 28 2005 */ print_benchmark_info(csound, Str("end of orchestra compile")); if (!csoundYield(csound)) return -1; /* IV - Oct 31 2002: now we can read and sort the score */ if (csound->scorename != NULL && (n = strlen(csound->scorename)) > 4 && /* if score ?.srt or ?.xtr */ (!strcmp(csound->scorename + (n - 4), ".srt") || !strcmp(csound->scorename + (n - 4), ".xtr"))) { csound->Message(csound, Str("using previous %s\n"), csound->scorename); //playscore = sortedscore = csound->scorename; /* use that one */ csound->scorestr = NULL; csound->scorestr = copy_to_corefile(csound, csound->scorename, NULL, 1); } else { //sortedscore = NULL; if (csound->scorestr==NULL) { csound->scorestr = copy_to_corefile(csound, csound->scorename, NULL, 1); if (csound->scorestr==NULL) csoundDie(csound, Str("cannot open scorefile %s"), csound->scorename); } csound->Message(csound, Str("sorting score ...\n")); scsortstr(csound, csound->scorestr); if (csound->keep_tmp) { FILE *ff = fopen("score.srt", "w"); fputs(corfile_body(csound->scstr), ff); fclose(ff); } } if (csound->xfilename != NULL) { /* optionally extract */ if (!(xfile = fopen(csound->xfilename, "r"))) csoundDie(csound, Str("cannot open extract file %s"),csound->xfilename); csoundNotifyFileOpened(csound, csound->xfilename, CSFTYPE_EXTRACT_PARMS, 0, 0); csound->Message(csound, Str(" ... extracting ...\n")); scxtract(csound, csound->scstr, xfile); fclose(xfile); csound->tempStatus &= ~csPlayScoMask; } csound->Message(csound, Str("\t... done\n")); /* copy sorted score name */ O->playscore = csound->scstr; /* IV - Jan 28 2005 */ print_benchmark_info(csound, Str("end of score sort")); if (O->syntaxCheckOnly) { csound->Message(csound, Str("Syntax check completed.\n")); return CSOUND_EXITJMP_SUCCESS; } /* open MIDI output (moved here from argdecode) */ if (O->Midioutname != NULL && O->Midioutname[0] == (char) '\0') O->Midioutname = NULL; if (O->FMidioutname != NULL && O->FMidioutname[0] == (char) '\0') O->FMidioutname = NULL; if (O->Midioutname != NULL || O->FMidioutname != NULL) openMIDIout(csound); return CSOUND_SUCCESS; }