xref: /MusicPlayer2/MusicPlayer2/SongInfoHelper.cpp (revision 6ff78c2af22a2540d4da0cd487a360b3fffc6e91)
1 #include "stdafx.h"
2 #include "SongInfoHelper.h"
3 #include "Common.h"
4 #include "AudioCommon.h"
5 #include "MusicPlayer2.h"
6 
GetBitrateString(const SongInfo & song)7 CString CSongInfoHelper::GetBitrateString(const SongInfo& song)
8 {
9     CString str;
10     if (song.bitrate == 0)
11     {
12         str = _T("-");
13     }
14     else
15     {
16         str.Format(_T("%d kbps"), song.bitrate);
17     }
18     return str;
19 }
20 
GetChannelsString(BYTE channels)21 wstring CSongInfoHelper::GetChannelsString(BYTE channels)
22 {
23     wstring chans_str;
24     if (channels == 0)
25         chans_str = L"-";
26     if (channels == 1)
27         chans_str = theApp.m_str_table.LoadText(L"UI_TXT_CHANNEL_MONO");
28     else if (channels == 2)
29         chans_str = theApp.m_str_table.LoadText(L"UI_TXT_CHANNEL_STEREO");
30     else if (channels == 6)
31         chans_str = theApp.m_str_table.LoadText(L"UI_TXT_CHANNEL_5_1");
32     else if (channels == 8)
33         chans_str = theApp.m_str_table.LoadText(L"UI_TXT_CHANNEL_7_1");
34     else if (channels > 2)
35         chans_str = theApp.m_str_table.LoadTextFormat(L"UI_TXT_CHANNEL_OTHER", { channels });
36     return chans_str;
37 }
38 
GetFreqString(const SongInfo & song)39 CString CSongInfoHelper::GetFreqString(const SongInfo& song)
40 {
41     CString freq;
42     if (song.freq == 0)
43         freq = _T("-");
44     else
45         freq.Format(_T("%.1f kHz"), song.freq / 1000.0f);
46     return freq;
47 }
48 
GetBitsString(const SongInfo & song)49 CString CSongInfoHelper::GetBitsString(const SongInfo& song)
50 {
51     CString bits;
52     if (song.bits == 0)
53         bits = theApp.m_str_table.LoadText(L"TXT_PROPERTY_DLG_FILE_BIT_DEPTH_UNDEFINED").c_str();
54     else
55         bits.Format(_T("%d Bit"), song.bits);
56     return bits;
57 }
58 
SetSongChannelInfo(SongInfo & song,const ChannelInfo & channel_info)59 void CSongInfoHelper::SetSongChannelInfo(SongInfo& song, const ChannelInfo& channel_info)
60 {
61     song.bitrate = channel_info.bitrate;
62     song.bits = static_cast<BYTE>(channel_info.bits);
63     song.freq = channel_info.freq;
64     song.channels = static_cast<BYTE>(channel_info.channels);
65 }
66 
GetSongChannelInfo(const SongInfo & song)67 CSongInfoHelper::ChannelInfo CSongInfoHelper::GetSongChannelInfo(const SongInfo& song)
68 {
69     ChannelInfo channel_info;
70     channel_info.bitrate = song.bitrate;
71     channel_info.bits = song.bits;
72     channel_info.freq = song.freq;
73     channel_info.channels = song.channels;
74     return channel_info;
75 }
76 
GetDisplayStr(const SongInfo & song_info,DisplayFormat display_format)77 std::wstring CSongInfoHelper::GetDisplayStr(const SongInfo& song_info, DisplayFormat display_format)
78 {
79     AudioType type{ CAudioCommon::GetAudioTypeByFileName(song_info.file_path) };
80     if (type == AU_MIDI)		//MIDI只显示文件名
81     {
82         display_format = DF_FILE_NAME;
83     }
84     switch (display_format)
85     {
86     case DF_FILE_NAME:		//显示为文件名
87         return song_info.GetFileName();
88     case DF_TITLE:			//显示为歌曲标题
89         if (song_info.IsTitleEmpty())	//如果获取不到歌曲标题,就显示文件名
90             return song_info.GetFileName();
91         else
92             return song_info.title;
93     case DF_ARTIST_TITLE:	//显示为艺术家 - 标题
94         if (song_info.IsTitleEmpty() && song_info.IsArtistEmpty())		//如果标题和艺术家都获取不到,就显示文件名
95             return song_info.GetFileName();
96         else
97             return (song_info.GetArtist() + _T(" - ") + song_info.GetTitle());
98     case DF_TITLE_ARTIST:	//显示为标题 - 艺术家
99         if (song_info.IsTitleEmpty() && song_info.IsArtistEmpty())		//如果标题和艺术家都获取不到,就显示文件名
100             return song_info.GetFileName();
101         else
102             return (song_info.GetTitle() + _T(" - ") + song_info.GetArtist());
103     default:
104         return song_info.GetFileName();
105     }
106 }
107 
GetPlaylistItemToolTip(const SongInfo & song_info,bool show_title,bool show_full_path)108 std::wstring CSongInfoHelper::GetPlaylistItemToolTip(const SongInfo& song_info, bool show_title, bool show_full_path)
109 {
110     std::wstring str_tip;
111     if (show_title)
112         str_tip += GetDisplayStr(song_info, theApp.m_media_lib_setting_data.display_format) + L"\r\n";
113     if (show_full_path)
114         str_tip += theApp.m_str_table.LoadText(L"TXT_PATH") + L": " + song_info.file_path + L"\r\n";
115     else
116         str_tip += theApp.m_str_table.LoadText(L"TXT_FILE_NAME") + L": " + song_info.GetFileName() + L"\r\n";
117 
118     str_tip += theApp.m_str_table.LoadText(L"TXT_TITLE") + L": " + song_info.GetTitle() + L"\r\n";
119     str_tip += theApp.m_str_table.LoadText(L"TXT_ARTIST") + L": " + song_info.GetArtist() + L"\r\n";
120     str_tip += theApp.m_str_table.LoadText(L"TXT_ALBUM") + L": " + song_info.GetAlbum() + L"\r\n";
121     str_tip += theApp.m_str_table.LoadText(L"TXT_BITRATE") + L": " + std::to_wstring(song_info.bitrate) + L"kbps";
122 
123     return str_tip;
124 }
125