1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 18:37:35 +00:00

Piano: Fix insertion and deletion of notes

On mouse move the pressed button is not present in the event argument
which causes the corresponding code to never fire. Instead it now stores
the original mouse down event and acts according to that on mouse move.
This commit is contained in:
Florian Kaiser 2023-02-06 20:46:41 +01:00 committed by Jelle Raaijmakers
parent 4ab7216827
commit 815442b2b5
6 changed files with 71 additions and 46 deletions

View file

@ -14,6 +14,15 @@ Sample AudioClip::sample_at(u32 time)
return m_samples[time];
}
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 {};
}
void NoteClip::set_note(RollNote note)
{
m_notes.remove_all_matching([&](auto const& other) {

View file

@ -6,6 +6,7 @@
#pragma once
#include <AK/Forward.h>
#include <AK/RefCounted.h>
#include <AK/SinglyLinkedList.h>
#include <AK/Types.h>
@ -50,6 +51,7 @@ public:
{
}
Optional<RollNote> note_at(u32 time, u8 pitch) const;
void set_note(RollNote note);
// May do nothing; that's fine.
void remove_note(RollNote note);

View file

@ -146,6 +146,16 @@ void AudioTrack::compute_current_clips_signal()
TODO();
}
Optional<RollNote> NoteTrack::note_at(u32 time, u8 pitch) const
{
for (auto& clip : m_clips) {
if (time >= clip.start() && time <= clip.end())
return clip.note_at(time, pitch);
}
return {};
}
void NoteTrack::set_note(RollNote note)
{
for (auto& clip : m_clips) {

View file

@ -80,6 +80,7 @@ public:
bool check_processor_chain_valid() const override;
ReadonlySpan<NonnullRefPtr<NoteClip>> notes() const { return m_clips.span(); }
Optional<RollNote> note_at(u32 time, u8 pitch) const;
void set_note(RollNote note);
void remove_note(RollNote note);