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.

163 lines
5.3KB

  1. /*
  2. * Carla Plugin
  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.hpp"
  18. #include "carla_plugin.hpp"
  19. #include <QtCore/QProcess>
  20. CARLA_BACKEND_START_NAMESPACE
  21. const char* PluginThreadMode2str(const CarlaPluginThread::PluginThreadMode mode)
  22. {
  23. switch (mode)
  24. {
  25. case CarlaPluginThread::PLUGIN_THREAD_DSSI_GUI:
  26. return "PLUGIN_THREAD_DSSI_GUI";
  27. case CarlaPluginThread::PLUGIN_THREAD_LV2_GUI:
  28. return "PLUGIN_THREAD_LV2_GUI";
  29. case CarlaPluginThread::PLUGIN_THREAD_VST_GUI:
  30. return "PLUGIN_THREAD_VST_GUI";
  31. case CarlaPluginThread::PLUGIN_THREAD_BRIDGE:
  32. return "PLUGIN_THREAD_BRIDGE";
  33. }
  34. qWarning("CarlaPluginThread::PluginThreadMode2str(%i) - invalid mode", mode);
  35. return nullptr;
  36. }
  37. CarlaPluginThread::CarlaPluginThread(CarlaBackend::CarlaEngine* const engine_, CarlaBackend::CarlaPlugin* const plugin_, const PluginThreadMode mode_, QObject* const parent)
  38. : QThread(parent),
  39. engine(engine_),
  40. plugin(plugin_),
  41. mode(mode_)
  42. {
  43. qDebug("CarlaPluginThread::CarlaPluginThread(plugin:\"%s\", engine:\"%s\", %s)", plugin->name(), engine->getName(), PluginThreadMode2str(mode));
  44. m_process = nullptr;
  45. }
  46. CarlaPluginThread::~CarlaPluginThread()
  47. {
  48. if (m_process)
  49. delete m_process;
  50. }
  51. void CarlaPluginThread::setOscData(const char* const binary, const char* const label, const char* const data1)
  52. {
  53. m_binary = QString(binary);
  54. m_label = QString(label);
  55. m_data1 = QString(data1);
  56. }
  57. void CarlaPluginThread::run()
  58. {
  59. qDebug("CarlaPluginThread::run()");
  60. if (! m_process)
  61. m_process = new QProcess(nullptr);
  62. m_process->setProcessChannelMode(QProcess::ForwardedChannels);
  63. QStringList arguments;
  64. const char* name = plugin->name() ? plugin->name() : "(none)";
  65. switch (mode)
  66. {
  67. case PLUGIN_THREAD_DSSI_GUI:
  68. /* osc_url */ arguments << QString("%1/%2").arg(engine->getOscServerPathUDP()).arg(plugin->id());
  69. /* filename */ arguments << plugin->filename();
  70. /* label */ arguments << m_label;
  71. /* ui-title */ arguments << QString("%1 (GUI)").arg(plugin->name());
  72. break;
  73. case PLUGIN_THREAD_LV2_GUI:
  74. /* osc_url */ arguments << QString("%1/%2").arg(engine->getOscServerPathTCP()).arg(plugin->id());
  75. /* URI */ arguments << m_label;
  76. /* ui-URI */ arguments << m_data1;
  77. /* ui-title */ arguments << QString("%1 (GUI)").arg(plugin->name());
  78. break;
  79. case PLUGIN_THREAD_VST_GUI:
  80. /* osc_url */ arguments << QString("%1/%2").arg(engine->getOscServerPathTCP()).arg(plugin->id());
  81. /* filename */ arguments << plugin->filename();
  82. /* ui-title */ arguments << QString("%1 (GUI)").arg(plugin->name());
  83. break;
  84. case PLUGIN_THREAD_BRIDGE:
  85. /* osc_url */ arguments << QString("%1/%2").arg(engine->getOscServerPathTCP()).arg(plugin->id());
  86. /* stype */ arguments << m_data1;
  87. /* filename */ arguments << plugin->filename();
  88. /* name */ arguments << name;
  89. /* label */ arguments << m_label;
  90. break;
  91. }
  92. m_process->start(m_binary, arguments);
  93. m_process->waitForStarted();
  94. switch (mode)
  95. {
  96. case PLUGIN_THREAD_DSSI_GUI:
  97. case PLUGIN_THREAD_LV2_GUI:
  98. case PLUGIN_THREAD_VST_GUI:
  99. if (plugin->showOscGui())
  100. {
  101. m_process->waitForFinished(-1);
  102. if (m_process->exitCode() == 0)
  103. {
  104. // Hide
  105. engine->callback(CarlaBackend::CALLBACK_SHOW_GUI, plugin->id(), 0, 0, 0.0);
  106. qWarning("CarlaPluginThread::run() - GUI closed");
  107. }
  108. else
  109. {
  110. // Kill
  111. engine->callback(CarlaBackend::CALLBACK_SHOW_GUI, plugin->id(), -1, 0, 0.0);
  112. qWarning("CarlaPluginThread::run() - GUI crashed");
  113. break;
  114. }
  115. }
  116. else
  117. {
  118. qDebug("CarlaPluginThread::run() - GUI timeout");
  119. engine->callback(CarlaBackend::CALLBACK_SHOW_GUI, plugin->id(), 0, 0, 0.0);
  120. }
  121. break;
  122. case PLUGIN_THREAD_BRIDGE:
  123. m_process->waitForFinished(-1);
  124. if (m_process->exitCode() != 0)
  125. {
  126. qWarning("CarlaPluginThread::run() - bridge crashed");
  127. QString errorString = QString("Plugin '%1' has crashed!\n"
  128. "Saving now will lose its current settings.\n"
  129. "Please remove this plugin, and not rely on it from this point.").arg(plugin->name());
  130. //CarlaBackend::setLastError(errorString.toUtf8().constData());
  131. engine->callback(CarlaBackend::CALLBACK_ERROR, plugin->id(), 0, 0, 0.0);
  132. }
  133. break;
  134. }
  135. }
  136. CARLA_BACKEND_END_NAMESPACE