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 #ifndef DGL_APP_HPP_INCLUDED
18 #define DGL_APP_HPP_INCLUDED
22 #ifdef DISTRHO_NAMESPACE
23 START_NAMESPACE_DISTRHO
24 class PluginApplication
;
30 // --------------------------------------------------------------------------------------------------------------------
33 Base DGL Application class.
35 One application instance is required for creating a window.
36 There's no single/global application instance in DGL, and multiple windows can share the same app instance.
38 In standalone mode an application will automatically quit its event-loop when all its windows are closed.
40 Unless stated otherwise, functions within this class are not thread-safe.
42 class DISTRHO_API Application
48 // NOTE: the default value is not yet passed, so we catch where we use this
49 Application(bool isStandalone
= true);
54 virtual ~Application();
58 This runs the application event-loop once.
63 Run the application event-loop until all Windows are closed.
64 idle() is called at regular intervals.
65 @note This function is meant for standalones only, *never* call this from plugins.
67 void exec(uint idleTimeInMs
= 30);
71 This stops the event-loop and closes all Windows.
72 This function is thread-safe.
77 Check if the application is about to quit.
78 Returning true means there's no event-loop running at the moment (or it's just about to stop).
79 This function is thread-safe.
81 bool isQuitting() const noexcept
;
84 Check if the application is standalone, otherwise running as a module or plugin.
85 This function is thread-safe.
87 bool isStandalone() const noexcept
;
90 Return the time in seconds.
92 This is a monotonically increasing clock with high resolution.@n
93 The returned time is only useful to compare against other times returned by this function,
94 its absolute value has no meaning.
96 double getTime() const;
99 Add a callback function to be triggered on every idle cycle.
100 You can add more than one, and remove them at anytime with removeIdleCallback().
101 Idle callbacks trigger right after OS event handling and Window idle events (within the same cycle).
102 There are no guarantees in terms of timing, use Window::addIdleCallback for time-relative callbacks.
104 void addIdleCallback(IdleCallback
* callback
);
107 Remove an idle callback previously added via addIdleCallback().
109 void removeIdleCallback(IdleCallback
* callback
);
112 Get the class name of the application.
114 This is a stable identifier for the application, used as the window class/instance name on X11 and Windows.
115 It is not displayed to the user, but can be used in scripts and by window managers,
116 so it should be the same for every instance of the application, but different from other applications.
118 Plugins created with DPF have their class name automatically set based on DGL_NAMESPACE and plugin name.
120 const char* getClassName() const noexcept
;
123 Set the class name of the application.
126 void setClassName(const char* name
);
130 PrivateData
* const pData
;
132 #ifdef DISTRHO_NAMESPACE
133 friend class DISTRHO_NAMESPACE::PluginApplication
;
136 DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Application
)
139 // --------------------------------------------------------------------------------------------------------------------
143 #endif // DGL_APP_HPP_INCLUDED