mute button
This commit is contained in:
@@ -305,6 +305,21 @@ ImVec2 audioDeviceWindow(ApplicationData& appData, std::vector<AudioDevice>& dev
|
|||||||
ImGui::TableNextColumn();
|
ImGui::TableNextColumn();
|
||||||
if (dev.state == DEVICE_STATE_ACTIVE)
|
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{};
|
static std::array<float, 2> meterValues{};
|
||||||
UINT channelCount = getMeterValues(dev.meterInterface, meterValues);
|
UINT channelCount = getMeterValues(dev.meterInterface, meterValues);
|
||||||
|
|
||||||
@@ -316,7 +331,7 @@ ImVec2 audioDeviceWindow(ApplicationData& appData, std::vector<AudioDevice>& dev
|
|||||||
|
|
||||||
const float linePaddingX = 3.;
|
const float linePaddingX = 3.;
|
||||||
cursorPos.x += linePaddingX;
|
cursorPos.x += linePaddingX;
|
||||||
|
|
||||||
// BG line
|
// BG line
|
||||||
drawList->AddLine(ImVec2(cursorPos.x, lineY), ImVec2(cursorPos.x + (space.x - 2. * linePaddingX), lineY), IM_COL32(120, 120, 120, 255), 2.);
|
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::SetNextItemWidth(space.x);
|
||||||
ImGui::PushID(&dev.id);
|
ImGui::PushID(&dev.id);
|
||||||
ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4(0, 0, 0, 0));
|
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);
|
float volume = getVolume(dev.volumeInterface);
|
||||||
if (ImGui::SliderFloat("", &volume, 0., 1., "", ImGuiSliderFlags_NoRoundToFormat | ImGuiSliderFlags_AlwaysClamp))
|
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);
|
setVolume(dev.volumeInterface, volume);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isDeviceMuted) ImGui::PopStyleColor();
|
||||||
ImGui::PopStyleColor();
|
ImGui::PopStyleColor();
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -171,4 +171,17 @@ void getVolumeLimit(IAudioEndpointVolume* volumeInterface, float* outMin, float*
|
|||||||
{
|
{
|
||||||
float dummy;
|
float dummy;
|
||||||
volumeInterface->GetVolumeRange(outMin, outMax, &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);
|
||||||
}
|
}
|
||||||
@@ -15,4 +15,6 @@ void setDefaultAudioDevice(AudioData& audioData, const wchar_t* deviceId, ERole
|
|||||||
float getVolume(IAudioEndpointVolume* volumeInterface);
|
float getVolume(IAudioEndpointVolume* volumeInterface);
|
||||||
void setVolume(IAudioEndpointVolume* volumeInterface, float newVolume);
|
void setVolume(IAudioEndpointVolume* volumeInterface, float newVolume);
|
||||||
UINT getMeterValues(IAudioMeterInformation* meterInterface, std::array<float, 2>& levels);
|
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);
|
||||||
Reference in New Issue
Block a user