Enhance audio page functionality: Added vuSensor state management and updated balance and vu sensitivity calculations. Adjusted slider ranges and improved real-time updates for audio settings. Localized system page labels for better user experience.
This commit is contained in:
@@ -58,14 +58,20 @@ export default function AudioPage() {
|
||||
const [, setLocation] = useLocation();
|
||||
const { deviceState, updateSetting } = useDevice();
|
||||
const ds = deviceState;
|
||||
const vuSensor = (ds as ({ vuSensor?: number } | null))?.vuSensor;
|
||||
|
||||
const balanceVal = ds?.balance ?? 0;
|
||||
// balance 从接口获取的是乘以 10 后的值,需要除以 10 显示(例如:-130 → -13.0)
|
||||
const balanceVal = ds?.balance !== undefined ? ds.balance / 10 : 0;
|
||||
// vuSensor 从接口获取的是放大 2 倍的值,需要除以 2 显示(例如:20 → +10dB)
|
||||
const vuSensVal = vuSensor !== undefined ? vuSensor / 2 : 0;
|
||||
const [localBalance, setLocalBalance] = useState(balanceVal);
|
||||
const [localVuSens, setLocalVuSens] = useState(12);
|
||||
const [localVuSens, setLocalVuSens] = useState(0);
|
||||
const [filterIdx] = useState(0);
|
||||
const isDragging = useRef(false);
|
||||
const isBalanceDragging = useRef(false);
|
||||
const isVuDragging = useRef(false);
|
||||
|
||||
useEffect(() => { if (!isDragging.current) setLocalBalance(balanceVal); }, [balanceVal]);
|
||||
useEffect(() => { if (!isBalanceDragging.current) setLocalBalance(balanceVal); }, [balanceVal]);
|
||||
useEffect(() => { if (!isVuDragging.current) setLocalVuSens(vuSensVal); }, [vuSensVal]);
|
||||
|
||||
const gainIdx = ds?.analogGain ?? 0;
|
||||
const stepIdx = ds?.soundStep ?? 1;
|
||||
@@ -99,12 +105,13 @@ export default function AudioPage() {
|
||||
{localBalance >= 0 ? `+${localBalance.toFixed(1)}` : localBalance.toFixed(1)} dB
|
||||
</span>
|
||||
</div>
|
||||
<CyanSlider value={localBalance} min={-10} max={10} step={0.1}
|
||||
<CyanSlider value={localBalance} min={-15} max={15} step={0.1}
|
||||
onChange={(v) => {
|
||||
isDragging.current = true;
|
||||
isBalanceDragging.current = true;
|
||||
setLocalBalance(v);
|
||||
updateSetting({ balance: v });
|
||||
setTimeout(() => { isDragging.current = false; }, 500);
|
||||
// 实时调用接口(例如:-13.0 → -130)
|
||||
updateSetting({ balance: Math.round(v * 10) });
|
||||
setTimeout(() => { isBalanceDragging.current = false; }, 500);
|
||||
}} />
|
||||
</div>
|
||||
<div className="border-t border-white/[0.06]" />
|
||||
@@ -112,14 +119,16 @@ export default function AudioPage() {
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="text-[16px] text-white">VU 表灵敏度</span>
|
||||
<span className="text-[16px] font-semibold" style={{ color: "#00FFF6" }}>
|
||||
{localVuSens} dB
|
||||
{localVuSens >= 0 ? `+${localVuSens}` : localVuSens} dB
|
||||
</span>
|
||||
</div>
|
||||
<CyanSlider value={localVuSens} min={0} max={24}
|
||||
<CyanSlider value={localVuSens} min={-20} max={20}
|
||||
onChange={(v) => {
|
||||
isDragging.current = true;
|
||||
isVuDragging.current = true;
|
||||
setLocalVuSens(v);
|
||||
setTimeout(() => { isDragging.current = false; }, 500);
|
||||
// 接口参数需要将显示值乘以 2(例如:10dB -> vuSensor=20)
|
||||
updateSetting({ vuSensor: Math.round(v * 2) });
|
||||
setTimeout(() => { isVuDragging.current = false; }, 500);
|
||||
}} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user