Fix decay on sine effects

pull/72/head
James Ball 2022-05-22 14:13:08 +01:00 zatwierdzone przez James H Ball
rodzic 9a2d2a9495
commit b4af5c905d
4 zmienionych plików z 20 dodań i 29 usunięć

Wyświetl plik

@ -17,7 +17,7 @@ public interface AudioPlayer<S> extends Runnable, MidiListener {
void setOctave(int octave);
void setBaseFrequencyVolumeScale(double scale);
void setBackingMidiVolume(double scale);
void setDecay(double decaySeconds);

Wyświetl plik

@ -73,7 +73,7 @@ public class ShapeAudioPlayer implements AudioPlayer<List<Shape>> {
private double volume = 1;
private double octaveFrequency;
private DoubleProperty frequency;
private double baseFrequencyVolumeScale = 0.75;
private double backingMidiVolume = 0.25;
private double baseFrequency;
private double traceMin = 0;
private double traceMax = 1;
@ -239,7 +239,7 @@ public class ShapeAudioPlayer implements AudioPlayer<List<Shape>> {
}
private Vector2 applyEffects(int frame, Vector2 vector) {
vector = vector.scale(2 * baseFrequencyVolumeScale * keyActualVolumes[mainChannel][baseNote.key()] / MidiNote.MAX_VELOCITY);
vector = vector.scale((double) keyActualVolumes[mainChannel][baseNote.key()] / MidiNote.MAX_VELOCITY);
if (midiStarted) {
if (lastDecay > decayFrames) {
for (int i = 0; i < keyActualVolumes.length; i++) {
@ -264,15 +264,12 @@ public class ShapeAudioPlayer implements AudioPlayer<List<Shape>> {
}
lastAttack++;
double scaledVolume = 1 - baseFrequencyVolumeScale;
for (int channel = 0; channel < keysDown.length; channel++) {
for (int key = 0; key < keysDown[0].length; key++) {
if (keysDown[channel][key] != null && !keysDown[channel][key].equals(baseNote)) {
if (keyActualVolumes[channel][key] > 0) {
Vector2 sine = sineEffects[channel][key].apply(frame, new Vector2());
double volume = scaledVolume * keyActualVolumes[channel][key] / MidiNote.MAX_VELOCITY;
vector = new Vector2(vector.x + volume * sine.x, vector.y + volume * sine.y);
}
if (keyActualVolumes[channel][key] > 0 && !(baseNote.key() == key && baseNote.channel() == channel)) {
Vector2 sine = sineEffects[channel][key].apply(frame, new Vector2());
double volume = backingMidiVolume * keyActualVolumes[channel][key] / MidiNote.MAX_VELOCITY;
vector = new Vector2(vector.x + volume * sine.x, vector.y + volume * sine.y);
}
}
}
@ -383,8 +380,8 @@ public class ShapeAudioPlayer implements AudioPlayer<List<Shape>> {
}
@Override
public void setBaseFrequencyVolumeScale(double scale) {
this.baseFrequencyVolumeScale = scale;
public void setBackingMidiVolume(double scale) {
this.backingMidiVolume = scale;
updateSineEffects();
}
@ -510,7 +507,6 @@ public class ShapeAudioPlayer implements AudioPlayer<List<Shape>> {
return;
}
}
}
public void setTraceMin(double traceMin) {

Wyświetl plik

@ -78,11 +78,11 @@ public class ImageController implements Initializable, SubController {
@FXML
private CheckBox volumeMic;
@FXML
private Slider visibilitySlider;
private Slider backingMidiSlider;
@FXML
private SVGPath visibilityMidi;
private SVGPath backingMidiMidi;
@FXML
private CheckBox visibilityMic;
private CheckBox backingMidiCheckBox;
@FXML
private Button resetRotationButton;
@FXML
@ -139,7 +139,7 @@ public class ImageController implements Initializable, SubController {
Map<Slider, Consumer<Double>> sliderMap = Map.of(
rotateSpeedSlider, rotateEffect::setSpeed,
translationSpeedSlider, translateEffect::setSpeed,
visibilitySlider, audioPlayer::setBaseFrequencyVolumeScale
backingMidiSlider, audioPlayer::setBackingMidiVolume
);
sliderMap.keySet().forEach(slider ->
slider.valueProperty().addListener((source, oldValue, newValue) ->
@ -184,11 +184,6 @@ public class ImageController implements Initializable, SubController {
volumeSlider.valueProperty().addListener((e, old, value) ->
audioPlayer.setVolume(value.doubleValue() / 3.0)
);
volumeSlider.valueProperty().addListener(e -> {
if (!audioPlayer.midiPlaying()) {
audioPlayer.resetMidi();
}
});
}
@Override
@ -198,7 +193,7 @@ public class ImageController implements Initializable, SubController {
rotateSpeedMidi, rotateSpeedSlider,
translationSpeedMidi, translationSpeedSlider,
volumeMidi, volumeSlider,
visibilityMidi, visibilitySlider,
backingMidiMidi, backingMidiSlider,
translationScaleMidi, translationScaleSlider
);
}
@ -206,13 +201,13 @@ public class ImageController implements Initializable, SubController {
@Override
public List<CheckBox> micCheckBoxes() {
return List.of(frequencyMic, rotateSpeedMic, translationSpeedMic, volumeMic,
visibilityMic, translationScaleMic);
backingMidiCheckBox, translationScaleMic);
}
@Override
public List<Slider> sliders() {
return List.of(frequencySlider, rotateSpeedSlider, translationSpeedSlider,
volumeSlider, visibilitySlider, translationScaleSlider);
volumeSlider, backingMidiSlider, translationScaleSlider);
}
@Override

Wyświetl plik

@ -56,13 +56,13 @@
<Label layoutX="335.0" layoutY="171.0" text="12000" />
<Label layoutX="152.0" layoutY="171.0" text="5" />
<Label layoutX="112.0" layoutY="171.0" text="0" />
<Label layoutX="19.0" layoutY="265.0" text="Image visibility">
<Label layoutX="29.0" layoutY="265.0" text="MIDI volume">
<font>
<Font size="13.0" />
</font>
</Label>
<Slider fx:id="visibilitySlider" blockIncrement="0.005" layoutX="106.0" layoutY="266.0" majorTickUnit="0.1" max="1.0" prefHeight="42.0" prefWidth="253.0" showTickLabels="true" showTickMarks="true" value="0.75" />
<SVGPath fx:id="visibilityMidi" 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="361.0" layoutY="263.0" pickOnBounds="true" />
<Slider fx:id="backingMidiSlider" blockIncrement="0.005" layoutX="106.0" layoutY="266.0" majorTickUnit="0.1" max="1.0" prefHeight="42.0" prefWidth="253.0" showTickLabels="true" showTickMarks="true" value="0.25" />
<SVGPath fx:id="backingMidiMidi" 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="361.0" layoutY="263.0" pickOnBounds="true" />
<CheckBox fx:id="translateCheckBox" layoutX="137.0" layoutY="43.0" mnemonicParsing="false" text="Translate with Mouse (Esc to disable)" />
<Slider fx:id="translationScaleSlider" blockIncrement="0.05" layoutX="105.0" layoutY="73.0" majorTickUnit="1.0" max="10.0" prefHeight="42.0" prefWidth="254.0" showTickLabels="true" showTickMarks="true" value="1.0" />
<Label layoutX="7.0" layoutY="72.0" text="Translation Scale">
@ -76,7 +76,7 @@
<CheckBox fx:id="rotateSpeedMic" layoutX="389.0" layoutY="189.0" mnemonicParsing="false" text="Mic" />
<CheckBox fx:id="translationSpeedMic" layoutX="389.0" layoutY="113.0" mnemonicParsing="false" text="Mic" />
<CheckBox fx:id="volumeMic" layoutX="389.0" layoutY="227.0" mnemonicParsing="false" text="Mic" />
<CheckBox fx:id="visibilityMic" layoutX="389.0" layoutY="266.0" mnemonicParsing="false" text="Mic" />
<CheckBox fx:id="backingMidiCheckBox" layoutX="389.0" layoutY="266.0" mnemonicParsing="false" text="Mic" />
<Button fx:id="resetRotationButton" layoutX="455.0" layoutY="185.0" mnemonicParsing="false" text="Reset" />
<Button fx:id="resetTranslationButton" layoutX="396.0" layoutY="4.0" mnemonicParsing="false" text="Reset Translation" />
<Spinner fx:id="frequencySpinner" editable="true" layoutX="440.0" layoutY="149.0" prefHeight="26.0" prefWidth="80.0" />