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.

zynaddsubfx-ui.cpp 7.6KB

7 years ago
7 years ago
11 years ago
9 years ago
7 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /*
  2. * Carla Native Plugins
  3. * Copyright (C) 2012-2017 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. #include "CarlaString.hpp"
  18. #include "CarlaPipeUtils.hpp"
  19. #define PLUGINVERSION
  20. #define SOURCE_DIR "/usr/share/zynaddsubfx"
  21. #undef override
  22. #ifdef NTK_GUI
  23. # include <dlfcn.h>
  24. static CarlaString getResourceDir()
  25. {
  26. Dl_info exeInfo;
  27. dladdr((void*)getResourceDir, &exeInfo);
  28. CarlaString filename(exeInfo.dli_fname);
  29. return filename.truncate(filename.rfind("-ui"));
  30. }
  31. CarlaString gUiPixmapPath(getResourceDir());
  32. #endif
  33. // base c-style headers
  34. #include "zynaddsubfx/rtosc/rtosc.h"
  35. // rtosc c includes
  36. extern "C" {
  37. #include "zynaddsubfx/rtosc/dispatch.c"
  38. #include "zynaddsubfx/rtosc/rtosc.c"
  39. }
  40. // ignore some compiler warnings
  41. #if defined(__clang__)
  42. # pragma clang diagnostic push
  43. # pragma clang diagnostic ignored "-Winconsistent-missing-override"
  44. # pragma clang diagnostic ignored "-Wunused-private-field"
  45. #elif defined(__GNUC__) && (__GNUC__ >= 6)
  46. # pragma GCC diagnostic push
  47. # pragma GCC diagnostic ignored "-Wmisleading-indentation"
  48. # if (__GNUC__ >= 7)
  49. # pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
  50. # endif
  51. #endif
  52. // rtosc c++ includes
  53. #include "zynaddsubfx/rtosc/cpp/midimapper.cpp"
  54. #include "zynaddsubfx/rtosc/cpp/miditable.cpp"
  55. #undef RTOSC_INVALID_MIDI
  56. #undef MAX_UNHANDLED_PATH
  57. #include "zynaddsubfx/rtosc/cpp/ports.cpp"
  58. #undef __builtin_expect
  59. #include "zynaddsubfx/rtosc/cpp/subtree-serialize.cpp"
  60. #include "zynaddsubfx/rtosc/cpp/thread-link.cpp"
  61. #undef off_t
  62. #undef static
  63. #include "zynaddsubfx/rtosc/cpp/undo-history.cpp"
  64. // zynaddsubfx ui includes
  65. #include "zynaddsubfx/UI/NioUI.cpp"
  66. #include "zynaddsubfx/UI/WidgetPDial.cpp"
  67. #include "zynaddsubfx/UI/ADnoteUI.cpp"
  68. #include "zynaddsubfx/UI/BankUI.cpp"
  69. #include "zynaddsubfx/UI/BankView.cpp"
  70. #include "zynaddsubfx/UI/ConfigUI.cpp"
  71. // #include "zynaddsubfx/UI/Connection.cpp"
  72. #include "zynaddsubfx/UI/EffUI.cpp"
  73. #include "zynaddsubfx/UI/EnvelopeFreeEdit.cpp"
  74. #include "zynaddsubfx/UI/EnvelopeUI.cpp"
  75. #include "zynaddsubfx/UI/FilterUI.cpp"
  76. #include "zynaddsubfx/UI/Fl_EQGraph.cpp"
  77. #include "zynaddsubfx/UI/Fl_Osc_Button.cpp"
  78. #include "zynaddsubfx/UI/Fl_Osc_Check.cpp"
  79. #include "zynaddsubfx/UI/Fl_Osc_Choice.cpp"
  80. #include "zynaddsubfx/UI/Fl_Osc_Counter.cpp"
  81. #include "zynaddsubfx/UI/Fl_Osc_Dial.cpp"
  82. #include "zynaddsubfx/UI/Fl_Osc_DialF.cpp"
  83. #include "zynaddsubfx/UI/Fl_Osc_Input.cpp"
  84. #include "zynaddsubfx/UI/Fl_Osc_ListView.cpp"
  85. #include "zynaddsubfx/UI/Fl_Osc_Numeric_Input.cpp"
  86. #include "zynaddsubfx/UI/Fl_Osc_Output.cpp"
  87. #include "zynaddsubfx/UI/Fl_Osc_Pane.cpp"
  88. #include "zynaddsubfx/UI/Fl_Osc_Roller.cpp"
  89. #include "zynaddsubfx/UI/Fl_Osc_Slider.cpp"
  90. #include "zynaddsubfx/UI/Fl_Osc_TSlider.cpp"
  91. #include "zynaddsubfx/UI/Fl_Osc_Value.cpp"
  92. #include "zynaddsubfx/UI/Fl_Osc_VSlider.cpp"
  93. #include "zynaddsubfx/UI/Fl_Osc_Widget.cpp"
  94. #include "zynaddsubfx/UI/Fl_Resonance_Graph.cpp"
  95. #include "zynaddsubfx/UI/FormantFilterGraph.cpp"
  96. #include "zynaddsubfx/UI/LFOUI.cpp"
  97. #include "zynaddsubfx/UI/MasterUI.cpp"
  98. #include "zynaddsubfx/UI/MicrotonalUI.cpp"
  99. #include "zynaddsubfx/UI/OscilGenUI.cpp"
  100. #include "zynaddsubfx/UI/PADnoteUI.cpp"
  101. #include "zynaddsubfx/UI/PartNameButton.cpp"
  102. #include "zynaddsubfx/UI/PartUI.cpp"
  103. #include "zynaddsubfx/UI/PresetsUI.cpp"
  104. #include "zynaddsubfx/UI/ResonanceUI.cpp"
  105. #include "zynaddsubfx/UI/SUBnoteUI.cpp"
  106. #include "zynaddsubfx/UI/TipWin.cpp"
  107. #include "zynaddsubfx/UI/VirKeyboard.cpp"
  108. #include "zynaddsubfx/UI/guimain.cpp"
  109. #if defined(__clang__)
  110. # pragma clang diagnostic pop
  111. #elif defined(__GNUC__) && (__GNUC__ >= 6)
  112. # pragma GCC diagnostic pop
  113. #endif
  114. class ZynPipeClient : public CarlaPipeClient
  115. {
  116. public:
  117. ZynPipeClient() noexcept
  118. : CarlaPipeClient(),
  119. fQuitReceived(false) {}
  120. ~ZynPipeClient() noexcept override
  121. {
  122. if (fQuitReceived)
  123. return;
  124. writeExitingMessageAndWait();
  125. }
  126. protected:
  127. bool msgReceived(const char* const msg) noexcept override
  128. {
  129. if (std::strcmp(msg, "control") == 0)
  130. {
  131. uint index;
  132. float value;
  133. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(index), true);
  134. CARLA_SAFE_ASSERT_RETURN(readNextLineAsFloat(value), true);
  135. // TODO
  136. return true;
  137. }
  138. if (std::strcmp(msg, "program") == 0)
  139. {
  140. uint i;
  141. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(i), true);
  142. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(i), true);
  143. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(i), true);
  144. return true;
  145. }
  146. if (std::strcmp(msg, "show") == 0)
  147. {
  148. try {
  149. GUI::raiseUi(gui, "/show", "i", 1);
  150. } CARLA_SAFE_EXCEPTION("msgReceived show");
  151. return true;
  152. }
  153. if (std::strcmp(msg, "hide") == 0)
  154. {
  155. try {
  156. GUI::raiseUi(gui, "/hide", "");
  157. } CARLA_SAFE_EXCEPTION("msgReceived hide");
  158. return true;
  159. }
  160. if (std::strcmp(msg, "focus") == 0)
  161. {
  162. try {
  163. GUI::raiseUi(gui, "/focus", "");
  164. } CARLA_SAFE_EXCEPTION("msgReceived focus");
  165. return true;
  166. }
  167. if (std::strcmp(msg, "uiTitle") == 0)
  168. {
  169. const char* uiTitle;
  170. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(uiTitle), true);
  171. try {
  172. GUI::raiseUi(gui, "/ui/title", "s", uiTitle);
  173. } CARLA_SAFE_EXCEPTION("msgReceived uiTitle");
  174. return true;
  175. }
  176. if (std::strcmp(msg, "quit") == 0)
  177. {
  178. fQuitReceived = true;
  179. try {
  180. GUI::raiseUi(gui, "/close-ui", "");
  181. } CARLA_SAFE_EXCEPTION("msgReceived quit");
  182. return true;
  183. }
  184. carla_stderr("ZynPipeClient::msgReceived : %s", msg);
  185. return false;
  186. }
  187. private:
  188. bool fQuitReceived;
  189. };
  190. int main(int argc, const char* argv[])
  191. {
  192. ZynPipeClient pipe;
  193. const char* uiTitle = nullptr;
  194. if (argc > 1)
  195. {
  196. sendtourl = argv[1];
  197. uiTitle = argv[2];
  198. if (! pipe.initPipeClient(argv))
  199. return 1;
  200. server = lo_server_new_with_proto(NULL, LO_UDP, liblo_error_cb);
  201. lo_server_add_method(server, NULL, NULL, handler_function, 0);
  202. }
  203. std::thread lo_watch(watch_lo);
  204. gui = GUI::createUi(new UI_Interface(), &Pexitprogram);
  205. if (argc == 1)
  206. {
  207. // testing only
  208. GUI::raiseUi(gui, "/show", "i", 1);
  209. }
  210. else
  211. {
  212. // full thing
  213. isPlugin = true;
  214. MasterUI::menu_mastermenu[11].hide(); // file -> nio settings
  215. }
  216. if (uiTitle != nullptr && uiTitle[0] != '\0')
  217. GUI::raiseUi(gui, "/ui/title", "s", uiTitle);
  218. for (; Pexitprogram == 0;)
  219. {
  220. pipe.idlePipe();
  221. GUI::tickUi(gui);
  222. for (; lo_buffer.hasNext();)
  223. raiseUi(gui, lo_buffer.read());
  224. }
  225. GUI::destroyUi(gui);
  226. gui = nullptr;
  227. lo_watch.join();
  228. return 0;
  229. }
  230. #include "CarlaPipeUtils.cpp"
  231. #include "water/misc/Time.cpp"
  232. // --------------------------------------------------------------------------------------------