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.0KB

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
10 years ago
11 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 hasUI, oscRegisted, needsSingleThread;
  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. hasUI = (plugin->getHints() & PLUGIN_HAS_CUSTOM_UI);
  55. needsSingleThread = (plugin->getHints() & PLUGIN_NEEDS_SINGLE_THREAD);
  56. // -----------------------------------------------------------
  57. // Process postponed events
  58. if (oscRegisted || ! needsSingleThread)
  59. {
  60. if (! needsSingleThread)
  61. {
  62. try {
  63. plugin->postRtEventsRun();
  64. } CARLA_SAFE_EXCEPTION("postRtEventsRun()")
  65. }
  66. if (oscRegisted || (hasUI && ! needsSingleThread))
  67. {
  68. // ---------------------------------------------------
  69. // Update parameter outputs
  70. for (uint32_t j=0, pcount=plugin->getParameterCount(); j < pcount; ++j)
  71. {
  72. if (! plugin->isParameterOutput(j))
  73. continue;
  74. value = plugin->getParameterValue(j);
  75. // Update OSC engine client
  76. if (oscRegisted)
  77. {
  78. #ifdef BUILD_BRIDGE
  79. kEngine->oscSend_bridge_parameter_value(j, value);
  80. #else
  81. kEngine->oscSend_control_set_parameter_value(i, static_cast<int32_t>(j), value);
  82. #endif
  83. }
  84. // Update UI
  85. if (hasUI && ! needsSingleThread)
  86. plugin->uiParameterChange(j, value);
  87. }
  88. }
  89. #ifndef BUILD_BRIDGE
  90. // -------------------------------------------------------
  91. // Update OSC control client peaks
  92. if (oscRegisted)
  93. kEngine->oscSend_control_set_peaks(i);
  94. #endif
  95. }
  96. }
  97. carla_msleep(25);
  98. }
  99. }
  100. // -----------------------------------------------------------------------
  101. CARLA_BACKEND_END_NAMESPACE