Clip.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * Copyright (c) 2021, kleines Filmröllchen <filmroellchen@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "Clip.h"
  7. namespace DSP {
  8. Sample AudioClip::sample_at(u32 time)
  9. {
  10. VERIFY(time < m_length);
  11. return m_samples[time];
  12. }
  13. Optional<RollNote> NoteClip::note_at(u32 time, u8 pitch) const
  14. {
  15. for (auto& note : m_notes) {
  16. if (time >= note.on_sample && time <= note.off_sample && pitch == note.pitch)
  17. return note;
  18. }
  19. return {};
  20. }
  21. void NoteClip::set_note(RollNote note)
  22. {
  23. m_notes.remove_all_matching([&](auto const& other) {
  24. return other.pitch == note.pitch && other.overlaps_with(note);
  25. });
  26. m_notes.append(note);
  27. }
  28. void NoteClip::remove_note(RollNote note)
  29. {
  30. // FIXME: See header; this could be much faster with a better datastructure.
  31. m_notes.remove_first_matching([note](auto const& element) {
  32. return element.on_sample == note.on_sample && element.off_sample == note.off_sample && element.pitch == note.pitch;
  33. });
  34. }
  35. }