2021-08-27 17:18:11 +03:00
|
|
|
/*
|
2022-05-11 22:37:55 +03:00
|
|
|
* Copyright (c) 2021-2022, kleines Filmröllchen <filmroellchen@serenityos.org>
|
2021-08-27 17:18:11 +03:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2022-05-11 22:37:55 +03:00
|
|
|
#include <AK/RefCounted.h>
|
2021-08-27 17:18:11 +03:00
|
|
|
#include <AK/SinglyLinkedList.h>
|
|
|
|
#include <AK/Types.h>
|
2022-05-11 22:37:55 +03:00
|
|
|
#include <LibDSP/Music.h>
|
2021-08-27 17:18:11 +03:00
|
|
|
|
2022-07-17 12:35:31 +03:00
|
|
|
namespace DSP {
|
2021-08-27 17:18:11 +03:00
|
|
|
|
|
|
|
// A clip is a self-contained snippet of notes or audio that can freely move inside and in between tracks.
|
2022-05-11 22:37:55 +03:00
|
|
|
class Clip : public RefCounted<Clip> {
|
2021-08-27 17:18:11 +03:00
|
|
|
public:
|
2022-07-13 13:44:19 +03:00
|
|
|
Clip(u32 start, u32 length)
|
|
|
|
: m_start(start)
|
|
|
|
, m_length(length)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-08-27 17:18:11 +03:00
|
|
|
virtual ~Clip() = default;
|
|
|
|
|
|
|
|
u32 start() const { return m_start; }
|
|
|
|
u32 length() const { return m_length; }
|
|
|
|
u32 end() const { return m_start + m_length; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
u32 m_start;
|
|
|
|
u32 m_length;
|
|
|
|
};
|
|
|
|
|
|
|
|
class AudioClip final : public Clip {
|
|
|
|
public:
|
|
|
|
Sample sample_at(u32 time);
|
|
|
|
|
|
|
|
Vector<Sample> const& samples() const { return m_samples; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
Vector<Sample> m_samples;
|
|
|
|
};
|
|
|
|
|
|
|
|
class NoteClip final : public Clip {
|
|
|
|
public:
|
2022-07-13 13:44:19 +03:00
|
|
|
NoteClip(u32 start, u32 length)
|
|
|
|
: Clip(start, length)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-08-27 17:18:11 +03:00
|
|
|
void set_note(RollNote note);
|
2022-07-13 13:44:19 +03:00
|
|
|
// May do nothing; that's fine.
|
|
|
|
void remove_note(RollNote note);
|
|
|
|
|
|
|
|
Span<RollNote const> notes() const { return m_notes.span(); }
|
2021-08-27 17:18:11 +03:00
|
|
|
|
2022-07-13 13:44:19 +03:00
|
|
|
RollNote operator[](size_t index) const { return m_notes[index]; }
|
|
|
|
RollNote operator[](size_t index) { return m_notes[index]; }
|
|
|
|
bool is_empty() const { return m_notes.is_empty(); }
|
2021-08-27 17:18:11 +03:00
|
|
|
|
|
|
|
private:
|
2022-07-13 13:44:19 +03:00
|
|
|
// FIXME: Better datastructures to think about here: B-Trees or good ol' RBTrees (not very cache friendly)
|
|
|
|
Vector<RollNote> m_notes;
|
2021-08-27 17:18:11 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|