Control Surface  1.1.1
MIDI Control Surface library for Arduino
VolumeControl.hpp
Go to the documentation of this file.
1 /* ✔ */
2 
3 #pragma once
4 
7 #include <Arduino.h>
8 #include <Audio.h>
9 #include <Def/Def.hpp>
10 
12 
22 template <uint8_t N>
23 class VolumeControl : public AH::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 
74 
75  private:
78  const float maxGain;
79 };
80 
AH::FilteredAnalog::map
void map(MappingFunction fn)
Specify a mapping function that is applied to the raw analog value before filtering.
Definition: FilteredAnalog.hpp:86
AH::Updatable
A super class for object that have to be updated regularly.
Definition: Updatable.hpp:25
VolumeControl::mixers
Array< AudioMixer4 *, N > mixers
Definition: VolumeControl.hpp:76
Updatable.hpp
VolumeControl::VolumeControl
VolumeControl(const Array< AudioMixer4 *, N > &mixers, pin_t analogPin, float maxGain=1.0)
Create a new VolumeControl object.
Definition: VolumeControl.hpp:37
AH::pin_t
uint16_t pin_t
The type for Arduino pins (and ExtendedIOElement pins).
Definition: Hardware-Types.hpp:17
VolumeControl::update
void update() override
Read the potentiometer value, and adjust the gain of the mixers.
Definition: VolumeControl.hpp:44
Def.hpp
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:9
AH::FilteredAnalog
A class that reads and filters an analog input.
Definition: FilteredAnalog.hpp:55
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:10
VolumeControl::maxGain
const float maxGain
Definition: VolumeControl.hpp:78
AH::Array
An array wrapper for easy copying, comparing, and iterating.
Definition: Array.hpp:36
VolumeControl::invert
void invert()
Invert the analog value.
Definition: VolumeControl.hpp:73
VolumeControl::begin
void begin() override
Initialize.
Definition: VolumeControl.hpp:56
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
AH::FilteredAnalog::invert
void invert()
Invert the analog value.
Definition: FilteredAnalog.hpp:95
VolumeControl::filteredAnalog
AH::FilteredAnalog filteredAnalog
Definition: VolumeControl.hpp:77
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
Definition: Def.hpp:19
AH::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:137
AH::FilteredAnalog::update
bool update()
Read the analog input value, apply the mapping function, and update the average.
Definition: FilteredAnalog.hpp:109