Every source, sink, and filter is now also a controller.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 26 May 2013 11:32:07 +0000 (13:32 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 27 May 2013 20:54:38 +0000 (22:54 +0200)
src/main/java/net/pterodactylus/sonitus/data/Filter.java
src/main/java/net/pterodactylus/sonitus/data/Sink.java
src/main/java/net/pterodactylus/sonitus/data/Source.java
src/main/java/net/pterodactylus/sonitus/data/filter/DummyFilter.java
src/main/java/net/pterodactylus/sonitus/data/sink/AudioSink.java
src/main/java/net/pterodactylus/sonitus/data/sink/FileSink.java
src/main/java/net/pterodactylus/sonitus/data/sink/Icecast2Sink.java
src/main/java/net/pterodactylus/sonitus/data/source/FileSource.java
src/main/java/net/pterodactylus/sonitus/data/source/MultiSource.java
src/main/java/net/pterodactylus/sonitus/data/source/StreamSource.java

index c6fab7e..794c82a 100644 (file)
@@ -23,6 +23,6 @@ package net.pterodactylus.sonitus.data;
  *
  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
  */
-public interface Filter extends Source, Sink {
+public interface Filter extends Controlled, Source, Sink {
 
 }
index 09679c6..c238fef 100644 (file)
@@ -8,7 +8,7 @@ import java.io.IOException;
  *
  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
  */
-public interface Sink {
+public interface Sink extends Controlled {
 
        /**
         * Opens this sink using the format parameters of the given metadata.
index 4e9895e..cf2dd66 100644 (file)
@@ -7,7 +7,7 @@ import java.io.IOException;
  *
  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
  */
-public interface Source {
+public interface Source extends Controlled {
 
        /**
         * Returns the metadata of the audio stream.
index a3ce099..2247ecc 100644 (file)
@@ -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<Controller> controllers() {
+               return Collections.emptyList();
+       }
+
+       //
        // FILTER METHODS
        //
 
index f80113b..72442f5 100644 (file)
 
 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<Controller> controllers() {
+               return Arrays.<Controller>asList(volumeFader);
+       }
+
        //
        // SINK METHODS
        //
index 7210f71..f3600f0 100644 (file)
@@ -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<Controller> controllers() {
+               return Collections.emptyList();
+       }
+
+       //
+       // SINK METHODS
+       //
+
        @Override
        public void open(Metadata metadata) throws IOException {
                fileOutputStream = new FileOutputStream(path);
index 638e15b..359c262 100644 (file)
@@ -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<Controller> controllers() {
+               return Collections.emptyList();
+       }
+
+       //
        // SINK METHODS
        //
 
index dfa1665..08139d5 100644 (file)
@@ -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<Controller> controllers() {
+               return Collections.emptyList();
+       }
+
+       //
        // SOURCE METHODS
        //
 
index b5705d5..0779b1a 100644 (file)
@@ -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<Controller> controllers() {
+               return Collections.emptyList();
+       }
+
+       //
        // SOURCE METHODS
        //
 
index d9df054..8c7464c 100644 (file)
@@ -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<Controller> controllers() {
+               return Collections.emptyList();
+       }
+
+       //
        // SOURCE METHODS
        //