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.

136 lines
4.3KB

  1. /*
  2. * Carla Plugin Host
  3. * Copyright (C) 2011-2014 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 "CarlaEngine.hpp"
  18. #include "CarlaEngineThread.hpp"
  19. #include "CarlaPlugin.hpp"
  20. CARLA_BACKEND_START_NAMESPACE
  21. // -----------------------------------------------------------------------
  22. CarlaEngineThread::CarlaEngineThread(CarlaEngine* const engine) noexcept
  23. : CarlaThread("CarlaEngineThread"),
  24. fEngine(engine)
  25. {
  26. CARLA_SAFE_ASSERT(engine != nullptr);
  27. carla_debug("CarlaEngineThread::CarlaEngineThread(%p)", engine);
  28. }
  29. CarlaEngineThread::~CarlaEngineThread() noexcept
  30. {
  31. carla_debug("CarlaEngineThread::~CarlaEngineThread()");
  32. }
  33. // -----------------------------------------------------------------------
  34. void CarlaEngineThread::run() noexcept
  35. {
  36. CARLA_SAFE_ASSERT_RETURN(fEngine != nullptr,);
  37. CARLA_SAFE_ASSERT(fEngine->isRunning());
  38. carla_debug("CarlaEngineThread::run()");
  39. bool hasUi, oscRegisted, needsSingleThread;
  40. float value;
  41. for (; fEngine->isRunning() && ! shouldThreadExit();)
  42. {
  43. #ifdef BUILD_BRIDGE
  44. oscRegisted = fEngine->isOscBridgeRegistered();
  45. #else
  46. oscRegisted = fEngine->isOscControlRegistered();
  47. #endif
  48. for (uint i=0, count = fEngine->getCurrentPluginCount(); i < count; ++i)
  49. {
  50. CarlaPlugin* const plugin(fEngine->getPluginUnchecked(i));
  51. CARLA_SAFE_ASSERT_CONTINUE(plugin != nullptr && plugin->isEnabled());
  52. CARLA_SAFE_ASSERT_UINT2(i == plugin->getId(), i, plugin->getId());
  53. hasUi = (plugin->getHints() & PLUGIN_HAS_CUSTOM_UI);
  54. needsSingleThread = (plugin->getHints() & PLUGIN_NEEDS_SINGLE_THREAD);
  55. // -----------------------------------------------------------
  56. // Process postponed events
  57. if (oscRegisted || ! needsSingleThread)
  58. {
  59. if (! needsSingleThread)
  60. {
  61. try {
  62. plugin->postRtEventsRun();
  63. }
  64. catch (...) {
  65. carla_stderr2("Caught exception during postRtEventsRun()");
  66. }
  67. }
  68. if (hasUi || oscRegisted)
  69. {
  70. // ---------------------------------------------------
  71. // Update parameter outputs
  72. for (uint32_t j=0, pcount=plugin->getParameterCount(); j < pcount; ++j)
  73. {
  74. if (! plugin->isParameterOutput(j))
  75. continue;
  76. value = plugin->getParameterValue(j);
  77. // Update UI
  78. if (hasUi && ! needsSingleThread)
  79. plugin->uiParameterChange(j, value);
  80. // Update OSC engine client
  81. if (oscRegisted)
  82. {
  83. #ifdef BUILD_BRIDGE
  84. fEngine->oscSend_bridge_parameter_value(j, value);
  85. #else
  86. fEngine->oscSend_control_set_parameter_value(i, static_cast<int32_t>(j), value);
  87. #endif
  88. }
  89. }
  90. }
  91. #ifndef BUILD_BRIDGE
  92. // -------------------------------------------------------
  93. // Update OSC control client peaks
  94. if (oscRegisted)
  95. fEngine->oscSend_control_set_peaks(i);
  96. #endif
  97. }
  98. }
  99. #ifdef BUILD_BRIDGE
  100. // ---------------------------------------------------------------
  101. // Send pong
  102. if (oscRegisted)
  103. fEngine->oscSend_bridge_pong();
  104. #endif
  105. carla_msleep(25);
  106. }
  107. }
  108. // -----------------------------------------------------------------------
  109. CARLA_BACKEND_END_NAMESPACE