diff options
| author | jacqueline <me@jacqueline.id.au> | 2024-02-12 17:10:03 +1100 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2024-02-12 17:10:03 +1100 |
| commit | 36f4c77fb22fd8ba433696a6fbd005d504e86186 (patch) | |
| tree | b3242f8edcd395f2b498fad40e43e1f36a9a2b00 /src/audio/track_queue.cpp | |
| parent | 03c0968168090b1093bda7e05874c201ae58b57b (diff) | |
| parent | 527374c72e1ec52e1d5814dbee3587ae100631dd (diff) | |
| download | tangara-fw-36f4c77fb22fd8ba433696a6fbd005d504e86186.tar.gz | |
Merge branch 'main' of codeberg.org:cool-tech-zone/tangara-fw
Diffstat (limited to 'src/audio/track_queue.cpp')
| -rw-r--r-- | src/audio/track_queue.cpp | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/src/audio/track_queue.cpp b/src/audio/track_queue.cpp index d68f2821..c4c101f6 100644 --- a/src/audio/track_queue.cpp +++ b/src/audio/track_queue.cpp @@ -34,12 +34,12 @@ namespace audio { [[maybe_unused]] static constexpr char kTag[] = "tracks"; RandomIterator::RandomIterator(size_t size) - : seed_(), pos_(0), size_(size), repeat_(false) { + : seed_(), pos_(0), size_(size), replay_(false) { esp_fill_random(&seed_, sizeof(seed_)); } auto RandomIterator::current() const -> size_t { - if (pos_ < size_ || repeat_) { + if (pos_ < size_ || replay_) { return MillerShuffle(pos_, seed_, size_); } return size_; @@ -65,8 +65,8 @@ auto RandomIterator::resize(size_t s) -> void { pos_ = 0; } -auto RandomIterator::repeat(bool r) -> void { - repeat_ = r; +auto RandomIterator::replay(bool r) -> void { + replay_ = r; } auto notifyChanged(bool current_changed) -> void { @@ -81,7 +81,8 @@ TrackQueue::TrackQueue(tasks::WorkerPool& bg_worker) pos_(0), tracks_(&memory::kSpiRamResource), shuffle_(), - repeat_(false) {} + repeat_(false), + replay_(false) {} auto TrackQueue::current() const -> std::optional<database::TrackId> { const std::shared_lock<std::shared_mutex> lock(mutex_); @@ -202,7 +203,7 @@ auto TrackQueue::next() -> void { pos_ = shuffle_->current(); } else { if (pos_ + 1 >= tracks_.size()) { - if (repeat_) { + if (replay_) { pos_ = 0; } } else { @@ -231,6 +232,14 @@ auto TrackQueue::previous() -> void { notifyChanged(true); } +auto TrackQueue::finish() -> void { + if (repeat_) { + notifyChanged(true); + } else { + next(); + } +} + auto TrackQueue::skipTo(database::TrackId id) -> void { // Defer this work to the background not because it's particularly // long-running (although it could be), but because we want to ensure we only @@ -279,7 +288,7 @@ auto TrackQueue::random(bool en) -> void { // repeated calls with en == true will re-shuffle. if (en) { shuffle_.emplace(tracks_.size()); - shuffle_->repeat(repeat_); + shuffle_->replay(replay_); } else { shuffle_.reset(); } @@ -298,9 +307,6 @@ auto TrackQueue::repeat(bool en) -> void { { const std::unique_lock<std::shared_mutex> lock(mutex_); repeat_ = en; - if (shuffle_) { - shuffle_->repeat(en); - } } notifyChanged(false); @@ -311,6 +317,22 @@ auto TrackQueue::repeat() const -> bool { return repeat_; } +auto TrackQueue::replay(bool en) -> void { + { + const std::unique_lock<std::shared_mutex> lock(mutex_); + replay_ = en; + if (shuffle_) { + shuffle_->replay(en); + } + } + notifyChanged(false); +} + +auto TrackQueue::replay() const -> bool { + const std::shared_lock<std::shared_mutex> lock(mutex_); + return replay_; +} + auto TrackQueue::serialise() -> std::string { cppbor::Array tracks{}; for (database::TrackId track : tracks_) { |
