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.

194 lines
5.1KB

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