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.

CarlaNativeExtUI.hpp 5.3KB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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) noexcept 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. try {
  117. uiParameterChanged(param, value);
  118. } catch(...) {}
  119. return true;
  120. }
  121. if (std::strcmp(msg, "program") == 0)
  122. {
  123. uint32_t channel, bank, program;
  124. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(channel), true);
  125. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(bank), true);
  126. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(program), true);
  127. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS, true);
  128. try {
  129. uiMidiProgramChanged(channel, bank, program);
  130. } catch(...) {}
  131. return true;
  132. }
  133. if (std::strcmp(msg, "configure") == 0)
  134. {
  135. const char* key;
  136. const char* value;
  137. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(key), true);
  138. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(value), true);
  139. try {
  140. uiCustomDataChanged(key, value);
  141. } catch(...) {}
  142. delete[] key;
  143. delete[] value;
  144. return true;
  145. }
  146. carla_stderr("msgReceived : %s", msg);
  147. return false;
  148. }
  149. private:
  150. CarlaString fExtUiPath;
  151. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(NativePluginAndUiClass)
  152. };
  153. /**@}*/
  154. // -----------------------------------------------------------------------
  155. #endif // CARLA_NATIVE_EXTERNAL_UI_HPP_INCLUDED