Lua API improvements and fixes

Co-authored-by: jacqueline <me@jacqueline.id.au>
custom
ailurux 8 months ago
parent 3421bd652c
commit 96a224c0df
  1. 4
      luals-stubs/backstack.lua
  2. 13
      luals-stubs/bluetooth.lua
  3. 5
      luals-stubs/playback.lua
  4. 4
      luals-stubs/queue.lua
  5. 15
      src/tangara/audio/track_queue.cpp
  6. 1
      src/tangara/audio/track_queue.hpp
  7. 19
      src/tangara/ui/ui_fsm.cpp

@ -17,4 +17,8 @@ function backstack.push(screen) end
--- there are no other screens in the stack.
function backstack.pop() end
--- Sets a new root screen, replacing any existing screens
--- @param screen screen The new root screen
function backstack.reset(screen) end
return backstack

@ -5,8 +5,17 @@
--- @class bluetooth
--- @field enabled Property Whether or not the Bluetooth stack is currently enabled. This property is writeable, and can be used to enable or disable Bluetooth.
--- @field connected Property Whether or not there is an active connection to another Bluetooth device.
--- @field paired_device Property The device that is currently paired. The bluetooth stack will automatically connected to this device if possible.
--- @field devices Property Devices nearby that have been discovered.
--- @field connecting Property Whether or not we are currently connecting to the paired device.
--- @field discovering Property Whether or not we are actively scanning for new devices.
--- @field paired_device Property The device that is currently paired. The bluetooth stack will automatically connect to this device if possible.
--- @field discovered_devices Property Devices nearby that have been discovered.
--- @field known_devices Property Devices that have previously been paired.
local bluetooth = {}
--- Enables Bluetooth, this is the same as bluetooth.enabled:set(true)
function bluetooth.enable() end
--- Disables Bluetooth, this is the same as bluetooth.enabled:set(false)
function bluetooth.disable() end
return bluetooth

@ -8,4 +8,9 @@
--- @field position Property The current playback position within the current track, in seconds.
local playback = {}
--- Returns whether or not this file can be played (i.e. is this an audio track)
--- @param filepath string
--- @return boolean
function playback.is_playable(filepath) end
return playback

@ -13,10 +13,10 @@
--- @field random Property Determines whether, when progressing to the next track in the queue, the next track will be chosen randomly. The random selection algorithm used is a Miller Shuffle, which guarantees that no repeat selections will be made until every item in the queue has been played. Writeable.
local queue = {}
--- Adds the given track or database iterator to the end of the queue. Database
--- Adds the given track, database iterator, or file to the end of the queue. Database
--- iterators passed to this method will be unnested and expanded into the track
--- ids they contain.
--- @param val TrackId|Iterator
--- @param val TrackId|Iterator|string
function queue.add(val) end
--- Opens a playlist file from a filepath

@ -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_) {

@ -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)

@ -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",

Loading…
Cancel
Save