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 3.9KB

11 years ago
10 years ago
10 years ago
11 years ago
10 years ago
11 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
11 years ago
11 years ago
10 years ago
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. CARLA_SAFE_ASSERT(kEngine->isRunning());
  39. carla_debug("CarlaEngineThread::run()");
  40. bool needsSingleThread, needsUiUpdates, oscRegisted;
  41. float value;
  42. for (; kEngine->isRunning() && ! shouldThreadExit();)
  43. {
  44. #ifdef BUILD_BRIDGE
  45. oscRegisted = kEngine->isOscBridgeRegistered();
  46. #else
  47. oscRegisted = kEngine->isOscControlRegistered();
  48. #endif
  49. for (uint i=0, count = kEngine->getCurrentPluginCount(); i < count; ++i)
  50. {
  51. CarlaPlugin* const plugin(kEngine->getPluginUnchecked(i));
  52. CARLA_SAFE_ASSERT_CONTINUE(plugin != nullptr && plugin->isEnabled());
  53. CARLA_SAFE_ASSERT_UINT2(i == plugin->getId(), i, plugin->getId());
  54. needsSingleThread = (plugin->getHints() & PLUGIN_NEEDS_SINGLE_THREAD);
  55. needsUiUpdates = (plugin->getHints() & PLUGIN_HAS_CUSTOM_UI) && ! needsSingleThread;
  56. // -----------------------------------------------------------
  57. // Process postponed events
  58. if (! needsSingleThread)
  59. {
  60. try {
  61. plugin->postRtEventsRun();
  62. } CARLA_SAFE_EXCEPTION("postRtEventsRun()")
  63. }
  64. if (oscRegisted || needsUiUpdates)
  65. {
  66. // -------------------------------------------------------
  67. // Update parameter outputs
  68. for (uint32_t j=0, pcount=plugin->getParameterCount(); j < pcount; ++j)
  69. {
  70. if (! plugin->isParameterOutput(j))
  71. continue;
  72. value = plugin->getParameterValue(j);
  73. // Update OSC engine client
  74. if (oscRegisted)
  75. {
  76. #ifdef BUILD_BRIDGE
  77. kEngine->oscSend_bridge_parameter_value(j, value);
  78. #else
  79. kEngine->oscSend_control_set_parameter_value(i, static_cast<int32_t>(j), value);
  80. #endif
  81. }
  82. // Update UI
  83. if (needsUiUpdates)
  84. plugin->uiParameterChange(j, value);
  85. }
  86. }
  87. #ifndef BUILD_BRIDGE
  88. // -----------------------------------------------------------
  89. // Update OSC control client peaks
  90. if (oscRegisted)
  91. kEngine->oscSend_control_set_peaks(i);
  92. #endif
  93. }
  94. carla_msleep(25);
  95. }
  96. }
  97. // -----------------------------------------------------------------------
  98. CARLA_BACKEND_END_NAMESPACE