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.

CarlaEngineThread.cpp 4.3KB

11 years ago
10 years ago
10 years ago
9 years ago
10 years ago
10 years ago
10 years ago
11 years ago
11 years ago
10 years ago
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. const bool kIsPlugin = kEngine->getType() == kEngineTypePlugin;
  39. const bool kIsAlwaysRunning = kEngine->getType() == kEngineTypeBridge || kIsPlugin;
  40. float value;
  41. // thread must do something...
  42. CARLA_SAFE_ASSERT_RETURN(kIsAlwaysRunning || kEngine->isRunning(),);
  43. for (; (kIsAlwaysRunning || kEngine->isRunning()) && ! shouldThreadExit();)
  44. {
  45. #if defined(HAVE_LIBLO) && ! defined(BUILD_BRIDGE)
  46. const bool oscRegisted = kEngine->isOscControlRegistered();
  47. #else
  48. const bool oscRegisted = false;
  49. #endif
  50. #if defined(HAVE_LIBLO) && !defined(BUILD_BRIDGE)
  51. if (kIsPlugin)
  52. kEngine->idleOsc();
  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. carla_debug("CarlaEngineThread closed");
  103. }
  104. // -----------------------------------------------------------------------
  105. CARLA_BACKEND_END_NAMESPACE