DISTRHO Plugin Framework
DistrhoUI.hpp
1 /*
2  * DISTRHO Plugin Framework (DPF)
3  * Copyright (C) 2012-2016 Filipe Coelho <falktx@falktx.com>
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any purpose with
6  * or without fee is hereby granted, provided that the above copyright notice and this
7  * permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
10  * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
11  * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
12  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
13  * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 #ifndef DISTRHO_UI_HPP_INCLUDED
18 #define DISTRHO_UI_HPP_INCLUDED
19 
20 #include "extra/LeakDetector.hpp"
21 #include "src/DistrhoPluginChecks.h"
22 
23 #ifndef HAVE_DGL
24 # include "extra/ExternalWindow.hpp"
25 typedef DISTRHO_NAMESPACE::ExternalWindow UIWidget;
26 #elif DISTRHO_UI_USE_NANOVG
27 # include "../dgl/NanoVG.hpp"
28 typedef DGL::NanoWidget UIWidget;
29 #else
30 # include "../dgl/Widget.hpp"
31 typedef DGL::Widget UIWidget;
32 #endif
33 
34 START_NAMESPACE_DISTRHO
35 
36 /* ------------------------------------------------------------------------------------------------------------
37  * DPF UI */
38 
39 /**
40  @addtogroup MainClasses
41  @{
42  */
43 
44 /**
45  DPF UI class from where UI instances are created.
46 
47  @note You must call setSize during construction,
48  @TODO Detailed information about this class.
49  */
50 class UI : public UIWidget
51 {
52 public:
53  /**
54  UI class constructor.
55  The UI should be initialized to a default state that matches the plugin side.
56  */
57  UI(uint width = 0, uint height = 0);
58 
59  /**
60  Destructor.
61  */
62  virtual ~UI();
63 
64  /* --------------------------------------------------------------------------------------------------------
65  * Host state */
66 
67  /**
68  Get the current sample rate used in plugin processing.
69  @see sampleRateChanged(double)
70  */
71  double getSampleRate() const noexcept;
72 
73  /**
74  editParameter.
75  @TODO Document this.
76  */
77  void editParameter(uint32_t index, bool started);
78 
79  /**
80  setParameterValue.
81  @TODO Document this.
82  */
83  void setParameterValue(uint32_t index, float value);
84 
85 #if DISTRHO_PLUGIN_WANT_STATE
86  /**
87  setState.
88  @TODO Document this.
89  */
90  void setState(const char* key, const char* value);
91 #endif
92 
93 #if DISTRHO_PLUGIN_IS_SYNTH
94  /**
95  sendNote.
96  @TODO Document this.
97  */
98  void sendNote(uint8_t channel, uint8_t note, uint8_t velocity);
99 #endif
100 
101 #if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
102  /* --------------------------------------------------------------------------------------------------------
103  * Direct DSP access - DO NOT USE THIS UNLESS STRICTLY NECESSARY!! */
104 
105  /**
106  getPluginInstancePointer.
107  @TODO Document this.
108  */
109  void* getPluginInstancePointer() const noexcept;
110 #endif
111 
112 #if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
113  /* --------------------------------------------------------------------------------------------------------
114  * External UI helpers */
115 
116  /**
117  Get the bundle path that will be used for the next UI.
118  @note: This function is only valid during createUI(),
119  it will return null when called from anywhere else.
120  */
121  static const char* getNextBundlePath() noexcept;
122 
123 # if DISTRHO_PLUGIN_HAS_EMBED_UI
124  /**
125  Get the Window Id that will be used for the next created window.
126  @note: This function is only valid during createUI(),
127  it will return 0 when called from anywhere else.
128  */
129  static uintptr_t getNextWindowId() noexcept;
130 # endif
131 #endif
132 
133 protected:
134  /* --------------------------------------------------------------------------------------------------------
135  * DSP/Plugin Callbacks */
136 
137  /**
138  A parameter has changed on the plugin side.@n
139  This is called by the host to inform the UI about parameter changes.
140  */
141  virtual void parameterChanged(uint32_t index, float value) = 0;
142 
143 #if DISTRHO_PLUGIN_WANT_PROGRAMS
144  /**
145  A program has been loaded on the plugin side.@n
146  This is called by the host to inform the UI about program changes.
147  */
148  virtual void programLoaded(uint32_t index) = 0;
149 #endif
150 
151 #if DISTRHO_PLUGIN_WANT_STATE
152  /**
153  A state has changed on the plugin side.@n
154  This is called by the host to inform the UI about state changes.
155  */
156  virtual void stateChanged(const char* key, const char* value) = 0;
157 #endif
158 
159  /* --------------------------------------------------------------------------------------------------------
160  * DSP/Plugin Callbacks (optional) */
161 
162  /**
163  Optional callback to inform the UI about a sample rate change on the plugin side.
164  @see getSampleRate()
165  */
166  virtual void sampleRateChanged(double newSampleRate);
167 
168 #ifdef HAVE_DGL
169  /* --------------------------------------------------------------------------------------------------------
170  * UI Callbacks (optional) */
171 
172  /**
173  uiIdle.
174  @TODO Document this.
175  */
176  virtual void uiIdle() {}
177 
178  /**
179  File browser selected function.
180  @see Window::fileBrowserSelected(const char*)
181  */
182  virtual void uiFileBrowserSelected(const char* filename);
183 
184  /**
185  OpenGL window reshape function, called when parent window is resized.
186  You can reimplement this function for a custom OpenGL state.
187  @see Window::onReshape(uint,uint)
188  */
189  virtual void uiReshape(uint width, uint height);
190 
191  /* --------------------------------------------------------------------------------------------------------
192  * UI Resize Handling, internal */
193 
194  /**
195  OpenGL widget resize function, called when the widget is resized.
196  This is overriden here so the host knows when the UI is resized by you.
197  @see Widget::onResize(const ResizeEvent&)
198  */
199  void onResize(const ResizeEvent& ev) override;
200 #endif
201 
202  // -------------------------------------------------------------------------------------------------------
203 
204 private:
205  struct PrivateData;
206  PrivateData* const pData;
207  friend class UIExporter;
208  friend class UIExporterWindow;
209 
210 #ifdef HAVE_DGL
211  // these should not be used
212  void setAbsoluteX(int) const noexcept {}
213  void setAbsoluteY(int) const noexcept {}
214  void setAbsolutePos(int, int) const noexcept {}
215  void setAbsolutePos(const DGL::Point<int>&) const noexcept {}
216 #endif
217 
218  DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(UI)
219 };
220 
221 /** @} */
222 
223 /* ------------------------------------------------------------------------------------------------------------
224  * Create UI, entry point */
225 
226 /**
227  @addtogroup EntryPoints
228  @{
229  */
230 
231 /**
232  createUI.
233  @TODO Document this.
234  */
235 extern UI* createUI();
236 
237 /** @} */
238 
239 // -----------------------------------------------------------------------------------------------------------
240 
241 END_NAMESPACE_DISTRHO
242 
243 #endif // DISTRHO_UI_HPP_INCLUDED
void editParameter(uint32_t index, bool started)
virtual void parameterChanged(uint32_t index, float value)=0
static uintptr_t getNextWindowId() noexcept
void onResize(const ResizeEvent &ev) override
virtual ~UI()
void setParameterValue(uint32_t index, float value)
void * getPluginInstancePointer() const noexcept
virtual void sampleRateChanged(double newSampleRate)
virtual void programLoaded(uint32_t index)=0
void sendNote(uint8_t channel, uint8_t note, uint8_t velocity)
UI(uint width=0, uint height=0)
static const char * getNextBundlePath() noexcept
UI * createUI()
virtual void stateChanged(const char *key, const char *value)=0
double getSampleRate() const noexcept
void setState(const char *key, const char *value)
virtual void uiFileBrowserSelected(const char *filename)
virtual void uiReshape(uint width, uint height)
Definition: DistrhoUI.hpp:50
virtual void uiIdle()
Definition: DistrhoUI.hpp:176