home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / mag&info / ptv3n5.zip / VBMIDI.ARJ / LISTING.TXT < prev    next >
Text File  |  1992-10-08  |  3KB  |  103 lines

  1. ' Listing 1
  2.  
  3. Declare Function midiOutOpen Lib "mmsystem" (handle As Integer, ByVal id As Integer, ByVal callback As Long, ByVal dwinstance As Long, ByVal flags As Long) As Integer
  4. Declare Sub midiOutClose Lib "mmsystem" (ByVal handle As Integer)
  5. Declare Function midiOutShortMsg Lib "mmsystem" (ByVal handle As Integer, ByVal message As Long) As Long
  6.  
  7. Global hMidi As Integer
  8. Global istatus As Integer
  9. Global ichannel As Integer
  10. Global idata1 As Integer
  11. Global ldata2 As Long
  12. Global lmessage As Long
  13.  
  14. ' Listing 2
  15. Sub Form_Load ()
  16.   ' Try to open the default MIDI device.
  17.   ErrCode = midiOutOpen(hmidi, -1, 0, 0, 0)
  18.   ' Quit w/error if unable to.
  19.   If ErrCode <> 0 Then
  20.     st$ = "Error code " + Str$(ErrCode)
  21.     MsgBox (st$) ', 16, "Error!")
  22.     End
  23.   Else
  24.    ' Send the patch change
  25.    ' for voice 25, the steel-
  26.    ' string guitar in General MIDI.
  27.    lmessage = &HC0 Or 0 Or (25 * 256) Or (0 * 65536)
  28.    ic& = midiOutShortMsg(hmidi, lmessage)
  29. End If
  30.  
  31. ' Set default values in the text boxes.
  32.  
  33. ' This is the Note On message.
  34. text1.text = "&h90"
  35. ' This value isn't used for note on.
  36. text2.text = "0"
  37. ' Middle C.
  38. text3.text = "64"
  39. ' Maximum volume.
  40. text4.text = "127"
  41.  
  42.  
  43.  
  44. End Sub
  45.  
  46. ' Listing 3
  47. Sub Form_Unload (Cancel As Integer)
  48.   ' Close the MIDI device. This must be
  49.   ' done; otherwise it can't be used until
  50.   ' Windows is restarted.
  51.   Call midiOutClose(hmidi)
  52. End Sub
  53.  
  54. ' Listing 4
  55. Sub Command1_Click ()
  56.   ' The 3 bytes of a MIDI message must be written to lmessage.
  57.   lmessage = istatus Or ichannel Or (idata1 * 256) Or (ldata2 * 65536)
  58.   ' Send the message to the hmidi device handle.
  59.   ic& = midiOutShortMsg(hmidi, lmessage)
  60. End Sub
  61.  
  62. ' Listing 5
  63. Sub Command2_Click ()
  64.   ' Make sure you close the MIDI device handle
  65.   ' before quitting VB.
  66.   Call midiOutClose(hmidi)
  67.   End
  68. End Sub
  69.  
  70. ' Listing 6
  71. Sub Text1_Change ()
  72.   ' This is the status byte portion
  73.   ' of the MIDI message.
  74.   ' Convert the value in the text
  75.   ' box to an integer.
  76.   istatus = Val(text1.text)
  77. End Sub
  78.  
  79. ' Listing 7
  80. Sub Text2_Change ()
  81.   ' This is the channel nybble of
  82.   ' the status byte.
  83.   ichannel = Val(text2.text)
  84. End Sub
  85.  
  86. ' Listing 8
  87. Sub Text3_Change ()
  88.   ' The first of 2 data bytes.
  89.   ' Convert the value in the text
  90.   ' box to an integer.
  91.   idata1 = Val(text3.text)
  92. End Sub
  93.  
  94. ' Listing 9
  95. Sub Text4_Change ()
  96.   ' The second of 2 data bytes.
  97.   ' Convert the value in the text
  98.   ' box to an integer.
  99.   ldata2 = Val(text4.text)
  100. End Sub
  101.  
  102.  
  103.