blob: ebd8588956986ff8b48adc7e3039e32a63cc5b70 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
/*
* Copyright (c) 2021, kleines Filmröllchen <filmroellchen@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "Clip.h"
namespace LibDSP {
Sample AudioClip::sample_at(u32 time)
{
VERIFY(time < m_length);
return m_samples[time];
}
void NoteClip::set_note(RollNote note)
{
VERIFY(note.pitch >= 0 && note.pitch < note_count);
VERIFY(note.off_sample < m_length);
VERIFY(note.length() >= 2);
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);
}
}
|