Don't try to serialise a missing playlist name

custom
jacqueline 9 months ago
parent 1ff28233bd
commit 2811a3c899
  1. 30
      src/tangara/audio/track_queue.cpp

@ -27,8 +27,8 @@
#include "events/event_queue.hpp" #include "events/event_queue.hpp"
#include "memory_resource.hpp" #include "memory_resource.hpp"
#include "tasks.hpp" #include "tasks.hpp"
#include "ui/ui_fsm.hpp"
#include "track_queue.hpp" #include "track_queue.hpp"
#include "ui/ui_fsm.hpp"
namespace audio { namespace audio {
@ -84,7 +84,6 @@ auto notifyChanged(bool current_changed, Reason reason) -> void {
events::Audio().Dispatch(ev); events::Audio().Dispatch(ev);
} }
TrackQueue::TrackQueue(tasks::WorkerPool& bg_worker, database::Handle db) TrackQueue::TrackQueue(tasks::WorkerPool& bg_worker, database::Handle db)
: mutex_(), : mutex_(),
bg_worker_(bg_worker), bg_worker_(bg_worker),
@ -129,8 +128,9 @@ auto TrackQueue::updateShuffler() -> void {
} }
auto TrackQueue::open() -> bool { auto TrackQueue::open() -> bool {
// FIX ME: If playlist opening fails, should probably fall back to a vector of tracks or something // FIX ME: If playlist opening fails, should probably fall back to a vector of
// so that we're not necessarily always needing mounted storage // tracks or something so that we're not necessarily always needing mounted
// storage
return playlist_.open(); return playlist_.open();
} }
@ -145,7 +145,8 @@ auto TrackQueue::openPlaylist(const std::string& playlist_file) -> bool {
return true; return true;
} }
auto TrackQueue::getFilepath(database::TrackId id) -> std::optional<std::string> { auto TrackQueue::getFilepath(database::TrackId id)
-> std::optional<std::string> {
auto db = db_.lock(); auto db = db_.lock();
if (!db) { if (!db) {
return {}; return {};
@ -153,9 +154,8 @@ auto TrackQueue::getFilepath(database::TrackId id) -> std::optional<std::string>
return db->getTrackPath(id); return db->getTrackPath(id);
} }
// TODO WIP: Atm only appends are allowed, this will only ever append regardless
// TODO WIP: Atm only appends are allowed, this will only ever append regardless of what index // of what index is given. But it is kept like this for compatability for now.
// is given. But it is kept like this for compatability for now.
auto TrackQueue::insert(Item i, size_t index) -> void { auto TrackQueue::insert(Item i, size_t index) -> void {
append(i); append(i);
} }
@ -237,7 +237,6 @@ auto TrackQueue::goTo(size_t position) {
} }
} }
auto TrackQueue::next(Reason r) -> void { auto TrackQueue::next(Reason r) -> void {
bool changed = true; bool changed = true;
@ -350,12 +349,19 @@ auto TrackQueue::replay() const -> bool {
auto TrackQueue::serialise() -> std::string { auto TrackQueue::serialise() -> std::string {
cppbor::Array tracks{}; cppbor::Array tracks{};
cppbor::Map encoded; cppbor::Map encoded;
encoded.add(cppbor::Uint{0}, cppbor::Array{
cppbor::Array metadata{
cppbor::Bool{repeat_}, cppbor::Bool{repeat_},
cppbor::Bool{replay_}, cppbor::Bool{replay_},
cppbor::Uint{position_}, cppbor::Uint{position_},
cppbor::Tstr{opened_playlist_->filepath()} };
});
if (opened_playlist_) {
metadata.add(cppbor::Tstr{opened_playlist_->filepath()});
}
encoded.add(cppbor::Uint{0}, std::move(metadata));
if (shuffle_) { if (shuffle_) {
encoded.add(cppbor::Uint{1}, cppbor::Array{ encoded.add(cppbor::Uint{1}, cppbor::Array{
cppbor::Uint{shuffle_->size()}, cppbor::Uint{shuffle_->size()},

Loading…
Cancel
Save