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

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