Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
param_ordering.hpp
Go to the documentation of this file.
1#pragma once
2
34
36#include <pulp/state/store.hpp>
37
38#include <cstddef>
39#include <span>
40#include <vector>
41
42namespace pulp::state {
43
63
74inline std::vector<ParamOrderingViolation> diff_param_ordering(
75 std::span<const ParamInfo> old_params,
76 std::span<const ParamInfo> new_params) {
77 std::vector<ParamOrderingViolation> violations;
78
79 const auto id_present_in_new = [&](ParamID id) {
80 for (const auto& p : new_params)
81 if (p.id == id) return true;
82 return false;
83 };
84
85 for (std::size_t i = 0; i < old_params.size(); ++i) {
86 const ParamID old_id = old_params[i].id;
87 if (i < new_params.size()) {
88 const ParamID new_id = new_params[i].id;
89 if (new_id != old_id) {
91 i, old_id, new_id});
92 // A position mismatch already means this slot moved; if the old
93 // ID also vanished entirely, that is the more serious removal —
94 // report it too so a caller sees the orphaned automation.
95 if (!id_present_in_new(old_id)) {
97 i, old_id, 0});
98 }
99 }
100 } else {
101 // The new version is shorter — this old slot has no counterpart.
102 violations.push_back({ParamOrderingViolation::Kind::ParamRemoved,
103 i, old_id, 0});
104 }
105 }
106 return violations;
107}
108
110inline std::vector<ParamOrderingViolation> diff_param_ordering(
111 const StateStore& old_store, const StateStore& new_store) {
112 return diff_param_ordering(old_store.all_params(), new_store.all_params());
113}
114
117inline bool param_ordering_stable(std::span<const ParamInfo> old_params,
118 std::span<const ParamInfo> new_params) {
119 return diff_param_ordering(old_params, new_params).empty();
120}
121
123inline bool param_ordering_stable(const StateStore& old_store,
124 const StateStore& new_store) {
125 return diff_param_ordering(old_store, new_store).empty();
126}
127
128} // namespace pulp::state
Centralized parameter storage with lock-free value access.
Definition store.hpp:164
std::span< const ParamInfo > all_params() const
View of all registered parameters (in registration order).
Definition store.hpp:439
SequencerStateChannel is the audio-safe transport for a plugin's structured NON-parameter state: the ...
Definition audio_device_manager.hpp:48
std::vector< ParamOrderingViolation > diff_param_ordering(std::span< const ParamInfo > old_params, std::span< const ParamInfo > new_params)
Diff two parameter descriptors (old vs new) and return every ordering / identity violation,...
Definition param_ordering.hpp:74
bool param_ordering_stable(std::span< const ParamInfo > old_params, std::span< const ParamInfo > new_params)
True iff new_params is an append-only, identity-preserving evolution of old_params (no re-order,...
Definition param_ordering.hpp:117
uint32_t ParamID
Unique parameter identifier, stable across plugin versions.
Definition parameter.hpp:55
One way a new descriptor version broke a previously-shipped parameter's host-facing identity.
Definition param_ordering.hpp:46
Kind
Definition param_ordering.hpp:47
@ ParamRemoved
A host-facing ID present in the old version is absent from the new version entirely.
Definition param_ordering.hpp:55
@ IdChangedAtIndex
The parameter that used to occupy index now carries a different host-facing ID (it was re-ID'd,...
Definition param_ordering.hpp:52
std::size_t index
Registration index in the OLD version.
Definition param_ordering.hpp:59
ParamID old_id
The ID the old version shipped at this slot.
Definition param_ordering.hpp:60
Kind kind
Definition param_ordering.hpp:58
ParamID new_id
The ID now at this index (0 for ParamRemoved).
Definition param_ordering.hpp:61