summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibDSP/Clip.h
blob: 818a18d15b6d5259e20f7526f2e74f3ec3142d5d (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
46
47
48
49
50
51
52
53
54
55
56
/*
 * Copyright (c) 2021-2022, kleines Filmröllchen <filmroellchen@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <AK/RefCounted.h>
#include <AK/SinglyLinkedList.h>
#include <AK/Types.h>
#include <LibDSP/Music.h>

namespace LibDSP {

// A clip is a self-contained snippet of notes or audio that can freely move inside and in between tracks.
class Clip : public RefCounted<Clip> {
public:
    virtual ~Clip() = default;

    u32 start() const { return m_start; }
    u32 length() const { return m_length; }
    u32 end() const { return m_start + m_length; }

protected:
    Clip(u32 start, u32 length)
        : m_start(start)
        , m_length(length)
    {
    }

    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:
    void set_note(RollNote note);

    Array<SinglyLinkedList<RollNote>, note_frequencies.size()> const& notes() const { return m_notes; }

private:
    Array<SinglyLinkedList<RollNote>, note_frequencies.size()> m_notes;
};

}