Guidance
指路人
g.yi.org
software / rapidq / Examples / Audio & Video / drum one / drum_one_01.bas

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

  
     $INCLUDE "rapidq.inc"

     DEFINT mx, my
     beat=0
     beatcount=0
     bpm=120
     stopgo=-1

     DECLARE SUB showxy
     DECLARE SUB dxtimerexpired
     DECLARE SUB canvaspaint (sender AS QCANVAS)
     DECLARE SUB canvasclick
     DECLARE SUB timerover
     DECLARE SUB playkicksub
     DECLARE SUB playrimsub
     DECLARE SUB playclosedsub
     DECLARE SUB playopensub
     DECLARE SUB bpmchange
     DECLARE SUB startstop

     DIM bitmap AS QBITMAP
     bitmap.height=80
     bitmap.width=400
     bitmap.paint(0,0,0,0)

     DIM kick_tick(8)
     FOR t=0 TO 7
      kick_tick(t)=-1
     NEXT
     DIM rim_tick(8)
     FOR t=0 TO 7
      rim_tick(t)=-1
     NEXT
     DIM closed_tick(8)
     FOR t=0 TO 7
      closed_tick(t)=-1
     NEXT
     DIM open_tick(8)
     FOR t=0 TO 7
      open_tick(t)=-1
     NEXT



     CREATE form AS QFORM
      clientheight=100
      clientwidth=390
      center
      borderstyle = bsdialog
      CAPTION = "Drum One - click on me"
      CREATE bpmlabel AS QLABEL
       left=10
       top=82
       CAPTION="bpm:"
      END CREATE
      CREATE bpmnumlabel AS QLABEL
       left=70
       top=82
       CAPTION="50"
      END CREATE
      CREATE temposcroll AS QSCROLLBAR
       left=120
       top=82
       width=200
       height=18
       min=50:max=250
       showhint=false
       onchange=bpmchange
      END CREATE
      CREATE button AS QBUTTON
       left=350
       top=84
       width=30
       height=14
       CAPTION="o/-"
       onclick=startstop
      END CREATE

      CREATE canvas AS QCANVAS
       clientwidth=400
       clientheight=80
       onclick=canvasclick
       onpaint=canvaspaint
      END CREATE
      CREATE playkick AS qdxsound
       filename="kick.wav"
      END CREATE
      CREATE playrim AS qdxsound
       filename="rim.wav"
      END CREATE
      CREATE playclosed AS qdxsound
       filename="closed.wav"
      END CREATE
      CREATE playopen AS qdxsound
       filename="open.wav"
      END CREATE
     END CREATE

     CREATE globaltimer AS QTIMER
      enabled = true
      interval = INT((60/bpm)*500)
      ontimer = timerover
     END CREATE



     SUB timerover
      IF kick_tick(beatcount)>0 THEN playkicksub
      IF rim_tick(beatcount)>0 THEN playrimsub
      IF closed_tick(beatcount)>0 THEN playclosedsub
      IF open_tick(beatcount)>0 THEN playopensub
      beatcount=beatcount+1
      IF beatcount=8 THEN beatcount=0
     END SUB

     SUB canvaspaint (sender AS QCANVAS)
      FOR t=0 TO 7
       IF kick_tick(t)>0 THEN bitmap.fillrect(0,0,49,80,&H00ff00)
      NEXT
      sender.draw(0,0,bitmap.bmp)
     END SUB

     SUB canvasclick
      showxy
      beat=(INT(mx/50))
      IF my<21 THEN
       kick_tick(beat)=kick_tick(beat)*-1
      ELSEIF my>20 AND my<41 THEN
       rim_tick(beat)=rim_tick(beat)*-1
      ELSEIF my>40 AND my<61 THEN
       closed_tick(beat)=closed_tick(beat)*-1
      ELSE
       open_tick(beat)=open_tick(beat)*-1
      END IF
      FOR t=0 TO 7
       IF my>40 AND my<61 AND closed_tick(t)>0 THEN open_tick(t)=-1
       IF my>60 AND open_tick(t)>0 THEN closed_tick(t)=-1
       IF kick_tick(t)>0 THEN
        bitmap.fillrect((t*50),0,(t*50)+49,19,&H0000ff)
       ELSE
        bitmap.fillrect((t*50),0,(t*50)+49,19,&H000000)
       END IF
       IF rim_tick(t)>0 THEN
        bitmap.fillrect((t*50),20,(t*50)+49,39,&Hff0000)
       ELSE
        bitmap.fillrect((t*50),20,(t*50)+49,39,&H000000)
       END IF
       IF closed_tick(t)>0 THEN
        bitmap.fillrect((t*50),40,(t*50)+49,59,&H00ff00)
       ELSE
        bitmap.fillrect((t*50),40,(t*50)+49,59,&H000000)
       END IF
       IF open_tick(t)>0 THEN
        bitmap.fillrect((t*50),60,(t*50)+49,80,&H00ffff)
       ELSE
        bitmap.fillrect((t*50),60,(t*50)+49,80,&H000000)
       END IF
      NEXT
      canvas.draw(0,0,bitmap.bmp)
     END SUB


     SUB playkicksub
      playkick.position=0
      playkick.play
     END SUB

     SUB playrimsub
      playrim.position=0
      playrim.play
     END SUB

     SUB playclosedsub
      playclosed.position=0
      playclosed.play
     END SUB

     SUB playopensub
      playopen.position=0
      playopen.play
     END SUB

     SUB bpmchange
      bpmnumlabel.CAPTION=STR$(temposcroll.position)
      bpm=temposcroll.position
      globaltimer.interval=INT((60/bpm)*500)
     END SUB

     SUB showxy
      mx=screen.MOUSEX-form.left-((form.width-form.clientwidth)/2)
      my=screen.MOUSEY-form.top-((form.height-form.clientheight))
     END SUB

     SUB startstop
      beatcount=0
      stopgo=stopgo*-1
      IF stopgo=1 THEN
       globaltimer.enabled=0
      ELSE
       globaltimer.enabled=1
      END IF
     END SUB

     form.SHOWMODAL
掌柜推荐
 
 
¥289.00 ·
 
 
¥1,080.00 ·
 
 
¥1,380.00 ·
 
 
¥638.00 ·
 
 
¥1,290.00 ·
 
 
¥1,420.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2003-03-30 19:42:04