Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
parameter_edit.hpp
Go to the documentation of this file.
1#pragma once
2
25
26#include <pulp/state/store.hpp>
27#include <array>
28#include <cstddef>
29
30namespace pulp::state {
31
33public:
35 static constexpr std::size_t kMaxParams = 8;
36
37 explicit ParameterEdit(StateStore& store) : store_(&store) {}
38
39 ParameterEdit(const ParameterEdit&) = delete;
41
45
50 void begin(std::initializer_list<ParamID> ids) {
51 finish();
52 count_ = 0;
53 for (ParamID id : ids) {
54 if (count_ >= kMaxParams) break;
55 ids_[count_] = id;
56 values_[count_] = store_->get_value(id);
57 store_->begin_gesture(id);
58 ++count_;
59 }
60 active_ = count_ > 0;
61 }
62
64 void begin(ParamID id) { begin({id}); }
65
68 void set(ParamID id, float value) {
69 for (std::size_t i = 0; i < count_; ++i) {
70 if (ids_[i] == id) {
71 values_[i] = value;
72 store_->set_value(id, value);
73 return;
74 }
75 }
76 }
77
82 float display_value(ParamID id, float fallback) const {
83 if (active_) {
84 for (std::size_t i = 0; i < count_; ++i)
85 if (ids_[i] == id) return values_[i];
86 }
87 return fallback;
88 }
89
90 bool active() const { return active_; }
91
94 void finish() {
95 if (!active_) return;
96 for (std::size_t i = 0; i < count_; ++i)
97 store_->end_gesture(ids_[i]);
98 active_ = false;
99 count_ = 0;
100 }
101
102private:
103 StateStore* store_;
104 std::array<ParamID, kMaxParams> ids_{};
105 std::array<float, kMaxParams> values_{};
106 std::size_t count_ = 0;
107 bool active_ = false;
108};
109
110} // namespace pulp::state
void set(ParamID id, float value)
Write a raw value to a parameter inside the gesture and update the in-flight cache.
Definition parameter_edit.hpp:68
ParameterEdit(StateStore &store)
Definition parameter_edit.hpp:37
void begin(ParamID id)
Convenience single-parameter begin.
Definition parameter_edit.hpp:64
void finish()
End the gesture (closing each parameter's host gesture).
Definition parameter_edit.hpp:94
bool active() const
Definition parameter_edit.hpp:90
float display_value(ParamID id, float fallback) const
The value the UI should display for id: the in-flight cache while a gesture is active,...
Definition parameter_edit.hpp:82
void begin(std::initializer_list< ParamID > ids)
Begin a gesture over ids.
Definition parameter_edit.hpp:50
ParameterEdit & operator=(const ParameterEdit &)=delete
~ParameterEdit()
End any in-flight gesture so a gesture is never left open if the view is destroyed mid-drag.
Definition parameter_edit.hpp:44
ParameterEdit(const ParameterEdit &)=delete
static constexpr std::size_t kMaxParams
Maximum number of parameters a single gesture can drive.
Definition parameter_edit.hpp:35
Centralized parameter storage with lock-free value access.
Definition store.hpp:164
SequencerStateChannel is the audio-safe transport for a plugin's structured NON-parameter state: the ...
Definition audio_device_manager.hpp:48
uint32_t ParamID
Unique parameter identifier, stable across plugin versions.
Definition parameter.hpp:55