Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
4.6KB

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