-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
151 lines (118 loc) · 4.92 KB
/
main.cpp
File metadata and controls
151 lines (118 loc) · 4.92 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
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
/**@file main.cpp
* Runs the user interface and testers (testers are in this file)
* @authors Forrest Wargo, Rup Patel, Elias Platt
*/
#include <iostream>
#include "Song.h"
#include "ArtistMap.h"
#include "CommandHandler.h"
#include "Playlist.h"
#include "PlaylistArrayList.h"
#include "List.h"
#include "TestLib.h"
#include <stdexcept>
#include <string>
using namespace std;
void runInterface(){
std::cout << "Importing playlists...." << endl;
CommandHandler* handler = new CommandHandler();
std::string mystr;
cout << "INTERFACE START:" << endl;
while(mystr != "quit") {
std::cout << "Enter your command or help for a list of commands (type quit to stop program):"<<endl;
getline(std::cin, mystr);
std::cout << mystr<<'\n';
if(mystr == "help"){
handler->help();
}else if(mystr == "library"){
handler->library();
}else if(mystr == "artist") {
std::cout << "Enter artist:" << std::endl;
std::string artist = "";
getline(std::cin, artist);
std::cout << "Displaying all songs by " + artist << std::endl;
handler->displayArtist(artist);
}else if(mystr == "song"){
std::cout << "Enter artist:" << std::endl;
std::string artist = "";
getline(std::cin, artist);
std::cout << "Enter title:" << std::endl;
std::string title = "";
getline(std::cin, title);
handler->song(artist, title);
}else if(mystr == "import"){
std::cout << "Enter filename (for files in this project/directory, put '../' before the filename):" << std::endl;
std::string filename = "";
getline(std::cin, filename);
handler->import(filename);
}else if(mystr == "discontinue"){
std::cout << "Warning: discontinue command may crash program. Enter invalid filename to cancel this command." <<std::endl;
std::cout << "Enter filename (for files in this project/directory, put '../' before the filename):" << std::endl;
std::string filename = "";
getline(std::cin, filename);
handler->discontinue(filename);
}else if(mystr == "list playlists"){
handler->listPlaylists();
}else if(mystr == "playlist"){
std::cout << "Enter playlist title:" << std::endl;
std::string playlistTitle = "";
getline(std::cin, playlistTitle);
handler->playlist(playlistTitle);
}else if(mystr == "new"){
std::cout << "Enter playlist title:" << std::endl;
std::string playlistTitle = "";
getline(std::cin, playlistTitle);
handler->newPlaylist(playlistTitle);
}else if(mystr == "add"){
std::cout << "Enter playlist title:" << std::endl;
std::string playlistTitle = "";
getline(std::cin, playlistTitle);
std::cout << "Enter artist name:" << std::endl;
std::string artistName = "";
getline(std::cin, artistName);
std::cout << "Enter song title:" << std::endl;
std::string songTitle = "";
getline(std::cin, songTitle);
handler->addToPlaylist(playlistTitle, songTitle,artistName);
}else if(mystr == "remove"){
std::cout << "Enter playlist title:" << std::endl;
std::string playlistTitle = "";
getline(std::cin, playlistTitle);
std::cout << "Enter song title:" << std::endl;
std::string songTitle = "";
getline(std::cin, songTitle);
std::cout << "Enter artist name:" << std::endl;
std::string artistName = "";
getline(std::cin, artistName);
handler->removeFromPlaylist(playlistTitle, songTitle, artistName
);
}else if(mystr == "play next"){
std::cout << "Enter playlist title:" << std::endl;
std::string playlistTitle = "";
getline(std::cin, playlistTitle);
handler->playNext(playlistTitle);
}else if(mystr == "new random"){
std::cout << "Enter playlist title:" << std::endl;
std::string playlistTitle = "";
getline(std::cin, playlistTitle);
std::cout << "Enter max duration:" << std::endl;
std::string durationStr = "";
getline(std::cin, durationStr);
int duration = stoi(durationStr);
handler->createRandomPlaylist(duration, playlistTitle);
}else if(mystr == "quit"){
break;
}
else{
cout << "Invalid command, type help for a list of commands." <<endl;
}
}
std::cout << "Saving and quitting program..." <<endl;
handler->quit();
delete handler;
}
int main() {
//To run Testers, replace main.cpp in CMakeLists.txt with Testers.cpp
runInterface();
return 0;
}