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.

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