Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
value_source_binding.hpp
Go to the documentation of this file.
1#pragma once
2
18
19#include <memory>
20
22
23namespace pulp::view {
24
25class View;
26class FrameClock;
27
46public:
50 using Tick = bool (*)(void* context, float dt);
51
52 FrameClockBinding(View& owner, Tick tick, void* context);
54
57
60 void set_wanted(bool wanted) { wanted_ = wanted; }
61 bool wanted() const { return wanted_; }
62
67 void refresh();
68
72 void stop();
73
74 bool subscribed() const { return sub_id_ != -1; }
75 FrameClock* subscribed_clock() const { return subscribed_clock_; }
76 View& owner() const { return owner_; }
77
78private:
79 friend class View;
80
83 bool on_frame(float dt);
84
85 View& owner_;
86 Tick tick_;
87 void* context_;
88 FrameClockBinding* next_ = nullptr; // owner's intrusive enrolment list
89 bool wanted_ = false; // owner has something to read
90 int sub_id_ = -1; // FrameClock subscription id, -1 = none
91 FrameClock* subscribed_clock_ = nullptr; // cached for unsubscribe
92};
93
103public:
104 explicit MeterSourceBinding(View& owner)
105 : binding_(owner, &MeterSourceBinding::tick, this) {}
106
111 void set_source(std::shared_ptr<MeterSource> source, int channel);
112
117 void set_active(bool active);
118 bool active() const { return active_; }
119
121 void refresh() { binding_.refresh(); }
122 void stop() { binding_.stop(); }
123
126 const MeterFrame& frame() const { return frame_; }
127
128 bool has_source() const { return static_cast<bool>(source_); }
129 int channel() const { return channel_; }
130 bool subscribed() const { return binding_.subscribed(); }
131 FrameClock* subscribed_clock() const { return binding_.subscribed_clock(); }
132
133private:
134 static bool tick(void* context, float dt);
135 void update_wanted() { binding_.set_wanted(source_ && active_); }
136
137 FrameClockBinding binding_;
138 std::shared_ptr<MeterSource> source_;
139 int channel_ = 0;
140 bool active_ = true;
141 MeterFrame frame_{};
142};
143
147public:
148 explicit ScalarSourceBinding(View& owner)
149 : binding_(owner, &ScalarSourceBinding::tick, this) {}
150
153 void set_source(std::shared_ptr<ScalarSource> source);
154
156 void set_active(bool active);
157 bool active() const { return active_; }
158
159 void refresh() { binding_.refresh(); }
160 void stop() { binding_.stop(); }
161
164 float value() const { return value_; }
165
166 bool has_source() const { return static_cast<bool>(source_); }
167 bool subscribed() const { return binding_.subscribed(); }
168 FrameClock* subscribed_clock() const { return binding_.subscribed_clock(); }
169
170private:
171 static bool tick(void* context, float dt);
172 void update_wanted() { binding_.set_wanted(source_ && active_); }
173
174 FrameClockBinding binding_;
175 std::shared_ptr<ScalarSource> source_;
176 bool active_ = true;
177 float value_ = 0.0f;
178};
179
180} // namespace pulp::view
friend class View
Definition value_source_binding.hpp:79
FrameClockBinding(View &owner, Tick tick, void *context)
void refresh()
(Re)point the subscription at the owner's currently reachable clock, unsubscribing when wanted() is f...
bool wanted() const
Definition value_source_binding.hpp:61
bool subscribed() const
Definition value_source_binding.hpp:74
FrameClockBinding(const FrameClockBinding &)=delete
bool(*)(void *context, float dt) Tick
Per-frame callback.
Definition value_source_binding.hpp:50
FrameClock * subscribed_clock() const
Definition value_source_binding.hpp:75
View & owner() const
Definition value_source_binding.hpp:76
void set_wanted(bool wanted)
Declare whether the owner currently has anything to read.
Definition value_source_binding.hpp:60
FrameClockBinding & operator=(const FrameClockBinding &)=delete
void stop()
Unsubscribe from the cached clock, if subscribed.
Definition frame_clock.hpp:14
void stop()
Definition value_source_binding.hpp:122
FrameClock * subscribed_clock() const
Definition value_source_binding.hpp:131
bool active() const
Definition value_source_binding.hpp:118
bool subscribed() const
Definition value_source_binding.hpp:130
void set_source(std::shared_ptr< MeterSource > source, int channel)
Bind a source (or nullptr to unbind, which drops the subscription so the view stops holding the edito...
bool has_source() const
Definition value_source_binding.hpp:128
void refresh()
Re-evaluate the subscription against the owner's reachable clock.
Definition value_source_binding.hpp:121
MeterSourceBinding(View &owner)
Definition value_source_binding.hpp:104
const MeterFrame & frame() const
The most recent frame snapshotted on the clock.
Definition value_source_binding.hpp:126
int channel() const
Definition value_source_binding.hpp:129
void set_active(bool active)
Owner-level gate, ANDed with having a source: false parks the binding (unsubscribed,...
void set_source(std::shared_ptr< ScalarSource > source)
Drops the cached value along with the old source — see MeterSourceBinding::set_source.
void stop()
Definition value_source_binding.hpp:160
bool subscribed() const
Definition value_source_binding.hpp:167
FrameClock * subscribed_clock() const
Definition value_source_binding.hpp:168
float value() const
The most recent value snapshotted on the clock.
Definition value_source_binding.hpp:164
ScalarSourceBinding(View &owner)
Definition value_source_binding.hpp:148
bool active() const
Definition value_source_binding.hpp:157
void set_active(bool active)
See MeterSourceBinding::set_active.
void refresh()
Definition value_source_binding.hpp:159
bool has_source() const
Definition value_source_binding.hpp:166
Definition view.hpp:73
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
A single multi-channel meter reading.
Definition value_source.hpp:39
Source-compatible spelling of <pulp/dataplane/value_source.hpp>.