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.

196 lines
4.8KB

  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-bls1/png2img.cc"
  19. #include "zita-bls1/guiclass.cc"
  20. #include "zita-bls1/mainwin.cc"
  21. #include "zita-bls1/rotary.cc"
  22. #include "zita-bls1/styles.cc"
  23. using namespace BLS1;
  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. mainwin->_rotary[index]->set_value(value);
  55. return true;
  56. }
  57. if (std::strcmp(msg, "show") == 0)
  58. {
  59. mainwin->x_map();
  60. return true;
  61. }
  62. if (std::strcmp(msg, "hide") == 0)
  63. {
  64. mainwin->x_unmap();
  65. return true;
  66. }
  67. if (std::strcmp(msg, "focus") == 0)
  68. {
  69. mainwin->x_mapraised();
  70. return true;
  71. }
  72. if (std::strcmp(msg, "uiTitle") == 0)
  73. {
  74. const char* uiTitle;
  75. CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(uiTitle), true);
  76. mainwin->x_set_title(uiTitle);
  77. return true;
  78. }
  79. if (std::strcmp(msg, "quit") == 0)
  80. {
  81. fQuitReceived = true;
  82. mainwin->stop();
  83. return true;
  84. }
  85. carla_stderr("ZitaPipeClient::msgReceived : %s", msg);
  86. return false;
  87. }
  88. void valueChangedCallback(uint index, double value) override
  89. {
  90. if (isPipeRunning())
  91. writeControlMessage(index, value);
  92. }
  93. private:
  94. bool fQuitReceived;
  95. };
  96. // --------------------------------------------------------------------------------------------
  97. int main(int argc, const char* argv[])
  98. {
  99. X_resman xresman;
  100. X_display *display;
  101. X_handler *handler;
  102. X_rootwin *rootwin;
  103. int ev, xp, yp, xs, ys;
  104. int fake_argc = 1;
  105. char* fake_argv[] = { (char*)"rev1" };
  106. xresman.init(&fake_argc, fake_argv, (char*)"rev1", nullptr, 0);
  107. display = new X_display(nullptr);
  108. if (display->dpy () == 0)
  109. {
  110. carla_stderr("Can't open display.");
  111. delete display;
  112. return 1;
  113. }
  114. ZitaPipeClient pipe;
  115. const char* uiTitle = "Test UI";
  116. if (argc > 1)
  117. {
  118. uiTitle = argv[2];
  119. if (! pipe.initPipeClient(argv))
  120. return 1;
  121. }
  122. xp = yp = 100;
  123. xs = Mainwin::XSIZE + 4;
  124. ys = Mainwin::YSIZE + 30;
  125. xresman.geometry(".geometry", display->xsize(), display->ysize(), 1, xp, yp, xs, ys);
  126. styles_init(display, &xresman);
  127. rootwin = new X_rootwin(display);
  128. mainwin = new Mainwin(rootwin, &xresman, xp, yp, &pipe);
  129. mainwin->x_set_title(uiTitle);
  130. rootwin->handle_event();
  131. handler = new X_handler(display, mainwin, EV_X11);
  132. handler->next_event();
  133. XFlush(display->dpy());
  134. if (argc == 1)
  135. mainwin->x_map();
  136. do
  137. {
  138. ev = mainwin->process();
  139. if (ev == EV_X11)
  140. {
  141. rootwin->handle_event();
  142. handler->next_event();
  143. }
  144. else if (ev == Esync::EV_TIME)
  145. {
  146. handler->next_event();
  147. if (pipe.isPipeRunning())
  148. pipe.idlePipe();
  149. }
  150. }
  151. while (ev != EV_EXIT && ! pipe.quitRequested());
  152. styles_fini(display);
  153. delete handler;
  154. delete rootwin;
  155. delete display;
  156. return 0;
  157. }
  158. // --------------------------------------------------------------------------------------------