Skip to content
Snippets Groups Projects
Commit a4da4b9b authored by Tobias Ullerich's avatar Tobias Ullerich
Browse files

Start working on play speed (#139)

parent 50faea9e
Branches
Tags
No related merge requests found
......@@ -6,10 +6,7 @@ import de.tobias.playpad.audio.AudioHandler;
import de.tobias.playpad.audio.AudioRegistry;
import de.tobias.playpad.pad.Pad;
import de.tobias.playpad.pad.PadStatus;
import de.tobias.playpad.pad.content.play.Durationable;
import de.tobias.playpad.pad.content.play.Equalizeable;
import de.tobias.playpad.pad.content.play.Pauseable;
import de.tobias.playpad.pad.content.play.Seekable;
import de.tobias.playpad.pad.content.play.*;
import de.tobias.playpad.pad.fade.Fade;
import de.tobias.playpad.pad.fade.FadeDelegate;
import de.tobias.playpad.pad.fade.Fadeable;
......@@ -26,7 +23,8 @@ import javafx.util.Duration;
import java.nio.file.Files;
import java.nio.file.Path;
public class AudioContent extends PadContent implements Pauseable, Durationable, Fadeable, Equalizeable, FadeDelegate, Seekable {
public class AudioContent extends PadContent implements Pauseable, Durationable, Fadeable,
Equalizeable, FadeDelegate, Seekable, SpeedAdjustable {
private final String type;
......@@ -36,6 +34,7 @@ public class AudioContent extends PadContent implements Pauseable, Durationable,
private ObjectProperty<Duration> positionProperty = new SimpleObjectProperty<>();
private ChangeListener<Number> volumeListener;
private ChangeListener<Number> rateListener;
private Fade fade;
......@@ -45,7 +44,8 @@ public class AudioContent extends PadContent implements Pauseable, Durationable,
fade = new Fade(this);
// Pad Volume Listener
volumeListener = (a, b, c) -> updateVolume();
volumeListener = (a, oldValue, newValue) -> updateVolume();
rateListener = (a, oldValue, newValue) -> setCurrentRate(newValue.doubleValue());
}
@Override
......@@ -83,6 +83,21 @@ public class AudioContent extends PadContent implements Pauseable, Durationable,
}
}
@Override
public double currentRate() {
if (audioHandler instanceof SpeedAdjustable) {
return ((SpeedAdjustable) audioHandler).currentRate();
}
return -1;
}
@Override
public void setCurrentRate(double rate) {
if (audioHandler instanceof SpeedAdjustable) {
((SpeedAdjustable) audioHandler).setCurrentRate(rate);
}
}
@Override
public void fadeIn() {
Pad pad = getPad();
......@@ -171,6 +186,7 @@ public class AudioContent extends PadContent implements Pauseable, Durationable,
positionProperty.bind(audioHandler.positionProperty());
getPad().getPadSettings().volumeProperty().addListener(volumeListener);
getPad().getPadSettings().speedProperty().addListener(rateListener);
updateVolume();
} else {
......@@ -194,6 +210,7 @@ public class AudioContent extends PadContent implements Pauseable, Durationable,
positionProperty.unbind();
getPad().getPadSettings().volumeProperty().removeListener(volumeListener);
getPad().getPadSettings().speedProperty().removeListener(rateListener);
if (audioHandler != null)
audioHandler.unloadMedia();
......
......@@ -3,6 +3,7 @@ package de.tobias.playpad.audio;
import de.tobias.playpad.pad.PadStatus;
import de.tobias.playpad.pad.content.PadContent;
import de.tobias.playpad.pad.content.play.Seekable;
import de.tobias.playpad.pad.content.play.SpeedAdjustable;
import javafx.application.Platform;
import javafx.beans.property.*;
import javafx.scene.media.AudioEqualizer;
......@@ -12,7 +13,7 @@ import javafx.util.Duration;
import java.nio.file.Path;
public class JavaFXAudioHandler extends AudioHandler implements AudioEqualizeable, Seekable {
public class JavaFXAudioHandler extends AudioHandler implements AudioEqualizeable, Seekable, SpeedAdjustable {
private Media media;
private MediaPlayer player;
......@@ -83,6 +84,16 @@ public class JavaFXAudioHandler extends AudioHandler implements AudioEqualizeabl
}
}
@Override
public double currentRate() {
return player.getCurrentRate();
}
@Override
public void setCurrentRate(double rate) {
player.setRate(rate);
}
@Override
public boolean isMediaLoaded() {
return player != null;
......
......@@ -29,6 +29,7 @@ import javafx.collections.ObservableList;
import org.dom4j.Element;
import java.nio.file.Path;
import java.util.Objects;
import java.util.UUID;
/**
......@@ -601,7 +602,7 @@ public class Pad implements Cloneable {
Pad pad = (Pad) o;
return uuid != null ? uuid.equals(pad.uuid) : pad.uuid == null;
return Objects.equals(uuid, pad.uuid);
}
// Clone
......
......@@ -25,6 +25,7 @@ public class PadSettings implements Cloneable {
// Settings
private DoubleProperty volumeProperty = new SimpleDoubleProperty(1.0);
private DoubleProperty speedProperty = new SimpleDoubleProperty(1.0);
private BooleanProperty loopProperty = new SimpleBooleanProperty(false);
private ObjectProperty<TimeMode> timeModeProperty = new SimpleObjectProperty<>();
private ObjectProperty<Fade> fadeProperty = new SimpleObjectProperty<>();
......@@ -34,7 +35,6 @@ public class PadSettings implements Cloneable {
private ModernCartDesign design;
private HashMap<TriggerPoint, Trigger> triggers = new HashMap<>();
private HashMap<String, Object> customSettings = new HashMap<>();
// Sync Listener
......@@ -72,6 +72,19 @@ public class PadSettings implements Cloneable {
return volumeProperty;
}
public double getSpeed() {
return speedProperty.get();
}
public void setSpeed(double rate) {
this.speedProperty.set(rate);
}
public DoubleProperty speedProperty() {
return speedProperty;
}
public boolean isLoop() {
return loopProperty.get();
}
......
package de.tobias.playpad.pad.content.play;
public interface SpeedAdjustable {
double currentRate();
void setCurrentRate(double rate);
}
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment