1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
|
//-------------------------------------------------------------------------------------------------------
// VST Plug-Ins SDK
// Version 2.4 $Date: 2006/11/13 09:08:28 $
//
// Category : VST 2.x SDK Samples
// Filename : minihost.cpp
// Created by : Steinberg
// Description : VST Mini Host
//
// � 2006, Steinberg Media Technologies, All Rights Reserved
//-------------------------------------------------------------------------------------------------------
#include "pluginterfaces/vst2.x/aeffectx.h"
#if _WIN32
#include <windows.h>
#elif TARGET_API_MAC_CARBON
#include <CoreFoundation/CoreFoundation.h>
#endif
#include <stdio.h>
//-------------------------------------------------------------------------------------------------------
static const VstInt32 kBlockSize = 512;
static const float kSampleRate = 48000.f;
static const VstInt32 kNumProcessCycles = 5;
//-------------------------------------------------------------------------------------------------------
typedef AEffect* (*PluginEntryProc) (audioMasterCallback audioMaster);
static VstIntPtr VSTCALLBACK HostCallback (AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt);
//-------------------------------------------------------------------------------------------------------
// PluginLoader
//-------------------------------------------------------------------------------------------------------
struct PluginLoader
{
//-------------------------------------------------------------------------------------------------------
void* module;
PluginLoader ()
: module (0)
{}
~PluginLoader ()
{
if (module)
{
#if _WIN32
FreeLibrary ((HMODULE)module);
#elif TARGET_API_MAC_CARBON
CFBundleUnloadExecutable ((CFBundleRef)module);
CFRelease ((CFBundleRef)module);
#endif
}
}
bool loadLibrary (const char* fileName)
{
#if _WIN32
module = LoadLibrary (fileName);
#elif TARGET_API_MAC_CARBON
CFStringRef fileNameString = CFStringCreateWithCString (NULL, fileName, kCFStringEncodingUTF8);
if (fileNameString == 0)
return false;
CFURLRef url = CFURLCreateWithFileSystemPath (NULL, fileNameString, kCFURLPOSIXPathStyle, false);
CFRelease (fileNameString);
if (url == 0)
return false;
module = CFBundleCreate (NULL, url);
CFRelease (url);
if (module && CFBundleLoadExecutable ((CFBundleRef)module) == false)
return false;
#endif
return module != 0;
}
PluginEntryProc getMainEntry ()
{
PluginEntryProc mainProc = 0;
#if _WIN32
mainProc = (PluginEntryProc)GetProcAddress ((HMODULE)module, "VSTPluginMain");
if (!mainProc)
mainProc = (PluginEntryProc)GetProcAddress ((HMODULE)module, "main");
#elif TARGET_API_MAC_CARBON
mainProc = (PluginEntryProc)CFBundleGetFunctionPointerForName ((CFBundleRef)module, CFSTR("VSTPluginMain"));
if (!mainProc)
mainProc = (PluginEntryProc)CFBundleGetFunctionPointerForName ((CFBundleRef)module, CFSTR("main_macho"));
#endif
return mainProc;
}
//-------------------------------------------------------------------------------------------------------
};
//-------------------------------------------------------------------------------------------------------
static bool checkPlatform ()
{
#if VST_64BIT_PLATFORM
printf ("*** This is a 64 Bit Build! ***\n");
#else
printf ("*** This is a 32 Bit Build! ***\n");
#endif
int sizeOfVstIntPtr = sizeof (VstIntPtr);
int sizeOfVstInt32 = sizeof (VstInt32);
int sizeOfPointer = sizeof (void*);
int sizeOfAEffect = sizeof (AEffect);
printf ("VstIntPtr = %d Bytes, VstInt32 = %d Bytes, Pointer = %d Bytes, AEffect = %d Bytes\n\n",
sizeOfVstIntPtr, sizeOfVstInt32, sizeOfPointer, sizeOfAEffect);
return sizeOfVstIntPtr == sizeOfPointer;
}
//-------------------------------------------------------------------------------------------------------
static void checkEffectProperties (AEffect* effect);
static void checkEffectProcessing (AEffect* effect);
extern bool checkEffectEditor (AEffect* effect); // minieditor.cpp
//-------------------------------------------------------------------------------------------------------
int main (int argc, char* argv[])
{
if (!checkPlatform ())
{
printf ("Platform verification failed! Please check your Compiler Settings!\n");
return -1;
}
const char* fileName = "again.dll";
//const char* fileName = "adelay.dll";
//const char* fileName = "surrounddelay.dll";
//const char* fileName = "vstxsynth.dll";
//const char* fileName = "drawtest.dll";
if (argc > 1)
fileName = argv[1];
printf ("HOST> Load library...\n");
PluginLoader loader;
if (!loader.loadLibrary (fileName))
{
printf ("Failed to load VST Plugin library!\n");
return -1;
}
PluginEntryProc mainEntry = loader.getMainEntry ();
if (!mainEntry)
{
printf ("VST Plugin main entry not found!\n");
return -1;
}
printf ("HOST> Create effect...\n");
AEffect* effect = mainEntry (HostCallback);
if (!effect)
{
printf ("Failed to create effect instance!\n");
return -1;
}
printf ("HOST> Init sequence...\n");
effect->dispatcher (effect, effOpen, 0, 0, 0, 0);
effect->dispatcher (effect, effSetSampleRate, 0, 0, 0, kSampleRate);
effect->dispatcher (effect, effSetBlockSize, 0, kBlockSize, 0, 0);
checkEffectProperties (effect);
checkEffectProcessing (effect);
checkEffectEditor (effect);
printf ("HOST> Close effect...\n");
effect->dispatcher (effect, effClose, 0, 0, 0, 0);
return 0;
}
//-------------------------------------------------------------------------------------------------------
void checkEffectProperties (AEffect* effect)
{
printf ("HOST> Gathering properties...\n");
char effectName[256] = {0};
char vendorString[256] = {0};
char productString[256] = {0};
effect->dispatcher (effect, effGetEffectName, 0, 0, effectName, 0);
effect->dispatcher (effect, effGetVendorString, 0, 0, vendorString, 0);
effect->dispatcher (effect, effGetProductString, 0, 0, productString, 0);
printf ("Name = %s\nVendor = %s\nProduct = %s\n\n", effectName, vendorString, productString);
printf ("numPrograms = %d\nnumParams = %d\nnumInputs = %d\nnumOutputs = %d\n\n",
effect->numPrograms, effect->numParams, effect->numInputs, effect->numOutputs);
// Iterate programs...
for (VstInt32 progIndex = 0; progIndex < effect->numPrograms; progIndex++)
{
char progName[256] = {0};
if (!effect->dispatcher (effect, effGetProgramNameIndexed, progIndex, 0, progName, 0))
{
effect->dispatcher (effect, effSetProgram, 0, progIndex, 0, 0); // Note: old program not restored here!
effect->dispatcher (effect, effGetProgramName, 0, 0, progName, 0);
}
printf ("Program %03d: %s\n", progIndex, progName);
}
printf ("\n");
// Iterate parameters...
for (VstInt32 paramIndex = 0; paramIndex < effect->numParams; paramIndex++)
{
char paramName[256] = {0};
char paramLabel[256] = {0};
char paramDisplay[256] = {0};
effect->dispatcher (effect, effGetParamName, paramIndex, 0, paramName, 0);
effect->dispatcher (effect, effGetParamLabel, paramIndex, 0, paramLabel, 0);
effect->dispatcher (effect, effGetParamDisplay, paramIndex, 0, paramDisplay, 0);
float value = effect->getParameter (effect, paramIndex);
printf ("Param %03d: %s [%s %s] (normalized = %f)\n", paramIndex, paramName, paramDisplay, paramLabel, value);
}
printf ("\n");
// Can-do nonsense...
static const char* canDos[] =
{
"receiveVstEvents",
"receiveVstMidiEvent",
"midiProgramNames"
};
for (VstInt32 canDoIndex = 0; canDoIndex < sizeof (canDos) / sizeof (canDos[0]); canDoIndex++)
{
printf ("Can do %s... ", canDos[canDoIndex]);
VstInt32 result = (VstInt32)effect->dispatcher (effect, effCanDo, 0, 0, (void*)canDos[canDoIndex], 0);
switch (result)
{
case 0 : printf ("don't know"); break;
case 1 : printf ("yes"); break;
case -1 : printf ("definitely not!"); break;
default : printf ("?????");
}
printf ("\n");
}
printf ("\n");
}
//-------------------------------------------------------------------------------------------------------
void checkEffectProcessing (AEffect* effect)
{
float** inputs = 0;
float** outputs = 0;
VstInt32 numInputs = effect->numInputs;
VstInt32 numOutputs = effect->numOutputs;
if (numInputs > 0)
{
inputs = new float*[numInputs];
for (VstInt32 i = 0; i < numInputs; i++)
{
inputs[i] = new float[kBlockSize];
memset (inputs[i], 0, kBlockSize * sizeof (float));
}
}
if (numOutputs > 0)
{
outputs = new float*[numOutputs];
for (VstInt32 i = 0; i < numOutputs; i++)
{
outputs[i] = new float[kBlockSize];
memset (outputs[i], 0, kBlockSize * sizeof (float));
}
}
printf ("HOST> Resume effect...\n");
effect->dispatcher (effect, effMainsChanged, 0, 1, 0, 0);
for (VstInt32 processCount = 0; processCount < kNumProcessCycles; processCount++)
{
printf ("HOST> Process Replacing...\n");
effect->processReplacing (effect, inputs, outputs, kBlockSize);
}
printf ("HOST> Suspend effect...\n");
effect->dispatcher (effect, effMainsChanged, 0, 0, 0, 0);
if (numInputs > 0)
{
for (VstInt32 i = 0; i < numInputs; i++)
delete [] inputs[i];
delete [] inputs;
}
if (numOutputs > 0)
{
for (VstInt32 i = 0; i < numOutputs; i++)
delete [] outputs[i];
delete [] outputs;
}
}
//-------------------------------------------------------------------------------------------------------
VstIntPtr VSTCALLBACK HostCallback (AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt)
{
VstIntPtr result = 0;
// Filter idle calls...
bool filtered = false;
if (opcode == audioMasterIdle)
{
static bool wasIdle = false;
if (wasIdle)
filtered = true;
else
{
printf ("(Future idle calls will not be displayed!)\n");
wasIdle = true;
}
}
if (!filtered)
printf ("PLUG> HostCallback (opcode %d)\n index = %d, value = %p, ptr = %p, opt = %f\n", opcode, index, FromVstPtr<void> (value), ptr, opt);
switch (opcode)
{
case audioMasterVersion :
result = kVstVersion;
break;
}
return result;
}
|