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.

254 lines
7.0KB

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