Rename a pipe method, add docs
[carla.git] / source / utils / CarlaVst2Utils.hpp
blob4a48f9d5f4b0b2424ea9f88a0f6b1be946fc1e16
1 /*
2 * Carla VST2 utils
3 * Copyright (C) 2011-2021 Filipe Coelho <falktx@falktx.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of
8 * the License, or any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * For a full copy of the GNU General Public License see the doc/GPL.txt file.
18 #ifndef CARLA_VST2_UTILS_HPP_INCLUDED
19 #define CARLA_VST2_UTILS_HPP_INCLUDED
21 #include "CarlaUtils.hpp"
23 // -----------------------------------------------------------------------
24 // Include fixes
26 // Disable deprecated VST features (NOT)
27 #define VST_2_4_EXTENSIONS 1
28 #define VST_FORCE_DEPRECATED 0
30 #include "vestige/vestige.h"
31 #define audioMasterGetOutputSpeakerArrangement audioMasterGetSpeakerArrangement
32 #define effFlagsProgramChunks (1 << 5)
33 #define effSetProgramName 4
34 #define effGetParamLabel 6
35 #define effGetParamDisplay 7
36 #define effGetVu 9
37 #define effEditDraw 16
38 #define effEditMouse 17
39 #define effEditKey 18
40 #define effEditSleep 21
41 #define effIdentify 22
42 #define effGetChunk 23
43 #define effSetChunk 24
44 #define effCanBeAutomated 26
45 #define effString2Parameter 27
46 #define effGetNumProgramCategories 28
47 #define effGetProgramNameIndexed 29
48 #define effCopyProgram 30
49 #define effConnectInput 31
50 #define effConnectOutput 32
51 #define effGetInputProperties 33
52 #define effGetOutputProperties 34
53 #define effGetCurrentPosition 36
54 #define effGetDestinationBuffer 37
55 #define effOfflineNotify 38
56 #define effOfflinePrepare 39
57 #define effOfflineRun 40
58 #define effProcessVarIo 41
59 #define effSetSpeakerArrangement 42
60 #define effSetBlockSizeAndSampleRate 43
61 #define effSetBypass 44
62 #define effGetErrorText 46
63 #define effVendorSpecific 50
64 #define effGetTailSize 52
65 #define effGetIcon 54
66 #define effSetViewPosition 55
67 #define effKeysRequired 57
68 #define effEditKeyDown 59
69 #define effEditKeyUp 60
70 #define effSetEditKnobMode 61
71 #define effGetMidiProgramName 62
72 #define effGetCurrentMidiProgram 63
73 #define effGetMidiProgramCategory 64
74 #define effHasMidiProgramsChanged 65
75 #define effGetMidiKeyName 66
76 #define effGetSpeakerArrangement 69
77 #define effSetTotalSampleToProcess 73
78 #define effSetPanLaw 74
79 #define effBeginLoadBank 75
80 #define effBeginLoadProgram 76
81 #define effSetProcessPrecision 77
82 #define effGetNumMidiInputChannels 78
83 #define effGetNumMidiOutputChannels 79
84 #define kVstAutomationOff 1
85 #define kVstAutomationReadWrite 4
86 #define kVstProcessLevelUnknown 0
87 #define kVstProcessLevelUser 1
88 #define kVstProcessLevelRealtime 2
89 #define kVstProcessLevelOffline 4
90 #define kVstProcessPrecision32 0
91 #define kVstVersion 2400
92 #define DECLARE_VST_DEPRECATED(idx) idx
93 #if defined(CARLA_OS_WIN) && defined(__cdecl)
94 # define VSTCALLBACK __cdecl
95 #else
96 # define VSTCALLBACK
97 #endif
98 struct ERect {
99 int16_t top, left, bottom, right;
102 // -----------------------------------------------------------------------
103 // Plugin callback
105 typedef AEffect* (*VST_Function)(audioMasterCallback);
107 // -----------------------------------------------------------------------
108 // Check if feature is supported by the plugin
110 static inline
111 bool vstPluginCanDo(AEffect* const effect, const char* const feature) noexcept
113 CARLA_SAFE_ASSERT_RETURN(effect != nullptr, false);
114 CARLA_SAFE_ASSERT_RETURN(feature != nullptr && feature[0] != '\0', false);
116 try {
117 return (effect->dispatcher(effect, effCanDo, 0, 0, const_cast<char*>(feature), 0.0f) == 1);
118 } CARLA_SAFE_EXCEPTION_RETURN("vstPluginCanDo", false);
121 // -----------------------------------------------------------------------
122 // Convert Effect opcode to string
124 static inline
125 const char* vstEffectOpcode2str(const int32_t opcode) noexcept
127 switch (opcode)
129 case effOpen:
130 return "effOpen";
131 case effClose:
132 return "effClose";
133 case effSetProgram:
134 return "effSetProgram";
135 case effGetProgram:
136 return "effGetProgram";
137 case effSetProgramName:
138 return "effSetProgramName";
139 case effGetProgramName:
140 return "effGetProgramName";
141 case effGetParamLabel:
142 return "effGetParamLabel";
143 case effGetParamDisplay:
144 return "effGetParamDisplay";
145 case effGetParamName:
146 return "effGetParamName";
147 case DECLARE_VST_DEPRECATED(effGetVu):
148 return "effGetVu";
149 case effSetSampleRate:
150 return "effSetSampleRate";
151 case effSetBlockSize:
152 return "effSetBlockSize";
153 case effMainsChanged:
154 return "effMainsChanged";
155 case effEditGetRect:
156 return "effEditGetRect";
157 case effEditOpen:
158 return "effEditOpen";
159 case effEditClose:
160 return "effEditClose";
161 case DECLARE_VST_DEPRECATED(effEditDraw):
162 return "effEditDraw";
163 case DECLARE_VST_DEPRECATED(effEditMouse):
164 return "effEditMouse";
165 case DECLARE_VST_DEPRECATED(effEditKey):
166 return "effEditKey";
167 case effEditIdle:
168 return "effEditIdle";
169 case DECLARE_VST_DEPRECATED(effEditTop):
170 return "effEditTop";
171 case DECLARE_VST_DEPRECATED(effEditSleep):
172 return "effEditSleep";
173 case DECLARE_VST_DEPRECATED(effIdentify):
174 return "effIdentify";
175 case effGetChunk:
176 return "effGetChunk";
177 case effSetChunk:
178 return "effSetChunk";
179 case effProcessEvents:
180 return "effProcessEvents";
181 case effCanBeAutomated:
182 return "effCanBeAutomated";
183 case effString2Parameter:
184 return "effString2Parameter";
185 case DECLARE_VST_DEPRECATED(effGetNumProgramCategories):
186 return "effGetNumProgramCategories";
187 case effGetProgramNameIndexed:
188 return "effGetProgramNameIndexed";
189 case DECLARE_VST_DEPRECATED(effCopyProgram):
190 return "effCopyProgram";
191 case DECLARE_VST_DEPRECATED(effConnectInput):
192 return "effConnectInput";
193 case DECLARE_VST_DEPRECATED(effConnectOutput):
194 return "effConnectOutput";
195 case effGetInputProperties:
196 return "effGetInputProperties";
197 case effGetOutputProperties:
198 return "effGetOutputProperties";
199 case effGetPlugCategory:
200 return "effGetPlugCategory";
201 case DECLARE_VST_DEPRECATED(effGetCurrentPosition):
202 return "effGetCurrentPosition";
203 case DECLARE_VST_DEPRECATED(effGetDestinationBuffer):
204 return "effGetDestinationBuffer";
205 case effOfflineNotify:
206 return "effOfflineNotify";
207 case effOfflinePrepare:
208 return "effOfflinePrepare";
209 case effOfflineRun:
210 return "effOfflineRun";
211 case effProcessVarIo:
212 return "effProcessVarIo";
213 case effSetSpeakerArrangement:
214 return "effSetSpeakerArrangement";
215 case DECLARE_VST_DEPRECATED(effSetBlockSizeAndSampleRate):
216 return "effSetBlockSizeAndSampleRate";
217 case effSetBypass:
218 return "effSetBypass";
219 case effGetEffectName:
220 return "effGetEffectName";
221 case DECLARE_VST_DEPRECATED(effGetErrorText):
222 return "effGetErrorText";
223 case effGetVendorString:
224 return "effGetVendorString";
225 case effGetProductString:
226 return "effGetProductString";
227 case effGetVendorVersion:
228 return "effGetVendorVersion";
229 case effVendorSpecific:
230 return "effVendorSpecific";
231 case effCanDo:
232 return "effCanDo";
233 case effGetTailSize:
234 return "effGetTailSize";
235 case DECLARE_VST_DEPRECATED(effIdle):
236 return "effIdle";
237 case DECLARE_VST_DEPRECATED(effGetIcon):
238 return "effGetIcon";
239 case DECLARE_VST_DEPRECATED(effSetViewPosition):
240 return "effSetViewPosition";
241 case effGetParameterProperties:
242 return "effGetParameterProperties";
243 case DECLARE_VST_DEPRECATED(effKeysRequired):
244 return "effKeysRequired";
245 case effGetVstVersion:
246 return "effGetVstVersion";
247 case effEditKeyDown:
248 return "effEditKeyDown";
249 case effEditKeyUp:
250 return "effEditKeyUp";
251 case effSetEditKnobMode:
252 return "effSetEditKnobMode";
253 case effGetMidiProgramName:
254 return "effGetMidiProgramName";
255 case effGetCurrentMidiProgram:
256 return "effGetCurrentMidiProgram";
257 case effGetMidiProgramCategory:
258 return "effGetMidiProgramCategory";
259 case effHasMidiProgramsChanged:
260 return "effHasMidiProgramsChanged";
261 case effGetMidiKeyName:
262 return "effGetMidiKeyName";
263 case effBeginSetProgram:
264 return "effBeginSetProgram";
265 case effEndSetProgram:
266 return "effEndSetProgram";
267 case effGetSpeakerArrangement:
268 return "effGetSpeakerArrangement";
269 case effShellGetNextPlugin:
270 return "effShellGetNextPlugin";
271 case effStartProcess:
272 return "effStartProcess";
273 case effStopProcess:
274 return "effStopProcess";
275 case effSetTotalSampleToProcess:
276 return "effSetTotalSampleToProcess";
277 case effSetPanLaw:
278 return "effSetPanLaw";
279 case effBeginLoadBank:
280 return "effBeginLoadBank";
281 case effBeginLoadProgram:
282 return "effBeginLoadProgram";
283 case effSetProcessPrecision:
284 return "effSetProcessPrecision";
285 case effGetNumMidiInputChannels:
286 return "effGetNumMidiInputChannels";
287 case effGetNumMidiOutputChannels:
288 return "effGetNumMidiOutputChannels";
289 default:
290 return "unknown";
294 // -----------------------------------------------------------------------
295 // Convert Host/Master opcode to string
297 static inline
298 const char* vstMasterOpcode2str(const int32_t opcode) noexcept
300 switch (opcode)
302 case audioMasterAutomate:
303 return "audioMasterAutomate";
304 case audioMasterVersion:
305 return "audioMasterVersion";
306 case audioMasterCurrentId:
307 return "audioMasterCurrentId";
308 case audioMasterIdle:
309 return "audioMasterIdle";
310 case DECLARE_VST_DEPRECATED(audioMasterPinConnected):
311 return "audioMasterPinConnected";
312 case DECLARE_VST_DEPRECATED(audioMasterWantMidi):
313 return "audioMasterWantMidi";
314 case audioMasterGetTime:
315 return "audioMasterGetTime";
316 case audioMasterProcessEvents:
317 return "audioMasterProcessEvents";
318 case DECLARE_VST_DEPRECATED(audioMasterSetTime):
319 return "audioMasterSetTime";
320 case DECLARE_VST_DEPRECATED(audioMasterTempoAt):
321 return "audioMasterTempoAt";
322 case DECLARE_VST_DEPRECATED(audioMasterGetNumAutomatableParameters):
323 return "audioMasterGetNumAutomatableParameters";
324 case DECLARE_VST_DEPRECATED(audioMasterGetParameterQuantization):
325 return "audioMasterGetParameterQuantization";
326 case audioMasterIOChanged:
327 return "audioMasterIOChanged";
328 case DECLARE_VST_DEPRECATED(audioMasterNeedIdle):
329 return "audioMasterNeedIdle";
330 case audioMasterSizeWindow:
331 return "audioMasterSizeWindow";
332 case audioMasterGetSampleRate:
333 return "audioMasterGetSampleRate";
334 case audioMasterGetBlockSize:
335 return "audioMasterGetBlockSize";
336 case audioMasterGetInputLatency:
337 return "audioMasterGetInputLatency";
338 case audioMasterGetOutputLatency:
339 return "audioMasterGetOutputLatency";
340 case DECLARE_VST_DEPRECATED(audioMasterGetPreviousPlug):
341 return "audioMasterGetPreviousPlug";
342 case DECLARE_VST_DEPRECATED(audioMasterGetNextPlug):
343 return "audioMasterGetNextPlug";
344 case DECLARE_VST_DEPRECATED(audioMasterWillReplaceOrAccumulate):
345 return "audioMasterWillReplaceOrAccumulate";
346 case audioMasterGetCurrentProcessLevel:
347 return "audioMasterGetCurrentProcessLevel";
348 case audioMasterGetAutomationState:
349 return "audioMasterGetAutomationState";
350 case audioMasterOfflineStart:
351 return "audioMasterOfflineStart";
352 case audioMasterOfflineRead:
353 return "audioMasterOfflineRead";
354 case audioMasterOfflineWrite:
355 return "audioMasterOfflineWrite";
356 case audioMasterOfflineGetCurrentPass:
357 return "audioMasterOfflineGetCurrentPass";
358 case audioMasterOfflineGetCurrentMetaPass:
359 return "audioMasterOfflineGetCurrentMetaPass";
360 case DECLARE_VST_DEPRECATED(audioMasterSetOutputSampleRate):
361 return "audioMasterSetOutputSampleRate";
362 case DECLARE_VST_DEPRECATED(audioMasterGetOutputSpeakerArrangement):
363 return "audioMasterGetOutputSpeakerArrangement";
364 case audioMasterGetVendorString:
365 return "audioMasterGetVendorString";
366 case audioMasterGetProductString:
367 return "audioMasterGetProductString";
368 case audioMasterGetVendorVersion:
369 return "audioMasterGetVendorVersion";
370 case audioMasterVendorSpecific:
371 return "audioMasterVendorSpecific";
372 case DECLARE_VST_DEPRECATED(audioMasterSetIcon):
373 return "audioMasterSetIcon";
374 case audioMasterCanDo:
375 return "audioMasterCanDo";
376 case audioMasterGetLanguage:
377 return "audioMasterGetLanguage";
378 case DECLARE_VST_DEPRECATED(audioMasterOpenWindow):
379 return "audioMasterOpenWindow";
380 case DECLARE_VST_DEPRECATED(audioMasterCloseWindow):
381 return "audioMasterCloseWindow";
382 case audioMasterGetDirectory:
383 return "audioMasterGetDirectory";
384 case audioMasterUpdateDisplay:
385 return "audioMasterUpdateDisplay";
386 case audioMasterBeginEdit:
387 return "audioMasterBeginEdit";
388 case audioMasterEndEdit:
389 return "audioMasterEndEdit";
390 case audioMasterOpenFileSelector:
391 return "audioMasterOpenFileSelector";
392 case audioMasterCloseFileSelector:
393 return "audioMasterCloseFileSelector";
394 case DECLARE_VST_DEPRECATED(audioMasterEditFile):
395 return "audioMasterEditFile";
396 case DECLARE_VST_DEPRECATED(audioMasterGetChunkFile):
397 return "audioMasterGetChunkFile";
398 case DECLARE_VST_DEPRECATED(audioMasterGetInputSpeakerArrangement):
399 return "audioMasterGetInputSpeakerArrangement";
400 default:
401 return "unknown";
405 // -----------------------------------------------------------------------
407 #endif // CARLA_VST2_UTILS_HPP_INCLUDED