diff --git a/pom.xml b/pom.xml
index 28334b0e..51eddb12 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
sh.ball
osci-render
- 1.1.0
+ 1.1.1
osci-render
diff --git a/src/main/java/sh/ball/audio/AudioPlayer.java b/src/main/java/sh/ball/audio/AudioPlayer.java
index c64802dc..c73e47bd 100644
--- a/src/main/java/sh/ball/audio/AudioPlayer.java
+++ b/src/main/java/sh/ball/audio/AudioPlayer.java
@@ -1,5 +1,6 @@
package sh.ball.audio;
+import sh.ball.audio.effect.Effect;
import xt.audio.Enums.XtSample;
import xt.audio.Enums.XtSetup;
import xt.audio.Enums.XtSystem;
@@ -17,7 +18,6 @@ import xt.audio.XtSafeBuffer;
import xt.audio.XtService;
import xt.audio.XtStream;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ArrayBlockingQueue;
@@ -224,6 +224,11 @@ public class AudioPlayer implements Renderer> {
}
}
+ @Override
+ public void flushFrames() {
+ frameQueue.clear();
+ }
+
@Override
public void addEffect(Object identifier, Effect effect) {
effects.put(identifier, effect);
diff --git a/src/main/java/sh/ball/audio/FrameProducer.java b/src/main/java/sh/ball/audio/FrameProducer.java
index 6452db0b..8e4de613 100644
--- a/src/main/java/sh/ball/audio/FrameProducer.java
+++ b/src/main/java/sh/ball/audio/FrameProducer.java
@@ -24,7 +24,8 @@ public class FrameProducer implements Runnable {
running = false;
}
- public void setFrameSettings(Object settings) {
- frames.setFrameSettings(settings);
+ public Object setFrameSettings(Object settings) {
+ renderer.flushFrames();
+ return frames.setFrameSettings(settings);
}
}
diff --git a/src/main/java/sh/ball/audio/FrameSet.java b/src/main/java/sh/ball/audio/FrameSet.java
index e8a7e893..879bae1d 100644
--- a/src/main/java/sh/ball/audio/FrameSet.java
+++ b/src/main/java/sh/ball/audio/FrameSet.java
@@ -4,5 +4,5 @@ public interface FrameSet {
T next();
- void setFrameSettings(Object settings);
+ Object setFrameSettings(Object settings);
}
diff --git a/src/main/java/sh/ball/audio/Renderer.java b/src/main/java/sh/ball/audio/Renderer.java
index 10a36a1b..eb8028a2 100644
--- a/src/main/java/sh/ball/audio/Renderer.java
+++ b/src/main/java/sh/ball/audio/Renderer.java
@@ -1,5 +1,7 @@
package sh.ball.audio;
+import sh.ball.audio.effect.Effect;
+
public interface Renderer extends Runnable {
void stop();
@@ -8,6 +10,8 @@ public interface Renderer extends Runnable {
void addFrame(T frame);
+ void flushFrames();
+
void addEffect(Object identifier, Effect effect);
void removeEffect(Object identifier);
diff --git a/src/main/java/sh/ball/audio/Effect.java b/src/main/java/sh/ball/audio/effect/Effect.java
similarity index 73%
rename from src/main/java/sh/ball/audio/Effect.java
rename to src/main/java/sh/ball/audio/effect/Effect.java
index 1785fd75..0f70c57f 100644
--- a/src/main/java/sh/ball/audio/Effect.java
+++ b/src/main/java/sh/ball/audio/effect/Effect.java
@@ -1,4 +1,4 @@
-package sh.ball.audio;
+package sh.ball.audio.effect;
import sh.ball.shapes.Vector2;
diff --git a/src/main/java/sh/ball/audio/effect/EffectType.java b/src/main/java/sh/ball/audio/effect/EffectType.java
new file mode 100644
index 00000000..7bcec4c6
--- /dev/null
+++ b/src/main/java/sh/ball/audio/effect/EffectType.java
@@ -0,0 +1,6 @@
+package sh.ball.audio.effect;
+
+public enum EffectType {
+ VECTOR_CANCELLING,
+ BIT_CRUSH
+}
diff --git a/src/main/java/sh/ball/audio/effect/EventFactory.java b/src/main/java/sh/ball/audio/effect/EventFactory.java
new file mode 100644
index 00000000..a8bdbf3c
--- /dev/null
+++ b/src/main/java/sh/ball/audio/effect/EventFactory.java
@@ -0,0 +1,26 @@
+package sh.ball.audio.effect;
+
+import sh.ball.shapes.Vector2;
+
+public class EventFactory {
+ public static Effect vectorCancelling(int frequency) {
+ return (count, v) -> count % frequency == 0 ? v.scale(-1) : v;
+ }
+
+ public static Effect bitCrush(double value) {
+ return (count, v) -> {
+ double x = v.getX();
+ double y = v.getY();
+ return new Vector2(round(x, value), round(y, value));
+ };
+ }
+
+ private static double round(double value, double places) {
+ if (places < 0) throw new IllegalArgumentException();
+
+ long factor = (long) Math.pow(10, places);
+ value = value * factor;
+ long tmp = Math.round(value);
+ return (double) tmp / factor;
+ }
+}
diff --git a/src/main/java/sh/ball/gui/Controller.java b/src/main/java/sh/ball/gui/Controller.java
index fce85917..f31b984d 100644
--- a/src/main/java/sh/ball/gui/Controller.java
+++ b/src/main/java/sh/ball/gui/Controller.java
@@ -2,13 +2,15 @@ package sh.ball.gui;
import javafx.scene.control.*;
import sh.ball.audio.AudioPlayer;
-import sh.ball.audio.Effect;
+import sh.ball.audio.effect.Effect;
import sh.ball.audio.FrameProducer;
+import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
+import java.util.EventListener;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
@@ -21,9 +23,13 @@ import javafx.fxml.Initializable;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException;
+import sh.ball.audio.effect.EffectType;
+import sh.ball.audio.effect.EventFactory;
import sh.ball.engine.Vector3;
import sh.ball.parser.obj.ObjFrameSettings;
import sh.ball.parser.obj.ObjParser;
@@ -87,6 +93,10 @@ public class Controller implements Initializable {
private CheckBox vectorCancellingCheckBox;
@FXML
private Slider vectorCancellingSlider;
+ @FXML
+ private CheckBox bitCrushCheckBox;
+ @FXML
+ private Slider bitCrushSlider;
public Controller() throws IOException {
}
@@ -111,7 +121,9 @@ public class Controller implements Initializable {
private void initializeEffectTypes() {
effectTypes = Map.of(
EffectType.VECTOR_CANCELLING,
- vectorCancellingSlider
+ vectorCancellingSlider,
+ EffectType.BIT_CRUSH,
+ bitCrushSlider
);
}
@@ -140,16 +152,25 @@ public class Controller implements Initializable {
tryParse(cameraXTextField.getText()),
tryParse(cameraYTextField.getText()),
tryParse(cameraZTextField.getText())
- )));
+ )));
+
cameraXTextField.textProperty().addListener(cameraPosUpdate);
cameraYTextField.textProperty().addListener(cameraPosUpdate);
cameraZTextField.textProperty().addListener(cameraPosUpdate);
- vectorCancellingCheckBox.selectedProperty().addListener((o, old, checked) ->
- updateEffect(EffectType.VECTOR_CANCELLING, checked,
- ((count, v) -> count % (int) vectorCancellingSlider.getValue() == 0 ? v.scale(-1) : v))
- );
+ InvalidationListener vectorCancellingListener = e ->
+ updateEffect(EffectType.VECTOR_CANCELLING, vectorCancellingCheckBox.isSelected(),
+ EventFactory.vectorCancelling((int) vectorCancellingSlider.getValue()));
+ InvalidationListener bitCrushListener = e ->
+ updateEffect(EffectType.BIT_CRUSH, bitCrushCheckBox.isSelected(),
+ EventFactory.bitCrush(bitCrushSlider.getValue()));
+
+ vectorCancellingSlider.valueProperty().addListener(vectorCancellingListener);
+ vectorCancellingCheckBox.selectedProperty().addListener(vectorCancellingListener);
+
+ bitCrushSlider.valueProperty().addListener(bitCrushListener);
+ bitCrushCheckBox.selectedProperty().addListener(bitCrushListener);
chooseFileButton.setOnAction(e -> {
File file = fileChooser.showOpenDialog(stage);
@@ -163,7 +184,10 @@ public class Controller implements Initializable {
}
private void setFocalLength(double focalLength) {
- producer.setFrameSettings(new ObjFrameSettings(focalLength));
+ Vector3 pos = (Vector3) producer.setFrameSettings(new ObjFrameSettings(focalLength));
+ cameraXTextField.setText(String.valueOf(pos.getX()));
+ cameraYTextField.setText(String.valueOf(pos.getY()));
+ cameraZTextField.setText(String.valueOf(pos.getZ()));
}
private double tryParse(String value) {
diff --git a/src/main/java/sh/ball/gui/EffectType.java b/src/main/java/sh/ball/gui/EffectType.java
deleted file mode 100644
index c13ffab2..00000000
--- a/src/main/java/sh/ball/gui/EffectType.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package sh.ball.gui;
-
-enum EffectType {
- VECTOR_CANCELLING
-}
diff --git a/src/main/java/sh/ball/parser/obj/ObjFrameSet.java b/src/main/java/sh/ball/parser/obj/ObjFrameSet.java
index 92162989..278d7094 100644
--- a/src/main/java/sh/ball/parser/obj/ObjFrameSet.java
+++ b/src/main/java/sh/ball/parser/obj/ObjFrameSet.java
@@ -29,7 +29,7 @@ public class ObjFrameSet implements FrameSet> {
}
@Override
- public void setFrameSettings(Object settings) {
+ public Object setFrameSettings(Object settings) {
if (settings instanceof ObjFrameSettings obj) {
Double focalLength = obj.focalLength();
Vector3 cameraPos = obj.cameraPos();
@@ -44,5 +44,7 @@ public class ObjFrameSet implements FrameSet> {
camera.setPos(cameraPos);
}
}
+
+ return camera.getPos();
}
}
diff --git a/src/main/java/sh/ball/shapes/Shape.java b/src/main/java/sh/ball/shapes/Shape.java
index de39a5c3..1e21a90b 100644
--- a/src/main/java/sh/ball/shapes/Shape.java
+++ b/src/main/java/sh/ball/shapes/Shape.java
@@ -40,7 +40,9 @@ public abstract class Shape implements FrameSet> {
}
@Override
- public void setFrameSettings(Object settings) {}
+ public Object setFrameSettings(Object settings) {
+ return null;
+ }
/* SHAPE HELPER FUNCTIONS */
diff --git a/src/main/java/sh/ball/shapes/ShapeFrameSet.java b/src/main/java/sh/ball/shapes/ShapeFrameSet.java
index 19810d5f..b93be234 100644
--- a/src/main/java/sh/ball/shapes/ShapeFrameSet.java
+++ b/src/main/java/sh/ball/shapes/ShapeFrameSet.java
@@ -18,6 +18,7 @@ public class ShapeFrameSet implements FrameSet> {
}
@Override
- public void setFrameSettings(Object settings) {
+ public Object setFrameSettings(Object settings) {
+ return null;
}
}
diff --git a/src/main/resources/fxml/osci-render.fxml b/src/main/resources/fxml/osci-render.fxml
index 3bf1c5a5..5026a232 100644
--- a/src/main/resources/fxml/osci-render.fxml
+++ b/src/main/resources/fxml/osci-render.fxml
@@ -25,13 +25,13 @@
-
+
-
+
-
+
@@ -39,7 +39,7 @@
-
+
@@ -47,6 +47,8 @@
+
+
@@ -56,13 +58,13 @@
-
+
-
-
-
-
+
+
+
+