-
Notifications
You must be signed in to change notification settings - Fork 208
Expand file tree
/
Copy pathplayer.cpp
More file actions
109 lines (98 loc) · 2.74 KB
/
player.cpp
File metadata and controls
109 lines (98 loc) · 2.74 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
#include "player.h"
#include <ctime>
int randomInt(int max_int) {
/** YOU DON'T NEED TO MODIFY THIS */
srand(time(NULL));
return (rand() % max_int) + 1;
}
void printInfo(List L) {
/**
* PR : menampilkan informasi ID, nama, dan lokasi file
* YOU DON'T NEED TO MODIFY THIS
*/
address Q = first(L);
if(first(L) != NULL){
do {
cout<<"name : "<<info(Q).name<<endl
<<"ID : "<<info(Q).ID<<endl
<<"location: "<<info(Q).location<<endl;
Q = next(Q);
} while(Q != first(L) && first(L) != NULL);
} else {
cout<<"Tidak Ada Lagu"<<endl;
}
cout<<"==============================================="<<endl;
}
void playMusic(address P) {
/**
* PR : memainkan lagu yang ditunjuk oleh pointer P
* YOU DON'T NEED TO MODIFY THIS
*/
string filename = info(P).location+"/"+info(P).name;
cout<<"playing "<<filename<<endl;
PlaySound(TEXT(filename.c_str()), NULL, SND_FILENAME);
_sleep(500); //delay 0.5 second
}
void shuffleList(List &L) {
/**
* PR : mengacak isi (elemen) dari list L
* FS : isi (elemen) dari list teracak
*/
//------------- YOUR CODE HERE -------------
address P = first(L);
address Q;
int lenList = 0;
do{
lenList = lenList + 1;
P = next(P);
} while(P != first(L));
while(lenList > 0){
P = first(L);
int random = randomInt(lenList);
while(random != 0){
P = next(P);
random = random - 1;
}
deleteAfter(L, prev(P), Q);
insertFirst(L, Q);
lenList = lenList - 1;
}
//----------------------------------------
}
void playRepeat(List &L, int n) {
/**
* PR : memainkan seluruh lagu di dalam list
* dari lagu pertama hingga terakhir sebanyak n kali
*/
//------------- YOUR CODE HERE -------------
address P = first(L);
int i = 1;
while(i <= n){
do{
cout<<"Sedang memutar lagu: "<<info(P).name<<endl;
playMusic(P);
P = next(P);
}while(P != first(L));
i = i + 1;
}
//----------------------------------------
}
void deleteMusicByID(List &L, infotype x) {
/**
* IS : list L mungkin kosong
* PR : menerima input user untuk ID lagu yang ingin dihapus
* jika ID lagu ditemukan, hapus (deallocate) lagu dari list
* FS : elemen dengan ID yang dicari dideallocate
*/
//------------- YOUR CODE HERE -------------
address P, Q;
P = findElmByID(L, x);
P = prev(P);
if(next(P) == first(L)){
deleteFirst(L, P);
} else if(info(next(P)).ID == x.ID){
deleteAfter(L, P, Q);
deallocate(Q);
}
//----------------------------------------
}