diff --git a/source/native-plugins/Makefile b/source/native-plugins/Makefile index cecd17c1a..edc91ff67 100644 --- a/source/native-plugins/Makefile +++ b/source/native-plugins/Makefile @@ -160,7 +160,7 @@ all: $(TARGETS) # ---------------------------------------------------------------------------------------------------------------------------- clean: - rm -f $(OBJDIR)/*.o $(MODULEDIR)/$(MODULENAME)*.a $(ZYN_UI_FILES_H) $(ZYN_UI_FILES_CPP) + rm -f $(OBJDIR)/*.o $(MODULEDIR)/$(MODULENAME)*.a $(ZYN_UI_FILES_H) $(ZYN_UI_FILES_CPP) $(TARGETS) debug: $(MAKE) DEBUG=true diff --git a/source/native-plugins/zynaddsubfx-ui.cpp b/source/native-plugins/zynaddsubfx-ui.cpp index ebbb60fd0..a96ebc2b5 100644 --- a/source/native-plugins/zynaddsubfx-ui.cpp +++ b/source/native-plugins/zynaddsubfx-ui.cpp @@ -150,8 +150,8 @@ int main(int argc, const char* argv[]) ZynPipeClient pipe; const char* uiTitle = nullptr; - // Startup Liblo Link - if (argc > 1) { + if (argc > 1) + { sendtourl = argv[1]; uiTitle = argv[2]; @@ -167,9 +167,12 @@ int main(int argc, const char* argv[]) if (argc == 1) GUI::raiseUi(gui, "/show", "i", 1); - while(Pexitprogram == 0) { - if(server) - while(lo_server_recv_noblock(server, 0)); + for (; Pexitprogram == 0;) + { + if (server != nullptr) { + for (; lo_server_recv_noblock(server, 0);) {} + } + pipe.idlePipe(); GUI::tickUi(gui); } @@ -180,56 +183,3 @@ int main(int argc, const char* argv[]) } // -------------------------------------------------------------------------------------------- -// we need juce::Time::getMillisecondCounter() - -#ifdef CARLA_OS_WIN - #include -#else - #include -#endif - -namespace juce { - -#include "juce_core/native/juce_BasicNativeHeaders.h" -#include "juce_core/juce_core.h" - -static uint32 lastMSCounterValue = 0; - -#ifdef CARLA_OS_WIN -uint32 juce_millisecondsSinceStartup() noexcept -{ - return (uint32) timeGetTime(); -} -#else -uint32 juce_millisecondsSinceStartup() noexcept -{ - timespec t; - clock_gettime (CLOCK_MONOTONIC, &t); - - return t.tv_sec * 1000 + t.tv_nsec / 1000000; -} -#endif - -uint32 Time::getMillisecondCounter() noexcept -{ - const uint32 now = juce_millisecondsSinceStartup(); - - if (now < lastMSCounterValue) - { - // in multi-threaded apps this might be called concurrently, so - // make sure that our last counter value only increases and doesn't - // go backwards.. - if (now < lastMSCounterValue - 1000) - lastMSCounterValue = now; - } - else - { - lastMSCounterValue = now; - } - - return now; -} - -} // namespace juce - -// -------------------------------------------------------------------------------------------- diff --git a/source/utils/CarlaPipeUtils.cpp b/source/utils/CarlaPipeUtils.cpp index 7840eb80a..ecdf52970 100644 --- a/source/utils/CarlaPipeUtils.cpp +++ b/source/utils/CarlaPipeUtils.cpp @@ -19,8 +19,6 @@ #include "CarlaString.hpp" #include "CarlaMIDI.h" -#include "juce_core.h" - // needed for atom-util #ifndef nullptr # undef NULL @@ -149,6 +147,40 @@ ssize_t WriteFileNonBlock(const HANDLE pipeh, const HANDLE cancelh, const void* } #endif // CARLA_OS_WIN +// ----------------------------------------------------------------------- +// getMillisecondCounter + +static uint32_t lastMSCounterValue = 0; + +static inline +uint32_t getMillisecondCounter() noexcept +{ + uint32_t now; + +#ifdef CARLA_OS_WIN + now = static_cast(timeGetTime()); +#else + timespec t; + clock_gettime(CLOCK_MONOTONIC, &t); + now = t.tv_sec * 1000 + t.tv_nsec / 1000000; +#endif + + if (now < lastMSCounterValue) + { + // in multi-threaded apps this might be called concurrently, so + // make sure that our last counter value only increases and doesn't + // go backwards.. + if (now < lastMSCounterValue - 1000) + lastMSCounterValue = now; + } + else + { + lastMSCounterValue = now; + } + + return now; +} + // ----------------------------------------------------------------------- // startProcess @@ -234,7 +266,7 @@ bool waitForClientFirstMessage(const P& pipe, const uint32_t timeOutMilliseconds char c; ssize_t ret; - const uint32_t timeoutEnd(juce::Time::getMillisecondCounter() + timeOutMilliseconds); + const uint32_t timeoutEnd(getMillisecondCounter() + timeOutMilliseconds); for (;;) { @@ -254,7 +286,7 @@ bool waitForClientFirstMessage(const P& pipe, const uint32_t timeOutMilliseconds if (errno == EAGAIN) #endif { - if (juce::Time::getMillisecondCounter() < timeoutEnd) + if (getMillisecondCounter() < timeoutEnd) { carla_msleep(5); continue; @@ -306,14 +338,14 @@ bool waitForProcessToStop(const PROCESS_INFORMATION& processInfo, const uint32_t // TODO - this code is completly wrong... - const uint32_t timeoutEnd(juce::Time::getMillisecondCounter() + timeOutMilliseconds); + const uint32_t timeoutEnd(getMillisecondCounter() + timeOutMilliseconds); for (;;) { if (WaitForSingleObject(processInfo.hProcess, 0) == WAIT_OBJECT_0) return true; - if (juce::Time::getMillisecondCounter() >= timeoutEnd) + if (getMillisecondCounter() >= timeoutEnd) break; carla_msleep(5); @@ -347,7 +379,7 @@ bool waitForChildToStop(const pid_t pid, const uint32_t timeOutMilliseconds) noe CARLA_SAFE_ASSERT_RETURN(timeOutMilliseconds > 0, false); pid_t ret; - const uint32_t timeoutEnd(juce::Time::getMillisecondCounter() + timeOutMilliseconds); + const uint32_t timeoutEnd(getMillisecondCounter() + timeOutMilliseconds); for (;;) { @@ -372,7 +404,7 @@ bool waitForChildToStop(const pid_t pid, const uint32_t timeOutMilliseconds) noe break; case 0: - if (juce::Time::getMillisecondCounter() < timeoutEnd) + if (getMillisecondCounter() < timeoutEnd) { carla_msleep(5); continue; @@ -1024,14 +1056,14 @@ const char* CarlaPipeCommon::_readline() const noexcept const char* CarlaPipeCommon::_readlineblock(const uint32_t timeOutMilliseconds) const noexcept { - const uint32_t timeoutEnd(juce::Time::getMillisecondCounter() + timeOutMilliseconds); + const uint32_t timeoutEnd(getMillisecondCounter() + timeOutMilliseconds); for (;;) { if (const char* const msg = _readline()) return msg; - if (juce::Time::getMillisecondCounter() >= timeoutEnd) + if (getMillisecondCounter() >= timeoutEnd) break; carla_msleep(5);