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
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 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. : kEngine(engine),
  24. fStopNow(true)
  25. {
  26. carla_debug("CarlaEngineThread::CarlaEngineThread(%p)", engine);
  27. CARLA_ASSERT(engine != nullptr);
  28. }
  29. CarlaEngineThread::~CarlaEngineThread()
  30. {
  31. carla_debug("CarlaEngineThread::~CarlaEngineThread()");
  32. CARLA_ASSERT(fStopNow);
  33. }
  34. // -----------------------------------------------------------------------
  35. void CarlaEngineThread::startNow()
  36. {
  37. carla_debug("CarlaEngineThread::startNow()");
  38. CARLA_ASSERT(fStopNow);
  39. fStopNow = false;
  40. start();
  41. }
  42. void CarlaEngineThread::stopNow()
  43. {
  44. carla_debug("CarlaEngineThread::stopNow()");
  45. if (fStopNow)
  46. return;
  47. fStopNow = true;
  48. const CarlaMutex::ScopedLocker sl(&fMutex);
  49. if (isRunning() && ! wait(500))
  50. terminate();
  51. }
  52. // -----------------------------------------------------------------------
  53. void CarlaEngineThread::run()
  54. {
  55. carla_debug("CarlaEngineThread::run()");
  56. CARLA_ASSERT(kEngine->isRunning());
  57. bool oscRegisted, usesSingleThread;
  58. unsigned int i, count;
  59. float value;
  60. while (kEngine->isRunning() && ! fStopNow)
  61. {
  62. const CarlaMutex::ScopedLocker sl(&fMutex);
  63. #ifdef BUILD_BRIDGE
  64. oscRegisted = kEngine->isOscBridgeRegistered();
  65. #else
  66. oscRegisted = kEngine->isOscControlRegistered();
  67. #endif
  68. for (i=0, count = kEngine->currentPluginCount(); i < count; ++i)
  69. {
  70. CarlaPlugin* const plugin = kEngine->getPluginUnchecked(i);
  71. if (plugin == nullptr || ! plugin->enabled())
  72. continue;
  73. CARLA_SAFE_ASSERT_INT2(i == plugin->id(), i, plugin->id());
  74. usesSingleThread = (plugin->hints() & PLUGIN_HAS_SINGLE_THREAD);
  75. // -------------------------------------------------------
  76. // Process postponed events
  77. if (oscRegisted || ! usesSingleThread)
  78. {
  79. if (! usesSingleThread)
  80. plugin->postRtEventsRun();
  81. // ---------------------------------------------------
  82. // Update parameter outputs
  83. for (uint32_t j=0; j < plugin->parameterCount(); ++j)
  84. {
  85. if (! plugin->parameterIsOutput(j))
  86. continue;
  87. value = plugin->getParameterValue(j);
  88. // Update UI
  89. if (! usesSingleThread)
  90. plugin->uiParameterChange(j, value);
  91. // Update OSC engine client
  92. if (oscRegisted)
  93. {
  94. #ifdef BUILD_BRIDGE
  95. kEngine->osc_send_bridge_set_parameter_value(j, value);
  96. #else
  97. kEngine->osc_send_control_set_parameter_value(i, j, value);
  98. #endif
  99. }
  100. }
  101. #ifndef BUILD_BRIDGE
  102. // ---------------------------------------------------
  103. // Update OSC control client peaks
  104. if (oscRegisted)
  105. kEngine->osc_send_control_set_peaks(i);
  106. #endif
  107. }
  108. }
  109. kEngine->idleOsc();
  110. carla_msleep(oscRegisted ? 30 : 50);
  111. }
  112. }
  113. CARLA_BACKEND_END_NAMESPACE