Control Surface
main
MIDI Control Surface library for Arduino
Toggle main menu visibility
Loading...
Searching...
No Matches
src
Audio
VolumeControl.hpp
Go to the documentation of this file.
1
/* ✔ */
2
3
#pragma once
4
5
#include <
AH/Arduino-Wrapper.h
>
6
#include <
AH/Containers/Updatable.hpp
>
7
#include <
AH/Hardware/FilteredAnalog.hpp
>
8
#include <Audio.h>
9
#include <
Def/Def.hpp
>
10
11
BEGIN_CS_NAMESPACE
12
22
template
<u
int
8_t N>
23
class
VolumeControl
:
public
AH::Updatable
<> {
24
public
:
37
VolumeControl
(
const
Array<AudioMixer4 *, N>
&
mixers
,
pin_t
analogPin,
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
{
filteredAnalog
.resetToCurrentValue(); }
57
70
void
map
(
MappingFunction
fn) {
filteredAnalog
.map(fn); }
71
73
void
invert
() {
filteredAnalog
.invert(); }
74
75
private
:
76
Array<AudioMixer4 *, N>
mixers
;
77
AH::FilteredAnalog<>
filteredAnalog
;
78
const
float
maxGain
;
79
};
80
81
END_CS_NAMESPACE
Arduino-Wrapper.h
Def.hpp
MappingFunction
analog_t(*)(analog_t) MappingFunction
Definition
Def.hpp:23
FilteredAnalog.hpp
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition
Settings/NamespaceSettings.hpp:14
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition
Settings/NamespaceSettings.hpp:11
Updatable.hpp
AH::FilteredAnalog
A class that reads and filters an analog input.
Definition
FilteredAnalog.hpp:275
AH::Updatable
A super class for object that have to be updated regularly.
Definition
Updatable.hpp:169
VolumeControl::VolumeControl
VolumeControl(const Array< AudioMixer4 *, N > &mixers, pin_t analogPin, float maxGain=1.0)
Create a new VolumeControl object.
Definition
VolumeControl.hpp:37
VolumeControl::mixers
Array< AudioMixer4 *, N > mixers
Definition
VolumeControl.hpp:76
VolumeControl::update
void update() override
Read the potentiometer value, and adjust the gain of the mixers.
Definition
VolumeControl.hpp:44
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
VolumeControl::begin
void begin() override
Initialize.
Definition
VolumeControl.hpp:56
VolumeControl::invert
void invert()
Invert the analog value.
Definition
VolumeControl.hpp:73
VolumeControl::filteredAnalog
AH::FilteredAnalog filteredAnalog
Definition
VolumeControl.hpp:77
VolumeControl::maxGain
const float maxGain
Definition
VolumeControl.hpp:78
AH::Array
An array wrapper for easy copying, comparing, and iterating.
Definition
Array.hpp:32
AH::ExtIO::pin_t
Type for storing pin numbers of Extended Input/Output elements.
Definition
Hardware-Types.hpp:25
Generated by
1.17.0