kopia lustrzana https://github.com/jameshball/osci-render
Remove Listener interface
rodzic
13fc416380
commit
09e95c9c13
|
@ -1,12 +1,8 @@
|
|||
package sh.ball.audio;
|
||||
|
||||
import sh.ball.parser.obj.Listener;
|
||||
|
||||
public interface FrameSet<T> {
|
||||
|
||||
T next();
|
||||
|
||||
void setFrameSettings(Object settings);
|
||||
|
||||
void addListener(Listener listener);
|
||||
}
|
||||
|
|
|
@ -44,14 +44,13 @@ import sh.ball.audio.engine.ConglomerateAudioEngine;
|
|||
import sh.ball.audio.midi.MidiCommunicator;
|
||||
import sh.ball.audio.midi.MidiListener;
|
||||
import sh.ball.engine.Vector3;
|
||||
import sh.ball.parser.obj.Listener;
|
||||
import sh.ball.parser.obj.ObjSettingsFactory;
|
||||
import sh.ball.parser.obj.ObjParser;
|
||||
import sh.ball.parser.ParserFactory;
|
||||
import sh.ball.shapes.Shape;
|
||||
import sh.ball.shapes.Vector2;
|
||||
|
||||
public class Controller implements Initializable, FrequencyListener, Listener, MidiListener {
|
||||
public class Controller implements Initializable, FrequencyListener, MidiListener {
|
||||
|
||||
private static final InputStream DEFAULT_OBJ = Controller.class.getResourceAsStream("/models/cube.obj");
|
||||
private static final double MAX_FREQUENCY = 12000;
|
||||
|
@ -195,7 +194,6 @@ public class Controller implements Initializable, FrequencyListener, Listener, M
|
|||
frameSets.add(frames);
|
||||
frameSetPaths.add("cube.obj");
|
||||
currentFrameSet = 0;
|
||||
frames.addListener(this);
|
||||
this.producer = new FrameProducer<>(audioPlayer, frames);
|
||||
this.defaultDevice = audioPlayer.getDefaultDevice();
|
||||
if (defaultDevice == null) {
|
||||
|
@ -502,11 +500,17 @@ public class Controller implements Initializable, FrequencyListener, Listener, M
|
|||
}
|
||||
|
||||
private void updateCameraPos() {
|
||||
producer.setFrameSettings(ObjSettingsFactory.cameraPosition(new Vector3(
|
||||
Vector3 vector = new Vector3(
|
||||
tryParse(cameraXTextField.getText()),
|
||||
tryParse(cameraYTextField.getText()),
|
||||
tryParse(cameraZTextField.getText())
|
||||
)));
|
||||
);
|
||||
|
||||
producer.setFrameSettings(ObjSettingsFactory.cameraPosition(vector));
|
||||
|
||||
cameraXTextField.setText(String.valueOf(round(vector.getX(), 3)));
|
||||
cameraYTextField.setText(String.valueOf(round(vector.getY(), 3)));
|
||||
cameraZTextField.setText(String.valueOf(round(vector.getZ(), 3)));
|
||||
}
|
||||
|
||||
private double tryParse(String value) {
|
||||
|
@ -530,7 +534,6 @@ public class Controller implements Initializable, FrequencyListener, Listener, M
|
|||
private void changeFrameSet() {
|
||||
FrameSet<List<Shape>> frames = frameSets.get(currentFrameSet);
|
||||
producer.stop();
|
||||
frames.addListener(this);
|
||||
producer = new FrameProducer<>(audioPlayer, frames);
|
||||
|
||||
updateObjectRotateSpeed();
|
||||
|
@ -623,17 +626,6 @@ public class Controller implements Initializable, FrequencyListener, Listener, M
|
|||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Object pos) {
|
||||
if (pos instanceof Vector3 vector) {
|
||||
Platform.runLater(() -> {
|
||||
cameraXTextField.setText(String.valueOf(round(vector.getX(), 3)));
|
||||
cameraYTextField.setText(String.valueOf(round(vector.getY(), 3)));
|
||||
cameraZTextField.setText(String.valueOf(round(vector.getZ(), 3)));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static double round(double value, double places) {
|
||||
if (places < 0) throw new IllegalArgumentException();
|
||||
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
package sh.ball.parser.obj;
|
||||
|
||||
public interface Listener {
|
||||
|
||||
void update(Object obj);
|
||||
}
|
|
@ -13,7 +13,6 @@ public class ObjFrameSet implements FrameSet<List<Shape>> {
|
|||
|
||||
private final WorldObject object;
|
||||
private final Camera camera;
|
||||
private final List<Listener> listeners = new ArrayList<>();
|
||||
|
||||
private Vector3 rotation = new Vector3();
|
||||
private Double rotateSpeed = 0.0;
|
||||
|
@ -23,20 +22,6 @@ public class ObjFrameSet implements FrameSet<List<Shape>> {
|
|||
this.camera = camera;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListener(Listener listener) {
|
||||
listeners.add(listener);
|
||||
notifyListener(listener);
|
||||
}
|
||||
|
||||
private void notifyListener(Listener listener) {
|
||||
listener.update(camera.getPos());
|
||||
}
|
||||
|
||||
private void notifyListeners() {
|
||||
listeners.forEach(this::notifyListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Shape> next() {
|
||||
if (rotateSpeed == 0) {
|
||||
|
@ -56,7 +41,6 @@ public class ObjFrameSet implements FrameSet<List<Shape>> {
|
|||
}
|
||||
if (obj.cameraPos != null && camera.getPos() != obj.cameraPos) {
|
||||
camera.setPos(obj.cameraPos);
|
||||
notifyListeners();
|
||||
}
|
||||
if (obj.rotation != null) {
|
||||
this.rotation = obj.rotation;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package sh.ball.shapes;
|
||||
|
||||
import sh.ball.audio.FrameSet;
|
||||
import sh.ball.parser.obj.Listener;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -20,7 +19,4 @@ public class ShapeFrameSet implements FrameSet<List<Shape>> {
|
|||
|
||||
@Override
|
||||
public void setFrameSettings(Object settings) {}
|
||||
|
||||
@Override
|
||||
public void addListener(Listener listener) { }
|
||||
}
|
||||
|
|
|
@ -42,11 +42,11 @@
|
|||
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="359.0">
|
||||
<Slider fx:id="focalLengthSlider" blockIncrement="0.01" layoutX="116.0" layoutY="22.0" majorTickUnit="0.2" max="2.0" min="1.0E-5" prefHeight="42.0" prefWidth="258.0" showTickLabels="true" showTickMarks="true" value="1.0" />
|
||||
<Label layoutX="34.0" layoutY="21.0" text="Focal length" />
|
||||
<TextField fx:id="cameraXTextField" layoutX="134.0" layoutY="74.0" prefHeight="26.0" prefWidth="65.0" text="0" />
|
||||
<TextField fx:id="cameraXTextField" layoutX="134.0" layoutY="74.0" prefHeight="26.0" prefWidth="65.0" text="0.0" />
|
||||
<Label layoutX="35.0" layoutY="78.0" text="Camera pos" />
|
||||
<Label layoutX="118.0" layoutY="78.0" text="x :" />
|
||||
<Label layoutX="207.0" layoutY="77.0" text="y :" />
|
||||
<TextField fx:id="cameraYTextField" layoutX="224.0" layoutY="74.0" prefHeight="26.0" prefWidth="65.0" text="0" />
|
||||
<TextField fx:id="cameraYTextField" layoutX="224.0" layoutY="74.0" prefHeight="26.0" prefWidth="65.0" text="0.0" />
|
||||
<Label layoutX="299.0" layoutY="77.0" text="z :" />
|
||||
<TextField fx:id="cameraZTextField" layoutX="315.0" layoutY="74.0" prefHeight="26.0" prefWidth="65.0" text="-2.5" />
|
||||
<Slider fx:id="objectRotateSpeedSlider" blockIncrement="0.005" layoutX="116.0" layoutY="121.0" majorTickUnit="0.1" max="1.0" prefHeight="42.0" prefWidth="258.0" showTickLabels="true" showTickMarks="true" />
|
||||
|
@ -98,11 +98,11 @@
|
|||
<Font size="13.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<TextField fx:id="translationXTextField" layoutX="138.0" layoutY="15.0" prefHeight="26.0" prefWidth="70.0" text="0" />
|
||||
<TextField fx:id="translationXTextField" layoutX="138.0" layoutY="15.0" prefHeight="26.0" prefWidth="70.0" text="0.0" />
|
||||
<Label layoutX="47.0" layoutY="18.0" text="Translation" />
|
||||
<Label layoutX="120.0" layoutY="18.0" text="x :" />
|
||||
<Label layoutX="219.0" layoutY="18.0" text="y :" />
|
||||
<TextField fx:id="translationYTextField" layoutX="238.0" layoutY="15.0" prefHeight="26.0" prefWidth="70.0" text="0" />
|
||||
<TextField fx:id="translationYTextField" layoutX="238.0" layoutY="15.0" prefHeight="26.0" prefWidth="70.0" text="0.0" />
|
||||
<Slider fx:id="frequencySlider" blockIncrement="0.001" layoutX="116.0" layoutY="45.0" majorTickUnit="0.07389" max="1.0" minorTickCount="2" prefHeight="42.0" prefWidth="253.0" showTickMarks="true" value="0.59269" />
|
||||
<SVGPath fx:id="frequencyMidi" content="M20.15 8.26H22V15.74H20.15M13 8.26H18.43C19 8.26 19.3 8.74 19.3 9.3V14.81C19.3 15.5 19 15.74 18.38 15.74H13V11H14.87V13.91H17.5V9.95H13M10.32 8.26H12.14V15.74H10.32M2 8.26H8.55C9.1 8.26 9.41 8.74 9.41 9.3V15.74H7.59V10.15H6.5V15.74H4.87V10.15H3.83V15.74H2Z" fill="WHITE" layoutX="371.0" layoutY="49.0" pickOnBounds="true" />
|
||||
<SVGPath fx:id="rotateSpeedMidi" content="M20.15 8.26H22V15.74H20.15M13 8.26H18.43C19 8.26 19.3 8.74 19.3 9.3V14.81C19.3 15.5 19 15.74 18.38 15.74H13V11H14.87V13.91H17.5V9.95H13M10.32 8.26H12.14V15.74H10.32M2 8.26H8.55C9.1 8.26 9.41 8.74 9.41 9.3V15.74H7.59V10.15H6.5V15.74H4.87V10.15H3.83V15.74H2Z" fill="WHITE" layoutX="371.0" layoutY="87.0" pickOnBounds="true" />
|
||||
|
|
Ładowanie…
Reference in New Issue