/* * Public Domain 1995,1996 Timothy Butler * * THIS DOCUMENT IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * */ /* Public Domain Additions 1998 Terence Kelly * Many more chunks and tags are now decoded than were * available in the original. Anyone wishing to add additional * chunks or tags simply needs to write a callback function for that * chunk/tag and register it in the InitParser function. My additions * only print numerical values rather than the enumerated names. Anyone wishing * to add to or alter the current callback functions to include them can follow the * examples Tim wrote in the NAMES.C library file. */ /* Public Domain Additions March 2001 Graham Jones * Changed doline(), doindent() * Added about 19 of " return RIFFIO_OK;" * Deleted unused strFOURCC, entryCLT in cbStringTable() * Changed printf() statements in quite a few places. I have removed the suffixes (L,C) which were sometimes appended to long and byte sized numbers. Also corrected some format strings: Changed "%ul" to "%lu" in cbListStart() to print an unsigned long. Changed printBYTE(), printSIGNEDBYTE() which were using formats "%*uC" and "%*dC" to printf a BYTE. I removed the C's and cast the BYTE to (unsigned int) or (int). Changed "%*luL" in printSTROFFSET() to "%*ld". (STROFFSET is typdef'd as a long, not unsigned long.) Similar changes to printf format in cbInvisible(), cbTagStart(), cbInfoStart(), cbChnkLenTable() * Added code to store string table so can output strings, not just offsets in printSTROFFSET(). (This does not work for Part Names cos they're read before strings) * Added some more chunks and tags. Page Header chunk, Anchor override tag, Number of staff lines tag, Tuplet chunk, Multinode Start/End of System tags, Small size tag, Grace note tag. Hairpin chunk. * Added some names in cbInfoStart(). * Merged CALLBACK.c and NIFFDUM2.c into this file (NIFF2txt). To make distribution easier, not to improve code! * Made program output to second argument, not stdout. See below, near end. I also changed the library source in a few places: * I changed clt.c, to get it compiled, not sure what's going on here. static niffChklentabEntry _DefaultCLTEntries[]; static niffChklentabEntry _DefaultCLTEntries[100]; * In store.c I added #include and changed call of RIFFIOFileDelete() to NIFFIOFileDelete(). */ /* Notes on building and usage: (Graham Jones March 2001) Copy this file and all files in the NIFF SDK that have extensions .c or .h into one directory, apart from NIFFDUM2.c and CALLBACK.c. Compile and link. File list below. Run as: NIFF2txt.exe inputfile.nif outputfile.txt File list: chunks.c clt.c error.c fcc.c inherit.c names.c nfile.c NIFF2txt.c parse.c register.c rfile.c rwbytes.c rwniff.c rwtypes.c stack.c stbl.c stdcriff.c store.c storenif.c table.c tags.c tcbtable.c niff.h niffio.h niffiop.h riffio.h riffiop.h */ #include #include #include #include "stdcriff.h" #include "niffio.h" enum { maxstringtablesize = (64*1024) }; static char stringtablebuffer[maxstringtablesize]; static FILE *outputfp; void doindent(unsigned indent) { unsigned int i; /* Don't indent levels 0 and 1 */ if ((--indent) <= 0 ) return; for (i = 0; i < indent; i++) fprintf(outputfp, " "); } void doline(int indent) { int i; if ((--indent) < 0) indent = 0; for (i = indent * 4; i < 80; i++) fprintf(outputfp, "/"); fprintf(outputfp, "\n"); } int printSHORT(int nIndent, int nFieldWidth, SHORT h, const char *strComment) { doindent(nIndent+1); return fprintf(outputfp, "%*hd // %s\n", nFieldWidth, h, strComment); } int printSTROFFSET(int nIndent, int nFieldWidth, STROFFSET offset, const char *strComment) { doindent(nIndent+1); return fprintf(outputfp, "%*ld \"%s\" // %s\n", nFieldWidth, offset, stringtablebuffer+offset, strComment); } int printRATIONAL(int nIndent, int nFieldWidth, RATIONAL r, const char *strComment) { doindent(nIndent+1); fprintf(outputfp, "%*hd // %s numerator\n", nFieldWidth, r.numerator, strComment); doindent(nIndent+1); return fprintf(outputfp, "%*hd // %s denominator\n", nFieldWidth, r.denominator, strComment); } int printBYTE(int nIndent, int nFieldWidth, BYTE b, const char *strComment) { doindent(nIndent+1); return fprintf(outputfp, "%*u // %s\n", nFieldWidth, (unsigned int)b, strComment); } printSIGNEDBYTE(int nIndent, int nFieldWidth, SIGNEDBYTE sb, const char *strComment) { doindent(nIndent + 1); return fprintf(outputfp, "%*d // %s\n", nFieldWidth, (int)sb, strComment); } /* Print a Time-Slice type */ printTS(int nIndent, int nFieldWidth, BYTE ts, const char *strComment) { if (! NIFFIOSymbolTS(ts)) return printBYTE(nIndent, nFieldWidth, ts, strComment); doindent(nIndent + 1); return fprintf(outputfp, "%*s // %s\n", nFieldWidth, NIFFIOSymbolTS(ts), strComment); } /* Print a Clef Shape */ printCLEFSHAPE(int nIndent, int nFieldWidth, BYTE cs, const char *strComment) { if (! NIFFIOSymbolCLEFSHAPE(cs)) return printBYTE(nIndent, nFieldWidth, cs, strComment); doindent(nIndent + 1); return fprintf(outputfp, "%*s // %s\n", nFieldWidth, NIFFIOSymbolCLEFSHAPE(cs), strComment); } printSymbol( const char * (decoder(BYTE)), int nIndent, int nFieldWidth, BYTE symbol, const char *strComment) { /* Do we know about this value */ if (! decoder(symbol)) { fprintf(outputfp, "//\n"); fprintf(outputfp, "// WARNING: UNKNOWN VALUE for %s\n", strComment); fprintf(outputfp, "//\n"); return printBYTE(nIndent, nFieldWidth, symbol, strComment); } doindent(nIndent + 1); return fprintf(outputfp, "%*s // %s\n", nFieldWidth, decoder(symbol), strComment); } /* * cbListStart * =========== * Print the beginning of a list */ RIFFIOSuccess cbListStart(NIFFIOChunkContext *pctxChunk) { char strId[RIFFIO_FOURCC_LIM]; char strType[RIFFIO_FOURCC_LIM]; assert (pctxChunk); assert(pctxChunk->pnf); assert(pctxChunk->pchunk); RIFFIOFOURCCToString(pctxChunk->pchunk->fccId, strId); RIFFIOFOURCCToString(pctxChunk->pchunk->fccType, strType); doindent(pctxChunk->nLevel); doline(pctxChunk->nLevel); doindent(pctxChunk->nLevel); fprintf(outputfp, "// %s\n", NIFFIONameListType(pctxChunk->pchunk->fccType)); doindent(pctxChunk->nLevel); fprintf(outputfp, "'%s' ( '%s' // sizeData = %lu\n", strId, strType, pctxChunk->pchunk->sizeData); fprintf(outputfp, "\n"); return RIFFIO_OK; } RIFFIOSuccess cbListEnd(NIFFIOChunkContext *pctxChunk) { char strType[RIFFIO_FOURCC_LIM]; assert (pctxChunk); assert(pctxChunk->pnf); assert(pctxChunk->pchunk); RIFFIOFOURCCToString(pctxChunk->pchunk->fccType, strType); doindent(pctxChunk->nLevel); fprintf(outputfp, ")\n"); doindent(pctxChunk->nLevel); fprintf(outputfp, "// %s\n", NIFFIONameListType(pctxChunk->pchunk->fccType)); doindent(pctxChunk->nLevel); doline(pctxChunk->nLevel); fprintf(outputfp, "\n"); return RIFFIO_OK; } RIFFIOSuccess cbFormStart(NIFFIOChunkContext *pctxChunk) { char strId[RIFFIO_FOURCC_LIM]; char strType[RIFFIO_FOURCC_LIM]; assert(pctxChunk != 0); assert(pctxChunk->pnf != 0); assert(pctxChunk->pchunk != 0); RIFFIOFOURCCToString(pctxChunk->pchunk->fccId, strId); RIFFIOFOURCCToString(pctxChunk->pchunk->fccType, strType); doline(0); fprintf(outputfp, "// NIFF Form\n"); fprintf(outputfp, "'%s' ( '%s' // sizeData=%lu\n", strId, strType, pctxChunk->pchunk->sizeData); fprintf(outputfp, "\n"); return RIFFIO_OK; } RIFFIOSuccess cbFormEnd(NIFFIOChunkContext *pctxChunk) { assert (pctxChunk != 0); assert (pctxChunk->pnf != 0); assert (pctxChunk->pchunk != 0); fprintf(outputfp, ")\n"); fprintf(outputfp, "// NIFF Form End\n"); doline(0); return RIFFIO_OK; } /* * cbChunkStart * ========== * Print the chunk's name and size */ RIFFIOSuccess cbChunkStart(NIFFIOChunkContext *pctxChunk) { char strId[RIFFIO_FOURCC_LIM]; assert(pctxChunk != 0); assert(pctxChunk->pnf != 0); assert(pctxChunk->pchunk != 0); RIFFIOFOURCCToString(pctxChunk->pchunk->fccId, strId); doindent(pctxChunk->nLevel); doline(pctxChunk->nLevel); doindent(pctxChunk->nLevel); fprintf(outputfp, "// %s\n", NIFFIONameChunkId(pctxChunk->pchunk->fccId)); doindent(pctxChunk->nLevel); fprintf(outputfp, "'%s' ( // sizeData=%lu\n", strId, pctxChunk->pchunk->sizeData); fprintf(outputfp, "\n"); return RIFFIO_OK; } /* * cbChunkEnd * ========== * Print the closing parenthesis of a chunk */ RIFFIOSuccess cbChunkEnd(NIFFIOChunkContext *pctxChunk) { doindent(pctxChunk->nLevel); fprintf(outputfp, ")\n\n"); return RIFFIO_OK; } /* * cbChunk * ======= * Default callback for any chunk */ RIFFIOSuccess cbChunk(NIFFIOChunkContext *pctxChunk) { cbChunkStart(pctxChunk); doindent(pctxChunk->nLevel + 1); fprintf(outputfp, "// Don't know how to decode this chunk (yet).\n"); fprintf(outputfp, "\n"); return cbChunkEnd(pctxChunk); } /* cbTag * ===== * Default callback for any tag */ RIFFIOSuccess cbTagStart(NIFFIOTagContext *pctxTag) { assert(pctxTag != 0); assert(pctxTag->pnf != 0); assert(pctxTag->pchunkParent != 0); doindent(pctxTag->nLevel); doline(pctxTag->nLevel); doindent(pctxTag->nLevel); fprintf(outputfp, "// %s\n", NIFFIONameTagId(pctxTag->ptag->tagid)); doindent(pctxTag->nLevel); fprintf(outputfp, "%u ( // sizeData = %u\n", (unsigned int)pctxTag->ptag->tagid, (unsigned int)pctxTag->ptag->tagsizeData); fprintf(outputfp, "\n"); return RIFFIO_OK; } cbTagEnd(NIFFIOTagContext *pctxTag) { doindent(pctxTag->nLevel); fprintf(outputfp, ")\n\n"); return RIFFIO_OK; } RIFFIOSuccess cbTag(NIFFIOTagContext *pctxTag) { cbTagStart(pctxTag); doindent(pctxTag->nLevel+1); fprintf(outputfp, "Don't know how to decode tag (yet).\n"); return cbTagEnd(pctxTag); } RIFFIOSuccess cbSetupSectionStart(NIFFIOChunkContext *pctxChunk) { char strId[5]; char strType[5]; assert(pctxChunk != 0); assert(pctxChunk->pnf != 0); assert(pctxChunk->pchunk != 0); RIFFIOFOURCCToString(pctxChunk->pchunk->fccId, strId); RIFFIOFOURCCToString(pctxChunk->pchunk->fccType, strType); doindent(pctxChunk->nLevel); fprintf(outputfp, "'%s' ( '%s' // Setup Section, sizeData=%lu\n", strId, strType, pctxChunk->pchunk->sizeData); return RIFFIO_OK; } RIFFIOSuccess cbSetupSectionEnd(NIFFIOChunkContext *pctxChunk) { assert(pctxChunk != 0); assert(pctxChunk->pnf != 0); assert(pctxChunk->pchunk != 0); doindent(pctxChunk->nLevel); fprintf(outputfp, ") // Setup Section\n"); return RIFFIO_OK; } RIFFIOSuccess cbInfoStart(NIFFIOChunkContext *pctxChunk, niffNiffInfo *ni) { const char *str; cbChunkStart(pctxChunk); doindent(pctxChunk->nLevel+1); fprintf(outputfp, "\"%.8s\" // NIF Version\n", ni->NIFFVersion); doindent(pctxChunk->nLevel+1); switch (ni->programType) { case progtypeNone: str = "None"; break; case progtypeEngraving: str = "Engraving"; break; case progtypeScanning: str = "Scanning"; break; case progtypeMidiInterpreter: str = "MidiInterpreter"; break; case progtypeSequencer: str = "Sequencer"; break; case progtypeResearch: str = "Research"; break; case progtypeEducational: str = "Educational"; break; default: str = "UNKNOWN"; break; } fprintf(outputfp, "%10u %s // Program Type\n", (unsigned int)ni->programType, str); doindent(pctxChunk->nLevel+1); switch (ni->standardUnits) { case unitsNoUnits: str = "NoUnits"; break; case unitsInches: str = "Inches"; break; case unitsCentimeters: str = "Centimeters"; break; case unitsPoints: str = "Points"; break; default: str = "UNKNOWN"; break; } fprintf(outputfp, "%10u %s // Standard Units\n", (unsigned int)ni->standardUnits, str); doindent(pctxChunk->nLevel+1); fprintf(outputfp, "%10d // Absolute Units\n", (int)ni->absoluteUnits); doindent(pctxChunk->nLevel+1); fprintf(outputfp, "%10d // Midi clocks per quarter\n", (int)ni->midiClocksPerQuarter); return RIFFIO_OK; } RIFFIOSuccess cbInfoEnd(NIFFIOChunkContext *pctxChunk,niffNiffInfo *ni) { return cbChunkEnd(pctxChunk); } RIFFIOSuccess cbFontDescriptionStart(NIFFIOChunkContext *pctxChunk, niffFontDescription *np) { int nLevel; nLevel = pctxChunk->nLevel; cbChunkStart(pctxChunk); printSTROFFSET( nLevel, 10, np->fontNamePtr, "name"); printSHORT( nLevel, 10, np->size, "size"); printSHORT( nLevel, 10, np->spaceHeight, "space height"); printSHORT( nLevel, 10, np->where, "where (-1 is local)"); printBYTE( nLevel, 10, np->style, "style"); fprintf(outputfp, "\n"); return RIFFIO_OK; } RIFFIOSuccess cbFontDescriptionEnd(NIFFIOChunkContext *pctxChunk,niffFontDescription *ni) { return cbChunkEnd(pctxChunk); } RIFFIOSuccess cbTextStart(NIFFIOChunkContext *pctxChunk, niffText *p) { int nLevel; nLevel = pctxChunk->nLevel; cbChunkStart(pctxChunk); printSTROFFSET( nLevel, 10, p->value,"string offset"); return RIFFIO_OK; } RIFFIOSuccess cbTextEnd(NIFFIOChunkContext *pctxChunk,niffText *p) { return cbChunkEnd(pctxChunk); } RIFFIOSuccess cbPartStart(NIFFIOChunkContext *pctxChunk, niffPart *np) { int nLevel; nLevel = pctxChunk->nLevel; cbChunkStart(pctxChunk); printSHORT( nLevel, 10, np->partID, "Part ID"); printSTROFFSET( nLevel, 10, np->name, "name"); printSTROFFSET( nLevel, 10, np->abbreviation, "abbreviation"); printBYTE( nLevel, 10, np->numberOfStaves, "number of staves"); printSIGNEDBYTE(nLevel, 10, np->midiChannel, "MIDI channel"); printSIGNEDBYTE(nLevel, 10, np->midiCable, "MIDI cable"); printSIGNEDBYTE(nLevel, 10, np->transpose, "transpose"); fprintf(outputfp, "\n"); return RIFFIO_OK; } RIFFIOSuccess cbPartEnd(NIFFIOChunkContext *pctxChunk, niffPart *np) { return cbChunkEnd(pctxChunk); } RIFFIOSuccess cbTimeSliceStart(NIFFIOChunkContext *pctxChunk, niffTimeSlice *p) { int nLevel; nLevel = pctxChunk->nLevel; cbChunkStart(pctxChunk); printSymbol(NIFFIOSymbolTS, nLevel, 15, p->type, "type"); printRATIONAL(nLevel, 15, p->startTime, "start time"); fprintf(outputfp, "\n"); return RIFFIO_OK; } RIFFIOSuccess cbTimeSliceEnd(NIFFIOChunkContext *pctxChunk, niffTimeSlice *p) { return cbChunkEnd(pctxChunk); } RIFFIOSuccess cbBarlineStart(NIFFIOChunkContext *pctxChunk, niffBarline *p) { int nLevel; nLevel = pctxChunk->nLevel; cbChunkStart(pctxChunk); printSymbol(NIFFIOSymbolBARTYPE, nLevel, 20, p->type, "type"); printSymbol(NIFFIOSymbolBAREXT, nLevel, 20, p->extendsTo, "extends to"); printSHORT(nLevel, 20, p->numberOfStaves, "number of staves"); fprintf(outputfp, "\n"); return RIFFIO_OK; } RIFFIOSuccess cbBarlineEnd(NIFFIOChunkContext *pctxChunk, niffBarline *p) { return cbChunkEnd(pctxChunk); } RIFFIOSuccess cbClefStart(NIFFIOChunkContext *pctxChunk, niffClef *p) { int nLevel; nLevel = pctxChunk->nLevel; cbChunkStart(pctxChunk); printSymbol(NIFFIOSymbolCLEFSHAPE, nLevel, 15, p->shape, "shape"); printSIGNEDBYTE(nLevel, 15, p->staffStep, "staffStep"); printSymbol(NIFFIOSymbolCLEFOCT, nLevel, 15, p->octaveNumber, "octaveNumber"); fprintf(outputfp, "\n"); return RIFFIO_OK; } RIFFIOSuccess cbClefEnd(NIFFIOChunkContext *pctxChunk, niffClef *p) { return cbChunkEnd(pctxChunk); } RIFFIOSuccess cbKeySignatureStart(NIFFIOChunkContext *pctxChunk, niffKeySignature *p) { int nLevel; nLevel = pctxChunk->nLevel; cbChunkStart(pctxChunk); printSIGNEDBYTE(nLevel, 15, p->standardCode, "standardCode"); fprintf(outputfp, "\n"); return RIFFIO_OK; } RIFFIOSuccess cbKeySignatureEnd(NIFFIOChunkContext *pctxChunk, niffKeySignature *p) { return cbChunkEnd(pctxChunk); } RIFFIOSuccess cbTimeSignatureStart(NIFFIOChunkContext *pctxChunk, niffTimeSignature *p) { int nLevel; nLevel = pctxChunk->nLevel; cbChunkStart(pctxChunk); printSIGNEDBYTE(nLevel, 15, p->topNumber, "top number"); printBYTE (nLevel, 15, p->bottomNumber, "bottom number"); fprintf(outputfp, "\n"); return RIFFIO_OK; } RIFFIOSuccess cbTimeSignatureEnd(NIFFIOChunkContext *pctxChunk, niffTimeSignature *p) { return cbChunkEnd(pctxChunk); } RIFFIOSuccess cbNoteheadStart(NIFFIOChunkContext *pctxChunk, niffNotehead *p) { int nLevel; nLevel = pctxChunk->nLevel; cbChunkStart(pctxChunk); printSymbol(NIFFIOSymbolNOTESHAPE, nLevel, 20, p->shape, "shape"); printSIGNEDBYTE(nLevel, 20, p->staffStep, "staff step"); printRATIONAL (nLevel, 20, p->duration, "duration"); fprintf(outputfp, "\n"); return RIFFIO_OK; } RIFFIOSuccess cbNoteheadEnd(NIFFIOChunkContext *pctxChunk, niffNotehead *p) { return cbChunkEnd(pctxChunk); } RIFFIOSuccess cbBeamStart(NIFFIOChunkContext *pctxChunk, niffBeam *p) { int nLevel; nLevel = pctxChunk->nLevel; cbChunkStart(pctxChunk); printBYTE(nLevel, 20, p->beamPartsToLeft, "parts to left"); printBYTE(nLevel, 20, p->beamPartsToRight, "parts to right"); fprintf(outputfp, "\n"); return RIFFIO_OK; } RIFFIOSuccess cbBeamEnd(NIFFIOChunkContext *pctxChunk, niffBeam *p) { return cbChunkEnd(pctxChunk); } RIFFIOSuccess cbOctaveSignStart(NIFFIOChunkContext *pctxChunk, niffOctaveSign *p) { int nLevel; nLevel = pctxChunk->nLevel; cbChunkStart(pctxChunk); printBYTE(nLevel, 20, p->numberOfOctaves, "parts to left"); printBYTE(nLevel, 20, p->aboveOrBelow, "1=Above, 2=Below"); printBYTE(nLevel, 20, p->type, "1=Transpose, 2=Double"); printSTROFFSET(nLevel,20,p->textString, "Text string"); fprintf(outputfp, "\n"); return RIFFIO_OK; } RIFFIOSuccess cbOctaveSignEnd(NIFFIOChunkContext *pctxChunk, niffOctaveSign *p) { return cbChunkEnd(pctxChunk); } RIFFIOSuccess cbRestStart(NIFFIOChunkContext *pctxChunk, niffRest *p) { int nLevel; nLevel = pctxChunk->nLevel; cbChunkStart(pctxChunk); printSymbol(NIFFIOSymbolREST, nLevel, 15, p->shape, "shape"); printSIGNEDBYTE(nLevel, 15, p->staffStep, "staff step"); printRATIONAL (nLevel, 15, p->duration, "duration"); fprintf(outputfp, "\n"); return RIFFIO_OK; } RIFFIOSuccess cbRestEnd(NIFFIOChunkContext *pctxChunk, niffRest *p) { return cbChunkEnd(pctxChunk); } RIFFIOSuccess cbAccidentalStart(NIFFIOChunkContext *pctxChunk, niffAccidental *p) { int nLevel; char *str; nLevel = pctxChunk->nLevel; cbChunkStart(pctxChunk); switch(p->shape) { case 1: str="double flat"; break; case 2: str="flat"; break; case 3: str="natural"; break; case 4: str="sharp"; break; case 5: str="double sharp"; break; case 6: str="quarter tone flat"; break; case 7: str="three quarter tones flat"; break; case 8: str="quarter tone sharp"; break; case 9: str="three quarter tones sharp"; break; default: str = "UNKNOWN accidental"; break; } doindent(nLevel+1); fprintf(outputfp, "%s\n",str); return RIFFIO_OK; } RIFFIOSuccess cbAccidentalEnd(NIFFIOChunkContext *pctxChunk, niffAccidental *p) { return cbChunkEnd(pctxChunk); } RIFFIOSuccess cbArticulationStart(NIFFIOChunkContext *pctxChunk, niffArticulation *p) { int nLevel; char *str; nLevel = pctxChunk->nLevel; cbChunkStart(pctxChunk); switch(p->shape) { case 1: str="strong accent (vertical wedge)"; break; case 2: str="medium accent (>)"; break; case 3: str="light accent (tenuto)"; break; case 4: str="staccato"; break; case 5: str="down bow"; break; case 6: str="up bow"; break; case 7: str="harmonic (small circle)"; break; case 8: str="fermata"; break; case 9: str="arsis sign (unstressed)"; break; case 10: str="thesis sign (stressed)"; break; case 11: str="plus sign"; break; case 12: str="vertical filled wedge (staccatissimo)"; break; case 13: str="double tonguing (two dots)"; break; case 14: str="triple tonguing (three dots)"; break; case 15: str="snap, pizzicato"; break; default: str = "UNKNOWN articulation"; break; } doindent(nLevel+1); fprintf(outputfp, "%s\n",str); return RIFFIO_OK; } RIFFIOSuccess cbArticulationEnd(NIFFIOChunkContext *pctxChunk, niffArticulation *p) { return cbChunkEnd(pctxChunk); } RIFFIOSuccess cbDynamicStart(NIFFIOChunkContext *pctxChunk, niffDynamic *p) { int nLevel; char *str; nLevel = pctxChunk->nLevel; cbChunkStart(pctxChunk); switch(p->code) { case 1: str="pppp"; break; case 2: str="ppp"; break; case 3: str="pp"; break; case 4: str="p"; break; case 5: str="mp"; break; case 6: str="mf"; break; case 7: str="f"; break; case 8: str="ff"; break; case 9: str="fff"; break; case 10: str="ffff"; break; case 11: str="sp"; break; case 12: str="sf"; break; case 13: str="sfz"; break; case 14: str="fz"; break; case 15: str="fp"; break; case 16: str="cresc"; break; case 17: str="crescendo"; break; case 18: str="dim"; break; case 19: str="diminuendo"; break; default: str = "UNKNOWN dynamic"; break; } doindent(nLevel+1); fprintf(outputfp, "%s\n",str); return RIFFIO_OK; } RIFFIOSuccess cbDynamicEnd(NIFFIOChunkContext *pctxChunk, niffDynamic *p) { return cbChunkEnd(pctxChunk); } RIFFIOSuccess cbHairpinStart(NIFFIOChunkContext *pctxChunk, niffHairpin *p) { int nLevel; char *str; nLevel = pctxChunk->nLevel; cbChunkStart(pctxChunk); switch (p->direction) { case 0: str = "not first node"; break; case hairpinOpenLeft: str = "open to left"; break; case hairpinOpenRight: str = "open to right"; break; default: str = "UNKNOWN hairpin direction"; } printBYTE(nLevel, 10, p->direction, str); fprintf(outputfp, "\n"); return RIFFIO_OK; } RIFFIOSuccess cbHairpinEnd(NIFFIOChunkContext *pctxChunk, niffHairpin *p) { return cbChunkEnd(pctxChunk); } RIFFIOSuccess cbInvisible(NIFFIOTagContext *pctxTag) { assert(pctxTag != 0); assert(pctxTag->pnf != 0); assert(pctxTag->pchunkParent != 0); doindent(pctxTag->nLevel); fprintf(outputfp, "%u <> // Invisible\n", (unsigned int)pctxTag->ptag->tagid); return RIFFIO_OK; } RIFFIOSuccess cbLogicalPlacement(NIFFIOTagContext *pctxTag, niffLogicalPlacement *p) { int nLevel; nLevel = pctxTag->nLevel; assert(pctxTag != 0); assert(pctxTag->pnf != 0); assert(pctxTag->pchunkParent != 0); cbTagStart(pctxTag); printSymbol(NIFFIOSymbolLOGPLACEH, nLevel, 20, p->horizontal, "horizontal"); printSymbol(NIFFIOSymbolLOGPLACEV, nLevel, 20, p->vertical, "vertical"); printSymbol(NIFFIOSymbolLOGPLACEPROX, nLevel, 20, p->proximity, "proximity"); cbTagEnd(pctxTag); return RIFFIO_OK; } RIFFIOSuccess cbTupletDesc(NIFFIOTagContext *pctxTag, niffTupletDesc *p) { int nLevel; nLevel = pctxTag->nLevel; assert(pctxTag != 0); assert(pctxTag->pnf != 0); assert(pctxTag->pchunkParent != 0); cbTagStart(pctxTag); printRATIONAL (nLevel, 20, p->transformRatioAB, "transform AB"); printRATIONAL (nLevel, 20, p->transformRatioCD, "transform CD"); printBYTE (nLevel, 20, p->groupingSymbol, "grouping symbol"); cbTagEnd(pctxTag); return RIFFIO_OK; } RIFFIOSuccess cbGraceNote(NIFFIOTagContext *pctxTag, niffGraceNote *p) { int nLevel; nLevel = pctxTag->nLevel; assert(pctxTag != 0); assert(pctxTag->pnf != 0); assert(pctxTag->pchunkParent != 0); cbTagStart(pctxTag); printRATIONAL (nLevel, 15, *p, "time offset"); cbTagEnd(pctxTag); return RIFFIO_OK; } RIFFIOSuccess cbAbsPlacement(NIFFIOTagContext *pctxTag, niffAbsPlacement *p) { int nLevel; nLevel = pctxTag->nLevel; assert(pctxTag != 0); assert(pctxTag->pnf != 0); assert(pctxTag->pchunkParent != 0); cbTagStart(pctxTag); printSHORT(nLevel, 10, p->horizontal, "horizontal"); printSHORT(nLevel, 10, p->vertical, "vertical"); cbTagEnd(pctxTag); return RIFFIO_OK; } RIFFIOSuccess cbAnchorOverride(NIFFIOTagContext *pctxTag, niffAnchorOverride *p) { int nLevel; char strId[RIFFIO_FOURCC_LIM]; nLevel = pctxTag->nLevel; assert(pctxTag != 0); assert(pctxTag->pnf != 0); assert(pctxTag->pchunkParent != 0); cbTagStart(pctxTag); RIFFIOFOURCCToString(*p, strId); doindent(nLevel+1); fprintf(outputfp, "%s ", strId); fprintf(outputfp, "// %s\n", NIFFIONameChunkId(*p)); cbTagEnd(pctxTag); return RIFFIO_OK; } RIFFIOSuccess cbPartID(NIFFIOTagContext *pctxTag, niffPartID *p) { int nLevel; nLevel = pctxTag->nLevel; assert(pctxTag != 0); assert(pctxTag->pnf != 0); assert(pctxTag->pchunkParent != 0); cbTagStart(pctxTag); printSHORT(nLevel, 10, *p, "Part ID Number"); cbTagEnd(pctxTag); return RIFFIO_OK; } RIFFIOSuccess cbWidth(NIFFIOTagContext *pctxTag, niffPartID *p) { int nLevel; nLevel = pctxTag->nLevel; assert(pctxTag != 0); assert(pctxTag->pnf != 0); assert(pctxTag->pchunkParent != 0); cbTagStart(pctxTag); printSHORT(nLevel, 10, *p, "Width in Abs. Units"); cbTagEnd(pctxTag); return RIFFIO_OK; } RIFFIOSuccess cbHeight(NIFFIOTagContext *pctxTag, niffHeight *p) { int nLevel; nLevel = pctxTag->nLevel; assert(pctxTag != 0); assert(pctxTag->pnf != 0); assert(pctxTag->pchunkParent != 0); cbTagStart(pctxTag); printSHORT(nLevel, 10, *p, "Height in Abs. Units"); cbTagEnd(pctxTag); return RIFFIO_OK; } RIFFIOSuccess cbNumberOfNodes(NIFFIOTagContext *pctxTag, niffNumberOfNodes *p) { int nLevel; nLevel = pctxTag->nLevel; assert(pctxTag != 0); assert(pctxTag->pnf != 0); assert(pctxTag->pchunkParent != 0); cbTagStart(pctxTag); printSHORT(nLevel, 10, *p, "Nodes"); cbTagEnd(pctxTag); return RIFFIO_OK; } RIFFIOSuccess cbNumStaffLines(NIFFIOTagContext *pctxTag, niffNumStaffLines *p) { int nLevel; nLevel = pctxTag->nLevel; assert(pctxTag != 0); assert(pctxTag->pnf != 0); assert(pctxTag->pchunkParent != 0); cbTagStart(pctxTag); printBYTE(nLevel, 10, *p, "Number of lines"); cbTagEnd(pctxTag); return RIFFIO_OK; } RIFFIOSuccess cbID(NIFFIOTagContext *pctxTag, niffID *p) { int nLevel; nLevel = pctxTag->nLevel; assert(pctxTag != 0); assert(pctxTag->pnf != 0); assert(pctxTag->pchunkParent != 0); cbTagStart(pctxTag); printSHORT(nLevel, 10, *p, "Node ID"); cbTagEnd(pctxTag); return RIFFIO_OK; } RIFFIOSuccess cbNumberOfFlags(NIFFIOTagContext *pctxTag, niffNumberOfFlags *p) { int nLevel; nLevel = pctxTag->nLevel; assert(pctxTag != 0); assert(pctxTag->pnf != 0); assert(pctxTag->pchunkParent != 0); cbTagStart(pctxTag); printBYTE(nLevel, 10, *p, ""); cbTagEnd(pctxTag); return RIFFIO_OK; } RIFFIOSuccess cbTieDirection(NIFFIOTagContext *pctxTag, niffTieDirection *p) { int nLevel; nLevel = pctxTag->nLevel; assert(pctxTag != 0); assert(pctxTag->pnf != 0); assert(pctxTag->pchunkParent != 0); cbTagStart(pctxTag); if (*p==1) { printBYTE(nLevel, 10, *p, "rounded above"); } if (*p==2) { printBYTE(nLevel, 10, *p, "rounded below"); } cbTagEnd(pctxTag); return RIFFIO_OK; } RIFFIOSuccess cbTagWithNoData(NIFFIOTagContext *pctxTag) { int nLevel; nLevel = pctxTag->nLevel; assert(pctxTag != 0); assert(pctxTag->pnf != 0); assert(pctxTag->pchunkParent != 0); cbTagStart(pctxTag); doindent(nLevel+1); fprintf(outputfp, "(No data)\n"); cbTagEnd(pctxTag); return RIFFIO_OK; } RIFFIOSuccess cbFontID(NIFFIOTagContext *pctxTag, niffFontID *p) { int nLevel; nLevel = pctxTag->nLevel; assert(pctxTag != 0); assert(pctxTag->pnf != 0); assert(pctxTag->pchunkParent != 0); cbTagStart(pctxTag); printSHORT(nLevel, 10, *p, "Offset in font list"); cbTagEnd(pctxTag); return RIFFIO_OK; } RIFFIOSuccess cbStringTable(NIFFIOChunkContext *pctxChunk) { NIFFIOFile *pnf; RIFFIOChunk *pchunk; char buffer; unsigned long offset; int bytesRead; pnf = pctxChunk->pnf; pchunk = pctxChunk->pchunk; cbChunkStart(pctxChunk); offset = 0; while (! NIFFIOChunkDataEnd(pnf, pchunk)) { doindent(pctxChunk->nLevel+1); fprintf(outputfp, "// offset == %lu\n", offset); doindent(pctxChunk->nLevel+1); fprintf(outputfp, "\""); bytesRead = NIFFIORead(pnf, &buffer, 1); offset += bytesRead; while(buffer) { fprintf(outputfp, "%c", buffer); if (offset < maxstringtablesize) { stringtablebuffer[offset-1] = buffer; } bytesRead = NIFFIORead(pnf, &buffer, 1); offset += bytesRead; } fprintf(outputfp, "\"Z\n"); if (offset < maxstringtablesize) { stringtablebuffer[offset-1] = 0; } fprintf(outputfp, "\n"); } stringtablebuffer[maxstringtablesize-1] = 0; cbChunkEnd(pctxChunk); return RIFFIO_OK; } RIFFIOSuccess cbChnkLenTable(NIFFIOChunkContext *pctxChunk) { char strFOURCC[RIFFIO_FOURCC_LIM]; /* Buffer for printing FOURCCs */ NIFFIOFile *pnf; RIFFIOChunk *pchunk; niffChklentabEntry entryCLT; pnf = pctxChunk->pnf; pchunk = pctxChunk->pchunk; cbChunkStart(pctxChunk); while (! NIFFIOChunkDataEnd(pnf, pchunk)) { NIFFIOReadniffChklentabEntry(pnf, & entryCLT); RIFFIOFOURCCToString(entryCLT.chunkName, strFOURCC); doindent(pctxChunk->nLevel+1); fprintf(outputfp, "'%s' %5ld\n", strFOURCC, entryCLT.offsetOfFirstTag); } doindent(pctxChunk->nLevel); fprintf(outputfp, "')'\n"); fprintf(outputfp, "\n"); return RIFFIO_OK; } NIFFIOParser * InitParser(void) { NIFFIOParser *pparserNew; pparserNew = NIFFIOParserNew(); NIFFIORegisterForm(pparserNew, cbFormStart, cbFormEnd); NIFFIORegisterDefaultList(pparserNew, cbListStart, cbListEnd); NIFFIORegisterDefaultAtomicChunk(pparserNew, cbChunk); NIFFIORegisterDefaultTaggedChunk(pparserNew, cbChunk, 0); NIFFIORegisterDefaultTag(pparserNew, cbTag); NIFFIORegisterChunkChnkLenTable(pparserNew, cbChnkLenTable); NIFFIORegisterChunkStringTable(pparserNew, cbStringTable); NIFFIORegisterChunkNiffInfo(pparserNew, cbInfoStart, cbInfoEnd); NIFFIORegisterChunkFontDescription(pparserNew, cbFontDescriptionStart, cbFontDescriptionEnd); NIFFIORegisterChunkText(pparserNew, cbTextStart, cbTextEnd); NIFFIORegisterChunkPart(pparserNew, cbPartStart, cbPartEnd); NIFFIORegisterChunkSystemHeader(pparserNew, cbChunkStart, cbChunkEnd); NIFFIORegisterChunkStaffHeader(pparserNew, cbChunkStart, cbChunkEnd); NIFFIORegisterChunkTimeSlice(pparserNew, cbTimeSliceStart, cbTimeSliceEnd); NIFFIORegisterChunkBarline(pparserNew, cbBarlineStart, cbBarlineEnd); NIFFIORegisterChunkClef(pparserNew, cbClefStart, cbClefEnd); NIFFIORegisterChunkKeySignature(pparserNew, cbKeySignatureStart, cbKeySignatureEnd); NIFFIORegisterChunkTimeSignature(pparserNew, cbTimeSignatureStart, cbTimeSignatureEnd); NIFFIORegisterChunkOctaveSign(pparserNew, cbOctaveSignStart, cbOctaveSignEnd); NIFFIORegisterChunkNotehead(pparserNew, cbNoteheadStart, cbNoteheadEnd); NIFFIORegisterChunkBeam(pparserNew, cbBeamStart, cbBeamEnd); NIFFIORegisterChunkRest(pparserNew, cbRestStart, cbRestEnd); NIFFIORegisterChunkAccidental(pparserNew, cbAccidentalStart, cbAccidentalEnd); NIFFIORegisterChunkArticulation(pparserNew, cbArticulationStart, cbArticulationEnd); NIFFIORegisterChunkDynamic(pparserNew, cbDynamicStart, cbDynamicEnd); NIFFIORegisterChunkHairpin(pparserNew, cbHairpinStart, cbHairpinEnd); NIFFIORegisterChunkStem(pparserNew, cbChunkStart, cbChunkEnd); NIFFIORegisterChunkAugDot(pparserNew, cbChunkStart, cbChunkEnd); NIFFIORegisterChunkSlur(pparserNew, cbChunkStart, cbChunkEnd); NIFFIORegisterChunkTie(pparserNew, cbChunkStart, cbChunkEnd); NIFFIORegisterChunkPageHeader(pparserNew, cbChunkStart, cbChunkEnd); NIFFIORegisterChunkTuplet(pparserNew, cbChunkStart, cbChunkEnd); NIFFIORegisterTagInvisible(pparserNew, niffckidArticulation, cbInvisible); NIFFIORegisterTagNumberOfFlags(pparserNew, NIFFIO_FOURCC_WILDCARD, cbNumberOfFlags); NIFFIORegisterTagLogicalPlacement(pparserNew, NIFFIO_FOURCC_WILDCARD, cbLogicalPlacement); NIFFIORegisterTagAbsPlacement(pparserNew, NIFFIO_FOURCC_WILDCARD, cbAbsPlacement); NIFFIORegisterTagAnchorOverride(pparserNew, NIFFIO_FOURCC_WILDCARD, cbAnchorOverride); NIFFIORegisterTagTupletDesc(pparserNew, NIFFIO_FOURCC_WILDCARD, cbTupletDesc); NIFFIORegisterTagGraceNote(pparserNew, NIFFIO_FOURCC_WILDCARD, cbGraceNote); NIFFIORegisterTagNumberOfNodes(pparserNew, NIFFIO_FOURCC_WILDCARD, cbNumberOfNodes); NIFFIORegisterTagNumStaffLines(pparserNew, NIFFIO_FOURCC_WILDCARD, cbNumStaffLines); NIFFIORegisterTagPartID(pparserNew, NIFFIO_FOURCC_WILDCARD, cbPartID); NIFFIORegisterTagWidth(pparserNew, NIFFIO_FOURCC_WILDCARD, cbWidth); NIFFIORegisterTagHeight(pparserNew, NIFFIO_FOURCC_WILDCARD, cbHeight); NIFFIORegisterTagID(pparserNew, NIFFIO_FOURCC_WILDCARD, cbID); NIFFIORegisterTagTieDirection(pparserNew, NIFFIO_FOURCC_WILDCARD, cbTieDirection); NIFFIORegisterTagSmallSize(pparserNew, NIFFIO_FOURCC_WILDCARD, cbTagWithNoData); NIFFIORegisterTagMultiNodeEndOfSyst(pparserNew, NIFFIO_FOURCC_WILDCARD, cbTagWithNoData); NIFFIORegisterTagMultiNodeStartOfSyst(pparserNew, NIFFIO_FOURCC_WILDCARD, cbTagWithNoData); NIFFIORegisterTagFontID(pparserNew, NIFFIO_FOURCC_WILDCARD, cbFontID); return pparserNew; } /*****************************************************************/ /* Was NIFFDUM2.c (Graham Jones) */ /*****************************************************************/ /* This file has been altered slightly from Tim Butler's original by * Terence Kelly, (tkelly@pressenter.com). This file should be linked with * callback.c, which I have added to substantially, and the Niff library as * provided by Tim. I have added code to redirect stdout to a file so that * the dump can be used as a development tool. That code is platform specific * but you should only have to alter 4 lines to make it work on your platform. * The appropriate lines are commented. * To save time and space I altered the doindent function to use tabs and rewrote * the separator (doline) function. Set tabs to 4 in your viewer, and the output will * be indistinguishable from the original. */ /* Graham Jones, March 2001. * I removed the platform specific code mentioned above and open an output file passed as second argument. */ static void usage(); static void doerror(const char *message); static char *Progname; int main(int argc, char **argv) { char *strNiffFile; FILE *pFILENiff; NIFFIOFile *pnf; NIFFIOParser *pparser; long bytesRead; unsigned char extraByte; unsigned long extraCount; Progname = argv[0]; /* * Check command line arguments */ if (argc != 3) { usage(); return 1; } strNiffFile = argv[1]; /* * Open the riff file */ pFILENiff = fopen(strNiffFile, "rb"); if (!pFILENiff) { perror("Can't open NIFF File"); return 1; } /* * Initialize the niffio file */ pnf = NIFFIOFileNewSTDC(pFILENiff); if (!pnf) doerror("Can't create new NIFFIOFile"); /* * Open output file */ outputfp = fopen(argv[2], "w"); if (!outputfp) { doerror("Can't open output file"); } /* * Initialize the parser */ pparser = InitParser(); NIFFIOParserSetTracing(pparser, 0); NIFFIOParseFile(pparser, pnf, 0, 0 ); /* close output */ fclose(outputfp); outputfp = 0; /* * Check for any extra bytes past the Form */ extraCount = 0; while ((bytesRead = NIFFIORead(pnf, &extraByte , 1)) == 1) { extraCount +=1; } if (extraCount != 0) { fprintf(stderr,"%s:WARNING:Found %lu extra bytes after Form\n", Progname, extraCount); } /* * Clean up */ NIFFIOParserDelete(pparser); NIFFIOFileDelete(pnf); fclose(pFILENiff); return 0; } static void usage() { fprintf(stderr, "Usage: niff2txt input.nif output.txt\n"); } static void doerror(const char *message) { fprintf(stderr, "%s:ERROR:%s\n", Progname, message); exit(1); }