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.

1309 lines
42KB

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