From 95eb945b04d1071315531e913196fdfaab08ac51 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 26 May 2013 13:58:56 +0200 Subject: [PATCH] Add mute switch to audio sink. --- .../pterodactylus/sonitus/data/sink/AudioSink.java | 23 +++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/pterodactylus/sonitus/data/sink/AudioSink.java b/src/main/java/net/pterodactylus/sonitus/data/sink/AudioSink.java index 72442f5..720b919 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/sink/AudioSink.java +++ b/src/main/java/net/pterodactylus/sonitus/data/sink/AudioSink.java @@ -34,6 +34,7 @@ import net.pterodactylus.sonitus.data.Metadata; import net.pterodactylus.sonitus.data.Sink; import net.pterodactylus.sonitus.data.Source; import net.pterodactylus.sonitus.data.controller.Fader; +import net.pterodactylus.sonitus.data.controller.Switch; import com.google.common.base.Preconditions; @@ -51,6 +52,9 @@ public class AudioSink implements Sink { /** The volume fader. */ private final Fader volumeFader; + /** The “mute” switch. */ + private final Switch muteSwitch; + /** The current metadata. */ private Metadata metadata; @@ -70,6 +74,23 @@ public class AudioSink implements Sink { } } }; + muteSwitch = new Switch() { + + private float previousValue; + + @Override + protected void valueSet(int value) { + if (sourceDataLine != null) { + FloatControl volumeControl = (FloatControl) sourceDataLine.getControl(VOLUME); + if (value == 1) { + previousValue = volumeControl.getValue(); + volumeControl.setValue(0); + } else { + volumeControl.setValue(previousValue); + } + } + } + }; } // @@ -78,7 +99,7 @@ public class AudioSink implements Sink { @Override public List controllers() { - return Arrays.asList(volumeFader); + return Arrays.asList(volumeFader, muteSwitch); } // -- 2.7.4