From e6844a68b61477d1c0a1d225d75c04c7e6678495 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Sat, 25 Nov 2023 08:51:14 +1100 Subject: implement play/pause --- src/ui/ui_fsm.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/ui/ui_fsm.cpp') diff --git a/src/ui/ui_fsm.cpp b/src/ui/ui_fsm.cpp index 557dc1a3..539cbc9b 100644 --- a/src/ui/ui_fsm.cpp +++ b/src/ui/ui_fsm.cpp @@ -7,6 +7,7 @@ #include "ui_fsm.hpp" #include +#include #include "lua.h" #include "lua.hpp" @@ -179,7 +180,8 @@ void Lua::entry() { queue_position_ = std::make_shared(0); queue_size_ = std::make_shared(0); - playback_playing_ = std::make_shared(false); + playback_playing_ = std::make_shared( + false, [&](const lua::LuaValue& val) { return SetPlaying(val); }); playback_track_ = std::make_shared(); playback_position_ = std::make_shared(); @@ -250,6 +252,18 @@ auto Lua::PopLuaScreen(lua_State* s) -> int { return 0; } +auto Lua::SetPlaying(const lua::LuaValue& val) -> bool { + bool current_val = std::get(playback_playing_->Get()); + if (!std::holds_alternative(val)) { + return false; + } + bool new_val = std::get(val); + if (current_val != new_val) { + events::Audio().Dispatch(audio::TogglePlayPause{}); + } + return true; +} + void Lua::exit() { lv_group_set_default(NULL); } -- cgit v1.2.3