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.

1803 lines
49KB

  1. /*
  2. * Carla Native Plugins
  3. * Copyright (C) 2012-2013 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 GPL.txt file
  16. */
  17. // for UINT32_MAX
  18. #define __STDC_LIMIT_MACROS
  19. #include <cstdint>
  20. #include "CarlaNative.hpp"
  21. #include "CarlaMIDI.h"
  22. #include "CarlaString.hpp"
  23. #include "RtList.hpp"
  24. #include <QtCore/QThread>
  25. #include "zynaddsubfx/Misc/Master.h"
  26. #include "zynaddsubfx/Misc/Part.h"
  27. #include "zynaddsubfx/Misc/Util.h"
  28. #include "zynaddsubfx/Effects/Alienwah.h"
  29. #include "zynaddsubfx/Effects/Chorus.h"
  30. #include "zynaddsubfx/Effects/Distorsion.h"
  31. #include "zynaddsubfx/Effects/DynamicFilter.h"
  32. #include "zynaddsubfx/Effects/Echo.h"
  33. #include "zynaddsubfx/Effects/EQ.h"
  34. #include "zynaddsubfx/Effects/Phaser.h"
  35. #include "zynaddsubfx/Effects/Reverb.h"
  36. #ifdef WANT_ZYNADDSUBFX_UI
  37. # ifdef override
  38. # define override_hack
  39. # undef override
  40. # endif
  41. # include "zynaddsubfx/UI/common.H"
  42. # include "zynaddsubfx/UI/MasterUI.h"
  43. # include <FL/Fl_Shared_Image.H>
  44. # include <FL/Fl_Tiled_Image.H>
  45. # include <FL/Fl_Theme.H>
  46. # ifdef override_hack
  47. # define override
  48. # undef override_hack
  49. # endif
  50. #endif
  51. #include <ctime>
  52. #include <set>
  53. #include <string>
  54. // Dummy variables and functions for linking purposes
  55. const char* instance_name = nullptr;
  56. class WavFile;
  57. namespace Nio {
  58. bool start(void){return 1;}
  59. void stop(void){}
  60. bool setSource(std::string){return true;}
  61. bool setSink(std::string){return true;}
  62. std::set<std::string> getSources(void){return std::set<std::string>();}
  63. std::set<std::string> getSinks(void){return std::set<std::string>();}
  64. std::string getSource(void){return "";}
  65. std::string getSink(void){return "";}
  66. void waveNew(WavFile*){}
  67. void waveStart(void){}
  68. void waveStop(void){}
  69. void waveEnd(void){}
  70. }
  71. SYNTH_T* synth = nullptr;
  72. #ifdef WANT_ZYNADDSUBFX_UI
  73. #define PIXMAP_PATH "/resources/zynaddsubfx/"
  74. static Fl_Tiled_Image* gModuleBackdrop = nullptr;
  75. static CarlaString gPixmapPath;
  76. extern CarlaString gUiPixmapPath;
  77. void set_module_parameters(Fl_Widget* o)
  78. {
  79. CARLA_ASSERT(gModuleBackdrop != nullptr);
  80. o->box(FL_DOWN_FRAME);
  81. o->align(o->align() | FL_ALIGN_IMAGE_BACKDROP);
  82. o->color(FL_BLACK);
  83. o->labeltype(FL_SHADOW_LABEL);
  84. if (gModuleBackdrop != nullptr)
  85. o->image(gModuleBackdrop);
  86. }
  87. #endif
  88. // -----------------------------------------------------------------------
  89. class ZynAddSubFxPrograms
  90. {
  91. public:
  92. ZynAddSubFxPrograms()
  93. : fInitiated(false)
  94. {
  95. }
  96. ~ZynAddSubFxPrograms()
  97. {
  98. if (! fInitiated)
  99. return;
  100. for (auto it = fPrograms.begin(); it.valid(); it.next())
  101. {
  102. const ProgramInfo*& pInfo(*it);
  103. delete pInfo;
  104. }
  105. fPrograms.clear();
  106. }
  107. void init()
  108. {
  109. if (fInitiated)
  110. return;
  111. fInitiated = true;
  112. fPrograms.append(new ProgramInfo(0, 0, "default"));
  113. Master& master(Master::getInstance());
  114. pthread_mutex_lock(&master.mutex);
  115. // refresh banks
  116. master.bank.rescanforbanks();
  117. for (uint32_t i=0, size = master.bank.banks.size(); i < size; ++i)
  118. {
  119. if (master.bank.banks[i].dir.empty())
  120. continue;
  121. master.bank.loadbank(master.bank.banks[i].dir);
  122. for (unsigned int instrument = 0; instrument < BANK_SIZE; ++instrument)
  123. {
  124. const std::string insName(master.bank.getname(instrument));
  125. if (insName.empty() || insName[0] == '\0' || insName[0] == ' ')
  126. continue;
  127. fPrograms.append(new ProgramInfo(i+1, instrument, insName.c_str()));
  128. }
  129. }
  130. pthread_mutex_unlock(&master.mutex);
  131. }
  132. void load(Master* const master, const uint8_t channel, const uint32_t bank, const uint32_t program)
  133. {
  134. if (bank == 0)
  135. {
  136. pthread_mutex_lock(&master->mutex);
  137. master->partonoff(channel, 1);
  138. master->part[channel]->defaults();
  139. master->part[channel]->applyparameters(false);
  140. pthread_mutex_unlock(&master->mutex);
  141. return;
  142. }
  143. const std::string& bankdir(master->bank.banks[bank-1].dir);
  144. if (! bankdir.empty())
  145. {
  146. pthread_mutex_lock(&master->mutex);
  147. master->partonoff(channel, 1);
  148. master->bank.loadbank(bankdir);
  149. master->bank.loadfromslot(program, master->part[channel]);
  150. master->part[channel]->applyparameters(false);
  151. pthread_mutex_unlock(&master->mutex);
  152. }
  153. }
  154. uint32_t count()
  155. {
  156. return fPrograms.count();
  157. }
  158. const MidiProgram* getInfo(const uint32_t index)
  159. {
  160. if (index >= fPrograms.count())
  161. return nullptr;
  162. const ProgramInfo*& pInfo(fPrograms.getAt(index));
  163. fRetProgram.bank = pInfo->bank;
  164. fRetProgram.program = pInfo->prog;
  165. fRetProgram.name = pInfo->name;
  166. return &fRetProgram;
  167. }
  168. private:
  169. struct ProgramInfo {
  170. uint32_t bank;
  171. uint32_t prog;
  172. const char* name;
  173. ProgramInfo(uint32_t bank_, uint32_t prog_, const char* name_)
  174. : bank(bank_),
  175. prog(prog_),
  176. name(carla_strdup(name_)) {}
  177. ~ProgramInfo()
  178. {
  179. if (name != nullptr)
  180. {
  181. delete[] name;
  182. name = nullptr;
  183. }
  184. }
  185. #ifdef CARLA_PROPER_CPP11_SUPPORT
  186. ProgramInfo() = delete;
  187. ProgramInfo(ProgramInfo&) = delete;
  188. ProgramInfo(const ProgramInfo&) = delete;
  189. #endif
  190. };
  191. bool fInitiated;
  192. MidiProgram fRetProgram;
  193. NonRtList<const ProgramInfo*> fPrograms;
  194. CARLA_DECLARE_NON_COPYABLE(ZynAddSubFxPrograms)
  195. };
  196. static ZynAddSubFxPrograms sPrograms;
  197. // -----------------------------------------------------------------------
  198. class ZynAddSubFxInstanceCount
  199. {
  200. public:
  201. ZynAddSubFxInstanceCount()
  202. : fCount(0)
  203. {
  204. }
  205. ~ZynAddSubFxInstanceCount()
  206. {
  207. CARLA_ASSERT(fCount == 0);
  208. }
  209. void addOne(const HostDescriptor* const host)
  210. {
  211. if (fCount++ == 0)
  212. {
  213. CARLA_ASSERT(synth == nullptr);
  214. CARLA_ASSERT(denormalkillbuf == nullptr);
  215. reinit(host);
  216. #ifdef WANT_ZYNADDSUBFX_UI
  217. if (gPixmapPath.isEmpty())
  218. {
  219. gPixmapPath = host->resource_dir;
  220. gPixmapPath += PIXMAP_PATH;
  221. gUiPixmapPath = gPixmapPath;
  222. }
  223. #endif
  224. }
  225. }
  226. void removeOne()
  227. {
  228. if (--fCount == 0)
  229. {
  230. CARLA_ASSERT(synth != nullptr);
  231. CARLA_ASSERT(denormalkillbuf != nullptr);
  232. Master::deleteInstance();
  233. delete[] denormalkillbuf;
  234. denormalkillbuf = nullptr;
  235. delete synth;
  236. synth = nullptr;
  237. }
  238. }
  239. void reinit(const HostDescriptor* const host)
  240. {
  241. Master::deleteInstance();
  242. if (denormalkillbuf != nullptr)
  243. {
  244. delete[] denormalkillbuf;
  245. denormalkillbuf = nullptr;
  246. }
  247. if (synth != nullptr)
  248. {
  249. delete synth;
  250. synth = nullptr;
  251. }
  252. synth = new SYNTH_T();
  253. synth->buffersize = host->get_buffer_size(host->handle);
  254. synth->samplerate = host->get_sample_rate(host->handle);
  255. synth->alias();
  256. config.init();
  257. config.cfg.SoundBufferSize = synth->buffersize;
  258. config.cfg.SampleRate = synth->samplerate;
  259. config.cfg.GzipCompression = 0;
  260. sprng(std::time(nullptr));
  261. denormalkillbuf = new float[synth->buffersize];
  262. for (int i=0; i < synth->buffersize; ++i)
  263. denormalkillbuf[i] = (RND - 0.5f) * 1e-16;
  264. Master::getInstance();
  265. }
  266. void maybeReinit(const HostDescriptor* const host)
  267. {
  268. if (host->get_buffer_size(host->handle) == static_cast<uint32_t>(synth->buffersize) &&
  269. host->get_sample_rate(host->handle) == static_cast<double>(synth->samplerate))
  270. return;
  271. reinit(host);
  272. }
  273. private:
  274. int fCount;
  275. CARLA_DECLARE_NON_COPYABLE(ZynAddSubFxInstanceCount)
  276. };
  277. static ZynAddSubFxInstanceCount sInstanceCount;
  278. // -----------------------------------------------------------------------
  279. class ZynAddSubFxThread : public QThread
  280. {
  281. public:
  282. ZynAddSubFxThread(Master* const master, const HostDescriptor* const host)
  283. : fMaster(master),
  284. kHost(host),
  285. #ifdef WANT_ZYNADDSUBFX_UI
  286. fUi(nullptr),
  287. fUiClosed(0),
  288. fNextUiAction(-1),
  289. #endif
  290. fQuit(false),
  291. fChangeProgram(false),
  292. fNextChannel(0),
  293. fNextBank(0),
  294. fNextProgram(0)
  295. {
  296. }
  297. ~ZynAddSubFxThread()
  298. {
  299. // must be closed by now
  300. #ifdef WANT_ZYNADDSUBFX_UI
  301. CARLA_ASSERT(fUi == nullptr);
  302. #endif
  303. CARLA_ASSERT(fQuit);
  304. }
  305. void loadProgramLater(const uint8_t channel, const uint32_t bank, const uint32_t program)
  306. {
  307. fNextChannel = channel;
  308. fNextBank = bank;
  309. fNextProgram = program;
  310. fChangeProgram = true;
  311. }
  312. void stopLoadProgramLater()
  313. {
  314. fChangeProgram = false;
  315. fNextChannel = 0;
  316. fNextBank = 0;
  317. fNextProgram = 0;
  318. }
  319. void setMaster(Master* const master)
  320. {
  321. fMaster = master;
  322. }
  323. void stop()
  324. {
  325. fQuit = true;
  326. quit();
  327. }
  328. #ifdef WANT_ZYNADDSUBFX_UI
  329. void uiHide()
  330. {
  331. fNextUiAction = 0;
  332. }
  333. void uiShow()
  334. {
  335. fNextUiAction = 1;
  336. }
  337. void uiRepaint()
  338. {
  339. if (fUi != nullptr)
  340. fNextUiAction = 2;
  341. }
  342. #endif
  343. protected:
  344. void run() override
  345. {
  346. while (! fQuit)
  347. {
  348. #ifdef WANT_ZYNADDSUBFX_UI
  349. Fl::lock();
  350. if (fNextUiAction == 2) // repaint
  351. {
  352. CARLA_ASSERT(fUi != nullptr);
  353. if (fUi != nullptr)
  354. fUi->refresh_master_ui();
  355. }
  356. else if (fNextUiAction == 1) // init/show
  357. {
  358. static bool initialized = false;
  359. if (! initialized)
  360. {
  361. initialized = true;
  362. fl_register_images();
  363. Fl_Dial::default_style(Fl_Dial::PIXMAP_DIAL);
  364. if (Fl_Shared_Image* const img = Fl_Shared_Image::get(gPixmapPath + "knob.png"))
  365. Fl_Dial::default_image(img);
  366. if (Fl_Shared_Image* const img = Fl_Shared_Image::get(gPixmapPath + "window_backdrop.png"))
  367. Fl::scheme_bg(new Fl_Tiled_Image(img));
  368. if(Fl_Shared_Image* const img = Fl_Shared_Image::get(gPixmapPath + "module_backdrop.png"))
  369. gModuleBackdrop = new Fl_Tiled_Image(img);
  370. Fl::background(50, 50, 50);
  371. Fl::background2(70, 70, 70);
  372. Fl::foreground(255, 255, 255);
  373. Fl_Theme::set("Cairo");
  374. }
  375. CARLA_ASSERT(fUi == nullptr);
  376. if (fUi == nullptr)
  377. {
  378. fUiClosed = 0;
  379. fUi = new MasterUI(fMaster, &fUiClosed);
  380. fUi->showUI();
  381. }
  382. }
  383. else if (fNextUiAction == 0) // close
  384. {
  385. CARLA_ASSERT(fUi != nullptr);
  386. if (fUi != nullptr)
  387. {
  388. delete fUi;
  389. fUi = nullptr;
  390. }
  391. }
  392. fNextUiAction = -1;
  393. if (fUiClosed != 0)
  394. {
  395. fUiClosed = 0;
  396. fNextUiAction = 0;
  397. kHost->ui_closed(kHost->handle);
  398. }
  399. Fl::check();
  400. Fl::unlock();
  401. #endif
  402. if (fChangeProgram)
  403. {
  404. fChangeProgram = false;
  405. sPrograms.load(fMaster, fNextChannel, fNextBank, fNextProgram);
  406. fNextChannel = 0;
  407. fNextBank = 0;
  408. fNextProgram = 0;
  409. #ifdef WANT_ZYNADDSUBFX_UI
  410. if (fUi != nullptr)
  411. {
  412. Fl::lock();
  413. fUi->refresh_master_ui();
  414. Fl::unlock();
  415. }
  416. #endif
  417. carla_msleep(15);
  418. }
  419. else
  420. {
  421. carla_msleep(30);
  422. }
  423. }
  424. #ifdef WANT_ZYNADDSUBFX_UI
  425. if (fQuit && fUi != nullptr)
  426. {
  427. Fl::lock();
  428. delete fUi;
  429. fUi = nullptr;
  430. Fl::check();
  431. Fl::unlock();
  432. }
  433. #endif
  434. }
  435. private:
  436. Master* fMaster;
  437. const HostDescriptor* const kHost;
  438. #ifdef WANT_ZYNADDSUBFX_UI
  439. MasterUI* fUi;
  440. int fUiClosed;
  441. int fNextUiAction;
  442. #endif
  443. bool fQuit;
  444. bool fChangeProgram;
  445. uint8_t fNextChannel;
  446. uint32_t fNextBank;
  447. uint32_t fNextProgram;
  448. };
  449. // -----------------------------------------------------------------------
  450. #define ZynPluginDescriptorClassEND(ClassName) \
  451. public: \
  452. static PluginHandle _instantiate(const PluginDescriptor*, HostDescriptor* host) \
  453. { \
  454. sInstanceCount.addOne(host); \
  455. return new ClassName(host); \
  456. } \
  457. static void _cleanup(PluginHandle handle) \
  458. { \
  459. delete (ClassName*)handle; \
  460. sInstanceCount.removeOne(); \
  461. }
  462. // -----------------------------------------------------------------------
  463. class FxAbstractPlugin : public PluginDescriptorClass
  464. {
  465. protected:
  466. FxAbstractPlugin(const HostDescriptor* const host, const uint32_t paramCount, const uint32_t programCount)
  467. : PluginDescriptorClass(host),
  468. fEffect(nullptr),
  469. efxoutl(new float[synth->buffersize]),
  470. efxoutr(new float[synth->buffersize]),
  471. fFirstInit(true),
  472. kParamCount(paramCount-2), // volume and pan handled by host
  473. kProgramCount(programCount)
  474. {
  475. carla_zeroFloat(efxoutl, synth->buffersize);
  476. carla_zeroFloat(efxoutr, synth->buffersize);
  477. }
  478. ~FxAbstractPlugin() override
  479. {
  480. CARLA_ASSERT(fEffect != nullptr);
  481. if (efxoutl != nullptr)
  482. {
  483. delete[] efxoutl;
  484. efxoutl = nullptr;
  485. }
  486. if (efxoutr != nullptr)
  487. {
  488. delete[] efxoutr;
  489. efxoutr = nullptr;
  490. }
  491. if (fEffect != nullptr)
  492. {
  493. delete fEffect;
  494. fEffect = nullptr;
  495. }
  496. }
  497. // -------------------------------------------------------------------
  498. // Plugin parameter calls
  499. uint32_t getParameterCount() final
  500. {
  501. return kParamCount;
  502. }
  503. float getParameterValue(const uint32_t index) final
  504. {
  505. return fEffect->getpar(index+2);
  506. }
  507. // -------------------------------------------------------------------
  508. // Plugin midi-program calls
  509. uint32_t getMidiProgramCount() final
  510. {
  511. return kProgramCount;
  512. }
  513. // -------------------------------------------------------------------
  514. // Plugin state calls
  515. void setParameterValue(const uint32_t index, const float value) final
  516. {
  517. fEffect->changepar(index+2, value);
  518. fFirstInit = false;
  519. }
  520. void setMidiProgram(const uint8_t, const uint32_t, const uint32_t program) final
  521. {
  522. fEffect->setpreset(program);
  523. //fFirstInit = false;
  524. const float volume(float(fEffect->getpar(0))/127.0f);
  525. hostDispatcher(HOST_OPCODE_SET_VOLUME, 0, 0, nullptr, volume);
  526. const unsigned char pan(fEffect->getpar(1));
  527. const float panning(float(pan)/63.5f-1.0f);
  528. hostDispatcher(HOST_OPCODE_SET_PANNING, 0, 0, nullptr, (pan == 64) ? 0.0f : panning);
  529. }
  530. // -------------------------------------------------------------------
  531. // Plugin process calls
  532. void activate() final
  533. {
  534. fEffect->cleanup();
  535. if (fFirstInit)
  536. {
  537. fFirstInit = false;
  538. hostDispatcher(HOST_OPCODE_SET_DRYWET, 0, 0, nullptr, 0.5f);
  539. }
  540. }
  541. void process(float** const inBuffer, float** const outBuffer, const uint32_t frames, const uint32_t, const MidiEvent* const) final
  542. {
  543. CARLA_ASSERT(synth->buffersize == static_cast<int>(frames));
  544. fEffect->out(Stereo<float*>(inBuffer[0], inBuffer[1]));
  545. carla_copyFloat(outBuffer[0], efxoutl, frames);
  546. carla_copyFloat(outBuffer[1], efxoutr, frames);
  547. }
  548. // -------------------------------------------------------------------
  549. // Plugin dispatcher
  550. intptr_t pluginDispatcher(const PluginDispatcherOpcode opcode, const int32_t, const intptr_t, void* const, const float) final
  551. {
  552. switch (opcode)
  553. {
  554. case PLUGIN_OPCODE_BUFFER_SIZE_CHANGED:
  555. {
  556. const uint32_t bufferSize(getBufferSize());
  557. delete[] efxoutl;
  558. delete[] efxoutr;
  559. efxoutl = new float[bufferSize];
  560. efxoutr = new float[bufferSize];
  561. *((float**)&fEffect->efxoutl) = efxoutl;
  562. *((float**)&fEffect->efxoutr) = efxoutr;
  563. // no break
  564. }
  565. case PLUGIN_OPCODE_SAMPLE_RATE_CHANGED:
  566. sInstanceCount.maybeReinit(hostHandle());
  567. break;
  568. default:
  569. break;
  570. }
  571. return 0;
  572. }
  573. Effect* fEffect;
  574. float* efxoutl;
  575. float* efxoutr;
  576. bool fFirstInit;
  577. const uint32_t kParamCount;
  578. const uint32_t kProgramCount;
  579. };
  580. // -----------------------------------------------------------------------
  581. class FxAlienWahPlugin : public FxAbstractPlugin
  582. {
  583. public:
  584. FxAlienWahPlugin(const HostDescriptor* const host)
  585. : FxAbstractPlugin(host, 11, 4)
  586. {
  587. fEffect = new Alienwah(false, efxoutl, efxoutr);
  588. }
  589. protected:
  590. // -------------------------------------------------------------------
  591. // Plugin parameter calls
  592. const Parameter* getParameterInfo(const uint32_t index) override
  593. {
  594. if (index >= kParamCount)
  595. return nullptr;
  596. static Parameter param;
  597. static ParameterScalePoint scalePoints[2];
  598. int hints = PARAMETER_IS_ENABLED|PARAMETER_IS_INTEGER;
  599. param.name = nullptr;
  600. param.unit = nullptr;
  601. param.ranges.def = 1.0f;
  602. param.ranges.min = 0.0f;
  603. param.ranges.max = 127.0f;
  604. param.ranges.step = 1.0f;
  605. param.ranges.stepSmall = 1.0f;
  606. param.ranges.stepLarge = 20.0f;
  607. param.scalePointCount = 0;
  608. param.scalePoints = nullptr;
  609. switch (index)
  610. {
  611. case 0:
  612. hints |= PARAMETER_IS_AUTOMABLE;
  613. param.name = "LFO Frequency";
  614. param.ranges.def = 70.0f;
  615. break;
  616. case 1:
  617. hints |= PARAMETER_IS_AUTOMABLE;
  618. param.name = "LFO Randomness";
  619. param.ranges.def = 0.0f;
  620. break;
  621. case 2:
  622. hints |= PARAMETER_IS_AUTOMABLE|PARAMETER_IS_BOOLEAN|PARAMETER_USES_SCALEPOINTS;
  623. param.name = "LFO Type";
  624. param.ranges.def = 0.0f;
  625. param.ranges.max = 1.0f;
  626. param.scalePointCount = 2;
  627. param.scalePoints = scalePoints;
  628. scalePoints[0].label = "Sine";
  629. scalePoints[1].label = "Triangle";
  630. scalePoints[0].value = 0.0f;
  631. scalePoints[1].value = 1.0f;
  632. break;
  633. case 3:
  634. hints |= PARAMETER_IS_AUTOMABLE;
  635. param.name = "LFO Stereo";
  636. param.ranges.def = 62.0f;
  637. break;
  638. case 4:
  639. hints |= PARAMETER_IS_AUTOMABLE;
  640. param.name = "Depth";
  641. param.ranges.def = 60.0f;
  642. break;
  643. case 5:
  644. hints |= PARAMETER_IS_AUTOMABLE;
  645. param.name = "Feedback";
  646. param.ranges.def = 105.0f;
  647. break;
  648. case 6:
  649. param.name = "Delay";
  650. param.ranges.def = 25.0f;
  651. param.ranges.max = 100.0f;
  652. break;
  653. case 7:
  654. hints |= PARAMETER_IS_AUTOMABLE;
  655. param.name = "L/R Cross";
  656. param.ranges.def = 0.0f;
  657. break;
  658. case 8:
  659. hints |= PARAMETER_IS_AUTOMABLE;
  660. param.name = "Phase";
  661. param.ranges.def = 64.0f;
  662. break;
  663. }
  664. param.hints = static_cast<ParameterHints>(hints);
  665. return &param;
  666. }
  667. // -------------------------------------------------------------------
  668. // Plugin midi-program calls
  669. const MidiProgram* getMidiProgramInfo(const uint32_t index) override
  670. {
  671. if (index >= kProgramCount)
  672. return nullptr;
  673. static MidiProgram midiProg;
  674. midiProg.bank = 0;
  675. midiProg.program = index;
  676. switch (index)
  677. {
  678. case 0:
  679. midiProg.name = "AlienWah1";
  680. break;
  681. case 1:
  682. midiProg.name = "AlienWah2";
  683. break;
  684. case 2:
  685. midiProg.name = "AlienWah3";
  686. break;
  687. case 3:
  688. midiProg.name = "AlienWah4";
  689. break;
  690. default:
  691. midiProg.name = nullptr;
  692. break;
  693. }
  694. return &midiProg;
  695. }
  696. ZynPluginDescriptorClassEND(FxAlienWahPlugin)
  697. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(FxAlienWahPlugin)
  698. };
  699. // -----------------------------------------------------------------------
  700. class FxChorusPlugin : public FxAbstractPlugin
  701. {
  702. public:
  703. FxChorusPlugin(const HostDescriptor* const host)
  704. : FxAbstractPlugin(host, 12, 10)
  705. {
  706. fEffect = new Chorus(false, efxoutl, efxoutr);
  707. }
  708. protected:
  709. // -------------------------------------------------------------------
  710. // Plugin parameter calls
  711. const Parameter* getParameterInfo(const uint32_t index) override
  712. {
  713. if (index >= kParamCount)
  714. return nullptr;
  715. static Parameter param;
  716. static ParameterScalePoint scalePoints[2];
  717. int hints = PARAMETER_IS_ENABLED|PARAMETER_IS_INTEGER;
  718. param.name = nullptr;
  719. param.unit = nullptr;
  720. param.ranges.def = 1.0f;
  721. param.ranges.min = 0.0f;
  722. param.ranges.max = 127.0f;
  723. param.ranges.step = 1.0f;
  724. param.ranges.stepSmall = 1.0f;
  725. param.ranges.stepLarge = 20.0f;
  726. param.scalePointCount = 0;
  727. param.scalePoints = nullptr;
  728. switch (index)
  729. {
  730. case 0:
  731. hints |= PARAMETER_IS_AUTOMABLE;
  732. param.name = "LFO Frequency";
  733. param.ranges.def = 50.0f;
  734. break;
  735. case 1:
  736. hints |= PARAMETER_IS_AUTOMABLE;
  737. param.name = "LFO Randomness";
  738. param.ranges.def = 0.0f;
  739. break;
  740. case 2:
  741. hints |= PARAMETER_IS_AUTOMABLE|PARAMETER_IS_BOOLEAN|PARAMETER_USES_SCALEPOINTS;
  742. param.name = "LFO Type";
  743. param.ranges.def = 0.0f;
  744. param.ranges.max = 1.0f;
  745. param.scalePointCount = 2;
  746. param.scalePoints = scalePoints;
  747. scalePoints[0].label = "Sine";
  748. scalePoints[1].label = "Triangle";
  749. scalePoints[0].value = 0.0f;
  750. scalePoints[1].value = 1.0f;
  751. break;
  752. case 3:
  753. hints |= PARAMETER_IS_AUTOMABLE;
  754. param.name = "LFO Stereo";
  755. param.ranges.def = 90.0f;
  756. break;
  757. case 4:
  758. hints |= PARAMETER_IS_AUTOMABLE;
  759. param.name = "Depth";
  760. param.ranges.def = 40.0f;
  761. break;
  762. case 5:
  763. hints |= PARAMETER_IS_AUTOMABLE;
  764. param.name = "Delay";
  765. param.ranges.def = 85.0f;
  766. break;
  767. case 6:
  768. hints |= PARAMETER_IS_AUTOMABLE;
  769. param.name = "Feedback";
  770. param.ranges.def = 64.0f;
  771. break;
  772. case 7:
  773. hints |= PARAMETER_IS_AUTOMABLE;
  774. param.name = "L/R Cross";
  775. param.ranges.def = 119.0f;
  776. break;
  777. case 8:
  778. hints |= PARAMETER_IS_AUTOMABLE|PARAMETER_IS_BOOLEAN;
  779. param.name = "Flange Mode";
  780. param.ranges.def = 0.0f;
  781. param.ranges.max = 1.0f;
  782. break;
  783. case 9:
  784. hints |= PARAMETER_IS_AUTOMABLE|PARAMETER_IS_BOOLEAN;
  785. param.name = "Subtract Output";
  786. param.ranges.def = 0.0f;
  787. param.ranges.max = 1.0f;
  788. break;
  789. }
  790. param.hints = static_cast<ParameterHints>(hints);
  791. return &param;
  792. }
  793. // -------------------------------------------------------------------
  794. // Plugin midi-program calls
  795. const MidiProgram* getMidiProgramInfo(const uint32_t index) override
  796. {
  797. if (index >= kProgramCount)
  798. return nullptr;
  799. static MidiProgram midiProg;
  800. midiProg.bank = 0;
  801. midiProg.program = index;
  802. switch (index)
  803. {
  804. case 0:
  805. midiProg.name = "Chorus1";
  806. break;
  807. case 1:
  808. midiProg.name = "Chorus2";
  809. break;
  810. case 2:
  811. midiProg.name = "Chorus3";
  812. break;
  813. case 3:
  814. midiProg.name = "Celeste1";
  815. break;
  816. case 4:
  817. midiProg.name = "Celeste2";
  818. break;
  819. case 5:
  820. midiProg.name = "Flange1";
  821. break;
  822. case 6:
  823. midiProg.name = "Flange2";
  824. break;
  825. case 7:
  826. midiProg.name = "Flange3";
  827. break;
  828. case 8:
  829. midiProg.name = "Flange4";
  830. break;
  831. case 9:
  832. midiProg.name = "Flange5";
  833. break;
  834. default:
  835. midiProg.name = nullptr;
  836. break;
  837. }
  838. return &midiProg;
  839. }
  840. ZynPluginDescriptorClassEND(FxChorusPlugin)
  841. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(FxChorusPlugin)
  842. };
  843. // -----------------------------------------------------------------------
  844. class FxDistortionPlugin : public FxAbstractPlugin
  845. {
  846. public:
  847. FxDistortionPlugin(const HostDescriptor* const host)
  848. : FxAbstractPlugin(host, 11, 6)
  849. {
  850. fEffect = new Distorsion(false, efxoutl, efxoutr);
  851. }
  852. protected:
  853. // -------------------------------------------------------------------
  854. // Plugin parameter calls
  855. const Parameter* getParameterInfo(const uint32_t index) override
  856. {
  857. if (index >= kParamCount)
  858. return nullptr;
  859. static Parameter param;
  860. static ParameterScalePoint scalePoints[14];
  861. int hints = PARAMETER_IS_ENABLED|PARAMETER_IS_INTEGER;
  862. param.name = nullptr;
  863. param.unit = nullptr;
  864. param.ranges.def = 1.0f;
  865. param.ranges.min = 0.0f;
  866. param.ranges.max = 127.0f;
  867. param.ranges.step = 1.0f;
  868. param.ranges.stepSmall = 1.0f;
  869. param.ranges.stepLarge = 20.0f;
  870. param.scalePointCount = 0;
  871. param.scalePoints = nullptr;
  872. switch (index)
  873. {
  874. case 0:
  875. hints |= PARAMETER_IS_AUTOMABLE;
  876. param.name = "L/R Cross";
  877. param.ranges.def = 35.0f;
  878. break;
  879. case 1:
  880. hints |= PARAMETER_IS_AUTOMABLE;
  881. param.name = "Drive";
  882. param.ranges.def = 56.0f;
  883. break;
  884. case 2:
  885. hints |= PARAMETER_IS_AUTOMABLE;
  886. param.name = "Level";
  887. param.ranges.def = 70.0f;
  888. break;
  889. case 3:
  890. hints |= PARAMETER_IS_AUTOMABLE|PARAMETER_USES_SCALEPOINTS;
  891. param.name = "Type";
  892. param.ranges.def = 0.0f;
  893. param.ranges.max = 13.0f;
  894. param.scalePointCount = 14;
  895. param.scalePoints = scalePoints;
  896. scalePoints[ 0].label = "Arctangent";
  897. scalePoints[ 1].label = "Asymmetric";
  898. scalePoints[ 2].label = "Pow";
  899. scalePoints[ 3].label = "Sine";
  900. scalePoints[ 4].label = "Quantisize";
  901. scalePoints[ 5].label = "Zigzag";
  902. scalePoints[ 6].label = "Limiter";
  903. scalePoints[ 7].label = "Upper Limiter";
  904. scalePoints[ 8].label = "Lower Limiter";
  905. scalePoints[ 9].label = "Inverse Limiter";
  906. scalePoints[10].label = "Clip";
  907. scalePoints[11].label = "Asym2";
  908. scalePoints[12].label = "Pow2";
  909. scalePoints[13].label = "sigmoid";
  910. scalePoints[ 0].value = 0.0f;
  911. scalePoints[ 1].value = 1.0f;
  912. scalePoints[ 2].value = 2.0f;
  913. scalePoints[ 3].value = 3.0f;
  914. scalePoints[ 4].value = 4.0f;
  915. scalePoints[ 5].value = 5.0f;
  916. scalePoints[ 6].value = 6.0f;
  917. scalePoints[ 7].value = 7.0f;
  918. scalePoints[ 8].value = 8.0f;
  919. scalePoints[ 9].value = 9.0f;
  920. scalePoints[10].value = 10.0f;
  921. scalePoints[11].value = 11.0f;
  922. scalePoints[12].value = 12.0f;
  923. scalePoints[13].value = 13.0f;
  924. break;
  925. case 4:
  926. hints |= PARAMETER_IS_AUTOMABLE|PARAMETER_IS_BOOLEAN;
  927. param.name = "Negate";
  928. param.ranges.def = 0.0f;
  929. param.ranges.max = 1.0f;
  930. break;
  931. case 5:
  932. hints |= PARAMETER_IS_AUTOMABLE;
  933. param.name = "Low-Pass Filter";
  934. param.ranges.def = 96.0f;
  935. break;
  936. case 6:
  937. hints |= PARAMETER_IS_AUTOMABLE;
  938. param.name = "High-Pass Filter";
  939. param.ranges.def = 0.0f;
  940. break;
  941. case 7:
  942. hints |= PARAMETER_IS_AUTOMABLE|PARAMETER_IS_BOOLEAN;
  943. param.name = "Stereo";
  944. param.ranges.def = 0.0f;
  945. param.ranges.max = 1.0f;
  946. break;
  947. case 8:
  948. hints |= PARAMETER_IS_AUTOMABLE|PARAMETER_IS_BOOLEAN;
  949. param.name = "Pre-Filtering";
  950. param.ranges.def = 0.0f;
  951. param.ranges.max = 1.0f;
  952. break;
  953. }
  954. param.hints = static_cast<ParameterHints>(hints);
  955. return &param;
  956. }
  957. // -------------------------------------------------------------------
  958. // Plugin midi-program calls
  959. const MidiProgram* getMidiProgramInfo(const uint32_t index) override
  960. {
  961. if (index >= kProgramCount)
  962. return nullptr;
  963. static MidiProgram midiProg;
  964. midiProg.bank = 0;
  965. midiProg.program = index;
  966. switch (index)
  967. {
  968. case 0:
  969. midiProg.name = "Overdrive 1";
  970. break;
  971. case 1:
  972. midiProg.name = "Overdrive 2";
  973. break;
  974. case 2:
  975. midiProg.name = "A. Exciter 1";
  976. break;
  977. case 3:
  978. midiProg.name = "A. Exciter 2";
  979. break;
  980. case 4:
  981. midiProg.name = "Guitar Amp";
  982. break;
  983. case 5:
  984. midiProg.name = "Quantisize";
  985. break;
  986. default:
  987. midiProg.name = nullptr;
  988. break;
  989. }
  990. return &midiProg;
  991. }
  992. ZynPluginDescriptorClassEND(FxDistortionPlugin)
  993. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(FxDistortionPlugin)
  994. };
  995. // -----------------------------------------------------------------------
  996. class FxReverbPlugin : public FxAbstractPlugin
  997. {
  998. public:
  999. FxReverbPlugin(const HostDescriptor* const host)
  1000. : FxAbstractPlugin(host, 13, 13)
  1001. {
  1002. fEffect = new Reverb(false, efxoutl, efxoutr);
  1003. }
  1004. protected:
  1005. // -------------------------------------------------------------------
  1006. // Plugin parameter calls
  1007. const Parameter* getParameterInfo(const uint32_t index) override
  1008. {
  1009. if (index >= kParamCount)
  1010. return nullptr;
  1011. static Parameter param;
  1012. int hints = PARAMETER_IS_ENABLED | PARAMETER_IS_INTEGER;
  1013. param.name = nullptr;
  1014. param.unit = nullptr;
  1015. param.ranges.def = 1.0f;
  1016. param.ranges.min = 0.0f;
  1017. param.ranges.max = 127.0f;
  1018. param.ranges.step = 1.0f;
  1019. param.ranges.stepSmall = 1.0f;
  1020. param.ranges.stepLarge = 20.0f;
  1021. param.scalePointCount = 0;
  1022. param.scalePoints = nullptr;
  1023. switch (index)
  1024. {
  1025. case 0:
  1026. hints |= PARAMETER_IS_AUTOMABLE;
  1027. param.name = "Time";
  1028. param.ranges.def = 63.0f;
  1029. break;
  1030. case 1:
  1031. param.name = "Delay";
  1032. param.ranges.def = 24.0f;
  1033. break;
  1034. case 2:
  1035. hints |= PARAMETER_IS_AUTOMABLE;
  1036. param.name = "Feedback";
  1037. param.ranges.def = 0.0f;
  1038. break;
  1039. case 3:
  1040. hints = 0x0;
  1041. param.name = "unused1";
  1042. break;
  1043. case 4:
  1044. hints = 0x0;
  1045. param.name = "unused2";
  1046. break;
  1047. case 5:
  1048. param.name = "Low-Pass Filter";
  1049. param.ranges.def = 85.0f;
  1050. break;
  1051. case 6:
  1052. param.name = "High-Pass Filter";
  1053. param.ranges.def = 5.0f;
  1054. break;
  1055. case 7:
  1056. hints |= PARAMETER_IS_AUTOMABLE;
  1057. param.name = "Damp";
  1058. param.ranges.def = 83.0f;
  1059. break;
  1060. case 8:
  1061. param.name = "Type";
  1062. param.ranges.def = 1.0f;
  1063. param.ranges.max = 2.0f;
  1064. break;
  1065. case 9:
  1066. param.name = "Room size";
  1067. param.ranges.def = 64.0f;
  1068. break;
  1069. case 10:
  1070. param.name = "Bandwidth";
  1071. param.ranges.def = 20.0f;
  1072. break;
  1073. }
  1074. param.hints = static_cast<ParameterHints>(hints);
  1075. return &param;
  1076. }
  1077. // -------------------------------------------------------------------
  1078. // Plugin midi-program calls
  1079. const MidiProgram* getMidiProgramInfo(const uint32_t index) override
  1080. {
  1081. if (index >= kProgramCount)
  1082. return nullptr;
  1083. static MidiProgram midiProg;
  1084. midiProg.bank = 0;
  1085. midiProg.program = index;
  1086. switch (index)
  1087. {
  1088. case 0:
  1089. midiProg.name = "Cathedral1";
  1090. break;
  1091. case 1:
  1092. midiProg.name = "Cathedral2";
  1093. break;
  1094. case 2:
  1095. midiProg.name = "Cathedral3";
  1096. break;
  1097. case 3:
  1098. midiProg.name = "Hall1";
  1099. break;
  1100. case 4:
  1101. midiProg.name = "Hall2";
  1102. break;
  1103. case 5:
  1104. midiProg.name = "Room1";
  1105. break;
  1106. case 6:
  1107. midiProg.name = "Room2";
  1108. break;
  1109. case 7:
  1110. midiProg.name = "Basement";
  1111. break;
  1112. case 8:
  1113. midiProg.name = "Tunnel";
  1114. break;
  1115. case 9:
  1116. midiProg.name = "Echoed1";
  1117. break;
  1118. case 10:
  1119. midiProg.name = "Echoed2";
  1120. break;
  1121. case 11:
  1122. midiProg.name = "VeryLong1";
  1123. break;
  1124. case 12:
  1125. midiProg.name = "VeryLong2";
  1126. break;
  1127. default:
  1128. midiProg.name = nullptr;
  1129. break;
  1130. }
  1131. return &midiProg;
  1132. }
  1133. ZynPluginDescriptorClassEND(FxReverbPlugin)
  1134. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(FxReverbPlugin)
  1135. };
  1136. // -----------------------------------------------------------------------
  1137. class ZynAddSubFxPlugin : public PluginDescriptorClass
  1138. {
  1139. public:
  1140. enum Parameters {
  1141. PARAMETER_COUNT = 0
  1142. };
  1143. ZynAddSubFxPlugin(const HostDescriptor* const host)
  1144. : PluginDescriptorClass(host),
  1145. fMaster(new Master()),
  1146. fSampleRate(getSampleRate()),
  1147. fIsActive(false),
  1148. fThread(fMaster, host)
  1149. {
  1150. fThread.start();
  1151. for (int i = 0; i < NUM_MIDI_PARTS; ++i)
  1152. fMaster->partonoff(i, 1);
  1153. sPrograms.init();
  1154. }
  1155. ~ZynAddSubFxPlugin() override
  1156. {
  1157. //ensure that everything has stopped
  1158. pthread_mutex_lock(&fMaster->mutex);
  1159. pthread_mutex_unlock(&fMaster->mutex);
  1160. fThread.stop();
  1161. fThread.wait();
  1162. delete fMaster;
  1163. fMaster = nullptr;
  1164. }
  1165. protected:
  1166. // -------------------------------------------------------------------
  1167. // Plugin parameter calls
  1168. uint32_t getParameterCount() override
  1169. {
  1170. return PARAMETER_COUNT;
  1171. }
  1172. const Parameter* getParameterInfo(const uint32_t index) override
  1173. {
  1174. CARLA_ASSERT(index < getParameterCount());
  1175. //if (index >= PARAMETER_COUNT)
  1176. return nullptr;
  1177. static Parameter param;
  1178. param.ranges.step = PARAMETER_RANGES_DEFAULT_STEP;
  1179. param.ranges.stepSmall = PARAMETER_RANGES_DEFAULT_STEP_SMALL;
  1180. param.ranges.stepLarge = PARAMETER_RANGES_DEFAULT_STEP_LARGE;
  1181. param.scalePointCount = 0;
  1182. param.scalePoints = nullptr;
  1183. switch (index)
  1184. {
  1185. #if 0
  1186. case PARAMETER_MASTER:
  1187. param.hints = PARAMETER_IS_ENABLED | PARAMETER_IS_AUTOMABLE;
  1188. param.name = "Master Volume";
  1189. param.unit = nullptr;
  1190. param.ranges.min = 0.0f;
  1191. param.ranges.max = 100.0f;
  1192. param.ranges.def = 100.0f;
  1193. break;
  1194. #endif
  1195. }
  1196. return &param;
  1197. }
  1198. float getParameterValue(const uint32_t index) override
  1199. {
  1200. CARLA_ASSERT(index < getParameterCount());
  1201. switch (index)
  1202. {
  1203. #if 0
  1204. case PARAMETER_MASTER:
  1205. return fMaster->Pvolume;
  1206. #endif
  1207. default:
  1208. return 0.0f;
  1209. }
  1210. }
  1211. // -------------------------------------------------------------------
  1212. // Plugin midi-program calls
  1213. uint32_t getMidiProgramCount() override
  1214. {
  1215. return sPrograms.count();
  1216. }
  1217. const MidiProgram* getMidiProgramInfo(const uint32_t index) override
  1218. {
  1219. return sPrograms.getInfo(index);
  1220. }
  1221. // -------------------------------------------------------------------
  1222. // Plugin state calls
  1223. void setParameterValue(const uint32_t index, const float value) override
  1224. {
  1225. CARLA_ASSERT(index < getParameterCount());
  1226. switch (index)
  1227. {
  1228. }
  1229. return;
  1230. // unused, TODO
  1231. (void)value;
  1232. }
  1233. void setMidiProgram(const uint8_t channel, const uint32_t bank, const uint32_t program) override
  1234. {
  1235. if (bank >= fMaster->bank.banks.size())
  1236. return;
  1237. if (program >= BANK_SIZE)
  1238. return;
  1239. if (isOffline() || ! fIsActive)
  1240. {
  1241. sPrograms.load(fMaster, channel, bank, program);
  1242. #ifdef WANT_ZYNADDSUBFX_UI
  1243. fThread.uiRepaint();
  1244. #endif
  1245. }
  1246. else
  1247. fThread.loadProgramLater(channel, bank, program);
  1248. }
  1249. void setCustomData(const char* const key, const char* const value) override
  1250. {
  1251. CARLA_ASSERT(key != nullptr);
  1252. CARLA_ASSERT(value != nullptr);
  1253. if (std::strcmp(key, "CarlaAlternateFile1") == 0) // xmz
  1254. fMaster->loadXML(value);
  1255. else if (std::strcmp(key, "CarlaAlternateFile2") == 0) // xiz
  1256. fMaster->part[0]->loadXMLinstrument(value);
  1257. }
  1258. // -------------------------------------------------------------------
  1259. // Plugin process calls
  1260. void activate() override
  1261. {
  1262. fIsActive = true;
  1263. }
  1264. void deactivate() override
  1265. {
  1266. fIsActive = false;
  1267. }
  1268. void process(float**, float** const outBuffer, const uint32_t frames, const uint32_t midiEventCount, const MidiEvent* const midiEvents) override
  1269. {
  1270. if (pthread_mutex_trylock(&fMaster->mutex) != 0)
  1271. {
  1272. carla_zeroFloat(outBuffer[0], frames);
  1273. carla_zeroFloat(outBuffer[1], frames);
  1274. return;
  1275. }
  1276. for (uint32_t i=0; i < midiEventCount; ++i)
  1277. {
  1278. const MidiEvent* const midiEvent(&midiEvents[i]);
  1279. const uint8_t status = MIDI_GET_STATUS_FROM_DATA(midiEvent->data);
  1280. const uint8_t channel = MIDI_GET_CHANNEL_FROM_DATA(midiEvent->data);
  1281. if (MIDI_IS_STATUS_NOTE_OFF(status))
  1282. {
  1283. const uint8_t note = midiEvent->data[1];
  1284. fMaster->noteOff(channel, note);
  1285. }
  1286. else if (MIDI_IS_STATUS_NOTE_ON(status))
  1287. {
  1288. const uint8_t note = midiEvent->data[1];
  1289. const uint8_t velo = midiEvent->data[2];
  1290. fMaster->noteOn(channel, note, velo);
  1291. }
  1292. else if (MIDI_IS_STATUS_POLYPHONIC_AFTERTOUCH(status))
  1293. {
  1294. const uint8_t note = midiEvent->data[1];
  1295. const uint8_t pressure = midiEvent->data[2];
  1296. fMaster->polyphonicAftertouch(channel, note, pressure);
  1297. }
  1298. else if (MIDI_IS_STATUS_CONTROL_CHANGE(status))
  1299. {
  1300. const uint8_t control = midiEvent->data[1];
  1301. const uint8_t value = midiEvent->data[2];
  1302. fMaster->setController(channel, control, value);
  1303. }
  1304. else if (MIDI_IS_STATUS_PITCH_WHEEL_CONTROL(status))
  1305. {
  1306. const uint8_t lsb = midiEvent->data[1];
  1307. const uint8_t msb = midiEvent->data[2];
  1308. const int value = ((msb << 7) | lsb) - 8192;
  1309. fMaster->setController(channel, C_pitchwheel, value);
  1310. }
  1311. }
  1312. fMaster->GetAudioOutSamples(frames, fSampleRate, outBuffer[0], outBuffer[1]);
  1313. pthread_mutex_unlock(&fMaster->mutex);
  1314. }
  1315. #ifdef WANT_ZYNADDSUBFX_UI
  1316. // -------------------------------------------------------------------
  1317. // Plugin UI calls
  1318. void uiShow(const bool show) override
  1319. {
  1320. if (show)
  1321. fThread.uiShow();
  1322. else
  1323. fThread.uiHide();
  1324. }
  1325. #endif
  1326. // -------------------------------------------------------------------
  1327. // Plugin state calls
  1328. char* getState() override
  1329. {
  1330. config.save();
  1331. char* data = nullptr;
  1332. fMaster->getalldata(&data);
  1333. return data;
  1334. }
  1335. void setState(const char* const data) override
  1336. {
  1337. fThread.stopLoadProgramLater();
  1338. fMaster->putalldata((char*)data, 0);
  1339. fMaster->applyparameters(true);
  1340. }
  1341. // -------------------------------------------------------------------
  1342. // Plugin dispatcher
  1343. intptr_t pluginDispatcher(const PluginDispatcherOpcode opcode, const int32_t index, const intptr_t value, void* const ptr, const float) override
  1344. {
  1345. switch (opcode)
  1346. {
  1347. case PLUGIN_OPCODE_NULL:
  1348. break;
  1349. case PLUGIN_OPCODE_BUFFER_SIZE_CHANGED:
  1350. // TODO
  1351. break;
  1352. case PLUGIN_OPCODE_SAMPLE_RATE_CHANGED:
  1353. // TODO
  1354. break;
  1355. case PLUGIN_OPCODE_OFFLINE_CHANGED:
  1356. break;
  1357. case PLUGIN_OPCODE_UI_NAME_CHANGED:
  1358. #ifdef WANT_ZYNADDSUBFX_UI
  1359. // TODO
  1360. #endif
  1361. break;
  1362. }
  1363. return 0;
  1364. // unused
  1365. (void)index;
  1366. (void)value;
  1367. (void)ptr;
  1368. }
  1369. // -------------------------------------------------------------------
  1370. private:
  1371. Master* fMaster;
  1372. unsigned fSampleRate;
  1373. bool fIsActive;
  1374. ZynAddSubFxThread fThread;
  1375. ZynPluginDescriptorClassEND(ZynAddSubFxPlugin)
  1376. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ZynAddSubFxPlugin)
  1377. };
  1378. // -----------------------------------------------------------------------
  1379. static const PluginDescriptor fxAlienWahDesc = {
  1380. /* category */ PLUGIN_CATEGORY_MODULATOR,
  1381. /* hints */ static_cast<PluginHints>(PLUGIN_IS_RTSAFE|PLUGIN_USES_PANNING|PLUGIN_USES_STATIC_BUFFERS),
  1382. /* supports */ static_cast<PluginSupports>(0x0),
  1383. /* audioIns */ 2,
  1384. /* audioOuts */ 2,
  1385. /* midiIns */ 0,
  1386. /* midiOuts */ 0,
  1387. /* paramIns */ 11-1,
  1388. /* paramOuts */ 0,
  1389. /* name */ "ZynAlienWah",
  1390. /* label */ "zynAlienWah",
  1391. /* maker */ "falkTX",
  1392. /* copyright */ "GNU GPL v2+",
  1393. PluginDescriptorFILL(FxAlienWahPlugin)
  1394. };
  1395. static const PluginDescriptor fxChorusDesc = {
  1396. /* category */ PLUGIN_CATEGORY_MODULATOR,
  1397. /* hints */ static_cast<PluginHints>(PLUGIN_IS_RTSAFE|PLUGIN_USES_PANNING|PLUGIN_USES_STATIC_BUFFERS),
  1398. /* supports */ static_cast<PluginSupports>(0x0),
  1399. /* audioIns */ 2,
  1400. /* audioOuts */ 2,
  1401. /* midiIns */ 0,
  1402. /* midiOuts */ 0,
  1403. /* paramIns */ 12-1,
  1404. /* paramOuts */ 0,
  1405. /* name */ "ZynChorus",
  1406. /* label */ "zynChorus",
  1407. /* maker */ "falkTX",
  1408. /* copyright */ "GNU GPL v2+",
  1409. PluginDescriptorFILL(FxChorusPlugin)
  1410. };
  1411. static const PluginDescriptor fxDistortionDesc = {
  1412. /* category */ PLUGIN_CATEGORY_MODULATOR,
  1413. /* hints */ static_cast<PluginHints>(PLUGIN_USES_PANNING|PLUGIN_USES_STATIC_BUFFERS),
  1414. /* supports */ static_cast<PluginSupports>(0x0),
  1415. /* audioIns */ 2,
  1416. /* audioOuts */ 2,
  1417. /* midiIns */ 0,
  1418. /* midiOuts */ 0,
  1419. /* paramIns */ 11-1,
  1420. /* paramOuts */ 0,
  1421. /* name */ "ZynDistortion",
  1422. /* label */ "zynDistortion",
  1423. /* maker */ "falkTX",
  1424. /* copyright */ "GNU GPL v2+",
  1425. PluginDescriptorFILL(FxDistortionPlugin)
  1426. };
  1427. #if 0
  1428. static const PluginDescriptor fxDynamicFilterDesc = {
  1429. /* category */ PLUGIN_CATEGORY_FILTER,
  1430. /* hints */ static_cast<PluginHints>(PLUGIN_USES_PANNING|PLUGIN_USES_STATIC_BUFFERS),
  1431. /* supports */ static_cast<PluginSupports>(0x0),
  1432. /* audioIns */ 2,
  1433. /* audioOuts */ 2,
  1434. /* midiIns */ 0,
  1435. /* midiOuts */ 0,
  1436. /* paramIns */ FxDynamicFilterPlugin::kParamCount,
  1437. /* paramOuts */ 0,
  1438. /* name */ "ZynDynamicFilter",
  1439. /* label */ "zynDynamicFilter",
  1440. /* maker */ "falkTX",
  1441. /* copyright */ "GNU GPL v2+",
  1442. PluginDescriptorFILL(FxDynamicFilterPlugin)
  1443. };
  1444. static const PluginDescriptor fxEchoDesc = {
  1445. /* category */ PLUGIN_CATEGORY_DELAY,
  1446. /* hints */ static_cast<PluginHints>(PLUGIN_USES_PANNING|PLUGIN_USES_STATIC_BUFFERS),
  1447. /* supports */ static_cast<PluginSupports>(0x0),
  1448. /* audioIns */ 2,
  1449. /* audioOuts */ 2,
  1450. /* midiIns */ 0,
  1451. /* midiOuts */ 0,
  1452. /* paramIns */ FxEchoPlugin::kParamCount,
  1453. /* paramOuts */ 0,
  1454. /* name */ "ZynEcho",
  1455. /* label */ "zynEcho",
  1456. /* maker */ "falkTX",
  1457. /* copyright */ "GNU GPL v2+",
  1458. PluginDescriptorFILL(FxEchoPlugin)
  1459. };
  1460. static const PluginDescriptor fxPhaserDesc = {
  1461. /* category */ PLUGIN_CATEGORY_MODULATOR,
  1462. /* hints */ static_cast<PluginHints>(PLUGIN_USES_PANNING|PLUGIN_USES_STATIC_BUFFERS),
  1463. /* supports */ static_cast<PluginSupports>(0x0),
  1464. /* audioIns */ 2,
  1465. /* audioOuts */ 2,
  1466. /* midiIns */ 0,
  1467. /* midiOuts */ 0,
  1468. /* paramIns */ FxPhaserPlugin::kParamCount,
  1469. /* paramOuts */ 0,
  1470. /* name */ "ZynPhaser",
  1471. /* label */ "zynPhaser",
  1472. /* maker */ "falkTX",
  1473. /* copyright */ "GNU GPL v2+",
  1474. PluginDescriptorFILL(FxPhaserPlugin)
  1475. };
  1476. #endif
  1477. static const PluginDescriptor fxReverbDesc = {
  1478. /* category */ PLUGIN_CATEGORY_DELAY,
  1479. /* hints */ static_cast<PluginHints>(PLUGIN_USES_PANNING|PLUGIN_USES_STATIC_BUFFERS),
  1480. /* supports */ static_cast<PluginSupports>(0x0),
  1481. /* audioIns */ 2,
  1482. /* audioOuts */ 2,
  1483. /* midiIns */ 0,
  1484. /* midiOuts */ 0,
  1485. /* paramIns */ 13-1,
  1486. /* paramOuts */ 0,
  1487. /* name */ "ZynReverb",
  1488. /* label */ "zynReverb",
  1489. /* maker */ "falkTX",
  1490. /* copyright */ "GNU GPL v2+",
  1491. PluginDescriptorFILL(FxReverbPlugin)
  1492. };
  1493. static const PluginDescriptor zynaddsubfxDesc = {
  1494. /* category */ PLUGIN_CATEGORY_SYNTH,
  1495. #ifdef WANT_ZYNADDSUBFX_UI
  1496. /* hints */ static_cast<PluginHints>(PLUGIN_IS_SYNTH|PLUGIN_HAS_GUI|PLUGIN_USES_STATE),
  1497. #else
  1498. /* hints */ static_cast<PluginHints>(PLUGIN_IS_SYNTH|PLUGIN_USES_STATE),
  1499. #endif
  1500. /* supports */ static_cast<PluginSupports>(PLUGIN_SUPPORTS_CONTROL_CHANGES|PLUGIN_SUPPORTS_NOTE_AFTERTOUCH|PLUGIN_SUPPORTS_PITCHBEND|PLUGIN_SUPPORTS_ALL_SOUND_OFF),
  1501. /* audioIns */ 0,
  1502. /* audioOuts */ 2,
  1503. /* midiIns */ 1,
  1504. /* midiOuts */ 0,
  1505. /* paramIns */ ZynAddSubFxPlugin::PARAMETER_COUNT,
  1506. /* paramOuts */ 0,
  1507. /* name */ "ZynAddSubFX",
  1508. /* label */ "zynaddsubfx",
  1509. /* maker */ "falkTX",
  1510. /* copyright */ "GNU GPL v2+",
  1511. PluginDescriptorFILL(ZynAddSubFxPlugin)
  1512. };
  1513. // -----------------------------------------------------------------------
  1514. void carla_register_native_plugin_zynaddsubfx()
  1515. {
  1516. carla_register_native_plugin(&fxAlienWahDesc);
  1517. carla_register_native_plugin(&fxChorusDesc);
  1518. carla_register_native_plugin(&fxDistortionDesc);
  1519. #if 0
  1520. carla_register_native_plugin(&fxDynamicFilterDesc);
  1521. carla_register_native_plugin(&fxEchoDesc);
  1522. carla_register_native_plugin(&fxPhaserDesc);
  1523. #endif
  1524. carla_register_native_plugin(&fxReverbDesc);
  1525. carla_register_native_plugin(&zynaddsubfxDesc);
  1526. }
  1527. // -----------------------------------------------------------------------