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.

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