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.

273 lines
7.5KB

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