Skip to content

Commit

Permalink
修正打轴时没有设置行始末时间的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve-xmh committed Feb 3, 2024
1 parent 17b1af3 commit 22d450b
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/components/LyricSyncEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import {storeToRefs} from "pinia";
import LyricSyncLine from "./LyricSyncLine.vue";
import {DynamicScroller, DynamicScrollerItem} from 'vue-virtual-scroller';
import LyricSyncWord from "./LyricSyncWord.vue";
import type {LyricWord} from "../utils/ttml-types";
import type {LyricLine, LyricWord} from "../utils/ttml-types";
const currentWord = useCurrentSyncWord();
const audio = useAudio();
Expand Down Expand Up @@ -114,6 +114,10 @@ function getCurrentWord(): LyricWord | undefined {
return lyric.lyrics[currentWord.lineIndex]?.words?.[currentWord.wordIndex];
}
function getCurrentLine(): LyricLine | undefined {
return lyric.lyrics[currentWord.lineIndex];
}
function moveRight() {
let lineIndex = currentWord.lineIndex;
let wordIndex = currentWord.wordIndex;
Expand Down Expand Up @@ -237,14 +241,27 @@ function onKeyPress(e: KeyboardEvent) {
}
case "KeyF": { // 记录当前时间为当前单词的起始时间
const curWord = getCurrentWord();
if (curWord) curWord.startTime = currentTimeMS.value;
if (curWord) {
curWord.startTime = currentTimeMS.value;
const currentLine = getCurrentLine();
if (currentWord.wordIndex === 0 && currentLine) {
currentLine.startTime = currentTimeMS.value;
}
}
collected = true;
break;
}
case "KeyG": { // 记录当前时间为当前单词的结束时间和下一个单词的起始时间,并移动到下一个单词
const curWord = getCurrentWord();
const currentLine = getCurrentLine();
const curWordIndex = currentWord.wordIndex;
if (moveRight()) {
if (curWord) curWord.endTime = currentTimeMS.value;
if (curWord) {
curWord.endTime = currentTimeMS.value;
if (currentLine && curWordIndex === currentLine.words.length - 1) {
currentLine.endTime = curWord.endTime;
}
}
const nextWord = getCurrentWord();
if (nextWord) nextWord.startTime = currentTimeMS.value;
}
Expand All @@ -253,8 +270,14 @@ function onKeyPress(e: KeyboardEvent) {
}
case "KeyH": { // 记录当前时间为当前单词的结束时间,并移动到下一个单词(用于空出间奏时间)
const curWord = getCurrentWord();
const currentLine = getCurrentLine();
if (moveRight()) {
if (curWord) curWord.endTime = currentTimeMS.value;
if (curWord) {
curWord.endTime = currentTimeMS.value;
if (currentLine && currentWord.wordIndex === currentLine.words.length - 1) {
currentLine.endTime = curWord.endTime;
}
}
}
collected = true;
break;
Expand Down

0 comments on commit 22d450b

Please sign in to comment.