-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic_info.c
237 lines (193 loc) · 6.37 KB
/
basic_info.c
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#include "basic_info.h"
#include "songs.h"
#include "utils.h"
#include "keyboards.h"
void
basic_state_checking(void)
{
int rep, ran, sgl, len, crt, vol, ply, btr;
struct mpd_status *status;
status = getStatus(conn);
rep = mpd_status_get_repeat(status);
ran = mpd_status_get_random(status);
sgl = mpd_status_get_single(status);
len = mpd_status_get_queue_length(status);
crt = mpd_status_get_song_id(status);
vol = mpd_status_get_volume(status);
ply = mpd_status_get_state(status);
btr = mpd_status_get_kbit_rate(status);
basic_info->crt_time = mpd_status_get_elapsed_time(status);
basic_info->total_time = mpd_status_get_total_time(status);
mpd_status_free(status);
if(rep != basic_info->repeat || ran != basic_info->random
|| sgl != basic_info->single || len != basic_info->total
|| crt != basic_info->current || vol != basic_info->volume
|| ply != basic_info->state)
{
basic_info->repeat = rep;
basic_info->random = ran;
basic_info->single = sgl;
basic_info->total = len;
basic_info->current = crt;
basic_info->volume = vol;
basic_info->state = ply;
signal_all_wins();
}
/* as many songs's bit rate varies while playing
we refresh the bit rate display only when the
relevant change greater than 0.2 */
if(abs(basic_info->bit_rate - btr) / (float)(btr + 1) > 0.2)
{
basic_info->bit_rate = btr;
signal_win(BASIC_INFO);
}
/* get current song's name */
status = init_mpd_status(conn);
strncpy(basic_info->format, "null", 16);
*basic_info->crt_name = '\0';
if (basic_info->state == MPD_STATE_PLAY ||
basic_info->state == MPD_STATE_PAUSE) {
struct mpd_song *song;
if (!mpd_response_next(conn))
printErrorAndExit(conn);
song = mpd_recv_song(conn);
if (song != NULL) {
strncpy(basic_info->crt_name, get_song_tag(song, MPD_TAG_TITLE), 512);
strncpy(basic_info->format, get_song_format(song), 16);
}
mpd_song_free(song);
}
mpd_status_free(status);
my_finishCommand(conn);
}
void
print_basic_help(void)
{
WINDOW *win = specific_win(HELPER);
wprintw(win, " [n] :\tNext song\t\t [R] :\tToggle repeat\n");
wprintw(win, " [p] :\tPrevious song\t\t [r] :\tToggle random\n");
wprintw(win, " [-] :\tVolume down\t\t [s] :\tToggle single\n");
wprintw(win, " [=] :\tVolume Up\t\t [b] :\tPlayback\n");
wprintw(win, " [t] :\tPlay / Pause\t\t [l] :\tRedraw screen\n");
wprintw(win, " <L> :\tSeek backward\t\t <R> :\tSeek forward\n");
wprintw(win, "\n [TAB] : New world\n");
wprintw(win, " [e/q] : Quit\n");
}
void
print_extra_info(void)
{
WINDOW *win = specific_win(EXTRA_INFO);
if (basic_info->volume >= 0)
wprintw(win, "Volume:%3i%c ", basic_info->volume, '%');
else {
wprintw(win, "Volume: n/a ");
}
mvwprintw(win, 0, 14, "Search: ");
color_print(win, 6,
mpd_tag_name(songlist->tags
[songlist->crt_tag_id]));
wprintw(win, " ");
}
void
print_basic_song_info(void)
{
WINDOW *win = specific_win(BASIC_INFO);
if (basic_info->crt_name) {
char buff[80];
/* int twid = 38; */
/* if(snprintf(buff, twid, "%s", */
/* get_song_tag(song, MPD_TAG_TITLE)) >= twid) */
/* strcpy(buff + twid - 4, "..."); // in case of long title */
/* color_print(win, 1, buff); */
/* print artist
int awid = 28;
if(snprintf(buff, awid, "\t%s",
get_song_tag(song, MPD_TAG_ARTIST)) >= awid)
strcpy(buff + awid - 4, "...");
color_print(win, 5, buff);
*/
int title_len = win->_maxx < (int)sizeof(buff) ?
win->_maxx : (int)sizeof(buff);
snprintf(buff, title_len, "%s", basic_info->crt_name);
color_print(win, 1, buff);
}
mvwprintw(win, 1, 0, "[");
if (basic_info->state == MPD_STATE_PLAY)
color_print(win, 6, "playing");
else if(basic_info->state == MPD_STATE_PAUSE)
color_print(win, 4, "paused");
else
color_print(win, 4, "stopped");
wprintw(win, "]");
/* mvwprintw(win, 1, 10, "[%i/%u]", */
/* mpd_status_get_song_pos(status) + 1, */
/* mpd_status_get_queue_length(status)); */
// status modes [ors] : repeat, random, single
mvwprintw(win, 1, 10, "[");
if (basic_info->random)
color_print(win, 1, "r");
else wprintw(win, "-");
if (basic_info->single)
color_print(win, 7, "s");
else wprintw(win, "-");
if (basic_info->repeat)
color_print(win, 5, "o");
else wprintw(win, "-");
wprintw(win, "]");
mvwprintw(win, 1, 16, "[%s]", basic_info->format); // music format
mvwprintw(win, 1, 46, "%02i:%02i",
basic_info->total_time / 60, basic_info->total_time % 60);
static int old_bit_rate = 111;
if(abs(old_bit_rate - basic_info->bit_rate)
/ (float) (basic_info->bit_rate + 1) > 0.2 && basic_info->bit_rate != 0)
old_bit_rate = basic_info->bit_rate;
else
basic_info->bit_rate = old_bit_rate;
mvwprintw(win, 1, 59, " %ikb/s", basic_info->bit_rate);
}
void // VERBOSE_PROC_BAR
print_basic_bar(void)
{
int crt_time, crt_time_perc, total_time,
fill_len, empty_len, i;
WINDOW *win = specific_win(VERBOSE_PROC_BAR);
const int axis_length = win->_maxx - 8;
crt_time = basic_info->crt_time;
total_time = basic_info->total_time;
crt_time_perc = (total_time == 0 ? 0 : 100 * crt_time / total_time);
fill_len = crt_time_perc * axis_length / 100;
empty_len = axis_length - fill_len;
wprintw(win, "[");
wattron(win, my_color_pairs[2]);
for(i = 0; i < fill_len - 1; wprintw(win, "="), i++);
if(i == fill_len - 1) wprintw(win, "+");
wprintw(win, ">");
//for(i = 0; i <= fill_len; wprintw(win, "="), i++);
for(i = 0; i < empty_len; wprintw(win, " "), i++);
wattroff(win, my_color_pairs[2]);
wprintw(win, "]");
//wprintw(win, "%3i%% ", crt_time_perc);
int left_time = total_time - crt_time;
wprintw(win, " %02i:%02i", left_time / 60, left_time % 60);
}
struct BasicInfo* basic_info_setup(void)
{
struct BasicInfo* binfo =
(struct BasicInfo*) malloc(sizeof(struct BasicInfo));
binfo->state = binfo->repeat
= binfo->random = binfo->single
= binfo->total = binfo->current
= binfo->volume = binfo->bit_rate
= binfo->crt_time = binfo->total_time = 0;
// window mode setup
binfo->wmode.size = 5;
binfo->wmode.wins = (struct WindowUnit**)
malloc(binfo->wmode.size * sizeof(struct WindowUnit*));
binfo->wmode.wins[0] = &wchain[BASIC_INFO];
binfo->wmode.wins[1] = &wchain[EXTRA_INFO];
binfo->wmode.wins[2] = &wchain[VERBOSE_PROC_BAR];
binfo->wmode.wins[3] = &wchain[VISUALIZER];
binfo->wmode.wins[4] = &wchain[HELPER];
binfo->wmode.listen_keyboard = &basic_keymap;
return binfo;
}