Skip to content

Commit

Permalink
PinVOL settings
Browse files Browse the repository at this point in the history
  • Loading branch information
syd711 committed Jan 26, 2025
1 parent 6df1009 commit 24b6144
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 27 deletions.
3 changes: 2 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
- **Highscore Settings**: Removed configuration option for highscore titles, e.g. "GRAND CHAMPION". These values are now part of the internal scoring database so that the user never has to deal with this kind of stuff.
- **Highscore Parsing**: Fixed highscores for tables **Defender, Black Pyramid and Catacomb**.
- **Tables / Playlists**: Renamed **Local Favorites** to **Playlist Favorites**.
- **Tables / PinVOL Settings**: The user interface for the PinVOL settings used the SSF DB limit value now. You can't configure this via Studio yet and have to configure it once via the PinVOL UI.
- **PinballX Frontend**: fixed zero byte download by using FTP passive mode, then try active mode if failure
- **System Manager**: Fixed Backglass Server update detection.
- **System Manager**: Fixed **Backglass Server** update detection.

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ public class PinVolPreferences {
private int global = 0;
private int night = 0;
private int defaultVol = 0;
private int ssfDbLimit = 10;

public int getSsfDbLimit() {
return ssfDbLimit;
}

public void setSsfDbLimit(int ssfDbLimit) {
this.ssfDbLimit = ssfDbLimit;
}

public int getGlobal() {
return global;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,29 +66,29 @@ public void applyValues(PinVolTableEntry tableVolume) {
setSecondaryVolume(tableVolume.getSecondaryVolume());
}

public String toSettingsString() {
public String toSettingsString(int ssfDbLimit) {
StringBuilder builder = new StringBuilder(getName());
builder.append("\t");
builder.append(getPrimaryVolume());
builder.append("\t");
builder.append(getSecondaryVolume());
builder.append("\t");
builder.append(formatGainValue(getSsfBassVolume()));
builder.append(formatGainValue(getSsfBassVolume(), ssfDbLimit));
builder.append("\t");
builder.append(formatGainValue(getSsfRearVolume()));
builder.append(formatGainValue(getSsfRearVolume(), ssfDbLimit));
builder.append("\t");
builder.append(formatGainValue(getSsfFrontVolume()));
builder.append(formatGainValue(getSsfFrontVolume(), ssfDbLimit));
builder.append("\n");
return builder.toString();
}

public static int formatGainValue(int i) {
public static int formatGainValue(int i, int ssfDbLimit) {
try {
if (i < -10) {
i = -10;
if (i < -ssfDbLimit) {
i = -ssfDbLimit;
}
else if (i > 10) {
i = 10;
else if (i > ssfDbLimit) {
i = ssfDbLimit;
}
return i;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ public PinVolPreferences getPinVolTablePreferences() {
private void loadIni() {
preferences = new PinVolPreferences();
try {
INIConfiguration pinVolSettingsConfig = getPinVolSettingsConfig();
if (pinVolSettingsConfig != null) {
preferences.setSsfDbLimit(pinVolSettingsConfig.getInt("SSFdBLimit", 10));
}

File tablesIni = getPinVolTablesIniFile();
if (!tablesIni.exists()) {
LOG.info("PinVol service table settings have not been loaded, because {} was not found.", tablesIni.getAbsolutePath());
Expand All @@ -120,7 +125,7 @@ private void loadIni() {
try (FileInputStream fileInputStream = new FileInputStream(tablesIni)) {
List<String> entries = IOUtils.readLines(fileInputStream, StandardCharsets.UTF_8);
for (String entry : entries) {
PinVolTableEntry e = createEntry(entry);
PinVolTableEntry e = createEntry(entry, preferences.getSsfDbLimit());
if (e != null) {
preferences.getTableEntries().add(e);
}
Expand Down Expand Up @@ -152,28 +157,29 @@ private void loadIni() {
}
}

private PinVolTableEntry createEntry(String line) {
private PinVolTableEntry createEntry(String line, int ssfDbLimit) {
String[] split = line.split("\\t");
if (split.length == 6) {
PinVolTableEntry entry = new PinVolTableEntry();
entry.setName(split[0]);
entry.setPrimaryVolume(Integer.parseInt(split[1]));
entry.setSecondaryVolume(Integer.parseInt(split[2]));
entry.setSsfBassVolume(parseGainValue(split[3]));
entry.setSsfRearVolume(parseGainValue(split[4]));
entry.setSsfFrontVolume(parseGainValue(split[5]));

entry.setSsfBassVolume(parseGainValue(split[3], ssfDbLimit));
entry.setSsfRearVolume(parseGainValue(split[4], ssfDbLimit));
entry.setSsfFrontVolume(parseGainValue(split[5], ssfDbLimit));
return entry;
}
return null;
}

private int parseGainValue(String value) {
private int parseGainValue(String value, int ssfDbLimit) {
try {
if (StringUtils.isEmpty(value)) {
return 0;
}
int i = Integer.parseInt(value);
return PinVolTableEntry.formatGainValue(i);
return PinVolTableEntry.formatGainValue(i, ssfDbLimit);
}
catch (NumberFormatException e) {
return 0;
Expand All @@ -184,13 +190,22 @@ private static File getPinVolTablesIniFile() {
return new File(SystemService.RESOURCES, "PinVolTables.ini");
}

private static File getPinVolSettingsIniFile() {
return new File(SystemService.RESOURCES, "PinVolSettings.ini");
}

private static File getPinVolVolIniFile() {
return new File(SystemService.RESOURCES, "PinVolVol.ini");
}

private void initListener() {
FileMonitoringThread monitoringThread = new FileMonitoringThread(this, getPinVolTablesIniFile(), true);
monitoringThread.startMonitoring();

if (getPinVolSettingsIniFile().exists()) {
FileMonitoringThread settingsThread = new FileMonitoringThread(this, getPinVolSettingsIniFile(), true);
settingsThread.startMonitoring();
}
}

public PinVolPreferences update(@NonNull PinVolUpdate update) {
Expand Down Expand Up @@ -228,7 +243,7 @@ private PinVolPreferences saveIniFile(PinVolPreferences preferences) {

List<PinVolTableEntry> tableEntries = preferences.getTableEntries();
for (PinVolTableEntry tableEntry : tableEntries) {
String value = tableEntry.toSettingsString();
String value = tableEntry.toSettingsString(preferences.getSsfDbLimit());
builder.append(value);
}

Expand Down Expand Up @@ -261,9 +276,35 @@ public void delete(@NonNull Game game) {
}
}

@Nullable
private INIConfiguration getPinVolSettingsConfig() {
try {
File volIni = getPinVolSettingsIniFile();
if (volIni.exists()) {
INIConfiguration iniConfiguration = new INIConfiguration();
iniConfiguration.setCommentLeadingCharsUsedInInput(";");
iniConfiguration.setSeparatorUsedInOutput("=");
iniConfiguration.setSeparatorUsedInInput("=");

try (FileReader fileReader = new FileReader(volIni)) {
iniConfiguration.read(fileReader);
}

return iniConfiguration;
}
else {
LOG.info("Skipped loading of {}, file not found.", volIni.getAbsolutePath());
}
}
catch (Exception e) {
LOG.error("Failed to load {}", "PinVolSettings.ini", e);
}
return null;
}

@Override
public void notifyFileChange(@Nullable File file) {
LOG.info("PinVolTable.ini changed");
LOG.info("PinVolSettings changed");
loadIni();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public void setData(Stage stage, List<GameRepresentation> games, boolean showSys

PinVolPreferences pinVolTablePreferences = client.getPinVolService().getPinVolTablePreferences();
systemVolume = pinVolTablePreferences.getSystemVolume();
int ssfDbLimit = pinVolTablePreferences.getSsfDbLimit();

SpinnerValueFactory.IntegerSpinnerValueFactory factory1 = new SpinnerValueFactory.IntegerSpinnerValueFactory(0, 100, systemVolume.getPrimaryVolume());
systemVolPrimarySpinner.setValueFactory(factory1);
Expand All @@ -153,21 +154,21 @@ public void setData(Stage stage, List<GameRepresentation> games, boolean showSys
dirty = true;
}, 300));

SpinnerValueFactory.IntegerSpinnerValueFactory factory3 = new SpinnerValueFactory.IntegerSpinnerValueFactory(-10, 10, systemVolume.getSsfBassVolume());
SpinnerValueFactory.IntegerSpinnerValueFactory factory3 = new SpinnerValueFactory.IntegerSpinnerValueFactory(-ssfDbLimit, ssfDbLimit, systemVolume.getSsfBassVolume());
systemVolBassSpinner.setValueFactory(factory3);
factory3.valueProperty().addListener((observableValue, integer, t1) -> debouncer.debounce("systemVolBassSpinner", () -> {
systemVolume.setSsfBassVolume(t1);
dirty = true;
}, 300));

SpinnerValueFactory.IntegerSpinnerValueFactory factory4 = new SpinnerValueFactory.IntegerSpinnerValueFactory(-10, 10, systemVolume.getSsfFrontVolume());
SpinnerValueFactory.IntegerSpinnerValueFactory factory4 = new SpinnerValueFactory.IntegerSpinnerValueFactory(-ssfDbLimit, ssfDbLimit, systemVolume.getSsfFrontVolume());
systemVolFrontSpinner.setValueFactory(factory4);
factory4.valueProperty().addListener((observableValue, integer, t1) -> debouncer.debounce("systemVolFrontSpinner", () -> {
systemVolume.setSsfFrontVolume(t1);
dirty = true;
}, 300));

SpinnerValueFactory.IntegerSpinnerValueFactory factory5 = new SpinnerValueFactory.IntegerSpinnerValueFactory(-10, 10, systemVolume.getSsfRearVolume());
SpinnerValueFactory.IntegerSpinnerValueFactory factory5 = new SpinnerValueFactory.IntegerSpinnerValueFactory(-ssfDbLimit, ssfDbLimit, systemVolume.getSsfRearVolume());
systemVolRearSpinner.setValueFactory(factory5);
factory5.valueProperty().addListener((observableValue, integer, t1) -> debouncer.debounce("systemVolRearSpinner", () -> {
systemVolume.setSsfRearVolume(t1);
Expand All @@ -193,11 +194,11 @@ public void setData(Stage stage, List<GameRepresentation> games, boolean showSys
}

if (!games.isEmpty()) {
setTableValues(systemVolume);
setTableValues(systemVolume, ssfDbLimit);
}
}

private void setTableValues(PinVolTableEntry systemVolume) {
private void setTableValues(PinVolTableEntry systemVolume, int ssfDbLimit) {
if (entry == null) {
entry = new PinVolTableEntry();
entry.setPrimaryVolume(client.getPinVolService().getPinVolTablePreferences().getDefaultVol());
Expand All @@ -221,21 +222,21 @@ private void setTableValues(PinVolTableEntry systemVolume) {
dirty = true;
}, 300));

SpinnerValueFactory.IntegerSpinnerValueFactory factory8 = new SpinnerValueFactory.IntegerSpinnerValueFactory(-10, 10, entry.getSsfBassVolume());
SpinnerValueFactory.IntegerSpinnerValueFactory factory8 = new SpinnerValueFactory.IntegerSpinnerValueFactory(-ssfDbLimit, ssfDbLimit, entry.getSsfBassVolume());
tableVolBassSpinner.setValueFactory(factory8);
factory8.valueProperty().addListener((observableValue, integer, t1) -> debouncer.debounce(PreferenceNames.IDLE_TIMEOUT, () -> {
entry.setSsfBassVolume(t1);
dirty = true;
}, 300));

SpinnerValueFactory.IntegerSpinnerValueFactory factory9 = new SpinnerValueFactory.IntegerSpinnerValueFactory(-10, 10, entry.getSsfFrontVolume());
SpinnerValueFactory.IntegerSpinnerValueFactory factory9 = new SpinnerValueFactory.IntegerSpinnerValueFactory(-ssfDbLimit, ssfDbLimit, entry.getSsfFrontVolume());
tableVolFrontSpinner.setValueFactory(factory9);
factory9.valueProperty().addListener((observableValue, integer, t1) -> debouncer.debounce(PreferenceNames.IDLE_TIMEOUT, () -> {
entry.setSsfFrontVolume(t1);
dirty = true;
}, 300));

SpinnerValueFactory.IntegerSpinnerValueFactory factory10 = new SpinnerValueFactory.IntegerSpinnerValueFactory(-10, 10, entry.getSsfRearVolume());
SpinnerValueFactory.IntegerSpinnerValueFactory factory10 = new SpinnerValueFactory.IntegerSpinnerValueFactory(-ssfDbLimit, ssfDbLimit, entry.getSsfRearVolume());
tableVolRearSpinner.setValueFactory(factory10);
factory10.valueProperty().addListener((observableValue, integer, t1) -> debouncer.debounce(PreferenceNames.IDLE_TIMEOUT, () -> {
entry.setSsfRearVolume(t1);
Expand Down

0 comments on commit 24b6144

Please sign in to comment.