修复原始歌词存在偏移时,歌词偏移设置的重置未按预期工作的问题

This commit is contained in:
lyswhut
2022-05-09 14:07:31 +08:00
parent e859d39b2b
commit 784515e411
7 changed files with 43 additions and 24 deletions
@@ -78,12 +78,14 @@ export default {
lyric: '',
tlyric: '',
lxlyric: '',
rawlyric: '',
musicInfo: null,
})
const updateMusicInfo = () => {
lyricInfo.lyric = playerMusicInfo.lrc
lyricInfo.tlyric = playerMusicInfo.tlrc
lyricInfo.lxlyric = playerMusicInfo.lxlrc
lyricInfo.rawlyric = playerMusicInfo.rawlrc
lyricInfo.musicInfo = musicInfoItem.value
}
const handleShowLyricMenu = event => {
@@ -98,7 +100,7 @@ export default {
tlrc: tlyric,
lxlrc: lxlyric,
})
console.log(offset)
// console.log(offset)
window.eventHub.emit(eventPlayerNames.updateLyricOffset, offset)
}
@@ -29,7 +29,7 @@
<div :class="$style.group">
<div :class="$style.subGroup">
<div :class="$style.title">{{$t('lyric_menu__offset', { offset })}}</div>
<button :class="[$style.btn, $style.titleBtn]" :disabled="offsetDisabled || !offset" @click="offsetReset">{{$t('lyric_menu__offset_reset')}}</button>
<button :class="[$style.btn, $style.titleBtn]" :disabled="offsetDisabled || offset == originOffset" @click="offsetReset">{{$t('lyric_menu__offset_reset')}}</button>
</div>
<div :class="$style.subGroup">
<button :class="$style.btn" :disabled="offsetDisabled" @click="setOffset(10)" ignore-tip :aria-label="$t('lyric_menu__offset_add_10')">+ 10ms</button>
@@ -59,6 +59,15 @@ const removeLyric = debounce(musicInfo => {
removeLyricEdited(musicInfo)
})
const getOffset = lrc => {
let offset = offsetTagRxp.exec(lrc)
if (offset) {
offset = parseInt(offset[1])
if (Number.isNaN(offset)) offset = 0
} else offset = 0
return offset
}
export default {
name: 'LyricMenu',
props: {
@@ -75,6 +84,7 @@ export default {
const offset = ref(0)
const offsetDisabled = ref(true)
const originOffset = ref(0)
const visible = computed(() => props.modelValue)
const musicInfo = computed(() => props.lyricInfo.musicInfo)
@@ -115,13 +125,15 @@ export default {
if (lxlyric) lxlyric = `[offset:${offset}]\n` + lxlyric
}
if (offset) {
if (offset == originOffset.value) {
removeLyric(props.lyricInfo.musicInfo)
} else {
saveLyric(props.lyricInfo.musicInfo, {
lyric,
tlyric,
lxlyric,
})
} else removeLyric(props.lyricInfo.musicInfo)
}
emit('updateLyric', {
lyric,
@@ -135,25 +147,15 @@ export default {
updateLyric(offset.value)
}
const offsetReset = () => {
if (!offset.value) return
offset.value = 0
updateLyric(0)
if (offset.value == originOffset.value) return
offset.value = originOffset.value
updateLyric(originOffset.value)
}
const parseLrcOffset = () => {
let lrcOffset
if (props.lyricInfo.lyric) {
lrcOffset = offsetTagRxp.exec(props.lyricInfo.lyric)
if (lrcOffset) {
lrcOffset = parseInt(lrcOffset[1])
if (Number.isNaN(lrcOffset)) lrcOffset = 0
} else lrcOffset = 0
offsetDisabled.value = false
} else {
offsetDisabled.value = true
lrcOffset = 0
}
offset.value = lrcOffset
offset.value = getOffset(props.lyricInfo.lyric)
originOffset.value = getOffset(props.lyricInfo.rawlyric)
offsetDisabled.value = !props.lyricInfo.lyric
}
@@ -177,6 +179,7 @@ export default {
menuStyles,
playDetailSetting,
offset,
originOffset,
fontSizeUp,
fontSizeDown,
fontSizeReset,
+1
View File
@@ -7,6 +7,7 @@ export const musicInfo = window.musicInfo = reactive({
lrc: null,
tlrc: null,
lxlrc: null,
rawlrc: null,
url: null,
name: '',
singer: '',
@@ -135,7 +135,7 @@ export default ({ setting }) => {
}
}
const setLrc = (targetSong) => {
getLrc(targetSong).then(({ lyric, tlyric, lxlyric }) => {
getLrc(targetSong).then(({ lyric, tlyric, lxlyric, rawInfo }) => {
if (targetSong.songmid !== musicInfo.songmid) return
return (
setting.value.player.isS2t
@@ -150,6 +150,7 @@ export default ({ setting }) => {
lrc: lyric,
tlrc: tlyric,
lxlrc: lxlyric,
rawlrc: rawInfo.lyric,
})
})
}).catch((err) => {
@@ -213,6 +214,7 @@ export default ({ setting }) => {
lrc: null,
tlrc: null,
lxlrc: null,
rawlrc: null,
url: null,
name: '',
singer: '',
+12 -3
View File
@@ -4,6 +4,7 @@ import {
getRandom,
checkPath,
getLyric as getStoreLyric,
getLyricRaw as getStoreLyricRaw,
setLyric,
setMusicUrl,
getMusicUrl as getStoreMusicUrl,
@@ -177,6 +178,14 @@ const getLyric = function(musicInfo, retryedSource = [], originMusic) {
})
}
const buildLyricInfo = async(lyricInfo, musicInfo) => {
const lyricRawInfo = await getStoreLyricRaw(musicInfo)
return {
...lyricInfo,
rawInfo: lyricRawInfo,
}
}
// getters
const getters = {
@@ -231,16 +240,16 @@ const actions = {
case 'kw':
break
default:
return lrcInfo
return buildLyricInfo(lrcInfo, musicInfo)
}
} else return lrcInfo
} else return buildLyricInfo(lrcInfo, musicInfo)
}
// lrcRequest = music[musicInfo.source].getLyric(musicInfo)
return getLyric.call(this, musicInfo).then(({ lyric, tlyric, lxlyric }) => {
// lrcRequest = null
commit('setLrc', { musicInfo, lyric, tlyric, lxlyric })
return { lyric, tlyric, lxlyric }
return buildLyricInfo({ lyric, tlyric, lxlyric }, musicInfo)
}).catch(err => {
// lrcRequest = null
return Promise.reject(err)
+1
View File
@@ -513,6 +513,7 @@ export const parseUrlParams = str => {
}
export const getLyric = musicInfo => rendererInvoke(NAMES.mainWindow.get_lyric, `${musicInfo.source}_${musicInfo.songmid}`)
export const getLyricRaw = musicInfo => rendererInvoke(NAMES.mainWindow.get_lyric_raw, `${musicInfo.source}_${musicInfo.songmid}`)
export const setLyric = (musicInfo, { lyric, tlyric, lxlyric }) => rendererSend(NAMES.mainWindow.save_lyric_raw, {
id: `${musicInfo.source}_${musicInfo.songmid}`,
lyrics: { lyric, tlyric, lxlyric },