Author Topic: Drum Machine Prototype by Dav  (Read 7900 times)

0 Members and 1 Guest are viewing this topic.

Offline Junior Librarian

  • Moderator
  • Newbie
  • Posts: 19
    • View Profile
Drum Machine Prototype by Dav
« on: September 23, 2021, 05:41:59 am »
Drum Machine Prototype

Author: @Dav
Source: qb64.org Forum
URL: https://www.qb64.org/forum/index.php?topic=2459.msg117923#msg117923
Version: v0.1c

Description:
Here's a drum machine, or beat maker.  I started making another puzzle game, but it turned into a little music making program instead.   With this you can make drum beats using 14 drum instrument samples.

Controls:
L Load Pattern
S Save Pattern
M Toggle Metronome

Source Code:
The code is given here for reference.  You will need to load all the files from the .zip.
Code: QB64: [Select]
  1.     '=======================
  2.     'DRUMMACHINE.BAS - v0.1c
  3.     '=======================
  4.     'QB64 Drum machine
  5.     'Make drum beats using 16 drum sounds.
  6.     'Coded by Dav for QB64, MAY/2020
  7.      
  8.     'Follow this programs development here:
  9.     'https://www.qb64.org/forum/index.php?topic=2459.0
  10.      
  11.     '===================================================================
  12.     'New in v0.1c...
  13.      
  14.     'Added: Added program _TITLE and _ICON.
  15.     'Added: New logo with keyboard command help.
  16.     'Added: Shows big TEMPO (BMP) font at top left.
  17.     'Added: Shows green playing position line down grid.
  18.     '       (replaced little white moving marker)
  19.     'Added: Give user notices when a Save/Load is done.
  20.     'Added: Instrument names can now be clicked on to mute/unmute.
  21.     'Added: Now shows on screen if metronome is ON/OFF
  22.     'Fixed: Changed keyboard input method. Much more responsive.
  23.     '
  24.     '===================================================================
  25.     ''NOTE: You need "\drummachine-data\" and all of its data files!
  26.     '===================================================================
  27.      
  28.     '=====
  29.     'ABOUT:
  30.     '=====
  31.      
  32.     'This is a very basic drum machine with limited capabilities.
  33.     'With it you can program beats (limited to 2 bars of 4/4 now).
  34.     'It uses 16 real drum sounds to make a real sound drum beat.
  35.     'Drum patterns can be saved and loaded by file DRUMMACHINE.SAV.
  36.     'I just wanted to see if QB64 can handle something like this,
  37.     'and it looks like it can.  So a more serious program can be tackled.
  38.     'The real drum sound samples were all found in public domain.
  39.      
  40.     '==========
  41.     'HOW TO USE:
  42.     '==========
  43.      
  44.     'The grid represents bars and notes that you can click on.
  45.     'Click on squares in a row to to add sound for that beat.
  46.     'Click an square again to turn it back off or change it's volume.
  47.     'A bright red square is loudest, a darker red is softer volume.
  48.      
  49.     'Click on the instrument name on left screen to mute/unmute it.
  50.      
  51.     'The following keys can be used as well:
  52.      
  53.     '* +/- keys:  Speeds up and slow down tempo (shown upper left)
  54.     '* SPACE key: Will pause and resume the playback.
  55.     '* ENTER:     Resets current playback marker to the beginning.
  56.     '* M:         Turns on/off metonome click sound (default is on)
  57.     '* C:         Clears the playing grid (starts over).
  58.     '* L:         Loads last saved grid pattern from DRUMMACHINE.SAV
  59.     '* S:         Saves current grid pattern to DRUMMACHINE.SAV.
  60.     '* D:         Enters drawing mode (fast filling of boxes.
  61.     '             (While in it, enter ESC to exit drawing mode)
  62.     '* ESC:       Exits program. DOES NOT ATUMATICALLY SAVE ON EXIT.
  63.      
  64.     '======================================================================
  65.      
  66.     $EXEICON:'.\drummachine-data\icon.ico'
  67.     _ICON
  68.      
  69.     'define playing grid and button deminsions
  70.     DIM SHARED row: row = 16 'rows in playing grid
  71.     DIM SHARED col: col = 8 * 4 'columns in grid (8 beats, 4 boxes per beat)
  72.     DIM SHARED size: size = 30 ' pixel size of buttons
  73.     DIM SHARED buttons: buttons = row * col ' total number of buttons on playing grid
  74.      
  75.     'define button data
  76.     DIM SHARED buttonv(row * col) ' num data for button
  77.     DIM SHARED buttonx(row * col), buttony(row * col) 'top x/y cords of buttons
  78.     DIM SHARED buttonx2(row * col), buttony2(row * col) ' bottom x/y cords of buttons
  79.      
  80.     'define intrument name data
  81.     DIM SHARED instv(row * col) 'value for is intrument on or off
  82.     DIM SHARED instx(row * col), insty(row * col) 'top x/y cords of instr names
  83.      
  84.     'share these sound files
  85.     DIM SHARED crash&, crash2&, ride&, ride2&, hhopen&, hhclosed&, snare&, kick&, tamb&, gong2&
  86.     DIM SHARED tomhigh&, tommid&, tomlow&, cowbell&, shaker&, gong&, vibraslap&, vibraslap2&
  87.     DIM SHARED clave&, trianglelong&, triangleshort&
  88.      
  89.     '====================================================
  90.      
  91.     'Set screen based on grid deminsions
  92.      
  93.     SCREEN _NEWIMAGE(size * col + 100, size * row + 100, 32)
  94.     DO: LOOP UNTIL _SCREENEXISTS 'Make sure window exists before TITLE used.
  95.      
  96.     _TITLE "QB64 Drum Machine"
  97.      
  98.     '===================================================
  99.      
  100.     CLS , _RGB(42, 42, 42)
  101.      
  102.     'Load title top area.
  103.     ttmp = _LOADIMAGE("drummachine-data\title.png")
  104.     _PUTIMAGE (5, 5), ttmp: _FREEIMAGE ttmp
  105.      
  106.     'Load media sounds used
  107.     click& = _SNDOPEN("drummachine-data\click.ogg")
  108.     hhopen& = _SNDOPEN("drummachine-data\hhopen.ogg")
  109.     hhclosed& = _SNDOPEN("drummachine-data\hhclosed.ogg")
  110.     kick& = _SNDOPEN("drummachine-data\kick.ogg")
  111.     snare& = _SNDOPEN("drummachine-data\snare.ogg")
  112.     crash& = _SNDOPEN("drummachine-data\crash.ogg")
  113.     crash2& = _SNDOPEN("drummachine-data\crash.ogg")
  114.     ride& = _SNDOPEN("drummachine-data\ride.ogg")
  115.     ride2& = _SNDOPEN("drummachine-data\ride.ogg")
  116.     tomhigh& = _SNDOPEN("drummachine-data\tomhigh.ogg")
  117.     tommid& = _SNDOPEN("drummachine-data\tommid.ogg")
  118.     tomlow& = _SNDOPEN("drummachine-data\tomlow.ogg")
  119.     cowbell& = _SNDOPEN("drummachine-data\cowbell.ogg")
  120.     shaker& = _SNDOPEN("drummachine-data\shaker.ogg")
  121.     vibraslap& = _SNDOPEN("drummachine-data\vibraslap.ogg")
  122.     gong& = _SNDOPEN("drummachine-data\gong.ogg")
  123.     vibraslap2& = _SNDOPEN("drummachine-data\vibraslap.ogg")
  124.     gong2& = _SNDOPEN("drummachine-data\gong.ogg")
  125.     tamb& = _SNDOPEN("drummachine-data\tamb.ogg")
  126.     clave& = _SNDOPEN("drummachine-data\clave.ogg")
  127.     trianglelong& = _SNDOPEN("drummachine-data\trianglelong.ogg")
  128.     triangleshort& = _SNDOPEN("drummachine-data\triangleshort.ogg")
  129.      
  130.     'Load special number font images fro BMP display
  131.     DIM SHARED num&(0 TO 9)
  132.     FOR t = 0 TO 9
  133.         n$ = LTRIM$(RTRIM$(STR$(t)))
  134.         num&(t) = _LOADIMAGE("drummachine-data\font\" + n$ + ".png")
  135.     NEXT
  136.      
  137.      
  138.     '===================================================
  139.      
  140.     'Set program defaults
  141.      
  142.     beats = 8 'number of beats in pattern
  143.     tempo = 80 'tempo of drum pattern
  144.     curbeat = 1 'start at bar 1
  145.     clickon = 1 'turn on click sound, on the beat
  146.     playing = 1 'Pattern is playing
  147.     firstlaunch = 1 'flag to know when program first launches
  148.      
  149.      
  150.     '=========================================================
  151.     START:
  152.     '========
  153.      
  154.     'Init the grids button values (x/y, data)
  155.     bc = 1 'counter
  156.     FOR r = 1 TO row
  157.         FOR c = 1 TO col
  158.             x = (c * size) + 100: y = (r * size) + 100
  159.             buttonx(bc) = x - size: buttonx2(bc) = x ' generate x/y values
  160.             buttony(bc) = y - size: buttony2(bc) = y
  161.             buttonv(bc) = 0 'default button is OFF
  162.             bc = bc + 1
  163.         NEXT
  164.     NEXT
  165.      
  166.     'Show metronome on/off
  167.     Metronome clickon
  168.      
  169.     'Show the grid buttons
  170.     bc = 1
  171.     FOR r = 1 TO row
  172.         FOR c = 1 TO col
  173.             Show "drummachine-data\off.jpg", buttonx(bc), buttony(bc), 0
  174.             bc = bc + 1
  175.         NEXT
  176.     NEXT
  177.      
  178.      
  179.     'Draw beat lines, every 4 squares ...
  180.     bc = 1
  181.     FOR c = 1 TO col STEP 4
  182.         LINE (buttonx(bc), buttony(bc))-(buttonx(bc), buttony(bc) + (size * row)), _RGB(128, 128, 0), B
  183.         bc = bc + 4
  184.     NEXT
  185.      
  186.     '====================================
  187.      
  188.     'Init Instrument name data
  189.     FOR c = 1 TO 16
  190.         instv(c) = 1 'all instruments on by default
  191.     NEXT
  192.     bc = 1
  193.     FOR c = 1 TO col * row STEP col
  194.         instx(bc) = 0: insty(bc) = 70 + (bc * 30)
  195.         bc = bc + 1
  196.     NEXT
  197.     'show the nstrument names
  198.     FOR c = 1 TO 16
  199.         ShowInst c, instx(c), insty(c)
  200.     NEXT
  201.      
  202.     '==============================================
  203.      
  204.     'Show current TEMPO (BMP) on upper left
  205.     FPRINT 140, 15, 20, 40, LTRIM$(RTRIM$(STR$(tempo)))
  206.      
  207.     '================================================
  208.      
  209.     'If firstlaunch, load the saved pattern file
  210.     IF firstlaunch = 1 THEN
  211.         firstlaunch = 0
  212.         GOSUB loadfile
  213.     END IF
  214.      
  215.     '============================================================
  216.      
  217.     MAIN:
  218.     '=====
  219.      
  220.     'Main Loop here
  221.     DO
  222.      
  223.         GOSUB GetUserInput
  224.      
  225.         IF playing THEN
  226.      
  227.             IF clickon THEN
  228.                 SELECT CASE curbeat
  229.                     CASE 1, 2, 3, 4, 5, 6, 7, 8: _SNDPLAY click&
  230.                 END SELECT
  231.             END IF
  232.      
  233.             IF curbeat = 1 THEN PlayBeat (1)
  234.             IF curbeat = 1.25 THEN PlayBeat (2)
  235.             IF curbeat = 1.50 THEN PlayBeat (3)
  236.             IF curbeat = 1.75 THEN PlayBeat (4)
  237.             IF curbeat = 2 THEN PlayBeat (5)
  238.             IF curbeat = 2.25 THEN PlayBeat (6)
  239.             IF curbeat = 2.50 THEN PlayBeat (7)
  240.             IF curbeat = 2.75 THEN PlayBeat (8)
  241.             IF curbeat = 3 THEN PlayBeat (9)
  242.             IF curbeat = 3.25 THEN PlayBeat (10)
  243.             IF curbeat = 3.50 THEN PlayBeat (11)
  244.             IF curbeat = 3.75 THEN PlayBeat (12)
  245.             IF curbeat = 4 THEN PlayBeat (13)
  246.             IF curbeat = 4.25 THEN PlayBeat (14)
  247.             IF curbeat = 4.50 THEN PlayBeat (15)
  248.             IF curbeat = 4.75 THEN PlayBeat (16)
  249.             IF curbeat = 5 THEN PlayBeat (17)
  250.             IF curbeat = 5.25 THEN PlayBeat (18)
  251.             IF curbeat = 5.50 THEN PlayBeat (19)
  252.             IF curbeat = 5.75 THEN PlayBeat (20)
  253.             IF curbeat = 6 THEN PlayBeat (21)
  254.             IF curbeat = 6.25 THEN PlayBeat (22)
  255.             IF curbeat = 6.50 THEN PlayBeat (23)
  256.             IF curbeat = 6.75 THEN PlayBeat (24)
  257.             IF curbeat = 7 THEN PlayBeat (25)
  258.             IF curbeat = 7.25 THEN PlayBeat (26)
  259.             IF curbeat = 7.50 THEN PlayBeat (27)
  260.             IF curbeat = 7.75 THEN PlayBeat (28)
  261.             IF curbeat = 8 THEN PlayBeat (29)
  262.             IF curbeat = 8.25 THEN PlayBeat (30)
  263.             IF curbeat = 8.50 THEN PlayBeat (31)
  264.             IF curbeat = 8.75 THEN PlayBeat (32)
  265.      
  266.             curbeat = curbeat + .25
  267.             IF curbeat > beats + .75 THEN curbeat = 1
  268.      
  269.             'Delay routine, based on TEMP
  270.             d1 = TIMER
  271.             DO
  272.                 d2 = TIMER
  273.      
  274.                 'still get user input while delaying....
  275.                 GOSUB GetUserInput
  276.      
  277.             LOOP UNTIL d2 - d1 >= (60 / 4 / tempo)
  278.      
  279.         END IF
  280.      
  281.     LOOP
  282.      
  283.     '===============================
  284.      
  285.     EndProgram:
  286.      
  287.     _SNDCLOSE click&
  288.     _SNDCLOSE hhopen&
  289.     _SNDCLOSE hhclosed&
  290.     _SNDCLOSE kick&
  291.     _SNDCLOSE snare&
  292.     _SNDCLOSE crash&
  293.     _SNDCLOSE crash2&
  294.     _SNDCLOSE ride&
  295.     _SNDCLOSE ride2&
  296.     _SNDCLOSE tomhigh&
  297.     _SNDCLOSE tommid&
  298.     _SNDCLOSE tomlow&
  299.     _SNDCLOSE cowbell&
  300.     _SNDCLOSE shaker&
  301.     _SNDCLOSE vibraslap&
  302.     _SNDCLOSE gong&
  303.     _SNDCLOSE vibraslap2&
  304.     _SNDCLOSE gong2&
  305.     _SNDCLOSE tamb&
  306.     _SNDCLOSE clave&
  307.     _SNDCLOSE trianglelong&
  308.     _SNDCLOSE triangleshort&
  309.      
  310.     END
  311.      
  312.      
  313.      
  314.     '================================================
  315.     GetUserInput:
  316.     '============
  317.      
  318.     trap = _MOUSEINPUT
  319.      
  320.     'if left mouse button clicked
  321.      
  322.         mx = _MOUSEX: my = _MOUSEY 'current mouse position
  323.      
  324.         'see if a grid button was pressed
  325.         FOR t = 1 TO buttons
  326.             bx = buttonx(t): bx2 = buttonx2(t)
  327.             by = buttony(t): by2 = buttony2(t)
  328.      
  329.             'If clicked on a grid button...
  330.             IF mx >= bx AND mx <= bx2 AND my >= by AND my <= by2 THEN
  331.                 IF _MOUSEBUTTON(1) THEN
  332.      
  333.                     'change its value...
  334.                     buttonv(t) = buttonv(t) + 1
  335.                     IF buttonv(t) > 2 THEN buttonv(t) = 0
  336.                     'LOCATE 1, 1: PRINT t   'for testing purposes...
  337.                     SELECT CASE buttonv(t)
  338.                         CASE 0: Show "drummachine-data\off.jpg", buttonx(t), buttony(t), 0
  339.                         CASE 1: Show "drummachine-data\hot.jpg", buttonx(t), buttony(t), 0
  340.                         CASE 2: Show "drummachine-data\med.jpg", buttonx(t), buttony(t), 0
  341.                     END SELECT
  342.                 ELSE
  343.                     buttonv(t) = 0
  344.                     Show "drummachine-data\off.jpg", buttonx(t), buttony(t), 0
  345.                 END IF
  346.      
  347.             END IF
  348.         NEXT
  349.      
  350.         'see if a instrument name was pressed
  351.         FOR t = 1 TO 16
  352.             bx = instx(t): bx2 = instx(t) + 100
  353.             by = insty(t): by2 = insty(t) + 30
  354.      
  355.             'If clicked on an instrument name...
  356.             IF mx >= bx AND mx <= bx2 AND my >= by AND my <= by2 THEN
  357.                 IF _MOUSEBUTTON(1) THEN
  358.      
  359.                     'change its value...
  360.                     instv(t) = instv(t) + 1
  361.                     IF instv(t) > 1 THEN instv(t) = 0
  362.                     'redraw instrument name here
  363.                     ShowInst t, instx(t), insty(t)
  364.                 END IF
  365.      
  366.             END IF
  367.         NEXT
  368.      
  369.      
  370.         IF _MOUSEBUTTON(1) THEN
  371.             'wait until mouse button up to continue
  372.             WHILE _MOUSEBUTTON(1) <> 0: n = _MOUSEINPUT: WEND
  373.         END IF
  374.      
  375.     END IF
  376.      
  377.      
  378.     'check is user made a keypress
  379.      
  380.      
  381.         CASE "D": 'd enters drawing mode
  382.             DO
  383.                 trap = _MOUSEINPUT
  384.                 IF _MOUSEBUTTON(1) OR _MOUSEBUTTON(2) THEN
  385.                     mx = _MOUSEX: my = _MOUSEY
  386.                     'see if a button was pressed
  387.                     FOR t = 1 TO buttons
  388.                         bx = buttonx(t): bx2 = buttonx2(t)
  389.                         by = buttony(t): by2 = buttony2(t)
  390.                         IF mx >= bx AND mx <= bx2 AND my >= by AND my <= by2 THEN
  391.                             IF _MOUSEBUTTON(1) THEN
  392.                                 buttonv(t) = 1
  393.                                 Show "drummachine-data\hot.jpg", buttonx(t), buttony(t), 0
  394.                             ELSE
  395.                                 buttonv(t) = 0
  396.                                 Show "drummachine-data\off.jpg", buttonx(t), buttony(t), 0
  397.                             END IF
  398.                         END IF
  399.                     NEXT
  400.                 END IF
  401.             LOOP UNTIL INKEY$ = CHR$(27)
  402.      
  403.         CASE "C": GOTO START 'C clears playing grid, starts over
  404.      
  405.         CASE "S": 's = saves current pattern to file
  406.             backtmp& = _COPYIMAGE(_DISPLAY)
  407.             f$ = "drummachine-data\savingpattern.png"
  408.             ttmp = _LOADIMAGE(f$)
  409.             _PUTIMAGE (350, 250), ttmp: _FREEIMAGE ttmp
  410.             _DELAY 1
  411.             OPEN "drummachine.sav" FOR OUTPUT AS #3
  412.             PRINT #3, MKI$(tempo);
  413.             PRINT #3, MKI$(buttons);
  414.             FOR fs = 1 TO buttons
  415.                 PRINT #3, MKI$(buttonv(fs));
  416.             NEXT
  417.             CLOSE #3
  418.             _PUTIMAGE (0, 0), backtmp&
  419.      
  420.         CASE "L"
  421.             backtmp& = _COPYIMAGE(_DISPLAY)
  422.             f$ = "drummachine-data\loadingpattern.png"
  423.             ttmp = _LOADIMAGE(f$)
  424.             _PUTIMAGE (350, 250), ttmp: _FREEIMAGE ttmp
  425.             _DELAY .5
  426.             _PUTIMAGE (0, 0), backtmp&
  427.             GOSUB loadfile
  428.      
  429.         CASE " " 'SPACE pauses and resumes playing
  430.             IF playing = 1 THEN
  431.                 playing = 0
  432.             ELSE
  433.                 playing = 1
  434.             END IF
  435.      
  436.         CASE CHR$(13) 'ENTER resets marker to beginning
  437.             'erase all marker positions
  438.             FOR e = 1 TO 32
  439.                 SELECT CASE e
  440.                     CASE 1, 5, 9, 13, 17, 21, 25, 29
  441.                         LINE (buttonx(e), buttony(e))-(buttonx(e), buttony(e) + (size * row)), _RGB(128, 128, 0), B
  442.                     CASE ELSE
  443.                         LINE (buttonx(e), buttony(e))-(buttonx(e), buttony(e) + (size * row)), _RGB(0, 0, 0), B
  444.                 END SELECT
  445.             NEXT
  446.             LINE (buttonx(1), buttony(1))-(buttonx(1), buttony(1) + (size * row)), _RGB(0, 255, 128), B
  447.             curbeat = 1: GOTO MAIN
  448.      
  449.         CASE "M" 'm = turn metronome click on/off
  450.             IF clickon = 1 THEN
  451.                 clickon = 0
  452.             ELSE
  453.                 clickon = 1
  454.             END IF
  455.             Metronome clickon
  456.      
  457.         CASE "+": tempo = tempo + 1: IF tempo > 280 THEN tempo = 280
  458.             FPRINT 140, 15, 20, 40, LTRIM$(RTRIM$(STR$(tempo)))
  459.      
  460.         CASE "-": tempo = tempo - 1: IF tempo < 40 THEN tempo = 40
  461.             FPRINT 140, 15, 20, 40, LTRIM$(RTRIM$(STR$(tempo)))
  462.         CASE CHR$(27): GOTO EndProgram
  463.      
  464.     END SELECT
  465.      
  466.     RETURN
  467.      
  468.      
  469.     '=================================================================
  470.      
  471.     loadfile: 'Loads pattern from save file
  472.     '=======
  473.      
  474.     fil$ = "drummachine.sav"
  475.     IF _FILEEXISTS(fil$) THEN
  476.         OPEN fil$ FOR BINARY AS #3
  477.         IF LOF(3) <= 1028 THEN
  478.             tempo = CVI(INPUT$(2, 3))
  479.             bb = CVI(INPUT$(2, 3))
  480.             FOR b = 1 TO bb
  481.                 buttonv(b) = CVI(INPUT$(2, 3))
  482.                 SELECT CASE buttonv(b)
  483.                     CASE 0: Show "drummachine-data\off.jpg", buttonx(b), buttony(b), 0
  484.                     CASE 1: Show "drummachine-data\hot.jpg", buttonx(b), buttony(b), 0
  485.                     CASE 2: Show "drummachine-data\med.jpg", buttonx(b), buttony(b), 0
  486.                 END SELECT
  487.             NEXT
  488.             CLOSE 3
  489.             'Show current TEMPO (BMP) on upper left
  490.             FPRINT 140, 15, 20, 40, LTRIM$(RTRIM$(STR$(tempo)))
  491.             GOTO MAIN
  492.         ELSE
  493.             CLOSE 3
  494.             'print error message here
  495.         END IF
  496.     END IF
  497.      
  498.     RETURN
  499.      
  500.     '========================================================
  501.      
  502.     SUB Show (nam$, x, y, dly)
  503.         'Loads & puts image filename img$ on screen at x,y
  504.         'dly is optional delay after putting image on screen
  505.         'SUB frees up image handle after loading file.
  506.         ttmp = _LOADIMAGE(nam$)
  507.         _PUTIMAGE (x + 1, y + 1)-(x - 1 + size - 1, y - 1 + size - 1), ttmp: _FREEIMAGE ttmp
  508.         IF dly <> 0 THEN _DELAY dly
  509.     END SUB
  510.      
  511.     '===============================================
  512.      
  513.     SUB ShowInst (num, x, y)
  514.         'This SUB loads the instrumet name image files
  515.         src$ = "drummachine-data\"
  516.         IF instv(num) = 1 THEN pre$ = "_" ELSE pre$ = ""
  517.         IF num = 1 THEN n$ = pre$ + "crash.png"
  518.         IF num = 2 THEN n$ = pre$ + "ride.png"
  519.         IF num = 3 THEN n$ = pre$ + "hhopen.png"
  520.         IF num = 4 THEN n$ = pre$ + "hhclosed.png"
  521.         IF num = 5 THEN n$ = pre$ + "tomhigh.png"
  522.         IF num = 6 THEN n$ = pre$ + "tommid.png"
  523.         IF num = 7 THEN n$ = pre$ + "tomlow.png"
  524.         IF num = 8 THEN n$ = pre$ + "snare.png"
  525.         IF num = 9 THEN n$ = pre$ + "kick.png"
  526.         IF num = 10 THEN n$ = pre$ + "cowbell.png"
  527.         IF num = 11 THEN n$ = pre$ + "shaker.png"
  528.         IF num = 12 THEN n$ = pre$ + "tambourine.png"
  529.         IF num = 13 THEN n$ = pre$ + "vibraslap.png"
  530.         IF num = 14 THEN n$ = pre$ + "gong.png"
  531.         IF num = 15 THEN n$ = pre$ + "triangle.png"
  532.         IF num = 16 THEN n$ = pre$ + "clave.png"
  533.      
  534.         fil$ = src$ + n$
  535.         ttmp = _LOADIMAGE(fil$)
  536.         _PUTIMAGE (x, y), ttmp: _FREEIMAGE ttmp
  537.     END SUB
  538.      
  539.     '===============================================
  540.      
  541.     SUB PlayBeat (num)
  542.         'This SUB plays the sounds on current beat position.
  543.         'It also shows the playing marker moving across the grid
  544.      
  545.         'erase previous marker pos displayed first, and redraw the 4 beat lines...
  546.         IF num = 1 THEN
  547.             'erase the end playing position on grid
  548.             LINE (buttonx(col), buttony(col))-(buttonx(col), buttony(col) + (size * row)), _RGB(0, 0, 0), B
  549.         ELSE
  550.             'erase the last beat position
  551.             LINE (buttonx(num - 1), buttony(num - 1))-(buttonx(num - 1), buttony(num - 1) + (size * row)), _RGB(0, 0, 0), B
  552.             'if last position was one of the 4 beat lines, redraw it
  553.             SELECT CASE (num - 1)
  554.                 CASE 1, 5, 9, 13, 17, 21, 25, 29
  555.                     LINE (buttonx(num - 1), buttony(num - 1))-(buttonx(num - 1), buttony(num - 1) + (size * row)), _RGB(128, 128, 0), B
  556.             END SELECT
  557.         END IF
  558.      
  559.         'Show curreny marker position
  560.         'Now Draw current playing position beat line
  561.         LINE (buttonx(num), buttony(num))-(buttonx(num), buttony(num) + (size * row)), _RGB(0, 255, 128), B
  562.      
  563.         'Play sounds on the current beat position, if inst not muted
  564.         'play crash
  565.         IF instv(1) = 1 THEN
  566.             IF buttonv(num) = 1 THEN _SNDVOL crash&, 6: _SNDPLAY crash& '1
  567.             IF buttonv(num) = 2 THEN _SNDVOL crash2&, .2: _SNDPLAY crash2& '1
  568.         END IF
  569.         'play ride
  570.         IF instv(2) = 1 THEN
  571.             IF buttonv(num + (col * 1)) = 1 THEN _SNDVOL ride&, 5: _SNDPLAY ride& '2
  572.             IF buttonv(num + (col * 1)) = 2 THEN _SNDVOL ride2&, .2: _SNDPLAY ride2& '2
  573.         END IF
  574.         'play hhopen
  575.         IF instv(3) = 1 THEN
  576.             IF buttonv(num + (col * 2)) = 1 THEN _SNDSETPOS hhopen&, 0: _SNDVOL hhopen&, 5: _SNDPLAY hhopen& '3
  577.             IF buttonv(num + (col * 2)) = 2 THEN _SNDSETPOS hhopen&, 0: _SNDVOL hhopen&, .15: _SNDPLAY hhopen& '3
  578.         END IF
  579.         'play hhclosed
  580.         IF instv(4) = 1 THEN
  581.             IF buttonv(num + (col * 3)) = 1 THEN _SNDSTOP hhopen&: _SNDVOL hhclosed&, 1: _SNDPLAY hhclosed& '4
  582.             IF buttonv(num + (col * 3)) = 2 THEN _SNDSTOP hhopen&: _SNDVOL hhclosed&, .2: _SNDPLAY hhclosed& '4
  583.         END IF
  584.         'play tom high
  585.         IF instv(5) THEN
  586.             IF buttonv(num + (col * 4)) = 1 THEN _SNDVOL tomhigh&, 9: _SNDPLAY tomhigh& '5
  587.             IF buttonv(num + (col * 4)) = 2 THEN _SNDVOL tomhigh&, .1: _SNDPLAY tomhigh& '5
  588.         END IF
  589.         'play tom mid
  590.         IF instv(6) THEN
  591.             IF buttonv(num + (col * 5)) = 1 THEN _SNDVOL tommid&, 9: _SNDPLAY tommid& '6
  592.             IF buttonv(num + (col * 5)) = 2 THEN _SNDVOL tommid&, .1: _SNDPLAY tommid& '6
  593.         END IF
  594.         'play tom low
  595.         IF instv(7) THEN
  596.             IF buttonv(num + (col * 6)) = 1 THEN _SNDVOL tomlow&, 9: _SNDPLAY tomlow& '7
  597.             IF buttonv(num + (col * 6)) = 2 THEN _SNDVOL tomlow&, .1: _SNDPLAY tomlow& '7
  598.         END IF
  599.         'play snare
  600.         IF instv(8) THEN
  601.             IF buttonv(num + (col * 7)) = 1 THEN _SNDVOL snare&, 1: _SNDPLAY snare& '8
  602.             IF buttonv(num + (col * 7)) = 2 THEN _SNDVOL snare&, .1: _SNDPLAY snare& '8
  603.         END IF
  604.         'play kick
  605.         IF instv(9) THEN
  606.             IF buttonv(num + (col * 8)) = 1 THEN _SNDVOL kick&, 1: _SNDPLAY kick& '9
  607.             IF buttonv(num + (col * 8)) = 2 THEN _SNDVOL kick&, .1: _SNDPLAY kick& '9
  608.         END IF
  609.         'play cowbell
  610.         IF instv(10) THEN
  611.             IF buttonv(num + (col * 9)) = 1 THEN _SNDVOL cowbell&, .3: _SNDPLAY cowbell& '10
  612.             IF buttonv(num + (col * 9)) = 2 THEN _SNDVOL cowbell&, .02: _SNDPLAY cowbell& '10
  613.         END IF
  614.         'play shaker
  615.         IF instv(11) THEN
  616.             IF buttonv(num + (col * 10)) = 1 THEN _SNDVOL shaker&, .6: _SNDPLAY shaker& '11
  617.             IF buttonv(num + (col * 10)) = 2 THEN _SNDVOL shaker&, .1: _SNDPLAY shaker& '11
  618.         END IF
  619.         'play tambourine
  620.         IF instv(12) THEN
  621.             IF buttonv(num + (col * 11)) = 1 THEN _SNDVOL tamb&, 1: _SNDPLAY tamb& '12
  622.             IF buttonv(num + (col * 11)) = 2 THEN _SNDVOL tamb&, .1: _SNDPLAY tamb& '12
  623.         END IF
  624.         'play vibraslap
  625.         IF instv(13) THEN
  626.             IF buttonv(num + (col * 12)) = 1 THEN _SNDVOL vibraslap&, .1: _SNDPLAY vibraslap& '13
  627.             IF buttonv(num + (col * 12)) = 2 THEN _SNDVOL vibraslap2&, .05: _SNDPLAY vibraslap2& '13
  628.         END IF
  629.         'play gong
  630.         IF instv(14) THEN
  631.             IF buttonv(num + (col * 13)) = 1 THEN _SNDVOL gong&, .1: _SNDPLAY gong& '14
  632.             IF buttonv(num + (col * 13)) = 2 THEN _SNDVOL gong2&, .03: _SNDPLAY gong2& '14
  633.         END IF
  634.         'play triangle
  635.         IF instv(15) THEN
  636.             IF buttonv(num + (col * 14)) = 1 THEN _SNDVOL trianglelong&, .3: _SNDPLAY trianglelong& '15
  637.             IF buttonv(num + (col * 14)) = 2 THEN _SNDVOL triangleshort&, .3: _SNDPLAY triangleshort& '15
  638.         END IF
  639.         'play clave
  640.         IF instv(16) THEN
  641.             IF buttonv(num + (col * 15)) = 1 THEN _SNDVOL clave&, .6: _SNDPLAY clave& '16
  642.             IF buttonv(num + (col * 15)) = 2 THEN _SNDVOL clave&, .02: _SNDPLAY clave& '16
  643.         END IF
  644.     END SUB
  645.      
  646.     SUB FPRINT (x, y, xsize, ysize, num$)
  647.         LINE (x, y)-(x + 100, y + ysize), _RGB(42, 42, 42), BF
  648.         FOR t = 1 TO LEN(num$)
  649.             n = VAL(MID$(num$, t, 1))
  650.             _PUTIMAGE (x, y)-(x + xsize, y + ysize), num&(n)
  651.             x = x + xsize: y = y + zsize
  652.         NEXT
  653.     END SUB
  654.      
  655.     SUB Metronome (way)
  656.         IF way = 1 THEN
  657.             f$ = "drummachine-data\metron.png"
  658.         ELSE
  659.             f$ = "drummachine-data\metroff.png"
  660.         END IF
  661.         ttmp = _LOADIMAGE(f$)
  662.         _PUTIMAGE (875, 72), ttmp: _FREEIMAGE ttmp
  663.     END SUB
  664.  
  665.  

 
                                                                                                                                         (117 downloads previously)
Drum Machine Screenshot.png