diff options
| author | jacqueline <me@jacqueline.id.au> | 2024-08-28 15:30:25 +1000 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2024-08-28 15:30:25 +1000 |
| commit | af7a70450e3ceaaf291aa09b9383b50b879759d9 (patch) | |
| tree | be024b6eb3373035407182efa41a6a587bb98a7d /src | |
| parent | 9145722b08b9c648e41d6b36f83bebbd106efc1e (diff) | |
| download | tangara-fw-af7a70450e3ceaaf291aa09b9383b50b879759d9.tar.gz | |
Support adding filepaths to the track queue
Diffstat (limited to 'src')
| -rw-r--r-- | src/tangara/audio/track_queue.cpp | 16 | ||||
| -rw-r--r-- | src/tangara/audio/track_queue.hpp | 12 | ||||
| -rw-r--r-- | src/tangara/lua/lua_queue.cpp | 18 |
3 files changed, 31 insertions, 15 deletions
diff --git a/src/tangara/audio/track_queue.cpp b/src/tangara/audio/track_queue.cpp index 6fa5511c..cc4770ae 100644 --- a/src/tangara/audio/track_queue.cpp +++ b/src/tangara/audio/track_queue.cpp @@ -161,12 +161,6 @@ auto TrackQueue::getFilepath(database::TrackId id) return db->getTrackPath(id); } -// TODO WIP: Atm only appends are allowed, this will only ever append regardless -// of what index is given. But it is kept like this for compatability for now. -auto TrackQueue::insert(Item i, size_t index) -> void { - append(i); -} - auto TrackQueue::append(Item i) -> void { bool was_queue_empty; bool current_changed; @@ -186,6 +180,16 @@ auto TrackQueue::append(Item i) -> void { updateShuffler(was_queue_empty); } notifyChanged(current_changed, Reason::kExplicitUpdate); + } else if (std::holds_alternative<std::string>(i)) { + auto& path = std::get<std::string>(i); + if (!path.empty()) { + { + const std::unique_lock<std::shared_mutex> lock(mutex_); + playlist_.append(std::get<std::string>(i)); + updateShuffler(was_queue_empty); + } + notifyChanged(current_changed, Reason::kExplicitUpdate); + } } else if (std::holds_alternative<database::TrackIterator>(i)) { // Iterators can be very large, and retrieving items from them often // requires disk i/o. Handle them asynchronously so that inserting them diff --git a/src/tangara/audio/track_queue.hpp b/src/tangara/audio/track_queue.hpp index 54898a5d..1d25568d 100644 --- a/src/tangara/audio/track_queue.hpp +++ b/src/tangara/audio/track_queue.hpp @@ -16,8 +16,8 @@ #include "cppbor_parse.h" #include "database/database.hpp" #include "database/track.hpp" -#include "tasks.hpp" #include "playlist.hpp" +#include "tasks.hpp" namespace audio { @@ -68,16 +68,18 @@ class TrackQueue { TrackQueue(tasks::WorkerPool& bg_worker, database::Handle db); /* Returns the currently playing track. */ - using TrackItem = std::variant<std::string, database::TrackId, std::monostate>; + using TrackItem = + std::variant<std::string, database::TrackId, std::monostate>; auto current() const -> TrackItem; auto currentPosition() const -> size_t; auto totalSize() const -> size_t; auto open() -> bool; - auto openPlaylist(const std::string& playlist_file, bool notify = true) -> bool; + auto openPlaylist(const std::string& playlist_file, bool notify = true) + -> bool; - using Item = std::variant<database::TrackId, database::TrackIterator>; - auto insert(Item, size_t index = 0) -> void; + using Item = + std::variant<database::TrackId, database::TrackIterator, std::string>; auto append(Item i) -> void; auto updateShuffler(bool andUpdatePosition) -> void; diff --git a/src/tangara/lua/lua_queue.cpp b/src/tangara/lua/lua_queue.cpp index 9e2002e6..7eb32c62 100644 --- a/src/tangara/lua/lua_queue.cpp +++ b/src/tangara/lua/lua_queue.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: GPL-3.0-only */ +#include "audio/audio_events.hpp" #include "lua/lua_database.hpp" #include <memory> @@ -39,6 +40,14 @@ static auto queue_add(lua_State* state) -> int { audio::TrackQueue& queue = instance->services().track_queue(); queue.append(id); }); + } else if (lua_isstring(state, 1)) { + size_t len; + const char* str = luaL_checklstring(state, 1, &len); + std::string path{str, len}; + instance->services().bg_worker().Dispatch<void>([=]() { + audio::TrackQueue& queue = instance->services().track_queue(); + queue.append(path); + }); } else { database::Iterator* it = db_check_iterator(state, 1); instance->services().bg_worker().Dispatch<void>([=]() { @@ -70,10 +79,11 @@ static auto queue_open_playlist(lua_State* state) -> int { return 0; } -static const struct luaL_Reg kQueueFuncs[] = {{"add", queue_add}, - {"clear", queue_clear}, - {"open_playlist", queue_open_playlist}, - {NULL, NULL}}; +static const struct luaL_Reg kQueueFuncs[] = { + {"add", queue_add}, + {"clear", queue_clear}, + {"open_playlist", queue_open_playlist}, + {NULL, NULL}}; static auto lua_queue(lua_State* state) -> int { luaL_newlib(state, kQueueFuncs); |
