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

cmTimeLine.c : Updates to use amicro instead of dticks in MIDI msgs.

master
kevin пре 9 година
родитељ
комит
a142123bd8
1 измењених фајлова са 17 додато и 20 уклоњено
  1. 17
    20
      app/cmTimeLine.c

+ 17
- 20
app/cmTimeLine.c Прегледај датотеку

@@ -530,16 +530,14 @@ cmTlRC_t _cmTlAllocRecd2(
530 530
   tp->flags      = 0;
531 531
   tp->text       = NULL;
532 532
 
533
+  //printf("%9i %9i %9i %9i\n",tp->begSmpIdx,tp->durSmpCnt,refPtr==NULL?0:refPtr->obj->seqSmpIdx, tp->seqSmpIdx);
534
+  
533 535
   op->obj        = tp;
534 536
   op->mem        = mem;
535 537
   op->memByteCnt = byteCnt;
536 538
   op->next       = NULL;
537 539
   op->prev       = NULL;
538 540
 
539
-
540
-  //if( seqId == 4 )
541
-  //  printf("seq:%i id:%i type:%i accum:%i ref:%i offs:%i %f\n",seqId, tp->uid, tp->typeId, tp->seqSmpIdx, refPtr==NULL?-1:refPtr->obj->uid, begSmpIdx, begSmpIdx/(96000.0*60.0) );
542
-
543 541
   _cmTlInsertAfter(p, _cmTlFindRecdBefore(p,op), op );
544 542
 
545 543
 
@@ -651,36 +649,36 @@ cmTlRC_t _cmTlProcMidiFile( _cmTl_t* p,  _cmTlObj_t* op, cmMidiFileH_t mfH )
651 649
   const cmMidiTrackMsg_t** mapp         = cmMidiFileMsgArray(mfH);
652 650
   unsigned                 mi           = 0;
653 651
   _cmTlObj_t*              refOp        = op;
652
+  double                   smpPerMicro  = p->srate / 1000000.0;
653
+  unsigned                 begSmpIdx0   = 0;
654 654
   mfp->noteOnCnt = 0;
655 655
   
656 656
   // for each midi message
657 657
   for(; mi<mn; ++mi)
658 658
   {
659
-    _cmTlObj_t*             meop = NULL;
660
-    const cmMidiTrackMsg_t* mp   = mapp[mi];
661
-
662
-    int      begSmpIdx         = mp->dtick;
663
-    int      durSmpCnt         = 0;
664
-    unsigned midiTrkMsgByteCnt = cmMidiFilePackTrackMsgBufByteCount( mp );
665
-    unsigned recdByteCnt       = sizeof(cmTlMidiEvt_t) + midiTrkMsgByteCnt;
666
-
667
-    //if( mfp->obj.seqId==4 && mi<=25 )
668
-    //  printf("%s: bsi:%9i acc:%f smp acc:%f min %s\n", mp->status == kNoteOnMdId?"non":"   ", begSmpIdx, accum, accum / (p->srate * 60),cmStringNullGuard(mfp->obj.name));
659
+    _cmTlObj_t*             meop              = NULL;
660
+    const cmMidiTrackMsg_t* mp                = mapp[mi];
661
+    int                     begSmpIdx         = mp->amicro * smpPerMicro;
662
+    int                     durSmpCnt         = 0;
663
+    unsigned                midiTrkMsgByteCnt = cmMidiFilePackTrackMsgBufByteCount( mp );
664
+    unsigned                recdByteCnt       = sizeof(cmTlMidiEvt_t) + midiTrkMsgByteCnt;
669 665
 
670 666
     // count the note-on messages
671 667
     if( cmMidiIsNoteOn(mp->status) )
672 668
     {
673
-      durSmpCnt = mp->u.chMsgPtr->durTicks;
669
+      durSmpCnt = mp->u.chMsgPtr->durMicros * smpPerMicro;
674 670
       ++mfp->noteOnCnt;
675 671
     }
676 672
 
677 673
     if( cmMidiIsCtl(mp->status) && cmMidiIsSustainPedal(mp->status,mp->u.chMsgPtr->d0) )
678
-      durSmpCnt = mp->u.chMsgPtr->durTicks;
674
+      durSmpCnt = mp->u.chMsgPtr->durMicros * smpPerMicro;
679 675
 
680 676
     // allocate the generic time-line object record
681
-    if((rc = _cmTlAllocRecd2(p, NULL, refOp, begSmpIdx, durSmpCnt, kMidiEvtTlId, mfp->obj.seqId, recdByteCnt, &meop)) != kOkTlRC )
677
+    if((rc = _cmTlAllocRecd2(p, NULL, refOp, begSmpIdx-begSmpIdx0, durSmpCnt, kMidiEvtTlId, mfp->obj.seqId, recdByteCnt, &meop)) != kOkTlRC )
682 678
       goto errLabel;
683 679
 
680
+    begSmpIdx0 = begSmpIdx;
681
+    
684 682
     assert( meop != NULL );
685 683
     
686 684
     cmTlMidiEvt_t* mep = _cmTimeLineMidiEvtObjPtr(p,meop->obj);
@@ -731,7 +729,7 @@ cmTlRC_t _cmTlAllocMidiFileRecd( _cmTl_t* p, const cmChar_t* nameStr, const cmCh
731 729
   unsigned durSmpCnt = floor(cmMidiFileDurSecs(mfH)*p->srate);
732 730
 
733 731
   // convert the midi file from delta ticks to delta samples
734
-  cmMidiFileTickToSamples(mfH,p->srate,false);
732
+  //cmMidiFileTickToSamples(mfH,p->srate,false);
735 733
 
736 734
   // assign note durations to all note-on msg's
737 735
   cmMidiFileCalcNoteDurations(mfH);
@@ -757,6 +755,7 @@ cmTlRC_t _cmTlAllocMidiFileRecd( _cmTl_t* p, const cmChar_t* nameStr, const cmCh
757 755
 
758 756
   op->obj->text = mp->fn;
759 757
 
758
+
760 759
   // insert the events in the midi file as individual time line objects
761 760
   if((rc = _cmTlProcMidiFile(p, op, mfH)) != kOkTlRC )
762 761
     goto errLabel;
@@ -778,8 +777,6 @@ cmTlRC_t _cmTlAllocMidiFileRecd( _cmTl_t* p, const cmChar_t* nameStr, const cmCh
778 777
 
779 778
 cmTlRC_t _cmTlAllocMarkerRecd( _cmTl_t* p, const cmChar_t* nameStr, const cmChar_t* refIdStr, int begSmpIdx, unsigned durSmpCnt, unsigned seqId, const cmChar_t* text, unsigned bar, const cmChar_t* sectionStr, unsigned markerTypeId, cmTlObj_t* refObjPtr )
780 779
 {
781
-  assert( refObjPtr != NULL );
782
-  
783 780
   cmTlRC_t        rc      = kOkTlRC;
784 781
   _cmTlObj_t*     op      = NULL;
785 782
   const cmChar_t* textStr = text==NULL       ? "" : text;

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