/* query posts frame, matrix, and all ascii info */ static void sdiflists_info(t_sdiflists *x) { /* What I want to Post: - information about external - filename - 1NVT - streams in file, frame/matrix types - selection - column info - framecount and timerange */ post("\n_-=-_ sdiflists -info _-=-_"); if(x->markers[0].timetag == -1) { post("sdiflists: open a file before getting info"); return; } post("filename: %s", x->filename->s_name); //size_t bytesread = 0; //int eof; SdifFClose (x->file); x->file = SdifFOpen ( x->filename->s_name, eReadFile); SdifFReadGeneralHeader (x->file); SdifFReadAllASCIIChunks (x->file); //----send all Names Values Tables out right most list outlet---- if (SdifNameValuesLIsNotEmpty(x->file->NameValues)) { x->string = SdifStringNew(); SdifListInitLoop(x->file->NameValues->NVTList); while (SdifListIsNext(x->file->NameValues->NVTList)) { x->file->NameValues->CurrNVT = (SdifNameValueTableT *) SdifListGetNext(x->file->NameValues->NVTList); SdifUInt4 iNV; SdifHashNT *pNV; SdifHashTableT *HTable; HTable = x->file->NameValues->CurrNVT->NVHT; for(iNV=0; iNV<HTable->HashSize; iNV++) for (pNV = HTable->Table[iNV]; pNV; pNV = pNV->Next) { SdifNameValueT *NameValue = (SdifNameValueT *) pNV->Data; SETSYMBOL(x->infolist , gensym(NameValue->Name)); SETSYMBOL(x->infolist + 1 , gensym(NameValue->Value)); outlet_list(x->infoout, gensym("list"), 2 , x->infolist); }//end for pNV } //end list while NVT SdifStringFree(x->string); }// end if NVT is not empty //---------------------- post 1IDS --------------------------- if ( (SdifExistUserMatrixType(x->file->MatrixTypesTable)) || (SdifExistUserFrameType(x->file->FrameTypesTable)) ) { x->string = SdifStringNew(); if ((x->file->TypeDefPass == eNotPass) || (x->file->TypeDefPass == eReadPass)) { SdifFAllMatrixTypeToSdifString(x->file, x->string); SETSYMBOL ( x->infolist , gensym( SdifSignatureToString(e1TYP)) ); SETSYMBOL ( x->infolist + 1 , gensym(x->string->str) ); outlet_list(x->infoout, gensym("list"), 2 , x->infolist); post("---- %s ----",SdifSignatureToString(e1TYP)); SdifFAllFrameTypeToSdifString(x->file, x->string); //this compiles } SdifStringFree(x->string); } if (SdifStreamIDTableGetNbData (x->file->StreamIDsTable) > 0) { x->string = SdifStringNew(); if ((x->file->StreamIDPass == eNotPass) || (x->file->StreamIDPass == eReadPass)) { SdifFAllStreamIDToSdifString(x->file, x->string); //this also undeclared in sdif.h. x->string? SETSYMBOL ( x->infolist , gensym(SdifSignatureToString(e1IDS)) ); SETSYMBOL ( x->infolist + 1 , gensym(x->string->str) ); outlet_list(x->infoout, gensym("list"), 2 , x->infolist); } SdifStringFree(x->string); } //------ output Stream ID's and corresponding Frame types -------- size_t bytesread = 0; int eof = 0; int nStream = 0; int streamIDlist[MAX_STREAMS]; int j, newStream; for(j = 0; j < MAX_STREAMS; j++) streamIDlist[j] = -1; while(!eof) { bytesread += SdifFReadFrameHeader (x->file); SdifUInt4 streamid = SdifFCurrID (x->file); SdifSignature fsig = SdifFCurrFrameSignature (x->file); newStream = 1; for(j = 0; j < MAX_STREAMS; j++) { if(streamIDlist[j] == (signed) streamid) newStream = 0; } if(newStream) { streamIDlist[nStream++] = streamid; SETSYMBOL(x->infolist , gensym("stream")); SETFLOAT(x->infolist + 1, streamid ); outlet_list(x->infoout, gensym("list"), 2 , x->infolist); SETSYMBOL(x->infolist , gensym("frametype")); SETSYMBOL (x->infolist + 1, gensym(SdifSignatureToString(fsig)) ); outlet_list(x->infoout, gensym("list"), 2 , x->infolist); } bytesread += SdifFSkipFrameData (x->file); eof = (SdifFGetSignature(x->file, &bytesread)== eEof); } //also send other useful info out rightmost list outlet SETSYMBOL(x->infolist , gensym("frames")); SETFLOAT (x->infolist + 1, (float) x->nframes); outlet_list(x->infoout, gensym("list"), 2 , x->infolist); SETSYMBOL(x->infolist , gensym("seconds")); SETFLOAT (x->infolist + 1, x->seconds ); outlet_list(x->infoout, gensym("list"), 2 , x->infolist); SETSYMBOL(x->infolist , gensym("maxlist")); SETFLOAT (x->infolist + 1, x->max_vec ); outlet_list(x->infoout, gensym("list"), 2 , x->infolist); }
int SDIFfile::readFile(const char *fileName) { SdifSignature mysig = SdifSignatureConst('1', 'T', 'R', 'C'); // char *sigstr = SdifSignatureToString(mysig); SdifFileT *file = SdifFOpen(fileName, eReadFile); if (file == NULL) return -1; SdifFReadGeneralHeader(file); SdifFReadAllASCIIChunks(file); int eof = 0; size_t bytesread = 0; while (!eof && SdifFLastError(file) == NULL) { bytesread += SdifFReadFrameHeader(file); while (!SdifFCurrFrameIsSelected(file) || SdifFCurrSignature(file) != mysig) { SdifFSkipFrameData(file); eof = SdifFGetSignature(file, &bytesread); if (eof == eEof) break; bytesread += SdifFReadFrameHeader(file); } if (!eof) { _checkFrameAlloc(); SdifSignature sig = SdifFCurrFrameSignature(file); SdifUInt4 nmatrix = SdifFCurrNbMatrix(file); SdifUInt4 streamid = SdifFCurrID(file); SdifFloat8 time = SdifFCurrTime(file); if (nmatrix != 1) { //FIXME: warn once? } for (SdifUInt4 m = 0; m < nmatrix; m++) { bytesread += SdifFReadMatrixHeader(file); if (SdifFCurrMatrixIsSelected(file)) { SdifSignature sig = SdifFCurrMatrixSignature(file); SdifDataTypeET type = SdifFCurrDataType(file); SdifInt4 nrows = SdifFCurrNbRow(file); SdifInt4 ncols = SdifFCurrNbCol(file); if (ncols < 4) { //FIXME: warn once } if (nrows > _maxSimultaneousPartials) _maxSimultaneousPartials = nrows; _frames[_numFrames] = new Frame(nrows); _frames[_numFrames]->time(time); // get direct access to partial node array PartialNode **partials = _frames[_numFrames]->partials(); _numFrames++; for (SdifInt4 row = 0; row < nrows; row++) { bytesread += SdifFReadOneRow(file); int id = (int) SdifFCurrOneRowCol(file, 1); float freq = (float) SdifFCurrOneRowCol(file, 2); float amp = (float) SdifFCurrOneRowCol(file, 3); float phase = (float) SdifFCurrOneRowCol(file, 4); for (SdifInt4 col = 5; col <= ncols; col++) SdifFCurrOneRowCol(file, col); // ignore any other cols //printf("[%ld] %f %f %f\n", index, freq, amp, phase); partials[row]->set(id, freq, amp, phase); if (id > _maxPartialID) _maxPartialID = id; } } else bytesread += SdifFSkipMatrixData(file); // ?? This is giving 4 bytes padding when the file doesn't have or need this. size_t padding = SdifFPaddingCalculate(file->Stream, bytesread); //printf("padding=%ld\n", padding); // bytesread += SdifFReadPadding(file, padding); //FIXME: this doesn't work if there is no padding. // bytesread += SdifFReadPadding(file, // SdifFPaddingCalculate(file->Stream, bytesread)); } eof = (SdifFGetSignature(file, &bytesread) == eEof); } } if (SdifFLastError(file)) { //FIXME: return -1; } SdifFClose(file); // Make a frame object for passing filtered frames to users of SDIFfile. _curFrame = new Frame(_maxSimultaneousPartials); // Make array that will cache filter decision for each partial. const int numTracks = maxPartialID() + 1; _filterPartials = new bool [numTracks]; for (int i = 0; i < numTracks; i++) _filterPartials[i] = false; _hasFile = true; return 0; }
/*in any order (accept :: is always first), allowing spaces*/ static void sdiflists_seek(t_sdiflists *x, t_floatarg gotoindex) { //check if file has been opened, -1 means first timetag was never set if(x->markers[0].timetag == -1) { post("sdiflists: open a file before seeking"); return; } x->index = (long)gotoindex; //check if index exists if( x->index >= x->nframes || gotoindex < 0) { #if DEBUG post("no index there."); #endif return; } #if DEBUG_MEM post ("index = %d , file pos = %d", x->index, x->markers[x->index].filepos); #endif t_colout *u; int i, selectedrow, selectedcol; unsigned int m; int nbrows =0; int nbcols =0; int xout = 0; int eof = 0; int col, row; float value = 0; size_t bytesread; int listsize[x->n_outs]; float timetag; //seek to index SdifFSetPos( x->file , &x->markers[x->index].filepos); //loop through while(!eof) { SdifFReadFrameHeader(x->file); timetag = SdifFCurrTime (x->file); //break once the current time has changed if( x->markers[x->index].timetag != timetag) break; outlet_float(x->timeout, timetag); /*Get the Data. If no selection is given when the file is opened, all rows/columns/matrices/frames will be obtained. */ if(SdifFCurrFrameIsSelected(x->file)) { #if DEBUG //fsig turns up 0 unless I close file and reopen in in the open function.. SdifSignature fsig = SdifFCurrFrameSignature (x->file); SdifUInt4 streamid = SdifFCurrID (x->file); post("\n frame header- Signature: '%s', timetag: %f, streamid: %d, nmatrices: %d", SdifSignatureToString(fsig),x->markers[x->index].timetag, streamid,SdifFCurrNbMatrix (x->file)); #endif //each frame can contain multiple matrices, so go through all of them for( m= 0; m < SdifFCurrNbMatrix (x->file) ; m++) { bytesread = SdifFReadMatrixHeader(x->file); //matrices not selected will be skipped, but they still need to be added to the bytesread tally if (SdifFCurrMatrixIsSelected (x->file)) { //get how many rows total, then check which ones are selected nbrows = SdifFCurrNbRow (x->file); nbcols = SdifFCurrNbCol (x->file); #if DEBUG //same problem with matrix signature as frame signature SdifDataTypeET type = SdifFCurrDataType(x->file); post("matrix header: Signature: '%s', nbrows: %d, nbcols %d, type %04x", SdifSignatureToString(SdifFCurrSignature(x->file)), nbrows, nbcols, type); #endif //go through every row and build vectors according to which column the row i sin for (selectedrow = 0, row = 0; row < nbrows; row++) { if(SdifFRowIsSelected (x->file, row)) { bytesread += SdifFReadOneRow (x->file); //put each member in the correct vector by accessing each one according to the current column //plus any previous columns from other matrices/frames for ( selectedcol= 0, col = 1, u = x->data + xout + selectedcol; col <= nbcols && xout + selectedcol < x->n_outs; col++, u++) { if(SdifFColumnIsSelected (x->file, col)) { value = SdifFCurrOneRowCol (x->file, col); SETFLOAT(u->outvec + selectedrow, value); selectedcol++; }//end if col is selected } //end for cols selectedrow++; }//end if row is selected }//end for rows //set how big each vector is that was just filled for(i = 0; i < SdifFNumColumnsSelected (x->file); i++) { listsize[xout + i] = SdifFNumRowsSelected (x->file); } //update number of columns xout += SdifFNumColumnsSelected (x->file); }//end if matrix is selected else bytesread += SdifFSkipMatrixData(x->file); SdifFReadPadding(x->file, SdifFPaddingCalculate(x->file->Stream, bytesread)); }//end for matrices in frame }// end if current frame is selected and not eof else SdifFSkipFrameData(x->file); eof = SdifFGetSignature (x->file, &bytesread) == eEof; } //end while not eof /* !! Once eof has been found, I have to close the file and reopen for the frame signatures to be found. someone please tell me why this is.. */ if(eof) { SdifFClose (x->file); x->file = SdifFOpen ( x->filename->s_name, eReadFile); SdifFReadGeneralHeader (x->file); SdifFReadAllASCIIChunks (x->file); eof = SdifFCurrSignature(x->file) == eEmptySignature; } #if DEBUG if (SdifFLastError (x->file)) { error(" in sdiflists_seek() "); } #endif // send out columns of rows, preserving right to left order for (i = x->n_outs, u = x->data + i; u--, i--;) outlet_list(u->out, gensym("list"),listsize[i], u->outvec); }