Clip.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright (c) 2021, kleines Filmröllchen <filmroellchen@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include "Music.h"
  8. #include <AK/SinglyLinkedList.h>
  9. #include <AK/Types.h>
  10. #include <LibCore/Object.h>
  11. namespace LibDSP {
  12. // A clip is a self-contained snippet of notes or audio that can freely move inside and in between tracks.
  13. class Clip : public Core::Object {
  14. C_OBJECT_ABSTRACT(Clip)
  15. public:
  16. Clip(u32 start, u32 length)
  17. : m_start(start)
  18. , m_length(length)
  19. {
  20. }
  21. virtual ~Clip() = default;
  22. u32 start() const { return m_start; }
  23. u32 length() const { return m_length; }
  24. u32 end() const { return m_start + m_length; }
  25. protected:
  26. u32 m_start;
  27. u32 m_length;
  28. };
  29. class AudioClip final : public Clip {
  30. public:
  31. Sample sample_at(u32 time);
  32. Vector<Sample> const& samples() const { return m_samples; }
  33. private:
  34. Vector<Sample> m_samples;
  35. };
  36. class NoteClip final : public Clip {
  37. public:
  38. void set_note(RollNote note);
  39. Array<SinglyLinkedList<RollNote>, note_count>& notes() { return m_notes; }
  40. private:
  41. Array<SinglyLinkedList<RollNote>, note_count> m_notes;
  42. };
  43. }