Click here to Skip to main content
15,851,915 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: MIDI and USB Keyboard! Pin
Sascha Lefèvre12-Nov-17 9:32
professionalSascha Lefèvre12-Nov-17 9:32 
GeneralRe: MIDI and USB Keyboard! Pin
User 989707412-Nov-17 9:34
User 989707412-Nov-17 9:34 
GeneralRe: MIDI and USB Keyboard! Pin
Sascha Lefèvre12-Nov-17 9:50
professionalSascha Lefèvre12-Nov-17 9:50 
GeneralRe: MIDI and USB Keyboard! Pin
User 989707412-Nov-17 9:56
User 989707412-Nov-17 9:56 
GeneralRe: MIDI and USB Keyboard! Pin
Sascha Lefèvre12-Nov-17 10:16
professionalSascha Lefèvre12-Nov-17 10:16 
GeneralRe: MIDI and USB Keyboard! Pin
User 989707413-Nov-17 0:36
User 989707413-Nov-17 0:36 
GeneralRe: MIDI and USB Keyboard! Pin
User 989707413-Nov-17 10:00
User 989707413-Nov-17 10:00 
GeneralRe: MIDI and USB Keyboard! Pin
User 989707429-Nov-17 5:16
User 989707429-Nov-17 5: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èvre30-Nov-17 0:34
professionalSascha Lefèvre30-Nov-17 0:34 
GeneralRe: MIDI and USB Keyboard! Pin
User 989707430-Nov-17 1:10
User 989707430-Nov-17 1:10 
GeneralRe: MIDI and USB Keyboard! Pin
User 98970742-Dec-17 1:48
User 98970742-Dec-17 1:48 
GeneralRe: MIDI and USB Keyboard! Pin
Sascha Lefèvre2-Dec-17 7:06
professionalSascha Lefèvre2-Dec-17 7:06 
GeneralRe: MIDI and USB Keyboard! Pin
User 98970742-Dec-17 7:44
User 98970742-Dec-17 7:44 
GeneralRe: MIDI and USB Keyboard! Pin
Sascha Lefèvre3-Dec-17 1:56
professionalSascha Lefèvre3-Dec-17 1:56 
GeneralRe: MIDI and USB Keyboard! Pin
User 98970743-Dec-17 3:39
User 98970743-Dec-17 3:39 
GeneralRe: MIDI and USB Keyboard! Pin
Sascha Lefèvre3-Dec-17 7:10
professionalSascha Lefèvre3-Dec-17 7:10 
GeneralRe: MIDI and USB Keyboard! Pin
User 98970743-Dec-17 9:11
User 98970743-Dec-17 9:11 
GeneralRe: MIDI and USB Keyboard! Pin
User 98970746-Dec-17 7:45
User 98970746-Dec-17 7:45 
GeneralRe: MIDI and USB Keyboard! Pin
User 98970749-Dec-17 7:01
User 98970749-Dec-17 7:01 
GeneralRe: MIDI and USB Keyboard! Pin
Sascha Lefèvre9-Dec-17 7:49
professionalSascha Lefèvre9-Dec-17 7:49 
GeneralRe: MIDI and USB Keyboard! Pin
User 98970749-Dec-17 8:31
User 98970749-Dec-17 8:31 
GeneralRe: MIDI and USB Keyboard! Pin
User 989707410-Dec-17 5:39
User 989707410-Dec-17 5:39 
GeneralRe: MIDI and USB Keyboard! Pin
User 989707411-Dec-17 1:56
User 989707411-Dec-17 1:56 
GeneralRe: MIDI and USB Keyboard! Pin
Sascha Lefèvre11-Dec-17 5:40
professionalSascha Lefèvre11-Dec-17 5:40 
GeneralRe: MIDI and USB Keyboard! Pin
User 989707411-Dec-17 5:48
User 989707411-Dec-17 5: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.