36 const std::filesystem::path& path);
56 [[nodiscard]] std::int64_t
position() const noexcept {
return position_; }
59 [[nodiscard]]
const std::optional<smf::SongLoop>&
loop() const noexcept {
return loop_; }
71 [[nodiscard]]
int loop_count() const noexcept {
return loop_count_; }
74 [[nodiscard]]
int loops_played() const noexcept {
return loops_played_; }
81 [[nodiscard]]
bool at_end() const noexcept
83 return finished_ || (cursor_ >= events_.size() && generator_->active_voices() == 0);
94 void render(std::span<float> left, std::span<float> right);
102 std::optional<double> end_seconds = std::nullopt);
111 void seek(std::int64_t sample);
115 void replay_to(std::int64_t sample);
118 void all_notes_off();
125 bool handle_loop_point();
128 std::vector<MidiEvent> events_;
129 std::int64_t last_event_position_ = 0;
130 std::int64_t position_ = 0;
131 std::size_t cursor_ = 0;
133 std::optional<smf::SongLoop> loop_;
135 int loops_played_ = 0;
136 double fade_seconds_ = 7.0;
139 std::int64_t rendered_ = 0;
141 std::int64_t fade_start_ = -1;
142 bool finished_ =
false;
144 int notes_before_reset_ = 0;
bool at_end() const noexcept
Whether every event has been dispatched and nothing is still sounding, or the post-loop fade has run ...
Definition sequence_player.hpp:81
std::int64_t last_event_position() const noexcept
Position of the final event of any kind.
Definition sequence_player.hpp:53
void set_loop_count(int count)
How many times the looped section should play, counting the first pass.
static SequencePlayer from_file(ToneGenerator &generator, const std::filesystem::path &path)
Reads a music file and creates a player for it.
RenderResult render_to_end(double tail_seconds=2.2, std::optional< double > end_seconds=std::nullopt)
Streams the whole file into memory, from wherever the player currently is.
std::int64_t position() const noexcept
Current position in samples.
Definition sequence_player.hpp:56
void set_fade_seconds(double seconds)
The post-loop fade length. Zero cuts at the loop end.
SequencePlayer(ToneGenerator &generator, smf::Song song)
Creates a player over an engine and a parsed song, keeping its loop points.
const std::optional< smf::SongLoop > & loop() const noexcept
The file's loop points, when it declared any.
Definition sequence_player.hpp:59
SequencePlayer(ToneGenerator &generator, std::vector< MidiEvent > events)
Creates a player over an engine and an event list ordered by position.
std::vector< int > addressed_parts() const
Which parts the file actually addresses, as port * 16 + channel.
void seek(std::int64_t sample)
Jumps to a position, leaving the engine in the state the file would have put it in.
int loop_count() const noexcept
Definition sequence_player.hpp:71
int loops_played() const noexcept
Completed passes over the loop body, counting up from zero on the initial pass.
Definition sequence_player.hpp:74
ToneGenerator & generator() noexcept
The engine being driven.
Definition sequence_player.hpp:47
void render(std::span< float > left, std::span< float > right)
Renders audio, dispatching every event that falls inside it.
The real-time engine: MIDI in, audio out, rendered a block at a time.
Definition tone_generator.hpp:100
Definition control_decode.hpp:7
A finished render.
Definition render_options.hpp:107
A parsed file: the event list plus what the container knew beyond the events.
Definition smf_reader.hpp:98