diff --git a/src/main/java/sh/ball/audio/AudioPlayer.java b/src/main/java/sh/ball/audio/AudioPlayer.java index 90208cc..48efd4b 100644 --- a/src/main/java/sh/ball/audio/AudioPlayer.java +++ b/src/main/java/sh/ball/audio/AudioPlayer.java @@ -17,7 +17,7 @@ public interface AudioPlayer extends Runnable, MidiListener { void setOctave(int octave); - void setBaseFrequencyVolumeScale(double scale); + void setBackingMidiVolume(double scale); void setDecay(double decaySeconds); diff --git a/src/main/java/sh/ball/audio/ShapeAudioPlayer.java b/src/main/java/sh/ball/audio/ShapeAudioPlayer.java index 53eb62e..e638dff 100644 --- a/src/main/java/sh/ball/audio/ShapeAudioPlayer.java +++ b/src/main/java/sh/ball/audio/ShapeAudioPlayer.java @@ -73,7 +73,7 @@ public class ShapeAudioPlayer implements AudioPlayer> { 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> { } 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> { } 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> { } @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> { return; } } - } public void setTraceMin(double traceMin) { diff --git a/src/main/java/sh/ball/gui/controller/ImageController.java b/src/main/java/sh/ball/gui/controller/ImageController.java index 05cec82..2cfe7aa 100644 --- a/src/main/java/sh/ball/gui/controller/ImageController.java +++ b/src/main/java/sh/ball/gui/controller/ImageController.java @@ -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> 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 micCheckBoxes() { return List.of(frequencyMic, rotateSpeedMic, translationSpeedMic, volumeMic, - visibilityMic, translationScaleMic); + backingMidiCheckBox, translationScaleMic); } @Override public List sliders() { return List.of(frequencySlider, rotateSpeedSlider, translationSpeedSlider, - volumeSlider, visibilitySlider, translationScaleSlider); + volumeSlider, backingMidiSlider, translationScaleSlider); } @Override diff --git a/src/main/resources/fxml/image.fxml b/src/main/resources/fxml/image.fxml index 99fc80e..9ed6f08 100644 --- a/src/main/resources/fxml/image.fxml +++ b/src/main/resources/fxml/image.fxml @@ -56,13 +56,13 @@