From f8912a5f10a45edf0134ed0cfa8edad7bbaa36e8 Mon Sep 17 00:00:00 2001 From: Zhong Yang Date: Tue, 6 Aug 2024 19:29:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BD=93lyrics=E5=85=83=E7=B4=A0=E6=8C=87?= =?UTF-8?q?=E5=AE=9A=E4=BA=86show=5Fsong=5Finfo=E5=B1=9E=E6=80=A7=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E5=9C=A8=E5=8D=95=E8=A1=8C=E6=98=BE=E7=A4=BA=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E4=B8=8B=EF=BC=8C=E5=A6=82=E6=9E=9C=E6=AD=8C=E8=AF=8D?= =?UTF-8?q?=E5=B7=B2=E7=BB=8F=E7=BB=93=E6=9D=9F=EF=BC=8C=E5=88=99=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E6=AD=8C=E6=9B=B2=E4=BF=A1=E6=81=AF=20=EF=BC=88?= =?UTF-8?q?=E4=BD=BF=E5=BE=97=E8=BF=B7=E4=BD=A0=E6=A8=A1=E5=BC=8F=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E7=95=8C=E9=9D=A2=E6=AD=8C=E8=AF=8D=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E7=9A=84=E9=80=BB=E8=BE=91=E5=92=8C=E4=B9=8B=E5=89=8D=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E4=B8=80=E8=87=B4=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MusicPlayer2/CUIDrawer.cpp | 86 ++++++++++++++++++++++---------------- 1 file changed, 51 insertions(+), 35 deletions(-) diff --git a/MusicPlayer2/CUIDrawer.cpp b/MusicPlayer2/CUIDrawer.cpp index 22b55ee4d..47e37b41d 100644 --- a/MusicPlayer2/CUIDrawer.cpp +++ b/MusicPlayer2/CUIDrawer.cpp @@ -260,48 +260,64 @@ void CUIDrawer::DrawLyricTextSingleLine(CRect rect, int& flag, bool double_line, Time time{ CPlayer::GetInstance().GetCurrentPosition() }; CLyrics::Lyric current_lyric{ now_lyrics.GetLyric(time, false, ignore_blank, karaoke) }; int progress{ now_lyrics.GetLyricProgress(time, ignore_blank, karaoke, [this](const wstring& str) { return GetTextExtent(str.c_str()).cx; }) }; - bool switch_flag{ flag > 5000 }; - switch_flag ^= (flag % 5000) > progress; - flag = switch_flag ? 10000 + progress : progress; - - if (current_lyric.text.empty()) - current_lyric.text = empty_lyric; - //双行显示歌词 - if (double_line && (current_lyric.translate.empty() || !theApp.m_lyric_setting_data.show_translate) && rect.Height() > static_cast(GetLyricTextHeight() * 1.73)) + + //当前歌词为空,且持续了超过了20秒 + bool no_lyric = (current_lyric.text.empty() && CPlayer::GetInstance().GetCurrentPosition() - current_lyric.time_start > 20000) || progress >= 1000; + //当指定了show_song_info时,如果当前歌词为空,且持续了超过了20秒,则显示歌曲信息 + if (no_lyric && show_song_info) { - wstring next_lyric_text; - next_lyric_text = now_lyrics.GetLyric(time, true, ignore_blank, karaoke).text; - if (next_lyric_text.empty()) - next_lyric_text = empty_lyric; - //这里实现文本从非高亮缓慢变化到高亮效果 - int last_time_span = time - current_lyric.time_start; //当前播放的歌词已持续的时间 - int fade_percent = last_time_span / 8; //计算颜色高亮变化的百分比,除数越大则持续时间越长,10则为1秒 - if (progress == 1000) fade_percent = 0; // 进度为1000时当前歌词“已完成”不再高亮 - // 这里的fade_percent当合并空行开启时可能为负,在颜色渐变处规范取值,此处不再处理 - DrawLyricDoubleLine(lyric_rect, current_lyric.text.c_str(), next_lyric_text.c_str(), align, progress, switch_flag, fade_percent); + //显示歌曲信息 + CString song_info_str; + const SongInfo& cur_song{ CPlayer::GetInstance().GetCurrentSongInfo() }; + song_info_str.Format(_T("%s - %s"), cur_song.GetArtist().c_str(), cur_song.GetTitle().c_str()); + static CDrawCommon::ScrollInfo lyric_scroll_info; + DrawScrollText(rect, song_info_str, m_colors.color_text, CPlayerUIHelper::GetScrollTextPixel(), theApp.m_lyric_setting_data.lyric_align != Alignment::LEFT, lyric_scroll_info); } else { - // AUTO时单行歌词居中显示 - if (align == Alignment::AUTO) align = Alignment::CENTER; - // 单行歌词在这里显示翻译,同时更新歌词区域为单行有翻译时的位置 - if (theApp.m_lyric_setting_data.show_translate && !current_lyric.translate.empty() && rect.Height() > static_cast(GetLyricTextHeight() * 1.73)) + bool switch_flag{ flag > 5000 }; + switch_flag ^= (flag % 5000) > progress; + flag = switch_flag ? 10000 + progress : progress; + + if (current_lyric.text.empty()) + current_lyric.text = empty_lyric; + //双行显示歌词 + if (double_line && (current_lyric.translate.empty() || !theApp.m_lyric_setting_data.show_translate) && rect.Height() > static_cast(GetLyricTextHeight() * 1.73)) { - lyric_rect.bottom = lyric_rect.top + rect.Height() / 2; - CRect translate_rect = lyric_rect; - translate_rect.MoveToY(lyric_rect.bottom); - - SetFont(m_lyric_tr_font); - DrawWindowText(translate_rect, current_lyric.translate.c_str(), m_colors.color_text, m_colors.color_text, progress, align, true); + wstring next_lyric_text; + next_lyric_text = now_lyrics.GetLyric(time, true, ignore_blank, karaoke).text; + if (next_lyric_text.empty()) + next_lyric_text = empty_lyric; + //这里实现文本从非高亮缓慢变化到高亮效果 + int last_time_span = time - current_lyric.time_start; //当前播放的歌词已持续的时间 + int fade_percent = last_time_span / 8; //计算颜色高亮变化的百分比,除数越大则持续时间越长,10则为1秒 + if (progress == 1000) fade_percent = 0; // 进度为1000时当前歌词“已完成”不再高亮 + // 这里的fade_percent当合并空行开启时可能为负,在颜色渐变处规范取值,此处不再处理 + DrawLyricDoubleLine(lyric_rect, current_lyric.text.c_str(), next_lyric_text.c_str(), align, progress, switch_flag, fade_percent); } - // 绘制单行歌词 - SetFont(m_lyric_font); - if (theApp.m_lyric_setting_data.lyric_karaoke_disp) - DrawWindowText(lyric_rect, current_lyric.text.c_str(), m_colors.color_text, m_colors.color_text_2, progress, align, true); - else if (0 < progress && progress < 1000) // 仅高亮“正在进行”的歌词 - DrawWindowText(lyric_rect, current_lyric.text.c_str(), m_colors.color_text, m_colors.color_text, progress, align, true); else - DrawWindowText(lyric_rect, current_lyric.text.c_str(), m_colors.color_text_2, m_colors.color_text_2, progress, align, true); + { + // AUTO时单行歌词居中显示 + if (align == Alignment::AUTO) align = Alignment::CENTER; + // 单行歌词在这里显示翻译,同时更新歌词区域为单行有翻译时的位置 + if (theApp.m_lyric_setting_data.show_translate && !current_lyric.translate.empty() && rect.Height() > static_cast(GetLyricTextHeight() * 1.73)) + { + lyric_rect.bottom = lyric_rect.top + rect.Height() / 2; + CRect translate_rect = lyric_rect; + translate_rect.MoveToY(lyric_rect.bottom); + + SetFont(m_lyric_tr_font); + DrawWindowText(translate_rect, current_lyric.translate.c_str(), m_colors.color_text, m_colors.color_text, progress, align, true); + } + // 绘制单行歌词 + SetFont(m_lyric_font); + if (theApp.m_lyric_setting_data.lyric_karaoke_disp) + DrawWindowText(lyric_rect, current_lyric.text.c_str(), m_colors.color_text, m_colors.color_text_2, progress, align, true); + else if (0 < progress && progress < 1000) // 仅高亮“正在进行”的歌词 + DrawWindowText(lyric_rect, current_lyric.text.c_str(), m_colors.color_text, m_colors.color_text, progress, align, true); + else + DrawWindowText(lyric_rect, current_lyric.text.c_str(), m_colors.color_text_2, m_colors.color_text_2, progress, align, true); + } } }