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.

123 lines
3.6KB

  1. /*
  2. * Carla Engine Thread
  3. * Copyright (C) 2012-2013 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 "CarlaEngineThread.hpp"
  18. #include "CarlaEngine.hpp"
  19. #include "CarlaPlugin.hpp"
  20. CARLA_BACKEND_START_NAMESPACE
  21. // -----------------------------------------------------------------------
  22. CarlaEngineThread::CarlaEngineThread(CarlaEngine* const engine)
  23. : Thread("CarlaEngineThread"),
  24. fEngine(engine)
  25. {
  26. CARLA_ASSERT(engine != nullptr);
  27. carla_debug("CarlaEngineThread::CarlaEngineThread(%p)", engine);
  28. setPriority(5);
  29. }
  30. CarlaEngineThread::~CarlaEngineThread()
  31. {
  32. carla_debug("CarlaEngineThread::~CarlaEngineThread()");
  33. }
  34. // -----------------------------------------------------------------------
  35. void CarlaEngineThread::run()
  36. {
  37. CARLA_SAFE_ASSERT_RETURN(fEngine != nullptr,);
  38. CARLA_ASSERT(fEngine->isRunning());
  39. carla_debug("CarlaEngineThread::run()");
  40. bool oscRegisted, needsSingleThread;
  41. float value;
  42. while (fEngine->isRunning() && ! threadShouldExit())
  43. {
  44. #ifdef BUILD_BRIDGE
  45. oscRegisted = fEngine->isOscBridgeRegistered();
  46. #else
  47. oscRegisted = fEngine->isOscControlRegistered();
  48. #endif
  49. for (unsigned int i=0, count = fEngine->getCurrentPluginCount(); i < count; ++i)
  50. {
  51. CarlaPlugin* const plugin(fEngine->getPluginUnchecked(i));
  52. if (plugin == nullptr || ! plugin->isEnabled())
  53. continue;
  54. CARLA_SAFE_ASSERT_INT2(i == plugin->getId(), i, plugin->getId());
  55. needsSingleThread = (plugin->getHints() & PLUGIN_NEEDS_SINGLE_THREAD);
  56. // -----------------------------------------------------------
  57. // Process postponed events
  58. if (oscRegisted || ! needsSingleThread)
  59. {
  60. if (! needsSingleThread)
  61. plugin->postRtEventsRun();
  62. // -------------------------------------------------------
  63. // Update parameter outputs
  64. for (uint32_t j=0, pcount=plugin->getParameterCount(); j < pcount; ++j)
  65. {
  66. if (! plugin->isParameterOutput(j))
  67. continue;
  68. value = plugin->getParameterValue(j);
  69. // Update UI
  70. if (! needsSingleThread)
  71. plugin->uiParameterChange(j, value);
  72. // Update OSC engine client
  73. if (oscRegisted)
  74. {
  75. #ifdef BUILD_BRIDGE
  76. fEngine->oscSend_bridge_set_parameter_value(j, value);
  77. #else
  78. fEngine->oscSend_control_set_parameter_value(i, j, value);
  79. #endif
  80. }
  81. }
  82. #ifndef BUILD_BRIDGE
  83. // ---------------------------------------------------
  84. // Update OSC control client peaks
  85. if (oscRegisted)
  86. fEngine->oscSend_control_set_peaks(i);
  87. #endif
  88. }
  89. }
  90. fEngine->idleOsc();
  91. Thread::sleep(oscRegisted ? 30 : 50);
  92. }
  93. }
  94. // -----------------------------------------------------------------------
  95. CARLA_BACKEND_END_NAMESPACE