2 * DISTRHO Plugin Framework (DPF)
3 * Copyright (C) 2012-2022 Filipe Coelho <falktx@falktx.com>
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.
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.
17 #include "DistrhoPluginInternal.hpp"
19 START_NAMESPACE_DISTRHO
21 /* ------------------------------------------------------------------------------------------------------------
22 * Static data, see DistrhoPluginInternal.hpp */
24 uint32_t d_nextBufferSize
= 0;
25 double d_nextSampleRate
= 0.0;
26 const char* d_nextBundlePath
= nullptr;
27 bool d_nextPluginIsDummy
= false;
28 bool d_nextCanRequestParameterValueChanges
= false;
30 /* ------------------------------------------------------------------------------------------------------------
31 * Static fallback data, see DistrhoPluginInternal.hpp */
33 const String
PluginExporter::sFallbackString
;
34 /* */ AudioPortWithBusId
PluginExporter::sFallbackAudioPort
;
35 const ParameterRanges
PluginExporter::sFallbackRanges
;
36 const ParameterEnumerationValues
PluginExporter::sFallbackEnumValues
;
37 const PortGroupWithId
PluginExporter::sFallbackPortGroup
;
39 /* ------------------------------------------------------------------------------------------------------------
42 Plugin::Plugin(uint32_t parameterCount
, uint32_t programCount
, uint32_t stateCount
)
43 : pData(new PrivateData())
45 #if DISTRHO_PLUGIN_NUM_INPUTS+DISTRHO_PLUGIN_NUM_OUTPUTS > 0
46 pData
->audioPorts
= new AudioPortWithBusId
[DISTRHO_PLUGIN_NUM_INPUTS
+DISTRHO_PLUGIN_NUM_OUTPUTS
];
49 #ifdef DPF_ABORT_ON_ERROR
50 # define DPF_ABORT abort();
55 if (parameterCount
> 0)
57 pData
->parameterCount
= parameterCount
;
58 pData
->parameters
= new Parameter
[parameterCount
];
63 #if DISTRHO_PLUGIN_WANT_PROGRAMS
64 pData
->programCount
= programCount
;
65 pData
->programNames
= new String
[programCount
];
67 d_stderr2("DPF warning: Plugins with programs must define `DISTRHO_PLUGIN_WANT_PROGRAMS` to 1");
74 #if DISTRHO_PLUGIN_WANT_STATE
75 pData
->stateCount
= stateCount
;
76 pData
->states
= new State
[stateCount
];
78 d_stderr2("DPF warning: Plugins with state must define `DISTRHO_PLUGIN_WANT_STATE` to 1");
91 /* ------------------------------------------------------------------------------------------------------------
94 uint32_t Plugin::getBufferSize() const noexcept
96 return pData
->bufferSize
;
99 double Plugin::getSampleRate() const noexcept
101 return pData
->sampleRate
;
104 const char* Plugin::getBundlePath() const noexcept
106 return pData
->bundlePath
;
109 bool Plugin::isDummyInstance() const noexcept
111 return pData
->isDummy
;
114 #if DISTRHO_PLUGIN_WANT_TIMEPOS
115 const TimePosition
& Plugin::getTimePosition() const noexcept
117 return pData
->timePosition
;
121 #if DISTRHO_PLUGIN_WANT_LATENCY
122 void Plugin::setLatency(uint32_t frames
) noexcept
124 pData
->latency
= frames
;
128 #if DISTRHO_PLUGIN_WANT_MIDI_OUTPUT
129 bool Plugin::writeMidiEvent(const MidiEvent
& midiEvent
) noexcept
131 return pData
->writeMidiCallback(midiEvent
);
135 #if DISTRHO_PLUGIN_WANT_PARAMETER_VALUE_CHANGE_REQUEST
136 bool Plugin::canRequestParameterValueChanges() const noexcept
138 return pData
->canRequestParameterValueChanges
;
141 bool Plugin::requestParameterValueChange(const uint32_t index
, const float value
) noexcept
143 return pData
->requestParameterValueChangeCallback(index
, value
);
147 #if DISTRHO_PLUGIN_WANT_STATE
148 bool Plugin::updateStateValue(const char* const key
, const char* const value
) noexcept
150 return pData
->updateStateValueCallback(key
, value
);
154 /* ------------------------------------------------------------------------------------------------------------
157 void Plugin::initAudioPort(bool input
, uint32_t index
, AudioPort
& port
)
159 if (port
.hints
& kAudioPortIsCV
)
161 port
.name
= input
? "CV Input " : "CV Output ";
162 port
.name
+= String(index
+1);
163 port
.symbol
= input
? "cv_in_" : "cv_out_";
164 port
.symbol
+= String(index
+1);
168 port
.name
= input
? "Audio Input " : "Audio Output ";
169 port
.name
+= String(index
+1);
170 port
.symbol
= input
? "audio_in_" : "audio_out_";
171 port
.symbol
+= String(index
+1);
175 void Plugin::initParameter(uint32_t, Parameter
&) {}
177 void Plugin::initPortGroup(const uint32_t groupId
, PortGroup
& portGroup
)
179 fillInPredefinedPortGroupData(groupId
, portGroup
);
182 #if DISTRHO_PLUGIN_WANT_PROGRAMS
183 void Plugin::initProgramName(uint32_t, String
&) {}
186 #if DISTRHO_PLUGIN_WANT_STATE
187 void Plugin::initState(const uint32_t index
, State
& state
)
190 String stateKey
, defaultStateValue
;
192 #if defined(__clang__)
193 #pragma clang diagnostic push
194 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
195 #elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
196 #pragma GCC diagnostic push
197 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
199 initState(index
, stateKey
, defaultStateValue
);
200 if (isStateFile(index
))
201 hints
= kStateIsFilenamePath
;
202 #if defined(__clang__)
203 #pragma clang diagnostic pop
204 #elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
205 #pragma GCC diagnostic pop
209 state
.key
= stateKey
;
210 state
.label
= stateKey
;
211 state
.defaultValue
= defaultStateValue
;
215 /* ------------------------------------------------------------------------------------------------------------
218 float Plugin::getParameterValue(uint32_t) const { return 0.0f
; }
219 void Plugin::setParameterValue(uint32_t, float) {}
221 #if DISTRHO_PLUGIN_WANT_PROGRAMS
222 void Plugin::loadProgram(uint32_t) {}
225 #if DISTRHO_PLUGIN_WANT_FULL_STATE
226 String
Plugin::getState(const char*) const { return String(); }
229 #if DISTRHO_PLUGIN_WANT_STATE
230 void Plugin::setState(const char*, const char*) {}
233 /* ------------------------------------------------------------------------------------------------------------
234 * Callbacks (optional) */
236 void Plugin::bufferSizeChanged(uint32_t) {}
237 void Plugin::sampleRateChanged(double) {}
239 // -----------------------------------------------------------------------------------------------------------
241 END_NAMESPACE_DISTRHO