-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayerDriverFinal.cpp
302 lines (259 loc) · 9.82 KB
/
PlayerDriverFinal.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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
/**************************************************************
* Name of the file: Song.cpp *
* Group 6: Ra'Caria Burgess, Janei Elliston, *
* Michael Mondelice, Michael Parrish *
* Date last edited: 4/26/2020 *
* Purpose of Player.cpp: allow users to create new named 8
* playlist, view all the playlists, merge (intersect) *
* exisiting playlists into a new list, and play a playlist. *
**************************************************************/
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <cmath>
#include <vector>
#include <string>
#include "Playlist.h"
#include "StringHelper.h"
#include "Song.h"
using namespace std;
// STATIC
int Playlist::mode = 0;
struct songDetails
{
string name;
string filename;
};
void parse(vector<string>&temp,string songLine){
string word = "";
for (int x=0;x<songLine.length();x++)
{
if (songLine[x] == ',')
{
temp.push_back(word);
// cout << word << endl;
word = "";
}
else
{
word = word + songLine[x];
}
}
temp.push_back(word);
}
void OutputToNewList(string fName, string list ){
ofstream file;
file.open("Playlist.list",ios::app);
file << endl << list;
}
void ShowPlaylist(vector<string>&list){
for(int i = 0; i < list.size(); i++){
cout << (i+1) << "- " << list[i] <<endl;
}
cout << endl;
}
void PFileOpen(string name, vector <string> & p)
{
string word;
ifstream inFile;
inFile.open(name.c_str());
while(inFile >> word )
{
p.push_back(word);
}
}
void erase(vector<string> & p)
{
sort(p.begin(), p.end());
p.erase(unique(p.begin(), p.end()), p.end());
}
int main(){
ifstream inF,inF2;
vector<string> mp3;
Song S;
bool v;
//SELCTION CONTROLS
int select, sel2, choice, choice1, choice2;
string C, C2;
char s, m, sel;
//PLAYLIST
string title, artist, album, selection, newP;
int year, len;
do{
//open playlist file and store data in vectors
PFileOpen("Playlist.list", mp3);
//Deletes duplicates
erase(mp3);
cout << "*********** WELCOME to the AutoPlayer **********" << endl << endl;
cout << "You currently have " << mp3.size() << " playlist(s)." << endl;
cout << "1 - Open an exisiting playlist\n";
cout << "2 - Create new list\n";
cout << "3 - Exit\n";
cout << "Selection: ";
cin >> choice1;
cout << endl;
if(choice1==1){
do{
cout << "Please select a playlist from below: " << endl;
ShowPlaylist(mp3);
cout << "Selection: ";
cin >> select;
if(select < 1 || select > mp3.size())
cout << "Invalid Choice" << endl << endl;
}while(sel < 1 || select > mp3.size());
C = mp3[select-1];
Playlist List(C);
do{
Spot:
cout << "You are now playing: " << List.getTitle() << endl;
cout << setw(24) << right << "A - Add a song\n";
cout << setw(27) << right << "D - Delete a song\n";
cout << setw(25) << right << "P - Play a song\n";
cout << setw(24) << right << "M - Set the mode\n";
cout << setw(28) << right << "S - Show all songs\n";
cout << setw(18) << right << "Q - Quit" << endl;
cout << "Selection: ";
cin >> sel;
sel = toupper(sel);
switch(sel)
{
case 'A': {
// RUN ADD SONG (need)
cout << "Song Details\n";
cout << "Title: ";
getline(cin,title); //Read in Spaces
cout << "Artist: ";
getline(cin,artist);
cout << "Album: ";
getline(cin,album);
cout << "Year: ";
cin >> year;
cout << "Length (in seconds): ";
cin >> len;
S.set(title, artist, album, year, len);
List.AttachToFile(S);
List.addSong(S);
}
break;
case 'D':{
// Delete song function (need)
cout << "Enter to delete: ";
cout << "Title: ";
cin >> S;
cout << "Artist: ";
cin >> S;
v = List.deleteSong(S);
if(v == true)
cout << "Song successfully deleted" << endl;
else
cout << "Song not found" << endl;
}
break;
case 'P':{
//play song function
List.play();
goto Spot;
}
break;
case 'M':{
//run set mode function
do{
cout << "Enter Mode: \n";
cout << "N - Normal\n";
cout << "R - Repeat\n";
cout << "L - Loop" << endl;
cout << "Selection: ";
cin >> m;
}while(m != 'N' && m != 'R' && m != 'L');
List.setMode(toupper(m));
cout << "Mode is: " << m <<endl;
}
break;
case 'S':{
cout << List;
}
break;
case 'Q':{
}
break;
default:{
cout<< "Invalid Input! Please try again." << endl << endl;
}
break;
}
}while(sel != 'Q');
}
else if(choice1==2){
while(sel2 != 1 && sel2 != 2 && sel2 != 3){
cout << "1 - Create new empty list" << endl
<< "2 - Merge 2 existing playlists" << endl
<< "3 - Intersect 2 existing playlists" << endl
<< "Selection: ";
cin >> sel2;
}
cout << "Name of new playlist (cannot contain underscores): ";
cin.ignore();
getline(cin,newP);
switch(sel2)
{
case 1: {
OutputToNewList("Playlist.list", newP);
cout << " Your are now playing: " << mp3[sel-1] << endl;
}
break;
case 2: {
// MERGE TWO PLAYLIST
cout << "Which of the following playlists would you like to merge" << endl;
ShowPlaylist(mp3);
Playlist PL2(newP);
OutputToNewList("Playlist.list", newP);
cout << "Playlist 1: ";
cin >> choice;
cout << endl;
C = mp3[choice-1];
Playlist p(C);
//PL2.merge(p);
cout << "Playlist 2: ";
cin >> choice2;
cout << endl;
C2 = mp3[choice2-1];
Playlist p1(C2);
//PL2.merge(p1);
}
break;
case 3:{
//INTERSECTING PLAYLIST
cout << "Which of the following playlists would you like to intersect? " << endl;
ShowPlaylist(mp3);
Playlist PL2(newP);
OutputToNewList("Playlist.list", newP);
cout << "Playlist 1: ";
cin >> choice;
cout << endl;
C = mp3[choice-1];
Playlist p(C);
PL2 = p;
cout << "Playlist 2: ";
cin >> choice2;
cout << endl;
C2 = mp3[choice2-1];
Playlist p1(C2);
PL2.intersect(p1);
}
break;
default:{
cout << "Invalid Entry. Please input a valid entry." << endl;
}
}
}
else if(choice1!=3){
cout << "Thank " << endl << endl;
}
else
cout << "Invalid entry. Please enter valid option" << endl << endl;
}while(choice1!=3);
return 0;
}