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