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.

183 lines
4.6KB

  1. // SPDX-FileCopyrightText: 2011-2025 Filipe Coelho <falktx@falktx.com>
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #ifndef CARLA_BRIDGE_FORMAT_HPP_INCLUDED
  4. #define CARLA_BRIDGE_FORMAT_HPP_INCLUDED
  5. #include "CarlaBridgeUI.hpp"
  6. #include "CarlaLibUtils.hpp"
  7. #include "CarlaPipeUtils.hpp"
  8. #include "extra/String.hpp"
  9. #include "lv2/atom.h"
  10. #include "lv2/urid.h"
  11. #include <vector>
  12. CARLA_BRIDGE_UI_START_NAMESPACE
  13. /*!
  14. * @defgroup CarlaBridgeUIAPI Carla UI Bridge API
  15. *
  16. * The Carla UI Bridge API.
  17. * @{
  18. */
  19. // -----------------------------------------------------------------------
  20. class CarlaBridgeFormat : public CarlaPipeClient
  21. {
  22. protected:
  23. /*!
  24. * Constructor.
  25. */
  26. CarlaBridgeFormat() noexcept;
  27. /*!
  28. * Destructor.
  29. */
  30. virtual ~CarlaBridgeFormat() /*noexcept*/;
  31. // ---------------------------------------------------------------------
  32. bool libOpen(const char* filename) noexcept;
  33. void* libSymbol(const char* symbol) const noexcept;
  34. const char* libError() const noexcept;
  35. // ---------------------------------------------------------------------
  36. // DSP Callbacks
  37. virtual void dspParameterChanged(uint32_t index, float value) = 0;
  38. virtual void dspParameterChanged(const char* uri, float value) = 0;
  39. virtual void dspProgramChanged(uint32_t index) = 0;
  40. virtual void dspMidiProgramChanged(uint32_t bank, uint32_t program) = 0;
  41. virtual void dspStateChanged(const char* key, const char* value) = 0;
  42. virtual void dspNoteReceived(bool onOff, uint8_t channel, uint8_t note, uint8_t velocity) = 0;
  43. virtual void dspAtomReceived(uint32_t index, const LV2_Atom* atom) = 0;
  44. virtual void dspURIDReceived(LV2_URID urid, const char* uri) = 0;
  45. struct BridgeFormatOptions {
  46. double sampleRate;
  47. uint32_t bgColor;
  48. uint32_t fgColor;
  49. float uiScale;
  50. bool isStandalone;
  51. bool useTheme;
  52. bool useThemeColors;
  53. const char* windowTitle;
  54. uintptr_t transientWindowId;
  55. };
  56. virtual void uiOptionsChanged(const BridgeFormatOptions& opts) = 0;
  57. public:
  58. // ---------------------------------------------------------------------
  59. // UI initialization
  60. virtual bool init(int argc, const char* argv[]);
  61. virtual void exec(bool showUI);
  62. virtual void idleUI() {}
  63. // ---------------------------------------------------------------------
  64. // UI management
  65. /*!
  66. * Get the widget associated with this UI.
  67. * This can be a Gtk widget, Qt widget or a native Window handle depending on the compile target.
  68. */
  69. virtual void* getWidget() const noexcept = 0;
  70. #ifndef CARLA_OS_MAC
  71. /*!
  72. * TESTING
  73. */
  74. virtual void setScaleFactor(double scaleFactor) = 0;
  75. #endif
  76. /*!
  77. * TESTING
  78. */
  79. virtual void uiResized(uint width, uint height) = 0;
  80. /*!
  81. * Options.
  82. */
  83. struct Options {
  84. /*!
  85. * UI is standalone, not controlled by another application.
  86. */
  87. bool isStandalone;
  88. /*!
  89. * UI is resizable by the user.
  90. * The UI can still sometimes resize itself internally if this is false.
  91. */
  92. bool isResizable;
  93. /*!
  94. * Use the Carla PRO theme if possible.
  95. */
  96. bool useTheme;
  97. /*!
  98. * Use the Carla PRO theme colors if possible.
  99. * This implies useTheme to be true.
  100. */
  101. bool useThemeColors;
  102. /*!
  103. * Window title.
  104. */
  105. String windowTitle;
  106. /*!
  107. * Transient window id (parent), zero if unset.
  108. */
  109. uintptr_t transientWindowId;
  110. /*!
  111. * Constructor for default options.
  112. */
  113. Options() noexcept
  114. : isStandalone(true),
  115. isResizable(true),
  116. useTheme(true),
  117. useThemeColors(true),
  118. windowTitle("TestUI"),
  119. transientWindowId(0) {}
  120. };
  121. /*!
  122. * Get options associated with this UI.
  123. */
  124. virtual const Options& getOptions() const noexcept = 0;
  125. // ---------------------------------------------------------------------
  126. protected:
  127. bool fQuitReceived;
  128. bool fGotOptions;
  129. int fLastMsgTimer;
  130. CarlaBridgeToolkit* fToolkit;
  131. lib_t fLib;
  132. String fLibFilename;
  133. std::vector<uint8_t> fBase64ReservedChunk;
  134. /*! @internal */
  135. bool msgReceived(const char* msg) noexcept override;
  136. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaBridgeFormat)
  137. };
  138. /**@}*/
  139. // -----------------------------------------------------------------------
  140. CARLA_BRIDGE_UI_END_NAMESPACE
  141. #endif // CARLA_BRIDGE_FORMAT_HPP_INCLUDED