-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmusic.cpp
131 lines (109 loc) · 3.08 KB
/
music.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
#ifndef _MDLP_MUSIC
#define _MDLP_MUSIC
#include "include/header.h"
using namespace std;
class Music
{
private:
vector<pair<int, string>> list[2];
public:
void MusicPrework();
void MusicMain();
void Load(int type);
void PrintList(int type);
FILE *ChooseMusic(int type);
} Music;
void Music::MusicPrework()
{
Load(1), Load(2);
}
void Music::MusicMain()
{
ClearScreen();
cout << "=========================MDLP Music Menu=======================" << endl;
cout << "1. MuseDash Mode" << endl;
cout << "2. 4K Mode" << endl;
cout << "3. Back" << endl;
cout << "===============================================================" << endl;
int type = 1;
while(true)
{
if(!_kbhit()) continue;
char c = _getch();
if(c == '1') { type = 1; break; }
else if(c == '2') { type = 2; break; }
else if(c == '3') return void();
}
PrintList(type);
cout << "Press 'q' to quit.";
while(true)
{
if(!_kbhit()) continue;
char c = _getch();
if(c == 'q' or c == 'Q') break;
}
}
void Music::Load(int type)
{
ClearScreen();
string type_name = type == 1 ? "MuseDashMode" : "4KMode";
Print("Loading ", 20);
Print(type_name, 20);
Print(" Music...\n", 20);
type--;
list[type].clear();
string path = ".\\data\\music\\" + type_name + "\\";
long long hFile = 0;
struct _finddata_t fileinfo;
string p;
int cnt = 0;
if((hFile = _findfirst(p.assign(path).append("\\*.rbq").c_str(), &fileinfo)) != -1)
{
do
{
if(!(fileinfo.attrib & _A_SUBDIR))
{
cnt++;
list[type].emplace_back(cnt, fileinfo.name);
cout << "Loading " << fileinfo.name << endl;
}
} while(_findnext(hFile, &fileinfo) == 0);
_findclose(hFile);
}
Sleep(OneSecond / 5);
cout << "Loaded!";
Sleep(OneSecond / 5);
}
void Music::PrintList(int type)
{
ClearScreen();
type--;
printf("=============== Music List(total %d) ===============\n", list[type].size());
for(int i = 0; i < list[type].size(); i++)
cout << list[type][i].first << " " << list[type][i].second << endl;
printf("===================================================\n");
}
/**
* @param type 1: MuseDash Mode, 2: 4K Mode
*/
FILE *Music::ChooseMusic(int type)
{
begin:
ClearScreen();
PrintList(type);
type--;
puts("Choose a music, input 114514 to quit:");
int id; cin >> id;
if(id == 114514) return NULL;
if(id > list[type].size())
{
puts("Invalid ID!");
Sleep(OneSecond);
goto begin;
}
string type_name = type == 0 ? "MuseDashMode" : "4KMode";
string path = ".\\data\\music\\";
path += type_name + "\\" + list[type][id - 1].second;
return fopen(path.data(), "r");
}
#endif // _MDLP_MUSIC