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.

455 lines
14KB

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