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