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.

zita-at1-ui.cpp 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. #include "zita-at1/png2img.cc"
  19. #include "zita-at1/button.cc"
  20. #include "zita-at1/guiclass.cc"
  21. #include "zita-at1/mainwin.cc"
  22. #include "zita-at1/rotary.cc"
  23. #include "zita-at1/styles.cc"
  24. #include "zita-at1/tmeter.cc"
  25. using namespace AT1;
  26. static Mainwin* mainwin = nullptr;
  27. // --------------------------------------------------------------------------------------------
  28. class ZitaPipeClient : public CarlaPipeClient,
  29. public Mainwin::ValueChangedCallback
  30. {
  31. public:
  32. ZitaPipeClient() noexcept
  33. : CarlaPipeClient(),
  34. fQuitReceived(false) {}
  35. ~ZitaPipeClient() noexcept override
  36. {
  37. if (fQuitReceived || ! isPipeRunning())
  38. return;
  39. const CarlaMutexLocker cml(getPipeLock());
  40. writeMessage("exiting\n");
  41. flushMessages();
  42. }
  43. bool quitRequested() const noexcept
  44. {
  45. return fQuitReceived;
  46. }
  47. protected:
  48. bool msgReceived(const char* const msg) noexcept override
  49. {
  50. if (std::strcmp(msg, "zita-data") == 0)
  51. {
  52. float error;
  53. int noteset, midiset;
  54. CARLA_SAFE_ASSERT_RETURN(readNextLineAsFloat(error), true);
  55. CARLA_SAFE_ASSERT_RETURN(readNextLineAsInt(noteset), true);
  56. CARLA_SAFE_ASSERT_RETURN(readNextLineAsInt(midiset), true);
  57. mainwin->setdata_ui(error, noteset, midiset);
  58. return true;
  59. }
  60. if (std::strcmp(msg, "zita-mask") == 0)
  61. {
  62. uint mask;
  63. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(mask), true);
  64. mainwin->setmask_ui(mask);
  65. return true;
  66. }
  67. if (std::strcmp(msg, "control") == 0)
  68. {
  69. uint index;
  70. float value;
  71. CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(index), true);
  72. CARLA_SAFE_ASSERT_RETURN(readNextLineAsFloat(value), true);
  73. if (index < Mainwin::NROTARY)
  74. mainwin->_rotary[index]->set_value(value);
  75. else if (index == Mainwin::NROTARY) // == kParameterM_CHANNEL
  76. mainwin->setchan_ui(value);
  77. return true;
  78. }
  79. if (std::strcmp(msg, "show") == 0)
  80. {
  81. mainwin->x_map();
  82. return true;
  83. }
  84. if (std::strcmp(msg, "hide") == 0)
  85. {
  86. mainwin->x_unmap();
  87. return true;
  88. }
  89. if (std::strcmp(msg, "focus") == 0)
  90. {
  91. mainwin->x_mapraised();
  92. return true;
  93. }
  94. if (std::strcmp(msg, "uiTitle") == 0)
  95. {
  96. const char* uiTitle;
  97. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(uiTitle), true);
  98. mainwin->x_set_title(uiTitle);
  99. return true;
  100. }
  101. if (std::strcmp(msg, "quit") == 0)
  102. {
  103. fQuitReceived = true;
  104. mainwin->stop();
  105. return true;
  106. }
  107. carla_stderr("ZitaPipeClient::msgReceived : %s", msg);
  108. return false;
  109. }
  110. void noteMaskChangedCallback(int mask)
  111. {
  112. if (! isPipeRunning())
  113. return;
  114. char tmpBuf[0xff+1];
  115. tmpBuf[0xff] = '\0';
  116. std::snprintf(tmpBuf, 0xff, "%i\n", mask);
  117. const CarlaMutexLocker cml(getPipeLock());
  118. writeMessage("zita-mask\n", 10);
  119. writeMessage(tmpBuf);
  120. flushMessages();
  121. }
  122. void valueChangedCallback(uint index, float value) override
  123. {
  124. if (! isPipeRunning())
  125. return;
  126. writeControlMessage(index, value);
  127. }
  128. private:
  129. bool fQuitReceived;
  130. };
  131. // --------------------------------------------------------------------------------------------
  132. int main(int argc, const char* argv[])
  133. {
  134. X_resman xresman;
  135. X_display *display;
  136. X_handler *handler;
  137. X_rootwin *rootwin;
  138. int ev, xp, yp, xs, ys;
  139. int fake_argc = 1;
  140. char* fake_argv[] = { (char*)"rev1" };
  141. xresman.init(&fake_argc, fake_argv, (char*)"rev1", nullptr, 0);
  142. display = new X_display(nullptr);
  143. if (display->dpy () == 0)
  144. {
  145. carla_stderr("Can't open display.");
  146. delete display;
  147. return 1;
  148. }
  149. ZitaPipeClient pipe;
  150. const char* uiTitle = "Test UI";
  151. if (argc > 1)
  152. {
  153. uiTitle = argv[2];
  154. if (! pipe.initPipeClient(argv))
  155. return 1;
  156. }
  157. xp = yp = 100;
  158. xs = Mainwin::XSIZE + 4;
  159. ys = Mainwin::YSIZE + 30;
  160. xresman.geometry(".geometry", display->xsize(), display->ysize(), 1, xp, yp, xs, ys);
  161. styles_init(display, &xresman);
  162. rootwin = new X_rootwin(display);
  163. mainwin = new Mainwin(rootwin, &xresman, xp, yp, &pipe);
  164. mainwin->x_set_title(uiTitle);
  165. rootwin->handle_event();
  166. handler = new X_handler(display, mainwin, EV_X11);
  167. handler->next_event();
  168. XFlush(display->dpy());
  169. if (argc == 1)
  170. mainwin->x_map();
  171. do
  172. {
  173. ev = mainwin->process();
  174. if (ev == EV_X11)
  175. {
  176. rootwin->handle_event();
  177. handler->next_event();
  178. }
  179. else if (ev == Esync::EV_TIME)
  180. {
  181. handler->next_event();
  182. if (pipe.isPipeRunning())
  183. pipe.idlePipe();
  184. }
  185. }
  186. while (ev != EV_EXIT && ! pipe.quitRequested());
  187. styles_fini(display);
  188. delete handler;
  189. delete rootwin;
  190. delete display;
  191. return 0;
  192. }
  193. // --------------------------------------------------------------------------------------------