DISTRHO Plugin Framework
Application.hpp
1 /*
2  * DISTRHO Plugin Framework (DPF)
3  * Copyright (C) 2012-2021 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 #ifndef DGL_APP_HPP_INCLUDED
18 #define DGL_APP_HPP_INCLUDED
19 
20 #include "Base.hpp"
21 
22 START_NAMESPACE_DGL
23 
24 // --------------------------------------------------------------------------------------------------------------------
25 
26 /**
27  Base DGL Application class.
28 
29  One application instance is required for creating a window.
30  There's no single/global application instance in DGL, and multiple windows can share the same app instance.
31 
32  In standalone mode an application will automatically quit its event-loop when all its windows are closed.
33 
34  Unless stated otherwise, functions within this class are not thread-safe.
35  */
37 {
38 public:
39  /**
40  Constructor.
41  */
42  // NOTE: the default value is not yet passed, so we catch where we use this
43  Application(bool isStandalone = true);
44 
45  /**
46  Destructor.
47  */
48  virtual ~Application();
49 
50  /**
51  Idle function.
52  This runs the application event-loop once.
53  */
54  void idle();
55 
56  /**
57  Run the application event-loop until all Windows are closed.
58  idle() is called at regular intervals.
59  @note This function is meant for standalones only, *never* call this from plugins.
60  */
61  void exec(uint idleTimeInMs = 30);
62 
63  /**
64  Quit the application.
65  This stops the event-loop and closes all Windows.
66  This function is thread-safe.
67  @note This function is meant for standalones only, *never* call this from plugins.
68  */
69  void quit();
70 
71  /**
72  Check if the application is about to quit.
73  Returning true means there's no event-loop running at the moment (or it's just about to stop).
74  This function is thread-safe.
75  */
76  bool isQuiting() const noexcept;
77 
78  /**
79  Add a callback function to be triggered on every idle cycle.
80  You can add more than one, and remove them at anytime with removeIdleCallback().
81  Idle callbacks trigger right after OS event handling and Window idle events (within the same cycle).
82  There are no guarantees in terms of timing, use Window::addIdleCallback for time-relative callbacks.
83  */
84  void addIdleCallback(IdleCallback* callback);
85 
86  /**
87  Remove an idle callback previously added via addIdleCallback().
88  */
89  void removeIdleCallback(IdleCallback* callback);
90 
91  /**
92  Set the class name of the application.
93 
94  This is a stable identifier for the application, used as the window class/instance name on X11 and Windows.
95  It is not displayed to the user, but can be used in scripts and by window managers,
96  so it should be the same for every instance of the application, but different from other applications.
97 
98  Plugins created with DPF have their class name automatically set based on DGL_NAMESPACE and plugin name.
99  */
100  void setClassName(const char* name);
101 
102 private:
103  struct PrivateData;
104  PrivateData* const pData;
105  friend class Window;
106 
107  DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Application)
108 };
109 
110 // --------------------------------------------------------------------------------------------------------------------
111 
112 END_NAMESPACE_DGL
113 
114 #endif // DGL_APP_HPP_INCLUDED
Application::quit
void quit()
Application::removeIdleCallback
void removeIdleCallback(IdleCallback *callback)
Window
Definition: Window.hpp:50
Application::idle
void idle()
Application::isQuiting
bool isQuiting() const noexcept
Application
Definition: Application.hpp:36
Application::~Application
virtual ~Application()
Application::Application
Application(bool isStandalone=true)
Application::exec
void exec(uint idleTimeInMs=30)
Application::addIdleCallback
void addIdleCallback(IdleCallback *callback)
IdleCallback
Definition: Base.hpp:159
Application::setClassName
void setClassName(const char *name)