update: gros commit fix editor srt panl

This commit is contained in:
Tom Boullay
2026-05-10 00:35:23 +01:00
parent 9969e86e9c
commit 64ebeee014
2 changed files with 52 additions and 1 deletions
+26 -1
View File
@@ -71,6 +71,10 @@ function formatSrtTime(totalSeconds: number): string {
return `${padTime(hours)}:${padTime(minutes)}:${padTime(seconds)},000`; 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 { function padTime(value: number): string {
return value.toString().padStart(2, "0"); return value.toString().padStart(2, "0");
} }
@@ -227,17 +231,24 @@ export function EditorSrtPanel(): React.JSX.Element {
const [status, setStatus] = useState("Chargement du SRT..."); const [status, setStatus] = useState("Chargement du SRT...");
const [isSaving, setIsSaving] = useState(false); const [isSaving, setIsSaving] = useState(false);
const [manifest, setManifest] = useState<DialogueManifest | null>(null); const [manifest, setManifest] = useState<DialogueManifest | null>(null);
const [audioCurrentTime, setAudioCurrentTime] = useState(0);
const [selectedDialogueId, setSelectedDialogueId] = useState("");
const selectedVoice = const selectedVoice =
SRT_VOICES.find((item) => item.id === voice) ?? DEFAULT_SRT_VOICE; SRT_VOICES.find((item) => item.id === voice) ?? DEFAULT_SRT_VOICE;
const expectedDialogues = getExpectedDialogues(manifest, voice); const expectedDialogues = getExpectedDialogues(manifest, voice);
const expectedCueIndexes = getExpectedCueIndexes(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 diagnostic = getSrtDiagnostic(content, expectedCueIndexes);
const isSrtValid = diagnostic.errors.length === 0; const isSrtValid = diagnostic.errors.length === 0;
const srtTemplate = createSrtTemplate( const srtTemplate = createSrtTemplate(
selectedVoice.label, selectedVoice.label,
expectedCueIndexes, expectedCueIndexes,
); );
const [selectedDialogueId, setSelectedDialogueId] = useState("");
const selectedDialogue = const selectedDialogue =
expectedDialogues.find((dialogue) => dialogue.id === selectedDialogueId) ?? expectedDialogues.find((dialogue) => dialogue.id === selectedDialogueId) ??
expectedDialogues[0] ?? expectedDialogues[0] ??
@@ -388,7 +399,21 @@ export function EditorSrtPanel(): React.JSX.Element {
key={selectedDialogue.audio} key={selectedDialogue.audio}
controls controls
src={selectedDialogue.audio} src={selectedDialogue.audio}
onLoadedMetadata={() => setAudioCurrentTime(0)}
onTimeUpdate={(event) =>
setAudioCurrentTime(event.currentTarget.currentTime)
}
/> />
<div className="editor-srt-active-cue">
<span>Temps audio: {formatPreviewTime(audioCurrentTime)}</span>
{activeCue ? (
<p>
<strong>Cue {activeCue.index}</strong> {activeCue.text}
</p>
) : (
<p>Aucune cue active a ce moment.</p>
)}
</div>
<button <button
className="editor-srt-jump-button" className="editor-srt-jump-button"
type="button" type="button"
+26
View File
@@ -1506,6 +1506,32 @@ canvas {
height: 34px; height: 34px;
} }
.editor-srt-active-cue {
display: grid;
gap: 5px;
padding: 8px 10px;
border: 1px solid #242424;
border-radius: 12px;
background: #101010;
}
.editor-srt-active-cue span {
color: #8d8d8d;
font-size: 0.7rem;
}
.editor-srt-active-cue p {
margin: 0;
color: #d7d7d7;
font-size: 0.74rem;
line-height: 1.4;
}
.editor-srt-active-cue strong {
margin-right: 4px;
color: #ffffff;
}
.editor-srt-jump-button { .editor-srt-jump-button {
width: 100%; width: 100%;
padding: 8px 10px; padding: 8px 10px;