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.

192 lines
4.7KB

  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. return true;
  83. }
  84. carla_stderr("ZitaPipeClient::msgReceived : %s", msg);
  85. return false;
  86. }
  87. void valueChangedCallback(uint index, double value) override
  88. {
  89. if (isPipeRunning())
  90. writeControlMessage(index, value);
  91. }
  92. private:
  93. bool fQuitReceived;
  94. };
  95. // --------------------------------------------------------------------------------------------
  96. int main(int argc, const char* argv[])
  97. {
  98. X_resman xresman;
  99. X_display *display;
  100. X_handler *handler;
  101. X_rootwin *rootwin;
  102. int ev, xp, yp, xs, ys;
  103. int fake_argc = 1;
  104. char* fake_argv[] = { (char*)"rev1" };
  105. xresman.init(&fake_argc, fake_argv, (char*)"rev1", nullptr, 0);
  106. display = new X_display(nullptr);
  107. if (display->dpy () == 0)
  108. {
  109. carla_stderr("Can't open display.");
  110. delete display;
  111. return 1;
  112. }
  113. ZitaPipeClient pipe;
  114. const char* uiTitle = "Test UI";
  115. if (argc > 1)
  116. {
  117. uiTitle = argv[2];
  118. if (! pipe.initPipeClient(argv))
  119. return 1;
  120. }
  121. xp = yp = 100;
  122. xs = Mainwin::XSIZE + 4;
  123. ys = Mainwin::YSIZE + 30;
  124. xresman.geometry(".geometry", display->xsize(), display->ysize(), 1, xp, yp, xs, ys);
  125. styles_init(display, &xresman);
  126. rootwin = new X_rootwin(display);
  127. mainwin = new Mainwin(rootwin, &xresman, xp, yp, &pipe);
  128. mainwin->x_set_title(uiTitle);
  129. rootwin->handle_event();
  130. handler = new X_handler(display, mainwin, EV_X11);
  131. handler->next_event();
  132. XFlush(display->dpy());
  133. do
  134. {
  135. ev = mainwin->process();
  136. if (ev == EV_X11)
  137. {
  138. rootwin->handle_event();
  139. handler->next_event();
  140. }
  141. else if (ev == Esync::EV_TIME)
  142. {
  143. handler->next_event();
  144. if (pipe.isPipeRunning())
  145. pipe.idlePipe();
  146. }
  147. }
  148. while (ev != EV_EXIT && ! pipe.quitRequested());
  149. styles_fini(display);
  150. delete handler;
  151. delete rootwin;
  152. delete display;
  153. return 0;
  154. }
  155. // --------------------------------------------------------------------------------------------