-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
132 lines (119 loc) · 2.81 KB
/
main.cpp
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
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
using namespace std;
typedef struct timing{
int m;
double s;
}Timing;
struct timingComp{
bool operator()(const Timing& a, const Timing& b){
if(a.m<b.m)return true;
else if(a.m==b.m){
return a.s<b.s;
}
else return false;
}
};
int main(int argc, char **argv){
ifstream fin;
string strin;
string artist, title, album, by;
char *tok, *stok;
char *cstrin, *lyric;
vector<Timing> timings;
Timing ttmp, ttmp2;
map<Timing, char *, timingComp> lyrics;
double gap;
double inacc=0;
double total=0;
double offset=0;
if(argc>2)offset=atof(argv[2]);
fin.open(argv[1]);
while(getline(fin, strin)){ //read in lrc file line by line
if(strin[0]!='['){
//cout<<"not"<<strin[0]<<endl;
continue;
}
cstrin=new char[strin.size()+1];
strcpy(cstrin, strin.c_str());
//cout<<cstrin<<endl;
tok=strtok(cstrin, "[]");
while(tok!=NULL){
//cout<<tok<<endl;
if((strlen(tok)==8&&tok[2]==':'&&tok[5]=='.')||(strlen(tok)==5&&tok[2]==':')){
ttmp.m=atoi(tok);
ttmp.s=atof(tok+3);
timings.push_back(ttmp);
//cout<<"timing "<<ttmp.m<<" "<<ttmp.s<<endl;
}
else{
lyric=new char[strlen(strstr(strin.c_str(), tok))+1];
strcpy(lyric, strstr(strin.c_str(), tok));
for(vector<Timing>::iterator i=timings.begin();i!=timings.end();i++){
lyrics.insert(pair<Timing, char *>(*i, lyric));
}
timings.clear();
//cout<<"lyric "<<lyric<<endl;
break;
}
tok=strtok(NULL, "[]");
}
if(timings.size()>0){
lyric=new char[1];
strcpy(lyric, "");
for(vector<Timing>::iterator i=timings.begin();i!=timings.end();i++){
lyrics.insert(pair<Timing, char *>(*i, lyric));
}
timings.clear();
}
}
printf("\25[30;40m^LS1\n5\n\25[30;40m^L\n4\n\25[30;40m^L\n3\n\25[30;40m^L\n2\n\25[30;40m^L\n1\n");
for(map<Timing, char *, timingComp>::iterator i=lyrics.begin();i!=lyrics.end();i++){
if(i==lyrics.begin()){
ttmp=i->first;
gap=(ttmp.m)*60+ttmp.s+offset;
inacc+=round(gap*10)/10-gap;
gap=round(gap*10)/10;
if(inacc>0.05){
gap-=0.1;
inacc-=0.1;
}
else if(inacc<-0.05){
gap+=0.1;
inacc+=0.1;
}
total+=gap;
printf("\25[30;40m^L%.1lf\n0\n", gap);
lyric=i->second;
continue;
}
gap=(i->first.m-ttmp.m)*60+i->first.s-ttmp.s;
inacc+=round(gap*10)/10-gap;
gap=round(gap*10)/10;
if(inacc>0){
gap-=0.1;
inacc-=0.1;
}
else if(inacc<0){
gap+=0.1;
inacc+=0.1;
}
total+=gap;
printf("\25[30;40m^L%.1lf\25[m\n", gap);
printf("%s\n", lyric);
ttmp=i->first;
lyric=i->second;
//cout<<i->first.m<<" "<<i->first.s<<" "<<i->second<<endl;
}
printf("\25[30;40m^LE\25[m\n");
printf("%s\n", lyric);
//cout<<total<<" "<<inacc<<endl;
//system("pause");
return 0;
}