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.
*
/**
* 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);
}
//
import net.pterodactylus.sonitus.data.Filter;
import net.pterodactylus.sonitus.data.Metadata;
+import com.google.common.eventbus.EventBus;
import com.google.common.io.Closeables;
/**
/** 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;
/**
* 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;
}
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
/**
* 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);
}
//
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
/**
* 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
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
/**
* 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
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.
/**
* 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;
}
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.
/**
* 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;
}
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.
/**
* 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
* @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.<Integer>absent() : Optional.<Integer>of(bitrate);
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}
/**
* 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;
}
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
/**
* 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<Metadata> metadataPredicate, Filter filter) {
- super(String.format("%s (maybe)", filter.name()));
+ public PredicateFilter(EventBus eventBus, Predicate<Metadata> metadataPredicate, Filter filter) {
+ super(eventBus, String.format("%s (maybe)", filter.name()));
this.metadataPredicate = metadataPredicate;
this.filter = filter;
}
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
/**
* 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
* 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));
}
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
/**
* 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;
}
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.
/** 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);
}
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
* 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;
}
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
/** 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;
}
}, 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
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.
/** 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;
/**
* 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;
}
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;
/** 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;
/**
* Creates a new Icecast2 sink.
*
+ * @param eventBus
+ * The event bus
* @param server
* The hostname of the server
* @param port
* {@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;
import com.google.common.base.Optional;
import com.google.common.collect.Maps;
+import com.google.common.eventbus.EventBus;
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;
* 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);