Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
design_knobs.hpp
Go to the documentation of this file.
1#pragma once
2
3// pulp::design — semantic knobs over a design's parameters.
4//
5// A knob is one expressive control whose value drives a *bundle* of parameter
6// writes at once: a "minimalism" slider that moves spacing, borders, shadows and
7// accent saturation together; a theme flip; a layout-variant switch. The value
8// of a knob is not a pixel — it is a named position, and each position carries
9// the exact set of writes that position means.
10//
11// Knobs are declared per-design (data-driven: adding a knob is a JSON edit, not
12// a C++ change), resolved to concrete writes here, and each write is classified
13// against the design's bound theme tokens:
14//
15// * a write whose key names a real theme token is a THEME-TOKEN write — apply
16// it at the token layer so the whole design re-tints coherently;
17// * every other write is a LOCAL override — persist it into the artifact's
18// own EDITMODE block (see design_tweaks.hpp) so it survives a reload and
19// lands in the diff, with local overriding theme at render time.
20//
21// The bound theme is passed in as a flat set of token names, not a whole
22// DesignManifest, on purpose: the knob model needs to know only which keys are
23// theme tokens, so it stays decoupled from the manifest/component/view headers
24// and is a pure, deterministic core — no I/O, no window, no render context —
25// unit-testable directly. A caller with a DesignManifest passes
26// `manifest.tokens[*].name`. The inspector panel and the send-to-agent
27// affordance are UI layers that drive these primitives and live elsewhere.
28
29#include <pulp/design/design_tweaks.hpp> // TweakParam, read/rewrite EDITMODE block
30
31#include <optional>
32#include <string>
33#include <string_view>
34#include <vector>
35
36namespace pulp::design {
37
40enum class KnobKind { Slider, Toggle, Enum };
41
46struct KnobWrite {
47 std::string key;
48 std::string json_value;
49};
50
55 std::string label;
56 double at = 0.0;
57 std::vector<KnobWrite> writes;
58};
59
62struct KnobSpec {
63 std::string id;
64 std::string label;
66 std::vector<KnobPosition> positions;
67};
68
70struct KnobSchema {
71 std::vector<KnobSpec> knobs;
72};
73
81std::optional<KnobSchema> parse_knob_schema(std::string_view json);
82
85std::string knob_schema_to_json(const KnobSchema& schema);
86
88const KnobSpec* find_knob(const KnobSchema& schema, std::string_view id);
89
96const KnobPosition* select_position(const KnobSpec& knob, std::string_view value);
97
100
105 const std::vector<std::string>& theme_tokens);
106
109 std::vector<KnobWrite> token_writes;
110 std::vector<KnobWrite> local_writes;
111};
112
115std::optional<KnobEffect> resolve_knob(const KnobSpec& knob, std::string_view value,
116 const std::vector<std::string>& theme_tokens);
117
119struct KnobApply {
120 std::string text;
121 std::vector<KnobWrite> token_writes;
122};
123
134std::optional<KnobApply> apply_knob(std::string_view artifact, const KnobSpec& knob,
135 std::string_view value,
136 const std::vector<std::string>& theme_tokens);
137
146
147} // namespace pulp::design
Definition design_adherence.hpp:32
WriteTarget
Where a resolved write lands.
Definition design_knobs.hpp:99
@ ThemeToken
Definition design_knobs.hpp:99
@ LocalBlock
Definition design_knobs.hpp:99
const KnobSpec * find_knob(const KnobSchema &schema, std::string_view id)
Look up a knob by id (nullptr when absent).
std::optional< KnobSchema > parse_knob_schema(std::string_view json)
Parse a declared knob schema from JSON.
std::optional< KnobEffect > resolve_knob(const KnobSpec &knob, std::string_view value, const std::vector< std::string > &theme_tokens)
Resolve knob set to value into its split writes against theme_tokens.
std::optional< KnobApply > apply_knob(std::string_view artifact, const KnobSpec &knob, std::string_view value, const std::vector< std::string > &theme_tokens)
Apply knob set to value to a design artifact: persist the local writes into the artifact's EDITMODE b...
KnobKind
The kind of control a knob presents.
Definition design_knobs.hpp:40
@ Slider
Definition design_knobs.hpp:40
@ Toggle
Definition design_knobs.hpp:40
@ Enum
Definition design_knobs.hpp:40
const KnobPosition * select_position(const KnobSpec &knob, std::string_view value)
Select the position of knob for value:
std::string knob_schema_to_json(const KnobSchema &schema)
Serialize a schema to stable JSON.
KnobSpec builtin_theme_flip()
Built-in theme-flip knob: an Enum over appearance with "light"/"dark" positions, each writing a local...
WriteTarget classify_write(const KnobWrite &write, const std::vector< std::string > &theme_tokens)
Classify a write against the design's bound theme tokens: ThemeToken iff write.key is one of theme_to...
The result of applying a knob to a design artifact.
Definition design_knobs.hpp:119
std::vector< KnobWrite > token_writes
the token-layer writes, for the caller to apply
Definition design_knobs.hpp:121
std::string text
artifact with the local writes persisted
Definition design_knobs.hpp:120
The concrete effect of setting a knob to a value: its writes split by target.
Definition design_knobs.hpp:108
std::vector< KnobWrite > local_writes
persist into the EDITMODE block
Definition design_knobs.hpp:110
std::vector< KnobWrite > token_writes
apply at the theme/token layer
Definition design_knobs.hpp:109
One selectable position of a knob.
Definition design_knobs.hpp:54
double at
Definition design_knobs.hpp:56
std::vector< KnobWrite > writes
Definition design_knobs.hpp:57
std::string label
Definition design_knobs.hpp:55
A design's declared set of knobs.
Definition design_knobs.hpp:70
std::vector< KnobSpec > knobs
Definition design_knobs.hpp:71
A declared knob: a stable id, a human label, its kind, and its positions in authored order (Slider po...
Definition design_knobs.hpp:62
std::vector< KnobPosition > positions
Definition design_knobs.hpp:66
std::string label
Definition design_knobs.hpp:64
std::string id
Definition design_knobs.hpp:63
KnobKind kind
Definition design_knobs.hpp:65
One parameter write a knob position produces.
Definition design_knobs.hpp:46
std::string json_value
Definition design_knobs.hpp:48
std::string key
Definition design_knobs.hpp:47