Преглед изворни кода

cmMidiFile.h/c, cmMidiFilePlay.c : Changed cmMidiTrackMsg_t.atick and amicro to type unsigned long long.

master
kevin пре 8 година
родитељ
комит
886bc82a52
3 измењених фајлова са 16 додато и 104 уклоњено
  1. 12
    100
      cmMidiFile.c
  2. 3
    3
      cmMidiFile.h
  3. 1
    1
      cmMidiFilePlay.c

+ 12
- 100
cmMidiFile.c Прегледај датотеку

@@ -428,7 +428,7 @@ int _cmMidiFileSortFunc( const void *p0, const void* p1 )
428 428
 void _cmMidiFileSetAccumulateTicks( _cmMidiFile_t* p )
429 429
 {
430 430
   cmMidiTrackMsg_t* nextTrkMsg[ p->trkN ]; // next msg in each track
431
-  unsigned          atick = 0;
431
+  unsigned long long atick = 0;
432 432
   unsigned          i;
433 433
   
434 434
   // iniitalize nextTrkTick[] and nextTrkMsg[].
@@ -466,8 +466,8 @@ void _cmMidiFileSetAbsoluteTime( _cmMidiFile_t* mfp )
466 466
   double   microsPerQN   = 60000000/120; // default tempo;
467 467
   double   amicro        = 0;
468 468
   double   microsPerTick = microsPerQN / mfp->ticksPerQN;
469
-  double   maxDMicro     = 60000000;
470
-  bool     fl            = true;
469
+  //double   maxDMicro     = 60000000;
470
+  //bool     fl            = false;
471 471
   unsigned i;
472 472
 
473 473
   for(i=0; i<mfp->msgN; ++i)
@@ -482,6 +482,7 @@ void _cmMidiFileSetAbsoluteTime( _cmMidiFile_t* mfp )
482 482
       dtick = mp->atick -  mfp->msgV[i-1]->atick;
483 483
     }
484 484
 
485
+    /*
485 486
     // if this is the first msg with a dtick greater than zero
486 487
     if( fl && mfp->msgV[i]->dtick > 0  )
487 488
     {
@@ -490,7 +491,7 @@ void _cmMidiFileSetAbsoluteTime( _cmMidiFile_t* mfp )
490 491
       // if this mesg has a large offset
491 492
       if( microsPerTick * dtick > maxDMicro )
492 493
       {
493
-        cmErrWarnMsg(&mfp->err,kLargeDeltaTickMfRC,"A message delta time of %f seconds was decreased to %f seconds.",(double)microsPerTick * dtick/1000000.0,(double)maxDMicro/1000000.0);        
494
+        cmErrWarnMsg(&mfp->err,kLargeDeltaTickMfRC,"An initial message delta time of %f seconds was decreased to %f seconds in '%s'.",(double)microsPerTick * dtick/1000000.0,(double)maxDMicro/1000000.0,cmStringNullGuard(mfp->fn));        
494 495
 
495 496
         // change the dtick to 1 (so it will still be the first msg w/ a non-zero dtick)
496 497
         mfp->msgV[i]->dtick = 1; 
@@ -503,6 +504,7 @@ void _cmMidiFileSetAbsoluteTime( _cmMidiFile_t* mfp )
503 504
 
504 505
       }
505 506
     }
507
+    */
506 508
     
507 509
     amicro     += microsPerTick * dtick;
508 510
     mp->amicro  = round(amicro);
@@ -631,94 +633,20 @@ cmMfRC_t cmMidiFileOpen( cmCtx_t* ctx, cmMidiFileH_t* hPtr, const char* fn )
631 633
     }
632 634
   }
633 635
 
634
-  /*
635
-  double microsPerQN  = 60000000/120; // default tempo;
636
-  double microsPerTick;
637
-  
638
-  double maxDMicro = 60.0 * 1000000.0; // max time between events (60 seconds)
639
-  
640
-  unsigned i = 0;
641
-  for(trkIdx=0; trkIdx<mfp->trkN; ++trkIdx)
642
-  {
643
-    unsigned          tick = 0;
644
-    cmMidiTrackMsg_t* tmp  = mfp->trkV[ trkIdx ].base;
645
-    
646
-    microsPerTick = microsPerQN / mfp->ticksPerQN;
647
-      
648
-    while( tmp != NULL )
649
-    {
650
-      assert( i < mfp->msgN);
651
-
652
-      // convert dtick to microseconds
653
-      unsigned dmicro = round(tmp->dtick * microsPerTick);
654
-
655
-      if( dmicro > maxDMicro )
656
-      {
657
-        tmp->dtick = round(maxDMicro / microsPerTick);
658
-        cmErrWarnMsg(&mfp->err,kLargeDeltaTickMfRC,"A message delta time of %f seconds was decreased to %f seconds.",(double)dmicro/1000000.0,(double)maxDMicro/1000000.0);        
659
-      }
660
-      
661
-      tick        += tmp->dtick;              // convert delta-ticks to absolute ticks
662
-      tmp->atick   = tick;
663
-      tmp->uid     = mfp->nextUid++;          // assign the msg uid
664
-      tmp->dmicro  = dmicro;
665
-      mfp->msgV[i] = tmp;
636
+  mfp->fn = _cmMidiFileMalloc(mfp,strlen(fn)+1);
637
+  assert( mfp->fn != NULL );
638
+  strcpy(mfp->fn,fn);
666 639
 
667
-      
668
-      
669
-      // track tempo changes
670
-      if( tmp->status == kMetaStId && tmp->metaId == kTempoMdId )
671
-        microsPerTick = tmp->u.iVal / mfp->ticksPerQN;
672
- 
673
-      tmp            = tmp->link;
674
-      ++i;
675
-    }  
676
-  }
677
-  */
678 640
 
679
-  // 
641
+  // set the atick value in each msg
680 642
   _cmMidiFileSetAccumulateTicks(mfp);
681 643
     
682 644
   // sort msgV[] in ascending order on atick
683 645
   qsort( mfp->msgV, mfp->msgN, sizeof(cmMidiTrackMsg_t*), _cmMidiFileSortFunc );
684 646
 
647
+  // set the amicro value in each msg
685 648
   _cmMidiFileSetAbsoluteTime(mfp);
686 649
   
687
-  /*
688
-  // set the amicro field of each midi message to the
689
-  // absolute time offset in microseconds
690
-  unsigned mi;
691
-  double amicro = 0;
692
-  microsPerTick = microsPerQN / mfp->ticksPerQN;
693
-
694
-  for(mi=0; mi<mfp->msgN; ++mi)
695
-  {
696
-    cmMidiTrackMsg_t* mp = mfp->msgV[mi];
697
-
698
-    // track tempo changes
699
-    if( mp->status == kMetaStId && mp->metaId == kTempoMdId )
700
-      microsPerTick = mp->u.iVal / mfp->ticksPerQN;
701
-
702
-    unsigned dtick = 0;
703
-    if( mi > 0 )
704
-    {
705
-      assert( mp->atick >= mfp->msgV[mi-1]->atick );
706
-      dtick = mp->atick -  mfp->msgV[mi-1]->atick;
707
-    }
708
-    
709
-    amicro     += microsPerTick * dtick;
710
-    mp->amicro  = round(amicro);
711
-  }
712
-  */
713
-  
714
-  //for(i=0; i<25; ++i)
715
-  //  printf("%i 0x%x 0x%x\n",mfp->msgV[i]->tick,mfp->msgV[i]->status,mfp->msgV[i]->metaId);
716
-
717
-  mfp->fn = _cmMidiFileMalloc(mfp,strlen(fn)+1);
718
-  assert( mfp->fn != NULL );
719
-  strcpy(mfp->fn,fn);
720
-
721
-
722 650
   hPtr->h = mfp;
723 651
 
724 652
  errLabel:
@@ -1199,7 +1127,7 @@ const cmMidiTrackMsg_t** cmMidiFileMsgArray(    cmMidiFileH_t h )
1199 1127
   return (const cmMidiTrackMsg_t**)mfp->msgV;
1200 1128
 }
1201 1129
 
1202
-unsigned  cmMidiFileSeekUsecs( cmMidiFileH_t h, unsigned offsUSecs, unsigned* msgUsecsPtr, unsigned* microsPerTickPtr )
1130
+unsigned  cmMidiFileSeekUsecs( cmMidiFileH_t h, unsigned long long offsUSecs, unsigned* msgUsecsPtr, unsigned* microsPerTickPtr )
1203 1131
 {
1204 1132
   _cmMidiFile_t* p;
1205 1133
 
@@ -1217,22 +1145,6 @@ unsigned  cmMidiFileSeekUsecs( cmMidiFileH_t h, unsigned offsUSecs, unsigned* ms
1217 1145
   for(mi=0; mi<p->msgN; ++mi)
1218 1146
   {
1219 1147
     const cmMidiTrackMsg_t* mp = p->msgV[mi];
1220
-    /*
1221
-    if( mp->status == kMetaStId && mp->metaId == kTempoMdId )
1222
-      microsPerTick = mp->u.iVal / p->ticksPerQN;
1223
-
1224
-    unsigned dtick = 0;
1225
-    if( mi > 0 )
1226
-    {
1227
-      assert( mp->atick >= p->msgV[mi-1]->atick )
1228
-      dtick = mp->atick - p->msgV[mi-1]->atick;
1229
-    }
1230
-    
1231
-    accUSecs += dtick * microsPerTick ;
1232
-
1233
-    if( accUSecs >= offsUSecs )
1234
-      break;
1235
-    */
1236 1148
 
1237 1149
     if( mp->amicro >= offsUSecs )
1238 1150
       break;

+ 3
- 3
cmMidiFile.h Прегледај датотеку

@@ -65,8 +65,8 @@ extern "C" {
65 65
   {
66 66
     unsigned                   uid;     // uid's are unique among all msg's in the file
67 67
     unsigned                   dtick;   // delta ticks between events on this track
68
-    unsigned                   atick;   // global (all tracks interleaved) accumulated ticks
69
-    unsigned                   amicro;  // global (all tracks interleaved) accumulated microseconds adjusted for tempo changes
68
+    unsigned long long         atick;   // global (all tracks interleaved) accumulated ticks
69
+    unsigned long long         amicro;  // global (all tracks interleaved) accumulated microseconds adjusted for tempo changes
70 70
     cmMidiByte_t               status;  // ch msg's have the channel value removed (it is stored in u.chMsgPtr->ch)
71 71
     cmMidiByte_t               metaId;  //
72 72
     unsigned short             trkIdx;  //  
@@ -151,7 +151,7 @@ extern "C" {
151 151
   // of the file.
152 152
   // On return *'msgUsecsPtr' is set to the actual time of the msg. 
153 153
   // (which will be equal to or greater than 'usecsOffs').
154
-  unsigned              cmMidiFileSeekUsecs( cmMidiFileH_t h, unsigned usecsOffs, unsigned* msgUsecsPtr, unsigned* newMicrosPerTickPtr );
154
+  unsigned              cmMidiFileSeekUsecs( cmMidiFileH_t h, unsigned long long usecsOffs, unsigned* msgUsecsPtr, unsigned* newMicrosPerTickPtr );
155 155
 
156 156
   double                cmMidiFileDurSecs( cmMidiFileH_t h );
157 157
 

+ 1
- 1
cmMidiFilePlay.c Прегледај датотеку

@@ -218,7 +218,7 @@ cmMfpRC_t cmMfpClock(  cmMfpH_t h, unsigned dusecs )
218 218
     // send the current message
219 219
     p->cbFunc( p->userCbPtr, p->mtime, mp );
220 220
 
221
-    unsigned amicro = mp->amicro;
221
+    unsigned long long amicro = mp->amicro;
222 222
     
223 223
     ++(p->msgIdx);
224 224
 

Loading…
Откажи
Сачувај