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
panel_report.hpp
Go to the documentation of this file.
1/**
2 * @file panel_report.hpp
3 * @brief An app's parameter values as `#PANEL` lines, for bench frontends
4 *
5 * Which parameters are on the panel, and their names, come from the app's
6 * params manifest: sloth generates PANEL_PARAMS and PARAM_NAMES in
7 * sbl/app/params.hpp and writes the rest of the declaration (controls, CCs,
8 * groups) into the SHIM, where a bench reads it. The app prints only values,
9 * as tagged-output lines:
10 * @code
11 * #PANEL tune=0.512 fine=0.500 wave=0.250 shape=0.500
12 * @endcode
13 *
14 * update() takes a parameter's current value and ignores a parameter the
15 * panel does not show. poll() writes the panel's values, in PANEL_PARAMS
16 * order, when one has moved, at a capped rate (log/tagged.hpp TaggedValues).
17 *
18 * @context Main loop only: the report writes to the log sink.
19 *
20 * Usage:
21 * @code
22 * #include <sbl/app/params.hpp>
23 * sbl::control::PanelReport panel{sbl::app::PANEL_PARAMS, sbl::app::PARAM_NAMES};
24 *
25 * while (true) { // main loop
26 * for (uint8_t i = 0; i < sbl::app::PARAM_COUNT; ++i) {
27 * const auto p = static_cast<sbl::app::Param>(i);
28 * panel.update(p, merged(p));
29 * }
30 * panel.poll<SBL_LOG_OUTPUT>(sbl::system::timer::millis());
31 * }
32 * @endcode
33 */
34
35#ifndef SBL_CONTROL_PANEL_REPORT_HPP_
36#define SBL_CONTROL_PANEL_REPORT_HPP_
37
38#include <cstddef>
39#include <cstdint>
40
42
43namespace sbl::control {
44
45/**
46 * @brief The values of the parameters a panel shows, as `#PANEL` lines
47 *
48 * @tparam Target The app's parameter enum (sbl::app::Param)
49 * @tparam N Number of parameters on the panel
50 * @tparam LINE Line buffer size; a longer `#PANEL` line is split over several lines
51 */
52template<typename Target, size_t N, size_t LINE = 128>
54public:
55 /**
56 * @param params The parameters on the panel, in page order (PANEL_PARAMS)
57 * @param names Every parameter's key, indexed by Target (PARAM_NAMES)
58 */
59 template<size_t COUNT>
60 PanelReport(const Target (&params)[N], const char* const (&names)[COUNT]) : params_(params), values_("PANEL") {
61 for (size_t slot = 0; slot < N; ++slot) {
62 const auto index = static_cast<size_t>(params[slot]);
63 values_.name(slot, index < COUNT ? names[index] : nullptr);
64 }
65 }
66
67 void set_interval_ms(uint32_t ms) { values_.set_interval_ms(ms); }
68 void set_threshold(float threshold) { values_.set_threshold(threshold); }
69 void set_decimals(uint8_t decimals) { values_.set_decimals(decimals); }
70
71 /** Take a parameter's current value; one the panel does not show is ignored. */
72 void update(Target target, float value) {
73 for (size_t slot = 0; slot < N; ++slot) {
74 if (params_[slot] == target) {
75 values_.set(slot, value);
76 return;
77 }
78 }
79 }
80
81 /** Write `#PANEL` if a value moved and the interval has passed; true if it wrote. */
82 template<typename Output>
83 bool poll(uint32_t now_ms) {
84 return values_.template poll<Output>(now_ms);
85 }
86
87 /** Write every value at the next poll, moved or not: for a reader that just connected. */
88 void force() { values_.force(); }
89
90private:
91 const Target (&params_)[N];
93};
94
95template<typename Target, size_t N, size_t COUNT>
96PanelReport(const Target (&)[N], const char* const (&)[COUNT]) -> PanelReport<Target, N>;
97
98} // namespace sbl::control
99
100#endif // SBL_CONTROL_PANEL_REPORT_HPP_
The values of the parameters a panel shows, as #PANEL lines.
void update(Target target, float value)
bool poll(uint32_t now_ms)
PanelReport(const Target(&params)[N], const char *const (&names)[COUNT])
Named values written under one tag, on change, at a capped rate.
Definition tagged.hpp:182
The control stack: scheduler, event queue, merge, CC mapping, calibration.
Tagged output lines: a builder and a throttled value report.