Fix queue serialisation so that the position is correctly applied

custom
ailurux 8 months ago
parent 0f9005626d
commit 978429109e
  1. 14
      src/tangara/audio/track_queue.cpp
  2. 3
      src/tangara/audio/track_queue.hpp

@ -137,14 +137,16 @@ auto TrackQueue::open() -> bool {
return playlist_.open(); return playlist_.open();
} }
auto TrackQueue::openPlaylist(const std::string& playlist_file) -> bool { auto TrackQueue::openPlaylist(const std::string& playlist_file, bool notify) -> bool {
opened_playlist_.emplace(playlist_file); opened_playlist_.emplace(playlist_file);
auto res = opened_playlist_->open(); auto res = opened_playlist_->open();
if (!res) { if (!res) {
return false; return false;
} }
updateShuffler(true); updateShuffler(true);
notifyChanged(true, Reason::kExplicitUpdate); if (notify) {
notifyChanged(true, Reason::kExplicitUpdate);
}
return true; return true;
} }
@ -371,7 +373,7 @@ auto TrackQueue::serialise() -> std::string {
} }
TrackQueue::QueueParseClient::QueueParseClient(TrackQueue& queue) TrackQueue::QueueParseClient::QueueParseClient(TrackQueue& queue)
: queue_(queue), state_(State::kInit), i_(0) {} : queue_(queue), state_(State::kInit), i_(0), position_to_set_(0) {}
cppbor::ParseClient* TrackQueue::QueueParseClient::item( cppbor::ParseClient* TrackQueue::QueueParseClient::item(
std::unique_ptr<cppbor::Item>& item, std::unique_ptr<cppbor::Item>& item,
@ -400,10 +402,11 @@ cppbor::ParseClient* TrackQueue::QueueParseClient::item(
i_ = 0; i_ = 0;
} else if (item->type() == cppbor::UINT) { } else if (item->type() == cppbor::UINT) {
auto val = item->asUint()->unsignedValue(); auto val = item->asUint()->unsignedValue();
queue_.goTo(val); // Save the position so we can apply it later when we have finished serialising
position_to_set_ = val;
} else if (item->type() == cppbor::TSTR) { } else if (item->type() == cppbor::TSTR) {
auto val = item->asTstr(); auto val = item->asTstr();
queue_.openPlaylist(val->value()); queue_.openPlaylist(val->value(), false);
} else if (item->type() == cppbor::SIMPLE) { } else if (item->type() == cppbor::SIMPLE) {
bool val = item->asBool()->value(); bool val = item->asBool()->value();
if (i_ == 0) { if (i_ == 0) {
@ -448,6 +451,7 @@ cppbor::ParseClient* TrackQueue::QueueParseClient::itemEnd(
if (state_ == State::kInit) { if (state_ == State::kInit) {
state_ = State::kFinished; state_ = State::kFinished;
} else if (state_ == State::kRoot) { } else if (state_ == State::kRoot) {
queue_.goTo(position_to_set_);
state_ = State::kFinished; state_ = State::kFinished;
} else if (state_ == State::kMetadata) { } else if (state_ == State::kMetadata) {
if (item->type() == cppbor::ARRAY) { if (item->type() == cppbor::ARRAY) {

@ -74,7 +74,7 @@ class TrackQueue {
auto currentPosition() const -> size_t; auto currentPosition() const -> size_t;
auto totalSize() const -> size_t; auto totalSize() const -> size_t;
auto open() -> bool; auto open() -> bool;
auto openPlaylist(const std::string& playlist_file) -> bool; auto openPlaylist(const std::string& playlist_file, bool notify = true) -> bool;
using Item = std::variant<database::TrackId, database::TrackIterator>; using Item = std::variant<database::TrackId, database::TrackIterator>;
auto insert(Item, size_t index = 0) -> void; auto insert(Item, size_t index = 0) -> void;
@ -163,6 +163,7 @@ class TrackQueue {
}; };
State state_; State state_;
size_t i_; size_t i_;
size_t position_to_set_;
}; };
}; };

Loading…
Cancel
Save