cmTakeSeqBldr.h/c : Completed code for cmTakeSeqBldrAlloc()/Free() and initial testing.
This commit is contained in:
parent
b2dee6219f
commit
1b6a798401
@ -40,8 +40,14 @@ typedef struct
|
||||
cmJsonH_t jsH;
|
||||
const cmChar_t* tlFn;
|
||||
const cmChar_t* scFn;
|
||||
cmTakeTsb_t* takeV;
|
||||
const cmChar_t* tlPrefixPath;
|
||||
|
||||
cmTakeTsb_t* takeV; // takeV[ takeN ]
|
||||
unsigned takeN;
|
||||
|
||||
cmTlH_t tlH;
|
||||
cmScH_t scH;
|
||||
|
||||
} cmTsb_t;
|
||||
|
||||
cmTakeSeqBldrH_t cmTakeSeqBldrNullHandle = cmSTATIC_NULL_HANDLE;
|
||||
@ -52,15 +58,39 @@ cmTsb_t* _cmTsbHandleToPtr( cmTakeSeqBldrH_t h )
|
||||
return p;
|
||||
}
|
||||
|
||||
cmTsbRC_t _cmTsbFree( cmTsb_t* p )
|
||||
cmTsbRC_t _cmTsbScoreTrkFree( cmTsb_t* p )
|
||||
{
|
||||
cmTsbRC_t rc = kOkTsbRC;
|
||||
cmTsbRC_t rc = kOkTsbRC;
|
||||
unsigned i;
|
||||
|
||||
if( cmJsonFinalize(&p->jsH) != kOkJsRC )
|
||||
{
|
||||
rc = cmErrMsg(&p->err,kJsonFailTsbRC,"JSON object finalize failed.");
|
||||
goto errLabel;
|
||||
}
|
||||
|
||||
for(i=0; i<p->takeN; ++i)
|
||||
cmMemPtrFree(&p->takeV[i].noteV);
|
||||
|
||||
cmMemPtrFree(&p->takeV);
|
||||
|
||||
if( cmTimeLineFinalize(&p->tlH) != kOkTlRC )
|
||||
rc = cmErrMsg(&p->err,kTimeLineFailTsbRC,"Time line object finalize failed.");
|
||||
|
||||
if( cmScoreFinalize(&p->scH) != kOkScRC )
|
||||
rc = cmErrMsg(&p->err,kScoreFailTsbRC,"Score finalize failed.");
|
||||
|
||||
errLabel:
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
cmTsbRC_t _cmTsbFree( cmTsb_t* p )
|
||||
{
|
||||
cmTsbRC_t rc = kOkTsbRC;
|
||||
|
||||
if((rc = _cmTsbScoreTrkFree(p)) != kOkTsbRC )
|
||||
goto errLabel;
|
||||
|
||||
cmMemFree(p);
|
||||
|
||||
@ -69,94 +99,45 @@ cmTsbRC_t _cmTsbFree( cmTsb_t* p )
|
||||
}
|
||||
|
||||
|
||||
cmTsbRC_t cmTakeSeqBldrAlloc( cmCtx_t* ctx, cmTakeSeqBldrH_t* hp )
|
||||
cmTsbRC_t _cmTsbLoadScoreTrkFile( cmTsb_t* p, const cmChar_t* scoreTrkFn )
|
||||
{
|
||||
cmTsbRC_t rc;
|
||||
if((rc = cmTakeSeqBldrFree(hp)) != kOkTsbRC )
|
||||
return kOkTsbRC;
|
||||
|
||||
cmTsb_t* p = cmMemAllocZ(cmTsb_t,1);
|
||||
|
||||
cmErrSetup(&p->err,&ctx->rpt,"TakeSeqBldr");
|
||||
|
||||
p->ctx = *ctx;
|
||||
hp->h = p;
|
||||
|
||||
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
cmTsbRC_t cmTakeSeqBldrAllocFn( cmCtx_t* ctx, cmTakeSeqBldrH_t* hp, const cmChar_t* tsbFn )
|
||||
{
|
||||
cmTsbRC_t rc;
|
||||
if((rc = cmTakeSeqBldrAlloc(ctx,hp)) != kOkTsbRC )
|
||||
return rc;
|
||||
|
||||
if((rc = cmTakeSeqBldrInitialize(*hp,tsbFn)) != kOkTsbRC )
|
||||
return rc;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
cmTsbRC_t cmTakeSeqBldrFree( cmTakeSeqBldrH_t* hp )
|
||||
{
|
||||
cmRC_t rc = kOkTsbRC;
|
||||
|
||||
if( hp == NULL || cmTakeSeqBldrIsValid(*hp)==false )
|
||||
return kOkTsbRC;
|
||||
|
||||
cmTsb_t* p = _cmTsbHandleToPtr(*hp);
|
||||
|
||||
if((rc = _cmTsbFree(p)) != kOkTsbRC )
|
||||
return rc;
|
||||
|
||||
hp->h = NULL;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
bool cmTakeSeqBldrIsValid( cmTakeSeqBldrH_t h )
|
||||
{ return h.h != NULL; }
|
||||
|
||||
|
||||
cmTsbRC_t cmTakeSeqBldrInitialize( cmTakeSeqBldrH_t h, const cmChar_t* tsbFn )
|
||||
{
|
||||
cmTsbRC_t rc = kOkTsbRC;
|
||||
cmTsb_t* p = _cmTsbHandleToPtr(h);
|
||||
cmTsbRC_t rc = kOkTsbRC;
|
||||
cmJsonNode_t* tkArrObj = NULL;
|
||||
cmJsRC_t jsRC = kOkJsRC;
|
||||
const cmChar_t* errMsg = NULL;
|
||||
unsigned i;
|
||||
|
||||
// initialize the TSB json object
|
||||
if(( rc = cmJsonInitializeFromFile(&p->jsH,tsbFn,&p->ctx)) != kOkJsRC )
|
||||
if(( rc = cmJsonInitializeFromFile(&p->jsH,scoreTrkFn,&p->ctx)) != kOkJsRC )
|
||||
{
|
||||
rc = cmErrMsg(&p->err,kJsonFailTsbRC,"The Take Sequence Builder JSON file object could not be initialized from '%s'.",cmStringNullGuard(tsbFn));
|
||||
rc = cmErrMsg(&p->err,kJsonFailTsbRC,"The Take Sequence Builder JSON file object could not be initialized from '%s'.",cmStringNullGuard(scoreTrkFn));
|
||||
goto errLabel;
|
||||
}
|
||||
|
||||
// parse the header
|
||||
if((jsRC = cmJsonMemberValues( cmJsonRoot(p->jsH), &errMsg,
|
||||
"tlFn",kStringTId,&p->tlFn,
|
||||
"scFn",kStringTId,&p->scFn,
|
||||
"takeArray",kArrayTId | kOptArgJsFl,&tkArrObj,
|
||||
"timeLineFn", kStringTId, &p->tlFn,
|
||||
"scoreFn", kStringTId, &p->scFn,
|
||||
"tlPrefixPath", kStringTId, &p->tlPrefixPath,
|
||||
"takeArray", kArrayTId | kOptArgJsFl, &tkArrObj,
|
||||
0 )) != kOkJsRC )
|
||||
{
|
||||
if( jsRC == kNodeNotFoundJsRC && errMsg != NULL )
|
||||
rc = cmErrMsg(&p->err,kParseFailTsbRC,"JSON file header parse failed missing required field:'%s'",errMsg);
|
||||
else
|
||||
rc = cmErrMsg(&p->err,kParseFailTsbRC,"JSON file header parse failed.");
|
||||
|
||||
goto errLabel;
|
||||
}
|
||||
|
||||
// count of take records
|
||||
unsigned tkArrN = cmJsonChildCount(tkArrObj);
|
||||
p->takeN = cmJsonChildCount(tkArrObj);
|
||||
|
||||
// array of take records
|
||||
p->takeV = cmMemAllocZ(cmTakeTsb_t,tkArrN);
|
||||
p->takeV = cmMemAllocZ(cmTakeTsb_t,p->takeN);
|
||||
|
||||
// for each take record
|
||||
for(i=0; i<tkArrN; ++i)
|
||||
for(i=0; i<p->takeN; ++i)
|
||||
{
|
||||
cmJsonNode_t* takeObj = NULL;
|
||||
cmJsonNode_t* noteArrObj = NULL;
|
||||
@ -179,7 +160,9 @@ cmTsbRC_t cmTakeSeqBldrInitialize( cmTakeSeqBldrH_t h, const cmChar_t* tsbFn )
|
||||
if( jsRC == kNodeNotFoundJsRC && errMsg != NULL )
|
||||
rc = cmErrMsg(&p->err,kParseFailTsbRC,"JSON file take record parse failed missing required field:'%s'",errMsg);
|
||||
else
|
||||
rc = cmErrMsg(&p->err,kParseFailTsbRC,"JSON file take record parse failed.");
|
||||
rc = cmErrMsg(&p->err,kParseFailTsbRC,"JSON file take record parse failed.");
|
||||
|
||||
goto errLabel;
|
||||
}
|
||||
|
||||
// get the count of note records
|
||||
@ -211,21 +194,103 @@ cmTsbRC_t cmTakeSeqBldrInitialize( cmTakeSeqBldrH_t h, const cmChar_t* tsbFn )
|
||||
rc = cmErrMsg(&p->err,kParseFailTsbRC,"JSON file note record parse failed missing required field:'%s'",errMsg);
|
||||
else
|
||||
rc = cmErrMsg(&p->err,kParseFailTsbRC,"JSON file note record parse failed.");
|
||||
|
||||
goto errLabel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
errLabel:
|
||||
if( rc != kOkTsbRC )
|
||||
rc = _cmTsbScoreTrkFree(p);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
cmTsbRC_t cmTakeSeqBldrLoadSection( cmTakeSeqBldrH_t h, unsigned tlMarkUid, bool overwriteFL )
|
||||
cmTsbRC_t cmTakeSeqBldrAlloc( cmCtx_t* ctx, cmTakeSeqBldrH_t* hp )
|
||||
{
|
||||
cmTsbRC_t rc;
|
||||
if((rc = cmTakeSeqBldrFree(hp)) != kOkTsbRC )
|
||||
return kOkTsbRC;
|
||||
|
||||
cmTsb_t* p = cmMemAllocZ(cmTsb_t,1);
|
||||
|
||||
cmErrSetup(&p->err,&ctx->rpt,"TakeSeqBldr");
|
||||
|
||||
p->ctx = *ctx;
|
||||
hp->h = p;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
cmTsbRC_t cmTakeSeqBldrAllocFn( cmCtx_t* ctx, cmTakeSeqBldrH_t* hp, const cmChar_t* scoreTrkFn )
|
||||
{
|
||||
cmTsbRC_t rc;
|
||||
if((rc = cmTakeSeqBldrAlloc(ctx,hp)) != kOkTsbRC )
|
||||
return rc;
|
||||
|
||||
if((rc = cmTakeSeqBldrInitialize(*hp,scoreTrkFn)) != kOkTsbRC )
|
||||
return rc;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
cmTsbRC_t cmTakeSeqBldrFree( cmTakeSeqBldrH_t* hp )
|
||||
{
|
||||
cmRC_t rc = kOkTsbRC;
|
||||
|
||||
if( hp == NULL || cmTakeSeqBldrIsValid(*hp)==false )
|
||||
return kOkTsbRC;
|
||||
|
||||
cmTsb_t* p = _cmTsbHandleToPtr(*hp);
|
||||
|
||||
if((rc = _cmTsbFree(p)) != kOkTsbRC )
|
||||
return rc;
|
||||
|
||||
hp->h = NULL;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
bool cmTakeSeqBldrIsValid( cmTakeSeqBldrH_t h )
|
||||
{ return h.h != NULL; }
|
||||
|
||||
|
||||
cmTsbRC_t cmTakeSeqBldrInitialize( cmTakeSeqBldrH_t h, const cmChar_t* scoreTrkFn )
|
||||
{
|
||||
cmTsbRC_t rc = kOkTsbRC;
|
||||
cmTsb_t* p = _cmTsbHandleToPtr(h);
|
||||
|
||||
if(( rc = _cmTsbLoadScoreTrkFile( p, scoreTrkFn )) != kOkTsbRC )
|
||||
return rc;
|
||||
|
||||
if( cmTimeLineInitializeFromFile(&p->ctx, &p->tlH, NULL, NULL, p->tlFn, p->tlPrefixPath ) != kOkTlRC )
|
||||
{
|
||||
rc = cmErrMsg(&p->err,kTimeLineFailTsbRC,"The time-line file '%s' could not be loaded.",p->tlFn);
|
||||
goto errLabel;
|
||||
}
|
||||
|
||||
if( cmScoreInitialize(&p->ctx, &p->scH, p->scFn, 0, NULL, 0, NULL, NULL, cmSymTblNullHandle ) != kOkScRC )
|
||||
{
|
||||
rc = cmErrMsg(&p->err,kScoreFailTsbRC,"The score file '%s' could not be loaded.",p->scFn);
|
||||
goto errLabel;
|
||||
}
|
||||
|
||||
errLabel:
|
||||
if( rc != kOkTsbRC )
|
||||
_cmTsbScoreTrkFree(p);
|
||||
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
cmTsbRC_t cmTakeSeqBldrLoadTake( cmTakeSeqBldrH_t h, unsigned tlMarkUid, bool overwriteFL )
|
||||
{
|
||||
cmTsbRC_t rc = kOkTsbRC;
|
||||
return rc;
|
||||
}
|
||||
|
||||
cmTsbRC_t cmTakeSeqBldrUnloadSection( cmTakeSeqBldrH_t h, unsigned tlMarkUid )
|
||||
cmTsbRC_t cmTakeSeqBldrUnloadTake( cmTakeSeqBldrH_t h, unsigned tlMarkUid )
|
||||
{
|
||||
cmTsbRC_t rc = kOkTsbRC;
|
||||
return rc;
|
||||
@ -269,12 +334,12 @@ cmTsbRC_t cmTakeSeqBldrWriteMidiFile( cmTakeSeqBldrH_t h, const char* fn )
|
||||
|
||||
cmTsbRC_t cmTakeSeqBldrTest( cmCtx_t* ctx )
|
||||
{
|
||||
const cmChar_t* tsbFn = "/home/kevin/src/cmkc/src/kc/data/assoc0.js";
|
||||
const cmChar_t* scoreTrkFn = "/home/kevin/src/cmkc/src/kc/data/assoc0.js";
|
||||
cmTakeSeqBldrH_t tsbH = cmTakeSeqBldrNullHandle;
|
||||
cmTsbRC_t tsbRC = kOkTsbRC;
|
||||
|
||||
if((tsbRC = cmTakeSeqBldrAllocFn(ctx, &tsbH, tsbFn )) != kOkTsbRC )
|
||||
return cmErrMsg(&ctx->err,tsbRC,"TSB Allocate and parse '%s' failed.",tsbFn);
|
||||
if((tsbRC = cmTakeSeqBldrAllocFn(ctx, &tsbH, scoreTrkFn )) != kOkTsbRC )
|
||||
return cmErrMsg(&ctx->err,tsbRC,"TSB Allocate and parse '%s' failed.",scoreTrkFn);
|
||||
|
||||
if((tsbRC = cmTakeSeqBldrFree(&tsbH)) != kOkTsbRC )
|
||||
return cmErrMsg(&ctx->err,tsbRC,"TSB Free failed.");
|
||||
|
@ -10,7 +10,9 @@ extern "C" {
|
||||
{
|
||||
kOkTsbRC = cmOkRC,
|
||||
kJsonFailTsbRC,
|
||||
kParseFailTsbRC
|
||||
kParseFailTsbRC,
|
||||
kTimeLineFailTsbRC,
|
||||
kScoreFailTsbRC
|
||||
};
|
||||
|
||||
typedef cmRC_t cmTsbRC_t;
|
||||
@ -19,13 +21,13 @@ extern "C" {
|
||||
extern cmTakeSeqBldrH_t cmTakeSeqBldrNullHandle;
|
||||
|
||||
cmTsbRC_t cmTakeSeqBldrAlloc( cmCtx_t* ctx, cmTakeSeqBldrH_t* hp );
|
||||
cmTsbRC_t cmTakeSeqBldrAllocFn( cmCtx_t* ctx, cmTakeSeqBldrH_t* hp, const cmChar_t* tsbFn );
|
||||
cmTsbRC_t cmTakeSeqBldrAllocFn( cmCtx_t* ctx, cmTakeSeqBldrH_t* hp, const cmChar_t* scoreTrkFn );
|
||||
|
||||
cmTsbRC_t cmTakeSeqBldrFree( cmTakeSeqBldrH_t* hp );
|
||||
|
||||
bool cmTakeSeqBldrIsValid( cmTakeSeqBldrH_t h );
|
||||
|
||||
cmTsbRC_t cmTakeSeqBldrInitialize( cmTakeSeqBldrH_t h, const cmChar_t* tsbFn );
|
||||
cmTsbRC_t cmTakeSeqBldrInitialize( cmTakeSeqBldrH_t h, const cmChar_t* scoreTrkFn );
|
||||
|
||||
// Load a group of notes delinated by a time-line marker into the sequence.
|
||||
// If notes overlap with existing notes according to their 'scEvtIdx' attribute:
|
||||
@ -38,8 +40,8 @@ extern "C" {
|
||||
//
|
||||
// If no overlapping notes exist then the incoming section is aligned by estimating
|
||||
// the alignment with existing notes using the score alone.
|
||||
cmTsbRC_t cmTakeSeqBldrLoadSection( cmTakeSeqBldrH_t h, unsigned tlMarkUid, bool overwriteFL );
|
||||
cmTsbRC_t cmTakeSeqBldrUnloadSection( cmTakeSeqBldrH_t h, unsigned tlMarkUid );
|
||||
cmTsbRC_t cmTakeSeqBldrLoadTake( cmTakeSeqBldrH_t h, unsigned tlMarkUid, bool overwriteFL );
|
||||
cmTsbRC_t cmTakeSeqBldrUnloadTake( cmTakeSeqBldrH_t h, unsigned tlMarkUid );
|
||||
|
||||
// Fill in missing notes from the score.
|
||||
cmTsbRC_t cmTakeSeqBldrInsertScoreNotes( cmTakeSeqBldrH_t h, unsigned begScEvtIdx, unsigned endScEvtId );
|
||||
|
Loading…
Reference in New Issue
Block a user