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.

134 lines
3.1KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2014 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 "../App.hpp"
  17. #include "../Window.hpp"
  18. #include <list>
  19. START_NAMESPACE_DGL
  20. // -----------------------------------------------------------------------
  21. struct App::PrivateData {
  22. bool doLoop;
  23. unsigned visibleWindows;
  24. std::list<Window*> windows;
  25. std::list<IdleCallback*> idleCallbacks;
  26. PrivateData()
  27. : doLoop(false),
  28. visibleWindows(0) {}
  29. };
  30. // -----------------------------------------------------------------------
  31. App::App()
  32. : pData(new PrivateData())
  33. {
  34. }
  35. App::~App()
  36. {
  37. pData->windows.clear();
  38. pData->idleCallbacks.clear();
  39. delete pData;
  40. }
  41. void App::idle()
  42. {
  43. for (std::list<Window*>::iterator it = pData->windows.begin(); it != pData->windows.end(); ++it)
  44. {
  45. Window* const window(*it);
  46. window->_idle();
  47. }
  48. for (std::list<IdleCallback*>::iterator it = pData->idleCallbacks.begin(); it != pData->idleCallbacks.end(); ++it)
  49. {
  50. IdleCallback* const idleCallback(*it);
  51. idleCallback->idleCallback();
  52. }
  53. }
  54. void App::exec()
  55. {
  56. while (pData->doLoop)
  57. {
  58. idle();
  59. d_msleep(10);
  60. }
  61. }
  62. void App::quit()
  63. {
  64. pData->doLoop = false;
  65. for (std::list<Window*>::reverse_iterator rit = pData->windows.rbegin(); rit != pData->windows.rend(); ++rit)
  66. {
  67. Window* const window(*rit);
  68. window->close();
  69. }
  70. }
  71. bool App::isQuiting() const
  72. {
  73. return !pData->doLoop;
  74. }
  75. // -----------------------------------------------------------------------
  76. void App::addIdleCallback(IdleCallback* const callback)
  77. {
  78. if (callback != nullptr)
  79. pData->idleCallbacks.push_back(callback);
  80. }
  81. void App::removeIdleCallback(IdleCallback* const callback)
  82. {
  83. if (callback != nullptr)
  84. pData->idleCallbacks.remove(callback);
  85. }
  86. // -----------------------------------------------------------------------
  87. void App::_addWindow(Window* const window)
  88. {
  89. if (window != nullptr)
  90. pData->windows.push_back(window);
  91. }
  92. void App::_removeWindow(Window* const window)
  93. {
  94. if (window != nullptr)
  95. pData->windows.remove(window);
  96. }
  97. void App::_oneShown()
  98. {
  99. if (++pData->visibleWindows == 1)
  100. pData->doLoop = true;
  101. }
  102. void App::_oneHidden()
  103. {
  104. if (--pData->visibleWindows == 0)
  105. pData->doLoop = false;
  106. }
  107. // -----------------------------------------------------------------------
  108. END_NAMESPACE_DGL