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.

922 lines
27KB

  1. /*
  2. * Carla Native Plugins
  3. * Copyright (C) 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 doc/GPL.txt file.
  16. */
  17. #include "CarlaNative.hpp"
  18. using namespace juce;
  19. #include "vex/cArp.h"
  20. #include "vex/cChorus.h"
  21. #include "vex/cDelay.h"
  22. #include "vex/cReverb.h"
  23. #include "vex/cSyntModule.h"
  24. // -----------------------------------------------------------------------
  25. class VexArpPlugin : public PluginClass
  26. {
  27. public:
  28. enum Params {
  29. kParamOnOff = 0,
  30. kParamLength,
  31. kParamTimeMode,
  32. kParamSyncMode,
  33. kParamFailMode,
  34. kParamVelMode,
  35. kParamCount
  36. };
  37. VexArpPlugin(const HostDescriptor* const host)
  38. : PluginClass(host),
  39. fSettings(),
  40. fArp(&fSettings)
  41. {
  42. for (int i=0; i < 8; ++i)
  43. fSettings.grid[i*10] = true;
  44. fSettings.grid[1] = true;
  45. fSettings.grid[2] = true;
  46. fSettings.grid[3] = true;
  47. fSettings.grid[41] = true;
  48. fSettings.grid[42] = true;
  49. fSettings.grid[43] = true;
  50. fSettings.grid[44] = true;
  51. fSettings.grid[45] = true;
  52. fArp.setSampleRate(getSampleRate());
  53. fMidiInBuffer.ensureSize(512*4);
  54. }
  55. protected:
  56. // -------------------------------------------------------------------
  57. // Plugin parameter calls
  58. uint32_t getParameterCount() const override
  59. {
  60. return kParamCount;
  61. }
  62. const Parameter* getParameterInfo(const uint32_t index) const override
  63. {
  64. static Parameter paramInfo;
  65. static ParameterScalePoint scalePoints[4];
  66. int hints = PARAMETER_IS_ENABLED|PARAMETER_IS_AUTOMABLE|PARAMETER_IS_INTEGER;
  67. paramInfo.name = nullptr;
  68. paramInfo.unit = nullptr;
  69. paramInfo.ranges.def = 0.0f;
  70. paramInfo.ranges.min = 0.0f;
  71. paramInfo.ranges.max = 1.0f;
  72. paramInfo.ranges.step = 1.0f;
  73. paramInfo.ranges.stepSmall = 1.0f;
  74. paramInfo.ranges.stepLarge = 1.0f;
  75. paramInfo.scalePointCount = 0;
  76. paramInfo.scalePoints = nullptr;
  77. switch (index)
  78. {
  79. case kParamOnOff:
  80. hints |= PARAMETER_IS_BOOLEAN;
  81. paramInfo.name = "On/Off";
  82. paramInfo.ranges.def = 0.0f;
  83. paramInfo.ranges.min = 0.0f;
  84. paramInfo.ranges.max = 1.0f;
  85. break;
  86. case kParamLength:
  87. paramInfo.name = "Length";
  88. paramInfo.ranges.def = 8.0f;
  89. paramInfo.ranges.min = 1.0f;
  90. paramInfo.ranges.max = 16.0f;
  91. break;
  92. case kParamTimeMode:
  93. hints |= PARAMETER_USES_SCALEPOINTS;
  94. paramInfo.name = "Time Signature";
  95. paramInfo.ranges.def = 2.0f;
  96. paramInfo.ranges.min = 1.0f;
  97. paramInfo.ranges.max = 3.0f;
  98. paramInfo.scalePointCount = 3;
  99. paramInfo.scalePoints = scalePoints;
  100. scalePoints[0].label = "8";
  101. scalePoints[1].label = "16";
  102. scalePoints[2].label = "32";
  103. scalePoints[0].value = 1.0f;
  104. scalePoints[1].value = 2.0f;
  105. scalePoints[2].value = 3.0f;
  106. break;
  107. case kParamSyncMode:
  108. hints |= PARAMETER_USES_SCALEPOINTS;
  109. paramInfo.name = "Sync Mode";
  110. paramInfo.ranges.def = 1.0f;
  111. paramInfo.ranges.min = 1.0f;
  112. paramInfo.ranges.max = 2.0f;
  113. paramInfo.scalePointCount = 2;
  114. paramInfo.scalePoints = scalePoints;
  115. scalePoints[0].label = "Key Sync";
  116. scalePoints[1].label = "Bar Sync";
  117. scalePoints[0].value = 1.0f;
  118. scalePoints[1].value = 2.0f;
  119. break;
  120. case kParamFailMode:
  121. hints |= PARAMETER_USES_SCALEPOINTS;
  122. paramInfo.name = "Fail Mode";
  123. paramInfo.ranges.def = 1.0f;
  124. paramInfo.ranges.min = 1.0f;
  125. paramInfo.ranges.max = 3.0f;
  126. paramInfo.scalePointCount = 3;
  127. paramInfo.scalePoints = scalePoints;
  128. scalePoints[0].label = "Silent Step";
  129. scalePoints[1].label = "Skip One";
  130. scalePoints[2].label = "Skip Two";
  131. scalePoints[0].value = 1.0f;
  132. scalePoints[1].value = 2.0f;
  133. scalePoints[2].value = 3.0f;
  134. break;
  135. case kParamVelMode:
  136. hints |= PARAMETER_USES_SCALEPOINTS;
  137. paramInfo.name = "Velocity Mode";
  138. paramInfo.ranges.def = 1.0f;
  139. paramInfo.ranges.min = 1.0f;
  140. paramInfo.ranges.max = 3.0f;
  141. paramInfo.scalePointCount = 3;
  142. paramInfo.scalePoints = scalePoints;
  143. scalePoints[0].label = "Pattern Velocity";
  144. scalePoints[1].label = "Input Velocity";
  145. scalePoints[2].label = "Sum Velocities";
  146. scalePoints[0].value = 1.0f;
  147. scalePoints[1].value = 2.0f;
  148. scalePoints[2].value = 3.0f;
  149. break;
  150. }
  151. paramInfo.hints = static_cast<ParameterHints>(hints);
  152. return &paramInfo;
  153. }
  154. float getParameterValue(const uint32_t index) const override
  155. {
  156. switch (index)
  157. {
  158. case kParamOnOff:
  159. return fSettings.on ? 1.0f : 0.0f;
  160. case kParamLength:
  161. return fSettings.length;
  162. case kParamTimeMode:
  163. return fSettings.timeMode;
  164. case kParamSyncMode:
  165. return fSettings.syncMode;
  166. case kParamFailMode:
  167. return fSettings.failMode;
  168. case kParamVelMode:
  169. return fSettings.velMode;
  170. default:
  171. return 0.0f;
  172. }
  173. }
  174. // -------------------------------------------------------------------
  175. // Plugin state calls
  176. void setParameterValue(const uint32_t index, const float value) override
  177. {
  178. switch (index)
  179. {
  180. case kParamOnOff:
  181. fSettings.on = (value >= 0.5f);
  182. break;
  183. case kParamLength:
  184. fSettings.length = value;
  185. break;
  186. case kParamTimeMode:
  187. fSettings.timeMode = value;
  188. break;
  189. case kParamSyncMode:
  190. fSettings.syncMode = value;
  191. break;
  192. case kParamFailMode:
  193. fSettings.failMode = value;
  194. break;
  195. case kParamVelMode:
  196. fSettings.velMode = value;
  197. break;
  198. }
  199. }
  200. // -------------------------------------------------------------------
  201. // Plugin process calls
  202. void process(float**, float**, const uint32_t frames, const MidiEvent* const midiEvents, const uint32_t midiEventCount) override
  203. {
  204. if (! fSettings.on)
  205. {
  206. for (uint32_t i=0; i < midiEventCount; ++i)
  207. writeMidiEvent(&midiEvents[i]);
  208. return;
  209. }
  210. const TimeInfo* const timeInfo(getTimeInfo());
  211. int timeFrame = 0;
  212. bool timePlaying = false;
  213. double ppqPos = 0.0;
  214. double barStartPos = 0.0;
  215. double bpm = 120.0;
  216. if (timeInfo != nullptr)
  217. {
  218. timeFrame = timeInfo->frame;
  219. timePlaying = timeInfo->playing;
  220. if (timeInfo->bbt.valid)
  221. {
  222. double ppqBar = double(timeInfo->bbt.bar - 1) * timeInfo->bbt.beatsPerBar;
  223. double ppqBeat = double(timeInfo->bbt.beat - 1);
  224. double ppqTick = double(timeInfo->bbt.tick) / timeInfo->bbt.ticksPerBeat;
  225. ppqPos = ppqBar + ppqBeat + ppqTick;
  226. barStartPos = ppqBar;
  227. bpm = timeInfo->bbt.beatsPerMinute;
  228. }
  229. }
  230. fMidiInBuffer.clear();
  231. for (uint32_t i=0; i < midiEventCount; ++i)
  232. {
  233. const MidiEvent* const midiEvent(&midiEvents[i]);
  234. fMidiInBuffer.addEvent(MidiMessage(midiEvent->data, midiEvent->size, midiEvent->time), timeFrame);
  235. }
  236. const MidiBuffer& outMidiBuffer(fArp.processMidi(fMidiInBuffer, timePlaying, ppqPos, barStartPos, bpm, frames));
  237. MidiBuffer::Iterator outBufferIterator(outMidiBuffer);
  238. MidiMessage midiMessage(0xf4);
  239. int sampleNumber;
  240. MidiEvent tmpEvent;
  241. tmpEvent.port = 0;
  242. while (outBufferIterator.getNextEvent(midiMessage, sampleNumber))
  243. {
  244. tmpEvent.size = midiMessage.getRawDataSize();
  245. tmpEvent.time = midiMessage.getTimeStamp();
  246. if (tmpEvent.size > 4)
  247. continue;
  248. std::memcpy(tmpEvent.data, midiMessage.getRawData(), sizeof(uint8_t)*tmpEvent.size);
  249. writeMidiEvent(&tmpEvent);
  250. }
  251. }
  252. // -------------------------------------------------------------------
  253. // Plugin dispatcher calls
  254. void sampleRateChanged(const double sampleRate) override
  255. {
  256. fArp.setSampleRate(sampleRate);
  257. }
  258. private:
  259. VexArpSettings fSettings;
  260. VexArp fArp;
  261. MidiBuffer fMidiInBuffer;
  262. PluginClassEND(VexArpPlugin)
  263. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(VexArpPlugin)
  264. };
  265. // -----------------------------------------------------------------------
  266. class VexChorusPlugin : public PluginClass
  267. {
  268. public:
  269. enum Params {
  270. kParamDepth = 0,
  271. kParamRate,
  272. kParamCount
  273. };
  274. VexChorusPlugin(const HostDescriptor* const host)
  275. : PluginClass(host),
  276. chorus(parameters)
  277. {
  278. parameters[0] = 0.6f;
  279. parameters[1] = 0.3f;
  280. chorus.setSampleRate(getSampleRate());
  281. }
  282. protected:
  283. // -------------------------------------------------------------------
  284. // Plugin parameter calls
  285. uint32_t getParameterCount() const override
  286. {
  287. return kParamCount;
  288. }
  289. const Parameter* getParameterInfo(const uint32_t index) const override
  290. {
  291. static Parameter paramInfo;
  292. int hints = PARAMETER_IS_ENABLED|PARAMETER_IS_AUTOMABLE;
  293. paramInfo.name = nullptr;
  294. paramInfo.unit = nullptr;
  295. paramInfo.ranges.def = 0.0f;
  296. paramInfo.ranges.min = 0.0f;
  297. paramInfo.ranges.max = 1.0f;
  298. paramInfo.ranges.step = 1.0f;
  299. paramInfo.ranges.stepSmall = 1.0f;
  300. paramInfo.ranges.stepLarge = 1.0f;
  301. paramInfo.scalePointCount = 0;
  302. paramInfo.scalePoints = nullptr;
  303. switch (index)
  304. {
  305. case kParamDepth:
  306. paramInfo.name = "Depth";
  307. paramInfo.ranges.def = 0.6f;
  308. paramInfo.ranges.min = 0.0f;
  309. paramInfo.ranges.max = 1.0f;
  310. break;
  311. case kParamRate:
  312. paramInfo.name = "Rate";
  313. paramInfo.ranges.def = 0.3f;
  314. paramInfo.ranges.min = 0.0f;
  315. paramInfo.ranges.max = 1.0f;
  316. break;
  317. }
  318. paramInfo.hints = static_cast<ParameterHints>(hints);
  319. return &paramInfo;
  320. }
  321. float getParameterValue(const uint32_t index) const override
  322. {
  323. if (index < kParamCount)
  324. return parameters[index];
  325. return 0.0f;
  326. }
  327. // -------------------------------------------------------------------
  328. // Plugin state calls
  329. void setParameterValue(const uint32_t index, const float value) override
  330. {
  331. if (index < kParamCount)
  332. parameters[index] = value;
  333. }
  334. // -------------------------------------------------------------------
  335. // Plugin process calls
  336. void process(float** const inBuffer, float** const outBuffer, const uint32_t frames, const MidiEvent* const, const uint32_t) override
  337. {
  338. if (inBuffer[0] != outBuffer[0])
  339. carla_copyFloat(outBuffer[0], inBuffer[0], frames);
  340. if (inBuffer[1] != outBuffer[1])
  341. carla_copyFloat(outBuffer[1], inBuffer[1], frames);
  342. chorus.processBlock(outBuffer[0], outBuffer[1], frames);
  343. }
  344. // -------------------------------------------------------------------
  345. // Plugin dispatcher calls
  346. void sampleRateChanged(const double sampleRate) override
  347. {
  348. chorus.setSampleRate(sampleRate);
  349. }
  350. private:
  351. VexChorus chorus;
  352. float parameters[2];
  353. PluginClassEND(VexChorusPlugin)
  354. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(VexChorusPlugin)
  355. };
  356. // -----------------------------------------------------------------------
  357. class VexDelayPlugin : public PluginClass
  358. {
  359. public:
  360. enum Params {
  361. kParamTime = 0,
  362. kParamFeedback,
  363. kParamCount
  364. };
  365. VexDelayPlugin(const HostDescriptor* const host)
  366. : PluginClass(host),
  367. delay(parameters)
  368. {
  369. parameters[0] = 4.0f;
  370. parameters[1] = 40.0f;
  371. delay.setSampleRate(getSampleRate());
  372. }
  373. protected:
  374. // -------------------------------------------------------------------
  375. // Plugin parameter calls
  376. uint32_t getParameterCount() const override
  377. {
  378. return kParamCount;
  379. }
  380. const Parameter* getParameterInfo(const uint32_t index) const override
  381. {
  382. static Parameter paramInfo;
  383. int hints = PARAMETER_IS_ENABLED|PARAMETER_IS_AUTOMABLE;
  384. paramInfo.name = nullptr;
  385. paramInfo.unit = nullptr;
  386. paramInfo.ranges.def = 0.0f;
  387. paramInfo.ranges.min = 0.0f;
  388. paramInfo.ranges.max = 1.0f;
  389. paramInfo.ranges.step = 1.0f;
  390. paramInfo.ranges.stepSmall = 1.0f;
  391. paramInfo.ranges.stepLarge = 1.0f;
  392. paramInfo.scalePointCount = 0;
  393. paramInfo.scalePoints = nullptr;
  394. switch (index)
  395. {
  396. case kParamTime:
  397. hints |= PARAMETER_IS_INTEGER;
  398. paramInfo.name = "Time";
  399. paramInfo.ranges.def = 4.0f;
  400. paramInfo.ranges.min = 0.0f;
  401. paramInfo.ranges.max = 8.0f;
  402. break;
  403. case kParamFeedback:
  404. paramInfo.name = "Feedback";
  405. paramInfo.unit = "%";
  406. paramInfo.ranges.def = 40.0f;
  407. paramInfo.ranges.min = 0.0f;
  408. paramInfo.ranges.max = 100.0f;
  409. break;
  410. }
  411. paramInfo.hints = static_cast<ParameterHints>(hints);
  412. return &paramInfo;
  413. }
  414. float getParameterValue(const uint32_t index) const override
  415. {
  416. if (index < kParamCount)
  417. return parameters[index];
  418. return 0.0f;
  419. }
  420. // -------------------------------------------------------------------
  421. // Plugin state calls
  422. void setParameterValue(const uint32_t index, const float value) override
  423. {
  424. if (index < kParamCount)
  425. parameters[index] = value;
  426. }
  427. // -------------------------------------------------------------------
  428. // Plugin process calls
  429. void process(float** const inBuffer, float** const outBuffer, const uint32_t frames, const MidiEvent* const, const uint32_t) override
  430. {
  431. if (inBuffer[0] != outBuffer[0])
  432. carla_copyFloat(outBuffer[0], inBuffer[0], frames);
  433. if (inBuffer[1] != outBuffer[1])
  434. carla_copyFloat(outBuffer[1], inBuffer[1], frames);
  435. const TimeInfo* const timeInfo(getTimeInfo());
  436. const double bpm((timeInfo != nullptr && timeInfo->bbt.valid) ? timeInfo->bbt.beatsPerMinute : 120.0);
  437. delay.processBlock(outBuffer[0], outBuffer[1], frames, bpm);
  438. }
  439. // -------------------------------------------------------------------
  440. // Plugin dispatcher calls
  441. void sampleRateChanged(const double sampleRate) override
  442. {
  443. delay.setSampleRate(sampleRate);
  444. }
  445. private:
  446. VexDelay delay;
  447. float parameters[2];
  448. PluginClassEND(VexDelayPlugin)
  449. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(VexDelayPlugin)
  450. };
  451. // -----------------------------------------------------------------------
  452. class VexReverbPlugin : public PluginClass
  453. {
  454. public:
  455. enum Params {
  456. kParamSize = 0,
  457. kParamWidth,
  458. kParamDamp,
  459. kParamCount
  460. };
  461. VexReverbPlugin(const HostDescriptor* const host)
  462. : PluginClass(host),
  463. reverb(parameters)
  464. {
  465. parameters[0] = 0.6f;
  466. parameters[1] = 0.7f;
  467. parameters[2] = 0.6f;
  468. }
  469. protected:
  470. // -------------------------------------------------------------------
  471. // Plugin parameter calls
  472. uint32_t getParameterCount() const override
  473. {
  474. return kParamCount;
  475. }
  476. const Parameter* getParameterInfo(const uint32_t index) const override
  477. {
  478. static Parameter paramInfo;
  479. int hints = PARAMETER_IS_ENABLED|PARAMETER_IS_AUTOMABLE;
  480. paramInfo.name = nullptr;
  481. paramInfo.unit = nullptr;
  482. paramInfo.ranges.def = 0.0f;
  483. paramInfo.ranges.min = 0.0f;
  484. paramInfo.ranges.max = 1.0f;
  485. paramInfo.ranges.step = 1.0f;
  486. paramInfo.ranges.stepSmall = 1.0f;
  487. paramInfo.ranges.stepLarge = 1.0f;
  488. paramInfo.scalePointCount = 0;
  489. paramInfo.scalePoints = nullptr;
  490. switch (index)
  491. {
  492. case kParamSize:
  493. paramInfo.name = "Size";
  494. paramInfo.ranges.def = 0.6f;
  495. paramInfo.ranges.min = 0.0f;
  496. paramInfo.ranges.max = 1.0f;
  497. break;
  498. case kParamWidth:
  499. paramInfo.name = "Width";
  500. paramInfo.ranges.def = 0.7f;
  501. paramInfo.ranges.min = 0.0f;
  502. paramInfo.ranges.max = 1.0f;
  503. break;
  504. case kParamDamp:
  505. paramInfo.name = "Damp";
  506. paramInfo.ranges.def = 0.6f;
  507. paramInfo.ranges.min = 0.0f;
  508. paramInfo.ranges.max = 1.0f;
  509. break;
  510. }
  511. paramInfo.hints = static_cast<ParameterHints>(hints);
  512. return &paramInfo;
  513. }
  514. float getParameterValue(const uint32_t index) const override
  515. {
  516. if (index < kParamCount)
  517. return parameters[index];
  518. return 0.0f;
  519. }
  520. // -------------------------------------------------------------------
  521. // Plugin state calls
  522. void setParameterValue(const uint32_t index, const float value) override
  523. {
  524. if (index < kParamCount)
  525. parameters[index] = value;
  526. }
  527. // -------------------------------------------------------------------
  528. // Plugin process calls
  529. void process(float** const inBuffer, float** const outBuffer, const uint32_t frames, const MidiEvent* const, const uint32_t) override
  530. {
  531. for (uint32_t i=0; i< frames; ++i)
  532. outBuffer[0][i] = inBuffer[0][i]/2.0f;
  533. for (uint32_t i=0; i< frames; ++i)
  534. outBuffer[1][i] = inBuffer[1][i]/2.0f;
  535. reverb.processBlock(outBuffer[0], outBuffer[1], frames);
  536. }
  537. private:
  538. VexReverb reverb;
  539. float parameters[3];
  540. PluginClassEND(VexReverbPlugin)
  541. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(VexReverbPlugin)
  542. };
  543. // -----------------------------------------------------------------------
  544. class VexSynthPlugin : public PluginClass
  545. {
  546. public:
  547. static const unsigned int kParamCount = 1;
  548. VexSynthPlugin(const HostDescriptor* const host)
  549. : PluginClass(host),
  550. synth(parameters)
  551. {
  552. std::memset(parameters, 0, sizeof(float)*92);
  553. for (int i = 0; i < 3; ++i)
  554. {
  555. const int offset = i * 24;
  556. parameters[offset + 1] = 0.5f;
  557. parameters[offset + 2] = 0.5f;
  558. parameters[offset + 3] = 0.5f;
  559. parameters[offset + 4] = 0.5f;
  560. parameters[offset + 5] = 0.9f;
  561. parameters[offset + 6] = 0.0f;
  562. parameters[offset + 7] = 1.0f;
  563. parameters[offset + 8] = 0.5f;
  564. parameters[offset + 9] = 0.0f;
  565. parameters[offset + 10] = 0.2f;
  566. parameters[offset + 11] = 0.0f;
  567. parameters[offset + 12] = 0.5f;
  568. parameters[offset + 13] = 0.5f;
  569. parameters[offset + 14] = 0.0f;
  570. parameters[offset + 15] = 0.3f;
  571. parameters[offset + 16] = 0.7f;
  572. parameters[offset + 17] = 0.1f;
  573. parameters[offset + 18] = 0.5f;
  574. parameters[offset + 19] = 0.5f;
  575. parameters[offset + 20] = 0.0f;
  576. parameters[offset + 21] = 0.0f;
  577. parameters[offset + 22] = 0.5f;
  578. parameters[offset + 23] = 0.5f;
  579. parameters[offset + 24] = 0.5f;
  580. }
  581. parameters[89] = 1.0f;
  582. synth.setSampleRate(getSampleRate());
  583. synth.update(89);
  584. }
  585. protected:
  586. // -------------------------------------------------------------------
  587. // Plugin parameter calls
  588. uint32_t getParameterCount() const override
  589. {
  590. return kParamCount;
  591. }
  592. const Parameter* getParameterInfo(const uint32_t index) const override
  593. {
  594. static Parameter paramInfo;
  595. int hints = PARAMETER_IS_ENABLED|PARAMETER_IS_AUTOMABLE;
  596. paramInfo.name = nullptr;
  597. paramInfo.unit = nullptr;
  598. paramInfo.ranges.def = 0.0f;
  599. paramInfo.ranges.min = 0.0f;
  600. paramInfo.ranges.max = 1.0f;
  601. paramInfo.ranges.step = 1.0f;
  602. paramInfo.ranges.stepSmall = 1.0f;
  603. paramInfo.ranges.stepLarge = 1.0f;
  604. paramInfo.scalePointCount = 0;
  605. paramInfo.scalePoints = nullptr;
  606. switch (index)
  607. {
  608. case 0:
  609. hints |= PARAMETER_IS_INTEGER;
  610. paramInfo.name = "Wave";
  611. paramInfo.ranges.def = 0.0f;
  612. paramInfo.ranges.min = 0.0f;
  613. paramInfo.ranges.max = WaveRenderer::getWaveTableSize();
  614. break;
  615. }
  616. paramInfo.hints = static_cast<ParameterHints>(hints);
  617. return &paramInfo;
  618. }
  619. float getParameterValue(const uint32_t index) const override
  620. {
  621. if (index < kParamCount)
  622. return parameters[index];
  623. return 0.0f;
  624. }
  625. // -------------------------------------------------------------------
  626. // Plugin state calls
  627. void setParameterValue(const uint32_t index, const float value) override
  628. {
  629. if (index < kParamCount)
  630. {
  631. parameters[index] = value;
  632. synth.setWaveLater(1, WaveRenderer::getWaveTableName(value));
  633. //synth.update(index);
  634. }
  635. }
  636. // -------------------------------------------------------------------
  637. // Plugin process calls
  638. void process(float**, float** outBuffer, const uint32_t frames, const MidiEvent* const midiEvents, const uint32_t midiEventCount) override
  639. {
  640. for (uint32_t i=0; i < midiEventCount; ++i)
  641. {
  642. const MidiEvent* const midiEvent(&midiEvents[i]);
  643. const uint8_t status(MIDI_GET_STATUS_FROM_DATA(midiEvent->data));
  644. if (status == MIDI_STATUS_NOTE_ON)
  645. {
  646. synth.playNote(midiEvent->data[1], midiEvent->data[2], 0, 1);
  647. }
  648. else if (status == MIDI_STATUS_NOTE_OFF)
  649. {
  650. synth.releaseNote(midiEvent->data[1], 0, 1);
  651. }
  652. else if (status == MIDI_STATUS_CONTROL_CHANGE)
  653. {
  654. const uint8_t control(midiEvent->data[1]);
  655. if (control == MIDI_CONTROL_ALL_SOUND_OFF)
  656. synth.kill();
  657. else if (control == MIDI_CONTROL_ALL_NOTES_OFF)
  658. synth.releaseAll(1);
  659. }
  660. }
  661. carla_zeroFloat(outBuffer[0], frames);
  662. carla_zeroFloat(outBuffer[1], frames);
  663. synth.doProcess(outBuffer[0], outBuffer[1], frames);
  664. }
  665. // -------------------------------------------------------------------
  666. // Plugin dispatcher calls
  667. void sampleRateChanged(const double sampleRate) override
  668. {
  669. synth.setSampleRate(sampleRate);
  670. }
  671. private:
  672. VexSyntModule synth;
  673. float parameters[92];
  674. PluginClassEND(VexSynthPlugin)
  675. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(VexSynthPlugin)
  676. };
  677. // -----------------------------------------------------------------------
  678. static const PluginDescriptor vexArpDesc = {
  679. /* category */ PLUGIN_CATEGORY_UTILITY,
  680. /* hints */ static_cast<PluginHints>(PLUGIN_USES_TIMEPOS),
  681. /* supports */ static_cast<PluginSupports>(PLUGIN_SUPPORTS_EVERYTHING),
  682. /* audioIns */ 0,
  683. /* audioOuts */ 0,
  684. /* midiIns */ 1,
  685. /* midiOuts */ 1,
  686. /* paramIns */ VexArpPlugin::kParamCount,
  687. /* paramOuts */ 0,
  688. /* name */ "VexArp",
  689. /* label */ "vexArp",
  690. /* maker */ "falkTX",
  691. /* copyright */ "GNU GPL v2+",
  692. PluginDescriptorFILL(VexArpPlugin)
  693. };
  694. static const PluginDescriptor vexChorusDesc = {
  695. /* category */ PLUGIN_CATEGORY_MODULATOR,
  696. /* hints */ static_cast<PluginHints>(PLUGIN_IS_RTSAFE),
  697. /* supports */ static_cast<PluginSupports>(0x0),
  698. /* audioIns */ 2,
  699. /* audioOuts */ 2,
  700. /* midiIns */ 0,
  701. /* midiOuts */ 0,
  702. /* paramIns */ VexChorusPlugin::kParamCount,
  703. /* paramOuts */ 0,
  704. /* name */ "VexChorus",
  705. /* label */ "vexChorus",
  706. /* maker */ "falkTX",
  707. /* copyright */ "GNU GPL v2+",
  708. PluginDescriptorFILL(VexChorusPlugin)
  709. };
  710. static const PluginDescriptor vexDelayDesc = {
  711. /* category */ PLUGIN_CATEGORY_DELAY,
  712. /* hints */ static_cast<PluginHints>(PLUGIN_IS_RTSAFE|PLUGIN_USES_TIMEPOS),
  713. /* supports */ static_cast<PluginSupports>(0x0),
  714. /* audioIns */ 2,
  715. /* audioOuts */ 2,
  716. /* midiIns */ 0,
  717. /* midiOuts */ 0,
  718. /* paramIns */ VexDelayPlugin::kParamCount,
  719. /* paramOuts */ 0,
  720. /* name */ "VexDelay",
  721. /* label */ "vexDelay",
  722. /* maker */ "falkTX",
  723. /* copyright */ "GNU GPL v2+",
  724. PluginDescriptorFILL(VexDelayPlugin)
  725. };
  726. static const PluginDescriptor vexReverbDesc = {
  727. /* category */ PLUGIN_CATEGORY_DELAY,
  728. /* hints */ static_cast<PluginHints>(PLUGIN_IS_RTSAFE),
  729. /* supports */ static_cast<PluginSupports>(0x0),
  730. /* audioIns */ 2,
  731. /* audioOuts */ 2,
  732. /* midiIns */ 0,
  733. /* midiOuts */ 0,
  734. /* paramIns */ VexReverbPlugin::kParamCount,
  735. /* paramOuts */ 0,
  736. /* name */ "VexReverb",
  737. /* label */ "vexReverb",
  738. /* maker */ "falkTX",
  739. /* copyright */ "GNU GPL v2+",
  740. PluginDescriptorFILL(VexReverbPlugin)
  741. };
  742. static const PluginDescriptor vexSynthDesc = {
  743. /* category */ PLUGIN_CATEGORY_SYNTH,
  744. /* hints */ static_cast<PluginHints>(0x0),
  745. /* supports */ static_cast<PluginSupports>(0x0),
  746. /* audioIns */ 0,
  747. /* audioOuts */ 2,
  748. /* midiIns */ 1,
  749. /* midiOuts */ 0,
  750. /* paramIns */ VexSynthPlugin::kParamCount,
  751. /* paramOuts */ 0,
  752. /* name */ "VexSynth",
  753. /* label */ "vexSynth",
  754. /* maker */ "falkTX",
  755. /* copyright */ "GNU GPL v2+",
  756. PluginDescriptorFILL(VexSynthPlugin)
  757. };
  758. // -----------------------------------------------------------------------
  759. CARLA_EXPORT
  760. void carla_register_native_plugin_vex()
  761. {
  762. carla_register_native_plugin(&vexArpDesc);
  763. carla_register_native_plugin(&vexChorusDesc);
  764. carla_register_native_plugin(&vexDelayDesc);
  765. carla_register_native_plugin(&vexReverbDesc);
  766. carla_register_native_plugin(&vexSynthDesc);
  767. }
  768. // -----------------------------------------------------------------------
  769. #include "vex/freeverb/allpass.cpp"
  770. #include "vex/freeverb/comb.cpp"
  771. #include "vex/freeverb/revmodel.cpp"
  772. #include "vex/cVoice.cpp"
  773. #include "vex/cWaveRenderer.cpp"
  774. #include "vex/ResourceFile.cpp"
  775. // -----------------------------------------------------------------------