forked from LordLaffey/MuseDashLightPlay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Music.cpp
101 lines (74 loc) · 1.88 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
#ifndef _MDLP_MUSIC
#define _MDLP_MUSIC
#include "header.cpp"
class Music{
private:
vector<pair<int,string> > list;
public:
void MusicMain();
void Load();
void PrintList();
FILE* ChooseMusic();
}Music;
void Music::MusicMain(){
PrintList();
cout << "Press 'q' to quit.";
while(1)
{
if(_kbhit())
{
char c=_getch();
if(c=='q' or c=='Q') break;
}
}
}
void Music::Load(){
ClearScreen();
Print("Loading Music...\n", 20);
string path=".\\data\\music\\";
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.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(){
ClearScreen();
printf("=============== Music List(total %d) ===============\n",list.size());
for(int i=0;i<list.size();i++)
cout<<list[i].first<<" "<<list[i].second<<endl;
printf("===================================================\n");
}
FILE* Music::ChooseMusic(){
begin:
ClearScreen();
PrintList();
puts("Choose a music:");
int id;
cin>>id;
if(id>list.size())
{
puts("Invalid ID!");
Sleep(OneSecond);
goto begin;
}
string path=".\\data\\music\\";
path+=list[id-1].second;
return fopen(path.data(),"r");
}
#endif // _MDLP_MUSIC