1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:47:35 +00:00

Piano+LibDSP: Move Track to LibDSP

This is a tangly commit and it fixes all the bugs that a plain move
would have caused (i.e. we need to touch other logic which had wrong
assumptions).
This commit is contained in:
kleines Filmröllchen 2022-07-13 12:44:19 +02:00 committed by Linus Groh
parent 125122a9ab
commit 4941cffdd0
29 changed files with 322 additions and 413 deletions

View file

@ -10,13 +10,14 @@
#pragma once
#include "Music.h"
#include "Track.h"
#include <AK/Array.h>
#include <AK/FixedArray.h>
#include <AK/Noncopyable.h>
#include <AK/NonnullOwnPtr.h>
#include <AK/NonnullRefPtr.h>
#include <AK/Vector.h>
#include <LibDSP/Keyboard.h>
#include <LibDSP/Track.h>
class TrackManager {
AK_MAKE_NONCOPYABLE(TrackManager);
@ -26,16 +27,12 @@ public:
TrackManager();
~TrackManager() = default;
Track& current_track() { return *m_tracks[m_current_track]; }
Span<const Sample> buffer() const { return m_current_front_buffer; }
NonnullRefPtr<DSP::NoteTrack> current_track() { return *m_tracks[m_current_track]; }
int track_count() { return m_tracks.size(); };
void set_current_track(size_t track_index)
{
VERIFY((int)track_index < track_count());
auto old_track = m_current_track;
m_current_track = track_index;
m_tracks[old_track]->set_active(false);
m_tracks[m_current_track]->set_active(true);
}
NonnullRefPtr<DSP::Transport> transport() const { return m_transport; }
@ -43,7 +40,7 @@ public:
// Legacy API, do not add new users.
void time_forward(int amount);
void fill_buffer(Span<Sample>);
void fill_buffer(FixedArray<DSP::Sample>&);
void reset();
void set_keyboard_note(int note, DSP::Keyboard::Switch note_switch);
void set_should_loop(bool b) { m_should_loop = b; }
@ -51,15 +48,12 @@ public:
int next_track_index() const;
private:
Vector<NonnullOwnPtr<Track>> m_tracks;
Vector<NonnullRefPtr<DSP::NoteTrack>> m_tracks;
NonnullRefPtr<DSP::Transport> m_transport;
NonnullRefPtr<DSP::Keyboard> m_keyboard;
size_t m_current_track { 0 };
Array<Sample, sample_count> m_front_buffer;
Array<Sample, sample_count> m_back_buffer;
Span<Sample> m_current_front_buffer { m_front_buffer.span() };
Span<Sample> m_current_back_buffer { m_back_buffer.span() };
FixedArray<DSP::Sample> m_temporary_track_buffer;
bool m_should_loop { true };
};