I have made a music program in Visual Studio for Windows with C and Fmod that contains a graphical keyboard, a selection of sound files etc., and which also contains a midi controller. I use the midi controller by connecting a midi keyboard to the computer. All the functionality of the midi controller is placed in a callback function, which is called when I press a specific button that is supposed to turn the midi functionality on and off. I am, however, not sure if this is necessary. Maybe I rather should turn it on automatically when starting the program, and turn it off only when quitting, though it’s maybe not so important. The button contains among others the following code:
if (!Midion) {
Midion = 1;
nMidiDeviceNum = midiInGetNumDevs();
if (nMidiDeviceNum == 0) return -1;
rv = midiInOpen(&hMidiDevice, nMidiPort, (DWORD)(void*)MidiInProc, 0, CALLBACK_FUNCTION);
if (rv != MMSYSERR_NOERROR) return -1;
midiInStart(hMidiDevice);
if (Midion) {
Midion = 0;
rv = midiInStop(hMidiDevice);
rv = midiInClose(hMidiDevice);
hMidiDevice = NULL;
}
The midi program works fine, and for a while I can at any time stop playing the midi keyboard and set graphic controls. But after about 5 minutes, nothing happen to the graphic controls when clicking them or dragging them, though they still change their function in a correct way. It is however not satisfying when the changes is not shown on the screen.
I have also found that the “rv” variable for midiInStop(hMidiDevice) and midiInClose(hMidiDevice) gives the value 5, which means MMSYSERR_INVALHANDLE, and I don't understand why. This also means that I can not turn off the midi functionality, as I am supposed to. The main problem is however the freezing of the graphic controls.
Thanks in advance.
Sincerely