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.

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