OK I put a conditional breakpoint on the first “if” in the following code.
[code] static LRESULT CALLBACK deviceChangeEventCallback (HWND h, const UINT message,
const WPARAM wParam, const LPARAM lParam)
{
if (message == WM_DEVICECHANGE
&& (wParam == 0x8000 /DBT_DEVICEARRIVAL/
|| wParam == 0x8004 /DBT_DEVICEREMOVECOMPLETE/))
{
((WASAPIAudioIODeviceType*) GetWindowLongPtr (h, GWLP_USERDATA))->handleDeviceChange();
}
return DefWindowProc (h, message, wParam, lParam);
}[/code]
My conditional breakpoint stops if “message == WM_DEVICECHANGE” is true (otherwise, it breaks on every single message so it’s impossible to debug )
What I found is that, when a device is plugged or unplugged (both the sound card or the midi controller), wParam==0x0007
According to Windows API docs this corresponds to DBT_DEVNODES_CHANGED - A device has been added to or removed from the system.
Basically the test is never true and handleDeviceChange is never called.
So I went further and replaced
if (message == WM_DEVICECHANGE
&& (wParam == 0x8000 /*DBT_DEVICEARRIVAL*/
|| wParam == 0x8004 /*DBT_DEVICEREMOVECOMPLETE*/))
by
if (message == WM_DEVICECHANGE
&& (wParam == 0x8000 /*DBT_DEVICEARRIVAL*/
|| wParam == 0x8004 /*DBT_DEVICEREMOVECOMPLETE*/ || wParam==0x0007))
And this time, obviously handleDeviceChange is called and … it works !
However the following test :
if (newOutNames != outputDeviceNames
|| newInNames != inputDeviceNames
|| newOutIds != outputDeviceIds
|| newInIds != inputDeviceIds)
apparently just tests for the sound card’s IO, not the other MIDI controlers IO.
In other words, if I remove the padControl, y handleDeviceChange is called but the “if” evaluates to false.
That would be really nice if it worked for midi controlers as well
Now about ASIO, I noticed that “handleDeviceChange” is also called in ASIO mode, however all the names/id are empty (numUsed==0) .
HTH !