diff options
| author | jacqueline <me@jacqueline.id.au> | 2023-11-24 15:13:10 +1100 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2023-11-24 15:13:10 +1100 |
| commit | 7c6eb2997cbba350e7384151e13659271508e08f (patch) | |
| tree | b6f95a4843521e69b24cbf4c126d84442d19fc23 /src/lua/property.cpp | |
| parent | 230721cd6271f3239b42e1d2471f8db15bebd712 (diff) | |
| download | tangara-fw-7c6eb2997cbba350e7384151e13659271508e08f.tar.gz | |
Migrate 'now playing' screen to lua
Diffstat (limited to 'src/lua/property.cpp')
| -rw-r--r-- | src/lua/property.cpp | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/src/lua/property.cpp b/src/lua/property.cpp index c63d243f..3e492237 100644 --- a/src/lua/property.cpp +++ b/src/lua/property.cpp @@ -9,10 +9,13 @@ #include <memory> #include <string> +#include "lua.h" #include "lua.hpp" #include "lua_thread.hpp" #include "lvgl.h" #include "service_locator.hpp" +#include "track.hpp" +#include "types.hpp" namespace lua { @@ -51,7 +54,7 @@ static auto property_bind(lua_State* state) -> int { lua_pushvalue(state, 2); p->PushValue(*state); - CallProtected(state, 1, 0); // Invoke the initial binding. + CallProtected(state, 1, 0); // Invoke the initial binding. lua_pushstring(state, kBindingsTable); lua_gettable(state, LUA_REGISTRYINDEX); // REGISTRY[kBindingsTable] @@ -171,6 +174,31 @@ auto Property::PushValue(lua_State& s) -> int { lua_pushboolean(&s, arg); } else if constexpr (std::is_same_v<T, std::string>) { lua_pushstring(&s, arg.c_str()); + } else if constexpr (std::is_same_v<T, audio::Track>) { + lua_newtable(&s); + int table = lua_gettop(&s); + for (const auto& [key, val] : arg.tags->tags()) { + lua_pushstring(&s, database::TagToString(key).c_str()); + lua_pushstring(&s, val.c_str()); + lua_settable(&s, table); + } + if (arg.db_info) { + lua_pushliteral(&s, "id"); + lua_pushinteger(&s, arg.db_info->id); + lua_settable(&s, table); + } + + lua_pushliteral(&s, "duration"); + lua_pushinteger(&s, arg.duration); + lua_settable(&s, table); + + lua_pushliteral(&s, "bitrate_kbps"); + lua_pushinteger(&s, arg.bitrate_kbps); + lua_settable(&s, table); + + lua_pushliteral(&s, "encoding"); + lua_pushstring(&s, codecs::StreamTypeToString(arg.encoding).c_str()); + lua_settable(&s, table); } else { static_assert(always_false_v<T>, "PushValue missing type"); } @@ -228,8 +256,8 @@ auto Property::Update(const LuaValue& v) -> void { continue; } - PushValue(*b.first); // push the argument - CallProtected(b.first, 1, 0); // invoke the closure + PushValue(*b.first); // push the argument + CallProtected(b.first, 1, 0); // invoke the closure } } |
