2020-01-31 03:02:45 +11:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
* Copyright (c) 2019-2020, William McPherson <willmcpherson2@gmail.com>
|
2021-07-11 12:58:17 +10:00
|
|
|
* Copyright (c) 2021, JJ Roberts-White <computerfido@gmail.com>
|
2020-01-31 03:02:45 +11:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-31 03:02:45 +11:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "Music.h"
|
2020-06-15 15:33:53 +10:00
|
|
|
#include "Track.h"
|
2020-09-06 21:40:46 +02:00
|
|
|
#include <AK/Array.h>
|
2020-01-31 03:02:45 +11:00
|
|
|
#include <AK/Noncopyable.h>
|
2020-06-15 15:33:53 +10:00
|
|
|
#include <AK/NonnullOwnPtr.h>
|
|
|
|
#include <AK/Vector.h>
|
2020-01-31 03:02:45 +11:00
|
|
|
|
2020-06-15 15:33:53 +10:00
|
|
|
class TrackManager {
|
2020-08-26 21:52:24 +02:00
|
|
|
AK_MAKE_NONCOPYABLE(TrackManager);
|
|
|
|
AK_MAKE_NONMOVABLE(TrackManager);
|
|
|
|
|
2020-01-31 03:02:45 +11:00
|
|
|
public:
|
2020-06-15 15:33:53 +10:00
|
|
|
TrackManager();
|
|
|
|
~TrackManager();
|
2020-01-31 03:02:45 +11:00
|
|
|
|
2020-06-15 15:33:53 +10:00
|
|
|
Track& current_track() { return *m_tracks[m_current_track]; }
|
2020-09-06 21:40:46 +02:00
|
|
|
Span<const Sample> buffer() const { return m_current_front_buffer; }
|
2020-01-31 03:02:45 +11:00
|
|
|
int octave() const { return m_octave; }
|
|
|
|
int octave_base() const { return (m_octave - octave_min) * 12; }
|
2021-12-04 22:42:35 -06:00
|
|
|
int track_count() { return m_tracks.size(); };
|
|
|
|
void set_current_track(size_t track_index)
|
|
|
|
{
|
|
|
|
VERIFY((int)track_index < track_count());
|
|
|
|
m_current_track = track_index;
|
|
|
|
}
|
2021-07-11 12:58:17 +10:00
|
|
|
|
2020-01-31 03:02:45 +11:00
|
|
|
int time() const { return m_time; }
|
2021-07-11 12:58:17 +10:00
|
|
|
void time_forward(int amount);
|
2020-01-31 03:02:45 +11:00
|
|
|
|
2020-09-06 21:40:46 +02:00
|
|
|
void fill_buffer(Span<Sample>);
|
2020-02-09 20:35:56 +11:00
|
|
|
void reset();
|
2021-09-28 18:01:39 +02:00
|
|
|
void set_keyboard_note(int note, Switch note_switch);
|
2020-02-27 01:01:17 +11:00
|
|
|
void set_should_loop(bool b) { m_should_loop = b; }
|
2020-01-31 03:02:45 +11:00
|
|
|
void set_octave(Direction);
|
2020-07-06 14:52:29 -06:00
|
|
|
void set_octave(int octave);
|
2020-06-15 15:33:53 +10:00
|
|
|
void add_track();
|
2021-12-04 22:42:35 -06:00
|
|
|
int next_track_index();
|
2020-01-31 03:02:45 +11:00
|
|
|
|
|
|
|
private:
|
2020-06-15 15:33:53 +10:00
|
|
|
Vector<NonnullOwnPtr<Track>> m_tracks;
|
|
|
|
size_t m_current_track { 0 };
|
2020-02-05 02:39:51 +11:00
|
|
|
|
2020-09-06 21:40:46 +02:00
|
|
|
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() };
|
2020-01-31 03:02:45 +11:00
|
|
|
|
|
|
|
int m_octave { 4 };
|
2020-02-27 01:01:17 +11:00
|
|
|
|
|
|
|
u32 m_time { 0 };
|
2020-01-31 03:02:45 +11:00
|
|
|
|
2020-02-27 01:01:17 +11:00
|
|
|
bool m_should_loop { true };
|
2020-01-31 03:02:45 +11:00
|
|
|
};
|