ソースを参照

cmTakeSeqBldr.c : Partial initial implementation of _cmTakeSeqBldrRender().

master
Kevin Larke 9年前
コミット
7daa1ebcee
1個のファイルの変更86行の追加17行の削除
  1. 86
    17
      app/cmTakeSeqBldr.c

+ 86
- 17
app/cmTakeSeqBldr.c ファイルの表示

@@ -23,7 +23,7 @@ typedef struct cmScTrkMidiTsb_str
23 23
 {
24 24
   unsigned mni;      // MIDI note index as an offset from the take marker
25 25
   unsigned muid;     // MIDI file msg  unique id
26
-  unsigned scEvtIdx; // score event index this not is assoc'd with or -1 if it did not match
26
+  unsigned scEvtIdx; // score event index this note/pedal is assoc'd with or -1 if it did not match
27 27
   unsigned flags;    // flags from cmScMatcherResult_t 
28 28
 } cmScTrkMidiTsb_t;
29 29
 
@@ -32,10 +32,10 @@ typedef struct cmScTrkMidiTsb_str
32 32
 typedef struct cmScTrkTakeTsb_str
33 33
 {
34 34
   unsigned          tlMarkerUid;  // marker time line uid assoc'd with this take
35
-  cmScTrkMidiTsb_t* midiV;      // midiV[midiN] score to midi file map recd. array.
36
-  unsigned          midiN; 
37
-  unsigned          minMuid;    // min MIDI muid in midiV[]
38
-  unsigned          maxMuid;    // max MIDI muid in midiV[]
35
+  cmScTrkMidiTsb_t* midiV;        // midiV[midiN] score to midi file map recd. array.
36
+  unsigned          midiN;        // count of records in midiV[]
37
+  unsigned          minMuid;      // min MIDI muid in midiV[]
38
+  unsigned          maxMuid;      // max MIDI muid in midiV[]
39 39
   bool              failFl;
40 40
 } cmScTrkTakeTsb_t;
41 41
 
@@ -131,9 +131,12 @@ cmTsbRC_t _cmTsbScoreTrkFree( cmTsb_t* p )
131 131
 
132 132
 // Free a take record. Note that the record must be unlinked
133 133
 // unlinked from p->takes (See _cmTakeTsbUnlink().) prior to calling this function.
134
-void _cmTsbTakeFree( cmTsb_t* p, cmTakeTsb_t* t )
134
+void _cmTsbTakeFree( cmTsb_t* p, cmTakeTsb_t** tp )
135 135
 {
136
-  cmMidiTsb_t* m  = t->midi;
136
+  if( tp == NULL || *tp==NULL )
137
+    return;
138
+
139
+  cmMidiTsb_t* m  = (*tp)->midi;
137 140
     
138 141
   while( m != NULL )
139 142
   {
@@ -142,7 +145,7 @@ void _cmTsbTakeFree( cmTsb_t* p, cmTakeTsb_t* t )
142 145
     m = nm;
143 146
   }
144 147
   
145
-  cmMemFree(t);
148
+  cmMemPtrFree(tp);
146 149
 }
147 150
 
148 151
 // Unlink a 'take' record from p->takes.
@@ -179,10 +182,12 @@ cmTsbRC_t _cmTsbFree( cmTsb_t* p )
179 182
   while( t != NULL )
180 183
   {
181 184
     cmTakeTsb_t* nt = t->link;
182
-    _cmTsbTakeFree(p,t);
185
+    _cmTsbTakeFree(p,&t);
183 186
     t = nt;
184 187
   }
185 188
 
189
+  _cmTsbTakeFree(p,&p->out);
190
+
186 191
   cmMemFree(p);
187 192
 
188 193
  errLabel:
@@ -327,6 +332,59 @@ cmTsbRC_t _cmTsbLoadScoreTrkFile( cmTsb_t* p, const cmChar_t* scoreTrkFn )
327 332
   return rc;
328 333
 }
329 334
 
335
+cmTsbRC_t _cmTakeSeqBldrRender( cmTsb_t* p )
336
+{
337
+  cmTsbRC_t rc = kOkTsbRC;
338
+
339
+  _cmTsbTakeFree(p,&p->out);
340
+
341
+  // get the min/max scEvtIdx among all takes
342
+  cmTakeTsb_t* t           = p->takes;
343
+  cmMidiTsb_t* m           = NULL;
344
+  unsigned     minScEvtIdx = INT_MAX;
345
+  unsigned     maxScEvtIdx = 0;
346
+  unsigned     i;
347
+
348
+  for(; t!=NULL; t=t->link)
349
+  {
350
+    for(m=t->midi; m!=NULL; m=m->link)
351
+    {
352
+      if( m->scEvtIdx < minScEvtIdx )
353
+        minScEvtIdx = m->scEvtIdx;
354
+
355
+      if( m->scEvtIdx > maxScEvtIdx )
356
+        maxScEvtIdx = m->scEvtIdx;
357
+    }
358
+  }
359
+
360
+  p->out = cmMemAllocZ(cmTakeTsb_t,1);
361
+
362
+  // allocate one event for each score postion to render
363
+  cmMidiTsb_t* m0 = NULL;
364
+  for(i=0; i<maxScEvtIdx-minScEvtIdx+1; ++i)
365
+  {
366
+    m = cmMemAllocZ(cmMidiTsb_t,1);
367
+    m->srcId    = cmInvalidId;
368
+    m->scEvtIdx = minScEvtIdx + i;
369
+    m->ref      = m0;
370
+    m0          = m;
371
+
372
+    if( p->out->midi == NULL )
373
+      p->out->midi = m;
374
+  }
375
+
376
+  // fill the event list from the selected takes
377
+  for(t=p->takes; t!=NULL; t=t->link)
378
+  {
379
+    
380
+  }
381
+  
382
+  if( rc != kOkTsbRC )
383
+    _cmTsbTakeFree(p,&p->out);
384
+
385
+  return rc;
386
+}
387
+
330 388
 cmTsbRC_t cmTakeSeqBldrAlloc( cmCtx_t* ctx, cmTakeSeqBldrH_t* hp )
331 389
 {
332 390
   cmTsbRC_t rc;
@@ -471,10 +529,8 @@ cmTsbRC_t cmTakeSeqBldrLoadTake( cmTakeSeqBldrH_t h, unsigned tlMarkUid, bool ov
471 529
   cmTakeTsb_t* t = cmMemAllocZ(cmTakeTsb_t,1);
472 530
 
473 531
   t->tlMarkerUid = tlMarkUid;
474
-  if( p->takes != NULL )
475
-    p->takes->link = t;
476
-
477
-  p->takes = t;
532
+  t->link        = p->takes;
533
+  p->takes       = t;
478 534
 
479 535
 
480 536
   cmMidiTsb_t*            m0  = NULL;
@@ -548,7 +604,7 @@ cmTsbRC_t cmTakeSeqBldrUnloadTake( cmTakeSeqBldrH_t h, unsigned tlMarkUid )
548 604
 
549 605
   assert( t != NULL );
550 606
 
551
-  _cmTsbTakeFree(p,t);
607
+  _cmTsbTakeFree(p,&t);
552 608
     
553 609
   return rc;
554 610
 }
@@ -591,13 +647,26 @@ cmTsbRC_t cmTakeSeqBldrWriteMidiFile( cmTakeSeqBldrH_t h, const char* fn )
591 647
 
592 648
 cmTsbRC_t cmTakeSeqBldrTest( cmCtx_t* ctx )
593 649
 {
594
-  const cmChar_t*  scoreTrkFn = "/home/kevin/src/cmkc/src/kc/data/assoc0.js";
595
-  cmTakeSeqBldrH_t tsbH  = cmTakeSeqBldrNullHandle;
596
-  cmTsbRC_t        tsbRC = kOkTsbRC;
650
+  const cmChar_t*  scoreTrkFn = "/home/kevin/src/cmkc/src/kc/data/takeSeqBldr0.js";
651
+  cmTakeSeqBldrH_t tsbH       = cmTakeSeqBldrNullHandle;
652
+  cmTsbRC_t        tsbRC      = kOkTsbRC;
653
+  unsigned         markerIdV[]  = { 2200, 2207 };
654
+  unsigned         markerN      = sizeof(markerIdV)/sizeof(markerIdV[0]);
655
+  unsigned         i;
597 656
 
598 657
   if((tsbRC = cmTakeSeqBldrAllocFn(ctx, &tsbH, scoreTrkFn )) != kOkTsbRC )
599 658
     return cmErrMsg(&ctx->err,tsbRC,"TSB Allocate and parse '%s' failed.",scoreTrkFn);
600 659
 
660
+  cmRptPrintf(&ctx->rpt, "TakeSeqBldr Allocation Completed.");
661
+
662
+  for(i=0; i<markerN; ++i)
663
+  {
664
+    if((tsbRC = cmTakeSeqBldrLoadTake(tsbH,markerIdV[i],false)) != kOkTsbRC )
665
+      cmErrMsg(&ctx->err,tsbRC,"TSB load take failed.");
666
+
667
+    cmRptPrintf(&ctx->rpt, "TakeSeqBldr Load Take %i Completed.",markerIdV[i]);
668
+  }
669
+
601 670
   if((tsbRC = cmTakeSeqBldrFree(&tsbH)) != kOkTsbRC )
602 671
     return cmErrMsg(&ctx->err,tsbRC,"TSB Free failed.");
603 672
 

読み込み中…
キャンセル
保存