voice-changer/client/demo_v13/src/001_globalHooks/001_useAppGuiSetting.ts

139 lines
4.0 KiB
TypeScript
Raw Normal View History

2023-04-04 10:38:30 +03:00
import { useState } from "react"
import { ClientType } from "@dannadori/voice-changer-client-js"
export type AppGuiSetting = AppGuiDemoSetting
export type AppGuiDemoSetting = {
type: "demo",
id: ClientType,
front: {
"title": {
"mainTitle": string,
"subTitle": string,
"lineNum": number
},
"serverControl": {
},
"modelSetting": {
"ONNXEnable": boolean,
"pyTorchEnable": boolean,
"MMVCCorrespondense": boolean,
"pyTorchClusterEnable": boolean,
2023-04-04 21:35:16 +03:00
"showPyTorchDefault": boolean
2023-04-04 10:38:30 +03:00
},
"deviceSetting": {},
"qualityControl": {
"F0DetectorEnable": boolean
},
2023-04-04 20:31:06 +03:00
"speakerSetting": {
"srcIdEnable": boolean
"editSpeakerIdMappingEnable": boolean
"f0FactorEnable": boolean
"tuningEnable": boolean
"clusterInferRationEnable": boolean
"noiseScaleEnable": boolean
"silentThresholdEnable": boolean
},
"converterSetting": {
"extraDataLengthEnable": boolean
},
"advancedSetting": {
"serverURLEnable": boolean,
"protocolEnable": boolean,
"sampleRateEnable": boolean,
"sendingSampleRateEnable": boolean,
"crossFadeOverlapSizeEnable": boolean,
"crossFadeOffsetRateEnable": boolean,
"crossFadeEndRateEnable": boolean,
"downSamplingModeEnable": boolean,
"trancateNumTresholdEnable": boolean,
}
2023-04-04 10:38:30 +03:00
},
dialogs: {
"license": { title: string, auther: string, contact: string, url: string, license: string }[]
}
}
const InitialAppGuiDemoSetting: AppGuiDemoSetting = {
type: "demo",
id: ClientType.MMVCv13,
front: {
"title": {
"mainTitle": "",
"subTitle": "",
"lineNum": 1
},
"serverControl": {
},
"modelSetting": {
"ONNXEnable": false,
"pyTorchEnable": false,
"MMVCCorrespondense": false,
"pyTorchClusterEnable": false,
2023-04-04 21:35:16 +03:00
"showPyTorchDefault": false
2023-04-04 10:38:30 +03:00
},
"deviceSetting": {},
"qualityControl": {
"F0DetectorEnable": false
},
2023-04-04 20:31:06 +03:00
"speakerSetting": {
"srcIdEnable": false,
"editSpeakerIdMappingEnable": false,
"f0FactorEnable": false,
"tuningEnable": false,
"clusterInferRationEnable": false,
"noiseScaleEnable": false,
"silentThresholdEnable": false
},
"converterSetting": {
"extraDataLengthEnable": false
},
"advancedSetting": {
"serverURLEnable": false,
"protocolEnable": false,
"sampleRateEnable": false,
"sendingSampleRateEnable": false,
"crossFadeOverlapSizeEnable": false,
"crossFadeOffsetRateEnable": false,
"crossFadeEndRateEnable": false,
"downSamplingModeEnable": false,
"trancateNumTresholdEnable": false,
}
2023-04-04 10:38:30 +03:00
},
dialogs: {
"license": [{ title: "", auther: "", contact: "", url: "", license: "MIT" }]
}
}
export type AppGuiSettingState = {
appGuiSetting: AppGuiSetting
2023-04-04 21:35:16 +03:00
guiSettingLoaded: boolean
2023-04-04 10:38:30 +03:00
}
export type AppGuiSettingStateAndMethod = AppGuiSettingState & {
getAppSetting: (url: string) => Promise<void>
}
export const userAppGuiSetting = (): AppGuiSettingStateAndMethod => {
2023-04-04 21:35:16 +03:00
const [guiSettingLoaded, setGuiSettingLoaded] = useState<boolean>(false)
2023-04-04 10:38:30 +03:00
const [appGuiSetting, setAppGuiSetting] = useState<AppGuiSetting>(InitialAppGuiDemoSetting)
const getAppSetting = async (url: string) => {
const res = await fetch(`${url}`, {
method: "GET",
})
const appSetting = await res.json() as AppGuiSetting
setAppGuiSetting(appSetting)
2023-04-04 21:35:16 +03:00
setGuiSettingLoaded(true)
2023-04-04 10:38:30 +03:00
}
return {
appGuiSetting,
2023-04-04 21:35:16 +03:00
guiSettingLoaded,
2023-04-04 10:38:30 +03:00
getAppSetting,
}
}