LMMS
Loading...
Searching...
No Matches
DistrhoPlugin.cpp
Go to the documentation of this file.
1/*
2 * DISTRHO Plugin Framework (DPF)
3 * Copyright (C) 2012-2022 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 "DistrhoPluginInternal.hpp"
18
20
21/* ------------------------------------------------------------------------------------------------------------
22 * Static data, see DistrhoPluginInternal.hpp */
23
25double d_nextSampleRate = 0.0;
26const char* d_nextBundlePath = nullptr;
29
30/* ------------------------------------------------------------------------------------------------------------
31 * Static fallback data, see DistrhoPluginInternal.hpp */
32
33const String PluginExporter::sFallbackString;
34/* */ AudioPortWithBusId PluginExporter::sFallbackAudioPort;
35const ParameterRanges PluginExporter::sFallbackRanges;
36const ParameterEnumerationValues PluginExporter::sFallbackEnumValues;
37const PortGroupWithId PluginExporter::sFallbackPortGroup;
38
39/* ------------------------------------------------------------------------------------------------------------
40 * Plugin */
41
42Plugin::Plugin(uint32_t parameterCount, uint32_t programCount, uint32_t stateCount)
43 : pData(new PrivateData())
44{
45#if DISTRHO_PLUGIN_NUM_INPUTS+DISTRHO_PLUGIN_NUM_OUTPUTS > 0
46 pData->audioPorts = new AudioPortWithBusId[DISTRHO_PLUGIN_NUM_INPUTS+DISTRHO_PLUGIN_NUM_OUTPUTS];
47#endif
48
49#ifdef DPF_ABORT_ON_ERROR
50# define DPF_ABORT abort();
51#else
52# define DPF_ABORT
53#endif
54
55 if (parameterCount > 0)
56 {
57 pData->parameterCount = parameterCount;
58 pData->parameters = new Parameter[parameterCount];
59 }
60
61 if (programCount > 0)
62 {
63#if DISTRHO_PLUGIN_WANT_PROGRAMS
64 pData->programCount = programCount;
65 pData->programNames = new String[programCount];
66#else
67 d_stderr2("DPF warning: Plugins with programs must define `DISTRHO_PLUGIN_WANT_PROGRAMS` to 1");
69#endif
70 }
71
72 if (stateCount > 0)
73 {
74#if DISTRHO_PLUGIN_WANT_STATE
75 pData->stateCount = stateCount;
76 pData->states = new State[stateCount];
77#else
78 d_stderr2("DPF warning: Plugins with state must define `DISTRHO_PLUGIN_WANT_STATE` to 1");
80#endif
81 }
82
83#undef DPF_ABORT
84}
85
86Plugin::~Plugin()
87{
88 delete pData;
89}
90
91/* ------------------------------------------------------------------------------------------------------------
92 * Host state */
93
94uint32_t Plugin::getBufferSize() const noexcept
95{
96 return pData->bufferSize;
97}
98
99double Plugin::getSampleRate() const noexcept
100{
101 return pData->sampleRate;
102}
103
104const char* Plugin::getBundlePath() const noexcept
105{
106 return pData->bundlePath;
107}
108
109bool Plugin::isDummyInstance() const noexcept
110{
111 return pData->isDummy;
112}
113
114#if DISTRHO_PLUGIN_WANT_TIMEPOS
115const TimePosition& Plugin::getTimePosition() const noexcept
116{
117 return pData->timePosition;
118}
119#endif
120
121#if DISTRHO_PLUGIN_WANT_LATENCY
122void Plugin::setLatency(uint32_t frames) noexcept
123{
124 pData->latency = frames;
125}
126#endif
127
128#if DISTRHO_PLUGIN_WANT_MIDI_OUTPUT
129bool Plugin::writeMidiEvent(const MidiEvent& midiEvent) noexcept
130{
131 return pData->writeMidiCallback(midiEvent);
132}
133#endif
134
135#if DISTRHO_PLUGIN_WANT_PARAMETER_VALUE_CHANGE_REQUEST
136bool Plugin::canRequestParameterValueChanges() const noexcept
137{
138 return pData->canRequestParameterValueChanges;
139}
140
141bool Plugin::requestParameterValueChange(const uint32_t index, const float value) noexcept
142{
143 return pData->requestParameterValueChangeCallback(index, value);
144}
145#endif
146
147#if DISTRHO_PLUGIN_WANT_STATE
148bool Plugin::updateStateValue(const char* const key, const char* const value) noexcept
149{
150 return pData->updateStateValueCallback(key, value);
151}
152#endif
153
154/* ------------------------------------------------------------------------------------------------------------
155 * Init */
156
157void Plugin::initAudioPort(bool input, uint32_t index, AudioPort& port)
158{
159 if (port.hints & kAudioPortIsCV)
160 {
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);
165 }
166 else
167 {
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);
172 }
173}
174
175void Plugin::initParameter(uint32_t, Parameter&) {}
176
177void Plugin::initPortGroup(const uint32_t groupId, PortGroup& portGroup)
178{
179 fillInPredefinedPortGroupData(groupId, portGroup);
180}
181
182#if DISTRHO_PLUGIN_WANT_PROGRAMS
183void Plugin::initProgramName(uint32_t, String&) {}
184#endif
185
186#if DISTRHO_PLUGIN_WANT_STATE
187void Plugin::initState(const uint32_t index, State& state)
188{
189 uint hints = 0x0;
190 String stateKey, defaultStateValue;
191
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"
198 #endif
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
206 #endif
207
208 state.hints = hints;
209 state.key = stateKey;
210 state.label = stateKey;
211 state.defaultValue = defaultStateValue;
212}
213#endif
214
215/* ------------------------------------------------------------------------------------------------------------
216 * Init */
217
218float Plugin::getParameterValue(uint32_t) const { return 0.0f; }
219void Plugin::setParameterValue(uint32_t, float) {}
220
221#if DISTRHO_PLUGIN_WANT_PROGRAMS
222void Plugin::loadProgram(uint32_t) {}
223#endif
224
225#if DISTRHO_PLUGIN_WANT_FULL_STATE
226String Plugin::getState(const char*) const { return String(); }
227#endif
228
229#if DISTRHO_PLUGIN_WANT_STATE
230void Plugin::setState(const char*, const char*) {}
231#endif
232
233/* ------------------------------------------------------------------------------------------------------------
234 * Callbacks (optional) */
235
236void Plugin::bufferSizeChanged(uint32_t) {}
237void Plugin::sampleRateChanged(double) {}
238
239// -----------------------------------------------------------------------------------------------------------
240
unsigned int uint
Definition CarlaDefines.h:327
#define noexcept
Definition DistrhoDefines.h:72
#define END_NAMESPACE_DISTRHO
Definition DistrhoDefines.h:191
#define START_NAMESPACE_DISTRHO
Definition DistrhoDefines.h:190
#define DPF_ABORT
START_NAMESPACE_DISTRHO uint32_t d_nextBufferSize
Definition DistrhoPlugin.cpp:24
const char * d_nextBundlePath
Definition DistrhoPlugin.cpp:26
bool d_nextPluginIsDummy
Definition DistrhoPlugin.cpp:27
bool d_nextCanRequestParameterValueChanges
Definition DistrhoPlugin.cpp:28
double d_nextSampleRate
Definition DistrhoPlugin.cpp:25
Definition String.h:48
#define DISTRHO_PLUGIN_NUM_INPUTS
Definition DistrhoPluginInfo.h:26
#define DISTRHO_PLUGIN_NUM_OUTPUTS
Definition DistrhoPluginInfo.h:27
struct _ParameterRanges ParameterRanges
static PuglViewHint int value
Definition pugl.h:1708
unsigned int uint32_t
Definition mid.cpp:100
jack_client_t client jack_client_t client jack_client_t client jack_client_t JackInfoShutdownCallback void arg jack_client_t jack_port_t * port
Definition juce_linux_JackAudio.cpp:65
Definition InMgr.h:16
Definition sordi.c:34
ZCONST char * key
Definition crypt.c:587
#define const
Definition zconf.h:137