DISTRHO Plugin Framework
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.

117 lines
3.9KB

  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. #ifndef DGL_APP_PRIVATE_DATA_HPP_INCLUDED
  17. #define DGL_APP_PRIVATE_DATA_HPP_INCLUDED
  18. #include "../Application.hpp"
  19. #include <list>
  20. #ifdef DISTRHO_OS_WINDOWS
  21. # ifndef NOMINMAX
  22. # define NOMINMAX
  23. # endif
  24. # include <winsock2.h>
  25. # include <windows.h>
  26. typedef HANDLE d_ThreadHandle;
  27. #else
  28. # include <pthread.h>
  29. typedef pthread_t d_ThreadHandle;
  30. #endif
  31. #ifdef DISTRHO_OS_MAC
  32. typedef struct PuglWorldImpl PuglWorld;
  33. #endif
  34. START_NAMESPACE_DGL
  35. class Window;
  36. #ifndef DISTRHO_OS_MAC
  37. typedef struct PuglWorldImpl PuglWorld;
  38. #endif
  39. // --------------------------------------------------------------------------------------------------------------------
  40. struct Application::PrivateData {
  41. /** Pugl world instance. */
  42. PuglWorld* const world;
  43. /** Whether the application is running as standalone, otherwise it is part of a plugin. */
  44. const bool isStandalone;
  45. /** Whether the applicating is about to quit, or already stopped. Defaults to false. */
  46. bool isQuitting;
  47. /** Helper for safely close everything from main thread. */
  48. bool isQuittingInNextCycle;
  49. /** Whether the applicating is starting up, that is, no windows have been made visible yet. Defaults to true. */
  50. bool isStarting;
  51. /** Counter of visible windows, only used in standalone mode.
  52. If 0->1, application is starting. If 1->0, application is quitting/stopping. */
  53. uint visibleWindows;
  54. /** Handle that identifies the main thread. Used to check if calls belong to current thread or not. */
  55. d_ThreadHandle mainThreadHandle;
  56. /** List of windows for this application. Only used during `close`. */
  57. std::list<DGL_NAMESPACE::Window*> windows;
  58. /** List of idle callbacks for this application. */
  59. std::list<DGL_NAMESPACE::IdleCallback*> idleCallbacks;
  60. /** Constructor and destructor */
  61. explicit PrivateData(bool standalone);
  62. ~PrivateData();
  63. /** Flag one window as shown, which increments @a visibleWindows.
  64. Sets @a isQuitting and @a isStarting as false if this is the first window.
  65. For standalone mode only. */
  66. void oneWindowShown() noexcept;
  67. /** Flag one window as closed, which decrements @a visibleWindows.
  68. Sets @a isQuitting as true if this is the last window.
  69. For standalone mode only. */
  70. void oneWindowClosed() noexcept;
  71. /** Run Pugl world update for @a timeoutInMs, and then each idle callback in order of registration. */
  72. void idle(uint timeoutInMs);
  73. /** Run each idle callback without updating pugl world. */
  74. void triggerIdleCallbacks();
  75. /** Set flag indicating application is quitting, and close all windows in reverse order of registration.
  76. For standalone mode only. */
  77. void quit();
  78. /** Get time via pugl */
  79. double getTime() const;
  80. /** Set pugl world class name. */
  81. void setClassName(const char* name);
  82. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PrivateData)
  83. };
  84. // --------------------------------------------------------------------------------------------------------------------
  85. END_NAMESPACE_DGL
  86. #endif // DGL_APP_PRIVATE_DATA_HPP_INCLUDED