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.

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