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

Visual Basic

 
GeneralRe: MIDI and USB Keyboard! Pin
Sascha Lefèvre12-Nov-17 8:32
professionalSascha Lefèvre12-Nov-17 8:32 
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 
GeneralRe: MIDI and USB Keyboard! Pin
User 989707429-Nov-17 4:16
User 989707429-Nov-17 4:16 
HI..some help please..

I have changed my code and i am now able to select a MIDI Device and play notes from it!
I am now facing a problem that is - note duration
When i insert the code for note duration it returns me an error that says something like this:

"the code is using a thread for what was not created"

Heres the code i am using...and i am also using a module called clsMIDI

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

        midiInStart(hMidiIn)
    End Sub

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

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

    Private Sub FillInstrumentCombo()
        For i = 0 To 128
            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

    Function MidiInProc(ByVal hMidiIn As Integer, ByVal wMsg As UInteger, ByVal dwInstance As Integer, ByVal dwParam1 As Integer, ByVal dwParam2 As Integer) As Integer
        Dim DataByte1 = (dwParam1) >> 8
        m.PlayMIDINote(DataByte1, 127)
        m.NoteDuration = CInt(cboduration.Text)
        m.Pan = 50
    End Function

End Class



TIA

modified 7-Jan-19 21:02pm.

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 

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.