Просмотр исходного кода

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

master
kevin 7 лет назад
Родитель
Сommit
ee9ba9270e
2 измененных файлов: 47 добавлений и 27 удалений
  1. 38
    26
      app/cmMidiScoreFollow.c
  2. 9
    1
      app/cmMidiScoreFollow.h

+ 38
- 26
app/cmMidiScoreFollow.c Просмотреть файл

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
 // Write one scScoreMatcherResult_t record to the file fH.
123
 // Write one scScoreMatcherResult_t record to the file fH.
116
 unsigned _cmMsf_WriteMatchFileLine( cmFileH_t fH, cmScH_t scH, const cmScMatcherResult_t* r )
124
 unsigned _cmMsf_WriteMatchFileLine( cmFileH_t fH, cmScH_t scH, const cmScMatcherResult_t* r )
117
 {
125
 {
130
     cmMidiToSciPitch(e->pitch,buf,5);
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
     loc==NULL ? 0 : loc->barNumb,              // score evt bar
142
     loc==NULL ? 0 : loc->barNumb,              // score evt bar
135
     scUid,                                     // score event uuid
143
     scUid,                                     // score event uuid
136
     buf,                                       // score event pitch
144
     buf,                                       // score event pitch
147
   r->rV[r->rN++] = *rp;
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
   double                   srate    = 96000.0;
169
   double                   srate    = 96000.0;
162
   cmScMatcher*             smp      = NULL;  
170
   cmScMatcher*             smp      = NULL;  
163
   cmScH_t                  scH      = cmScNullHandle;
171
   cmScH_t                  scH      = cmScNullHandle;
179
   cmCtx* prCtx   = cmCtxAlloc(NULL, err.rpt, cmLHeapNullHandle, cmSymTblNullHandle );
187
   cmCtx* prCtx   = cmCtxAlloc(NULL, err.rpt, cmLHeapNullHandle, cmSymTblNullHandle );
180
   
188
   
181
   // initialize the score
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
     goto errLabel;
193
     goto errLabel;
186
   }
194
   }
187
 
195
 
188
   // setup the callback record
196
   // setup the callback record
189
   if((sfr.rAllocN  = cmScoreEvtCount( scH )*2) == 0)
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
     goto errLabel;
200
     goto errLabel;
193
   }
201
   }
194
 
202
 
229
   printf("MIDI notes:%i Score Events:%i\n",mN,cmScoreEvtCount(scH));
237
   printf("MIDI notes:%i Score Events:%i\n",mN,cmScoreEvtCount(scH));
230
 
238
 
231
   // create the output file
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
     goto errLabel;    
243
     goto errLabel;    
236
   }
244
   }
237
 
245
 
238
   // allocate the graphics object
246
   // allocate the graphics object
239
-  if( cmScoreMatchGraphicAlloc( ctx, &smgH, scoreFn, midiFn ) != kOkSmgRC )
247
+  if( cmScoreMatchGraphicAlloc( ctx, &smgH, scoreCsvFn, midiFn ) != kOkSmgRC )
240
   {
248
   {
241
     rc = cmErrMsg(&err,kFailMsfRC,"Score Match Graphics allocation failed..");
249
     rc = cmErrMsg(&err,kFailMsfRC,"Score Match Graphics allocation failed..");
242
     goto errLabel;    
250
     goto errLabel;    
243
   }
251
   }
244
 
252
 
253
+  // write the match report output file header
254
+  _cmMsf_WriteMatchFileHeader(fH);
245
 
255
 
246
   // for each score follower callback record 
256
   // for each score follower callback record 
247
   for(i=0; i<sfr.rN; ++i)
257
   for(i=0; i<sfr.rN; ++i)
267
   //cmMidiFilePrintMsgs( mfH, &ctx->rpt );
277
   //cmMidiFilePrintMsgs( mfH, &ctx->rpt );
268
 
278
 
269
   // write the tracking match file as an SVG file.
279
   // write the tracking match file as an SVG file.
270
-  cmScoreMatchGraphicWrite( smgH, svgFn );
280
+  cmScoreMatchGraphicWrite( smgH, matchSvgOutFn );
271
 
281
 
272
   // write a cmTimeLine file which contains markers at each bar position
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
  errLabel:
290
  errLabel:
286
 
298
 
287
   cmCtxFree(&prCtx);
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
   return rc;
308
   return rc;
297
 }
309
 }

+ 9
- 1
app/cmMidiScoreFollow.h Просмотреть файл

15
   typedef cmRC_t cmMsfRC_t;
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
 #ifdef __cplusplus
28
 #ifdef __cplusplus
21
 }
29
 }

Загрузка…
Отмена
Сохранить