This is an old version of the documentation. View the latest version here.
Control Surface  1.0.0
MIDI Control Surface library for Arduino
VolumeControl.hpp
Go to the documentation of this file.
1 /* ✔ */
2 
3 #pragma once
4 
5 #include <Arduino.h>
6 #include <Audio.h>
7 #include <Def/Def.hpp>
9 #include <Helpers/Updatable.hpp>
10 
12 
22 template <uint8_t N>
23 class VolumeControl : public Updatable<Potentiometer> {
24  public:
38  float maxGain = 1.0)
39  : mixers(mixers), filteredAnalog(analogPin), maxGain(maxGain) {}
40 
44  void update() override {
45  if (filteredAnalog.update()) {
46  float gain = filteredAnalog.getFloatValue() * maxGain;
47  for (AudioMixer4 *mixer : mixers)
48  for (uint8_t ch = 0; ch < 4; ch++)
49  mixer->gain(ch, gain);
50  }
51  }
52 
56  void begin() override {}
57 
71 
73  void invert() { filteredAnalog.invert(); }
74 
75  private:
78  const float maxGain;
79 };
80 
Updatable
A super class for object that have to be updated regularly.
Definition: Updatable.hpp:20
FilteredAnalog
A class that reads and filters an analog input.
Definition: FilteredAnalog.hpp:47
Updatable.hpp
VolumeControl::mixers
Array< AudioMixer4 *, N > mixers
Definition: VolumeControl.hpp:76
pin_t
uint16_t pin_t
The type for Arduino pins (and ExtendedIOElement pins).
Definition: Def.hpp:17
VolumeControl::map
void map(MappingFunction fn)
Specify a mapping function that is applied to the raw analog value before setting the volume.
Definition: VolumeControl.hpp:70
Def.hpp
Array< AudioMixer4 *, N >
FilteredAnalog::getFloatValue
float getFloatValue() const
Get the filtered value of the analog input with the mapping function applied as a floating point numb...
Definition: FilteredAnalog.hpp:122
FilteredAnalog::update
bool update()
Read the analog input value, apply the mapping function, and update the average.
Definition: FilteredAnalog.hpp:97
VolumeControl::begin
void begin() override
Initialize.
Definition: VolumeControl.hpp:56
VolumeControl::VolumeControl
VolumeControl(const Array< AudioMixer4 *, N > &mixers, pin_t analogPin, float maxGain=1.0)
Create a new VolumeControl object.
Definition: VolumeControl.hpp:37
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: NamespaceSettings.hpp:9
VolumeControl::filteredAnalog
FilteredAnalog filteredAnalog
Definition: VolumeControl.hpp:77
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: NamespaceSettings.hpp:10
FilteredAnalog::map
void map(MappingFunction fn)
Specify a mapping function that is applied to the raw analog value before filtering.
Definition: FilteredAnalog.hpp:74
FilteredAnalog::invert
void invert()
Invert the analog value.
Definition: FilteredAnalog.hpp:83
VolumeControl::update
void update() override
Read the potentiometer value, and adjust the gain of the mixers.
Definition: VolumeControl.hpp:44
VolumeControl
A class for controlling the volume of AudioMixer4 objects using a potentiometer.
Definition: VolumeControl.hpp:23
FilteredAnalog.hpp
MappingFunction
analog_t(*)(analog_t) MappingFunction
A function pointer to a mapping function to map analog values.
Definition: Def.hpp:28
VolumeControl::maxGain
const float maxGain
Definition: VolumeControl.hpp:78
VolumeControl::invert
void invert()
Invert the analog value.
Definition: VolumeControl.hpp:73