-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNewPlaylist
166 lines (136 loc) · 3.96 KB
/
NewPlaylist
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
/**************************************************************
* Name of the file: Song.cpp *
* Group 6: Ra'Caria Burgess, Janei Elliston, *
* Michael Mondelice, Michael Parrish *
* Date last edited: 4/24/2020 *
* Purpose of Playlist.cpp: Is to manage the songs, by *
* creating *
all of the normal functions of a playlist. *
**************************************************************/
#include <iostream>
#include <string>
#include "Playlist.h"
#include "Song.h"
using namespace std;
void Playlist::setName(std::string n){
name = n;
}
std::string Playlist::getName(){
return name;
}
void Playlist::addSong(Song song){
playlist.push_back(song);
}
bool Playlist::deleteSong(Song song){
bool has_song = false;
for(int i = 0; i < playlist.size(); i++){
if(song == playlist[i]){
playlist.erase(playlist.begin()+i);
has_song = true;
}
}
return has_song;
}
Playlist Playlist::intersect(Playlist i_list){
Playlist intersect_list;
for(int s = 0; s < playlist.size(); s++){
for(int i=0; i<i_list.playlist.size(); i++){
if(playlist[s] == i_list.playlist[i]){
intersect_list.addSong(playlist[s]);
break;
}
}
}
return intersect_list;
}
Playlist Playlist::merge(Playlist m_list){
Playlist merge_list;
for(int s = 0; s < playlist.size(); s++){
merge_list.addSong(playlist[s]);
}
for(int s = 0; s < m_list.playlist.size(); s++){
merge_list.addSong(playlist[s]);
}
return merge_list;
}
void Playlist::play(){
switch(play_mode){
case 'N':
if(now_playing < playlist.size()){
std::cout << "NOW PLAYING: " << playlist[now_playing] << std::endl;
now_playing++;
}
break;
case 'R':
std::cout << "NOW PLAYING: " << playlist[now_playing] << std::endl;
break;
case 'L':
if(now_playing < playlist.size()){
std::cout << "NOW PLAYING: " << playlist[now_playing] << std::endl;
now_playing++;
}
if(now_playing == playlist.size()){
now_playing = 0;
}
break;
default:
if(now_playing < playlist.size()){
std::cout << "NOW PLAYING: " << playlist[now_playing] << std::endl;
now_playing++;
}
break;
}
}
void Playlist::setMode(char mode){
//N = Normal
//R = Repeat
//L = Loop
char m = toupper(mode);
if(m != 'N' && m != 'R' && m != 'L'){
return;
}else {
play_mode = m;
}
}
std::ostream& operator<<(std::ostream& os, const Playlist& pList){
os << "PLAYLIST SONGS" << std::endl;
os << "--------------------------------" << std::endl;
for(int s = 0; s < pList.playlist.size(); s++){
os << s << std::endl;
}
os << "--------------------------------" << std::endl;
return os;
};
Playlist operator+(Playlist p1, Playlist p2){
Playlist merge_list;
for(int s = 0; s < p1.playlist.size(); s++){
merge_list.addSong(p1.playlist[s]);
}
for(int s = 0; s < p2.playlist.size(); s++){
merge_list.addSong(p2.playlist[s]);
}
return merge_list;
};
Playlist operator+(Playlist p, Song song){
Playlist plus_list;
for(int s = 0; s < p.playlist.size(); s++){
plus_list.addSong(p.playlist[s]);
}
plus_list.playlist.push_back(song);
return plus_list;
};
Playlist operator-(Playlist p, Song song){
Playlist d_list;
for(int s = 0; s < p.playlist.size(); s++){
if(!(p.playlist[s] == song)){
d_list = d_list+song;
}
}
return d_list;
};
Playlist::Playlist(){
name = " ";
now_playing = 0;
play_mode = 'N';
playlist = {};
}