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.

121 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. while (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. if (plugin == nullptr || ! plugin->isEnabled())
  52. continue;
  53. CARLA_SAFE_ASSERT_INT2(i == plugin->getId(), i, plugin->getId());
  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. // -------------------------------------------------------
  62. // Update parameter outputs
  63. for (uint32_t j=0, pcount=plugin->getParameterCount(); j < pcount; ++j)
  64. {
  65. if (! plugin->isParameterOutput(j))
  66. continue;
  67. value = plugin->getParameterValue(j);
  68. // Update UI
  69. if (! needsSingleThread)
  70. plugin->uiParameterChange(j, value);
  71. // Update OSC engine client
  72. if (oscRegisted)
  73. {
  74. #ifdef BUILD_BRIDGE
  75. fEngine->oscSend_bridge_set_parameter_value(j, value);
  76. #else
  77. fEngine->oscSend_control_set_parameter_value(i, j, value);
  78. #endif
  79. }
  80. }
  81. #ifndef BUILD_BRIDGE
  82. // ---------------------------------------------------
  83. // Update OSC control client peaks
  84. if (oscRegisted)
  85. fEngine->oscSend_control_set_peaks(i);
  86. #endif
  87. }
  88. }
  89. fEngine->idleOsc();
  90. carla_msleep(oscRegisted ? 30 : 50);
  91. }
  92. }
  93. // -----------------------------------------------------------------------
  94. CARLA_BACKEND_END_NAMESPACE