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

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
+1
View File
@@ -7,3 +7,4 @@
- 修复某些情况下歌曲播放出错时不会自动切歌的问题 - 修复某些情况下歌曲播放出错时不会自动切歌的问题
- 修复关闭“显示切换动画”设置后,在应用启动时该设置没有被应用的问题 - 修复关闭“显示切换动画”设置后,在应用启动时该设置没有被应用的问题
- 修复原始歌词存在偏移时,歌词偏移设置的重置未按预期工作的问题
@@ -78,12 +78,14 @@ export default {
lyric: '', lyric: '',
tlyric: '', tlyric: '',
lxlyric: '', lxlyric: '',
rawlyric: '',
musicInfo: null, musicInfo: null,
}) })
const updateMusicInfo = () => { const updateMusicInfo = () => {
lyricInfo.lyric = playerMusicInfo.lrc lyricInfo.lyric = playerMusicInfo.lrc
lyricInfo.tlyric = playerMusicInfo.tlrc lyricInfo.tlyric = playerMusicInfo.tlrc
lyricInfo.lxlyric = playerMusicInfo.lxlrc lyricInfo.lxlyric = playerMusicInfo.lxlrc
lyricInfo.rawlyric = playerMusicInfo.rawlrc
lyricInfo.musicInfo = musicInfoItem.value lyricInfo.musicInfo = musicInfoItem.value
} }
const handleShowLyricMenu = event => { const handleShowLyricMenu = event => {
@@ -98,7 +100,7 @@ export default {
tlrc: tlyric, tlrc: tlyric,
lxlrc: lxlyric, lxlrc: lxlyric,
}) })
console.log(offset) // console.log(offset)
window.eventHub.emit(eventPlayerNames.updateLyricOffset, offset) window.eventHub.emit(eventPlayerNames.updateLyricOffset, offset)
} }
@@ -29,7 +29,7 @@
<div :class="$style.group"> <div :class="$style.group">
<div :class="$style.subGroup"> <div :class="$style.subGroup">
<div :class="$style.title">{{$t('lyric_menu__offset', { offset })}}</div> <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>
<div :class="$style.subGroup"> <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> <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) 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 { export default {
name: 'LyricMenu', name: 'LyricMenu',
props: { props: {
@@ -75,6 +84,7 @@ export default {
const offset = ref(0) const offset = ref(0)
const offsetDisabled = ref(true) const offsetDisabled = ref(true)
const originOffset = ref(0)
const visible = computed(() => props.modelValue) const visible = computed(() => props.modelValue)
const musicInfo = computed(() => props.lyricInfo.musicInfo) const musicInfo = computed(() => props.lyricInfo.musicInfo)
@@ -115,13 +125,15 @@ export default {
if (lxlyric) lxlyric = `[offset:${offset}]\n` + lxlyric if (lxlyric) lxlyric = `[offset:${offset}]\n` + lxlyric
} }
if (offset) { if (offset == originOffset.value) {
removeLyric(props.lyricInfo.musicInfo)
} else {
saveLyric(props.lyricInfo.musicInfo, { saveLyric(props.lyricInfo.musicInfo, {
lyric, lyric,
tlyric, tlyric,
lxlyric, lxlyric,
}) })
} else removeLyric(props.lyricInfo.musicInfo) }
emit('updateLyric', { emit('updateLyric', {
lyric, lyric,
@@ -135,25 +147,15 @@ export default {
updateLyric(offset.value) updateLyric(offset.value)
} }
const offsetReset = () => { const offsetReset = () => {
if (!offset.value) return if (offset.value == originOffset.value) return
offset.value = 0 offset.value = originOffset.value
updateLyric(0) updateLyric(originOffset.value)
} }
const parseLrcOffset = () => { const parseLrcOffset = () => {
let lrcOffset offset.value = getOffset(props.lyricInfo.lyric)
if (props.lyricInfo.lyric) { originOffset.value = getOffset(props.lyricInfo.rawlyric)
lrcOffset = offsetTagRxp.exec(props.lyricInfo.lyric) offsetDisabled.value = !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
} }
@@ -177,6 +179,7 @@ export default {
menuStyles, menuStyles,
playDetailSetting, playDetailSetting,
offset, offset,
originOffset,
fontSizeUp, fontSizeUp,
fontSizeDown, fontSizeDown,
fontSizeReset, fontSizeReset,
+1
View File
@@ -7,6 +7,7 @@ export const musicInfo = window.musicInfo = reactive({
lrc: null, lrc: null,
tlrc: null, tlrc: null,
lxlrc: null, lxlrc: null,
rawlrc: null,
url: null, url: null,
name: '', name: '',
singer: '', singer: '',
@@ -135,7 +135,7 @@ export default ({ setting }) => {
} }
} }
const setLrc = (targetSong) => { const setLrc = (targetSong) => {
getLrc(targetSong).then(({ lyric, tlyric, lxlyric }) => { getLrc(targetSong).then(({ lyric, tlyric, lxlyric, rawInfo }) => {
if (targetSong.songmid !== musicInfo.songmid) return if (targetSong.songmid !== musicInfo.songmid) return
return ( return (
setting.value.player.isS2t setting.value.player.isS2t
@@ -150,6 +150,7 @@ export default ({ setting }) => {
lrc: lyric, lrc: lyric,
tlrc: tlyric, tlrc: tlyric,
lxlrc: lxlyric, lxlrc: lxlyric,
rawlrc: rawInfo.lyric,
}) })
}) })
}).catch((err) => { }).catch((err) => {
@@ -213,6 +214,7 @@ export default ({ setting }) => {
lrc: null, lrc: null,
tlrc: null, tlrc: null,
lxlrc: null, lxlrc: null,
rawlrc: null,
url: null, url: null,
name: '', name: '',
singer: '', singer: '',
+12 -3
View File
@@ -4,6 +4,7 @@ import {
getRandom, getRandom,
checkPath, checkPath,
getLyric as getStoreLyric, getLyric as getStoreLyric,
getLyricRaw as getStoreLyricRaw,
setLyric, setLyric,
setMusicUrl, setMusicUrl,
getMusicUrl as getStoreMusicUrl, 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 // getters
const getters = { const getters = {
@@ -231,16 +240,16 @@ const actions = {
case 'kw': case 'kw':
break break
default: default:
return lrcInfo return buildLyricInfo(lrcInfo, musicInfo)
} }
} else return lrcInfo } else return buildLyricInfo(lrcInfo, musicInfo)
} }
// lrcRequest = music[musicInfo.source].getLyric(musicInfo) // lrcRequest = music[musicInfo.source].getLyric(musicInfo)
return getLyric.call(this, musicInfo).then(({ lyric, tlyric, lxlyric }) => { return getLyric.call(this, musicInfo).then(({ lyric, tlyric, lxlyric }) => {
// lrcRequest = null // lrcRequest = null
commit('setLrc', { musicInfo, lyric, tlyric, lxlyric }) commit('setLrc', { musicInfo, lyric, tlyric, lxlyric })
return { lyric, tlyric, lxlyric } return buildLyricInfo({ lyric, tlyric, lxlyric }, musicInfo)
}).catch(err => { }).catch(err => {
// lrcRequest = null // lrcRequest = null
return Promise.reject(err) 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 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, { export const setLyric = (musicInfo, { lyric, tlyric, lxlyric }) => rendererSend(NAMES.mainWindow.save_lyric_raw, {
id: `${musicInfo.source}_${musicInfo.songmid}`, id: `${musicInfo.source}_${musicInfo.songmid}`,
lyrics: { lyric, tlyric, lxlyric }, lyrics: { lyric, tlyric, lxlyric },