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.

94 lines
2.7KB

  1. #pragma once
  2. #include <JuceHeader.h>
  3. #include "PluginChain.hpp"
  4. #include "CloneableLRFilter.hpp"
  5. struct BandState {
  6. bool isSoloed;
  7. std::shared_ptr<PluginChain> chain;
  8. BandState() : isSoloed(false) {
  9. }
  10. };
  11. class CrossoverState {
  12. public:
  13. // Num low/highpass filters = num bands - 1 (= num crossovers)
  14. std::vector<std::shared_ptr<CloneableLRFilter<float>>> lowpassFilters;
  15. std::vector<std::shared_ptr<CloneableLRFilter<float>>> highpassFilters;
  16. // Num allpass filters = num bands - 2
  17. std::vector<std::shared_ptr<CloneableLRFilter<float>>> allpassFilters;
  18. // Num buffers = num bands - 1 (= num crossovers)
  19. std::vector<juce::AudioBuffer<float>> buffers;
  20. std::vector<BandState> bands;
  21. HostConfiguration config;
  22. // We only need to implement solo at this level - chains handle bypass and mute themselves
  23. int numBandsSoloed;
  24. CrossoverState() : numBandsSoloed(0) {}
  25. CrossoverState* clone() const {
  26. auto newState = new CrossoverState();
  27. const int numFilterChannels {canDoStereoSplitTypes(config.layout) ? 2 : 1};
  28. for (auto& filter : lowpassFilters) {
  29. newState->lowpassFilters.emplace_back(filter->clone());
  30. }
  31. for (auto& filter : highpassFilters) {
  32. newState->highpassFilters.emplace_back(filter->clone());
  33. }
  34. for (auto& filter : allpassFilters) {
  35. newState->allpassFilters.emplace_back(filter->clone());
  36. }
  37. for (auto& buffer : buffers) {
  38. newState->buffers.emplace_back(buffer);
  39. }
  40. for (auto& band : bands) {
  41. newState->bands.emplace_back();
  42. newState->bands.back().isSoloed = band.isSoloed;
  43. newState->bands.back().chain = band.chain;
  44. }
  45. newState->config = config;
  46. newState->numBandsSoloed = numBandsSoloed;
  47. return newState;
  48. }
  49. };
  50. inline std::shared_ptr<CrossoverState> createDefaultCrossoverState(HostConfiguration newConfig) {
  51. auto state = std::make_shared<CrossoverState>();
  52. // Initialise configuration for two bands
  53. constexpr int DEFAULT_FREQ {1000};
  54. state->lowpassFilters.emplace_back(new CloneableLRFilter<float>());
  55. state->lowpassFilters[0]->setType(juce::dsp::LinkwitzRileyFilterType::lowpass);
  56. state->lowpassFilters[0]->setCutoffFrequency(DEFAULT_FREQ);
  57. state->highpassFilters.emplace_back(new CloneableLRFilter<float>());
  58. state->highpassFilters[0]->setType(juce::dsp::LinkwitzRileyFilterType::highpass);
  59. state->highpassFilters[0]->setCutoffFrequency(DEFAULT_FREQ);
  60. state->buffers.emplace_back();
  61. state->bands.emplace_back();
  62. state->bands.emplace_back();
  63. state->config = newConfig;
  64. return state;
  65. }