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.

141 lines
4.4KB

  1. /*
  2. * Carla Plugin Host
  3. * Copyright (C) 2011-2019 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 "CarlaEngineThread.hpp"
  18. #include "CarlaEngineInternal.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_debug("CarlaEngineThread::run()");
  38. const bool kIsPlugin = kEngine->getType() == kEngineTypePlugin;
  39. const bool kIsAlwaysRunning = kEngine->getType() == kEngineTypeBridge || kIsPlugin;
  40. float value;
  41. #if defined(HAVE_LIBLO) && ! defined(BUILD_BRIDGE)
  42. CarlaEngineOsc& engineOsc(kEngine->pData->osc);
  43. #endif
  44. // thread must do something...
  45. CARLA_SAFE_ASSERT_RETURN(kIsAlwaysRunning || kEngine->isRunning(),);
  46. for (; (kIsAlwaysRunning || kEngine->isRunning()) && ! shouldThreadExit();)
  47. {
  48. #if defined(HAVE_LIBLO) && ! defined(BUILD_BRIDGE)
  49. const bool oscRegisted = kEngine->isOscControlRegistered();
  50. #else
  51. const bool oscRegisted = false;
  52. #endif
  53. #if defined(HAVE_LIBLO) && !defined(BUILD_BRIDGE)
  54. if (kIsPlugin)
  55. engineOsc.idle();
  56. if (oscRegisted)
  57. engineOsc.sendRuntimeInfo();
  58. #endif
  59. for (uint i=0, count = kEngine->getCurrentPluginCount(); i < count; ++i)
  60. {
  61. CarlaPlugin* const plugin(kEngine->getPluginUnchecked(i));
  62. CARLA_SAFE_ASSERT_CONTINUE(plugin != nullptr && plugin->isEnabled());
  63. CARLA_SAFE_ASSERT_UINT2(i == plugin->getId(), i, plugin->getId());
  64. const uint hints(plugin->getHints());
  65. const bool updateUI((hints & PLUGIN_HAS_CUSTOM_UI) != 0 && (hints & PLUGIN_NEEDS_UI_MAIN_THREAD) == 0);
  66. // -----------------------------------------------------------
  67. // DSP Idle
  68. try {
  69. plugin->idle();
  70. } CARLA_SAFE_EXCEPTION("idle()")
  71. // -----------------------------------------------------------
  72. // Post-poned events
  73. if (oscRegisted || updateUI)
  74. {
  75. // -------------------------------------------------------
  76. // Update parameter outputs
  77. for (uint32_t j=0, pcount=plugin->getParameterCount(); j < pcount; ++j)
  78. {
  79. if (! plugin->isParameterOutput(j))
  80. continue;
  81. value = plugin->getParameterValue(j);
  82. #if defined(HAVE_LIBLO) && ! defined(BUILD_BRIDGE)
  83. // Update OSC engine client
  84. if (oscRegisted)
  85. engineOsc.sendParameterValue(i, j, value);
  86. #endif
  87. // Update UI
  88. if (updateUI)
  89. plugin->uiParameterChange(j, value);
  90. }
  91. if (updateUI)
  92. {
  93. try {
  94. plugin->uiIdle();
  95. } CARLA_SAFE_EXCEPTION("uiIdle()")
  96. }
  97. }
  98. #if defined(HAVE_LIBLO) && ! defined(BUILD_BRIDGE)
  99. // -----------------------------------------------------------
  100. // Update OSC control client peaks
  101. if (oscRegisted)
  102. engineOsc.sendPeaks(i, kEngine->getPeaks(i));
  103. #endif
  104. }
  105. carla_msleep(25);
  106. }
  107. carla_debug("CarlaEngineThread closed");
  108. }
  109. // -----------------------------------------------------------------------
  110. CARLA_BACKEND_END_NAMESPACE