Collection of tools useful for audio production
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.

157 lines
4.8KB

  1. /*
  2. * Carla Engine
  3. * Copyright (C) 2012 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * 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 COPYING file
  16. */
  17. #include "carla_engine_thread.hpp"
  18. #include "carla_plugin.hpp"
  19. CarlaCheckThread::CarlaCheckThread(CarlaBackend::CarlaEngine* const engine_, QObject* const parent)
  20. : QThread(parent),
  21. engine(engine_)
  22. {
  23. qDebug("CarlaCheckThread::CarlaCheckThread(%p, %p)", engine, parent);
  24. CARLA_ASSERT(engine);
  25. }
  26. CarlaCheckThread::~CarlaCheckThread()
  27. {
  28. qDebug("CarlaCheckThread::~CarlaCheckThread()");
  29. }
  30. void CarlaCheckThread::startNow()
  31. {
  32. qDebug("CarlaCheckThread::startNow()");
  33. start(QThread::HighPriority);
  34. }
  35. void CarlaCheckThread::stopNow()
  36. {
  37. if (m_stopNow)
  38. return;
  39. m_stopNow = true;
  40. // TESTING - let processing finish first
  41. QMutexLocker(&this->mutex); // FIXME
  42. if (isRunning() && ! wait(200))
  43. {
  44. quit();
  45. if (isRunning() && ! wait(300))
  46. terminate();
  47. }
  48. }
  49. void CarlaCheckThread::run()
  50. {
  51. qDebug("CarlaCheckThread::run()");
  52. using namespace CarlaBackend;
  53. bool oscControlRegisted, usesSingleThread;
  54. unsigned short id, maxPluginNumber = CarlaEngine::maxPluginNumber();
  55. double value;
  56. m_stopNow = false;
  57. while (engine->isRunning() && ! m_stopNow)
  58. {
  59. const ScopedLocker m(this);
  60. oscControlRegisted = engine->isOscControlRegisted();
  61. #ifndef BUILD_BRIDGE
  62. if (engine->getType() != CarlaEngineTypePlugin)
  63. engine->oscWaitEvents();
  64. #endif
  65. for (unsigned short i=0; i < maxPluginNumber; i++)
  66. {
  67. CarlaPlugin* const plugin = engine->getPluginUnchecked(i);
  68. if (plugin && plugin->enabled())
  69. {
  70. id = plugin->id();
  71. usesSingleThread = (plugin->hints() & PLUGIN_USES_SINGLE_THREAD);
  72. // -------------------------------------------------------
  73. // Process postponed events
  74. if (! usesSingleThread)
  75. plugin->postEventsRun();
  76. // -------------------------------------------------------
  77. // Update parameter outputs
  78. if (oscControlRegisted || ! usesSingleThread)
  79. {
  80. for (uint32_t i=0; i < plugin->parameterCount(); i++)
  81. {
  82. if (plugin->parameterIsOutput(i))
  83. {
  84. value = plugin->getParameterValue(i);
  85. // Update UI
  86. if (! usesSingleThread)
  87. plugin->uiParameterChange(i, value);
  88. // Update OSC control client
  89. if (oscControlRegisted)
  90. {
  91. #ifdef BUILD_BRIDGE
  92. engine->osc_send_bridge_set_parameter_value(i, value);
  93. #else
  94. engine->osc_send_control_set_parameter_value(id, i, value);
  95. #endif
  96. }
  97. }
  98. }
  99. }
  100. // -------------------------------------------------------
  101. // Update OSC control client
  102. if (oscControlRegisted)
  103. {
  104. // Peak values
  105. if (plugin->audioInCount() > 0)
  106. {
  107. #ifdef BUILD_BRIDGE
  108. engine->osc_send_bridge_set_inpeak(1, engine->getInputPeak(id, 0));
  109. engine->osc_send_bridge_set_inpeak(2, engine->getInputPeak(id, 1));
  110. #else
  111. engine->osc_send_control_set_input_peak_value(id, 1, engine->getInputPeak(id, 0));
  112. engine->osc_send_control_set_input_peak_value(id, 2, engine->getInputPeak(id, 1));
  113. #endif
  114. }
  115. if (plugin->audioOutCount() > 0)
  116. {
  117. #ifdef BUILD_BRIDGE
  118. engine->osc_send_bridge_set_outpeak(1, engine->getOutputPeak(id, 0));
  119. engine->osc_send_bridge_set_outpeak(2, engine->getOutputPeak(id, 1));
  120. #else
  121. engine->osc_send_control_set_output_peak_value(id, 1, engine->getOutputPeak(id, 0));
  122. engine->osc_send_control_set_output_peak_value(id, 2, engine->getOutputPeak(id, 1));
  123. #endif
  124. }
  125. }
  126. }
  127. }
  128. msleep(50);
  129. }
  130. }