diff --git a/AsuroTool/AsuroTool.cpp b/AsuroTool/AsuroTool.cpp index 63481d1..25f72f8 100644 --- a/AsuroTool/AsuroTool.cpp +++ b/AsuroTool/AsuroTool.cpp @@ -305,6 +305,21 @@ ImVec2 audioDeviceWindow(ApplicationData& appData, std::vector& dev ImGui::TableNextColumn(); if (dev.state == DEVICE_STATE_ACTIVE) { + // Mute button + ImGui::PushID(std::string("bn_mute_").append(deviceIdUtf8).c_str()); + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0)); + + bool isDeviceMuted = isMuted(dev.volumeInterface); + if (ImGui::Button(isDeviceMuted ? "\xEF\x8A\x9D" : "\xEF\x8A\xA1")) + { + setMuted(dev.volumeInterface, !isDeviceMuted); + } + + ImGui::PopStyleColor(); + ImGui::PopID(); + ImGui::SameLine(0, 2); + + // Meter static std::array meterValues{}; UINT channelCount = getMeterValues(dev.meterInterface, meterValues); @@ -316,7 +331,7 @@ ImVec2 audioDeviceWindow(ApplicationData& appData, std::vector& dev const float linePaddingX = 3.; cursorPos.x += linePaddingX; - + // BG line drawList->AddLine(ImVec2(cursorPos.x, lineY), ImVec2(cursorPos.x + (space.x - 2. * linePaddingX), lineY), IM_COL32(120, 120, 120, 255), 2.); @@ -334,6 +349,7 @@ ImVec2 audioDeviceWindow(ApplicationData& appData, std::vector& dev ImGui::SetNextItemWidth(space.x); ImGui::PushID(&dev.id); ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4(0, 0, 0, 0)); + if (isDeviceMuted) ImGui::PushStyleColor(ImGuiCol_SliderGrab, ImVec4(.4, .4, .4, 1.)); float volume = getVolume(dev.volumeInterface); if (ImGui::SliderFloat("", &volume, 0., 1., "", ImGuiSliderFlags_NoRoundToFormat | ImGuiSliderFlags_AlwaysClamp)) @@ -341,6 +357,7 @@ ImVec2 audioDeviceWindow(ApplicationData& appData, std::vector& dev setVolume(dev.volumeInterface, volume); } + if (isDeviceMuted) ImGui::PopStyleColor(); ImGui::PopStyleColor(); ImGui::PopID(); } diff --git a/AsuroTool/AudioApi.cpp b/AsuroTool/AudioApi.cpp index 88f2532..5f1d60d 100644 --- a/AsuroTool/AudioApi.cpp +++ b/AsuroTool/AudioApi.cpp @@ -171,4 +171,17 @@ void getVolumeLimit(IAudioEndpointVolume* volumeInterface, float* outMin, float* { float dummy; volumeInterface->GetVolumeRange(outMin, outMax, &dummy); +} + +bool isMuted(IAudioEndpointVolume* volumeInterface) +{ + BOOL result = false; + if (FAILED(volumeInterface->GetMute(&result))) return false; + + return static_cast(result); +} + +void setMuted(IAudioEndpointVolume* volumeInterface, bool newState) +{ + volumeInterface->SetMute(static_cast(newState), NULL); } \ No newline at end of file diff --git a/AsuroTool/AudioApi.h b/AsuroTool/AudioApi.h index e041fea..f72ba79 100644 --- a/AsuroTool/AudioApi.h +++ b/AsuroTool/AudioApi.h @@ -15,4 +15,6 @@ void setDefaultAudioDevice(AudioData& audioData, const wchar_t* deviceId, ERole float getVolume(IAudioEndpointVolume* volumeInterface); void setVolume(IAudioEndpointVolume* volumeInterface, float newVolume); UINT getMeterValues(IAudioMeterInformation* meterInterface, std::array& levels); -void getVolumeLimit(IAudioEndpointVolume* volumeInterface, float* outMin, float* outMax); \ No newline at end of file +void getVolumeLimit(IAudioEndpointVolume* volumeInterface, float* outMin, float* outMax); +bool isMuted(IAudioEndpointVolume* volumeInterface); +void setMuted(IAudioEndpointVolume* volumeInterface, bool newState); \ No newline at end of file