Add frequency spinner to set specific frequencies

pull/65/head
James Ball 2022-05-12 22:28:09 +01:00 zatwierdzone przez James H Ball
rodzic 6f5c4b7dd5
commit 0d312b11e3
3 zmienionych plików z 67 dodań i 44 usunięć

Wyświetl plik

@ -4,10 +4,8 @@ import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Slider;
import javafx.scene.control.TextField;
import javafx.scene.control.*;
import javafx.scene.input.KeyCode;
import javafx.scene.shape.SVGPath;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@ -56,6 +54,8 @@ public class ImageController implements Initializable, SubController {
@FXML
private Slider frequencySlider;
@FXML
private Spinner<Double> frequencySpinner;
@FXML
private SVGPath frequencyMidi;
@FXML
private CheckBox frequencyMic;
@ -162,13 +162,27 @@ public class ImageController implements Initializable, SubController {
translationScaleSlider.valueProperty().addListener((e, old, scale) -> translateEffect.setScale(scale.doubleValue()));
// converts the value of frequencySlider to the actual frequency that it represents so that it
// can increase at an exponential scale.
frequencySlider.valueProperty().addListener((o, old, f) -> frequency.set(Math.pow(MAX_FREQUENCY, f.doubleValue())));
frequency.addListener((o, old, f) -> frequencySlider.setValue(Math.log(f.doubleValue()) / Math.log(MAX_FREQUENCY)));
frequencySpinner.setValueFactory(new SpinnerValueFactory.DoubleSpinnerValueFactory(0, MAX_FREQUENCY, MidiNote.MIDDLE_C, 1));
frequencySpinner.valueProperty().addListener((o, old, f) -> {
frequency.set(f);
});
frequency.addListener((o, old, f) -> {
frequencySlider.setValue(Math.log(f.doubleValue()) / Math.log(MAX_FREQUENCY));
frequencySpinner.setValueFactory(new SpinnerValueFactory.DoubleSpinnerValueFactory(0, MAX_FREQUENCY, f.doubleValue(), 1));
});
audioPlayer.setFrequency(frequency);
// default value is middle C
frequency.set(MidiNote.MIDDLE_C);
frequencySlider.setOnKeyPressed(e -> {
if (e.getCode() == KeyCode.LEFT || e.getCode() == KeyCode.RIGHT) {
frequency.set(Math.pow(MAX_FREQUENCY, frequencySlider.getValue()));
}
});
frequencySlider.setOnMouseDragged(e -> {
frequency.set(Math.pow(MAX_FREQUENCY, frequencySlider.getValue()));
});
volumeSlider.valueProperty().addListener((e, old, value) -> {
audioPlayer.setVolume(value.doubleValue() / 3.0);
});
@ -232,6 +246,8 @@ public class ImageController implements Initializable, SubController {
translationXTextField.setText(x.getTextContent());
translationYTextField.setText(y.getTextContent());
frequency.set(Math.pow(MAX_FREQUENCY, frequencySlider.getValue()));
// For backwards compatibility we assume a default value
Element ellipse = (Element) element.getElementsByTagName("ellipse").item(0);
translateEllipseCheckBox.setSelected(ellipse != null && Boolean.parseBoolean(ellipse.getTextContent()));

Wyświetl plik

@ -409,7 +409,12 @@ public class MainController implements Initializable, FrequencyListener, MidiLis
deadzoneSpinner.valueProperty().addListener((e, old, deadzone) -> this.midiDeadzone = deadzone);
List<PrintableSlider> printableSliders = new ArrayList<>();
sliders.forEach(slider -> printableSliders.add(new PrintableSlider(slider)));
sliders.forEach(slider -> {
// don't allow frequency slider to be changed
if (!slider.getId().contains("frequency")) {
printableSliders.add(new PrintableSlider(slider));
}
});
sliderComboBox.setItems(FXCollections.observableList(printableSliders));
sliderComboBox.valueProperty().addListener((e, old, slider) -> {
sliderMinTextField.setText(FORMAT.format(slider.slider.getMin()));

Wyświetl plik

@ -4,6 +4,7 @@
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Slider?>
<?import javafx.scene.control.Spinner?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.shape.SVGPath?>
@ -12,25 +13,25 @@
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="307.0" prefWidth="519.0" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sh.ball.gui.controller.ImageController">
<children>
<CheckBox fx:id="translateEllipseCheckBox" layoutX="324.0" layoutY="9.0" mnemonicParsing="false" text="Ellipse" />
<Slider fx:id="rotateSpeedSlider" blockIncrement="0.05" layoutX="116.0" layoutY="189.0" majorTickUnit="1.0" max="10.0" prefHeight="42.0" prefWidth="254.0" showTickLabels="true" showTickMarks="true" />
<Label layoutX="12.0" layoutY="188.0" text="2D Rotate speed">
<Slider fx:id="rotateSpeedSlider" blockIncrement="0.05" layoutX="106.0" layoutY="189.0" majorTickUnit="1.0" max="10.0" prefHeight="42.0" prefWidth="254.0" showTickLabels="true" showTickMarks="true" />
<Label layoutX="7.0" layoutY="188.0" text="2D Rotate speed">
<font>
<Font size="13.0" />
</font>
</Label>
<Slider fx:id="translationSpeedSlider" blockIncrement="0.05" layoutX="116.0" layoutY="113.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="112.0" text="Translation speed">
<Slider fx:id="translationSpeedSlider" blockIncrement="0.05" layoutX="106.0" layoutY="113.0" majorTickUnit="1.0" max="10.0" prefHeight="42.0" prefWidth="254.0" showTickLabels="true" showTickMarks="true" value="1.0" />
<Label layoutX="2.0" layoutY="112.0" text="Translation speed">
<font>
<Font size="13.0" />
</font>
</Label>
<Slider fx:id="volumeSlider" blockIncrement="0.05" layoutX="116.0" layoutY="227.0" majorTickUnit="1.0" max="10.0" prefHeight="42.0" prefWidth="253.0" showTickLabels="true" showTickMarks="true" value="3.0" />
<Label layoutX="33.0" layoutY="226.0" text="Volume scale">
<Slider fx:id="volumeSlider" blockIncrement="0.05" layoutX="106.0" layoutY="227.0" majorTickUnit="1.0" max="10.0" prefHeight="42.0" prefWidth="253.0" showTickLabels="true" showTickMarks="true" value="3.0" />
<Label layoutX="28.0" layoutY="226.0" text="Volume scale">
<font>
<Font size="13.0" />
</font>
</Label>
<Label layoutX="11.0" layoutY="150.0" text="Target frequency">
<Label layoutX="6.0" layoutY="150.0" text="Target frequency">
<font>
<Font size="13.0" />
</font>
@ -40,43 +41,44 @@
<Label layoutX="120.0" layoutY="8.0" text="x :" />
<Label layoutX="222.0" layoutY="8.0" text="y :" />
<TextField fx:id="translationYTextField" layoutX="241.0" layoutY="5.0" prefHeight="26.0" prefWidth="69.0" text="0.0" />
<Slider fx:id="frequencySlider" blockIncrement="0.001" layoutX="116.0" layoutY="145.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="149.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="186.0" pickOnBounds="true" />
<SVGPath fx:id="translationSpeedMidi" 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="110.0" pickOnBounds="true" />
<SVGPath fx:id="volumeMidi" 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="224.0" pickOnBounds="true" />
<Label layoutX="257.0" layoutY="171.0" text="C4" />
<Label layoutX="239.0" layoutY="171.0" text="C3" />
<Label layoutX="222.0" layoutY="171.0" text="C2" />
<Label layoutX="193.0" layoutY="171.0" text="20" />
<Label layoutX="274.0" layoutY="171.0" text="C5" />
<Label layoutX="292.0" layoutY="171.0" text="C6" />
<Label layoutX="310.0" layoutY="171.0" text="C7" />
<Label layoutX="345.0" layoutY="171.0" text="12000" />
<Label layoutX="162.0" layoutY="171.0" text="5" />
<Label layoutX="122.0" layoutY="171.0" text="0" />
<Label layoutX="24.0" layoutY="265.0" text="Image visibility">
<Slider fx:id="frequencySlider" blockIncrement="0.001" layoutX="106.0" layoutY="145.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="361.0" layoutY="149.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="361.0" layoutY="186.0" pickOnBounds="true" />
<SVGPath fx:id="translationSpeedMidi" 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="110.0" pickOnBounds="true" />
<SVGPath fx:id="volumeMidi" 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="224.0" pickOnBounds="true" />
<Label layoutX="247.0" layoutY="171.0" text="C4" />
<Label layoutX="229.0" layoutY="171.0" text="C3" />
<Label layoutX="212.0" layoutY="171.0" text="C2" />
<Label layoutX="183.0" layoutY="171.0" text="20" />
<Label layoutX="264.0" layoutY="171.0" text="C5" />
<Label layoutX="282.0" layoutY="171.0" text="C6" />
<Label layoutX="300.0" layoutY="171.0" text="C7" />
<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">
<font>
<Font size="13.0" />
</font>
</Label>
<Slider fx:id="visibilitySlider" blockIncrement="0.005" layoutX="116.0" layoutY="266.0" majorTickUnit="0.1" max="1.0" prefHeight="42.0" prefWidth="253.0" showTickLabels="true" showTickMarks="true" value="0.5" />
<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="371.0" layoutY="263.0" pickOnBounds="true" />
<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.5" />
<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" />
<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="115.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="12.0" layoutY="72.0" text="Translation Scale">
<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">
<font>
<Font size="13.0" />
</font>
</Label>
<SVGPath fx:id="translationScaleMidi" 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="370.0" layoutY="70.0" pickOnBounds="true" />
<CheckBox fx:id="translationScaleMic" layoutX="408.0" layoutY="73.0" mnemonicParsing="false" text="Mic" />
<CheckBox fx:id="frequencyMic" layoutX="408.0" layoutY="152.0" mnemonicParsing="false" text="Mic" />
<CheckBox fx:id="rotateSpeedMic" layoutX="408.0" layoutY="189.0" mnemonicParsing="false" text="Mic" />
<CheckBox fx:id="translationSpeedMic" layoutX="408.0" layoutY="113.0" mnemonicParsing="false" text="Mic" />
<CheckBox fx:id="volumeMic" layoutX="408.0" layoutY="227.0" mnemonicParsing="false" text="Mic" />
<CheckBox fx:id="visibilityMic" layoutX="408.0" layoutY="266.0" mnemonicParsing="false" text="Mic" />
<Button fx:id="resetRotationButton" layoutX="464.0" layoutY="185.0" mnemonicParsing="false" text="Reset" />
<SVGPath fx:id="translationScaleMidi" 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="360.0" layoutY="70.0" pickOnBounds="true" />
<CheckBox fx:id="translationScaleMic" layoutX="389.0" layoutY="73.0" mnemonicParsing="false" text="Mic" />
<CheckBox fx:id="frequencyMic" layoutX="389.0" layoutY="152.0" mnemonicParsing="false" text="Mic" />
<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" />
<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" />
</children>
</AnchorPane>