From 525e31073530115fe0500c7da006aaf7019c9aa1 Mon Sep 17 00:00:00 2001 From: Wohlstand Date: Thu, 1 Aug 2024 08:43:40 +0300 Subject: MidiPlay: Added an ugly workaround for macOS If the real sleep functions doesn't work as supposed, then, I will make own, ~~with blackjack and hookers~~ that tracks the clock to simulate the sleep. --- utils/midiplay/adlmidiplay.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/utils/midiplay/adlmidiplay.cpp b/utils/midiplay/adlmidiplay.cpp index 40cfa41..f5fb855 100644 --- a/utils/midiplay/adlmidiplay.cpp +++ b/utils/midiplay/adlmidiplay.cpp @@ -35,9 +35,14 @@ #include #include + #if defined(ADLMIDI_ENABLE_HW_SERIAL) && !defined(OUTPUT_WAVE_ONLY) # ifdef ADLMIDI_USE_SDL2 # include +#ifdef __APPLE__ +# include +#endif + static inline double s_getTime() { return SDL_GetTicks64() / 1000.0; @@ -45,7 +50,17 @@ static inline double s_getTime() static inline void s_sleepU(double s) { +#ifdef __APPLE__ + static double debt = 0.0; + double target = s_getTime() + s - debt; + + while(s_getTime() < target) + usleep(100); + + debt = s_getTime() - target; +#else SDL_Delay((Uint32)(s * 1000)); +#endif } # else -- cgit v1.2.3