From 26f6156f34b38708ed3cf0d79378c5c53739869c Mon Sep 17 00:00:00 2001 From: Alexis Maiquez Date: Tue, 7 Feb 2023 11:29:57 +0100 Subject: [PATCH] MPV should respect volume levels now Signed-off-by: Alexis Maiquez --- main.cpp | 2 ++ src/WallpaperEngine/Application/CWallpaperApplication.cpp | 3 +++ src/WallpaperEngine/Audio/Drivers/CSDLAudioDriver.cpp | 2 +- src/WallpaperEngine/Render/CVideo.cpp | 4 ++++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index 9787084..35e624b 100644 --- a/main.cpp +++ b/main.cpp @@ -66,5 +66,7 @@ int main (int argc, char* argv[]) // show the wallpaper application app.show (); + appPointer = nullptr; + return 0; } \ No newline at end of file diff --git a/src/WallpaperEngine/Application/CWallpaperApplication.cpp b/src/WallpaperEngine/Application/CWallpaperApplication.cpp index 82df30c..5ff380c 100644 --- a/src/WallpaperEngine/Application/CWallpaperApplication.cpp +++ b/src/WallpaperEngine/Application/CWallpaperApplication.cpp @@ -20,6 +20,9 @@ using namespace WallpaperEngine::Application; CWallpaperApplication::CWallpaperApplication (CApplicationContext& context) : m_context (context) { + // copy state to global variables for now + g_AudioVolume = context.audioVolume; + g_AudioEnabled = context.audioEnabled; this->setupContainer (); this->loadProject (); this->setupProperties (); diff --git a/src/WallpaperEngine/Audio/Drivers/CSDLAudioDriver.cpp b/src/WallpaperEngine/Audio/Drivers/CSDLAudioDriver.cpp index b66df03..e2f93c9 100644 --- a/src/WallpaperEngine/Audio/Drivers/CSDLAudioDriver.cpp +++ b/src/WallpaperEngine/Audio/Drivers/CSDLAudioDriver.cpp @@ -12,7 +12,7 @@ using namespace WallpaperEngine::Audio::Drivers; void audio_callback (void* userdata, uint8_t* streamData, int length) { - CSDLAudioDriver* driver = reinterpret_cast (userdata); + auto* driver = reinterpret_cast (userdata); memset (streamData, 0, length); diff --git a/src/WallpaperEngine/Render/CVideo.cpp b/src/WallpaperEngine/Render/CVideo.cpp index 287f5df..f57b506 100644 --- a/src/WallpaperEngine/Render/CVideo.cpp +++ b/src/WallpaperEngine/Render/CVideo.cpp @@ -5,6 +5,7 @@ #include extern bool g_AudioEnabled; +extern int g_AudioVolume; using namespace WallpaperEngine; using namespace WallpaperEngine::Render; @@ -19,6 +20,8 @@ CVideo::CVideo (Core::CVideo* video, CRenderContext* context, CAudioContext* aud m_width (16), m_height (16) { + double volume = g_AudioVolume * 100.0 / 128.0; + // create mpv contexts this->m_mpv = mpv_create (); @@ -37,6 +40,7 @@ CVideo::CVideo (Core::CVideo* video, CRenderContext* context, CAudioContext* aud mpv_set_option_string (this->m_mpv, "hwdec", "auto"); mpv_set_option_string (this->m_mpv, "loop", "inf"); + mpv_set_option (this->m_mpv, "volume", MPV_FORMAT_DOUBLE, &volume); // initialize gl context for mpv mpv_opengl_init_params gl_init_params {get_proc_address, nullptr};