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.

474 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/pluginterfaces/vst2.x/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) noexcept
  135. {
  136. try {
  137. return (effect->dispatcher(effect, effCanDo, 0, 0, const_cast<char*>(feature), 0.0f) == 1);
  138. } CARLA_SAFE_EXCEPTION_RETURN("vstPluginCanDo", false);
  139. }
  140. // -----------------------------------------------------------------------
  141. // Convert Effect opcode to string
  142. static inline
  143. const char* vstEffectOpcode2str(const int32_t opcode) noexcept
  144. {
  145. switch (opcode)
  146. {
  147. case effOpen:
  148. return "effOpen";
  149. case effClose:
  150. return "effClose";
  151. case effSetProgram:
  152. return "effSetProgram";
  153. case effGetProgram:
  154. return "effGetProgram";
  155. case effSetProgramName:
  156. return "effSetProgramName";
  157. case effGetProgramName:
  158. return "effGetProgramName";
  159. case effGetParamLabel:
  160. return "effGetParamLabel";
  161. case effGetParamDisplay:
  162. return "effGetParamDisplay";
  163. case effGetParamName:
  164. return "effGetParamName";
  165. #if ! VST_FORCE_DEPRECATED
  166. case effGetVu:
  167. return "effGetVu";
  168. #endif
  169. case effSetSampleRate:
  170. return "effSetSampleRate";
  171. case effSetBlockSize:
  172. return "effSetBlockSize";
  173. case effMainsChanged:
  174. return "effMainsChanged";
  175. case effEditGetRect:
  176. return "effEditGetRect";
  177. case effEditOpen:
  178. return "effEditOpen";
  179. case effEditClose:
  180. return "effEditClose";
  181. #if ! VST_FORCE_DEPRECATED
  182. case effEditDraw:
  183. return "effEditDraw";
  184. case effEditMouse:
  185. return "effEditMouse";
  186. case effEditKey:
  187. return "effEditKey";
  188. #endif
  189. case effEditIdle:
  190. return "effEditIdle";
  191. #if ! VST_FORCE_DEPRECATED
  192. case effEditTop:
  193. return "effEditTop";
  194. case effEditSleep:
  195. return "effEditSleep";
  196. case effIdentify:
  197. return "effIdentify";
  198. #endif
  199. case effGetChunk:
  200. return "effGetChunk";
  201. case effSetChunk:
  202. return "effSetChunk";
  203. case effProcessEvents:
  204. return "effProcessEvents";
  205. case effCanBeAutomated:
  206. return "effCanBeAutomated";
  207. case effString2Parameter:
  208. return "effString2Parameter";
  209. #if ! VST_FORCE_DEPRECATED
  210. case effGetNumProgramCategories:
  211. return "effGetNumProgramCategories";
  212. #endif
  213. case effGetProgramNameIndexed:
  214. return "effGetProgramNameIndexed";
  215. #if ! VST_FORCE_DEPRECATED
  216. case effCopyProgram:
  217. return "effCopyProgram";
  218. case effConnectInput:
  219. return "effConnectInput";
  220. case effConnectOutput:
  221. return "effConnectOutput";
  222. #endif
  223. case effGetInputProperties:
  224. return "effGetInputProperties";
  225. case effGetOutputProperties:
  226. return "effGetOutputProperties";
  227. case effGetPlugCategory:
  228. return "effGetPlugCategory";
  229. #if ! VST_FORCE_DEPRECATED
  230. case effGetCurrentPosition:
  231. return "effGetCurrentPosition";
  232. case effGetDestinationBuffer:
  233. return "effGetDestinationBuffer";
  234. #endif
  235. case effOfflineNotify:
  236. return "effOfflineNotify";
  237. case effOfflinePrepare:
  238. return "effOfflinePrepare";
  239. case effOfflineRun:
  240. return "effOfflineRun";
  241. case effProcessVarIo:
  242. return "effProcessVarIo";
  243. case effSetSpeakerArrangement:
  244. return "effSetSpeakerArrangement";
  245. #if ! VST_FORCE_DEPRECATED
  246. case effSetBlockSizeAndSampleRate:
  247. return "effSetBlockSizeAndSampleRate";
  248. #endif
  249. case effSetBypass:
  250. return "effSetBypass";
  251. case effGetEffectName:
  252. return "effGetEffectName";
  253. #if ! VST_FORCE_DEPRECATED
  254. case effGetErrorText:
  255. return "effGetErrorText";
  256. #endif
  257. case effGetVendorString:
  258. return "effGetVendorString";
  259. case effGetProductString:
  260. return "effGetProductString";
  261. case effGetVendorVersion:
  262. return "effGetVendorVersion";
  263. case effVendorSpecific:
  264. return "effVendorSpecific";
  265. case effCanDo:
  266. return "effCanDo";
  267. case effGetTailSize:
  268. return "effGetTailSize";
  269. #if ! VST_FORCE_DEPRECATED
  270. case effIdle:
  271. return "effIdle";
  272. case effGetIcon:
  273. return "effGetIcon";
  274. case effSetViewPosition:
  275. return "effSetViewPosition";
  276. #endif
  277. case effGetParameterProperties:
  278. return "effGetParameterProperties";
  279. #if ! VST_FORCE_DEPRECATED
  280. case effKeysRequired:
  281. return "effKeysRequired";
  282. #endif
  283. case effGetVstVersion:
  284. return "effGetVstVersion";
  285. case effEditKeyDown:
  286. return "effEditKeyDown";
  287. case effEditKeyUp:
  288. return "effEditKeyUp";
  289. case effSetEditKnobMode:
  290. return "effSetEditKnobMode";
  291. case effGetMidiProgramName:
  292. return "effGetMidiProgramName";
  293. case effGetCurrentMidiProgram:
  294. return "effGetCurrentMidiProgram";
  295. case effGetMidiProgramCategory:
  296. return "effGetMidiProgramCategory";
  297. case effHasMidiProgramsChanged:
  298. return "effHasMidiProgramsChanged";
  299. case effGetMidiKeyName:
  300. return "effGetMidiKeyName";
  301. case effBeginSetProgram:
  302. return "effBeginSetProgram";
  303. case effEndSetProgram:
  304. return "effEndSetProgram";
  305. case effGetSpeakerArrangement:
  306. return "effGetSpeakerArrangement";
  307. case effShellGetNextPlugin:
  308. return "effShellGetNextPlugin";
  309. case effStartProcess:
  310. return "effStartProcess";
  311. case effStopProcess:
  312. return "effStopProcess";
  313. case effSetTotalSampleToProcess:
  314. return "effSetTotalSampleToProcess";
  315. case effSetPanLaw:
  316. return "effSetPanLaw";
  317. case effBeginLoadBank:
  318. return "effBeginLoadBank";
  319. case effBeginLoadProgram:
  320. return "effBeginLoadProgram";
  321. case effSetProcessPrecision:
  322. return "effSetProcessPrecision";
  323. case effGetNumMidiInputChannels:
  324. return "effGetNumMidiInputChannels";
  325. case effGetNumMidiOutputChannels:
  326. return "effGetNumMidiOutputChannels";
  327. default:
  328. return "unknown";
  329. }
  330. }
  331. // -----------------------------------------------------------------------
  332. // Convert Host/Master opcode to string
  333. static inline
  334. const char* vstMasterOpcode2str(const int32_t opcode) noexcept
  335. {
  336. switch (opcode)
  337. {
  338. case audioMasterAutomate:
  339. return "audioMasterAutomate";
  340. case audioMasterVersion:
  341. return "audioMasterVersion";
  342. case audioMasterCurrentId:
  343. return "audioMasterCurrentId";
  344. case audioMasterIdle:
  345. return "audioMasterIdle";
  346. #if ! VST_FORCE_DEPRECATED
  347. case audioMasterPinConnected:
  348. return "audioMasterPinConnected";
  349. case audioMasterWantMidi:
  350. return "audioMasterWantMidi";
  351. #endif
  352. case audioMasterGetTime:
  353. return "audioMasterGetTime";
  354. case audioMasterProcessEvents:
  355. return "audioMasterProcessEvents";
  356. #if ! VST_FORCE_DEPRECATED
  357. case audioMasterSetTime:
  358. return "audioMasterSetTime";
  359. case audioMasterTempoAt:
  360. return "audioMasterTempoAt";
  361. case audioMasterGetNumAutomatableParameters:
  362. return "audioMasterGetNumAutomatableParameters";
  363. case audioMasterGetParameterQuantization:
  364. return "audioMasterGetParameterQuantization";
  365. #endif
  366. case audioMasterIOChanged:
  367. return "audioMasterIOChanged";
  368. #if ! VST_FORCE_DEPRECATED
  369. case audioMasterNeedIdle:
  370. return "audioMasterNeedIdle";
  371. #endif
  372. case audioMasterSizeWindow:
  373. return "audioMasterSizeWindow";
  374. case audioMasterGetSampleRate:
  375. return "audioMasterGetSampleRate";
  376. case audioMasterGetBlockSize:
  377. return "audioMasterGetBlockSize";
  378. case audioMasterGetInputLatency:
  379. return "audioMasterGetInputLatency";
  380. case audioMasterGetOutputLatency:
  381. return "audioMasterGetOutputLatency";
  382. #if ! VST_FORCE_DEPRECATED
  383. case audioMasterGetPreviousPlug:
  384. return "audioMasterGetPreviousPlug";
  385. case audioMasterGetNextPlug:
  386. return "audioMasterGetNextPlug";
  387. case audioMasterWillReplaceOrAccumulate:
  388. return "audioMasterWillReplaceOrAccumulate";
  389. #endif
  390. case audioMasterGetCurrentProcessLevel:
  391. return "audioMasterGetCurrentProcessLevel";
  392. case audioMasterGetAutomationState:
  393. return "audioMasterGetAutomationState";
  394. case audioMasterOfflineStart:
  395. return "audioMasterOfflineStart";
  396. case audioMasterOfflineRead:
  397. return "audioMasterOfflineRead";
  398. case audioMasterOfflineWrite:
  399. return "audioMasterOfflineWrite";
  400. case audioMasterOfflineGetCurrentPass:
  401. return "audioMasterOfflineGetCurrentPass";
  402. case audioMasterOfflineGetCurrentMetaPass:
  403. return "audioMasterOfflineGetCurrentMetaPass";
  404. #if ! VST_FORCE_DEPRECATED
  405. case audioMasterSetOutputSampleRate:
  406. return "audioMasterSetOutputSampleRate";
  407. case audioMasterGetOutputSpeakerArrangement:
  408. return "audioMasterGetOutputSpeakerArrangement";
  409. #endif
  410. case audioMasterGetVendorString:
  411. return "audioMasterGetVendorString";
  412. case audioMasterGetProductString:
  413. return "audioMasterGetProductString";
  414. case audioMasterGetVendorVersion:
  415. return "audioMasterGetVendorVersion";
  416. case audioMasterVendorSpecific:
  417. return "audioMasterVendorSpecific";
  418. #if ! VST_FORCE_DEPRECATED
  419. case audioMasterSetIcon:
  420. return "audioMasterSetIcon";
  421. #endif
  422. case audioMasterCanDo:
  423. return "audioMasterCanDo";
  424. case audioMasterGetLanguage:
  425. return "audioMasterGetLanguage";
  426. #if ! VST_FORCE_DEPRECATED
  427. case audioMasterOpenWindow:
  428. return "audioMasterOpenWindow";
  429. case audioMasterCloseWindow:
  430. return "audioMasterCloseWindow";
  431. #endif
  432. case audioMasterGetDirectory:
  433. return "audioMasterGetDirectory";
  434. case audioMasterUpdateDisplay:
  435. return "audioMasterUpdateDisplay";
  436. case audioMasterBeginEdit:
  437. return "audioMasterBeginEdit";
  438. case audioMasterEndEdit:
  439. return "audioMasterEndEdit";
  440. case audioMasterOpenFileSelector:
  441. return "audioMasterOpenFileSelector";
  442. case audioMasterCloseFileSelector:
  443. return "audioMasterCloseFileSelector";
  444. #if ! VST_FORCE_DEPRECATED
  445. case audioMasterEditFile:
  446. return "audioMasterEditFile";
  447. case audioMasterGetChunkFile:
  448. return "audioMasterGetChunkFile";
  449. case audioMasterGetInputSpeakerArrangement:
  450. return "audioMasterGetInputSpeakerArrangement";
  451. #endif
  452. default:
  453. return "unknown";
  454. }
  455. }
  456. // -----------------------------------------------------------------------
  457. #endif // CARLA_VST_UTILS_HPP_INCLUDED