diff --git a/source/bridges-plugin/CarlaBridgePlugin.cpp b/source/bridges-plugin/CarlaBridgePlugin.cpp index 1f2a08ea8..333bbb854 100644 --- a/source/bridges-plugin/CarlaBridgePlugin.cpp +++ b/source/bridges-plugin/CarlaBridgePlugin.cpp @@ -19,6 +19,7 @@ #include "CarlaHost.h" #include "CarlaBackendUtils.hpp" +#include "CarlaMainLoop.hpp" #include "CarlaMIDI.h" #ifdef CARLA_OS_UNIX @@ -41,6 +42,7 @@ using CarlaBackend::CarlaEngine; using CarlaBackend::EngineCallbackOpcode; using CarlaBackend::EngineCallbackOpcode2Str; +using CarlaBackend::runMainLoopOnce; using juce::CharPointer_UTF8; using juce::File; @@ -173,10 +175,10 @@ public: gIsInitiated = true; - for (; ! gCloseNow;) + for (; runMainLoopOnce() && ! gCloseNow;) { gIdle(); - carla_msleep(8); + carla_msleep(1); } carla_set_engine_about_to_close(); diff --git a/source/utils/CarlaMainLoop.hpp b/source/utils/CarlaMainLoop.hpp new file mode 100644 index 000000000..e14de214e --- /dev/null +++ b/source/utils/CarlaMainLoop.hpp @@ -0,0 +1,52 @@ +/* + * Carla DSSI utils + * Copyright (C) 2017 Filipe Coelho + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * For a full copy of the GNU General Public License see the doc/GPL.txt file. + */ + +#ifndef CARLA_MAIN_LOOP_HPP_INCLUDED +#define CARLA_MAIN_LOOP_HPP_INCLUDED + +#include "CarlaBackend.h" +#include "CarlaUtils.hpp" + +// --------------------------------------------------------------------------------------------------------------------- + +CARLA_BACKEND_START_NAMESPACE + +bool runMainLoopOnce() +{ +#if defined(CARLA_OS_WIN) + MSG msg; + if (! ::PeekMessage(&msg, nullptr, 0, 0, PM_NOREMOVE)) + return true; + + if (::GetMessage(&msg, nullptr, 0, 0) >= 0) + { + if (msg.message == WM_QUIT) + return false; + + //TranslateMessage(&msg); + DispatchMessage(&msg); + } +#endif + + return true; +} + +CARLA_BACKEND_END_NAMESPACE + +// --------------------------------------------------------------------------------------------------------------------- + +#endif // CARLA_MAIN_LOOP_HPP_INCLUDED