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.

zynaddsubfx-synth.cpp 21KB

10 years ago
10 years ago
10 years ago
10 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851
  1. /*
  2. * Carla Native Plugins
  3. * Copyright (C) 2012-2014 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. #include "CarlaNative.hpp"
  18. #include "CarlaMIDI.h"
  19. #include "CarlaThread.hpp"
  20. #include "LinkedList.hpp"
  21. #include "CarlaMathUtils.hpp"
  22. #include "zynaddsubfx/DSP/FFTwrapper.h"
  23. #include "zynaddsubfx/Misc/Master.h"
  24. #include "zynaddsubfx/Misc/Part.h"
  25. #include "zynaddsubfx/Misc/Util.h"
  26. #ifdef WANT_ZYNADDSUBFX_UI
  27. # ifdef override
  28. # define override_hack
  29. # undef override
  30. # endif
  31. # include "zynaddsubfx/UI/common.H"
  32. # include "zynaddsubfx/UI/MasterUI.h"
  33. # include <FL/Fl_Shared_Image.H>
  34. # include <FL/Fl_Tiled_Image.H>
  35. # include <FL/Fl_Theme.H>
  36. # ifdef override_hack
  37. # define override
  38. # undef override_hack
  39. # endif
  40. #endif
  41. #include <ctime>
  42. #include <set>
  43. #include <string>
  44. #include "juce_audio_basics.h"
  45. using juce::FloatVectorOperations;
  46. #ifdef WANT_ZYNADDSUBFX_UI
  47. static Fl_Tiled_Image* gModuleBackdrop = nullptr;
  48. static CarlaString gPixmapPath;
  49. extern CarlaString gUiPixmapPath;
  50. void set_module_parameters(Fl_Widget* o)
  51. {
  52. CARLA_ASSERT(gModuleBackdrop != nullptr);
  53. o->box(FL_DOWN_FRAME);
  54. o->align(o->align() | FL_ALIGN_IMAGE_BACKDROP);
  55. o->color(FL_BLACK);
  56. o->labeltype(FL_SHADOW_LABEL);
  57. if (gModuleBackdrop != nullptr)
  58. o->image(gModuleBackdrop);
  59. }
  60. #endif
  61. // -----------------------------------------------------------------------
  62. class ZynAddSubFxPrograms
  63. {
  64. public:
  65. ZynAddSubFxPrograms()
  66. : fInitiated(false)
  67. {
  68. }
  69. ~ZynAddSubFxPrograms()
  70. {
  71. if (! fInitiated)
  72. return;
  73. for (LinkedList<const ProgramInfo*>::Itenerator it = fPrograms.begin(); it.valid(); it.next())
  74. {
  75. const ProgramInfo* const& pInfo(it.getValue());
  76. delete pInfo;
  77. }
  78. fPrograms.clear();
  79. FFT_cleanup();
  80. }
  81. void init()
  82. {
  83. if (fInitiated)
  84. return;
  85. fInitiated = true;
  86. fPrograms.append(new ProgramInfo(0, 0, "default"));
  87. Master& master(Master::getInstance());
  88. pthread_mutex_lock(&master.mutex);
  89. // refresh banks
  90. master.bank.rescanforbanks();
  91. for (uint32_t i=0, size = master.bank.banks.size(); i < size; ++i)
  92. {
  93. if (master.bank.banks[i].dir.empty())
  94. continue;
  95. master.bank.loadbank(master.bank.banks[i].dir);
  96. for (unsigned int instrument = 0; instrument < BANK_SIZE; ++instrument)
  97. {
  98. const std::string insName(master.bank.getname(instrument));
  99. if (insName.empty() || insName[0] == '\0' || insName[0] == ' ')
  100. continue;
  101. fPrograms.append(new ProgramInfo(i+1, instrument, insName.c_str()));
  102. }
  103. }
  104. pthread_mutex_unlock(&master.mutex);
  105. }
  106. void load(Master* const master, const uint8_t channel, const uint32_t bank, const uint32_t program)
  107. {
  108. if (bank == 0)
  109. {
  110. pthread_mutex_lock(&master->mutex);
  111. master->partonoff(channel, 1);
  112. master->part[channel]->defaults();
  113. master->part[channel]->applyparameters(false);
  114. pthread_mutex_unlock(&master->mutex);
  115. return;
  116. }
  117. const std::string& bankdir(master->bank.banks[bank-1].dir);
  118. if (! bankdir.empty())
  119. {
  120. pthread_mutex_lock(&master->mutex);
  121. master->partonoff(channel, 1);
  122. master->bank.loadbank(bankdir);
  123. master->bank.loadfromslot(program, master->part[channel]);
  124. master->part[channel]->applyparameters(false);
  125. pthread_mutex_unlock(&master->mutex);
  126. }
  127. }
  128. uint32_t count()
  129. {
  130. return fPrograms.count();
  131. }
  132. const NativeMidiProgram* getInfo(const uint32_t index)
  133. {
  134. if (index >= fPrograms.count())
  135. return nullptr;
  136. const ProgramInfo* const pInfo(fPrograms.getAt(index, nullptr));
  137. CARLA_SAFE_ASSERT_RETURN(pInfo != nullptr, nullptr);
  138. fRetProgram.bank = pInfo->bank;
  139. fRetProgram.program = pInfo->prog;
  140. fRetProgram.name = pInfo->name;
  141. return &fRetProgram;
  142. }
  143. private:
  144. struct ProgramInfo {
  145. uint32_t bank;
  146. uint32_t prog;
  147. const char* name;
  148. ProgramInfo(uint32_t bank_, uint32_t prog_, const char* name_)
  149. : bank(bank_),
  150. prog(prog_),
  151. name(carla_strdup(name_)) {}
  152. ~ProgramInfo()
  153. {
  154. if (name != nullptr)
  155. {
  156. delete[] name;
  157. name = nullptr;
  158. }
  159. }
  160. #ifdef CARLA_PROPER_CPP11_SUPPORT
  161. ProgramInfo() = delete;
  162. ProgramInfo(ProgramInfo&) = delete;
  163. ProgramInfo(const ProgramInfo&) = delete;
  164. ProgramInfo& operator=(ProgramInfo&);
  165. ProgramInfo& operator=(const ProgramInfo&);
  166. #endif
  167. };
  168. bool fInitiated;
  169. NativeMidiProgram fRetProgram;
  170. LinkedList<const ProgramInfo*> fPrograms;
  171. CARLA_DECLARE_NON_COPY_CLASS(ZynAddSubFxPrograms)
  172. };
  173. static ZynAddSubFxPrograms sPrograms;
  174. // -----------------------------------------------------------------------
  175. class ZynAddSubFxInstanceCount
  176. {
  177. public:
  178. ZynAddSubFxInstanceCount()
  179. : fCount(0)
  180. {
  181. }
  182. ~ZynAddSubFxInstanceCount()
  183. {
  184. CARLA_ASSERT(fCount == 0);
  185. }
  186. void addOne(const NativeHostDescriptor* const host)
  187. {
  188. if (fCount++ == 0)
  189. {
  190. CARLA_ASSERT(synth == nullptr);
  191. CARLA_ASSERT(denormalkillbuf == nullptr);
  192. reinit(host);
  193. #ifdef WANT_ZYNADDSUBFX_UI
  194. if (gPixmapPath.isEmpty())
  195. {
  196. gPixmapPath = host->resourceDir;
  197. gPixmapPath += "/zynaddsubfx/";
  198. gUiPixmapPath = gPixmapPath;
  199. }
  200. #endif
  201. }
  202. }
  203. void removeOne()
  204. {
  205. if (--fCount == 0)
  206. {
  207. CARLA_ASSERT(synth != nullptr);
  208. CARLA_ASSERT(denormalkillbuf != nullptr);
  209. Master::deleteInstance();
  210. delete[] denormalkillbuf;
  211. denormalkillbuf = nullptr;
  212. delete synth;
  213. synth = nullptr;
  214. }
  215. }
  216. void reinit(const NativeHostDescriptor* const host)
  217. {
  218. Master::deleteInstance();
  219. if (denormalkillbuf != nullptr)
  220. {
  221. delete[] denormalkillbuf;
  222. denormalkillbuf = nullptr;
  223. }
  224. if (synth != nullptr)
  225. {
  226. delete synth;
  227. synth = nullptr;
  228. }
  229. synth = new SYNTH_T();
  230. synth->buffersize = host->get_buffer_size(host->handle);
  231. synth->samplerate = host->get_sample_rate(host->handle);
  232. if (synth->buffersize > 32)
  233. synth->buffersize = 32;
  234. synth->alias();
  235. config.init();
  236. config.cfg.SoundBufferSize = synth->buffersize;
  237. config.cfg.SampleRate = synth->samplerate;
  238. config.cfg.GzipCompression = 0;
  239. sprng(std::time(nullptr));
  240. denormalkillbuf = new float[synth->buffersize];
  241. for (int i=0; i < synth->buffersize; ++i)
  242. denormalkillbuf[i] = (RND - 0.5f) * 1e-16;
  243. Master::getInstance();
  244. }
  245. void maybeReinit(const NativeHostDescriptor* const host)
  246. {
  247. if (host->get_buffer_size(host->handle) == static_cast<uint32_t>(synth->buffersize) &&
  248. host->get_sample_rate(host->handle) == static_cast<double>(synth->samplerate))
  249. return;
  250. reinit(host);
  251. }
  252. private:
  253. int fCount;
  254. CARLA_DECLARE_NON_COPY_CLASS(ZynAddSubFxInstanceCount)
  255. };
  256. static ZynAddSubFxInstanceCount sInstanceCount;
  257. // -----------------------------------------------------------------------
  258. class ZynAddSubFxThread : public CarlaThread
  259. {
  260. public:
  261. ZynAddSubFxThread(Master* const master, const NativeHostDescriptor* const host)
  262. : CarlaThread("ZynAddSubFxThread"),
  263. fMaster(master),
  264. kHost(host),
  265. #ifdef WANT_ZYNADDSUBFX_UI
  266. fUi(nullptr),
  267. fUiClosed(0),
  268. fNextUiAction(-1),
  269. #endif
  270. fChangeProgram(false),
  271. fNextChannel(0),
  272. fNextBank(0),
  273. fNextProgram(0)
  274. {
  275. }
  276. ~ZynAddSubFxThread()
  277. {
  278. #ifdef WANT_ZYNADDSUBFX_UI
  279. // must be closed by now
  280. CARLA_ASSERT(fUi == nullptr);
  281. #endif
  282. }
  283. void loadProgramLater(const uint8_t channel, const uint32_t bank, const uint32_t program)
  284. {
  285. fNextChannel = channel;
  286. fNextBank = bank;
  287. fNextProgram = program;
  288. fChangeProgram = true;
  289. }
  290. void stopLoadProgramLater()
  291. {
  292. fChangeProgram = false;
  293. fNextChannel = 0;
  294. fNextBank = 0;
  295. fNextProgram = 0;
  296. }
  297. void setMaster(Master* const master)
  298. {
  299. fMaster = master;
  300. }
  301. #ifdef WANT_ZYNADDSUBFX_UI
  302. void uiHide()
  303. {
  304. fNextUiAction = 0;
  305. }
  306. void uiShow()
  307. {
  308. fNextUiAction = 1;
  309. }
  310. void uiRepaint()
  311. {
  312. if (fUi != nullptr)
  313. fNextUiAction = 2;
  314. }
  315. void uiChangeName(const char* const name)
  316. {
  317. if (fUi != nullptr)
  318. {
  319. Fl::lock();
  320. fUi->masterwindow->label(name);
  321. Fl::unlock();
  322. }
  323. }
  324. #endif
  325. protected:
  326. void run() override
  327. {
  328. while (! shouldThreadExit())
  329. {
  330. #ifdef WANT_ZYNADDSUBFX_UI
  331. Fl::lock();
  332. if (fNextUiAction == 2) // repaint
  333. {
  334. CARLA_ASSERT(fUi != nullptr);
  335. if (fUi != nullptr)
  336. fUi->refresh_master_ui();
  337. }
  338. else if (fNextUiAction == 1) // init/show
  339. {
  340. static bool initialized = false;
  341. if (! initialized)
  342. {
  343. initialized = true;
  344. fl_register_images();
  345. Fl_Dial::default_style(Fl_Dial::PIXMAP_DIAL);
  346. if (Fl_Shared_Image* const img = Fl_Shared_Image::get(gPixmapPath + "knob.png"))
  347. Fl_Dial::default_image(img);
  348. if (Fl_Shared_Image* const img = Fl_Shared_Image::get(gPixmapPath + "window_backdrop.png"))
  349. Fl::scheme_bg(new Fl_Tiled_Image(img));
  350. if(Fl_Shared_Image* const img = Fl_Shared_Image::get(gPixmapPath + "module_backdrop.png"))
  351. gModuleBackdrop = new Fl_Tiled_Image(img);
  352. Fl::background(50, 50, 50);
  353. Fl::background2(70, 70, 70);
  354. Fl::foreground(255, 255, 255);
  355. Fl_Theme::set("Cairo");
  356. }
  357. if (fUi == nullptr)
  358. {
  359. fUiClosed = 0;
  360. fUi = new MasterUI(fMaster, &fUiClosed);
  361. fUi->masterwindow->label(kHost->uiName);
  362. fUi->showUI();
  363. }
  364. else
  365. fUi->showUI();
  366. }
  367. else if (fNextUiAction == 0) // close
  368. {
  369. CARLA_ASSERT(fUi != nullptr);
  370. if (fUi != nullptr)
  371. {
  372. delete fUi;
  373. fUi = nullptr;
  374. }
  375. }
  376. fNextUiAction = -1;
  377. if (fUiClosed != 0)
  378. {
  379. fUiClosed = 0;
  380. fNextUiAction = 0;
  381. kHost->ui_closed(kHost->handle);
  382. }
  383. Fl::check();
  384. Fl::unlock();
  385. #endif
  386. if (fChangeProgram)
  387. {
  388. fChangeProgram = false;
  389. sPrograms.load(fMaster, fNextChannel, fNextBank, fNextProgram);
  390. fNextChannel = 0;
  391. fNextBank = 0;
  392. fNextProgram = 0;
  393. #ifdef WANT_ZYNADDSUBFX_UI
  394. if (fUi != nullptr)
  395. {
  396. Fl::lock();
  397. fUi->refresh_master_ui();
  398. Fl::unlock();
  399. }
  400. #endif
  401. carla_msleep(15);
  402. }
  403. else
  404. {
  405. carla_msleep(30);
  406. }
  407. }
  408. #ifdef WANT_ZYNADDSUBFX_UI
  409. if (shouldThreadExit() || fUi != nullptr)
  410. {
  411. Fl::lock();
  412. delete fUi;
  413. fUi = nullptr;
  414. Fl::check();
  415. Fl::unlock();
  416. }
  417. #endif
  418. }
  419. private:
  420. Master* fMaster;
  421. const NativeHostDescriptor* const kHost;
  422. #ifdef WANT_ZYNADDSUBFX_UI
  423. MasterUI* fUi;
  424. int fUiClosed;
  425. volatile int fNextUiAction;
  426. #endif
  427. volatile bool fChangeProgram;
  428. volatile uint8_t fNextChannel;
  429. volatile uint32_t fNextBank;
  430. volatile uint32_t fNextProgram;
  431. };
  432. // -----------------------------------------------------------------------
  433. class ZynAddSubFxPlugin : public NativePluginClass
  434. {
  435. public:
  436. ZynAddSubFxPlugin(const NativeHostDescriptor* const host)
  437. : NativePluginClass(host),
  438. fMaster(new Master()),
  439. fSampleRate(getSampleRate()),
  440. fIsActive(false),
  441. fThread(fMaster, host)
  442. {
  443. fThread.startThread();
  444. for (int i = 0; i < NUM_MIDI_PARTS; ++i)
  445. fMaster->partonoff(i, 1);
  446. sPrograms.init();
  447. #if 0
  448. // create instance if needed
  449. getGlobalMutex();
  450. #endif
  451. }
  452. ~ZynAddSubFxPlugin() override
  453. {
  454. deleteMaster();
  455. }
  456. protected:
  457. // -------------------------------------------------------------------
  458. // Plugin midi-program calls
  459. uint32_t getMidiProgramCount() const override
  460. {
  461. return sPrograms.count();
  462. }
  463. const NativeMidiProgram* getMidiProgramInfo(const uint32_t index) const override
  464. {
  465. return sPrograms.getInfo(index);
  466. }
  467. // -------------------------------------------------------------------
  468. // Plugin state calls
  469. void setMidiProgram(const uint8_t channel, const uint32_t bank, const uint32_t program) override
  470. {
  471. if (bank >= fMaster->bank.banks.size())
  472. return;
  473. if (program >= BANK_SIZE)
  474. return;
  475. if (isOffline() || ! fIsActive)
  476. {
  477. sPrograms.load(fMaster, channel, bank, program);
  478. #ifdef WANT_ZYNADDSUBFX_UI
  479. fThread.uiRepaint();
  480. #endif
  481. }
  482. else
  483. fThread.loadProgramLater(channel, bank, program);
  484. }
  485. void setCustomData(const char* const key, const char* const value) override
  486. {
  487. CARLA_SAFE_ASSERT_RETURN(key != nullptr,);
  488. CARLA_SAFE_ASSERT_RETURN(value != nullptr,);
  489. pthread_mutex_lock(&fMaster->mutex);
  490. if (std::strcmp(key, "CarlaAlternateFile1") == 0) // xmz
  491. {
  492. fMaster->defaults();
  493. fMaster->loadXML(value);
  494. }
  495. else if (std::strcmp(key, "CarlaAlternateFile2") == 0) // xiz
  496. {
  497. fMaster->part[0]->defaultsinstrument();
  498. fMaster->part[0]->loadXMLinstrument(value);
  499. }
  500. pthread_mutex_unlock(&fMaster->mutex);
  501. fMaster->applyparameters();
  502. }
  503. // -------------------------------------------------------------------
  504. // Plugin process calls
  505. void activate() override
  506. {
  507. fIsActive = true;
  508. }
  509. void deactivate() override
  510. {
  511. fIsActive = false;
  512. }
  513. void process(float**, float** const outBuffer, const uint32_t frames, const NativeMidiEvent* const midiEvents, const uint32_t midiEventCount) override
  514. {
  515. if (pthread_mutex_trylock(&fMaster->mutex) != 0)
  516. {
  517. FloatVectorOperations::clear(outBuffer[0], frames);
  518. FloatVectorOperations::clear(outBuffer[1], frames);
  519. return;
  520. }
  521. #if 0
  522. const CarlaMutexLocker csm(getGlobalMutex());
  523. #endif
  524. for (uint32_t i=0; i < midiEventCount; ++i)
  525. {
  526. const NativeMidiEvent* const midiEvent(&midiEvents[i]);
  527. const uint8_t status = MIDI_GET_STATUS_FROM_DATA(midiEvent->data);
  528. const uint8_t channel = MIDI_GET_CHANNEL_FROM_DATA(midiEvent->data);
  529. if (MIDI_IS_STATUS_NOTE_OFF(status))
  530. {
  531. const uint8_t note = midiEvent->data[1];
  532. fMaster->noteOff(channel, note);
  533. }
  534. else if (MIDI_IS_STATUS_NOTE_ON(status))
  535. {
  536. const uint8_t note = midiEvent->data[1];
  537. const uint8_t velo = midiEvent->data[2];
  538. fMaster->noteOn(channel, note, velo);
  539. }
  540. else if (MIDI_IS_STATUS_POLYPHONIC_AFTERTOUCH(status))
  541. {
  542. const uint8_t note = midiEvent->data[1];
  543. const uint8_t pressure = midiEvent->data[2];
  544. fMaster->polyphonicAftertouch(channel, note, pressure);
  545. }
  546. else if (MIDI_IS_STATUS_CONTROL_CHANGE(status))
  547. {
  548. const uint8_t control = midiEvent->data[1];
  549. const uint8_t value = midiEvent->data[2];
  550. fMaster->setController(channel, control, value);
  551. }
  552. else if (MIDI_IS_STATUS_PITCH_WHEEL_CONTROL(status))
  553. {
  554. const uint8_t lsb = midiEvent->data[1];
  555. const uint8_t msb = midiEvent->data[2];
  556. const int value = ((msb << 7) | lsb) - 8192;
  557. fMaster->setController(channel, C_pitchwheel, value);
  558. }
  559. }
  560. fMaster->GetAudioOutSamples(frames, fSampleRate, outBuffer[0], outBuffer[1]);
  561. pthread_mutex_unlock(&fMaster->mutex);
  562. }
  563. #ifdef WANT_ZYNADDSUBFX_UI
  564. // -------------------------------------------------------------------
  565. // Plugin UI calls
  566. void uiShow(const bool show) override
  567. {
  568. if (show)
  569. fThread.uiShow();
  570. else
  571. fThread.uiHide();
  572. }
  573. #endif
  574. // -------------------------------------------------------------------
  575. // Plugin state calls
  576. char* getState() const override
  577. {
  578. config.save();
  579. char* data = nullptr;
  580. fMaster->getalldata(&data);
  581. return data;
  582. }
  583. void setState(const char* const data) override
  584. {
  585. fThread.stopLoadProgramLater();
  586. fMaster->putalldata((char*)data, 0);
  587. fMaster->applyparameters(true);
  588. }
  589. // -------------------------------------------------------------------
  590. // Plugin dispatcher
  591. // TODO - save&load current state
  592. void bufferSizeChanged(const uint32_t) final
  593. {
  594. deleteMaster();
  595. sInstanceCount.maybeReinit(getHostHandle());
  596. initMaster();
  597. }
  598. void sampleRateChanged(const double sampleRate) final
  599. {
  600. fSampleRate = sampleRate;
  601. deleteMaster();
  602. sInstanceCount.maybeReinit(getHostHandle());
  603. initMaster();
  604. }
  605. void initMaster()
  606. {
  607. fMaster = new Master();
  608. fThread.setMaster(fMaster);
  609. fThread.startThread();
  610. for (int i = 0; i < NUM_MIDI_PARTS; ++i)
  611. fMaster->partonoff(i, 1);
  612. }
  613. void deleteMaster()
  614. {
  615. //ensure that everything has stopped
  616. pthread_mutex_lock(&fMaster->mutex);
  617. pthread_mutex_unlock(&fMaster->mutex);
  618. fThread.stopThread(-1);
  619. delete fMaster;
  620. fMaster = nullptr;
  621. }
  622. #ifdef WANT_ZYNADDSUBFX_UI
  623. void uiNameChanged(const char* const uiName) override
  624. {
  625. fThread.uiChangeName(uiName);
  626. }
  627. #endif
  628. // -------------------------------------------------------------------
  629. private:
  630. Master* fMaster;
  631. unsigned fSampleRate;
  632. bool fIsActive;
  633. ZynAddSubFxThread fThread;
  634. #if 0
  635. // -------------------------------------------------------------------
  636. static CarlaMutex& getGlobalMutex() noexcept
  637. {
  638. static CarlaMutex m;
  639. return m;
  640. }
  641. #endif
  642. // -------------------------------------------------------------------
  643. public:
  644. static NativePluginHandle _instantiate(const NativeHostDescriptor* host)
  645. {
  646. sInstanceCount.addOne(host);
  647. return new ZynAddSubFxPlugin(host);
  648. }
  649. static void _cleanup(NativePluginHandle handle)
  650. {
  651. delete (ZynAddSubFxPlugin*)handle;
  652. sInstanceCount.removeOne();
  653. }
  654. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ZynAddSubFxPlugin)
  655. };
  656. // -----------------------------------------------------------------------
  657. static const NativePluginDescriptor zynaddsubfxDesc = {
  658. /* category */ PLUGIN_CATEGORY_SYNTH,
  659. #ifdef WANT_ZYNADDSUBFX_UI
  660. /* hints */ static_cast<NativePluginHints>(PLUGIN_IS_SYNTH|PLUGIN_HAS_UI|PLUGIN_USES_MULTI_PROGS|PLUGIN_USES_STATE),
  661. #else
  662. /* hints */ static_cast<NativePluginHints>(PLUGIN_IS_SYNTH|PLUGIN_USES_MULTI_PROGS|PLUGIN_USES_STATE),
  663. #endif
  664. /* supports */ static_cast<NativePluginSupports>(PLUGIN_SUPPORTS_CONTROL_CHANGES|PLUGIN_SUPPORTS_NOTE_AFTERTOUCH|PLUGIN_SUPPORTS_PITCHBEND|PLUGIN_SUPPORTS_ALL_SOUND_OFF),
  665. /* audioIns */ 0,
  666. /* audioOuts */ 2,
  667. /* midiIns */ 1,
  668. /* midiOuts */ 0,
  669. /* paramIns */ 0,
  670. /* paramOuts */ 0,
  671. /* name */ "ZynAddSubFX",
  672. /* label */ "zynaddsubfx",
  673. /* maker */ "falkTX, Mark McCurry, Nasca Octavian Paul",
  674. /* copyright */ "GNU GPL v2+",
  675. PluginDescriptorFILL(ZynAddSubFxPlugin)
  676. };
  677. // -----------------------------------------------------------------------
  678. CARLA_EXPORT
  679. void carla_register_native_plugin_zynaddsubfx_synth()
  680. {
  681. carla_register_native_plugin(&zynaddsubfxDesc);
  682. }
  683. // -----------------------------------------------------------------------