Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CarlaVstUtils.hpp 14KB

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