Control Surface  1.2.0
MIDI Control Surface library for Arduino
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | Static Protected Attributes | Private Attributes | List of all members
VolumeControl< N > Class Template Reference

A class for controlling the volume of AudioMixer4 objects using a potentiometer. More...

#include <Audio/VolumeControl.hpp>

+ Inheritance diagram for VolumeControl< N >:
+ Collaboration diagram for VolumeControl< N >:

Public Types

using Mutex = typename std::conditional< ThreadSafe, DefaultMutEx, EmptyMutex >::type
 
using LockGuard = typename std::conditional< ThreadSafe, DefaultLockGuard< Mutex >, EmptyLockGuard< Mutex > >::type
 

Public Member Functions

 VolumeControl (const Array< AudioMixer4 *, N > &mixers, pin_t analogPin, float maxGain=1.0)
 Create a new VolumeControl object. More...
 
void update () override
 Read the potentiometer value, and adjust the gain of the mixers. More...
 
void begin () override
 Initialize. More...
 
void map (MappingFunction fn)
 Specify a mapping function that is applied to the raw analog value before setting the volume. More...
 
void invert ()
 Invert the analog value. More...
 

Static Public Member Functions

static MutexgetMutex ()
 

Protected Attributes

Updatable< Potentiometer, false > * next
 
Updatable< Potentiometer, false > * previous
 

Static Protected Attributes

static DoublyLinkedList< Updatable< Potentiometer, false > > updatables
 
static Mutex mutex
 

Private Attributes

Array< AudioMixer4 *, N > mixers
 
AH::FilteredAnalog filteredAnalog
 
const float maxGain
 

Main initialization and updating methods

static void applyToAll (const LockGuard &, void(Derived::*method)(Args &&...), Args &&... args)
 
static void applyToAll (void(Derived::*method)(Args &&...), Args &&... args)
 

Enabling and disabling updatables

void enable (const LockGuard &lock)
 Enable this updatable: insert it into the linked list of instances, so it gets updated automatically. More...
 
void enable ()
 Enable this updatable: insert it into the linked list of instances, so it gets updated automatically. More...
 
void disable (const LockGuard &lock)
 Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically. More...
 
void disable ()
 Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically. More...
 
bool isEnabled (const LockGuard &) const
 Check if this updatable is enabled. More...
 
bool isEnabled ()
 Check if this updatable is enabled. More...
 
void moveDown (const LockGuard &)
 Move down this element in the list. More...
 
void moveDown ()
 Move down this element in the list. More...
 
static void enable (UpdatableCRTP *element)
 Enable this updatable: insert it into the linked list of instances, so it gets updated automatically. More...
 
static void enable (UpdatableCRTP &element)
 Enable this updatable: insert it into the linked list of instances, so it gets updated automatically. More...
 
static void enable (U(&array)[N])
 Enable this updatable: insert it into the linked list of instances, so it gets updated automatically. More...
 
static void disable (UpdatableCRTP *element)
 Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically. More...
 
static void disable (UpdatableCRTP &element)
 Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically. More...
 
static void disable (U(&array)[N])
 Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically. More...
 

Main initialization and updating methods

static void beginAll ()
 Begin all enabled instances of this class. More...
 
static void updateAll ()
 Update all enabled instances of this class. More...
 

Detailed Description

template<uint8_t N>
class VolumeControl< N >

A class for controlling the volume of AudioMixer4 objects using a potentiometer.

Template Parameters
NThe number of mixers.
Examples
1.Volume-Controlled-USB-DAC.ino, and 2.VU-Meter-OLED-USB-DAC.ino.

Definition at line 23 of file VolumeControl.hpp.

Member Typedef Documentation

◆ Mutex

using Mutex = typename std::conditional<ThreadSafe, DefaultMutEx, EmptyMutex>::type
inherited

Definition at line 36 of file Updatable.hpp.

◆ LockGuard

using LockGuard = typename std::conditional<ThreadSafe, DefaultLockGuard<Mutex>, EmptyLockGuard<Mutex> >::type
inherited

Definition at line 38 of file Updatable.hpp.

Constructor & Destructor Documentation

◆ VolumeControl()

VolumeControl ( const Array< AudioMixer4 *, N > &  mixers,
pin_t  analogPin,
float  maxGain = 1.0 
)
inline

Create a new VolumeControl object.

Parameters
mixersAn array of pointers to audio mixers.
Only the pointers are saved, so the mixers should outlive this object.
analogPinThe analog pin with the potentiometer connected.
maxGainThe maximum gain for the mixers.

Definition at line 37 of file VolumeControl.hpp.

Member Function Documentation

◆ update()

void update ( )
inlineoverridevirtual

Read the potentiometer value, and adjust the gain of the mixers.

Implements Updatable< Potentiometer >.

Definition at line 44 of file VolumeControl.hpp.

◆ begin()

void begin ( )
inlineoverridevirtual

Initialize.

Implements Updatable< Potentiometer >.

Definition at line 56 of file VolumeControl.hpp.

◆ map()

void map ( MappingFunction  fn)
inline

Specify a mapping function that is applied to the raw analog value before setting the volume.

Parameters
fnA function pointer to the mapping function. This function should take the filtered analog value of \( 16 - \mathrm{ANALOG\_FILTER\_SHIFT\_FACTOR} \) bits as a parameter, and should return a value in the same range.
See also
FilteredAnalog::map

Definition at line 70 of file VolumeControl.hpp.

◆ invert()

void invert ( )
inline

Invert the analog value.

Definition at line 73 of file VolumeControl.hpp.

◆ beginAll()

static void beginAll
inlinestaticinherited

Begin all enabled instances of this class.

See also
begin()

Definition at line 208 of file Updatable.hpp.

◆ updateAll()

static void updateAll
inlinestaticinherited

Update all enabled instances of this class.

See also
update()
Examples
2.VU-Meter-OLED-USB-DAC.ino.

Definition at line 212 of file Updatable.hpp.

◆ getMutex()

static Mutex& getMutex
inlinestaticinherited

Definition at line 79 of file Updatable.hpp.

◆ applyToAll() [1/2]

static void applyToAll ( const LockGuard ,
void(Derived::*)(Args &&...)  method,
Args &&...  args 
)
inlinestaticinherited

Definition at line 85 of file Updatable.hpp.

◆ applyToAll() [2/2]

static void applyToAll ( void(Derived::*)(Args &&...)  method,
Args &&...  args 
)
inlinestaticinherited

Definition at line 93 of file Updatable.hpp.

◆ enable() [1/5]

void enable ( const LockGuard lock)
inlineinherited

Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.

Definition at line 106 of file Updatable.hpp.

◆ enable() [2/5]

void enable
inlineinherited

Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.

Definition at line 115 of file Updatable.hpp.

◆ enable() [3/5]

static void enable ( UpdatableCRTP< Updatable< Potentiometer, false >, false > *  element)
inlinestaticinherited

Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.

Definition at line 144 of file Updatable.hpp.

◆ enable() [4/5]

static void enable ( UpdatableCRTP< Updatable< Potentiometer, false >, false > &  element)
inlinestaticinherited

Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.

Definition at line 146 of file Updatable.hpp.

◆ enable() [5/5]

static void enable ( U(&)  array[N])
inlinestaticinherited

Enable this updatable: insert it into the linked list of instances, so it gets updated automatically.

Definition at line 149 of file Updatable.hpp.

◆ disable() [1/5]

void disable ( const LockGuard lock)
inlineinherited

Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically.

Definition at line 119 of file Updatable.hpp.

◆ disable() [2/5]

void disable
inlineinherited

Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically.

Definition at line 128 of file Updatable.hpp.

◆ disable() [3/5]

static void disable ( UpdatableCRTP< Updatable< Potentiometer, false >, false > *  element)
inlinestaticinherited

Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically.

Definition at line 155 of file Updatable.hpp.

◆ disable() [4/5]

static void disable ( UpdatableCRTP< Updatable< Potentiometer, false >, false > &  element)
inlinestaticinherited

Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically.

Definition at line 157 of file Updatable.hpp.

◆ disable() [5/5]

static void disable ( U(&)  array[N])
inlinestaticinherited

Disable this updatable: remove it from the linked list of instances, so it no longer gets updated automatically.

Definition at line 160 of file Updatable.hpp.

◆ isEnabled() [1/2]

bool isEnabled ( const LockGuard ) const
inlineinherited

Check if this updatable is enabled.

Note
Assumes that the updatable is not added to a different linked list by the user.

Definition at line 136 of file Updatable.hpp.

◆ isEnabled() [2/2]

bool isEnabled
inlineinherited

Check if this updatable is enabled.

Note
Assumes that the updatable is not added to a different linked list by the user.

Definition at line 141 of file Updatable.hpp.

◆ moveDown() [1/2]

void moveDown ( const LockGuard )
inlineinherited

Move down this element in the list.

Definition at line 166 of file Updatable.hpp.

◆ moveDown() [2/2]

void moveDown
inlineinherited

Move down this element in the list.

Definition at line 168 of file Updatable.hpp.

Member Data Documentation

◆ mixers

Array<AudioMixer4 *, N> mixers
private

Definition at line 76 of file VolumeControl.hpp.

◆ filteredAnalog

AH::FilteredAnalog filteredAnalog
private

Definition at line 77 of file VolumeControl.hpp.

◆ maxGain

const float maxGain
private

Definition at line 78 of file VolumeControl.hpp.

◆ updatables

DoublyLinkedList< Updatable< Potentiometer, false > > updatables
staticprotectedinherited

Definition at line 173 of file Updatable.hpp.

◆ mutex

UpdatableCRTP< Updatable< Potentiometer, false > , ThreadSafe >::Mutex mutex
staticprotectedinherited

Definition at line 174 of file Updatable.hpp.

◆ next

Updatable< Potentiometer, false > * next
protectedinherited

Definition at line 323 of file LinkedList.hpp.

◆ previous

Updatable< Potentiometer, false > * previous
protectedinherited

Definition at line 324 of file LinkedList.hpp.


The documentation for this class was generated from the following file: