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.

1342 lines
44KB

  1. /*
  2. * Carla Native Plugins
  3. * Copyright (C) 2013-2023 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. #ifdef __WINE__
  18. #error This file is not supposed to be built with wine!
  19. #endif
  20. #ifndef CARLA_PLUGIN_SYNTH
  21. #error CARLA_PLUGIN_SYNTH undefined
  22. #endif
  23. #ifndef CARLA_VST_SHELL
  24. #ifndef CARLA_PLUGIN_PATCHBAY
  25. #error CARLA_PLUGIN_PATCHBAY undefined
  26. #endif
  27. #if defined(CARLA_PLUGIN_64CH) || defined(CARLA_PLUGIN_32CH) || defined(CARLA_PLUGIN_16CH)
  28. #if ! CARLA_PLUGIN_SYNTH
  29. #error CARLA_PLUGIN_16/32/64CH requires CARLA_PLUGIN_SYNTH
  30. #endif
  31. #endif
  32. #endif
  33. #define CARLA_NATIVE_PLUGIN_VST
  34. #include "carla-base.cpp"
  35. #include "carla-vst.hpp"
  36. #include "water/files/File.h"
  37. #include "CarlaMathUtils.hpp"
  38. #include "CarlaVst2Utils.hpp"
  39. static uint32_t d_lastBufferSize = 0;
  40. static double d_lastSampleRate = 0.0;
  41. static const int32_t kBaseUniqueID = CCONST('C', 'r', 'l', 'a');
  42. static const int32_t kVstMidiEventSize = static_cast<int32_t>(sizeof(VstMidiEvent));
  43. #ifdef CARLA_VST_SHELL
  44. # if CARLA_PLUGIN_SYNTH
  45. static const int32_t kShellUniqueID = CCONST('C', 'r', 'l', 's');
  46. # else
  47. static const int32_t kShellUniqueID = CCONST('C', 'r', 'l', 'F');
  48. # endif
  49. #else
  50. static const int32_t kNumParameters = 100;
  51. #endif
  52. static const bool kIsUsingUILauncher = isUsingUILauncher();
  53. // --------------------------------------------------------------------------------------------------------------------
  54. // Carla Internal Plugin API exposed as VST plugin
  55. class NativePlugin
  56. {
  57. public:
  58. static const uint32_t kMaxMidiEvents = 512;
  59. NativePlugin(AEffect* const effect, const NativePluginDescriptor* desc)
  60. : fEffect(effect),
  61. fHandle(nullptr),
  62. fHost(),
  63. fDescriptor(desc),
  64. fBufferSize(d_lastBufferSize),
  65. fSampleRate(d_lastSampleRate),
  66. fIsActive(false),
  67. fMidiEventCount(0),
  68. fTimeInfo(),
  69. fVstRect(),
  70. fUiLauncher(nullptr),
  71. fHostType(kHostTypeNull),
  72. fMidiOutEvents(),
  73. fStateChunk(nullptr)
  74. {
  75. fHost.handle = this;
  76. fHost.uiName = carla_strdup("CarlaVST");
  77. fHost.uiParentId = 0;
  78. std::memset(fProgramName, 0, sizeof(fProgramName));
  79. std::strcpy(fProgramName, "Default");
  80. // find resource dir
  81. using water::File;
  82. using water::String;
  83. File curExe = File::getSpecialLocation(File::currentExecutableFile).getLinkedTarget();
  84. File resDir = curExe.getSiblingFile("resources");
  85. #ifndef CARLA_OS_MAC
  86. // FIXME: proper fallback path for other OSes
  87. if (! resDir.exists())
  88. resDir = File("/usr/local/share/carla/resources");
  89. if (! resDir.exists())
  90. resDir = File("/usr/share/carla/resources");
  91. #endif
  92. // find host type
  93. const String hostFilename(File::getSpecialLocation(File::hostApplicationPath).getFileName());
  94. /**/ if (hostFilename.startsWith("ardour"))
  95. fHostType = kHostTypeArdour;
  96. else if (hostFilename.startsWith("Bitwig"))
  97. fHostType = kHostTypeBitwig;
  98. fHost.resourceDir = carla_strdup(resDir.getFullPathName().toRawUTF8());
  99. fHost.get_buffer_size = host_get_buffer_size;
  100. fHost.get_sample_rate = host_get_sample_rate;
  101. fHost.is_offline = host_is_offline;
  102. fHost.get_time_info = host_get_time_info;
  103. fHost.write_midi_event = host_write_midi_event;
  104. fHost.ui_parameter_changed = host_ui_parameter_changed;
  105. fHost.ui_custom_data_changed = host_ui_custom_data_changed;
  106. fHost.ui_closed = host_ui_closed;
  107. fHost.ui_open_file = host_ui_open_file;
  108. fHost.ui_save_file = host_ui_save_file;
  109. fHost.dispatcher = host_dispatcher;
  110. fVstRect.top = 0;
  111. fVstRect.left = 0;
  112. if (kIsUsingUILauncher || (fDescriptor->hints & NATIVE_PLUGIN_USES_UI_SIZE) == 0x0)
  113. {
  114. fVstRect.right = ui_launcher_res::carla_uiWidth;
  115. fVstRect.bottom = ui_launcher_res::carla_uiHeight;
  116. }
  117. else
  118. {
  119. fVstRect.right = static_cast<int16_t>(fDescriptor->ui_width);
  120. fVstRect.bottom = static_cast<int16_t>(fDescriptor->ui_height);
  121. }
  122. init();
  123. }
  124. ~NativePlugin()
  125. {
  126. if (fIsActive)
  127. {
  128. // host has not de-activated the plugin yet, nasty!
  129. fIsActive = false;
  130. if (fDescriptor->deactivate != nullptr)
  131. fDescriptor->deactivate(fHandle);
  132. }
  133. if (fDescriptor->cleanup != nullptr && fHandle != nullptr)
  134. fDescriptor->cleanup(fHandle);
  135. fHandle = nullptr;
  136. if (fStateChunk != nullptr)
  137. {
  138. std::free(fStateChunk);
  139. fStateChunk = nullptr;
  140. }
  141. if (fHost.uiName != nullptr)
  142. {
  143. delete[] fHost.uiName;
  144. fHost.uiName = nullptr;
  145. }
  146. if (fHost.resourceDir != nullptr)
  147. {
  148. delete[] fHost.resourceDir;
  149. fHost.resourceDir = nullptr;
  150. }
  151. }
  152. bool init()
  153. {
  154. if (fDescriptor->instantiate == nullptr || fDescriptor->process == nullptr)
  155. {
  156. carla_stderr("Plugin is missing something...");
  157. return false;
  158. }
  159. fHandle = fDescriptor->instantiate(&fHost);
  160. CARLA_SAFE_ASSERT_RETURN(fHandle != nullptr, false);
  161. carla_zeroStructs(fMidiEvents, kMaxMidiEvents);
  162. carla_zeroStruct(fTimeInfo);
  163. return true;
  164. }
  165. const NativePluginDescriptor* getDescriptor() const noexcept
  166. {
  167. return fDescriptor;
  168. }
  169. // -------------------------------------------------------------------
  170. intptr_t vst_dispatcher(const int32_t opcode,
  171. const int32_t index, const intptr_t value, void* const ptr, const float opt)
  172. {
  173. CARLA_SAFE_ASSERT_RETURN(fHandle != nullptr, 0);
  174. intptr_t ret = 0;
  175. switch (opcode)
  176. {
  177. case effGetProgram:
  178. return 0;
  179. case effSetProgramName:
  180. if (char* const programName = (char*)ptr)
  181. {
  182. std::strncpy(fProgramName, programName, 32);
  183. return 1;
  184. }
  185. break;
  186. case effGetProgramName:
  187. if (char* const programName = (char*)ptr)
  188. {
  189. std::strncpy(programName, fProgramName, 23);
  190. programName[23] = '\0';
  191. return 1;
  192. }
  193. break;
  194. case effGetProgramNameIndexed:
  195. if (char* const programName = (char*)ptr)
  196. {
  197. std::strncpy(programName, fProgramName, 23);
  198. programName[23] = '\0';
  199. return 1;
  200. }
  201. break;
  202. case effGetParamDisplay:
  203. CARLA_SAFE_ASSERT_RETURN(index >= 0, 0);
  204. #ifndef CARLA_VST_SHELL
  205. CARLA_SAFE_ASSERT_RETURN(index < kNumParameters, 0);
  206. #endif
  207. if (char* const cptr = (char*)ptr)
  208. {
  209. const uint32_t uindex = static_cast<uint32_t>(index);
  210. CARLA_SAFE_ASSERT_RETURN(uindex < fDescriptor->paramIns, 0);
  211. const NativeParameter* const param = fDescriptor->get_parameter_info(fHandle, uindex);
  212. CARLA_SAFE_ASSERT_RETURN(param != nullptr, 0);
  213. float paramValue = fDescriptor->get_parameter_value(fHandle, uindex);
  214. if (param->hints & NATIVE_PARAMETER_IS_BOOLEAN)
  215. {
  216. const NativeParameterRanges& ranges(param->ranges);
  217. const float midRange = ranges.min + (ranges.max - ranges.min) / 2.0f;
  218. paramValue = paramValue > midRange ? ranges.max : ranges.min;
  219. }
  220. else if (param->hints & NATIVE_PARAMETER_IS_INTEGER)
  221. {
  222. paramValue = std::round(paramValue);
  223. }
  224. for (uint32_t i = 0; i < param->scalePointCount; ++i)
  225. {
  226. const NativeParameterScalePoint& scalePoint(param->scalePoints[uindex]);
  227. if (carla_isNotEqual(paramValue, scalePoint.value))
  228. continue;
  229. std::strncpy(cptr, scalePoint.label, 23);
  230. cptr[23] = '\0';
  231. return 1;
  232. }
  233. if (param->hints & NATIVE_PARAMETER_IS_INTEGER)
  234. {
  235. std::snprintf(cptr, 23, "%d%s%s",
  236. static_cast<int>(paramValue),
  237. param->unit != nullptr && param->unit[0] != '\0' ? " " : "",
  238. param->unit != nullptr && param->unit[0] != '\0' ? param->unit : "");
  239. cptr[23] = '\0';
  240. }
  241. else
  242. {
  243. std::snprintf(cptr, 23, "%.12g%s%s",
  244. static_cast<double>(paramValue),
  245. param->unit != nullptr && param->unit[0] != '\0' ? " " : "",
  246. param->unit != nullptr && param->unit[0] != '\0' ? param->unit : "");
  247. cptr[23] = '\0';
  248. }
  249. return 1;
  250. }
  251. break;
  252. case effGetParamName:
  253. CARLA_SAFE_ASSERT_RETURN(index >= 0, 0);
  254. #ifndef CARLA_VST_SHELL
  255. CARLA_SAFE_ASSERT_RETURN(index < kNumParameters, 0);
  256. #endif
  257. if (char* const cptr = (char*)ptr)
  258. {
  259. const uint32_t uindex = static_cast<uint32_t>(index);
  260. CARLA_SAFE_ASSERT_RETURN(uindex < fDescriptor->paramIns, 0);
  261. const NativeParameter* const param = fDescriptor->get_parameter_info(fHandle, uindex);
  262. CARLA_SAFE_ASSERT_RETURN(param != nullptr, 0);
  263. std::strncpy(cptr, param->name, 15);
  264. cptr[15] = '\0';
  265. return 1;
  266. }
  267. return 0;
  268. case effSetSampleRate:
  269. CARLA_SAFE_ASSERT_RETURN(opt > 0.0f, 0);
  270. if (carla_isEqual(fSampleRate, static_cast<double>(opt)))
  271. return 0;
  272. fSampleRate = opt;
  273. if (fDescriptor->dispatcher != nullptr)
  274. fDescriptor->dispatcher(fHandle, NATIVE_PLUGIN_OPCODE_SAMPLE_RATE_CHANGED, 0, 0, nullptr, opt);
  275. break;
  276. case effSetBlockSize:
  277. CARLA_SAFE_ASSERT_RETURN(value > 0, 0);
  278. if (fBufferSize == static_cast<uint32_t>(value))
  279. return 0;
  280. fBufferSize = static_cast<uint32_t>(value);
  281. if (fDescriptor->dispatcher != nullptr)
  282. fDescriptor->dispatcher(fHandle, NATIVE_PLUGIN_OPCODE_BUFFER_SIZE_CHANGED, 0, value, nullptr, 0.0f);
  283. break;
  284. case effMainsChanged:
  285. if (value != 0)
  286. {
  287. fMidiEventCount = 0;
  288. carla_zeroStruct(fTimeInfo);
  289. // tell host we want MIDI events
  290. if (fDescriptor->midiIns > 0)
  291. hostCallback(audioMasterWantMidi);
  292. // deactivate for possible changes
  293. if (fDescriptor->deactivate != nullptr && fIsActive)
  294. fDescriptor->deactivate(fHandle);
  295. // check if something changed
  296. const uint32_t bufferSize = static_cast<uint32_t>(hostCallback(audioMasterGetBlockSize));
  297. const double sampleRate = static_cast<double>(hostCallback(audioMasterGetSampleRate));
  298. if (bufferSize != 0 && fBufferSize != bufferSize && (fHostType != kHostTypeArdour || fBufferSize == 0))
  299. {
  300. fBufferSize = bufferSize;
  301. if (fDescriptor->dispatcher != nullptr)
  302. fDescriptor->dispatcher(fHandle, NATIVE_PLUGIN_OPCODE_BUFFER_SIZE_CHANGED, 0, bufferSize, nullptr, 0.0f);
  303. }
  304. if (carla_isNotZero(sampleRate) && carla_isNotEqual(fSampleRate, sampleRate))
  305. {
  306. fSampleRate = sampleRate;
  307. if (fDescriptor->dispatcher != nullptr)
  308. fDescriptor->dispatcher(fHandle, NATIVE_PLUGIN_OPCODE_SAMPLE_RATE_CHANGED, 0, 0, nullptr, (float)sampleRate);
  309. }
  310. if (fDescriptor->activate != nullptr)
  311. fDescriptor->activate(fHandle);
  312. fIsActive = true;
  313. }
  314. else
  315. {
  316. CARLA_SAFE_ASSERT_BREAK(fIsActive);
  317. if (fDescriptor->deactivate != nullptr)
  318. fDescriptor->deactivate(fHandle);
  319. fIsActive = false;
  320. }
  321. break;
  322. case effEditGetRect:
  323. *(VstRect**)ptr = &fVstRect;
  324. ret = 1;
  325. break;
  326. case effEditOpen:
  327. if (fDescriptor->ui_show != nullptr)
  328. {
  329. if (kIsUsingUILauncher)
  330. {
  331. destoryUILauncher(fUiLauncher);
  332. fUiLauncher = createUILauncher((uintptr_t)ptr, fDescriptor, fHandle);
  333. getUILauncherSize(fUiLauncher, &fVstRect);
  334. }
  335. else
  336. {
  337. char strBuf[0xff+1];
  338. std::snprintf(strBuf, 0xff, P_INTPTR, (intptr_t)ptr);
  339. strBuf[0xff] = '\0';
  340. // set CARLA_PLUGIN_EMBED_WINID for external process
  341. carla_setenv("CARLA_PLUGIN_EMBED_WINID", strBuf);
  342. // show UI now
  343. fDescriptor->ui_show(fHandle, true);
  344. // reset CARLA_PLUGIN_EMBED_WINID just in case
  345. carla_setenv("CARLA_PLUGIN_EMBED_WINID", "0");
  346. }
  347. ret = 1;
  348. }
  349. break;
  350. case effEditClose:
  351. if (fDescriptor->ui_show != nullptr)
  352. {
  353. if (kIsUsingUILauncher)
  354. {
  355. destoryUILauncher(fUiLauncher);
  356. fUiLauncher = nullptr;
  357. }
  358. else
  359. {
  360. fDescriptor->ui_show(fHandle, false);
  361. }
  362. ret = 1;
  363. }
  364. break;
  365. case effEditIdle:
  366. if (fUiLauncher != nullptr)
  367. idleUILauncher(fUiLauncher);
  368. if (fDescriptor->ui_idle != nullptr)
  369. fDescriptor->ui_idle(fHandle);
  370. break;
  371. case effGetChunk:
  372. if (ptr == nullptr || fDescriptor->get_state == nullptr)
  373. return 0;
  374. if (fStateChunk != nullptr)
  375. std::free(fStateChunk);
  376. fStateChunk = fDescriptor->get_state(fHandle);
  377. if (fStateChunk == nullptr)
  378. return 0;
  379. ret = static_cast<intptr_t>(std::strlen(fStateChunk)+1);
  380. *(void**)ptr = fStateChunk;
  381. break;
  382. case effSetChunk:
  383. if (value <= 0 || fDescriptor->set_state == nullptr)
  384. return 0;
  385. if (value == 1)
  386. return 1;
  387. if (const char* const state = (const char*)ptr)
  388. {
  389. fDescriptor->set_state(fHandle, state);
  390. ret = 1;
  391. }
  392. break;
  393. case effProcessEvents:
  394. if (! fIsActive)
  395. {
  396. // host has not activated the plugin yet, nasty!
  397. vst_dispatcher(effMainsChanged, 0, 1, nullptr, 0.0f);
  398. }
  399. if (const VstEvents* const events = (const VstEvents*)ptr)
  400. {
  401. if (events->numEvents == 0)
  402. break;
  403. for (int i=0, count=events->numEvents; i < count; ++i)
  404. {
  405. const VstMidiEvent* const vstMidiEvent((const VstMidiEvent*)events->events[i]);
  406. if (vstMidiEvent == nullptr)
  407. break;
  408. if (vstMidiEvent->type != kVstMidiType || vstMidiEvent->deltaFrames < 0)
  409. continue;
  410. if (fMidiEventCount >= kMaxMidiEvents)
  411. break;
  412. const uint32_t j(fMidiEventCount++);
  413. fMidiEvents[j].port = 0;
  414. fMidiEvents[j].time = static_cast<uint32_t>(vstMidiEvent->deltaFrames);
  415. fMidiEvents[j].size = 3;
  416. for (uint32_t k=0; k<3; ++k)
  417. fMidiEvents[j].data[k] = static_cast<uint8_t>(vstMidiEvent->midiData[k]);
  418. }
  419. }
  420. break;
  421. case effCanBeAutomated:
  422. ret = 1;
  423. break;
  424. case effCanDo:
  425. if (const char* const canDo = (const char*)ptr)
  426. {
  427. if (std::strcmp(canDo, "receiveVstEvents") == 0 || std::strcmp(canDo, "receiveVstMidiEvent") == 0)
  428. {
  429. if (fDescriptor->midiIns == 0)
  430. return -1;
  431. return 1;
  432. }
  433. if (std::strcmp(canDo, "sendVstEvents") == 0 || std::strcmp(canDo, "sendVstMidiEvent") == 0)
  434. {
  435. if (fDescriptor->midiOuts == 0)
  436. return -1;
  437. return 1;
  438. }
  439. if (std::strcmp(canDo, "receiveVstTimeInfo") == 0)
  440. return 1;
  441. }
  442. break;
  443. }
  444. return ret;
  445. }
  446. float vst_getParameter(const int32_t index)
  447. {
  448. CARLA_SAFE_ASSERT_RETURN(index >= 0, 0.0f);
  449. const uint32_t uindex = static_cast<uint32_t>(index);
  450. CARLA_SAFE_ASSERT_RETURN(uindex < fDescriptor->paramIns, 0.0f);
  451. const NativeParameter* const param = fDescriptor->get_parameter_info(fHandle, uindex);
  452. CARLA_SAFE_ASSERT_RETURN(param != nullptr, 0);
  453. const float realValue = fDescriptor->get_parameter_value(fHandle, uindex);
  454. return (realValue - param->ranges.min) / (param->ranges.max - param->ranges.min);
  455. }
  456. void vst_setParameter(const int32_t index, const float value)
  457. {
  458. CARLA_SAFE_ASSERT_RETURN(index >= 0,);
  459. const uint32_t uindex = static_cast<uint32_t>(index);
  460. CARLA_SAFE_ASSERT_RETURN(uindex < fDescriptor->paramIns,);
  461. const NativeParameter* const param = fDescriptor->get_parameter_info(fHandle, uindex);
  462. CARLA_SAFE_ASSERT_RETURN(param != nullptr,);
  463. float realValue;
  464. if (param->hints & NATIVE_PARAMETER_IS_BOOLEAN)
  465. {
  466. realValue = value > 0.5f ? param->ranges.max : param->ranges.min;
  467. }
  468. else
  469. {
  470. realValue = param->ranges.min + ((param->ranges.max - param->ranges.min) * value);
  471. if (param->hints & NATIVE_PARAMETER_IS_INTEGER)
  472. realValue = std::round(realValue);
  473. }
  474. fDescriptor->set_parameter_value(fHandle, uindex, realValue);
  475. }
  476. // FIXME for v3.0, use const for the input buffer
  477. void vst_processReplacing(float** const inputs, float** const outputs, const int32_t sampleFrames)
  478. {
  479. if (sampleFrames <= 0)
  480. return;
  481. if (fHostType == kHostTypeBitwig && static_cast<int32_t>(fBufferSize) != sampleFrames)
  482. {
  483. // deactivate first if needed
  484. if (fIsActive && fDescriptor->deactivate != nullptr)
  485. fDescriptor->deactivate(fHandle);
  486. fBufferSize = static_cast<uint32_t>(sampleFrames);
  487. if (fDescriptor->dispatcher != nullptr)
  488. fDescriptor->dispatcher(fHandle, NATIVE_PLUGIN_OPCODE_BUFFER_SIZE_CHANGED, 0, sampleFrames, nullptr, 0.0f);
  489. // activate again
  490. if (fDescriptor->activate != nullptr)
  491. fDescriptor->activate(fHandle);
  492. fIsActive = true;
  493. }
  494. if (! fIsActive)
  495. {
  496. // host has not activated the plugin yet, nasty!
  497. vst_dispatcher(effMainsChanged, 0, 1, nullptr, 0.0f);
  498. }
  499. static const int kWantVstTimeFlags = kVstTransportPlaying|kVstPpqPosValid|kVstTempoValid|kVstTimeSigValid;
  500. if (const VstTimeInfo* const vstTimeInfo = (const VstTimeInfo*)hostCallback(audioMasterGetTime, 0, kWantVstTimeFlags))
  501. {
  502. fTimeInfo.frame = static_cast<uint64_t>(std::max(0.0, vstTimeInfo->samplePos));
  503. fTimeInfo.playing = (vstTimeInfo->flags & kVstTransportPlaying);
  504. fTimeInfo.bbt.valid = ((vstTimeInfo->flags & kVstTempoValid) != 0 || (vstTimeInfo->flags & kVstTimeSigValid) != 0);
  505. // ticksPerBeat is not possible with VST
  506. fTimeInfo.bbt.ticksPerBeat = 960.0;
  507. if (vstTimeInfo->flags & kVstTempoValid)
  508. fTimeInfo.bbt.beatsPerMinute = vstTimeInfo->tempo;
  509. else
  510. fTimeInfo.bbt.beatsPerMinute = 120.0;
  511. if ((vstTimeInfo->flags & kVstPpqPosValid) != 0 && (vstTimeInfo->flags & kVstTimeSigValid) != 0)
  512. {
  513. const double ppqPos = std::abs(vstTimeInfo->ppqPos);
  514. const int ppqPerBar = vstTimeInfo->timeSigNumerator * 4 / vstTimeInfo->timeSigDenominator;
  515. const double barBeats = (std::fmod(ppqPos, ppqPerBar) / ppqPerBar) * vstTimeInfo->timeSigNumerator;
  516. const double rest = std::fmod(barBeats, 1.0);
  517. fTimeInfo.bbt.bar = static_cast<int32_t>(ppqPos) / ppqPerBar + 1;
  518. fTimeInfo.bbt.beat = static_cast<int32_t>(barBeats - rest + 0.5) + 1;
  519. fTimeInfo.bbt.tick = rest * fTimeInfo.bbt.ticksPerBeat;
  520. fTimeInfo.bbt.beatsPerBar = static_cast<float>(vstTimeInfo->timeSigNumerator);
  521. fTimeInfo.bbt.beatType = static_cast<float>(vstTimeInfo->timeSigDenominator);
  522. if (vstTimeInfo->ppqPos < 0.0)
  523. {
  524. fTimeInfo.bbt.bar = std::max(1, fTimeInfo.bbt.bar-1);
  525. fTimeInfo.bbt.beat = std::max(1, vstTimeInfo->timeSigNumerator - fTimeInfo.bbt.beat + 1);
  526. fTimeInfo.bbt.tick = std::max(0.0, fTimeInfo.bbt.ticksPerBeat - fTimeInfo.bbt.tick - 1);
  527. }
  528. }
  529. else
  530. {
  531. fTimeInfo.bbt.bar = 1;
  532. fTimeInfo.bbt.beat = 1;
  533. fTimeInfo.bbt.tick = 0.0;
  534. fTimeInfo.bbt.beatsPerBar = 4.0f;
  535. fTimeInfo.bbt.beatType = 4.0f;
  536. }
  537. #if 0
  538. // for testing bad host values
  539. static double last = -99999.0;
  540. if (carla_isNotEqual(vstTimeInfo->samplePos, last))
  541. {
  542. last = vstTimeInfo->samplePos;
  543. carla_stdout("time info %f %f %lu | %i %i",
  544. vstTimeInfo->samplePos, vstTimeInfo->ppqPos, fTimeInfo.frame,
  545. vstTimeInfo->timeSigNumerator, vstTimeInfo->timeSigDenominator);
  546. }
  547. #endif
  548. fTimeInfo.bbt.barStartTick = fTimeInfo.bbt.ticksPerBeat *
  549. static_cast<double>(fTimeInfo.bbt.beatsPerBar) *
  550. (fTimeInfo.bbt.bar - 1);
  551. }
  552. fMidiOutEvents.numEvents = 0;
  553. if (fHandle != nullptr)
  554. fDescriptor->process(fHandle,
  555. inputs, outputs, static_cast<uint32_t>(sampleFrames),
  556. fMidiEvents, fMidiEventCount);
  557. fMidiEventCount = 0;
  558. if (fMidiOutEvents.numEvents > 0)
  559. hostCallback(audioMasterProcessEvents, 0, 0, &fMidiOutEvents, 0.0f);
  560. }
  561. protected:
  562. // -------------------------------------------------------------------
  563. bool handleWriteMidiEvent(const NativeMidiEvent* const event)
  564. {
  565. CARLA_SAFE_ASSERT_RETURN(fDescriptor->midiOuts > 0, false);
  566. CARLA_SAFE_ASSERT_RETURN(event != nullptr, false);
  567. CARLA_SAFE_ASSERT_RETURN(event->data[0] != 0, false);
  568. if (fMidiOutEvents.numEvents >= static_cast<int32_t>(kMaxMidiEvents))
  569. {
  570. // send current events
  571. hostCallback(audioMasterProcessEvents, 0, 0, &fMidiOutEvents, 0.0f);
  572. // clear
  573. fMidiOutEvents.numEvents = 0;
  574. }
  575. VstMidiEvent& vstMidiEvent(fMidiOutEvents.mdata[fMidiOutEvents.numEvents++]);
  576. vstMidiEvent.type = kVstMidiType;
  577. vstMidiEvent.byteSize = kVstMidiEventSize;
  578. uint8_t i=0;
  579. for (; i<event->size; ++i)
  580. vstMidiEvent.midiData[i] = static_cast<char>(event->data[i]);
  581. for (; i<4; ++i)
  582. vstMidiEvent.midiData[i] = 0;
  583. return true;
  584. }
  585. void handleUiParameterChanged(const uint32_t index, const float value) const
  586. {
  587. const NativeParameter* const param = fDescriptor->get_parameter_info(fHandle, index);
  588. CARLA_SAFE_ASSERT_RETURN(param != nullptr,);
  589. const float normalizedValue = (value - param->ranges.min) / (param->ranges.max - param->ranges.min);
  590. hostCallback(audioMasterAutomate, static_cast<int32_t>(index), 0, nullptr, normalizedValue);
  591. }
  592. void handleUiParameterTouch(const uint32_t index, const bool touch) const
  593. {
  594. hostCallback(touch ? audioMasterBeginEdit : audioMasterEndEdit, static_cast<int32_t>(index));
  595. }
  596. void handleUiResize(const int16_t width, const int16_t height)
  597. {
  598. if (kIsUsingUILauncher)
  599. return;
  600. fVstRect.right = width;
  601. fVstRect.bottom = height;
  602. hostCallback(audioMasterSizeWindow, width, height);
  603. }
  604. void handleUiCustomDataChanged(const char* const /*key*/, const char* const /*value*/) const
  605. {
  606. }
  607. void handleUiClosed()
  608. {
  609. }
  610. const char* handleUiOpenFile(const bool /*isDir*/, const char* const /*title*/, const char* const /*filter*/) const
  611. {
  612. // TODO
  613. return nullptr;
  614. }
  615. const char* handleUiSaveFile(const bool /*isDir*/, const char* const /*title*/, const char* const /*filter*/) const
  616. {
  617. // TODO
  618. return nullptr;
  619. }
  620. intptr_t handleDispatcher(const NativeHostDispatcherOpcode opcode, const int32_t index, const intptr_t value, void* const ptr, const float opt)
  621. {
  622. carla_debug("NativePlugin::handleDispatcher(%i, %i, " P_INTPTR ", %p, %f)",
  623. opcode, index, value, ptr, static_cast<double>(opt));
  624. switch (opcode)
  625. {
  626. case NATIVE_HOST_OPCODE_NULL:
  627. case NATIVE_HOST_OPCODE_UPDATE_PARAMETER:
  628. case NATIVE_HOST_OPCODE_UPDATE_MIDI_PROGRAM:
  629. case NATIVE_HOST_OPCODE_RELOAD_PARAMETERS:
  630. case NATIVE_HOST_OPCODE_RELOAD_MIDI_PROGRAMS:
  631. case NATIVE_HOST_OPCODE_UI_UNAVAILABLE:
  632. case NATIVE_HOST_OPCODE_INTERNAL_PLUGIN:
  633. case NATIVE_HOST_OPCODE_QUEUE_INLINE_DISPLAY:
  634. case NATIVE_HOST_OPCODE_REQUEST_IDLE:
  635. case NATIVE_HOST_OPCODE_GET_FILE_PATH:
  636. case NATIVE_HOST_OPCODE_PREVIEW_BUFFER_DATA:
  637. // nothing
  638. break;
  639. case NATIVE_HOST_OPCODE_RELOAD_ALL:
  640. hostCallback(audioMasterUpdateDisplay);
  641. break;
  642. case NATIVE_HOST_OPCODE_HOST_IDLE:
  643. hostCallback(audioMasterIdle);
  644. break;
  645. case NATIVE_HOST_OPCODE_UI_TOUCH_PARAMETER:
  646. CARLA_SAFE_ASSERT_RETURN(index >= 0, 0);
  647. handleUiParameterTouch(static_cast<uint32_t>(index), value != 0);
  648. break;
  649. case NATIVE_HOST_OPCODE_UI_RESIZE:
  650. CARLA_SAFE_ASSERT_RETURN(index > 0 && index < INT16_MAX, 0);
  651. CARLA_SAFE_ASSERT_RETURN(value > 0 && value < INT16_MAX, 0);
  652. handleUiResize(static_cast<int16_t>(index), static_cast<int16_t>(value));
  653. break;
  654. }
  655. // unused for now
  656. return 0;
  657. (void)ptr; (void)opt;
  658. }
  659. private:
  660. // VST stuff
  661. AEffect* const fEffect;
  662. // Native data
  663. NativePluginHandle fHandle;
  664. NativeHostDescriptor fHost;
  665. const NativePluginDescriptor* const fDescriptor;
  666. // VST host data
  667. uint32_t fBufferSize;
  668. double fSampleRate;
  669. // Temporary data
  670. bool fIsActive;
  671. uint32_t fMidiEventCount;
  672. NativeMidiEvent fMidiEvents[kMaxMidiEvents];
  673. char fProgramName[32+1];
  674. NativeTimeInfo fTimeInfo;
  675. VstRect fVstRect;
  676. // UI button
  677. CarlaUILauncher* fUiLauncher;
  678. // Host data
  679. enum HostType {
  680. kHostTypeNull = 0,
  681. kHostTypeArdour,
  682. kHostTypeBitwig
  683. };
  684. HostType fHostType;
  685. // host callback
  686. intptr_t hostCallback(const int32_t opcode,
  687. const int32_t index = 0,
  688. const intptr_t value = 0,
  689. void* const ptr = nullptr,
  690. const float opt = 0.0f) const
  691. {
  692. return VSTAudioMaster(fEffect, opcode, index, value, ptr, opt);
  693. }
  694. struct FixedVstEvents {
  695. int32_t numEvents;
  696. intptr_t reserved;
  697. VstEvent* data[kMaxMidiEvents];
  698. VstMidiEvent mdata[kMaxMidiEvents];
  699. FixedVstEvents()
  700. : numEvents(0),
  701. reserved(0)
  702. {
  703. for (uint32_t i=0; i<kMaxMidiEvents; ++i)
  704. data[i] = (VstEvent*)&mdata[i];
  705. carla_zeroStructs(mdata, kMaxMidiEvents);
  706. }
  707. CARLA_DECLARE_NON_COPYABLE(FixedVstEvents);
  708. } fMidiOutEvents;
  709. char* fStateChunk;
  710. // -------------------------------------------------------------------
  711. #define handlePtr ((NativePlugin*)handle)
  712. static uint32_t host_get_buffer_size(NativeHostHandle handle)
  713. {
  714. return handlePtr->fBufferSize;
  715. }
  716. static double host_get_sample_rate(NativeHostHandle handle)
  717. {
  718. return handlePtr->fSampleRate;
  719. }
  720. static bool host_is_offline(NativeHostHandle /*handle*/)
  721. {
  722. // TODO
  723. return false;
  724. }
  725. static const NativeTimeInfo* host_get_time_info(NativeHostHandle handle)
  726. {
  727. return &(handlePtr->fTimeInfo);
  728. }
  729. static bool host_write_midi_event(NativeHostHandle handle, const NativeMidiEvent* event)
  730. {
  731. return handlePtr->handleWriteMidiEvent(event);
  732. }
  733. static void host_ui_parameter_changed(NativeHostHandle handle, uint32_t index, float value)
  734. {
  735. handlePtr->handleUiParameterChanged(index, value);
  736. }
  737. static void host_ui_custom_data_changed(NativeHostHandle handle, const char* key, const char* value)
  738. {
  739. handlePtr->handleUiCustomDataChanged(key, value);
  740. }
  741. static void host_ui_closed(NativeHostHandle handle)
  742. {
  743. handlePtr->handleUiClosed();
  744. }
  745. static const char* host_ui_open_file(NativeHostHandle handle, bool isDir, const char* title, const char* filter)
  746. {
  747. return handlePtr->handleUiOpenFile(isDir, title, filter);
  748. }
  749. static const char* host_ui_save_file(NativeHostHandle handle, bool isDir, const char* title, const char* filter)
  750. {
  751. return handlePtr->handleUiSaveFile(isDir, title, filter);
  752. }
  753. static intptr_t host_dispatcher(NativeHostHandle handle, NativeHostDispatcherOpcode opcode, int32_t index, intptr_t value, void* ptr, float opt)
  754. {
  755. return handlePtr->handleDispatcher(opcode, index, value, ptr, opt);
  756. }
  757. #undef handlePtr
  758. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(NativePlugin)
  759. };
  760. // -----------------------------------------------------------------------
  761. #define validObject effect != nullptr && effect->object != nullptr
  762. #define validPlugin effect != nullptr && effect->object != nullptr && ((VstObject*)effect->object)->plugin != nullptr
  763. #define vstObjectPtr (VstObject*)effect->object
  764. #define pluginPtr (vstObjectPtr)->plugin
  765. intptr_t vst_dispatcherCallback(AEffect* effect, int32_t opcode, int32_t index, intptr_t value, void* ptr, float opt)
  766. {
  767. // handle base opcodes
  768. switch (opcode)
  769. {
  770. case effOpen:
  771. if (VstObject* const obj = vstObjectPtr)
  772. {
  773. // this must always be valid
  774. CARLA_SAFE_ASSERT_RETURN(obj->audioMaster != nullptr, 0);
  775. // some hosts call effOpen twice
  776. if (obj->plugin != nullptr)
  777. return 1;
  778. d_lastBufferSize = static_cast<uint32_t>(VSTAudioMaster(effect, audioMasterGetBlockSize, 0, 0, nullptr, 0.0f));
  779. d_lastSampleRate = static_cast<double>(VSTAudioMaster(effect, audioMasterGetSampleRate, 0, 0, nullptr, 0.0f));
  780. // some hosts are not ready at this point or return 0 buffersize/samplerate
  781. if (d_lastBufferSize == 0)
  782. d_lastBufferSize = 2048;
  783. if (d_lastSampleRate <= 0.0)
  784. d_lastSampleRate = 44100.0;
  785. const NativePluginDescriptor* pluginDesc = nullptr;
  786. PluginListManager& plm(PluginListManager::getInstance());
  787. #ifdef CARLA_VST_SHELL
  788. if (effect->uniqueID == 0)
  789. effect->uniqueID = kShellUniqueID;
  790. if (effect->uniqueID == kShellUniqueID)
  791. {
  792. // first open for discovery, nothing to do
  793. effect->numParams = 0;
  794. effect->numPrograms = 0;
  795. effect->numInputs = 0;
  796. effect->numOutputs = 0;
  797. return 1;
  798. }
  799. const int32_t plugIndex = effect->uniqueID - kShellUniqueID - 1;
  800. CARLA_SAFE_ASSERT_RETURN(plugIndex >= 0, 0);
  801. pluginDesc = plm.descs.getAt(static_cast<size_t>(plugIndex), nullptr);
  802. #else // CARLA_VST_SHELL
  803. # if defined(CARLA_PLUGIN_64CH)
  804. const char* const pluginLabel = "carlapatchbay64";
  805. # elif defined(CARLA_PLUGIN_32CH)
  806. const char* const pluginLabel = "carlapatchbay32";
  807. # elif defined(CARLA_PLUGIN_16CH)
  808. const char* const pluginLabel = "carlapatchbay16";
  809. # elif CARLA_PLUGIN_PATCHBAY
  810. const char* const pluginLabel = "carlapatchbay";
  811. # else
  812. const char* const pluginLabel = "carlarack";
  813. # endif
  814. for (LinkedList<const NativePluginDescriptor*>::Itenerator it = plm.descs.begin2(); it.valid(); it.next())
  815. {
  816. const NativePluginDescriptor* const& tmpDesc(it.getValue(nullptr));
  817. CARLA_SAFE_ASSERT_CONTINUE(tmpDesc != nullptr);
  818. if (std::strcmp(tmpDesc->label, pluginLabel) == 0)
  819. {
  820. pluginDesc = tmpDesc;
  821. break;
  822. }
  823. }
  824. #endif // CARLA_VST_SHELL
  825. CARLA_SAFE_ASSERT_RETURN(pluginDesc != nullptr, 0);
  826. #ifdef CARLA_VST_SHELL
  827. effect->numPrograms = 1;
  828. effect->numParams = static_cast<int>(pluginDesc->paramIns);
  829. effect->numInputs = static_cast<int>(pluginDesc->audioIns);
  830. effect->numOutputs = static_cast<int>(pluginDesc->audioOuts);
  831. if (pluginDesc->hints & NATIVE_PLUGIN_HAS_UI)
  832. effect->flags |= effFlagsHasEditor;
  833. else
  834. effect->flags &= ~effFlagsHasEditor;
  835. /* carla as plugin always has NATIVE_PLUGIN_IS_SYNTH set
  836. if (pluginDesc->hints & NATIVE_PLUGIN_IS_SYNTH)
  837. effect->flags |= effFlagsIsSynth;
  838. else
  839. effect->flags &= ~effFlagsIsSynth;
  840. */
  841. #endif // CARLA_VST_SHELL
  842. #if CARLA_PLUGIN_SYNTH
  843. // override if requested
  844. effect->flags |= effFlagsIsSynth;
  845. #endif
  846. obj->plugin = new NativePlugin(effect, pluginDesc);
  847. return 1;
  848. }
  849. return 0;
  850. case effClose:
  851. if (VstObject* const obj = vstObjectPtr)
  852. {
  853. NativePlugin* const plugin(obj->plugin);
  854. if (plugin != nullptr)
  855. {
  856. obj->plugin = nullptr;
  857. delete plugin;
  858. }
  859. #if 0
  860. /* This code invalidates the object created in VSTPluginMain
  861. * Probably not safe against all hosts */
  862. obj->audioMaster = nullptr;
  863. effect->object = nullptr;
  864. delete obj;
  865. #endif
  866. return 1;
  867. }
  868. //delete effect;
  869. return 0;
  870. case effGetPlugCategory:
  871. #ifdef CARLA_VST_SHELL
  872. if (validPlugin)
  873. {
  874. #if CARLA_PLUGIN_SYNTH
  875. return kPlugCategSynth;
  876. #else
  877. const NativePluginDescriptor* const desc = pluginPtr->getDescriptor();
  878. return desc->category == NATIVE_PLUGIN_CATEGORY_SYNTH ? kPlugCategSynth : kPlugCategEffect;
  879. #endif
  880. }
  881. return kPlugCategShell;
  882. #elif CARLA_PLUGIN_SYNTH
  883. return kPlugCategSynth;
  884. #else
  885. return kPlugCategEffect;
  886. #endif
  887. case effGetEffectName:
  888. if (char* const cptr = (char*)ptr)
  889. {
  890. #if defined(CARLA_VST_SHELL)
  891. if (validPlugin)
  892. {
  893. const NativePluginDescriptor* const desc = pluginPtr->getDescriptor();
  894. #if CARLA_PLUGIN_SYNTH
  895. std::strncpy(cptr, desc->name, 32);
  896. #else
  897. std::snprintf(cptr, 32, "%s FX", desc->name);
  898. #endif
  899. }
  900. else
  901. {
  902. std::strncpy(cptr, "Carla-VstShell", 32);
  903. }
  904. #elif defined(CARLA_PLUGIN_64CH)
  905. std::strncpy(cptr, "Carla-Patchbay64", 32);
  906. #elif defined(CARLA_PLUGIN_32CH)
  907. std::strncpy(cptr, "Carla-Patchbay32", 32);
  908. #elif defined(CARLA_PLUGIN_16CH)
  909. std::strncpy(cptr, "Carla-Patchbay16", 32);
  910. #elif CARLA_PLUGIN_PATCHBAY
  911. # if CARLA_PLUGIN_SYNTH
  912. std::strncpy(cptr, "Carla-Patchbay", 32);
  913. # else
  914. std::strncpy(cptr, "Carla-PatchbayFX", 32);
  915. # endif
  916. #else // Rack mode
  917. # if CARLA_PLUGIN_SYNTH
  918. std::strncpy(cptr, "Carla-Rack", 32);
  919. # else
  920. std::strncpy(cptr, "Carla-RackFX", 32);
  921. # endif
  922. #endif
  923. return 1;
  924. }
  925. return 0;
  926. case effGetVendorString:
  927. if (char* const cptr = (char*)ptr)
  928. {
  929. #ifdef CARLA_VST_SHELL
  930. if (validPlugin)
  931. {
  932. const NativePluginDescriptor* const desc = pluginPtr->getDescriptor();
  933. std::strncpy(cptr, desc->maker, 32);
  934. }
  935. else
  936. #endif
  937. std::strncpy(cptr, "falkTX", 32);
  938. return 1;
  939. }
  940. return 0;
  941. case effGetProductString:
  942. if (char* const cptr = (char*)ptr)
  943. {
  944. #if defined(CARLA_VST_SHELL)
  945. if (validPlugin)
  946. {
  947. const NativePluginDescriptor* const desc = pluginPtr->getDescriptor();
  948. #if CARLA_PLUGIN_SYNTH
  949. std::strncpy(cptr, desc->label, 32);
  950. #else
  951. std::snprintf(cptr, 32, "%sFX", desc->label);
  952. #endif
  953. }
  954. else
  955. {
  956. std::strncpy(cptr, "CarlaVstShell", 32);
  957. }
  958. #elif defined(CARLA_PLUGIN_64CH)
  959. std::strncpy(cptr, "CarlaPatchbay64", 32);
  960. #elif defined(CARLA_PLUGIN_32CH)
  961. std::strncpy(cptr, "CarlaPatchbay32", 32);
  962. #elif defined(CARLA_PLUGIN_16CH)
  963. std::strncpy(cptr, "CarlaPatchbay16", 32);
  964. #elif CARLA_PLUGIN_PATCHBAY
  965. # if CARLA_PLUGIN_SYNTH
  966. std::strncpy(cptr, "CarlaPatchbay", 32);
  967. # else
  968. std::strncpy(cptr, "CarlaPatchbayFX", 32);
  969. # endif
  970. #else
  971. # if CARLA_PLUGIN_SYNTH
  972. std::strncpy(cptr, "CarlaRack", 32);
  973. # else
  974. std::strncpy(cptr, "CarlaRackFX", 32);
  975. # endif
  976. #endif
  977. return 1;
  978. }
  979. return 0;
  980. case effGetVendorVersion:
  981. return CARLA_VERSION_HEX;
  982. case effGetVstVersion:
  983. return kVstVersion;
  984. #ifdef CARLA_VST_SHELL
  985. case effShellGetNextPlugin:
  986. if (char* const cptr = (char*)ptr)
  987. {
  988. CARLA_SAFE_ASSERT_RETURN(effect != nullptr, 0);
  989. CARLA_SAFE_ASSERT_RETURN(effect->uniqueID >= kShellUniqueID, 0);
  990. PluginListManager& plm(PluginListManager::getInstance());
  991. for (;;)
  992. {
  993. const uint index2 = static_cast<uint>(effect->uniqueID - kShellUniqueID);
  994. if (index2 >= plm.descs.count())
  995. {
  996. effect->uniqueID = kShellUniqueID;
  997. return 0;
  998. }
  999. const NativePluginDescriptor* const desc = plm.descs.getAt(index2, nullptr);
  1000. CARLA_SAFE_ASSERT_RETURN(desc != nullptr, 0);
  1001. ++effect->uniqueID;
  1002. if (desc->midiIns > 1 || desc->midiOuts > 1)
  1003. continue;
  1004. #if CARLA_PLUGIN_SYNTH
  1005. std::strncpy(cptr, desc->label, 32);
  1006. #else
  1007. std::snprintf(cptr, 32, "%sFX", desc->label);
  1008. #endif
  1009. return effect->uniqueID;
  1010. }
  1011. }
  1012. #endif
  1013. };
  1014. // handle advanced opcodes
  1015. if (validPlugin)
  1016. return pluginPtr->vst_dispatcher(opcode, index, value, ptr, opt);
  1017. return 0;
  1018. }
  1019. float vst_getParameterCallback(AEffect* effect, int32_t index)
  1020. {
  1021. if (validPlugin)
  1022. return pluginPtr->vst_getParameter(index);
  1023. return 0.0f;
  1024. }
  1025. void vst_setParameterCallback(AEffect* effect, int32_t index, float value)
  1026. {
  1027. if (validPlugin)
  1028. pluginPtr->vst_setParameter(index, value);
  1029. }
  1030. void vst_processCallback(AEffect* effect, float** inputs, float** outputs, int32_t sampleFrames)
  1031. {
  1032. if (validPlugin)
  1033. pluginPtr->vst_processReplacing(inputs, outputs, sampleFrames);
  1034. }
  1035. void vst_processReplacingCallback(AEffect* effect, float** inputs, float** outputs, int32_t sampleFrames)
  1036. {
  1037. if (validPlugin)
  1038. pluginPtr->vst_processReplacing(inputs, outputs, sampleFrames);
  1039. }
  1040. #undef pluginPtr
  1041. #undef validObject
  1042. #undef validPlugin
  1043. #undef vstObjectPtr
  1044. // -----------------------------------------------------------------------
  1045. const AEffect* VSTPluginMainInit(AEffect* const effect)
  1046. {
  1047. #if defined(CARLA_VST_SHELL)
  1048. if (const intptr_t uniqueID = VSTAudioMaster(effect, audioMasterCurrentId, 0, 0, nullptr, 0.0f))
  1049. effect->uniqueID = static_cast<int>(uniqueID);
  1050. else
  1051. effect->uniqueID = kShellUniqueID;
  1052. #elif defined(CARLA_PLUGIN_64CH)
  1053. effect->uniqueID = kBaseUniqueID+7;
  1054. #elif defined(CARLA_PLUGIN_32CH)
  1055. effect->uniqueID = kBaseUniqueID+6;
  1056. #elif defined(CARLA_PLUGIN_16CH)
  1057. effect->uniqueID = kBaseUniqueID+5;
  1058. #elif CARLA_PLUGIN_PATCHBAY
  1059. # if CARLA_PLUGIN_SYNTH
  1060. effect->uniqueID = kBaseUniqueID+4;
  1061. # else
  1062. effect->uniqueID = kBaseUniqueID+3;
  1063. # endif
  1064. #else
  1065. # if CARLA_PLUGIN_SYNTH
  1066. effect->uniqueID = kBaseUniqueID+2;
  1067. # else
  1068. effect->uniqueID = kBaseUniqueID+1;
  1069. # endif
  1070. #endif
  1071. // plugin fields
  1072. #ifndef CARLA_VST_SHELL
  1073. effect->numParams = kNumParameters;
  1074. effect->numPrograms = 1;
  1075. # if defined(CARLA_PLUGIN_64CH)
  1076. effect->numInputs = 64;
  1077. effect->numOutputs = 64;
  1078. # elif defined(CARLA_PLUGIN_32CH)
  1079. effect->numInputs = 32;
  1080. effect->numOutputs = 32;
  1081. # elif defined(CARLA_PLUGIN_16CH)
  1082. effect->numInputs = 16;
  1083. effect->numOutputs = 16;
  1084. # else
  1085. effect->numInputs = 2;
  1086. effect->numOutputs = 2;
  1087. # endif
  1088. #endif
  1089. // plugin flags
  1090. effect->flags |= effFlagsCanReplacing;
  1091. effect->flags |= effFlagsProgramChunks;
  1092. #ifndef CARLA_VST_SHELL
  1093. effect->flags |= effFlagsHasEditor;
  1094. #endif
  1095. #if CARLA_PLUGIN_SYNTH
  1096. effect->flags |= effFlagsIsSynth;
  1097. #endif
  1098. return effect;
  1099. // may be unused
  1100. (void)kBaseUniqueID;
  1101. }
  1102. // -----------------------------------------------------------------------