-
Notifications
You must be signed in to change notification settings - Fork 6
/
lmsmonitor.c
196 lines (167 loc) · 4.4 KB
/
lmsmonitor.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
/*
* lmsmonitor.c
*
* (c) 2015 László TÓTH
*
* Todo: Done - Automatic server discovery
* Done - Get playerID automatically
* Reconect to server
*
* 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.
*
* See <http://www.gnu.org/licenses/> to get a copy of the GNU General
* Public License.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <errno.h>
#include "tagUtils.h"
#include "mixermon.h"
#include "sliminfo.h"
#include "display.h"
#include "common.h"
#ifdef __arm__
#include "ArduiPi_OLED_lib.h"
#include "Adafruit_GFX.h"
#include "ArduiPi_OLED.h"
#include "display.h"
#endif
#define SLEEP_TIME (25000/25)
#define CHRPIXEL 8
char stbl[BSIZE];
tag *tags;
int main(int argc, char *argv[]) {
long lastVolume = 0;
long actVolume = 0;
long pTime, dTime;
char buff[255];
char *sndCard = NULL;
char *playerName = NULL;
int aName;
#define LINE_NUM 4
tagtypes_t layout[LINE_NUM][3] = {
{COMPOSER, ARTIST, MAXTAG_TYPES},
{ALBUM, MAXTAG_TYPES, MAXTAG_TYPES},
{TITLE, MAXTAG_TYPES, MAXTAG_TYPES},
{ALBUMARTIST, CONDUCTOR, MAXTAG_TYPES},
};
opterr = 0;
while ((aName = getopt (argc, argv, "o:n:tvh")) != -1) {
switch (aName) {
case 't':
enableTOut();
break;
case 'v':
incVerbose();
break;
case 'o':
sndCard = optarg;
break;
case 'n':
playerName = optarg;
break;
case 'h':
printf("LMSMonitor Ver. 0.2\nUsage [options] -n Player name\noptions:\n -o Soundcard (eg. hw:CARD=IQaudIODAC)\n -t enable print info to stdout\n -v increment verbose level\n\n");
exit(1);
break;
}
}
if((tags = initSliminfo(playerName)) == NULL) { exit(1); }
// init ALSA mixer monitor
startMimo(sndCard, NULL);
#ifdef __arm__
// init OLED display
if (initDisplay() == EXIT_FAILURE) {
exit(EXIT_FAILURE);
}
#endif
while (true) {
actVolume = getActVolume();
if (actVolume != lastVolume) {
sprintf(buff, "Vol: %3ld%%", actVolume);
#ifdef __arm__
putText(0, 0, buff);
drawHorizontalBargraph(24, 2, 75, 4, actVolume);
refreshDisplay();
#endif
tOut(buff);
lastVolume = actVolume;
}
if (isRefreshed()) {
tOut("_____________________\n");
for (int line = 0; line < LINE_NUM; line++) {
#ifdef __arm__
int filled = false;
#endif
for (tagtypes_t *t = layout[line]; *t != MAXTAG_TYPES; t++) {
if (tags[*t].valid) {
#ifdef __arm__
filled = true;
#endif
if (tags[*t].changed) {
strncpy(buff, tags[*t].tagData, maxCharacter());
#ifdef __arm__
putTextToCenter((line + 1) * 10, buff);
#endif
}
sprintf(stbl, "%s\n", tags[*t].tagData);
tOut(stbl);
break;
}
}
#ifdef __arm__
if(!filled) {
clearLine((line + 1) * 10);
}
#endif
}
pTime = tags[TIME].valid ? strtol(tags[TIME].tagData, NULL, 10) : 0;
dTime = tags[DURATION].valid ? strtol(tags[DURATION].tagData, NULL, 10) : 0;
#ifdef __arm__
sprintf(buff, "%ld:%02ld", pTime/60, pTime%60);
int tlen = strlen(buff);
clearLine(56);
putText(0, 56, buff);
sprintf(buff, "%ld:%02ld", dTime/60, dTime%60);
int dlen = strlen(buff);
putText(maxXPixel() - (dlen * CHAR_WIDTH), 56, buff);
sprintf(buff, "%s", tags[MODE].valid ? tags[MODE].tagData : "");
int mlen = strlen(buff);
putText(((maxXPixel() - ((tlen + mlen + dlen) * CHAR_WIDTH)) / 2) + (tlen * CHAR_WIDTH), 56, buff);
drawHorizontalBargraph(-1, 51, 0, 4, (pTime*100) / (dTime == 0 ? 1 : dTime));
#else
sprintf(buff, "%3ld:%02ld %5s %3ld:%02ld", pTime/60, pTime%60, tags[MODE].valid ? tags[MODE].tagData : "", dTime/60, dTime%60);
sprintf(stbl, "%s\n\n", buff);
tOut(stbl);
#endif
for(int i = 0; i < MAXTAG_TYPES; i++) {
tags[i].changed = false;
}
#ifdef __arm__
refreshDisplay();
#endif
askRefresh();
}
usleep(SLEEP_TIME);
}
#ifdef __arm__
closeDisplay();
#endif
closeSliminfo();
return 0;
}