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  DPF UI class from where UI instances are created.
38 
39  TODO.
40 
41  must call setSize during construction,
42  */
43 class UI : public UIWidget
44 {
45 public:
46  /**
47  UI class constructor.
48  The UI should be initialized to a default state that matches the plugin side.
49  */
50  UI(uint width = 0, uint height = 0);
51 
52  /**
53  Destructor.
54  */
55  virtual ~UI();
56 
57  /* --------------------------------------------------------------------------------------------------------
58  * Host state */
59 
60  /**
61  Get the current sample rate used in plugin processing.
62  @see d_sampleRateChanged(double)
63  */
64  double d_getSampleRate() const noexcept;
65 
66  /**
67  TODO: Document this.
68  */
69  void d_editParameter(const uint32_t index, const bool started);
70 
71  /**
72  TODO: Document this.
73  */
74  void d_setParameterValue(const uint32_t index, const float value);
75 
76 #if DISTRHO_PLUGIN_WANT_STATE
77  /**
78  TODO: Document this.
79  */
80  void d_setState(const char* const key, const char* const value);
81 #endif
82 
83 #if DISTRHO_PLUGIN_IS_SYNTH
84  /**
85  TODO: Document this.
86  */
87  void d_sendNote(const uint8_t channel, const uint8_t note, const uint8_t velocity);
88 #endif
89 
90 #if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
91  /* --------------------------------------------------------------------------------------------------------
92  * Direct DSP access - DO NOT USE THIS UNLESS STRICTLY NECESSARY!! */
93 
94  /**
95  TODO: Document this.
96  */
97  void* d_getPluginInstancePointer() const noexcept;
98 #endif
99 
100 protected:
101  /* --------------------------------------------------------------------------------------------------------
102  * DSP/Plugin Callbacks */
103 
104  /**
105  A parameter has changed on the plugin side.
106  This is called by the host to inform the UI about parameter changes.
107  */
108  virtual void d_parameterChanged(uint32_t index, float value) = 0;
109 
110 #if DISTRHO_PLUGIN_WANT_PROGRAMS
111  /**
112  The current program has changed on the plugin side.
113  This is called by the host to inform the UI about program changes.
114  */
115  virtual void d_programChanged(uint32_t index) = 0;
116 #endif
117 
118 #if DISTRHO_PLUGIN_WANT_STATE
119  /**
120  A state has changed on the plugin side.
121  This is called by the host to inform the UI about state changes.
122  */
123  virtual void d_stateChanged(const char* key, const char* value) = 0;
124 #endif
125 
126  /* --------------------------------------------------------------------------------------------------------
127  * DSP/Plugin Callbacks (optional) */
128 
129  /**
130  Optional callback to inform the UI about a sample rate change on the plugin side.
131  @see d_getSampleRate()
132  */
133  virtual void d_sampleRateChanged(double newSampleRate);
134 
135  /* --------------------------------------------------------------------------------------------------------
136  * UI Callbacks (optional) */
137 
138  /**
139  TODO: Document this.
140  */
141  virtual void d_uiIdle() {}
142 
143  /**
144  File browser selected function.
145  @see Window::fileBrowserSelected(const char*)
146  */
147  virtual void d_uiFileBrowserSelected(const char* filename);
148 
149  /**
150  OpenGL window reshape function, called when parent window is resized.
151  You can reimplement this function for a custom OpenGL state.
152  @see Window::onReshape(uint,uint)
153  */
154  virtual void d_uiReshape(uint width, uint height);
155 
156  /* --------------------------------------------------------------------------------------------------------
157  * UI Resize Handling, internal */
158 
159  /**
160  OpenGL widget resize function, called when the widget is resized.
161  This is overriden here so the host knows when the UI is resized by you.
162  @see Widget::onResize(const ResizeEvent&)
163  */
164  void onResize(const ResizeEvent& ev) override;
165 
166  // -------------------------------------------------------------------------------------------------------
167 
168 private:
169  struct PrivateData;
170  PrivateData* const pData;
171  friend class UIExporter;
172  friend class UIExporterWindow;
173 
174  // these should not be used
175  void setAbsoluteX(int) const noexcept {}
176  void setAbsoluteY(int) const noexcept {}
177  void setAbsolutePos(int, int) const noexcept {}
178  void setAbsolutePos(const DGL::Point<int>&) const noexcept {}
179  void setNeedsFullViewport(bool) const noexcept {}
180 
181  DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(UI)
182 };
183 
184 /* ------------------------------------------------------------------------------------------------------------
185  * Create UI, entry point */
186 
187 /**
188  TODO.
189  */
190 extern UI* createUI();
191 
192 // -----------------------------------------------------------------------------------------------------------
193 
194 END_NAMESPACE_DISTRHO
195 
196 #endif // DISTRHO_UI_HPP_INCLUDED
virtual void d_sampleRateChanged(double newSampleRate)
void onResize(const ResizeEvent &ev) override
virtual ~UI()
virtual void d_stateChanged(const char *key, const char *value)=0
void * d_getPluginInstancePointer() const noexcept
virtual void d_parameterChanged(uint32_t index, float value)=0
virtual void d_uiFileBrowserSelected(const char *filename)
void d_setState(const char *const key, const char *const value)
virtual void d_programChanged(uint32_t index)=0
UI(uint width=0, uint height=0)
virtual void d_uiIdle()
Definition: DistrhoUI.hpp:141
void d_sendNote(const uint8_t channel, const uint8_t note, const uint8_t velocity)
void d_editParameter(const uint32_t index, const bool started)
Definition: DistrhoUI.hpp:43
double d_getSampleRate() const noexcept
void d_setParameterValue(const uint32_t index, const float value)
virtual void d_uiReshape(uint width, uint height)