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.

408 lines
14KB

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