quantumVERB  1.0.0
A FOSS convolution reverb plugin
Task.h
1 /*
2  ==============================================================================
3 
4  Task.h
5 
6  ==============================================================================
7 */
8 
9 #pragma once
10 
11 #include "../JuceLibraryCode/JuceHeader.h"
12 
13 namespace reverb
14 {
15 
16  using AudioBlock = juce::dsp::AudioBlock<float>;
17 
18  /**
19  * @brief Normalise intensity range of block to given threshold
20  *
21  * @param [in] maxValue Threshold for min/max values
22  */
23  forcedinline AudioBlock& normalise(AudioBlock& block, float threshold)
24  {
25  if (block.getNumSamples() == 0)
26  {
27  return block;
28  }
29 
30  // Find absolute magnitude of maximum value in block
31  juce::Range<float> range = block.findMinAndMax();
32 
33  float absMax = std::max(std::abs(range.getStart()),
34  std::abs(range.getEnd()));
35 
36  // Don't scale if block doesn't contain any non-zero values
37  if (absMax < std::numeric_limits<float>::epsilon())
38  {
39  return block;
40  }
41 
42  // Scale IR intensity to meet normal threshold
43  float scale = threshold / absMax;
44 
46 
47  return block;
48  }
49 
50  //==============================================================================
51  /**
52  * Abstract task object used to represent various processing elements
53  */
54  class Task
55  {
56  public:
57  //==============================================================================
59 
60  //==============================================================================
61  using Ptr = std::shared_ptr<Task>;
62 
63  //==============================================================================
64  /**
65  * @brief Updates parameters from processor parameter tree
66  *
67  * @param [in] params Processor parameter tree
68  * @param [in] blockId ID of block whose paramters should be checked
69  */
71  const juce::String& blockId) = 0;
72 
73  /**
74  * @brief Apply block logic to input buffer
75  */
76  virtual AudioBlock exec(AudioBlock) = 0;
77 
78  /**
79  * @brief Tells caller whether block must be run for current block
80  *
81  * May be overriden by IR blocks since these are executed sparingly.
82  */
83  virtual bool needsToRun() const { return mustExec; }
84 
85  //==============================================================================
86  double sampleRate;
87 
88  /**
89  * @brief Update sample rate for task block
90  *
91  * Compares new sample rate with previous value. If different, sets mustExec to
92  * true in order to re-run task for new sample rate. Store new sample rate
93  * value in object.
94  *
95  * @param [in] sr Sample rate
96  */
97  virtual void updateSampleRate(double sr)
98  {
99  if (sr != sampleRate)
100  {
101  sampleRate = sr;
102  mustExec = true;
103  }
104  }
105 
106  protected:
107  //==============================================================================
108  /**
109  * @brief Internal method used to get (and check) a parameter's value
110  */
112  const juce::String& blockId) const
113  {
115 
116  if (!paramPtr)
117  {
118  throw std::invalid_argument("Parameter not found: " + blockId.toStdString());
119  }
120 
121  return *paramPtr;
122  }
123 
124  //==============================================================================
126 
127  //==============================================================================
128  bool mustExec = true;
129  };
130 
131 }
float getParam(const juce::AudioProcessorValueTreeState &params, const juce::String &blockId) const
Internal method used to get (and check) a parameter&#39;s value.
Definition: Task.h:111