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.

416 lines
14KB

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