Cleanup
[carla.git] / source / modules / dgl / src / Application.cpp
blob0ec4de820234b70228858d2ff84001ffb80c0d52
1 /*
2 * DISTRHO Plugin Framework (DPF)
3 * Copyright (C) 2012-2022 Filipe Coelho <falktx@falktx.com>
5 * Permission to use, copy, modify, and/or distribute this software for any purpose with
6 * or without fee is hereby granted, provided that the above copyright notice and this
7 * permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
10 * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
11 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
12 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
13 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #include "ApplicationPrivateData.hpp"
19 #ifdef __EMSCRIPTEN__
20 # include <emscripten/emscripten.h>
21 #endif
23 START_NAMESPACE_DGL
25 // --------------------------------------------------------------------------------------------------------------------
27 #ifdef __EMSCRIPTEN__
28 static void app_idle(void* const app)
30 static_cast<Application*>(app)->idle();
32 #endif
34 Application::Application(const bool isStandalone)
35 : pData(new PrivateData(isStandalone)) {}
37 Application::~Application()
39 delete pData;
42 void Application::idle()
44 pData->idle(0);
47 void Application::exec(const uint idleTimeInMs)
49 DISTRHO_SAFE_ASSERT_RETURN(pData->isStandalone,);
51 #ifdef __EMSCRIPTEN__
52 emscripten_set_main_loop_arg(app_idle, this, 0, true);
53 #else
54 while (! pData->isQuitting)
55 pData->idle(idleTimeInMs);
56 #endif
59 void Application::quit()
61 pData->quit();
64 bool Application::isQuitting() const noexcept
66 return pData->isQuitting || pData->isQuittingInNextCycle;
69 bool Application::isStandalone() const noexcept
71 return pData->isStandalone;
74 double Application::getTime() const
76 return pData->getTime();
79 void Application::addIdleCallback(IdleCallback* const callback)
81 DISTRHO_SAFE_ASSERT_RETURN(callback != nullptr,)
83 pData->idleCallbacks.push_back(callback);
86 void Application::removeIdleCallback(IdleCallback* const callback)
88 DISTRHO_SAFE_ASSERT_RETURN(callback != nullptr,)
90 pData->idleCallbacks.remove(callback);
93 void Application::setClassName(const char* const name)
95 pData->setClassName(name);
98 // --------------------------------------------------------------------------------------------------------------------
100 END_NAMESPACE_DGL