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.

CarlaEngineRunner.cpp 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * Carla Plugin Host
  3. * Copyright (C) 2011-2022 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #include "CarlaEngineRunner.hpp"
  18. #include "CarlaEngineInternal.hpp"
  19. #include "CarlaPlugin.hpp"
  20. #include "water/misc/Time.h"
  21. CARLA_BACKEND_START_NAMESPACE
  22. // -----------------------------------------------------------------------
  23. CarlaEngineRunner::CarlaEngineRunner(CarlaEngine* const engine) noexcept
  24. : CarlaRunner("CarlaEngineRunner"),
  25. kEngine(engine),
  26. fIsAlwaysRunning(false),
  27. fIsPlugin(false)
  28. {
  29. CARLA_SAFE_ASSERT(engine != nullptr);
  30. carla_debug("CarlaEngineRunner::CarlaEngineRunner(%p)", engine);
  31. }
  32. CarlaEngineRunner::~CarlaEngineRunner() noexcept
  33. {
  34. carla_debug("CarlaEngineRunner::~CarlaEngineRunner()");
  35. }
  36. void CarlaEngineRunner::start()
  37. {
  38. carla_debug("CarlaEngineRunner::start()");
  39. if (isRunnerActive())
  40. stopRunner();
  41. fIsPlugin = kEngine->getType() == kEngineTypePlugin;
  42. fIsAlwaysRunning = kEngine->getType() == kEngineTypeBridge || fIsPlugin;
  43. startRunner(25);
  44. }
  45. void CarlaEngineRunner::stop()
  46. {
  47. carla_debug("CarlaEngineRunner::stop()");
  48. stopRunner();
  49. }
  50. // -----------------------------------------------------------------------
  51. bool CarlaEngineRunner::run() noexcept
  52. {
  53. CARLA_SAFE_ASSERT_RETURN(kEngine != nullptr, false);
  54. float value;
  55. #if defined(HAVE_LIBLO) && ! defined(BUILD_BRIDGE)
  56. // int64_t lastPingTime = 0;
  57. const CarlaEngineOsc& engineOsc(kEngine->pData->osc);
  58. #endif
  59. // runner must do something...
  60. CARLA_SAFE_ASSERT_RETURN(fIsAlwaysRunning || kEngine->isRunning(), false);
  61. #if defined(HAVE_LIBLO) && ! defined(BUILD_BRIDGE)
  62. const bool oscRegistedForUDP = engineOsc.isControlRegisteredForUDP();
  63. #else
  64. const bool oscRegistedForUDP = false;
  65. #endif
  66. #if defined(HAVE_LIBLO) && !defined(BUILD_BRIDGE)
  67. if (fIsPlugin)
  68. engineOsc.idle();
  69. #endif
  70. for (uint i=0, count = kEngine->getCurrentPluginCount(); i < count; ++i)
  71. {
  72. const CarlaPluginPtr plugin = kEngine->getPluginUnchecked(i);
  73. CARLA_SAFE_ASSERT_CONTINUE(plugin.get() != nullptr && plugin->isEnabled());
  74. CARLA_SAFE_ASSERT_UINT2(i == plugin->getId(), i, plugin->getId());
  75. const uint hints = plugin->getHints();
  76. const bool updateUI = (hints & PLUGIN_HAS_CUSTOM_UI) != 0 && (hints & PLUGIN_NEEDS_UI_MAIN_THREAD) == 0;
  77. // -----------------------------------------------------------
  78. // DSP Idle
  79. try {
  80. plugin->idle();
  81. } CARLA_SAFE_EXCEPTION("idle()")
  82. // -----------------------------------------------------------
  83. // Post-poned events
  84. if (oscRegistedForUDP || updateUI)
  85. {
  86. // -------------------------------------------------------
  87. // Update parameter outputs
  88. for (uint32_t j=0, pcount=plugin->getParameterCount(); j < pcount; ++j)
  89. {
  90. if (! plugin->isParameterOutput(j))
  91. continue;
  92. value = plugin->getParameterValue(j);
  93. #if defined(HAVE_LIBLO) && ! defined(BUILD_BRIDGE)
  94. // Update OSC engine client
  95. if (oscRegistedForUDP)
  96. engineOsc.sendParameterValue(i, j, value);
  97. #endif
  98. // Update UI
  99. if (updateUI)
  100. plugin->uiParameterChange(j, value);
  101. }
  102. if (updateUI)
  103. {
  104. try {
  105. plugin->uiIdle();
  106. } CARLA_SAFE_EXCEPTION("uiIdle()")
  107. }
  108. }
  109. #if defined(HAVE_LIBLO) && ! defined(BUILD_BRIDGE)
  110. // -----------------------------------------------------------
  111. // Update OSC control client peaks
  112. if (oscRegistedForUDP)
  113. engineOsc.sendPeaks(i, kEngine->getPeaks(i));
  114. #endif
  115. }
  116. #if defined(HAVE_LIBLO) && !defined(BUILD_BRIDGE)
  117. if (oscRegistedForUDP)
  118. engineOsc.sendRuntimeInfo();
  119. /*
  120. if (engineOsc.isControlRegisteredForTCP())
  121. {
  122. const int64_t timeNow = water::Time::currentTimeMillis();
  123. if (timeNow - lastPingTime > 1000)
  124. {
  125. engineOsc.sendPing();
  126. lastPingTime = timeNow;
  127. }
  128. }
  129. */
  130. #endif
  131. return true;
  132. }
  133. // -----------------------------------------------------------------------
  134. CARLA_BACKEND_END_NAMESPACE