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.

107 lines
2.7KB

  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() noexcept
  32. : fFilename(),
  33. fArg1(),
  34. fArg2(),
  35. fUiState(UiNone),
  36. leakDetector_CarlaExternalUI() {}
  37. ~CarlaExternalUI() /*noexcept*/ 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 char* const arg1, const char* const arg2) noexcept
  48. {
  49. fFilename = filename;
  50. fArg1 = arg1;
  51. fArg2 = arg2;
  52. }
  53. void setData(const char* const filename, const double sampleRate, const char* const uiTitle) noexcept
  54. {
  55. fFilename = filename;
  56. fArg1 = CarlaString(sampleRate);
  57. fArg2 = uiTitle;
  58. }
  59. bool startPipeServer(const bool show = true) noexcept
  60. {
  61. if (CarlaPipeServer::startPipeServer(fFilename, fArg1, fArg2))
  62. {
  63. if (show)
  64. writeShowMessage();
  65. return true;
  66. }
  67. return false;
  68. }
  69. protected:
  70. // returns true if msg was handled
  71. bool msgReceived(const char* const msg) noexcept override
  72. {
  73. if (std::strcmp(msg, "exiting") == 0)
  74. {
  75. closePipeServer();
  76. fUiState = UiHide;
  77. return true;
  78. }
  79. return false;
  80. }
  81. private:
  82. CarlaString fFilename;
  83. CarlaString fArg1;
  84. CarlaString fArg2;
  85. UiState fUiState;
  86. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaExternalUI)
  87. };
  88. // -----------------------------------------------------------------------
  89. #endif // CARLA_EXTERNAL_UI_HPP_INCLUDED