-
Notifications
You must be signed in to change notification settings - Fork 0
/
kode_vst3_plugin.h
260 lines (222 loc) · 9.21 KB
/
kode_vst3_plugin.h
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
#ifndef kode_vst3_plugin_included
#define kode_vst3_plugin_included
//----------------------------------------------------------------------
//
// needs kode_vst3.h, which is gpl3
// so this file also needs to be gpl3
//
//----------------------------------------------------------------------
#include "plugin/vst3/kode_vst3.h"
#include "plugin/vst3/kode_vst3_instance.h"
#include "plugin/vst3/kode_vst3_utils.h"
//----------------------------------------------------------------------
//
//
//
//----------------------------------------------------------------------
template <class DESC, class INST>
class KODE_Vst3Plugin
: public KODE_Vst3IPluginFactory3 {
//------------------------------
private:
//------------------------------
uint32_t MRefCount = 1;
KODE_Vst3FUnknown* MHostContext = nullptr;
DESC MDescriptor;
//------------------------------
public:
//------------------------------
KODE_Vst3Plugin() {
KODE_Vst3Print("1\n");
MRefCount = 1;
}
//----------
virtual ~KODE_Vst3Plugin() {
KODE_VST3PRINT;
}
//------------------------------
public: // FUnknown
//------------------------------
uint32_t KODE_VST3_PLUGIN_API addRef() final {
MRefCount++;
KODE_Vst3Print("-> %i\n",MRefCount);
return MRefCount;
}
//----------
uint32_t KODE_VST3_PLUGIN_API release() final {
const uint32_t r = --MRefCount;
KODE_Vst3Print("-> %i %s",r, (r==0) ? "(delete)\n" : "\n" );
if (r == 0) delete this;
return r;
}
//----------
int32_t KODE_VST3_PLUGIN_API queryInterface(const KODE_Vst3Id _iid, void** obj) final {
KODE_Vst3Print("iid: ");
KODE_Vst3PrintIID(_iid);
if (KODE_iidEqual(KODE_Vst3IPluginFactory2_iid,_iid)) {
*obj = (KODE_Vst3IPluginFactory2*)this;
KODE_Vst3DPrint(" (IPluginFactory2) -> Ok\n");
addRef();
return kode_vst3_ResultOk;
}
if (KODE_iidEqual(KODE_Vst3IPluginFactory3_iid,_iid)) {
*obj = (KODE_Vst3IPluginFactory3*)this;
KODE_Vst3DPrint(" (IPluginFactory3) -> Ok\n");
addRef();
return kode_vst3_ResultOk;
}
*obj = nullptr;
KODE_Vst3DPrint(" (unknown) -> NoInterface\n");
return kode_vst3_NoInterface;
}
//------------------------------
public:
//------------------------------
//--------------------
// IPluginFactory
//--------------------
int32_t KODE_VST3_PLUGIN_API getFactoryInfo(KODE_Vst3PFactoryInfo* info) final {
KODE_Vst3Print(" -> Ok\n");
strcpy(info->vendor,MDescriptor.getAuthor());
strcpy(info->url,MDescriptor.getUrl());
strcpy(info->email,MDescriptor.getEmail());
info->flags = KODE_Vst3PFactoryInfo::kode_vst3_NoFlags;
KODE_Vst3DPrint(". author: '%s'\n",info->vendor);
KODE_Vst3DPrint(". url: '%s'\n",info->url);
KODE_Vst3DPrint(". email: '%s'\n",info->email);
KODE_Vst3DPrint(". flags: %i\n",info->flags);
return kode_vst3_ResultOk;
}
//----------
int32_t KODE_VST3_PLUGIN_API countClasses() final {
KODE_Vst3Print(" -> 1\n");
return 1;
}
//----------
int32_t KODE_VST3_PLUGIN_API getClassInfo(int32_t index, KODE_Vst3PClassInfo* info) final {
KODE_Vst3Print("index: %i",index);
switch (index) {
case 0:
KODE_Vst3DPrint(" -> Ok\n");
memcpy(info->cid,MDescriptor.getLongId(),16);
info->cardinality = KODE_Vst3PClassInfo::kode_vst3_ManyInstances;
strncpy(info->category,kode_vst3_VstAudioEffectClass,KODE_Vst3PClassInfo::kode_vst3_CategorySize);
strncpy(info->name,MDescriptor.getName(),KODE_Vst3PClassInfo::kode_vst3_NameSize);
KODE_Vst3DPrint(". cid: "); KODE_Vst3PrintIID(info->cid); KODE_Vst3DPrint("\n");
KODE_Vst3DPrint(". cardinality: %i (%s)\n",info->cardinality,info->cardinality?"ManyInstances":"");
KODE_Vst3DPrint(". category: '%s'\n",info->category);
KODE_Vst3DPrint(". name: '%s'\n",info->name);
return kode_vst3_ResultOk;
}
KODE_Vst3DPrint(" -> False\n");
return kode_vst3_ResultFalse;
}
//----------
int32_t KODE_VST3_PLUGIN_API createInstance(const char* cid, const char* _iid, void** obj) final {
KODE_Vst3Print("cid: ");
//KODE_Vst3DPrint(cid);
KODE_Vst3PrintIID(cid);
if (KODE_iidEqual(MDescriptor.getLongId(),cid)) {
KODE_Vst3DPrint(" (%s) -> Ok\n",MDescriptor.getName());
INST* instance = new INST(&MDescriptor);
instance->on_plugin_open();
instance->setDefaultParameterValues();
instance->updateAllParameters();
*obj = (KODE_Vst3IComponent*)instance;
return kode_vst3_ResultOk;
}
*obj = nullptr;
KODE_Vst3DPrint(" (unknown) -> False\n");
return kode_vst3_NotImplemented;
}
//------------------------------
public: // IPluginFactory2
//------------------------------
int32_t KODE_VST3_PLUGIN_API getClassInfo2(int32_t index, KODE_Vst3PClassInfo2* info) final {
KODE_Vst3Print("index: %i",index);
switch (index) {
case 0:
memcpy(info->cid,MDescriptor.getLongId(),16);
info->cardinality = KODE_Vst3PClassInfo::kode_vst3_ManyInstances;
strcpy(info->category,kode_vst3_VstAudioEffectClass);
strcpy(info->name,MDescriptor.getName());
info->classFlags = 0;
if (MDescriptor.isSynth()) {
strcpy(info->subCategories,kode_vst3_Instrument);
}
else {
strcpy(info->subCategories,kode_vst3_Fx);
}
strcpy(info->vendor,MDescriptor.getAuthor());
strcpy(info->version,MDescriptor.getVersionText());
strcpy(info->sdkVersion,kode_vst3_VstVersionString);
KODE_Vst3DPrint(" -> Ok\n");
KODE_Vst3DPrint(". cid: "); KODE_Vst3PrintIID(info->cid); KODE_Vst3DPrint("\n");
KODE_Vst3DPrint(". cardinality: %i (%s)\n",info->cardinality,info->cardinality?"ManyInstances":"");
KODE_Vst3DPrint(". category: '%s'\n",info->category);
KODE_Vst3DPrint(". name: '%s'\n",info->name);
KODE_Vst3DPrint(". classFlags: %i\n",info->classFlags);
KODE_Vst3DPrint(". subCategories: '%s'\n",info->subCategories);
return kode_vst3_ResultOk;
}
KODE_Vst3DPrint(" -> False\n");
return kode_vst3_ResultFalse;
}
//------------------------------
public: // IPluginFactory3
//------------------------------
int32_t KODE_VST3_PLUGIN_API getClassInfoUnicode(int32_t index, KODE_Vst3PClassInfoW* info) final {
KODE_Vst3Print("index: %i -> False\n",index);
return kode_vst3_ResultFalse;
}
//----------
int32_t KODE_VST3_PLUGIN_API setHostContext(KODE_Vst3FUnknown* context) final {
KODE_Vst3Print("context: %p -> Ok\n",context);
MHostContext = context;
return kode_vst3_ResultOk;
}
};
//----------------------------------------------------------------------
//
// entrypoint
//
//----------------------------------------------------------------------
#define VST3_MAIN_SYMBOL asm ("GetPluginFactory");
KODE_Vst3IPluginFactory* KODE_VST3_PLUGIN_API vst3_entrypoint() VST3_MAIN_SYMBOL;
#define VST3_MODULE_ENTRY_SYMBOL asm ("ModuleEntry");
bool vst3_module_entry(void* sharedLibraryHandle) VST3_MODULE_ENTRY_SYMBOL;
#define VST3_MODULE_EXIT_SYMBOL asm ("ModuleExit");
bool vst3_module_exit(void) VST3_MODULE_EXIT_SYMBOL;
//----------
#define KODE_VST3_ENTRYPOINT(DESC,INST) \
\
__KODE_DLLEXPORT \
KODE_Vst3IPluginFactory* KODE_VST3_PLUGIN_API vst3_entrypoint() { \
KODE_Vst3Print("\n"); \
return new KODE_Vst3Plugin<DESC,INST>(); \
} \
\
/* void* moduleHandle = nullptr; */ \
/* static int counter {0}; */ \
\
__KODE_DLLEXPORT \
bool vst3_module_entry(void* sharedLibraryHandle) { \
/* KODE_Vst3Print("\n"); */ \
/* if (++counter == 1) { */ \
/* moduleHandle = sharedLibraryHandle; */ \
/* return true; */ \
/* } */ \
return true; \
} \
\
__KODE_DLLEXPORT \
bool vst3_module_exit(void) { \
/* KODE_Vst3Print("\n"); */ \
/* if (--counter == 0) { */ \
/* moduleHandle = nullptr; */ \
/* return true; */ \
/* } */ \
return true; \
}
//----------------------------------------------------------------------
#endif