Click here to Skip to main content
15,847,414 members
Home / Discussions / Visual Basic
   

Visual Basic

 
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 
GeneralRe: MIDI and USB Keyboard! Pin
Sascha Lefèvre30-Nov-17 0:34
professionalSascha Lefèvre30-Nov-17 0:34 
Controls (a Form, ComboBox, TextBox..) can only be accessed by the UI-thread. That's the thread that created them and the thread that executes all your code unless you either explicitly create additional threads or use some kind of event/callback mechanism - the latter you apparently do here:
VB
midiInOpen(hMidiIn, DeviceID, AddressOf MidiInProc, 0, CALLBACK_FUNCTION)
So that midi-library you're using seems to call your function MidiInProc(..) on a different thread than your UI-thread and then tries to access cboduration.Text which is one of your controls which may only be accessed by your UI thread. That's the problem.

The easiest solution for you here is this: Read the value of cboduration.Text into a class variable (let's call it duration) the moment that it is changed by the user. Also initialize that variable with the same value as the control. Then replace this:
VB
m.NoteDuration = CInt(cboduration.Text)
..by this:
VB
m.NoteDuration = duration
Now the UI thread does the reading from the control and the thread that executes MidiInProc doesn't "touch" any controls any more.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson

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 
GeneralRe: MIDI and USB Keyboard! Pin
Sascha Lefèvre11-Dec-17 5:56
professionalSascha Lefèvre11-Dec-17 5: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.