From 1064053bc67f23cf5cae9792d04de88e6ccc7406 Mon Sep 17 00:00:00 2001 From: Clo Yun-Hee Dufour Date: Thu, 19 Jan 2023 14:19:03 +0100 Subject: [PATCH] Better behaviour & icon for volume muted --- src/app/Application.cpp | 2 +- src/app/CMakeLists.txt | 3 +-- src/app/SourceModelApp.cpp | 36 +++++++++++++++++++++++++++--------- src/app/SourceModelApp.h | 1 + 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/app/Application.cpp b/src/app/Application.cpp index 5ae2960..033be3a 100644 --- a/src/app/Application.cpp +++ b/src/app/Application.cpp @@ -250,7 +250,7 @@ void Application::setupFonts() { 0xF04B, // Play 0xF04C, // Pause 0xF6A8, - 0xF6A8, // Volume-mid + 0xF6A9, // Volume-mid, volume-mute 0, }; diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index 1316c99..44899db 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -73,8 +73,7 @@ add_embedded_font(${_target} "fonts/vollkorn-bold.ttf" add_embedded_font(${_target} "fonts/fa-solid.ttf" font_faSolid.h gFontFaSolid - "F026-F028,F04B-F04C,F6A8") - #TODO : rebuild when unicode string changes + "F026-F028,F04B-F04C,F6A8-F6A9") target_include_directories(${_target} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/src/app/SourceModelApp.cpp b/src/app/SourceModelApp.cpp index 6ccae11..3efc825 100644 --- a/src/app/SourceModelApp.cpp +++ b/src/app/SourceModelApp.cpp @@ -27,6 +27,7 @@ SourceModelApp::SourceModelApp(const int initialWidth, const int initialHeight) m_doBypassFilter(false), m_doNormalizeFlowPlot(true), m_spectrumFrequencyScale(FrequencyScale_Mel), + m_isVolumeMuted(false), m_mutedLogVolume(0), m_logVolume(90), m_linVolume(0.6561) { @@ -123,33 +124,50 @@ void SourceModelApp::renderMenuBar() { ImGui::Separator(); // Volume icon + // Muted: char is 0xF6A9 // Off: <= 16, char is 0xF026 // Low: <= 33, char is 0xF027 // Mid: <= 67, char is 0xF6A8 // High: > 67, char is 0xF028 const float afterVolX = ImGui::GetCursorPosX() + ImGui::CalcTextSize("\uF028").x; - if ((int)m_logVolume <= 16) { - ImGui::TextUnformatted("\uF026"); - } else if ((int)m_logVolume <= 33) { - ImGui::TextUnformatted("\uF027"); - } else if ((int)m_logVolume <= 67) { - ImGui::TextUnformatted("\uF6A8"); + if (!m_isVolumeMuted) { + if ((int)m_logVolume <= 16) { + ImGui::TextUnformatted("\uF026"); + } else if ((int)m_logVolume <= 33) { + ImGui::TextUnformatted("\uF027"); + } else if ((int)m_logVolume <= 67) { + ImGui::TextUnformatted("\uF6A8"); + } else { + ImGui::TextUnformatted("\uF028"); + } } else { - ImGui::TextUnformatted("\uF028"); + ImGui::TextUnformatted("\uF6A9"); } if (ImGui::IsItemClicked()) { std::swap(m_mutedLogVolume, m_logVolume); - // Using x^4 as an approximation. - m_linVolume = std::pow(m_logVolume / 100.0_f, 4.0_f); + if (!m_isVolumeMuted) { + m_linVolume = 0; + m_isVolumeMuted = true; + } else { + // Using x^4 as an approximation. + m_linVolume = std::pow(m_logVolume / 100.0_f, 4.0_f); + m_isVolumeMuted = false; + } } ImGui::SameLine(afterVolX); ImGui::SetNextItemWidth(5 * em()); if (ImGui::SliderFloatOrDouble("##Volume", &m_logVolume, 0.0_f, 100.0_f, "%.0f %%")) { + // Unmute if it was muted. + if (m_isVolumeMuted) { + std::swap(m_mutedLogVolume, m_logVolume); + m_isVolumeMuted = false; + } // Using x^4 as an approximation. m_linVolume = std::pow(m_logVolume / 100.0_f, 4.0_f); + m_isVolumeMuted = false; } ImGui::Separator(); diff --git a/src/app/SourceModelApp.h b/src/app/SourceModelApp.h index d1038fe..5738b7c 100644 --- a/src/app/SourceModelApp.h +++ b/src/app/SourceModelApp.h @@ -112,6 +112,7 @@ class SourceModelApp : public Application { bool m_doBypassFilter; bool m_doNormalizeFlowPlot; FrequencyScale m_spectrumFrequencyScale; + bool m_isVolumeMuted; Scalar m_mutedLogVolume; Scalar m_logVolume; Scalar m_linVolume;