From 815014b3277b59d39e8a9742326f412c9b77e71d Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Wed, 20 Jun 2018 19:45:12 +0900 Subject: [PATCH] Improve querying sinks/sources Minor fixes to remove most compiler warnings. Now version 1.6 --- CMakeLists.txt | 2 +- Changelog.md | 5 +++++ src/MfPA/GetSinkSourceInfo.cpp | 38 ++++++++++++++++++---------------- src/MfPA/GetSinkSourceInfo.hpp | 4 +--- 4 files changed, 27 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 03e3a73..dc2a016 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.0) -project(MeterForPulseAudio VERSION 1.5) +project(MeterForPulseAudio VERSION 1.6) set(MeterForPulseAudio_SOURCES GameDevTools/src/GDT/GameLoop.cpp diff --git a/Changelog.md b/Changelog.md index 0263f38..c95dd45 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,8 @@ +# Version 1.6 + +Improve options "--list-sinks" and "--list-sources" (now halts after querying +for sinks/sources has finished instead of waiting for 1 second to pass). + # Version 1.5 Color of previous max amount in meter is inverted after a certain threshold diff --git a/src/MfPA/GetSinkSourceInfo.cpp b/src/MfPA/GetSinkSourceInfo.cpp index 3aa9fc0..f20df71 100644 --- a/src/MfPA/GetSinkSourceInfo.cpp +++ b/src/MfPA/GetSinkSourceInfo.cpp @@ -6,7 +6,7 @@ MfPA::GetSinkSourceInfo::GetSinkSourceInfo(bool getSinkInfo) : getSinkInfo(getSinkInfo), -isReady(false), +operation(nullptr), run(true) { mainLoop = pa_mainloop_new(); @@ -21,6 +21,11 @@ run(true) MfPA::GetSinkSourceInfo::~GetSinkSourceInfo() { + if(operation) + { + pa_operation_unref(operation); + } + if(context) { pa_context_disconnect(context); @@ -44,22 +49,21 @@ void MfPA::GetSinkSourceInfo::get_state_callback(pa_context* c, void* userdata) case PA_CONTEXT_SETTING_NAME: break; case PA_CONTEXT_READY: - getInfo->isReady = true; if(getInfo->getSinkInfo) { std::cout << "Available sinks:" << std::endl; - pa_operation_unref(pa_context_get_sink_info_list( + getInfo->operation = pa_context_get_sink_info_list( c, MfPA::GetSinkSourceInfo::get_sink_info_callback, - userdata)); + userdata); } else { std::cout << "Available sources:" << std::endl; - pa_operation_unref(pa_context_get_source_info_list( + getInfo->operation = pa_context_get_source_info_list( c, MfPA::GetSinkSourceInfo::get_source_info_callback, - userdata)); + userdata); } break; case PA_CONTEXT_FAILED: @@ -72,10 +76,10 @@ void MfPA::GetSinkSourceInfo::get_state_callback(pa_context* c, void* userdata) } void MfPA::GetSinkSourceInfo::get_sink_info_callback( - pa_context* c, + pa_context* /* c */, const pa_sink_info* i, int eol, - void* userdata) + void* /* userdata */) { // MfPA::GetSinkSourceInfo* getInfo = (MfPA::GetSinkSourceInfo*) userdata; if(eol != PA_OK) @@ -86,10 +90,10 @@ void MfPA::GetSinkSourceInfo::get_sink_info_callback( } void MfPA::GetSinkSourceInfo::get_source_info_callback( - pa_context* c, + pa_context* /* c */, const pa_source_info* i, int eol, - void* userdata) + void* /* userdata */) { // MfPA::GetSinkSourceInfo* getInfo = (MfPA::GetSinkSourceInfo*) userdata; if(eol != PA_OK) @@ -101,18 +105,16 @@ void MfPA::GetSinkSourceInfo::get_source_info_callback( void MfPA::GetSinkSourceInfo::startMainLoop() { - float timer = GET_SINK_SOURCE_INFO_ITERATION_TIME; GDT::IntervalBasedGameLoop( &run, - [this, &timer] (float dt) { + [this] (float /* dt */) { pa_mainloop_iterate(mainLoop, 0, nullptr); - if(isReady) + if(operation + && pa_operation_get_state(operation) == PA_OPERATION_DONE) { - timer -= dt; - if(timer <= 0.0f) - { - run = false; - } + pa_operation_unref(operation); + operation = nullptr; + run = false; } }, [] () {}, diff --git a/src/MfPA/GetSinkSourceInfo.hpp b/src/MfPA/GetSinkSourceInfo.hpp index b9110df..52269fa 100644 --- a/src/MfPA/GetSinkSourceInfo.hpp +++ b/src/MfPA/GetSinkSourceInfo.hpp @@ -1,8 +1,6 @@ #ifndef GET_SINK_SOURCE_INFO_HPP #define GET_SINK_SOURCE_INFO_HPP -#define GET_SINK_SOURCE_INFO_ITERATION_TIME 1.0f - #include namespace MfPA @@ -33,7 +31,7 @@ private: pa_mainloop* mainLoop; pa_context* context; - bool isReady; + pa_operation* operation; bool run; -- 2.49.0