@@ -20,12 +20,11 @@ static int s_updateCount = 0;
2020
2121void usbMidiProcess (bool bPlugAndPlayUpdated)
2222{
23- if (!bPlugAndPlayUpdated) return ;
24-
2523 s_updateCount++;
24+ bool bNeedsScan = bPlugAndPlayUpdated || (s_updateCount % 30 == 1 );
2625
27- // Every 10th PnP update , log which umidi slots are present
28- if (s_updateCount % 10 == 1 )
26+ // Every 30th iteration , log which umidi slots are present
27+ if (bNeedsScan && s_updateCount % 30 == 1 )
2928 {
3029 CString name;
3130 CString found;
@@ -39,18 +38,20 @@ void usbMidiProcess(bool bPlugAndPlayUpdated)
3938 s_updateCount, found.GetLength () ? (const char *)found : " none" );
4039 }
4140
42- CString name;
43- for (int i = 1 ; i <= 8 ; i++)
44- {
45- if (s_registered[i]) continue ;
46- name.Format (" umidi%d" , i);
47- CUSBMIDIDevice *pDev = (CUSBMIDIDevice *)
48- CDeviceNameService::Get ()->GetDevice ((const char *)name, FALSE );
49- if (!pDev) continue ;
50- s_pDevices[i] = pDev;
51- s_registered[i] = true ;
52- CLogger::Get ()->Write (log_name, LogNotice, " USB MIDI device connected: %s" , (const char *)name);
53- pDev->RegisterPacketHandler (packetHandler);
41+ if (bNeedsScan) {
42+ CString name;
43+ for (int i = 1 ; i <= 8 ; i++)
44+ {
45+ if (s_registered[i]) continue ;
46+ name.Format (" umidi%d" , i);
47+ CUSBMIDIDevice *pDev = (CUSBMIDIDevice *)
48+ CDeviceNameService::Get ()->GetDevice ((const char *)name, FALSE );
49+ if (!pDev) continue ;
50+ s_pDevices[i] = pDev;
51+ s_registered[i] = true ;
52+ CLogger::Get ()->Write (log_name, LogNotice, " USB MIDI device connected: %s" , (const char *)name);
53+ pDev->RegisterPacketHandler (packetHandler);
54+ }
5455 }
5556}
5657
0 commit comments