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

6 years ago
6 years ago
10 years ago
10 years ago
10 years ago
6 years ago
6 years ago
6 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
10 years ago
10 years ago
10 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*
  2. * Carla Native Plugin API (C++)
  3. * Copyright (C) 2012-2016 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 pathToExternalUI)
  32. : NativePluginClass(host),
  33. CarlaExternalUI(),
  34. fExtUiPath(getResourceDir())
  35. {
  36. fExtUiPath += CARLA_OS_SEP_STR;
  37. fExtUiPath += pathToExternalUI;
  38. #ifdef CARLA_OS_WIN
  39. fExtUiPath += ".exe";
  40. #endif
  41. }
  42. const char* getExtUiPath() const noexcept
  43. {
  44. return fExtUiPath;
  45. }
  46. protected:
  47. // -------------------------------------------------------------------
  48. // Plugin UI calls
  49. void uiShow(const bool show) override
  50. {
  51. if (show)
  52. {
  53. if (isPipeRunning())
  54. {
  55. writeFocusMessage();
  56. return;
  57. }
  58. carla_stdout("Trying to start UI using \"%s\"", fExtUiPath.buffer());
  59. CarlaExternalUI::setData(fExtUiPath, getSampleRate(), getUiName());
  60. if (! CarlaExternalUI::startPipeServer(true))
  61. {
  62. uiClosed();
  63. hostUiUnavailable();
  64. }
  65. }
  66. else
  67. {
  68. CarlaExternalUI::stopPipeServer(2000);
  69. }
  70. }
  71. void uiIdle() override
  72. {
  73. CarlaExternalUI::idlePipe();
  74. switch (CarlaExternalUI::getAndResetUiState())
  75. {
  76. case CarlaExternalUI::UiNone:
  77. case CarlaExternalUI::UiShow:
  78. break;
  79. case CarlaExternalUI::UiCrashed:
  80. uiClosed();
  81. hostUiUnavailable();
  82. break;
  83. case CarlaExternalUI::UiHide:
  84. uiClosed();
  85. CarlaExternalUI::stopPipeServer(1000);
  86. break;
  87. }
  88. }
  89. void uiSetParameterValue(const uint32_t index, const float value) noexcept override
  90. {
  91. CARLA_SAFE_ASSERT_RETURN(index < getParameterCount(),);
  92. writeControlMessage(index, value);
  93. }
  94. void uiSetMidiProgram(const uint8_t channel, const uint32_t bank, const uint32_t program) noexcept override
  95. {
  96. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,);
  97. writeProgramMessage(channel, bank, program);
  98. }
  99. void uiSetCustomData(const char* const key, const char* const value) noexcept override
  100. {
  101. CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0',);
  102. CARLA_SAFE_ASSERT_RETURN(value != nullptr,);
  103. writeConfigureMessage(key, value);
  104. }
  105. void uiNameChanged(const char* const uiName) override
  106. {
  107. CARLA_SAFE_ASSERT_RETURN(uiName != nullptr && uiName[0] != '\0',);
  108. const CarlaMutexLocker cml(getPipeLock());
  109. if (! writeMessage("uiTitle\n", 8))
  110. return;
  111. if (! writeAndFixMessage(uiName))
  112. return;
  113. flushMessages();
  114. }
  115. // -------------------------------------------------------------------
  116. // Pipe Server calls
  117. bool msgReceived(const char* const msg) noexcept override
  118. {
  119. if (CarlaExternalUI::msgReceived(msg))
  120. return true;
  121. if (std::strcmp(msg, "control") == 0)
  122. {
  123. uint32_t param;
  124. float value;
  125. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(param), true);
  126. CARLA_SAFE_ASSERT_RETURN(readNextLineAsFloat(value), true);
  127. try {
  128. uiParameterChanged(param, value);
  129. } CARLA_SAFE_EXCEPTION("uiParameterChanged");
  130. return true;
  131. }
  132. if (std::strcmp(msg, "program") == 0)
  133. {
  134. uint32_t channel, bank, program;
  135. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(channel), true);
  136. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(bank), true);
  137. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(program), true);
  138. CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS, true);
  139. try {
  140. uiMidiProgramChanged(static_cast<uint8_t>(channel), bank, program);
  141. } CARLA_SAFE_EXCEPTION("uiMidiProgramChanged");
  142. return true;
  143. }
  144. if (std::strcmp(msg, "configure") == 0)
  145. {
  146. const char* key;
  147. const char* value;
  148. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(key), true);
  149. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(value), true);
  150. try {
  151. uiCustomDataChanged(key, value);
  152. } CARLA_SAFE_EXCEPTION("uiCustomDataChanged");
  153. delete[] key;
  154. delete[] value;
  155. return true;
  156. }
  157. return false;
  158. }
  159. private:
  160. CarlaString fExtUiPath;
  161. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(NativePluginAndUiClass)
  162. };
  163. /**@}*/
  164. // -----------------------------------------------------------------------
  165. #endif // CARLA_NATIVE_EXTERNAL_UI_HPP_INCLUDED