|
50 | 50 | #include "mpt/string/utility.hpp" |
51 | 51 | #include "openmpt/sounddevice/SoundDeviceManager.hpp" |
52 | 52 |
|
| 53 | +#include <thread> |
| 54 | + |
53 | 55 | #if MPT_MSVC_AT_LEAST(2022, 2) && MPT_MSVC_BEFORE(2022, 3) |
54 | 56 | // Work-around <https://developercommunity.visualstudio.com/t/warning-C4311-in-MFC-header-afxrecovery/10041328>, |
55 | 57 | // see <https://developercommunity.visualstudio.com/t/Compiler-warnings-after-upgrading-to-17/10036311#T-N10061908>. |
@@ -1541,6 +1543,21 @@ BOOL CTrackApp::InitInstanceImpl(CMPTCommandLineInfo &cmdInfo) |
1541 | 1543 | m_pSoundDevicesManager = std::make_unique<SoundDevice::Manager>(m_GlobalLogger, sysInfo, appInfo, std::move(deviceEnumerators)); |
1542 | 1544 | m_pTrackerSettings->MigrateOldSoundDeviceSettings(*m_pSoundDevicesManager); |
1543 | 1545 |
|
| 1546 | + // Windows 11 lazily initializes its MIDI service on first use, which can |
| 1547 | + // take several seconds as it scans for Bluetooth and Network MIDI devices. |
| 1548 | + // Once the service is running, the delay / hang when trying to use any |
| 1549 | + // MIDI APIs effectively disappears. |
| 1550 | + // To work around that, force some MIDI API usage on a separate thread to |
| 1551 | + // force-initialize MidiSrv. Adding an instance of the MIDI I/O plugin, |
| 1552 | + // reviewing MIDI settings or turning on MIDI recording should no longer |
| 1553 | + // hang on first use then. |
| 1554 | + // Note that this can still block the OpenMPT UI if the main thread |
| 1555 | + // enumerates MME audio devices at the same time, e.g. because the user |
| 1556 | + // opened the settings dialog, as there appears to be shared internal lock |
| 1557 | + // between these two APIs. |
| 1558 | + // See https://github.com/microsoft/MIDI/issues/1076 |
| 1559 | + std::thread{midiInGetNumDevs}.detach(); |
| 1560 | + |
1544 | 1561 | // Set default note names |
1545 | 1562 | CSoundFile::SetDefaultNoteNames(); |
1546 | 1563 |
|
|
0 commit comments