|
@@ -28,19 +28,20 @@ enum
|
28
|
28
|
kTimeLineFailSpRC,
|
29
|
29
|
kScoreMatchFailSpRC,
|
30
|
30
|
kFileFailSpRC,
|
|
31
|
+ kProcFailSpRC
|
31
|
32
|
};
|
32
|
33
|
|
33
|
|
-typedef struct _cmScMeas_t
|
|
34
|
+typedef enum
|
34
|
35
|
{
|
35
|
|
- cmTlMarker_t* markPtr; // time-line marker in which this 'set' exists
|
36
|
|
- cmScoreSet_t* setPtr; // score set on which this measurment is based
|
37
|
|
- double value; // the value of the measurement
|
38
|
|
- double cost; // the quality of the perf->score match
|
39
|
|
- struct _cmScMeas_t* link;
|
40
|
|
-} _cmScMeas_t;
|
|
36
|
+ kBeginSectionSpId,
|
|
37
|
+ kEndSectionSpId
|
|
38
|
+} cmScoreProcSelId_t;
|
41
|
39
|
|
|
40
|
+struct cmSp_str;
|
42
|
41
|
|
43
|
|
-typedef struct
|
|
42
|
+typedef cmSpRC_t (*cmScoreProcCb_t)( void* arg, struct cmSp_str* p, cmScoreProcSelId_t id, cmTlMarker_t* curMarkPtr );
|
|
43
|
+
|
|
44
|
+typedef struct cmSp_str
|
44
|
45
|
{
|
45
|
46
|
cmErr_t err; // score proc object error state
|
46
|
47
|
cmCtx* ctx; // application context
|
|
@@ -51,13 +52,12 @@ typedef struct
|
51
|
52
|
unsigned* dynArray; // dynArray[dynCnt] dynamics reference array
|
52
|
53
|
unsigned dynCnt; //
|
53
|
54
|
double srate; //
|
54
|
|
- cmScMeas* meas; // performance analyzer
|
55
|
55
|
cmScMatcher* match; // score follower
|
56
|
56
|
|
57
|
|
- cmTlMarker_t* curMarkPtr;
|
58
|
|
- _cmScMeas_t* list_beg;
|
59
|
|
- _cmScMeas_t* list_end;
|
60
|
|
- _cmScMeas_t* slist_beg;
|
|
57
|
+ cmScMatcherCb_t matchCb; // score follower callback
|
|
58
|
+ cmScoreProcCb_t procCb; // score processor callback
|
|
59
|
+ void* cbArg; // callback arg. for both matchCb and procCb.
|
|
60
|
+
|
61
|
61
|
} cmSp_t;
|
62
|
62
|
|
63
|
63
|
|
|
@@ -81,15 +81,13 @@ cmSpRC_t _cmJsonReadDynArray( cmJsonH_t jsH, unsigned** dynArray, unsigned* dynC
|
81
|
81
|
return kOkSpRC;
|
82
|
82
|
}
|
83
|
83
|
|
84
|
|
-cmSpRC_t _cmScoreProcInit( cmCtx_t* ctx, cmSp_t* p, const cmChar_t* rsrcFn )
|
|
84
|
+cmSpRC_t _cmScoreProcInit( cmCtx_t* ctx, cmSp_t* p, const cmChar_t* rsrcFn, cmScoreProcCb_t procCb, cmScMatcherCb_t matchCb, void* cbArg )
|
85
|
85
|
{
|
86
|
86
|
cmSpRC_t rc = kOkSpRC;
|
87
|
87
|
const cmChar_t* scFn = NULL;
|
88
|
88
|
const cmChar_t* tlFn = NULL;
|
89
|
89
|
const cmChar_t* tlPrefixPath = NULL;
|
90
|
90
|
|
91
|
|
- p->srate = 96000;
|
92
|
|
-
|
93
|
91
|
cmErrSetup(&p->err,&ctx->rpt,"ScoreProc");
|
94
|
92
|
|
95
|
93
|
// open the resource file
|
|
@@ -129,6 +127,15 @@ cmSpRC_t _cmScoreProcInit( cmCtx_t* ctx, cmSp_t* p, const cmChar_t* rsrcFn )
|
129
|
127
|
}
|
130
|
128
|
|
131
|
129
|
|
|
130
|
+ // load the time-line file
|
|
131
|
+ if( cmTimeLineInitializeFromFile(ctx, &p->tlH, NULL, NULL, tlFn, tlPrefixPath ) != kOkTlRC )
|
|
132
|
+ {
|
|
133
|
+ rc = cmErrMsg(&p->err,kTimeLineFailSpRC,"Time line load failed for time line file:%s.",cmStringNullGuard(tlFn));
|
|
134
|
+ goto errLabel;
|
|
135
|
+ }
|
|
136
|
+
|
|
137
|
+ p->srate = cmTimeLineSampleRate(p->tlH);
|
|
138
|
+
|
132
|
139
|
// load the score file
|
133
|
140
|
if( cmScoreInitialize(ctx, &p->scH, scFn, p->srate, NULL, 0, NULL, NULL, cmSymTblNullHandle ) != kOkScRC )
|
134
|
141
|
{
|
|
@@ -136,16 +143,133 @@ cmSpRC_t _cmScoreProcInit( cmCtx_t* ctx, cmSp_t* p, const cmChar_t* rsrcFn )
|
136
|
143
|
goto errLabel;
|
137
|
144
|
}
|
138
|
145
|
|
139
|
|
- // load the time-line file
|
140
|
|
- if( cmTimeLineInitializeFromFile(ctx, &p->tlH, NULL, NULL, tlFn, tlPrefixPath ) != kOkTlRC )
|
|
146
|
+ p->ctx = cmCtxAlloc(NULL, &ctx->rpt, cmLHeapNullHandle, cmSymTblNullHandle );
|
|
147
|
+ p->matchCb = matchCb;
|
|
148
|
+ p->procCb = procCb;
|
|
149
|
+ p->cbArg = cbArg;
|
|
150
|
+
|
|
151
|
+ errLabel:
|
|
152
|
+ return rc;
|
|
153
|
+}
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+cmSpRC_t _cmScoreProcProcess(cmCtx_t* ctx, cmSp_t* sp)
|
|
157
|
+{
|
|
158
|
+ cmSpRC_t rc = kOkSpRC;
|
|
159
|
+ unsigned midiN = 7;
|
|
160
|
+ unsigned scWndN = 10;
|
|
161
|
+ unsigned seqN = cmTimeLineSeqCount(sp->tlH);
|
|
162
|
+ double srate = cmTimeLineSampleRate(sp->tlH);
|
|
163
|
+ unsigned seqId;
|
|
164
|
+
|
|
165
|
+ assert( sp->srate == srate);
|
|
166
|
+
|
|
167
|
+ // allocate the score matcher
|
|
168
|
+ sp->match = cmScMatcherAlloc(sp->ctx,NULL,sp->srate,sp->scH,scWndN,midiN,sp->matchCb,sp->cbArg);
|
|
169
|
+ assert(sp->match != NULL );
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+ // for each time line sequence
|
|
173
|
+ for(seqId=0; seqId<seqN; ++seqId)
|
141
|
174
|
{
|
142
|
|
- rc = cmErrMsg(&p->err,kTimeLineFailSpRC,"Time line load failed for time line file:%s.",cmStringNullGuard(tlFn));
|
143
|
|
- goto errLabel;
|
|
175
|
+ cmTlObj_t* o0p = NULL;
|
|
176
|
+
|
|
177
|
+ // for each 'marker' in this time line sequence
|
|
178
|
+ while( (o0p = cmTimeLineNextTypeObj(sp->tlH, o0p, seqId, kMarkerTlId)) != NULL )
|
|
179
|
+ {
|
|
180
|
+ // get the 'marker' recd
|
|
181
|
+ cmTlMarker_t* markPtr = cmTimeLineMarkerObjPtr(sp->tlH,o0p);
|
|
182
|
+ assert( markPtr != NULL );
|
|
183
|
+
|
|
184
|
+ // if the marker does not have a valid start bar location
|
|
185
|
+ if( markPtr->bar == 0 )
|
|
186
|
+ continue;
|
|
187
|
+
|
|
188
|
+ // get the end-of-marker time as a sample index
|
|
189
|
+ unsigned markEndSmpIdx = markPtr->obj.seqSmpIdx + markPtr->obj.durSmpCnt;
|
|
190
|
+
|
|
191
|
+ // get the score event associated with the marker's bar number.
|
|
192
|
+ const cmScoreEvt_t* evtPtr = cmScoreBarEvt(sp->scH,markPtr->bar);
|
|
193
|
+ assert( evtPtr != NULL );
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+ // get the score location associated with the markers bar score event
|
|
197
|
+ const cmScoreLoc_t* locPtr = cmScoreEvtLoc(sp->scH,evtPtr);
|
|
198
|
+ assert( locPtr != NULL );
|
|
199
|
+
|
|
200
|
+ cmRptPrintf(&ctx->rpt,"Processing loc:%i seq:%i %s %s\n",locPtr->index,seqId,cmStringNullGuard(markPtr->obj.name),cmStringNullGuard(markPtr->text));
|
|
201
|
+
|
|
202
|
+ // inform the score processor that we are about to start a new section
|
|
203
|
+ if( sp->procCb( sp->cbArg, sp, kBeginSectionSpId, markPtr ) != kOkSpRC )
|
|
204
|
+ {
|
|
205
|
+ cmErrMsg(&sp->err,kProcFailSpRC,"The score process object failed on reset.");
|
|
206
|
+ continue;
|
|
207
|
+ }
|
|
208
|
+
|
|
209
|
+ // reset the score matcher to begin searching at the bar location
|
|
210
|
+ if( cmScMatcherReset(sp->match, locPtr->index ) != cmOkRC )
|
|
211
|
+ {
|
|
212
|
+ cmErrMsg(&sp->err,kScoreMatchFailSpRC,"The score matcher reset failed on location: %i.",locPtr->index);
|
|
213
|
+ continue;
|
|
214
|
+ }
|
|
215
|
+
|
|
216
|
+ cmTlObj_t* o1p = o0p;
|
|
217
|
+
|
|
218
|
+ // as long as more MIDI events are available get the next MIDI msg
|
|
219
|
+ while( (rc == kOkSpRC) && (o1p = cmTimeLineNextTypeObj(sp->tlH, o1p, seqId, kMidiEvtTlId )) != NULL )
|
|
220
|
+ {
|
|
221
|
+ cmTlMidiEvt_t* mep = cmTimeLineMidiEvtObjPtr(sp->tlH,o1p);
|
|
222
|
+ assert(mep != NULL );
|
|
223
|
+
|
|
224
|
+ // if the msg falls after the end of the marker then we are done
|
|
225
|
+ if( mep->obj.seqSmpIdx != cmInvalidIdx && mep->obj.seqSmpIdx > markEndSmpIdx )
|
|
226
|
+ break;
|
|
227
|
+
|
|
228
|
+ // if the time line MIDI msg a note-on
|
|
229
|
+ if( mep->msg->status == kNoteOnMdId )
|
|
230
|
+ {
|
|
231
|
+ cmRC_t cmRC = cmScMatcherExec(sp->match, mep->obj.seqSmpIdx, mep->msg->status, mep->msg->u.chMsgPtr->d0, mep->msg->u.chMsgPtr->d1, NULL );
|
|
232
|
+
|
|
233
|
+ switch( cmRC )
|
|
234
|
+ {
|
|
235
|
+ case cmOkRC: // continue processing MIDI events
|
|
236
|
+ break;
|
|
237
|
+
|
|
238
|
+ case cmEofRC: // end of the score was encountered
|
|
239
|
+ break;
|
|
240
|
+
|
|
241
|
+ case cmInvalidArgRC: // p->eli was not set correctly
|
|
242
|
+ rc = cmErrMsg(&sp->err,kScoreMatchFailSpRC,"The score matcher failed due to an invalid argument.");
|
|
243
|
+ goto errLabel;
|
|
244
|
+ break;
|
|
245
|
+
|
|
246
|
+ case cmSubSysFailRC: // scan resync failed
|
|
247
|
+ rc = cmErrMsg(&sp->err,kScoreMatchFailSpRC,"The score matcher failed on resync.");
|
|
248
|
+ cmScMatcherPrint(sp->match);
|
|
249
|
+ //goto errLabel;
|
|
250
|
+ break;
|
|
251
|
+
|
|
252
|
+ default:
|
|
253
|
+ { assert(0); }
|
|
254
|
+ }
|
|
255
|
+ }
|
|
256
|
+ }
|
|
257
|
+
|
|
258
|
+ // inform the score processor that we done processing a section
|
|
259
|
+ if( sp->procCb( sp->cbArg, sp, kEndSectionSpId, NULL ) != kOkSpRC )
|
|
260
|
+ cmErrMsg(&sp->err,kProcFailSpRC,"The score process object failed on reset.");
|
|
261
|
+
|
|
262
|
+ rc = kOkSpRC;
|
|
263
|
+ }
|
144
|
264
|
}
|
145
|
265
|
|
146
|
|
- p->ctx = cmCtxAlloc(NULL, &ctx->rpt, cmLHeapNullHandle, cmSymTblNullHandle );
|
147
|
266
|
|
148
|
267
|
errLabel:
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+ if( cmScMatcherFree(&sp->match) != cmOkRC )
|
|
271
|
+ cmErrMsg(&sp->err,kScoreMatchFailSpRC,"The score matcher release failed.");
|
|
272
|
+
|
149
|
273
|
return rc;
|
150
|
274
|
}
|
151
|
275
|
|
|
@@ -169,17 +293,26 @@ cmSpRC_t _cmScoreProcFinal( cmSp_t* p )
|
169
|
293
|
return rc;
|
170
|
294
|
}
|
171
|
295
|
|
172
|
|
-unsigned _cmScMeasSectCount( cmSp_t* sp )
|
173
|
|
-{
|
174
|
|
- const _cmScMeas_t* mp = sp->list_beg;
|
175
|
|
- unsigned n = 0;
|
176
|
|
- for(; mp != NULL; mp=mp->link)
|
177
|
|
- n += mp->setPtr->sectCnt;
|
178
|
|
-
|
179
|
|
- return n;
|
180
|
|
-}
|
|
296
|
+//==================================================================================================
|
181
|
297
|
|
|
298
|
+typedef struct _cmSpMeas_t
|
|
299
|
+{
|
|
300
|
+ cmTlMarker_t* markPtr; // time-line marker in which this 'set' exists
|
|
301
|
+ cmScoreSet_t* setPtr; // score set on which this measurment is based
|
|
302
|
+ double value; // the value of the measurement
|
|
303
|
+ double cost; // the quality of the perf->score match
|
|
304
|
+ struct _cmSpMeas_t* link;
|
|
305
|
+} _cmSpMeas_t;
|
182
|
306
|
|
|
307
|
+typedef struct
|
|
308
|
+{
|
|
309
|
+ struct cmSp_str* sp;
|
|
310
|
+ cmScMeas* meas; // performance analyzer
|
|
311
|
+ cmTlMarker_t* curMarkPtr; //
|
|
312
|
+ _cmSpMeas_t* list_beg; //
|
|
313
|
+ _cmSpMeas_t* list_end; //
|
|
314
|
+ _cmSpMeas_t* slist_beg; //
|
|
315
|
+} _cmSpMeasProc_t;
|
183
|
316
|
|
184
|
317
|
typedef struct
|
185
|
318
|
{
|
|
@@ -192,25 +325,35 @@ typedef struct
|
192
|
325
|
const cmChar_t* dstSectLabelStr;
|
193
|
326
|
double value;
|
194
|
327
|
double cost;
|
195
|
|
-} _cmScMeasSect_t;
|
|
328
|
+} _cmSpMeasSect_t;
|
|
329
|
+
|
|
330
|
+unsigned _cmSpMeasSectCount( _cmSpMeasProc_t* m )
|
|
331
|
+{
|
|
332
|
+ const _cmSpMeas_t* mp = m->list_beg;
|
|
333
|
+ unsigned n = 0;
|
|
334
|
+ for(; mp != NULL; mp=mp->link)
|
|
335
|
+ n += mp->setPtr->sectCnt;
|
|
336
|
+
|
|
337
|
+ return n;
|
|
338
|
+}
|
196
|
339
|
|
197
|
|
-int _cmScMeasSectCompare( const void* p0, const void* p1 )
|
|
340
|
+int _cmSpMeasSectCompare( const void* p0, const void* p1 )
|
198
|
341
|
{
|
199
|
|
- _cmScMeasSect_t* m0 = (_cmScMeasSect_t*)p0;
|
200
|
|
- _cmScMeasSect_t* m1 = (_cmScMeasSect_t*)p1;
|
|
342
|
+ _cmSpMeasSect_t* m0 = (_cmSpMeasSect_t*)p0;
|
|
343
|
+ _cmSpMeasSect_t* m1 = (_cmSpMeasSect_t*)p1;
|
201
|
344
|
|
202
|
345
|
return (int)m0->dstScLocIdx - (int)m1->dstScLocIdx;
|
203
|
346
|
}
|
204
|
347
|
|
205
|
|
-cmSpRC_t _cmScWriteMeasFile( cmCtx_t* ctx, cmSp_t* sp, const cmChar_t* outFn )
|
|
348
|
+cmSpRC_t _cmScWriteMeasFile( cmCtx_t* ctx, cmSp_t* sp, _cmSpMeasProc_t* m, const cmChar_t* outFn )
|
206
|
349
|
{
|
207
|
350
|
cmFileH_t fH = cmFileNullHandle;
|
208
|
351
|
cmSpRC_t rc = kOkSpRC;
|
209
|
352
|
unsigned i,j,k;
|
210
|
|
- _cmScMeas_t* mp = sp->list_beg;
|
|
353
|
+ _cmSpMeas_t* mp = m->list_beg;
|
211
|
354
|
|
212
|
|
- unsigned scnt = _cmScMeasSectCount(sp);
|
213
|
|
- _cmScMeasSect_t sarray[ scnt ];
|
|
355
|
+ unsigned scnt = _cmSpMeasSectCount(m);
|
|
356
|
+ _cmSpMeasSect_t sarray[ scnt ];
|
214
|
357
|
for(i=0,k=0; k<scnt && mp!=NULL; ++i,mp=mp->link)
|
215
|
358
|
{
|
216
|
359
|
const cmChar_t* typeLabel = NULL;
|
|
@@ -225,7 +368,7 @@ cmSpRC_t _cmScWriteMeasFile( cmCtx_t* ctx, cmSp_t* sp, const cmChar_t* outFn )
|
225
|
368
|
|
226
|
369
|
for(j=0; j<mp->setPtr->sectCnt; ++j,++k)
|
227
|
370
|
{
|
228
|
|
- _cmScMeasSect_t* r = sarray + k;
|
|
371
|
+ _cmSpMeasSect_t* r = sarray + k;
|
229
|
372
|
|
230
|
373
|
r->srcSeqId = mp->markPtr->obj.seqId,
|
231
|
374
|
r->srcMarkNameStr = cmStringNullGuard(mp->markPtr->obj.name),
|
|
@@ -242,7 +385,7 @@ cmSpRC_t _cmScWriteMeasFile( cmCtx_t* ctx, cmSp_t* sp, const cmChar_t* outFn )
|
242
|
385
|
|
243
|
386
|
assert(mp==NULL && k==scnt);
|
244
|
387
|
|
245
|
|
- qsort(sarray,scnt,sizeof(sarray[0]),_cmScMeasSectCompare);
|
|
388
|
+ qsort(sarray,scnt,sizeof(sarray[0]),_cmSpMeasSectCompare);
|
246
|
389
|
|
247
|
390
|
if( cmFileOpen(&fH,outFn,kWriteFileFl,&ctx->rpt) != kOkFileRC )
|
248
|
391
|
{
|
|
@@ -254,7 +397,7 @@ cmSpRC_t _cmScWriteMeasFile( cmCtx_t* ctx, cmSp_t* sp, const cmChar_t* outFn )
|
254
|
397
|
|
255
|
398
|
for(i=0; i<scnt; ++i)
|
256
|
399
|
{
|
257
|
|
- _cmScMeasSect_t* r = sarray + i;
|
|
400
|
+ _cmSpMeasSect_t* r = sarray + i;
|
258
|
401
|
|
259
|
402
|
cmFilePrintf(fH,"[ \"%s\" \"%s\" %f %f %i %i %i \"%s\" %i ]\n",
|
260
|
403
|
r->dstSectLabelStr,
|
|
@@ -300,11 +443,11 @@ cmSpRC_t _cmScWriteMeasFile( cmCtx_t* ctx, cmSp_t* sp, const cmChar_t* outFn )
|
300
|
443
|
return rc;
|
301
|
444
|
}
|
302
|
445
|
|
303
|
|
-
|
304
|
|
-void _cmScMatchCb( cmScMatcher* p, void* arg, cmScMatcherResult_t* rp )
|
|
446
|
+// score matcher callback
|
|
447
|
+void _cmSpMatchMeasCb( cmScMatcher* p, void* arg, cmScMatcherResult_t* rp )
|
305
|
448
|
{
|
306
|
|
- cmSp_t* sp = (cmSp_t*)arg;
|
307
|
|
- cmScMeas* sm = sp->meas;
|
|
449
|
+ _cmSpMeasProc_t* m = (_cmSpMeasProc_t*)arg;
|
|
450
|
+ cmScMeas* sm = m->meas;
|
308
|
451
|
|
309
|
452
|
if( cmScMeasExec(sm, rp->mni, rp->locIdx, rp->scEvtIdx, rp->flags, rp->smpIdx, rp->pitch, rp->vel ) == cmOkRC )
|
310
|
453
|
{
|
|
@@ -313,190 +456,160 @@ void _cmScMatchCb( cmScMatcher* p, void* arg, cmScMatcherResult_t* rp )
|
313
|
456
|
// ignore set's which did not produce a valid value
|
314
|
457
|
if(sm->set[i].value != DBL_MAX )
|
315
|
458
|
{
|
316
|
|
- _cmScMeas_t* r = cmMemAllocZ(_cmScMeas_t,1);
|
317
|
|
- r->markPtr = sp->curMarkPtr;
|
|
459
|
+ _cmSpMeas_t* r = cmMemAllocZ(_cmSpMeas_t,1);
|
|
460
|
+ r->markPtr = m->curMarkPtr;
|
318
|
461
|
r->setPtr = sm->set[i].sp;
|
319
|
462
|
r->value = sm->set[i].value;
|
320
|
463
|
r->cost = sm->set[i].match_cost;
|
321
|
464
|
|
322
|
|
- if( sp->list_beg == NULL )
|
|
465
|
+ if( m->list_beg == NULL )
|
323
|
466
|
{
|
324
|
|
- sp->list_beg = r;
|
325
|
|
- sp->list_end = r;
|
|
467
|
+ m->list_beg = r;
|
|
468
|
+ m->list_end = r;
|
326
|
469
|
}
|
327
|
470
|
else
|
328
|
471
|
{
|
329
|
|
- sp->list_end->link = r;
|
330
|
|
- sp->list_end = r;
|
|
472
|
+ m->list_end->link = r;
|
|
473
|
+ m->list_end = r;
|
331
|
474
|
}
|
332
|
475
|
}
|
333
|
476
|
}
|
334
|
477
|
}
|
335
|
478
|
|
336
|
|
-
|
337
|
|
-cmSpRC_t _cmScoreGenAllMeasurements(cmCtx_t* ctx, cmSp_t* sp, const cmChar_t* outFn)
|
|
479
|
+// measurement proc callback
|
|
480
|
+cmSpRC_t _cmSpProcMeasCb( void* arg, cmSp_t* sp, cmScoreProcSelId_t id, cmTlMarker_t* curMarkPtr )
|
338
|
481
|
{
|
339
|
|
- cmSpRC_t rc = kOkSpRC;
|
340
|
|
- unsigned midiN = 7;
|
341
|
|
- unsigned scWndN = 10;
|
342
|
|
- unsigned seqN = cmTimeLineSeqCount(sp->tlH);
|
343
|
|
- double srate = cmTimeLineSampleRate(sp->tlH);
|
344
|
|
- unsigned seqId;
|
|
482
|
+ cmSpRC_t rc = kOkSpRC;
|
|
483
|
+ _cmSpMeasProc_t* m = (_cmSpMeasProc_t*)arg;
|
345
|
484
|
|
346
|
|
- assert( sp->srate == srate);
|
347
|
|
-
|
348
|
|
- // allocate the performance eval. object
|
349
|
|
- sp->meas = cmScMeasAlloc( sp->ctx, NULL, sp->scH, sp->srate, sp->dynArray, sp->dynCnt );
|
350
|
|
- assert( sp->meas != NULL );
|
351
|
|
-
|
352
|
|
- // allocate the score matcher
|
353
|
|
- sp->match = cmScMatcherAlloc(sp->ctx,NULL,sp->srate,sp->scH,scWndN,midiN,_cmScMatchCb,sp);
|
354
|
|
- assert(sp->match != NULL );
|
355
|
|
-
|
356
|
|
-
|
357
|
|
- // for each time line sequence
|
358
|
|
- for(seqId=0; seqId<seqN; ++seqId)
|
|
485
|
+ switch( id )
|
359
|
486
|
{
|
360
|
|
- cmTlObj_t* o0p = NULL;
|
361
|
|
-
|
362
|
|
- // for each 'marker' in this time line sequence
|
363
|
|
- while( (o0p = cmTimeLineNextTypeObj(sp->tlH, o0p, seqId, kMarkerTlId)) != NULL )
|
364
|
|
- {
|
365
|
|
- // get the 'marker' recd
|
366
|
|
- cmTlMarker_t* markPtr = cmTimeLineMarkerObjPtr(sp->tlH,o0p);
|
367
|
|
- assert( markPtr != NULL );
|
368
|
|
-
|
369
|
|
- // if the marker does not have a valid start bar location
|
370
|
|
- if( markPtr->bar == 0 )
|
371
|
|
- continue;
|
372
|
|
-
|
373
|
|
- // set the marker ptr (which is used in _cmScMatchCb())
|
374
|
|
- sp->curMarkPtr = markPtr;
|
375
|
|
-
|
376
|
|
- // get the end-of-marker time as a sample index
|
377
|
|
- unsigned markEndSmpIdx = markPtr->obj.seqSmpIdx + markPtr->obj.durSmpCnt;
|
378
|
|
-
|
379
|
|
- // get the score event associated with the marker's bar number.
|
380
|
|
- const cmScoreEvt_t* evtPtr = cmScoreBarEvt(sp->scH,markPtr->bar);
|
381
|
|
- assert( evtPtr != NULL );
|
382
|
|
-
|
383
|
|
-
|
384
|
|
- // get the score location associated with the markers bar score event
|
385
|
|
- const cmScoreLoc_t* locPtr = cmScoreEvtLoc(sp->scH,evtPtr);
|
386
|
|
- assert( locPtr != NULL );
|
387
|
|
-
|
388
|
|
- cmRptPrintf(&ctx->rpt,"Processing loc:%i seq:%i %s %s\n",locPtr->index,seqId,cmStringNullGuard(markPtr->obj.name),cmStringNullGuard(markPtr->text));
|
|
487
|
+ case kBeginSectionSpId:
|
389
|
488
|
|
390
|
489
|
// reset the performance evaluation object
|
391
|
|
- if( cmScMeasReset(sp->meas) != cmOkRC )
|
392
|
|
- {
|
393
|
|
- cmErrMsg(&sp->err,kScoreMatchFailSpRC,"The score performance evaluation object failed on reset.");
|
394
|
|
- continue;
|
395
|
|
- }
|
396
|
|
-
|
397
|
|
- // reset the score matcher to begin searching at the bar location
|
398
|
|
- if( cmScMatcherReset(sp->match, locPtr->index ) != cmOkRC )
|
399
|
|
- {
|
400
|
|
- cmErrMsg(&sp->err,kScoreMatchFailSpRC,"The score matcher reset failed on location: %i.",locPtr->index);
|
401
|
|
- continue;
|
402
|
|
- }
|
403
|
|
-
|
404
|
|
- cmTlObj_t* o1p = o0p;
|
|
490
|
+ if( cmScMeasReset(m->meas) != cmOkRC )
|
|
491
|
+ rc = cmErrMsg(&sp->err,kScoreMatchFailSpRC,"The score performance evaluation object failed on reset.");
|
405
|
492
|
|
406
|
|
- // as long as more MIDI events are available get the next MIDI msg
|
407
|
|
- while( (rc == kOkSpRC) && (o1p = cmTimeLineNextTypeObj(sp->tlH, o1p, seqId, kMidiEvtTlId )) != NULL )
|
408
|
|
- {
|
409
|
|
- cmTlMidiEvt_t* mep = cmTimeLineMidiEvtObjPtr(sp->tlH,o1p);
|
410
|
|
- assert(mep != NULL );
|
|
493
|
+ m->curMarkPtr = curMarkPtr;
|
|
494
|
+ break;
|
411
|
495
|
|
412
|
|
- // if the msg falls after the end of the marker then we are done
|
413
|
|
- if( mep->obj.seqSmpIdx != cmInvalidIdx && mep->obj.seqSmpIdx > markEndSmpIdx )
|
414
|
|
- break;
|
|
496
|
+ case kEndSectionSpId:
|
|
497
|
+ break;
|
|
498
|
+ }
|
415
|
499
|
|
416
|
|
-
|
417
|
|
- // if the time line MIDI msg a note-on
|
418
|
|
- if( mep->msg->status == kNoteOnMdId )
|
419
|
|
- {
|
420
|
|
- cmRC_t cmRC = cmScMatcherExec(sp->match, mep->obj.seqSmpIdx, mep->msg->status, mep->msg->u.chMsgPtr->d0, mep->msg->u.chMsgPtr->d1, NULL );
|
|
500
|
+ return rc;
|
|
501
|
+}
|
421
|
502
|
|
422
|
|
- switch( cmRC )
|
423
|
|
- {
|
424
|
|
- case cmOkRC: // continue processing MIDI events
|
425
|
|
- break;
|
426
|
503
|
|
427
|
|
- case cmEofRC: // end of the score was encountered
|
428
|
|
- break;
|
|
504
|
+cmSpRC_t _cmScoreProcGenAllMeasurementsMain(cmCtx_t* ctx)
|
|
505
|
+{
|
|
506
|
+ const cmChar_t* rsrcFn = "/home/kevin/.kc/time_line.js";
|
|
507
|
+ const cmChar_t* outFn = "/home/kevin/src/cmkc/src/kc/data/meas0.js";
|
429
|
508
|
|
430
|
|
- case cmInvalidArgRC: // p->eli was not set correctly
|
431
|
|
- rc = cmErrMsg(&sp->err,kScoreMatchFailSpRC,"The score matcher failed due to an invalid argument.");
|
432
|
|
- goto errLabel;
|
433
|
|
- break;
|
|
509
|
+ cmSpRC_t rc = kOkSpRC;
|
|
510
|
+ _cmSpMeasProc_t* m = cmMemAllocZ(_cmSpMeasProc_t,1);
|
|
511
|
+ cmSp_t s;
|
|
512
|
+ cmSp_t* sp = &s;
|
434
|
513
|
|
435
|
|
- case cmSubSysFailRC: // scan resync failed
|
436
|
|
- rc = cmErrMsg(&sp->err,kScoreMatchFailSpRC,"The score matcher failed on resync.");
|
437
|
|
- cmScMatcherPrint(sp->match);
|
438
|
|
- //goto errLabel;
|
439
|
|
- break;
|
|
514
|
+ memset(sp,0,sizeof(s));
|
440
|
515
|
|
441
|
|
- default:
|
442
|
|
- { assert(0); }
|
443
|
|
- }
|
444
|
|
- }
|
445
|
|
- }
|
|
516
|
+ cmRptPrintf(&ctx->rpt,"Score Performance Evaluation Start\n");
|
446
|
517
|
|
447
|
|
- rc = kOkSpRC;
|
448
|
|
- }
|
449
|
|
- }
|
|
518
|
+ // initialize the score processor
|
|
519
|
+ if((rc = _cmScoreProcInit(ctx,sp,rsrcFn,_cmSpProcMeasCb,_cmSpMatchMeasCb,m)) != kOkSpRC )
|
|
520
|
+ goto errLabel;
|
450
|
521
|
|
|
522
|
+ // allocate the performance evaluation measurement object
|
|
523
|
+ m->meas = cmScMeasAlloc( sp->ctx, NULL, sp->scH, sp->srate, sp->dynArray, sp->dynCnt );
|
|
524
|
+ m->sp = sp;
|
451
|
525
|
|
452
|
|
- errLabel:
|
|
526
|
+ // run the score processor
|
|
527
|
+ _cmScoreProcProcess(ctx,sp);
|
453
|
528
|
|
454
|
|
- if((rc = _cmScWriteMeasFile(ctx, sp, outFn )) != kOkSpRC )
|
|
529
|
+ // write the results of the performance evaluation
|
|
530
|
+ if((rc = _cmScWriteMeasFile(ctx, sp, m, outFn )) != kOkSpRC )
|
455
|
531
|
cmErrMsg(&sp->err,kFileFailSpRC,"The measurement output did not complete without errors.");
|
456
|
532
|
|
457
|
|
- _cmScMeas_t* mp = sp->list_beg;
|
|
533
|
+ // free the measurement linked list
|
|
534
|
+ _cmSpMeas_t* mp = m->list_beg;
|
458
|
535
|
while(mp!=NULL)
|
459
|
536
|
{
|
460
|
|
- _cmScMeas_t* np = mp->link;
|
|
537
|
+ _cmSpMeas_t* np = mp->link;
|
461
|
538
|
cmMemFree(mp);
|
462
|
539
|
mp = np;
|
463
|
540
|
}
|
464
|
541
|
|
465
|
|
- if( cmScMatcherFree(&sp->match) != cmOkRC )
|
466
|
|
- cmErrMsg(&sp->err,kScoreMatchFailSpRC,"The score matcher release failed.");
|
467
|
|
-
|
468
|
|
- if( cmScMeasFree(&sp->meas) != cmOkRC )
|
|
542
|
+ // free the performance evaluation object
|
|
543
|
+ if( cmScMeasFree(&m->meas) != cmOkRC )
|
469
|
544
|
cmErrMsg(&sp->err,kScoreMatchFailSpRC,"The performance evaluation object failed.");
|
470
|
545
|
|
|
546
|
+ //cmScorePrint(sp.scH,&ctx->rpt);
|
|
547
|
+ //cmScorePrintLoc(sp.scH);
|
|
548
|
+
|
|
549
|
+
|
|
550
|
+ errLabel:
|
|
551
|
+ _cmScoreProcFinal(sp);
|
|
552
|
+
|
|
553
|
+ cmMemFree(m);
|
|
554
|
+
|
|
555
|
+ cmRptPrintf(&ctx->rpt,"Score Proc End\n");
|
471
|
556
|
|
472
|
557
|
return rc;
|
|
558
|
+
|
473
|
559
|
}
|
474
|
560
|
|
475
|
|
-
|
476
|
561
|
//==================================================================================================
|
|
562
|
+typedef struct
|
|
563
|
+{
|
|
564
|
+ cmSp_t* sp;
|
|
565
|
+} cmSpPerfProc_t;
|
477
|
566
|
|
478
|
|
-unsigned cmScoreProc(cmCtx_t* ctx)
|
|
567
|
+void _cmSpMatchPerfCb( cmScMatcher* p, void* arg, cmScMatcherResult_t* rp )
|
|
568
|
+{
|
|
569
|
+ cmSpPerfProc_t* m = (cmSpPerfProc_t*)arg;
|
|
570
|
+
|
|
571
|
+}
|
|
572
|
+
|
|
573
|
+cmSpRC_t _cmSpProcPerfCb( void* arg, cmSp_t* sp, cmScoreProcSelId_t id, cmTlMarker_t* curMarkPtr )
|
|
574
|
+{
|
|
575
|
+ cmSpPerfProc_t* m = (cmSpPerfProc_t*)arg;
|
|
576
|
+
|
|
577
|
+}
|
|
578
|
+
|
|
579
|
+cmSpRC_t _cmScoreProcGenPerfMain(cmCtx_t* ctx)
|
479
|
580
|
{
|
480
|
|
- cmSpRC_t rc = kOkSpRC;
|
481
|
581
|
const cmChar_t* rsrcFn = "/home/kevin/.kc/time_line.js";
|
482
|
582
|
const cmChar_t* outFn = "/home/kevin/src/cmkc/src/kc/data/meas0.js";
|
483
|
|
- cmSp_t sp;
|
484
|
583
|
|
485
|
|
- memset(&sp,0,sizeof(sp));
|
|
584
|
+ cmSpRC_t rc = kOkSpRC;
|
|
585
|
+ cmSpPerfProc_t* m = cmMemAllocZ(cmSpPerfProc_t,1);
|
|
586
|
+ cmSp_t s;
|
|
587
|
+ cmSp_t* sp = &s;
|
|
588
|
+
|
|
589
|
+ memset(sp,0,sizeof(s));
|
486
|
590
|
|
487
|
|
- cmRptPrintf(&ctx->rpt,"Score Proc Start\n");
|
|
591
|
+ cmRptPrintf(&ctx->rpt,"Score Performance Start\n");
|
488
|
592
|
|
489
|
|
- if((rc = _cmScoreProcInit(ctx,&sp,rsrcFn)) != kOkSpRC )
|
|
593
|
+ // initialize the score processor
|
|
594
|
+ if((rc = _cmScoreProcInit(ctx,sp,rsrcFn,_cmSpProcPerfCb,_cmSpMatchPerfCb,m)) != kOkSpRC )
|
490
|
595
|
goto errLabel;
|
491
|
|
-
|
492
|
|
- _cmScoreGenAllMeasurements(ctx,&sp,outFn);
|
|
596
|
+
|
|
597
|
+ m->sp = sp;
|
|
598
|
+
|
|
599
|
+ // run the score processor
|
|
600
|
+ _cmScoreProcProcess(ctx,sp);
|
|
601
|
+
|
|
602
|
+ // write the results of the performance evaluation
|
|
603
|
+ if((rc = _cmScWriteMeasFile(ctx, sp, m, outFn )) != kOkSpRC )
|
|
604
|
+ cmErrMsg(&sp->err,kFileFailSpRC,"The measurement output did not complete without errors.");
|
493
|
605
|
|
494
|
606
|
//cmScorePrint(sp.scH,&ctx->rpt);
|
495
|
607
|
//cmScorePrintLoc(sp.scH);
|
496
|
|
-
|
497
|
608
|
|
498
|
609
|
errLabel:
|
499
|
|
- _cmScoreProcFinal(&sp);
|
|
610
|
+ _cmScoreProcFinal(sp);
|
|
611
|
+
|
|
612
|
+ cmMemFree(m);
|
500
|
613
|
|
501
|
614
|
cmRptPrintf(&ctx->rpt,"Score Proc End\n");
|
502
|
615
|
|
|
@@ -504,3 +617,17 @@ unsigned cmScoreProc(cmCtx_t* ctx)
|
504
|
617
|
|
505
|
618
|
}
|
506
|
619
|
|
|
620
|
+
|
|
621
|
+
|
|
622
|
+//==================================================================================================
|
|
623
|
+
|
|
624
|
+cmSpRC_t cmScoreProc(cmCtx_t* ctx)
|
|
625
|
+{
|
|
626
|
+ cmSpRC_t rc = kOkSpRC;
|
|
627
|
+
|
|
628
|
+ _cmScoreProcGenAllMeasurementsMain(ctx);
|
|
629
|
+
|
|
630
|
+ return rc;
|
|
631
|
+
|
|
632
|
+}
|
|
633
|
+
|