home *** CD-ROM | disk | FTP | other *** search
/ Sound, Music & MIDI Collection 2 / SMMVOL2.bin / MIDI_PAT / MTOOLS.ZIP / PLAYRDEV.EXE / MIDI_MM.TXT < prev    next >
Encoding:
Text File  |  1993-09-14  |  6.6 KB  |  293 lines

  1. ; MMGRASP interface to Play/D MIDI Engine         7/20/93
  2. ;
  3. ; Copyright 1993, Kevin Weiner, All rights reserved.
  4. ;
  5. ; Modified for MMGRASP by Max Templeton, Paul Mace Software
  6.  
  7. mfinit:
  8. ;
  9. ; Test for presence of MIDI player and initialize
  10. ;
  11. ;    returns 1 if initialized ok, else 0
  12. ;
  13.  
  14.   if !def(m_idnum)                      ; TesSeRact interface variables
  15.     global m_idnum -1                   ;  Play/R id number
  16.     global m_param 0
  17.     alloc m_param 64
  18.     global m_playrid 0
  19.  
  20.     alloc m_playrid len("Play/R  ")
  21.     set @m_playrid "Play/R  "
  22.  
  23.     global m_tessmpx 0x5453        ;  Tess multiplex id
  24.     global note_on 0x90
  25.     global ctrl_ch 0xb0
  26.     global prog_ch 0xc0
  27.                     ; mfstatus globals
  28.     global etime 0            ;   Elapsed time (ms)
  29.     global songcount 0            ;   Size of play list
  30.     global cursong 0            ;   Current song in playlist
  31.   endif
  32.  
  33.   if @m_idnum<0
  34.   ; Multiplex interrupt call to test for Play/R
  35.     int 0x2f,-1,0,0,0,(@m_playrid&0xFFFF),0,(@m_playrid>>16
  36.     int 0x2f,@m_tessmpx,0,0,0,@m_playrid&0xFFFF,0,@m_playrid>>16
  37.     if @ax==0xffff
  38.       set m_idnum @cx            ; TSR found, cx is tsr id number
  39.       poke @m_param 13            ; m_param[0] =  13 (set timer mode)
  40.       poke @m_param+1 3            ; m_param[1] =  3  (mode 3)
  41.       callplayr
  42.       poke @m_param 12            ; m_param[0] =  12 (reset interface)
  43.       callplayr
  44.       return 1                ; Init was successful 
  45.     else
  46.       return 0                ; Not found - return false
  47.     endif
  48.   else
  49.     return 1                ; Already initialized
  50.   endif
  51.  
  52.  
  53. mfload:
  54. ;
  55. ; Load MIDI file
  56. ;
  57. ;   mfload <filename>
  58. ;
  59. ;     returns:     0    Loaded successfully
  60. ;        1    File not found
  61. ;        2    Not MIDI file format
  62. ;        3    Unexpected end of file
  63. ;        4    Format not supported
  64. ;        5    Track not found
  65. ;        6    I/O error reading file
  66. ;        7    Not enough memory
  67. ;        255    Nothing loaded
  68.  
  69.   if @m_idnum>=0
  70.     poke @m_param 8            ; m_param[0]    =  8 (load file)
  71.     set size len(@1)
  72.     set pos 1
  73.     mark @size                ; m_param[1..size] =  file string
  74.       poke @m_param+@pos asc(mid(@1,@pos,1))
  75.       set pos @pos+1
  76.     loop
  77.     poke @m_param+@pos 0        ; m_param[size+1]  =  0 terminator
  78.     callplayr
  79.     return peek(@m_param)
  80.   endif
  81.   return 255
  82.  
  83.  
  84. mfplay:
  85. ;
  86. ; Start or resume play
  87.  
  88.   if @m_idnum>=0
  89.     poke @m_param 1            ; m_param[0] =  1 (play)
  90.     callplayr
  91.   endif
  92.   return
  93.  
  94.  
  95. mfpause:
  96. ;
  97. ; Pause MIDI file play
  98.  
  99.   if @m_idnum>=0
  100.     poke @m_param 9            ; m_param[0] =  9 (quiet)
  101.     callplayr
  102.     poke @m_param 0            ; m_param[0] =  0 (pause)
  103.     callplayr
  104.   endif
  105.   return
  106.  
  107.  
  108. mfrewind:
  109. ;
  110. ; Rewind to beginning of MIDI file and pause
  111.  
  112.   if @m_idnum>=0
  113.     poke @m_param 3            ; m_param[0] =  3 (rewind)
  114.     callplayr
  115.   endif
  116.   return
  117.  
  118.  
  119. mfsetpos:
  120. ;
  121. ; Set song position
  122. ;
  123. ;   mfsetpos <pos>
  124. ;
  125. ;     <pos> = Song position in milliseconds if positive.
  126. ;          Number of milliseconds to fast forward if negative.
  127.  
  128.   if @m_idnum>=0
  129.     poke @m_param 16            ; m_param[0] =  16 (set pos)
  130.     set i 1                ; m_param[1..4] = position
  131.     set ttime @1
  132.     mark 4
  133.       poke @m_param+@i @ttime&0xff
  134.       set ttime @ttime>>8
  135.       set i @i+1
  136.     loop
  137.     callplayr
  138.   endif
  139.   return
  140.  
  141.  
  142. mfskip:
  143. ;
  144. ; Skip to specific song in play list
  145. ;
  146. ;   mfsetpos <num>
  147. ;
  148. ;     <num> = Song number in play list.  If beyond last song, skip to 1st.
  149.  
  150.   if @m_idnum>=0
  151.     poke @m_param 17            ; m_param[0] = 17 (skip)
  152.     poke @m_param+1 @1            ; m_param[1] = num
  153.     callplayr
  154.   endif
  155.   return
  156.  
  157.  
  158. mfstatus:
  159. ;
  160. ; Get MIDI file play status
  161. ;
  162. ;    returns:   0       Paused
  163. ;               1       Playing
  164. ;               2       Done
  165. ;
  166. ;    global varibles set:
  167. ;    etime = elapsed time of song in milliseconds
  168. ;    songcount = size of play list
  169. ;    cursong = current song number
  170.  
  171.   if @m_idnum>=0
  172.     poke @m_param 5            ; m_param[0] =  5 (play status)
  173.     callplayr
  174.     set pstat peek(@m_param)        ; play status
  175.     set dstat peek(@m_param+1)        ; done status
  176.     set etime 0
  177.     set i 5
  178.     mark 4
  179.       set etime (@etime*256)+peek(@m_param+@i)
  180.       set i @i-1
  181.     loop
  182.     set songcount peek(@m_param+6)
  183.     set cursong peek(@m_param+7)
  184.     if @dstat==1
  185.       return 2                          ; Done = 2
  186.     else
  187.       return @pstat                     ; Playing=1/Paused=0
  188.     endif
  189.   endif
  190.   return 0
  191.  
  192. mstimer:
  193. ;
  194. ; Returns current value of millisecond timer
  195. ;
  196. ;   (Time since driver was loaded)
  197. ;
  198.  
  199.   if @m_idnum>=0
  200.     poke @m_param 25            ; m_param[0] =  25 (ms time)
  201.     callplayr
  202.     set temp 0
  203.     set i 4                             ; time returned in pos 1-4
  204.     mark 4
  205.       set temp (@temp*256)+peek(@m_param+@i)
  206.       set i @i-1
  207.     loop
  208.     return @temp
  209.   endif
  210.   return 0
  211.  
  212.  
  213. mfvolume:
  214. ;
  215. ; Adjust MIDI file volume
  216. ;
  217. ;  mfvolume <vol>
  218. ;
  219. ;    <vol> = -127 to +127  (adjustment to initial volume)
  220. ;
  221.  
  222.   if @m_idnum>=0
  223.     poke @m_param 11            ; m_param[0] =  11 (rewind)
  224.     poke @m_param+1 @1&0xff             ; vol is 8-bit 2's comp
  225.     callplayr
  226.   endif
  227.   return
  228.  
  229. midisend:
  230. ;
  231. ; Send MIDI message
  232. ;
  233. ;  midiSend <status> <data1> <data2>
  234. ;
  235. ;    <status> = message + channel  (ex: note on = 0x90 + chan)
  236. ;    <data1>  = first data byte, if any
  237. ;    <data2>  = second data byte, if any
  238. ;
  239.  
  240.   if @m_idnum>=0
  241.     poke @m_param 21            ; m_param[0] = 21 (send bytes, short)
  242.     poke @m_param+1 0                   ; m_param[1] = 0  (default device)
  243.     poke @m_param+3 @1                  ; m_param[3] = status byte
  244.     set len 1
  245.     if @2<>""                           ; Add any data bytes
  246.       poke @m_param+4 @2
  247.       set len @len+1
  248.       if @3<>""
  249.         poke @m_param+5 @3
  250.         set len @len+1
  251.       endif
  252.     endif
  253.     poke @m_param+2 @len                ; m_param[2] = message length
  254.     callplayr
  255.   endif
  256.   return
  257.  
  258. mididev:
  259. ;
  260. ; Returns default MIDI/sound device type as a 3-character string:
  261. ;
  262. ;     "MPU"   :   Roland MPU compatible
  263. ;     "MFC"   :   IBM PC Music Feature Card
  264. ;     "SBM"   :   Sound Blaster MIDI
  265. ;     "SBF"   :   Sound Blaster FM Sound
  266. ;     "MID"   :   Key MIDIator
  267. ;     "ADL"   :   AdLib FM Sound
  268. ;     "NUL"   :   No music interface
  269. ;
  270.  
  271.   if @m_idnum>=0
  272.     poke @m_param 26            ; m_param[0] = 26 (get default dev id)
  273.     callplayr
  274.     if peek(@m_param+1)>0        ; m_param[1] is dev id num
  275.       poke @m_param 20                  ; m_param[0] = 20 (get dev name)
  276.       callplayr
  277.       return chr(peek(@m_param+2))$chr(peek(@m_param+3))$chr(peek(@m_param+4))
  278.     endif
  279.   endif
  280.   return "NUL"
  281.          
  282. callplayr:
  283. ;
  284. ; Call MIDI engine with contents of global parameter block m_param 
  285.  
  286.   if @m_idnum>=0
  287.     set pseg @m_param>>16
  288.     set pofs @m_param&0xffff
  289.     int 0x2f,-1,0x20,@m_idnum,0,0,@pofs,0,@pseg
  290.     int 0x2f,@m_tessmpx,0x20,@m_idnum,0,0,@pofs,0,@pseg
  291.   endif
  292.   return
  293.