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.

1327 lines
43KB

  1. /*
  2. * Carla Native Plugins
  3. * Copyright (C) 2013-2020 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 "CarlaVstUtils.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. *(ERect**)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((intptr_t)ptr, fDescriptor, fHandle);
  333. }
  334. else
  335. {
  336. char strBuf[0xff+1];
  337. std::snprintf(strBuf, 0xff, P_INTPTR, (intptr_t)ptr);
  338. strBuf[0xff] = '\0';
  339. // set CARLA_PLUGIN_EMBED_WINID for external process
  340. carla_setenv("CARLA_PLUGIN_EMBED_WINID", strBuf);
  341. // show UI now
  342. fDescriptor->ui_show(fHandle, true);
  343. // reset CARLA_PLUGIN_EMBED_WINID just in case
  344. carla_setenv("CARLA_PLUGIN_EMBED_WINID", "0");
  345. }
  346. ret = 1;
  347. }
  348. break;
  349. case effEditClose:
  350. if (fDescriptor->ui_show != nullptr)
  351. {
  352. if (kIsUsingUILauncher)
  353. {
  354. destoryUILauncher(fUiLauncher);
  355. fUiLauncher = nullptr;
  356. }
  357. else
  358. {
  359. fDescriptor->ui_show(fHandle, false);
  360. }
  361. ret = 1;
  362. }
  363. break;
  364. case effEditIdle:
  365. if (fUiLauncher != nullptr)
  366. idleUILauncher(fUiLauncher);
  367. if (fDescriptor->ui_idle != nullptr)
  368. fDescriptor->ui_idle(fHandle);
  369. break;
  370. case effGetChunk:
  371. if (ptr == nullptr || fDescriptor->get_state == nullptr)
  372. return 0;
  373. if (fStateChunk != nullptr)
  374. std::free(fStateChunk);
  375. fStateChunk = fDescriptor->get_state(fHandle);
  376. if (fStateChunk == nullptr)
  377. return 0;
  378. ret = static_cast<intptr_t>(std::strlen(fStateChunk)+1);
  379. *(void**)ptr = fStateChunk;
  380. break;
  381. case effSetChunk:
  382. if (value <= 0 || fDescriptor->set_state == nullptr)
  383. return 0;
  384. if (value == 1)
  385. return 1;
  386. if (const char* const state = (const char*)ptr)
  387. {
  388. fDescriptor->set_state(fHandle, state);
  389. ret = 1;
  390. }
  391. break;
  392. case effProcessEvents:
  393. if (! fIsActive)
  394. {
  395. // host has not activated the plugin yet, nasty!
  396. vst_dispatcher(effMainsChanged, 0, 1, nullptr, 0.0f);
  397. }
  398. if (const VstEvents* const events = (const VstEvents*)ptr)
  399. {
  400. if (events->numEvents == 0)
  401. break;
  402. for (int i=0, count=events->numEvents; i < count; ++i)
  403. {
  404. const VstMidiEvent* const vstMidiEvent((const VstMidiEvent*)events->events[i]);
  405. if (vstMidiEvent == nullptr)
  406. break;
  407. if (vstMidiEvent->type != kVstMidiType || vstMidiEvent->deltaFrames < 0)
  408. continue;
  409. if (fMidiEventCount >= kMaxMidiEvents)
  410. break;
  411. const uint32_t j(fMidiEventCount++);
  412. fMidiEvents[j].port = 0;
  413. fMidiEvents[j].time = static_cast<uint32_t>(vstMidiEvent->deltaFrames);
  414. fMidiEvents[j].size = 3;
  415. for (uint32_t k=0; k<3; ++k)
  416. fMidiEvents[j].data[k] = static_cast<uint8_t>(vstMidiEvent->midiData[k]);
  417. }
  418. }
  419. break;
  420. case effCanBeAutomated:
  421. ret = 1;
  422. break;
  423. case effCanDo:
  424. if (const char* const canDo = (const char*)ptr)
  425. {
  426. if (std::strcmp(canDo, "receiveVstEvents") == 0 || std::strcmp(canDo, "receiveVstMidiEvent") == 0)
  427. {
  428. if (fDescriptor->midiIns == 0)
  429. return -1;
  430. return 1;
  431. }
  432. if (std::strcmp(canDo, "sendVstEvents") == 0 || std::strcmp(canDo, "sendVstMidiEvent") == 0)
  433. {
  434. if (fDescriptor->midiOuts == 0)
  435. return -1;
  436. return 1;
  437. }
  438. if (std::strcmp(canDo, "receiveVstTimeInfo") == 0)
  439. return 1;
  440. }
  441. break;
  442. }
  443. return ret;
  444. }
  445. float vst_getParameter(const int32_t index)
  446. {
  447. CARLA_SAFE_ASSERT_RETURN(index >= 0, 0.0f);
  448. const uint32_t uindex = static_cast<uint32_t>(index);
  449. CARLA_SAFE_ASSERT_RETURN(uindex < fDescriptor->paramIns, 0.0f);
  450. const NativeParameter* const param = fDescriptor->get_parameter_info(fHandle, uindex);
  451. CARLA_SAFE_ASSERT_RETURN(param != nullptr, 0);
  452. const float realValue = fDescriptor->get_parameter_value(fHandle, uindex);
  453. return (realValue - param->ranges.min) / (param->ranges.max - param->ranges.min);
  454. }
  455. void vst_setParameter(const int32_t index, const float value)
  456. {
  457. CARLA_SAFE_ASSERT_RETURN(index >= 0,);
  458. const uint32_t uindex = static_cast<uint32_t>(index);
  459. CARLA_SAFE_ASSERT_RETURN(uindex < fDescriptor->paramIns,);
  460. const NativeParameter* const param = fDescriptor->get_parameter_info(fHandle, uindex);
  461. CARLA_SAFE_ASSERT_RETURN(param != nullptr,);
  462. float realValue;
  463. if (param->hints & NATIVE_PARAMETER_IS_BOOLEAN)
  464. {
  465. realValue = value > 0.5f ? param->ranges.max : param->ranges.min;
  466. }
  467. else
  468. {
  469. realValue = param->ranges.min + ((param->ranges.max - param->ranges.min) * value);
  470. if (param->hints & NATIVE_PARAMETER_IS_INTEGER)
  471. realValue = std::round(realValue);
  472. }
  473. fDescriptor->set_parameter_value(fHandle, uindex, realValue);
  474. }
  475. // FIXME for v3.0, use const for the input buffer
  476. void vst_processReplacing(float** const inputs, float** const outputs, const int32_t sampleFrames)
  477. {
  478. if (sampleFrames <= 0)
  479. return;
  480. if (fHostType == kHostTypeBitwig && static_cast<int32_t>(fBufferSize) != sampleFrames)
  481. {
  482. // deactivate first if needed
  483. if (fIsActive && fDescriptor->deactivate != nullptr)
  484. fDescriptor->deactivate(fHandle);
  485. fBufferSize = static_cast<uint32_t>(sampleFrames);
  486. if (fDescriptor->dispatcher != nullptr)
  487. fDescriptor->dispatcher(fHandle, NATIVE_PLUGIN_OPCODE_BUFFER_SIZE_CHANGED, 0, sampleFrames, nullptr, 0.0f);
  488. // activate again
  489. if (fDescriptor->activate != nullptr)
  490. fDescriptor->activate(fHandle);
  491. fIsActive = true;
  492. }
  493. if (! fIsActive)
  494. {
  495. // host has not activated the plugin yet, nasty!
  496. vst_dispatcher(effMainsChanged, 0, 1, nullptr, 0.0f);
  497. }
  498. static const int kWantVstTimeFlags = kVstTransportPlaying|kVstPpqPosValid|kVstTempoValid|kVstTimeSigValid;
  499. if (const VstTimeInfo* const vstTimeInfo = (const VstTimeInfo*)hostCallback(audioMasterGetTime, 0, kWantVstTimeFlags))
  500. {
  501. fTimeInfo.frame = static_cast<uint64_t>(vstTimeInfo->samplePos);
  502. fTimeInfo.playing = (vstTimeInfo->flags & kVstTransportPlaying);
  503. fTimeInfo.bbt.valid = ((vstTimeInfo->flags & kVstTempoValid) != 0 || (vstTimeInfo->flags & kVstTimeSigValid) != 0);
  504. // ticksPerBeat is not possible with VST
  505. fTimeInfo.bbt.ticksPerBeat = 960.0;
  506. if (vstTimeInfo->flags & kVstTempoValid)
  507. fTimeInfo.bbt.beatsPerMinute = vstTimeInfo->tempo;
  508. else
  509. fTimeInfo.bbt.beatsPerMinute = 120.0;
  510. if (vstTimeInfo->flags & (kVstPpqPosValid|kVstTimeSigValid))
  511. {
  512. const double ppqPos = std::abs(vstTimeInfo->ppqPos);
  513. const int ppqPerBar = vstTimeInfo->timeSigNumerator * 4 / vstTimeInfo->timeSigDenominator;
  514. const double barBeats = (std::fmod(ppqPos, ppqPerBar) / ppqPerBar) * vstTimeInfo->timeSigNumerator;
  515. const double rest = std::fmod(barBeats, 1.0);
  516. fTimeInfo.bbt.bar = static_cast<int32_t>(ppqPos) / ppqPerBar + 1;
  517. fTimeInfo.bbt.beat = static_cast<int32_t>(barBeats - rest + 0.5) + 1;
  518. fTimeInfo.bbt.tick = static_cast<int32_t>(rest * fTimeInfo.bbt.ticksPerBeat + 0.5);
  519. fTimeInfo.bbt.beatsPerBar = static_cast<float>(vstTimeInfo->timeSigNumerator);
  520. fTimeInfo.bbt.beatType = static_cast<float>(vstTimeInfo->timeSigDenominator);
  521. if (vstTimeInfo->ppqPos < 0.0)
  522. {
  523. --fTimeInfo.bbt.bar;
  524. fTimeInfo.bbt.beat = vstTimeInfo->timeSigNumerator - fTimeInfo.bbt.beat + 1;
  525. fTimeInfo.bbt.tick = fTimeInfo.bbt.ticksPerBeat - fTimeInfo.bbt.tick - 1;
  526. }
  527. }
  528. else
  529. {
  530. fTimeInfo.bbt.bar = 1;
  531. fTimeInfo.bbt.beat = 1;
  532. fTimeInfo.bbt.tick = 0;
  533. fTimeInfo.bbt.beatsPerBar = 4.0f;
  534. fTimeInfo.bbt.beatType = 4.0f;
  535. }
  536. fTimeInfo.bbt.barStartTick = fTimeInfo.bbt.ticksPerBeat *
  537. static_cast<double>(fTimeInfo.bbt.beatsPerBar) *
  538. (fTimeInfo.bbt.bar - 1);
  539. }
  540. fMidiOutEvents.numEvents = 0;
  541. if (fHandle != nullptr)
  542. fDescriptor->process(fHandle,
  543. inputs, outputs, static_cast<uint32_t>(sampleFrames),
  544. fMidiEvents, fMidiEventCount);
  545. fMidiEventCount = 0;
  546. if (fMidiOutEvents.numEvents > 0)
  547. hostCallback(audioMasterProcessEvents, 0, 0, &fMidiOutEvents, 0.0f);
  548. }
  549. protected:
  550. // -------------------------------------------------------------------
  551. bool handleWriteMidiEvent(const NativeMidiEvent* const event)
  552. {
  553. CARLA_SAFE_ASSERT_RETURN(fDescriptor->midiOuts > 0, false);
  554. CARLA_SAFE_ASSERT_RETURN(event != nullptr, false);
  555. CARLA_SAFE_ASSERT_RETURN(event->data[0] != 0, false);
  556. if (fMidiOutEvents.numEvents >= static_cast<int32_t>(kMaxMidiEvents))
  557. {
  558. // send current events
  559. hostCallback(audioMasterProcessEvents, 0, 0, &fMidiOutEvents, 0.0f);
  560. // clear
  561. fMidiOutEvents.numEvents = 0;
  562. }
  563. VstMidiEvent& vstMidiEvent(fMidiOutEvents.mdata[fMidiOutEvents.numEvents++]);
  564. vstMidiEvent.type = kVstMidiType;
  565. vstMidiEvent.byteSize = kVstMidiEventSize;
  566. uint8_t i=0;
  567. for (; i<event->size; ++i)
  568. vstMidiEvent.midiData[i] = static_cast<char>(event->data[i]);
  569. for (; i<4; ++i)
  570. vstMidiEvent.midiData[i] = 0;
  571. return true;
  572. }
  573. void handleUiParameterChanged(const uint32_t index, const float value) const
  574. {
  575. const NativeParameter* const param = fDescriptor->get_parameter_info(fHandle, index);
  576. CARLA_SAFE_ASSERT_RETURN(param != nullptr,);
  577. const float normalizedValue = (value - param->ranges.min) / (param->ranges.max - param->ranges.min);
  578. hostCallback(audioMasterAutomate, static_cast<int32_t>(index), 0, nullptr, normalizedValue);
  579. }
  580. void handleUiParameterTouch(const uint32_t index, const bool touch) const
  581. {
  582. hostCallback(touch ? audioMasterBeginEdit : audioMasterEndEdit, static_cast<int32_t>(index));
  583. }
  584. void handleUiResize(const int16_t width, const int16_t height)
  585. {
  586. if (kIsUsingUILauncher)
  587. return;
  588. fVstRect.right = width;
  589. fVstRect.bottom = height;
  590. hostCallback(audioMasterSizeWindow, width, height);
  591. }
  592. void handleUiCustomDataChanged(const char* const /*key*/, const char* const /*value*/) const
  593. {
  594. }
  595. void handleUiClosed()
  596. {
  597. }
  598. const char* handleUiOpenFile(const bool /*isDir*/, const char* const /*title*/, const char* const /*filter*/) const
  599. {
  600. // TODO
  601. return nullptr;
  602. }
  603. const char* handleUiSaveFile(const bool /*isDir*/, const char* const /*title*/, const char* const /*filter*/) const
  604. {
  605. // TODO
  606. return nullptr;
  607. }
  608. intptr_t handleDispatcher(const NativeHostDispatcherOpcode opcode, const int32_t index, const intptr_t value, void* const ptr, const float opt)
  609. {
  610. carla_debug("NativePlugin::handleDispatcher(%i, %i, " P_INTPTR ", %p, %f)",
  611. opcode, index, value, ptr, static_cast<double>(opt));
  612. switch (opcode)
  613. {
  614. case NATIVE_HOST_OPCODE_NULL:
  615. case NATIVE_HOST_OPCODE_UPDATE_PARAMETER:
  616. case NATIVE_HOST_OPCODE_UPDATE_MIDI_PROGRAM:
  617. case NATIVE_HOST_OPCODE_RELOAD_PARAMETERS:
  618. case NATIVE_HOST_OPCODE_RELOAD_MIDI_PROGRAMS:
  619. case NATIVE_HOST_OPCODE_UI_UNAVAILABLE:
  620. case NATIVE_HOST_OPCODE_INTERNAL_PLUGIN:
  621. case NATIVE_HOST_OPCODE_QUEUE_INLINE_DISPLAY:
  622. case NATIVE_HOST_OPCODE_REQUEST_IDLE:
  623. case NATIVE_HOST_OPCODE_GET_FILE_PATH:
  624. // nothing
  625. break;
  626. case NATIVE_HOST_OPCODE_RELOAD_ALL:
  627. hostCallback(audioMasterUpdateDisplay);
  628. break;
  629. case NATIVE_HOST_OPCODE_HOST_IDLE:
  630. hostCallback(audioMasterIdle);
  631. break;
  632. case NATIVE_HOST_OPCODE_UI_TOUCH_PARAMETER:
  633. CARLA_SAFE_ASSERT_RETURN(index >= 0, 0);
  634. handleUiParameterTouch(static_cast<uint32_t>(index), value != 0);
  635. break;
  636. case NATIVE_HOST_OPCODE_UI_RESIZE:
  637. CARLA_SAFE_ASSERT_RETURN(index > 0 && index < INT16_MAX, 0);
  638. CARLA_SAFE_ASSERT_RETURN(value > 0 && value < INT16_MAX, 0);
  639. handleUiResize(static_cast<int16_t>(index), static_cast<int16_t>(value));
  640. break;
  641. }
  642. // unused for now
  643. return 0;
  644. (void)ptr; (void)opt;
  645. }
  646. private:
  647. // VST stuff
  648. AEffect* const fEffect;
  649. // Native data
  650. NativePluginHandle fHandle;
  651. NativeHostDescriptor fHost;
  652. const NativePluginDescriptor* const fDescriptor;
  653. // VST host data
  654. uint32_t fBufferSize;
  655. double fSampleRate;
  656. // Temporary data
  657. bool fIsActive;
  658. uint32_t fMidiEventCount;
  659. NativeMidiEvent fMidiEvents[kMaxMidiEvents];
  660. char fProgramName[32+1];
  661. NativeTimeInfo fTimeInfo;
  662. ERect fVstRect;
  663. // UI button
  664. CarlaUILauncher* fUiLauncher;
  665. // Host data
  666. enum HostType {
  667. kHostTypeNull = 0,
  668. kHostTypeArdour,
  669. kHostTypeBitwig
  670. };
  671. HostType fHostType;
  672. // host callback
  673. intptr_t hostCallback(const int32_t opcode,
  674. const int32_t index = 0,
  675. const intptr_t value = 0,
  676. void* const ptr = nullptr,
  677. const float opt = 0.0f) const
  678. {
  679. return VSTAudioMaster(fEffect, opcode, index, value, ptr, opt);
  680. }
  681. struct FixedVstEvents {
  682. int32_t numEvents;
  683. intptr_t reserved;
  684. VstEvent* data[kMaxMidiEvents];
  685. VstMidiEvent mdata[kMaxMidiEvents];
  686. FixedVstEvents()
  687. : numEvents(0),
  688. reserved(0)
  689. {
  690. for (uint32_t i=0; i<kMaxMidiEvents; ++i)
  691. data[i] = (VstEvent*)&mdata[i];
  692. carla_zeroStructs(mdata, kMaxMidiEvents);
  693. }
  694. CARLA_DECLARE_NON_COPY_STRUCT(FixedVstEvents);
  695. } fMidiOutEvents;
  696. char* fStateChunk;
  697. // -------------------------------------------------------------------
  698. #define handlePtr ((NativePlugin*)handle)
  699. static uint32_t host_get_buffer_size(NativeHostHandle handle)
  700. {
  701. return handlePtr->fBufferSize;
  702. }
  703. static double host_get_sample_rate(NativeHostHandle handle)
  704. {
  705. return handlePtr->fSampleRate;
  706. }
  707. static bool host_is_offline(NativeHostHandle /*handle*/)
  708. {
  709. // TODO
  710. return false;
  711. }
  712. static const NativeTimeInfo* host_get_time_info(NativeHostHandle handle)
  713. {
  714. return &(handlePtr->fTimeInfo);
  715. }
  716. static bool host_write_midi_event(NativeHostHandle handle, const NativeMidiEvent* event)
  717. {
  718. return handlePtr->handleWriteMidiEvent(event);
  719. }
  720. static void host_ui_parameter_changed(NativeHostHandle handle, uint32_t index, float value)
  721. {
  722. handlePtr->handleUiParameterChanged(index, value);
  723. }
  724. static void host_ui_custom_data_changed(NativeHostHandle handle, const char* key, const char* value)
  725. {
  726. handlePtr->handleUiCustomDataChanged(key, value);
  727. }
  728. static void host_ui_closed(NativeHostHandle handle)
  729. {
  730. handlePtr->handleUiClosed();
  731. }
  732. static const char* host_ui_open_file(NativeHostHandle handle, bool isDir, const char* title, const char* filter)
  733. {
  734. return handlePtr->handleUiOpenFile(isDir, title, filter);
  735. }
  736. static const char* host_ui_save_file(NativeHostHandle handle, bool isDir, const char* title, const char* filter)
  737. {
  738. return handlePtr->handleUiSaveFile(isDir, title, filter);
  739. }
  740. static intptr_t host_dispatcher(NativeHostHandle handle, NativeHostDispatcherOpcode opcode, int32_t index, intptr_t value, void* ptr, float opt)
  741. {
  742. return handlePtr->handleDispatcher(opcode, index, value, ptr, opt);
  743. }
  744. #undef handlePtr
  745. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(NativePlugin)
  746. };
  747. // -----------------------------------------------------------------------
  748. #define validObject effect != nullptr && effect->object != nullptr
  749. #define validPlugin effect != nullptr && effect->object != nullptr && ((VstObject*)effect->object)->plugin != nullptr
  750. #define vstObjectPtr (VstObject*)effect->object
  751. #define pluginPtr (vstObjectPtr)->plugin
  752. intptr_t vst_dispatcherCallback(AEffect* effect, int32_t opcode, int32_t index, intptr_t value, void* ptr, float opt)
  753. {
  754. // handle base opcodes
  755. switch (opcode)
  756. {
  757. case effOpen:
  758. if (VstObject* const obj = vstObjectPtr)
  759. {
  760. // this must always be valid
  761. CARLA_SAFE_ASSERT_RETURN(obj->audioMaster != nullptr, 0);
  762. // some hosts call effOpen twice
  763. CARLA_SAFE_ASSERT_RETURN(obj->plugin == nullptr, 1);
  764. d_lastBufferSize = static_cast<uint32_t>(VSTAudioMaster(effect, audioMasterGetBlockSize, 0, 0, nullptr, 0.0f));
  765. d_lastSampleRate = static_cast<double>(VSTAudioMaster(effect, audioMasterGetSampleRate, 0, 0, nullptr, 0.0f));
  766. // some hosts are not ready at this point or return 0 buffersize/samplerate
  767. if (d_lastBufferSize == 0)
  768. d_lastBufferSize = 2048;
  769. if (d_lastSampleRate <= 0.0)
  770. d_lastSampleRate = 44100.0;
  771. const NativePluginDescriptor* pluginDesc = nullptr;
  772. PluginListManager& plm(PluginListManager::getInstance());
  773. #ifdef CARLA_VST_SHELL
  774. if (effect->uniqueID == 0)
  775. effect->uniqueID = kShellUniqueID;
  776. if (effect->uniqueID == kShellUniqueID)
  777. {
  778. // first open for discovery, nothing to do
  779. effect->numParams = 0;
  780. effect->numPrograms = 0;
  781. effect->numInputs = 0;
  782. effect->numOutputs = 0;
  783. return 1;
  784. }
  785. const int32_t plugIndex = effect->uniqueID - kShellUniqueID - 1;
  786. CARLA_SAFE_ASSERT_RETURN(plugIndex >= 0, 0);
  787. pluginDesc = plm.descs.getAt(static_cast<size_t>(plugIndex), nullptr);
  788. #else // CARLA_VST_SHELL
  789. # if defined(CARLA_PLUGIN_64CH)
  790. const char* const pluginLabel = "carlapatchbay64";
  791. # elif defined(CARLA_PLUGIN_32CH)
  792. const char* const pluginLabel = "carlapatchbay32";
  793. # elif defined(CARLA_PLUGIN_16CH)
  794. const char* const pluginLabel = "carlapatchbay16";
  795. # elif CARLA_PLUGIN_PATCHBAY
  796. const char* const pluginLabel = "carlapatchbay";
  797. # else
  798. const char* const pluginLabel = "carlarack";
  799. # endif
  800. for (LinkedList<const NativePluginDescriptor*>::Itenerator it = plm.descs.begin2(); it.valid(); it.next())
  801. {
  802. const NativePluginDescriptor* const& tmpDesc(it.getValue(nullptr));
  803. CARLA_SAFE_ASSERT_CONTINUE(tmpDesc != nullptr);
  804. if (std::strcmp(tmpDesc->label, pluginLabel) == 0)
  805. {
  806. pluginDesc = tmpDesc;
  807. break;
  808. }
  809. }
  810. #endif // CARLA_VST_SHELL
  811. CARLA_SAFE_ASSERT_RETURN(pluginDesc != nullptr, 0);
  812. #ifdef CARLA_VST_SHELL
  813. effect->numPrograms = 1;
  814. effect->numParams = static_cast<int>(pluginDesc->paramIns);
  815. effect->numInputs = static_cast<int>(pluginDesc->audioIns);
  816. effect->numOutputs = static_cast<int>(pluginDesc->audioOuts);
  817. if (pluginDesc->hints & NATIVE_PLUGIN_HAS_UI)
  818. effect->flags |= effFlagsHasEditor;
  819. else
  820. effect->flags &= ~effFlagsHasEditor;
  821. /* carla as plugin always has NATIVE_PLUGIN_IS_SYNTH set
  822. if (pluginDesc->hints & NATIVE_PLUGIN_IS_SYNTH)
  823. effect->flags |= effFlagsIsSynth;
  824. else
  825. effect->flags &= ~effFlagsIsSynth;
  826. */
  827. #endif // CARLA_VST_SHELL
  828. #if CARLA_PLUGIN_SYNTH
  829. // override if requested
  830. effect->flags |= effFlagsIsSynth;
  831. #endif
  832. obj->plugin = new NativePlugin(effect, pluginDesc);
  833. return 1;
  834. }
  835. return 0;
  836. case effClose:
  837. if (VstObject* const obj = vstObjectPtr)
  838. {
  839. NativePlugin* const plugin(obj->plugin);
  840. if (plugin != nullptr)
  841. {
  842. obj->plugin = nullptr;
  843. delete plugin;
  844. }
  845. #if 0
  846. /* This code invalidates the object created in VSTPluginMain
  847. * Probably not safe against all hosts */
  848. obj->audioMaster = nullptr;
  849. effect->object = nullptr;
  850. delete obj;
  851. #endif
  852. return 1;
  853. }
  854. //delete effect;
  855. return 0;
  856. case effGetPlugCategory:
  857. #ifdef CARLA_VST_SHELL
  858. if (validPlugin)
  859. {
  860. #if CARLA_PLUGIN_SYNTH
  861. return kPlugCategSynth;
  862. #else
  863. const NativePluginDescriptor* const desc = pluginPtr->getDescriptor();
  864. return desc->category == NATIVE_PLUGIN_CATEGORY_SYNTH ? kPlugCategSynth : kPlugCategEffect;
  865. #endif
  866. }
  867. return kPlugCategShell;
  868. #elif CARLA_PLUGIN_SYNTH
  869. return kPlugCategSynth;
  870. #else
  871. return kPlugCategEffect;
  872. #endif
  873. case effGetEffectName:
  874. if (char* const cptr = (char*)ptr)
  875. {
  876. #if defined(CARLA_VST_SHELL)
  877. if (validPlugin)
  878. {
  879. const NativePluginDescriptor* const desc = pluginPtr->getDescriptor();
  880. #if CARLA_PLUGIN_SYNTH
  881. std::strncpy(cptr, desc->name, 32);
  882. #else
  883. std::snprintf(cptr, 32, "%s FX", desc->name);
  884. #endif
  885. }
  886. else
  887. {
  888. std::strncpy(cptr, "Carla-VstShell", 32);
  889. }
  890. #elif defined(CARLA_PLUGIN_64CH)
  891. std::strncpy(cptr, "Carla-Patchbay64", 32);
  892. #elif defined(CARLA_PLUGIN_32CH)
  893. std::strncpy(cptr, "Carla-Patchbay32", 32);
  894. #elif defined(CARLA_PLUGIN_16CH)
  895. std::strncpy(cptr, "Carla-Patchbay16", 32);
  896. #elif CARLA_PLUGIN_PATCHBAY
  897. # if CARLA_PLUGIN_SYNTH
  898. std::strncpy(cptr, "Carla-Patchbay", 32);
  899. # else
  900. std::strncpy(cptr, "Carla-PatchbayFX", 32);
  901. # endif
  902. #else // Rack mode
  903. # if CARLA_PLUGIN_SYNTH
  904. std::strncpy(cptr, "Carla-Rack", 32);
  905. # else
  906. std::strncpy(cptr, "Carla-RackFX", 32);
  907. # endif
  908. #endif
  909. return 1;
  910. }
  911. return 0;
  912. case effGetVendorString:
  913. if (char* const cptr = (char*)ptr)
  914. {
  915. #ifdef CARLA_VST_SHELL
  916. if (validPlugin)
  917. {
  918. const NativePluginDescriptor* const desc = pluginPtr->getDescriptor();
  919. std::strncpy(cptr, desc->maker, 32);
  920. }
  921. else
  922. #endif
  923. std::strncpy(cptr, "falkTX", 32);
  924. return 1;
  925. }
  926. return 0;
  927. case effGetProductString:
  928. if (char* const cptr = (char*)ptr)
  929. {
  930. #if defined(CARLA_VST_SHELL)
  931. if (validPlugin)
  932. {
  933. const NativePluginDescriptor* const desc = pluginPtr->getDescriptor();
  934. #if CARLA_PLUGIN_SYNTH
  935. std::strncpy(cptr, desc->label, 32);
  936. #else
  937. std::snprintf(cptr, 32, "%sFX", desc->label);
  938. #endif
  939. }
  940. else
  941. {
  942. std::strncpy(cptr, "CarlaVstShell", 32);
  943. }
  944. #elif defined(CARLA_PLUGIN_64CH)
  945. std::strncpy(cptr, "CarlaPatchbay64", 32);
  946. #elif defined(CARLA_PLUGIN_32CH)
  947. std::strncpy(cptr, "CarlaPatchbay32", 32);
  948. #elif defined(CARLA_PLUGIN_16CH)
  949. std::strncpy(cptr, "CarlaPatchbay16", 32);
  950. #elif CARLA_PLUGIN_PATCHBAY
  951. # if CARLA_PLUGIN_SYNTH
  952. std::strncpy(cptr, "CarlaPatchbay", 32);
  953. # else
  954. std::strncpy(cptr, "CarlaPatchbayFX", 32);
  955. # endif
  956. #else
  957. # if CARLA_PLUGIN_SYNTH
  958. std::strncpy(cptr, "CarlaRack", 32);
  959. # else
  960. std::strncpy(cptr, "CarlaRackFX", 32);
  961. # endif
  962. #endif
  963. return 1;
  964. }
  965. return 0;
  966. case effGetVendorVersion:
  967. return CARLA_VERSION_HEX;
  968. case effGetVstVersion:
  969. return kVstVersion;
  970. #ifdef CARLA_VST_SHELL
  971. case effShellGetNextPlugin:
  972. if (char* const cptr = (char*)ptr)
  973. {
  974. CARLA_SAFE_ASSERT_RETURN(effect != nullptr, 0);
  975. CARLA_SAFE_ASSERT_RETURN(effect->uniqueID >= kShellUniqueID, 0);
  976. PluginListManager& plm(PluginListManager::getInstance());
  977. for (;;)
  978. {
  979. const uint index2 = static_cast<uint>(effect->uniqueID - kShellUniqueID);
  980. if (index2 >= plm.descs.count())
  981. {
  982. effect->uniqueID = kShellUniqueID;
  983. return 0;
  984. }
  985. const NativePluginDescriptor* const desc = plm.descs.getAt(index2, nullptr);
  986. CARLA_SAFE_ASSERT_RETURN(desc != nullptr, 0);
  987. ++effect->uniqueID;
  988. if (desc->midiIns > 1 || desc->midiOuts > 1)
  989. continue;
  990. #if CARLA_PLUGIN_SYNTH
  991. std::strncpy(cptr, desc->label, 32);
  992. #else
  993. std::snprintf(cptr, 32, "%sFX", desc->label);
  994. #endif
  995. return effect->uniqueID;
  996. }
  997. }
  998. #endif
  999. };
  1000. // handle advanced opcodes
  1001. if (validPlugin)
  1002. return pluginPtr->vst_dispatcher(opcode, index, value, ptr, opt);
  1003. return 0;
  1004. }
  1005. float vst_getParameterCallback(AEffect* effect, int32_t index)
  1006. {
  1007. if (validPlugin)
  1008. return pluginPtr->vst_getParameter(index);
  1009. return 0.0f;
  1010. }
  1011. void vst_setParameterCallback(AEffect* effect, int32_t index, float value)
  1012. {
  1013. if (validPlugin)
  1014. pluginPtr->vst_setParameter(index, value);
  1015. }
  1016. void vst_processCallback(AEffect* effect, float** inputs, float** outputs, int32_t sampleFrames)
  1017. {
  1018. if (validPlugin)
  1019. pluginPtr->vst_processReplacing(inputs, outputs, sampleFrames);
  1020. }
  1021. void vst_processReplacingCallback(AEffect* effect, float** inputs, float** outputs, int32_t sampleFrames)
  1022. {
  1023. if (validPlugin)
  1024. pluginPtr->vst_processReplacing(inputs, outputs, sampleFrames);
  1025. }
  1026. #undef pluginPtr
  1027. #undef validObject
  1028. #undef validPlugin
  1029. #undef vstObjectPtr
  1030. // -----------------------------------------------------------------------
  1031. const AEffect* VSTPluginMainInit(AEffect* const effect)
  1032. {
  1033. #if defined(CARLA_VST_SHELL)
  1034. if (const intptr_t uniqueID = VSTAudioMaster(effect, audioMasterCurrentId, 0, 0, nullptr, 0.0f))
  1035. effect->uniqueID = static_cast<int>(uniqueID);
  1036. else
  1037. effect->uniqueID = kShellUniqueID;
  1038. #elif defined(CARLA_PLUGIN_64CH)
  1039. effect->uniqueID = kBaseUniqueID+7;
  1040. #elif defined(CARLA_PLUGIN_32CH)
  1041. effect->uniqueID = kBaseUniqueID+6;
  1042. #elif defined(CARLA_PLUGIN_16CH)
  1043. effect->uniqueID = kBaseUniqueID+5;
  1044. #elif CARLA_PLUGIN_PATCHBAY
  1045. # if CARLA_PLUGIN_SYNTH
  1046. effect->uniqueID = kBaseUniqueID+4;
  1047. # else
  1048. effect->uniqueID = kBaseUniqueID+3;
  1049. # endif
  1050. #else
  1051. # if CARLA_PLUGIN_SYNTH
  1052. effect->uniqueID = kBaseUniqueID+2;
  1053. # else
  1054. effect->uniqueID = kBaseUniqueID+1;
  1055. # endif
  1056. #endif
  1057. // plugin fields
  1058. #ifndef CARLA_VST_SHELL
  1059. effect->numParams = kNumParameters;
  1060. effect->numPrograms = 1;
  1061. # if defined(CARLA_PLUGIN_64CH)
  1062. effect->numInputs = 64;
  1063. effect->numOutputs = 64;
  1064. # elif defined(CARLA_PLUGIN_32CH)
  1065. effect->numInputs = 32;
  1066. effect->numOutputs = 32;
  1067. # elif defined(CARLA_PLUGIN_16CH)
  1068. effect->numInputs = 16;
  1069. effect->numOutputs = 16;
  1070. # else
  1071. effect->numInputs = 2;
  1072. effect->numOutputs = 2;
  1073. # endif
  1074. #endif
  1075. // plugin flags
  1076. effect->flags |= effFlagsCanReplacing;
  1077. effect->flags |= effFlagsProgramChunks;
  1078. #ifndef CARLA_VST_SHELL
  1079. effect->flags |= effFlagsHasEditor;
  1080. #endif
  1081. #if CARLA_PLUGIN_SYNTH
  1082. effect->flags |= effFlagsIsSynth;
  1083. #endif
  1084. return effect;
  1085. // may be unused
  1086. (void)kBaseUniqueID;
  1087. }
  1088. // -----------------------------------------------------------------------