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.

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