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.

115 lines
3.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #ifndef DOXYGEN
  20. namespace ProcessorHelpers // Internal helper classes used in building the ProcessorChain
  21. {
  22. template <int arg>
  23. struct GetterHelper
  24. {
  25. template <typename ProcessorType>
  26. static auto& get (ProcessorType& a) noexcept { return GetterHelper<arg - 1>::get (a.processors); }
  27. };
  28. template <>
  29. struct GetterHelper<0>
  30. {
  31. template <typename ProcessorType>
  32. static auto& get (ProcessorType& a) noexcept { return a.getProcessor(); }
  33. };
  34. template <typename Processor, typename Subclass>
  35. struct ChainBase
  36. {
  37. Processor processor;
  38. Processor& getProcessor() noexcept { return processor; }
  39. Subclass& getThis() noexcept { return *static_cast<Subclass*> (this); }
  40. template <int arg> auto& get() noexcept { return GetterHelper<arg>::get (getThis()); }
  41. };
  42. template <typename FirstProcessor, typename... SubsequentProcessors>
  43. struct Chain : public ChainBase<FirstProcessor, Chain<FirstProcessor, SubsequentProcessors...>>
  44. {
  45. using Base = ChainBase<FirstProcessor, Chain<FirstProcessor, SubsequentProcessors...>>;
  46. void prepare (const ProcessSpec& spec)
  47. {
  48. Base::processor.prepare (spec);
  49. processors.prepare (spec);
  50. }
  51. template <typename ProcessContext>
  52. void process (ProcessContext& context) noexcept
  53. {
  54. Base::processor.process (context);
  55. processors.process (context);
  56. }
  57. void reset()
  58. {
  59. Base::processor.reset();
  60. processors.reset();
  61. }
  62. Chain<SubsequentProcessors...> processors;
  63. };
  64. template <typename ProcessorType>
  65. struct Chain<ProcessorType> : public ChainBase<ProcessorType, Chain<ProcessorType>>
  66. {
  67. using Base = ChainBase<ProcessorType, Chain<ProcessorType>>;
  68. template <typename ProcessContext>
  69. void process (ProcessContext& context) noexcept
  70. {
  71. Base::processor.process (context);
  72. }
  73. void prepare (const ProcessSpec& spec)
  74. {
  75. Base::processor.prepare (spec);
  76. }
  77. void reset()
  78. {
  79. Base::processor.reset();
  80. }
  81. };
  82. }
  83. #endif
  84. //==============================================================================
  85. /**
  86. This variadically-templated class lets you join together any number of processor
  87. classes into a single processor which will call process() on them all in sequence.
  88. */
  89. template <typename... Processors>
  90. using ProcessorChain = ProcessorHelpers::Chain<Processors...>;