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
31namespace sbl::control {
32
33/// One controller value in a preset.
38
39/// A named set of controller values, selected by MIDI program number.
40struct 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
45};
46
47/// The preset a program selects, or nullptr if the table has none.
48inline 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.
57template<typename Sink>
58inline 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_
Control Stack v2: scheduler, event queue, merge, CC mapping, calibration, presets.
void apply_preset(const Preset &preset, Sink &&sink)
Send a preset's values wherever a controller's would go.
Definition preset.hpp:58
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
uint8_t cc
controller number (the MSB for Paired14)
Definition cc_mapper.hpp:57
One controller value in a preset.
Definition preset.hpp:34
A named set of controller values, selected by MIDI program number.
Definition preset.hpp:40
const char * name
what it is called, for logs and displays
Definition preset.hpp:42
const PresetCc * cc
the values it sets
Definition preset.hpp:43
uint8_t program
MIDI program (0–127) that selects it.
Definition preset.hpp:41