Rename a pipe method, add docs
[carla.git] / source / bridges-ui / CarlaBridgeFormat.hpp
blobc3f05e045a43ce0925ff39c7fa71efe405de33aa
1 /*
2 * Carla Bridge UI
3 * Copyright (C) 2011-2021 Filipe Coelho <falktx@falktx.com>
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.
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.
15 * For a full copy of the GNU General Public License see the doc/GPL.txt file.
18 #ifndef CARLA_BRIDGE_FORMAT_HPP_INCLUDED
19 #define CARLA_BRIDGE_FORMAT_HPP_INCLUDED
21 #include "CarlaBridgeUI.hpp"
23 #include "CarlaLibUtils.hpp"
24 #include "CarlaPipeUtils.hpp"
25 #include "CarlaString.hpp"
27 #include "lv2/atom.h"
28 #include "lv2/urid.h"
30 #include <vector>
32 CARLA_BRIDGE_UI_START_NAMESPACE
34 /*!
35 * @defgroup CarlaBridgeUIAPI Carla UI Bridge API
37 * The Carla UI Bridge API.
38 * @{
41 // -----------------------------------------------------------------------
43 class CarlaBridgeFormat : public CarlaPipeClient
45 protected:
46 /*!
47 * Constructor.
49 CarlaBridgeFormat() noexcept;
51 /*!
52 * Destructor.
54 virtual ~CarlaBridgeFormat() /*noexcept*/;
56 // ---------------------------------------------------------------------
58 bool libOpen(const char* filename) noexcept;
59 void* libSymbol(const char* symbol) const noexcept;
60 const char* libError() const noexcept;
62 // ---------------------------------------------------------------------
63 // DSP Callbacks
65 virtual void dspParameterChanged(uint32_t index, float value) = 0;
66 virtual void dspParameterChanged(const char* uri, float value) = 0;
67 virtual void dspProgramChanged(uint32_t index) = 0;
68 virtual void dspMidiProgramChanged(uint32_t bank, uint32_t program) = 0;
69 virtual void dspStateChanged(const char* key, const char* value) = 0;
70 virtual void dspNoteReceived(bool onOff, uint8_t channel, uint8_t note, uint8_t velocity) = 0;
72 virtual void dspAtomReceived(uint32_t index, const LV2_Atom* atom) = 0;
73 virtual void dspURIDReceived(LV2_URID urid, const char* uri) = 0;
75 struct BridgeFormatOptions {
76 double sampleRate;
77 uint32_t bgColor;
78 uint32_t fgColor;
79 float uiScale;
80 bool isStandalone;
81 bool useTheme;
82 bool useThemeColors;
83 const char* windowTitle;
84 uintptr_t transientWindowId;
87 virtual void uiOptionsChanged(const BridgeFormatOptions& opts) = 0;
89 public:
90 // ---------------------------------------------------------------------
91 // UI initialization
93 virtual bool init(int argc, const char* argv[]);
94 virtual void exec(bool showUI);
95 virtual void idleUI() {}
97 // ---------------------------------------------------------------------
98 // UI management
101 * Get the widget associated with this UI.
102 * This can be a Gtk widget, Qt widget or a native Window handle depending on the compile target.
104 virtual void* getWidget() const noexcept = 0;
106 #ifndef CARLA_OS_MAC
108 * TESTING
110 virtual void setScaleFactor(double scaleFactor) = 0;
111 #endif
114 * TESTING
116 virtual void uiResized(uint width, uint height) = 0;
119 * Options.
121 struct Options {
123 * UI is standalone, not controlled by another application.
125 bool isStandalone;
128 * UI is resizable by the user.
129 * The UI can still sometimes resize itself internally if this is false.
131 bool isResizable;
134 * Use the Carla PRO theme if possible.
136 bool useTheme;
139 * Use the Carla PRO theme colors if possible.
140 * This implies useTheme to be true.
142 bool useThemeColors;
145 * Window title.
147 CarlaString windowTitle;
150 * Transient window id (parent), zero if unset.
152 uintptr_t transientWindowId;
155 * Constructor for default options.
157 Options() noexcept
158 : isStandalone(true),
159 isResizable(true),
160 useTheme(true),
161 useThemeColors(true),
162 windowTitle("TestUI"),
163 transientWindowId(0) {}
167 * Get options associated with this UI.
169 virtual const Options& getOptions() const noexcept = 0;
171 // ---------------------------------------------------------------------
173 protected:
174 bool fQuitReceived;
175 bool fGotOptions;
176 int fLastMsgTimer;
177 CarlaBridgeToolkit* fToolkit;
179 lib_t fLib;
180 CarlaString fLibFilename;
181 std::vector<uint8_t> fBase64ReservedChunk;
183 /*! @internal */
184 bool msgReceived(const char* msg) noexcept override;
186 CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaBridgeFormat)
189 /**@}*/
191 // -----------------------------------------------------------------------
193 CARLA_BRIDGE_UI_END_NAMESPACE
195 #endif // CARLA_BRIDGE_FORMAT_HPP_INCLUDED