From: David ‘Bombe’ Roden Date: Sun, 26 May 2013 16:26:19 +0000 (+0200) Subject: Add name to all controlled components. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=09f8bd2297dc864e24baa67c65be97104e00c320;p=sonitus.git Add name to all controlled components. --- diff --git a/src/main/java/net/pterodactylus/sonitus/data/Controlled.java b/src/main/java/net/pterodactylus/sonitus/data/Controlled.java index b84a114..e311681 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/Controlled.java +++ b/src/main/java/net/pterodactylus/sonitus/data/Controlled.java @@ -27,6 +27,13 @@ import java.util.List; 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 diff --git a/src/main/java/net/pterodactylus/sonitus/data/filter/AudioProcessingFilter.java b/src/main/java/net/pterodactylus/sonitus/data/filter/AudioProcessingFilter.java index 5539eea..e87935b 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/AudioProcessingFilter.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/AudioProcessingFilter.java @@ -30,6 +30,16 @@ import net.pterodactylus.sonitus.io.ProcessingOutputStream; */ 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 // 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 9d81923..ce02254 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/DummyFilter.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/DummyFilter.java @@ -40,6 +40,9 @@ import com.google.common.io.Closeables; */ public class DummyFilter implements Filter { + /** The name of this filter. */ + private final String name; + /** 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; + /** + * 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 + public String name() { + return name; + } + + @Override public List> controllers() { return Collections.emptyList(); } diff --git a/src/main/java/net/pterodactylus/sonitus/data/filter/ExternalFilter.java b/src/main/java/net/pterodactylus/sonitus/data/filter/ExternalFilter.java index 72c6177..990f976 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/ExternalFilter.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/ExternalFilter.java @@ -42,6 +42,16 @@ public abstract class ExternalFilter extends DummyFilter { /** 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 // diff --git a/src/main/java/net/pterodactylus/sonitus/data/filter/ExternalMp3Decoder.java b/src/main/java/net/pterodactylus/sonitus/data/filter/ExternalMp3Decoder.java index 2e80ec7..f81d532 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/ExternalMp3Decoder.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/ExternalMp3Decoder.java @@ -33,6 +33,16 @@ import net.pterodactylus.sonitus.data.Metadata; */ 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"); diff --git a/src/main/java/net/pterodactylus/sonitus/data/filter/ExternalMp3Encoder.java b/src/main/java/net/pterodactylus/sonitus/data/filter/ExternalMp3Encoder.java index 391e01b..21654af 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/ExternalMp3Encoder.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/ExternalMp3Encoder.java @@ -33,6 +33,16 @@ import net.pterodactylus.sonitus.data.Metadata; */ 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"); diff --git a/src/main/java/net/pterodactylus/sonitus/data/filter/FlacDecoder.java b/src/main/java/net/pterodactylus/sonitus/data/filter/FlacDecoder.java index cbb2698..e8447ef 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/FlacDecoder.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/FlacDecoder.java @@ -41,6 +41,7 @@ public class FlacDecoder extends ExternalFilter { * The location of the binary */ public FlacDecoder(String binary) { + super("FLAC Decoder"); this.binary = binary; } diff --git a/src/main/java/net/pterodactylus/sonitus/data/filter/LameMp3Decoder.java b/src/main/java/net/pterodactylus/sonitus/data/filter/LameMp3Decoder.java index cb23259..7493b3e 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/LameMp3Decoder.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/LameMp3Decoder.java @@ -41,6 +41,7 @@ public class LameMp3Decoder extends ExternalMp3Decoder { * The location of the binary */ public LameMp3Decoder(String binary) { + super("LAME Decoder"); this.binary = binary; } diff --git a/src/main/java/net/pterodactylus/sonitus/data/filter/LameMp3Encoder.java b/src/main/java/net/pterodactylus/sonitus/data/filter/LameMp3Encoder.java index 85675ce..d425fe2 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/LameMp3Encoder.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/LameMp3Encoder.java @@ -98,6 +98,7 @@ public class LameMp3Encoder extends ExternalMp3Encoder { * 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.absent() : Optional.of(bitrate); diff --git a/src/main/java/net/pterodactylus/sonitus/data/filter/OggVorbisDecoder.java b/src/main/java/net/pterodactylus/sonitus/data/filter/OggVorbisDecoder.java index 5ea2d48..b142fdd 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/OggVorbisDecoder.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/OggVorbisDecoder.java @@ -47,6 +47,7 @@ public class OggVorbisDecoder extends ExternalFilter { * The location of the binary */ public OggVorbisDecoder(String binary) { + super("Ogg Vorbis Decoder"); this.binary = binary; } diff --git a/src/main/java/net/pterodactylus/sonitus/data/filter/PredicateFilter.java b/src/main/java/net/pterodactylus/sonitus/data/filter/PredicateFilter.java index 1e8c7fa..173073e 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/PredicateFilter.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/PredicateFilter.java @@ -53,6 +53,7 @@ public class PredicateFilter extends DummyFilter { * The filter to use if the predicate matches the metadata */ public PredicateFilter(Predicate metadataPredicate, Filter filter) { + super(String.format("%s (maybe)", filter.name())); this.metadataPredicate = metadataPredicate; this.filter = filter; } diff --git a/src/main/java/net/pterodactylus/sonitus/data/filter/RateLimitingFilter.java b/src/main/java/net/pterodactylus/sonitus/data/filter/RateLimitingFilter.java index d513df6..fc89a50 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/RateLimitingFilter.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/RateLimitingFilter.java @@ -46,23 +46,28 @@ public class RateLimitingFilter extends DummyFilter { /** * Creates a new rate limiting filter. * + * @param name + * The name of the filter * @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. * + * @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) */ - 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)); } diff --git a/src/main/java/net/pterodactylus/sonitus/data/filter/SoxResampleFilter.java b/src/main/java/net/pterodactylus/sonitus/data/filter/SoxResampleFilter.java index a5061fb..f562574 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/SoxResampleFilter.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/SoxResampleFilter.java @@ -49,6 +49,7 @@ public class SoxResampleFilter extends ExternalFilter { * 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; } diff --git a/src/main/java/net/pterodactylus/sonitus/data/filter/StereoSeparationFilter.java b/src/main/java/net/pterodactylus/sonitus/data/filter/StereoSeparationFilter.java index d3ec652..3993e11 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/StereoSeparationFilter.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/StereoSeparationFilter.java @@ -37,6 +37,7 @@ public class StereoSeparationFilter extends AudioProcessingFilter { /** Creates a new stereo separation filter. */ public StereoSeparationFilter() { + super("Stereo Separation"); separationKnob = new Knob("Separation", 1.0); } diff --git a/src/main/java/net/pterodactylus/sonitus/data/filter/TimeCounterFilter.java b/src/main/java/net/pterodactylus/sonitus/data/filter/TimeCounterFilter.java index 3bb4415..a528200 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/TimeCounterFilter.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/TimeCounterFilter.java @@ -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}. + * + * @param name + * The name of the filter */ - public TimeCounterFilter() { - this(true); + public TimeCounterFilter(String name) { + this(name, true); } /** * 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 */ - public TimeCounterFilter(boolean resetOnMetadataUpdate) { + public TimeCounterFilter(String name, boolean resetOnMetadataUpdate) { + super(name); this.resetOnMetadataUpdate = resetOnMetadataUpdate; } 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 d95df6e..f7ab938 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/sink/AudioSink.java +++ b/src/main/java/net/pterodactylus/sonitus/data/sink/AudioSink.java @@ -85,7 +85,6 @@ public class AudioSink implements Sink { /** Creates a new audio sink. */ public AudioSink() { - super(); volumeFader = new Fader("Volume") { @Override @@ -120,6 +119,11 @@ public class AudioSink implements Sink { // @Override + public String name() { + return "Audio Output"; + } + + @Override public List> controllers() { return Arrays.>asList(volumeFader, muteSwitch); } 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 9da8b48..9bebc6b 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/sink/FileSink.java +++ b/src/main/java/net/pterodactylus/sonitus/data/sink/FileSink.java @@ -58,6 +58,11 @@ public class FileSink implements Sink { // @Override + public String name() { + return path; + } + + @Override public List> controllers() { return Collections.emptyList(); } 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 89a930c..36413f9 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/sink/Icecast2Sink.java +++ b/src/main/java/net/pterodactylus/sonitus/data/sink/Icecast2Sink.java @@ -115,6 +115,11 @@ public class Icecast2Sink implements Sink { // @Override + public String name() { + return String.format("icecast://%s:%d/%s", server, port, mountPoint); + } + + @Override public List> controllers() { return Collections.emptyList(); } 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 840bd9f..766d7de 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/source/FileSource.java +++ b/src/main/java/net/pterodactylus/sonitus/data/source/FileSource.java @@ -78,6 +78,11 @@ public class FileSource implements Source { // @Override + public String name() { + return path; + } + + @Override public List> controllers() { return Collections.emptyList(); } 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 6eab01e..a1d0202 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/source/MultiSource.java +++ b/src/main/java/net/pterodactylus/sonitus/data/source/MultiSource.java @@ -88,6 +88,11 @@ public class MultiSource implements Source { // @Override + public String name() { + return "Multisource"; + } + + @Override public List> controllers() { return Collections.emptyList(); } 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 90cf645..750642e 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/source/StreamSource.java +++ b/src/main/java/net/pterodactylus/sonitus/data/source/StreamSource.java @@ -50,6 +50,9 @@ public class StreamSource implements Source { /** 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; @@ -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); + streamName = httpUrlConnection.getHeaderField("ICY-Name"); } // @@ -121,6 +125,11 @@ public class StreamSource implements Source { // @Override + public String name() { + return streamName; + } + + @Override public List> controllers() { return Collections.emptyList(); } diff --git a/src/main/java/net/pterodactylus/sonitus/gui/MainWindow.java b/src/main/java/net/pterodactylus/sonitus/gui/MainWindow.java index 0cc3b13..cdd0776 100644 --- a/src/main/java/net/pterodactylus/sonitus/gui/MainWindow.java +++ b/src/main/java/net/pterodactylus/sonitus/gui/MainWindow.java @@ -64,7 +64,7 @@ public class MainWindow extends JFrame { return; } ControlledPane controlledPane = new ControlledPane(controlled); - tabbedPane.addTab(controlled.toString(), controlledPane); + tabbedPane.addTab(controlled.name(), controlledPane); } }