Skip to content

Commit 7025279

Browse files
committed
add support from changing the timeFilter, hue frame rate and hue colors from the ui
1 parent fcc7d61 commit 7025279

11 files changed

Lines changed: 152 additions & 42 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ hs_err_pid*
3939

4040
# Config files
4141
/application.properties
42+
/color.properties

src/main/java/com/lazydash/audio/visualizer/Main.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
import com.lazydash.audio.visualizer.external.hue.manager.HueIntegrationManager;
77
import com.lazydash.audio.visualizer.system.config.AppConfig;
88
import com.lazydash.audio.visualizer.system.config.WindowConfig;
9-
import com.lazydash.audio.visualizer.system.persistance.ConfigurationService;
9+
import com.lazydash.audio.visualizer.system.persistance.AppConfigPersistence;
10+
import com.lazydash.audio.visualizer.system.persistance.ColorConfigPersistence;
1011
import com.lazydash.audio.visualizer.system.setup.SystemSetup;
1112
import com.lazydash.audio.visualizer.ui.code.color.GlobalColorAnimator;
1213
import com.lazydash.audio.visualizer.ui.code.color.GlobalColorView;
@@ -51,7 +52,8 @@ public static void main(String[] args) {
5152
@Override
5253
public void start(Stage stage) throws Exception {
5354
// create
54-
ConfigurationService configurationService = ConfigurationService.createAndReadConfiguration();
55+
AppConfigPersistence appConfigPersistence = AppConfigPersistence.createAndReadConfiguration();
56+
ColorConfigPersistence colorConfigPersistence = ColorConfigPersistence.createAndReadColorConfiguration();
5557
TarsosAudioEngine tarsosAudioEngine = new TarsosAudioEngine();
5658
HueIntegration hueIntegration = new HueIntegration();
5759

@@ -80,7 +82,7 @@ public void start(Stage stage) throws Exception {
8082
tarsosAudioEngine.getFttListenerList().add(globalColorFFTService);
8183

8284
wireSettingsStage(settingsStage, scene);
83-
wirePrimaryStage(stage, configurationService);
85+
wirePrimaryStage(stage, appConfigPersistence, colorConfigPersistence);
8486

8587
// run
8688
tarsosAudioEngine.start();
@@ -101,11 +103,12 @@ private void wireSettingsStage(Stage settingsStage, Scene rootScene) {
101103
});
102104
}
103105

104-
private void wirePrimaryStage(Stage primaryStage, ConfigurationService configurationService) {
106+
private void wirePrimaryStage(Stage primaryStage, AppConfigPersistence appConfigPersistence, ColorConfigPersistence colorConfigPersistence) {
105107
primaryStage.setOnCloseRequest(event -> {
106108
AppConfig.setWindowHeight(primaryStage.getHeight());
107109
AppConfig.setWindowWidth(primaryStage.getWidth());
108-
configurationService.persistConfig();
110+
appConfigPersistence.persistConfig();
111+
colorConfigPersistence.persistConfig();
109112
Platform.exit();
110113
});
111114
}

src/main/java/com/lazydash/audio/visualizer/core/algorithm/FrequencyBars.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,6 @@ public static List<FrequencyBar> createFrequencyBars(double[] binsHz, float[] am
2828
return frequencyBars;
2929
}
3030

31-
public static void updateFrequencyBars(List<FrequencyBar> frequencyBars, double[] binsHz, float[] amplitudes){
32-
for (int i = 0; i < frequencyBars.size(); i++) {
33-
FrequencyBar frequencyBar = frequencyBars.get(i);
34-
frequencyBar.setHz(binsHz[i]);
35-
frequencyBar.setHeight(amplitudes[i]);
36-
}
37-
}
38-
3931
private static void addColorsToFrequencyBars(List<FrequencyBar> frequencyBars, Color startColor, Color endColor, int startHz, int endHz){
4032
int countFreq = 0;
4133
for (FrequencyBar frequencyBar : frequencyBars) {

src/main/java/com/lazydash/audio/visualizer/core/service/FrequencyBarsFFTService.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,7 @@ public List<FrequencyBar> getFrequencyBarList(double targetFps) {
5454

5555
}
5656

57-
if (frequencyBarList.size() != returnBinz.length) {
58-
frequencyBarList = FrequencyBars.createFrequencyBars(returnBinz, returnAmplitudes);
59-
} else {
60-
FrequencyBars.updateFrequencyBars(frequencyBarList, returnBinz, returnAmplitudes);
61-
}
57+
frequencyBarList = FrequencyBars.createFrequencyBars(returnBinz, returnAmplitudes);
6258

6359
return frequencyBarList;
6460

src/main/java/com/lazydash/audio/visualizer/system/config/ColorConfig.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,9 @@ public class ColorConfig {
1111

1212
public static List<ColorBand> colorBands = Arrays.asList(
1313
new ColorBand(
14-
Color.color(0, 0, 1, 1),
15-
Color.color(0.5, 0.0, 0.5, 1),
14+
Color.color(0.0, 0.0, 1.0),
15+
Color.color(0.8, 0.0, 0.5),
1616
Integer.MIN_VALUE,
17-
80),
18-
19-
new ColorBand(
20-
Color.color(0.5, 0, 0.5, 1),
21-
Color.color(1.0, 0.0, 0.5, 1),
22-
81,
2317
Integer.MAX_VALUE)
2418
);
2519
}

src/main/java/com/lazydash/audio/visualizer/system/persistance/ConfigurationService.java renamed to src/main/java/com/lazydash/audio/visualizer/system/persistance/AppConfigPersistence.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@
1212
import java.util.Properties;
1313
import java.util.stream.Stream;
1414

15-
public class ConfigurationService {
16-
private String applicationProperties = "application.properties";
15+
public class AppConfigPersistence {
16+
private String applicationPropertiesLocation = "application.properties";
1717

18-
public static ConfigurationService createAndReadConfiguration() {
19-
ConfigurationService configurationService = new ConfigurationService();
20-
configurationService.readConfig();
21-
return configurationService;
18+
public static AppConfigPersistence createAndReadConfiguration() {
19+
AppConfigPersistence appConfigPersistence = new AppConfigPersistence();
20+
appConfigPersistence.readConfig();
21+
return appConfigPersistence;
2222
}
2323

2424
private void readConfig() {
25-
Path applicationPropertiesPath = Paths.get(applicationProperties);
25+
Path applicationPropertiesPath = Paths.get(applicationPropertiesLocation);
2626
if (Files.exists(applicationPropertiesPath)) {
2727

2828
Properties appProps = new Properties();
2929
try {
30-
appProps.load(new FileReader(applicationProperties));
30+
appProps.load(new FileReader(applicationPropertiesLocation));
3131

3232
} catch (IOException e) {
3333
e.printStackTrace();
@@ -82,7 +82,7 @@ public void persistConfig() {
8282

8383

8484
try {
85-
appProps.store(new FileWriter(applicationProperties), "Bass Frequency Analyzer");
85+
appProps.store(new FileWriter(applicationPropertiesLocation), "visualizer - config");
8686

8787
} catch (IOException e) {
8888
e.printStackTrace();
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package com.lazydash.audio.visualizer.system.persistance;
2+
3+
import com.lazydash.audio.visualizer.system.config.ColorConfig;
4+
import javafx.scene.paint.Color;
5+
6+
import java.io.FileReader;
7+
import java.io.FileWriter;
8+
import java.io.IOException;
9+
import java.nio.file.Files;
10+
import java.nio.file.Path;
11+
import java.nio.file.Paths;
12+
import java.util.Properties;
13+
14+
public class ColorConfigPersistence {
15+
private String colorPropertiesLocation = "color.properties";
16+
17+
public static ColorConfigPersistence createAndReadColorConfiguration() {
18+
ColorConfigPersistence colorConfigPersistence = new ColorConfigPersistence();
19+
colorConfigPersistence.readConfig();
20+
return colorConfigPersistence;
21+
}
22+
23+
private void readConfig() {
24+
Path colorPropertiesPath = Paths.get(colorPropertiesLocation);
25+
if (Files.exists(colorPropertiesPath)) {
26+
27+
Properties appProps = new Properties();
28+
try {
29+
appProps.load(new FileReader(colorPropertiesLocation));
30+
31+
String startColor = appProps.getProperty("startColor");
32+
String endColor = appProps.getProperty("endColor");
33+
34+
ColorConfig.colorBands.get(0).setStartColor(
35+
Color.web(startColor)
36+
);
37+
38+
ColorConfig.colorBands.get(0).setEndColor(
39+
Color.web(endColor)
40+
);
41+
42+
} catch (IOException e) {
43+
e.printStackTrace();
44+
}
45+
46+
47+
}
48+
}
49+
50+
public void persistConfig() {
51+
Properties appProps = new Properties();
52+
53+
Color startColor = ColorConfig.colorBands.get(0).getStartColor();
54+
Color endColor = ColorConfig.colorBands.get(0).getEndColor();
55+
56+
String startColorHex = toRGBCode(startColor);
57+
String endColorHex = toRGBCode(endColor);
58+
59+
appProps.setProperty("startColor", startColorHex);
60+
appProps.setProperty("endColor", endColorHex);
61+
62+
try {
63+
appProps.store(new FileWriter(colorPropertiesLocation), "visualizer - colors");
64+
65+
} catch (IOException e) {
66+
e.printStackTrace();
67+
}
68+
}
69+
70+
private String toRGBCode( Color color ) {
71+
return String.format( "#%02X%02X%02X",
72+
(int)( color.getRed() * 255 ),
73+
(int)( color.getGreen() * 255 ),
74+
(int)( color.getBlue() * 255 ) );
75+
}
76+
77+
}

src/main/java/com/lazydash/audio/visualizer/ui/fxml/settings/components/HueIntegrationController.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
import javafx.application.Platform;
88
import javafx.event.ActionEvent;
99
import javafx.scene.control.Label;
10+
import javafx.scene.control.Spinner;
1011
import javafx.scene.control.TextField;
1112
import javafx.scene.input.KeyEvent;
1213

1314
public class HueIntegrationController {
1415
public Label hueStatus;
1516
public TextField hueEntertainmentName;
17+
public Spinner<Integer> hueTargetFrameRate;
1618

1719
public void initialize() {
1820
hueStatus.setText(AppConfig.getHueStatus());
@@ -25,6 +27,11 @@ public void run(String message) {
2527
});
2628

2729
hueEntertainmentName.setText(AppConfig.getHueEntertainmentName());
30+
31+
hueTargetFrameRate.getValueFactory().setValue((int) AppConfig.getHueTargetFPS());
32+
hueTargetFrameRate.valueProperty().addListener((observable, oldValue, newValue) -> {
33+
AppConfig.setHueTargetFPS(newValue);
34+
});
2835
}
2936

3037
public void stopHueIntegration(ActionEvent actionEvent) {

src/main/java/com/lazydash/audio/visualizer/ui/fxml/settings/components/SpectralViewController.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package com.lazydash.audio.visualizer.ui.fxml.settings.components;
22

33
import com.lazydash.audio.visualizer.system.config.AppConfig;
4+
import com.lazydash.audio.visualizer.system.config.ColorConfig;
45
import javafx.beans.value.ChangeListener;
56
import javafx.beans.value.ObservableValue;
7+
import javafx.scene.control.ColorPicker;
68
import javafx.scene.control.Label;
79
import javafx.scene.control.Slider;
810
import javafx.scene.control.Spinner;
@@ -16,6 +18,9 @@ public class SpectralViewController {
1618
public Slider signalThreshold;
1719
public Label signalAmplificationValue;
1820
public Label signalThresholdValue;
21+
public Spinner<Integer> timeFilter;
22+
public ColorPicker startColor;
23+
public ColorPicker endColor;
1924

2025
public void initialize() {
2126
signalAmplificationValue.setText(String.valueOf(AppConfig.getSignalAmplification()));
@@ -38,6 +43,11 @@ public void changed(ObservableValue<? extends Number> observable, Number oldValu
3843
}
3944
});
4045

46+
timeFilter.getValueFactory().setValue(AppConfig.getTimeFilterSize());
47+
timeFilter.valueProperty().addListener((observable, oldValue, newValue) -> {
48+
AppConfig.setTimeFilterSize(newValue);
49+
});
50+
4151
barNumber.getValueFactory().setValue(AppConfig.getBarNumber());
4252
barNumber.valueProperty().addListener((observable, oldValue, newValue) -> {
4353
AppConfig.setBarNumber(newValue);
@@ -52,5 +62,15 @@ public void changed(ObservableValue<? extends Number> observable, Number oldValu
5262
minBarHeight.valueProperty().addListener((observable, oldValue, newValue) -> {
5363
AppConfig.setMinBarHeight(newValue);
5464
});
65+
66+
startColor.setValue(ColorConfig.colorBands.get(0).getStartColor());
67+
startColor.valueProperty().addListener((observable, oldValue, newValue) -> {
68+
ColorConfig.colorBands.get(0).setStartColor(newValue);
69+
});
70+
71+
endColor.setValue(ColorConfig.colorBands.get(0).getEndColor());
72+
endColor.valueProperty().addListener((observable, oldValue, newValue) -> {
73+
ColorConfig.colorBands.get(0).setEndColor(newValue);
74+
});
5575
}
5676
}

src/main/resources/ui.fxml.settings/components/hue_integration.fxml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,14 @@
1616
<Label text="Entertainment name:" GridPane.rowIndex="1" GridPane.columnIndex="0" GridPane.halignment="RIGHT"/>
1717
<TextField fx:id="hueEntertainmentName" onKeyReleased="#updateHueEntertainmentName" GridPane.rowIndex="1" GridPane.columnIndex="1"/>
1818

19-
<HBox styleClass="button-group" GridPane.rowIndex="2" GridPane.columnIndex="1" GridPane.halignment="RIGHT"
19+
<Label text="Target frame rate:" GridPane.rowIndex="2" GridPane.columnIndex="0" GridPane.halignment="RIGHT"/>
20+
<Spinner fx:id="hueTargetFrameRate" editable="true" GridPane.rowIndex="2" GridPane.columnIndex="1">
21+
<valueFactory>
22+
<SpinnerValueFactory.IntegerSpinnerValueFactory min="1" max="60" amountToStepBy="1"/>
23+
</valueFactory>
24+
</Spinner>
25+
26+
<HBox styleClass="button-group" GridPane.rowIndex="3" GridPane.columnIndex="1" GridPane.halignment="RIGHT"
2027
alignment="CENTER_RIGHT">
2128
<Button text="Stop" onAction="#stopHueIntegration"/>
2229
<Button text="Start" onAction="#startHueIntegration"/>

0 commit comments

Comments
 (0)