1 /**
2 * Copyright: Steinberg.
3 * License:   To use this file you MUST agree with the Steinberg VST license included in the VST SDK.
4 * Authors:   D translation by Guillaume Piolat.
5 */
6 module dplug.vst.aeffect;
7 
8 import core.stdc.string; // for strncpy
9 
10 /** Define SDK Version (you can generate different versions (from 2.0 to 2.4) of this SDK by unsetting the unwanted extensions). */
11 
12 version = VST_2_1_EXTENSIONS; /// Version 2.1 extensions (08-06-2000)
13 version = VST_2_2_EXTENSIONS; /// Version 2.2 extensions (08-06-2001)
14 version = VST_2_3_EXTENSIONS; /// Version 2.3 extensions (20-05-2003)
15 version = VST_2_4_EXTENSIONS; /// Version 2.4 extensions (01-01-2006)
16 
17 /** Current VST Version */
18 version(VST_2_4_EXTENSIONS)
19     enum kVstVersion = 2400;
20 else version(VST_2_3_EXTENSIONS)
21     enum kVstVersion = 2300;
22 else version(VST_2_2_EXTENSIONS)
23     enum kVstVersion = 2200;
24 else version(VST_2_1_EXTENSIONS)
25     enum kVstVersion = 2100;
26 else
27     enum kVstVersion = 2;
28 
29 /** Define for 64 Bit Platform. */
30 static if((void*).sizeof == 8)
31 {
32     version = VST_64BIT_PLATFORM;
33 }
34 
35 //-------------------------------------------------------------------------------------------------------
36 // Integral Types
37 //-------------------------------------------------------------------------------------------------------
38 alias short VstInt16;
39 alias int VstInt32;
40 alias long VstInt64;
41 alias ptrdiff_t VstIntPtr;
42 
43 alias extern(C) nothrow VstIntPtr function(AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt) AEffectDispatcherProc;
44 alias extern(C) nothrow @nogc VstIntPtr function(AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt) HostCallbackFunction;
45 alias extern(C) nothrow void function(AEffect* effect, float** inputs, float** outputs, VstInt32 sampleFrames) AEffectProcessProc;
46 alias extern(C) nothrow void function(AEffect* effect, double** inputs, double** outputs, VstInt32 sampleFrames) AEffectProcessDoubleProc;
47 alias extern(C) nothrow void function(AEffect* effect, VstInt32 index, float parameter) AEffectSetParameterProc;
48 alias extern(C) nothrow float function(AEffect* effect, VstInt32 index) AEffectGetParameterProc;
49 
50 /** AEffect magic number */
51 enum kEffectMagic = CCONST('V', 's', 't', 'P');
52 
53 /// Basic VST Effect "C" Interface.
54 align(8) struct AEffect
55 {
56     VstInt32 magic;         ///< must be #kEffectMagic ('VstP')
57 
58     /** Host to Plug-in dispatcher @see AudioEffect::dispatcher */
59     AEffectDispatcherProc dispatcher;
60 
61     /** \deprecated Accumulating process mode is deprecated in VST 2.4! Use AEffect::processReplacing instead! */
62     AEffectProcessProc DEPRECATED_process;
63 
64     /** Set value of automatable parameter @see AudioEffect::setParameter */
65     AEffectSetParameterProc setParameter;
66 
67     /** Returns current value of automatable parameter @see AudioEffect::getParameter*/
68     AEffectGetParameterProc getParameter;
69 
70     VstInt32 numPrograms;   ///< number of programs
71     VstInt32 numParams;     ///< all programs are assumed to have numParams parameters
72     VstInt32 numInputs;     ///< number of audio inputs
73     VstInt32 numOutputs;    ///< number of audio outputs
74 
75     VstInt32 flags;         ///< @see VstAEffectFlags
76 
77     VstIntPtr resvd1;       ///< reserved for Host, must be 0
78     VstIntPtr resvd2;       ///< reserved for Host, must be 0
79 
80     VstInt32 initialDelay;  ///< for algorithms which need input in the first place (Group delay or latency in Samples). This value should be initialized in a resume state.
81 
82     VstInt32 DEPRECATED_realQualities;    ///< \deprecated unused member
83     VstInt32 DEPRECATED_offQualities;     ///< \deprecated unused member
84     float    DEPRECATED_ioRatio;          ///< \deprecated unused member
85 
86     void* object;           ///< #AudioEffect class pointer
87     void* user;             ///< user-defined pointer
88 
89     VstInt32 uniqueID;      ///< registered unique identifier (register it at Steinberg 3rd party support Web). This is used to identify a plug-in during save+load of preset and project.
90     VstInt32 version_;       ///< plug-in version (example 1100 for version 1.1.0.0)
91 
92     /** Process audio samples in replacing mode @see AudioEffect::processReplacing */
93     AEffectProcessProc processReplacing;
94 
95     version(VST_2_4_EXTENSIONS)
96     {
97         /** Process double-precision audio samples in replacing mode @see AudioEffect::processDoubleReplacing */
98         AEffectProcessDoubleProc processDoubleReplacing;
99 
100         char[56] future;        ///< reserved for future use (please zero)
101     }
102     else
103     {
104         char[60] future;        ///< reserved for future use (please zero)
105     }
106 }
107 
108 /// AEffect flags
109 alias int VstAEffectFlags;
110 enum : VstAEffectFlags
111 {
112     effFlagsHasEditor     = 1 << 0,         /// set if the plug-in provides a custom editor
113     effFlagsCanReplacing  = 1 << 4,         /// supports replacing process mode (which should the default mode in VST 2.4)
114     effFlagsProgramChunks = 1 << 5,         /// program data is handled in formatless chunks
115     effFlagsIsSynth       = 1 << 8,         /// plug-in is a synth (VSTi), Host may assign mixer channels for its outputs
116     effFlagsNoSoundInStop = 1 << 9,         /// plug-in does not produce sound when input is all silence
117 
118     DEPRECATED_effFlagsHasClip = 1 << 1,          /// deprecated in VST 2.4
119     DEPRECATED_effFlagsHasVu   = 1 << 2,          /// deprecated in VST 2.4
120     DEPRECATED_effFlagsCanMono = 1 << 3,          /// deprecated in VST 2.4
121     DEPRECATED_effFlagsExtIsAsync   = 1 << 10,    /// deprecated in VST 2.4
122     DEPRECATED_effFlagsExtHasBuffer = 1 << 11     /// deprecated in VST 2.4
123 }
124 
125 version(VST_2_4_EXTENSIONS)
126 {
127     enum : VstAEffectFlags
128     {
129         effFlagsCanDoubleReplacing = 1 << 12,   ///< plug-in supports double precision processing (VST 2.4)
130     }
131 }
132 
133 
134 /// Basic dispatcher Opcodes (Host to Plug-in) */
135 alias int AEffectOpcodes;
136 enum : AEffectOpcodes
137 {
138     effOpen = 0,        ///< no arguments  @see AudioEffect::open
139     effClose,           ///< no arguments  @see AudioEffect::close
140 
141     effSetProgram,      ///< [value]: program number  @see AudioEffect::setProgram
142     effGetProgram,      ///< [return value]: current program number  @see AudioEffect::getProgram
143     effSetProgramName,  ///< [ptr]: char* with program name, limited to #kVstMaxProgNameLen  @see AudioEffect::setProgramName
144     effGetProgramName,  ///< [ptr]: char buffer for current program name, limited to #kVstMaxProgNameLen  @see AudioEffect::getProgramName
145 
146     effGetParamLabel,   ///< [ptr]: char buffer for parameter label, limited to #kVstMaxParamStrLen  @see AudioEffect::getParameterLabel
147     effGetParamDisplay, ///< [ptr]: char buffer for parameter display, limited to #kVstMaxParamStrLen  @see AudioEffect::getParameterDisplay
148     effGetParamName,    ///< [ptr]: char buffer for parameter name, limited to #kVstMaxParamStrLen  @see AudioEffect::getParameterName
149 
150     DEPRECATED_effGetVu,  ///< \deprecated deprecated in VST 2.4
151 
152     effSetSampleRate,   ///< [opt]: sample rate for audio processing  @see AudioEffect::setSampleRate
153     effSetBlockSize,    ///< [value]: maximum block size for audio processing  @see AudioEffect::setBlockSize
154     effMainsChanged,    ///< [value]: 0 means "turn off", 1 means "turn on"  @see AudioEffect::suspend @see AudioEffect::resume
155 
156     effEditGetRect,     ///< [ptr]: #ERect** receiving pointer to editor size  @see ERect @see AEffEditor::getRect
157     effEditOpen,        ///< [ptr]: system dependent Window pointer, e.g. HWND on Windows  @see AEffEditor::open
158     effEditClose,       ///< no arguments @see AEffEditor::close
159 
160     DEPRECATED_effEditDraw,   ///< \deprecated deprecated in VST 2.4
161     DEPRECATED_effEditMouse,  ///< \deprecated deprecated in VST 2.4
162     DEPRECATED_effEditKey,    ///< \deprecated deprecated in VST 2.4
163 
164     effEditIdle,        ///< no arguments @see AEffEditor::idle
165 
166     DEPRECATED_effEditTop,    ///< \deprecated deprecated in VST 2.4
167     DEPRECATED_effEditSleep,  ///< \deprecated deprecated in VST 2.4
168     DEPRECATED_effIdentify,   ///< \deprecated deprecated in VST 2.4
169 
170     effGetChunk,        ///< [ptr]: void** for chunk data address [index]: 0 for bank, 1 for program  @see AudioEffect::getChunk
171     effSetChunk,        ///< [ptr]: chunk data [value]: byte size [index]: 0 for bank, 1 for program  @see AudioEffect::setChunk
172 
173     effNumOpcodes
174 }
175 
176 /// Basic dispatcher Opcodes (Plug-in to Host)
177 alias int AudioMasterOpcodes;
178 enum : AudioMasterOpcodes
179 {
180     audioMasterAutomate = 0,    ///< [index]: parameter index [opt]: parameter value  @see AudioEffect::setParameterAutomated
181     audioMasterVersion,         ///< [return value]: Host VST version (for example 2400 for VST 2.4) @see AudioEffect::getMasterVersion
182     audioMasterCurrentId,       ///< [return value]: current unique identifier on shell plug-in  @see AudioEffect::getCurrentUniqueId
183     audioMasterIdle,            ///< no arguments  @see AudioEffect::masterIdle
184     DEPRECATED_audioMasterPinConnected ///< \deprecated deprecated in VST 2.4 r2
185 }
186 
187 /// String length limits (in characters excl. 0 byte)
188 enum VstStringConstants
189 {
190     kVstMaxProgNameLen   = 24,  ///< used for #effGetProgramName, #effSetProgramName, #effGetProgramNameIndexed
191     kVstMaxParamStrLen   = 8,   ///< used for #effGetParamLabel, #effGetParamDisplay, #effGetParamName
192     kVstMaxVendorStrLen  = 64,  ///< used for #effGetVendorString, #audioMasterGetVendorString
193     kVstMaxProductStrLen = 64,  ///< used for #effGetProductString, #audioMasterGetProductString
194     kVstMaxEffectNameLen = 32   ///< used for #effGetEffectName
195 }
196 
197 
198 /// String copy taking care of null terminator.
199 char* vst_strncpy (char* dst, const char* src, size_t maxLen)
200 {
201     char* result = strncpy (dst, src, maxLen);
202     dst[maxLen] = 0;
203     return result;
204 }
205 
206 //-------------------------------------------------------------------------------------------------------
207 /** String concatenation taking care of null terminator. */
208 //-------------------------------------------------------------------------------------------------------
209 char* vst_strncat (char* dst, const char* src, size_t maxLen)
210 {
211     char* result = strncat (dst, src, maxLen);
212     dst[maxLen] = 0;
213     return result;
214 }
215 
216 //-------------------------------------------------------------------------------------------------------
217 /** Cast #VstIntPtr to pointer. */
218 //-------------------------------------------------------------------------------------------------------
219 T* FromVstPtr(T)(VstIntPtr arg)
220 {
221     T** address = cast(T**)&arg;
222     return *address;
223 }
224 
225 //-------------------------------------------------------------------------------------------------------
226 /** Cast pointer to #VstIntPtr. */
227 //-------------------------------------------------------------------------------------------------------
228 VstIntPtr ToVstPtr(T)(T* ptr)
229 {
230     VstIntPtr* address = cast(VstIntPtr*)&ptr;
231     return *address;
232 }
233 
234 /// Structure used for #effEditGetRect.
235 struct ERect
236 {
237     VstInt16 top;       ///< top coordinate
238     VstInt16 left;      ///< left coordinate
239     VstInt16 bottom;    ///< bottom coordinate
240     VstInt16 right;     ///< right coordinate
241 }
242 
243 /** Four Character Constant (for AEffect->uniqueID) */
244 private int CCONST(int a, int b, int c, int d) pure nothrow
245 {
246     return (a << 24) | (b << 16) | (c << 8) | (d << 0);
247 }