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 "DistrhoPluginInternal.hpp"
18
19 START_NAMESPACE_DISTRHO
20
21 /* ------------------------------------------------------------------------------------------------------------
22 * Static data, see DistrhoPluginInternal.hpp */
23
24 uint32_t d_lastBufferSize = 0;
25 double d_lastSampleRate = 0.0;
26
27 /* ------------------------------------------------------------------------------------------------------------
28 * Static fallback data, see DistrhoPluginInternal.hpp */
29
30 const String PluginExporter::sFallbackString;
31 const AudioPort PluginExporter::sFallbackAudioPort;
32 const ParameterRanges PluginExporter::sFallbackRanges;
33 const ParameterEnumerationValues PluginExporter::sFallbackEnumValues;
34
35 /* ------------------------------------------------------------------------------------------------------------
36 * Plugin */
37
Plugin(uint32_t parameterCount,uint32_t programCount,uint32_t stateCount)38 Plugin::Plugin(uint32_t parameterCount, uint32_t programCount, uint32_t stateCount)
39 : pData(new PrivateData())
40 {
41 #if DISTRHO_PLUGIN_NUM_INPUTS+DISTRHO_PLUGIN_NUM_OUTPUTS > 0
42 pData->audioPorts = new AudioPort[DISTRHO_PLUGIN_NUM_INPUTS+DISTRHO_PLUGIN_NUM_OUTPUTS];
43 #endif
44
45 if (parameterCount > 0)
46 {
47 pData->parameterCount = parameterCount;
48 pData->parameters = new Parameter[parameterCount];
49 }
50
51 #if DISTRHO_PLUGIN_WANT_PROGRAMS
52 if (programCount > 0)
53 {
54 pData->programCount = programCount;
55 pData->programNames = new String[programCount];
56 }
57 #else
58 DISTRHO_SAFE_ASSERT(programCount == 0);
59 #endif
60
61 #if DISTRHO_PLUGIN_WANT_STATE
62 if (stateCount > 0)
63 {
64 pData->stateCount = stateCount;
65 pData->stateKeys = new String[stateCount];
66 pData->stateDefValues = new String[stateCount];
67 }
68 #else
69 DISTRHO_SAFE_ASSERT(stateCount == 0);
70 #endif
71 }
72
~Plugin()73 Plugin::~Plugin()
74 {
75 delete pData;
76 }
77
78 /* ------------------------------------------------------------------------------------------------------------
79 * Host state */
80
getBufferSize() const81 uint32_t Plugin::getBufferSize() const noexcept
82 {
83 return pData->bufferSize;
84 }
85
getSampleRate() const86 double Plugin::getSampleRate() const noexcept
87 {
88 return pData->sampleRate;
89 }
90
91 #if DISTRHO_PLUGIN_WANT_TIMEPOS
getTimePosition() const92 const TimePosition& Plugin::getTimePosition() const noexcept
93 {
94 return pData->timePosition;
95 }
96 #endif
97
98 #if DISTRHO_PLUGIN_WANT_LATENCY
setLatency(uint32_t frames)99 void Plugin::setLatency(uint32_t frames) noexcept
100 {
101 pData->latency = frames;
102 }
103 #endif
104
105 #if DISTRHO_PLUGIN_WANT_MIDI_OUTPUT
writeMidiEvent(const MidiEvent & midiEvent)106 bool Plugin::writeMidiEvent(const MidiEvent& midiEvent) noexcept
107 {
108 return pData->writeMidiCallback(midiEvent);
109 }
110 #endif
111
112 /* ------------------------------------------------------------------------------------------------------------
113 * Init */
114
initAudioPort(bool input,uint32_t index,AudioPort & port)115 void Plugin::initAudioPort(bool input, uint32_t index, AudioPort& port)
116 {
117 if (port.hints & kAudioPortIsCV)
118 {
119 port.name = input ? "CV Input " : "CV Output ";
120 port.name += String(index+1);
121 port.symbol = input ? "cv_in_" : "cv_out_";
122 port.symbol += String(index+1);
123 }
124 else
125 {
126 port.name = input ? "Audio Input " : "Audio Output ";
127 port.name += String(index+1);
128 port.symbol = input ? "audio_in_" : "audio_out_";
129 port.symbol += String(index+1);
130 }
131 }
132
133 /* ------------------------------------------------------------------------------------------------------------
134 * Callbacks (optional) */
135
bufferSizeChanged(uint32_t)136 void Plugin::bufferSizeChanged(uint32_t) {}
sampleRateChanged(double)137 void Plugin::sampleRateChanged(double) {}
138
139 // -----------------------------------------------------------------------------------------------------------
140
141 END_NAMESPACE_DISTRHO
142