Click here to Skip to main content
15,917,645 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: MIDI and USB Keyboard! Pin
User 989707412-Nov-17 8:34
User 989707412-Nov-17 8:34 
GeneralRe: MIDI and USB Keyboard! Pin
Sascha Lefèvre12-Nov-17 8:50
professionalSascha Lefèvre12-Nov-17 8:50 
GeneralRe: MIDI and USB Keyboard! Pin
User 989707412-Nov-17 8:56
User 989707412-Nov-17 8:56 
GeneralRe: MIDI and USB Keyboard! Pin
Sascha Lefèvre12-Nov-17 9:16
professionalSascha Lefèvre12-Nov-17 9:16 
GeneralRe: MIDI and USB Keyboard! Pin
User 989707412-Nov-17 23:36
User 989707412-Nov-17 23:36 
GeneralRe: MIDI and USB Keyboard! Pin
User 989707413-Nov-17 9:00
User 989707413-Nov-17 9:00 
Well... i did not had an answer..even because my registration in their forums was a mess..and i could not even register there!
I searched for more help and i came accross with some examples..i kinda mixed 2 codes and i am now able to open my midi devices an play the sounds through my MIDI controller. I am only having 2 issues that i am not being able to solve!

1 - the sound is playing twice..one for "note on" another for "note off"...when i press my MIDI controller key it plays..and when i release it ..it plays again!!!!

2 - the notes seem to be infinite..i do not know where to put the
STOPAllMIDINotes()
function!

I have all this code:

VB
<pre>    Public Declare Function midiInGetNumDevs Lib "winmm.dll" () As Integer
    Public Declare Function midiInGetDevCaps Lib "winmm.dll" Alias "midiInGetDevCapsA" (ByVal uDeviceID As Integer, ByRef lpCaps As MIDIINCAPS, ByVal uSize As Integer) As Integer
    Public Declare Function midiInOpen Lib "winmm.dll" (ByRef hMidiIn As Integer, ByVal uDeviceID As Integer, ByVal dwCallback As MidiInCallback, ByVal dwInstance As Integer, ByVal dwFlags As Integer) As Integer
    Public Declare Function midiInStart Lib "winmm.dll" (ByVal hMidiIn As Integer) As Integer
    Public Declare Function midiInStop Lib "winmm.dll" (ByVal hMidiIn As Integer) As Integer
    Public Declare Function midiInReset Lib "winmm.dll" (ByVal hMidiIn As Integer) As Integer
    Public Declare Function midiInClose Lib "winmm.dll" (ByVal hMidiIn As Integer) As Integer

    Public Delegate Function MidiInCallback(ByVal hMidiIn As Integer, ByVal wMsg As UInteger, ByVal dwInstance As Integer, ByVal dwParam1 As Integer, ByVal dwParam2 As Integer) As Integer
    Public ptrCallback As New MidiInCallback(AddressOf MidiInProc)
    Public Const CALLBACK_FUNCTION As Integer = &H30000
    Public Const MIDI_IO_STATUS = &H20

    Public Delegate Sub DisplayDataDelegate(dwParam1)

    Public Structure MIDIINCAPS
        Dim wMid As Int16 ' Manufacturer ID
        Dim wPid As Int16 ' Product ID
        Dim vDriverVersion As Integer ' Driver version
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=32)> Dim szPname As String ' Product Name
        Dim dwSupport As Integer ' Reserved
    End Structure

    Dim hMidiIn As Integer
    Dim DataByte1 As Byte

    Dim m As New clsMIDI

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        FillInstrumentCombo()
        If midiInGetNumDevs() = 0 Then
            MsgBox("No MIDI devices connected")
            Application.Exit()
        End If

        Dim InCaps As New MIDIINCAPS
        Dim DevCnt As Integer

        For DevCnt = 0 To (midiInGetNumDevs - 1)
            midiInGetDevCaps(DevCnt, InCaps, Len(InCaps))
            ComboBox1.Items.Add(InCaps.szPname)
        Next DevCnt

        midiInStart(hMidiIn)
    End Sub


    Function MidiInProc(ByVal hMidiIn As Integer, ByVal wMsg As UInteger, ByVal dwInstance As Integer, ByVal dwParam1 As Integer, ByVal dwParam2 As Integer) As Integer
        DataByte1 = (dwParam1 And &HFF00) >> 8
        m.PlayMIDINote(DataByte1, 127)
        m.STOPAllMIDINotes()
    End Function

    Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        Dim DeviceID As Integer = ComboBox1.SelectedIndex
        midiInOpen(hMidiIn, DeviceID, ptrCallback, 0, CALLBACK_FUNCTION Or MIDI_IO_STATUS)
        midiInStart(hMidiIn)
    End Sub

    Private Sub Form1_Closed(sender As Object, e As EventArgs) Handles Me.Closed
        midiInStop(hMidiIn)
        midiInReset(hMidiIn)
        midiInClose(hMidiIn)
        Application.Exit()
    End Sub


I do not know where "to go" now...!!!

modified 7-Jan-19 21:02pm.

GeneralRe: MIDI and USB Keyboard! Pin
User 989707429-Nov-17 4:16
User 989707429-Nov-17 4:16 
GeneralRe: MIDI and USB Keyboard! Pin
Sascha Lefèvre29-Nov-17 23:34
professionalSascha Lefèvre29-Nov-17 23:34 
GeneralRe: MIDI and USB Keyboard! Pin
User 989707430-Nov-17 0:10
User 989707430-Nov-17 0:10 
GeneralRe: MIDI and USB Keyboard! Pin
User 98970742-Dec-17 0:48
User 98970742-Dec-17 0:48 
GeneralRe: MIDI and USB Keyboard! Pin
Sascha Lefèvre2-Dec-17 6:06
professionalSascha Lefèvre2-Dec-17 6:06 
GeneralRe: MIDI and USB Keyboard! Pin
User 98970742-Dec-17 6:44
User 98970742-Dec-17 6:44 
GeneralRe: MIDI and USB Keyboard! Pin
Sascha Lefèvre3-Dec-17 0:56
professionalSascha Lefèvre3-Dec-17 0:56 
GeneralRe: MIDI and USB Keyboard! Pin
User 98970743-Dec-17 2:39
User 98970743-Dec-17 2:39 
GeneralRe: MIDI and USB Keyboard! Pin
Sascha Lefèvre3-Dec-17 6:10
professionalSascha Lefèvre3-Dec-17 6:10 
GeneralRe: MIDI and USB Keyboard! Pin
User 98970743-Dec-17 8:11
User 98970743-Dec-17 8:11 
GeneralRe: MIDI and USB Keyboard! Pin
User 98970746-Dec-17 6:45
User 98970746-Dec-17 6:45 
GeneralRe: MIDI and USB Keyboard! Pin
User 98970749-Dec-17 6:01
User 98970749-Dec-17 6:01 
GeneralRe: MIDI and USB Keyboard! Pin
Sascha Lefèvre9-Dec-17 6:49
professionalSascha Lefèvre9-Dec-17 6:49 
GeneralRe: MIDI and USB Keyboard! Pin
User 98970749-Dec-17 7:31
User 98970749-Dec-17 7:31 
GeneralRe: MIDI and USB Keyboard! Pin
User 989707410-Dec-17 4:39
User 989707410-Dec-17 4:39 
GeneralRe: MIDI and USB Keyboard! Pin
User 989707411-Dec-17 0:56
User 989707411-Dec-17 0:56 
GeneralRe: MIDI and USB Keyboard! Pin
Sascha Lefèvre11-Dec-17 4:40
professionalSascha Lefèvre11-Dec-17 4:40 
GeneralRe: MIDI and USB Keyboard! Pin
User 989707411-Dec-17 4:48
User 989707411-Dec-17 4:48 
GeneralRe: MIDI and USB Keyboard! Pin
Sascha Lefèvre11-Dec-17 4:56
professionalSascha Lefèvre11-Dec-17 4:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.