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.

135 lines
4.3KB

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