Move EffectComponentGroups to subcontrollers and move updateEffect to audio player

pull/112/head
James Ball 2022-08-18 19:28:20 +01:00 zatwierdzone przez James H Ball
rodzic 0fd3e9f997
commit ddafc8ef8c
9 zmienionych plików z 71 dodań i 69 usunięć

Wyświetl plik

@ -20,6 +20,7 @@ import javax.sound.midi.ShortMessage;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import static sh.ball.gui.Gui.audioPlayer;
import static sh.ball.gui.Gui.logger;
public class ShapeAudioPlayer implements AudioPlayer<List<Shape>> {
@ -418,6 +419,17 @@ public class ShapeAudioPlayer implements AudioPlayer<List<Shape>> {
effects.removeIf(e -> e.type == type);
}
// selects or deselects the given audio effect
public void updateEffect(EffectType type, boolean checked, SettableEffect effect) {
if (type != null) {
if (checked) {
audioPlayer.addEffect(type, effect);
} else {
audioPlayer.removeEffect(type);
}
}
}
@Override
public void read(byte[] buffer) throws InterruptedException {
Listener listener = new Listener(buffer);

Wyświetl plik

@ -163,6 +163,11 @@ public class EffectComponentGroupController implements Initializable, SubControl
return List.of(model.getLabel());
}
@Override
public List<EffectComponentGroup> effects() {
return List.of(model);
}
@Override
public List<Element> save(Document document) {
Element checkBox = document.createElement(model.getLabel());

Wyświetl plik

@ -124,13 +124,7 @@ public class EffectsController implements Initializable, SubController {
// selects or deselects the given audio effect
public void updateEffect(EffectType type, boolean checked, SettableEffect effect) {
if (type != null) {
if (checked) {
audioPlayer.addEffect(type, effect);
} else {
audioPlayer.removeEffect(type);
}
}
audioPlayer.updateEffect(type, checked, effect);
if (type == EffectType.DEPTH_3D) {
Platform.runLater(() ->
@ -242,7 +236,8 @@ public class EffectsController implements Initializable, SubController {
executor.setScript(script);
}
private List<EffectComponentGroup> effects() {
@Override
public List<EffectComponentGroup> effects() {
return List.of(
vectorCancelling,
bitCrush,
@ -281,8 +276,6 @@ public class EffectsController implements Initializable, SubController {
@Override
public List<Element> save(Document document) {
Element element = document.createElement("checkBoxes");
effects().forEach(effect -> effect.save(document).forEach(element::appendChild));
Element translation = document.createElement("translation");
Element x = document.createElement("x");
x.appendChild(document.createTextNode(translationXTextField.getText()));
@ -296,13 +289,11 @@ public class EffectsController implements Initializable, SubController {
translation.appendChild(x);
translation.appendChild(y);
translation.appendChild(ellipse);
return List.of(element, translation, depthFunction);
return List.of(translation, depthFunction);
}
@Override
public void load(Element root) {
Element element = (Element) root.getElementsByTagName("checkBoxes").item(0);
effects().forEach(effect -> effect.load(element));
Element translation = (Element) root.getElementsByTagName("translation").item(0);
Element x = (Element) translation.getElementsByTagName("x").item(0);
Element y = (Element) translation.getElementsByTagName("y").item(0);

Wyświetl plik

@ -16,6 +16,7 @@ import javafx.stage.Stage;
import javafx.util.Duration;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import sh.ball.gui.components.EffectComponentGroup;
import java.io.File;
import java.io.IOException;
@ -292,6 +293,11 @@ public class GeneralController implements Initializable, SubController {
return List.of("octave", "micVolume");
}
@Override
public List<EffectComponentGroup> effects() {
return List.of();
}
@Override
public List<Element> save(Document document) {
Element element = document.createElement("general");

Wyświetl plik

@ -8,6 +8,7 @@ import javafx.scene.shape.SVGPath;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import sh.ball.audio.midi.MidiNote;
import sh.ball.gui.components.EffectComponentGroup;
import java.net.URL;
import java.util.List;
@ -72,6 +73,11 @@ public class ImageController implements Initializable, SubController {
return List.of("frequency");
}
@Override
public List<EffectComponentGroup> effects() {
return List.of();
}
@Override
public List<Element> save(Document document) {
return List.of(document.createElement("null"));

Wyświetl plik

@ -37,7 +37,8 @@ public class LuaController implements Initializable, SubController {
this.mainController = mainController;
}
private List<EffectComponentGroup> effects() {
@Override
public List<EffectComponentGroup> effects() {
return List.of(luaA, luaB, luaC, luaD, luaE);
}
@ -54,7 +55,7 @@ public class LuaController implements Initializable, SubController {
effect.setAnimator(new EffectAnimator(EffectAnimator.DEFAULT_SAMPLE_RATE, new ConsumerEffect(value -> updateLuaVariable(effect.getId(), value))))
);
effects().forEach(effect -> effect.setEffectUpdater(this::updateEffect));
effects().forEach(effect -> effect.setEffectUpdater(audioPlayer::updateEffect));
resetStepCounterButton.setOnAction(e -> mainController.resetLuaStep());
}
@ -86,34 +87,14 @@ public class LuaController implements Initializable, SubController {
@Override
public List<Element> save(Document document) {
Element element = document.createElement("luaController");
effects().forEach(effect -> effect.save(document).forEach(element::appendChild));
return List.of(element);
return List.of(document.createElement("null"));
}
@Override
public void load(Element root) {
Element element = (Element) root.getElementsByTagName("luaController").item(0);
if (element != null) {
effects().forEach(effect -> effect.load(element));
} else {
effects().forEach(effect -> effect.setAnimationType(AnimationType.STATIC));
}
}
public void load(Element root) {}
@Override
public void micNotAvailable() {
effects().forEach(EffectComponentGroup::micNotAvailable);
}
// selects or deselects the given audio effect
public void updateEffect(EffectType type, boolean checked, SettableEffect effect) {
if (type != null) {
if (checked) {
audioPlayer.addEffect(type, effect);
} else {
audioPlayer.removeEffect(type);
}
}
}
}

Wyświetl plik

@ -48,12 +48,14 @@ import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import sh.ball.audio.effect.AnimationType;
import sh.ball.audio.engine.*;
import sh.ball.audio.midi.MidiListener;
import sh.ball.audio.midi.MidiNote;
import sh.ball.engine.ObjectServer;
import sh.ball.engine.ObjectSet;
import sh.ball.gui.Gui;
import sh.ball.gui.components.EffectComponentGroup;
import sh.ball.oscilloscope.ByteWebSocketServer;
import sh.ball.parser.FileParser;
import sh.ball.parser.lua.LuaParser;
@ -1017,6 +1019,11 @@ public class MainController implements Initializable, FrequencyListener, MidiLis
sliders.add(brightnessSlider);
return sliders;
}
private List<EffectComponentGroup> effects() {
return subControllers().stream().map(SubController::effects).flatMap(Collection::stream).toList();
}
private List<String> labels() {
List<String> labels = new ArrayList<>();
subControllers().forEach(controller -> labels.addAll(controller.labels()));
@ -1131,6 +1138,9 @@ public class MainController implements Initializable, FrequencyListener, MidiLis
subControllers().forEach(controller -> controller.save(document).forEach(root::appendChild));
Element element = document.createElement("checkBoxes");
effects().forEach(effect -> effect.save(document).forEach(element::appendChild));
Element flipX = document.createElement("flipX");
Element flipY = document.createElement("flipY");
flipX.appendChild(document.createTextNode(String.valueOf(flipXCheckMenuItem.isSelected())));
@ -1267,6 +1277,13 @@ public class MainController implements Initializable, FrequencyListener, MidiLis
subControllers().forEach(controller -> controller.load(root));
Element element = (Element) root.getElementsByTagName("checkBoxes").item(0);
if (element != null) {
effects().forEach(effect -> effect.load(element));
} else {
effects().forEach(effect -> effect.setAnimationType(AnimationType.STATIC));
}
Element flipX = (Element) root.getElementsByTagName("flipX").item(0);
Element flipY = (Element) root.getElementsByTagName("flipY").item(0);
if (flipX != null) {

Wyświetl plik

@ -44,14 +44,10 @@ public class ObjController implements Initializable, SubController {
@FXML
private Button resetObjectRotationButton;
private List<EffectComponentGroup> effectComponentGroups() {
return List.of(focalLength, rotateX, rotateY, rotateZ, rotateSpeed);
}
@Override
public Map<SVGPath, Slider> getMidiButtonMap() {
Map<SVGPath, Slider> map = new HashMap<>();
effectComponentGroups().forEach(ecg -> map.putAll(ecg.getMidiButtonMap()));
effects().forEach(effect -> map.putAll(effect.getMidiButtonMap()));
return map;
}
@ -151,55 +147,40 @@ public class ObjController implements Initializable, SubController {
rotateZ.setAnimator(new EffectAnimator(DEFAULT_SAMPLE_RATE, new ConsumerEffect(this::setObjRotateZ)));
rotateSpeed.setAnimator(new EffectAnimator(DEFAULT_SAMPLE_RATE, new ConsumerEffect(this::setObjectRotateSpeed)));
effectComponentGroups().forEach(effect -> effect.setEffectUpdater(this::updateEffect));
}
// selects or deselects the given audio effect
public void updateEffect(EffectType type, boolean checked, SettableEffect effect) {
if (type != null) {
if (checked) {
audioPlayer.addEffect(type, effect);
} else {
audioPlayer.removeEffect(type);
}
}
effects().forEach(effect -> effect.setEffectUpdater(audioPlayer::updateEffect));
}
@Override
public List<BooleanProperty> micSelected() {
return effectComponentGroups().stream().map(EffectComponentGroup::isMicSelectedProperty).toList();
return effects().stream().map(EffectComponentGroup::isMicSelectedProperty).toList();
}
@Override
public List<Slider> sliders() {
return effectComponentGroups().stream().map(EffectComponentGroup::sliders).flatMap(List::stream).toList();
return effects().stream().map(EffectComponentGroup::sliders).flatMap(List::stream).toList();
}
@Override
public List<String> labels() {
return effectComponentGroups().stream().map(EffectComponentGroup::getLabel).toList();
return effects().stream().map(EffectComponentGroup::getLabel).toList();
}
@Override
public List<EffectComponentGroup> effects() {
return List.of(focalLength, rotateX, rotateY, rotateZ, rotateSpeed);
}
@Override
public List<Element> save(Document document) {
Element element = document.createElement("objController");
effectComponentGroups().forEach(effect -> effect.save(document).forEach(element::appendChild));
return List.of(element);
return List.of(document.createElement("null"));
}
@Override
public void load(Element root) {
Element element = (Element) root.getElementsByTagName("objController").item(0);
if (element != null) {
effectComponentGroups().forEach(effect -> effect.load(element));
} else {
effectComponentGroups().forEach(effect -> effect.setAnimationType(AnimationType.STATIC));
}
}
public void load(Element root) {}
@Override
public void micNotAvailable() {
effectComponentGroups().forEach(EffectComponentGroup::micNotAvailable);
effects().forEach(EffectComponentGroup::micNotAvailable);
}
public void renderUsingGpu(boolean usingGpu) {

Wyświetl plik

@ -6,6 +6,7 @@ import javafx.scene.shape.SVGPath;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import sh.ball.gui.components.EffectComponentGroup;
import java.util.List;
import java.util.Map;
@ -20,6 +21,8 @@ public interface SubController {
List<String> labels();
List<EffectComponentGroup> effects();
List<? extends Node> save(Document document);
void load(Element root);