summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/tangara/audio/track_queue.cpp15
-rw-r--r--src/tangara/audio/track_queue.hpp1
-rw-r--r--src/tangara/ui/ui_fsm.cpp19
3 files changed, 34 insertions, 1 deletions
diff --git a/src/tangara/audio/track_queue.cpp b/src/tangara/audio/track_queue.cpp
index cc4770ae..2c1faf96 100644
--- a/src/tangara/audio/track_queue.cpp
+++ b/src/tangara/audio/track_queue.cpp
@@ -236,6 +236,21 @@ auto TrackQueue::next() -> void {
next(Reason::kExplicitUpdate);
}
+auto TrackQueue::currentPosition(size_t position) -> bool {
+ {
+ const std::shared_lock<std::shared_mutex> lock(mutex_);
+ if (position >= totalSize()) {
+ return false;
+ }
+ goTo(position);
+ }
+
+ // If we're explicitly setting the position, we want to treat it as though
+ // the current track has changed, even if the position was the same
+ notifyChanged(true, Reason::kExplicitUpdate);
+ return true;
+}
+
auto TrackQueue::goTo(size_t position) -> void {
position_ = position;
if (opened_playlist_) {
diff --git a/src/tangara/audio/track_queue.hpp b/src/tangara/audio/track_queue.hpp
index 1d25568d..a8d1dc3a 100644
--- a/src/tangara/audio/track_queue.hpp
+++ b/src/tangara/audio/track_queue.hpp
@@ -73,6 +73,7 @@ class TrackQueue {
auto current() const -> TrackItem;
auto currentPosition() const -> size_t;
+ auto currentPosition(size_t position) -> bool;
auto totalSize() const -> size_t;
auto open() -> bool;
auto openPlaylist(const std::string& playlist_file, bool notify = true)
diff --git a/src/tangara/ui/ui_fsm.cpp b/src/tangara/ui/ui_fsm.cpp
index 94d1caf8..669b3298 100644
--- a/src/tangara/ui/ui_fsm.cpp
+++ b/src/tangara/ui/ui_fsm.cpp
@@ -201,7 +201,14 @@ lua::Property UiState::sPlaybackPosition{
return true;
}};
-lua::Property UiState::sQueuePosition{0};
+lua::Property UiState::sQueuePosition{0, [](const lua::LuaValue& val){
+ if (!std::holds_alternative<int>(val)) {
+ return false;
+ }
+ int new_val = std::get<int>(val);
+ // val-1 because Lua uses 1-based indexing
+ return sServices->track_queue().currentPosition(new_val-1);
+ }};
lua::Property UiState::sQueueSize{0};
lua::Property UiState::sQueueRepeat{false, [](const lua::LuaValue& val) {
if (!std::holds_alternative<bool>(val)) {
@@ -610,6 +617,16 @@ void Lua::entry() {
{"paired_device", &sBluetoothPairedDevice},
{"discovered_devices", &sBluetoothDiscoveredDevices},
{"known_devices", &sBluetoothKnownDevices},
+ {"enable",
+ [&](lua_State* s) {
+ sBluetoothEnabled.set(true);
+ return 0;
+ }},
+ {"disable",
+ [&](lua_State* s) {
+ sBluetoothEnabled.set(false);
+ return 0;
+ }},
});
registry.AddPropertyModule(
"playback",