-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathReadLyric.cpp
More file actions
164 lines (144 loc) · 4.15 KB
/
ReadLyric.cpp
File metadata and controls
164 lines (144 loc) · 4.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#include "ReadLyric.h"
//#include "tchar.h"
#include "fstream"
using namespace std;
//#ifdef _WINDOWS_
// #undef _WINDOWS_
// #include "afxcmn.h"
//#endif
int LineCount = 0; //总行数
LYRIC stLyric[1000]; //时间戳和歌词
//读取并把歌词切分成句
bool SplitLyric(CString path)
{
//初始化存储数组
for (int i = 0;i<1000;i++)
{
for(int j = 0;j<1000;j++)
{
stLyric[i].Lyric [j] = 0;
stLyric[i].Time = 0;
}
}
LineCount = 0; //初始化总行数
path.Replace (L".mp3",L".lrc"); //歌词路径
path.Replace (L".MP3",L".lrc"); //路径大小写
ifstream file(path,ios::in);
if (!file)
{
path.Replace (L".lrc",L".LRC"); //解决歌词后缀大写问题
file.open (path,ios::in);
if(!file)
{
//MessageBox(L"歌词没有发现");
file.close ();
return false; //没有歌词
}
}
char pbuf[1000];
while (file.getline (pbuf,1000))
{
DWORD dwNum = MultiByteToWideChar(CP_ACP,0,pbuf,-1,NULL,0);
TCHAR *pTmp;
pTmp = new TCHAR[dwNum];
MultiByteToWideChar(CP_ACP,0,pbuf,-1,pTmp,dwNum);
CString Lyric;
Lyric = pTmp;
int pos = 0;
int ppos = 0;
LONGLONG tmpTime = 0;
CString strLyric,bstrLyric,strTime,bstrTime;
pos = Lyric.Find (L"]");
//判断有时间戳
strTime = Lyric.Left (pos+1);
strTime.Remove (L'[');
strTime.Remove (L']'); //获得时间格式 03:25.68
ppos = strTime.Find (L'0');
if (pos != -1 || ppos != -1) //判断是否是 空行就是连时间戳都没有
{
strLyric = Lyric.Right (Lyric.GetLength ()-pos-1); //获得歌词
//pc时间转换
char fenbuf[100];
char miaobuf[100];
char haombuf[100];
CString fen, //分
miao, //秒
haom; //毫秒
fen = strTime.Mid (0,2);
miao = strTime.Mid (3,2);
haom = strTime.Mid (6,strTime.GetLength ()-6);
for(int i = 0;i<fen.GetLength ()+1;i++)
{
fenbuf[i]= fen.GetAt (i);
}
for(int i = 0;i<miao.GetLength ()+1;i++)
{
miaobuf[i]= miao.GetAt (i);
}
for(int i = 0;i<haom.GetLength ()+1;i++)
{
haombuf[i]= haom.GetAt (i);
}
//atoi wince和pc不同
tmpTime = (atoi(fenbuf)*60 + atoi(miaobuf)); //转换成秒 //*1000 + atoi(haombuf); //时间转换 毫秒
//第一行的处理
if (tmpTime == 0)
{
tmpTime = 1; //一秒时出现
}
//有补偿的时间标签处理
int bpos =0;
bpos = strLyric.Find (L"]");
if (bpos != -1)
{
bstrLyric = strLyric; //还有时间标签的歌词
strLyric = strLyric.Right (strLyric.GetLength ()-bpos-1);
}
//存储
for (int i = 0;i<strLyric.GetLength ()+1;i++)
{
stLyric[LineCount].Lyric[i] = strLyric.GetAt (i);
}
stLyric[LineCount].Time = tmpTime;
LineCount++;
if (bpos != -1)
{
//bstrLyric = bstrLyric.Right (bstrLyric.GetLength ()-bpos-1);
bstrTime = bstrLyric.Left (bpos+1);
bstrTime.Remove (L'[');
bstrTime.Remove (L']'); //获得时间格式 03:25.68
char fenbuf[100];
char miaobuf[100];
char haombuf[100];
CString fen,miao,haom;
fen = bstrTime.Mid (0,2);
miao = bstrTime.Mid (3,2);
haom = bstrTime.Mid (6,bstrTime.GetLength ()-6);
for(int i = 0;i<fen.GetLength ()+1;i++)
{
fenbuf[i]= fen.GetAt (i);
}
for(int i = 0;i<miao.GetLength ()+1;i++)
{
miaobuf[i]= miao.GetAt (i);
}
for(int i = 0;i<haom.GetLength ()+1;i++)
{
haombuf[i]= haom.GetAt (i);
}
//atoi wince和pc不同
tmpTime = (atoi(fenbuf)*60 + atoi(miaobuf)); //秒 //*1000 + atoi(haombuf);
bstrLyric = bstrLyric.Right (bstrLyric.GetLength ()-bpos-1);
for (int i = 0;i<bstrLyric.GetLength ()+1;i++)
{
stLyric[LineCount].Lyric [i] = bstrLyric.GetAt (i);
}
stLyric[LineCount].Time = tmpTime;
LineCount++;
}//end if (bpos != -1)
}//end 判断是否是 空行就是连时间戳都没有
delete pTmp;
}// end while (file.getline (pbuf,1000))
file.close ();
return true;
}