-
Notifications
You must be signed in to change notification settings - Fork 7
/
ScreenNowPlaying.cpp
129 lines (117 loc) · 3.57 KB
/
ScreenNowPlaying.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
/*
ScreenNowPlaying.cpp - Slimmer
Copyright (C) 2016-2017 Terényi, Balázs ([email protected])
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ScreenNowPlaying.h"
#include "Config.h"
#include <math.h>
ScreenNowPlaying::ScreenNowPlaying(LCDClient* parent) : Screen(parent, "NowPlaying", "NowPlaying")
{
setHeartBeat(LCD_HEARTBEAT_OFF);
mMode.move(1, 1);
mTime.move(3, 1);
mPlaylist.move(width()-5, 1);
mLine2.set("", 1, 2, width(), 2, Config::scrollSpeed(), LCDScroller::Marquee);
if (height() > 2)
mLine3.set("", 1, 3, width(), 3, Config::scrollSpeed(), LCDScroller::Marquee);
if (height() > 3)
mLine4.set("", 1, 4, width(), 4, Config::scrollSpeed(), LCDScroller::Marquee);
add(&mMode);
add(&mTime);
add(&mPlaylist);
add(&mLine2);
if (height() > 2) add(&mLine3);
if (height() > 3) add(&mLine4);
}
void ScreenNowPlaying::update(const Player& player)
{
// MODE
string s = "?";
if (player.mode() == Player::Play)
s = ">";
else if (player.mode() == Player::Stop)
s = "-";
else if (player.mode() == Player::Pause)
s = "=";
mMode.setText(s);
// PLAYLIST INDEX AND SIZE
string pls;
if (player.playlistSize() == 0)
pls = "0/0";
else
pls = std::to_string(player.playlistIndex() + 1) + "/" + std::to_string(player.playlistSize());
mPlaylist.move(width() - pls.length() + 1);
mPlaylist.setText(pls);
// PLAYING TIME
s = std::to_string((int)(player.time() / 60.0f)) + ":";
string sec = std::to_string((int)(fmod(player.time(), 60.0f)));
sec.insert(0, 2 - sec.length(), '0');
s += sec;
if (player.duration() > 0)
{
string durs = "/" + std::to_string((int)(player.duration() / 60.0f)) + ":";
sec = std::to_string((int)(fmod(player.duration(), 60.0f)));
sec.insert(0, 2 - sec.length(), '0');
durs += sec;
if (3 + s.length() + durs.length() + pls.length() <= width()) s += durs;
}
mTime.setText(s);
// EMPTY QUEUE
if (player.playlistSize() == 0)
{
s = string(width() > cEmptyQueueTextLength ? width() / 2 - cEmptyQueueTextLength / 2 : 0, ' ') + cEmptyQueueText;
if (height() > 3)
{
mLine2.setText("");
mLine3.setText(s);
mLine4.setText("");
}
else
mLine2.setText(s);
return;
}
// SONG INFO
if (!player.remote())
{
if (height() > 3)
{
mLine2.setText(trail(toLCDString(player.artist())));
mLine3.setText(trail(toLCDString(player.album())));
}
else
{
s = "";
if (player.artist().length() > 0) s += player.artist() + ": ";
if (player.album().length() > 0) s += player.album() + " - ";
if (player.title().length() > 0) s += player.title();
mLine2.setText(trail(toLCDString(s)));
}
}
else
{
if (height() > 3)
{
mLine2.setText(trail(toLCDString(player.remoteTitle())));
mLine3.setText(trail(toLCDString(player.artist())));
}
else
{
s = "";
if (player.artist().length() > 0) s += player.artist() + ": ";
if (player.title().length() > 0) s += player.title() + " ";
s += "[" + player.remoteTitle() + "]";
mLine2.setText(trail(toLCDString(s)));
}
}
if (height() > 3) mLine4.setText(trail(toLCDString(player.title())));
}