-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathraaga.cpp
More file actions
97 lines (92 loc) · 2.8 KB
/
raaga.cpp
File metadata and controls
97 lines (92 loc) · 2.8 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
#include "Raaga.h"
Raaga::Raaga(int &argc, char*** argv)
{
_cfg.load("raaga.cfg");
_cfg.dump();
_player = std::make_shared<GstPlayer>();
_io = std::make_shared<ConsoleIO>();
_player->init(argc, argv);
}
bool Raaga::loadList()
{
std::ifstream fin(_cfg.get<std::string>("PLAYING.LIST"));
if(fin)
{
std::string line;
while(std::getline(fin, line))
{
std::streampos pos = line.find_first_of(";");
NameUriPair uriPair = NameUriPair(line.substr(0LL,pos) , line.substr(pos+1LL,line.length()));
std::cout << uriPair.first << " -- " << uriPair.second << std::endl;
_list.push_back(uriPair);
}
if(_list.size() > 0)
{
_listIt = _list.begin();
}
else
{
return false;
}
}
else
{
return false;
}
return true;
}
void Raaga::run()
{
bool quit(false);
while(!quit)
{
Instruction inst = _io->getInstruction();
switch(inst)
{
case Instruction::PLAY:
_player->play(_listIt->second);
_io->sendState(State::PLAYING);
break;
case Instruction::PAUSE:
_player->pause();
_io->sendState(State::PAUSED);
break;
case Instruction::STOP:
_player->stop();
_io->sendState(State::STOPPED);
break;
case Instruction::QUIT:
_player->quit();
_io->sendState(State::QUITTING);
quit = true;
break;
case Instruction::VOLUME_UP:
_player->setVolume(_player->getVolume()+0.05);
_io->sendState(State::VOLUME_SET);
break;
case Instruction::VOLUME_DOWN:
_player->setVolume(_player->getVolume()-0.05);
_io->sendState(State::VOLUME_SET);
break;
case Instruction::MUTE:
_player->setMute(!_player->getMute());
_io->sendState(State::MUTE);
break;
case Instruction::NEXT:
_player->stop();
_listIt = _listIt == _list.end()-1? _list.begin() : _listIt+1;
_player->play(_listIt->second);
_io->sendState(State::PLAYING);
break;
case Instruction::PREVIOUS:
_player->stop();
_listIt = _listIt == _list.begin()? _list.end()-1 : _listIt-1;
_player->play(_listIt->second);
_io->sendState(State::PLAYING);
break;
default:
_io->sendState(State::ERROR);
break;
}
}
}