ape  0.5.0
Audio Programming Environment
meter.h
Go to the documentation of this file.
1 #ifndef CPPAPE_METER_H
2 #define CPPAPE_METER_H
3 
4 #include "baselib.h"
5 #include <string>
6 #include <cmath>
7 
8 namespace ape
9 {
14  class MeteredValue : public UIObject
15  {
16  public:
23  MeteredValue(std::string name)
24  : peak(), value(), peakTimer() /* , name(std::move(name)) */
25  {
26  id = getInterface().createMeter(&getInterface(), name.c_str(), &value, &peak);
27 
28  auto sampleRate = getInterface().getSampleRate(&getInterface());
29  pole = std::exp(-1.0 / (0.25 * sampleRate));
30  peakStop = static_cast<std::size_t>(sampleRate);
31  }
32 
34  {
35  getInterface().destroyResource(&getInterface(), id, 0);
36  }
37 
41  template<typename T>
42  T operator = (T input) noexcept
43  {
44  pushValue(static_cast<double>(input));
45  return input;
46  }
47 
52  void pushValue(double input) noexcept
53  {
54  input = std::abs(input);
55  if (input <= value)
56  {
57  value *= pole;
58  }
59  else
60  {
61  value = input;
62  }
63 
64  if (input <= peak)
65  {
66  if (peakTimer > peakStop)
67  {
68  peak *= pole;
69  }
70  else
71  {
72  peakTimer++;
73  }
74  }
75  else
76  {
77  peak = input;
78  peakTimer = 0;
79  }
80  }
81 
82  private:
83 
84  double peak, value, pole;
85  int id;
86  std::size_t peakTimer, peakStop;
87 
88  //std::string name;
89  };
90 
91 }
92 #endif
ape::getInterface
APE_SharedInterface & getInterface()
Acquire the low-level C API.
ape::MeteredValue::pushValue
void pushValue(double input) noexcept
Update the meter with the input value. This will also calculate peak hold positions and decay envelo...
Definition: meter.h:52
ape::UIObject
Base traits class for all classes that are displayed in the GUI.
Definition: baselib.h:62
ape::MeteredValue::operator=
T operator=(T input) noexcept
Alias for pushValue
Definition: meter.h:42
ape
Definition: audiofile.h:7
ape::MeteredValue::MeteredValue
MeteredValue(std::string name)
Create a new metered value.
Definition: meter.h:23
ape::MeteredValue::~MeteredValue
~MeteredValue()
Definition: meter.h:33
baselib.h
ape::MeteredValue
A value you can continously assign to (at audio rate), and a meter with a decay in the GUI will displ...
Definition: meter.h:14