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