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.

129 lines
4.1KB

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