1 /*
2 * DISTRHO Plugin Framework (DPF)
3 * Copyright (C) 2012-2018 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 ExternalExamplePlugin : public Plugin
27 {
28 public:
ExternalExamplePlugin()29 ExternalExamplePlugin()
30 : Plugin(kParameterCount, 0, 0),
31 fValue(0.0f)
32 {
33 }
34
35 protected:
36 /* --------------------------------------------------------------------------------------------------------
37 * Information */
38
39 /**
40 Get the plugin label.
41 This label is a short restricted name consisting of only _, a-z, A-Z and 0-9 characters.
42 */
getLabel() const43 const char* getLabel() const override
44 {
45 return "ExternalUI";
46 }
47
48 /**
49 Get an extensive comment/description about the plugin.
50 */
getDescription() const51 const char* getDescription() const override
52 {
53 return "Plugin to show how to use an external / remote UI.";
54 }
55
56 /**
57 Get the plugin author/maker.
58 */
getMaker() const59 const char* getMaker() const override
60 {
61 return "DISTRHO";
62 }
63
64 /**
65 Get the plugin homepage.
66 */
getHomePage() const67 const char* getHomePage() const override
68 {
69 return "https://github.com/DISTRHO/DPF";
70 }
71
72 /**
73 Get the plugin license name (a single line of text).
74 For commercial plugins this should return some short copyright information.
75 */
getLicense() const76 const char* getLicense() const override
77 {
78 return "ISC";
79 }
80
81 /**
82 Get the plugin version, in hexadecimal.
83 */
getVersion() const84 uint32_t getVersion() const override
85 {
86 return d_version(1, 0, 0);
87 }
88
89 /**
90 Get the plugin unique Id.
91 This value is used by LADSPA, DSSI and VST plugin formats.
92 */
getUniqueId() const93 int64_t getUniqueId() const override
94 {
95 return d_cconst('d', 'E', 'x', 't');
96 }
97
98 /* --------------------------------------------------------------------------------------------------------
99 * Init */
100
101 /**
102 Initialize the parameter @a index.
103 This function will be called once, shortly after the plugin is created.
104 */
initParameter(uint32_t index,Parameter & parameter)105 void initParameter(uint32_t index, Parameter& parameter) override
106 {
107 if (index != 0)
108 return;
109
110 parameter.hints = kParameterIsAutomable|kParameterIsInteger;
111 parameter.ranges.def = 0.0f;
112 parameter.ranges.min = 0.0f;
113 parameter.ranges.max = 100.0f;
114 parameter.name = "Value";
115 parameter.symbol = "value";
116 }
117
118 /* --------------------------------------------------------------------------------------------------------
119 * Internal data */
120
121 /**
122 Get the current value of a parameter.
123 The host may call this function from any context, including realtime processing.
124 */
getParameterValue(uint32_t index) const125 float getParameterValue(uint32_t index) const override
126 {
127 if (index != 0)
128 return 0.0f;
129
130 return fValue;
131
132 }
133
134 /**
135 Change a parameter value.
136 The host may call this function from any context, including realtime processing.
137 When a parameter is marked as automable, you must ensure no non-realtime operations are performed.
138 @note This function will only be called for parameter inputs.
139 */
setParameterValue(uint32_t index,float value)140 void setParameterValue(uint32_t index, float value) override
141 {
142 if (index != 0)
143 return;
144
145 fValue = value;
146 }
147
148 /* --------------------------------------------------------------------------------------------------------
149 * Audio/MIDI Processing */
150
151 /**
152 Run/process function for plugins without MIDI input.
153 @note Some parameters might be null if there are no audio inputs or outputs.
154 */
run(const float ** inputs,float ** outputs,uint32_t frames)155 void run(const float** inputs, float** outputs, uint32_t frames) override
156 {
157 /**
158 This plugin does nothing, it just demonstrates information usage.
159 So here we directly copy inputs over outputs, leaving the audio untouched.
160 We need to be careful in case the host re-uses the same buffer for both inputs and outputs.
161 */
162 if (outputs[0] != inputs[0])
163 std::memcpy(outputs[0], inputs[0], sizeof(float)*frames);
164 }
165
166 // -------------------------------------------------------------------------------------------------------
167
168 private:
169 // Parameters
170 float fValue;
171
172 /**
173 Set our plugin class as non-copyable and add a leak detector just in case.
174 */
175 DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ExternalExamplePlugin)
176 };
177
178 /* ------------------------------------------------------------------------------------------------------------
179 * Plugin entry point, called by DPF to create a new plugin instance. */
180
createPlugin()181 Plugin* createPlugin()
182 {
183 return new ExternalExamplePlugin();
184 }
185
186 // -----------------------------------------------------------------------------------------------------------
187
188 END_NAMESPACE_DISTRHO
189