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