From 9a5bbdb694cda8f4bc0794aea136b993399961dd 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:32:07 +0200 Subject: [PATCH] Every source, sink, and filter is now also a controller. --- .../net/pterodactylus/sonitus/data/Filter.java | 2 +- .../java/net/pterodactylus/sonitus/data/Sink.java | 2 +- .../net/pterodactylus/sonitus/data/Source.java | 2 +- .../sonitus/data/filter/DummyFilter.java | 12 ++++++++ .../pterodactylus/sonitus/data/sink/AudioSink.java | 34 ++++++++++++++++++++++ .../pterodactylus/sonitus/data/sink/FileSink.java | 16 ++++++++++ .../sonitus/data/sink/Icecast2Sink.java | 12 ++++++++ .../sonitus/data/source/FileSource.java | 12 ++++++++ .../sonitus/data/source/MultiSource.java | 12 ++++++++ .../sonitus/data/source/StreamSource.java | 12 ++++++++ 10 files changed, 113 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/pterodactylus/sonitus/data/Filter.java b/src/main/java/net/pterodactylus/sonitus/data/Filter.java index c6fab7e..794c82a 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/Filter.java +++ b/src/main/java/net/pterodactylus/sonitus/data/Filter.java @@ -23,6 +23,6 @@ package net.pterodactylus.sonitus.data; * * @author David ‘Bombe’ Roden */ -public interface Filter extends Source, Sink { +public interface Filter extends Controlled, Source, Sink { } diff --git a/src/main/java/net/pterodactylus/sonitus/data/Sink.java b/src/main/java/net/pterodactylus/sonitus/data/Sink.java index 09679c6..c238fef 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/Sink.java +++ b/src/main/java/net/pterodactylus/sonitus/data/Sink.java @@ -8,7 +8,7 @@ import java.io.IOException; * * @author David ‘Bombe’ Roden */ -public interface Sink { +public interface Sink extends Controlled { /** * Opens this sink using the format parameters of the given metadata. diff --git a/src/main/java/net/pterodactylus/sonitus/data/Source.java b/src/main/java/net/pterodactylus/sonitus/data/Source.java index 4e9895e..cf2dd66 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/Source.java +++ b/src/main/java/net/pterodactylus/sonitus/data/Source.java @@ -7,7 +7,7 @@ import java.io.IOException; * * @author David ‘Bombe’ Roden */ -public interface Source { +public interface Source extends Controlled { /** * Returns the metadata of the audio stream. diff --git a/src/main/java/net/pterodactylus/sonitus/data/filter/DummyFilter.java b/src/main/java/net/pterodactylus/sonitus/data/filter/DummyFilter.java index a3ce099..2247ecc 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/DummyFilter.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/DummyFilter.java @@ -24,7 +24,10 @@ import java.io.OutputStream; import java.io.PipedInputStream; import java.io.PipedOutputStream; import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import net.pterodactylus.sonitus.data.Controller; import net.pterodactylus.sonitus.data.Filter; import net.pterodactylus.sonitus.data.Metadata; @@ -47,6 +50,15 @@ public class DummyFilter implements Filter { private Metadata metadata; // + // CONTROLLED METHODS + // + + @Override + public List controllers() { + return Collections.emptyList(); + } + + // // FILTER METHODS // 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 f80113b..72442f5 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/sink/AudioSink.java +++ b/src/main/java/net/pterodactylus/sonitus/data/sink/AudioSink.java @@ -17,16 +17,23 @@ package net.pterodactylus.sonitus.data.sink; +import static javax.sound.sampled.FloatControl.Type.VOLUME; + import java.io.IOException; +import java.util.Arrays; +import java.util.List; import java.util.logging.Logger; import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioSystem; +import javax.sound.sampled.FloatControl; import javax.sound.sampled.LineUnavailableException; import javax.sound.sampled.SourceDataLine; +import net.pterodactylus.sonitus.data.Controller; 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 com.google.common.base.Preconditions; @@ -41,12 +48,39 @@ public class AudioSink implements Sink { /** The logger. */ private static final Logger logger = Logger.getLogger(AudioSink.class.getName()); + /** The volume fader. */ + private final Fader volumeFader; + /** The current metadata. */ private Metadata metadata; /** The audio output. */ private SourceDataLine sourceDataLine; + /** Creates a new audio sink. */ + public AudioSink() { + super(); + volumeFader = new Fader() { + + @Override + protected void valueSet(int value) { + if (sourceDataLine != null) { + FloatControl volumeControl = (FloatControl) sourceDataLine.getControl(VOLUME); + volumeControl.setValue(value * volumeControl.getMaximum() / (float) maximum()); + } + } + }; + } + + // + // CONTROLLED METHODS + // + + @Override + public List controllers() { + return Arrays.asList(volumeFader); + } + // // SINK METHODS // diff --git a/src/main/java/net/pterodactylus/sonitus/data/sink/FileSink.java b/src/main/java/net/pterodactylus/sonitus/data/sink/FileSink.java index 7210f71..f3600f0 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/sink/FileSink.java +++ b/src/main/java/net/pterodactylus/sonitus/data/sink/FileSink.java @@ -19,8 +19,11 @@ package net.pterodactylus.sonitus.data.sink; import java.io.FileOutputStream; import java.io.IOException; +import java.util.Collections; +import java.util.List; import java.util.logging.Logger; +import net.pterodactylus.sonitus.data.Controller; import net.pterodactylus.sonitus.data.Metadata; import net.pterodactylus.sonitus.data.Sink; @@ -50,6 +53,19 @@ public class FileSink implements Sink { this.path = path; } + // + // CONTROLLED METHODS + // + + @Override + public List controllers() { + return Collections.emptyList(); + } + + // + // SINK METHODS + // + @Override public void open(Metadata metadata) throws IOException { fileOutputStream = new FileOutputStream(path); diff --git a/src/main/java/net/pterodactylus/sonitus/data/sink/Icecast2Sink.java b/src/main/java/net/pterodactylus/sonitus/data/sink/Icecast2Sink.java index 638e15b..359c262 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/sink/Icecast2Sink.java +++ b/src/main/java/net/pterodactylus/sonitus/data/sink/Icecast2Sink.java @@ -24,9 +24,12 @@ import java.io.UnsupportedEncodingException; import java.net.Socket; import java.net.URLEncoder; import java.util.Arrays; +import java.util.Collections; +import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; +import net.pterodactylus.sonitus.data.Controller; import net.pterodactylus.sonitus.data.Metadata; import net.pterodactylus.sonitus.data.Sink; import net.pterodactylus.sonitus.io.InputStreamDrainer; @@ -108,6 +111,15 @@ public class Icecast2Sink implements Sink { } // + // CONTROLLED METHODS + // + + @Override + public List controllers() { + return Collections.emptyList(); + } + + // // SINK METHODS // diff --git a/src/main/java/net/pterodactylus/sonitus/data/source/FileSource.java b/src/main/java/net/pterodactylus/sonitus/data/source/FileSource.java index dfa1665..08139d5 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/source/FileSource.java +++ b/src/main/java/net/pterodactylus/sonitus/data/source/FileSource.java @@ -24,7 +24,10 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import net.pterodactylus.sonitus.data.Controller; import net.pterodactylus.sonitus.data.Metadata; import net.pterodactylus.sonitus.data.Source; import net.pterodactylus.sonitus.io.IdentifyingInputStream; @@ -71,6 +74,15 @@ public class FileSource implements Source { } // + // CONTROLLED METHODS + // + + @Override + public List controllers() { + return Collections.emptyList(); + } + + // // SOURCE METHODS // diff --git a/src/main/java/net/pterodactylus/sonitus/data/source/MultiSource.java b/src/main/java/net/pterodactylus/sonitus/data/source/MultiSource.java index b5705d5..0779b1a 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/source/MultiSource.java +++ b/src/main/java/net/pterodactylus/sonitus/data/source/MultiSource.java @@ -21,9 +21,12 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.io.EOFException; import java.io.IOException; +import java.util.Collections; +import java.util.List; import java.util.concurrent.atomic.AtomicReference; import java.util.logging.Logger; +import net.pterodactylus.sonitus.data.Controller; import net.pterodactylus.sonitus.data.Metadata; import net.pterodactylus.sonitus.data.Source; import net.pterodactylus.sonitus.data.event.SourceFinishedEvent; @@ -81,6 +84,15 @@ public class MultiSource implements Source { } // + // CONTROLLED METHODS + // + + @Override + public List controllers() { + return Collections.emptyList(); + } + + // // SOURCE METHODS // diff --git a/src/main/java/net/pterodactylus/sonitus/data/source/StreamSource.java b/src/main/java/net/pterodactylus/sonitus/data/source/StreamSource.java index d9df054..8c7464c 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/source/StreamSource.java +++ b/src/main/java/net/pterodactylus/sonitus/data/source/StreamSource.java @@ -22,9 +22,12 @@ import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; +import java.util.Collections; +import java.util.List; import java.util.Map; import net.pterodactylus.sonitus.data.ContentMetadata; +import net.pterodactylus.sonitus.data.Controller; import net.pterodactylus.sonitus.data.FormatMetadata; import net.pterodactylus.sonitus.data.Metadata; import net.pterodactylus.sonitus.data.Source; @@ -114,6 +117,15 @@ public class StreamSource implements Source { } // + // CONTROLLED METHODS + // + + @Override + public List controllers() { + return Collections.emptyList(); + } + + // // SOURCE METHODS // -- 2.7.4