From: David ‘Bombe’ Roden Date: Sun, 26 May 2013 11:58:56 +0000 (+0200) Subject: Add mute switch to audio sink. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=95eb945b04d1071315531e913196fdfaab08ac51;p=sonitus.git Add mute switch to audio sink. --- 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); } //