多年都没写博客了,今天忽然受到点触动,发一篇。
今天测试电脑的录音功能,因为笔记本自带的板载声卡干扰比较严重,就又插了一个几年前买的一个USB声卡,同时把吃灰十多年的森海塞尔耳麦插上了。为了测试一下声卡是不是好使,找到歌曲文件夹,随便点了一首歌,然后我就被震惊了,这声音咋这么好听。
我一直不是一个音乐发烧友,对音质没啥特别高的要求,有了智能手机一直都是用手机听歌,没想到忽然用电脑听了一下歌居然被震撼到了,比手机好听不少(苹果手机+AirPods Pro)。一下把自己拉回了好多年前用电脑听歌的时候,那时候还都是下载歌曲用播放器在本地听,当年的王者播放器就是Winamp没有之一,等Foobar2000能与Winamp竞争时整个本地播放行业都没落了,已经被千千静听、酷我音乐之类的网络播放器取代了。话说当年我自己还开发过一个播放器呢,嗯,还有显示歌词功能,自己写了一个歌词解析的模块。
我最开始是一直用Winamp的,后来Foobar2000出来也没切换过去,一是当时Foobar2000宣称的特色功能无损音乐格式对我来说并不需要,我对音质要求一直也不是很高,对空间当时还是比较在意的,直播放MP3没必要换播放器,还有一个似乎是更重要的原因,因为当时Foobar出来的时候界面太丑了,比Winamp那么多绚丽的皮肤差太多了。再后来就开始用酷我音乐,搜歌下歌和显示歌词之类的功能都很方便,所以后期很长很长时间我都一直用酷我音乐,Winamp基本就被我淘汰了。由于酷我用的比较舒服,所以同时期的千千静听也就没怎么用。再后来,各公司版权意识加强了(要赚钱了),有一段时间用了几次酷我,那时候已经和当初不一样了,歌曲也开始要收费或会员了,用起来感觉就很不好了。那时候就已经开始基本都是用手机听歌了,所以电脑上播放器基本就放弃了,播放本地歌曲有时候我就直接用微软的Media Player。
当年也是下了上千首歌的,基本上喜欢某个歌手的一首歌,索性就把这个歌手所有歌都下载,像王菲、刘德华、邓丽君、凤凰传奇、张韶涵等等基本都是把当时他们能下载的歌曲都下载到本地了。后来觉得网络播放挺方便,在本地保留这么多歌曲也没啥用,还挺占用硬盘空间的,于是为了节省硬盘空间好多都删掉了(现在好多歌都要会员、收费,哎,等于删掉了不少钱呀),再加上我的硬盘曾经坏过一次,那次也损失了大量的歌曲(歌曲类的文件对我来说不算重要文件,从不备份),到现在还有一千多首歌吧。由于多年不用电脑听歌,这次一听感觉很好,就打算边用电脑边听听歌,于是决定下载个播放器,搜了一下,Winamp和Foobar2000都还有,不过有人推荐了一个MusicPlayer2,说是也不错,甚至说是目前最好的本地歌曲播放器。我寻思着那就都试试,于是就先去看了一下MusicPlayer2,是开源的,用VS C++开发的,看作者名称应该是中国的,于是就下载了,用了一下感觉还挺好,那就用这个吧,另外两个也就不下了。
多年不在CSDN发文章了,刚才正在编写的时候旁边有提示说此文章质量较低,不会获得较多流量支持,可能篇幅太短、广告涉嫌违规。本来我就只是发一下感慨,也不在乎流量啥的。被旁边的提示搞的很没心情了。那就只写到这里吧。为了通过可能还得加点代码段,大家可以无视。
#include "stdafx.h"
#include "CPlayerUI.h"
CPlayerUI::CPlayerUI(UIData& ui_data, CWnd* pMainWnd)
: CPlayerUIBase(ui_data, pMainWnd)
{
}
CPlayerUI::~CPlayerUI()
{
}
void CPlayerUI::_DrawInfo(CRect draw_rect, bool reset)
{
//draw_rect.MoveToXY(0, 0);
CPoint text_start{ draw_rect.left + SpectralSize().cx + Margin() + EdgeMargin(true), draw_rect.top + EdgeMargin(false) }; //文本的起始坐标
int text_height{ DPI(18) }; //文本的高度
//全屏模式时在右上角绘制时间
if (m_ui_data.full_screen)
{
DrawCurrentTime();
}
//绘制右上角图标
int top_right_icon_size = DrawTopRightIcons();
//显示歌曲信息
m_draw.SetFont(&theApp.m_font_set.font9.GetFont(m_ui_data.full_screen));
//m_draw.SetBackColor(color_back);
CRect tmp{ text_start, CSize{1, text_height} };
tmp.right = draw_rect.right - EdgeMargin(true) - top_right_icon_size;
DrawSongInfo(tmp, reset);
wchar_t buff[64];
wstring lable1_str, lable1_content;
wstring lable2_str, lable2_content;
wstring lable3_str, lable3_content;
wstring lable4_str, lable4_content;
lable1_str = CCommon::LoadText(IDS_TITLE, _T(": "));
lable1_content = CPlayer::GetInstance().GetCurrentSongInfo().GetTitle();
if (CPlayer::GetInstance().IsMidi())
{
const MidiInfo& midi_info{ CPlayer::GetInstance().GetMidiInfo() };
lable2_str = CCommon::LoadText(IDS_RHYTHM, _T(": "));
swprintf_s(buff, L"%d/%d (%dbpm)", midi_info.midi_position, midi_info.midi_length, midi_info.speed);
lable2_content = buff;
//lable3_str = _T("速度:");
//swprintf_s(buff, L"%d bpm", midi_info.speed);
//lable3_content = buff;
lable3_str = CCommon::LoadText(IDS_SOUND_FONT, _T(": "));
lable3_content = CPlayer::GetInstance().GetSoundFontName();
}
else
{
lable2_str = CCommon::LoadText(IDS_ARTIST, _T(": "));
lable2_content = CPlayer::GetInstance().GetCurrentSongInfo().GetArtist();
lable3_str = CCommon::LoadText(IDS_ALBUM, _T(": "));
lable3_content = CPlayer::GetInstance().GetCurrentSongInfo().GetAlbum();
}
lable4_str = CCommon::LoadText(IDS_FORMAT, _T(": "));
//const BASS_CHANNELINFO channel_info{ CPlayer::GetInstance().GetChannelInfo() };
lable4_content = GetDisplayFormatString();
//显示标题
tmp.MoveToXY(text_start.x, text_start.y + text_height);
tmp.right = tmp.left + DPI(52);
m_draw.DrawWindowText(tmp, lable1_str.c_str(), m_colors.color_text_lable);
tmp.MoveToX(tmp.left + DPI(52));
tmp.right = draw_rect.right - EdgeMargin(true) - top_right_icon_size;
static CDrawCommon::ScrollInfo scroll_info2;
m_draw.DrawScrollText2(tmp, lable1_content.c_str(), m_colors.color_text, GetScrollTextPixel(true), false, scroll_info2, reset);
//显示艺术家
tmp.MoveToXY(text_start.x, text_start.y + 2 * text_height);
tmp.right = tmp.left + DPI(52);
m_draw.DrawWindowText(tmp, lable2_str.c_str(), m_colors.color_text_lable);
tmp.MoveToX(tmp.left + DPI(52));
tmp.right = draw_rect.right - EdgeMargin(true);
static CDrawCommon::ScrollInfo scroll_info3;
if (CPlayer::GetInstance().IsMidi())
m_draw.DrawWindowText(tmp, lable2_content.c_str(), m_colors.color_text);
else
m_draw.DrawScrollText2(tmp, lable2_content.c_str(), m_colors.color_text, GetScrollTextPixel(true), false, scroll_info3, reset);
//显示唱片集
tmp.MoveToXY(text_start.x, text_start.y + 3 * text_height);
tmp.right = tmp.left + DPI(52);
m_draw.DrawWindowText(tmp, lable3_str.c_str(), m_colors.color_text_lable);
tmp.MoveToX(tmp.left + DPI(52));
tmp.right = draw_rect.right - EdgeMargin(true);
static CDrawCommon::ScrollInfo scroll_info4;
m_draw.DrawScrollText2(tmp, lable3_content.c_str(), m_colors.color_text, GetScrollTextPixel(true), false, scroll_info4, reset);
//显示文件格式和比特率
tmp.MoveToXY(text_start.x, text_start.y + 4 * text_height);
tmp.right = tmp.left + DPI(52);
m_draw.DrawWindowText(tmp, lable4_str.c_str(), m_colors.color_text_lable);
tmp.MoveToX(tmp.left + DPI(52));
tmp.right = draw_rect.right - EdgeMargin(true);
static CDrawCommon::ScrollInfo scroll_info5;
m_draw.DrawScrollText2(tmp, lable4_content.c_str(), m_colors.color_text, GetScrollTextPixel(true), false, scroll_info5, reset);
//显示频谱分析
CRect spectral_rect{ CPoint{draw_rect.left + EdgeMargin(true), draw_rect.top + EdgeMargin(false)}, SpectralSize() };
//绘制背景
if (IsDrawBackgroundAlpha())
m_draw.FillAlphaRect(spectral_rect, m_colors.color_spectrum_back, ALPHA_CHG(theApp.m_app_setting_data.background_transparency) * 2 / 3);
else
m_draw.FillRect(spectral_rect, m_colors.color_spectrum_back);
CRect cover_rect = spectral_rect;
cover_rect.DeflateRect(Margin() / 2, Margin() / 2);
m_buttons[BTN_COVER].rect = DrawAreaToClient(cover_rect, m_draw_rect);
//绘制专辑封面
DrawAlbumCover(cover_rect);
if (theApp.m_app_setting_data.show_spectrum)
{
m_draw.SetDrawArea(cover_rect);
const int ROWS = 32; //要显示的频谱柱形的数量
int gap_width{ theApp.DPIRound(1, 0.4) }; //频谱柱形间隙宽度
int width = (spectral_rect.Width() - (ROWS - 2) * gap_width) / (ROWS - 2);
COLORREF color;
if (theApp.m_app_setting_data.show_album_cover && CPlayer::GetInstance().AlbumCoverExist())
color = m_colors.color_spectrum_cover;
else
color = m_colors.color_spectrum;
m_draw.DrawSpectrum(cover_rect, width, gap_width, ROWS, color, false, theApp.m_app_setting_data.spectrum_low_freq_in_center);
}
//绘制工具条
CPoint point{ spectral_rect.left, spectral_rect.bottom };
point.y += 2 * Margin();
CRect other_info_rect{ point, CSize(draw_rect.Width() - 2 * EdgeMargin(true), DPI(24)) };
DrawToolBar(other_info_rect, IsDrawNarrowMode());
//显示歌词
CRect lyric_rect;
if (IsDrawNarrowMode())
{
lyric_rect = other_info_rect;
lyric_rect.MoveToY(other_info_rect.bottom + Margin());
if (lyric_rect.Width() >= m_progress_on_top_threshold) //如果界面宽度足够大导致进度条不显示在按钮上方而是右侧,则歌词区域可以有更大的高度
lyric_rect.bottom += DPI(16);
if (draw_rect.bottom - lyric_rect.bottom < DPI(40))
lyric_rect.bottom = draw_rect.bottom - DPI(40);
//绘制歌词
DrawLyrics(lyric_rect, 0);
}
else
{
//if (CPlayer::GetInstance().IsPlaying() || reset)
//{
int control_bar_height;
if (draw_rect.Width() - 2 * EdgeMargin(true) < m_progress_on_top_threshold) //如果控制条的宽度小于一定值,则增加其高度,以便将进度条显示在按钮上方
control_bar_height = DPI(50);
else
control_bar_height = DPI(36);
lyric_rect = draw_rect;
lyric_rect.MoveToY(other_info_rect.bottom + Margin() + control_bar_height);
lyric_rect.bottom = draw_rect.bottom;
DrawLyricsArea(lyric_rect);
//}
}
m_draw_data.lyric_rect = lyric_rect;
m_draw_data.thumbnail_rect = draw_rect;
if (!IsDrawNarrowMode())
{
m_draw_data.thumbnail_rect.bottom = lyric_rect.top;
}
//绘制播放控制条
CRect rc_control_bar;
if (IsDrawNarrowMode())
{
rc_control_bar.top = lyric_rect.bottom + Margin();
rc_control_bar.left = Margin();
rc_control_bar.right = draw_rect.right - Margin();
rc_control_bar.bottom = draw_rect.bottom - Margin();
}
else
{
rc_control_bar.top = other_info_rect.bottom + Margin();
rc_control_bar.left = EdgeMargin(true);
rc_control_bar.right = draw_rect.right - EdgeMargin(true);
rc_control_bar.bottom = lyric_rect.top;
}
DrawControlBar(rc_control_bar);
//绘制音量调按钮,因为必须在上层,所以必须在最后绘制
DrawVolumnAdjBtn();
}
void CPlayerUI::DrawLyricsArea(CRect lyric_rect)
{
bool draw_background{ IsDrawBackgroundAlpha() };
bool midi_lyric = CPlayerUIHelper::IsMidiLyric();
//显示“歌词秀”
CRect tmp;
tmp = lyric_rect;
tmp.left += (Margin() + EdgeMargin(true));
tmp.bottom = tmp.top + DPI(28);
m_draw.SetFont(&theApp.m_font_set.font9.GetFont(m_ui_data.full_screen));
m_draw.DrawWindowText(tmp, CCommon::LoadText(IDS_LYRIC_SHOW, _T(": ")), m_colors.color_text);
//显示翻译按钮
CRect translate_rect{ tmp };
translate_rect.DeflateRect(DPI(4), DPI(4));
translate_rect.right = lyric_rect.right - (Margin() + EdgeMargin(true));
translate_rect.left = translate_rect.right - translate_rect.Height();
DrawTranslateButton(translate_rect);
//绘制歌词
CRect lyric_area = lyric_rect;
lyric_area.DeflateRect(Margin() + EdgeMargin(true), 0);
lyric_area.top += 2 * Margin();
lyric_area.bottom -= (Margin() + EdgeMargin(false));
lyric_area.top += DPI(20);
DrawLyrics(lyric_area, 2 * Margin());
}