mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 05:07:35 +00:00
Piano+LibDSP: Move Track to LibDSP
This is a tangly commit and it fixes all the bugs that a plain move would have caused (i.e. we need to touch other logic which had wrong assumptions).
This commit is contained in:
parent
125122a9ab
commit
4941cffdd0
29 changed files with 322 additions and 413 deletions
|
@ -16,30 +16,18 @@ Sample AudioClip::sample_at(u32 time)
|
|||
|
||||
void NoteClip::set_note(RollNote note)
|
||||
{
|
||||
VERIFY(note.pitch >= 0 && note.pitch < note_frequencies.size());
|
||||
VERIFY(note.off_sample < m_length);
|
||||
VERIFY(note.length() >= 2);
|
||||
m_notes.remove_all_matching([&](auto const& other) {
|
||||
return other.pitch == note.pitch && other.overlaps_with(note);
|
||||
});
|
||||
m_notes.append(note);
|
||||
}
|
||||
|
||||
auto& notes = m_notes[note.pitch];
|
||||
for (auto it = notes.begin(); !it.is_end();) {
|
||||
auto iterated_note = *it;
|
||||
if (iterated_note.on_sample > note.off_sample) {
|
||||
notes.insert_before(it, note);
|
||||
return;
|
||||
}
|
||||
if (iterated_note.on_sample <= note.on_sample && iterated_note.off_sample >= note.on_sample) {
|
||||
notes.remove(it);
|
||||
return;
|
||||
}
|
||||
if ((note.on_sample == 0 || iterated_note.on_sample >= note.on_sample - 1) && iterated_note.on_sample <= note.off_sample) {
|
||||
notes.remove(it);
|
||||
it = notes.begin();
|
||||
continue;
|
||||
}
|
||||
++it;
|
||||
}
|
||||
|
||||
notes.append(note);
|
||||
void NoteClip::remove_note(RollNote note)
|
||||
{
|
||||
// FIXME: See header; this could be much faster with a better datastructure.
|
||||
m_notes.remove_first_matching([note](auto const& element) {
|
||||
return element.on_sample == note.on_sample && element.off_sample == note.off_sample && element.pitch == note.pitch;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue