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.

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