20#include "memory/sdram_allocator.h"
54template <
typename... Params>
56 return ((uint64_t{1} <<
static_cast<uint32_t
>(
params)) | ...);
65 [[nodiscard]] int32_t size()
const {
return count_; }
66 [[nodiscard]]
bool empty()
const {
return mask_ == 0; }
68 [[nodiscard]] std::span<const uint8_t>
params()
const {
return {params_.data(), count_}; }
69 [[nodiscard]] std::span<const int32_t> values()
const {
return {values_.data(), count_}; }
72 [[nodiscard]] uint64_t
mask()
const {
return mask_; }
73 [[nodiscard]]
bool has(int32_t param)
const {
return ((mask_ >> param) & 1) != 0; }
74 [[nodiscard]]
bool hasAnyOf(uint64_t
paramMask)
const {
return (mask_ &
paramMask) != 0; }
77 [[nodiscard]] std::optional<int32_t>
get(int32_t param)
const {
78 if (!has(param)) [[likely]] {
82 while (params_[i] != param) {
90 bool set(int32_t param, int32_t value);
92 bool remove(int32_t param);
95 void clear() { *
this =
LockSet{}; }
97 [[nodiscard]]
bool operator==(
const LockSet& other)
const;
103 std::array<uint8_t, kMaxLocksPerNote> params_{};
104 std::array<int32_t, kMaxLocksPerNote> values_{};
116 Pool(Pool&&) =
default;
117 Pool& operator=(Pool&&) =
default;
118 Pool(
const Pool&) =
delete;
119 Pool& operator=(
const Pool&) =
delete;
123 [[nodiscard]] std::optional<uint16_t>
intern(
const LockSet& locks);
126 [[nodiscard]]
LockSet get(uint16_t index)
const;
128 [[nodiscard]] int32_t numSets()
const {
return offsets_.empty() ? 0 :
static_cast<int32_t
>(offsets_.size()) - 1; }
131 template <
typename T>
132 using Array = std::vector<T, memory::sdram_allocator<T>>;
134 [[nodiscard]] uint16_t lookup(uint32_t hash,
const LockSet& locks)
const;
135 void addToHash(uint32_t hash, uint16_t index);
136 void rehash(uint32_t newCapacity);
140 Array<uint32_t> words_;
141 Array<uint32_t> offsets_;
142 Array<uint16_t> hash_;
Definition note_locks.h:63
std::optional< int32_t > get(int32_t param) const
The locked value of param, if it's locked.
Definition note_locks.h:77
uint64_t mask() const
Bit p set if param p is locked.
Definition note_locks.h:72
bool set(int32_t param, int32_t value)
Definition note_locks.cpp:36
bool remove(int32_t param)
False if param wasn't locked.
Definition note_locks.cpp:57
bool merge(const LockSet &other)
Sets each of other's locks, on top of these. False if any of them didn't fit.
Definition note_locks.cpp:71
std::optional< uint16_t > intern(const LockSet &locks)
Definition note_locks.cpp:153
LockSet get(uint16_t index) const
Empty for index 0 or an out-of-range index, so a stale index can never read outside the pool.
Definition note_locks.cpp:108
How a note's parameter locks (note_locks.h) get from the sequencer to the Voice that plays the note.
Definition note_lock_editor.h:29
bool isLockableParam(int32_t param)
Definition note_locks.cpp:30
constexpr uint64_t paramMask(Params... params)
A bit per param, as LockSet::mask() has them.
Definition note_locks.h:55
bool locksSustain(const LockSet &locks)
Definition note_locks.cpp:83
constexpr int32_t kMaxLocksPerNote
Max locks on one note.
Definition note_locks.h:47