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 15KB

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