Guidance
指路人
g.yi.org
software / rapidq / Examples / Audio & Video / midi / midifile2.bas

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
     $INCLUDE "rapidq.inc"

     DIM file AS QFILESTREAM
     bpmnum01=0
     bpmnum02=0
     bpmnum03=0
     DECLARE SUB makefile
     DECLARE SUB bpmfix
     DECLARE SUB closeprog
     file.OPEN ("midi01_file.mid", fmcreate)

     CREATE form AS QFORM
      height=180
      width=450
      center
      borderstyle=bsdialog

      CREATE songname AS QEDIT
       top=10
       left=10
       width=100
       height=26
      END CREATE
      CREATE bpm AS QEDIT
       top=50
       left=10
       width=50
       height=26
      END CREATE

      CREATE playbutton AS QBUTTON
       CAPTION="make"
       top=50
       left=150
       height=22
       onclick=makefile
      END CREATE
      CREATE closebutton AS QBUTTON
       CAPTION="close"
       top=10
       left=150
       height=22
       onclick=closeprog
      END CREATE
      SHOWMODAL
     END CREATE

     SUB makefile
      file.writestr("MThd",4) ' indicates midi file header chunk
      file.writenum(0,1)
      file.writenum(0,1)
      file.writenum(0,1)
      file.writenum(6,1) ' header length, 4 bytes
      file.writenum(0,1)
      file.writenum(1,1) ' midi format, 2 bytes
      file.writenum(0,1)
      file.writenum(2,1) ' number of tracks, 2 bytes
      file.writenum(0,1)
      file.writenum(96,1) ' ticks per beat, 2 bytes


' --------------------- tempo info et c. track
      file.writestr("MTrk",4) ' indicates midi track header chunk
      file.writenum(0,1)
      file.writenum(0,1)
      file.writenum(0,1)
      file.writenum(19,1) ' length of track data, 4 bytes

      bpmfix

      file.writenum(0,1)
      file.writenum(255,1) ' ff 51 03 = indicates tempo meta event
      file.writenum(81,1)
      file.writenum(3,1)
      file.writenum(bpmnum01,1) ' tempo 500,000 microseconds **per quarter note** (ie. 120bpm=7,161,32)
      file.writenum(bpmnum02,1) ' dec to hex 7=07 161=a1 32=20
      file.writenum(bpmnum03,1) ' hex 07 a1 20 = 500,000


      file.writenum(0,1)
      file.writenum(255,1) ' ff 58 04 time signature statement
      file.writenum(88,1)
      file.writenum(4,1)

      file.writenum(4,1) ' divisions per, ie. first # of time signature
      file.writenum(2,1) ' per neg. power of 2, ie. 2=2, 3=8
      file.writenum(24,1) ' midi clocks per metronome click
      file.writenum(8,1) ' # of 32nd notes per beat

      file.writenum(0,1)
      file.writenum(255,1) ' initiate end of track
      file.writenum(47,1) ' end of track part 2
      file.writenum(0,1) ' end of track part 3




' --------------------- note track
      file.writestr("MTrk",4) ' indicates midi track header chunk
      file.writenum(0,1)
      file.writenum(0,1)
      file.writenum(0,1)
      file.writenum(68,1) ' length of track data, 4 bytes


      file.writenum(0,1) ' ticks until event, 1-4 bytes
      file.writenum(145,1) ' hex90 "status," type of event ie. note on, chan.1
      file.writenum(63,1) ' note #
      file.writenum(100,1) ' velocity


      file.writenum(48,1) ' ticks until event, 1-4 bytes
      file.writenum(129,1) ' hex80 note off, chan.1
      file.writenum(63,1) ' note #
      file.writenum(100,1) ' note off vel.

' notes 2-8
      FOR t=1 TO 7
       file.writenum(0,1) ' ticks until event, 1-4 bytes
       file.writenum(145,1) ' hex90 "status," type of event ie. note on, chan.1
       file.writenum(63,1) ' note #
       file.writenum(100,1) ' velocity
       file.writenum(48,1) ' ticks until event, 1-4 bytes
       file.writenum(129,1) ' hex80 note off, chan.1
       file.writenum(63,1) ' note #
       file.writenum(100,1) ' note off vel.
      NEXT t





      file.writenum(0,1)
      file.writenum(255,1) ' initiate end of track
      file.writenum(47,1) ' end of track part 2
      file.writenum(0,1) ' end of track part 3


      file.CLOSE
      RENAME (DIR$("midi01_file.mid",faanyfile),songname.text+".mid")
     END SUB

     SUB bpmfix
      bpmnum=INT(VAL(bpm.text))
      IF bpmnum<1 THEN bpmnum=1
      IF bpmnum>2048 THEN bpmnum=2048
      bpmnum=INT((60/bpmnum)*1000000)
      bpmhex$=HEX$(bpmnum)
      bpmhex01$=RIGHT$(LEFT$(bpmhex$,4),2)
      bpmhex02$=RIGHT$(LEFT$(bpmhex$,6),2)
      bpmhex03$=RIGHT$(bpmhex$,2)
      bpmnum01=VAL(CONVBASE$(bpmhex01$,16,10))
      bpmnum02=VAL(CONVBASE$(bpmhex02$,16,10))
      bpmnum03=VAL(CONVBASE$(bpmhex03$,16,10))
     END SUB

     SUB closeprog
      form.CLOSE
      END
     END SUB

掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Wed 2023-2-1  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2003-04-26 19:02:07