mute button

This commit is contained in:
2022-07-26 20:34:40 +02:00
parent 5f5e24fa9c
commit c58b6c5624
3 changed files with 34 additions and 2 deletions

View File

@@ -305,6 +305,21 @@ ImVec2 audioDeviceWindow(ApplicationData& appData, std::vector<AudioDevice>& 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<float, 2> meterValues{};
UINT channelCount = getMeterValues(dev.meterInterface, meterValues);
@@ -316,7 +331,7 @@ ImVec2 audioDeviceWindow(ApplicationData& appData, std::vector<AudioDevice>& 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<AudioDevice>& 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<AudioDevice>& dev
setVolume(dev.volumeInterface, volume);
}
if (isDeviceMuted) ImGui::PopStyleColor();
ImGui::PopStyleColor();
ImGui::PopID();
}

View File

@@ -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<bool>(result);
}
void setMuted(IAudioEndpointVolume* volumeInterface, bool newState)
{
volumeInterface->SetMute(static_cast<BOOL>(newState), NULL);
}

View File

@@ -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<float, 2>& levels);
void getVolumeLimit(IAudioEndpointVolume* volumeInterface, float* outMin, float* outMax);
void getVolumeLimit(IAudioEndpointVolume* volumeInterface, float* outMin, float* outMax);
bool isMuted(IAudioEndpointVolume* volumeInterface);
void setMuted(IAudioEndpointVolume* volumeInterface, bool newState);