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.

CarlaExternalUI.hpp 2.5KB

10 years ago
10 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. fSampleRate(),
  34. fUiTitle(),
  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 double sampleRate, const char* const uiTitle) noexcept
  48. {
  49. fFilename = filename;
  50. fSampleRate = CarlaString(sampleRate);
  51. fUiTitle = uiTitle;
  52. }
  53. bool startPipeServer(const bool show = true) noexcept
  54. {
  55. if (CarlaPipeServer::startPipeServer(fFilename, fSampleRate, fUiTitle))
  56. {
  57. if (show)
  58. writeShowMessage();
  59. return true;
  60. }
  61. return false;
  62. }
  63. protected:
  64. // returns true if msg was handled
  65. bool msgReceived(const char* const msg) noexcept override
  66. {
  67. if (std::strcmp(msg, "exiting") == 0)
  68. {
  69. closePipeServer();
  70. fUiState = UiHide;
  71. return true;
  72. }
  73. return false;
  74. }
  75. private:
  76. CarlaString fFilename;
  77. CarlaString fSampleRate;
  78. CarlaString fUiTitle;
  79. UiState fUiState;
  80. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaExternalUI)
  81. };
  82. // -----------------------------------------------------------------------
  83. #endif // CARLA_EXTERNAL_UI_HPP_INCLUDED