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.

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