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.

CarlaEngineThread.cpp 4.9KB

11 years ago
10 years ago
10 years ago
9 years ago
10 years ago
10 years ago
10 years ago
11 years ago
11 years ago
10 years ago
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * Carla Plugin Host
  3. * Copyright (C) 2011-2019 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 "CarlaEngineThread.hpp"
  18. #include "CarlaEngineInternal.hpp"
  19. #include "CarlaPlugin.hpp"
  20. #include "water/misc/Time.h"
  21. CARLA_BACKEND_START_NAMESPACE
  22. // -----------------------------------------------------------------------
  23. CarlaEngineThread::CarlaEngineThread(CarlaEngine* const engine) noexcept
  24. : CarlaThread("CarlaEngineThread"),
  25. kEngine(engine)
  26. {
  27. CARLA_SAFE_ASSERT(engine != nullptr);
  28. carla_debug("CarlaEngineThread::CarlaEngineThread(%p)", engine);
  29. }
  30. CarlaEngineThread::~CarlaEngineThread() noexcept
  31. {
  32. carla_debug("CarlaEngineThread::~CarlaEngineThread()");
  33. }
  34. // -----------------------------------------------------------------------
  35. void CarlaEngineThread::run() noexcept
  36. {
  37. CARLA_SAFE_ASSERT_RETURN(kEngine != nullptr,);
  38. carla_debug("CarlaEngineThread::run()");
  39. const bool kIsPlugin = kEngine->getType() == kEngineTypePlugin;
  40. const bool kIsAlwaysRunning = kEngine->getType() == kEngineTypeBridge || kIsPlugin;
  41. float value;
  42. #if defined(HAVE_LIBLO) && ! defined(BUILD_BRIDGE)
  43. // int64_t lastPingTime = 0;
  44. const CarlaEngineOsc& engineOsc(kEngine->pData->osc);
  45. #endif
  46. // thread must do something...
  47. CARLA_SAFE_ASSERT_RETURN(kIsAlwaysRunning || kEngine->isRunning(),);
  48. for (; (kIsAlwaysRunning || kEngine->isRunning()) && ! shouldThreadExit();)
  49. {
  50. #if defined(HAVE_LIBLO) && ! defined(BUILD_BRIDGE)
  51. const bool oscRegistedForUDP = engineOsc.isControlRegisteredForUDP();
  52. #else
  53. const bool oscRegistedForUDP = false;
  54. #endif
  55. #if defined(HAVE_LIBLO) && !defined(BUILD_BRIDGE)
  56. if (kIsPlugin)
  57. engineOsc.idle();
  58. #endif
  59. for (uint i=0, count = kEngine->getCurrentPluginCount(); i < count; ++i)
  60. {
  61. CarlaPlugin* const plugin(kEngine->getPluginUnchecked(i));
  62. CARLA_SAFE_ASSERT_CONTINUE(plugin != nullptr && plugin->isEnabled());
  63. CARLA_SAFE_ASSERT_UINT2(i == plugin->getId(), i, plugin->getId());
  64. const uint hints(plugin->getHints());
  65. const bool updateUI((hints & PLUGIN_HAS_CUSTOM_UI) != 0 && (hints & PLUGIN_NEEDS_UI_MAIN_THREAD) == 0);
  66. // -----------------------------------------------------------
  67. // DSP Idle
  68. try {
  69. plugin->idle();
  70. } CARLA_SAFE_EXCEPTION("idle()")
  71. // -----------------------------------------------------------
  72. // Post-poned events
  73. if (oscRegistedForUDP || updateUI)
  74. {
  75. // -------------------------------------------------------
  76. // Update parameter outputs
  77. for (uint32_t j=0, pcount=plugin->getParameterCount(); j < pcount; ++j)
  78. {
  79. if (! plugin->isParameterOutput(j))
  80. continue;
  81. value = plugin->getParameterValue(j);
  82. #if defined(HAVE_LIBLO) && ! defined(BUILD_BRIDGE)
  83. // Update OSC engine client
  84. if (oscRegistedForUDP)
  85. engineOsc.sendParameterValue(i, j, value);
  86. #endif
  87. // Update UI
  88. if (updateUI)
  89. plugin->uiParameterChange(j, value);
  90. }
  91. if (updateUI)
  92. {
  93. try {
  94. plugin->uiIdle();
  95. } CARLA_SAFE_EXCEPTION("uiIdle()")
  96. }
  97. }
  98. #if defined(HAVE_LIBLO) && ! defined(BUILD_BRIDGE)
  99. // -----------------------------------------------------------
  100. // Update OSC control client peaks
  101. if (oscRegistedForUDP)
  102. engineOsc.sendPeaks(i, kEngine->getPeaks(i));
  103. #endif
  104. }
  105. #if defined(HAVE_LIBLO) && !defined(BUILD_BRIDGE)
  106. if (oscRegistedForUDP)
  107. engineOsc.sendRuntimeInfo();
  108. /*
  109. if (engineOsc.isControlRegisteredForTCP())
  110. {
  111. const int64_t timeNow = water::Time::currentTimeMillis();
  112. if (timeNow - lastPingTime > 1000)
  113. {
  114. engineOsc.sendPing();
  115. lastPingTime = timeNow;
  116. }
  117. }
  118. */
  119. #endif
  120. carla_msleep(25);
  121. }
  122. carla_debug("CarlaEngineThread closed");
  123. }
  124. // -----------------------------------------------------------------------
  125. CARLA_BACKEND_END_NAMESPACE