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

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