Add name to all controlled components.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 26 May 2013 16:26:19 +0000 (18:26 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 27 May 2013 20:54:39 +0000 (22:54 +0200)
22 files changed:
src/main/java/net/pterodactylus/sonitus/data/Controlled.java
src/main/java/net/pterodactylus/sonitus/data/filter/AudioProcessingFilter.java
src/main/java/net/pterodactylus/sonitus/data/filter/DummyFilter.java
src/main/java/net/pterodactylus/sonitus/data/filter/ExternalFilter.java
src/main/java/net/pterodactylus/sonitus/data/filter/ExternalMp3Decoder.java
src/main/java/net/pterodactylus/sonitus/data/filter/ExternalMp3Encoder.java
src/main/java/net/pterodactylus/sonitus/data/filter/FlacDecoder.java
src/main/java/net/pterodactylus/sonitus/data/filter/LameMp3Decoder.java
src/main/java/net/pterodactylus/sonitus/data/filter/LameMp3Encoder.java
src/main/java/net/pterodactylus/sonitus/data/filter/OggVorbisDecoder.java
src/main/java/net/pterodactylus/sonitus/data/filter/PredicateFilter.java
src/main/java/net/pterodactylus/sonitus/data/filter/RateLimitingFilter.java
src/main/java/net/pterodactylus/sonitus/data/filter/SoxResampleFilter.java
src/main/java/net/pterodactylus/sonitus/data/filter/StereoSeparationFilter.java
src/main/java/net/pterodactylus/sonitus/data/filter/TimeCounterFilter.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
src/main/java/net/pterodactylus/sonitus/gui/MainWindow.java

index b84a114..e311681 100644 (file)
@@ -27,6 +27,13 @@ import java.util.List;
 public interface Controlled {
 
        /**
 public interface Controlled {
 
        /**
+        * Returns the name of this controlled component.
+        *
+        * @return The name of this controlled component
+        */
+       public String name();
+
+       /**
         * Returns the controllers offered by this component.
         *
         * @return The controllers of this component
         * Returns the controllers offered by this component.
         *
         * @return The controllers of this component
index 5539eea..e87935b 100644 (file)
@@ -30,6 +30,16 @@ import net.pterodactylus.sonitus.io.ProcessingOutputStream;
  */
 public abstract class AudioProcessingFilter extends DummyFilter {
 
  */
 public abstract class AudioProcessingFilter extends DummyFilter {
 
+       /**
+        * Creates a new audio processing filter with the given name.
+        *
+        * @param name
+        *              The name of the filter
+        */
+       protected AudioProcessingFilter(String name) {
+               super(name);
+       }
+
        //
        // DUMMYFILTER METHODS
        //
        //
        // DUMMYFILTER METHODS
        //
index 9d81923..ce02254 100644 (file)
@@ -40,6 +40,9 @@ import com.google.common.io.Closeables;
  */
 public class DummyFilter implements Filter {
 
  */
 public class DummyFilter implements Filter {
 
+       /** The name of this filter. */
+       private final String name;
+
        /** The input stream from which to read. */
        private InputStream inputStream;
 
        /** The input stream from which to read. */
        private InputStream inputStream;
 
@@ -49,11 +52,26 @@ public class DummyFilter implements Filter {
        /** The current metadata. */
        private Metadata metadata;
 
        /** The current metadata. */
        private Metadata metadata;
 
+       /**
+        * Creates a new dummy filter with the given name.
+        *
+        * @param name
+        *              The name of the filter
+        */
+       public DummyFilter(String name) {
+               this.name = name;
+       }
+
        //
        // CONTROLLED METHODS
        //
 
        @Override
        //
        // CONTROLLED METHODS
        //
 
        @Override
+       public String name() {
+               return name;
+       }
+
+       @Override
        public List<Controller<?>> controllers() {
                return Collections.emptyList();
        }
        public List<Controller<?>> controllers() {
                return Collections.emptyList();
        }
index 72c6177..990f976 100644 (file)
@@ -42,6 +42,16 @@ public abstract class ExternalFilter extends DummyFilter {
        /** The external process. */
        private Process process;
 
        /** The external process. */
        private Process process;
 
+       /**
+        * Creates a new external filter with the given name.
+        *
+        * @param name
+        *              The name of the filter
+        */
+       protected ExternalFilter(String name) {
+               super(name);
+       }
+
        //
        // FILTER METHODS
        //
        //
        // FILTER METHODS
        //
index 2e80ec7..f81d532 100644 (file)
@@ -33,6 +33,16 @@ import net.pterodactylus.sonitus.data.Metadata;
  */
 public abstract class ExternalMp3Decoder extends ExternalFilter {
 
  */
 public abstract class ExternalMp3Decoder extends ExternalFilter {
 
+       /**
+        * Creates a new external MP3 decoder.
+        *
+        * @param name
+        *              The name of the filter
+        */
+       protected ExternalMp3Decoder(String name) {
+               super(name);
+       }
+
        @Override
        public Metadata metadata() {
                return super.metadata().encoding("PCM");
        @Override
        public Metadata metadata() {
                return super.metadata().encoding("PCM");
index 391e01b..21654af 100644 (file)
@@ -33,6 +33,16 @@ import net.pterodactylus.sonitus.data.Metadata;
  */
 public abstract class ExternalMp3Encoder extends ExternalFilter {
 
  */
 public abstract class ExternalMp3Encoder extends ExternalFilter {
 
+       /**
+        * Creates a new external MP3 encoder.
+        *
+        * @param name
+        *              The name of the filter
+        */
+       protected ExternalMp3Encoder(String name) {
+               super(name);
+       }
+
        @Override
        public Metadata metadata() {
                return super.metadata().encoding("MP3");
        @Override
        public Metadata metadata() {
                return super.metadata().encoding("MP3");
index cbb2698..e8447ef 100644 (file)
@@ -41,6 +41,7 @@ public class FlacDecoder extends ExternalFilter {
         *              The location of the binary
         */
        public FlacDecoder(String binary) {
         *              The location of the binary
         */
        public FlacDecoder(String binary) {
+               super("FLAC Decoder");
                this.binary = binary;
        }
 
                this.binary = binary;
        }
 
index cb23259..7493b3e 100644 (file)
@@ -41,6 +41,7 @@ public class LameMp3Decoder extends ExternalMp3Decoder {
         *              The location of the binary
         */
        public LameMp3Decoder(String binary) {
         *              The location of the binary
         */
        public LameMp3Decoder(String binary) {
+               super("LAME Decoder");
                this.binary = binary;
        }
 
                this.binary = binary;
        }
 
index 85675ce..d425fe2 100644 (file)
@@ -98,6 +98,7 @@ public class LameMp3Encoder extends ExternalMp3Encoder {
         *              The bitrate to encode to (in kbps)
         */
        private LameMp3Encoder(String binary, Preset preset, int bitrate) {
         *              The bitrate to encode to (in kbps)
         */
        private LameMp3Encoder(String binary, Preset preset, int bitrate) {
+               super("LAME Encoder");
                this.binary = binary;
                this.preset = Optional.fromNullable(preset);
                this.bitrate = (bitrate < 0) ? Optional.<Integer>absent() : Optional.<Integer>of(bitrate);
                this.binary = binary;
                this.preset = Optional.fromNullable(preset);
                this.bitrate = (bitrate < 0) ? Optional.<Integer>absent() : Optional.<Integer>of(bitrate);
index 5ea2d48..b142fdd 100644 (file)
@@ -47,6 +47,7 @@ public class OggVorbisDecoder extends ExternalFilter {
         *              The location of the binary
         */
        public OggVorbisDecoder(String binary) {
         *              The location of the binary
         */
        public OggVorbisDecoder(String binary) {
+               super("Ogg Vorbis Decoder");
                this.binary = binary;
        }
 
                this.binary = binary;
        }
 
index 1e8c7fa..173073e 100644 (file)
@@ -53,6 +53,7 @@ public class PredicateFilter extends DummyFilter {
         *              The filter to use if the predicate matches the metadata
         */
        public PredicateFilter(Predicate<Metadata> metadataPredicate, Filter filter) {
         *              The filter to use if the predicate matches the metadata
         */
        public PredicateFilter(Predicate<Metadata> metadataPredicate, Filter filter) {
+               super(String.format("%s (maybe)", filter.name()));
                this.metadataPredicate = metadataPredicate;
                this.filter = filter;
        }
                this.metadataPredicate = metadataPredicate;
                this.filter = filter;
        }
index d513df6..fc89a50 100644 (file)
@@ -46,23 +46,28 @@ public class RateLimitingFilter extends DummyFilter {
        /**
         * Creates a new rate limiting filter.
         *
        /**
         * Creates a new rate limiting filter.
         *
+        * @param name
+        *              The name of the filter
         * @param rate
         *              The limiting rate (in bytes/second)
         */
         * @param rate
         *              The limiting rate (in bytes/second)
         */
-       public RateLimitingFilter(int rate) {
-               this(rate, 0);
+       public RateLimitingFilter(String name, int rate) {
+               this(name, rate, 0);
        }
 
        /**
         * Creates a new rate limiting filter.
         *
        }
 
        /**
         * Creates a new rate limiting filter.
         *
+        * @param name
+        *              The name of the filter
         * @param rate
         *              The limiting rate (in bytes/second)
         * @param fastStartTime
         *              The amount of time at the start of the filtering during which no delay
         *              will occur (in milliseconds)
         */
         * @param rate
         *              The limiting rate (in bytes/second)
         * @param fastStartTime
         *              The amount of time at the start of the filtering during which no delay
         *              will occur (in milliseconds)
         */
-       public RateLimitingFilter(int rate, long fastStartTime) {
+       public RateLimitingFilter(String name, int rate, long fastStartTime) {
+               super(name);
                this.rate = rate;
                this.counter = (long) (-rate * (fastStartTime / 1000.0));
        }
                this.rate = rate;
                this.counter = (long) (-rate * (fastStartTime / 1000.0));
        }
index a5061fb..f562574 100644 (file)
@@ -49,6 +49,7 @@ public class SoxResampleFilter extends ExternalFilter {
         *              The new sampling rate
         */
        public SoxResampleFilter(String binary, int rate) {
         *              The new sampling rate
         */
        public SoxResampleFilter(String binary, int rate) {
+               super(String.format("Resample to %s kHz", rate / 1000.0));
                this.binary = binary;
                this.rate = rate;
        }
                this.binary = binary;
                this.rate = rate;
        }
index d3ec652..3993e11 100644 (file)
@@ -37,6 +37,7 @@ public class StereoSeparationFilter extends AudioProcessingFilter {
 
        /** Creates a new stereo separation filter. */
        public StereoSeparationFilter() {
 
        /** Creates a new stereo separation filter. */
        public StereoSeparationFilter() {
+               super("Stereo Separation");
                separationKnob = new Knob("Separation", 1.0);
        }
 
                separationKnob = new Knob("Separation", 1.0);
        }
 
index 3bb4415..a528200 100644 (file)
@@ -41,19 +41,25 @@ public class TimeCounterFilter extends DummyFilter {
        /**
         * Creates a new time counter filter that automatically resets the counter when
         * the metadata is {@link #metadataUpdated(Metadata) updated}.
        /**
         * Creates a new time counter filter that automatically resets the counter when
         * the metadata is {@link #metadataUpdated(Metadata) updated}.
+        *
+        * @param name
+        *              The name of the filter
         */
         */
-       public TimeCounterFilter() {
-               this(true);
+       public TimeCounterFilter(String name) {
+               this(name, true);
        }
 
        /**
         * Creates a new time counter filter.
         *
        }
 
        /**
         * Creates a new time counter filter.
         *
+        * @param name
+        *              The name of the filter
         * @param resetOnMetadataUpdate
         *              {@code true} if the counter should automatically be reset if the metadata
         *              is updated, {@code false} otherwise
         */
         * @param resetOnMetadataUpdate
         *              {@code true} if the counter should automatically be reset if the metadata
         *              is updated, {@code false} otherwise
         */
-       public TimeCounterFilter(boolean resetOnMetadataUpdate) {
+       public TimeCounterFilter(String name, boolean resetOnMetadataUpdate) {
+               super(name);
                this.resetOnMetadataUpdate = resetOnMetadataUpdate;
        }
 
                this.resetOnMetadataUpdate = resetOnMetadataUpdate;
        }
 
index d95df6e..f7ab938 100644 (file)
@@ -85,7 +85,6 @@ public class AudioSink implements Sink {
 
        /** Creates a new audio sink. */
        public AudioSink() {
 
        /** Creates a new audio sink. */
        public AudioSink() {
-               super();
                volumeFader = new Fader("Volume") {
 
                        @Override
                volumeFader = new Fader("Volume") {
 
                        @Override
@@ -120,6 +119,11 @@ public class AudioSink implements Sink {
        //
 
        @Override
        //
 
        @Override
+       public String name() {
+               return "Audio Output";
+       }
+
+       @Override
        public List<Controller<?>> controllers() {
                return Arrays.<Controller<?>>asList(volumeFader, muteSwitch);
        }
        public List<Controller<?>> controllers() {
                return Arrays.<Controller<?>>asList(volumeFader, muteSwitch);
        }
index 9da8b48..9bebc6b 100644 (file)
@@ -58,6 +58,11 @@ public class FileSink implements Sink {
        //
 
        @Override
        //
 
        @Override
+       public String name() {
+               return path;
+       }
+
+       @Override
        public List<Controller<?>> controllers() {
                return Collections.emptyList();
        }
        public List<Controller<?>> controllers() {
                return Collections.emptyList();
        }
index 89a930c..36413f9 100644 (file)
@@ -115,6 +115,11 @@ public class Icecast2Sink implements Sink {
        //
 
        @Override
        //
 
        @Override
+       public String name() {
+               return String.format("icecast://%s:%d/%s", server, port, mountPoint);
+       }
+
+       @Override
        public List<Controller<?>> controllers() {
                return Collections.emptyList();
        }
        public List<Controller<?>> controllers() {
                return Collections.emptyList();
        }
index 840bd9f..766d7de 100644 (file)
@@ -78,6 +78,11 @@ public class FileSource implements Source {
        //
 
        @Override
        //
 
        @Override
+       public String name() {
+               return path;
+       }
+
+       @Override
        public List<Controller<?>> controllers() {
                return Collections.emptyList();
        }
        public List<Controller<?>> controllers() {
                return Collections.emptyList();
        }
index 6eab01e..a1d0202 100644 (file)
@@ -88,6 +88,11 @@ public class MultiSource implements Source {
        //
 
        @Override
        //
 
        @Override
+       public String name() {
+               return "Multisource";
+       }
+
+       @Override
        public List<Controller<?>> controllers() {
                return Collections.emptyList();
        }
        public List<Controller<?>> controllers() {
                return Collections.emptyList();
        }
index 90cf645..750642e 100644 (file)
@@ -50,6 +50,9 @@ public class StreamSource implements Source {
        /** The URL of the stream. */
        private final String streamUrl;
 
        /** The URL of the stream. */
        private final String streamUrl;
 
+       /** The name of the station. */
+       private final String streamName;
+
        /** The metadata stream. */
        private final MetadataStream metadataStream;
 
        /** The metadata stream. */
        private final MetadataStream metadataStream;
 
@@ -114,6 +117,7 @@ public class StreamSource implements Source {
 
                metadata = new Metadata(new FormatMetadata(audioParameters.get("ice-channels"), audioParameters.get("ice-samplerate"), "MP3"), new ContentMetadata());
                metadataStream = new MetadataStream(new BufferedInputStream(httpUrlConnection.getInputStream()), metadataInterval);
 
                metadata = new Metadata(new FormatMetadata(audioParameters.get("ice-channels"), audioParameters.get("ice-samplerate"), "MP3"), new ContentMetadata());
                metadataStream = new MetadataStream(new BufferedInputStream(httpUrlConnection.getInputStream()), metadataInterval);
+               streamName = httpUrlConnection.getHeaderField("ICY-Name");
        }
 
        //
        }
 
        //
@@ -121,6 +125,11 @@ public class StreamSource implements Source {
        //
 
        @Override
        //
 
        @Override
+       public String name() {
+               return streamName;
+       }
+
+       @Override
        public List<Controller<?>> controllers() {
                return Collections.emptyList();
        }
        public List<Controller<?>> controllers() {
                return Collections.emptyList();
        }
index 0cc3b13..cdd0776 100644 (file)
@@ -64,7 +64,7 @@ public class MainWindow extends JFrame {
                        return;
                }
                ControlledPane controlledPane = new ControlledPane(controlled);
                        return;
                }
                ControlledPane controlledPane = new ControlledPane(controlled);
-               tabbedPane.addTab(controlled.toString(), controlledPane);
+               tabbedPane.addTab(controlled.name(), controlledPane);
        }
 
 }
        }
 
 }