Browse Source

cmScoreMatchGraphic.c : Fixed cmScoreMatchGraphicTimeLineBars() to find bar locations which were not directly adjacent to note events.

master
kevin 8 years ago
parent
commit
5cfd2095c7
1 changed files with 25 additions and 4 deletions
  1. 25
    4
      app/cmScoreMatchGraphic.c

+ 25
- 4
app/cmScoreMatchGraphic.c View File

@@ -625,15 +625,36 @@ cmSmgRC_t cmScoreMatchGraphicGenTimeLineBars( cmSmgH_t h, const cmChar_t* fn, un
625 625
   if( cmFileOpen(&f,fn,kWriteFileFl,p->err.rpt)  != kOkFileRC )
626 626
     return cmErrMsg(&p->err,kFileSmgRC,"The time-line bar file '%s' could not be created.",cmStringNullGuard(fn));
627 627
 
628
+  // for each MIDI event
628 629
   for(i=0; i<p->mN; ++i)
629
-    if( p->mV[i].matchV != NULL && p->mV[i].matchV->score != NULL && p->mV[i].matchV->score > p->scV && p->mV[i].matchV->score[-1].type==kBarEvtScId )      
630
+  {
631
+    // if this MIDI event matched a score event
632
+    if( p->mV[i].matchV == NULL || p->mV[i].matchV->score == NULL )
633
+      continue;
634
+
635
+    // backup the score position by one location - because we are looking for bar events
636
+    // which are just prior to note events - because for our purposes they will have the same onset.
637
+    cmSmgSc_t* s = p->mV[i].matchV->score - 1;
638
+    for(; s >= p->scV; s-- )
630 639
     {
631
-      unsigned bar = p->mV[i].matchV->score->barNumb;
640
+      // if this is a bar event just preceding the matched MIDI event - then the bar happens at the same time as the note event
641
+      if( s->type == kBarEvtScId )
642
+        break;
643
+
644
+      // if this is a note event - then there is no preceding bar event 
645
+      if( s->type == kNonEvtScId )
646
+        break;
647
+    }
648
+    
649
+    // if a bar was found
650
+    if(s >= p->scV && s->type == kBarEvtScId)
651
+    {
652
+      unsigned bar    = s->barNumb;
632 653
       unsigned offset = p->mV[i].secs * srate;
633
-      unsigned smpCnt = p->mfDurSecs * srate - offset;
654
+      unsigned smpCnt = p->mfDurSecs  * srate - offset;
634 655
       cmFilePrintf(f,"{ label: \"%i\" type: \"mk\" ref: \"mf-0\" offset: %8i smpCnt:%8i trackId: 0 textStr: \"Bar %3i\" bar: %3i sec:\"%3i\" }\n",bar,offset,smpCnt,bar,bar,bar);
635 656
     }
636
-
657
+  }
637 658
   cmFileClose(&f);
638 659
   return rc;
639 660
   

Loading…
Cancel
Save