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.

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