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.

CarlaVstUtils.hpp 14KB

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