-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
95 lines (81 loc) · 1.78 KB
/
main.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
/*
* main.cpp
*
* Created on: Sep 11, 2017
* Author: jussi
*/
#include "s3mContainer.hpp"
#include "ALSAPlayer.hpp"
#include <thread>
#include <iostream>
#include <csignal>
#include <sstream>
static std::thread* playerT;
static s3mContainer* player;
void TERMHandler(int signal)
{
std::cout << std::endl; std::cout << "Signaled exit by user" << std::endl;
player->requestQuit();
playerT->join();
delete player;
delete playerT;
exit(0);
}
void playerThread(s3mContainer* w_player, std::string w_command)
{
if(w_command == "play")
{
// placeholder
}
else
{
w_player->loadSong(w_command);
w_player->playSong();
}
}
int main(int argc, char** argv)
{
// input argument check
if (argc < 2)
{
printf("Usage: %s <filename>\n", argv[0]);
return -1;
}
// set signal handlers for SIGINT and SIGTERM
signal(SIGINT, TERMHandler);
signal(SIGTERM, TERMHandler);
player = new s3mContainer();
std::string command(argv[1]);
playerT = new std::thread;
*playerT = std::thread(playerThread, player, command);
std::string readCmd = "";
while(1)
{
std::cin >> readCmd;
if(readCmd == "quit" || readCmd == "exit")
{
break;
}
else if(readCmd.substr(4) == "play")
{
// parse play command
}
else if(readCmd == "pause")
{
player->pause();
}
else if(readCmd.length() >= 8 && readCmd.substr(8) == "playlist")
{
// parse playlist command
}
else if(readCmd == "resume")
{
player->resume();
}
}
player->requestQuit();
playerT->join();
delete player;
delete playerT;
return 0;
}