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.

134 lines
4.4KB

  1. /*
  2. * Swanky Amp tube amplifier simulation
  3. * Copyright (C) 2020 Garrin McGoldrick
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. #pragma once
  19. #include <JuceHeader.h>
  20. #include "Components/LevelMeter.h"
  21. #include "dsp/PushPullAmp.h"
  22. class SwankyAmpAudioProcessor : public AudioProcessor
  23. {
  24. public:
  25. SwankyAmpAudioProcessor();
  26. ~SwankyAmpAudioProcessor();
  27. // The amplifier DSP objects (contains DSP state and the process function)
  28. // one for each possible channel (even if unused)
  29. PushPullAmp amp_channel[2];
  30. // Objects with an `update` method for updating the value of input meters.
  31. LevelMeterListener* meterListenersIn[2] = {nullptr, nullptr};
  32. LevelMeterListener* meterListenersOut[2] = {nullptr, nullptr};
  33. AudioProcessorValueTreeState parameters;
  34. std::atomic<float>* parInputLevel = nullptr;
  35. std::atomic<float>* parOutputLevel = nullptr;
  36. std::atomic<float>* parTsLow = nullptr;
  37. std::atomic<float>* parTsMid = nullptr;
  38. std::atomic<float>* parTsHigh = nullptr;
  39. std::atomic<float>* parTsPresence = nullptr;
  40. std::atomic<float>* parTsSelection = nullptr;
  41. std::atomic<float>* parGainStages = nullptr;
  42. std::atomic<float>* parGainOverhead = nullptr;
  43. std::atomic<float>* parCabOnOff = nullptr;
  44. std::atomic<float>* parCabBrightness = nullptr;
  45. std::atomic<float>* parCabDistance = nullptr;
  46. std::atomic<float>* parCabDynamic = nullptr;
  47. std::atomic<float>* parPreAmpDrive = nullptr;
  48. std::atomic<float>* parPreAmpTight = nullptr;
  49. std::atomic<float>* parPreAmpGrit = nullptr;
  50. std::atomic<float>* parLowCut = nullptr;
  51. std::atomic<float>* parPowerAmpDrive = nullptr;
  52. std::atomic<float>* parPowerAmpTight = nullptr;
  53. std::atomic<float>* parPowerAmpGrit = nullptr;
  54. std::atomic<float>* parPowerAmpSag = nullptr;
  55. std::atomic<float>* parPowerAmpSagRatio = nullptr;
  56. const std::vector<String> parameterIds = {
  57. "idInputLevel", "idOutputLevel",
  58. "idTsLow", "idTsMid",
  59. "idTsHigh", "idTsPresence",
  60. "idTsSelection", "idGainStages",
  61. "idGainOverhead", "idCabOnOff",
  62. "idCabBrightness", "idCabDistance",
  63. "idCabDynamic", "idPreAmpDrive",
  64. "idPreAmpTight", "idPreAmpGrit",
  65. "idLowCut", "idPowerAmpDrive",
  66. "idPowerAmpTight", "idPowerAmpGrit",
  67. "idPowerAmpSag", "idPowerAmpSagRatio",
  68. };
  69. std::atomic<bool> notifyStateChanged { false };
  70. const int burnInLength = 1024;
  71. std::atomic<int> numBurnIn { burnInLength };
  72. void setAmpParameters();
  73. void prepareToPlay(double sampleRate, int samplesPerBlock) override;
  74. void releaseResources() override;
  75. #ifndef JucePlugin_PreferredChannelConfigurations
  76. bool isBusesLayoutSupported(const BusesLayout& layouts) const override;
  77. #endif
  78. void processBlock(AudioBuffer<float>&, MidiBuffer&) override;
  79. #if ! JUCE_AUDIOPROCESSOR_NO_GUI
  80. AudioProcessorEditor* createEditor() override;
  81. bool hasEditor() const override;
  82. #endif
  83. const String getName() const override;
  84. bool acceptsMidi() const override;
  85. bool producesMidi() const override;
  86. bool isMidiEffect() const override;
  87. double getTailLengthSeconds() const override;
  88. int getNumPrograms() override;
  89. int getCurrentProgram() override;
  90. void setCurrentProgram(int index) override;
  91. const String getProgramName(int index) override;
  92. void changeProgramName(int index, const String& newName) override;
  93. void getStateInformation(MemoryBlock& destData) override;
  94. void setStateInformation(const void* data, int sizeInBytes) override;
  95. void setStateInformation(
  96. const std::unique_ptr<XmlElement>& state,
  97. const String& presetName,
  98. bool useAll = true);
  99. void setPresetText(const String& text);
  100. const String& getPresetText() const;
  101. private:
  102. CriticalSection setStateMutex;
  103. String storedPresetText;
  104. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(SwankyAmpAudioProcessor)
  105. };