"use strict"
const er = require('@electron/remote')
const saveUserSettings = () => localStorage.setItem("userSettings", JSON.stringify(window.userSettings))
// const saveUserSettings = () => {}
const deleteFolderRecursive = function (directoryPath) {
if (fs.existsSync(directoryPath)) {
fs.readdirSync(directoryPath).forEach((file, index) => {
const curPath = `${directoryPath}/${file}`;
if (fs.lstatSync(curPath).isDirectory()) {
// recurse
deleteFolderRecursive(curPath);
} else {
// delete file
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(directoryPath);
}
};
// Load user settings
window.userSettings = localStorage.getItem("userSettings") ||
// window.userSettings =
{
useGPU: false,
customWindowSize:`${window.innerHeight},${window.innerWidth}`,
base_speaker: "default",
autoplay: true,
autoPlayGen: false,
audio: {
format: "wav"
},
plugins: {
}
}
if ((typeof window.userSettings)=="string") {
window.userSettings = JSON.parse(window.userSettings)
}
if (!Object.keys(window.userSettings).includes("installation")) { // For backwards compatibility
window.userSettings.installation = "cpu"
}
if (!Object.keys(window.userSettings).includes("audio")) { // For backwards compatibility
window.userSettings.audio = {format: "wav", hz: 44100, padStart: 0, padEnd: 0, pitchMult: 1, tempo: 1, nr: 5, nf: -20, deessing: 0.1}
}
if (!Object.keys(window.userSettings).includes("sliderTooltip")) { // For backwards compatibility
window.userSettings.sliderTooltip = true
}
// if (!Object.keys(window.userSettings).includes("darkPrompt")) { // For backwards compatibility
// window.userSettings.darkPrompt = false
// }
if (!Object.keys(window.userSettings).includes("showDiscordStatus")) { // For backwards compatibility
window.userSettings.showDiscordStatus = true
}
if (!Object.keys(window.userSettings).includes("prompt_fontSize")) { // For backwards compatibility
window.userSettings.prompt_fontSize = 15
}
if (!Object.keys(window.userSettings).includes("bg_gradient_opacity")) { // For backwards compatibility
window.userSettings.bg_gradient_opacity = 13
}
if (!Object.keys(window.userSettings).includes("autoReloadVoices")) { // For backwards compatibility
window.userSettings.autoReloadVoices = false
}
if (!Object.keys(window.userSettings).includes("audio") || !Object.keys(window.userSettings.audio).includes("hz")) { // For backwards compatibility
window.userSettings.audio.hz = 44100
}
if (!Object.keys(window.userSettings).includes("audio") || !Object.keys(window.userSettings.audio).includes("padStart")) { // For backwards compatibility
window.userSettings.audio.padStart = 0
}
if (!Object.keys(window.userSettings).includes("audio") || !Object.keys(window.userSettings.audio).includes("padEnd")) { // For backwards compatibility
window.userSettings.audio.padEnd = 0
}
if (!Object.keys(window.userSettings).includes("audio") || !Object.keys(window.userSettings.audio).includes("pitchMult")) { // For backwards compatibility
window.userSettings.audio.pitchMult = 1
}
if (!Object.keys(window.userSettings).includes("audio") || !Object.keys(window.userSettings.audio).includes("tempo")) { // For backwards compatibility
window.userSettings.audio.tempo = 1
}
if (!Object.keys(window.userSettings).includes("audio") || !Object.keys(window.userSettings.audio).includes("deessing")) { // For backwards compatibility
window.userSettings.audio.deessing = 0.1
}
if (!Object.keys(window.userSettings).includes("audio") || !Object.keys(window.userSettings.audio).includes("nr")) { // For backwards compatibility
window.userSettings.audio.nr = 5
}
if (!Object.keys(window.userSettings).includes("audio") || !Object.keys(window.userSettings.audio).includes("nf")) { // For backwards compatibility
window.userSettings.audio.nf = -20
}
if (!Object.keys(window.userSettings).includes("audio") || !Object.keys(window.userSettings.audio).includes("ffmpeg")) { // For backwards compatibility
window.userSettings.audio.ffmpeg = true
}
// if (!Object.keys(window.userSettings).includes("audio") || !Object.keys(window.userSettings.audio).includes("ffmpeg_preview")) { // For backwards compatibility
// window.userSettings.audio.ffmpeg_preview = true
// }
if (!Object.keys(window.userSettings).includes("audio") || !Object.keys(window.userSettings.audio).includes("useNR")) { // For backwards compatibility
window.userSettings.audio.useNR = true
}
if (!Object.keys(window.userSettings).includes("audio") || !Object.keys(window.userSettings.audio).includes("bitdepth")) { // For backwards compatibility
window.userSettings.audio.bitdepth = "pcm_s32le"
}
if (!Object.keys(window.userSettings).includes("showEditorFFMPEGAmplitude")) { // For backwards compatibility
window.userSettings.showEditorFFMPEGAmplitude = false
}
if (!Object.keys(window.userSettings).includes("vocoder")) { // For backwards compatibility
window.userSettings.vocoder = "256_waveglow"
}
if (!Object.keys(window.userSettings).includes("audio") || !Object.keys(window.userSettings.audio).includes("amplitude")) { // For backwards compatibility
window.userSettings.audio.amplitude = 1
}
if (!Object.keys(window.userSettings).includes("max_filename_chars")) { // For backwards compatibility
window.userSettings.max_filename_chars = 70
}
if (!Object.keys(window.userSettings).includes("clear_text_after_synth")) { // For backwards compatibility
window.userSettings.clear_text_after_synth = false
}
if (!Object.keys(window.userSettings).includes("do_model_version_highlight")) { // For backwards compatibility
window.userSettings.do_model_version_highlight = false
}
if (!Object.keys(window.userSettings).includes("model_version_highlight")) { // For backwards compatibility
window.userSettings.model_version_highlight = 3.0
}
if (!Object.keys(window.userSettings).includes("do_pitchrangeoverride")) { // For backwards compatibility
window.userSettings.do_pitchrangeoverride = false
}
if (!Object.keys(window.userSettings).includes("pitchrangeoverride")) { // For backwards compatibility
window.userSettings.pitchrangeoverride = 6.0
}
if (!Object.keys(window.userSettings).includes("keepPaceOnNew")) { // For backwards compatibility
window.userSettings.keepPaceOnNew = true
}
if (!Object.keys(window.userSettings).includes("batchOutFolder")) { // For backwards compatibility
window.userSettings.batchOutFolder = `${__dirname.replace(/\\/g,"/")}/batch`.replace(/\/\//g, "/").replace("resources/app/resources/app", "resources/app").replace("/javascript", "")
}
if (!Object.keys(window.userSettings).includes("batch_clearDirFirst")) { // For backwards compatibility
window.userSettings.batch_clearDirFirst = false
}
// if (!Object.keys(window.userSettings).includes("batch_fastMode")) { // For backwards compatibility
// window.userSettings.batch_fastMode = false
// }
// if (!Object.keys(window.userSettings).includes("batch_fastModeMaxParallelizations")) { // For backwards compatibility
// window.userSettings.batch_fastModeMaxParallelizations = 1000
// }
if (!Object.keys(window.userSettings).includes("batch_json")) { // For backwards compatibility
window.userSettings.batch_json = false
}
if (!Object.keys(window.userSettings).includes("batch_useMP")) { // For backwards compatibility
window.userSettings.batch_useMP = false
}
if (!Object.keys(window.userSettings).includes("batch_MPCount")) { // For backwards compatibility
window.userSettings.batch_MPCount = 0
}
if (!Object.keys(window.userSettings).includes("batch_skipExisting")) { // For backwards compatibility
window.userSettings.batch_skipExisting = true
}
if (!Object.keys(window.userSettings).includes("batch_doGrouping")) { // For backwards compatibility
window.userSettings.batch_doGrouping = true
}
if (!Object.keys(window.userSettings).includes("batch_doVocoderGrouping")) { // For backwards compatibility
window.userSettings.batch_doVocoderGrouping = false
}
if (!Object.keys(window.userSettings).includes("batch_delimiter")) { // For backwards compatibility
window.userSettings.batch_delimiter = ","
}
if (!Object.keys(window.userSettings).includes("batch_paginationSize")) { // For backwards compatibility
window.userSettings.batch_paginationSize = 100
}
if (!Object.keys(window.userSettings).includes("defaultToHiFi")) { // For backwards compatibility
window.userSettings.defaultToHiFi = true
}
if (!Object.keys(window.userSettings).includes("batch_batchSize")) { // For backwards compatibility
window.userSettings.batch_batchSize = 1
}
if (!Object.keys(window.userSettings).includes("autoPlayGen")) { // For backwards compatibility
window.userSettings.autoPlayGen = true
}
if (!Object.keys(window.userSettings).includes("outputJSON")) { // For backwards compatibility
window.userSettings.outputJSON = true
}
if (!Object.keys(window.userSettings).includes("keepEditorOnVoiceChange")) { // For backwards compatibility
window.userSettings.keepEditorOnVoiceChange = false
}
if (!Object.keys(window.userSettings).includes("filenameNumericalSeq")) { // For backwards compatibility
window.userSettings.filenameNumericalSeq = false
}
if (!Object.keys(window.userSettings).includes("spacePadding")) { // For backwards compatibility
window.userSettings.spacePadding = true
}
if (!Object.keys(window.userSettings).includes("useErrorSound")) { // For backwards compatibility
window.userSettings.useErrorSound = false
}
if (!Object.keys(window.userSettings).includes("showTipOfTheDay")) { // For backwards compatibility
window.userSettings.showTipOfTheDay = true
}
if (!Object.keys(window.userSettings).includes("showUnseenTipOfTheDay")) { // For backwards compatibility
window.userSettings.showUnseenTipOfTheDay = false
}
if (!Object.keys(window.userSettings).includes("playChangedAudio")) { // For backwards compatibility
window.userSettings.playChangedAudio = false
}
if (!Object.keys(window.userSettings).includes("errorSoundFile")) { // For backwards compatibility
window.userSettings.errorSoundFile = `${__dirname.replace(/\\/g,"/")}/lib/xp_error.mp3`.replace(/\/\//g, "/").replace("resources/app/resources/app", "resources/app").replace("/javascript", "")
}
if (!Object.keys(window.userSettings).includes("plugins")) { // For backwards compatibility
window.userSettings.plugins = {}
}
if (!Object.keys(window.userSettings.plugins).includes("loadOrder")) { // For backwards compatibility
window.userSettings.plugins.loadOrder = ""
}
if (!Object.keys(window.userSettings).includes("externalAudioEditor")) { // For backwards compatibility
window.userSettings.externalAudioEditor = ""
}
if (!Object.keys(window.userSettings).includes("s2s_autogenerate")) { // For backwards compatibility
window.userSettings.s2s_autogenerate = true
}
if (!Object.keys(window.userSettings).includes("s2s_prePitchShift")) { // For backwards compatibility
window.userSettings.s2s_prePitchShift = false
}
if (!Object.keys(window.userSettings).includes("s2s_removeNoise")) { // For backwards compatibility
window.userSettings.s2s_removeNoise = false
}
if (!Object.keys(window.userSettings).includes("s2s_noiseRemStrength")) { // For backwards compatibility
window.userSettings.s2s_noiseRemStrength = 0.25
}
if (!Object.keys(window.userSettings).includes("vc_strength")) { // For backwards compatibility
window.userSettings.vc_strength = 2
}
if (!Object.keys(window.userSettings).includes("waveglow_path")) { // For backwards compatibility
window.userSettings.waveglow_path = `${__dirname.replace(/\\/g,"/")}/models/waveglow_256channels_universal_v4.pt`.replace(/\/\//g, "/").replace("resources/app/resources/app", "resources/app").replace("/javascript", "")
}
if (!Object.keys(window.userSettings).includes("bigwaveglow_path")) { // For backwards compatibility
window.userSettings.bigwaveglow_path = `${__dirname.replace(/\\/g,"/")}/models/nvidia_waveglowpyt_fp32_20190427.pt`.replace(/\/\//g, "/").replace("resources/app/resources/app", "resources/app").replace("/javascript", "")
}
if (!Object.keys(window.userSettings).includes("arpabet_paginationSize")) { // For backwards compatibility
window.userSettings.arpabet_paginationSize = 200
}
if (!Object.keys(window.userSettings).includes("output_files_pagination_size")) { // For backwards compatibility
window.userSettings.output_files_pagination_size = 25
}
const updateUIWithSettings = () => {
useGPUCbx.checked = window.userSettings.useGPU
autoplay_ckbx.checked = window.userSettings.autoplay
// setting_slidersTooltip.checked = window.userSettings.sliderTooltip
setting_defaultToHiFi.checked = window.userSettings.defaultToHiFi
setting_keepPaceOnNew.checked = window.userSettings.keepPaceOnNew
setting_autoplaygenCbx.checked = window.userSettings.autoPlayGen
// setting_darkprompt.checked = window.userSettings.darkPrompt
setting_show_discord_status.checked = window.userSettings.showDiscordStatus
setting_prompt_fontSize.value = window.userSettings.prompt_fontSize
setting_bg_gradient_opacity.value = window.userSettings.bg_gradient_opacity
setting_areload_voices.checked = window.userSettings.autoReloadVoices
setting_output_json.checked = window.userSettings.outputJSON
setting_output_num_seq.checked = window.userSettings.filenameNumericalSeq
setting_space_padding.checked = window.userSettings.spacePadding
setting_keepEditorOnVoiceChange.checked = window.userSettings.keepEditorOnVoiceChange
setting_use_error_sound.checked = window.userSettings.useErrorSound
setting_error_sound_file.value = window.userSettings.errorSoundFile
setting_showTipOfTheDay.checked = window.userSettings.showTipOfTheDay
totdShowTips.checked = window.userSettings.showTipOfTheDay
setting_showUnseenTipOfTheDay.checked = window.userSettings.showUnseenTipOfTheDay
totdShowOnlyUnseenTips.checked = window.userSettings.showUnseenTipOfTheDay
setting_playChangedAudio.checked = window.userSettings.playChangedAudio
setting_external_audio_editor.value = window.userSettings.externalAudioEditor
setting_audio_ffmpeg.checked = window.userSettings.audio.ffmpeg
// setting_audio_ffmpeg_preview.checked = window.userSettings.audio.ffmpeg && window.userSettings.audio.ffmpeg_preview
setting_audio_useNR.checked = window.userSettings.audio.ffmpeg && window.userSettings.audio.useNR
setting_audio_format.value = window.userSettings.audio.format
setting_audio_hz.value = window.userSettings.audio.hz
setting_audio_pad_start.value = window.userSettings.audio.padStart
setting_audio_pad_end.value = window.userSettings.audio.padEnd
setting_audio_pitchMult.value = window.userSettings.audio.pitchMult
setting_audio_tempo.value = window.userSettings.audio.tempo
setting_audio_deessing.value = window.userSettings.audio.deessing
setting_audio_nr.value = window.userSettings.audio.nr
setting_audio_nf.value = window.userSettings.audio.nf
setting_audio_bitdepth.value = window.userSettings.audio.bitdepth
setting_audio_amplitude.value = window.userSettings.audio.amplitude
setting_editor_audio_amplitude.value = window.userSettings.audio.amplitude
setting_show_editor_ffmpegamplitude.checked = window.userSettings.showEditorFFMPEGAmplitude
editor_amplitude_options.style.display = window.userSettings.showEditorFFMPEGAmplitude ? "flex" : "none"
// setting_s2s_autogenerate.checked = window.userSettings.s2s_autogenerate
// setting_s2s_prePitchShift.checked = window.userSettings.s2s_prePitchShift
// setting_s2s_removeNoise.checked = window.userSettings.s2s_removeNoise
// setting_s2s_noiseRemStrength.value = window.userSettings.s2s_noiseRemStrength
setting_s2s_vcstrength.value = window.userSettings.vc_strength
setting_batch_json.checked = window.userSettings.batch_json
// setting_batch_fastmode.checked = window.userSettings.batch_fastMode // No more fast modde. TODO, remove completely
// setting_batch_maxFastModeParallelizations.value = window.userSettings.batch_fastModeMaxParallelizations // No more fast modde. TODO, remove completely
setting_batch_multip.checked = window.userSettings.batch_useMP
setting_batch_multip_count.value = window.userSettings.batch_MPCount
setting_batch_delimiter.value = window.userSettings.batch_delimiter
setting_batch_paginationSize.value = window.userSettings.batch_paginationSize
setting_batch_doGrouping.checked = window.userSettings.batch_doGrouping
setting_batch_doVocoderGrouping.checked = window.userSettings.batch_doVocoderGrouping
batch_batchSizeInput.value = parseInt(window.userSettings.batch_batchSize)
batch_skipExisting.checked = window.userSettings.batch_skipExisting
batch_clearDirFirstCkbx.checked = window.userSettings.batch_clearDirFirst
setting_256waveglow_path.value = window.userSettings.waveglow_path
setting_bigwaveglow_path.value = window.userSettings.bigwaveglow_path
setting_arpabet_paginationSize.value = window.userSettings.arpabet_paginationSize
setting_output_files_pagination_size.value = window.userSettings.output_files_pagination_size
setting_max_filename_chars.value = window.userSettings.max_filename_chars
setting_clear_text_after_synth.checked = window.userSettings.clear_text_after_synth
setting_do_model_version_highlight.checked = window.userSettings.do_model_version_highlight
setting_model_version_highlight.value = window.userSettings.model_version_highlight
setting_pitchrangeoverrideEnabledCkbx.checked = window.userSettings.do_pitchrangeoverride
setting_pitchrangeoverride.value = window.userSettings.pitchrangeoverride
const [height, width] = window.userSettings.customWindowSize.split(",").map(v => parseInt(v))
ipcRenderer.send("resize", {height, width})
}
updateUIWithSettings()
saveUserSettings()
// Add the SVG code this way, because otherwise the index.html file will be spammed with way too much svg code
Array.from(window.document.querySelectorAll(".svgButton")).forEach(svgButton => {
svgButton.innerHTML = ``
})
// Installation sever handling
// =========================
settings_installation.innerHTML = window.userSettings.installation=="cpu" ? `CPU` : "CPU+GPU"
setting_change_installation.innerHTML = window.userSettings.installation=="cpu" ? `Change to CPU+GPU` : `Change to CPU`
setting_change_installation.addEventListener("click", () => {
spinnerModal("Changing installation sever...")
doFetch(`http://localhost:8008/stopServer`, {
method: "Post",
body: JSON.stringify({})
}).then(r=>r.text()).then(console.log) // The server stopping should mean this never runs
.catch(() => {
if (window.userSettings.installation=="cpu") {
window.userSettings.installation = "gpu"
useGPUCbx.disabled = false
settings_installation.innerHTML = `GPU`
setting_change_installation.innerHTML = `Change to CPU`
} else {
doFetch(`http://localhost:8008/setDevice`, {
method: "Post",
body: JSON.stringify({device: "cpu"})
})
window.userSettings.installation = "cpu"
useGPUCbx.checked = false
useGPUCbx.disabled = true
window.userSettings.useGPU = false
settings_installation.innerHTML = `CPU`
setting_change_installation.innerHTML = `Change to CPU+GPU`
}
saveUserSettings()
// Start the new server
if (window.PRODUCTION) {
window.appLogger.log(window.userSettings.installation)
window.pythonProcess = spawn(`${path}/cpython_${window.userSettings.installation}/server.exe`, {stdio: "ignore"})
} else {
window.pythonProcess = spawn("python", [`${path}/server.py`], {stdio: "ignore"})
}
window.currentModel = undefined
titleName.innerHTML = window.i18n.SELECT_VOICE_TYPE
keepSampleButton.style.display = "none"
wavesurferContainer.innerHTML = ""
generateVoiceButton.dataset.modelQuery = "null"
generateVoiceButton.dataset.modelIDLoaded = undefined
generateVoiceButton.innerHTML = window.i18n.LOAD_MODEL
generateVoiceButton.disabled = true
window.serverIsUp = false
window.doWeirdServerStartupCheck(`${window.i18n.LOADING}...
${window.i18n.MAY_TAKE_A_MINUTE}
${window.i18n.STARTING_PYTHON}...`)
})
})
// =========================
// Audio hardware
// ==============
navigator.mediaDevices.enumerateDevices().then(devices => {
devices = devices.filter(device => device.kind=="audiooutput" && device.deviceId!="communications")
// Base device
devices.forEach(device => {
const option = createElem("option", device.label)
option.value = device.deviceId
setting_base_speaker.appendChild(option)
})
setting_base_speaker.addEventListener("change", () => {
window.userSettings.base_speaker = setting_base_speaker.value
window.saveUserSettings()
window.document.querySelectorAll("audio").forEach(audioElem => {
audioElem.setSinkId(window.userSettings.base_speaker)
})
})
if (Object.keys(window.userSettings).includes("base_speaker")) {
setting_base_speaker.value = window.userSettings.base_speaker
} else {
window.userSettings.base_speaker = setting_base_speaker.value
window.saveUserSettings()
}
// Alternate device
devices.forEach(device => {
const option = createElem("option", device.label)
option.value = device.deviceId
setting_alt_speaker.appendChild(option)
})
setting_alt_speaker.addEventListener("change", () => {
window.userSettings.alt_speaker = setting_alt_speaker.value
window.saveUserSettings()
})
if (Object.keys(window.userSettings).includes("alt_speaker")) {
setting_alt_speaker.value = window.userSettings.alt_speaker
} else {
window.userSettings.alt_speaker = setting_alt_speaker.value
window.saveUserSettings()
}
})
// Settings Menu
// =============
useGPUCbx.addEventListener("change", () => {
spinnerModal(window.i18n.CHANGING_DEVICE)
doFetch(`http://localhost:8008/setDevice`, {
method: "Post",
body: JSON.stringify({device: useGPUCbx.checked ? "gpu" : "cpu"})
}).then(r=>r.text()).then(res => {
window.closeModal(undefined, settingsContainer)
window.userSettings.useGPU = useGPUCbx.checked
saveUserSettings()
}).catch(e => {
console.log(e)
if (e.code =="ENOENT") {
window.closeModal(undefined, settingsContainer).then(() => {
window.errorModal(window.i18n.THERE_WAS_A_PROBLEM)
})
}
})
})
const initMenuSetting = (elem, setting, type, callback=undefined, valFn=undefined) => {
valFn = valFn ? valFn : x=>x
if (type=="checkbox") {
elem.addEventListener("click", () => {
if (setting.includes(".")) {
window.userSettings[setting.split(".")[0]][setting.split(".")[1]] = valFn(elem.checked)
} else {
window.userSettings[setting] = valFn(elem.checked)
}
saveUserSettings()
if (callback) callback()
})
} else {
elem.addEventListener("change", () => {
if (setting.includes(".")) {
window.userSettings[setting.split(".")[0]][setting.split(".")[1]] = valFn(elem.value)
} else {
window.userSettings[setting] = valFn(elem.value)
}
saveUserSettings()
if (callback) callback()
})
}
}
window.initFilePickerButton = (button, input, setting, properties, filters=undefined, defaultPath=undefined, callback=undefined) => {
button.addEventListener("click", () => {
const defaultPath = input.value.replace(/\//g, "\\")
er.dialog.showOpenDialog({ properties, filters, defaultPath}).then(filePath => {
if (filePath) {
filePath = filePath.filePaths[0].replace(/\\/g, "/")
input.value = filePath.replace(/\\/g, "/")
setting = typeof(setting)=="function" ? setting() : setting
window.userSettings[setting] = filePath
saveUserSettings()
if (callback) {
callback()
}
}
})
})
}
const setPromptTheme = () => {
// if (window.userSettings.darkPrompt) {
// dialogueInput.style.backgroundColor = "rgba(25,25,25,0.9)"
// dialogueInput.style.color = "white"
// } else {
// dialogueInput.style.backgroundColor = "rgba(255,255,255,0.9)"
// dialogueInput.style.color = "black"
// }
}
const updateDiscord = () => {
let gameName = undefined
if (window.userSettings.showDiscordStatus && window.currentGame) {
gameName = window.currentGame.gameName
}
ipcRenderer.send('updateDiscord', {details: gameName})
}
const setPromptFontSize = () => {
dialogueInput.style.fontSize = `${window.userSettings.prompt_fontSize}pt`
}
const updateBackground = () => {
const background = `linear-gradient(0deg, rgba(128,128,128,${window.userSettings.bg_gradient_opacity}) 0px, rgba(0,0,0,0)), url("assets/${window.currentGame.assetFile}")`
// Fade the background image transition
rightBG1.style.background = background
rightBG2.style.opacity = 0
setTimeout(() => {
rightBG2.style.background = rightBG1.style.background
rightBG2.style.opacity = 1
}, 1000)
}
initMenuSetting(setting_autoplaygenCbx, "autoPlayGen", "checkbox")
// initMenuSetting(setting_slidersTooltip, "sliderTooltip", "checkbox")
initMenuSetting(setting_defaultToHiFi, "defaultToHiFi", "checkbox")
initMenuSetting(setting_keepPaceOnNew, "keepPaceOnNew", "checkbox")
initMenuSetting(setting_areload_voices, "autoReloadVoices", "checkbox")
initMenuSetting(setting_output_json, "outputJSON", "checkbox")
initMenuSetting(setting_keepEditorOnVoiceChange, "keepEditorOnVoiceChange", "checkbox")
initMenuSetting(setting_output_num_seq, "filenameNumericalSeq", "checkbox")
initMenuSetting(setting_space_padding, "spacePadding", "checkbox")
// initMenuSetting(setting_darkprompt, "darkPrompt", "checkbox", setPromptTheme)
initMenuSetting(setting_show_discord_status, "showDiscordStatus", "checkbox", updateDiscord)
initMenuSetting(setting_prompt_fontSize, "prompt_fontSize", "number", setPromptFontSize)
initMenuSetting(setting_bg_gradient_opacity, "bg_gradient_opacity", "number", updateBackground)
initMenuSetting(setting_use_error_sound, "useErrorSound", "checkbox")
initMenuSetting(setting_error_sound_file, "errorSoundFile", "text")
initFilePickerButton(setting_errorSoundFileBtn, setting_error_sound_file, "errorSoundFile", ["openFile"], [{name: "Audio", extensions: ["wav", "mp3", "ogg"]}])
initMenuSetting(setting_showTipOfTheDay, "showTipOfTheDay", "checkbox", () => {
totdShowTips.checked = setting_showTipOfTheDay.checked
})
initMenuSetting(totdShowTips, "showTipOfTheDay", "checkbox", () => {
setting_showTipOfTheDay.checked = totdShowTips.checked
})
initMenuSetting(setting_showUnseenTipOfTheDay, "showUnseenTipOfTheDay", "checkbox", () => {
totdShowOnlyUnseenTips.checked = setting_showUnseenTipOfTheDay.checked
})
initMenuSetting(totdShowOnlyUnseenTips, "showUnseenTipOfTheDay", "checkbox", () => {
setting_showUnseenTipOfTheDay.checked = totdShowOnlyUnseenTips.checked
})
initMenuSetting(setting_playChangedAudio, "playChangedAudio", "checkbox")
initMenuSetting(setting_external_audio_editor, "externalAudioEditor", "text")
initFilePickerButton(setting_externalEditorButton, setting_external_audio_editor, "externalAudioEditor", ["openFile"])
initMenuSetting(setting_audio_ffmpeg, "audio.ffmpeg", "checkbox", () => {
// setting_audio_ffmpeg_preview.checked = window.userSettings.audio.ffmpeg && window.userSettings.audio.ffmpeg_preview
// setting_audio_ffmpeg_preview.disabled = !window.userSettings.audio.ffmpeg
setting_audio_useNR.checked = window.userSettings.audio.ffmpeg && window.userSettings.audio.useNR
setting_audio_useNR.disabled = !window.userSettings.audio.ffmpeg
setting_audio_format.disabled = !window.userSettings.audio.ffmpeg
setting_audio_hz.disabled = !window.userSettings.audio.ffmpeg
setting_audio_pad_start.disabled = !window.userSettings.audio.ffmpeg
setting_audio_pad_end.disabled = !window.userSettings.audio.ffmpeg
setting_audio_pitchMult.disabled = !window.userSettings.audio.ffmpeg
setting_audio_tempo.disabled = !window.userSettings.audio.ffmpeg
setting_audio_deessing.disabled = !window.userSettings.audio.ffmpeg
setting_audio_nr.disabled = !window.userSettings.audio.ffmpeg
setting_audio_nf.disabled = !window.userSettings.audio.ffmpeg
setting_audio_bitdepth.disabled = !window.userSettings.audio.ffmpeg
setting_audio_amplitude.disabled = !window.userSettings.audio.ffmpeg
setting_editor_audio_amplitude.disabled = !window.userSettings.audio.ffmpeg
})
// initMenuSetting(setting_audio_ffmpeg_preview, "audio.ffmpeg_preview", "checkbox")
initMenuSetting(setting_audio_useNR, "audio.useNR", "checkbox")
initMenuSetting(setting_audio_format, "audio.format", "text")
initMenuSetting(setting_audio_hz, "audio.hz", "text", undefined, parseInt)
initMenuSetting(setting_audio_pad_start, "audio.padStart", "text", undefined, parseInt)
initMenuSetting(setting_audio_pad_end, "audio.padEnd", "text", undefined, parseInt)
initMenuSetting(setting_audio_pitchMult, "audio.pitchMult", "number", undefined, parseFloat)
initMenuSetting(setting_audio_tempo, "audio.tempo", "number", undefined, parseFloat)
initMenuSetting(setting_audio_deessing, "audio.deessing", "number", undefined, parseFloat)
initMenuSetting(setting_audio_nr, "audio.nr", "number", undefined, parseFloat)
initMenuSetting(setting_audio_nf, "audio.nf", "number", undefined, parseFloat)
initMenuSetting(setting_audio_bitdepth, "audio.bitdepth", "select")
initMenuSetting(setting_audio_amplitude, "audio.amplitude", "number", () => {
setting_editor_audio_amplitude.value = setting_audio_amplitude.value
}, parseFloat)
initMenuSetting(setting_editor_audio_amplitude, "audio.amplitude", "number", () => {
setting_audio_amplitude.value = setting_editor_audio_amplitude.value
}, parseFloat)
initMenuSetting(setting_show_editor_ffmpegamplitude, "showEditorFFMPEGAmplitude", "checkbox", () => {
editor_amplitude_options.style.display = window.userSettings.showEditorFFMPEGAmplitude ? "flex" : "none"
})
initMenuSetting(setting_batch_json, "batch_json", "checkbox")
// initMenuSetting(setting_batch_fastmode, "batch_fastMode", "checkbox") // No more fast modde. TODO, remove completely
// initMenuSetting(setting_batch_maxFastModeParallelizations, "batch_fastModeMaxParallelizations", "number") // No more fast modde. TODO, remove completely
initMenuSetting(setting_batch_multip, "batch_useMP", "checkbox")
initMenuSetting(setting_batch_multip_count, "batch_MPCount", "number", undefined, parseInt)
initMenuSetting(setting_batch_doGrouping, "batch_doGrouping", "checkbox")
initMenuSetting(setting_batch_doVocoderGrouping, "batch_doVocoderGrouping", "checkbox")
initMenuSetting(batch_clearDirFirstCkbx, "batch_clearDirFirst", "checkbox")
initMenuSetting(batch_skipExisting, "batch_skipExisting", "checkbox")
initMenuSetting(batch_batchSizeInput, "batch_batchSize", "text", undefined, parseInt)
initMenuSetting(setting_batch_delimiter, "batch_delimiter")
initMenuSetting(setting_batch_paginationSize, "batch_paginationSize", "number", undefined, parseInt)
// initMenuSetting(setting_s2s_autogenerate, "s2s_autogenerate", "checkbox")
// initMenuSetting(setting_s2s_prePitchShift, "s2s_prePitchShift", "checkbox")
// initMenuSetting(setting_s2s_removeNoise, "s2s_removeNoise", "checkbox")
// initMenuSetting(setting_s2s_noiseRemStrength, "s2s_noiseRemStrength", "number", undefined, parseFloat)
initMenuSetting(setting_s2s_vcstrength, "vc_strength", "number", undefined, parseFloat)
initMenuSetting(setting_256waveglow_path, "waveglow_path", "text")
initFilePickerButton(setting_waveglowPathButton, setting_256waveglow_path, "waveglow_path", ["openFile"], [{name: "Pytorch checkpoint", extensions: ["pt"]}])
initMenuSetting(setting_bigwaveglow_path, "bigwaveglow_path", "text")
initFilePickerButton(setting_bigwaveglowPathButton, setting_bigwaveglow_path, "bigwaveglow_path", ["openFile"], [{name: "Pytorch checkpoint", extensions: ["pt"]}])
initFilePickerButton(setting_modelsPathButton, setting_models_path_input, ()=>`modelspath_${window.currentGame.gameId}`, ["openDirectory"], undefined, undefined, ()=>window.updateGameList())
initFilePickerButton(setting_outPathButton, setting_out_path_input, ()=>`outpath_${window.currentGame.gameId}`, ["openDirectory"], undefined, undefined, ()=>{
if (window.currentModelButton) {
window.currentModelButton.click()
}
})
initMenuSetting(setting_arpabet_paginationSize, "arpabet_paginationSize", "number", undefined, parseInt)
initMenuSetting(setting_output_files_pagination_size, "output_files_pagination_size", "number", () => {
window.resetPagination()
window.refreshRecordsList()
}, parseInt)
initMenuSetting(setting_max_filename_chars, "max_filename_chars", "number", undefined, parseInt)
initMenuSetting(setting_clear_text_after_synth, "clear_text_after_synth", "checkbox")
initMenuSetting(setting_do_model_version_highlight, "do_model_version_highlight", "checkbox", ()=>window.changeGame(window.currentGame))
initMenuSetting(setting_model_version_highlight, "model_version_highlight", "number", ()=>window.changeGame(window.currentGame), parseFloat)
const updateSequenceEditorRange = () => {
if (window.sequenceEditor.isCreated && window.currentModel) {
const pitchRange = window.userSettings.pitchrangeoverride ? window.userSettings.pitchrangeoverride : window.sequenceEditor.pitchSliderRange
// Make sure to cap the existing values if upding the range to be smaller than the current values
if (window.userSettings.pitchrangeoverride) {
window.sequenceEditor.pitchNew.forEach((val,vi) => {
if (Math.abs(val)>window.userSettings.pitchrangeoverride) {
val = Math.max(-window.userSettings.pitchrangeoverride, Math.min(window.userSettings.pitchrangeoverride, val))
window.sequenceEditor.pitchNew[vi] = val
}
})
}
window.sequenceEditor.update(window.currentModel.modelType, pitchRange)
}
}
initMenuSetting(setting_pitchrangeoverrideEnabledCkbx, "do_pitchrangeoverride", "checkbox", updateSequenceEditorRange)
initMenuSetting(setting_pitchrangeoverride, "pitchrangeoverride", "number", updateSequenceEditorRange, parseFloat)
setPromptTheme()
setPromptFontSize()
setting_audio_format.disabled = !window.userSettings.audio.ffmpeg
setting_audio_hz.disabled = !window.userSettings.audio.ffmpeg
setting_audio_pad_start.disabled = !window.userSettings.audio.ffmpeg
setting_audio_pad_end.disabled = !window.userSettings.audio.ffmpeg
setting_audio_pitchMult.disabled = !window.userSettings.audio.ffmpeg
setting_audio_tempo.disabled = !window.userSettings.audio.ffmpeg
setting_audio_deessing.disabled = !window.userSettings.audio.ffmpeg
setting_audio_nr.disabled = !window.userSettings.audio.ffmpeg
setting_audio_nf.disabled = !window.userSettings.audio.ffmpeg
setting_audio_bitdepth.disabled = !window.userSettings.audio.ffmpeg
setting_audio_amplitude.disabled = !window.userSettings.audio.ffmpeg
setting_editor_audio_amplitude.disabled = !window.userSettings.audio.ffmpeg
openDiscord.addEventListener("click", () => {
shell.openExternal("https://discord.gg/nv7c6E2TzV")
})
setting_models_path_input.addEventListener("change", () => {
const gameFolder = window.currentGame.gameId
setting_models_path_input.value = setting_models_path_input.value.replace(/\/\//g, "/").replace(/\\/g,"/")
window.userSettings[`modelspath_${gameFolder}`] = setting_models_path_input.value
window.saveUserSettings()
window.loadAllModels().then(() => {
window.changeGame(window.currentGame)
})
if (!window.watchedModelsDirs.includes(setting_models_path_input.value)) {
window.watchedModelsDirs.push(setting_models_path_input.value)
fs.watch(setting_models_path_input.value, {recursive: false, persistent: true}, (eventType, filename) => {
window.changeGame(window.currentGame)
})
}
window.updateGameList()
// Gather the model paths to send to the server
const modelsPaths = {}
Object.keys(window.userSettings).filter(key => key.includes("modelspath_")).forEach(key => {
modelsPaths[key.split("_")[1]] = window.userSettings[key]
})
doFetch(`http://localhost:8008/setAvailableVoices`, {
method: "Post",
body: JSON.stringify({
modelsPaths: JSON.stringify(modelsPaths)
})
})
})
// Output path
fs.readdir(`${window.path}/models`, (err, gameDirs) => {
gameDirs.filter(name => !name.includes(".")).forEach(gameFolder => {
// Initialize the default output directory setting for this game
if (!Object.keys(window.userSettings).includes(`outpath_${gameFolder}`)) {
window.userSettings[`outpath_${gameFolder}`] = `${__dirname.replace(/\\/g,"/")}/output/${gameFolder}`.replace(/\/\//g, "/").replace("resources/app/resources/app", "resources/app").replace("/javascript", "")
window.saveUserSettings()
}
})
})
setting_out_path_input.addEventListener("change", () => {
const gameFolder = window.currentGame.gameId
setting_out_path_input.value = setting_out_path_input.value.replace(/\/\//g, "/").replace(/\\/g,"/")
window.userSettings[`outpath_${gameFolder}`] = setting_out_path_input.value
saveUserSettings()
if (window.currentModelButton) {
window.currentModelButton.click()
}
})
// Models path
const assetFiles = fs.readdirSync(`${window.path}/assets`)
assetFiles.filter(fn=>fn.endsWith(".json")).forEach(assetFileName => {
const gameId = assetFileName.split(".json")[0]
// Initialize the default models directory setting for this game
if (!Object.keys(window.userSettings).includes(`modelspath_${gameId}`)) {
window.userSettings[`modelspath_${gameId}`] = `${__dirname.replace(/\\/g,"/")}/models/${gameId}`.replace(/\/\//g, "/").replace("resources/app/resources/app", "resources/app").replace("/javascript", "")
window.userSettings[`outpath_${gameId}`] = `${__dirname.replace(/\\/g,"/")}/output/${gameId}`.replace(/\/\//g, "/").replace("resources/app/resources/app", "resources/app").replace("/javascript", "")
saveUserSettings()
}
})
// Batch stuff
// Output folder
batch_outputFolderInput.addEventListener("change", () => {
if (batch_outputFolderInput.value.length==0) {
window.errorModal(window.i18n.ENTER_DIR_PATH)
batch_outputFolderInput.value = window.userSettings.batchOutFolder
} else {
window.userSettings.batchOutFolder = batch_outputFolderInput.value
saveUserSettings()
}
})
batch_outputFolderInput.value = window.userSettings.batchOutFolder
// ======
reset_settings_btn.addEventListener("click", () => {
window.confirmModal(window.i18n.SURE_RESET_SETTINGS).then(confirmation => {
if (confirmation) {
window.userSettings.audio.format = "wav"
window.userSettings.audio.hz = 44100
window.userSettings.audio.padStart = 0
window.userSettings.audio.padEnd = 0
window.userSettings.audio.pitchMult = 1
window.userSettings.audio.tempo = 1
window.userSettings.audio.deessing = 0.1
window.userSettings.audio.nr = 5
window.userSettings.audio.nf = -20
window.userSettings.audio.ffmpeg = true
// window.userSettings.audio.ffmpeg_preview = true
window.userSettings.audio.useNR = true
window.userSettings.audio.amplitude = 1
window.userSettings.autoPlayGen = true
window.userSettings.autoReloadVoices = false
window.userSettings.autoplay = true
// window.userSettings.darkPrompt = false
window.userSettings.showDiscordStatus = true
window.userSettings.prompt_fontSize = 15
window.userSettings.bg_gradient_opacity = 13
window.userSettings.outputJSON = true
window.userSettings.keepEditorOnVoiceChange = false
window.userSettings.filenameNumericalSeq = false
window.userSettings.spacePadding = true
window.userSettings.useErrorSound = false
window.userSettings.showTipOfTheDay = true
window.userSettings.showUnseenTipOfTheDay = false
window.userSettings.playChangedAudio = false
window.userSettings.plugins = {}
window.userSettings.plugins.loadOrder = ""
window.userSettings.externalAudioEditor = ""
window.userSettings.s2s_autogenerate = true // TODO, remove
window.userSettings.s2s_prePitchShift = false // TODO, remove
window.userSettings.s2s_removeNoise = false // TODO, remove
window.userSettings.s2s_noiseRemStrength = 0.25 // TODO, remove
window.userSettings.vc_strength = 2
window.userSettings.defaultToHiFi = true
window.userSettings.keepPaceOnNew = true
window.userSettings.sliderTooltip = true
window.userSettings.audio.bitdepth = "pcm_s32le"
window.userSettings.showEditorFFMPEGAmplitude = false
window.userSettings.vocoder = "256_waveglow"
window.userSettings.max_filename_chars = 70
window.userSettings.clear_text_after_synth = false
window.userSettings.do_model_version_highlight = false
window.userSettings.model_version_highlight = 3.0
window.userSettings.do_pitchrangeoverride = false
window.userSettings.pitchrangeoverride = 6.0
window.userSettings.keepPaceOnNew = true
window.userSettings.arpabet_paginationSize = 200
window.userSettings.output_files_pagination_size = 25
window.userSettings.batch_clearDirFirst = false
window.userSettings.batch_fastMode = false
window.userSettings.batch_batchSize = 1
window.userSettings.batch_skipExisting = true
window.userSettings.batch_fastModeMaxParallelizations = 1000
window.userSettings.batch_json = false
window.userSettings.batch_useMP = false
window.userSettings.batch_MPCount = 0
window.userSettings.batch_doGrouping = true
window.userSettings.batch_doVocoderGrouping = false
window.userSettings.batch_delimiter = ","
window.userSettings.batch_paginationSize = 100
updateUIWithSettings()
saveUserSettings()
}
})
})
reset_paths_btn.addEventListener("click", () => {
window.confirmModal(window.i18n.SURE_RESET_PATHS).then(confirmation => {
if (confirmation) {
const pathKeys = Object.keys(window.userSettings).filter(key => key.includes("modelspath_"))
pathKeys.forEach(key => {
delete window.userSettings[key]
})
const currGame = window.currentGame ? window.currentGame.gameId : undefined
// Models and output paths
const assetFiles = fs.readdirSync(`${path}/assets`)
assetFiles.filter(fn=>fn.endsWith(".json")).forEach(jsonFileName => {
const gameId = jsonFileName.split(".")[0]
window.userSettings[`modelspath_${gameId}`] = `${__dirname.replace(/\\/g,"/")}/models/${gameId}`.replace(/\/\//g, "/").replace("resources/app/resources/app", "resources/app").replace("/javascript", "")
window.userSettings[`outpath_${gameId}`] = `${__dirname.replace(/\\/g,"/")}/output/${gameId}`.replace(/\/\//g, "/").replace("resources/app/resources/app", "resources/app").replace("/javascript", "")
if (gameId==currGame) {
setting_models_path_input.value = window.userSettings[`modelspath_${gameId}`]
setting_out_path_input.value = window.userSettings[`outpath_${gameId}`]
}
})
if (window.currentModelButton) {
window.currentModelButton.click()
}
window.userSettings.errorSoundFile = `${__dirname.replace(/\\/g,"/")}/lib/xp_error.mp3`.replace(/\/\//g, "/").replace("resources/app/resources/app", "resources/app").replace("/javascript", "")
window.userSettings.batchOutFolder = `${__dirname.replace(/\\/g,"/")}/batch`.replace(/\/\//g, "/").replace("resources/app/resources/app", "resources/app").replace("/javascript", "")
batch_outputFolderInput.value = window.userSettings.batchOutFolder
window.loadAllModels().then(() => {
if (currGame) {
window.changeGame(window.currentGame)
}
})
saveUserSettings()
// Gather the model paths to send to the server
const modelsPaths = {}
Object.keys(window.userSettings).filter(key => key.includes("modelspath_")).forEach(key => {
modelsPaths[key.split("_")[1]] = window.userSettings[key]
})
doFetch(`http://localhost:8008/setAvailableVoices`, {
method: "Post",
body: JSON.stringify({
modelsPaths: JSON.stringify(modelsPaths)
})
})
}
})
})
// Search settings
const settingItems = Array.from(settingsOptionsContainer.children)
searchSettingsInput.addEventListener("keyup", () => {
const query = searchSettingsInput.value.trim().toLowerCase()
const filteredItems = settingItems.map(el => {
if (el.tagName=="HR") {return [el, true]}
if (el.tagName=="DIV") {
if (!query.length || el.children[0].innerHTML.toLowerCase().includes(query)) {
return [el, true]
}
}
return [el, false]
})
let lastIsHR = false
filteredItems.forEach(elem => {
const [el, showIt] = elem
if (el.tagName=="HR") {
if (lastIsHR) {
el.style.display = "none"
return
}
lastIsHR = true
el.style.display = "flex"
} else {
if (showIt) {
el.style.display = "flex"
lastIsHR = false
} else {
el.style.display = "none"
}
}
})
})
const currentWindow = er.getCurrentWindow()
currentWindow.on("move", () => {
const bounds = er.getCurrentWindow().webContents.getOwnerBrowserWindow().getBounds()
window.userSettings.customWindowPosition = `${bounds.x},${bounds.y}`
saveUserSettings()
})
if (window.userSettings.customWindowPosition) {
ipcRenderer.send('updatePosition', {details: window.userSettings.customWindowPosition.split(",")})
}
window.saveUserSettings = saveUserSettings
exports.saveUserSettings = saveUserSettings
exports.deleteFolderRecursive = deleteFolderRecursive