Explorar el Código

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

master
Kevin Larke hace 9 años
padre
commit
7daa1ebcee
Se han modificado 1 ficheros con 86 adiciones y 17 borrados
  1. 86
    17
      app/cmTakeSeqBldr.c

+ 86
- 17
app/cmTakeSeqBldr.c Ver fichero

23
 {
23
 {
24
   unsigned mni;      // MIDI note index as an offset from the take marker
24
   unsigned mni;      // MIDI note index as an offset from the take marker
25
   unsigned muid;     // MIDI file msg  unique id
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
   unsigned flags;    // flags from cmScMatcherResult_t 
27
   unsigned flags;    // flags from cmScMatcherResult_t 
28
 } cmScTrkMidiTsb_t;
28
 } cmScTrkMidiTsb_t;
29
 
29
 
32
 typedef struct cmScTrkTakeTsb_str
32
 typedef struct cmScTrkTakeTsb_str
33
 {
33
 {
34
   unsigned          tlMarkerUid;  // marker time line uid assoc'd with this take
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
   bool              failFl;
39
   bool              failFl;
40
 } cmScTrkTakeTsb_t;
40
 } cmScTrkTakeTsb_t;
41
 
41
 
131
 
131
 
132
 // Free a take record. Note that the record must be unlinked
132
 // Free a take record. Note that the record must be unlinked
133
 // unlinked from p->takes (See _cmTakeTsbUnlink().) prior to calling this function.
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
   while( m != NULL )
141
   while( m != NULL )
139
   {
142
   {
142
     m = nm;
145
     m = nm;
143
   }
146
   }
144
   
147
   
145
-  cmMemFree(t);
148
+  cmMemPtrFree(tp);
146
 }
149
 }
147
 
150
 
148
 // Unlink a 'take' record from p->takes.
151
 // Unlink a 'take' record from p->takes.
179
   while( t != NULL )
182
   while( t != NULL )
180
   {
183
   {
181
     cmTakeTsb_t* nt = t->link;
184
     cmTakeTsb_t* nt = t->link;
182
-    _cmTsbTakeFree(p,t);
185
+    _cmTsbTakeFree(p,&t);
183
     t = nt;
186
     t = nt;
184
   }
187
   }
185
 
188
 
189
+  _cmTsbTakeFree(p,&p->out);
190
+
186
   cmMemFree(p);
191
   cmMemFree(p);
187
 
192
 
188
  errLabel:
193
  errLabel:
327
   return rc;
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
 cmTsbRC_t cmTakeSeqBldrAlloc( cmCtx_t* ctx, cmTakeSeqBldrH_t* hp )
388
 cmTsbRC_t cmTakeSeqBldrAlloc( cmCtx_t* ctx, cmTakeSeqBldrH_t* hp )
331
 {
389
 {
332
   cmTsbRC_t rc;
390
   cmTsbRC_t rc;
471
   cmTakeTsb_t* t = cmMemAllocZ(cmTakeTsb_t,1);
529
   cmTakeTsb_t* t = cmMemAllocZ(cmTakeTsb_t,1);
472
 
530
 
473
   t->tlMarkerUid = tlMarkUid;
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
   cmMidiTsb_t*            m0  = NULL;
536
   cmMidiTsb_t*            m0  = NULL;
548
 
604
 
549
   assert( t != NULL );
605
   assert( t != NULL );
550
 
606
 
551
-  _cmTsbTakeFree(p,t);
607
+  _cmTsbTakeFree(p,&t);
552
     
608
     
553
   return rc;
609
   return rc;
554
 }
610
 }
591
 
647
 
592
 cmTsbRC_t cmTakeSeqBldrTest( cmCtx_t* ctx )
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
   if((tsbRC = cmTakeSeqBldrAllocFn(ctx, &tsbH, scoreTrkFn )) != kOkTsbRC )
657
   if((tsbRC = cmTakeSeqBldrAllocFn(ctx, &tsbH, scoreTrkFn )) != kOkTsbRC )
599
     return cmErrMsg(&ctx->err,tsbRC,"TSB Allocate and parse '%s' failed.",scoreTrkFn);
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
   if((tsbRC = cmTakeSeqBldrFree(&tsbH)) != kOkTsbRC )
670
   if((tsbRC = cmTakeSeqBldrFree(&tsbH)) != kOkTsbRC )
602
     return cmErrMsg(&ctx->err,tsbRC,"TSB Free failed.");
671
     return cmErrMsg(&ctx->err,tsbRC,"TSB Free failed.");
603
 
672
 

Loading…
Cancelar
Guardar