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

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