kopia lustrzana https://github.com/jameshball/osci-render
Let animator range to be set
rodzic
0f72b18ae3
commit
30b7442be1
|
@ -9,13 +9,21 @@ public class EffectAnimator extends PhaseEffect implements SettableEffect {
|
||||||
private final SettableEffect effect;
|
private final SettableEffect effect;
|
||||||
|
|
||||||
private AnimationType type = AnimationType.STATIC;
|
private AnimationType type = AnimationType.STATIC;
|
||||||
private double value = 0.5;
|
private double targetValue = 0.5;
|
||||||
private double actualValue = 0.5;
|
private double actualValue = 0.5;
|
||||||
private boolean linearDirection = true;
|
private boolean linearDirection = true;
|
||||||
|
private double min;
|
||||||
|
private double max;
|
||||||
|
|
||||||
public EffectAnimator(int sampleRate, SettableEffect effect) {
|
public EffectAnimator(int sampleRate, SettableEffect effect, double min, double max) {
|
||||||
super(sampleRate, 1.0);
|
super(sampleRate, 1.0);
|
||||||
this.effect = effect;
|
this.effect = effect;
|
||||||
|
this.min = min;
|
||||||
|
this.max = max;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EffectAnimator(int sampleRate, SettableEffect effect) {
|
||||||
|
this(sampleRate, effect, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAnimation(AnimationType type) {
|
public void setAnimation(AnimationType type) {
|
||||||
|
@ -23,14 +31,30 @@ public class EffectAnimator extends PhaseEffect implements SettableEffect {
|
||||||
this.linearDirection = true;
|
this.linearDirection = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setMin(double min) {
|
||||||
|
this.min = min;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMax(double max) {
|
||||||
|
this.max = max;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Vector2 apply(int count, Vector2 vector) {
|
public Vector2 apply(int count, Vector2 vector) {
|
||||||
|
double minValue = min;
|
||||||
|
double maxValue = max;
|
||||||
|
double range = maxValue - minValue;
|
||||||
|
if (range <= 0) {
|
||||||
|
return vector;
|
||||||
|
}
|
||||||
|
double normalisedTargetValue = (targetValue - minValue) / range;
|
||||||
|
double normalisedActualValue = (actualValue - minValue) / range;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case STATIC -> actualValue = value;
|
case STATIC -> actualValue = targetValue;
|
||||||
case SEESAW -> {
|
case SEESAW -> {
|
||||||
double scalar = 10 * Math.max(Math.min(actualValue, 1 - actualValue), 0.01);
|
double scalar = 10 * Math.max(Math.min(normalisedActualValue, 1 - normalisedActualValue), 0.01);
|
||||||
double change = scalar * SPEED_SCALE * value / sampleRate;
|
double change = range * scalar * SPEED_SCALE * normalisedTargetValue / sampleRate;
|
||||||
if (actualValue + change > 1 || actualValue - change < 0) {
|
if (actualValue + change > maxValue || actualValue - change < minValue) {
|
||||||
linearDirection = !linearDirection;
|
linearDirection = !linearDirection;
|
||||||
}
|
}
|
||||||
if (linearDirection) {
|
if (linearDirection) {
|
||||||
|
@ -40,8 +64,8 @@ public class EffectAnimator extends PhaseEffect implements SettableEffect {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case LINEAR -> {
|
case LINEAR -> {
|
||||||
double change = SPEED_SCALE * value / sampleRate;
|
double change = range * SPEED_SCALE * normalisedTargetValue / sampleRate;
|
||||||
if (actualValue + change > 1 || actualValue - change < 0) {
|
if (actualValue + change > maxValue || actualValue - change < minValue) {
|
||||||
linearDirection = !linearDirection;
|
linearDirection = !linearDirection;
|
||||||
}
|
}
|
||||||
if (linearDirection) {
|
if (linearDirection) {
|
||||||
|
@ -51,15 +75,15 @@ public class EffectAnimator extends PhaseEffect implements SettableEffect {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case FORWARD -> {
|
case FORWARD -> {
|
||||||
actualValue += 0.5 * SPEED_SCALE * value / sampleRate;
|
actualValue += range * 0.5 * SPEED_SCALE * normalisedTargetValue / sampleRate;
|
||||||
if (actualValue > 1) {
|
if (actualValue > maxValue) {
|
||||||
actualValue = 0;
|
actualValue = minValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case REVERSE -> {
|
case REVERSE -> {
|
||||||
actualValue -= 0.5 * SPEED_SCALE * value / sampleRate;
|
actualValue -= range * 0.5 * SPEED_SCALE * normalisedTargetValue / sampleRate;
|
||||||
if (actualValue < 0) {
|
if (actualValue < minValue) {
|
||||||
actualValue = 1;
|
actualValue = maxValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,7 +93,7 @@ public class EffectAnimator extends PhaseEffect implements SettableEffect {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setValue(double value) {
|
public void setValue(double value) {
|
||||||
this.value = value;
|
this.targetValue = value;
|
||||||
effect.setValue(value);
|
effect.setValue(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ public class EffectsController implements Initializable, SubController {
|
||||||
private final EffectAnimator traceAnimator;
|
private final EffectAnimator traceAnimator;
|
||||||
private final EffectAnimator vectorCancellingAnimator;
|
private final EffectAnimator vectorCancellingAnimator;
|
||||||
private final EffectAnimator bitCrushAnimator;
|
private final EffectAnimator bitCrushAnimator;
|
||||||
private final EffectAnimator smoothAnimator;
|
private final EffectAnimator smoothingAnimator;
|
||||||
private final EffectAnimator verticalDistortAnimator;
|
private final EffectAnimator verticalDistortAnimator;
|
||||||
private final EffectAnimator horizontalDistortAnimator;
|
private final EffectAnimator horizontalDistortAnimator;
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ public class EffectsController implements Initializable, SubController {
|
||||||
this.traceAnimator = new EffectAnimator(DEFAULT_SAMPLE_RATE, new TraceEffect(audioPlayer));
|
this.traceAnimator = new EffectAnimator(DEFAULT_SAMPLE_RATE, new TraceEffect(audioPlayer));
|
||||||
this.vectorCancellingAnimator = new EffectAnimator(DEFAULT_SAMPLE_RATE, new VectorCancellingEffect());
|
this.vectorCancellingAnimator = new EffectAnimator(DEFAULT_SAMPLE_RATE, new VectorCancellingEffect());
|
||||||
this.bitCrushAnimator = new EffectAnimator(DEFAULT_SAMPLE_RATE, new BitCrushEffect());
|
this.bitCrushAnimator = new EffectAnimator(DEFAULT_SAMPLE_RATE, new BitCrushEffect());
|
||||||
this.smoothAnimator = new EffectAnimator(DEFAULT_SAMPLE_RATE, new SmoothEffect(1));
|
this.smoothingAnimator = new EffectAnimator(DEFAULT_SAMPLE_RATE, new SmoothEffect(1));
|
||||||
this.verticalDistortAnimator = new EffectAnimator(DEFAULT_SAMPLE_RATE, new VerticalDistortEffect(0.2));
|
this.verticalDistortAnimator = new EffectAnimator(DEFAULT_SAMPLE_RATE, new VerticalDistortEffect(0.2));
|
||||||
this.horizontalDistortAnimator = new EffectAnimator(DEFAULT_SAMPLE_RATE, new HorizontalDistortEffect(0.2));
|
this.horizontalDistortAnimator = new EffectAnimator(DEFAULT_SAMPLE_RATE, new HorizontalDistortEffect(0.2));
|
||||||
}
|
}
|
||||||
|
@ -139,7 +139,7 @@ public class EffectsController implements Initializable, SubController {
|
||||||
vectorCancellingComboBox, vectorCancellingAnimator,
|
vectorCancellingComboBox, vectorCancellingAnimator,
|
||||||
bitCrushComboBox, bitCrushAnimator,
|
bitCrushComboBox, bitCrushAnimator,
|
||||||
wobbleComboBox, wobbleAnimator,
|
wobbleComboBox, wobbleAnimator,
|
||||||
smoothingComboBox, smoothAnimator,
|
smoothingComboBox, smoothingAnimator,
|
||||||
traceComboBox, traceAnimator,
|
traceComboBox, traceAnimator,
|
||||||
verticalDistortComboBox, verticalDistortAnimator,
|
verticalDistortComboBox, verticalDistortAnimator,
|
||||||
horizontalDistortComboBox, horizontalDistortAnimator
|
horizontalDistortComboBox, horizontalDistortAnimator
|
||||||
|
@ -217,7 +217,7 @@ public class EffectsController implements Initializable, SubController {
|
||||||
InvalidationListener wobbleListener = e ->
|
InvalidationListener wobbleListener = e ->
|
||||||
updateEffect(EffectType.WOBBLE, wobbleCheckBox.isSelected(), wobbleAnimator, wobbleSlider.getValue());
|
updateEffect(EffectType.WOBBLE, wobbleCheckBox.isSelected(), wobbleAnimator, wobbleSlider.getValue());
|
||||||
InvalidationListener smoothListener = e ->
|
InvalidationListener smoothListener = e ->
|
||||||
updateEffect(EffectType.SMOOTH, smoothingCheckBox.isSelected(), smoothAnimator, smoothingSlider.getValue());
|
updateEffect(EffectType.SMOOTH, smoothingCheckBox.isSelected(), smoothingAnimator, smoothingSlider.getValue());
|
||||||
InvalidationListener vectorCancellingListener = e ->
|
InvalidationListener vectorCancellingListener = e ->
|
||||||
updateEffect(EffectType.VECTOR_CANCELLING, vectorCancellingCheckBox.isSelected(), vectorCancellingAnimator, vectorCancellingSlider.getValue());
|
updateEffect(EffectType.VECTOR_CANCELLING, vectorCancellingCheckBox.isSelected(), vectorCancellingAnimator, vectorCancellingSlider.getValue());
|
||||||
InvalidationListener traceListener = e ->
|
InvalidationListener traceListener = e ->
|
||||||
|
@ -261,6 +261,16 @@ public class EffectsController implements Initializable, SubController {
|
||||||
entry.getValue().setAnimation(animationType);
|
entry.getValue().setAnimation(animationType);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<EffectAnimator> animators = animators();
|
||||||
|
List<Slider> sliders = sliders();
|
||||||
|
for (int i = 0; i < sliders.size(); i++) {
|
||||||
|
int finalI = i;
|
||||||
|
sliders.get(i).minProperty().addListener((e, old, min) ->
|
||||||
|
animators.get(finalI).setMin(min.doubleValue()));
|
||||||
|
sliders.get(i).maxProperty().addListener((e, old, max) ->
|
||||||
|
animators.get(finalI).setMax(max.doubleValue()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ComboBox<AnimationType>> comboBoxes() {
|
private List<ComboBox<AnimationType>> comboBoxes() {
|
||||||
|
@ -270,6 +280,10 @@ public class EffectsController implements Initializable, SubController {
|
||||||
return List.of(vectorCancellingCheckBox, bitCrushCheckBox, verticalDistortCheckBox,
|
return List.of(vectorCancellingCheckBox, bitCrushCheckBox, verticalDistortCheckBox,
|
||||||
horizontalDistortCheckBox, wobbleCheckBox, smoothingCheckBox, traceCheckBox);
|
horizontalDistortCheckBox, wobbleCheckBox, smoothingCheckBox, traceCheckBox);
|
||||||
}
|
}
|
||||||
|
private List<EffectAnimator> animators() {
|
||||||
|
return List.of(vectorCancellingAnimator, bitCrushAnimator, verticalDistortAnimator,
|
||||||
|
horizontalDistortAnimator, wobbleAnimator, smoothingAnimator, traceAnimator);
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public List<CheckBox> micCheckBoxes() {
|
public List<CheckBox> micCheckBoxes() {
|
||||||
return List.of(vectorCancellingMic, bitCrushMic, verticalDistortMic, horizontalDistortMic,
|
return List.of(vectorCancellingMic, bitCrushMic, verticalDistortMic, horizontalDistortMic,
|
||||||
|
|
|
@ -265,14 +265,16 @@ public class MainController implements Initializable, FrequencyListener, MidiLis
|
||||||
});
|
});
|
||||||
sliderComboBox.setValue(printableSliders.get(0));
|
sliderComboBox.setValue(printableSliders.get(0));
|
||||||
|
|
||||||
sliderMinTextField.textProperty().addListener((e, old, text) -> {
|
sliderMinTextField.focusedProperty().addListener((e, old, focused) -> {
|
||||||
if (parseable(text)) {
|
String text = sliderMinTextField.getText();
|
||||||
|
if (!focused && parseable(text)) {
|
||||||
sliderComboBox.getValue().slider.setMin(Double.parseDouble(text));
|
sliderComboBox.getValue().slider.setMin(Double.parseDouble(text));
|
||||||
updateSliderUnits(sliderComboBox.getValue().slider);
|
updateSliderUnits(sliderComboBox.getValue().slider);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
sliderMaxTextField.textProperty().addListener((e, old, text) -> {
|
sliderMaxTextField.focusedProperty().addListener((e, old, focused) -> {
|
||||||
if (parseable(text)) {
|
String text = sliderMaxTextField.getText();
|
||||||
|
if (!focused && parseable(text)) {
|
||||||
sliderComboBox.getValue().slider.setMax(Double.parseDouble(text));
|
sliderComboBox.getValue().slider.setMax(Double.parseDouble(text));
|
||||||
updateSliderUnits(sliderComboBox.getValue().slider);
|
updateSliderUnits(sliderComboBox.getValue().slider);
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue