Sound Byte Libs 0.5.1-340-gab5b79a
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
sbl::control::CcMapper< Target > Class Template Reference

Routes MIDI CCs to app targets through a constexpr table. More...

Detailed Description

template<typename Target>
class sbl::control::CcMapper< Target >

Routes MIDI CCs to app targets through a constexpr table.

A constexpr table routes MIDI CCs: each row routes one controller on one channel to an app-defined target through a curve. Curves are LUTE cam tables (the same vocabulary as knob macros) or linear.

Dispatch is event-driven, inside the control tick's drain loop, after the app's CC store has taken the event - store before mapper. The store stays the only CC state: a Paired14 row reads the other half of its pair from it. Values are absolute; every matching row fires, so a CC with two rows fans out to two targets.

The sink is the app's write into the merge layer, e.g. pickups[param].hold(value). The mapper holds a pointer to the table, so the table must outlive the mapper.

Usage:

enum class Param : uint8_t { Pitch, Timbre };
constexpr sbl::control::CcEntry<Param> CC_MAP[] = {
{ 0, 87, Param::Timbre, {cam::timbre_256, 256}, sbl::control::CcFlags::None },
};
sbl::control::CcMapper<Param> mapper{CC_MAP, write_param, nullptr};
// drain loop, per ControlChange event:
converter.cc(e.cc_number(), e.cc_value());
mapper.on_cc(e.channel, e.cc_number(), e.cc_value(), converter);
Routes MIDI CCs to app targets through a constexpr table.
Definition cc_mapper.hpp:85
constexpr CcCurve CC_LINEAR
Definition cc_mapper.hpp:27
One row of a CC map.
Definition cc_mapper.hpp:43
Template Parameters
TargetApp-defined target type, usually a parameter enum

Definition at line 85 of file cc_mapper.hpp.

#include <cc_mapper.hpp>

Public Types

using Sink = void(*)(void *context, Target target, float value)
 The app's write into the merge layer: the context pointer, the row's target and the curve output.
 

Public Member Functions

template<size_t N>
 CcMapper (const CcEntry< Target >(&table)[N], Sink sink, void *context)
 Construct over a table.
 
template<typename Store >
uint8_t on_cc (uint8_t channel, uint8_t cc, uint8_t value, const Store &store) const
 Route one ControlChange event.
 
uint8_t on_cc (uint8_t channel, uint8_t cc, uint8_t value) const
 Route one ControlChange event through a map with no 14-bit rows.
 
size_t size () const
 Rows in the map.
 
const CcEntry< Target > * begin () const
 The first row, for a walk over them (an echo of the targets' values, a listing)
 
const CcEntry< Target > * end () const
 One past the last row.
 

Member Typedef Documentation

◆ Sink

template<typename Target >
using sbl::control::CcMapper< Target >::Sink = void (*)(void* context, Target target, float value)

The app's write into the merge layer: the context pointer, the row's target and the curve output.

Definition at line 88 of file cc_mapper.hpp.

Constructor & Destructor Documentation

◆ CcMapper()

template<typename Target >
template<size_t N>
sbl::control::CcMapper< Target >::CcMapper ( const CcEntry< Target >(&)  table[N],
Sink  sink,
void *  context 
)
inline

Construct over a table.

Parameters
tableThe rows; the table must outlive the mapper
sinkCalled once per matching row
contextPassed to sink unchanged

Definition at line 97 of file cc_mapper.hpp.

Member Function Documentation

◆ on_cc() [1/2]

template<typename Target >
template<typename Store >
uint8_t sbl::control::CcMapper< Target >::on_cc ( uint8_t  channel,
uint8_t  cc,
uint8_t  value,
const Store &  store 
) const
inline

Route one ControlChange event.

Call after store has taken the event.

Template Parameters
StoreProvides float cc(uint8_t number) const in [0, 1]
Parameters
channelMIDI channel, 0 to 15
ccController number, 0 to 127
valueController value, 0 to 127
storeThe app's CC store; supplies the other half of a 14-bit pair
Returns
Rows dispatched

Definition at line 113 of file cc_mapper.hpp.

References sbl::control::ANY_CHANNEL, sbl::control::cam_evaluate(), sbl::control::CcEntry< Target >::cc, sbl::control::CcEntry< Target >::channel, sbl::control::CcEntry< Target >::curve, sbl::control::CcEntry< Target >::flags, sbl::control::Paired14, sbl::control::CcEntry< Target >::target, and sbl::midi::to_7bit().

◆ on_cc() [2/2]

template<typename Target >
uint8_t sbl::control::CcMapper< Target >::on_cc ( uint8_t  channel,
uint8_t  cc,
uint8_t  value 
) const
inline

Route one ControlChange event through a map with no 14-bit rows.

Parameters
channelMIDI channel, 0 to 15
ccController number, 0 to 127
valueController value, 0 to 127
Returns
Rows dispatched

Definition at line 151 of file cc_mapper.hpp.

References sbl::control::CcMapper< Target >::on_cc().

Referenced by sbl::control::CcMapper< Target >::on_cc().

◆ size()

template<typename Target >
size_t sbl::control::CcMapper< Target >::size ( ) const
inline

Rows in the map.

Definition at line 154 of file cc_mapper.hpp.

◆ begin()

template<typename Target >
const CcEntry< Target > * sbl::control::CcMapper< Target >::begin ( ) const
inline

The first row, for a walk over them (an echo of the targets' values, a listing)

Definition at line 157 of file cc_mapper.hpp.

◆ end()

template<typename Target >
const CcEntry< Target > * sbl::control::CcMapper< Target >::end ( ) const
inline

One past the last row.

Definition at line 159 of file cc_mapper.hpp.


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