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.

100 lines
2.5KB

  1. /*
  2. * Carla External UI
  3. * Copyright (C) 2013-2014 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. #ifndef CARLA_EXTERNAL_UI_HPP_INCLUDED
  18. #define CARLA_EXTERNAL_UI_HPP_INCLUDED
  19. #include "CarlaPipeUtils.hpp"
  20. #include "CarlaString.hpp"
  21. // -----------------------------------------------------------------------
  22. class CarlaExternalUI : public CarlaPipeServer
  23. {
  24. public:
  25. enum UiState {
  26. UiNone = 0,
  27. UiHide,
  28. UiShow,
  29. UiCrashed
  30. };
  31. CarlaExternalUI()
  32. : fFilename(),
  33. fSampleRate(),
  34. fUiTitle(),
  35. fUiState(UiNone),
  36. leakDetector_CarlaExternalUI() {}
  37. ~CarlaExternalUI() override
  38. {
  39. CARLA_SAFE_ASSERT_INT(fUiState == UiNone, fUiState);
  40. }
  41. UiState getAndResetUiState() noexcept
  42. {
  43. const UiState uiState(fUiState);
  44. fUiState = UiNone;
  45. return uiState;
  46. }
  47. void setData(const char* const filename, const double sampleRate, const char* const uiTitle) noexcept
  48. {
  49. fFilename = filename;
  50. fSampleRate = CarlaString(sampleRate);
  51. fUiTitle = uiTitle;
  52. }
  53. void start(const bool show = true) noexcept
  54. {
  55. CarlaPipeServer::start(fFilename, fSampleRate, fUiTitle);
  56. if (! show)
  57. return;
  58. const CarlaMutexLocker cml(getLock());
  59. writeMsg("show\n", 5);
  60. flush();
  61. }
  62. protected:
  63. // returns true if msg was handled
  64. bool msgReceived(const char* const msg) noexcept override
  65. {
  66. if (std::strcmp(msg, "exiting") == 0)
  67. {
  68. close();
  69. fUiState = UiHide;
  70. return true;
  71. }
  72. return false;
  73. }
  74. private:
  75. CarlaString fFilename;
  76. CarlaString fSampleRate;
  77. CarlaString fUiTitle;
  78. UiState fUiState;
  79. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaExternalUI)
  80. };
  81. // -----------------------------------------------------------------------
  82. #endif // CARLA_EXTERNAL_UI_HPP_INCLUDED