forked from ASD-ADF/ASD_Task_4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.cpp
207 lines (181 loc) · 5 KB
/
player.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#include "player.h"
void inputNewSong(infotype &x){
/**
* PR : meminta input user untuk mengisi nama dan lokasi file
* FS : infotype x terisi nama dan lokasi file
*/
cout<<"input name song (.wav) : ";
cin>>x.name;
cout<<"input song location "<<endl<<"(write - for default location) :";
cin>>x.location;
if(x.location=="-"){x.location="";}
}
void printInfo(List L){
/**
* PR : menampilkan informasi ID, nama, dan lokasi file
*/
address Q = First(L);
while(Q != NULL)
do
{
cout<<"name : "<<Info(Q).name<<endl
<<"ID: "<<Info(Q).ID<<endl;
<<"location: "<<Info(Q).location<<endl;
cout<<"Name : "<<Info(Q).name<<endl;
cout<<"ID : "<<Info(Q).ID<<endl;
cout<<"Location : "<<Info(Q).location<<endl;
Q = Next(Q);
}while(Q != First(L));
}
}
void playSong(address P){
/**
* PR : memainkan lagu yang ditunjuk oleh pointer P
*/
string filename = Info(P).location+Info(P).name;
cout<<"playing "<<filename<<endl;
PlaySound(TEXT(filename.c_str()), NULL, SND_FILENAME);
_sleep(1000); //delay 1 second
}
void playNext(address &P){
/**
* PR : memainkan file lagu pada elemen setelah P
* FS : P menunjuk next lagu dan lagu dimainkan
*/
P = Next(P);
playSong(P);
}
void playPrev(address &P){
/**
* PR : memainkan file lagu pada elemen sebelum P
* FS : P menunjuk prev lagu dan lagu dimainkan
*/
//-------------your code here-------------
P = Prev(P);
playSong(P);
//----------------------------------------
}
void shuffleList(List &L){
/**
* PR : mengacak isi (elemen) dari list L
* FS : isi (elemen) dari list teracak
*/
//-------------your code here-------------
address P = L.first;
int numRand = rand() % 10 + 1;
for(int i=1; i <= numRand; i++)
{
P = Next(P);
}
playSong(P);
//----------------------------------------
}
void sortList(List &L, int condition){
/**
* PR : mengurutkan isi (elemen) dari list L berdasarkan kondisi
* FS : isi (elemen) dari list L terurut
* jika kondisi = 1, sort by ID
* jika kondisi = 2, sort by nama
*/
//-------------your code here-------------
infotype temp;
+ int i,j,k;
+ if (condition == 1)
+ {
+ address P;
+ P = L.first;
+ for (i = 1; i <= countElm(L)-1; i++)
+ {
+ P = L.first;
+ for (j = 1 ; j <= (countElm(L) - i) ; j++)
+ {
+ if (P->info.ID > P->next->info.ID)
+ {
+ temp = P->next->info;
+ P->next->info = P->info;
+ P->info = temp;
+ P = P->next;
+ }
+ else
+ {
+ P = P->next;
+ }
+
+ }
+ }
+ }
+ else if (condition == 2)
+ {
+ address P;
+ P = L.first;
+ for (i = 1; i <= countElm(L)-1; i++)
+ {
+ P = L.first;
+ for (j = 1 ; j <= (countElm(L) - i) ; j++)
+ {
+ if (P->info.name > P->next->info.name)
+ {
+ temp = P->next->info;
+ P->next->info = P->info;
+ P->info = temp;
+ P = P->next;
+ }
+ else
+ {
+ P = P->next;
+ }
+
+ }
+ }
+ }
//----------------------------------------
}
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 = L.first;
+ int totData = countElm(L);
+ playSong(P);
+ for(int i=1; i < totData*n; i++)
+ {
+ playNext(P);
+ }
//----------------------------------------
}
void deleteSong(List &L){
/**
* IS : list L mungkin kosong
* PR : menerima input user untuk ID lagu yang ingin dihapus
* jika ID lagu ditemukan, hapus (dealokasi) lagu dari list
* FS : elemen dengan ID yang dicari didealokasi
*/
//-------------your code here-------------
int number;
+ address P;
+ cout <<"Pilih Posisi : 1. First"<<endl
+ <<" 2. After"<<endl
+ <<" 3. Last"<<endl
+ <<"Masukkan Posisi : ";cin>>number;
+ if (number == 1) {
+ deleteFirst(L,P);
+ cout << "Lagu Berhasil Dihapus";
+ }
+ else if (number == 2) {
+ address R = new elmlist;
+ cout << "Masukkan ID Element Sebelum Element Yang Akan Dihapus : ";
+ cin >> R->info.ID;
+ deleteAfter(L,P,R);
+ cout << "Lagu Berhasil Dihapus";
+ }
+ else if (number == 3) {
+ deleteLast(L,P);
+ cout << "Lagu Berhasil Dihapus";
+ }
+ else {
+ cout <<"Menu Salah"<<endl;
+ }
//----------------------------------------
}