Click here to Skip to main content
15,887,585 members
Home / Discussions / Visual Basic
   

Visual Basic

 
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 
may i ask for your attention once again?

my code has changed....i am now able to do everything i want from it...but i am just having a small problem...
When i press the midi key of my controller it plays the note and when i unpress it it also plays the same note!
I have tried the .StopMIDINote() function but i do not know where to insert it?!!! If i was using a button i would know..mousedown play..mouseup stop..but i am using my MIDI hardware keyboard!

Below i show the code....if you have some advice i would appreciate it?!!?!?
Thanks You!


VB
<pre>Public Class Form1
    Dim m As New clsMIDI
    Dim hMidiIn As Integer

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        FillInstrumentCombo()

        If midiInGetNumDevs() = 0 Then
            MsgBox("No MIDI devices connected")
        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


    End Sub

    Private Sub Form1_Closed(sender As Object, e As EventArgs) Handles Me.Closed
        midiInStop(hMidiIn)
        midiInReset(hMidiIn)
        midiInClose(hMidiIn)
    End Sub
    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 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)

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

    Dim DataByte1 As Byte

    Function MidiInProc(ByVal hMidiIn As Integer, ByVal wMsg As UInteger, ByVal dwInstance As Integer, ByVal dwParam1 As Integer, ByVal dwParam2 As Integer) As Integer
        TextBox1.Invoke(New DisplayDataDelegate(AddressOf DisplayData), New Object() {dwParam1})
        m.PlayMIDINote(DataByte1, 127)
    End Function

    Private Sub DisplayData(dwParam1)
        DataByte1 = (dwParam1 And &HFF00) >> 8
        TextBox1.AppendText(String.Format("{0:X2}{1}", DataByte1, vbCrLf))
    End Sub


    Private Sub FillInstrumentCombo()
        For i = 0 To 121
            cboInstruments.Items.Add(Instrument.GMInstrumentNames(i))
        Next
        cboInstruments.SelectedIndex = 0
    End Sub

    Private Sub cboInstruments_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboInstruments.SelectedIndexChanged
        m.CurrentInstrument = cboInstruments.Text
    End Sub

    Private Sub hsbVolume_ValueChanged(sender As Object, e As EventArgs) Handles hsbVolume.ValueChanged
        m.Volume = hsbVolume.Value
    End Sub

    Private Sub cboduration_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboduration.SelectedIndexChanged
        Dim duration = CInt(cboduration.Text)
        m.NoteDuration = duration
    End Sub
End Class


modified 7-Jan-19 21:02pm.

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 
GeneralRe: MIDI and USB Keyboard! Pin
Sascha Lefèvre11-Dec-17 4:58
professionalSascha Lefèvre11-Dec-17 4:58 
GeneralRe: MIDI and USB Keyboard! Pin
User 989707411-Dec-17 5:04
User 989707411-Dec-17 5:04 
GeneralRe: MIDI and USB Keyboard! Pin
Sascha Lefèvre11-Dec-17 5:09
professionalSascha Lefèvre11-Dec-17 5:09 
GeneralRe: MIDI and USB Keyboard! Pin
User 989707411-Dec-17 5:18
User 989707411-Dec-17 5:18 
GeneralRe: MIDI and USB Keyboard! Pin
Sascha Lefèvre11-Dec-17 5:39
professionalSascha Lefèvre11-Dec-17 5:39 
GeneralRe: MIDI and USB Keyboard! Pin
User 989707411-Dec-17 5:55
User 989707411-Dec-17 5:55 
GeneralRe: MIDI and USB Keyboard! Pin
Sascha Lefèvre11-Dec-17 6:01
professionalSascha Lefèvre11-Dec-17 6:01 
GeneralRe: MIDI and USB Keyboard! Pin
User 989707411-Dec-17 6:05
User 989707411-Dec-17 6:05 
GeneralRe: MIDI and USB Keyboard! Pin
User 989707411-Dec-17 6:12
User 989707411-Dec-17 6:12 

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.