cmScoreProc.c : Reorganized the score processor to support plugging in different
score processing algorithms without changing the processor. Created the shell code for generating performance editing data.
This commit is contained in:
parent
cac6e8e974
commit
88d5d9a499
@ -28,19 +28,20 @@ enum
|
||||
kTimeLineFailSpRC,
|
||||
kScoreMatchFailSpRC,
|
||||
kFileFailSpRC,
|
||||
kProcFailSpRC
|
||||
};
|
||||
|
||||
typedef struct _cmScMeas_t
|
||||
typedef enum
|
||||
{
|
||||
cmTlMarker_t* markPtr; // time-line marker in which this 'set' exists
|
||||
cmScoreSet_t* setPtr; // score set on which this measurment is based
|
||||
double value; // the value of the measurement
|
||||
double cost; // the quality of the perf->score match
|
||||
struct _cmScMeas_t* link;
|
||||
} _cmScMeas_t;
|
||||
kBeginSectionSpId,
|
||||
kEndSectionSpId
|
||||
} cmScoreProcSelId_t;
|
||||
|
||||
struct cmSp_str;
|
||||
|
||||
typedef struct
|
||||
typedef cmSpRC_t (*cmScoreProcCb_t)( void* arg, struct cmSp_str* p, cmScoreProcSelId_t id, cmTlMarker_t* curMarkPtr );
|
||||
|
||||
typedef struct cmSp_str
|
||||
{
|
||||
cmErr_t err; // score proc object error state
|
||||
cmCtx* ctx; // application context
|
||||
@ -51,13 +52,12 @@ typedef struct
|
||||
unsigned* dynArray; // dynArray[dynCnt] dynamics reference array
|
||||
unsigned dynCnt; //
|
||||
double srate; //
|
||||
cmScMeas* meas; // performance analyzer
|
||||
cmScMatcher* match; // score follower
|
||||
|
||||
cmTlMarker_t* curMarkPtr;
|
||||
_cmScMeas_t* list_beg;
|
||||
_cmScMeas_t* list_end;
|
||||
_cmScMeas_t* slist_beg;
|
||||
cmScMatcherCb_t matchCb; // score follower callback
|
||||
cmScoreProcCb_t procCb; // score processor callback
|
||||
void* cbArg; // callback arg. for both matchCb and procCb.
|
||||
|
||||
} cmSp_t;
|
||||
|
||||
|
||||
@ -81,15 +81,13 @@ cmSpRC_t _cmJsonReadDynArray( cmJsonH_t jsH, unsigned** dynArray, unsigned* dynC
|
||||
return kOkSpRC;
|
||||
}
|
||||
|
||||
cmSpRC_t _cmScoreProcInit( cmCtx_t* ctx, cmSp_t* p, const cmChar_t* rsrcFn )
|
||||
cmSpRC_t _cmScoreProcInit( cmCtx_t* ctx, cmSp_t* p, const cmChar_t* rsrcFn, cmScoreProcCb_t procCb, cmScMatcherCb_t matchCb, void* cbArg )
|
||||
{
|
||||
cmSpRC_t rc = kOkSpRC;
|
||||
const cmChar_t* scFn = NULL;
|
||||
const cmChar_t* tlFn = NULL;
|
||||
const cmChar_t* tlPrefixPath = NULL;
|
||||
|
||||
p->srate = 96000;
|
||||
|
||||
cmErrSetup(&p->err,&ctx->rpt,"ScoreProc");
|
||||
|
||||
// open the resource file
|
||||
@ -129,13 +127,6 @@ cmSpRC_t _cmScoreProcInit( cmCtx_t* ctx, cmSp_t* p, const cmChar_t* rsrcFn )
|
||||
}
|
||||
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
// load the time-line file
|
||||
if( cmTimeLineInitializeFromFile(ctx, &p->tlH, NULL, NULL, tlFn, tlPrefixPath ) != kOkTlRC )
|
||||
{
|
||||
@ -143,12 +134,145 @@ cmSpRC_t _cmScoreProcInit( cmCtx_t* ctx, cmSp_t* p, const cmChar_t* rsrcFn )
|
||||
goto errLabel;
|
||||
}
|
||||
|
||||
p->srate = cmTimeLineSampleRate(p->tlH);
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
p->ctx = cmCtxAlloc(NULL, &ctx->rpt, cmLHeapNullHandle, cmSymTblNullHandle );
|
||||
p->matchCb = matchCb;
|
||||
p->procCb = procCb;
|
||||
p->cbArg = cbArg;
|
||||
|
||||
errLabel:
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
cmSpRC_t _cmScoreProcProcess(cmCtx_t* ctx, cmSp_t* sp)
|
||||
{
|
||||
cmSpRC_t rc = kOkSpRC;
|
||||
unsigned midiN = 7;
|
||||
unsigned scWndN = 10;
|
||||
unsigned seqN = cmTimeLineSeqCount(sp->tlH);
|
||||
double srate = cmTimeLineSampleRate(sp->tlH);
|
||||
unsigned seqId;
|
||||
|
||||
assert( sp->srate == srate);
|
||||
|
||||
// allocate the score matcher
|
||||
sp->match = cmScMatcherAlloc(sp->ctx,NULL,sp->srate,sp->scH,scWndN,midiN,sp->matchCb,sp->cbArg);
|
||||
assert(sp->match != NULL );
|
||||
|
||||
|
||||
// for each time line sequence
|
||||
for(seqId=0; seqId<seqN; ++seqId)
|
||||
{
|
||||
cmTlObj_t* o0p = NULL;
|
||||
|
||||
// for each 'marker' in this time line sequence
|
||||
while( (o0p = cmTimeLineNextTypeObj(sp->tlH, o0p, seqId, kMarkerTlId)) != NULL )
|
||||
{
|
||||
// get the 'marker' recd
|
||||
cmTlMarker_t* markPtr = cmTimeLineMarkerObjPtr(sp->tlH,o0p);
|
||||
assert( markPtr != NULL );
|
||||
|
||||
// if the marker does not have a valid start bar location
|
||||
if( markPtr->bar == 0 )
|
||||
continue;
|
||||
|
||||
// get the end-of-marker time as a sample index
|
||||
unsigned markEndSmpIdx = markPtr->obj.seqSmpIdx + markPtr->obj.durSmpCnt;
|
||||
|
||||
// get the score event associated with the marker's bar number.
|
||||
const cmScoreEvt_t* evtPtr = cmScoreBarEvt(sp->scH,markPtr->bar);
|
||||
assert( evtPtr != NULL );
|
||||
|
||||
|
||||
// get the score location associated with the markers bar score event
|
||||
const cmScoreLoc_t* locPtr = cmScoreEvtLoc(sp->scH,evtPtr);
|
||||
assert( locPtr != NULL );
|
||||
|
||||
cmRptPrintf(&ctx->rpt,"Processing loc:%i seq:%i %s %s\n",locPtr->index,seqId,cmStringNullGuard(markPtr->obj.name),cmStringNullGuard(markPtr->text));
|
||||
|
||||
// inform the score processor that we are about to start a new section
|
||||
if( sp->procCb( sp->cbArg, sp, kBeginSectionSpId, markPtr ) != kOkSpRC )
|
||||
{
|
||||
cmErrMsg(&sp->err,kProcFailSpRC,"The score process object failed on reset.");
|
||||
continue;
|
||||
}
|
||||
|
||||
// reset the score matcher to begin searching at the bar location
|
||||
if( cmScMatcherReset(sp->match, locPtr->index ) != cmOkRC )
|
||||
{
|
||||
cmErrMsg(&sp->err,kScoreMatchFailSpRC,"The score matcher reset failed on location: %i.",locPtr->index);
|
||||
continue;
|
||||
}
|
||||
|
||||
cmTlObj_t* o1p = o0p;
|
||||
|
||||
// as long as more MIDI events are available get the next MIDI msg
|
||||
while( (rc == kOkSpRC) && (o1p = cmTimeLineNextTypeObj(sp->tlH, o1p, seqId, kMidiEvtTlId )) != NULL )
|
||||
{
|
||||
cmTlMidiEvt_t* mep = cmTimeLineMidiEvtObjPtr(sp->tlH,o1p);
|
||||
assert(mep != NULL );
|
||||
|
||||
// if the msg falls after the end of the marker then we are done
|
||||
if( mep->obj.seqSmpIdx != cmInvalidIdx && mep->obj.seqSmpIdx > markEndSmpIdx )
|
||||
break;
|
||||
|
||||
// if the time line MIDI msg a note-on
|
||||
if( mep->msg->status == kNoteOnMdId )
|
||||
{
|
||||
cmRC_t cmRC = cmScMatcherExec(sp->match, mep->obj.seqSmpIdx, mep->msg->status, mep->msg->u.chMsgPtr->d0, mep->msg->u.chMsgPtr->d1, NULL );
|
||||
|
||||
switch( cmRC )
|
||||
{
|
||||
case cmOkRC: // continue processing MIDI events
|
||||
break;
|
||||
|
||||
case cmEofRC: // end of the score was encountered
|
||||
break;
|
||||
|
||||
case cmInvalidArgRC: // p->eli was not set correctly
|
||||
rc = cmErrMsg(&sp->err,kScoreMatchFailSpRC,"The score matcher failed due to an invalid argument.");
|
||||
goto errLabel;
|
||||
break;
|
||||
|
||||
case cmSubSysFailRC: // scan resync failed
|
||||
rc = cmErrMsg(&sp->err,kScoreMatchFailSpRC,"The score matcher failed on resync.");
|
||||
cmScMatcherPrint(sp->match);
|
||||
//goto errLabel;
|
||||
break;
|
||||
|
||||
default:
|
||||
{ assert(0); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// inform the score processor that we done processing a section
|
||||
if( sp->procCb( sp->cbArg, sp, kEndSectionSpId, NULL ) != kOkSpRC )
|
||||
cmErrMsg(&sp->err,kProcFailSpRC,"The score process object failed on reset.");
|
||||
|
||||
rc = kOkSpRC;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
errLabel:
|
||||
|
||||
|
||||
if( cmScMatcherFree(&sp->match) != cmOkRC )
|
||||
cmErrMsg(&sp->err,kScoreMatchFailSpRC,"The score matcher release failed.");
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
cmSpRC_t _cmScoreProcFinal( cmSp_t* p )
|
||||
{
|
||||
cmSpRC_t rc = kOkSpRC;
|
||||
@ -169,17 +293,26 @@ cmSpRC_t _cmScoreProcFinal( cmSp_t* p )
|
||||
return rc;
|
||||
}
|
||||
|
||||
unsigned _cmScMeasSectCount( cmSp_t* sp )
|
||||
//==================================================================================================
|
||||
|
||||
typedef struct _cmSpMeas_t
|
||||
{
|
||||
const _cmScMeas_t* mp = sp->list_beg;
|
||||
unsigned n = 0;
|
||||
for(; mp != NULL; mp=mp->link)
|
||||
n += mp->setPtr->sectCnt;
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
cmTlMarker_t* markPtr; // time-line marker in which this 'set' exists
|
||||
cmScoreSet_t* setPtr; // score set on which this measurment is based
|
||||
double value; // the value of the measurement
|
||||
double cost; // the quality of the perf->score match
|
||||
struct _cmSpMeas_t* link;
|
||||
} _cmSpMeas_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
struct cmSp_str* sp;
|
||||
cmScMeas* meas; // performance analyzer
|
||||
cmTlMarker_t* curMarkPtr; //
|
||||
_cmSpMeas_t* list_beg; //
|
||||
_cmSpMeas_t* list_end; //
|
||||
_cmSpMeas_t* slist_beg; //
|
||||
} _cmSpMeasProc_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@ -192,25 +325,35 @@ typedef struct
|
||||
const cmChar_t* dstSectLabelStr;
|
||||
double value;
|
||||
double cost;
|
||||
} _cmScMeasSect_t;
|
||||
} _cmSpMeasSect_t;
|
||||
|
||||
int _cmScMeasSectCompare( const void* p0, const void* p1 )
|
||||
unsigned _cmSpMeasSectCount( _cmSpMeasProc_t* m )
|
||||
{
|
||||
_cmScMeasSect_t* m0 = (_cmScMeasSect_t*)p0;
|
||||
_cmScMeasSect_t* m1 = (_cmScMeasSect_t*)p1;
|
||||
const _cmSpMeas_t* mp = m->list_beg;
|
||||
unsigned n = 0;
|
||||
for(; mp != NULL; mp=mp->link)
|
||||
n += mp->setPtr->sectCnt;
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
int _cmSpMeasSectCompare( const void* p0, const void* p1 )
|
||||
{
|
||||
_cmSpMeasSect_t* m0 = (_cmSpMeasSect_t*)p0;
|
||||
_cmSpMeasSect_t* m1 = (_cmSpMeasSect_t*)p1;
|
||||
|
||||
return (int)m0->dstScLocIdx - (int)m1->dstScLocIdx;
|
||||
}
|
||||
|
||||
cmSpRC_t _cmScWriteMeasFile( cmCtx_t* ctx, cmSp_t* sp, const cmChar_t* outFn )
|
||||
cmSpRC_t _cmScWriteMeasFile( cmCtx_t* ctx, cmSp_t* sp, _cmSpMeasProc_t* m, const cmChar_t* outFn )
|
||||
{
|
||||
cmFileH_t fH = cmFileNullHandle;
|
||||
cmSpRC_t rc = kOkSpRC;
|
||||
unsigned i,j,k;
|
||||
_cmScMeas_t* mp = sp->list_beg;
|
||||
_cmSpMeas_t* mp = m->list_beg;
|
||||
|
||||
unsigned scnt = _cmScMeasSectCount(sp);
|
||||
_cmScMeasSect_t sarray[ scnt ];
|
||||
unsigned scnt = _cmSpMeasSectCount(m);
|
||||
_cmSpMeasSect_t sarray[ scnt ];
|
||||
for(i=0,k=0; k<scnt && mp!=NULL; ++i,mp=mp->link)
|
||||
{
|
||||
const cmChar_t* typeLabel = NULL;
|
||||
@ -225,7 +368,7 @@ cmSpRC_t _cmScWriteMeasFile( cmCtx_t* ctx, cmSp_t* sp, const cmChar_t* outFn )
|
||||
|
||||
for(j=0; j<mp->setPtr->sectCnt; ++j,++k)
|
||||
{
|
||||
_cmScMeasSect_t* r = sarray + k;
|
||||
_cmSpMeasSect_t* r = sarray + k;
|
||||
|
||||
r->srcSeqId = mp->markPtr->obj.seqId,
|
||||
r->srcMarkNameStr = cmStringNullGuard(mp->markPtr->obj.name),
|
||||
@ -242,7 +385,7 @@ cmSpRC_t _cmScWriteMeasFile( cmCtx_t* ctx, cmSp_t* sp, const cmChar_t* outFn )
|
||||
|
||||
assert(mp==NULL && k==scnt);
|
||||
|
||||
qsort(sarray,scnt,sizeof(sarray[0]),_cmScMeasSectCompare);
|
||||
qsort(sarray,scnt,sizeof(sarray[0]),_cmSpMeasSectCompare);
|
||||
|
||||
if( cmFileOpen(&fH,outFn,kWriteFileFl,&ctx->rpt) != kOkFileRC )
|
||||
{
|
||||
@ -254,7 +397,7 @@ cmSpRC_t _cmScWriteMeasFile( cmCtx_t* ctx, cmSp_t* sp, const cmChar_t* outFn )
|
||||
|
||||
for(i=0; i<scnt; ++i)
|
||||
{
|
||||
_cmScMeasSect_t* r = sarray + i;
|
||||
_cmSpMeasSect_t* r = sarray + i;
|
||||
|
||||
cmFilePrintf(fH,"[ \"%s\" \"%s\" %f %f %i %i %i \"%s\" %i ]\n",
|
||||
r->dstSectLabelStr,
|
||||
@ -300,11 +443,11 @@ cmSpRC_t _cmScWriteMeasFile( cmCtx_t* ctx, cmSp_t* sp, const cmChar_t* outFn )
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
void _cmScMatchCb( cmScMatcher* p, void* arg, cmScMatcherResult_t* rp )
|
||||
// score matcher callback
|
||||
void _cmSpMatchMeasCb( cmScMatcher* p, void* arg, cmScMatcherResult_t* rp )
|
||||
{
|
||||
cmSp_t* sp = (cmSp_t*)arg;
|
||||
cmScMeas* sm = sp->meas;
|
||||
_cmSpMeasProc_t* m = (_cmSpMeasProc_t*)arg;
|
||||
cmScMeas* sm = m->meas;
|
||||
|
||||
if( cmScMeasExec(sm, rp->mni, rp->locIdx, rp->scEvtIdx, rp->flags, rp->smpIdx, rp->pitch, rp->vel ) == cmOkRC )
|
||||
{
|
||||
@ -313,190 +456,101 @@ void _cmScMatchCb( cmScMatcher* p, void* arg, cmScMatcherResult_t* rp )
|
||||
// ignore set's which did not produce a valid value
|
||||
if(sm->set[i].value != DBL_MAX )
|
||||
{
|
||||
_cmScMeas_t* r = cmMemAllocZ(_cmScMeas_t,1);
|
||||
r->markPtr = sp->curMarkPtr;
|
||||
_cmSpMeas_t* r = cmMemAllocZ(_cmSpMeas_t,1);
|
||||
r->markPtr = m->curMarkPtr;
|
||||
r->setPtr = sm->set[i].sp;
|
||||
r->value = sm->set[i].value;
|
||||
r->cost = sm->set[i].match_cost;
|
||||
|
||||
if( sp->list_beg == NULL )
|
||||
if( m->list_beg == NULL )
|
||||
{
|
||||
sp->list_beg = r;
|
||||
sp->list_end = r;
|
||||
m->list_beg = r;
|
||||
m->list_end = r;
|
||||
}
|
||||
else
|
||||
{
|
||||
sp->list_end->link = r;
|
||||
sp->list_end = r;
|
||||
m->list_end->link = r;
|
||||
m->list_end = r;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
cmSpRC_t _cmScoreGenAllMeasurements(cmCtx_t* ctx, cmSp_t* sp, const cmChar_t* outFn)
|
||||
// measurement proc callback
|
||||
cmSpRC_t _cmSpProcMeasCb( void* arg, cmSp_t* sp, cmScoreProcSelId_t id, cmTlMarker_t* curMarkPtr )
|
||||
{
|
||||
cmSpRC_t rc = kOkSpRC;
|
||||
unsigned midiN = 7;
|
||||
unsigned scWndN = 10;
|
||||
unsigned seqN = cmTimeLineSeqCount(sp->tlH);
|
||||
double srate = cmTimeLineSampleRate(sp->tlH);
|
||||
unsigned seqId;
|
||||
_cmSpMeasProc_t* m = (_cmSpMeasProc_t*)arg;
|
||||
|
||||
assert( sp->srate == srate);
|
||||
|
||||
// allocate the performance eval. object
|
||||
sp->meas = cmScMeasAlloc( sp->ctx, NULL, sp->scH, sp->srate, sp->dynArray, sp->dynCnt );
|
||||
assert( sp->meas != NULL );
|
||||
|
||||
// allocate the score matcher
|
||||
sp->match = cmScMatcherAlloc(sp->ctx,NULL,sp->srate,sp->scH,scWndN,midiN,_cmScMatchCb,sp);
|
||||
assert(sp->match != NULL );
|
||||
|
||||
|
||||
// for each time line sequence
|
||||
for(seqId=0; seqId<seqN; ++seqId)
|
||||
switch( id )
|
||||
{
|
||||
cmTlObj_t* o0p = NULL;
|
||||
|
||||
// for each 'marker' in this time line sequence
|
||||
while( (o0p = cmTimeLineNextTypeObj(sp->tlH, o0p, seqId, kMarkerTlId)) != NULL )
|
||||
{
|
||||
// get the 'marker' recd
|
||||
cmTlMarker_t* markPtr = cmTimeLineMarkerObjPtr(sp->tlH,o0p);
|
||||
assert( markPtr != NULL );
|
||||
|
||||
// if the marker does not have a valid start bar location
|
||||
if( markPtr->bar == 0 )
|
||||
continue;
|
||||
|
||||
// set the marker ptr (which is used in _cmScMatchCb())
|
||||
sp->curMarkPtr = markPtr;
|
||||
|
||||
// get the end-of-marker time as a sample index
|
||||
unsigned markEndSmpIdx = markPtr->obj.seqSmpIdx + markPtr->obj.durSmpCnt;
|
||||
|
||||
// get the score event associated with the marker's bar number.
|
||||
const cmScoreEvt_t* evtPtr = cmScoreBarEvt(sp->scH,markPtr->bar);
|
||||
assert( evtPtr != NULL );
|
||||
|
||||
|
||||
// get the score location associated with the markers bar score event
|
||||
const cmScoreLoc_t* locPtr = cmScoreEvtLoc(sp->scH,evtPtr);
|
||||
assert( locPtr != NULL );
|
||||
|
||||
cmRptPrintf(&ctx->rpt,"Processing loc:%i seq:%i %s %s\n",locPtr->index,seqId,cmStringNullGuard(markPtr->obj.name),cmStringNullGuard(markPtr->text));
|
||||
case kBeginSectionSpId:
|
||||
|
||||
// reset the performance evaluation object
|
||||
if( cmScMeasReset(sp->meas) != cmOkRC )
|
||||
{
|
||||
cmErrMsg(&sp->err,kScoreMatchFailSpRC,"The score performance evaluation object failed on reset.");
|
||||
continue;
|
||||
}
|
||||
if( cmScMeasReset(m->meas) != cmOkRC )
|
||||
rc = cmErrMsg(&sp->err,kScoreMatchFailSpRC,"The score performance evaluation object failed on reset.");
|
||||
|
||||
// reset the score matcher to begin searching at the bar location
|
||||
if( cmScMatcherReset(sp->match, locPtr->index ) != cmOkRC )
|
||||
{
|
||||
cmErrMsg(&sp->err,kScoreMatchFailSpRC,"The score matcher reset failed on location: %i.",locPtr->index);
|
||||
continue;
|
||||
}
|
||||
|
||||
cmTlObj_t* o1p = o0p;
|
||||
|
||||
// as long as more MIDI events are available get the next MIDI msg
|
||||
while( (rc == kOkSpRC) && (o1p = cmTimeLineNextTypeObj(sp->tlH, o1p, seqId, kMidiEvtTlId )) != NULL )
|
||||
{
|
||||
cmTlMidiEvt_t* mep = cmTimeLineMidiEvtObjPtr(sp->tlH,o1p);
|
||||
assert(mep != NULL );
|
||||
|
||||
// if the msg falls after the end of the marker then we are done
|
||||
if( mep->obj.seqSmpIdx != cmInvalidIdx && mep->obj.seqSmpIdx > markEndSmpIdx )
|
||||
m->curMarkPtr = curMarkPtr;
|
||||
break;
|
||||
|
||||
|
||||
// if the time line MIDI msg a note-on
|
||||
if( mep->msg->status == kNoteOnMdId )
|
||||
{
|
||||
cmRC_t cmRC = cmScMatcherExec(sp->match, mep->obj.seqSmpIdx, mep->msg->status, mep->msg->u.chMsgPtr->d0, mep->msg->u.chMsgPtr->d1, NULL );
|
||||
|
||||
switch( cmRC )
|
||||
{
|
||||
case cmOkRC: // continue processing MIDI events
|
||||
case kEndSectionSpId:
|
||||
break;
|
||||
|
||||
case cmEofRC: // end of the score was encountered
|
||||
break;
|
||||
|
||||
case cmInvalidArgRC: // p->eli was not set correctly
|
||||
rc = cmErrMsg(&sp->err,kScoreMatchFailSpRC,"The score matcher failed due to an invalid argument.");
|
||||
goto errLabel;
|
||||
break;
|
||||
|
||||
case cmSubSysFailRC: // scan resync failed
|
||||
rc = cmErrMsg(&sp->err,kScoreMatchFailSpRC,"The score matcher failed on resync.");
|
||||
cmScMatcherPrint(sp->match);
|
||||
//goto errLabel;
|
||||
break;
|
||||
|
||||
default:
|
||||
{ assert(0); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rc = kOkSpRC;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
errLabel:
|
||||
|
||||
if((rc = _cmScWriteMeasFile(ctx, sp, outFn )) != kOkSpRC )
|
||||
cmErrMsg(&sp->err,kFileFailSpRC,"The measurement output did not complete without errors.");
|
||||
|
||||
_cmScMeas_t* mp = sp->list_beg;
|
||||
while(mp!=NULL)
|
||||
{
|
||||
_cmScMeas_t* np = mp->link;
|
||||
cmMemFree(mp);
|
||||
mp = np;
|
||||
}
|
||||
|
||||
if( cmScMatcherFree(&sp->match) != cmOkRC )
|
||||
cmErrMsg(&sp->err,kScoreMatchFailSpRC,"The score matcher release failed.");
|
||||
|
||||
if( cmScMeasFree(&sp->meas) != cmOkRC )
|
||||
cmErrMsg(&sp->err,kScoreMatchFailSpRC,"The performance evaluation object failed.");
|
||||
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
|
||||
unsigned cmScoreProc(cmCtx_t* ctx)
|
||||
cmSpRC_t _cmScoreProcGenAllMeasurementsMain(cmCtx_t* ctx)
|
||||
{
|
||||
cmSpRC_t rc = kOkSpRC;
|
||||
const cmChar_t* rsrcFn = "/home/kevin/.kc/time_line.js";
|
||||
const cmChar_t* outFn = "/home/kevin/src/cmkc/src/kc/data/meas0.js";
|
||||
cmSp_t sp;
|
||||
|
||||
memset(&sp,0,sizeof(sp));
|
||||
cmSpRC_t rc = kOkSpRC;
|
||||
_cmSpMeasProc_t* m = cmMemAllocZ(_cmSpMeasProc_t,1);
|
||||
cmSp_t s;
|
||||
cmSp_t* sp = &s;
|
||||
|
||||
cmRptPrintf(&ctx->rpt,"Score Proc Start\n");
|
||||
memset(sp,0,sizeof(s));
|
||||
|
||||
if((rc = _cmScoreProcInit(ctx,&sp,rsrcFn)) != kOkSpRC )
|
||||
cmRptPrintf(&ctx->rpt,"Score Performance Evaluation Start\n");
|
||||
|
||||
// initialize the score processor
|
||||
if((rc = _cmScoreProcInit(ctx,sp,rsrcFn,_cmSpProcMeasCb,_cmSpMatchMeasCb,m)) != kOkSpRC )
|
||||
goto errLabel;
|
||||
|
||||
_cmScoreGenAllMeasurements(ctx,&sp,outFn);
|
||||
// allocate the performance evaluation measurement object
|
||||
m->meas = cmScMeasAlloc( sp->ctx, NULL, sp->scH, sp->srate, sp->dynArray, sp->dynCnt );
|
||||
m->sp = sp;
|
||||
|
||||
// run the score processor
|
||||
_cmScoreProcProcess(ctx,sp);
|
||||
|
||||
// write the results of the performance evaluation
|
||||
if((rc = _cmScWriteMeasFile(ctx, sp, m, outFn )) != kOkSpRC )
|
||||
cmErrMsg(&sp->err,kFileFailSpRC,"The measurement output did not complete without errors.");
|
||||
|
||||
// free the measurement linked list
|
||||
_cmSpMeas_t* mp = m->list_beg;
|
||||
while(mp!=NULL)
|
||||
{
|
||||
_cmSpMeas_t* np = mp->link;
|
||||
cmMemFree(mp);
|
||||
mp = np;
|
||||
}
|
||||
|
||||
// free the performance evaluation object
|
||||
if( cmScMeasFree(&m->meas) != cmOkRC )
|
||||
cmErrMsg(&sp->err,kScoreMatchFailSpRC,"The performance evaluation object failed.");
|
||||
|
||||
//cmScorePrint(sp.scH,&ctx->rpt);
|
||||
//cmScorePrintLoc(sp.scH);
|
||||
|
||||
|
||||
errLabel:
|
||||
_cmScoreProcFinal(&sp);
|
||||
_cmScoreProcFinal(sp);
|
||||
|
||||
cmMemFree(m);
|
||||
|
||||
cmRptPrintf(&ctx->rpt,"Score Proc End\n");
|
||||
|
||||
@ -504,3 +558,76 @@ unsigned cmScoreProc(cmCtx_t* ctx)
|
||||
|
||||
}
|
||||
|
||||
//==================================================================================================
|
||||
typedef struct
|
||||
{
|
||||
cmSp_t* sp;
|
||||
} cmSpPerfProc_t;
|
||||
|
||||
void _cmSpMatchPerfCb( cmScMatcher* p, void* arg, cmScMatcherResult_t* rp )
|
||||
{
|
||||
cmSpPerfProc_t* m = (cmSpPerfProc_t*)arg;
|
||||
|
||||
}
|
||||
|
||||
cmSpRC_t _cmSpProcPerfCb( void* arg, cmSp_t* sp, cmScoreProcSelId_t id, cmTlMarker_t* curMarkPtr )
|
||||
{
|
||||
cmSpPerfProc_t* m = (cmSpPerfProc_t*)arg;
|
||||
|
||||
}
|
||||
|
||||
cmSpRC_t _cmScoreProcGenPerfMain(cmCtx_t* ctx)
|
||||
{
|
||||
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;
|
||||
cmSpPerfProc_t* m = cmMemAllocZ(cmSpPerfProc_t,1);
|
||||
cmSp_t s;
|
||||
cmSp_t* sp = &s;
|
||||
|
||||
memset(sp,0,sizeof(s));
|
||||
|
||||
cmRptPrintf(&ctx->rpt,"Score Performance Start\n");
|
||||
|
||||
// initialize the score processor
|
||||
if((rc = _cmScoreProcInit(ctx,sp,rsrcFn,_cmSpProcPerfCb,_cmSpMatchPerfCb,m)) != kOkSpRC )
|
||||
goto errLabel;
|
||||
|
||||
m->sp = sp;
|
||||
|
||||
// run the score processor
|
||||
_cmScoreProcProcess(ctx,sp);
|
||||
|
||||
// write the results of the performance evaluation
|
||||
if((rc = _cmScWriteMeasFile(ctx, sp, m, outFn )) != kOkSpRC )
|
||||
cmErrMsg(&sp->err,kFileFailSpRC,"The measurement output did not complete without errors.");
|
||||
|
||||
//cmScorePrint(sp.scH,&ctx->rpt);
|
||||
//cmScorePrintLoc(sp.scH);
|
||||
|
||||
errLabel:
|
||||
_cmScoreProcFinal(sp);
|
||||
|
||||
cmMemFree(m);
|
||||
|
||||
cmRptPrintf(&ctx->rpt,"Score Proc End\n");
|
||||
|
||||
return rc;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
|
||||
cmSpRC_t cmScoreProc(cmCtx_t* ctx)
|
||||
{
|
||||
cmSpRC_t rc = kOkSpRC;
|
||||
|
||||
_cmScoreProcGenAllMeasurementsMain(ctx);
|
||||
|
||||
return rc;
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user