home *** CD-ROM | disk | FTP | other *** search
/ Sound Sensations! / sound_sensations.iso / miditool / mpudemo1 / mpudemo1.bas next >
Encoding:
BASIC Source File  |  1987-06-20  |  6.6 KB  |  204 lines

  1. ' ***************************************************************************
  2. ' *                                                                         *
  3. ' *   FileName:  MPUDEMO1.BAS, MPUDEMO1.EXE - for IBM and ROLAND MPU-401    *
  4. ' *                                                                         *
  5. ' *      Demonstrates the speed of Borland's TURBO BASIC, and allows you    *
  6. ' *        to experiment with the ROLAND MPU-401 and MIDI synthesizers.     *
  7. ' *   MPUDEMO1 puts your MPU-401 into its "DUMB UART" mode and then plays   *
  8. ' *    a quick scale and some chords on MIDI Channel 1.  To run, connect    *
  9. ' *        your synth (on Chan.1) to MPU-401 OUT, type MPUDEMO1 <CR>        *
  10. ' *   WARNING:  If you don't HAVE an MPU-401 hooked up, program hangs up!   *
  11. ' *       Compile ONLY with TURBO BASIC V. 1.0 on IBM PC/XT or equiv.       *
  12. ' *         Please feel free to tinker around to learn about MIDI!          *
  13. ' *                                                                         *
  14. ' *               By Gino F. Silvestri 06/19/87 1700 Hrs.                   *
  15. ' *                                                                         *
  16. ' ***************************************************************************
  17.  
  18. ' ***************************************************************************
  19. ' *                        D E F I N I T I O N S                            *
  20. ' ***************************************************************************
  21.  
  22.     DEFINT A-Z
  23. '            TURBO BASIC Constants:
  24.  
  25.     %ComdPort   = &H331            ' MPU-401 Command Port on IBM
  26.     %StatPort   = &H331            ' MPU-401 Status Port on IBM
  27.     %DataPort   = &H330            ' MPU-401 Data I/O Port on IBM
  28.     %DRR        = &H40            ' Mask for Data Read Reg. Bit
  29.     %DSR        = &H80            ' Mask for Data Set Ready Bit
  30.     %ACK        = &HFE            ' MPU-401 Acknowledge Response
  31.     %MaskFlip   = &HFF            ' WAIT Function Bit Mask XOR
  32.     %MPUReset   = &HFF            ' MPU-401 Total Reset Command
  33.     %UARTMode   = &H3F            ' MPU-401 "Dumb UART Mode"
  34.     %NoteOn1    = &H90            ' MIDI Note On for Channel 1
  35.     %Velocity   = 64            ' MIDI Medium Key Velocity
  36.     %NoteOff    = 0                ' 0 Velocity = Note Off
  37.     %FirstNote  = 36            ' First note synth can play
  38.     %LastNote   = 96            ' Last note synth can play
  39.  
  40. ' ***************************************************************************
  41. ' *                       I N I T I A L I Z A T I O N                       *
  42. ' ***************************************************************************
  43.  
  44. RSTMPU:                     ' Reset the MPU-401                                 
  45.     CLS                    ' Clear Display
  46.  
  47.     OUT %ComdPort,%MPUReset            ' Send MPU-401 RESET Command
  48.     A = INP(%DataPort)            ' Dummy read to clear buffer
  49.  
  50.      WAIT %StatPort,%DRR,%MaskFlip        ' Wait for port ready
  51.  
  52.         OUT %ComdPort,%UARTMode            ' Set MPU-401 "Dumb UART" Mode
  53.      A = INP(%DataPort)            ' Dummy Read to clear buffer
  54.  
  55.      WAIT %StatPort,%DSR,%MaskFlip        ' Wait for "UART" port ready -
  56.                          '  Really crucial!
  57. REM Form Feed 
  58.  
  59. ' ***************************************************************************
  60. ' *                         M A I N   P R O G R A M                         *
  61. ' ***************************************************************************
  62.  
  63. MPUPlay:
  64.  
  65.     PRINT : PRINT : PRINT : PRINT : PRINT
  66.  
  67.     PRINT TAB(10)"MPUDEMO1 now playing a fast scale on MIDI Channel 1"
  68.  
  69.     FOR N = %FirstNote TO %LastNote     ' Ascending Scale
  70.  
  71.         Note = N
  72.         GOSUB Playit            ' Play a note
  73.  
  74.         DELAY .06            ' Duration of note ON
  75.  
  76.         GOSUB Offit               ' Stop that same note
  77.  
  78.     NEXT                    ' Play next note
  79.  
  80.  
  81.     DELAY .1                ' Pause between scales
  82.  
  83.  
  84.     FOR N = %LastNote TO %FirstNote STEP -1    ' Descending Scales
  85.  
  86.         Note =  N
  87.         GOSUB Playit            ' Play a note
  88.  
  89.         DELAY .06            ' Duration of note OFF
  90.  
  91.         GOSUB Offit               ' Stop that same note
  92.  
  93.     NEXT
  94.  
  95.  
  96.     DELAY 1                    ' Pause between demos
  97.  
  98. REM Form Feed 
  99.  
  100.     PRINT : PRINT : PRINT
  101.  
  102.     PRINT TAB(10)"MPUDEMO1 now playing some chords on MIDI Channel 1"
  103.  
  104.     FOR N = 1 to 3                ' Playing first chord thrice
  105.  
  106.         Note = 65            ' F3
  107.         GOSUB Playit            ' Start a chord
  108.         Note = 69                       ' A3
  109.         GOSUB Playit
  110.         Note = 72            ' C4
  111.         GOSUB Playit
  112.  
  113.         DELAY .3            ' Duration of held chord
  114.  
  115.         Note = 65                       ' F3
  116.         GOSUB Offit            ' Stop the chord
  117.         Note = 69                       ' A3
  118.         GOSUB Offit
  119.         Note = 72                       ' C4
  120.         GOSUB Offit
  121.  
  122.         DELAY .3            ' Duration of rest
  123.  
  124.  
  125.     NEXT                    ' Play chord again
  126.  
  127.  
  128.         Note = 64                       ' E3
  129.         GOSUB Playit            ' Start last chord
  130.         Note = 67                       ' G3
  131.         GOSUB Playit
  132.         Note = 72                       ' C4
  133.         GOSUB Playit
  134.  
  135.         DELAY 3                ' Duration of held chord
  136.  
  137.         Note = 64
  138.         GOSUB Offit            ' Stop the chord
  139.         Note = 67
  140.         GOSUB Offit
  141.         Note = 72
  142.         GOSUB Offit
  143.  
  144.     PRINT : PRINT : PRINT
  145.  
  146.     PRINT TAB(10)"MPUDEMO1 is through - Tinker with it!"
  147.  
  148.     END
  149.  
  150.     REM Form Feed 
  151.  
  152. ' ***************************************************************************
  153. ' *                          S U B R O U T I N E S                          *
  154. ' ***************************************************************************
  155.  
  156.  
  157. ' ***************************** Playit SUBROUTINE ***************************
  158.  
  159. Playit:                     ' Play a MIDI Note
  160.  
  161.     OUT  %DataPort,%NoteOn1            ' Send Chan. 1 note ON code
  162.      A    = INP(%DataPort)            ' Dummy Read to clear buffer *
  163.      WAIT %StatPort,%DRR,%MaskFlip        ' Wait for port ready
  164.     
  165.     OUT  %DataPort,Note            ' Send note Number to turn ON
  166.      A    = INP(%DataPort)            ' Dummy Read to clear buffer *
  167.      WAIT %StatPort,%DRR,%MaskFlip         ' Wait for port ready
  168.  
  169.     OUT  %DataPort,%Velocity        ' Send medium velocity
  170.      A    = INP(%DataPort)            ' Dummy Read to clear buffer *
  171.      WAIT %StatPort,%DRR,%MaskFlip         ' Wait for port ready
  172.  
  173.     RETURN
  174.  
  175.  
  176. ' ***************************** Offit SUBROUTINE ***************************
  177.  
  178. Offit:                         ' Turn off a MIDI Note
  179.  
  180.     OUT  %DataPort,%NoteOn1            ' Send Chan. 1 note ON code
  181.      A    = INP(%DataPort)            ' Dummy Read to clear buffer *
  182.     WAIT %StatPort,%DRR,%MaskFlip        ' Wait for port ready
  183.  
  184.     OUT  %DataPort,Note            ' Send note number to turn OFF
  185.      A    = INP(%DataPort)            ' Dummy Read to clear buffer *
  186.      WAIT %StatPort,%DRR,%MaskFlip        ' Wait for port ready
  187.  
  188.     OUT  %DataPort,%NoteOff            ' Send 0 Velocity = Note Off
  189.      A    = INP(%DataPort)            ' Dummy Read to clear buffer *
  190.      WAIT %StatPort,%DRR,%MaskFlip        ' Wait for port ready
  191.  
  192.     RETURN
  193.  
  194. ' * Note: Read of %DataPort prevents hang-up if MIDI IN from a keyboard is
  195. '   connected and played - WAIT would stay FOREVER if you hit any key once!
  196.  
  197.     END
  198.  
  199.  
  200. ' ************************* Last Line of MPUDEMO1.BAS ************************
  201. ' Last Edited 06/20/87 1531 Hrs. G. F. Silvestri
  202.  
  203.     END
  204.