Skip to content

Commit

Permalink
Better behaviour & icon for volume muted
Browse files Browse the repository at this point in the history
  • Loading branch information
clo-yunhee committed Jan 19, 2023
1 parent 192dccf commit 1064053
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/app/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ void Application::setupFonts() {
0xF04B, // Play
0xF04C, // Pause
0xF6A8,
0xF6A8, // Volume-mid
0xF6A9, // Volume-mid, volume-mute
0,
};

Expand Down
3 changes: 1 addition & 2 deletions src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down
36 changes: 27 additions & 9 deletions src/app/SourceModelApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/app/SourceModelApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 1064053

Please sign in to comment.