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.6KB

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