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.

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