Control Surface master
MIDI Control Surface library for Arduino
VolumeControl.hpp
Go to the documentation of this file.
1/* ✔ */
2
3#pragma once
4
8#include <Audio.h>
9#include <Def/Def.hpp>
10
12
22template <uint8_t N>
23class VolumeControl : public AH::Updatable<> {
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
57
71
74
75 private:
78 const float maxGain;
79};
80
analog_t(*)(analog_t) MappingFunction
Definition: Def.hpp:21
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
A class that reads and filters an analog input.
void invert()
Invert the analog value.
void resetToCurrentValue()
Reset the filtered value to the value that's currently being measured at the analog input.
void map(MappingFunction fn)
Specify a mapping function/functor that is applied to the analog value after filtering and before app...
float getFloatValue() const
Get the filtered value of the analog input with the mapping function applied as a floating point numb...
bool update()
Read the analog input value, apply the mapping function, and update the average.
A super class for object that have to be updated regularly.
Definition: Updatable.hpp:173
A class for controlling the volume of AudioMixer4 objects using a potentiometer.
VolumeControl(const Array< AudioMixer4 *, N > &mixers, pin_t analogPin, float maxGain=1.0)
Create a new VolumeControl object.
Array< AudioMixer4 *, N > mixers
void update() override
Read the potentiometer value, and adjust the gain of the mixers.
void map(MappingFunction fn)
Specify a mapping function that is applied to the raw analog value before setting the volume.
void begin() override
Initialize.
void invert()
Invert the analog value.
AH::FilteredAnalog filteredAnalog
const float maxGain
uint16_t pin_t
The type for Arduino pins (and ExtendedIOElement pins).
An array wrapper for easy copying, comparing, and iterating.
Definition: Array.hpp:36