Click here to Skip to main content
15,887,683 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 
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 
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 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.