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.

111 lines
3.3KB

  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. #include "ApplicationPrivateData.hpp"
  17. #include "../Window.hpp"
  18. #include "pugl-upstream/include/pugl/pugl.h"
  19. START_NAMESPACE_DGL
  20. // --------------------------------------------------------------------------------------------------------------------
  21. Application::PrivateData::PrivateData(const bool standalone)
  22. : world(puglNewWorld(standalone ? PUGL_PROGRAM : PUGL_MODULE,
  23. standalone ? PUGL_WORLD_THREADS : 0x0)),
  24. isStandalone(standalone),
  25. isStarting(true),
  26. isQuitting(false),
  27. visibleWindows(0),
  28. windows(),
  29. idleCallbacks()
  30. {
  31. DISTRHO_SAFE_ASSERT_RETURN(world != nullptr,);
  32. puglSetWorldHandle(world, this);
  33. puglSetClassName(world, DISTRHO_MACRO_AS_STRING(DGL_NAMESPACE));
  34. // puglSetLogLevel(world, PUGL_LOG_LEVEL_DEBUG);
  35. }
  36. Application::PrivateData::~PrivateData()
  37. {
  38. DISTRHO_SAFE_ASSERT(!isStarting);
  39. DISTRHO_SAFE_ASSERT(isQuitting);
  40. DISTRHO_SAFE_ASSERT(visibleWindows == 0);
  41. windows.clear();
  42. idleCallbacks.clear();
  43. if (world != nullptr)
  44. puglFreeWorld(world);
  45. }
  46. // --------------------------------------------------------------------------------------------------------------------
  47. void Application::PrivateData::oneWindowShown() noexcept
  48. {
  49. DISTRHO_SAFE_ASSERT_RETURN(isStandalone,);
  50. if (++visibleWindows == 1)
  51. {
  52. isStarting = false;
  53. isQuitting = false;
  54. }
  55. }
  56. void Application::PrivateData::oneWindowHidden() noexcept
  57. {
  58. DISTRHO_SAFE_ASSERT_RETURN(isStandalone,);
  59. DISTRHO_SAFE_ASSERT_RETURN(visibleWindows != 0,);
  60. if (--visibleWindows == 0)
  61. isQuitting = true;
  62. }
  63. void Application::PrivateData::idle(const uint timeoutInMs)
  64. {
  65. puglUpdate(world, timeoutInMs == 0 ? 0.0 : static_cast<double>(timeoutInMs) / 1000.0);
  66. for (std::list<Window*>::iterator it = windows.begin(), ite = windows.end(); it != ite; ++it)
  67. {
  68. Window* const window(*it);
  69. window->_idle();
  70. }
  71. for (std::list<IdleCallback*>::iterator it = idleCallbacks.begin(), ite = idleCallbacks.end(); it != ite; ++it)
  72. {
  73. IdleCallback* const idleCallback(*it);
  74. idleCallback->idleCallback();
  75. }
  76. }
  77. void Application::PrivateData::quit()
  78. {
  79. isQuitting = true;
  80. for (std::list<Window*>::reverse_iterator rit = windows.rbegin(), rite = windows.rend(); rit != rite; ++rit)
  81. {
  82. Window* const window(*rit);
  83. window->close();
  84. }
  85. }
  86. // --------------------------------------------------------------------------------------------------------------------
  87. END_NAMESPACE_DGL