17 { slot.has_value() } -> std::convertible_to<bool>;
33 { slot.width() } -> std::convertible_to<size_t>;
34 { slot.value() } -> std::convertible_to<double>;
35 { slot.pending() } -> std::same_as<std::optional<double>>;
59template <ControlSlot Slot>
74 auto storage = std::make_shared<C>();
75 C& controls = *storage;
102 template <
typename C>
103 [[nodiscard]] C
snapshot(
const double* scale =
nullptr)
const
106 ? *
static_cast<const C*
>(
m_storage.get())
110 [&](
const auto&... member) {
124 for (
const Entry& entry :
m_slots) {
125 entry.slot->refresh();
130 if (
const auto due =
m_scale->pending()) {
131 *scale = std::max(0.0, *due);
147 for (
const Entry& entry :
m_slots) {
148 if (entry.name == name) {
149 if (entry.slot->width() > 1) {
152 entry.slot->assign(Slot(value));
168 for (
const Entry& entry :
m_slots) {
169 if (entry.name == name) {
170 entry.slot->settle();
181 template <
typename C>
183 [[nodiscard]]
static std::optional<double>
read_named(
const C& controls, std::string_view name)
185 std::optional<double> found;
187 [&](
const auto&... member) {
200 template <
typename C>
201 [[nodiscard]]
static const void*
tag() noexcept
203 static constexpr char value = 0;
207 template <
typename C>
211 [&](
const auto&... member) {
217 template <
typename Member,
typename C>
218 void add_member(
const Member& member, C& owner,
const std::string& prefix)
220 using Value =
typename Member::value_type;
221 auto& value = member.get(owner);
222 if constexpr (std::same_as<Value, Slot>) {
223 m_slots.push_back({ prefix + std::string(member.name), &value });
225 if (prefix.empty() && member.name ==
"scale") {
231 "every member of a controls struct must be the store's slot type or a described struct of them");
232 add_members(value, prefix + std::string(member.name) +
".");
236 template <
typename C>
240 [&](
const auto&... member) {
246 template <
typename Member,
typename C>
247 static void merge_member(
const Member& member, C& live,
const C& incoming)
249 using Value =
typename Member::value_type;
250 if constexpr (std::same_as<Value, Slot>) {
251 const Slot& given = member.get(incoming);
252 if (given.has_value()) {
253 member.get(live).assign(given);
260 template <
typename Member,
typename C>
264 if (member.name ==
"scale") {
265 member.get(current).observe(scale);
270 template <
typename Member,
typename C>
271 static void read_member(
const Member& member,
const C& owner, std::string_view name,
272 std::optional<double>& found)
274 const auto& value = member.get(owner);
275 if constexpr (std::same_as<typename Member::value_type, Slot>) {
276 if (member.name == name && value.has_value() && value.width() == 1) {
277 found = value.value();
279 }
else if (name.size() > member.name.size() && name.starts_with(member.name)
280 && name[member.name.size()] ==
'.') {
281 if (
const auto inner =
read_named(value, name.substr(member.name.size() + 1))) {
305template <
typename Key, ControlSlot Slot>
311 template <
typename C>
315 store = std::make_unique<Store>();
322 const auto found =
m_stores.find(key);
323 return found ==
m_stores.end() ? nullptr : found->second.get();
326 [[nodiscard]]
const Store*
find(
const Key& key)
const noexcept
328 const auto found =
m_stores.find(key);
329 return found ==
m_stores.end() ? nullptr : found->second.get();
340 for (
const auto& entry :
m_stores) {
341 entry.second->refresh();
346 template <
typename Visit>
349 for (
const auto& entry :
m_stores) {
350 visit(entry.first, *entry.second);
bool settle_named(std::string_view name)
Drops the pending value of the member called name.
bool set_named(std::string_view name, double value)
Sets the member called name to the number value.
ControlValueStore()=default
ControlValueStore & operator=(ControlValueStore &&)=delete
~ControlValueStore()=default
ControlValueStore & operator=(const ControlValueStore &)=delete
static std::optional< double > read_named(const C &controls, std::string_view name)
The number held by the member called name, or nullopt for none or a vector.
static void read_member(const Member &member, const C &owner, std::string_view name, std::optional< double > &found)
static const void * tag() noexcept
C & declare()
Creates the struct and returns it, for the host to hold by reference.
static void observe_scale(const Member &member, C ¤t, double scale)
ControlValueStore(ControlValueStore &&)=delete
static void merge_member(const Member &member, C &live, const C &incoming)
std::shared_ptr< void > m_storage
C snapshot(const double *scale=nullptr) const
A copy of the struct.
static void merge_members(C &live, const C &incoming)
void refresh(double *scale=nullptr)
Reads sources into their slots.
std::vector< Entry > m_slots
void add_members(C &owner, const std::string &prefix)
ControlValueStore(const ControlValueStore &)=delete
void add_member(const Member &member, C &owner, const std::string &prefix)
void merge(const C &incoming)
Applies every member of incoming that holds a value.
Owns one described struct of Slot members for a host such as a network, an operator or an input node.
const Store * find(const Key &key) const noexcept
size_t size() const noexcept
ControlValueStore< Slot > Store
void for_each(const Visit &visit)
Calls visit(key, store) for every store in key order.
std::map< Key, std::unique_ptr< Store > > m_stores
bool erase(const Key &key)
Drops the store of key.
C & declare(const Key &key)
Creates the store of key, replacing any it had, and returns its struct.
void refresh()
Reads the sources of every store.
Store * find(const Key &key) noexcept
The store of key, or null when it has none.
One ControlValueStore per key, for a host with a runtime count of tunable groups.
What ControlValueStore needs of the slot type it owns.
A ControlSlot that also reads as a number, which the named access and the scale mirror need.
A type whose generated sidecar defines Generated::Description<T>::members().
std::shared_ptr< T > store(std::shared_ptr< T > obj)
Transfer ownership of an existing object to the persistent store for process lifetime.
Main namespace for the Maya Flux audio engine.