修改配置类的代码逻辑:

设立一个全局的类(GlobalConfig)专门存放相关的配置类,以静态变量的方式访问这些配置实例。
而不是像以前那样一个动态变量传来传去,眼都看花了...
main
lensfrex 3 years ago
parent 1a091588f5
commit 58d2dbbe62
Signed by: lensfrex
GPG Key ID: 0F69A0A2FBEE98A0
  1. 4
      Dogename/dogename.iml
  2. 52
      Dogename/src/main/java/me/lensferno/dogename/configs/ConfigLoader.java
  3. 6
      Dogename/src/main/java/me/lensferno/dogename/configs/GlobalConfig.java
  4. 40
      Dogename/src/main/java/me/lensferno/dogename/configs/MainConfig.java
  5. 52
      Dogename/src/main/java/me/lensferno/dogename/controllers/MainInterfaceController.java
  6. 29
      Dogename/src/main/java/me/lensferno/dogename/controllers/MiniPaneController.java
  7. 62
      Dogename/src/main/java/me/lensferno/dogename/controllers/SettingsPaneController.java
  8. 17
      Dogename/src/main/java/me/lensferno/dogename/controllers/VoiceSettingsPaneController.java
  9. 25
      Dogename/src/main/java/me/lensferno/dogename/select/Selector.java
  10. 24
      Dogename/src/main/java/me/lensferno/dogename/select/core/Worker.java
  11. 22
      Dogename/src/main/java/me/lensferno/dogename/voice/VoicePlayer.java
  12. 22
      Dogename/src/main/resources/me/lensferno/dogename/FXMLs/SettingsPane.fxml

@ -19,5 +19,9 @@
<orderEntry type="library" name="Maven: org.json:json:20160810" level="project" /> <orderEntry type="library" name="Maven: org.json:json:20160810" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" /> <orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-simple:1.7.25" level="project" /> <orderEntry type="library" name="Maven: org.slf4j:slf4j-simple:1.7.25" level="project" />
<orderEntry type="library" name="Maven: com.googlecode.soundlibs:mp3spi:1.9.5.4" level="project" />
<orderEntry type="library" name="Maven: com.googlecode.soundlibs:jlayer:1.0.1.4" level="project" />
<orderEntry type="library" name="Maven: junit:junit:3.8.2" level="project" />
<orderEntry type="library" name="Maven: com.googlecode.soundlibs:tritonus-share:0.3.7.4" level="project" />
</component> </component>
</module> </module>

@ -20,8 +20,6 @@ import java.nio.charset.StandardCharsets;
public class ConfigLoader { public class ConfigLoader {
private final String mainConfigLocation = FilePath.toSpecificPathForm("files/Config.json"); private final String mainConfigLocation = FilePath.toSpecificPathForm("files/Config.json");
private final String voiceConfigLocation = FilePath.toSpecificPathForm("files/VoiceConfig.json"); private final String voiceConfigLocation = FilePath.toSpecificPathForm("files/VoiceConfig.json");
//ConfigValuesBean config;
private MainConfig mainConfig;
public String getMainConfigLocation() { public String getMainConfigLocation() {
return mainConfigLocation; return mainConfigLocation;
@ -31,11 +29,7 @@ public class ConfigLoader {
return voiceConfigLocation; return voiceConfigLocation;
} }
public MainConfig getMainConfig() { public void readMainConfig(String fileLocation) {
return mainConfig;
}
public MainConfig readConfigFromFile(String fileLocation) {
//property属性应该要自定义一个json适配器才能解析出来 //property属性应该要自定义一个json适配器才能解析出来
Gson gson = new GsonBuilder() Gson gson = new GsonBuilder()
.registerTypeAdapter(SimpleBooleanProperty.class, new BooleanPropertyAdapter()) .registerTypeAdapter(SimpleBooleanProperty.class, new BooleanPropertyAdapter())
@ -52,34 +46,29 @@ public class ConfigLoader {
if (!configFile.exists()) { if (!configFile.exists()) {
configFile.getParentFile().mkdirs(); configFile.getParentFile().mkdirs();
configFile.createNewFile(); configFile.createNewFile();
mainConfig = new MainConfig(); GlobalConfig.mainConfig = new MainConfig();
writeMainConfigToFile(mainConfigLocation); writeMainConfigToFile(mainConfigLocation);
return mainConfig; return;
} }
InputStream inputStream = new FileInputStream(configFile); InputStream inputStream = new FileInputStream(configFile);
configJson = IOUtils.toString(inputStream, StandardCharsets.UTF_8); configJson = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
inputStream.close(); inputStream.close();
mainConfig = gson.fromJson(configJson, MainConfig.class); GlobalConfig.mainConfig = gson.fromJson(configJson, MainConfig.class);
if (mainConfig == null) { if (GlobalConfig.mainConfig == null) {
mainConfig = new MainConfig(); GlobalConfig.mainConfig = new MainConfig();
writeMainConfigToFile(mainConfigLocation); writeMainConfigToFile(mainConfigLocation);
return mainConfig;
} }
} catch (Exception e) { } catch (Exception e) {
System.out.println("Error to load config file:" + e + "\nUse Default config."); System.out.println("Error to load config file:" + e + "\nUse Default config.");
mainConfig = new MainConfig(); GlobalConfig.mainConfig = new MainConfig();
writeMainConfigToFile(mainConfigLocation); writeMainConfigToFile(mainConfigLocation);
return mainConfig;
} }
return this.mainConfig;
} }
public VoiceConfig readVoiceConfigFromFile(String fileLocation) { public void loadVoiceConfig(String fileLocation) {
//property属性应该要自定义一个json适配器才能解析出来 //property属性应该要自定义一个json适配器才能解析出来
Gson gson = new GsonBuilder() Gson gson = new GsonBuilder()
.registerTypeAdapter(SimpleBooleanProperty.class, new BooleanPropertyAdapter()) .registerTypeAdapter(SimpleBooleanProperty.class, new BooleanPropertyAdapter())
@ -97,31 +86,26 @@ public class ConfigLoader {
configFile.getParentFile().mkdirs(); configFile.getParentFile().mkdirs();
configFile.createNewFile(); configFile.createNewFile();
VoicePlayer.voiceConfig = new VoiceConfig(); GlobalConfig.voiceConfig = new VoiceConfig();
writeVoiceConfigToFile(voiceConfigLocation); writeVoiceConfigToFile(voiceConfigLocation);
return VoicePlayer.voiceConfig; return;
} }
InputStream inputStream = new FileInputStream(configFile); InputStream inputStream = new FileInputStream(configFile);
configJson = IOUtils.toString(inputStream, StandardCharsets.UTF_8); configJson = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
inputStream.close(); inputStream.close();
VoicePlayer.voiceConfig = gson.fromJson(configJson, VoiceConfig.class); GlobalConfig.voiceConfig = gson.fromJson(configJson, VoiceConfig.class);
if (VoicePlayer.voiceConfig == null) { if (GlobalConfig.voiceConfig == null) {
VoicePlayer.voiceConfig = new VoiceConfig(); GlobalConfig.voiceConfig = new VoiceConfig();
writeVoiceConfigToFile(voiceConfigLocation); writeVoiceConfigToFile(voiceConfigLocation);
return VoicePlayer.voiceConfig;
} }
} catch (Exception e) { } catch (Exception e) {
System.out.println("Error to load voice config file:" + e + "\nUse Default voice config."); System.out.println("Error to load voice config file:" + e + "\nUse Default voice config.");
VoicePlayer.voiceConfig = new VoiceConfig(); GlobalConfig.voiceConfig = new VoiceConfig();
writeVoiceConfigToFile(voiceConfigLocation); writeVoiceConfigToFile(voiceConfigLocation);
return VoicePlayer.voiceConfig;
} }
return VoicePlayer.voiceConfig;
} }
private String toJSON(MainConfig config) { private String toJSON(MainConfig config) {
@ -154,10 +138,10 @@ public class ConfigLoader {
outputFile.createNewFile(); outputFile.createNewFile();
} }
OutputStream stream = new FileOutputStream(outputFile); OutputStream stream = new FileOutputStream(outputFile);
IOUtils.write(toJSON(this.mainConfig).getBytes(StandardCharsets.UTF_8), stream); IOUtils.write(toJSON(GlobalConfig.mainConfig).getBytes(StandardCharsets.UTF_8), stream);
OutputStream voiceConfigFileStream = new FileOutputStream(voiceConfigFile); OutputStream voiceConfigFileStream = new FileOutputStream(voiceConfigFile);
IOUtils.write(getConfigJson(VoicePlayer.voiceConfig).getBytes(StandardCharsets.UTF_8), voiceConfigFileStream); IOUtils.write(getConfigJson(GlobalConfig.voiceConfig).getBytes(StandardCharsets.UTF_8), voiceConfigFileStream);
} catch (Exception e) { } catch (Exception e) {
System.out.println("Error in writing all config:" + e); System.out.println("Error in writing all config:" + e);
@ -174,7 +158,7 @@ public class ConfigLoader {
} }
OutputStream stream = new FileOutputStream(outputFile); OutputStream stream = new FileOutputStream(outputFile);
IOUtils.write(toJSON(this.mainConfig).getBytes(StandardCharsets.UTF_8), stream); IOUtils.write(toJSON(GlobalConfig.mainConfig).getBytes(StandardCharsets.UTF_8), stream);
} catch (Exception e) { } catch (Exception e) {
System.out.println("Error in writing main config:" + e); System.out.println("Error in writing main config:" + e);
@ -191,7 +175,7 @@ public class ConfigLoader {
outputFile.createNewFile(); outputFile.createNewFile();
} }
OutputStream voiceConfigFileStream = new FileOutputStream(voiceConfigFile); OutputStream voiceConfigFileStream = new FileOutputStream(voiceConfigFile);
IOUtils.write(getConfigJson(VoicePlayer.voiceConfig).getBytes(StandardCharsets.UTF_8), voiceConfigFileStream); IOUtils.write(getConfigJson(GlobalConfig.voiceConfig).getBytes(StandardCharsets.UTF_8), voiceConfigFileStream);
} catch (Exception e) { } catch (Exception e) {
System.out.println("Error in writing voice config:" + e); System.out.println("Error in writing voice config:" + e);

@ -0,0 +1,6 @@
package me.lensferno.dogename.configs;
public class GlobalConfig {
public static VoiceConfig voiceConfig = null;
public static MainConfig mainConfig = null;
}

@ -8,9 +8,7 @@ import javafx.beans.property.SimpleStringProperty;
public class MainConfig { public class MainConfig {
// ---------------------- Default values --------------------------------------------------------- // ---------------------- Default values ---------------------------------------------------------
@Expose @Expose
public static final boolean DEFAULT_NAME_CHOOSE = true;
public static final int METHOD_NAME = 0; // 名字挑选法 public static final int METHOD_NAME = 0; // 名字挑选法
public static final int METHOD_NUMBER = 1; // 数字挑选法 public static final int METHOD_NUMBER = 1; // 数字挑选法
public static final int DEFAULT_MAX_TOTAL_COUNT = 120; // 默认轮回次数:120 public static final int DEFAULT_MAX_TOTAL_COUNT = 120; // 默认轮回次数:120
@ -21,13 +19,10 @@ public class MainConfig {
public static final boolean DEFAULT_NEW_ALGO = true; // 默认使用新算法"Java sec random" public static final boolean DEFAULT_NEW_ALGO = true; // 默认使用新算法"Java sec random"
public static final boolean DEFAULT_VOICE_PLAY = true; // 默认使用语音播报 public static final boolean DEFAULT_VOICE_PLAY = true; // 默认使用语音播报
public static final boolean DEFAULT_SHOW_SAYING = true; public static final boolean DEFAULT_SHOW_SAYING = true;
private final int currentVersion = 3;
// ----------------------Properties---------------------------------------------------------------- // ----------------------Properties----------------------------------------------------------------
private final SimpleBooleanProperty nameChoose;
private final SimpleBooleanProperty randomCount; // 挑选次数是否随机 private final SimpleBooleanProperty randomCount; // 挑选次数是否随机
private final SimpleBooleanProperty passSelectedResult; // 是否忽略已经被点过的名字/数字 private final SimpleBooleanProperty ignoreSelectedResult; // 是否忽略已经被点过的名字/数字
private final SimpleIntegerProperty chooseMethod; // 挑选方式: 0->名字挑选法 1->数字挑选法 private final SimpleIntegerProperty chooseMethod; // 挑选方式: 0->名字挑选法 1->数字挑选法
private final SimpleIntegerProperty maxTotalCount; // 挑选轮回次数 private final SimpleIntegerProperty maxTotalCount; // 挑选轮回次数
@ -47,10 +42,9 @@ public class MainConfig {
// -------------------------- 初始化 -------------------------------------------------------------- // -------------------------- 初始化 --------------------------------------------------------------
public MainConfig() { public MainConfig() {
randomCount = new SimpleBooleanProperty(DEFAULT_RANDOM_TIMES); randomCount = new SimpleBooleanProperty(DEFAULT_RANDOM_TIMES);
passSelectedResult = new SimpleBooleanProperty(DEFAULT_IGNORE_PAST); ignoreSelectedResult = new SimpleBooleanProperty(DEFAULT_IGNORE_PAST);
chooseMethod = new SimpleIntegerProperty(METHOD_NAME); chooseMethod = new SimpleIntegerProperty(METHOD_NAME);
nameChoose = new SimpleBooleanProperty(DEFAULT_NAME_CHOOSE);
maxTotalCount = new SimpleIntegerProperty(DEFAULT_MAX_TOTAL_COUNT); maxTotalCount = new SimpleIntegerProperty(DEFAULT_MAX_TOTAL_COUNT);
@ -68,19 +62,6 @@ public class MainConfig {
} }
// -------------------------- Getters and Setters --------------------------------------------- // -------------------------- Getters and Setters ---------------------------------------------
public boolean getNameChoose() {
return nameChoose.get();
}
public void setNameChoose(boolean nameChoose) {
this.nameChoose.set(nameChoose);
}
public SimpleBooleanProperty nameChooseProperty() {
return nameChoose;
}
public boolean getRandomCount() { public boolean getRandomCount() {
return randomCount.get(); return randomCount.get();
} }
@ -93,16 +74,16 @@ public class MainConfig {
return randomCount; return randomCount;
} }
public boolean getPassSelectedResult() { public boolean getIgnoreSelectedResult() {
return passSelectedResult.get(); return ignoreSelectedResult.get();
} }
public void setPassSelectedResult(boolean passSelectedResult) { public void setIgnoreSelectedResult(boolean ignoreSelectedResult) {
this.passSelectedResult.set(passSelectedResult); this.ignoreSelectedResult.set(ignoreSelectedResult);
} }
public SimpleBooleanProperty passSelectedResultProperty() { public SimpleBooleanProperty ignoreSelectedResultProperty() {
return passSelectedResult; return ignoreSelectedResult;
} }
public int getChooseMethod() { public int getChooseMethod() {
@ -212,9 +193,4 @@ public class MainConfig {
public SimpleBooleanProperty showSayingProperty() { public SimpleBooleanProperty showSayingProperty() {
return showSaying; return showSaying;
} }
public int getCurrentConfigVersion() {
return currentVersion;
}
} }

@ -16,17 +16,15 @@ import javafx.scene.layout.Pane;
import javafx.stage.Stage; import javafx.stage.Stage;
import javafx.stage.StageStyle; import javafx.stage.StageStyle;
import me.lensferno.dogename.configs.ConfigLoader; import me.lensferno.dogename.configs.ConfigLoader;
import me.lensferno.dogename.configs.GlobalConfig;
import me.lensferno.dogename.configs.MainConfig; import me.lensferno.dogename.configs.MainConfig;
import me.lensferno.dogename.configs.VoiceConfig;
import me.lensferno.dogename.data.Data; import me.lensferno.dogename.data.Data;
import me.lensferno.dogename.data.History; import me.lensferno.dogename.data.History;
import me.lensferno.dogename.select.Selector; import me.lensferno.dogename.select.Selector;
import me.lensferno.dogename.utils.DialogMaker; import me.lensferno.dogename.utils.DialogMaker;
import me.lensferno.dogename.utils.FilePath; import me.lensferno.dogename.utils.FilePath;
import me.lensferno.dogename.utils.ocr.OcrTool; import me.lensferno.dogename.utils.ocr.OcrTool;
import me.lensferno.dogename.voice.VoicePlayer;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Random; import java.util.Random;
@ -38,7 +36,6 @@ public final class MainInterfaceController {
OcrTool ocrTool = null; OcrTool ocrTool = null;
History history = new History(); History history = new History();
MainConfig mainConfig;
Random random = new Random(); Random random = new Random();
Data data = new Data(); Data data = new Data();
Selector selector = new Selector(); Selector selector = new Selector();
@ -72,14 +69,15 @@ public final class MainInterfaceController {
history.loadHistory(); history.loadHistory();
} }
private final ToggleGroup toggleGroup = new ToggleGroup();
public void bindProperties() { public void bindProperties() {
nameChoose.selectedProperty().bindBidirectional(mainConfig.nameChooseProperty()); nameChoose.setToggleGroup(toggleGroup);
numbChoose.setToggleGroup(toggleGroup);
numbChoose.selectedProperty().bind(mainConfig.nameChooseProperty().not());
numbChoose.selectedProperty().unbind();
mainConfig.nameChooseProperty().addListener((observable, oldValue, newValue) -> { toggleGroup.selectToggle(GlobalConfig.mainConfig.getChooseMethod() == MainConfig.METHOD_NAME ? nameChoose : numbChoose);
mainConfig.setChooseMethod(mainConfig.getNameChoose() ? MainConfig.METHOD_NAME : MainConfig.METHOD_NUMBER); toggleGroup.selectedToggleProperty().addListener((observable, oldValue, newValue) -> {
GlobalConfig.mainConfig.setChooseMethod(newValue == nameChoose ? MainConfig.METHOD_NAME : MainConfig.METHOD_NUMBER);
System.out.println("change!"+(newValue == nameChoose));
}); });
} }
@ -88,8 +86,8 @@ public final class MainInterfaceController {
} }
public void setUpConfig(ConfigLoader configLoader) { public void setUpConfig(ConfigLoader configLoader) {
mainConfig = configLoader.readConfigFromFile(FilePath.toSpecificPathForm("files/Config.json")); configLoader.readMainConfig(FilePath.toSpecificPathForm("files/Config.json"));
VoicePlayer.voiceConfig = configLoader.readVoiceConfigFromFile(FilePath.toSpecificPathForm("files/VoiceConfig.json")); configLoader.loadVoiceConfig(FilePath.toSpecificPathForm("files/VoiceConfig.json"));
} }
@FXML @FXML
@ -116,9 +114,8 @@ public final class MainInterfaceController {
return; return;
} }
NumberSettingsPaneController numberSettingsPaneController = new NumberSettingsPaneController(data); NumberSettingsPaneController numberSettingsPaneController = new NumberSettingsPaneController(data);
numberSettingsPaneController.bindProperties(mainConfig); numberSettingsPaneController.bindProperties(GlobalConfig.mainConfig);
new DialogMaker(rootPane).createDialogWithOneBtn("调整数字", numberSettingsPaneController); new DialogMaker(rootPane).createDialogWithOneBtn("调整数字", numberSettingsPaneController);
} }
@FXML @FXML
@ -138,7 +135,7 @@ public final class MainInterfaceController {
miniStage.initStyle(StageStyle.UNDECORATED); miniStage.initStyle(StageStyle.UNDECORATED);
MiniPaneController miniPaneController = loader.getController(); MiniPaneController miniPaneController = loader.getController();
miniPaneController.setBase(data, mainConfig, selector); miniPaneController.setBase(data, selector);
Stage currentStage = (Stage) anPaiBtn.getScene().getWindow(); Stage currentStage = (Stage) anPaiBtn.getScene().getWindow();
miniPaneController.setOldStage(currentStage); miniPaneController.setOldStage(currentStage);
@ -154,11 +151,10 @@ public final class MainInterfaceController {
@FXML @FXML
void showSettings(ActionEvent event) { void showSettings(ActionEvent event) {
SettingsPaneController settingsPaneController = new SettingsPaneController(); SettingsPaneController settingsPaneController = new SettingsPaneController();
settingsPaneController.setToggleGroup(); settingsPaneController.setToggleGroup();
settingsPaneController.bindProperties(mainConfig); settingsPaneController.bindProperties();
settingsPaneController.setRootPane(rootPane); settingsPaneController.setRootPane(rootPane);
@ -177,7 +173,7 @@ public final class MainInterfaceController {
public void init() { public void init() {
selector.initialVariable(mainConfig, data, history, upperLabel.textProperty(), downLabel.textProperty()); selector.initialVariable(data, history, upperLabel.textProperty(), downLabel.textProperty());
selector.addStoppedEventListener((observableValue, oldValue, stop) -> { selector.addStoppedEventListener((observableValue, oldValue, stop) -> {
if (stop) { if (stop) {
anPaiBtn.setText("安排一下"); anPaiBtn.setText("安排一下");
@ -200,11 +196,11 @@ public final class MainInterfaceController {
return; return;
} }
if (mainConfig.getRandomCount()) { if (GlobalConfig.mainConfig.getRandomCount()) {
mainConfig.setMaxTotalCount(100 + random.nextInt(151)); GlobalConfig.mainConfig.setMaxTotalCount(100 + random.nextInt(151));
} }
if (mainConfig.getNameChoose()) { if (GlobalConfig.mainConfig.getChooseMethod() == MainConfig.METHOD_NAME) {
runNameMode(); runNameMode();
} else { } else {
runNumberMode(); runNumberMode();
@ -225,9 +221,9 @@ public final class MainInterfaceController {
return; return;
} }
if (data.compareNameIgnoreList() && mainConfig.getPassSelectedResult()) { if (data.compareNameIgnoreList() && GlobalConfig.mainConfig.getIgnoreSelectedResult()) {
if (mainConfig.getEqualMode()) { if (GlobalConfig.mainConfig.getEqualMode()) {
new DialogMaker(rootPane).createDialogWithOKAndCancel("啊?", "全部名字都被点完啦!\n要把名字的忽略列表重置吗?", e -> data.clearNameIgnoreList()); new DialogMaker(rootPane).createDialogWithOKAndCancel("啊?", "全部名字都被点完啦!\n要把名字的忽略列表重置吗?", e -> data.clearNameIgnoreList());
} else { } else {
new DialogMaker(rootPane).createMessageDialog("啊?", "全部名字都被点完啦!\n请多添加几个名字 或 点击“机会均等”的“重置”按钮。"); new DialogMaker(rootPane).createMessageDialog("啊?", "全部名字都被点完啦!\n请多添加几个名字 或 点击“机会均等”的“重置”按钮。");
@ -244,16 +240,16 @@ public final class MainInterfaceController {
try { try {
int minNumber = Integer.parseInt(mainConfig.getMinNumber()); int minNumber = Integer.parseInt(GlobalConfig.mainConfig.getMinNumber());
int maxNumber = Integer.parseInt(mainConfig.getMaxNumber()); int maxNumber = Integer.parseInt(GlobalConfig.mainConfig.getMaxNumber());
if (maxNumber - minNumber <= 0) { if (maxNumber - minNumber <= 0) {
new DialogMaker(rootPane).createMessageDialog("嗯哼?", "数字要前小后大啊~"); new DialogMaker(rootPane).createMessageDialog("嗯哼?", "数字要前小后大啊~");
return; return;
} }
if (data.getNumberIgnoreListSize() >= (maxNumber - minNumber + 1) && mainConfig.getPassSelectedResult()) { if (data.getNumberIgnoreListSize() >= (maxNumber - minNumber + 1) && GlobalConfig.mainConfig.getIgnoreSelectedResult()) {
if (mainConfig.getEqualMode()) { if (GlobalConfig.mainConfig.getEqualMode()) {
new DialogMaker(rootPane).createDialogWithOKAndCancel("啊?", "全部数字都被点完啦!\n要把数字的忽略列表重置吗?", e -> data.clearNumberIgnoreList()); new DialogMaker(rootPane).createDialogWithOKAndCancel("啊?", "全部数字都被点完啦!\n要把数字的忽略列表重置吗?", e -> data.clearNumberIgnoreList());
} else { } else {
new DialogMaker(rootPane).createMessageDialog("啊?", "全部数字都被点完啦!\n请扩大数字范围 或 点击“机会均等”的“重置”按钮。"); new DialogMaker(rootPane).createMessageDialog("啊?", "全部数字都被点完啦!\n请扩大数字范围 或 点击“机会均等”的“重置”按钮。");
@ -280,6 +276,6 @@ public final class MainInterfaceController {
} }
public MainConfig getMainConfig() { public MainConfig getMainConfig() {
return mainConfig; return GlobalConfig.mainConfig;
} }
} }

@ -10,6 +10,7 @@ import javafx.scene.control.Label;
import javafx.scene.input.MouseEvent; import javafx.scene.input.MouseEvent;
import javafx.scene.input.TouchEvent; import javafx.scene.input.TouchEvent;
import javafx.stage.Stage; import javafx.stage.Stage;
import me.lensferno.dogename.configs.GlobalConfig;
import me.lensferno.dogename.configs.MainConfig; import me.lensferno.dogename.configs.MainConfig;
import me.lensferno.dogename.controllers.WindowListeners.MoveWindowByMouse; import me.lensferno.dogename.controllers.WindowListeners.MoveWindowByMouse;
import me.lensferno.dogename.controllers.WindowListeners.MoveWindowByTouch; import me.lensferno.dogename.controllers.WindowListeners.MoveWindowByTouch;
@ -32,13 +33,8 @@ public class MiniPaneController {
private JFXButton miniModeBtn; private JFXButton miniModeBtn;
private final Random random = new Random(); private final Random random = new Random();
private Data data; private Data data;
private MainConfig mainConfig;
private Selector selector = new Selector(); private Selector selector = new Selector();
public Stage getOldStage() {
return oldStage;
}
public void setOldStage(Stage oldStage) { public void setOldStage(Stage oldStage) {
this.oldStage = oldStage; this.oldStage = oldStage;
} }
@ -51,19 +47,16 @@ public class MiniPaneController {
this.currentStage = currentStage; this.currentStage = currentStage;
} }
public void setBase(Data data, MainConfig mainConfig, Selector selector) { public void setBase(Data data, Selector selector) {
this.data = data; this.data = data;
this.mainConfig = mainConfig;
this.selector = selector; this.selector = selector;
this.selector.setLabelTexts(chosenNameLabel.textProperty()); this.selector.setLabelTexts(chosenNameLabel.textProperty());
this.oldTextProperties = oldTextProperties;
} }
@FXML @FXML
void recoverMode(ActionEvent event) { void recoverMode(ActionEvent event) {
this.oldStage.setOnShown((e) -> { // todo: 待修复:界面恢复后label无法正常显示名字
selector.setLabelTexts(oldTextProperties); this.oldStage.setOnShown((e) -> selector.setLabelTexts(oldTextProperties));
});
this.oldStage.show(); this.oldStage.show();
currentStage.close(); currentStage.close();
@ -100,11 +93,11 @@ public class MiniPaneController {
return; return;
} }
if (mainConfig.getRandomCount()) { if (GlobalConfig.mainConfig.getRandomCount()) {
mainConfig.setMaxTotalCount(100 + random.nextInt(151)); GlobalConfig.mainConfig.setMaxTotalCount(100 + random.nextInt(151));
} }
if (mainConfig.getNameChoose()) { if (GlobalConfig.mainConfig.getChooseMethod() == MainConfig.METHOD_NAME) {
runNameMode(); runNameMode();
} else { } else {
runNumberMode(); runNumberMode();
@ -118,7 +111,7 @@ public class MiniPaneController {
return; return;
} }
if (data.compareNameIgnoreList() && mainConfig.getPassSelectedResult()) { if (data.compareNameIgnoreList() && GlobalConfig.mainConfig.getIgnoreSelectedResult()) {
return; return;
} }
@ -131,14 +124,14 @@ public class MiniPaneController {
try { try {
int minNumber = Integer.parseInt(mainConfig.getMinNumber()); int minNumber = Integer.parseInt(GlobalConfig.mainConfig.getMinNumber());
int maxNumber = Integer.parseInt(mainConfig.getMaxNumber()); int maxNumber = Integer.parseInt(GlobalConfig.mainConfig.getMaxNumber());
if (maxNumber - minNumber <= 0) { if (maxNumber - minNumber <= 0) {
return; return;
} }
if (data.getNumberIgnoreListSize() >= (maxNumber - minNumber + 1) && mainConfig.getPassSelectedResult()) { if (data.getNumberIgnoreListSize() >= (maxNumber - minNumber + 1) && GlobalConfig.mainConfig.getIgnoreSelectedResult()) {
return; return;
} }

@ -9,15 +9,12 @@ import javafx.fxml.FXMLLoader;
import javafx.scene.control.ToggleGroup; import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.Pane; import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import me.lensferno.dogename.configs.MainConfig; import me.lensferno.dogename.configs.GlobalConfig;
import me.lensferno.dogename.configs.VoiceConfig;
import me.lensferno.dogename.data.Data; import me.lensferno.dogename.data.Data;
import me.lensferno.dogename.utils.DialogMaker; import me.lensferno.dogename.utils.DialogMaker;
import me.lensferno.dogename.voice.VoicePlayer;
public class SettingsPaneController extends VBox { public class SettingsPaneController extends VBox {
MainConfig mainConfig;
Pane rootPane; Pane rootPane;
Data data; Data data;
@ -34,9 +31,9 @@ public class SettingsPaneController extends VBox {
@FXML @FXML
private JFXCheckBox equalModeBtn; private JFXCheckBox equalModeBtn;
@FXML @FXML
private JFXRadioButton ignoreOnce; private JFXRadioButton ignoreSelectedResultBtn;
@FXML @FXML
private JFXRadioButton chooseOnce; private JFXRadioButton notIgnoreSelectedResultBtn;
@FXML @FXML
private JFXRadioButton randomTimes; private JFXRadioButton randomTimes;
@FXML @FXML
@ -53,47 +50,48 @@ public class SettingsPaneController extends VBox {
} }
} }
public void setMainConfig(MainConfig mainConfig) {
this.mainConfig = mainConfig;
}
public void setRootPane(Pane rootPane) { public void setRootPane(Pane rootPane) {
this.rootPane = rootPane; this.rootPane = rootPane;
} }
public void bindProperties(MainConfig mainConfig) { private final ToggleGroup chooseRuleToggleGroup = new ToggleGroup();
setMainConfig(mainConfig); private final ToggleGroup chooseCountRuleToggleGroup = new ToggleGroup();
ignoreOnce.selectedProperty().bindBidirectional(mainConfig.passSelectedResultProperty());
chooseOnce.setSelected(!mainConfig.getPassSelectedResult());
randomTimes.selectedProperty().bindBidirectional(mainConfig.randomCountProperty()); public void bindProperties() {
fixedTimes.setSelected(!mainConfig.getRandomCount()); ignoreSelectedResultBtn.setToggleGroup(chooseRuleToggleGroup);
notIgnoreSelectedResultBtn.setToggleGroup(chooseRuleToggleGroup);
chooseRuleToggleGroup.selectToggle(GlobalConfig.mainConfig.getIgnoreSelectedResult() ? ignoreSelectedResultBtn : notIgnoreSelectedResultBtn);
chooseRuleToggleGroup.selectedToggleProperty().addListener((observable, oldValue, newValue) ->
GlobalConfig.mainConfig.setIgnoreSelectedResult(newValue == ignoreSelectedResultBtn));
equalModeBtn.selectedProperty().bindBidirectional(mainConfig.equalModeProperty()); GlobalConfig.mainConfig.ignoreSelectedResultProperty().addListener((observable, oldValue, isIgnorePast) -> {
if (!isIgnorePast) {
//如果“忽略被点过的名字”选项被取消后就把机会均等模式的按钮给取消掉
equalModeBtn.setSelected(false);
}
});
newAlgoBtn.selectedProperty().bindBidirectional(mainConfig.secureRandomProperty()); randomTimes.setToggleGroup(chooseCountRuleToggleGroup);
fixedTimes.setToggleGroup(chooseCountRuleToggleGroup);
chooseCountRuleToggleGroup.selectToggle(GlobalConfig.mainConfig.getRandomCount() ? randomTimes : fixedTimes);
chooseCountRuleToggleGroup.selectedToggleProperty().addListener((observable, oldValue, newValue) ->
GlobalConfig.mainConfig.setRandomCount(newValue == randomTimes));
voicePlayBtn.selectedProperty().bindBidirectional(mainConfig.voicePlayProperty()); newAlgoBtn.selectedProperty().bindBidirectional(GlobalConfig.mainConfig.secureRandomProperty());
cycleTimesBar.valueProperty().bindBidirectional(mainConfig.maxTotalCountProperty()); voicePlayBtn.selectedProperty().bindBidirectional(GlobalConfig.mainConfig.voicePlayProperty());
speedBar.valueProperty().bindBidirectional(mainConfig.speedProperty()); cycleTimesBar.valueProperty().bindBidirectional(GlobalConfig.mainConfig.maxTotalCountProperty());
showSayingBtn.selectedProperty().bindBidirectional(mainConfig.showSayingProperty()); speedBar.valueProperty().bindBidirectional(GlobalConfig.mainConfig.speedProperty());
mainConfig.passSelectedResultProperty().addListener((observable, oldValue, isIgnorePast) -> { showSayingBtn.selectedProperty().bindBidirectional(GlobalConfig.mainConfig.showSayingProperty());
if (!isIgnorePast) {
//如果 忽略被点过的名字 被取消后就把机会均等模式的按钮给取消掉
equalModeBtn.setSelected(false);
}
});
} }
public void setToggleGroup() { public void setToggleGroup() {
ToggleGroup pastGroup = new ToggleGroup(); ToggleGroup pastGroup = new ToggleGroup();
chooseOnce.setToggleGroup(pastGroup); notIgnoreSelectedResultBtn.setToggleGroup(pastGroup);
ignoreOnce.setToggleGroup(pastGroup); ignoreSelectedResultBtn.setToggleGroup(pastGroup);
ToggleGroup fixedTimesGroup = new ToggleGroup(); ToggleGroup fixedTimesGroup = new ToggleGroup();
randomTimes.setToggleGroup(fixedTimesGroup); randomTimes.setToggleGroup(fixedTimesGroup);
@ -123,7 +121,7 @@ public class SettingsPaneController extends VBox {
@FXML @FXML
void equalBtnAction(ActionEvent event) { void equalBtnAction(ActionEvent event) {
if (!mainConfig.getPassSelectedResult()) { if (!GlobalConfig.mainConfig.getIgnoreSelectedResult()) {
equalModeBtn.setSelected(false); equalModeBtn.setSelected(false);
new DialogMaker(rootPane).createMessageDialog("且慢", new DialogMaker(rootPane).createMessageDialog("且慢",
"无法在“概率均分”的模式下使用,如需使用请在“人人有份”模式下启用。"); "无法在“概率均分”的模式下使用,如需使用请在“人人有份”模式下启用。");

@ -12,6 +12,7 @@ import javafx.scene.control.Toggle;
import javafx.scene.control.ToggleGroup; import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.Pane; import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import me.lensferno.dogename.configs.GlobalConfig;
import me.lensferno.dogename.configs.VoiceConfig; import me.lensferno.dogename.configs.VoiceConfig;
import me.lensferno.dogename.utils.DialogMaker; import me.lensferno.dogename.utils.DialogMaker;
import me.lensferno.dogename.voice.VoicePlayer; import me.lensferno.dogename.voice.VoicePlayer;
@ -56,7 +57,7 @@ public class VoiceSettingsPaneController extends VBox {
} }
if (speakerList.isEmpty()) { if (speakerList.isEmpty()) {
speakerList.addAll( speakerList.addAll(
"度小宇=1", "度小美=0", "度逍遥=3", "度丫丫=4" "度小宇", "度小美", "度逍遥", "度丫丫"
// 非高级API用户,这些精品音频库用不了(等把“高级设置”弄出来再说吧...) // 非高级API用户,这些精品音频库用不了(等把“高级设置”弄出来再说吧...)
/*, "度博文=106", "度小童=110", "度小萌=111", "度米朵=103", "度小娇=5"*/); /*, "度博文=106", "度小童=110", "度小萌=111", "度米朵=103", "度小娇=5"*/);
} }
@ -74,20 +75,20 @@ public class VoiceSettingsPaneController extends VBox {
audioFormatMap.put(VoiceConfig.AUDIO_FORMAT_WAV, wavFormatButton); audioFormatMap.put(VoiceConfig.AUDIO_FORMAT_WAV, wavFormatButton);
audioFormatMap.put(VoiceConfig.AUDIO_FORMAT_MP3, mp3FormatButton); audioFormatMap.put(VoiceConfig.AUDIO_FORMAT_MP3, mp3FormatButton);
audioFormatToggleGroup.selectToggle(audioFormatMap.get(VoicePlayer.voiceConfig.getAudioFormat())); audioFormatToggleGroup.selectToggle(audioFormatMap.get(GlobalConfig.voiceConfig.getAudioFormat()));
audioFormatToggleGroup.selectedToggleProperty().addListener((observable, oldValue, selectBtn) -> audioFormatToggleGroup.selectedToggleProperty().addListener((observable, oldValue, selectBtn) ->
VoicePlayer.voiceConfig.setAudioFormat(selectBtn.equals(wavFormatButton) ? VoiceConfig.AUDIO_FORMAT_WAV : VoiceConfig.AUDIO_FORMAT_MP3)); GlobalConfig.voiceConfig.setAudioFormat(selectBtn.equals(wavFormatButton) ? VoiceConfig.AUDIO_FORMAT_WAV : VoiceConfig.AUDIO_FORMAT_MP3));
speakerSelectBar.getSelectionModel().select(VoicePlayer.voiceConfig.getSpeaker()); speakerSelectBar.getSelectionModel().select(GlobalConfig.voiceConfig.getSpeaker());
speakerSelectBar.valueProperty().addListener((observable, oldValue, newValue) -> { speakerSelectBar.valueProperty().addListener((observable, oldValue, newValue) -> {
int selectedSpeakerIndex = speakerSelectBar.getSelectionModel().getSelectedIndex(); int selectedSpeakerIndex = speakerSelectBar.getSelectionModel().getSelectedIndex();
VoicePlayer.voiceConfig.setSpeakerIdString(speakers[selectedSpeakerIndex]); GlobalConfig.voiceConfig.setSpeakerIdString(speakers[selectedSpeakerIndex]);
VoicePlayer.voiceConfig.setSpeaker(selectedSpeakerIndex); GlobalConfig.voiceConfig.setSpeaker(selectedSpeakerIndex);
}); });
voiceSpeedBar.valueProperty().bindBidirectional(VoicePlayer.voiceConfig.speedProperty()); voiceSpeedBar.valueProperty().bindBidirectional(GlobalConfig.voiceConfig.speedProperty());
intonationBar.valueProperty().bindBidirectional(VoicePlayer.voiceConfig.intonationProperty()); intonationBar.valueProperty().bindBidirectional(GlobalConfig.voiceConfig.intonationProperty());
} }
@FXML @FXML

@ -4,6 +4,7 @@ import javafx.animation.AnimationTimer;
import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.StringProperty; import javafx.beans.property.StringProperty;
import javafx.beans.value.ChangeListener; import javafx.beans.value.ChangeListener;
import me.lensferno.dogename.configs.GlobalConfig;
import me.lensferno.dogename.configs.MainConfig; import me.lensferno.dogename.configs.MainConfig;
import me.lensferno.dogename.configs.VoiceConfig; import me.lensferno.dogename.configs.VoiceConfig;
import me.lensferno.dogename.data.Data; import me.lensferno.dogename.data.Data;
@ -24,10 +25,9 @@ public final class Selector {
public void initialVoicePlayer() { public void initialVoicePlayer() {
TokenManager tokenManager = new TokenManager(); TokenManager tokenManager = new TokenManager();
VoiceConfig voiceConfig = new VoiceConfig();
tokenManager.init(); tokenManager.init();
if (tokenManager.getTokenStatus() == TokenManager.TOKEN_OK) { if (tokenManager.getTokenStatus() == TokenManager.TOKEN_OK) {
voicePlayer = new VoicePlayer(tokenManager.getToken(), voiceConfig); voicePlayer = new VoicePlayer(tokenManager.getToken());
} }
} }
@ -43,8 +43,8 @@ public final class Selector {
processor.stopProcess(); processor.stopProcess();
} }
public void initialVariable(MainConfig config, Data data, History history, StringProperty... labelTexts) { public void initialVariable(Data data, History history, StringProperty... labelTexts) {
processor.initialVariable(config, voicePlayer, data, history, labelTexts); processor.initialVariable(voicePlayer, data, history, labelTexts);
} }
public boolean isWorkerRunning() { public boolean isWorkerRunning() {
@ -61,13 +61,10 @@ public final class Selector {
// --------------------------------------------------- // ---------------------------------------------------
static class Processor extends AnimationTimer { static class Processor extends AnimationTimer {
MainConfig config = null;
private Worker coreWorker; private Worker coreWorker;
protected void initialVariable(MainConfig config, VoicePlayer voicePlayer, Data data, History history, StringProperty... labelTexts) { protected void initialVariable(VoicePlayer voicePlayer, Data data, History history, StringProperty... labelTexts) {
coreWorker = new Worker(labelTexts, config, data, history, voicePlayer); coreWorker = new Worker(labelTexts, data, history, voicePlayer);
this.config = config;
} }
protected void setWorkerLabelTexts(StringProperty... labelTexts) { protected void setWorkerLabelTexts(StringProperty... labelTexts) {
@ -75,8 +72,8 @@ public final class Selector {
} }
protected void updateNewValue() { protected void updateNewValue() {
coreWorker.setSpeed(100 - config.getSpeed()); coreWorker.setSpeed(100 - GlobalConfig.mainConfig.getSpeed());
coreWorker.setMaxTotalCount(config.getMaxTotalCount()); coreWorker.setMaxTotalCount(GlobalConfig.mainConfig.getMaxTotalCount());
} }
protected SimpleBooleanProperty stoppedIndicatorProperty() { protected SimpleBooleanProperty stoppedIndicatorProperty() {
@ -100,12 +97,10 @@ public final class Selector {
} }
public void setNumberRange() { public void setNumberRange() {
int minNumber = Integer.parseInt(config.getMinNumber()); int minNumber = Integer.parseInt(GlobalConfig.mainConfig.getMinNumber());
int maxNumber = Integer.parseInt(config.getMaxNumber()); int maxNumber = Integer.parseInt(GlobalConfig.mainConfig.getMaxNumber());
coreWorker.setNumberRange(minNumber, maxNumber); coreWorker.setNumberRange(minNumber, maxNumber);
} }
} }
} }

@ -2,8 +2,8 @@ package me.lensferno.dogename.select.core;
import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.StringProperty; import javafx.beans.property.StringProperty;
import me.lensferno.dogename.configs.GlobalConfig;
import me.lensferno.dogename.configs.MainConfig; import me.lensferno.dogename.configs.MainConfig;
import me.lensferno.dogename.configs.VoiceConfig;
import me.lensferno.dogename.data.Data; import me.lensferno.dogename.data.Data;
import me.lensferno.dogename.data.History; import me.lensferno.dogename.data.History;
import me.lensferno.dogename.utils.Random; import me.lensferno.dogename.utils.Random;
@ -14,7 +14,6 @@ public final class Worker {
private final Random randomNumber = new Random(); private final Random randomNumber = new Random();
private final SimpleBooleanProperty stoppedIndicator = new SimpleBooleanProperty(true); private final SimpleBooleanProperty stoppedIndicator = new SimpleBooleanProperty(true);
private final MainConfig config;
private final Data data; private final Data data;
private final History history; private final History history;
private final VoicePlayer voicePlayer; private final VoicePlayer voicePlayer;
@ -40,9 +39,8 @@ public final class Worker {
private boolean continueSelecting = false; private boolean continueSelecting = false;
private int resultLabelId = 0; private int resultLabelId = 0;
public Worker(StringProperty[] labelTexts, MainConfig config, Data data, History history, VoicePlayer voicePlayer) { public Worker(StringProperty[] labelTexts, Data data, History history, VoicePlayer voicePlayer) {
this.labelTexts = labelTexts; this.labelTexts = labelTexts;
this.config = config;
this.data = data; this.data = data;
this.history = history; this.history = history;
this.voicePlayer = voicePlayer; this.voicePlayer = voicePlayer;
@ -69,8 +67,8 @@ public final class Worker {
// 如果不是这三种情况就选到符合其中一种情况为止 // 如果不是这三种情况就选到符合其中一种情况为止
// 由于后两者在安排进程中不可能改变,因此继续挑选后只有选中的结果不在忽略名单中才会结束挑选 // 由于后两者在安排进程中不可能改变,因此继续挑选后只有选中的结果不在忽略名单中才会结束挑选
// 若忽略名单已满(名单中数量=总的名单数量),点击“安排一下”时会提示已满,无法再进行挑选,因此在运行时总有 忽略名单<总名单,总有名字不在忽略列表中,不会死循环,放心吧 // 若忽略名单已满(名单中数量=总的名单数量),点击“安排一下”时会提示已满,无法再进行挑选,因此在运行时总有 忽略名单<总名单,总有名字不在忽略列表中,不会死循环,放心吧
boolean resultIgnored = (config.getChooseMethod() == MainConfig.METHOD_NAME) ? (data.checkNameIgnored(selectedResult)) : (data.checkNumberIgnored(selectedResult)); boolean resultIgnored = (GlobalConfig.mainConfig.getChooseMethod() == MainConfig.METHOD_NAME) ? (data.checkNameIgnored(selectedResult)) : (data.checkNumberIgnored(selectedResult));
if (!resultIgnored || !config.getPassSelectedResult() || forceStop) { if (!resultIgnored || !GlobalConfig.mainConfig.getIgnoreSelectedResult() || forceStop) {
this.stopSelect(); this.stopSelect();
finalResult = true; finalResult = true;
return; return;
@ -83,25 +81,25 @@ public final class Worker {
resultLabelId = counter.getNewResultLabelId(); resultLabelId = counter.getNewResultLabelId();
finalResult = false; finalResult = false;
this.selectedResult = this.pick(config.getChooseMethod()); this.selectedResult = this.pick(GlobalConfig.mainConfig.getChooseMethod());
} }
public void stopSelect() { public void stopSelect() {
if (config.getPassSelectedResult()) { if (GlobalConfig.mainConfig.getIgnoreSelectedResult()) {
if (config.nameChooseProperty().getValue()) { if (GlobalConfig.mainConfig.getChooseMethod() == MainConfig.METHOD_NAME) {
data.addNameToIgnoreList(selectedResult); data.addNameToIgnoreList(selectedResult);
} else { } else {
data.addNumberToIgnoreList(selectedResult); data.addNumberToIgnoreList(selectedResult);
} }
} }
if (config.getEqualMode()) { if (GlobalConfig.mainConfig.getEqualMode()) {
data.writeIgnoreList(Data.IGNORELIST_ALL); data.writeIgnoreList(Data.IGNORELIST_ALL);
} }
history.addHistory(selectedResult); history.addHistory(selectedResult);
if (config.getVoicePlay() && voicePlayer != null) { if (GlobalConfig.mainConfig.getVoicePlay() && voicePlayer != null) {
voicePlayer.playVoice(selectedResult); voicePlayer.playVoice(selectedResult);
} }
@ -114,9 +112,9 @@ public final class Worker {
private String pick(int selectMethod) { private String pick(int selectMethod) {
switch (selectMethod) { switch (selectMethod) {
case MainConfig.METHOD_NAME: case MainConfig.METHOD_NAME:
return data.randomGet(config.getSecureRandom()); return data.randomGet(GlobalConfig.mainConfig.getSecureRandom());
case MainConfig.METHOD_NUMBER: case MainConfig.METHOD_NUMBER:
randomNumber.setUseSecureRandom(config.getSecureRandom()); randomNumber.setUseSecureRandom(GlobalConfig.mainConfig.getSecureRandom());
return String.valueOf(randomNumber.getRandomNumber(numberRange[MIN_NUMBER], numberRange[MAX_NUMBER])); return String.valueOf(randomNumber.getRandomNumber(numberRange[MIN_NUMBER], numberRange[MAX_NUMBER]));
default: default:
return "(´・ω・`)?"; return "(´・ω・`)?";

@ -1,6 +1,7 @@
package me.lensferno.dogename.voice; package me.lensferno.dogename.voice;
import javazoom.spi.mpeg.sampled.file.MpegAudioFileReader; import javazoom.spi.mpeg.sampled.file.MpegAudioFileReader;
import me.lensferno.dogename.configs.GlobalConfig;
import me.lensferno.dogename.configs.VoiceConfig; import me.lensferno.dogename.configs.VoiceConfig;
import me.lensferno.dogename.utils.FilePath; import me.lensferno.dogename.utils.FilePath;
import me.lensferno.dogename.utils.IOUtil; import me.lensferno.dogename.utils.IOUtil;
@ -17,23 +18,20 @@ public class VoicePlayer {
public static final String cachePath = FilePath.toSpecificPathForm("caches/voice/"); public static final String cachePath = FilePath.toSpecificPathForm("caches/voice/");
private final Token token; private final Token token;
public static VoiceConfig voiceConfig; public VoicePlayer(Token token) {
public VoicePlayer(Token token, VoiceConfig voiceConfig) {
this.token = token; this.token = token;
VoicePlayer.voiceConfig = voiceConfig;
} }
public void playVoice(String name) { public void playVoice(String name) {
String speaker = voiceConfig.getSpeakerIdString(); String speaker = GlobalConfig.voiceConfig.getSpeakerIdString();
String intonation = String.valueOf(voiceConfig.getIntonation()); String intonation = String.valueOf(GlobalConfig.voiceConfig.getIntonation());
String speed = String.valueOf(voiceConfig.getSpeed()); String speed = String.valueOf(GlobalConfig.voiceConfig.getSpeed());
String cacheName = String.format("%s_%s_%s_%s", name, speaker, speed, intonation); String cacheName = String.format("%s_%s_%s_%s", name, speaker, speed, intonation);
File cache = new File(String.format("%s%s.%s", cachePath, cacheName, VoiceConfig.getAudioFileSuffix(voiceConfig.getAudioFormat()))); File cache = new File(String.format("%s%s.%s", cachePath, cacheName, VoiceConfig.getAudioFileSuffix(GlobalConfig.voiceConfig.getAudioFormat())));
new Thread(() -> { new Thread(() -> {
if (!cache.exists()) { if (!cache.exists()) {
@ -59,7 +57,7 @@ public class VoicePlayer {
speed, speed,
intonation, intonation,
speaker, speaker,
voiceConfig.getAudioFormat(), GlobalConfig.voiceConfig.getAudioFormat(),
URLEncoder.encode(name, "UTF-8") URLEncoder.encode(name, "UTF-8")
); );
@ -94,12 +92,12 @@ public class VoicePlayer {
private void playSound(File file) { private void playSound(File file) {
try { try {
AudioInputStream sourceAudioInputStream; AudioInputStream sourceAudioInputStream;
if (voiceConfig.getAudioFormat() == VoiceConfig.AUDIO_FORMAT_WAV) { if (GlobalConfig.voiceConfig.getAudioFormat() == VoiceConfig.AUDIO_FORMAT_WAV) {
sourceAudioInputStream = AudioSystem.getAudioInputStream(file); sourceAudioInputStream = AudioSystem.getAudioInputStream(file);
} else { } else {
sourceAudioInputStream = new MpegAudioFileReader().getAudioInputStream(file); sourceAudioInputStream = new MpegAudioFileReader().getAudioInputStream(file);
} }
AudioFormat sourceFormat = sourceAudioInputStream.getFormat(); AudioFormat sourceFormat = sourceAudioInputStream.getFormat();
AudioFormat targetFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, AudioFormat targetFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
sourceFormat.getSampleRate(), 16, sourceFormat.getChannels(), sourceFormat.getSampleRate(), 16, sourceFormat.getChannels(),

@ -1,22 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?> <?import com.jfoenix.controls.JFXButton?>
<?import javafx.scene.control.*?> <?import com.jfoenix.controls.JFXCheckBox?>
<?import javafx.scene.shape.*?> <?import com.jfoenix.controls.JFXRadioButton?>
<?import com.jfoenix.controls.*?> <?import com.jfoenix.controls.JFXSlider?>
<?import javafx.geometry.*?> <?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?> <?import javafx.scene.control.Label?>
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.shape.Line?> <?import javafx.scene.shape.Line?>
<?import javafx.scene.text.*?> <?import javafx.scene.text.Font?>
<fx:root prefHeight="360.0" prefWidth="593.0" style="-fx-background-color: white;" type="VBox" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"> <fx:root prefHeight="360.0" prefWidth="593.0" style="-fx-background-color: white;" type="VBox" xmlns="http://javafx.com/javafx/8.0.321" xmlns:fx="http://javafx.com/fxml/1">
<children> <children>
<HBox prefHeight="50.0" prefWidth="592.0" spacing="10.0"> <HBox prefHeight="50.0" prefWidth="592.0" spacing="10.0">
<children> <children>
<Pane prefHeight="50.0" prefWidth="296.0"> <Pane prefHeight="50.0" prefWidth="296.0">
<children> <children>
<JFXRadioButton fx:id="ignoreOnce" layoutX="14.0" layoutY="14.0" selected="true" text="人人有份(跳过已点过的名字)"> <JFXRadioButton fx:id="ignoreSelectedResultBtn" layoutX="14.0" layoutY="14.0" selected="true" text="人人有份(跳过已点过的名字)">
<font> <font>
<Font name="Microsoft YaHei" size="17.0" /> <Font name="Microsoft YaHei" size="17.0" />
</font> </font>
@ -38,7 +40,7 @@
<children> <children>
<Pane prefHeight="50.0" prefWidth="296.0"> <Pane prefHeight="50.0" prefWidth="296.0">
<children> <children>
<JFXRadioButton fx:id="chooseOnce" layoutX="14.0" layoutY="14.0" text="概率均分(不跳过已点过的名字)"> <JFXRadioButton fx:id="notIgnoreSelectedResultBtn" layoutX="14.0" layoutY="14.0" text="概率均分(不跳过已点过的名字)">
<font> <font>
<Font name="Microsoft YaHei" size="17.0" /> <Font name="Microsoft YaHei" size="17.0" />
</font> </font>

Loading…
Cancel
Save