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.

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