From 4a8a1368b22ca3135386eae8ee43e35c65dc7b1f Mon Sep 17 00:00:00 2001 From: Tom Boullay Date: Sun, 10 May 2026 00:35:23 +0100 Subject: [PATCH] update: gros commit fix editor srt panl --- src/components/editor/EditorSrtPanel.tsx | 27 +++++++++++++++++++++++- src/index.css | 26 +++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/src/components/editor/EditorSrtPanel.tsx b/src/components/editor/EditorSrtPanel.tsx index 8fc21cf..2319e51 100644 --- a/src/components/editor/EditorSrtPanel.tsx +++ b/src/components/editor/EditorSrtPanel.tsx @@ -71,6 +71,10 @@ function formatSrtTime(totalSeconds: number): string { return `${padTime(hours)}:${padTime(minutes)}:${padTime(seconds)},000`; } +function formatPreviewTime(totalSeconds: number): string { + return `${Math.floor(totalSeconds)}.${Math.floor((totalSeconds % 1) * 10)}s`; +} + function padTime(value: number): string { return value.toString().padStart(2, "0"); } @@ -227,17 +231,24 @@ export function EditorSrtPanel(): React.JSX.Element { const [status, setStatus] = useState("Chargement du SRT..."); const [isSaving, setIsSaving] = useState(false); const [manifest, setManifest] = useState(null); + const [audioCurrentTime, setAudioCurrentTime] = useState(0); + const [selectedDialogueId, setSelectedDialogueId] = useState(""); const selectedVoice = SRT_VOICES.find((item) => item.id === voice) ?? DEFAULT_SRT_VOICE; const expectedDialogues = getExpectedDialogues(manifest, voice); const expectedCueIndexes = getExpectedCueIndexes(manifest, voice); + const parsedCues = parseSrt(content); + const activeCue = + parsedCues.find( + (cue) => + audioCurrentTime >= cue.startTime && audioCurrentTime < cue.endTime, + ) ?? null; const diagnostic = getSrtDiagnostic(content, expectedCueIndexes); const isSrtValid = diagnostic.errors.length === 0; const srtTemplate = createSrtTemplate( selectedVoice.label, expectedCueIndexes, ); - const [selectedDialogueId, setSelectedDialogueId] = useState(""); const selectedDialogue = expectedDialogues.find((dialogue) => dialogue.id === selectedDialogueId) ?? expectedDialogues[0] ?? @@ -388,7 +399,21 @@ export function EditorSrtPanel(): React.JSX.Element { key={selectedDialogue.audio} controls src={selectedDialogue.audio} + onLoadedMetadata={() => setAudioCurrentTime(0)} + onTimeUpdate={(event) => + setAudioCurrentTime(event.currentTarget.currentTime) + } /> +
+ Temps audio: {formatPreviewTime(audioCurrentTime)} + {activeCue ? ( +

+ Cue {activeCue.index} {activeCue.text} +

+ ) : ( +

Aucune cue active a ce moment.

+ )} +