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_NAMESPACE::NanoWidget UIWidget;
29 #else
30 # include "../dgl/Widget.hpp"
31 typedef DGL_NAMESPACE::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_WANT_MIDI_INPUT
94  /**
95  sendNote.
96  @TODO Document this.
97  @note Work in progress. Implemented for DSSI and LV2 formats.
98  */
99  void sendNote(uint8_t channel, uint8_t note, uint8_t velocity);
100 #endif
101 
102 #if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
103  /* --------------------------------------------------------------------------------------------------------
104  * Direct DSP access - DO NOT USE THIS UNLESS STRICTLY NECESSARY!! */
105 
106  /**
107  getPluginInstancePointer.
108  @TODO Document this.
109  */
110  void* getPluginInstancePointer() const noexcept;
111 #endif
112 
113 #if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
114  /* --------------------------------------------------------------------------------------------------------
115  * External UI helpers */
116 
117  /**
118  Get the bundle path that will be used for the next UI.
119  @note: This function is only valid during createUI(),
120  it will return null when called from anywhere else.
121  */
122  static const char* getNextBundlePath() noexcept;
123 
124 # if DISTRHO_PLUGIN_HAS_EMBED_UI
125  /**
126  Get the Window Id that will be used for the next created window.
127  @note: This function is only valid during createUI(),
128  it will return 0 when called from anywhere else.
129  */
130  static uintptr_t getNextWindowId() noexcept;
131 # endif
132 #endif
133 
134 protected:
135  /* --------------------------------------------------------------------------------------------------------
136  * DSP/Plugin Callbacks */
137 
138  /**
139  A parameter has changed on the plugin side.@n
140  This is called by the host to inform the UI about parameter changes.
141  */
142  virtual void parameterChanged(uint32_t index, float value) = 0;
143 
144 #if DISTRHO_PLUGIN_WANT_PROGRAMS
145  /**
146  A program has been loaded on the plugin side.@n
147  This is called by the host to inform the UI about program changes.
148  */
149  virtual void programLoaded(uint32_t index) = 0;
150 #endif
151 
152 #if DISTRHO_PLUGIN_WANT_STATE
153  /**
154  A state has changed on the plugin side.@n
155  This is called by the host to inform the UI about state changes.
156  */
157  virtual void stateChanged(const char* key, const char* value) = 0;
158 #endif
159 
160  /* --------------------------------------------------------------------------------------------------------
161  * DSP/Plugin Callbacks (optional) */
162 
163  /**
164  Optional callback to inform the UI about a sample rate change on the plugin side.
165  @see getSampleRate()
166  */
167  virtual void sampleRateChanged(double newSampleRate);
168 
169 #ifdef HAVE_DGL
170  /* --------------------------------------------------------------------------------------------------------
171  * UI Callbacks (optional) */
172 
173  /**
174  uiIdle.
175  @TODO Document this.
176  */
177  virtual void uiIdle() {}
178 
179 #ifndef DGL_FILE_BROWSER_DISABLED
180  /**
181  File browser selected function.
182  @see Window::fileBrowserSelected(const char*)
183  */
184  virtual void uiFileBrowserSelected(const char* filename);
185 #endif
186 
187  /**
188  OpenGL window reshape function, called when parent window is resized.
189  You can reimplement this function for a custom OpenGL state.
190  @see Window::onReshape(uint,uint)
191  */
192  virtual void uiReshape(uint width, uint height);
193 
194  /* --------------------------------------------------------------------------------------------------------
195  * UI Resize Handling, internal */
196 
197  /**
198  OpenGL widget resize function, called when the widget is resized.
199  This is overriden here so the host knows when the UI is resized by you.
200  @see Widget::onResize(const ResizeEvent&)
201  */
202  void onResize(const ResizeEvent& ev) override;
203 #endif
204 
205  // -------------------------------------------------------------------------------------------------------
206 
207 private:
208  struct PrivateData;
209  PrivateData* const pData;
210  friend class UIExporter;
211  friend class UIExporterWindow;
212 
213 #ifdef HAVE_DGL
214  // these should not be used
215  void setAbsoluteX(int) const noexcept {}
216  void setAbsoluteY(int) const noexcept {}
217  void setAbsolutePos(int, int) const noexcept {}
218  void setAbsolutePos(const DGL_NAMESPACE::Point<int>&) const noexcept {}
219 #endif
220 
221  DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(UI)
222 };
223 
224 /** @} */
225 
226 /* ------------------------------------------------------------------------------------------------------------
227  * Create UI, entry point */
228 
229 /**
230  @addtogroup EntryPoints
231  @{
232  */
233 
234 /**
235  createUI.
236  @TODO Document this.
237  */
238 extern UI* createUI();
239 
240 /** @} */
241 
242 // -----------------------------------------------------------------------------------------------------------
243 
244 END_NAMESPACE_DISTRHO
245 
246 #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:177