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.

82 lines
2.7KB

  1. #pragma once
  2. #include <JuceHeader.h>
  3. #include "ChainSlots.hpp"
  4. #include "LatencyListener.hpp"
  5. #include "General/AudioSpinMutex.h"
  6. #include "CloneableDelayLine.hpp"
  7. typedef CloneableDelayLine<float, juce::dsp::DelayLineInterpolationTypes::None> CloneableDelayLineType;
  8. class PluginChain {
  9. public:
  10. std::vector<std::shared_ptr<ChainSlotBase>> chain;
  11. bool isChainBypassed;
  12. bool isChainMuted;
  13. std::function<float(int, MODULATION_TYPE)> getModulationValueCallback;
  14. std::unique_ptr<CloneableDelayLineType> latencyCompLine;
  15. WECore::AudioSpinMutex latencyCompLineMutex;
  16. PluginChainLatencyListener latencyListener;
  17. juce::String customName;
  18. PluginChain(std::function<float(int, MODULATION_TYPE)> getModulationValueCallback) :
  19. isChainBypassed(false),
  20. isChainMuted(false),
  21. getModulationValueCallback(getModulationValueCallback),
  22. latencyListener(this) {
  23. latencyCompLine.reset(new CloneableDelayLineType(0));
  24. latencyCompLine->setDelay(0);
  25. }
  26. virtual ~PluginChain() {
  27. // The plugins might outlive this chain if they're also referenced by another copy in the
  28. // history, so remove the listener
  29. for (auto& slot : chain) {
  30. if (std::shared_ptr<ChainSlotPlugin> plugin = std::dynamic_pointer_cast<ChainSlotPlugin>(slot)) {
  31. plugin->plugin->removeListener(&latencyListener);
  32. }
  33. }
  34. }
  35. PluginChain* clone() const {
  36. return new PluginChain(
  37. chain,
  38. isChainBypassed,
  39. isChainMuted,
  40. getModulationValueCallback,
  41. std::unique_ptr<CloneableDelayLineType>(latencyCompLine->clone()),
  42. customName
  43. );
  44. }
  45. private:
  46. PluginChain(
  47. std::vector<std::shared_ptr<ChainSlotBase>> newChain,
  48. bool newIsChainBypassed,
  49. bool newIsChainMuted,
  50. std::function<float(int, MODULATION_TYPE)> newGetModulationValueCallback,
  51. std::unique_ptr<CloneableDelayLineType> newLatencyCompLine,
  52. const juce::String& newCustomName) :
  53. isChainBypassed(newIsChainBypassed),
  54. isChainMuted(newIsChainMuted),
  55. getModulationValueCallback(newGetModulationValueCallback),
  56. latencyCompLine(std::move(newLatencyCompLine)),
  57. latencyListener(this),
  58. customName(newCustomName) {
  59. for (auto& slot : newChain) {
  60. chain.push_back(std::shared_ptr<ChainSlotBase>(slot->clone()));
  61. if (auto plugin = std::dynamic_pointer_cast<ChainSlotPlugin>(slot)) {
  62. plugin->plugin->addListener(&latencyListener);
  63. }
  64. }
  65. latencyListener.onPluginChainUpdate();
  66. }
  67. };