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.

189 lines
5.0KB

  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 uiResized(uint width, uint height) = 0;
  88. /*!
  89. * Options.
  90. */
  91. struct Options {
  92. /*!
  93. * UI is standalone, not controlled by another application.
  94. */
  95. bool isStandalone;
  96. /*!
  97. * UI is resizable by the user.
  98. * The UI can still sometimes resize itself internally if this is false.
  99. */
  100. bool isResizable;
  101. /*!
  102. * Use the Carla PRO theme if possible.
  103. */
  104. bool useTheme;
  105. /*!
  106. * Use the Carla PRO theme colors if possible.
  107. * This implies useTheme to be true.
  108. */
  109. bool useThemeColors;
  110. /*!
  111. * Window title.
  112. */
  113. CarlaString windowTitle;
  114. /*!
  115. * Transient window id (parent), zero if unset.
  116. */
  117. uintptr_t transientWindowId;
  118. /*!
  119. * Constructor for default options.
  120. */
  121. Options() noexcept
  122. : isStandalone(true),
  123. isResizable(true),
  124. useTheme(true),
  125. useThemeColors(true),
  126. windowTitle("TestUI"),
  127. transientWindowId(0) {}
  128. };
  129. /*!
  130. * Get options associated with this UI.
  131. */
  132. virtual const Options& getOptions() const noexcept = 0;
  133. // ---------------------------------------------------------------------
  134. protected:
  135. bool fQuitReceived;
  136. bool fGotOptions;
  137. int fLastMsgTimer;
  138. CarlaBridgeToolkit* fToolkit;
  139. lib_t fLib;
  140. CarlaString fLibFilename;
  141. std::vector<uint8_t> fBase64ReservedChunk;
  142. /*! @internal */
  143. bool msgReceived(const char* msg) noexcept override;
  144. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaBridgeFormat)
  145. };
  146. /**@}*/
  147. // -----------------------------------------------------------------------
  148. CARLA_BRIDGE_UI_END_NAMESPACE
  149. #endif // CARLA_BRIDGE_FORMAT_HPP_INCLUDED