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.

689 lines
20KB

  1. /*
  2. * Segment Juice Plugin
  3. * Copyright (C) 2014 Andre Sklenar <andre.sklenar@gmail.com>, www.juicelab.cz
  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 "SegmentJuicePlugin.hpp"
  18. START_NAMESPACE_DISTRHO
  19. // -----------------------------------------------------------------------
  20. SegmentJuicePlugin::SegmentJuicePlugin()
  21. : Plugin(paramCount, 1, 0) // 1 program, 0 states
  22. {
  23. // set default values
  24. d_setProgram(0);
  25. // reset
  26. d_deactivate();
  27. }
  28. SegmentJuicePlugin::~SegmentJuicePlugin()
  29. {
  30. }
  31. // -----------------------------------------------------------------------
  32. // Init
  33. void SegmentJuicePlugin::d_initParameter(uint32_t index, Parameter& parameter)
  34. {
  35. switch (index)
  36. {
  37. case paramWave1:
  38. parameter.hints = PARAMETER_IS_AUTOMABLE;
  39. parameter.name = "Wave1";
  40. parameter.symbol = "w1";
  41. parameter.unit = "";
  42. parameter.ranges.def = 3.0f;
  43. parameter.ranges.min = 1.0f;
  44. parameter.ranges.max = 4.0f;
  45. break;
  46. case paramWave2:
  47. parameter.hints = PARAMETER_IS_AUTOMABLE;
  48. parameter.name = "Wave2";
  49. parameter.symbol = "w2";
  50. parameter.unit = "";
  51. parameter.ranges.def = 3.0f;
  52. parameter.ranges.min = 1.0f;
  53. parameter.ranges.max = 4.0f;
  54. break;
  55. case paramWave3:
  56. parameter.hints = PARAMETER_IS_AUTOMABLE;
  57. parameter.name = "Wave3";
  58. parameter.symbol = "w3";
  59. parameter.unit = "";
  60. parameter.ranges.def = 3.0f;
  61. parameter.ranges.min = 1.0f;
  62. parameter.ranges.max = 4.0f;
  63. break;
  64. case paramWave4:
  65. parameter.hints = PARAMETER_IS_AUTOMABLE;
  66. parameter.name = "Wave4";
  67. parameter.symbol = "w4";
  68. parameter.unit = "";
  69. parameter.ranges.def = 3.0f;
  70. parameter.ranges.min = 1.0f;
  71. parameter.ranges.max = 4.0f;
  72. break;
  73. case paramWave5:
  74. parameter.hints = PARAMETER_IS_AUTOMABLE;
  75. parameter.name = "Wave5";
  76. parameter.symbol = "w5";
  77. parameter.unit = "";
  78. parameter.ranges.def = 3.0f;
  79. parameter.ranges.min = 1.0f;
  80. parameter.ranges.max = 4.0f;
  81. break;
  82. case paramWave6:
  83. parameter.hints = PARAMETER_IS_AUTOMABLE;
  84. parameter.name = "w6";
  85. parameter.symbol = "";
  86. parameter.unit = "";
  87. parameter.ranges.def = 3.0f;
  88. parameter.ranges.min = 1.0f;
  89. parameter.ranges.max = 4.0f;
  90. break;
  91. case paramFM1:
  92. parameter.hints = PARAMETER_IS_AUTOMABLE;
  93. parameter.name = "FM1";
  94. parameter.symbol = "f1";
  95. parameter.unit = "";
  96. parameter.ranges.def = 0.5f;
  97. parameter.ranges.min = 0.0f;
  98. parameter.ranges.max = 1.0f;
  99. break;
  100. case paramFM2:
  101. parameter.hints = PARAMETER_IS_AUTOMABLE;
  102. parameter.name = "FM2";
  103. parameter.symbol = "f2";
  104. parameter.unit = "";
  105. parameter.ranges.def = 0.5f;
  106. parameter.ranges.min = 0.0f;
  107. parameter.ranges.max = 1.0f;
  108. break;
  109. case paramFM3:
  110. parameter.hints = PARAMETER_IS_AUTOMABLE;
  111. parameter.name = "FM3";
  112. parameter.symbol = "f3";
  113. parameter.unit = "";
  114. parameter.ranges.def = 0.5f;
  115. parameter.ranges.min = 0.0f;
  116. parameter.ranges.max = 1.0f;
  117. break;
  118. case paramFM4:
  119. parameter.hints = PARAMETER_IS_AUTOMABLE;
  120. parameter.name = "FM4";
  121. parameter.symbol = "f4";
  122. parameter.unit = "";
  123. parameter.ranges.def = 0.5f;
  124. parameter.ranges.min = 0.0f;
  125. parameter.ranges.max = 1.0f;
  126. break;
  127. case paramFM5:
  128. parameter.hints = PARAMETER_IS_AUTOMABLE;
  129. parameter.name = "FM5";
  130. parameter.symbol = "f5";
  131. parameter.unit = "";
  132. parameter.ranges.def = 0.5f;
  133. parameter.ranges.min = 0.0f;
  134. parameter.ranges.max = 1.0f;
  135. break;
  136. case paramFM6:
  137. parameter.hints = PARAMETER_IS_AUTOMABLE;
  138. parameter.name = "FM6";
  139. parameter.symbol = "f6";
  140. parameter.unit = "";
  141. parameter.ranges.def = 0.0f;
  142. parameter.ranges.min = -1.0f;
  143. parameter.ranges.max = 1.0f;
  144. break;
  145. case paramPan1:
  146. parameter.hints = PARAMETER_IS_AUTOMABLE;
  147. parameter.name = "Pan1";
  148. parameter.symbol = "p1";
  149. parameter.unit = "";
  150. parameter.ranges.def = 0.0f;
  151. parameter.ranges.min = -1.0f;
  152. parameter.ranges.max = 1.0f;
  153. break;
  154. case paramPan2:
  155. parameter.hints = PARAMETER_IS_AUTOMABLE;
  156. parameter.name = "Pan2";
  157. parameter.symbol = "p2";
  158. parameter.unit = "";
  159. parameter.ranges.def = 0.0f;
  160. parameter.ranges.min = -1.0f;
  161. parameter.ranges.max = 1.0f;
  162. break;
  163. case paramPan3:
  164. parameter.hints = PARAMETER_IS_AUTOMABLE;
  165. parameter.name = "Pan3";
  166. parameter.symbol = "p3";
  167. parameter.unit = "";
  168. parameter.ranges.def = 0.0f;
  169. parameter.ranges.min = -1.0f;
  170. parameter.ranges.max = 1.0f;
  171. break;
  172. case paramPan4:
  173. parameter.hints = PARAMETER_IS_AUTOMABLE;
  174. parameter.name = "Pan4";
  175. parameter.symbol = "p4";
  176. parameter.unit = "";
  177. parameter.ranges.def = 0.0f;
  178. parameter.ranges.min = -1.0f;
  179. parameter.ranges.max = 1.0f;
  180. break;
  181. case paramPan5:
  182. parameter.hints = PARAMETER_IS_AUTOMABLE;
  183. parameter.name = "Pan5";
  184. parameter.symbol = "p5";
  185. parameter.unit = "";
  186. parameter.ranges.def = 0.0f;
  187. parameter.ranges.min = -1.0f;
  188. parameter.ranges.max = 1.0f;
  189. break;
  190. case paramPan6:
  191. parameter.hints = PARAMETER_IS_AUTOMABLE;
  192. parameter.name = "p6";
  193. parameter.symbol = "p6";
  194. parameter.unit = "";
  195. parameter.ranges.def = 0.0f;
  196. parameter.ranges.min = -1.0f;
  197. parameter.ranges.max = 1.0f;
  198. break;
  199. case paramAmp1:
  200. parameter.hints = PARAMETER_IS_AUTOMABLE;
  201. parameter.name = "Amp1";
  202. parameter.symbol = "a1";
  203. parameter.unit = "";
  204. parameter.ranges.def = 0.5f;
  205. parameter.ranges.min = 0.0f;
  206. parameter.ranges.max = 1.0f;
  207. break;
  208. case paramAmp2:
  209. parameter.hints = PARAMETER_IS_AUTOMABLE;
  210. parameter.name = "Amp2";
  211. parameter.symbol = "a2";
  212. parameter.unit = "";
  213. parameter.ranges.def = 0.5f;
  214. parameter.ranges.min = 0.0f;
  215. parameter.ranges.max = 1.0f;
  216. break;
  217. case paramAmp3:
  218. parameter.hints = PARAMETER_IS_AUTOMABLE;
  219. parameter.name = "Amp3";
  220. parameter.symbol = "a3";
  221. parameter.unit = "";
  222. parameter.ranges.def = 0.5f;
  223. parameter.ranges.min = 0.0f;
  224. parameter.ranges.max = 1.0f;
  225. break;
  226. case paramAmp4:
  227. parameter.hints = PARAMETER_IS_AUTOMABLE;
  228. parameter.name = "Amp4";
  229. parameter.symbol = "a4";
  230. parameter.unit = "";
  231. parameter.ranges.def = 0.5f;
  232. parameter.ranges.min = 0.0f;
  233. parameter.ranges.max = 1.0f;
  234. break;
  235. case paramAmp5:
  236. parameter.hints = PARAMETER_IS_AUTOMABLE;
  237. parameter.name = "Amp5";
  238. parameter.symbol = "a5";
  239. parameter.unit = "";
  240. parameter.ranges.def = 0.5f;
  241. parameter.ranges.min = 0.0f;
  242. parameter.ranges.max = 1.0f;
  243. break;
  244. case paramAmp6:
  245. parameter.hints = PARAMETER_IS_AUTOMABLE;
  246. parameter.name = "Amp6";
  247. parameter.symbol = "a6";
  248. parameter.unit = "";
  249. parameter.ranges.def = 0.5f;
  250. parameter.ranges.min = 0.0f;
  251. parameter.ranges.max = 1.0f;
  252. break;
  253. case paramAttack:
  254. parameter.hints = PARAMETER_IS_AUTOMABLE;
  255. parameter.name = "Attack";
  256. parameter.symbol = "att";
  257. parameter.unit = "";
  258. parameter.ranges.def = 0.0f;
  259. parameter.ranges.min = 0.0f;
  260. parameter.ranges.max = 1.0f;
  261. break;
  262. case paramDecay:
  263. parameter.hints = PARAMETER_IS_AUTOMABLE;
  264. parameter.name = "Decay";
  265. parameter.symbol = "dec";
  266. parameter.unit = "";
  267. parameter.ranges.def = 0.0f;
  268. parameter.ranges.min = 0.0f;
  269. parameter.ranges.max = 1.0f;
  270. break;
  271. case paramSustain:
  272. parameter.hints = PARAMETER_IS_AUTOMABLE;
  273. parameter.name = "Sustain";
  274. parameter.symbol = "sus";
  275. parameter.unit = "";
  276. parameter.ranges.def = 1.0f;
  277. parameter.ranges.min = 0.0f;
  278. parameter.ranges.max = 1.0f;
  279. break;
  280. case paramRelease:
  281. parameter.hints = PARAMETER_IS_AUTOMABLE;
  282. parameter.name = "Release";
  283. parameter.symbol = "rel";
  284. parameter.unit = "";
  285. parameter.ranges.def = 0.0f;
  286. parameter.ranges.min = 0.0f;
  287. parameter.ranges.max = 1.0f;
  288. break;
  289. case paramStereo:
  290. parameter.hints = PARAMETER_IS_AUTOMABLE;
  291. parameter.name = "Stereo";
  292. parameter.symbol = "str";
  293. parameter.unit = "";
  294. parameter.ranges.def = 0.0f;
  295. parameter.ranges.min = -1.0f;
  296. parameter.ranges.max = 1.0f;
  297. break;
  298. case paramTune:
  299. parameter.hints = PARAMETER_IS_AUTOMABLE;
  300. parameter.name = "Tune";
  301. parameter.symbol = "tun";
  302. parameter.unit = "";
  303. parameter.ranges.def = 0.0f;
  304. parameter.ranges.min = -1.0f;
  305. parameter.ranges.max = 1.0f;
  306. break;
  307. case paramVolume:
  308. parameter.hints = PARAMETER_IS_AUTOMABLE;
  309. parameter.name = "Volume";
  310. parameter.symbol = "vol";
  311. parameter.unit = "";
  312. parameter.ranges.def = 0.5f;
  313. parameter.ranges.min = 0.0f;
  314. parameter.ranges.max = 1.0f;
  315. break;
  316. case paramGlide:
  317. parameter.hints = PARAMETER_IS_AUTOMABLE;
  318. parameter.name = "Glide";
  319. parameter.symbol = "gld";
  320. parameter.unit = "";
  321. parameter.ranges.def = 0.0f;
  322. parameter.ranges.min = 0.0f;
  323. parameter.ranges.max = 1.0f;
  324. break;
  325. }
  326. }
  327. void SegmentJuicePlugin::d_initProgramName(uint32_t index, d_string& programName)
  328. {
  329. if (index != 0)
  330. return;
  331. programName = "Default";
  332. }
  333. // -----------------------------------------------------------------------
  334. // Internal data
  335. float SegmentJuicePlugin::d_getParameterValue(uint32_t index) const
  336. {
  337. switch (index)
  338. {
  339. case paramWave1:
  340. return wave1;
  341. case paramWave2:
  342. return wave2;
  343. case paramWave3:
  344. return wave3;
  345. case paramWave4:
  346. return wave4;
  347. case paramWave5:
  348. return wave5;
  349. case paramWave6:
  350. return wave6;
  351. case paramFM1:
  352. return FM1;
  353. case paramFM2:
  354. return FM2;
  355. case paramFM3:
  356. return FM3;
  357. case paramFM4:
  358. return FM4;
  359. case paramFM5:
  360. return FM5;
  361. case paramFM6:
  362. return FM6;
  363. case paramPan1:
  364. return pan1;
  365. case paramPan2:
  366. return pan2;
  367. case paramPan3:
  368. return pan3;
  369. case paramPan4:
  370. return pan4;
  371. case paramPan5:
  372. return pan5;
  373. case paramPan6:
  374. return pan6;
  375. case paramAmp1:
  376. return amp1;
  377. case paramAmp2:
  378. return amp2;
  379. case paramAmp3:
  380. return amp3;
  381. case paramAmp4:
  382. return amp4;
  383. case paramAmp5:
  384. return amp5;
  385. case paramAmp6:
  386. return amp6;
  387. case paramAttack:
  388. return attack;
  389. case paramDecay:
  390. return decay;
  391. case paramSustain:
  392. return sustain;
  393. case paramRelease:
  394. return release;
  395. case paramStereo:
  396. return stereo;
  397. case paramTune:
  398. return tune;
  399. case paramVolume:
  400. return volume;
  401. case paramGlide:
  402. return glide;
  403. default:
  404. return 0.0f;
  405. }
  406. }
  407. void SegmentJuicePlugin::d_setParameterValue(uint32_t index, float value)
  408. {
  409. switch (index)
  410. {
  411. case paramWave1:
  412. synthL.setWave(0, value);
  413. synthR.setWave(0, value);
  414. wave1 = value;
  415. break;
  416. case paramWave2:
  417. synthL.setWave(1, value);
  418. synthR.setWave(1, value);
  419. wave2 = value;
  420. break;
  421. case paramWave3:
  422. synthL.setWave(2, value);
  423. synthR.setWave(2, value);
  424. wave3 = value;
  425. break;
  426. case paramWave4:
  427. synthL.setWave(3, value);
  428. synthR.setWave(3, value);
  429. wave4 = value;
  430. break;
  431. case paramWave5:
  432. synthL.setWave(4, value);
  433. synthR.setWave(4, value);
  434. wave5 = value;
  435. break;
  436. case paramWave6:
  437. synthL.setWave(5, value);
  438. synthR.setWave(5, value);
  439. wave6 = value;
  440. break;
  441. case paramFM1:
  442. synthL.setFM(0, value);
  443. synthR.setFM(0, value);
  444. FM1 = value;
  445. break;
  446. case paramFM2:
  447. synthL.setFM(1, value);
  448. synthR.setFM(1, value);
  449. FM2 = value;
  450. break;
  451. case paramFM3:
  452. synthL.setFM(2, value);
  453. synthR.setFM(2, value);
  454. FM3 = value;
  455. break;
  456. case paramFM4:
  457. synthL.setFM(3, value);
  458. synthR.setFM(3, value);
  459. FM4 = value;
  460. break;
  461. case paramFM5:
  462. synthL.setFM(4, value);
  463. synthR.setFM(4, value);
  464. FM5 = value;
  465. break;
  466. case paramFM6:
  467. synthL.setFM(5, value);
  468. synthR.setFM(5, value);
  469. FM6 = value;
  470. break;
  471. case paramPan1:
  472. synthL.setPan(0, -value);
  473. synthR.setPan(0, value);
  474. pan1 = value;
  475. break;
  476. case paramPan2:
  477. synthL.setPan(1, -value);
  478. synthR.setPan(1, value);
  479. pan2 = value;
  480. break;
  481. case paramPan3:
  482. synthL.setPan(2, -value);
  483. synthR.setPan(2, value);
  484. pan3 = value;
  485. break;
  486. case paramPan4:
  487. synthL.setPan(3, -value);
  488. synthR.setPan(3, value);
  489. pan4 = value;
  490. break;
  491. case paramPan5:
  492. synthL.setPan(4, -value);
  493. synthR.setPan(4, value);
  494. pan5 = value;
  495. break;
  496. case paramPan6:
  497. synthL.setPan(5, -value);
  498. synthR.setPan(5, value);
  499. pan6 = value;
  500. break;
  501. case paramAmp1:
  502. synthL.setAmp(0, value);
  503. synthR.setAmp(0, value);
  504. amp1 = value;
  505. break;
  506. case paramAmp2:
  507. synthL.setAmp(1, value);
  508. synthR.setAmp(1, value);
  509. amp2 = value;
  510. break;
  511. case paramAmp3:
  512. synthL.setAmp(2, value);
  513. synthR.setAmp(2, value);
  514. amp3 = value;
  515. break;
  516. case paramAmp4:
  517. synthL.setAmp(3, value);
  518. synthR.setAmp(3, value);
  519. amp4 = value;
  520. break;
  521. case paramAmp5:
  522. synthL.setAmp(4, value);
  523. synthR.setAmp(4, value);
  524. amp5 = value;
  525. break;
  526. case paramAmp6:
  527. synthL.setAmp(5, value);
  528. synthR.setAmp(5, value);
  529. amp6 = value;
  530. break;
  531. case paramAttack:
  532. synthL.setAttack(value);
  533. synthR.setAttack(value);
  534. attack = value;
  535. break;
  536. case paramDecay:
  537. synthL.setDecay(value);
  538. synthR.setDecay(value);
  539. attack = value;
  540. break;
  541. case paramSustain:
  542. synthL.setSustain(value);
  543. synthR.setSustain(value);
  544. attack = value;
  545. break;
  546. case paramRelease:
  547. synthL.setRelease(value);
  548. synthR.setRelease(value);
  549. attack = value;
  550. break;
  551. case paramStereo:
  552. synthL.setStereo(-value);
  553. synthR.setStereo(value);
  554. attack = value;
  555. break;
  556. case paramTune:
  557. synthL.setTune(value);
  558. synthR.setTune(value);
  559. attack = value;
  560. break;
  561. case paramVolume:
  562. synthL.setMAmp(value);
  563. synthR.setMAmp(value);
  564. attack = value;
  565. case paramGlide:
  566. synthL.setGlide(value);
  567. synthR.setGlide(value);
  568. glide = value;
  569. break;
  570. }
  571. }
  572. void SegmentJuicePlugin::d_setProgram(uint32_t index)
  573. {
  574. if (index != 0)
  575. return;
  576. /* Default parameter values */
  577. wave1=wave2=wave3=wave4=wave5=wave6=3.0f;
  578. FM1=FM2=FM3=FM4=FM5=FM6=0.5f;
  579. pan1=pan2=pan3=pan4=pan5=pan6=0.0f;
  580. amp1=amp2=amp3=amp4=amp5=amp6=0.5f;
  581. attack=decay=release=stereo=tune=glide=0.0f;
  582. sustain=1.0f;
  583. volume=0.5f;
  584. for (int i=0; i<6; i++) {
  585. synthL.setFM(i, 0.5f);
  586. synthR.setFM(i, 0.5f);
  587. synthL.setPan(i, 0.0f);
  588. synthR.setPan(i, 0.0f);
  589. synthL.setAmp(i, 0.5f);
  590. synthR.setAmp(i, 0.5f);
  591. }
  592. /* Default variable values */
  593. synthL.setSampleRate(d_getSampleRate());
  594. synthR.setSampleRate(d_getSampleRate());
  595. synthL.setMAmp(0.5);
  596. synthR.setMAmp(0.5);
  597. synthL.setTune(0.0f);
  598. synthR.setTune(0.0f);
  599. synthL.setStereo(0.0f);
  600. synthR.setStereo(0.0f);
  601. synthL.setGlide(0.0f);
  602. synthR.setGlide(0.0f);
  603. synthL.setAttack(0.0f);
  604. synthR.setAttack(0.0f);
  605. synthL.setDecay(0.0f);
  606. synthR.setDecay(0.0f);
  607. synthL.setSustain(1.0f);
  608. synthR.setSustain(1.0f);
  609. synthL.setRelease(0.0f);
  610. synthR.setRelease(0.0f);
  611. /* reset filter values */
  612. d_activate();
  613. }
  614. // -----------------------------------------------------------------------
  615. // Process
  616. void SegmentJuicePlugin::d_activate()
  617. {
  618. }
  619. void SegmentJuicePlugin::d_deactivate()
  620. {
  621. // all values to zero
  622. }
  623. void SegmentJuicePlugin::d_run(const float**, float** outputs, uint32_t frames, const MidiEvent* midiEvents, uint32_t midiEventCount)
  624. {
  625. for (uint32_t i = 0; i<midiEventCount; i++) {
  626. int mType = midiEvents[i].buf[0] & 0xF0;
  627. //int mChan = midiEvents[i].buf[0] & 0x0F;
  628. int mNum = midiEvents[i].buf[1];
  629. if (mType == 0x90) {
  630. //note on
  631. synthL.play(mNum);
  632. synthR.play(mNum);
  633. } else if (mType == 0x80) {
  634. //note off
  635. synthL.stop(mNum);
  636. synthR.stop(mNum);
  637. }
  638. }
  639. for (uint32_t i = 0; i<frames; i++) {
  640. outputs[0][i] = synthL.run();
  641. outputs[1][i] = synthR.run();
  642. }
  643. }
  644. // -----------------------------------------------------------------------
  645. Plugin* createPlugin()
  646. {
  647. return new SegmentJuicePlugin();
  648. }
  649. // -----------------------------------------------------------------------
  650. END_NAMESPACE_DISTRHO