From: David ‘Bombe’ Roden Date: Mon, 27 May 2013 07:39:51 +0000 (+0200) Subject: Create all controlled components with an event bus. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=c548332c486d812bfce23a9121219bf86ecc5588;p=sonitus.git Create all controlled components with an event bus. --- 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 e87935b..b584395 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/AudioProcessingFilter.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/AudioProcessingFilter.java @@ -23,6 +23,8 @@ import java.io.OutputStream; import net.pterodactylus.sonitus.data.Filter; import net.pterodactylus.sonitus.io.ProcessingOutputStream; +import com.google.common.eventbus.EventBus; + /** * {@link Filter} implementation that can process audio samples internally. * @@ -33,11 +35,13 @@ public abstract class AudioProcessingFilter extends DummyFilter { /** * Creates a new audio processing filter with the given name. * + * @param eventBus + * The event bus * @param name * The name of the filter */ - protected AudioProcessingFilter(String name) { - super(name); + protected AudioProcessingFilter(EventBus eventBus, String name) { + super(eventBus, name); } // 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 ce02254..4e19683 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/DummyFilter.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/DummyFilter.java @@ -31,6 +31,7 @@ import net.pterodactylus.sonitus.data.Controller; import net.pterodactylus.sonitus.data.Filter; import net.pterodactylus.sonitus.data.Metadata; +import com.google.common.eventbus.EventBus; import com.google.common.io.Closeables; /** @@ -43,6 +44,9 @@ public class DummyFilter implements Filter { /** The name of this filter. */ private final String name; + /** The event bus. */ + private final EventBus eventBus; + /** The input stream from which to read. */ private InputStream inputStream; @@ -55,10 +59,13 @@ public class DummyFilter implements Filter { /** * Creates a new dummy filter with the given name. * + * @param eventBus + * The event bus * @param name * The name of the filter */ - public DummyFilter(String name) { + public DummyFilter(EventBus eventBus, String name) { + this.eventBus = eventBus; this.name = name; } 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 990f976..a6e2966 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/ExternalFilter.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/ExternalFilter.java @@ -27,6 +27,7 @@ import net.pterodactylus.sonitus.io.InputStreamDrainer; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; +import com.google.common.eventbus.EventBus; /** * {@link net.pterodactylus.sonitus.data.Filter} implementation that runs its @@ -45,11 +46,13 @@ public abstract class ExternalFilter extends DummyFilter { /** * Creates a new external filter with the given name. * + * @param eventBus + * The event bus * @param name * The name of the filter */ - protected ExternalFilter(String name) { - super(name); + protected ExternalFilter(EventBus eventBus, String name) { + super(eventBus, name); } // 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 f81d532..d97708d 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/ExternalMp3Decoder.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/ExternalMp3Decoder.java @@ -24,6 +24,8 @@ import java.io.IOException; import net.pterodactylus.sonitus.data.Metadata; +import com.google.common.eventbus.EventBus; + /** * Basic {@link net.pterodactylus.sonitus.data.filter.ExternalFilter} * implementation that verifies that the connected source is MP3-encoded and @@ -36,11 +38,13 @@ public abstract class ExternalMp3Decoder extends ExternalFilter { /** * Creates a new external MP3 decoder. * + * @param eventBus + * The event bus * @param name * The name of the filter */ - protected ExternalMp3Decoder(String name) { - super(name); + protected ExternalMp3Decoder(EventBus eventBus, String name) { + super(eventBus, name); } @Override 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 21654af..85810c9 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/ExternalMp3Encoder.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/ExternalMp3Encoder.java @@ -24,6 +24,8 @@ import java.io.IOException; import net.pterodactylus.sonitus.data.Metadata; +import com.google.common.eventbus.EventBus; + /** * Basic {@link net.pterodactylus.sonitus.data.filter.ExternalFilter} * implementation that verifies that the connected source is PCM-encoded and @@ -36,11 +38,13 @@ public abstract class ExternalMp3Encoder extends ExternalFilter { /** * Creates a new external MP3 encoder. * + * @param eventBus + * The event bus * @param name * The name of the filter */ - protected ExternalMp3Encoder(String name) { - super(name); + protected ExternalMp3Encoder(EventBus eventBus, String name) { + super(eventBus, name); } @Override 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 e8447ef..fb644d3 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/FlacDecoder.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/FlacDecoder.java @@ -20,6 +20,7 @@ package net.pterodactylus.sonitus.data.filter; import net.pterodactylus.sonitus.data.Metadata; import com.google.common.collect.ImmutableList; +import com.google.common.eventbus.EventBus; /** * Decoder {@link net.pterodactylus.sonitus.data.Filter} for FLAC files. @@ -37,11 +38,13 @@ public class FlacDecoder extends ExternalFilter { /** * Creates a new FLAC decoder. * + * @param eventBus + * The event bus * @param binary * The location of the binary */ - public FlacDecoder(String binary) { - super("FLAC Decoder"); + public FlacDecoder(EventBus eventBus, String binary) { + super(eventBus, "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 7493b3e..17e0973 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/LameMp3Decoder.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/LameMp3Decoder.java @@ -20,6 +20,7 @@ package net.pterodactylus.sonitus.data.filter; import net.pterodactylus.sonitus.data.Metadata; import com.google.common.collect.ImmutableList; +import com.google.common.eventbus.EventBus; /** * {@link ExternalMp3Decoder} implementation that uses LAME to decode an MP3. @@ -37,11 +38,13 @@ public class LameMp3Decoder extends ExternalMp3Decoder { /** * Creates a new LAME MP3 decoder. * + * @param eventBus + * The event bus * @param binary * The location of the binary */ - public LameMp3Decoder(String binary) { - super("LAME Decoder"); + public LameMp3Decoder(EventBus eventBus, String binary) { + super(eventBus, "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 d425fe2..77df8aa 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/LameMp3Encoder.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/LameMp3Encoder.java @@ -23,6 +23,7 @@ import net.pterodactylus.sonitus.data.Metadata; import com.google.common.base.Optional; import com.google.common.collect.ImmutableList; +import com.google.common.eventbus.EventBus; /** * {@link ExternalMp3Encoder} implementation that uses LAME to encode MP3s. @@ -66,30 +67,36 @@ public class LameMp3Encoder extends ExternalMp3Encoder { /** * Creates a new LAME MP3 encoder. * + * @param eventBus + * The event bus * @param binary * The location of the binary * @param preset * The preset to use */ - public LameMp3Encoder(String binary, Preset preset) { - this(binary, preset, -1); + public LameMp3Encoder(EventBus eventBus, String binary, Preset preset) { + this(eventBus, binary, preset, -1); } /** * Creates a new LAME MP3 encoder. * + * @param eventBus + * The event bus * @param binary * The location of the binary * @param bitrate * The bitrate to encode to (in kbps) */ - public LameMp3Encoder(String binary, int bitrate) { - this(binary, null, bitrate); + public LameMp3Encoder(EventBus eventBus, String binary, int bitrate) { + this(eventBus, binary, null, bitrate); } /** * Creates a new LAME MP3 encoder. * + * @param eventBus + * The event bus * @param binary * The location of the binary * @param preset @@ -97,8 +104,8 @@ public class LameMp3Encoder extends ExternalMp3Encoder { * @param bitrate * The bitrate to encode to (in kbps) */ - private LameMp3Encoder(String binary, Preset preset, int bitrate) { - super("LAME Encoder"); + private LameMp3Encoder(EventBus eventBus, String binary, Preset preset, int bitrate) { + super(eventBus, "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 b142fdd..d98abe1 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/OggVorbisDecoder.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/OggVorbisDecoder.java @@ -25,6 +25,7 @@ import java.io.IOException; import net.pterodactylus.sonitus.data.Metadata; import com.google.common.collect.ImmutableList; +import com.google.common.eventbus.EventBus; /** * Ogg Vorbis decoder that uses {@code oggdec} (from the {@code vorbis-tools} @@ -43,11 +44,13 @@ public class OggVorbisDecoder extends ExternalFilter { /** * Creates a new Ogg Vorbis decoder. * + * @param eventBus + * The event bus * @param binary * The location of the binary */ - public OggVorbisDecoder(String binary) { - super("Ogg Vorbis Decoder"); + public OggVorbisDecoder(EventBus eventBus, String binary) { + super(eventBus, "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 173073e..4edc661 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/PredicateFilter.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/PredicateFilter.java @@ -26,6 +26,7 @@ import net.pterodactylus.sonitus.data.Filter; import net.pterodactylus.sonitus.data.Metadata; import com.google.common.base.Predicate; +import com.google.common.eventbus.EventBus; /** * {@link Filter} implementation that uses a {@link Predicate} to determine @@ -47,13 +48,15 @@ public class PredicateFilter extends DummyFilter { /** * Creates a new predicate filter. * + * @param eventBus + * The event bus * @param metadataPredicate * The predicate to evaluate every time the metadata changes * @param filter * The filter to use if the predicate matches the metadata */ - public PredicateFilter(Predicate metadataPredicate, Filter filter) { - super(String.format("%s (maybe)", filter.name())); + public PredicateFilter(EventBus eventBus, Predicate metadataPredicate, Filter filter) { + super(eventBus, 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 fc89a50..d67604b 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/RateLimitingFilter.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/RateLimitingFilter.java @@ -22,6 +22,8 @@ import java.util.logging.Logger; import net.pterodactylus.sonitus.data.Metadata; +import com.google.common.eventbus.EventBus; + /** * Rate limiting filter that only passes a specified amount of data per second * from its {@link net.pterodactylus.sonitus.data.Source} to its {@link @@ -46,18 +48,22 @@ public class RateLimitingFilter extends DummyFilter { /** * Creates a new rate limiting filter. * + * @param eventBus + * The event bus * @param name * The name of the filter * @param rate * The limiting rate (in bytes/second) */ - public RateLimitingFilter(String name, int rate) { - this(name, rate, 0); + public RateLimitingFilter(EventBus eventBus, String name, int rate) { + this(eventBus, name, rate, 0); } /** * Creates a new rate limiting filter. * + * @param eventBus + * The event bus * @param name * The name of the filter * @param rate @@ -66,8 +72,8 @@ public class RateLimitingFilter extends DummyFilter { * The amount of time at the start of the filtering during which no delay * will occur (in milliseconds) */ - public RateLimitingFilter(String name, int rate, long fastStartTime) { - super(name); + public RateLimitingFilter(EventBus eventBus, String name, int rate, long fastStartTime) { + super(eventBus, 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 f562574..ecbe1cb 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/SoxResampleFilter.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/SoxResampleFilter.java @@ -25,6 +25,7 @@ import java.io.IOException; import net.pterodactylus.sonitus.data.Metadata; import com.google.common.collect.ImmutableList; +import com.google.common.eventbus.EventBus; /** * {@link net.pterodactylus.sonitus.data.Filter} implementation that uses {@code @@ -43,13 +44,15 @@ public class SoxResampleFilter extends ExternalFilter { /** * Creates a new resample filter. * + * @param eventBus + * The event bus * @param binary * The location of the binary * @param rate * The new sampling rate */ - public SoxResampleFilter(String binary, int rate) { - super(String.format("Resample to %s kHz", rate / 1000.0)); + public SoxResampleFilter(EventBus eventBus, String binary, int rate) { + super(eventBus, 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 3993e11..def3f3d 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/StereoSeparationFilter.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/StereoSeparationFilter.java @@ -24,6 +24,8 @@ import net.pterodactylus.sonitus.data.Controller; import net.pterodactylus.sonitus.data.Filter; import net.pterodactylus.sonitus.data.controller.Knob; +import com.google.common.eventbus.EventBus; + /** * {@link Filter} implementation that can reduce the stereo width of a signal, * or even reverse the channels. @@ -35,9 +37,14 @@ public class StereoSeparationFilter extends AudioProcessingFilter { /** The separation knob. */ private final Knob separationKnob; - /** Creates a new stereo separation filter. */ - public StereoSeparationFilter() { - super("Stereo Separation"); + /** + * Creates a new stereo separation filter. + * + * @param eventBus + * The event bus + */ + public StereoSeparationFilter(EventBus eventBus) { + super(eventBus, "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 a528200..1864b1c 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/filter/TimeCounterFilter.java +++ b/src/main/java/net/pterodactylus/sonitus/data/filter/TimeCounterFilter.java @@ -23,6 +23,8 @@ import java.util.concurrent.atomic.AtomicLong; import net.pterodactylus.sonitus.data.Filter; import net.pterodactylus.sonitus.data.Metadata; +import com.google.common.eventbus.EventBus; + /** * {@link Filter} implementation that uses the number of bytes that have been * {@link #process(byte[]) processed} together with the {@link Metadata} to @@ -42,24 +44,28 @@ 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 eventBus + * The event bus * @param name * The name of the filter */ - public TimeCounterFilter(String name) { - this(name, true); + public TimeCounterFilter(EventBus eventBus, String name) { + this(eventBus, name, true); } /** * Creates a new time counter filter. * + * @param eventBus + * The event bus * @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(String name, boolean resetOnMetadataUpdate) { - super(name); + public TimeCounterFilter(EventBus eventBus, String name, boolean resetOnMetadataUpdate) { + super(eventBus, 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 05253f3..a0a4c6a 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/sink/AudioSink.java +++ b/src/main/java/net/pterodactylus/sonitus/data/sink/AudioSink.java @@ -39,6 +39,7 @@ import net.pterodactylus.sonitus.data.controller.Switch; import net.pterodactylus.sonitus.io.IntegralWriteOutputStream; import com.google.common.base.Preconditions; +import com.google.common.eventbus.EventBus; /** * {@link Sink} implementation that uses the JDK’s {@link AudioSystem} to play @@ -51,6 +52,9 @@ public class AudioSink implements Sink { /** The logger. */ private static final Logger logger = Logger.getLogger(AudioSink.class.getName()); + /** The event bus. */ + private final EventBus eventBus; + /** The volume fader. */ private final Fader volumeFader; @@ -83,8 +87,14 @@ public class AudioSink implements Sink { } }, 1024); - /** Creates a new audio sink. */ - public AudioSink() { + /** + * Creates a new audio sink. + * + * @param eventBus + * The event bus + */ + public AudioSink(EventBus eventBus) { + this.eventBus = eventBus; volumeFader = new Fader("Volume") { @Override 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 92dd59a..769ac65 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/sink/FileSink.java +++ b/src/main/java/net/pterodactylus/sonitus/data/sink/FileSink.java @@ -27,6 +27,8 @@ import net.pterodactylus.sonitus.data.Controller; import net.pterodactylus.sonitus.data.Metadata; import net.pterodactylus.sonitus.data.Sink; +import com.google.common.eventbus.EventBus; + /** * {@link net.pterodactylus.sonitus.data.Sink} that writes all received data * into a file. @@ -38,6 +40,9 @@ public class FileSink implements Sink { /** The logger. */ private static final Logger logger = Logger.getLogger(FileSink.class.getName()); + /** The event bus. */ + private final EventBus eventBus; + /** The path of the file to write to. */ private final String path; @@ -49,10 +54,13 @@ public class FileSink implements Sink { /** * Creates a new file sink that will write to the given path. * + * @param eventBus + * The event bus * @param path * The path of the file to write to */ - public FileSink(String path) { + public FileSink(EventBus eventBus, String path) { + this.eventBus = eventBus; this.path = 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 5487cc4..4d492fd 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/sink/Icecast2Sink.java +++ b/src/main/java/net/pterodactylus/sonitus/data/sink/Icecast2Sink.java @@ -38,6 +38,7 @@ import com.google.common.base.Function; import com.google.common.base.Joiner; import com.google.common.base.Optional; import com.google.common.collect.FluentIterable; +import com.google.common.eventbus.EventBus; import com.google.common.io.BaseEncoding; import com.google.common.io.Closeables; @@ -52,6 +53,9 @@ public class Icecast2Sink implements Sink { /** The logger. */ private static final Logger logger = Logger.getLogger(Icecast2Sink.class.getName()); + /** The event bus. */ + private final EventBus eventBus; + /** The server name. */ private final String server; @@ -84,6 +88,8 @@ public class Icecast2Sink implements Sink { /** * Creates a new Icecast2 sink. * + * @param eventBus + * The event bus * @param server * The hostname of the server * @param port @@ -102,7 +108,8 @@ public class Icecast2Sink implements Sink { * {@code true} to publish the server in a public directory, {@code false} to * not publish it */ - public Icecast2Sink(String server, int port, String password, String mountPoint, String serverName, String serverDescription, String genre, boolean publishServer) { + public Icecast2Sink(EventBus eventBus, String server, int port, String password, String mountPoint, String serverName, String serverDescription, String genre, boolean publishServer) { + this.eventBus = eventBus; this.server = server; this.port = port; this.password = password; 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 9a624e0..a116d80 100644 --- a/src/main/java/net/pterodactylus/sonitus/data/source/StreamSource.java +++ b/src/main/java/net/pterodactylus/sonitus/data/source/StreamSource.java @@ -35,6 +35,7 @@ import net.pterodactylus.sonitus.io.MetadataStream; import com.google.common.base.Optional; import com.google.common.collect.Maps; +import com.google.common.eventbus.EventBus; import com.google.common.primitives.Ints; /** @@ -47,6 +48,9 @@ import com.google.common.primitives.Ints; */ public class StreamSource implements Source { + /** The event bus. */ + private final EventBus eventBus; + /** The URL of the stream. */ private final String streamUrl; @@ -64,12 +68,15 @@ public class StreamSource implements Source { * the response header for vital information (sampling frequency, number of * channels, etc.). * + * @param eventBus + * The event bus * @param streamUrl * The URL of the stream * @throws IOException * if an I/O error occurs */ - public StreamSource(String streamUrl) throws IOException { + public StreamSource(EventBus eventBus, String streamUrl) throws IOException { + this.eventBus = eventBus; this.streamUrl = streamUrl; URL url = new URL(streamUrl);