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.

188 lines
5.1KB

  1. /*
  2. * Carla Native Plugin API (C++)
  3. * Copyright (C) 2012-2014 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. #ifndef CARLA_NATIVE_EXTERNAL_UI_HPP_INCLUDED
  18. #define CARLA_NATIVE_EXTERNAL_UI_HPP_INCLUDED
  19. #include "CarlaNative.hpp"
  20. #include "CarlaExternalUI.hpp"
  21. /*!
  22. * @defgroup CarlaNativeAPI Carla Native API
  23. * @{
  24. */
  25. // -----------------------------------------------------------------------
  26. // Native Plugin and External UI class
  27. class NativePluginAndUiClass : public NativePluginClass,
  28. public CarlaExternalUI
  29. {
  30. public:
  31. NativePluginAndUiClass(const NativeHostDescriptor* const host, const char* const extUiPath)
  32. : NativePluginClass(host),
  33. fExtUiPath(extUiPath)
  34. {
  35. }
  36. ~NativePluginAndUiClass() override
  37. {
  38. }
  39. protected:
  40. // -------------------------------------------------------------------
  41. // Plugin UI calls
  42. void uiShow(const bool show) override
  43. {
  44. if (show)
  45. {
  46. CarlaString path(getResourceDir() + fExtUiPath);
  47. carla_stdout("Trying to start UI using \"%s\"", path.buffer());
  48. CarlaExternalUI::setData(path, getSampleRate(), getUiName());
  49. CarlaExternalUI::start();
  50. }
  51. else
  52. {
  53. CarlaExternalUI::stop();
  54. }
  55. }
  56. void uiIdle() override
  57. {
  58. CarlaExternalUI::idle();
  59. if (! CarlaExternalUI::isOk())
  60. return;
  61. switch (CarlaExternalUI::getAndResetUiState())
  62. {
  63. case CarlaExternalUI::UiNone:
  64. case CarlaExternalUI::UiShow:
  65. break;
  66. case CarlaExternalUI::UiCrashed:
  67. hostUiUnavailable();
  68. break;
  69. case CarlaExternalUI::UiHide:
  70. uiClosed();
  71. break;
  72. }
  73. }
  74. void uiSetParameterValue(const uint32_t index, const float value) override
  75. {
  76. CARLA_SAFE_ASSERT_RETURN(index < getParameterCount(),);
  77. char tmpBuf[0xff+1];
  78. writeMsg("control\n", 8);
  79. std::sprintf(tmpBuf, "%i\n", index);
  80. writeMsg(tmpBuf);
  81. std::sprintf(tmpBuf, "%f\n", value);
  82. writeMsg(tmpBuf);
  83. }
  84. void uiSetMidiProgram(const uint8_t channel, const uint32_t bank, const uint32_t program) override
  85. {
  86. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
  87. char tmpBuf[0xff+1];
  88. writeMsg("program\n", 8);
  89. std::sprintf(tmpBuf, "%i\n", channel);
  90. writeMsg(tmpBuf);
  91. std::sprintf(tmpBuf, "%i\n", bank);
  92. writeMsg(tmpBuf);
  93. std::sprintf(tmpBuf, "%i\n", program);
  94. writeMsg(tmpBuf);
  95. }
  96. void uiSetCustomData(const char* const key, const char* const value) override
  97. {
  98. CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0',);
  99. CARLA_SAFE_ASSERT_RETURN(value != nullptr,);
  100. writeMsg("configure\n", 10);
  101. writeAndFixMsg(key);
  102. writeAndFixMsg(value);
  103. }
  104. // -------------------------------------------------------------------
  105. // Pipe Server calls
  106. bool msgReceived(const char* const msg) override
  107. {
  108. if (CarlaExternalUI::msgReceived(msg))
  109. return true;
  110. if (std::strcmp(msg, "control") == 0)
  111. {
  112. uint32_t param;
  113. float value;
  114. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(param), true);
  115. CARLA_SAFE_ASSERT_RETURN(readNextLineAsFloat(value), true);
  116. uiParameterChanged(param, value);
  117. }
  118. else if (std::strcmp(msg, "program") == 0)
  119. {
  120. uint32_t channel, bank, program;
  121. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(channel), true);;
  122. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(bank), true);
  123. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(program), true);
  124. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS, true);
  125. uiMidiProgramChanged(channel, bank, program);
  126. }
  127. else if (std::strcmp(msg, "configure") == 0)
  128. {
  129. const char* key;
  130. const char* value;
  131. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(key), true);
  132. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(value), true);
  133. uiCustomDataChanged(key, value);
  134. delete[] key;
  135. delete[] value;
  136. }
  137. else
  138. {
  139. carla_stderr("msgReceived : %s", msg);
  140. return false;
  141. }
  142. return true;
  143. }
  144. private:
  145. CarlaString fExtUiPath;
  146. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(NativePluginAndUiClass)
  147. };
  148. /**@}*/
  149. // -----------------------------------------------------------------------
  150. #endif // CARLA_NATIVE_EXTERNAL_UI_HPP_INCLUDED