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.

2100 lines
93KB

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