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

10 years ago
10 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. // -----------------------------------------------------------------------
  21. class CarlaExternalUI : public CarlaPipeServer
  22. {
  23. public:
  24. enum UiState {
  25. UiNone = 0,
  26. UiHide,
  27. UiShow,
  28. UiCrashed
  29. };
  30. CarlaExternalUI()
  31. : fFilename(),
  32. fSampleRate(),
  33. fUiTitle(),
  34. fUiState(UiNone),
  35. leakDetector_CarlaExternalUI() {}
  36. ~CarlaExternalUI() 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 double sampleRate, const char* const uiTitle) noexcept
  47. {
  48. fFilename = filename;
  49. fSampleRate = CarlaString(sampleRate);
  50. fUiTitle = uiTitle;
  51. }
  52. void start() noexcept
  53. {
  54. CarlaPipeServer::start(fFilename, fSampleRate, fUiTitle);
  55. const CarlaMutexLocker cml(fWriteLock);
  56. writeMsg("show\n", 5);
  57. }
  58. protected:
  59. // returns true if msg was handled
  60. bool msgReceived(const char* const msg) noexcept override
  61. {
  62. if (std::strcmp(msg, "exiting") == 0)
  63. {
  64. waitChildClose();
  65. fUiState = UiHide;
  66. return true;
  67. }
  68. return false;
  69. }
  70. private:
  71. CarlaString fFilename;
  72. CarlaString fSampleRate;
  73. CarlaString fUiTitle;
  74. UiState fUiState;
  75. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaExternalUI)
  76. };
  77. // -----------------------------------------------------------------------
  78. #endif // CARLA_EXTERNAL_UI_HPP_INCLUDED