Deluge Firmware 1.3.0
Build date: 2026.11.28
Loading...
Searching...
No Matches
note_lock_playback.h
1/*
2 * Copyright © 2026 Synthstrom Audible Limited
3 *
4 * This file is part of The Synthstrom Audible Deluge Firmware.
5 *
6 * The Synthstrom Audible Deluge Firmware is free software: you can redistribute it and/or modify it under the
7 * terms of the GNU General Public License as published by the Free Software Foundation,
8 * either version 3 of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
11 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * See the GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along with this program.
15 * If not, see <https://www.gnu.org/licenses/>.
16 */
17
18#pragma once
19
20#include "model/note/note_locks.h"
21#include <array>
22#include <cstdint>
23#include <optional>
24
26
27namespace deluge::note_locks {
28
30struct NoteRef {
31 uint16_t lockSet{0}; // The note's committed set: Note::lockSet, an index into the Song's Pool
32 uint16_t liveTag{0}; // LiveEdit::tag of the held pad whose uncommitted edits the note hears too, else 0
33
34 bool operator==(const NoteRef&) const = default;
35};
36
46struct LiveEdit {
47 LockSet edits;
48 uint16_t tag{0}; // Voices started with this slot's locks carry this tag (VoiceNoteLocks::liveEditTag)
49
50 [[nodiscard]] bool armed() const { return song != nullptr; }
51 [[nodiscard]] bool isFor(const void* song_, const void* clip_) const { return song == song_ && clip == clip_; }
53 [[nodiscard]] bool matches(const void* clip_, int32_t noteRowId_, uint32_t pos_) const {
54 if (clip != clip_ || noteRowId != noteRowId_) {
55 return false;
56 }
57 // With wrap (cross-screen) editing, every copy (pos +- n * wrapLevel) gets the edits too, as it will on commit
58 uint32_t base = pos % wrapLevel;
59 uint32_t offset = pos_ % wrapLevel;
60 return (offset >= base ? offset - base : offset + wrapLevel - base) < length;
61 }
62
63private:
64 friend class LiveEdits;
65 const void* song{nullptr}; // nullptr = not armed
66 const void* clip{nullptr}; // The InstrumentClip, as a TimelineCounter* (what the sequencer's model stack holds)
67 int32_t noteRowId{0};
68 uint32_t pos{0}; // Applies to the notes in [pos, pos + length) of that row
69 uint32_t length{1};
70 uint32_t wrapLevel{1u << 31}; // InstrumentClip::getWrapEditLevel(): huge when not wrap editing
71};
72
74class LiveEdits {
75public:
76 static constexpr int32_t kNumSlots = 8;
77
78 [[nodiscard]] LiveEdit& operator[](int32_t slot) { return slots_[slot]; }
79
84 void arm(int32_t slot, const void* song, const void* clip, int32_t noteRowId, uint32_t pos, uint32_t length,
85 uint32_t wrapLevel, bool samePress = false);
87 void disarm(int32_t slot);
89 void disarmAllOf(const void* owner);
90
92 [[nodiscard]] const LiveEdit* find(const void* clip, int32_t noteRowId, uint32_t pos) const {
93 if (numArmed_ == 0) [[likely]] {
94 return nullptr;
95 }
96 return findArmed(clip, noteRowId, pos);
97 }
98
99 [[nodiscard]] const LiveEdit* findByTag(uint16_t tag) const;
100
101private:
102 [[nodiscard]] const LiveEdit* findArmed(const void* clip, int32_t noteRowId, uint32_t pos) const;
103
104 std::array<LiveEdit, kNumSlots> slots_;
105 int32_t numArmed_{0};
106 uint16_t nextTag_{0};
107};
108
109extern LiveEdits liveEdits;
110
116struct Pending {
117 const LockSet* locks{nullptr}; // nullptr if the note has none
118 NoteRef ref; // Where they came from, for the arpeggiators to remember (ArpNote::locks)
119};
120extern Pending pending;
121
124[[nodiscard]] LockSet currentLocks(const Pool& pool, NoteRef note);
125
128public:
131 PendingScope(const Pool& pool, uint16_t lockSet, const LiveEdit* live) {
132 if (live != nullptr || NoteRef{lockSet, 0} != pending.ref) [[unlikely]] {
133 open(pool, lockSet, live);
134 }
135 }
136
140 PendingScope(const Pool& pool, NoteRef note) {
141 if (note != pending.ref) [[unlikely]] {
142 open(pool, note.lockSet, liveEdits.findByTag(note.liveTag));
143 }
144 }
145
147 PendingScope(const LockSet& locks, NoteRef note) { openWith(locks, note); }
148 ~PendingScope() {
149 if (opened_) [[unlikely]] {
150 pending = opened_->outer;
151 }
152 }
153 PendingScope(const PendingScope&) = delete;
154 PendingScope& operator=(const PendingScope&) = delete;
155
156private:
157 void open(const Pool& pool, uint16_t lockSet, const LiveEdit* live);
158 void openWith(const LockSet& locks, NoteRef note);
159
160 struct Opened {
161 Pending outer;
162 LockSet locks; // What `pending.locks` points at while this scope is open
163 };
164 std::optional<Opened> opened_;
165};
166
167} // namespace deluge::note_locks
The live-edit slots: one per clip-view edit pad press (kEditPadPressBufferSize), indexed like editPad...
Definition note_lock_playback.h:74
void disarm(int32_t slot)
Drops the slot's edits. Its tag stays, so re-arming the same press keeps reaching the voices it start...
Definition note_lock_playback.cpp:46
const LiveEdit * findByTag(uint16_t tag) const
The armed slot with this tag, or nullptr (also for tag 0).
Definition note_lock_playback.cpp:64
const LiveEdit * find(const void *clip, int32_t noteRowId, uint32_t pos) const
The armed slot covering this note, or nullptr. Cheap when no pad is held, which is how the sequencer ...
Definition note_lock_playback.h:92
void disarmAllOf(const void *owner)
Disarms every slot whose song or clip is owner (called as a Song / InstrumentClip is destroyed).
Definition note_lock_playback.cpp:56
void arm(int32_t slot, const void *song, const void *clip, int32_t noteRowId, uint32_t pos, uint32_t length, uint32_t wrapLevel, bool samePress=false)
Definition note_lock_playback.cpp:25
Definition note_locks.h:63
Makes one note's locks pending for as long as it's in scope, then puts back what was pending before.
Definition note_lock_playback.h:127
PendingScope(const Pool &pool, NoteRef note)
Definition note_lock_playback.h:140
PendingScope(const LockSet &locks, NoteRef note)
Definition note_lock_playback.h:147
PendingScope(const Pool &pool, uint16_t lockSet, const LiveEdit *live)
Definition note_lock_playback.h:131
The lock sets of every Note in one Song (or of the notes on the clipboard). Sets are only ever added.
Definition note_locks.h:113
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
LockSet currentLocks(const Pool &pool, NoteRef note)
Definition note_lock_playback.cpp:95
Definition note_lock_playback.h:46
bool matches(const void *clip_, int32_t noteRowId_, uint32_t pos_) const
Whether this slot's edits apply to the note at pos_ of that row.
Definition note_lock_playback.h:53
What something that plays a note later (an arpeggiator) remembers of its locks.
Definition note_lock_playback.h:30
Definition note_lock_playback.h:160
Definition note_lock_playback.h:116