The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

2038 lines
98KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE examples.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. The code included in this file is provided under the terms of the ISC license
  6. http://www.isc.org/downloads/software-support-policy/isc-license. Permission
  7. To use, copy, modify, and/or distribute this software for any purpose with or
  8. without fee is hereby granted provided that the above copyright notice and
  9. this permission notice appear in all copies.
  10. THE SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES,
  11. WHETHER EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR
  12. PURPOSE, ARE DISCLAIMED.
  13. ==============================================================================
  14. */
  15. /*******************************************************************************
  16. The block below describes the properties of this PIP. A PIP is a short snippet
  17. of code that can be read by the Projucer and used to generate a JUCE project.
  18. BEGIN_JUCE_PIP_METADATA
  19. name: DSPModulePluginDemo
  20. version: 1.0.0
  21. vendor: JUCE
  22. website: http://juce.com
  23. description: An audio plugin using the DSP module.
  24. dependencies: juce_audio_basics, juce_audio_devices, juce_audio_formats,
  25. juce_audio_plugin_client, juce_audio_processors,
  26. juce_audio_utils, juce_core, juce_data_structures, juce_dsp,
  27. juce_events, juce_graphics, juce_gui_basics, juce_gui_extra
  28. exporters: xcode_mac, vs2019, linux_make
  29. moduleFlags: JUCE_STRICT_REFCOUNTEDPOINTER=1
  30. type: AudioProcessor
  31. mainClass: DspModulePluginDemoAudioProcessor
  32. useLocalCopy: 1
  33. END_JUCE_PIP_METADATA
  34. *******************************************************************************/
  35. #pragma once
  36. #include "../Assets/DemoUtilities.h"
  37. namespace ID
  38. {
  39. #define PARAMETER_ID(str) constexpr const char* str { #str };
  40. PARAMETER_ID (inputGain)
  41. PARAMETER_ID (outputGain)
  42. PARAMETER_ID (pan)
  43. PARAMETER_ID (distortionEnabled)
  44. PARAMETER_ID (distortionType)
  45. PARAMETER_ID (distortionOversampler)
  46. PARAMETER_ID (distortionLowpass)
  47. PARAMETER_ID (distortionHighpass)
  48. PARAMETER_ID (distortionInGain)
  49. PARAMETER_ID (distortionCompGain)
  50. PARAMETER_ID (distortionMix)
  51. PARAMETER_ID (convolutionCabEnabled)
  52. PARAMETER_ID (convolutionReverbEnabled)
  53. PARAMETER_ID (convolutionReverbMix)
  54. PARAMETER_ID (multiBandEnabled)
  55. PARAMETER_ID (multiBandFreq)
  56. PARAMETER_ID (multiBandLowVolume)
  57. PARAMETER_ID (multiBandHighVolume)
  58. PARAMETER_ID (compressorEnabled)
  59. PARAMETER_ID (compressorThreshold)
  60. PARAMETER_ID (compressorRatio)
  61. PARAMETER_ID (compressorAttack)
  62. PARAMETER_ID (compressorRelease)
  63. PARAMETER_ID (noiseGateEnabled)
  64. PARAMETER_ID (noiseGateThreshold)
  65. PARAMETER_ID (noiseGateRatio)
  66. PARAMETER_ID (noiseGateAttack)
  67. PARAMETER_ID (noiseGateRelease)
  68. PARAMETER_ID (limiterEnabled)
  69. PARAMETER_ID (limiterThreshold)
  70. PARAMETER_ID (limiterRelease)
  71. PARAMETER_ID (directDelayEnabled)
  72. PARAMETER_ID (directDelayType)
  73. PARAMETER_ID (directDelayValue)
  74. PARAMETER_ID (directDelaySmoothing)
  75. PARAMETER_ID (directDelayMix)
  76. PARAMETER_ID (delayEffectEnabled)
  77. PARAMETER_ID (delayEffectType)
  78. PARAMETER_ID (delayEffectValue)
  79. PARAMETER_ID (delayEffectSmoothing)
  80. PARAMETER_ID (delayEffectLowpass)
  81. PARAMETER_ID (delayEffectFeedback)
  82. PARAMETER_ID (delayEffectMix)
  83. PARAMETER_ID (phaserEnabled)
  84. PARAMETER_ID (phaserRate)
  85. PARAMETER_ID (phaserDepth)
  86. PARAMETER_ID (phaserCentreFrequency)
  87. PARAMETER_ID (phaserFeedback)
  88. PARAMETER_ID (phaserMix)
  89. PARAMETER_ID (chorusEnabled)
  90. PARAMETER_ID (chorusRate)
  91. PARAMETER_ID (chorusDepth)
  92. PARAMETER_ID (chorusCentreDelay)
  93. PARAMETER_ID (chorusFeedback)
  94. PARAMETER_ID (chorusMix)
  95. PARAMETER_ID (ladderEnabled)
  96. PARAMETER_ID (ladderCutoff)
  97. PARAMETER_ID (ladderResonance)
  98. PARAMETER_ID (ladderDrive)
  99. PARAMETER_ID (ladderMode)
  100. #undef PARAMETER_ID
  101. }
  102. template <typename Func, typename... Items>
  103. constexpr void forEach (Func&& func, Items&&... items)
  104. noexcept (noexcept (std::initializer_list<int> { (func (std::forward<Items> (items)), 0)... }))
  105. {
  106. (void) std::initializer_list<int> { ((void) func (std::forward<Items> (items)), 0)... };
  107. }
  108. template <typename... Components>
  109. void addAllAndMakeVisible (Component& target, Components&... children)
  110. {
  111. forEach ([&] (Component& child) { target.addAndMakeVisible (child); }, children...);
  112. }
  113. template <typename... Processors>
  114. void prepareAll (const dsp::ProcessSpec& spec, Processors&... processors)
  115. {
  116. forEach ([&] (auto& proc) { proc.prepare (spec); }, processors...);
  117. }
  118. template <typename... Processors>
  119. void resetAll (Processors&... processors)
  120. {
  121. forEach ([] (auto& proc) { proc.reset(); }, processors...);
  122. }
  123. //==============================================================================
  124. class DspModulePluginDemo : public AudioProcessor,
  125. private ValueTree::Listener
  126. {
  127. public:
  128. DspModulePluginDemo()
  129. : DspModulePluginDemo (AudioProcessorValueTreeState::ParameterLayout{}) {}
  130. //==============================================================================
  131. void prepareToPlay (double sampleRate, int samplesPerBlock) override
  132. {
  133. const auto channels = jmax (getTotalNumInputChannels(), getTotalNumOutputChannels());
  134. if (channels == 0)
  135. return;
  136. chain.prepare ({ sampleRate, (uint32) samplesPerBlock, (uint32) channels });
  137. reset();
  138. }
  139. void reset() override
  140. {
  141. chain.reset();
  142. update();
  143. }
  144. void releaseResources() override {}
  145. void processBlock (AudioBuffer<float>& buffer, MidiBuffer&) override
  146. {
  147. if (jmax (getTotalNumInputChannels(), getTotalNumOutputChannels()) == 0)
  148. return;
  149. ScopedNoDenormals noDenormals;
  150. if (requiresUpdate.load())
  151. update();
  152. irSize = dsp::get<convolutionIndex> (chain).reverb.getCurrentIRSize();
  153. const auto totalNumInputChannels = getTotalNumInputChannels();
  154. const auto totalNumOutputChannels = getTotalNumOutputChannels();
  155. setLatencySamples (dsp::get<convolutionIndex> (chain).getLatency()
  156. + (dsp::isBypassed<distortionIndex> (chain) ? 0 : roundToInt (dsp::get<distortionIndex> (chain).getLatency())));
  157. const auto numChannels = jmax (totalNumInputChannels, totalNumOutputChannels);
  158. auto inoutBlock = dsp::AudioBlock<float> (buffer).getSubsetChannelBlock (0, (size_t) numChannels);
  159. chain.process (dsp::ProcessContextReplacing<float> (inoutBlock));
  160. }
  161. void processBlock (AudioBuffer<double>&, MidiBuffer&) override {}
  162. //==============================================================================
  163. AudioProcessorEditor* createEditor() override { return nullptr; }
  164. bool hasEditor() const override { return false; }
  165. //==============================================================================
  166. const String getName() const override { return "DSPModulePluginDemo"; }
  167. bool acceptsMidi() const override { return false; }
  168. bool producesMidi() const override { return false; }
  169. bool isMidiEffect() const override { return false; }
  170. double getTailLengthSeconds() const override { return 0.0; }
  171. //==============================================================================
  172. int getNumPrograms() override { return 1; }
  173. int getCurrentProgram() override { return 0; }
  174. void setCurrentProgram (int) override {}
  175. const String getProgramName (int) override { return {}; }
  176. void changeProgramName (int, const String&) override {}
  177. //==============================================================================
  178. void getStateInformation (MemoryBlock& destData) override
  179. {
  180. copyXmlToBinary (*apvts.copyState().createXml(), destData);
  181. }
  182. void setStateInformation (const void* data, int sizeInBytes) override
  183. {
  184. apvts.replaceState (ValueTree::fromXml (*getXmlFromBinary (data, sizeInBytes)));
  185. }
  186. int getCurrentIRSize() const { return irSize; }
  187. using Parameter = AudioProcessorValueTreeState::Parameter;
  188. // This struct holds references to the raw parameters, so that we don't have to search
  189. // the APVTS (involving string comparisons and map lookups!) every time a parameter
  190. // changes.
  191. struct ParameterReferences
  192. {
  193. template <typename Param>
  194. static Param& addToLayout (AudioProcessorValueTreeState::ParameterLayout& layout,
  195. std::unique_ptr<Param> param)
  196. {
  197. auto& ref = *param;
  198. layout.add (std::move (param));
  199. return ref;
  200. }
  201. static String valueToTextFunction (float x) { return String (x, 2); }
  202. static float textToValueFunction (const String& str) { return str.getFloatValue(); }
  203. static String valueToTextPanFunction (float x) { return getPanningTextForValue ((x + 100.0f) / 200.0f); }
  204. static float textToValuePanFunction (const String& str) { return getPanningValueForText (str) * 200.0f - 100.0f; }
  205. // Creates parameters, adds them to the layout, and stores references to the parameters
  206. // in this struct.
  207. explicit ParameterReferences (AudioProcessorValueTreeState::ParameterLayout& layout)
  208. : inputGain (addToLayout (layout,
  209. std::make_unique<Parameter> (ID::inputGain,
  210. "Input",
  211. "dB",
  212. NormalisableRange<float> (-40.0f, 40.0f),
  213. 0.0f,
  214. valueToTextFunction,
  215. textToValueFunction))),
  216. outputGain (addToLayout (layout,
  217. std::make_unique<Parameter> (ID::outputGain,
  218. "Output",
  219. "dB",
  220. NormalisableRange<float> (-40.0f, 40.0f),
  221. 0.0f,
  222. valueToTextFunction,
  223. textToValueFunction))),
  224. pan (addToLayout (layout,
  225. std::make_unique<Parameter> (ID::pan,
  226. "Panning",
  227. "",
  228. NormalisableRange<float> (-100.0f, 100.0f),
  229. 0.0f,
  230. valueToTextPanFunction,
  231. textToValuePanFunction))),
  232. distortionEnabled (addToLayout (layout,
  233. std::make_unique<AudioParameterBool> (ID::distortionEnabled,
  234. "Distortion",
  235. true,
  236. ""))),
  237. distortionType (addToLayout (layout,
  238. std::make_unique<AudioParameterChoice> (ID::distortionType,
  239. "Waveshaper",
  240. StringArray { "std::tanh", "Approx. tanh" },
  241. 0))),
  242. distortionInGain (addToLayout (layout,
  243. std::make_unique<Parameter> (ID::distortionInGain,
  244. "Gain",
  245. "dB",
  246. NormalisableRange<float> (-40.0f, 40.0f),
  247. 0.0f,
  248. valueToTextFunction,
  249. textToValueFunction))),
  250. distortionLowpass (addToLayout (layout,
  251. std::make_unique<Parameter> (ID::distortionLowpass,
  252. "Post Low-pass",
  253. "Hz",
  254. NormalisableRange<float> (20.0f, 22000.0f, 0.0f, 0.25f),
  255. 22000.0f,
  256. valueToTextFunction,
  257. textToValueFunction))),
  258. distortionHighpass (addToLayout (layout,
  259. std::make_unique<Parameter> (ID::distortionHighpass,
  260. "Pre High-pass",
  261. "Hz",
  262. NormalisableRange<float> (20.0f, 22000.0f, 0.0f, 0.25f),
  263. 20.0f,
  264. valueToTextFunction,
  265. textToValueFunction))),
  266. distortionCompGain (addToLayout (layout,
  267. std::make_unique<Parameter> (ID::distortionCompGain,
  268. "Compensat.",
  269. "dB",
  270. NormalisableRange<float> (-40.0f, 40.0f),
  271. 0.0f,
  272. valueToTextFunction,
  273. textToValueFunction))),
  274. distortionMix (addToLayout (layout,
  275. std::make_unique<Parameter> (ID::distortionMix,
  276. "Mix",
  277. "%",
  278. NormalisableRange<float> (0.0f, 100.0f),
  279. 100.0f,
  280. valueToTextFunction,
  281. textToValueFunction))),
  282. distortionOversampler (addToLayout (layout,
  283. std::make_unique<AudioParameterChoice> (ID::distortionOversampler,
  284. "Oversampling",
  285. StringArray { "2X", "4X", "8X", "2X compensated", "4X compensated", "8X compensated" },
  286. 1))),
  287. multiBandEnabled (addToLayout (layout,
  288. std::make_unique<AudioParameterBool> (ID::multiBandEnabled,
  289. "Multi-band",
  290. false,
  291. ""))),
  292. multiBandFreq (addToLayout (layout,
  293. std::make_unique<Parameter> (ID::multiBandFreq,
  294. "Sep. Freq.",
  295. "Hz",
  296. NormalisableRange<float> (20.0f, 22000.0f, 0.0f, 0.25f),
  297. 2000.0f,
  298. valueToTextFunction,
  299. textToValueFunction))),
  300. multiBandLowVolume (addToLayout (layout,
  301. std::make_unique<Parameter> (ID::multiBandLowVolume,
  302. "Low volume",
  303. "dB",
  304. NormalisableRange<float> (-40.0f, 40.0f),
  305. 0.0f,
  306. valueToTextFunction,
  307. textToValueFunction))),
  308. multiBandHighVolume (addToLayout (layout,
  309. std::make_unique<Parameter> (ID::multiBandHighVolume,
  310. "High volume",
  311. "dB",
  312. NormalisableRange<float> (-40.0f, 40.0f),
  313. 0.0f,
  314. valueToTextFunction,
  315. textToValueFunction))),
  316. convolutionCabEnabled (addToLayout (layout,
  317. std::make_unique<AudioParameterBool> (ID::convolutionCabEnabled,
  318. "Cabinet",
  319. false,
  320. ""))),
  321. convolutionReverbEnabled (addToLayout (layout,
  322. std::make_unique<AudioParameterBool> (ID::convolutionReverbEnabled,
  323. "Reverb",
  324. false,
  325. ""))),
  326. convolutionReverbMix (addToLayout (layout,
  327. std::make_unique<Parameter> (ID::convolutionReverbMix,
  328. "Reverb Mix",
  329. "%",
  330. NormalisableRange<float> (0.0f, 100.0f),
  331. 50.0f,
  332. valueToTextFunction,
  333. textToValueFunction))),
  334. compressorEnabled (addToLayout (layout,
  335. std::make_unique<AudioParameterBool> (ID::compressorEnabled,
  336. "Comp.",
  337. false,
  338. ""))),
  339. compressorThreshold (addToLayout (layout,
  340. std::make_unique<Parameter> (ID::compressorThreshold,
  341. "Threshold",
  342. "dB",
  343. NormalisableRange<float> (-100.0f, 0.0f),
  344. 0.0f,
  345. valueToTextFunction,
  346. textToValueFunction))),
  347. compressorRatio (addToLayout (layout,
  348. std::make_unique<Parameter> (ID::compressorRatio,
  349. "Ratio",
  350. ":1",
  351. NormalisableRange<float> (1.0f, 100.0f, 0.0f, 0.25f),
  352. 1.0f,
  353. valueToTextFunction,
  354. textToValueFunction))),
  355. compressorAttack (addToLayout (layout,
  356. std::make_unique<Parameter> (ID::compressorAttack,
  357. "Attack",
  358. "ms",
  359. NormalisableRange<float> (0.01f, 1000.0f, 0.0f, 0.25f),
  360. 1.0f,
  361. valueToTextFunction,
  362. textToValueFunction))),
  363. compressorRelease (addToLayout (layout,
  364. std::make_unique<Parameter> (ID::compressorRelease,
  365. "Release",
  366. "ms",
  367. NormalisableRange<float> (10.0f, 10000.0f, 0.0f, 0.25f),
  368. 100.0f,
  369. valueToTextFunction,
  370. textToValueFunction))),
  371. noiseGateEnabled (addToLayout (layout,
  372. std::make_unique<AudioParameterBool> (ID::noiseGateEnabled,
  373. "Gate",
  374. false,
  375. ""))),
  376. noiseGateThreshold (addToLayout (layout,
  377. std::make_unique<Parameter> (ID::noiseGateThreshold,
  378. "Threshold",
  379. "dB",
  380. NormalisableRange<float> (-100.0f, 0.0f),
  381. -100.0f,
  382. valueToTextFunction,
  383. textToValueFunction))),
  384. noiseGateRatio (addToLayout (layout,
  385. std::make_unique<Parameter> (ID::noiseGateRatio,
  386. "Ratio",
  387. ":1",
  388. NormalisableRange<float> (1.0f, 100.0f, 0.0f, 0.25f),
  389. 10.0f,
  390. valueToTextFunction,
  391. textToValueFunction))),
  392. noiseGateAttack (addToLayout (layout,
  393. std::make_unique<Parameter> (ID::noiseGateAttack,
  394. "Attack",
  395. "ms",
  396. NormalisableRange<float> (0.01f, 1000.0f, 0.0f, 0.25f),
  397. 1.0f,
  398. valueToTextFunction,
  399. textToValueFunction))),
  400. noiseGateRelease (addToLayout (layout,
  401. std::make_unique<Parameter> (ID::noiseGateRelease,
  402. "Release",
  403. "ms",
  404. NormalisableRange<float> (10.0f, 10000.0f, 0.0f, 0.25f),
  405. 100.0f,
  406. valueToTextFunction,
  407. textToValueFunction))),
  408. limiterEnabled (addToLayout (layout,
  409. std::make_unique<AudioParameterBool> (ID::limiterEnabled,
  410. "Limiter",
  411. false,
  412. ""))),
  413. limiterThreshold (addToLayout (layout,
  414. std::make_unique<Parameter> (ID::limiterThreshold,
  415. "Threshold",
  416. "dB",
  417. NormalisableRange<float> (-40.0f, 0.0f),
  418. 0.0f,
  419. valueToTextFunction,
  420. textToValueFunction))),
  421. limiterRelease (addToLayout (layout,
  422. std::make_unique<Parameter> (ID::limiterRelease,
  423. "Release",
  424. "ms",
  425. NormalisableRange<float> (10.0f, 10000.0f, 0.0f, 0.25f),
  426. 100.0f,
  427. valueToTextFunction,
  428. textToValueFunction))),
  429. directDelayEnabled (addToLayout (layout,
  430. std::make_unique<AudioParameterBool> (ID::directDelayEnabled,
  431. "DL Dir.",
  432. false,
  433. ""))),
  434. directDelayType (addToLayout (layout,
  435. std::make_unique<AudioParameterChoice> (ID::directDelayType,
  436. "DL Type",
  437. StringArray { "None", "Linear", "Lagrange", "Thiran" },
  438. 1))),
  439. directDelayValue (addToLayout (layout,
  440. std::make_unique<Parameter> (ID::directDelayValue,
  441. "Delay",
  442. "smps",
  443. NormalisableRange<float> (0.0f, 44100.0f),
  444. 0.0f,
  445. valueToTextFunction,
  446. textToValueFunction))),
  447. directDelaySmoothing (addToLayout (layout,
  448. std::make_unique<Parameter> (ID::directDelaySmoothing,
  449. "Smooth",
  450. "ms",
  451. NormalisableRange<float> (20.0f, 10000.0f, 0.0f, 0.25f),
  452. 200.0f,
  453. valueToTextFunction,
  454. textToValueFunction))),
  455. directDelayMix (addToLayout (layout,
  456. std::make_unique<Parameter> (ID::directDelayMix,
  457. "Delay Mix",
  458. "%",
  459. NormalisableRange<float> (0.0f, 100.0f),
  460. 50.0f,
  461. valueToTextFunction,
  462. textToValueFunction))),
  463. delayEffectEnabled (addToLayout (layout,
  464. std::make_unique<AudioParameterBool> (ID::delayEffectEnabled,
  465. "DL Effect",
  466. false,
  467. ""))),
  468. delayEffectType (addToLayout (layout,
  469. std::make_unique<AudioParameterChoice> (ID::delayEffectType,
  470. "DL Type",
  471. StringArray { "None", "Linear", "Lagrange", "Thiran" },
  472. 1))),
  473. delayEffectValue (addToLayout (layout,
  474. std::make_unique<Parameter> (ID::delayEffectValue,
  475. "Delay",
  476. "ms",
  477. NormalisableRange<float> (0.01f, 1000.0f),
  478. 100.0f,
  479. valueToTextFunction,
  480. textToValueFunction))),
  481. delayEffectSmoothing (addToLayout (layout,
  482. std::make_unique<Parameter> (ID::delayEffectSmoothing,
  483. "Smooth",
  484. "ms",
  485. NormalisableRange<float> (20.0f, 10000.0f, 0.0f, 0.25f),
  486. 400.0f,
  487. valueToTextFunction,
  488. textToValueFunction))),
  489. delayEffectLowpass (addToLayout (layout,
  490. std::make_unique<Parameter> (ID::delayEffectLowpass,
  491. "Low-pass",
  492. "Hz",
  493. NormalisableRange<float> (20.0f, 22000.0f, 0.0f, 0.25f),
  494. 22000.0f,
  495. valueToTextFunction,
  496. textToValueFunction))),
  497. delayEffectMix (addToLayout (layout,
  498. std::make_unique<Parameter> (ID::delayEffectMix,
  499. "Delay Mix",
  500. "%",
  501. NormalisableRange<float> (0.0f, 100.0f),
  502. 50.0f,
  503. valueToTextFunction,
  504. textToValueFunction))),
  505. delayEffectFeedback (addToLayout (layout,
  506. std::make_unique<Parameter> (ID::delayEffectFeedback,
  507. "Feedback",
  508. "dB",
  509. NormalisableRange<float> (-100.0f, 0.0f),
  510. -100.0f,
  511. valueToTextFunction,
  512. textToValueFunction))),
  513. phaserEnabled (addToLayout (layout,
  514. std::make_unique<AudioParameterBool> (ID::phaserEnabled,
  515. "Phaser",
  516. false,
  517. ""))),
  518. phaserRate (addToLayout (layout,
  519. std::make_unique<Parameter> (ID::phaserRate,
  520. "Rate",
  521. "Hz",
  522. NormalisableRange<float> (0.05f, 20.0f, 0.0f, 0.25f),
  523. 1.0f,
  524. valueToTextFunction,
  525. textToValueFunction))),
  526. phaserDepth (addToLayout (layout,
  527. std::make_unique<Parameter> (ID::phaserDepth,
  528. "Depth",
  529. "%",
  530. NormalisableRange<float> (0.0f, 100.0f),
  531. 50.0f,
  532. valueToTextFunction,
  533. textToValueFunction))),
  534. phaserCentreFrequency (addToLayout (layout,
  535. std::make_unique<Parameter> (ID::phaserCentreFrequency,
  536. "Center",
  537. "Hz",
  538. NormalisableRange<float> (20.0f, 20000.0f, 0.0f, 0.25f),
  539. 600.0f,
  540. valueToTextFunction,
  541. textToValueFunction))),
  542. phaserFeedback (addToLayout (layout,
  543. std::make_unique<Parameter> (ID::phaserFeedback,
  544. "Feedback",
  545. "%",
  546. NormalisableRange<float> (0.0f, 100.0f),
  547. 50.0f,
  548. valueToTextFunction,
  549. textToValueFunction))),
  550. phaserMix (addToLayout (layout,
  551. std::make_unique<Parameter> (ID::phaserMix,
  552. "Mix",
  553. "%",
  554. NormalisableRange<float> (0.0f, 100.0f),
  555. 50.0f,
  556. valueToTextFunction,
  557. textToValueFunction))),
  558. chorusEnabled (addToLayout (layout,
  559. std::make_unique<AudioParameterBool> (ID::chorusEnabled,
  560. "Chorus",
  561. false,
  562. ""))),
  563. chorusRate (addToLayout (layout,
  564. std::make_unique<Parameter> (ID::chorusRate,
  565. "Rate",
  566. "Hz",
  567. NormalisableRange<float> (0.05f, 20.0f, 0.0f, 0.25f),
  568. 1.0f,
  569. valueToTextFunction,
  570. textToValueFunction))),
  571. chorusDepth (addToLayout (layout,
  572. std::make_unique<Parameter> (ID::chorusDepth,
  573. "Depth",
  574. "%",
  575. NormalisableRange<float> (0.0f, 100.0f),
  576. 50.0f,
  577. valueToTextFunction,
  578. textToValueFunction))),
  579. chorusCentreDelay (addToLayout (layout,
  580. std::make_unique<Parameter> (ID::chorusCentreDelay,
  581. "Center",
  582. "ms",
  583. NormalisableRange<float> (1.0f, 100.0f, 0.0f, 0.25f),
  584. 7.0f,
  585. valueToTextFunction,
  586. textToValueFunction))),
  587. chorusFeedback (addToLayout (layout,
  588. std::make_unique<Parameter> (ID::chorusFeedback,
  589. "Feedback",
  590. "%",
  591. NormalisableRange<float> (0.0f, 100.0f),
  592. 50.0f,
  593. valueToTextFunction,
  594. textToValueFunction))),
  595. chorusMix (addToLayout (layout,
  596. std::make_unique<Parameter> (ID::chorusMix,
  597. "Mix",
  598. "%",
  599. NormalisableRange<float> (0.0f, 100.0f),
  600. 50.0f,
  601. valueToTextFunction,
  602. textToValueFunction))),
  603. ladderEnabled (addToLayout (layout,
  604. std::make_unique<AudioParameterBool> (ID::ladderEnabled,
  605. "Ladder",
  606. false,
  607. ""))),
  608. ladderMode (addToLayout (layout,
  609. std::make_unique<AudioParameterChoice> (ID::ladderMode,
  610. "Mode",
  611. StringArray { "LP12", "LP24", "HP12", "HP24", "BP12", "BP24" },
  612. 1))),
  613. ladderCutoff (addToLayout (layout,
  614. std::make_unique<Parameter> (ID::ladderCutoff,
  615. "Frequency",
  616. "Hz",
  617. NormalisableRange<float> (10.0f, 22000.0f, 0.0f, 0.25f),
  618. 1000.0f,
  619. valueToTextFunction,
  620. textToValueFunction))),
  621. ladderResonance (addToLayout (layout,
  622. std::make_unique<Parameter> (ID::ladderResonance,
  623. "Resonance",
  624. "%",
  625. NormalisableRange<float> (0.0f, 100.0f),
  626. 0.0f,
  627. valueToTextFunction,
  628. textToValueFunction))),
  629. ladderDrive (addToLayout (layout,
  630. std::make_unique<Parameter> (ID::ladderDrive,
  631. "Drive",
  632. "dB",
  633. NormalisableRange<float> (0.0f, 40.0f),
  634. 0.0f,
  635. valueToTextFunction,
  636. textToValueFunction)))
  637. {}
  638. Parameter& inputGain;
  639. Parameter& outputGain;
  640. Parameter& pan;
  641. AudioParameterBool& distortionEnabled;
  642. AudioParameterChoice& distortionType;
  643. Parameter& distortionInGain;
  644. Parameter& distortionLowpass;
  645. Parameter& distortionHighpass;
  646. Parameter& distortionCompGain;
  647. Parameter& distortionMix;
  648. AudioParameterChoice& distortionOversampler;
  649. AudioParameterBool& multiBandEnabled;
  650. Parameter& multiBandFreq;
  651. Parameter& multiBandLowVolume;
  652. Parameter& multiBandHighVolume;
  653. AudioParameterBool& convolutionCabEnabled;
  654. AudioParameterBool& convolutionReverbEnabled;
  655. Parameter& convolutionReverbMix;
  656. AudioParameterBool& compressorEnabled;
  657. Parameter& compressorThreshold;
  658. Parameter& compressorRatio;
  659. Parameter& compressorAttack;
  660. Parameter& compressorRelease;
  661. AudioParameterBool& noiseGateEnabled;
  662. Parameter& noiseGateThreshold;
  663. Parameter& noiseGateRatio;
  664. Parameter& noiseGateAttack;
  665. Parameter& noiseGateRelease;
  666. AudioParameterBool& limiterEnabled;
  667. Parameter& limiterThreshold;
  668. Parameter& limiterRelease;
  669. AudioParameterBool& directDelayEnabled;
  670. AudioParameterChoice& directDelayType;
  671. Parameter& directDelayValue;
  672. Parameter& directDelaySmoothing;
  673. Parameter& directDelayMix;
  674. AudioParameterBool& delayEffectEnabled;
  675. AudioParameterChoice& delayEffectType;
  676. Parameter& delayEffectValue;
  677. Parameter& delayEffectSmoothing;
  678. Parameter& delayEffectLowpass;
  679. Parameter& delayEffectMix;
  680. Parameter& delayEffectFeedback;
  681. AudioParameterBool& phaserEnabled;
  682. Parameter& phaserRate;
  683. Parameter& phaserDepth;
  684. Parameter& phaserCentreFrequency;
  685. Parameter& phaserFeedback;
  686. Parameter& phaserMix;
  687. AudioParameterBool& chorusEnabled;
  688. Parameter& chorusRate;
  689. Parameter& chorusDepth;
  690. Parameter& chorusCentreDelay;
  691. Parameter& chorusFeedback;
  692. Parameter& chorusMix;
  693. AudioParameterBool& ladderEnabled;
  694. AudioParameterChoice& ladderMode;
  695. Parameter& ladderCutoff;
  696. Parameter& ladderResonance;
  697. Parameter& ladderDrive;
  698. };
  699. const ParameterReferences& getParameterValues() const noexcept { return parameters; }
  700. //==============================================================================
  701. // We store this here so that the editor retains its state if it is closed and reopened
  702. int indexTab = 0;
  703. private:
  704. struct LayoutAndReferences
  705. {
  706. AudioProcessorValueTreeState::ParameterLayout layout;
  707. ParameterReferences references;
  708. };
  709. explicit DspModulePluginDemo (AudioProcessorValueTreeState::ParameterLayout layout)
  710. : AudioProcessor (BusesProperties().withInput ("In", AudioChannelSet::stereo())
  711. .withOutput ("Out", AudioChannelSet::stereo())),
  712. parameters { layout },
  713. apvts { *this, nullptr, "state", std::move (layout) }
  714. {
  715. apvts.state.addListener (this);
  716. forEach ([] (dsp::Gain<float>& gain) { gain.setRampDurationSeconds (0.05); },
  717. dsp::get<inputGainIndex> (chain),
  718. dsp::get<outputGainIndex> (chain));
  719. dsp::get<pannerIndex> (chain).setRule (dsp::PannerRule::linear);
  720. }
  721. //==============================================================================
  722. void valueTreePropertyChanged (ValueTree&, const Identifier&) override
  723. {
  724. requiresUpdate.store (true);
  725. }
  726. //==============================================================================
  727. void update()
  728. {
  729. {
  730. DistortionProcessor& distortion = dsp::get<distortionIndex> (chain);
  731. if (distortion.currentIndexOversampling != parameters.distortionOversampler.getIndex())
  732. {
  733. distortion.currentIndexOversampling = parameters.distortionOversampler.getIndex();
  734. prepareToPlay (getSampleRate(), getBlockSize());
  735. return;
  736. }
  737. distortion.currentIndexWaveshaper = parameters.distortionType.getIndex();
  738. distortion.lowpass .setCutoffFrequency (parameters.distortionLowpass.get());
  739. distortion.highpass.setCutoffFrequency (parameters.distortionHighpass.get());
  740. distortion.distGain.setGainDecibels (parameters.distortionInGain.get());
  741. distortion.compGain.setGainDecibels (parameters.distortionCompGain.get());
  742. distortion.mixer.setWetMixProportion (parameters.distortionMix.get() / 100.0f);
  743. dsp::setBypassed<distortionIndex> (chain, ! parameters.distortionEnabled);
  744. }
  745. {
  746. ConvolutionProcessor& convolution = dsp::get<convolutionIndex> (chain);
  747. convolution.cabEnabled = parameters.convolutionCabEnabled;
  748. convolution.reverbEnabled = parameters.convolutionReverbEnabled;
  749. convolution.mixer.setWetMixProportion (parameters.convolutionReverbMix.get() / 100.0f);
  750. }
  751. dsp::get<inputGainIndex> (chain).setGainDecibels (parameters.inputGain.get());
  752. dsp::get<outputGainIndex> (chain).setGainDecibels (parameters.outputGain.get());
  753. dsp::get<pannerIndex> (chain).setPan (parameters.pan.get() / 100.0f);
  754. {
  755. MultiBandProcessor& multiband = dsp::get<multiBandIndex> (chain);
  756. const auto multibandFreq = parameters.multiBandFreq.get();
  757. multiband.lowpass .setCutoffFrequency (multibandFreq);
  758. multiband.highpass.setCutoffFrequency (multibandFreq);
  759. const bool enabled = parameters.multiBandEnabled;
  760. multiband.lowVolume .setGainDecibels (enabled ? parameters.multiBandLowVolume .get() : 0.0f);
  761. multiband.highVolume.setGainDecibels (enabled ? parameters.multiBandHighVolume.get() : 0.0f);
  762. dsp::setBypassed<multiBandIndex> (chain, ! enabled);
  763. }
  764. {
  765. dsp::Compressor<float>& compressor = dsp::get<compressorIndex> (chain);
  766. compressor.setThreshold (parameters.compressorThreshold.get());
  767. compressor.setRatio (parameters.compressorRatio.get());
  768. compressor.setAttack (parameters.compressorAttack.get());
  769. compressor.setRelease (parameters.compressorRelease.get());
  770. dsp::setBypassed<compressorIndex> (chain, ! parameters.compressorEnabled);
  771. }
  772. {
  773. dsp::NoiseGate<float>& noiseGate = dsp::get<noiseGateIndex> (chain);
  774. noiseGate.setThreshold (parameters.noiseGateThreshold.get());
  775. noiseGate.setRatio (parameters.noiseGateRatio.get());
  776. noiseGate.setAttack (parameters.noiseGateAttack.get());
  777. noiseGate.setRelease (parameters.noiseGateRelease.get());
  778. dsp::setBypassed<noiseGateIndex> (chain, ! parameters.noiseGateEnabled);
  779. }
  780. {
  781. dsp::Limiter<float>& limiter = dsp::get<limiterIndex> (chain);
  782. limiter.setThreshold (parameters.limiterThreshold.get());
  783. limiter.setRelease (parameters.limiterRelease.get());
  784. dsp::setBypassed<limiterIndex> (chain, ! parameters.limiterEnabled);
  785. }
  786. {
  787. DirectDelayProcessor& delay = dsp::get<directDelayIndex> (chain);
  788. delay.delayLineDirectType = parameters.directDelayType.getIndex();
  789. std::fill (delay.delayDirectValue.begin(),
  790. delay.delayDirectValue.end(),
  791. (double) parameters.directDelayValue.get());
  792. delay.smoothFilter.setCutoffFrequency (1000.0 / parameters.directDelaySmoothing.get());
  793. delay.mixer.setWetMixProportion (parameters.directDelayMix.get() / 100.0f);
  794. dsp::setBypassed<directDelayIndex> (chain, ! parameters.directDelayEnabled);
  795. }
  796. {
  797. DelayEffectProcessor& delay = dsp::get<delayEffectIndex> (chain);
  798. delay.delayEffectType = parameters.delayEffectType.getIndex();
  799. std::fill (delay.delayEffectValue.begin(),
  800. delay.delayEffectValue.end(),
  801. (double) parameters.delayEffectValue.get() / 1000.0 * getSampleRate());
  802. const auto feedbackGain = Decibels::decibelsToGain (parameters.delayEffectFeedback.get(), -100.0f);
  803. for (auto& volume : delay.delayFeedbackVolume)
  804. volume.setTargetValue (feedbackGain);
  805. delay.smoothFilter.setCutoffFrequency (1000.0 / parameters.delayEffectSmoothing.get());
  806. delay.lowpass.setCutoffFrequency (parameters.delayEffectLowpass.get());
  807. delay.mixer.setWetMixProportion (parameters.delayEffectMix.get() / 100.0f);
  808. dsp::setBypassed<delayEffectIndex> (chain, ! parameters.delayEffectEnabled);
  809. }
  810. {
  811. dsp::Phaser<float>& phaser = dsp::get<phaserIndex> (chain);
  812. phaser.setRate (parameters.phaserRate.get());
  813. phaser.setDepth (parameters.phaserDepth.get() / 100.0f);
  814. phaser.setCentreFrequency (parameters.phaserCentreFrequency.get());
  815. phaser.setFeedback (parameters.phaserFeedback.get() / 100.0f * 0.95f);
  816. phaser.setMix (parameters.phaserMix.get() / 100.0f);
  817. dsp::setBypassed<phaserIndex> (chain, ! parameters.phaserEnabled);
  818. }
  819. {
  820. dsp::Chorus<float>& chorus = dsp::get<chorusIndex> (chain);
  821. chorus.setRate (parameters.chorusRate.get());
  822. chorus.setDepth (parameters.chorusDepth.get() / 100.0f);
  823. chorus.setCentreDelay (parameters.chorusCentreDelay.get());
  824. chorus.setFeedback (parameters.chorusFeedback.get() / 100.0f * 0.95f);
  825. chorus.setMix (parameters.chorusMix.get() / 100.0f);
  826. dsp::setBypassed<chorusIndex> (chain, ! parameters.chorusEnabled);
  827. }
  828. {
  829. dsp::LadderFilter<float>& ladder = dsp::get<ladderIndex> (chain);
  830. ladder.setCutoffFrequencyHz (parameters.ladderCutoff.get());
  831. ladder.setResonance (parameters.ladderResonance.get() / 100.0f);
  832. ladder.setDrive (Decibels::decibelsToGain (parameters.ladderDrive.get()));
  833. ladder.setMode ([&]
  834. {
  835. switch (parameters.ladderMode.getIndex())
  836. {
  837. case 0: return dsp::LadderFilterMode::LPF12;
  838. case 1: return dsp::LadderFilterMode::LPF24;
  839. case 2: return dsp::LadderFilterMode::HPF12;
  840. case 3: return dsp::LadderFilterMode::HPF24;
  841. case 4: return dsp::LadderFilterMode::BPF12;
  842. default: break;
  843. }
  844. return dsp::LadderFilterMode::BPF24;
  845. }());
  846. dsp::setBypassed<ladderIndex> (chain, ! parameters.ladderEnabled);
  847. }
  848. requiresUpdate.store (false);
  849. }
  850. //==============================================================================
  851. static String getPanningTextForValue (float value)
  852. {
  853. if (value == 0.5f)
  854. return "center";
  855. if (value < 0.5f)
  856. return String (roundToInt ((0.5f - value) * 200.0f)) + "%L";
  857. return String (roundToInt ((value - 0.5f) * 200.0f)) + "%R";
  858. }
  859. static float getPanningValueForText (String strText)
  860. {
  861. if (strText.compareIgnoreCase ("center") == 0 || strText.compareIgnoreCase ("c") == 0)
  862. return 0.5f;
  863. strText = strText.trim();
  864. if (strText.indexOfIgnoreCase ("%L") != -1)
  865. {
  866. auto percentage = (float) strText.substring (0, strText.indexOf ("%")).getDoubleValue();
  867. return (100.0f - percentage) / 100.0f * 0.5f;
  868. }
  869. if (strText.indexOfIgnoreCase ("%R") != -1)
  870. {
  871. auto percentage = (float) strText.substring (0, strText.indexOf ("%")).getDoubleValue();
  872. return percentage / 100.0f * 0.5f + 0.5f;
  873. }
  874. return 0.5f;
  875. }
  876. //==============================================================================
  877. struct DistortionProcessor
  878. {
  879. DistortionProcessor()
  880. {
  881. forEach ([] (dsp::Gain<float>& gain) { gain.setRampDurationSeconds (0.05); },
  882. distGain,
  883. compGain);
  884. lowpass.setType (dsp::FirstOrderTPTFilterType::lowpass);
  885. highpass.setType (dsp::FirstOrderTPTFilterType::highpass);
  886. mixer.setMixingRule (dsp::DryWetMixingRule::linear);
  887. }
  888. void prepare (const dsp::ProcessSpec& spec)
  889. {
  890. for (auto& oversampler : oversamplers)
  891. oversampler.initProcessing (spec.maximumBlockSize);
  892. prepareAll (spec, lowpass, highpass, distGain, compGain, mixer);
  893. }
  894. void reset()
  895. {
  896. for (auto& oversampler : oversamplers)
  897. oversampler.reset();
  898. resetAll (lowpass, highpass, distGain, compGain, mixer);
  899. }
  900. float getLatency() const
  901. {
  902. return oversamplers[size_t (currentIndexOversampling)].getLatencyInSamples();
  903. }
  904. template <typename Context>
  905. void process (Context& context)
  906. {
  907. if (context.isBypassed)
  908. return;
  909. const auto& inputBlock = context.getInputBlock();
  910. mixer.setWetLatency (getLatency());
  911. mixer.pushDrySamples (inputBlock);
  912. distGain.process (context);
  913. highpass.process (context);
  914. auto ovBlock = oversamplers[size_t (currentIndexOversampling)].processSamplesUp (inputBlock);
  915. dsp::ProcessContextReplacing<float> waveshaperContext (ovBlock);
  916. if (isPositiveAndBelow (currentIndexWaveshaper, waveShapers.size()))
  917. {
  918. waveShapers[size_t (currentIndexWaveshaper)].process (waveshaperContext);
  919. if (currentIndexWaveshaper == 1)
  920. clipping.process (waveshaperContext);
  921. waveshaperContext.getOutputBlock() *= 0.7f;
  922. }
  923. auto& outputBlock = context.getOutputBlock();
  924. oversamplers[size_t (currentIndexOversampling)].processSamplesDown (outputBlock);
  925. lowpass.process (context);
  926. compGain.process (context);
  927. mixer.mixWetSamples (outputBlock);
  928. }
  929. std::array<dsp::Oversampling<float>, 6> oversamplers
  930. { {
  931. { 2, 1, dsp::Oversampling<float>::filterHalfBandPolyphaseIIR, true, false },
  932. { 2, 2, dsp::Oversampling<float>::filterHalfBandPolyphaseIIR, true, false },
  933. { 2, 3, dsp::Oversampling<float>::filterHalfBandPolyphaseIIR, true, false },
  934. { 2, 1, dsp::Oversampling<float>::filterHalfBandPolyphaseIIR, true, true },
  935. { 2, 2, dsp::Oversampling<float>::filterHalfBandPolyphaseIIR, true, true },
  936. { 2, 3, dsp::Oversampling<float>::filterHalfBandPolyphaseIIR, true, true },
  937. } };
  938. static float clip (float in) { return juce::jlimit (-1.0f, 1.0f, in); }
  939. dsp::FirstOrderTPTFilter<float> lowpass, highpass;
  940. dsp::Gain<float> distGain, compGain;
  941. dsp::DryWetMixer<float> mixer { 10 };
  942. std::array<dsp::WaveShaper<float>, 2> waveShapers { { { std::tanh },
  943. { dsp::FastMathApproximations::tanh } } };
  944. dsp::WaveShaper<float> clipping { clip };
  945. int currentIndexOversampling = 0;
  946. int currentIndexWaveshaper = 0;
  947. };
  948. struct ConvolutionProcessor
  949. {
  950. ConvolutionProcessor()
  951. {
  952. loadImpulseResponse (cabinet, "guitar_amp.wav");
  953. loadImpulseResponse (reverb, "reverb_ir.wav");
  954. mixer.setMixingRule (dsp::DryWetMixingRule::balanced);
  955. }
  956. void prepare (const dsp::ProcessSpec& spec)
  957. {
  958. prepareAll (spec, cabinet, reverb, mixer);
  959. }
  960. void reset()
  961. {
  962. resetAll (cabinet, reverb, mixer);
  963. }
  964. template <typename Context>
  965. void process (Context& context)
  966. {
  967. auto contextConv = context;
  968. contextConv.isBypassed = (! cabEnabled) || context.isBypassed;
  969. cabinet.process (contextConv);
  970. if (cabEnabled)
  971. context.getOutputBlock().multiplyBy (4.0f);
  972. if (reverbEnabled)
  973. mixer.pushDrySamples (context.getInputBlock());
  974. contextConv.isBypassed = (! reverbEnabled) || context.isBypassed;
  975. reverb.process (contextConv);
  976. if (reverbEnabled)
  977. {
  978. const auto& outputBlock = context.getOutputBlock();
  979. outputBlock.multiplyBy (4.0f);
  980. mixer.mixWetSamples (outputBlock);
  981. }
  982. }
  983. int getLatency() const
  984. {
  985. auto latency = 0;
  986. if (cabEnabled)
  987. latency += cabinet.getLatency();
  988. if (reverbEnabled)
  989. latency += reverb.getLatency();
  990. return latency;
  991. }
  992. dsp::ConvolutionMessageQueue queue;
  993. dsp::Convolution cabinet { dsp::Convolution::NonUniform { 512 }, queue };
  994. dsp::Convolution reverb { dsp::Convolution::NonUniform { 512 }, queue };
  995. dsp::DryWetMixer<float> mixer;
  996. bool cabEnabled = false, reverbEnabled = false;
  997. private:
  998. static void loadImpulseResponse (dsp::Convolution& convolution, const char* filename)
  999. {
  1000. auto stream = createAssetInputStream (filename);
  1001. if (stream == nullptr)
  1002. {
  1003. jassertfalse;
  1004. return;
  1005. }
  1006. AudioFormatManager manager;
  1007. manager.registerBasicFormats();
  1008. std::unique_ptr<AudioFormatReader> reader { manager.createReaderFor (std::move (stream)) };
  1009. if (reader == nullptr)
  1010. {
  1011. jassertfalse;
  1012. return;
  1013. }
  1014. AudioBuffer<float> buffer (static_cast<int> (reader->numChannels),
  1015. static_cast<int> (reader->lengthInSamples));
  1016. reader->read (buffer.getArrayOfWritePointers(), buffer.getNumChannels(), 0, buffer.getNumSamples());
  1017. convolution.loadImpulseResponse (std::move (buffer),
  1018. reader->sampleRate,
  1019. dsp::Convolution::Stereo::yes,
  1020. dsp::Convolution::Trim::yes,
  1021. dsp::Convolution::Normalise::yes);
  1022. }
  1023. };
  1024. struct MultiBandProcessor
  1025. {
  1026. MultiBandProcessor()
  1027. {
  1028. forEach ([] (dsp::Gain<float>& gain) { gain.setRampDurationSeconds (0.05); },
  1029. lowVolume,
  1030. highVolume);
  1031. lowpass .setType (dsp::LinkwitzRileyFilterType::lowpass);
  1032. highpass.setType (dsp::LinkwitzRileyFilterType::highpass);
  1033. }
  1034. void prepare (const dsp::ProcessSpec& spec)
  1035. {
  1036. prepareAll (spec, lowpass, highpass, lowVolume, highVolume);
  1037. bufferSeparation.setSize (4, int (spec.maximumBlockSize), false, false, true);
  1038. }
  1039. void reset()
  1040. {
  1041. resetAll (lowpass, highpass, lowVolume, highVolume);
  1042. }
  1043. template <typename Context>
  1044. void process (Context& context)
  1045. {
  1046. const auto& inputBlock = context.getInputBlock();
  1047. const auto numSamples = inputBlock.getNumSamples();
  1048. const auto numChannels = inputBlock.getNumChannels();
  1049. auto sepBlock = dsp::AudioBlock<float> (bufferSeparation).getSubBlock (0, (size_t) numSamples);
  1050. auto sepLowBlock = sepBlock.getSubsetChannelBlock (0, (size_t) numChannels);
  1051. auto sepHighBlock = sepBlock.getSubsetChannelBlock (2, (size_t) numChannels);
  1052. sepLowBlock .copyFrom (inputBlock);
  1053. sepHighBlock.copyFrom (inputBlock);
  1054. auto contextLow = dsp::ProcessContextReplacing<float> (sepLowBlock);
  1055. contextLow.isBypassed = context.isBypassed;
  1056. lowpass .process (contextLow);
  1057. lowVolume.process (contextLow);
  1058. auto contextHigh = dsp::ProcessContextReplacing<float> (sepHighBlock);
  1059. contextHigh.isBypassed = context.isBypassed;
  1060. highpass .process (contextHigh);
  1061. highVolume.process (contextHigh);
  1062. if (! context.isBypassed)
  1063. {
  1064. sepLowBlock.add (sepHighBlock);
  1065. context.getOutputBlock().copyFrom (sepLowBlock);
  1066. }
  1067. }
  1068. dsp::LinkwitzRileyFilter<float> lowpass, highpass;
  1069. dsp::Gain<float> lowVolume, highVolume;
  1070. AudioBuffer<float> bufferSeparation;
  1071. };
  1072. struct DirectDelayProcessor
  1073. {
  1074. DirectDelayProcessor()
  1075. {
  1076. smoothFilter.setType (dsp::FirstOrderTPTFilterType::lowpass);
  1077. mixer.setMixingRule (dsp::DryWetMixingRule::linear);
  1078. }
  1079. void prepare (const dsp::ProcessSpec& spec)
  1080. {
  1081. prepareAll (spec, noInterpolation, linear, lagrange, thiran, smoothFilter, mixer);
  1082. }
  1083. void reset()
  1084. {
  1085. resetAll (noInterpolation, linear, lagrange, thiran, smoothFilter, mixer);
  1086. }
  1087. template <typename Context>
  1088. void process (Context& context)
  1089. {
  1090. if (context.isBypassed)
  1091. return;
  1092. const auto& inputBlock = context.getInputBlock();
  1093. const auto& outputBlock = context.getOutputBlock();
  1094. mixer.pushDrySamples (inputBlock);
  1095. const auto numChannels = inputBlock.getNumChannels();
  1096. const auto numSamples = inputBlock.getNumSamples();
  1097. for (size_t channel = 0; channel < numChannels; ++channel)
  1098. {
  1099. auto* samplesIn = inputBlock .getChannelPointer (channel);
  1100. auto* samplesOut = outputBlock.getChannelPointer (channel);
  1101. for (size_t i = 0; i < numSamples; ++i)
  1102. {
  1103. const auto delay = smoothFilter.processSample (int (channel), delayDirectValue[channel]);
  1104. samplesOut[i] = [&]
  1105. {
  1106. switch (delayLineDirectType)
  1107. {
  1108. case 0:
  1109. noInterpolation.pushSample (int (channel), samplesIn[i]);
  1110. noInterpolation.setDelay ((float) delay);
  1111. return noInterpolation.popSample (int (channel));
  1112. case 1:
  1113. linear.pushSample (int (channel), samplesIn[i]);
  1114. linear.setDelay ((float) delay);
  1115. return linear.popSample (int (channel));
  1116. case 2:
  1117. lagrange.pushSample (int (channel), samplesIn[i]);
  1118. lagrange.setDelay ((float) delay);
  1119. return lagrange.popSample (int (channel));
  1120. case 3:
  1121. thiran.pushSample (int (channel), samplesIn[i]);
  1122. thiran.setDelay ((float) delay);
  1123. return thiran.popSample (int (channel));
  1124. default:
  1125. break;
  1126. }
  1127. jassertfalse;
  1128. return 0.0f;
  1129. }();
  1130. }
  1131. }
  1132. mixer.mixWetSamples (outputBlock);
  1133. }
  1134. static constexpr auto directDelayBufferSize = 44100;
  1135. dsp::DelayLine<float, dsp::DelayLineInterpolationTypes::None> noInterpolation { directDelayBufferSize };
  1136. dsp::DelayLine<float, dsp::DelayLineInterpolationTypes::Linear> linear { directDelayBufferSize };
  1137. dsp::DelayLine<float, dsp::DelayLineInterpolationTypes::Lagrange3rd> lagrange { directDelayBufferSize };
  1138. dsp::DelayLine<float, dsp::DelayLineInterpolationTypes::Thiran> thiran { directDelayBufferSize };
  1139. // Double precision to avoid some approximation issues
  1140. dsp::FirstOrderTPTFilter<double> smoothFilter;
  1141. dsp::DryWetMixer<float> mixer;
  1142. std::array<double, 2> delayDirectValue { {} };
  1143. int delayLineDirectType = 1;
  1144. };
  1145. struct DelayEffectProcessor
  1146. {
  1147. DelayEffectProcessor()
  1148. {
  1149. smoothFilter.setType (dsp::FirstOrderTPTFilterType::lowpass);
  1150. lowpass.setType (dsp::FirstOrderTPTFilterType::lowpass);
  1151. mixer.setMixingRule (dsp::DryWetMixingRule::linear);
  1152. }
  1153. void prepare (const dsp::ProcessSpec& spec)
  1154. {
  1155. prepareAll (spec, noInterpolation, linear, lagrange, thiran, smoothFilter, lowpass, mixer);
  1156. for (auto& volume : delayFeedbackVolume)
  1157. volume.reset (spec.sampleRate, 0.05);
  1158. }
  1159. void reset()
  1160. {
  1161. resetAll (noInterpolation, linear, lagrange, thiran, smoothFilter, lowpass, mixer);
  1162. std::fill (lastDelayEffectOutput.begin(), lastDelayEffectOutput.end(), 0.0f);
  1163. }
  1164. template <typename Context>
  1165. void process (Context& context)
  1166. {
  1167. if (context.isBypassed)
  1168. return;
  1169. const auto& inputBlock = context.getInputBlock();
  1170. const auto& outputBlock = context.getOutputBlock();
  1171. const auto numSamples = inputBlock.getNumSamples();
  1172. const auto numChannels = inputBlock.getNumChannels();
  1173. mixer.pushDrySamples (inputBlock);
  1174. for (size_t channel = 0; channel < numChannels; ++channel)
  1175. {
  1176. auto* samplesIn = inputBlock .getChannelPointer (channel);
  1177. auto* samplesOut = outputBlock.getChannelPointer (channel);
  1178. for (size_t i = 0; i < numSamples; ++i)
  1179. {
  1180. auto input = samplesIn[i] - lastDelayEffectOutput[channel];
  1181. auto delay = smoothFilter.processSample (int (channel), delayEffectValue[channel]);
  1182. const auto output = [&]
  1183. {
  1184. switch (delayEffectType)
  1185. {
  1186. case 0:
  1187. noInterpolation.pushSample (int (channel), input);
  1188. noInterpolation.setDelay ((float) delay);
  1189. return noInterpolation.popSample (int (channel));
  1190. case 1:
  1191. linear.pushSample (int (channel), input);
  1192. linear.setDelay ((float) delay);
  1193. return linear.popSample (int (channel));
  1194. case 2:
  1195. lagrange.pushSample (int (channel), input);
  1196. lagrange.setDelay ((float) delay);
  1197. return lagrange.popSample (int (channel));
  1198. case 3:
  1199. thiran.pushSample (int (channel), input);
  1200. thiran.setDelay ((float) delay);
  1201. return thiran.popSample (int (channel));
  1202. default:
  1203. break;
  1204. }
  1205. jassertfalse;
  1206. return 0.0f;
  1207. }();
  1208. const auto processed = lowpass.processSample (int (channel), output);
  1209. samplesOut[i] = processed;
  1210. lastDelayEffectOutput[channel] = processed * delayFeedbackVolume[channel].getNextValue();
  1211. }
  1212. }
  1213. mixer.mixWetSamples (outputBlock);
  1214. }
  1215. static constexpr auto effectDelaySamples = 192000;
  1216. dsp::DelayLine<float, dsp::DelayLineInterpolationTypes::None> noInterpolation { effectDelaySamples };
  1217. dsp::DelayLine<float, dsp::DelayLineInterpolationTypes::Linear> linear { effectDelaySamples };
  1218. dsp::DelayLine<float, dsp::DelayLineInterpolationTypes::Lagrange3rd> lagrange { effectDelaySamples };
  1219. dsp::DelayLine<float, dsp::DelayLineInterpolationTypes::Thiran> thiran { effectDelaySamples };
  1220. // Double precision to avoid some approximation issues
  1221. dsp::FirstOrderTPTFilter<double> smoothFilter;
  1222. std::array<double, 2> delayEffectValue;
  1223. std::array<LinearSmoothedValue<float>, 2> delayFeedbackVolume;
  1224. dsp::FirstOrderTPTFilter<float> lowpass;
  1225. dsp::DryWetMixer<float> mixer;
  1226. std::array<float, 2> lastDelayEffectOutput;
  1227. int delayEffectType = 1;
  1228. };
  1229. ParameterReferences parameters;
  1230. AudioProcessorValueTreeState apvts;
  1231. using Chain = dsp::ProcessorChain<dsp::NoiseGate<float>,
  1232. dsp::Gain<float>,
  1233. DirectDelayProcessor,
  1234. MultiBandProcessor,
  1235. dsp::Compressor<float>,
  1236. dsp::Phaser<float>,
  1237. dsp::Chorus<float>,
  1238. DistortionProcessor,
  1239. dsp::LadderFilter<float>,
  1240. DelayEffectProcessor,
  1241. ConvolutionProcessor,
  1242. dsp::Limiter<float>,
  1243. dsp::Gain<float>,
  1244. dsp::Panner<float>>;
  1245. Chain chain;
  1246. // We use this enum to index into the chain above
  1247. enum ProcessorIndices
  1248. {
  1249. noiseGateIndex,
  1250. inputGainIndex,
  1251. directDelayIndex,
  1252. multiBandIndex,
  1253. compressorIndex,
  1254. phaserIndex,
  1255. chorusIndex,
  1256. distortionIndex,
  1257. ladderIndex,
  1258. delayEffectIndex,
  1259. convolutionIndex,
  1260. limiterIndex,
  1261. outputGainIndex,
  1262. pannerIndex
  1263. };
  1264. //==============================================================================
  1265. std::atomic<bool> requiresUpdate { true };
  1266. std::atomic<int> irSize { 0 };
  1267. //==============================================================================
  1268. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DspModulePluginDemo)
  1269. };
  1270. //==============================================================================
  1271. class DspModulePluginDemoEditor : public AudioProcessorEditor
  1272. {
  1273. public:
  1274. explicit DspModulePluginDemoEditor (DspModulePluginDemo& p)
  1275. : AudioProcessorEditor (&p),
  1276. proc (p)
  1277. {
  1278. comboEffect.addSectionHeading ("Main");
  1279. comboEffect.addItem ("Distortion", TabDistortion);
  1280. comboEffect.addItem ("Convolution", TabConvolution);
  1281. comboEffect.addItem ("Multi-band", TabMultiBand);
  1282. comboEffect.addSectionHeading ("Dynamics");
  1283. comboEffect.addItem ("Compressor", TabCompressor);
  1284. comboEffect.addItem ("Noise gate", TabNoiseGate);
  1285. comboEffect.addItem ("Limiter", TabLimiter);
  1286. comboEffect.addSectionHeading ("Delay");
  1287. comboEffect.addItem ("Delay line direct", TabDelayLineDirect);
  1288. comboEffect.addItem ("Delay line effect", TabDelayLineEffect);
  1289. comboEffect.addSectionHeading ("Others");
  1290. comboEffect.addItem ("Phaser", TabPhaser);
  1291. comboEffect.addItem ("Chorus", TabChorus);
  1292. comboEffect.addItem ("Ladder filter", TabLadder);
  1293. comboEffect.setSelectedId (proc.indexTab + 1, dontSendNotification);
  1294. comboEffect.onChange = [this]
  1295. {
  1296. proc.indexTab = comboEffect.getSelectedId() - 1;
  1297. updateVisibility();
  1298. };
  1299. addAllAndMakeVisible (*this,
  1300. comboEffect,
  1301. labelEffect,
  1302. basicControls,
  1303. distortionControls,
  1304. convolutionControls,
  1305. multibandControls,
  1306. compressorControls,
  1307. noiseGateControls,
  1308. limiterControls,
  1309. directDelayControls,
  1310. delayEffectControls,
  1311. phaserControls,
  1312. chorusControls,
  1313. ladderControls);
  1314. labelEffect.setJustificationType (Justification::centredRight);
  1315. labelEffect.attachToComponent (&comboEffect, true);
  1316. updateVisibility();
  1317. setSize (800, 430);
  1318. }
  1319. //==============================================================================
  1320. void paint (Graphics& g) override
  1321. {
  1322. auto rect = getLocalBounds();
  1323. auto rectTop = rect.removeFromTop (topSize);
  1324. auto rectBottom = rect.removeFromBottom (bottomSize);
  1325. auto rectEffects = rect.removeFromBottom (tabSize);
  1326. auto rectChoice = rect.removeFromBottom (midSize);
  1327. g.setColour (getLookAndFeel().findColour (ResizableWindow::backgroundColourId));
  1328. g.fillRect (rect);
  1329. g.setColour (getLookAndFeel().findColour (ResizableWindow::backgroundColourId).brighter (0.2f));
  1330. g.fillRect (rectEffects);
  1331. g.setColour (getLookAndFeel().findColour (ResizableWindow::backgroundColourId).darker (0.2f));
  1332. g.fillRect (rectTop);
  1333. g.fillRect (rectBottom);
  1334. g.fillRect (rectChoice);
  1335. g.setColour (Colours::white);
  1336. g.setFont (Font (20.0f).italicised().withExtraKerningFactor (0.1f));
  1337. g.drawFittedText ("DSP MODULE DEMO", rectTop.reduced (10, 0), Justification::centredLeft, 1);
  1338. g.setFont (Font (14.0f));
  1339. String strText = "IR length (reverb): " + String (proc.getCurrentIRSize()) + " samples";
  1340. g.drawFittedText (strText, rectBottom.reduced (10, 0), Justification::centredRight, 1);
  1341. }
  1342. void resized() override
  1343. {
  1344. auto rect = getLocalBounds();
  1345. rect.removeFromTop (topSize);
  1346. rect.removeFromBottom (bottomSize);
  1347. auto rectEffects = rect.removeFromBottom (tabSize);
  1348. auto rectChoice = rect.removeFromBottom (midSize);
  1349. comboEffect.setBounds (rectChoice.withSizeKeepingCentre (200, 24));
  1350. rect.reduce (80, 0);
  1351. rectEffects.reduce (20, 0);
  1352. basicControls.setBounds (rect);
  1353. forEach ([&] (Component& comp) { comp.setBounds (rectEffects); },
  1354. distortionControls,
  1355. convolutionControls,
  1356. multibandControls,
  1357. compressorControls,
  1358. noiseGateControls,
  1359. limiterControls,
  1360. directDelayControls,
  1361. delayEffectControls,
  1362. phaserControls,
  1363. chorusControls,
  1364. ladderControls);
  1365. }
  1366. private:
  1367. class AttachedSlider : public Component
  1368. {
  1369. public:
  1370. explicit AttachedSlider (RangedAudioParameter& param)
  1371. : label ("", param.name),
  1372. attachment (param, slider)
  1373. {
  1374. addAllAndMakeVisible (*this, slider, label);
  1375. slider.setTextValueSuffix (" " + param.label);
  1376. label.attachToComponent (&slider, false);
  1377. label.setJustificationType (Justification::centred);
  1378. }
  1379. void resized() override { slider.setBounds (getLocalBounds().reduced (0, 40)); }
  1380. private:
  1381. Slider slider { Slider::RotaryVerticalDrag, Slider::TextBoxBelow };
  1382. Label label;
  1383. SliderParameterAttachment attachment;
  1384. };
  1385. class AttachedToggle : public Component
  1386. {
  1387. public:
  1388. explicit AttachedToggle (RangedAudioParameter& param)
  1389. : toggle (param.name),
  1390. attachment (param, toggle)
  1391. {
  1392. addAndMakeVisible (toggle);
  1393. }
  1394. void resized() override { toggle.setBounds (getLocalBounds()); }
  1395. private:
  1396. ToggleButton toggle;
  1397. ButtonParameterAttachment attachment;
  1398. };
  1399. class AttachedCombo : public Component
  1400. {
  1401. public:
  1402. explicit AttachedCombo (RangedAudioParameter& param)
  1403. : combo (param),
  1404. label ("", param.name),
  1405. attachment (param, combo)
  1406. {
  1407. addAllAndMakeVisible (*this, combo, label);
  1408. label.attachToComponent (&combo, false);
  1409. label.setJustificationType (Justification::centred);
  1410. }
  1411. void resized() override
  1412. {
  1413. combo.setBounds (getLocalBounds().withSizeKeepingCentre (jmin (getWidth(), 150), 24));
  1414. }
  1415. private:
  1416. struct ComboWithItems : public ComboBox
  1417. {
  1418. explicit ComboWithItems (RangedAudioParameter& param)
  1419. {
  1420. // Adding the list here in the constructor means that the combo
  1421. // is already populated when we construct the attachment below
  1422. addItemList (dynamic_cast<AudioParameterChoice&> (param).choices, 1);
  1423. }
  1424. };
  1425. ComboWithItems combo;
  1426. Label label;
  1427. ComboBoxParameterAttachment attachment;
  1428. };
  1429. //==============================================================================
  1430. void updateVisibility()
  1431. {
  1432. const auto indexEffect = comboEffect.getSelectedId();
  1433. const auto op = [&] (const std::tuple<Component&, int>& tup)
  1434. {
  1435. Component& comp = std::get<0> (tup);
  1436. const int tabIndex = std::get<1> (tup);
  1437. comp.setVisible (tabIndex == indexEffect);
  1438. };
  1439. forEach (op,
  1440. std::forward_as_tuple (distortionControls, TabDistortion),
  1441. std::forward_as_tuple (convolutionControls, TabConvolution),
  1442. std::forward_as_tuple (multibandControls, TabMultiBand),
  1443. std::forward_as_tuple (compressorControls, TabCompressor),
  1444. std::forward_as_tuple (noiseGateControls, TabNoiseGate),
  1445. std::forward_as_tuple (limiterControls, TabLimiter),
  1446. std::forward_as_tuple (directDelayControls, TabDelayLineDirect),
  1447. std::forward_as_tuple (delayEffectControls, TabDelayLineEffect),
  1448. std::forward_as_tuple (phaserControls, TabPhaser),
  1449. std::forward_as_tuple (chorusControls, TabChorus),
  1450. std::forward_as_tuple (ladderControls, TabLadder));
  1451. }
  1452. enum EffectsTabs
  1453. {
  1454. TabDistortion = 1,
  1455. TabConvolution,
  1456. TabMultiBand,
  1457. TabCompressor,
  1458. TabNoiseGate,
  1459. TabLimiter,
  1460. TabDelayLineDirect,
  1461. TabDelayLineEffect,
  1462. TabPhaser,
  1463. TabChorus,
  1464. TabLadder
  1465. };
  1466. //==============================================================================
  1467. ComboBox comboEffect;
  1468. Label labelEffect { "Audio effect: " };
  1469. struct GetTrackInfo
  1470. {
  1471. // Combo boxes need a lot of room
  1472. Grid::TrackInfo operator() (AttachedCombo&) const { return 120_px; }
  1473. // Toggles are a bit smaller
  1474. Grid::TrackInfo operator() (AttachedToggle&) const { return 80_px; }
  1475. // Sliders take up as much room as they can
  1476. Grid::TrackInfo operator() (AttachedSlider&) const { return 1_fr; }
  1477. };
  1478. template <typename... Components>
  1479. static void performLayout (const Rectangle<int>& bounds, Components&... components)
  1480. {
  1481. Grid grid;
  1482. using Track = Grid::TrackInfo;
  1483. grid.autoColumns = Track (1_fr);
  1484. grid.autoRows = Track (1_fr);
  1485. grid.columnGap = Grid::Px (10);
  1486. grid.rowGap = Grid::Px (0);
  1487. grid.autoFlow = Grid::AutoFlow::column;
  1488. grid.templateColumns = { GetTrackInfo{} (components)... };
  1489. grid.items = { GridItem (components)... };
  1490. grid.performLayout (bounds);
  1491. }
  1492. struct BasicControls : public Component
  1493. {
  1494. explicit BasicControls (const DspModulePluginDemo::ParameterReferences& state)
  1495. : pan (state.pan),
  1496. input (state.inputGain),
  1497. output (state.outputGain)
  1498. {
  1499. addAllAndMakeVisible (*this, pan, input, output);
  1500. }
  1501. void resized() override
  1502. {
  1503. performLayout (getLocalBounds(), input, output, pan);
  1504. }
  1505. AttachedSlider pan, input, output;
  1506. };
  1507. struct DistortionControls : public Component
  1508. {
  1509. explicit DistortionControls (const DspModulePluginDemo::ParameterReferences& state)
  1510. : toggle (state.distortionEnabled),
  1511. lowpass (state.distortionLowpass),
  1512. highpass (state.distortionHighpass),
  1513. mix (state.distortionMix),
  1514. gain (state.distortionInGain),
  1515. compv (state.distortionCompGain),
  1516. type (state.distortionType),
  1517. oversampling (state.distortionOversampler)
  1518. {
  1519. addAllAndMakeVisible (*this, toggle, type, lowpass, highpass, mix, gain, compv, oversampling);
  1520. }
  1521. void resized() override
  1522. {
  1523. performLayout (getLocalBounds(), toggle, type, gain, highpass, lowpass, compv, mix, oversampling);
  1524. }
  1525. AttachedToggle toggle;
  1526. AttachedSlider lowpass, highpass, mix, gain, compv;
  1527. AttachedCombo type, oversampling;
  1528. };
  1529. struct ConvolutionControls : public Component
  1530. {
  1531. explicit ConvolutionControls (const DspModulePluginDemo::ParameterReferences& state)
  1532. : cab (state.convolutionCabEnabled),
  1533. reverb (state.convolutionReverbEnabled),
  1534. mix (state.convolutionReverbMix)
  1535. {
  1536. addAllAndMakeVisible (*this, cab, reverb, mix);
  1537. }
  1538. void resized() override
  1539. {
  1540. performLayout (getLocalBounds(), cab, reverb, mix);
  1541. }
  1542. AttachedToggle cab, reverb;
  1543. AttachedSlider mix;
  1544. };
  1545. struct MultiBandControls : public Component
  1546. {
  1547. explicit MultiBandControls (const DspModulePluginDemo::ParameterReferences& state)
  1548. : toggle (state.multiBandEnabled),
  1549. low (state.multiBandLowVolume),
  1550. high (state.multiBandHighVolume),
  1551. lRFreq (state.multiBandFreq)
  1552. {
  1553. addAllAndMakeVisible (*this, toggle, low, high, lRFreq);
  1554. }
  1555. void resized() override
  1556. {
  1557. performLayout (getLocalBounds(), toggle, lRFreq, low, high);
  1558. }
  1559. AttachedToggle toggle;
  1560. AttachedSlider low, high, lRFreq;
  1561. };
  1562. struct CompressorControls : public Component
  1563. {
  1564. explicit CompressorControls (const DspModulePluginDemo::ParameterReferences& state)
  1565. : toggle (state.compressorEnabled),
  1566. threshold (state.compressorThreshold),
  1567. ratio (state.compressorRatio),
  1568. attack (state.compressorAttack),
  1569. release (state.compressorRelease)
  1570. {
  1571. addAllAndMakeVisible (*this, toggle, threshold, ratio, attack, release);
  1572. }
  1573. void resized() override
  1574. {
  1575. performLayout (getLocalBounds(), toggle, threshold, ratio, attack, release);
  1576. }
  1577. AttachedToggle toggle;
  1578. AttachedSlider threshold, ratio, attack, release;
  1579. };
  1580. struct NoiseGateControls : public Component
  1581. {
  1582. explicit NoiseGateControls (const DspModulePluginDemo::ParameterReferences& state)
  1583. : toggle (state.noiseGateEnabled),
  1584. threshold (state.noiseGateThreshold),
  1585. ratio (state.noiseGateRatio),
  1586. attack (state.noiseGateAttack),
  1587. release (state.noiseGateRelease)
  1588. {
  1589. addAllAndMakeVisible (*this, toggle, threshold, ratio, attack, release);
  1590. }
  1591. void resized() override
  1592. {
  1593. performLayout (getLocalBounds(), toggle, threshold, ratio, attack, release);
  1594. }
  1595. AttachedToggle toggle;
  1596. AttachedSlider threshold, ratio, attack, release;
  1597. };
  1598. struct LimiterControls : public Component
  1599. {
  1600. explicit LimiterControls (const DspModulePluginDemo::ParameterReferences& state)
  1601. : toggle (state.limiterEnabled),
  1602. threshold (state.limiterThreshold),
  1603. release (state.limiterRelease)
  1604. {
  1605. addAllAndMakeVisible (*this, toggle, threshold, release);
  1606. }
  1607. void resized() override
  1608. {
  1609. performLayout (getLocalBounds(), toggle, threshold, release);
  1610. }
  1611. AttachedToggle toggle;
  1612. AttachedSlider threshold, release;
  1613. };
  1614. struct DirectDelayControls : public Component
  1615. {
  1616. explicit DirectDelayControls (const DspModulePluginDemo::ParameterReferences& state)
  1617. : toggle (state.directDelayEnabled),
  1618. type (state.directDelayType),
  1619. delay (state.directDelayValue),
  1620. smooth (state.directDelaySmoothing),
  1621. mix (state.directDelayMix)
  1622. {
  1623. addAllAndMakeVisible (*this, toggle, type, delay, smooth, mix);
  1624. }
  1625. void resized() override
  1626. {
  1627. performLayout (getLocalBounds(), toggle, type, delay, smooth, mix);
  1628. }
  1629. AttachedToggle toggle;
  1630. AttachedCombo type;
  1631. AttachedSlider delay, smooth, mix;
  1632. };
  1633. struct DelayEffectControls : public Component
  1634. {
  1635. explicit DelayEffectControls (const DspModulePluginDemo::ParameterReferences& state)
  1636. : toggle (state.delayEffectEnabled),
  1637. type (state.delayEffectType),
  1638. value (state.delayEffectValue),
  1639. smooth (state.delayEffectSmoothing),
  1640. lowpass (state.delayEffectLowpass),
  1641. feedback (state.delayEffectFeedback),
  1642. mix (state.delayEffectMix)
  1643. {
  1644. addAllAndMakeVisible (*this, toggle, type, value, smooth, lowpass, feedback, mix);
  1645. }
  1646. void resized() override
  1647. {
  1648. performLayout (getLocalBounds(), toggle, type, value, smooth, lowpass, feedback, mix);
  1649. }
  1650. AttachedToggle toggle;
  1651. AttachedCombo type;
  1652. AttachedSlider value, smooth, lowpass, feedback, mix;
  1653. };
  1654. struct PhaserControls : public Component
  1655. {
  1656. explicit PhaserControls (const DspModulePluginDemo::ParameterReferences& state)
  1657. : toggle (state.phaserEnabled),
  1658. rate (state.phaserRate),
  1659. depth (state.phaserDepth),
  1660. centre (state.phaserCentreFrequency),
  1661. feedback (state.phaserFeedback),
  1662. mix (state.phaserMix)
  1663. {
  1664. addAllAndMakeVisible (*this, toggle, rate, depth, centre, feedback, mix);
  1665. }
  1666. void resized() override
  1667. {
  1668. performLayout (getLocalBounds(), toggle, rate, depth, centre, feedback, mix);
  1669. }
  1670. AttachedToggle toggle;
  1671. AttachedSlider rate, depth, centre, feedback, mix;
  1672. };
  1673. struct ChorusControls : public Component
  1674. {
  1675. explicit ChorusControls (const DspModulePluginDemo::ParameterReferences& state)
  1676. : toggle (state.chorusEnabled),
  1677. rate (state.chorusRate),
  1678. depth (state.chorusDepth),
  1679. centre (state.chorusCentreDelay),
  1680. feedback (state.chorusFeedback),
  1681. mix (state.chorusMix)
  1682. {
  1683. addAllAndMakeVisible (*this, toggle, rate, depth, centre, feedback, mix);
  1684. }
  1685. void resized() override
  1686. {
  1687. performLayout (getLocalBounds(), toggle, rate, depth, centre, feedback, mix);
  1688. }
  1689. AttachedToggle toggle;
  1690. AttachedSlider rate, depth, centre, feedback, mix;
  1691. };
  1692. struct LadderControls : public Component
  1693. {
  1694. explicit LadderControls (const DspModulePluginDemo::ParameterReferences& state)
  1695. : toggle (state.ladderEnabled),
  1696. mode (state.ladderMode),
  1697. freq (state.ladderCutoff),
  1698. resonance (state.ladderResonance),
  1699. drive (state.ladderDrive)
  1700. {
  1701. addAllAndMakeVisible (*this, toggle, mode, freq, resonance, drive);
  1702. }
  1703. void resized() override
  1704. {
  1705. performLayout (getLocalBounds(), toggle, mode, freq, resonance, drive);
  1706. }
  1707. AttachedToggle toggle;
  1708. AttachedCombo mode;
  1709. AttachedSlider freq, resonance, drive;
  1710. };
  1711. //==============================================================================
  1712. static constexpr auto topSize = 40,
  1713. bottomSize = 40,
  1714. midSize = 40,
  1715. tabSize = 155;
  1716. //==============================================================================
  1717. DspModulePluginDemo& proc;
  1718. BasicControls basicControls { proc.getParameterValues() };
  1719. DistortionControls distortionControls { proc.getParameterValues() };
  1720. ConvolutionControls convolutionControls { proc.getParameterValues() };
  1721. MultiBandControls multibandControls { proc.getParameterValues() };
  1722. CompressorControls compressorControls { proc.getParameterValues() };
  1723. NoiseGateControls noiseGateControls { proc.getParameterValues() };
  1724. LimiterControls limiterControls { proc.getParameterValues() };
  1725. DirectDelayControls directDelayControls { proc.getParameterValues() };
  1726. DelayEffectControls delayEffectControls { proc.getParameterValues() };
  1727. PhaserControls phaserControls { proc.getParameterValues() };
  1728. ChorusControls chorusControls { proc.getParameterValues() };
  1729. LadderControls ladderControls { proc.getParameterValues() };
  1730. //==============================================================================
  1731. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DspModulePluginDemoEditor)
  1732. };
  1733. struct DspModulePluginDemoAudioProcessor : public DspModulePluginDemo
  1734. {
  1735. AudioProcessorEditor* createEditor() override
  1736. {
  1737. return new DspModulePluginDemoEditor (*this);
  1738. }
  1739. bool hasEditor() const override { return true; }
  1740. };