/** * 片段调速面板 — Drawer 形式 * 速度滑块(0.25x ~ 4x)+ 预设快捷按钮 + 音调修正开关 * 支持应用到当前片段 / 所有片段 */ import React, { useCallback } from "react" import { Drawer, Slider } from "antd" import type { SpeedConfig } from "../types" import { DEFAULT_SPEED } from "../types" /* ──────────── 预设速度 ──────────── */ const SPEED_PRESETS: { rate: number; label: string }[] = [ { rate: 0.5, label: "0.5x" }, { rate: 1.0, label: "1x" }, { rate: 1.5, label: "1.5x" }, { rate: 2.0, label: "2x" }, ] /* ──────────── Props ──────────── */ interface SpeedPanelProps { open: boolean onClose: () => void /** 当前片段调速配置 */ config: SpeedConfig onChange: (config: SpeedConfig) => void /** 应用到所有片段 */ onApplyAll?: (config: SpeedConfig) => void } const SpeedPanel: React.FC = ({ open, onClose, config, onChange, onApplyAll }) => { /* ── 修改速度 ── */ const handleChangeRate = useCallback( (rate: number) => { onChange({ ...config, rate }) }, [config, onChange], ) /* ── 切换音调修正 ── */ const handleTogglePitch = useCallback(() => { onChange({ ...config, pitchCorrection: !config.pitchCorrection }) }, [config, onChange]) /* ── 选择预设 ── */ const handlePreset = useCallback( (rate: number) => { onChange({ ...config, rate }) }, [config, onChange], ) /* ── 应用到所有片段 ── */ const handleApplyAll = useCallback(() => { onApplyAll?.(config) }, [config, onApplyAll]) /* ── 重置 ── */ const handleReset = useCallback(() => { onChange({ ...DEFAULT_SPEED }) }, [onChange]) /* ── 速度描述文字 ── */ const speedLabel = config.rate < 1 ? "慢速(慢动作)" : config.rate === 1 ? "原速" : config.rate < 2 ? "快速" : "极速" return ( {/* ── 速度滑块 ── */}
播放速度 {config.rate.toFixed(2)}x
`${(v as number).toFixed(2)}x` }} />
0.25x 1x 2x 4x
{speedLabel}
{/* ── 预设快捷按钮 ── */}
快捷预设
{SPEED_PRESETS.map((p) => ( ))}
{/* ── 音调修正开关 ── */}
音调修正 {config.pitchCorrection ? "变速不变调(推荐)" : "变速同时变调"}
{/* ── 底部操作 ── */}
{onApplyAll && ( )}
) } export default SpeedPanel