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.

130 lines
4.0KB

  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. leakDetector_CarlaEngineThread()
  26. {
  27. CARLA_SAFE_ASSERT(engine != nullptr);
  28. carla_debug("CarlaEngineThread::CarlaEngineThread(%p)", engine);
  29. }
  30. CarlaEngineThread::~CarlaEngineThread() noexcept
  31. {
  32. carla_debug("CarlaEngineThread::~CarlaEngineThread()");
  33. }
  34. // -----------------------------------------------------------------------
  35. void CarlaEngineThread::run() noexcept
  36. {
  37. CARLA_SAFE_ASSERT_RETURN(kEngine != nullptr,);
  38. #ifndef BUILD_BRIDGE
  39. CARLA_SAFE_ASSERT(kEngine->isRunning());
  40. #endif
  41. carla_debug("CarlaEngineThread::run()");
  42. float value;
  43. #ifdef BUILD_BRIDGE
  44. for (; /*kEngine->isRunning() &&*/ ! shouldThreadExit();)
  45. #else
  46. for (; kEngine->isRunning() && ! shouldThreadExit();)
  47. #endif
  48. {
  49. #if defined(HAVE_LIBLO) && ! defined(BUILD_BRIDGE)
  50. const bool oscRegisted = kEngine->isOscControlRegistered();
  51. #else
  52. const bool oscRegisted = false;
  53. #endif
  54. for (uint i=0, count = kEngine->getCurrentPluginCount(); i < count; ++i)
  55. {
  56. CarlaPlugin* const plugin(kEngine->getPluginUnchecked(i));
  57. CARLA_SAFE_ASSERT_CONTINUE(plugin != nullptr && plugin->isEnabled());
  58. CARLA_SAFE_ASSERT_UINT2(i == plugin->getId(), i, plugin->getId());
  59. const uint hints(plugin->getHints());
  60. const bool updateUI((hints & PLUGIN_HAS_CUSTOM_UI) != 0 && (hints & PLUGIN_NEEDS_UI_MAIN_THREAD) == 0);
  61. // -----------------------------------------------------------
  62. // DSP Idle
  63. try {
  64. plugin->idle();
  65. } CARLA_SAFE_EXCEPTION("idle()")
  66. // -----------------------------------------------------------
  67. // Post-poned events
  68. if (oscRegisted || updateUI)
  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. #if defined(HAVE_LIBLO) && ! defined(BUILD_BRIDGE)
  78. // Update OSC engine client
  79. if (oscRegisted)
  80. kEngine->oscSend_control_set_parameter_value(i, static_cast<int32_t>(j), value);
  81. #endif
  82. // Update UI
  83. if (updateUI)
  84. plugin->uiParameterChange(j, value);
  85. }
  86. if (updateUI)
  87. {
  88. try {
  89. plugin->uiIdle();
  90. } CARLA_SAFE_EXCEPTION("uiIdle()")
  91. }
  92. }
  93. #if defined(HAVE_LIBLO) && ! defined(BUILD_BRIDGE)
  94. // -----------------------------------------------------------
  95. // Update OSC control client peaks
  96. if (oscRegisted)
  97. kEngine->oscSend_control_set_peaks(i);
  98. #endif
  99. }
  100. carla_msleep(25);
  101. }
  102. }
  103. // -----------------------------------------------------------------------
  104. CARLA_BACKEND_END_NAMESPACE