diff --git a/Makefile.am b/Makefile.am index d0d8766..4efe2a3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -68,8 +68,11 @@ cmHDR += src/libcm/cmProcObj.h src/libcm/cmProc.h src/libcm/cmProc2.h src/libcm/ cmSRC += src/libcm/cmProcObj.c src/libcm/cmProc.c src/libcm/cmProc2.c src/libcm/cmProc3.c src/libcm/cmProc4.c src/libcm/cmProcTest.c -cmHDR += src/libcm/app/cmOnset.h src/libcm/app/cmTimeLine.h src/libcm/app/cmScore.h src/libcm/app/cmPickup.h src/libcm/cmRbm.h -cmSRC += src/libcm/app/cmOnset.c src/libcm/app/cmTimeLine.c src/libcm/app/cmScore.c src/libcm/app/cmPickup.c src/libcm/cmRbm.c +cmHDR += src/libcm/app/cmOnset.h src/libcm/app/cmTimeLine.h src/libcm/app/cmScore.h src/libcm/app/cmScoreProc.h +cmSRC += src/libcm/app/cmOnset.c src/libcm/app/cmTimeLine.c src/libcm/app/cmScore.c src/libcm/app/cmScoreProc.c + +cmHDR += src/libcm/app/cmPickup.h src/libcm/cmRbm.h +cmSRC += src/libcm/app/cmPickup.c src/libcm/cmRbm.c if OS_LINUX cmSRC += src/libcm/linux/cmFileSysLinux.c src/libcm/linux/cmAudioPortAlsa.c src/libcm/linux/cmMidiAlsa.c diff --git a/app/cmScoreProc.c b/app/cmScoreProc.c new file mode 100644 index 0000000..4700224 --- /dev/null +++ b/app/cmScoreProc.c @@ -0,0 +1,157 @@ +#include "cmGlobal.h" +#include "cmFloatTypes.h" +#include "cmRpt.h" +#include "cmErr.h" +#include "cmCtx.h" +#include "cmMem.h" +#include "cmMallocDebug.h" +#include "cmLinkedHeap.h" +#include "cmSymTbl.h" +#include "cmJson.h" +#include "cmMidi.h" +#include "cmMidiFile.h" +#include "cmAudioFile.h" +#include "cmScore.h" +#include "cmTimeLine.h" +#include "cmScoreProc.h" + +enum +{ + kOkSpRC, + kJsonFailSpRC, + kScoreFailSpRC, + kTimeLineFailSpRC +}; + + +typedef struct +{ + cmErr_t err; + cmScH_t scH; + const cmChar_t* tlFn; + cmTlH_t tlH; + cmJsonH_t jsH; + unsigned* dynArray; + unsigned dynCnt; + double srate; +} cmSp_t; + + +cmSpRC_t _cmJsonReadDynArray( cmJsonH_t jsH, unsigned** dynArray, unsigned* dynCnt ) +{ + cmJsonNode_t* np; + int i; + + if( cmJsonPathToArray(jsH, NULL, NULL, "dynRef", &np ) != kOkJsRC ) + return kJsonFailSpRC; + + *dynCnt = cmJsonChildCount(np); + + *dynArray = cmMemAllocZ(unsigned,*dynCnt); + + for(i=0; i<*dynCnt; ++i) + if( cmJsonUIntValue( cmJsonArrayElement(np,i), (*dynArray)+i ) != kOkJsRC ) + return kJsonFailSpRC; + + return kOkSpRC; +} + +cmSpRC_t _cmScoreProcInit( cmCtx_t* ctx, cmSp_t* p, const cmChar_t* rsrcFn ) +{ + cmSpRC_t rc = kOkSpRC; + const cmChar_t* scFn = NULL; + const cmChar_t* tlFn = NULL; + + p->srate = 96000; + + cmErrSetup(&p->err,&ctx->rpt,"ScoreProc"); + + // open the resource file + if( cmJsonInitializeFromFile( &p->jsH, rsrcFn, ctx ) != kOkJsRC ) + { + rc = cmErrMsg(&p->err,kJsonFailSpRC,"Unable to load the main resource file:%s.",cmStringNullGuard(rsrcFn)); + goto errLabel; + } + + // get the time line fn + if( cmJsonPathToString( p->jsH, NULL, NULL, "timeLineFn", &tlFn ) != kOkJsRC ) + { + rc = cmErrMsg(&p->err,kJsonFailSpRC,"Unable to locate the time line file name in the main resource file:%s",cmStringNullGuard(rsrcFn)); + goto errLabel; + } + + // get the score file name + if( cmJsonPathToString( p->jsH, NULL, NULL, "scoreFn", &scFn ) != kOkJsRC ) + { + rc = cmErrMsg(&p->err,kJsonFailSpRC,"Unable to locate the score file name in the main resource file:%s",cmStringNullGuard(rsrcFn)); + goto errLabel; + } + + // read the dynamics reference array + if((rc = _cmJsonReadDynArray( p->jsH, &p->dynArray, &p->dynCnt )) != kOkSpRC ) + { + rc = cmErrMsg(&p->err,rc,"Unable to read dynamics reference array resource from the main resource file:%s",cmStringNullGuard(rsrcFn)); + goto errLabel; + } + + + // load the score file + if( cmScoreInitialize(ctx, &p->scH, scFn, p->srate, NULL, 0, NULL, NULL, cmSymTblNullHandle ) != kOkScRC ) + { + rc = cmErrMsg(&p->err,kScoreFailSpRC,"Score load failed for score file:%s.",cmStringNullGuard(scFn)); + goto errLabel; + } + + if( cmTimeLineInitialize(ctx, &p->tlH, NULL, NULL ) != kOkTlRC ) + { + rc = cmErrMsg(&p->err,kTimeLineFailSpRC,"Time line load failed for time line file:%s.",cmStringNullGuard(tlFn)); + goto errLabel; + } + + errLabel: + return rc; +} + +cmSpRC_t _cmScoreProcFinal( cmSp_t* p ) +{ + cmSpRC_t rc = kOkSpRC; + + if( cmScoreFinalize(&p->scH) != kOkScRC ) + cmErrMsg(&p->err,kScoreFailSpRC,"Score finalize failed."); + + if( cmTimeLineFinalize(&p->tlH) != kOkTlRC ) + cmErrMsg(&p->err,kTimeLineFailSpRC,"Time line finalize failed."); + + if( cmJsonFinalize(&p->jsH) != kOkJsRC ) + cmErrMsg(&p->err,kJsonFailSpRC,"JSON finalize failed."); + + cmMemFree(p->dynArray); + + return rc; +} + +unsigned cmScoreProc(cmCtx_t* ctx) +{ + cmSpRC_t rc = kOkSpRC; + const cmChar_t* rsrcFn = "/home/kevin/.kc/time_line.js"; + cmSp_t sp; + + memset(&sp,0,sizeof(sp)); + + cmRptPrintf(&ctx->rpt,"Score Proc Start\n"); + + if((rc = _cmScoreProcInit(ctx,&sp,rsrcFn)) != kOkSpRC ) + goto errLabel; + + + + + errLabel: + _cmScoreProcFinal(&sp); + + cmRptPrintf(&ctx->rpt,"Score Proc End\n"); + + return rc; + +} + diff --git a/app/cmScoreProc.h b/app/cmScoreProc.h new file mode 100644 index 0000000..12379f4 --- /dev/null +++ b/app/cmScoreProc.h @@ -0,0 +1,16 @@ +#ifndef cmScoreProc_h +#define cmScoreProc_h + +#ifdef __cplusplus +extern "C" { +#endif + + typedef unsigned cmSpRC_t; + + cmSpRC_t cmScoreProc(cmCtx_t* ctx ); + +#ifdef __cplusplus +} +#endif + +#endif