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.

CarlaBridgeFormat.hpp 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. * Carla Bridge UI
  3. * Copyright (C) 2011-2017 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 useTheme;
  65. bool useThemeColors;
  66. const char* windowTitle;
  67. uintptr_t transientWindowId;
  68. };
  69. virtual void uiOptionsChanged(const BridgeFormatOptions& opts) = 0;
  70. public:
  71. // ---------------------------------------------------------------------
  72. // UI initialization
  73. virtual bool init(int argc, const char* argv[]);
  74. virtual void exec(bool showUI);
  75. virtual void idleUI() {}
  76. // ---------------------------------------------------------------------
  77. // UI management
  78. /*!
  79. * Get the widget associated with this UI.
  80. * This can be a Gtk widget, Qt widget or a native Window handle depending on the compile target.
  81. */
  82. virtual void* getWidget() const noexcept = 0;
  83. /*!
  84. * TESTING
  85. */
  86. virtual void uiResized(uint width, uint height) = 0;
  87. /*!
  88. * Options.
  89. */
  90. struct Options {
  91. /*!
  92. * UI is resizable by the user.
  93. * The UI can still sometimes resize itself internally if this is false.
  94. */
  95. bool isResizable;
  96. /*!
  97. * Use the Carla PRO theme if possible.
  98. */
  99. bool useTheme;
  100. /*!
  101. * Use the Carla PRO theme colors if possible.
  102. * This implies useTheme to be true.
  103. */
  104. bool useThemeColors;
  105. /*!
  106. * Window title.
  107. */
  108. CarlaString windowTitle;
  109. /*!
  110. * Transient window id (parent), zero if unset.
  111. */
  112. uintptr_t transientWindowId;
  113. /*!
  114. * Constructor for default options.
  115. */
  116. Options() noexcept
  117. : isResizable(true),
  118. useTheme(true),
  119. useThemeColors(true),
  120. windowTitle("TestUI"),
  121. transientWindowId(0) {}
  122. };
  123. /*!
  124. * Get options associated with this UI.
  125. */
  126. virtual const Options& getOptions() const noexcept = 0;
  127. // ---------------------------------------------------------------------
  128. protected:
  129. bool fQuitReceived;
  130. bool fGotOptions;
  131. int fLastMsgTimer;
  132. CarlaBridgeToolkit* fToolkit;
  133. lib_t fLib;
  134. CarlaString fLibFilename;
  135. std::vector<uint8_t> fBase64ReservedChunk;
  136. /*! @internal */
  137. bool msgReceived(const char* msg) noexcept override;
  138. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaBridgeFormat)
  139. };
  140. /**@}*/
  141. // -----------------------------------------------------------------------
  142. CARLA_BRIDGE_UI_END_NAMESPACE
  143. #endif // CARLA_BRIDGE_FORMAT_HPP_INCLUDED