2021-08-27 16:18:11 +02:00
|
|
|
/*
|
2022-01-13 12:07:00 +01:00
|
|
|
* Copyright (c) 2021, kleines Filmröllchen <filmroellchen@serenityos.org>
|
2021-08-27 16:18:11 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "Clip.h"
|
|
|
|
|
|
2022-07-17 11:35:31 +02:00
|
|
|
namespace DSP {
|
2021-08-27 16:18:11 +02:00
|
|
|
|
|
|
|
|
Sample AudioClip::sample_at(u32 time)
|
|
|
|
|
{
|
|
|
|
|
VERIFY(time < m_length);
|
|
|
|
|
return m_samples[time];
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-06 20:46:41 +01:00
|
|
|
Optional<RollNote> NoteClip::note_at(u32 time, u8 pitch) const
|
|
|
|
|
{
|
|
|
|
|
for (auto& note : m_notes) {
|
|
|
|
|
if (time >= note.on_sample && time <= note.off_sample && pitch == note.pitch)
|
|
|
|
|
return note;
|
|
|
|
|
}
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-27 16:18:11 +02:00
|
|
|
void NoteClip::set_note(RollNote note)
|
|
|
|
|
{
|
2022-07-13 12:44:19 +02:00
|
|
|
m_notes.remove_all_matching([&](auto const& other) {
|
|
|
|
|
return other.pitch == note.pitch && other.overlaps_with(note);
|
|
|
|
|
});
|
|
|
|
|
m_notes.append(note);
|
|
|
|
|
}
|
2021-08-27 16:18:11 +02:00
|
|
|
|
2022-07-13 12:44:19 +02:00
|
|
|
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;
|
|
|
|
|
});
|
2021-08-27 16:18:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|