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.

120 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. : CarlaThread("CarlaEngineThread"),
  24. fEngine(engine)
  25. {
  26. CARLA_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_ASSERT(fEngine->isRunning());
  38. carla_debug("CarlaEngineThread::run()");
  39. bool oscRegisted, needsSingleThread;
  40. float value;
  41. for (; fEngine->isRunning() && ! shouldExit();)
  42. {
  43. #ifdef BUILD_BRIDGE
  44. oscRegisted = fEngine->isOscBridgeRegistered();
  45. #else
  46. oscRegisted = fEngine->isOscControlRegistered();
  47. #endif
  48. for (unsigned int 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_INT2(i == plugin->getId(), i, plugin->getId());
  53. needsSingleThread = (plugin->getHints() & PLUGIN_NEEDS_SINGLE_THREAD);
  54. // -----------------------------------------------------------
  55. // Process postponed events
  56. if (oscRegisted || ! needsSingleThread)
  57. {
  58. if (! needsSingleThread)
  59. plugin->postRtEventsRun();
  60. // -------------------------------------------------------
  61. // Update parameter outputs
  62. for (uint32_t j=0, pcount=plugin->getParameterCount(); j < pcount; ++j)
  63. {
  64. if (! plugin->isParameterOutput(j))
  65. continue;
  66. value = plugin->getParameterValue(j);
  67. // Update UI
  68. if (! needsSingleThread)
  69. plugin->uiParameterChange(j, value);
  70. // Update OSC engine client
  71. if (oscRegisted)
  72. {
  73. #ifdef BUILD_BRIDGE
  74. fEngine->oscSend_bridge_parameter_value(j, value);
  75. #else
  76. fEngine->oscSend_control_set_parameter_value(i, j, value);
  77. #endif
  78. }
  79. }
  80. #ifndef BUILD_BRIDGE
  81. // ---------------------------------------------------
  82. // Update OSC control client peaks
  83. if (oscRegisted)
  84. fEngine->oscSend_control_set_peaks(i);
  85. #endif
  86. }
  87. }
  88. fEngine->idleOsc();
  89. carla_msleep(oscRegisted ? 30 : 50);
  90. }
  91. }
  92. // -----------------------------------------------------------------------
  93. CARLA_BACKEND_END_NAMESPACE