It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Visual Basic Forum

cannot receive external MIDI with VB2005

Moderator: dafunkymunky

cannot receive external MIDI with VB2005

Postby JimOnVb on Sun Sep 16, 2007 1:16 am

Hi,
I've been trying to write a program which can read MIDI messages from (and send MIDI messages to) an external USB-based MIDI interface. I got the sending part working; this post focuses on the receiving. My whole approach is sort of based on something called Carl's MIDI tools, but his thing didn't have an input example and was for VB6.
Here's my code. I appreciate any insight. What'm I doing wrong? :?
Code: Select all
Option Explicit On

Public Delegate Sub MIDIProcDelegate(ByVal hDlg As Integer, ByVal Msg As Integer, _
ByVal wInstance As Integer, ByVal wParam As Integer, ByVal lParam As Integer)

Public Class MidiViewTwo
    ' Function privates.
    Private Declare Function midiInGetNumDevs Lib "winmm.dll" () As Integer
    Declare Function midiInOpen Lib "winmm.dll" (ByVal lphMidiIn As Integer, ByVal uDeviceID As Integer, _
    ByVal dwCallback As MIDIProcDelegate, ByVal dwInstance As Integer, ByVal dwFlags As Integer) As Integer
    Private Declare Function midiInClose Lib "winmm.dll" (ByVal hMidiIN As Integer) As Integer
    Private Declare Function MidiInProc Lib "winmm.dll" (ByVal MidiInHandle As Int32, ByVal NewMsg As Int32, _
    ByVal Instance As Int32, ByVal wParam As Int32, ByVal lParam As Int32)
    ' Variable privates.
    Private _NumOfInputDevices As Short = midiInGetNumDevs()
    Private _InHandle As Long

    Private Sub MidiViewTwo_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' Determine number of input devices.
        MessageBox.Show("There are " & _NumOfInputDevices.ToString & " input devices!", "Will this work?")
        ' Above message should, and does, cite 2 input devices.

        ' Open the first MIDI input device.
        Dim mMIDIInProcDelegate As MIDIProcDelegate
        mMIDIInProcDelegate = AddressOf MidiInProcessor
        Dim CALLBACK_FUNCTION As Integer = &H30000
        Dim MidiInOpenResult As Long = midiInOpen(_InHandle, 1, mMIDIInProcDelegate, 0, CALLBACK_FUNCTION)
        ' Maybe that last 0 is the same value as the can't-be-found CALLBACK_FUNCTION
        MessageBox.Show("MidiInOpenResult is " & MidiInOpenResult.ToString, "Will this work?")
        ' Above message should display 0 but actually displays 11. Good luck finding out what 11 means.
    End Sub

    Protected Sub MidiInProcessor(ByVal MidiInHandle As Int32, ByVal NewMsg As Int32, ByVal Instance As Int32, _
    ByVal wParam As Int32, ByVal lParam As Int32)
        MessageBox.Show("Received a MIDI message.", "Will this work?")
        ' Well that's not working. Not sure how to get this callback to fire.
    End Sub

    Private Sub CloseButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseButton.Click
        ' Close the MIDI input device.
        Dim MidiInCloseResult As Long = midiInClose(_InHandle)
        MessageBox.Show("MidiInCloseResult is " & MidiInCloseResult.ToString, "Will this work?")
        ' Above message should display 0 but actually displays 5. Good luck finding out what 5 means.
        Close()
    End Sub
End Class
JimOnVb
 
Posts: 0
Joined: Sun Sep 16, 2007 1:06 am

Who is online

Users browsing this forum: No registered users and 2 guests