DISTRHO Plugin Framework
 All Classes Functions Variables Modules Pages
DistrhoUI.hpp
1 /*
2  * DISTRHO Plugin Framework (DPF)
3  * Copyright (C) 2012-2015 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/d_leakdetector.hpp"
21 #include "src/DistrhoPluginChecks.h"
22 
23 #if DISTRHO_UI_USE_NANOVG
24 # include "../dgl/NanoVG.hpp"
25 typedef DGL::NanoWidget UIWidget;
26 #else
27 # include "../dgl/Widget.hpp"
28 typedef DGL::Widget UIWidget;
29 #endif
30 
31 START_NAMESPACE_DISTRHO
32 
33 /* ------------------------------------------------------------------------------------------------------------
34  * DPF UI */
35 
36 /**
37  @addtogroup MainClasses
38  @{
39  */
40 
41 /**
42  DPF UI class from where UI instances are created.
43 
44  TODO.
45 
46  must call setSize during construction,
47  */
48 class UI : public UIWidget
49 {
50 public:
51  /**
52  UI class constructor.
53  The UI should be initialized to a default state that matches the plugin side.
54  */
55  UI(uint width = 0, uint height = 0);
56 
57  /**
58  Destructor.
59  */
60  virtual ~UI();
61 
62  /* --------------------------------------------------------------------------------------------------------
63  * Host state */
64 
65  /**
66  Get the current sample rate used in plugin processing.
67  @see sampleRateChanged(double)
68  */
69  double getSampleRate() const noexcept;
70 
71  /**
72  TODO: Document this.
73  */
74  void editParameter(const uint32_t index, const bool started);
75 
76  /**
77  TODO: Document this.
78  */
79  void setParameterValue(const uint32_t index, const float value);
80 
81 #if DISTRHO_PLUGIN_WANT_STATE
82  /**
83  TODO: Document this.
84  */
85  void setState(const char* const key, const char* const value);
86 #endif
87 
88 #if DISTRHO_PLUGIN_IS_SYNTH
89  /**
90  TODO: Document this.
91  */
92  void sendNote(const uint8_t channel, const uint8_t note, const uint8_t velocity);
93 #endif
94 
95 #if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
96  /* --------------------------------------------------------------------------------------------------------
97  * Direct DSP access - DO NOT USE THIS UNLESS STRICTLY NECESSARY!! */
98 
99  /**
100  TODO: Document this.
101  */
102  void* getPluginInstancePointer() const noexcept;
103 #endif
104 
105 protected:
106  /* --------------------------------------------------------------------------------------------------------
107  * DSP/Plugin Callbacks */
108 
109  /**
110  A parameter has changed on the plugin side.
111  This is called by the host to inform the UI about parameter changes.
112  */
113  virtual void parameterChanged(uint32_t index, float value) = 0;
114 
115 #if DISTRHO_PLUGIN_WANT_PROGRAMS
116  /**
117  The current program has changed on the plugin side.
118  This is called by the host to inform the UI about program changes.
119  */
120  virtual void programChanged(uint32_t index) = 0;
121 #endif
122 
123 #if DISTRHO_PLUGIN_WANT_STATE
124  /**
125  A state has changed on the plugin side.
126  This is called by the host to inform the UI about state changes.
127  */
128  virtual void stateChanged(const char* key, const char* value) = 0;
129 #endif
130 
131  /* --------------------------------------------------------------------------------------------------------
132  * DSP/Plugin Callbacks (optional) */
133 
134  /**
135  Optional callback to inform the UI about a sample rate change on the plugin side.
136  @see getSampleRate()
137  */
138  virtual void sampleRateChanged(double newSampleRate);
139 
140  /* --------------------------------------------------------------------------------------------------------
141  * UI Callbacks (optional) */
142 
143  /**
144  TODO: Document this.
145  */
146  virtual void uiIdle() {}
147 
148  /**
149  File browser selected function.
150  @see Window::fileBrowserSelected(const char*)
151  */
152  virtual void uiFileBrowserSelected(const char* filename);
153 
154  /**
155  OpenGL window reshape function, called when parent window is resized.
156  You can reimplement this function for a custom OpenGL state.
157  @see Window::onReshape(uint,uint)
158  */
159  virtual void uiReshape(uint width, uint height);
160 
161  /* --------------------------------------------------------------------------------------------------------
162  * UI Resize Handling, internal */
163 
164  /**
165  OpenGL widget resize function, called when the widget is resized.
166  This is overriden here so the host knows when the UI is resized by you.
167  @see Widget::onResize(const ResizeEvent&)
168  */
169  void onResize(const ResizeEvent& ev) override;
170 
171  // -------------------------------------------------------------------------------------------------------
172 
173 private:
174  struct PrivateData;
175  PrivateData* const pData;
176  friend class UIExporter;
177  friend class UIExporterWindow;
178 
179  // these should not be used
180  void setAbsoluteX(int) const noexcept {}
181  void setAbsoluteY(int) const noexcept {}
182  void setAbsolutePos(int, int) const noexcept {}
183  void setAbsolutePos(const DGL::Point<int>&) const noexcept {}
184  void setNeedsFullViewport(bool) const noexcept {}
185 
186  DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(UI)
187 };
188 
189 /** @} */
190 
191 /* ------------------------------------------------------------------------------------------------------------
192  * Create UI, entry point */
193 
194 /**
195  @addtogroup EntryPoints
196  @{
197  */
198 
199 /**
200  TODO.
201  */
202 extern UI* createUI();
203 
204 /** @} */
205 
206 // -----------------------------------------------------------------------------------------------------------
207 
208 END_NAMESPACE_DISTRHO
209 
210 #endif // DISTRHO_UI_HPP_INCLUDED
virtual void parameterChanged(uint32_t index, float value)=0
void onResize(const ResizeEvent &ev) override
virtual ~UI()
void editParameter(const uint32_t index, const bool started)
void * getPluginInstancePointer() const noexcept
virtual void programChanged(uint32_t index)=0
virtual void sampleRateChanged(double newSampleRate)
void setState(const char *const key, const char *const value)
UI(uint width=0, uint height=0)
UI * createUI()
void setParameterValue(const uint32_t index, const float value)
virtual void stateChanged(const char *key, const char *value)=0
double getSampleRate() const noexcept
void sendNote(const uint8_t channel, const uint8_t note, const uint8_t velocity)
virtual void uiFileBrowserSelected(const char *filename)
virtual void uiReshape(uint width, uint height)
Definition: DistrhoUI.hpp:48
virtual void uiIdle()
Definition: DistrhoUI.hpp:146