-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlaylist.cpp
242 lines (205 loc) · 4.86 KB
/
Playlist.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
/**************************************************************
* 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 Playlist.cpp: Is to manage the songs, by *
* creating *
all of the normal functions of a playlist. *
**************************************************************/
#include <string>
#include "Song.h"
#include <iomanip>
#include <iostream>
#include <vector>
#include <fstream>
#include "Playlist.h"
#include "StringHelper.h"
#include <stdlib.h>
using namespace std;
Playlist::Playlist()
{
songs = 0;
}
Playlist::Playlist(string name)
{
songs= 0;
this->title = name;
string song, artist,album, line;
int year, songLength;
ifstream file;
file.open((StringHelper::stou(name) + ".playlist").c_str());
while(getline(file,line))
{
Song s;
song = StringHelper::parse(line,',')[0];
artist = StringHelper::parse(line,',')[1];
album = StringHelper::parse(line,',')[2];
year = atoi(StringHelper::parse(line,',')[3].c_str());
song_length = atoi(StringHelper::parse(line,',')[4].c_str());
s.set(song,artist,album,song_length,year);
addSong(s);
writeF();
}
}
void Playlist::setTitle(string songTitle)
{
this->title = songTitle;
}
string Playlist::getTitle() const
{
return name;
}
//will take a Song object as a parameter and insert it into list.
void Playlist::addSong(Song song)
{
playlist.push_back(song);
}
//will take a Song object as a parameter and delete it list.
bool Playlist:: deleteSong(Song & song)
{
for(int i = 0; i < playlist.size(); i++)
{
if(song == playlist[i])
{
playlist.erase(playlist.begin()+i);
return true;
}
}
return false;
}
// Adds song to current playlist
Playlist operator+(Playlist & p ,Song & s)
{
p.addSong(s);
return p;
}
// concatenation of two playlist objects
Playlist operator+(Playlist & playlist, Playlist & p)
{
vector<Song> s = p.getPlaylist();
Playlist p2 = playlist;
for (int i = 0; i < s.size(); i++)
{
p2.addSong(s[i]);
}
return p2;
}
//removing a song from a playlist
Playlist operator-(Playlist & p , Song & song)
{
p.deleteSong(song);
return p;
}
vector<Song> Playlist:: getPlaylist()
{
return playlist;
}
// Intersection of two playlists will have not have duplicate songs
Playlist Playlist::intersect(Playlist & p)
{
vector<Song> s1 = this ->playlist;
vector <Song> s2 = p.getPlaylist();
Playlist p1 = this ->title;
for (int i = 0; i < s1.size(); i++)
{
if(s1[i] == s2[i])
{
p1.appendToFile(s2[i]);
}
}
return p1;
}
//creates a playlist that is a merge of two playlists.
Playlist Playlist::merge(Playlist & p)
{
Playlist p1 = this ->title;
vector<Song> v = p.getPlaylist();
for (int i = 0; i < v.size() ; i++)
{
p1.addSong(v[i]);
p1.AttachToFile(v[i]);
}
return p1;
}
//finds what play mode is selected
int Playlist::getMode()
{
int count = 0;
if(mode == 0)
{
return count;
count++;
}
if(mode == 1)
{
return count;
}
if(mode == 2)
{
return count;
}
return count;
}
// play's one song from the play list starting at first index
void Playlist::play()
{
if(mode == 0 || mode == 2)
{
cout << playlist[songs] << endl;
songs++;
}
if(mode == 1)
cout << playlist[songs] << endl;
if (mode == 2 && songs == playlist.size())
{
songnumber = 0;
}
if (mode == 0 && songs == playlist.size())
{
cout << " END OF PLAYLIST" << endl;
return;
}
}
// sets player mode Normal Repeat Loop
void Playlist::setMode(char M)
{
if(M == 'N')
mode = 0;
if(M == 'R')
mode = 1;
if(M == 'L')
mode = 2;
}
void Playlist::AttachToFile(Song song)
{
ofstream file;
file.open((StringHelper::stou(title) + ".playlist").c_str(), ios::app);
file << song;
}
void Playlist::writeF()
{
ofstream file;
file.open((StringHelper::stou(title) + ".playlist").c_str());
for (int i = 0; i < playlist.size(); i++)
{
file << playlist[i];
}
}
ostream& operator<<(ostream& os, const Playlist& playlist)
{
for(int i = 0; i < playlist.playlist.size(); i++)
{
os << playlist.playlist[i] << endl;
return os;
}
}
Playlist:: Playlist(const Playlist & p)
{
playlist = p.playlist;
}
void Playlist::print()
{
for(int i = 0; i < playlist.size(); i++)
cout << playlist[i] << endl;
}