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 #include "DistrhoPlugin.hpp"
18
19 START_NAMESPACE_DISTRHO
20
21 // -----------------------------------------------------------------------------------------------------------
22
23 /**
24 Plugin to show how to get some basic information sent to the UI.
25 */
26 class InfoExamplePlugin : public Plugin
27 {
28 public:
InfoExamplePlugin()29 InfoExamplePlugin()
30 : Plugin(kParameterCount, 0, 0)
31 {
32 // clear all parameters
33 std::memset(fParameters, 0, sizeof(float)*kParameterCount);
34
35 // we can know buffer-size right at the start
36 fParameters[kParameterBufferSize] = getBufferSize();
37 }
38
39 protected:
40 /* --------------------------------------------------------------------------------------------------------
41 * Information */
42
43 /**
44 Get the plugin label.
45 This label is a short restricted name consisting of only _, a-z, A-Z and 0-9 characters.
46 */
getLabel() const47 const char* getLabel() const override
48 {
49 return "Info";
50 }
51
52 /**
53 Get an extensive comment/description about the plugin.
54 */
getDescription() const55 const char* getDescription() const override
56 {
57 return "Plugin to show how to get some basic information sent to the UI.";
58 }
59
60 /**
61 Get the plugin author/maker.
62 */
getMaker() const63 const char* getMaker() const override
64 {
65 return "DISTRHO";
66 }
67
68 /**
69 Get the plugin homepage.
70 */
getHomePage() const71 const char* getHomePage() const override
72 {
73 return "https://github.com/DISTRHO/DPF";
74 }
75
76 /**
77 Get the plugin license name (a single line of text).
78 For commercial plugins this should return some short copyright information.
79 */
getLicense() const80 const char* getLicense() const override
81 {
82 return "ISC";
83 }
84
85 /**
86 Get the plugin version, in hexadecimal.
87 */
getVersion() const88 uint32_t getVersion() const override
89 {
90 return d_version(1, 0, 0);
91 }
92
93 /**
94 Get the plugin unique Id.
95 This value is used by LADSPA, DSSI and VST plugin formats.
96 */
getUniqueId() const97 int64_t getUniqueId() const override
98 {
99 return d_cconst('d', 'N', 'f', 'o');
100 }
101
102 /* --------------------------------------------------------------------------------------------------------
103 * Init */
104
105 /**
106 Initialize the parameter @a index.
107 This function will be called once, shortly after the plugin is created.
108 */
initParameter(uint32_t index,Parameter & parameter)109 void initParameter(uint32_t index, Parameter& parameter) override
110 {
111 parameter.hints = kParameterIsAutomable|kParameterIsOutput;
112 parameter.ranges.def = 0.0f;
113 parameter.ranges.min = 0.0f;
114 parameter.ranges.max = 16777216.0f;
115
116 switch (index)
117 {
118 case kParameterBufferSize:
119 parameter.name = "BufferSize";
120 parameter.symbol = "buffer_size";
121 break;
122 case kParameterTimePlaying:
123 parameter.hints |= kParameterIsBoolean;
124 parameter.name = "TimePlaying";
125 parameter.symbol = "time_playing";
126 parameter.ranges.min = 0.0f;
127 parameter.ranges.max = 1.0f;
128 break;
129 case kParameterTimeFrame:
130 parameter.name = "TimeFrame";
131 parameter.symbol = "time_frame";
132 break;
133 case kParameterTimeValidBBT:
134 parameter.hints |= kParameterIsBoolean;
135 parameter.name = "TimeValidBBT";
136 parameter.symbol = "time_validbbt";
137 parameter.ranges.min = 0.0f;
138 parameter.ranges.max = 1.0f;
139 break;
140 case kParameterTimeBar:
141 parameter.name = "TimeBar";
142 parameter.symbol = "time_bar";
143 break;
144 case kParameterTimeBeat:
145 parameter.name = "TimeBeat";
146 parameter.symbol = "time_beat";
147 break;
148 case kParameterTimeTick:
149 parameter.name = "TimeTick";
150 parameter.symbol = "time_tick";
151 break;
152 case kParameterTimeBarStartTick:
153 parameter.name = "TimeBarStartTick";
154 parameter.symbol = "time_barstarttick";
155 break;
156 case kParameterTimeBeatsPerBar:
157 parameter.name = "TimeBeatsPerBar";
158 parameter.symbol = "time_beatsperbar";
159 break;
160 case kParameterTimeBeatType:
161 parameter.name = "TimeBeatType";
162 parameter.symbol = "time_beattype";
163 break;
164 case kParameterTimeTicksPerBeat:
165 parameter.name = "TimeTicksPerBeat";
166 parameter.symbol = "time_ticksperbeat";
167 break;
168 case kParameterTimeBeatsPerMinute:
169 parameter.name = "TimeBeatsPerMinute";
170 parameter.symbol = "time_beatsperminute";
171 break;
172 }
173 }
174
175 /* --------------------------------------------------------------------------------------------------------
176 * Internal data */
177
178 /**
179 Get the current value of a parameter.
180 The host may call this function from any context, including realtime processing.
181 */
getParameterValue(uint32_t index) const182 float getParameterValue(uint32_t index) const override
183 {
184 return fParameters[index];
185
186 }
187
188 /**
189 Change a parameter value.
190 The host may call this function from any context, including realtime processing.
191 When a parameter is marked as automable, you must ensure no non-realtime operations are performed.
192 @note This function will only be called for parameter inputs.
193 */
setParameterValue(uint32_t,float)194 void setParameterValue(uint32_t, float) override
195 {
196 // this is only called for input parameters, which we have none of.
197 }
198
199 /* --------------------------------------------------------------------------------------------------------
200 * Audio/MIDI Processing */
201
202 /**
203 Run/process function for plugins without MIDI input.
204 @note Some parameters might be null if there are no audio inputs or outputs.
205 */
run(const float ** inputs,float ** outputs,uint32_t frames)206 void run(const float** inputs, float** outputs, uint32_t frames) override
207 {
208 /**
209 This plugin does nothing, it just demonstrates information usage.
210 So here we directly copy inputs over outputs, leaving the audio untouched.
211 We need to be careful in case the host re-uses the same buffer for both ins and outs.
212 */
213 if (outputs[0] != inputs[0])
214 std::memcpy(outputs[0], inputs[0], sizeof(float)*frames);
215
216 if (outputs[1] != inputs[1])
217 std::memcpy(outputs[1], inputs[1], sizeof(float)*frames);
218
219 // get time position
220 const TimePosition& timePos(getTimePosition());
221
222 // set basic values
223 fParameters[kParameterTimePlaying] = timePos.playing ? 1.0f : 0.0f;
224 fParameters[kParameterTimeFrame] = timePos.frame;
225 fParameters[kParameterTimeValidBBT] = timePos.bbt.valid ? 1.0f : 0.0f;
226
227 // set bbt
228 if (timePos.bbt.valid)
229 {
230 fParameters[kParameterTimeBar] = timePos.bbt.bar;
231 fParameters[kParameterTimeBeat] = timePos.bbt.beat;
232 fParameters[kParameterTimeTick] = timePos.bbt.tick;
233 fParameters[kParameterTimeBarStartTick] = timePos.bbt.barStartTick;
234 fParameters[kParameterTimeBeatsPerBar] = timePos.bbt.beatsPerBar;
235 fParameters[kParameterTimeBeatType] = timePos.bbt.beatType;
236 fParameters[kParameterTimeTicksPerBeat] = timePos.bbt.ticksPerBeat;
237 fParameters[kParameterTimeBeatsPerMinute] = timePos.bbt.beatsPerMinute;
238 }
239 else
240 {
241 fParameters[kParameterTimeBar] = 0.0f;
242 fParameters[kParameterTimeBeat] = 0.0f;
243 fParameters[kParameterTimeTick] = 0.0f;
244 fParameters[kParameterTimeBarStartTick] = 0.0f;
245 fParameters[kParameterTimeBeatsPerBar] = 0.0f;
246 fParameters[kParameterTimeBeatType] = 0.0f;
247 fParameters[kParameterTimeTicksPerBeat] = 0.0f;
248 fParameters[kParameterTimeBeatsPerMinute] = 0.0f;
249 }
250 }
251
252 /* --------------------------------------------------------------------------------------------------------
253 * Callbacks (optional) */
254
255 /**
256 Optional callback to inform the plugin about a buffer size change.
257 This function will only be called when the plugin is deactivated.
258 @note This value is only a hint!
259 Hosts might call run() with a higher or lower number of frames.
260 */
bufferSizeChanged(uint32_t newBufferSize)261 void bufferSizeChanged(uint32_t newBufferSize) override
262 {
263 fParameters[kParameterBufferSize] = newBufferSize;
264 }
265
266 // -------------------------------------------------------------------------------------------------------
267
268 private:
269 // Parameters
270 float fParameters[kParameterCount];
271
272 /**
273 Set our plugin class as non-copyable and add a leak detector just in case.
274 */
275 DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(InfoExamplePlugin)
276 };
277
278 /* ------------------------------------------------------------------------------------------------------------
279 * Plugin entry point, called by DPF to create a new plugin instance. */
280
createPlugin()281 Plugin* createPlugin()
282 {
283 return new InfoExamplePlugin();
284 }
285
286 // -----------------------------------------------------------------------------------------------------------
287
288 END_NAMESPACE_DISTRHO
289