27 requires GlmVectorType<T>;
28 requires std::same_as<glm_component_type<T>,
float>;
32 static constexpr bool is_box =
requires(T box) {
33 requires std::same_as<
decltype(box.min), glm::vec3>;
34 requires std::same_as<
decltype(box.max), glm::vec3>;
35 } &&
sizeof(T) == 2 *
sizeof(glm::vec3);
47 m_dirty.store(
true, std::memory_order_release);
73 [[nodiscard]]
bool has_value() const noexcept {
return m_set.load(std::memory_order_acquire); }
76 [[nodiscard]]
size_t width() const noexcept {
return m_width.load(std::memory_order_acquire); }
79 [[nodiscard]]
double value() const noexcept {
return m_lane[0].load(std::memory_order_relaxed); }
84 [[nodiscard]] T
value() const noexcept
89 operator double() const noexcept {
return value(); }
95 void settle() noexcept {
m_dirty.exchange(
false, std::memory_order_acq_rel); }
103 template <
typename T =
double>
105 [[nodiscard]] std::optional<T>
pending() noexcept
110 if (!
m_dirty.exchange(
false, std::memory_order_acq_rel)) {
122 const State state = incoming.read_state();
124 m_dirty.store(
true, std::memory_order_release);
128 template <
typename T>
138 template <
typename T>
142 return static_cast<uint8_t
>(glm_component_count<T>());
150 [[nodiscard]]
bool changed() const noexcept {
return m_dirty.load(std::memory_order_acquire); }
159 std::array<double, k_lanes>
lanes {};
164 template <
typename T>
167 std::array<double, k_lanes> lanes {};
169 for (
size_t index = 0; index < glm_component_count<T>(); ++index) {
170 lanes[index] =
value[
static_cast<glm::length_t
>(index)];
174 }
else if constexpr (std::is_enum_v<T>) {
175 lanes[0] =
static_cast<double>(
static_cast<std::underlying_type_t<T>
>(
value));
177 lanes[0] =
static_cast<double>(
value);
182 template <
typename T>
183 static T
from_lanes(
const std::array<double, k_lanes>& lanes)
noexcept
187 for (
size_t index = 0; index < glm_component_count<T>(); ++index) {
188 vector[
static_cast<glm::length_t
>(index)] =
static_cast<float>(lanes[index]);
193 box.min = {
static_cast<float>(lanes[0]),
static_cast<float>(lanes[1]),
static_cast<float>(lanes[2]) };
194 box.max = {
static_cast<float>(lanes[3]),
static_cast<float>(lanes[4]),
static_cast<float>(lanes[5]) };
196 }
else if constexpr (std::is_enum_v<T>) {
197 return static_cast<T
>(
static_cast<std::underlying_type_t<T>
>(lanes[0]));
198 }
else if constexpr (std::same_as<T, bool>) {
199 return lanes[0] != 0.0;
201 return static_cast<T
>(lanes[0]);
205 template <
typename T>
206 [[nodiscard]] std::array<double, k_lanes>
lanes_for() const noexcept
209 return {
m_lane[0].load(std::memory_order_relaxed), 0.0, 0.0, 0.0 };
219 for (
size_t index = 0; index <
k_lanes; ++index) {
220 state.
lanes[index] =
m_lane[index].load(std::memory_order_relaxed);
223 state.
set =
m_set.load(std::memory_order_relaxed);
228 void store(
const std::array<double, k_lanes>& lanes, uint8_t
width,
bool set)
noexcept
231 for (
size_t index = 0; index <
k_lanes; ++index) {
232 m_lane[index].store(lanes[index], std::memory_order_relaxed);
235 m_set.store(set, std::memory_order_release);
240 const State state = other.read_state();
242 m_dirty.store(other.m_dirty.load(std::memory_order_acquire), std::memory_order_release);
bool has_value() const noexcept
True once a value was given.
static constexpr uint8_t width_of() noexcept
static T from_lanes(const std::array< double, k_lanes > &lanes) noexcept
double value() const noexcept
The value as a double.
bool changed() const noexcept
void set_scalar(double value) noexcept
State read_state() const noexcept
ControlValue & operator=(ControlValue &&other) noexcept
T value() const noexcept
The value as type T, which must be the type it was set with.
static std::array< double, k_lanes > to_lanes(T value) noexcept
void set_blank() noexcept
Marks the slot set with one zero lane and leaves it clean.
ControlValue & operator=(const ControlValue &other) noexcept
static constexpr bool is_box
ControlValue(T value) noexcept
static constexpr bool is_value
std::atomic< uint8_t > m_width
std::array< std::atomic< double >, k_lanes > m_lane
std::array< double, k_lanes > lanes_for() const noexcept
static constexpr size_t k_lanes
std::atomic< bool > m_dirty
ControlValue(ControlValue &&other) noexcept
static constexpr bool is_vector
size_t width() const noexcept
Components held: 0 when empty, 1 for a number, flag or enum, 2 to 4 for a vector, 6 for a box.
void store(const std::array< double, k_lanes > &lanes, uint8_t width, bool set) noexcept
std::atomic< bool > m_set
ControlValue(const ControlValue &other) noexcept
void observe(T actual) noexcept
Shows the value the owner really has.
void assign(const ControlValue &incoming) noexcept
Takes everything incoming holds, so the next due() is true.
bool due() const noexcept
True when a consumer should apply this value now.
void settle() noexcept
Marks the current value as applied.
void refresh() noexcept
Nothing to read for a plain value.
std::optional< T > pending() noexcept
The value to apply now as type T, or nullopt when nothing is due.
void copy_state(const ControlValue &other) noexcept
Sequence lock for fixed-size data regions.
Scope guard for a serialized Seqlock write.
auto seqlock_read(const Seqlock &lock, uint32_t max_attempts, Fn &&fn) -> std::optional< std::invoke_result_t< Fn > >
Invoke a read functor under a Seqlock with a bounded retry count.
Main namespace for the Maya Flux audio engine.
std::array< double, k_lanes > lanes