summaryrefslogtreecommitdiff
path: root/Userland/Applications/Piano
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2021-06-15 23:46:54 +0300
committerLinus Groh <mail@linusgroh.de>2021-06-15 23:59:21 +0100
commit8c7fe8d6c8cca71334c3b46ed201809843d9cf07 (patch)
treed802a66576dc67da67c29e7ccbd50d70bda667f0 /Userland/Applications/Piano
parent08ff148bc38de2db28781b6f37f55c3b1ee66421 (diff)
downloadserenity-8c7fe8d6c8cca71334c3b46ed201809843d9cf07.zip
AK: Add support for removing SinglyLinkedList nodes during iteration
This commit also fixes the now-broken usage of SinglyLinkedList::remove in the Piano application.
Diffstat (limited to 'Userland/Applications/Piano')
-rw-r--r--Userland/Applications/Piano/Track.cpp22
-rw-r--r--Userland/Applications/Piano/Track.h2
2 files changed, 12 insertions, 12 deletions
diff --git a/Userland/Applications/Piano/Track.cpp b/Userland/Applications/Piano/Track.cpp
index 5dde39da04..38d5a3cc65 100644
--- a/Userland/Applications/Piano/Track.cpp
+++ b/Userland/Applications/Piano/Track.cpp
@@ -30,14 +30,14 @@ void Track::fill_sample(Sample& sample)
Audio::Frame new_sample;
for (size_t note = 0; note < note_count; ++note) {
- if (!m_roll_iters[note].is_end()) {
- if (m_roll_iters[note]->on_sample == m_time) {
+ if (!m_roll_iterators[note].is_end()) {
+ if (m_roll_iterators[note]->on_sample == m_time) {
set_note(note, On);
- } else if (m_roll_iters[note]->off_sample == m_time) {
+ } else if (m_roll_iterators[note]->off_sample == m_time) {
set_note(note, Off);
- ++m_roll_iters[note];
- if (m_roll_iters[note].is_end())
- m_roll_iters[note] = m_roll_notes[note].begin();
+ ++m_roll_iterators[note];
+ if (m_roll_iterators[note].is_end())
+ m_roll_iterators[note] = m_roll_notes[note].begin();
}
}
@@ -118,7 +118,7 @@ void Track::reset()
memset(m_envelope, 0, sizeof(m_envelope));
for (size_t note = 0; note < note_count; ++note)
- m_roll_iters[note] = m_roll_notes[note].begin();
+ m_roll_iterators[note] = m_roll_notes[note].begin();
}
String Track::set_recorded_sample(const StringView& path)
@@ -259,9 +259,9 @@ void Track::sync_roll(int note)
{
auto it = m_roll_notes[note].find_if([&](auto& roll_note) { return roll_note.off_sample > m_time; });
if (it.is_end())
- m_roll_iters[note] = m_roll_notes[note].begin();
+ m_roll_iterators[note] = m_roll_notes[note].begin();
else
- m_roll_iters[note] = it;
+ m_roll_iterators[note] = it;
}
void Track::set_roll_note(int note, u32 on_sample, u32 off_sample)
@@ -281,14 +281,14 @@ void Track::set_roll_note(int note, u32 on_sample, u32 off_sample)
if (it->on_sample <= new_roll_note.on_sample && it->off_sample >= new_roll_note.on_sample) {
if (m_time >= it->on_sample && m_time <= it->off_sample)
set_note(note, Off);
- m_roll_notes[note].remove(it);
+ it.remove(m_roll_notes[note]);
sync_roll(note);
return;
}
if ((new_roll_note.on_sample == 0 || it->on_sample >= new_roll_note.on_sample - 1) && it->on_sample <= new_roll_note.off_sample) {
if (m_time >= new_roll_note.off_sample && m_time <= it->off_sample)
set_note(note, Off);
- m_roll_notes[note].remove(it);
+ it.remove(m_roll_notes[note]);
it = m_roll_notes[note].begin();
continue;
}
diff --git a/Userland/Applications/Piano/Track.h b/Userland/Applications/Piano/Track.h
index d6a2abfb1c..696c22ca59 100644
--- a/Userland/Applications/Piano/Track.h
+++ b/Userland/Applications/Piano/Track.h
@@ -86,5 +86,5 @@ private:
const u32& m_time;
SinglyLinkedList<RollNote> m_roll_notes[note_count];
- RollIter m_roll_iters[note_count];
+ RollIter m_roll_iterators[note_count];
};