Browse Source

cmMidiScoreFollow.h/c : Added filename parameters to cmMidiScoreFollowMain().

master
kevin 8 years ago
parent
commit
ee9ba9270e
2 changed files with 47 additions and 27 deletions
  1. 38
    26
      app/cmMidiScoreFollow.c
  2. 9
    1
      app/cmMidiScoreFollow.h

+ 38
- 26
app/cmMidiScoreFollow.c View File

@@ -112,6 +112,14 @@ void _cmMsf_ReportMidiErrors( const _cmMsf_ScoreFollow_t* f, cmScH_t scH, const
112 112
   }
113 113
 }
114 114
 
115
+void _cmMsf_WriteMatchFileHeader( cmFileH_t fH )
116
+{
117
+  cmFilePrintf(fH,"  Score Score Score MIDI  MIDI MIDI\n");
118
+  cmFilePrintf(fH,"  Bar   UUID  Pitch UUID  Ptch Vel.\n");
119
+  cmFilePrintf(fH,"- ----- ----- ----- ----- ---- ----\n");
120
+}
121
+
122
+
115 123
 // Write one scScoreMatcherResult_t record to the file fH.
116 124
 unsigned _cmMsf_WriteMatchFileLine( cmFileH_t fH, cmScH_t scH, const cmScMatcherResult_t* r )
117 125
 {
@@ -130,7 +138,7 @@ unsigned _cmMsf_WriteMatchFileLine( cmFileH_t fH, cmScH_t scH, const cmScMatcher
130 138
     cmMidiToSciPitch(e->pitch,buf,5);
131 139
   }
132 140
   
133
-  cmFilePrintf(fH,"m %3i %5i %4s %5i %4s %3i\n",
141
+  cmFilePrintf(fH,"m %5i %5i %5s %5i %4s %3i\n",
134 142
     loc==NULL ? 0 : loc->barNumb,              // score evt bar
135 143
     scUid,                                     // score event uuid
136 144
     buf,                                       // score event pitch
@@ -147,17 +155,17 @@ void _cmMsf_ScoreFollowCb( struct cmScMatcher_str* p, void* arg, cmScMatcherResu
147 155
   r->rV[r->rN++] = *rp;
148 156
 }
149 157
 
150
-cmMsfRC_t cmMidiScoreFollowMain( cmCtx_t* ctx )
158
+cmMsfRC_t cmMidiScoreFollowMain(
159
+  cmCtx_t* ctx,
160
+  const cmChar_t* scoreCsvFn,      // score CSV file as generated from cmXScoreTest().
161
+  const cmChar_t* midiFn,          // MIDI file to track
162
+  const cmChar_t* matchRptOutFn,   // Score follow status report 
163
+  const cmChar_t* matchSvgOutFn,   // Score follow graphic report
164
+  const cmChar_t* midiOutFn,       // (optional) midiFn with apply sostenuto and velocities from the score to the MIDI file
165
+  const cmChar_t* tlBarOutFn       // (optional) bar positions sutiable for use in a cmTimeLine description file.
166
+)
151 167
 {
152
-  cmMsfRC_t             rc          = kOkMsfRC;
153
-  //const cmChar_t* scoreFn         = cmFsMakeUserDirFn("src/kc/src/kc/data","mod2e.csv");
154
-  const cmChar_t*          scoreFn  = cmFsMakeUserDirFn("temp","a7.csv");
155
-  const cmChar_t*          midiFn   = cmFsMakeUserDirFn("media/projects/imag_themes/scores/gen","round1-utf8_11.mid");
156
-  const cmChar_t*          outFn    = cmFsMakeUserDirFn("temp","match.txt");
157
-  const cmChar_t*          svgFn    = cmFsMakeUserDirFn("temp","score0.html");
158
-  const cmChar_t*          newMidiFn= cmFsMakeUserDirFn("temp","a7.mid");
159
-  const cmChar_t*          tlBarFn  = cmFsMakeUserDirFn("temp","time_line_temp.txt");
160
-  
168
+  cmMsfRC_t                rc        = kOkMsfRC;  
161 169
   double                   srate    = 96000.0;
162 170
   cmScMatcher*             smp      = NULL;  
163 171
   cmScH_t                  scH      = cmScNullHandle;
@@ -179,16 +187,16 @@ cmMsfRC_t cmMidiScoreFollowMain( cmCtx_t* ctx )
179 187
   cmCtx* prCtx   = cmCtxAlloc(NULL, err.rpt, cmLHeapNullHandle, cmSymTblNullHandle );
180 188
   
181 189
   // initialize the score
182
-  if( cmScoreInitialize( ctx, &scH, scoreFn, srate, NULL, 0, NULL, NULL, cmSymTblNullHandle) != kOkScRC )
190
+  if( cmScoreInitialize( ctx, &scH, scoreCsvFn, srate, NULL, 0, NULL, NULL, cmSymTblNullHandle) != kOkScRC )
183 191
   {
184
-    rc = cmErrMsg(&err,kFailMsfRC,"cmScoreInitialize() failed on %s",cmStringNullGuard(scoreFn));
192
+    rc = cmErrMsg(&err,kFailMsfRC,"cmScoreInitialize() failed on %s",cmStringNullGuard(scoreCsvFn));
185 193
     goto errLabel;
186 194
   }
187 195
 
188 196
   // setup the callback record
189 197
   if((sfr.rAllocN  = cmScoreEvtCount( scH )*2) == 0)
190 198
   {
191
-    rc = cmErrMsg(&err,kFailMsfRC,"The score %s appears to be empty.",cmStringNullGuard(scoreFn));
199
+    rc = cmErrMsg(&err,kFailMsfRC,"The score %s appears to be empty.",cmStringNullGuard(scoreCsvFn));
192 200
     goto errLabel;
193 201
   }
194 202
 
@@ -229,19 +237,21 @@ cmMsfRC_t cmMidiScoreFollowMain( cmCtx_t* ctx )
229 237
   printf("MIDI notes:%i Score Events:%i\n",mN,cmScoreEvtCount(scH));
230 238
 
231 239
   // create the output file
232
-  if( cmFileOpen(&fH,outFn,kWriteFileFl,&ctx->rpt) != kOkFileRC )
240
+  if( cmFileOpen(&fH,matchRptOutFn,kWriteFileFl,&ctx->rpt) != kOkFileRC )
233 241
   {
234
-    rc = cmErrMsg(&err,kFailMsfRC,"Unable to create the file '%s'.",cmStringNullGuard(outFn));
242
+    rc = cmErrMsg(&err,kFailMsfRC,"Unable to create the file '%s'.",cmStringNullGuard(matchRptOutFn));
235 243
     goto errLabel;    
236 244
   }
237 245
 
238 246
   // allocate the graphics object
239
-  if( cmScoreMatchGraphicAlloc( ctx, &smgH, scoreFn, midiFn ) != kOkSmgRC )
247
+  if( cmScoreMatchGraphicAlloc( ctx, &smgH, scoreCsvFn, midiFn ) != kOkSmgRC )
240 248
   {
241 249
     rc = cmErrMsg(&err,kFailMsfRC,"Score Match Graphics allocation failed..");
242 250
     goto errLabel;    
243 251
   }
244 252
 
253
+  // write the match report output file header
254
+  _cmMsf_WriteMatchFileHeader(fH);
245 255
 
246 256
   // for each score follower callback record 
247 257
   for(i=0; i<sfr.rN; ++i)
@@ -267,12 +277,14 @@ cmMsfRC_t cmMidiScoreFollowMain( cmCtx_t* ctx )
267 277
   //cmMidiFilePrintMsgs( mfH, &ctx->rpt );
268 278
 
269 279
   // write the tracking match file as an SVG file.
270
-  cmScoreMatchGraphicWrite( smgH, svgFn );
280
+  cmScoreMatchGraphicWrite( smgH, matchSvgOutFn );
271 281
 
272 282
   // write a cmTimeLine file which contains markers at each bar position
273
-  cmScoreMatchGraphicGenTimeLineBars(smgH, tlBarFn, srate );
283
+  if( tlBarOutFn != NULL )
284
+    cmScoreMatchGraphicGenTimeLineBars(smgH, tlBarOutFn, srate );
274 285
 
275
-  cmScoreMatchGraphicUpdateMidiFromScore( ctx, smgH, newMidiFn );
286
+  if( midiOutFn != NULL )
287
+    cmScoreMatchGraphicUpdateMidiFromScore( ctx, smgH, midiOutFn );
276 288
 
277 289
 
278 290
  errLabel:
@@ -286,12 +298,12 @@ cmMsfRC_t cmMidiScoreFollowMain( cmCtx_t* ctx )
286 298
 
287 299
   cmCtxFree(&prCtx);
288 300
 
289
-  cmFsFreeFn(scoreFn);
290
-  cmFsFreeFn(midiFn);
291
-  cmFsFreeFn(outFn);
292
-  cmFsFreeFn(svgFn);
293
-  cmFsFreeFn(newMidiFn);
294
-  cmFsFreeFn(tlBarFn);
301
+  //cmFsFreeFn(scoreCsvFn);
302
+  //cmFsFreeFn(midiFn);
303
+  //cmFsFreeFn(matchRptOutFn);
304
+  //cmFsFreeFn(matchSvgOutFn);
305
+  //cmFsFreeFn(outMidiFn);
306
+  //cmFsFreeFn(tlBarFn);
295 307
   
296 308
   return rc;
297 309
 }

+ 9
- 1
app/cmMidiScoreFollow.h View File

@@ -15,7 +15,15 @@ extern "C" {
15 15
   typedef cmRC_t cmMsfRC_t;
16 16
   
17 17
 
18
-  cmMsfRC_t cmMidiScoreFollowMain( cmCtx_t* ctx );
18
+  cmMsfRC_t cmMidiScoreFollowMain(
19
+    cmCtx_t* ctx,
20
+    const cmChar_t* scoreCsvFn,      // score CSV file as generated from cmXScoreTest().
21
+    const cmChar_t* midiFn,          // MIDI file to track
22
+    const cmChar_t* matchRptOutFn,   // Score follow status report 
23
+    const cmChar_t* matchSvgOutFn,   // Score follow graphic report
24
+    const cmChar_t* midiOutFn,       // (optional) midiFn with apply sostenuto and velocities from the score to the MIDI file
25
+    const cmChar_t* tlBarOutFn       // (optional) bar positions sutiable for use in a cmTimeLine description file.
26
+                                  );
19 27
   
20 28
 #ifdef __cplusplus
21 29
 }

Loading…
Cancel
Save