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.

436 lines
15KB

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