Merge pull request #33 from jameshball/record-length

Add ability to record output for a predetermined length
pull/35/head
James H Ball 2021-07-10 21:58:46 +01:00 zatwierdzone przez GitHub
commit 550dee5f3f
2 zmienionych plików z 116 dodań i 63 usunięć

Wyświetl plik

@ -61,6 +61,7 @@ public class Controller implements Initializable, FrequencyListener, Listener {
private FrequencyAnalyser<List<Shape>> analyser;
private final AudioDevice defaultDevice;
private boolean recording = false;
private Timeline recordingTimeline;
private String lastVisitedDirectory;
private FrameProducer<List<Shape>> producer;
@ -85,6 +86,12 @@ public class Controller implements Initializable, FrequencyListener, Listener {
@FXML
private Label recordLabel;
@FXML
private TextField recordTextField;
@FXML
private CheckBox recordCheckBox;
@FXML
private Label recordLengthLabel;
@FXML
private TextField translationXTextField;
@FXML
private TextField translationYTextField;
@ -264,6 +271,11 @@ public class Controller implements Initializable, FrequencyListener, Listener {
recordButton.setOnAction(event -> toggleRecord());
recordCheckBox.selectedProperty().addListener((e, oldVal, newVal) -> {
recordLengthLabel.setDisable(!newVal);
recordTextField.setDisable(!newVal);
});
updateObjectRotateSpeed();
audioPlayer.addEffect(EffectType.SCALE, scaleEffect);
@ -321,27 +333,62 @@ public class Controller implements Initializable, FrequencyListener, Listener {
private void toggleRecord() {
recording = !recording;
boolean timedRecord = recordCheckBox.isSelected();
if (recording) {
if (timedRecord) {
double recordingLength;
try {
recordingLength = Double.parseDouble(recordTextField.getText());
} catch (NumberFormatException e) {
recordLabel.setText("Please set a valid record length");
recording = false;
return;
}
recordButton.setText("Cancel");
KeyFrame kf1 = new KeyFrame(
Duration.seconds(0),
e -> audioPlayer.startRecord()
);
KeyFrame kf2 = new KeyFrame(
Duration.seconds(recordingLength),
e -> {
saveRecording();
recording = false;
}
);
recordingTimeline = new Timeline(kf1, kf2);
Platform.runLater(recordingTimeline::play);
} else {
recordButton.setText("Stop Recording");
audioPlayer.startRecord();
}
recordLabel.setText("Recording...");
recordButton.setText("Stop Recording");
audioPlayer.startRecord();
} else if (timedRecord) {
recordingTimeline.stop();
recordLabel.setText("");
recordButton.setText("Record");
audioPlayer.stopRecord();
} else {
saveRecording();
}
}
private void saveRecording() {
try {
recordButton.setText("Record");
AudioInputStream input = audioPlayer.stopRecord();
try {
File file = fileChooser.showSaveDialog(stage);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
Date date = new Date(System.currentTimeMillis());
if (file == null) {
file = new File("out-" + formatter.format(date) + ".wav");
}
AudioSystem.write(input, AudioFileFormat.Type.WAVE, file);
input.close();
recordLabel.setText("Saved to " + file.getAbsolutePath());
} catch (IOException e) {
recordLabel.setText("Error saving file");
e.printStackTrace();
File file = fileChooser.showSaveDialog(stage);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
Date date = new Date(System.currentTimeMillis());
if (file == null) {
file = new File("out-" + formatter.format(date) + ".wav");
}
AudioSystem.write(input, AudioFileFormat.Type.WAVE, file);
input.close();
recordLabel.setText("Saved to " + file.getAbsolutePath());
} catch (IOException e) {
recordLabel.setText("Error saving file");
e.printStackTrace();
}
}
@ -423,7 +470,8 @@ public class Controller implements Initializable, FrequencyListener, Listener {
try {
frameSets.add(ParserFactory.getParser(file.getAbsolutePath()).parse());
frameSetPaths.add(file.getName());
} catch (IOException ignored) {}
} catch (IOException ignored) {
}
}
} else {
jkLabel.setVisible(false);

Wyświetl plik

@ -11,21 +11,9 @@
<?import javafx.scene.text.Font?>
<AnchorPane prefHeight="539.0" prefWidth="837.0" xmlns="http://javafx.com/javafx/16" xmlns:fx="http://javafx.com/fxml/1">
<AnchorPane id="control-pane" layoutX="423.0" layoutY="14.0" prefHeight="232.0" prefWidth="402.0">
<children>
<Button fx:id="chooseFileButton" layoutX="14.0" layoutY="53.0" mnemonicParsing="false" prefHeight="26.0" prefWidth="114.0" text="Choose File" />
<Label fx:id="fileLabel" layoutX="144.0" layoutY="57.0" maxWidth="270.0" prefHeight="18.0" prefWidth="246.0" text="cube.obj" />
<Button fx:id="recordButton" layoutX="14.0" layoutY="129.0" mnemonicParsing="false" prefHeight="26.0" prefWidth="114.0" text="Record" />
<Label fx:id="recordLabel" layoutX="144.0" layoutY="133.0" maxWidth="270.0" prefHeight="18.0" prefWidth="245.0" />
<Label id="frequency" fx:id="frequencyLabel" layoutX="13.0" layoutY="166.0" prefHeight="58.0" prefWidth="376.0" text="L/R Frequency:&#10; &#10;" />
<ComboBox fx:id="deviceComboBox" layoutX="14.0" layoutY="11.0" prefHeight="26.0" prefWidth="376.0" />
<Button fx:id="chooseFolderButton" layoutX="14.0" layoutY="91.0" mnemonicParsing="false" prefHeight="26.0" prefWidth="114.0" text="Choose Folder" />
<Label fx:id="jkLabel" layoutX="143.0" layoutY="95.0" maxWidth="270.0" prefHeight="18.0" prefWidth="246.0" text="Use j and k to cycle between files" visible="false" />
</children>
</AnchorPane>
<TitledPane animated="false" collapsible="false" layoutX="423.0" layoutY="252.0" prefHeight="272.0" prefWidth="402.0" text="Effects">
<TitledPane animated="false" collapsible="false" layoutX="426.0" layoutY="8.0" prefHeight="303.0" prefWidth="402.0" text="Effects">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="246.0" prefWidth="442.0">
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="262.0" prefWidth="401.0">
<children>
<CheckBox fx:id="vectorCancellingCheckBox" layoutX="14.0" layoutY="15.0" mnemonicParsing="false" text="Vector cancelling" />
<Slider fx:id="vectorCancellingSlider" blockIncrement="0.05" disable="true" layoutX="167.0" layoutY="16.0" majorTickUnit="1.0" max="10.0" min="2.0" prefHeight="38.0" prefWidth="222.0" showTickLabels="true" showTickMarks="true" snapToTicks="true" value="2.0" />
@ -41,7 +29,7 @@
</AnchorPane>
</content>
</TitledPane>
<TitledPane fx:id="objTitledPane" animated="false" collapsible="false" layoutX="12.0" layoutY="280.0" maxHeight="-Infinity" maxWidth="-Infinity" prefHeight="244.0" prefWidth="402.0" text="3D .obj file settings">
<TitledPane fx:id="objTitledPane" animated="false" collapsible="false" layoutX="426.0" layoutY="318.0" maxHeight="-Infinity" maxWidth="-Infinity" prefHeight="210.0" prefWidth="402.0" text="3D .obj file settings">
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="359.0">
<Slider fx:id="focalLengthSlider" blockIncrement="0.01" layoutX="116.0" layoutY="15.0" majorTickUnit="0.2" max="2.0" min="1.0E-5" prefHeight="38.0" prefWidth="270.0" showTickLabels="true" showTickMarks="true" value="1.0" />
<Label layoutX="30.0" layoutY="14.0" text="Focal length" />
@ -57,39 +45,56 @@
<CheckBox fx:id="rotateCheckBox" layoutX="90.0" layoutY="147.0" mnemonicParsing="false" text="Rotate with Mouse (Esc to disable)" />
</AnchorPane>
</TitledPane>
<TitledPane collapsible="false" layoutX="12.0" layoutY="14.0" prefHeight="257.0" prefWidth="402.0" text="Image settings">
<AnchorPane id="control-pane" layoutX="12.0" layoutY="7.0" prefHeight="274.0" prefWidth="402.0">
<children>
<Button fx:id="chooseFileButton" layoutX="14.0" layoutY="53.0" mnemonicParsing="false" prefHeight="26.0" prefWidth="114.0" text="Choose File" />
<Label fx:id="fileLabel" layoutX="144.0" layoutY="57.0" maxWidth="270.0" prefHeight="18.0" prefWidth="246.0" text="cube.obj" />
<Button fx:id="recordButton" layoutX="13.0" layoutY="142.0" mnemonicParsing="false" prefHeight="26.0" prefWidth="114.0" text="Record" />
<Label fx:id="recordLabel" layoutX="13.0" layoutY="184.0" maxWidth="358.0" prefHeight="18.0" prefWidth="357.0" />
<Label id="frequency" fx:id="frequencyLabel" layoutX="13.0" layoutY="212.0" prefHeight="58.0" prefWidth="376.0" text="L/R Frequency:&#10; &#10;" />
<ComboBox fx:id="deviceComboBox" layoutX="14.0" layoutY="11.0" prefHeight="26.0" prefWidth="376.0" />
<Button fx:id="chooseFolderButton" layoutX="14.0" layoutY="91.0" mnemonicParsing="false" prefHeight="26.0" prefWidth="114.0" text="Choose Folder" />
<Label fx:id="jkLabel" layoutX="143.0" layoutY="95.0" maxWidth="270.0" prefHeight="18.0" prefWidth="246.0" text="Use j and k to cycle between files" visible="false" />
<TextField fx:id="recordTextField" disable="true" layoutX="300.0" layoutY="154.0" prefHeight="26.0" prefWidth="70.0" text="2.0" />
<Label fx:id="recordLengthLabel" disable="true" layoutX="290.0" layoutY="128.0" text="Record length (s)" />
<CheckBox fx:id="recordCheckBox" layoutX="143.0" layoutY="146.0" mnemonicParsing="false" text="Timed record" />
</children>
</AnchorPane>
<TitledPane collapsible="false" layoutX="12.0" layoutY="289.0" prefHeight="239.0" prefWidth="402.0" text="Image settings">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0">
<Slider fx:id="rotateSpeedSlider" blockIncrement="0.05" layoutX="116.0" layoutY="90.0" majorTickUnit="1.0" max="10.0" prefHeight="38.0" prefWidth="270.0" showTickLabels="true" showTickMarks="true" />
<Label layoutX="33.0" layoutY="88.0" text="Rotate speed">
<font>
<Font size="13.0" />
</font>
</Label>
<Slider fx:id="translationSpeedSlider" blockIncrement="0.05" layoutX="116.0" layoutY="128.0" majorTickUnit="1.0" max="10.0" prefHeight="38.0" prefWidth="270.0" showTickLabels="true" showTickMarks="true" />
<Label layoutX="7.0" layoutY="126.0" text="Translation speed">
<font>
<Font size="13.0" />
</font>
</Label>
<Slider fx:id="scaleSlider" blockIncrement="0.05" layoutX="116.0" layoutY="167.0" majorTickUnit="1.0" max="10.0" prefHeight="38.0" prefWidth="270.0" showTickLabels="true" showTickMarks="true" value="1.0" />
<Label layoutX="79.0" layoutY="164.0" text="Scale">
<font>
<Font size="13.0" />
</font>
</Label>
<Label layoutX="43.0" layoutY="49.0" text="Line weight">
<font>
<Font size="13.0" />
</font>
</Label>
<TextField fx:id="translationXTextField" layoutX="138.0" layoutY="15.0" prefHeight="26.0" prefWidth="70.0" text="0" />
<Label layoutX="47.0" layoutY="18.0" text="Translation" />
<Label layoutX="120.0" layoutY="18.0" text="x :" />
<Label layoutX="219.0" layoutY="18.0" text="y :" />
<TextField fx:id="translationYTextField" layoutX="238.0" layoutY="15.0" prefHeight="26.0" prefWidth="70.0" text="0" />
<Slider fx:id="weightSlider" blockIncrement="1.0" layoutX="116.0" layoutY="52.0" majorTickUnit="100.0" max="1000.0" prefHeight="38.0" prefWidth="269.0" showTickLabels="true" showTickMarks="true" value="100.0" />
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0">
<children>
<Slider fx:id="rotateSpeedSlider" blockIncrement="0.05" layoutX="116.0" layoutY="90.0" majorTickUnit="1.0" max="10.0" prefHeight="38.0" prefWidth="270.0" showTickLabels="true" showTickMarks="true" />
<Label layoutX="33.0" layoutY="88.0" text="Rotate speed">
<font>
<Font size="13.0" />
</font>
</Label>
<Slider fx:id="translationSpeedSlider" blockIncrement="0.05" layoutX="116.0" layoutY="128.0" majorTickUnit="1.0" max="10.0" prefHeight="38.0" prefWidth="270.0" showTickLabels="true" showTickMarks="true" />
<Label layoutX="7.0" layoutY="126.0" text="Translation speed">
<font>
<Font size="13.0" />
</font>
</Label>
<Slider fx:id="scaleSlider" blockIncrement="0.05" layoutX="116.0" layoutY="167.0" majorTickUnit="1.0" max="10.0" prefHeight="38.0" prefWidth="270.0" showTickLabels="true" showTickMarks="true" value="1.0" />
<Label layoutX="79.0" layoutY="164.0" text="Scale">
<font>
<Font size="13.0" />
</font>
</Label>
<Label layoutX="43.0" layoutY="49.0" text="Line weight">
<font>
<Font size="13.0" />
</font>
</Label>
<TextField fx:id="translationXTextField" layoutX="138.0" layoutY="15.0" prefHeight="26.0" prefWidth="70.0" text="0" />
<Label layoutX="47.0" layoutY="18.0" text="Translation" />
<Label layoutX="120.0" layoutY="18.0" text="x :" />
<Label layoutX="219.0" layoutY="18.0" text="y :" />
<TextField fx:id="translationYTextField" layoutX="238.0" layoutY="15.0" prefHeight="26.0" prefWidth="70.0" text="0" />
<Slider fx:id="weightSlider" blockIncrement="1.0" layoutX="116.0" layoutY="52.0" majorTickUnit="100.0" max="1000.0" prefHeight="38.0" prefWidth="269.0" showTickLabels="true" showTickMarks="true" value="100.0" />
</children>
</AnchorPane>
</content>
</TitledPane>
</AnchorPane>