Sound Byte Libs
0.5.1-121-g3358a44
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
preset.hpp
Go to the documentation of this file.
1
// sbl/control/preset.hpp — A voice's settings, kept and recalled by program
2
//
3
// A preset is what a controller would have sent: a handful of CC values. It
4
// is applied by pushing those values through the app's own CcMapper, so a
5
// preset lands exactly where a knob does — same curves, same merge policies,
6
// same targets — and an app needs no second path into its parameters.
7
//
8
// Presets are generated, never parsed: they are authored in the app's
9
// `app.sbl.json` (inline, or a file or directory it points at) and sloth
10
// emits them as `sbl::app::presets`. Nothing reads a file at runtime, and
11
// hardware and the workbench get the same table.
12
//
13
// Program numbers are MIDI's: a Program Change selects a preset, so a MIDI
14
// file that names a sound gets one. A program the table does not have leaves
15
// the voice alone; silence is worse than an unchanged voice.
16
//
17
// Usage:
18
// #include <sbl/hw/config/presets.hpp> // generated
19
// if (const auto* p = sbl::control::find_preset(sbl::app::presets,
20
// sbl::app::preset_count, program)) {
21
// sbl::control::apply_preset(*p, [](uint8_t cc, uint8_t value) {
22
// mapper.on_cc(channel, cc, value, store);
23
// });
24
// }
25
26
#ifndef SBL_CONTROL_PRESET_HPP_
27
#define SBL_CONTROL_PRESET_HPP_
28
29
#include <cstdint>
30
31
namespace
sbl::control
{
32
33
/// One controller value in a preset.
34
struct
PresetCc
{
35
uint8_t
cc
;
36
uint8_t
value
;
37
};
38
39
/// A named set of controller values, selected by MIDI program number.
40
struct
Preset
{
41
uint8_t
program
;
///< MIDI program (0–127) that selects it
42
const
char
*
name
;
///< what it is called, for logs and displays
43
const
PresetCc
*
cc
;
///< the values it sets
44
uint8_t
count
;
45
};
46
47
/// The preset a program selects, or nullptr if the table has none.
48
inline
const
Preset
*
find_preset
(
const
Preset
*
presets
,
uint8_t
count,
uint8_t
program) {
49
if
(
presets
==
nullptr
)
return
nullptr
;
50
for
(
uint8_t
i
= 0;
i
< count; ++
i
) {
51
if
(
presets
[
i
].program == program)
return
&
presets
[
i
];
52
}
53
return
nullptr
;
54
}
55
56
/// Send a preset's values wherever a controller's would go.
57
template
<
typename
Sink>
58
inline
void
apply_preset
(
const
Preset
&
preset
, Sink&&
sink
) {
59
for
(
uint8_t
i
= 0;
i
<
preset
.count; ++
i
) {
60
sink
(
preset
.
cc
[
i
].
cc
,
preset
.
cc
[
i
].value);
61
}
62
}
63
64
}
// namespace sbl::control
65
66
#endif
// SBL_CONTROL_PRESET_HPP_
sbl::control
Control Stack v2: scheduler, event queue, merge, CC mapping, calibration, presets.
Definition
calibration.hpp:34
sbl::control::apply_preset
void apply_preset(const Preset &preset, Sink &&sink)
Send a preset's values wherever a controller's would go.
Definition
preset.hpp:58
sbl::control::find_preset
const Preset * find_preset(const Preset *presets, uint8_t count, uint8_t program)
The preset a program selects, or nullptr if the table has none.
Definition
preset.hpp:48
sbl::control::CcEntry
Definition
cc_mapper.hpp:55
sbl::control::CcEntry::cc
uint8_t cc
controller number (the MSB for Paired14)
Definition
cc_mapper.hpp:57
sbl::control::PresetCc
One controller value in a preset.
Definition
preset.hpp:34
sbl::control::PresetCc::cc
uint8_t cc
Definition
preset.hpp:35
sbl::control::PresetCc::value
uint8_t value
Definition
preset.hpp:36
sbl::control::Preset
A named set of controller values, selected by MIDI program number.
Definition
preset.hpp:40
sbl::control::Preset::name
const char * name
what it is called, for logs and displays
Definition
preset.hpp:42
sbl::control::Preset::count
uint8_t count
Definition
preset.hpp:44
sbl::control::Preset::cc
const PresetCc * cc
the values it sets
Definition
preset.hpp:43
sbl::control::Preset::program
uint8_t program
MIDI program (0–127) that selects it.
Definition
preset.hpp:41
src
sbl
control
preset.hpp
Generated by
1.9.8