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
4.2KB

  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. CARLA_SAFE_EXCEPTION("postRtEventsRun()")
  65. }
  66. if (oscRegisted || (hasUi && ! needsSingleThread))
  67. {
  68. // ---------------------------------------------------
  69. // Update parameter outputs
  70. for (uint32_t j=0, pcount=plugin->getParameterCount(); j < pcount; ++j)
  71. {
  72. if (! plugin->isParameterOutput(j))
  73. continue;
  74. value = plugin->getParameterValue(j);
  75. // Update OSC engine client
  76. if (oscRegisted)
  77. {
  78. #ifdef BUILD_BRIDGE
  79. fEngine->oscSend_bridge_parameter_value(j, value);
  80. #else
  81. fEngine->oscSend_control_set_parameter_value(i, static_cast<int32_t>(j), value);
  82. #endif
  83. }
  84. // Update UI
  85. if (hasUi && ! needsSingleThread)
  86. plugin->uiParameterChange(j, value);
  87. }
  88. }
  89. #ifndef BUILD_BRIDGE
  90. // -------------------------------------------------------
  91. // Update OSC control client peaks
  92. if (oscRegisted)
  93. fEngine->oscSend_control_set_peaks(i);
  94. #endif
  95. }
  96. }
  97. #ifdef BUILD_BRIDGE
  98. // ---------------------------------------------------------------
  99. // Send pong
  100. if (oscRegisted)
  101. fEngine->oscSend_bridge_pong();
  102. #endif
  103. carla_msleep(25);
  104. }
  105. }
  106. // -----------------------------------------------------------------------
  107. CARLA_BACKEND_END_NAMESPACE