-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrecorder.cpp
166 lines (135 loc) · 3.97 KB
/
recorder.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
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
165
166
/**
* @details A recorder to record the Spectrum of MuseDashLightPlay.
* @author LordLaffey
* @version v1.13
*/
#include "include/console.h"
#include "include/header.h"
#include "settings.cpp"
#include "music.cpp"
using namespace std;
void About();
void Help();
void Record();
void RecordMain();
void Save(string name, int cnt, int len, int type);
void RecordMain()
{
ClearScreen();
while(true)
{
ClearScreen();
cout << "==========================MDLP Spectrum Recorder==========================" << endl;
cout << "1. Start recording(s)" << endl;
cout << "2. About(a)" << endl;
cout << "3. Exit(q)" << endl;
cout << "==========================================================================" << endl;
char c = WaitForInput();
switch(lower(c))
{
case 's': Record(); break;
case 'a': About(); break;
case 'q': case 27: return void(); break;
default: break;
}
}
}
void About()
{
ClearScreen();
Print("This is a project to record the Spectrum of MuseDashLightPlay.\n", 20);
Print("This program is written by C++.\n", 20);
Print("And it is coded by LingChen, LordLaffey and Ptilopsis_w.\n", 20);
Print("You can contact us by github:@LordLaffey, @qingchenling, @Ptilopsis_w.\n", 20);
WaitForInput();
}
void Save(string name, int cnt, int len, int type)
{
ClearScreen();
Print("Saveing...\n", 20);
Sleep(OneSecond / 2);
FILE *fr = fopen(name.data(), "r");
FILE *tmpw = fopen("data/music/tmp.rubbish", "w");
if(fr == nullptr)
{
cout << "Error: Cannot open file!" << endl;
return void();
}
char s1[1000], s2[1000];
for(int i = 1; i <= cnt; i++)
{
fscanf(fr, "%s ", s1);
fscanf(fr, "%s\n", s2);
fprintf(tmpw, "%s %s\n", s1, s2);
}
fclose(fr);
fclose(tmpw);
FILE *fw = fopen(name.data(), "w");
FILE *tmpr = fopen("data/music/tmp.rubbish", "r");
fprintf(fw, "%d %d %d\n", cnt, len, type);
for(int i = 1; i <= cnt; i++)
{
fscanf(tmpr, "%s ", s1);
fscanf(tmpr, "%s\n", s2);
fprintf(fw, "%s %d %s\n",s2,1,s1);
}
fclose(fw);
fclose(tmpr);
system("del data\\music\\tmp.rubbish");
puts("Saved!");
Sleep(OneSecond / 2);
puts("Reloading music list...");
Music.Load(type);
}
void Record()
{
ClearScreen();
cout << "Please input the name of the music:" << endl;
string name;
cin >> name;
ChooseType:
ClearScreen();
cout << "Please input the type of the music:" << endl;
cout << "1. MuseDash mode" << endl;
cout << "2. 4K mode" << endl;
int type;
cin >> type;
string type_name = type == 1 ? "MuseDashMode" : "4KMode";
type--;
name = "data/music/" + type_name + "/" + name + ".rbq";
FILE *fw = fopen(name.data(), "w");
if(type != 1 && type != 2)
{
puts("No such type!");
Sleep(OneSecond / 2);
goto ChooseType;
}
ClearScreen();
cout << "Press any key to start recording..." << endl;
WaitForInput();
Print("3...\n", 5);
Print("2...\n", 5);
int start_time = clock();
Print("1...\n", 5);
cout << "Start!" << endl;
ClearScreen();
int cnt = 0;
while(true)
{
if(!_kbhit()) continue;
char c = _getch();
if(c == 'q' or c == 'Q')
break;
int key = setting[type].checkKey(c);
if(key != -1)
{
fprintf(fw, "%d ", clock()-start_time);
fprintf(fw, "%d\n", key);
printf("%dms ", clock()-start_time);
printf("%d\n", key);
cnt++;
}
}
fclose(fw);
Save(name, cnt, clock()-start_time, type);
}