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.5KB

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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. if (isOk())
  47. return;
  48. CarlaString path(getResourceDir() + fExtUiPath);
  49. carla_stdout("Trying to start UI using \"%s\"", path.buffer());
  50. CarlaExternalUI::setData(path, getSampleRate(), getUiName());
  51. CarlaExternalUI::start();
  52. }
  53. else
  54. {
  55. CarlaExternalUI::stop();
  56. }
  57. }
  58. void uiIdle() override
  59. {
  60. CarlaExternalUI::idle();
  61. if (! CarlaExternalUI::isOk())
  62. return;
  63. switch (CarlaExternalUI::getAndResetUiState())
  64. {
  65. case CarlaExternalUI::UiNone:
  66. case CarlaExternalUI::UiShow:
  67. break;
  68. case CarlaExternalUI::UiCrashed:
  69. hostUiUnavailable();
  70. break;
  71. case CarlaExternalUI::UiHide:
  72. uiClosed();
  73. CarlaExternalUI::stop();
  74. break;
  75. }
  76. }
  77. void uiSetParameterValue(const uint32_t index, const float value) override
  78. {
  79. CARLA_SAFE_ASSERT_RETURN(index < getParameterCount(),);
  80. char tmpBuf[0xff+1];
  81. const CarlaMutexLocker cml(fWriteLock);
  82. writeMsg("control\n", 8);
  83. std::sprintf(tmpBuf, "%i\n", index);
  84. writeMsg(tmpBuf);
  85. std::sprintf(tmpBuf, "%f\n", value);
  86. writeMsg(tmpBuf);
  87. }
  88. void uiSetMidiProgram(const uint8_t channel, const uint32_t bank, const uint32_t program) override
  89. {
  90. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
  91. char tmpBuf[0xff+1];
  92. const CarlaMutexLocker cml(fWriteLock);
  93. writeMsg("program\n", 8);
  94. std::sprintf(tmpBuf, "%i\n", channel);
  95. writeMsg(tmpBuf);
  96. std::sprintf(tmpBuf, "%i\n", bank);
  97. writeMsg(tmpBuf);
  98. std::sprintf(tmpBuf, "%i\n", program);
  99. writeMsg(tmpBuf);
  100. }
  101. void uiSetCustomData(const char* const key, const char* const value) override
  102. {
  103. CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0',);
  104. CARLA_SAFE_ASSERT_RETURN(value != nullptr,);
  105. const CarlaMutexLocker cml(fWriteLock);
  106. writeMsg("configure\n", 10);
  107. writeAndFixMsg(key);
  108. writeAndFixMsg(value);
  109. }
  110. // -------------------------------------------------------------------
  111. // Pipe Server calls
  112. bool msgReceived(const char* const msg) noexcept override
  113. {
  114. if (CarlaExternalUI::msgReceived(msg))
  115. return true;
  116. if (std::strcmp(msg, "control") == 0)
  117. {
  118. uint32_t param;
  119. float value;
  120. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(param), true);
  121. CARLA_SAFE_ASSERT_RETURN(readNextLineAsFloat(value), true);
  122. try {
  123. uiParameterChanged(param, value);
  124. } catch(...) {}
  125. return true;
  126. }
  127. if (std::strcmp(msg, "program") == 0)
  128. {
  129. uint32_t channel, bank, program;
  130. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(channel), true);
  131. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(bank), true);
  132. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(program), true);
  133. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS, true);
  134. try {
  135. uiMidiProgramChanged(channel, bank, program);
  136. } catch(...) {}
  137. return true;
  138. }
  139. if (std::strcmp(msg, "configure") == 0)
  140. {
  141. const char* key;
  142. const char* value;
  143. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(key), true);
  144. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(value), true);
  145. try {
  146. uiCustomDataChanged(key, value);
  147. } catch(...) {}
  148. delete[] key;
  149. delete[] value;
  150. return true;
  151. }
  152. carla_stderr("msgReceived : %s", msg);
  153. return false;
  154. }
  155. private:
  156. CarlaString fExtUiPath;
  157. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(NativePluginAndUiClass)
  158. };
  159. /**@}*/
  160. // -----------------------------------------------------------------------
  161. #endif // CARLA_NATIVE_EXTERNAL_UI_HPP_INCLUDED