21inline std::pair<std::unique_ptr<Knob>, state::Binding>
24 auto knob = std::make_unique<Knob>();
31 auto unit =
info->unit;
32 auto range =
info->range;
33 knob->set_format([unit, range](
float norm) {
34 float val = range.denormalize(norm);
36 if (std::abs(val) >= 100) std::snprintf(buf,
sizeof(buf),
"%.0f", val);
37 else if (std::abs(val) >= 10) std::snprintf(buf,
sizeof(buf),
"%.1f", val);
38 else std::snprintf(buf,
sizeof(buf),
"%.2f", val);
39 return std::string(buf) + (unit.empty() ?
"" :
" " + unit);
44 knob->flex().preferred_width = size;
45 knob->flex().preferred_height = size;
49 knob->on_change = [&store, param_id](
float norm) {
58 knob->on_gesture_end = [&store, param_id]() { store.
end_gesture(param_id); };
60 return {std::move(
knob), std::move(binding)};
67 auto fader = std::make_unique<Fader>();
78 fader->on_change = [&store, param_id](
float norm) {
83 fader->on_gesture_end = [&store, param_id]() { store.
end_gesture(param_id); };
85 return {std::move(
fader), std::move(binding)};
92 auto toggle = std::make_unique<Toggle>();
106 toggle->on_toggle = [&store, param_id](
bool on) {
113 return {std::move(
toggle), std::move(binding)};
119 std::vector<std::string> items) {
121 auto combo = std::make_unique<ComboBox>();
124 if (
info) combo->set_id(
info->name);
125 combo->set_items(std::move(items));
126 combo->set_selected(
static_cast<int>(binding.
get()));
129 combo->on_change = [&store, param_id](
int index) {
132 store.
set_value(param_id,
static_cast<float>(index));
136 return {std::move(combo), std::move(binding)};
147 for (
auto&
b : bindings)
b.poll();
158 auto setter = cfg.
set;
159 auto range = cfg.
range;
162 std::string name = cfg.
name;
163 std::string unit = cfg.
unit;
166 auto knob = std::make_unique<Knob>();
168 knob->set_label(name);
171 knob->set_format([unit, range](
float norm) {
172 float val = range.denormalize(norm);
174 if (std::abs(val) >= 100) std::snprintf(buf,
sizeof(buf),
"%.0f", val);
175 else if (std::abs(val) >= 10) std::snprintf(buf,
sizeof(buf),
"%.1f", val);
176 else std::snprintf(buf,
sizeof(buf),
"%.2f", val);
177 return std::string(buf) + (unit.empty() ?
"" :
" " + unit);
180 knob->flex().preferred_width = size;
181 knob->flex().preferred_height = size;
182 knob->on_change = [setter, range](
float norm) {
183 if (setter) setter(range.denormalize(norm));
187 knob->on_gesture_begin = [begin]() {
if (begin) begin(); };
189 return {std::move(
knob), std::move(binding)};
194 auto setter = cfg.
set;
195 auto range = cfg.
range;
198 std::string name = cfg.
name;
201 auto fader = std::make_unique<Fader>();
203 fader->set_label(name);
207 fader->on_change = [setter, range](
float norm) {
208 if (setter) setter(range.denormalize(norm));
210 fader->on_gesture_begin = [begin]() {
if (begin) begin(); };
212 return {std::move(
fader), std::move(binding)};
217 auto setter = cfg.
set;
218 auto range = cfg.
range;
221 std::string name = cfg.
name;
224 auto toggle = std::make_unique<Toggle>();
232 toggle->on_toggle = [setter, range, begin,
end](
bool on) {
235 if (setter) setter(range.denormalize(
on ? 1.0f : 0.0f));
238 return {std::move(
toggle), std::move(binding)};
Reactive parameter binding for UI integration.
Reactive binding between a UI widget and a StateStore parameter.
Definition binding.hpp:43
float get_normalized() const
Read the parameter's value mapped to [0, 1].
Definition binding.hpp:70
const ParamInfo * info() const
Get the immutable metadata for the bound parameter.
Definition binding.hpp:141
float get() const
Read the parameter's current value.
Definition binding.hpp:54
Reactive binding between a UI widget and an arbitrary external value source, interface-compatible wit...
Definition external_binding.hpp:55
float get_normalized() const
Read the value mapped to [0, 1] through the configured range.
Definition external_binding.hpp:81
Centralized parameter storage with lock-free value access.
Definition store.hpp:164
void set_value(ParamID id, float value)
Write a parameter's base value (lock-free).
void set_normalized(ParamID id, float normalized)
Write a parameter from a normalized [0, 1] value (lock-free).
void end_gesture(ParamID id)
Signal the host that the current gesture has ended.
void begin_gesture(ParamID id)
Signal the host that a gesture (drag, click) has begun on a parameter.
Lambda-backed parameter binding for values NOT owned by a StateStore.
uint32_t ParamID
Unique parameter identifier, stable across plugin versions.
Definition parameter.hpp:55
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
std::pair< std::unique_ptr< Knob >, state::Binding > attach_knob(state::StateStore &store, state::ParamID id, float size=60.0f)
Attach a Knob widget to a parameter.
Definition param_attachment.hpp:22
std::pair< std::unique_ptr< Toggle >, state::Binding > attach_toggle(state::StateStore &store, state::ParamID id)
Attach a Toggle widget to a boolean parameter.
Definition param_attachment.hpp:90
void poll_bindings(std::vector< state::Binding > &bindings)
Poll all bindings in a vector to sync with host automation.
Definition param_attachment.hpp:146
std::pair< std::unique_ptr< ComboBox >, state::Binding > attach_combo(state::StateStore &store, state::ParamID id, std::vector< std::string > items)
Attach a ComboBox to an integer/stepped parameter.
Definition param_attachment.hpp:118
std::pair< std::unique_ptr< Fader >, state::Binding > attach_fader(state::StateStore &store, state::ParamID id)
Attach a Fader widget to a parameter.
Definition param_attachment.hpp:65
@ fader
Definition design_ir.hpp:261
@ toggle
Definition design_ir.hpp:272
@ knob
Definition design_ir.hpp:260
@ b
Definition input_events.hpp:39
@ end
Definition geometry.hpp:370
@ info
Definition design_ir.hpp:695
@ on
Definition accessibility.hpp:132
Configuration for an ExternalBinding: the getter/setter that back a UI control whose value is NOT a S...
Definition external_binding.hpp:21
std::string unit
Definition external_binding.hpp:35
std::function< void(float)> set
Write a new plain value. Required for an editable control.
Definition external_binding.hpp:25
std::function< void()> end_gesture
Definition external_binding.hpp:32
std::string name
Display metadata for the widget (label / value formatting). Optional.
Definition external_binding.hpp:34
ParamRange range
Maps plain <-> normalized [0,1].
Definition external_binding.hpp:28
std::function< void()> begin_gesture
Optional host-undo gesture boundaries, called exactly like StateStore gestures around a drag/edit.
Definition external_binding.hpp:31
Additional UI components: ComboBox, Tooltip, ProgressBar, CallOutBox, TabPanel, ListBox,...