comparison DPF-Prymula-audioplugins/dpf/dgl/src/Application.cpp @ 3:84e66ea83026

DPF-Prymula-audioplugins-0.231015-2
author prymula <prymula76@outlook.com>
date Mon, 16 Oct 2023 21:53:34 +0200
parents
children
comparison
equal deleted inserted replaced
2:cf2cb71d31dd 3:84e66ea83026
1 /*
2 * DISTRHO Plugin Framework (DPF)
3 * Copyright (C) 2012-2022 Filipe Coelho <falktx@falktx.com>
4 *
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.
8 *
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.
15 */
16
17 #include "ApplicationPrivateData.hpp"
18
19 #if defined(__EMSCRIPTEN__)
20 # include <emscripten/emscripten.h>
21 #elif defined(DISTRHO_OS_MAC)
22 # include <CoreFoundation/CoreFoundation.h>
23 #endif
24
25 START_NAMESPACE_DGL
26
27 // --------------------------------------------------------------------------------------------------------------------
28
29 #ifdef __EMSCRIPTEN__
30 static void app_idle(void* const app)
31 {
32 static_cast<Application*>(app)->idle();
33 }
34 #endif
35
36 Application::Application(const bool isStandalone)
37 : pData(new PrivateData(isStandalone)) {}
38
39 Application::~Application()
40 {
41 delete pData;
42 }
43
44 void Application::idle()
45 {
46 pData->idle(0);
47 }
48
49 void Application::exec(const uint idleTimeInMs)
50 {
51 DISTRHO_SAFE_ASSERT_RETURN(pData->isStandalone,);
52
53 #if defined(__EMSCRIPTEN__)
54 emscripten_set_main_loop_arg(app_idle, this, 0, true);
55 #elif defined(DISTRHO_OS_MAC)
56 const CFTimeInterval idleTimeInSecs = static_cast<CFTimeInterval>(idleTimeInMs) / 1000;
57
58 while (! pData->isQuitting)
59 {
60 pData->idle(0);
61
62 if (CFRunLoopRunInMode(kCFRunLoopDefaultMode, idleTimeInSecs, true) == kCFRunLoopRunFinished)
63 break;
64 }
65 #else
66 while (! pData->isQuitting)
67 pData->idle(idleTimeInMs);
68 #endif
69 }
70
71 void Application::quit()
72 {
73 pData->quit();
74 }
75
76 bool Application::isQuitting() const noexcept
77 {
78 return pData->isQuitting || pData->isQuittingInNextCycle;
79 }
80
81 bool Application::isStandalone() const noexcept
82 {
83 return pData->isStandalone;
84 }
85
86 double Application::getTime() const
87 {
88 return pData->getTime();
89 }
90
91 void Application::addIdleCallback(IdleCallback* const callback)
92 {
93 DISTRHO_SAFE_ASSERT_RETURN(callback != nullptr,)
94
95 pData->idleCallbacks.push_back(callback);
96 }
97
98 void Application::removeIdleCallback(IdleCallback* const callback)
99 {
100 DISTRHO_SAFE_ASSERT_RETURN(callback != nullptr,)
101
102 pData->idleCallbacks.remove(callback);
103 }
104
105 void Application::setClassName(const char* const name)
106 {
107 pData->setClassName(name);
108 }
109
110 // --------------------------------------------------------------------------------------------------------------------
111
112 END_NAMESPACE_DGL