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.

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