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.

1311 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, 23);
  202. programName[23] = '\0';
  203. return 1;
  204. }
  205. break;
  206. case effGetProgramNameIndexed:
  207. if (char* const programName = (char*)ptr)
  208. {
  209. std::strncpy(programName, fProgramName, 23);
  210. programName[23] = '\0';
  211. return 1;
  212. }
  213. break;
  214. case effGetParamDisplay:
  215. CARLA_SAFE_ASSERT_RETURN(index >= 0, 0);
  216. #ifndef CARLA_VST_SHELL
  217. CARLA_SAFE_ASSERT_RETURN(index < kNumParameters, 0);
  218. #endif
  219. if (char* const cptr = (char*)ptr)
  220. {
  221. const uint32_t uindex = static_cast<uint32_t>(index);
  222. CARLA_SAFE_ASSERT_RETURN(uindex < fDescriptor->paramIns, 0);
  223. const NativeParameter* const param = fDescriptor->get_parameter_info(fHandle, uindex);
  224. CARLA_SAFE_ASSERT_RETURN(param != nullptr, 0);
  225. float paramValue = fDescriptor->get_parameter_value(fHandle, uindex);
  226. if (param->hints & NATIVE_PARAMETER_IS_BOOLEAN)
  227. {
  228. const NativeParameterRanges& ranges(param->ranges);
  229. const float midRange = ranges.min + (ranges.max - ranges.min) / 2.0f;
  230. paramValue = paramValue > midRange ? ranges.max : ranges.min;
  231. }
  232. else if (param->hints & NATIVE_PARAMETER_IS_INTEGER)
  233. {
  234. paramValue = std::round(paramValue);
  235. }
  236. for (uint32_t i = 0; i < param->scalePointCount; ++i)
  237. {
  238. const NativeParameterScalePoint& scalePoint(param->scalePoints[uindex]);
  239. if (carla_isNotEqual(paramValue, scalePoint.value))
  240. continue;
  241. std::strncpy(cptr, scalePoint.label, 23);
  242. cptr[23] = '\0';
  243. return 1;
  244. }
  245. if (param->hints & NATIVE_PARAMETER_IS_INTEGER)
  246. {
  247. std::snprintf(cptr, 23, "%d%s%s",
  248. static_cast<int>(paramValue),
  249. param->unit != nullptr && param->unit[0] != '\0' ? " " : "",
  250. param->unit != nullptr && param->unit[0] != '\0' ? param->unit : "");
  251. cptr[23] = '\0';
  252. }
  253. else
  254. {
  255. std::snprintf(cptr, 23, "%.12g%s%s",
  256. static_cast<double>(paramValue),
  257. param->unit != nullptr && param->unit[0] != '\0' ? " " : "",
  258. param->unit != nullptr && param->unit[0] != '\0' ? param->unit : "");
  259. cptr[23] = '\0';
  260. }
  261. return 1;
  262. }
  263. break;
  264. case effGetParamName:
  265. CARLA_SAFE_ASSERT_RETURN(index >= 0, 0);
  266. #ifndef CARLA_VST_SHELL
  267. CARLA_SAFE_ASSERT_RETURN(index < kNumParameters, 0);
  268. #endif
  269. if (char* const cptr = (char*)ptr)
  270. {
  271. const uint32_t uindex = static_cast<uint32_t>(index);
  272. CARLA_SAFE_ASSERT_RETURN(uindex < fDescriptor->paramIns, 0);
  273. const NativeParameter* const param = fDescriptor->get_parameter_info(fHandle, uindex);
  274. CARLA_SAFE_ASSERT_RETURN(param != nullptr, 0);
  275. std::strncpy(cptr, param->name, 15);
  276. cptr[15] = '\0';
  277. return 1;
  278. }
  279. return 0;
  280. case effSetSampleRate:
  281. CARLA_SAFE_ASSERT_RETURN(opt > 0.0f, 0);
  282. if (carla_isEqual(fSampleRate, static_cast<double>(opt)))
  283. return 0;
  284. fSampleRate = opt;
  285. if (fDescriptor->dispatcher != nullptr)
  286. fDescriptor->dispatcher(fHandle, NATIVE_PLUGIN_OPCODE_SAMPLE_RATE_CHANGED, 0, 0, nullptr, opt);
  287. break;
  288. case effSetBlockSize:
  289. CARLA_SAFE_ASSERT_RETURN(value > 0, 0);
  290. if (fBufferSize == static_cast<uint32_t>(value))
  291. return 0;
  292. fBufferSize = static_cast<uint32_t>(value);
  293. if (fDescriptor->dispatcher != nullptr)
  294. fDescriptor->dispatcher(fHandle, NATIVE_PLUGIN_OPCODE_BUFFER_SIZE_CHANGED, 0, value, nullptr, 0.0f);
  295. break;
  296. case effMainsChanged:
  297. if (value != 0)
  298. {
  299. fMidiEventCount = 0;
  300. carla_zeroStruct(fTimeInfo);
  301. // tell host we want MIDI events
  302. if (fDescriptor->midiIns > 0)
  303. hostCallback(audioMasterWantMidi);
  304. // deactivate for possible changes
  305. if (fDescriptor->deactivate != nullptr && fIsActive)
  306. fDescriptor->deactivate(fHandle);
  307. // check if something changed
  308. const uint32_t bufferSize = static_cast<uint32_t>(hostCallback(audioMasterGetBlockSize));
  309. const double sampleRate = static_cast<double>(hostCallback(audioMasterGetSampleRate));
  310. if (bufferSize != 0 && fBufferSize != bufferSize && (fHostType != kHostTypeArdour || fBufferSize == 0))
  311. {
  312. fBufferSize = bufferSize;
  313. if (fDescriptor->dispatcher != nullptr)
  314. fDescriptor->dispatcher(fHandle, NATIVE_PLUGIN_OPCODE_BUFFER_SIZE_CHANGED, 0, bufferSize, nullptr, 0.0f);
  315. }
  316. if (carla_isNotZero(sampleRate) && carla_isNotEqual(fSampleRate, sampleRate))
  317. {
  318. fSampleRate = sampleRate;
  319. if (fDescriptor->dispatcher != nullptr)
  320. fDescriptor->dispatcher(fHandle, NATIVE_PLUGIN_OPCODE_SAMPLE_RATE_CHANGED, 0, 0, nullptr, (float)sampleRate);
  321. }
  322. if (fDescriptor->activate != nullptr)
  323. fDescriptor->activate(fHandle);
  324. fIsActive = true;
  325. }
  326. else
  327. {
  328. CARLA_SAFE_ASSERT_BREAK(fIsActive);
  329. if (fDescriptor->deactivate != nullptr)
  330. fDescriptor->deactivate(fHandle);
  331. fIsActive = false;
  332. }
  333. break;
  334. case effEditGetRect:
  335. *(ERect**)ptr = &fVstRect;
  336. ret = 1;
  337. break;
  338. case effEditOpen:
  339. if (fDescriptor->ui_show != nullptr)
  340. {
  341. if (kIsUsingUILauncher)
  342. {
  343. destoryUILauncher(fUiLauncher);
  344. fUiLauncher = createUILauncher((intptr_t)ptr, fDescriptor, fHandle);
  345. }
  346. else
  347. {
  348. char strBuf[0xff+1];
  349. std::snprintf(strBuf, 0xff, P_INTPTR, (intptr_t)ptr);
  350. strBuf[0xff] = '\0';
  351. // set CARLA_PLUGIN_EMBED_WINID for external process
  352. carla_setenv("CARLA_PLUGIN_EMBED_WINID", strBuf);
  353. // show UI now
  354. fDescriptor->ui_show(fHandle, true);
  355. // reset CARLA_PLUGIN_EMBED_WINID just in case
  356. carla_setenv("CARLA_PLUGIN_EMBED_WINID", "0");
  357. }
  358. ret = 1;
  359. }
  360. break;
  361. case effEditClose:
  362. if (fDescriptor->ui_show != nullptr)
  363. {
  364. if (kIsUsingUILauncher)
  365. {
  366. destoryUILauncher(fUiLauncher);
  367. fUiLauncher = nullptr;
  368. }
  369. else
  370. {
  371. fDescriptor->ui_show(fHandle, false);
  372. }
  373. ret = 1;
  374. }
  375. break;
  376. case effEditIdle:
  377. if (fUiLauncher != nullptr)
  378. idleUILauncher(fUiLauncher);
  379. if (fDescriptor->ui_idle != nullptr)
  380. fDescriptor->ui_idle(fHandle);
  381. break;
  382. case effGetChunk:
  383. if (ptr == nullptr || fDescriptor->get_state == nullptr)
  384. return 0;
  385. if (fStateChunk != nullptr)
  386. std::free(fStateChunk);
  387. fStateChunk = fDescriptor->get_state(fHandle);
  388. if (fStateChunk == nullptr)
  389. return 0;
  390. ret = static_cast<intptr_t>(std::strlen(fStateChunk)+1);
  391. *(void**)ptr = fStateChunk;
  392. break;
  393. case effSetChunk:
  394. if (value <= 0 || fDescriptor->set_state == nullptr)
  395. return 0;
  396. if (value == 1)
  397. return 1;
  398. if (const char* const state = (const char*)ptr)
  399. {
  400. fDescriptor->set_state(fHandle, state);
  401. ret = 1;
  402. }
  403. break;
  404. case effProcessEvents:
  405. if (! fIsActive)
  406. {
  407. // host has not activated the plugin yet, nasty!
  408. vst_dispatcher(effMainsChanged, 0, 1, nullptr, 0.0f);
  409. }
  410. if (const VstEvents* const events = (const VstEvents*)ptr)
  411. {
  412. if (events->numEvents == 0)
  413. break;
  414. for (int i=0, count=events->numEvents; i < count; ++i)
  415. {
  416. const VstMidiEvent* const vstMidiEvent((const VstMidiEvent*)events->events[i]);
  417. if (vstMidiEvent == nullptr)
  418. break;
  419. if (vstMidiEvent->type != kVstMidiType || vstMidiEvent->deltaFrames < 0)
  420. continue;
  421. if (fMidiEventCount >= kMaxMidiEvents)
  422. break;
  423. const uint32_t j(fMidiEventCount++);
  424. fMidiEvents[j].port = 0;
  425. fMidiEvents[j].time = static_cast<uint32_t>(vstMidiEvent->deltaFrames);
  426. fMidiEvents[j].size = 3;
  427. for (uint32_t k=0; k<3; ++k)
  428. fMidiEvents[j].data[k] = static_cast<uint8_t>(vstMidiEvent->midiData[k]);
  429. }
  430. }
  431. break;
  432. case effCanBeAutomated:
  433. ret = 1;
  434. break;
  435. case effCanDo:
  436. if (const char* const canDo = (const char*)ptr)
  437. {
  438. if (std::strcmp(canDo, "receiveVstEvents") == 0 || std::strcmp(canDo, "receiveVstMidiEvent") == 0)
  439. {
  440. if (fDescriptor->midiIns == 0)
  441. return -1;
  442. return 1;
  443. }
  444. if (std::strcmp(canDo, "sendVstEvents") == 0 || std::strcmp(canDo, "sendVstMidiEvent") == 0)
  445. {
  446. if (fDescriptor->midiOuts == 0)
  447. return -1;
  448. return 1;
  449. }
  450. if (std::strcmp(canDo, "receiveVstTimeInfo") == 0)
  451. return 1;
  452. }
  453. break;
  454. }
  455. return ret;
  456. }
  457. float vst_getParameter(const int32_t index)
  458. {
  459. CARLA_SAFE_ASSERT_RETURN(index >= 0, 0.0f);
  460. const uint32_t uindex = static_cast<uint32_t>(index);
  461. CARLA_SAFE_ASSERT_RETURN(uindex < fDescriptor->paramIns, 0.0f);
  462. const NativeParameter* const param = fDescriptor->get_parameter_info(fHandle, uindex);
  463. CARLA_SAFE_ASSERT_RETURN(param != nullptr, 0);
  464. const float realValue = fDescriptor->get_parameter_value(fHandle, uindex);
  465. return (realValue - param->ranges.min) / (param->ranges.max - param->ranges.min);
  466. }
  467. void vst_setParameter(const int32_t index, const float value)
  468. {
  469. CARLA_SAFE_ASSERT_RETURN(index >= 0,);
  470. const uint32_t uindex = static_cast<uint32_t>(index);
  471. CARLA_SAFE_ASSERT_RETURN(uindex < fDescriptor->paramIns,);
  472. const NativeParameter* const param = fDescriptor->get_parameter_info(fHandle, uindex);
  473. CARLA_SAFE_ASSERT_RETURN(param != nullptr,);
  474. float realValue;
  475. if (param->hints & NATIVE_PARAMETER_IS_BOOLEAN)
  476. {
  477. realValue = value > 0.5f ? param->ranges.max : param->ranges.min;
  478. }
  479. else
  480. {
  481. realValue = param->ranges.min + ((param->ranges.max - param->ranges.min) * value);
  482. if (param->hints & NATIVE_PARAMETER_IS_INTEGER)
  483. realValue = std::round(realValue);
  484. }
  485. fDescriptor->set_parameter_value(fHandle, uindex, realValue);
  486. }
  487. void vst_processReplacing(const float** const inputs, float** const outputs, const int32_t sampleFrames)
  488. {
  489. if (sampleFrames <= 0)
  490. return;
  491. if (fHostType == kHostTypeBitwig && static_cast<int32_t>(fBufferSize) != sampleFrames)
  492. {
  493. // deactivate first if needed
  494. if (fIsActive && fDescriptor->deactivate != nullptr)
  495. fDescriptor->deactivate(fHandle);
  496. fBufferSize = static_cast<uint32_t>(sampleFrames);
  497. if (fDescriptor->dispatcher != nullptr)
  498. fDescriptor->dispatcher(fHandle, NATIVE_PLUGIN_OPCODE_BUFFER_SIZE_CHANGED, 0, sampleFrames, nullptr, 0.0f);
  499. // activate again
  500. if (fDescriptor->activate != nullptr)
  501. fDescriptor->activate(fHandle);
  502. fIsActive = true;
  503. }
  504. if (! fIsActive)
  505. {
  506. // host has not activated the plugin yet, nasty!
  507. vst_dispatcher(effMainsChanged, 0, 1, nullptr, 0.0f);
  508. }
  509. static const int kWantVstTimeFlags = kVstTransportPlaying|kVstPpqPosValid|kVstTempoValid|kVstTimeSigValid;
  510. if (const VstTimeInfo* const vstTimeInfo = (const VstTimeInfo*)hostCallback(audioMasterGetTime, 0, kWantVstTimeFlags))
  511. {
  512. fTimeInfo.frame = static_cast<uint64_t>(vstTimeInfo->samplePos);
  513. fTimeInfo.playing = (vstTimeInfo->flags & kVstTransportPlaying);
  514. fTimeInfo.bbt.valid = ((vstTimeInfo->flags & kVstTempoValid) != 0 || (vstTimeInfo->flags & kVstTimeSigValid) != 0);
  515. // ticksPerBeat is not possible with VST
  516. fTimeInfo.bbt.ticksPerBeat = 960.0;
  517. if (vstTimeInfo->flags & kVstTempoValid)
  518. fTimeInfo.bbt.beatsPerMinute = vstTimeInfo->tempo;
  519. else
  520. fTimeInfo.bbt.beatsPerMinute = 120.0;
  521. if (vstTimeInfo->flags & (kVstPpqPosValid|kVstTimeSigValid))
  522. {
  523. const double ppqPos = std::abs(vstTimeInfo->ppqPos);
  524. const int ppqPerBar = vstTimeInfo->timeSigNumerator * 4 / vstTimeInfo->timeSigDenominator;
  525. const double barBeats = (std::fmod(ppqPos, ppqPerBar) / ppqPerBar) * vstTimeInfo->timeSigNumerator;
  526. const double rest = std::fmod(barBeats, 1.0);
  527. fTimeInfo.bbt.bar = static_cast<int32_t>(ppqPos) / ppqPerBar + 1;
  528. fTimeInfo.bbt.beat = static_cast<int32_t>(barBeats - rest + 0.5) + 1;
  529. fTimeInfo.bbt.tick = static_cast<int32_t>(rest * fTimeInfo.bbt.ticksPerBeat + 0.5);
  530. fTimeInfo.bbt.beatsPerBar = static_cast<float>(vstTimeInfo->timeSigNumerator);
  531. fTimeInfo.bbt.beatType = static_cast<float>(vstTimeInfo->timeSigDenominator);
  532. if (vstTimeInfo->ppqPos < 0.0)
  533. {
  534. --fTimeInfo.bbt.bar;
  535. fTimeInfo.bbt.beat = vstTimeInfo->timeSigNumerator - fTimeInfo.bbt.beat + 1;
  536. fTimeInfo.bbt.tick = fTimeInfo.bbt.ticksPerBeat - fTimeInfo.bbt.tick - 1;
  537. }
  538. }
  539. else
  540. {
  541. fTimeInfo.bbt.bar = 1;
  542. fTimeInfo.bbt.beat = 1;
  543. fTimeInfo.bbt.tick = 0;
  544. fTimeInfo.bbt.beatsPerBar = 4.0f;
  545. fTimeInfo.bbt.beatType = 4.0f;
  546. }
  547. fTimeInfo.bbt.barStartTick = fTimeInfo.bbt.ticksPerBeat *
  548. static_cast<double>(fTimeInfo.bbt.beatsPerBar) *
  549. (fTimeInfo.bbt.bar - 1);
  550. }
  551. fMidiOutEvents.numEvents = 0;
  552. if (fHandle != nullptr)
  553. // FIXME
  554. fDescriptor->process(fHandle,
  555. inputs, outputs, static_cast<uint32_t>(sampleFrames),
  556. fMidiEvents, fMidiEventCount);
  557. fMidiEventCount = 0;
  558. if (fMidiOutEvents.numEvents > 0)
  559. hostCallback(audioMasterProcessEvents, 0, 0, &fMidiOutEvents, 0.0f);
  560. }
  561. protected:
  562. // -------------------------------------------------------------------
  563. bool handleWriteMidiEvent(const NativeMidiEvent* const event)
  564. {
  565. CARLA_SAFE_ASSERT_RETURN(fDescriptor->midiOuts > 0, false);
  566. CARLA_SAFE_ASSERT_RETURN(event != nullptr, false);
  567. CARLA_SAFE_ASSERT_RETURN(event->data[0] != 0, false);
  568. if (fMidiOutEvents.numEvents >= static_cast<int32_t>(kMaxMidiEvents))
  569. {
  570. // send current events
  571. hostCallback(audioMasterProcessEvents, 0, 0, &fMidiOutEvents, 0.0f);
  572. // clear
  573. fMidiOutEvents.numEvents = 0;
  574. }
  575. VstMidiEvent& vstMidiEvent(fMidiOutEvents.mdata[fMidiOutEvents.numEvents++]);
  576. vstMidiEvent.type = kVstMidiType;
  577. vstMidiEvent.byteSize = kVstMidiEventSize;
  578. uint8_t i=0;
  579. for (; i<event->size; ++i)
  580. vstMidiEvent.midiData[i] = static_cast<char>(event->data[i]);
  581. for (; i<4; ++i)
  582. vstMidiEvent.midiData[i] = 0;
  583. return true;
  584. }
  585. void handleUiParameterChanged(const uint32_t index, const float value) const
  586. {
  587. const NativeParameter* const param = fDescriptor->get_parameter_info(fHandle, index);
  588. CARLA_SAFE_ASSERT_RETURN(param != nullptr,);
  589. const float normalizedValue = (value - param->ranges.min) / (param->ranges.max - param->ranges.min);
  590. hostCallback(audioMasterAutomate, static_cast<int32_t>(index), 0, nullptr, normalizedValue);
  591. }
  592. void handleUiParameterTouch(const uint32_t index, const bool touch) const
  593. {
  594. hostCallback(touch ? audioMasterBeginEdit : audioMasterEndEdit, static_cast<int32_t>(index));
  595. }
  596. void handleUiCustomDataChanged(const char* const /*key*/, const char* const /*value*/) const
  597. {
  598. }
  599. void handleUiClosed()
  600. {
  601. }
  602. const char* handleUiOpenFile(const bool /*isDir*/, const char* const /*title*/, const char* const /*filter*/) const
  603. {
  604. // TODO
  605. return nullptr;
  606. }
  607. const char* handleUiSaveFile(const bool /*isDir*/, const char* const /*title*/, const char* const /*filter*/) const
  608. {
  609. // TODO
  610. return nullptr;
  611. }
  612. intptr_t handleDispatcher(const NativeHostDispatcherOpcode opcode, const int32_t index, const intptr_t value, void* const ptr, const float opt)
  613. {
  614. carla_debug("NativePlugin::handleDispatcher(%i, %i, " P_INTPTR ", %p, %f)",
  615. opcode, index, value, ptr, static_cast<double>(opt));
  616. switch (opcode)
  617. {
  618. case NATIVE_HOST_OPCODE_NULL:
  619. case NATIVE_HOST_OPCODE_UPDATE_PARAMETER:
  620. case NATIVE_HOST_OPCODE_UPDATE_MIDI_PROGRAM:
  621. case NATIVE_HOST_OPCODE_RELOAD_PARAMETERS:
  622. case NATIVE_HOST_OPCODE_RELOAD_MIDI_PROGRAMS:
  623. case NATIVE_HOST_OPCODE_UI_UNAVAILABLE:
  624. case NATIVE_HOST_OPCODE_INTERNAL_PLUGIN:
  625. case NATIVE_HOST_OPCODE_QUEUE_INLINE_DISPLAY:
  626. case NATIVE_HOST_OPCODE_REQUEST_IDLE:
  627. case NATIVE_HOST_OPCODE_GET_FILE_PATH:
  628. // nothing
  629. break;
  630. case NATIVE_HOST_OPCODE_RELOAD_ALL:
  631. hostCallback(audioMasterUpdateDisplay);
  632. break;
  633. case NATIVE_HOST_OPCODE_HOST_IDLE:
  634. hostCallback(audioMasterIdle);
  635. break;
  636. case NATIVE_HOST_OPCODE_UI_TOUCH_PARAMETER:
  637. CARLA_SAFE_ASSERT_RETURN(index >= 0, 0);
  638. handleUiParameterTouch(static_cast<uint32_t>(index), value != 0);
  639. break;
  640. }
  641. // unused for now
  642. return 0;
  643. (void)ptr; (void)opt;
  644. }
  645. private:
  646. // VST stuff
  647. AEffect* const fEffect;
  648. // Native data
  649. NativePluginHandle fHandle;
  650. NativeHostDescriptor fHost;
  651. const NativePluginDescriptor* const fDescriptor;
  652. // VST host data
  653. uint32_t fBufferSize;
  654. double fSampleRate;
  655. // Temporary data
  656. bool fIsActive;
  657. uint32_t fMidiEventCount;
  658. NativeMidiEvent fMidiEvents[kMaxMidiEvents];
  659. char fProgramName[32+1];
  660. NativeTimeInfo fTimeInfo;
  661. ERect fVstRect;
  662. // UI button
  663. CarlaUILauncher* fUiLauncher;
  664. // Host data
  665. enum HostType {
  666. kHostTypeNull = 0,
  667. kHostTypeArdour,
  668. kHostTypeBitwig
  669. };
  670. HostType fHostType;
  671. // host callback
  672. intptr_t hostCallback(const int32_t opcode,
  673. const int32_t index = 0,
  674. const intptr_t value = 0,
  675. void* const ptr = nullptr,
  676. const float opt = 0.0f) const
  677. {
  678. return VSTAudioMaster(fEffect, opcode, index, value, ptr, opt);
  679. }
  680. struct FixedVstEvents {
  681. int32_t numEvents;
  682. intptr_t reserved;
  683. VstEvent* data[kMaxMidiEvents];
  684. VstMidiEvent mdata[kMaxMidiEvents];
  685. FixedVstEvents()
  686. : numEvents(0),
  687. reserved(0)
  688. {
  689. for (uint32_t i=0; i<kMaxMidiEvents; ++i)
  690. data[i] = (VstEvent*)&mdata[i];
  691. carla_zeroStructs(mdata, kMaxMidiEvents);
  692. }
  693. CARLA_DECLARE_NON_COPY_STRUCT(FixedVstEvents);
  694. } fMidiOutEvents;
  695. #ifdef USING_JUCE
  696. juce::SharedResourcePointer<juce::ScopedJuceInitialiser_GUI> fJuceInitialiser;
  697. #endif
  698. char* fStateChunk;
  699. // -------------------------------------------------------------------
  700. #define handlePtr ((NativePlugin*)handle)
  701. static uint32_t host_get_buffer_size(NativeHostHandle handle)
  702. {
  703. return handlePtr->fBufferSize;
  704. }
  705. static double host_get_sample_rate(NativeHostHandle handle)
  706. {
  707. return handlePtr->fSampleRate;
  708. }
  709. static bool host_is_offline(NativeHostHandle /*handle*/)
  710. {
  711. // TODO
  712. return false;
  713. }
  714. static const NativeTimeInfo* host_get_time_info(NativeHostHandle handle)
  715. {
  716. return &(handlePtr->fTimeInfo);
  717. }
  718. static bool host_write_midi_event(NativeHostHandle handle, const NativeMidiEvent* event)
  719. {
  720. return handlePtr->handleWriteMidiEvent(event);
  721. }
  722. static void host_ui_parameter_changed(NativeHostHandle handle, uint32_t index, float value)
  723. {
  724. handlePtr->handleUiParameterChanged(index, value);
  725. }
  726. static void host_ui_custom_data_changed(NativeHostHandle handle, const char* key, const char* value)
  727. {
  728. handlePtr->handleUiCustomDataChanged(key, value);
  729. }
  730. static void host_ui_closed(NativeHostHandle handle)
  731. {
  732. handlePtr->handleUiClosed();
  733. }
  734. static const char* host_ui_open_file(NativeHostHandle handle, bool isDir, const char* title, const char* filter)
  735. {
  736. return handlePtr->handleUiOpenFile(isDir, title, filter);
  737. }
  738. static const char* host_ui_save_file(NativeHostHandle handle, bool isDir, const char* title, const char* filter)
  739. {
  740. return handlePtr->handleUiSaveFile(isDir, title, filter);
  741. }
  742. static intptr_t host_dispatcher(NativeHostHandle handle, NativeHostDispatcherOpcode opcode, int32_t index, intptr_t value, void* ptr, float opt)
  743. {
  744. return handlePtr->handleDispatcher(opcode, index, value, ptr, opt);
  745. }
  746. #undef handlePtr
  747. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(NativePlugin)
  748. };
  749. // -----------------------------------------------------------------------
  750. #define validObject effect != nullptr && effect->object != nullptr
  751. #define validPlugin effect != nullptr && effect->object != nullptr && ((VstObject*)effect->object)->plugin != nullptr
  752. #define vstObjectPtr (VstObject*)effect->object
  753. #define pluginPtr (vstObjectPtr)->plugin
  754. intptr_t vst_dispatcherCallback(AEffect* effect, int32_t opcode, int32_t index, intptr_t value, void* ptr, float opt)
  755. {
  756. // handle base opcodes
  757. switch (opcode)
  758. {
  759. case effOpen:
  760. if (VstObject* const obj = vstObjectPtr)
  761. {
  762. // this must always be valid
  763. CARLA_SAFE_ASSERT_RETURN(obj->audioMaster != nullptr, 0);
  764. // some hosts call effOpen twice
  765. CARLA_SAFE_ASSERT_RETURN(obj->plugin == nullptr, 1);
  766. d_lastBufferSize = static_cast<uint32_t>(VSTAudioMaster(effect, audioMasterGetBlockSize, 0, 0, nullptr, 0.0f));
  767. d_lastSampleRate = static_cast<double>(VSTAudioMaster(effect, audioMasterGetSampleRate, 0, 0, nullptr, 0.0f));
  768. // some hosts are not ready at this point or return 0 buffersize/samplerate
  769. if (d_lastBufferSize == 0)
  770. d_lastBufferSize = 2048;
  771. if (d_lastSampleRate <= 0.0)
  772. d_lastSampleRate = 44100.0;
  773. const NativePluginDescriptor* pluginDesc = nullptr;
  774. PluginListManager& plm(PluginListManager::getInstance());
  775. #ifdef CARLA_VST_SHELL
  776. if (effect->uniqueID == 0)
  777. effect->uniqueID = kShellUniqueID;
  778. if (effect->uniqueID == kShellUniqueID)
  779. {
  780. // first open for discovery, nothing to do
  781. effect->numParams = 0;
  782. effect->numPrograms = 0;
  783. effect->numInputs = 0;
  784. effect->numOutputs = 0;
  785. return 1;
  786. }
  787. const int32_t plugIndex = effect->uniqueID - kShellUniqueID - 1;
  788. CARLA_SAFE_ASSERT_RETURN(plugIndex >= 0, 0);
  789. pluginDesc = plm.descs.getAt(static_cast<size_t>(plugIndex), nullptr);
  790. #else // CARLA_VST_SHELL
  791. # if defined(CARLA_PLUGIN_64CH)
  792. const char* const pluginLabel = "carlapatchbay64";
  793. # elif defined(CARLA_PLUGIN_32CH)
  794. const char* const pluginLabel = "carlapatchbay32";
  795. # elif defined(CARLA_PLUGIN_16CH)
  796. const char* const pluginLabel = "carlapatchbay16";
  797. # elif CARLA_PLUGIN_PATCHBAY
  798. const char* const pluginLabel = "carlapatchbay";
  799. # else
  800. const char* const pluginLabel = "carlarack";
  801. # endif
  802. for (LinkedList<const NativePluginDescriptor*>::Itenerator it = plm.descs.begin2(); it.valid(); it.next())
  803. {
  804. const NativePluginDescriptor* const& tmpDesc(it.getValue(nullptr));
  805. CARLA_SAFE_ASSERT_CONTINUE(tmpDesc != nullptr);
  806. if (std::strcmp(tmpDesc->label, pluginLabel) == 0)
  807. {
  808. pluginDesc = tmpDesc;
  809. break;
  810. }
  811. }
  812. #endif // CARLA_VST_SHELL
  813. CARLA_SAFE_ASSERT_RETURN(pluginDesc != nullptr, 0);
  814. #ifdef CARLA_VST_SHELL
  815. effect->numPrograms = 1;
  816. effect->numParams = static_cast<int>(pluginDesc->paramIns);
  817. effect->numInputs = static_cast<int>(pluginDesc->audioIns);
  818. effect->numOutputs = static_cast<int>(pluginDesc->audioOuts);
  819. if (pluginDesc->hints & NATIVE_PLUGIN_HAS_UI)
  820. effect->flags |= effFlagsHasEditor;
  821. else
  822. effect->flags &= ~effFlagsHasEditor;
  823. if (pluginDesc->hints & NATIVE_PLUGIN_IS_SYNTH)
  824. effect->flags |= effFlagsIsSynth;
  825. else
  826. effect->flags &= ~effFlagsIsSynth;
  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. std::strncpy(cptr, desc->name, 32);
  881. }
  882. else
  883. {
  884. std::strncpy(cptr, "Carla-VstShell", 32);
  885. }
  886. #elif defined(CARLA_PLUGIN_64CH)
  887. std::strncpy(cptr, "Carla-Patchbay64", 32);
  888. #elif defined(CARLA_PLUGIN_32CH)
  889. std::strncpy(cptr, "Carla-Patchbay32", 32);
  890. #elif defined(CARLA_PLUGIN_16CH)
  891. std::strncpy(cptr, "Carla-Patchbay16", 32);
  892. #elif CARLA_PLUGIN_PATCHBAY
  893. # if CARLA_PLUGIN_SYNTH
  894. std::strncpy(cptr, "Carla-Patchbay", 32);
  895. # else
  896. std::strncpy(cptr, "Carla-PatchbayFX", 32);
  897. # endif
  898. #else // Rack mode
  899. # if CARLA_PLUGIN_SYNTH
  900. std::strncpy(cptr, "Carla-Rack", 32);
  901. # else
  902. std::strncpy(cptr, "Carla-RackFX", 32);
  903. # endif
  904. #endif
  905. return 1;
  906. }
  907. return 0;
  908. case effGetVendorString:
  909. if (char* const cptr = (char*)ptr)
  910. {
  911. #ifdef CARLA_VST_SHELL
  912. if (validPlugin)
  913. {
  914. const NativePluginDescriptor* const desc = pluginPtr->getDescriptor();
  915. std::strncpy(cptr, desc->maker, 32);
  916. }
  917. else
  918. #endif
  919. std::strncpy(cptr, "falkTX", 32);
  920. return 1;
  921. }
  922. return 0;
  923. case effGetProductString:
  924. if (char* const cptr = (char*)ptr)
  925. {
  926. #if defined(CARLA_VST_SHELL)
  927. if (validPlugin)
  928. {
  929. const NativePluginDescriptor* const desc = pluginPtr->getDescriptor();
  930. std::strncpy(cptr, desc->label, 32);
  931. }
  932. else
  933. {
  934. std::strncpy(cptr, "CarlaVstShell", 32);
  935. }
  936. #elif defined(CARLA_PLUGIN_64CH)
  937. std::strncpy(cptr, "CarlaPatchbay64", 32);
  938. #elif defined(CARLA_PLUGIN_32CH)
  939. std::strncpy(cptr, "CarlaPatchbay32", 32);
  940. #elif defined(CARLA_PLUGIN_16CH)
  941. std::strncpy(cptr, "CarlaPatchbay16", 32);
  942. #elif CARLA_PLUGIN_PATCHBAY
  943. # if CARLA_PLUGIN_SYNTH
  944. std::strncpy(cptr, "CarlaPatchbay", 32);
  945. # else
  946. std::strncpy(cptr, "CarlaPatchbayFX", 32);
  947. # endif
  948. #else
  949. # if CARLA_PLUGIN_SYNTH
  950. std::strncpy(cptr, "CarlaRack", 32);
  951. # else
  952. std::strncpy(cptr, "CarlaRackFX", 32);
  953. # endif
  954. #endif
  955. return 1;
  956. }
  957. return 0;
  958. case effGetVendorVersion:
  959. return CARLA_VERSION_HEX;
  960. case effGetVstVersion:
  961. return kVstVersion;
  962. #ifdef CARLA_VST_SHELL
  963. case effShellGetNextPlugin:
  964. if (char* const cptr = (char*)ptr)
  965. {
  966. CARLA_SAFE_ASSERT_RETURN(effect != nullptr, 0);
  967. CARLA_SAFE_ASSERT_RETURN(effect->uniqueID >= kShellUniqueID, 0);
  968. PluginListManager& plm(PluginListManager::getInstance());
  969. for (;;)
  970. {
  971. const uint index2 = static_cast<uint>(effect->uniqueID - kShellUniqueID);
  972. if (index2 >= plm.descs.count())
  973. {
  974. effect->uniqueID = kShellUniqueID;
  975. return 0;
  976. }
  977. const NativePluginDescriptor* const desc = plm.descs.getAt(index2, nullptr);
  978. CARLA_SAFE_ASSERT_RETURN(desc != nullptr, 0);
  979. ++effect->uniqueID;
  980. if (desc->midiIns > 1 || desc->midiOuts > 1)
  981. continue;
  982. std::strncpy(cptr, desc->label, 32);
  983. return effect->uniqueID;
  984. }
  985. }
  986. #endif
  987. };
  988. // handle advanced opcodes
  989. if (validPlugin)
  990. return pluginPtr->vst_dispatcher(opcode, index, value, ptr, opt);
  991. return 0;
  992. }
  993. float vst_getParameterCallback(AEffect* effect, int32_t index)
  994. {
  995. if (validPlugin)
  996. return pluginPtr->vst_getParameter(index);
  997. return 0.0f;
  998. }
  999. void vst_setParameterCallback(AEffect* effect, int32_t index, float value)
  1000. {
  1001. if (validPlugin)
  1002. pluginPtr->vst_setParameter(index, value);
  1003. }
  1004. void vst_processCallback(AEffect* effect, float** inputs, float** outputs, int32_t sampleFrames)
  1005. {
  1006. if (validPlugin)
  1007. pluginPtr->vst_processReplacing(const_cast<const float**>(inputs), outputs, sampleFrames);
  1008. }
  1009. void vst_processReplacingCallback(AEffect* effect, float** inputs, float** outputs, int32_t sampleFrames)
  1010. {
  1011. if (validPlugin)
  1012. pluginPtr->vst_processReplacing(const_cast<const float**>(inputs), outputs, sampleFrames);
  1013. }
  1014. #undef pluginPtr
  1015. #undef validObject
  1016. #undef validPlugin
  1017. #undef vstObjectPtr
  1018. // -----------------------------------------------------------------------
  1019. const AEffect* VSTPluginMainInit(AEffect* const effect)
  1020. {
  1021. #if defined(CARLA_VST_SHELL)
  1022. if (const intptr_t uniqueID = VSTAudioMaster(effect, audioMasterCurrentId, 0, 0, nullptr, 0.0f))
  1023. effect->uniqueID = static_cast<int>(uniqueID);
  1024. else
  1025. effect->uniqueID = kShellUniqueID;
  1026. #elif defined(CARLA_PLUGIN_64CH)
  1027. effect->uniqueID = kBaseUniqueID+7;
  1028. #elif defined(CARLA_PLUGIN_32CH)
  1029. effect->uniqueID = kBaseUniqueID+6;
  1030. #elif defined(CARLA_PLUGIN_16CH)
  1031. effect->uniqueID = kBaseUniqueID+5;
  1032. #elif CARLA_PLUGIN_PATCHBAY
  1033. # if CARLA_PLUGIN_SYNTH
  1034. effect->uniqueID = kBaseUniqueID+4;
  1035. # else
  1036. effect->uniqueID = kBaseUniqueID+3;
  1037. # endif
  1038. #else
  1039. # if CARLA_PLUGIN_SYNTH
  1040. effect->uniqueID = kBaseUniqueID+2;
  1041. # else
  1042. effect->uniqueID = kBaseUniqueID+1;
  1043. # endif
  1044. #endif
  1045. // plugin fields
  1046. #ifndef CARLA_VST_SHELL
  1047. effect->numParams = kNumParameters;
  1048. effect->numPrograms = 1;
  1049. # if defined(CARLA_PLUGIN_64CH)
  1050. effect->numInputs = 64;
  1051. effect->numOutputs = 64;
  1052. # elif defined(CARLA_PLUGIN_32CH)
  1053. effect->numInputs = 32;
  1054. effect->numOutputs = 32;
  1055. # elif defined(CARLA_PLUGIN_16CH)
  1056. effect->numInputs = 16;
  1057. effect->numOutputs = 16;
  1058. # else
  1059. effect->numInputs = 2;
  1060. effect->numOutputs = 2;
  1061. # endif
  1062. #endif
  1063. // plugin flags
  1064. effect->flags |= effFlagsCanReplacing;
  1065. effect->flags |= effFlagsProgramChunks;
  1066. #ifndef CARLA_VST_SHELL
  1067. effect->flags |= effFlagsHasEditor;
  1068. #endif
  1069. #if CARLA_PLUGIN_SYNTH
  1070. effect->flags |= effFlagsIsSynth;
  1071. #endif
  1072. return effect;
  1073. }
  1074. // -----------------------------------------------------------------------