From 9d5697d9cd48af4d50215c93be08b4a560eda3a4 Mon Sep 17 00:00:00 2001 From: kevin Date: Fri, 17 Jul 2020 18:48:01 -0400 Subject: [PATCH] Many changes to support cmtools. --- app/cmScore.c | 23 +++++++--- app/cmScore.h | 2 +- app/cmScoreProc.c | 112 +++++++++++++++++++++++++--------------------- app/cmScoreProc.h | 7 +-- app/cmTimeLine.c | 20 +++++++++ app/cmTimeLine.h | 4 +- app/cmXScore.c | 27 ++++++----- app/cmXScore.h | 2 +- cmApBuf.c | 8 ++-- cmAudioFile.c | 32 +++++++++++++ cmAudioFile.h | 3 ++ cmMidiFile.c | 27 ++++++++--- cmMidiFile.h | 2 +- cmPgmOpts.c | 7 +-- cmProc4.c | 2 +- cmSvgWriter.c | 48 ++++++++++---------- cmSvgWriter.h | 2 +- 17 files changed, 216 insertions(+), 112 deletions(-) diff --git a/app/cmScore.c b/app/cmScore.c index e99018d..5850953 100644 --- a/app/cmScore.c +++ b/app/cmScore.c @@ -19,6 +19,7 @@ #include "cmFile.h" #include "cmScore.h" #include "cmVectOpsTemplateMain.h" +#include "cmRptFile.h" cmScH_t cmScNullHandle = cmSTATIC_NULL_HANDLE; @@ -2441,7 +2442,7 @@ void _cmScorePrintHdr( cmRpt_t* rpt ) void _cmScorePrintEvent( cmSc_t* p, const cmScoreEvt_t* r, unsigned i, cmRpt_t* rpt ) { - bool eolFl = true; + //bool eolFl = true; switch(r->type) { case kBarEvtScId: @@ -2469,7 +2470,7 @@ void _cmScorePrintEvent( cmSc_t* p, const cmScoreEvt_t* r, unsigned i, cmRpt_t* break; default: - eolFl = false; + //eolFl = false; break; } @@ -2741,15 +2742,27 @@ cmScRC_t cmScoreFileFromMidi( cmCtx_t* ctx, const cmChar_t* midiFn, const c } -void cmScoreReport( cmCtx_t* ctx, const cmChar_t* fn ) +void cmScoreReport( cmCtx_t* ctx, const cmChar_t* fn, const cmChar_t* outFn ) { - cmScH_t h = cmScNullHandle; + cmScH_t h = cmScNullHandle; + cmRptFileH_t fH = cmRptFileNullHandle; + cmRpt_t* rpt = &ctx->rpt; + + if( outFn != NULL ) + if( cmRptFileCreate( ctx, &fH, outFn, NULL ) == kOkRfRC ) + rpt = cmRptFileRpt( fH ); + + if( cmScoreInitialize(ctx,&h,fn,0,NULL,0,NULL,NULL, cmSymTblNullHandle ) != kOkScRC ) return; - cmScorePrint(h,&ctx->rpt); + cmScorePrint(h,rpt); cmScoreFinalize(&h); + + if( cmRptFileIsValid( fH ) ) + cmRptFileClose( &fH ); + } void cmScoreTest( cmCtx_t* ctx, const cmChar_t* fn ) diff --git a/app/cmScore.h b/app/cmScore.h index 853963d..a2739df 100644 --- a/app/cmScore.h +++ b/app/cmScore.h @@ -282,7 +282,7 @@ extern "C" { // Print open the score file 'fn' and report the contents. This function // simply wraps calls to cmScoreInitialize() and cmScorePrint(). - void cmScoreReport( cmCtx_t* ctx, const cmChar_t* fn ); + void cmScoreReport( cmCtx_t* ctx, const cmChar_t* fn, const cmChar_t* outFn ); void cmScoreTest( cmCtx_t* ctx, const cmChar_t* fn ); diff --git a/app/cmScoreProc.c b/app/cmScoreProc.c index 15b8327..33aa4af 100644 --- a/app/cmScoreProc.c +++ b/app/cmScoreProc.c @@ -339,10 +339,12 @@ typedef struct unsigned _cmSpMeasSectCount( _cmSpMeasProc_t* m ) { const _cmSpMeas_t* mp = m->list_beg; - unsigned n = 0; - for(; mp != NULL; mp=mp->link) + unsigned n = 0; + unsigned M = 0; + + for(; mp != NULL; mp=mp->link,++M) n += mp->setPtr->sectCnt; - + return n; } @@ -359,9 +361,10 @@ cmSpRC_t _cmScWriteMeasFile( cmCtx_t* ctx, cmSp_t* sp, _cmSpMeasProc_t* m, const cmFileH_t fH = cmFileNullHandle; cmSpRC_t rc = kOkSpRC; unsigned i,j,k; + unsigned scnt = _cmSpMeasSectCount(m); + _cmSpMeas_t* mp = m->list_beg; - unsigned scnt = _cmSpMeasSectCount(m); _cmSpMeasSect_t sarray[ scnt ]; for(i=0,k=0; klink) { @@ -375,24 +378,26 @@ cmSpRC_t _cmScWriteMeasFile( cmCtx_t* ctx, cmSp_t* sp, _cmSpMeasProc_t* m, const { assert(0); } } + for(j=0; jsetPtr->sectCnt; ++j,++k) { + assert(ksrcSeqId = mp->markPtr->obj.seqId, - r->srcMarkNameStr = cmStringNullGuard(mp->markPtr->obj.name), - r->srcTypeId = mp->setPtr->varId, - r->srcTypeLabelStr = typeLabel, - r->dstScLocIdx = mp->setPtr->sectArray[j]->locPtr->index, - r->dstEvtIdx = mp->setPtr->sectArray[j]->begEvtIndex, - r->dstSectLabelStr = cmStringNullGuard(mp->setPtr->sectArray[j]->label), - r->value = mp->value, - r->cost = mp->cost; - + r->srcSeqId = mp->markPtr->obj.seqId; + r->srcMarkNameStr = cmStringNullGuard(mp->markPtr->obj.name); + r->srcTypeId = mp->setPtr->varId; + r->srcTypeLabelStr = typeLabel; + r->dstScLocIdx = mp->setPtr->sectArray[j]->locPtr->index; + r->dstEvtIdx = mp->setPtr->sectArray[j]->begEvtIndex; + r->dstSectLabelStr = cmStringNullGuard(mp->setPtr->sectArray[j]->label); + r->value = mp->value; + r->cost = mp->cost; } } - assert(mp==NULL && k==scnt); + // assert(mp==NULL && k==scnt); if the ending mp->setPtr->sectCnt==0 then this assert will not work correctly even though there would be no data inconsistency qsort(sarray,scnt,sizeof(sarray[0]),_cmSpMeasSectCompare); @@ -408,39 +413,39 @@ cmSpRC_t _cmScWriteMeasFile( cmCtx_t* ctx, cmSp_t* sp, _cmSpMeasProc_t* m, const { _cmSpMeasSect_t* r = sarray + i; - cmFilePrintf(fH,"[ \"%s\" \"%s\" %f %f %i %i %i \"%s\" %i ]\n", - r->dstSectLabelStr, - r->srcTypeLabelStr, - r->value, - r->cost, - r->dstScLocIdx, - r->dstEvtIdx, - r->srcSeqId, - r->srcMarkNameStr, - r->srcTypeId - ); + cmFilePrintf(fH,"[ \"%s\" \"%s\" %f %f %i %i %i \"%s\" %i ]\n", + r->dstSectLabelStr, + r->srcTypeLabelStr, + r->value, + r->cost, + r->dstScLocIdx, + r->dstEvtIdx, + r->srcSeqId, + r->srcMarkNameStr, + r->srcTypeId + ); } /* - mp = sp->list_beg; - for(; mp!=NULL; mp=mp->link) - { + mp = sp->list_beg; + for(; mp!=NULL; mp=mp->link) + { for(i=0; isetPtr->sectCnt; ++i) { - cmFilePrintf(fH,"[ %i \"%s\" %i \"%s\" %i %i \"%s\" %f %f ]\n", - mp->markPtr->obj.seqId, - cmStringNullGuard(mp->markPtr->obj.name), - mp->setPtr->varId, - typeLabel, - mp->setPtr->sectArray[i]->locPtr->index, - mp->setPtr->sectArray[i]->begEvtIndex, - cmStringNullGuard(mp->setPtr->sectArray[i]->label), - mp->value, - mp->cost ); + cmFilePrintf(fH,"[ %i \"%s\" %i \"%s\" %i %i \"%s\" %f %f ]\n", + mp->markPtr->obj.seqId, + cmStringNullGuard(mp->markPtr->obj.name), + mp->setPtr->varId, + typeLabel, + mp->setPtr->sectArray[i]->locPtr->index, + mp->setPtr->sectArray[i]->begEvtIndex, + cmStringNullGuard(mp->setPtr->sectArray[i]->label), + mp->value, + mp->cost ); } - } + } */ cmFilePrintf(fH,"\n]\n}\n"); @@ -516,10 +521,10 @@ cmSpRC_t _cmSpProcMeasCb( void* arg, cmSp_t* sp, cmScoreProcSelId_t id, cmTlObj } -cmSpRC_t _cmScoreProcGenAllMeasurementsMain(cmCtx_t* ctx) +cmSpRC_t _cmScoreProcGenAllMeasurementsMain(cmCtx_t* ctx, const cmChar_t* pgmRsrcFn, const cmChar_t* outFn) { - const cmChar_t* rsrcFn = "/home/kevin/.kc/time_line.js"; - const cmChar_t* outFn = "/home/kevin/src/cmkc/src/kc/data/meas0.js"; + //const cmChar_t* rsrcFn = "/home/kevin/.kc/time_line.js"; + //const cmChar_t* outFn = "/home/kevin/src/cmkc/src/kc/data/meas0.js"; cmSpRC_t rc = kOkSpRC; _cmSpMeasProc_t* m = cmMemAllocZ(_cmSpMeasProc_t,1); @@ -531,7 +536,7 @@ cmSpRC_t _cmScoreProcGenAllMeasurementsMain(cmCtx_t* ctx) cmRptPrintf(&ctx->rpt,"Score Performance Evaluation Start\n"); // initialize the score processor - if((rc = _cmScoreProcInit(ctx,sp,rsrcFn,_cmSpProcMeasCb,_cmSpMatchMeasCb,m)) != kOkSpRC ) + if((rc = _cmScoreProcInit(ctx,sp,pgmRsrcFn,_cmSpProcMeasCb,_cmSpMatchMeasCb,m)) != kOkSpRC ) goto errLabel; // allocate the performance evaluation measurement object @@ -719,10 +724,10 @@ cmSpRC_t _cmSpProcAssocCb( void* arg, cmSp_t* sp, cmScoreProcSelId_t id, cmTlOb return rc; } -cmSpRC_t _cmScoreProcGenAssocMain(cmCtx_t* ctx) +cmSpRC_t _cmScoreProcGenAssocMain(cmCtx_t* ctx, const cmChar_t* pgmRsrcFn, const cmChar_t* outFn ) { - const cmChar_t* rsrcFn = "/home/kevin/.kc/time_line.js"; - const cmChar_t* outFn = "/home/kevin/src/cmkc/src/kc/data/takeSeqBldr0.js"; + //const cmChar_t* pgmRsrcFn = "/home/kevin/.kc/time_line.js"; + //const cmChar_t* outFn = "/home/kevin/src/cmkc/src/kc/data/takeSeqBldr0.js"; cmSpRC_t rc = kOkSpRC; cmSpAssocProc_t* m = cmMemAllocZ(cmSpAssocProc_t,1); cmSp_t s; @@ -749,7 +754,7 @@ cmSpRC_t _cmScoreProcGenAssocMain(cmCtx_t* ctx) } // initialize the score processor - if((rc = _cmScoreProcInit(ctx,sp,rsrcFn,_cmSpProcAssocCb,_cmSpMatchAssocCb, m)) != kOkSpRC ) + if((rc = _cmScoreProcInit(ctx,sp,pgmRsrcFn,_cmSpProcAssocCb,_cmSpMatchAssocCb, m)) != kOkSpRC ) goto errLabel; m->sp = sp; @@ -804,12 +809,17 @@ cmSpRC_t _cmScoreProcGenAssocMain(cmCtx_t* ctx) //================================================================================================== -cmSpRC_t cmScoreProc(cmCtx_t* ctx) +cmSpRC_t cmScoreProc(cmCtx_t* ctx, const cmChar_t* sel, const cmChar_t* pgmRsrcFn, const cmChar_t* outFn) { cmSpRC_t rc = kOkSpRC; - //_cmScoreProcGenAllMeasurementsMain(ctx); - _cmScoreProcGenAssocMain(ctx); + if( strcmp(sel,"meas") == 0 ) + _cmScoreProcGenAllMeasurementsMain(ctx,pgmRsrcFn,outFn); + else + if( strcmp(sel,"assoc") == 0 ) + _cmScoreProcGenAssocMain(ctx,pgmRsrcFn,outFn); + else + cmErrMsg(&ctx->err,kSelectorFailSpRC,"Unknown selector %s.", cmStringNullGuard(sel)); return rc; diff --git a/app/cmScoreProc.h b/app/cmScoreProc.h index 4460f51..5cd1d65 100644 --- a/app/cmScoreProc.h +++ b/app/cmScoreProc.h @@ -17,12 +17,13 @@ extern "C" { kTimeLineFailSpRC, kScoreMatchFailSpRC, kFileFailSpRC, - kProcFailSpRC + kProcFailSpRC, + kSelectorFailSpRC }; - cmSpRC_t cmScoreProc(cmCtx_t* ctx ); - + cmSpRC_t cmScoreProc(cmCtx_t* ctx, const cmChar_t* sel, const cmChar_t* pgmRsrcFn, const cmChar_t* outFn); + //) #ifdef __cplusplus diff --git a/app/cmTimeLine.c b/app/cmTimeLine.c index 9ebc521..708f7a0 100644 --- a/app/cmTimeLine.c +++ b/app/cmTimeLine.c @@ -15,6 +15,7 @@ #include "cmFileSys.h" #include "cmTimeLine.h" #include "cmOnset.h" +#include "cmRptFile.h" // id's used to track the type of a serialized object enum @@ -1802,6 +1803,25 @@ cmTlRC_t cmTimeLinePrintFn( cmCtx_t* ctx, const cmChar_t* fn, const cmChar_t* pr return cmTimeLineFinalize(&h); } +cmTlRC_t cmTimeLineReport( cmCtx_t* ctx, const cmChar_t* tlFn, const cmChar_t* tlPrefixPath, const cmChar_t* rptFn ) +{ + cmTlRC_t rc; + cmRptFileH_t rptH = cmRptFileNullHandle; + + if(( rc = cmRptFileCreate(ctx, &rptH, rptFn, NULL )) != kOkRfRC ) + { + rc = cmErrMsg(&ctx->err,kRptFileFailTlRC,"Unable to open the report file: %s\n",cmStringNullGuard(rptFn)); + goto errLabel; + } + + rc = cmTimeLinePrintFn(ctx, tlFn, tlPrefixPath, cmRptFileRpt(rptH) ); + + errLabel: + cmRptFileClose(&rptH); + + return rc; +} + cmTlRC_t cmTimeLineTest( cmCtx_t* ctx, const cmChar_t* jsFn, const cmChar_t* prefixPath ) { diff --git a/app/cmTimeLine.h b/app/cmTimeLine.h index 60087c2..af3a29f 100644 --- a/app/cmTimeLine.h +++ b/app/cmTimeLine.h @@ -27,7 +27,8 @@ extern "C" { kFinalizeFailTlRC, kInvalidSeqIdTlRC, kOnsetFailTlRC, - kAssertFailTlRC + kAssertFailTlRC, + kRptFileFailTlRC }; typedef enum @@ -217,6 +218,7 @@ extern "C" { cmTlRC_t cmTimeLinePrint( cmTlH_t h, cmRpt_t* rpt ); cmTlRC_t cmTimeLinePrintFn( cmCtx_t* ctx, const cmChar_t* tlFn, const cmChar_t* prefixPath, cmRpt_t* rpt ); + cmTlRC_t cmTimeLineReport( cmCtx_t* ctx, const cmChar_t* tlFn, const cmChar_t* prefixPath, const cmChar_t* rptFn ); cmTlRC_t cmTimeLineTest( cmCtx_t* ctx, const cmChar_t* tlFn, const cmChar_t* prefixPath ); diff --git a/app/cmXScore.c b/app/cmXScore.c index cf71be1..3e3c75c 100644 --- a/app/cmXScore.c +++ b/app/cmXScore.c @@ -3856,19 +3856,19 @@ void _cmXsWriteMidiSvgLinePoint( cmSvgH_t svgH, double x0, double y0, double x1, } -cmXsRC_t _cmXsWriteMidiSvg( cmCtx_t* ctx, cmXScore_t* p, cmXsMidiFile_t* mf, const cmChar_t* dir, const cmChar_t* fn ) +cmXsRC_t _cmXsWriteMidiSvg( cmCtx_t* ctx, cmXScore_t* p, cmXsMidiFile_t* mf, const cmChar_t* svgFn, bool standAloneFl, bool panZoomFl ) { cmXsRC_t rc = kOkXsRC; cmSvgH_t svgH = cmSvgNullHandle; cmXsSvgEvt_t* e = mf->elist; unsigned noteHeight = 10; - cmChar_t* fn0 = cmMemAllocStr( fn ); - const cmChar_t* svgFn = cmFsMakeFn(dir,fn0 = cmTextAppendSS(fn0,"_midi_svg"),"html",NULL); + //cmChar_t* fn0 = cmMemAllocStr( fn ); + //const cmChar_t* svgFn = cmFsMakeFn(dir,fn0 = cmTextAppendSS(fn0,"_midi_svg"),"html",NULL); const cmChar_t* cssFn = cmFsMakeFn(NULL,"score_midi_svg","css",NULL); cmChar_t* t0 = NULL; // temporary dynamic string unsigned i = 0; const cmXsSvgEvt_t* e0 = NULL; - cmMemFree(fn0); + //cmMemFree(fn0); // create the SVG writer if( cmSvgWriterAlloc(ctx,&svgH) != kOkSvgRC ) @@ -3960,12 +3960,12 @@ cmXsRC_t _cmXsWriteMidiSvg( cmCtx_t* ctx, cmXScore_t* p, cmXsMidiFile_t* mf, con cmErrMsg(&p->err,kSvgFailXsRC,"SVG element insert failed."); if( rc == kOkXsRC ) - if( cmSvgWriterWrite(svgH,cssFn,svgFn) != kOkSvgRC ) + if( cmSvgWriterWrite(svgH,cssFn,svgFn,standAloneFl, panZoomFl) != kOkSvgRC ) rc = cmErrMsg(&p->err,kSvgFailXsRC,"SVG file write to '%s' failed.",cmStringNullGuard(svgFn)); errLabel: cmSvgWriterFree(&svgH); - cmFsFreeFn(svgFn); + //cmFsFreeFn(svgFn); cmFsFreeFn(cssFn); cmMemFree(t0); @@ -4001,7 +4001,7 @@ void _cmXsPushSvgEvent( cmXScore_t* p, cmXsMidiFile_t* mf, unsigned flags, unsig mf->eol = e; } -cmXsRC_t _cmXScoreGenSvg( cmCtx_t* ctx, cmXsH_t h, int beginMeasNumb, const cmChar_t* dir, const cmChar_t* fn ) +cmXsRC_t _cmXScoreGenSvg( cmCtx_t* ctx, cmXsH_t h, int beginMeasNumb, const cmChar_t* svgFn, bool standAloneFl, bool panZoomFl ) { cmXScore_t* p = _cmXScoreHandleToPtr(h); cmXsPart_t* pp = p->partL; @@ -4058,12 +4058,11 @@ cmXsRC_t _cmXScoreGenSvg( cmCtx_t* ctx, cmXsH_t h, int beginMeasNumb, const cmCh _cmXsPushSvgEvent(p,&mf,note->flags,note->tick,note->duration,0,d0,127,NULL); continue; } - } } } - return _cmXsWriteMidiSvg( ctx, p, &mf, dir, fn ); + return _cmXsWriteMidiSvg( ctx, p, &mf, svgFn, standAloneFl, panZoomFl ); } @@ -4073,9 +4072,12 @@ cmXsRC_t cmXScoreTest( const cmChar_t* editFn, const cmChar_t* csvOutFn, const cmChar_t* midiOutFn, + const cmChar_t* svgOutFn, bool reportFl, int beginMeasNumb, - int beginBPM ) + int beginBPM, + bool standAloneFl, + bool panZoomFl ) { cmXsRC_t rc; cmXsH_t h = cmXsNullHandle; @@ -4113,12 +4115,13 @@ cmXsRC_t cmXScoreTest( _cmXsIsMidiFileValid(ctx, h, pp->dirStr, pp->fnStr ); - _cmXScoreGenSvg( ctx, h, beginMeasNumb, pp->dirStr, pp->fnStr ); - cmFsFreePathParts(pp); } + if( svgOutFn != NULL ) + _cmXScoreGenSvg( ctx, h, beginMeasNumb, svgOutFn, standAloneFl, panZoomFl ); + if(reportFl) cmXScoreReport(h,&ctx->rpt,true); diff --git a/app/cmXScore.h b/app/cmXScore.h index c7334cd..19b6205 100644 --- a/app/cmXScore.h +++ b/app/cmXScore.h @@ -72,7 +72,7 @@ extern "C" { // Set reportFl to true to print a report of the score following processing. // Set begMeasNumb to the first measure the to be written to the output csv, MIDI and SVG files. // Set begBPM to 0 to use the tempo from the score otherwise set it to the tempo at begMeasNumb. - cmXsRC_t cmXScoreTest( cmCtx_t* ctx, const cmChar_t* xmlFn, const cmChar_t* reorderFn, const cmChar_t* csvOutFn, const cmChar_t* midiOutFn, bool reportFl, int begMeasNumb, int begBPM ); + cmXsRC_t cmXScoreTest( cmCtx_t* ctx, const cmChar_t* xmlFn, const cmChar_t* reorderFn, const cmChar_t* csvOutFn, const cmChar_t* midiOutFn, const cmChar_t* svgOutFn, bool reportFl, int begMeasNumb, int begBPM, bool svgStandAloneFl, bool svgPanZoomFl ); #ifdef __cplusplus } diff --git a/cmApBuf.c b/cmApBuf.c index a277ac4..a34e6c3 100644 --- a/cmApBuf.c +++ b/cmApBuf.c @@ -610,7 +610,7 @@ cmAbRC_t cmApBufUpdate( n0 = pp->audioFramesCnt; cmApSample_t* bpp = ((cmApSample_t*)pp->audioBytesPtr) + j; - cmApSample_t* dp = bpp; + //cmApSample_t* dp = bpp; bool enaFl = cmIsFlag(cp->fl,kChApFl) && cmIsFlag(cp->fl,kMuteApFl)==false; unsigned decrSmpN = 0; @@ -625,7 +625,7 @@ cmAbRC_t cmApBufUpdate( else // otherwise copy samples from the output buffer to the packet { const cmApSample_t* sp = enaFl ? cp->b + cp->oi : _cmApBuf.zeroBuf; - const cmApSample_t* ep = sp + n0; + //const cmApSample_t* ep = sp + n0; unsigned pi = cp->oi; cp->oi = _cmApCopyOutSamples( enaFl ? cp->b : _cmApBuf.zeroBuf, op->n, cp->oi, (cmApSample_t*)pp->audioBytesPtr, pp->audioFramesCnt, pp->chCnt, j, op->srateMult, cp->gain, &cp->s0 ); @@ -1061,8 +1061,8 @@ void cmApBufReport( cmRpt_t* rpt ) } cmRptPrintf(rpt,"%s - i:%7i o:%7i f:%7i n:%7i err %s:%7i mtr:%5.4f ", - j==0?"IN":"OUT", - ii,oi,fn,ip->n, (j==0?"over":"under"), ip->faultCnt, mtr); + j==0?"IN ":"OUT", + ii,oi,fn,ip->n, (j==0?"over ":"under"), ip->faultCnt, mtr); } diff --git a/cmAudioFile.c b/cmAudioFile.c index 46d259d..1a4da95 100644 --- a/cmAudioFile.c +++ b/cmAudioFile.c @@ -9,6 +9,7 @@ #include "cmAudioFile.h" #include "cmMath.h" #include "cmFileSys.h" +#include "cmRptFile.h" // #define _24to32_aif( p ) ((int)( ((p[0]>127?255:0) << 24) + (((int)p[0]) << 16) + (((int)p[1]) <<8) + p[2])) // no-swap equivalent @@ -1804,6 +1805,37 @@ cmRC_t cmAudioFileReportFn( const cmChar_t* fn, unsigned frmIdx, unsigned fr return cmAudioFileDelete(&h); } +cmRC_t cmAudioFileReportInfo( cmCtx_t* ctx, const cmChar_t* audioFn, const cmChar_t* rptFn ) +{ + cmRC_t rc = kOkAfRC; + cmRptFileH_t rptH = cmRptFileNullHandle; + cmAudioFileInfo_t afInfo; + memset(&afInfo,0,sizeof(afInfo)); + cmAudioFileH_t afH = cmAudioFileNewOpen( audioFn, &afInfo, &rc, &ctx->rpt ); + + + if( rc != kOkAfRC ) + { + rc = cmErrMsg(&ctx->err,rc,"Audio file '%s' open failed.",cmStringNullGuard(audioFn)); + goto errLabel; + } + + if(( rc = cmRptFileCreate(ctx, &rptH, rptFn, NULL )) != kOkRfRC ) + { + rc = cmErrMsg(&ctx->err,kRptFileFailAfRC,"Unable to open the report file: %s\n",cmStringNullGuard(rptFn)); + goto errLabel; + } + + cmAudioFilePrintInfo(&afInfo,cmRptFileRpt(rptH)); + + errLabel: + cmRptFileClose(&rptH); + cmAudioFileDelete(&afH); + + return rc; +} + + cmRC_t cmAudioFileSetSrate( const cmChar_t* fn, unsigned srate ) { cmRC_t rc = kOkAfRC; diff --git a/cmAudioFile.h b/cmAudioFile.h index 62aa925..7623723 100644 --- a/cmAudioFile.h +++ b/cmAudioFile.h @@ -36,6 +36,7 @@ extern "C" { kInvalidFileModeAfRC, kInvalidHandleAfRC, kInvalidChCountAfRC, + kRptFileFailAfRC, kUnknownErrAfRC }; @@ -271,6 +272,8 @@ extern "C" { // Print the cmAudioFileInfo_t to a file. void cmAudioFilePrintInfo( const cmAudioFileInfo_t* infoPtr, cmRpt_t* ); + cmRC_t cmAudioFileReportInfo( cmCtx_t* ctx, const cmChar_t* audioFn, const cmChar_t* rptFn ); + // Print the file header information and frmCnt sample values beginning at frame index frmIdx. cmRC_t cmAudioFileReport( cmAudioFileH_t h, cmRpt_t* rpt, unsigned frmIdx, unsigned frmCnt ); diff --git a/cmMidiFile.c b/cmMidiFile.c index 4683aa9..bf52be2 100644 --- a/cmMidiFile.c +++ b/cmMidiFile.c @@ -1848,7 +1848,22 @@ void _cmMidiFilePrintMsg( cmRpt_t* rpt, const cmMidiTrackMsg_t* tmp ) if( tmp->status == kMetaStId ) { - cmRptPrintf(rpt,"%s ", cmMidiMetaStatusToLabel(tmp->metaId)); + + switch( tmp->metaId ) + { + case kTempoMdId: + cmRptPrintf(rpt,"%s bpm %i", cmMidiMetaStatusToLabel(tmp->metaId),60000000 / tmp->u.iVal); + break; + + case kTimeSigMdId: + cmRptPrintf(rpt,"%s %i %i", cmMidiMetaStatusToLabel(tmp->metaId), tmp->u.timeSigPtr->num,tmp->u.timeSigPtr->den); + break; + + + default: + cmRptPrintf(rpt,"%s ", cmMidiMetaStatusToLabel(tmp->metaId)); + + } } else { @@ -1923,9 +1938,11 @@ cmMidiFileDensity_t* cmMidiFileNoteDensity( cmMidiFileH_t h, unsigned* cntRef ) { dV[k].uid = msgs[i]->uid; dV[k].amicro = msgs[i]->amicro; - + + // count the number of notes occuring in the time window + // between this note and one second prior to this note. for(j=i; j>=0; --j) - { + { if( msgs[i]->amicro - msgs[j]->amicro > 1000000 ) break; @@ -1979,7 +1996,7 @@ cmMfRC_t cmMidiFileGenPlotFile( cmCtx_t* ctx, const cmChar_t* midiFn, const cmCh return rc; } -cmMfRC_t cmMidiFileGenSvgFile( cmCtx_t* ctx, const cmChar_t* midiFn, const cmChar_t* outSvgFn, const cmChar_t* cssFn ) +cmMfRC_t cmMidiFileGenSvgFile( cmCtx_t* ctx, const cmChar_t* midiFn, const cmChar_t* outSvgFn, const cmChar_t* cssFn, bool standAloneFl, bool panZoomFl ) { cmMfRC_t rc = kOkMfRC; cmSvgH_t svgH = cmSvgNullHandle; @@ -2061,7 +2078,7 @@ cmMfRC_t cmMidiFileGenSvgFile( cmCtx_t* ctx, const cmChar_t* midiFn, const cmCha cmMemFree(tx); if( rc == kOkMfRC ) - if( cmSvgWriterWrite(svgH,cssFn,outSvgFn) != kOkSvgRC ) + if( cmSvgWriterWrite(svgH,cssFn,outSvgFn, standAloneFl, panZoomFl) != kOkSvgRC ) rc = cmErrMsg(&ctx->err,kSvgFailMfRC,"SVG file write to '%s' failed.",cmStringNullGuard(outSvgFn)); diff --git a/cmMidiFile.h b/cmMidiFile.h index dcf6176..6775f31 100644 --- a/cmMidiFile.h +++ b/cmMidiFile.h @@ -229,7 +229,7 @@ extern "C" { // Generate a piano-roll plot description file which can be displayed with cmXScore.m cmMfRC_t cmMidiFileGenPlotFile( cmCtx_t* ctx, const cmChar_t* midiFn, const cmChar_t* outFn ); - cmMfRC_t cmMidiFileGenSvgFile( cmCtx_t* ctx, const cmChar_t* midiFn, const cmChar_t* outSvgFn, const cmChar_t* cssFn ); + cmMfRC_t cmMidiFileGenSvgFile( cmCtx_t* ctx, const cmChar_t* midiFn, const cmChar_t* outSvgFn, const cmChar_t* cssFn, bool standAloneFl, bool panZoomFl ); // Generate a text file reportusing cmMIdiFilePrintMsgs() cmMfRC_t cmMidiFileReport( cmCtx_t* ctx, const cmChar_t* midiFn, const cmChar_t* outTextFn ); diff --git a/cmPgmOpts.c b/cmPgmOpts.c index 8c0d703..a0716bf 100644 --- a/cmPgmOpts.c +++ b/cmPgmOpts.c @@ -242,13 +242,14 @@ _cmPoOpt_t* _cmPgmOptWordIdToOptRecd( _cmPo_t* p, const cmChar_t* wordId ) cmPoRC_t _cmPgmOptInstall( _cmPo_t* p, unsigned numId, const cmChar_t charId, const cmChar_t* wordId, unsigned cflags, unsigned sflags, unsigned enumId, unsigned cnt, const cmChar_t* helpStr, _cmPoOpt_t** rpp ) -{ +{ // validate the num. id - if( cmIsNotFlag(sflags,kEnumPoFl) && _cmPgmOptNumIdToOptRecd(p,numId) != NULL ) + if( cmIsNotFlag(sflags,kEnumPoFl) && _cmPgmOptNumIdToOptRecd(p,numId) != NULL ) return cmErrMsg(&p->err,kDuplicateIdPoRC,"The numeric id '%i' was already used by another parameter.",numId); + // validate the char. id - if( _cmPgmOptCharIdToOptRecd(p,charId) != NULL ) + if(_cmPgmOptCharIdToOptRecd(p,charId) != NULL ) return cmErrMsg(&p->err,kDuplicateIdPoRC,"The character id -'%c' was already used by another parameter.",charId); // validate the word. id diff --git a/cmProc4.c b/cmProc4.c index f4dbb76..cdc49e2 100644 --- a/cmProc4.c +++ b/cmProc4.c @@ -3909,7 +3909,7 @@ cmRC_t cmRecdPlayInsertRecord(cmRecdPlay* p, unsigned labelSymId, const return rc; } - return cmCtxRtCondition( &p->obj, cmInvalidArgRC, "The fragment label symbol id '%i' not found for 'begin record'.",labelSymId); + return cmCtxRtCondition( &p->obj, cmInvalidArgRC, "The fragment label symbol id '%i' not found for 'begin record'.",labelSymId); } diff --git a/cmSvgWriter.c b/cmSvgWriter.c index 7845955..2433f1a 100644 --- a/cmSvgWriter.c +++ b/cmSvgWriter.c @@ -185,16 +185,7 @@ void _cmSvgWriterFlipY( cmSvg_t* p, unsigned height ) } } -/* - "\n" - "\n" - - */ - -cmSvgRC_t cmSvgWriterWrite( cmSvgH_t h, const cmChar_t* cssFn, const cmChar_t* outFn ) +cmSvgRC_t cmSvgWriterWrite( cmSvgH_t h, const cmChar_t* cssFn, const cmChar_t* outFn, bool standAloneFl, bool panZoomFl ) { cmSvgRC_t rc = kOkSvgRC; cmSvg_t* p = _cmSvgHandleToPtr(h); @@ -205,29 +196,36 @@ cmSvgRC_t cmSvgWriterWrite( cmSvgH_t h, const cmChar_t* cssFn, const cmChar_t* cmChar_t* s0 = NULL; cmChar_t* s1 = NULL; - cmChar_t hdr[] = + cmChar_t panZoomHdr[] = + "\n" + "\n"; + + + cmChar_t standAloneFmt[] = "\n" "\n" "\n" "\n" "\n" + "%s\n" "\n" - "\n" - "\n"; + "\n"; + + cmChar_t svgFmt[] = "\n"; - - _cmSvgSize(p, &svgWidth, &svgHeight ); _cmSvgWriterFlipY( p, svgHeight ); - // print the file header - if( (s0 = cmTsPrintfP(s0,hdr,cssFn,svgWidth,svgHeight)) == NULL ) - { - rc = cmErrMsg(&p->err,kPrintFailSvgRC,"File prefix write failed."); - goto errLabel; - } + s0 = cmTsPrintfP(s0, standAloneFmt, cssFn, panZoomFl ? panZoomHdr : ""); + + s1 = cmTsPrintfP(s1,"%s%s", standAloneFl ? s0 : "", svgFmt); + s0 = cmTsPrintfP(s0,s1,svgWidth,svgHeight); + for(; e!=NULL; e=e->link) { switch( e->id ) @@ -262,12 +260,15 @@ cmSvgRC_t cmSvgWriterWrite( cmSvgH_t h, const cmChar_t* cssFn, const cmChar_t* } - if( (s1 = cmTsPrintfP(s1,"\n\n\n")) == NULL ) + if( (s1 = cmTsPrintfP(s1,"\n")) == NULL ) { rc = cmErrMsg(&p->err,kPrintFailSvgRC,"File suffix write failed."); goto errLabel; } - + + if( standAloneFl ) + s1 = cmTextAppendSS(s1,"\n\n"); + if( cmFileOpen(&fH,outFn,kWriteFileFl,p->err.rpt) != kOkFileRC ) { rc = cmErrMsg(&p->err,kFileFailSvgRC,"SVG file create failed for '%s'.",cmStringNullGuard(outFn)); @@ -280,6 +281,7 @@ cmSvgRC_t cmSvgWriterWrite( cmSvgH_t h, const cmChar_t* cssFn, const cmChar_t* goto errLabel; } + errLabel: cmFileClose(&fH); diff --git a/cmSvgWriter.h b/cmSvgWriter.h index 01214cf..d8a4ec9 100644 --- a/cmSvgWriter.h +++ b/cmSvgWriter.h @@ -30,7 +30,7 @@ enum // and the Javascript file svg-pan-zoom.min.js from https://github.com/ariutta/svg-pan-zoom. // Both the CSS file and svg-pan-zoom.min.js should therefore be in the same directory // as the output HTML file. - cmSvgRC_t cmSvgWriterWrite( cmSvgH_t h, const cmChar_t* cssFn, const cmChar_t* outFn ); + cmSvgRC_t cmSvgWriterWrite( cmSvgH_t h, const cmChar_t* cssFn, const cmChar_t* outFn, bool standaloneFl, bool panZoomFl ); #ifdef __cplusplus }