feat: 优化歌词视觉效果
This commit is contained in:
1 parent
82b1fa0d47
commit
60fbbced7d
6 files changed
+532
-47
No files matched your search
+177
-9
@@ -659,10 +659,83 @@
|
||||
<Select.Option value="none">无</Select.Option>
|
||||
</Select>
|
||||
</StyleField>
|
||||
|
||||
<StyleField label="显示下一句">
|
||||
<Switch checked={style.showNextLine !== false} onChange={v => set({ showNextLine: v })} />
|
||||
</StyleField>
|
||||
|
||||
<StyleField label="入场时长 (ms)">
|
||||
<InputNumber
|
||||
min={0} max={10000} step={50}
|
||||
value={style.enterDurationMs}
|
||||
onChange={v => set({ enterDurationMs: v == null ? 300 : v })}
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
</StyleField>
|
||||
<StyleField label="入场模糊半径 (px,模糊/出场用)">
|
||||
<InputNumber
|
||||
min={0} max={60} step={1}
|
||||
value={style.blurPx}
|
||||
onChange={v => set({ blurPx: v == null ? 10 : v })}
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
</StyleField>
|
||||
<StyleField label="出场动画">
|
||||
<Select value={style.outro} onChange={v => set({ outro: v })} style={{ width: '100%' }}>
|
||||
<Select.Option value="fade">淡出</Select.Option>
|
||||
<Select.Option value="blur">模糊消散</Select.Option>
|
||||
<Select.Option value="slideDown">下滑淡出</Select.Option>
|
||||
<Select.Option value="slideUp">上浮淡出</Select.Option>
|
||||
<Select.Option value="zoom">缩小淡出</Select.Option>
|
||||
<Select.Option value="custom">自定义(写 CSS)</Select.Option>
|
||||
<Select.Option value="none">无</Select.Option>
|
||||
</Select>
|
||||
</StyleField>
|
||||
<StyleField label="出场时长 (ms)">
|
||||
<InputNumber
|
||||
min={0} max={10000} step={50}
|
||||
value={style.outDurationMs}
|
||||
onChange={v => set({ outDurationMs: v == null ? 260 : v })}
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
</StyleField>
|
||||
|
||||
<StyleField label="入场后回缩到 (1 = 不回缩)">
|
||||
<InputNumber
|
||||
min={0.3} max={1} step={0.01}
|
||||
value={style.holdShrinkTo}
|
||||
onChange={v => set({ holdShrinkTo: v == null ? 1 : v })}
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
</StyleField>
|
||||
<StyleField label="回缩时长 (ms)">
|
||||
<InputNumber
|
||||
min={0} max={20000} step={100}
|
||||
value={style.shrinkDurationMs}
|
||||
onChange={v => set({ shrinkDurationMs: v == null ? 0 : v })}
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
</StyleField>
|
||||
<StyleField label="回缩效果">
|
||||
<Space style={{ height: 32 }}>
|
||||
<Button
|
||||
size="small"
|
||||
onClick={() => set({ holdShrinkTo: 0.92, shrinkDurationMs: 1200 })}
|
||||
>轻微回缩</Button>
|
||||
<Button
|
||||
size="small"
|
||||
onClick={() => set({ holdShrinkTo: 1, shrinkDurationMs: 0 })}
|
||||
disabled={Number(style.holdShrinkTo) === 1}
|
||||
>关闭</Button>
|
||||
</Space>
|
||||
</StyleField>
|
||||
<StyleField label="当前效果预览">
|
||||
<Text style={{ color: '#888', fontSize: 12 }}>
|
||||
入场 {Number(style.enterDurationMs || 0)}ms → 回缩到 {Number(style.holdShrinkTo || 1)}({Number(style.shrinkDurationMs || 0)}ms)
|
||||
→ 出场 {Number(style.outDurationMs || 0)}ms
|
||||
</Text>
|
||||
</StyleField>
|
||||
|
||||
<StyleField label="显示背景">
|
||||
<Switch
|
||||
checked={style.backgroundEnabled !== false}
|
||||
@@ -790,7 +863,9 @@
|
||||
);
|
||||
}
|
||||
|
||||
function LrcPreviewStage({ style, cue, text, nextText, playing, elapsed }) {
|
||||
const LRC_OUTRO_OPTIONS = ['none', 'fade', 'blur', 'slideDown', 'slideUp', 'zoom', 'custom'];
|
||||
|
||||
function LrcPreviewStage({ style, cue, text, nextText, playing, elapsed, phase, configKey, fittedTiming }) {
|
||||
const scale = 0.42;
|
||||
const alignItems = style.position === 'top' ? 'flex-start' : (style.position === 'center' ? 'center' : 'flex-end');
|
||||
const justifyContent = style.align === 'left' ? 'flex-start' : (style.align === 'right' ? 'flex-end' : 'center');
|
||||
@@ -806,9 +881,19 @@
|
||||
});
|
||||
}
|
||||
|
||||
const outro = LRC_OUTRO_OPTIONS.includes(style.outro) ? style.outro : 'fade';
|
||||
const hideText = phase === 'leaving' && outro === 'none';
|
||||
// 传入的 phaseTiming 由播放循环按当前句间隔算好(入场+回缩必须塞进单句时长)
|
||||
const phaseTiming = fittedTiming || {
|
||||
enterMs: Number(style.enterDurationMs || 0),
|
||||
shrinkMs: Number(style.shrinkDurationMs || 0)
|
||||
};
|
||||
const phaseKey = (cue ? cue.t : 'empty') + '|' + (phase || 'alpha') + '|' + configKey
|
||||
+ '|' + phaseTiming.enterMs + '|' + phaseTiming.shrinkMs;
|
||||
return (
|
||||
<div
|
||||
className={'lrc-preview-layer lrc-layer lrc-anim-' + (style.animation || 'fade')}
|
||||
className={'lrc-preview-layer lrc-layer lrc-anim-' + (style.animation || 'fade')
|
||||
+ ' lrc-out-' + outro + (phase ? ' lrc-state-' + phase : '')}
|
||||
style={{
|
||||
position: 'relative', width: '100%', aspectRatio: '16/9',
|
||||
background: 'linear-gradient(135deg, #141826, #05070c)',
|
||||
@@ -817,7 +902,12 @@
|
||||
paddingTop: style.position === 'top' ? edge : 0,
|
||||
paddingBottom: style.position === 'bottom' ? edge : 0,
|
||||
paddingLeft: 18, paddingRight: 18,
|
||||
boxSizing: 'border-box'
|
||||
boxSizing: 'border-box',
|
||||
'--lrc-in-dur': Number(phaseTiming.enterMs) + 'ms',
|
||||
'--lrc-out-dur': Number(style.outDurationMs || 0) + 'ms',
|
||||
'--lrc-shrink-dur': Number(phaseTiming.shrinkMs) + 'ms',
|
||||
'--lrc-shrink-to': String(style.holdShrinkTo == null ? 1 : style.holdShrinkTo),
|
||||
'--lrc-blur-px': Number(style.blurPx == null ? 10 : style.blurPx) + 'px'
|
||||
}}
|
||||
>
|
||||
<div
|
||||
@@ -832,7 +922,7 @@
|
||||
}}
|
||||
>
|
||||
<div
|
||||
key={cue ? cue.t : 'empty'}
|
||||
key={phaseKey}
|
||||
className="lrc-text"
|
||||
style={{
|
||||
whiteSpace: 'pre-line', wordBreak: 'break-word',
|
||||
@@ -843,6 +933,7 @@
|
||||
letterSpacing: (style.letterSpacing || 0) * scale + 'px',
|
||||
lineHeight: style.lineHeight,
|
||||
textShadow: shadow,
|
||||
visibility: hideText ? 'hidden' : 'visible',
|
||||
'--lrc-color': style.color,
|
||||
'--lrc-karaoke-pending': style.karaokePendingColor || 'rgba(255, 255, 255, 0.45)'
|
||||
}}
|
||||
@@ -857,8 +948,9 @@
|
||||
))
|
||||
: (text || '(字幕预览)')}
|
||||
</div>
|
||||
{style.showNextLine !== false && nextText ? (
|
||||
{style.showNextLine !== false && nextText && outro !== 'none' ? (
|
||||
<div
|
||||
key={'next-' + phaseKey}
|
||||
className="lrc-next"
|
||||
style={{
|
||||
marginTop: 3, whiteSpace: 'pre-line', wordBreak: 'break-word',
|
||||
@@ -901,6 +993,8 @@
|
||||
const [previewRun, setPreviewRun] = React.useState(0);
|
||||
const [previewIndex, setPreviewIndex] = React.useState(-1);
|
||||
const [previewElapsed, setPreviewElapsed] = React.useState(0);
|
||||
const [previewPhase, setPreviewPhase] = React.useState(null);
|
||||
const [previewLoop, setPreviewLoop] = React.useState(true);
|
||||
const [nowTick, setNowTick] = React.useState(Date.now());
|
||||
const fileRef = React.useRef(null);
|
||||
const initializedRef = React.useRef(false);
|
||||
@@ -1012,6 +1106,7 @@
|
||||
setPreviewPlaying(false);
|
||||
setPreviewIndex(-1);
|
||||
setPreviewElapsed(0);
|
||||
setPreviewPhase(null);
|
||||
}, [configKey]);
|
||||
|
||||
React.useEffect(() => {
|
||||
@@ -1021,9 +1116,35 @@
|
||||
setPreviewPlaying(false);
|
||||
return undefined;
|
||||
}
|
||||
const style = draft.style || {};
|
||||
const baseEnterMs = Math.max(0, Number(style.enterDurationMs) || 0);
|
||||
const baseShrinkMs = Math.max(0, Number(style.shrinkDurationMs) || 0);
|
||||
const outMs = Math.max(0, Number(style.outDurationMs) || 0);
|
||||
const outro = LRC_OUTRO_OPTIONS.includes(style.outro) ? style.outro : 'fade';
|
||||
const last = cues[cues.length - 1];
|
||||
const outroStart = last.t + (Number(draft.tailMs) || 0);
|
||||
const endAt = outroStart + (outro === 'none' ? 0 : outMs);
|
||||
const loopPause = 700;
|
||||
|
||||
// 和 OBS 端一致:入场 + 回缩必须塞进「到下一句」的间隔里
|
||||
const fitToWindow = (index) => {
|
||||
const cue = cues[index];
|
||||
if (!cue) return { enterMs: baseEnterMs, shrinkMs: baseShrinkMs, windowMs: 0 };
|
||||
const next = cues[index + 1];
|
||||
const windowMs = Math.max(0, (next ? next.t : cue.t + (Number(draft.tailMs) || 0)) - cue.t);
|
||||
const available = Math.max(120, windowMs);
|
||||
if (baseEnterMs + baseShrinkMs <= available) {
|
||||
return { enterMs: baseEnterMs, shrinkMs: baseShrinkMs, windowMs };
|
||||
}
|
||||
const enterMs = Math.round(Math.min(baseEnterMs, available * 0.45));
|
||||
const shrinkMs = Math.round(Math.max(120, Math.min(baseShrinkMs, available - enterMs)));
|
||||
return { enterMs, shrinkMs, windowMs };
|
||||
};
|
||||
|
||||
const startedAt = performance.now();
|
||||
setPreviewIndex(-1);
|
||||
setPreviewElapsed(0);
|
||||
setPreviewPhase(null);
|
||||
const timer = setInterval(() => {
|
||||
const elapsed = performance.now() - startedAt;
|
||||
let index = -1;
|
||||
@@ -1033,12 +1154,28 @@
|
||||
}
|
||||
setPreviewIndex(index);
|
||||
setPreviewElapsed(elapsed);
|
||||
const last = cues[cues.length - 1];
|
||||
if (elapsed > last.t + (draft.tailMs || 0) + 600) setPreviewPlaying(false);
|
||||
// 注意:预览用粗粒度 tick 判断阶段,字幕点到点之间可能只差 300ms,
|
||||
// 所以用「距本句开始已过多久」而不是绝对时间,确保每句都会走完入场→回缩。
|
||||
if (index >= 0 && elapsed >= outroStart) {
|
||||
setPreviewPhase(outro === 'none' ? null : 'leaving');
|
||||
} else if (index >= 0) {
|
||||
const fitted = fitToWindow(index);
|
||||
setPreviewPhase(elapsed >= cues[index].t + fitted.enterMs ? 'hold' : 'entering');
|
||||
} else {
|
||||
setPreviewPhase(null);
|
||||
}
|
||||
if (elapsed > endAt + loopPause) {
|
||||
if (previewLoop) {
|
||||
setPreviewRun(v => v + 1);
|
||||
} else {
|
||||
setPreviewPlaying(false);
|
||||
setPreviewPhase(null);
|
||||
}
|
||||
}
|
||||
}, 50);
|
||||
return () => clearInterval(timer);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [previewPlaying, previewRun, parsed]);
|
||||
}, [previewPlaying, previewRun, parsed, previewLoop]);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!lrcState || !lrcState.playing) return undefined;
|
||||
@@ -1084,11 +1221,31 @@
|
||||
const stageCue = previewCue || cues[0] || null;
|
||||
const stageIndex = previewCue ? previewIndex : 0;
|
||||
const stageElapsed = previewPlaying ? previewElapsed : Infinity;
|
||||
// 未播放时直接展示「入场结束后的停留状态」,方便看清最终样式
|
||||
const stagePhase = previewPlaying ? previewPhase : 'hold';
|
||||
const sampleText = stageCue ? stageCue.text : '';
|
||||
const sampleNext = cues[stageIndex + 1] ? cues[stageIndex + 1].text : '';
|
||||
const selectedCount = cues.length;
|
||||
const karaokeCount = cues.filter(cue => Array.isArray(cue.segments) && cue.segments.length >= 2).length;
|
||||
|
||||
// 当前舞台这句的适配时长(与 OBS 端一致:入场+回缩塞进到下一句的间隔里)
|
||||
const stageFitted = (() => {
|
||||
const cue = stageCue;
|
||||
const style = (draft && draft.style) || {};
|
||||
const base = {
|
||||
enterMs: Math.max(0, Number(style.enterDurationMs) || 0),
|
||||
shrinkMs: Math.max(0, Number(style.shrinkDurationMs) || 0)
|
||||
};
|
||||
if (!cue) return base;
|
||||
const next = cues[stageIndex + 1];
|
||||
const windowMs = Math.max(0, (next ? next.t : cue.t + (Number(draft.tailMs) || 0)) - cue.t);
|
||||
const available = Math.max(120, windowMs);
|
||||
if (base.enterMs + base.shrinkMs <= available) return { ...base, windowMs };
|
||||
const enterMs = Math.round(Math.min(base.enterMs, available * 0.45));
|
||||
const shrinkMs = Math.round(Math.max(120, Math.min(base.shrinkMs, available - enterMs)));
|
||||
return { enterMs, shrinkMs, windowMs };
|
||||
})();
|
||||
|
||||
const saveDraft = async (options = {}) => {
|
||||
if (!draft) return null;
|
||||
setSaving(true);
|
||||
@@ -1604,8 +1761,11 @@
|
||||
nextText={sampleNext}
|
||||
playing={previewPlaying}
|
||||
elapsed={stageElapsed}
|
||||
phase={stagePhase}
|
||||
configKey={configKey}
|
||||
fittedTiming={stageFitted}
|
||||
/>
|
||||
<Space style={{ marginTop: 8 }}>
|
||||
<Space style={{ marginTop: 8 }} wrap>
|
||||
<Button
|
||||
type="primary"
|
||||
ghost
|
||||
@@ -1613,8 +1773,16 @@
|
||||
onClick={() => { setPreviewRun(v => v + 1); setPreviewPlaying(true); }}
|
||||
>▶ 试播本段</Button>
|
||||
<Button disabled={!previewPlaying} onClick={() => setPreviewPlaying(false)}>停止试播</Button>
|
||||
<Space size={4}>
|
||||
<Switch size="small" checked={previewLoop} onChange={setPreviewLoop} />
|
||||
<Text style={{ color: '#888', fontSize: 12 }}>循环</Text>
|
||||
</Space>
|
||||
<Text style={{ color: '#888', fontSize: 12 }}>
|
||||
{previewCue ? formatMs(previewCue.t) : '—'} / {formatMs(parsed ? parsed.totalMs : 0)}
|
||||
{previewPlaying && previewPhase ? ' · ' + (
|
||||
previewPhase === 'entering' ? '入场中'
|
||||
: previewPhase === 'hold' ? '停留 / 回缩' : '出场中'
|
||||
) : ''}
|
||||
</Text>
|
||||
</Space>
|
||||
</Col>
|
||||
|
||||
Reference in new issue
Block a user