summaryrefslogtreecommitdiff
path: root/apps/wps-display.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/wps-display.c')
-rw-r--r--apps/wps-display.c240
1 files changed, 131 insertions, 109 deletions
diff --git a/apps/wps-display.c b/apps/wps-display.c
index c360b7cf70..18a85cdc0f 100644
--- a/apps/wps-display.c
+++ b/apps/wps-display.c
@@ -46,9 +46,14 @@
46#include "ajf.h" 46#include "ajf.h"
47#endif 47#endif
48 48
49#define WPS_CONFIG ROCKBOX_DIR "/wps.config" 49#define WPS_CONFIG ROCKBOX_DIR "/default.wps"
50 50
51#ifdef HAVE_LCD_BITMAP
51#define MAX_LINES 10 52#define MAX_LINES 10
53#else
54#define MAX_LINES 2
55#endif
56
52#define FORMAT_BUFFER_SIZE 300 57#define FORMAT_BUFFER_SIZE 300
53 58
54struct format_flags 59struct format_flags
@@ -103,12 +108,19 @@ static void wps_format(char* fmt)
103 } 108 }
104} 109}
105 110
106static bool load_custom_wps(void) 111bool wps_load_custom(char* file)
107{ 112{
108 char buffer[FORMAT_BUFFER_SIZE]; 113 char buffer[FORMAT_BUFFER_SIZE];
109 int fd; 114 int fd;
115 bool special = true;
116
117 /* default wps file? */
118 if (!file) {
119 file = WPS_CONFIG;
120 special = false;
121 }
110 122
111 fd = open(WPS_CONFIG, O_RDONLY); 123 fd = open(file, O_RDONLY);
112 124
113 if (-1 != fd) 125 if (-1 != fd)
114 { 126 {
@@ -121,6 +133,17 @@ static bool load_custom_wps(void)
121 } 133 }
122 134
123 close(fd); 135 close(fd);
136
137 if ( special ) {
138 int i;
139 lcd_clear_display();
140 lcd_setmargins(0,0);
141 for (i=0; i<MAX_LINES && format_lines[i]; i++)
142 lcd_puts(0,i,format_lines[i]);
143 lcd_update();
144 sleep(HZ);
145 }
146
124 return numread > 0; 147 return numread > 0;
125 } 148 }
126 149
@@ -195,8 +218,11 @@ static char* get_dir(char* buf, int buf_size, char* path, int level)
195 * 218 *
196 * Returns the tag. NULL indicates the tag wasn't available. 219 * Returns the tag. NULL indicates the tag wasn't available.
197 */ 220 */
198static char* get_tag(struct mp3entry* id3, char* tag, char* buf, int buf_size, 221static char* get_tag(struct mp3entry* id3,
199 struct format_flags* flags) 222 char* tag,
223 char* buf,
224 int buf_size,
225 struct format_flags* flags)
200{ 226{
201 if ((0 == tag[0]) || (0 == tag[1])) 227 if ((0 == tag[0]) || (0 == tag[1]))
202 { 228 {
@@ -205,122 +231,122 @@ static char* get_tag(struct mp3entry* id3, char* tag, char* buf, int buf_size,
205 231
206 switch (tag[0]) 232 switch (tag[0])
207 { 233 {
208 case 'i': /* ID3 Information */ 234 case 'i': /* ID3 Information */
209 switch (tag[1]) 235 switch (tag[1])
210 { 236 {
211 case 't': /* ID3 Title */ 237 case 't': /* ID3 Title */
212 return id3->title; 238 return id3->title;
213 239
214 case 'a': /* ID3 Artist */ 240 case 'a': /* ID3 Artist */
215 return id3->artist; 241 return id3->artist;
216 242
217 case 'n': /* ID3 Track Number */ 243 case 'n': /* ID3 Track Number */
218 if (id3->tracknum) 244 if (id3->tracknum)
219 { 245 {
220 snprintf(buf, buf_size, "%d", id3->tracknum); 246 snprintf(buf, buf_size, "%d", id3->tracknum);
221 return buf; 247 return buf;
248 }
249 else
250 {
251 return NULL;
252 }
253
254 case 'd': /* ID3 Album/Disc */
255 return id3->album;
222 } 256 }
223 else 257 break;
224 {
225 return NULL;
226 }
227
228 case 'd': /* ID3 Album/Disc */
229 return id3->album;
230 }
231 break;
232
233 case 'f': /* File Information */
234 switch(tag[1])
235 {
236 case 'v': /* VBR file? */
237 return id3->vbr ? "(avg)" : NULL;
238
239 case 'b': /* File Bitrate */
240 snprintf(buf, buf_size, "%d", id3->bitrate);
241 return buf;
242
243 case 'f': /* File Frequency */
244 snprintf(buf, buf_size, "%d", id3->frequency);
245 return buf;
246
247 case 'p': /* File Path */
248 return id3->path;
249
250 case 'm': /* File Name - With Extension */
251 return get_dir(buf, buf_size, id3->path, 0);
252
253 case 'n': /* File Name */
254 if (get_dir(buf, buf_size, id3->path, 0))
255 {
256 /* Remove extension */
257 char* sep = strrchr(buf, '.');
258
259 if (NULL != sep)
260 {
261 *sep = 0;
262 }
263 258
264 return buf; 259 case 'f': /* File Information */
265 } 260 switch(tag[1])
266 else
267 { 261 {
268 return NULL; 262 case 'v': /* VBR file? */
263 return id3->vbr ? "(avg)" : NULL;
264
265 case 'b': /* File Bitrate */
266 snprintf(buf, buf_size, "%d", id3->bitrate);
267 return buf;
268
269 case 'f': /* File Frequency */
270 snprintf(buf, buf_size, "%d", id3->frequency);
271 return buf;
272
273 case 'p': /* File Path */
274 return id3->path;
275
276 case 'm': /* File Name - With Extension */
277 return get_dir(buf, buf_size, id3->path, 0);
278
279 case 'n': /* File Name */
280 if (get_dir(buf, buf_size, id3->path, 0))
281 {
282 /* Remove extension */
283 char* sep = strrchr(buf, '.');
284
285 if (NULL != sep)
286 {
287 *sep = 0;
288 }
289
290 return buf;
291 }
292 else
293 {
294 return NULL;
295 }
296
297 case 's': /* File Size (in kilobytes) */
298 snprintf(buf, buf_size, "%d", id3->filesize / 1024);
299 return buf;
269 } 300 }
301 break;
270 302
271 case 's': /* File Size (in kilobytes) */ 303 case 'p': /* Playlist/Song Information */
272 snprintf(buf, buf_size, "%d", id3->filesize / 1024); 304 switch(tag[1])
273 return buf; 305 {
274 }
275 break;
276
277 case 'p': /* Playlist/Song Information */
278 switch(tag[1])
279 {
280#if defined(HAVE_LCD_CHARCELLS) && !defined(SIMULATOR) 306#if defined(HAVE_LCD_CHARCELLS) && !defined(SIMULATOR)
281 case 'b': /* Player progress bar */ 307 case 'b': /* Player progress bar */
282 flags->player_progress = true; 308 flags->player_progress = true;
283 flags->dynamic = true; 309 flags->dynamic = true;
284 return "\x01"; 310 return "\x01";
285#endif 311#endif
286 312
287 case 'p': /* Playlist Position */ 313 case 'p': /* Playlist Position */
288 snprintf(buf, buf_size, "%d", id3->index + 1); 314 snprintf(buf, buf_size, "%d", id3->index + 1);
289 return buf; 315 return buf;
290 316
291 case 'e': /* Playlist Total Entries */ 317 case 'e': /* Playlist Total Entries */
292 snprintf(buf, buf_size, "%d", playlist.amount); 318 snprintf(buf, buf_size, "%d", playlist.amount);
293 return buf; 319 return buf;
294 320
295 case 'c': /* Current Time in Song */ 321 case 'c': /* Current Time in Song */
296 flags->dynamic = true; 322 flags->dynamic = true;
297 format_time(buf, buf_size, id3->elapsed + ff_rewind_count); 323 format_time(buf, buf_size, id3->elapsed + ff_rewind_count);
298 return buf; 324 return buf;
299 325
300 case 'r': /* Remaining Time in Song */ 326 case 'r': /* Remaining Time in Song */
301 flags->dynamic = true; 327 flags->dynamic = true;
302 format_time(buf, buf_size, id3->length - id3->elapsed + ff_rewind_count); 328 format_time(buf, buf_size, id3->length - id3->elapsed + ff_rewind_count);
303 return buf; 329 return buf;
304 330
305 case 't': /* Total Time */ 331 case 't': /* Total Time */
306 format_time(buf, buf_size, id3->length); 332 format_time(buf, buf_size, id3->length);
307 return buf; 333 return buf;
308 } 334 }
309 break; 335 break;
310 336
311 case 'd': /* Directory path information */ 337 case 'd': /* Directory path information */
312 switch(tag[1]) 338 switch(tag[1])
313 { 339 {
314 case '1': /* Parent folder */ 340 case '1': /* Parent folder */
315 return get_dir(buf, buf_size, id3->path, 1); 341 return get_dir(buf, buf_size, id3->path, 1);
316 342
317 case '2': /* Parent of parent */ 343 case '2': /* Parent of parent */
318 return get_dir(buf, buf_size, id3->path, 2); 344 return get_dir(buf, buf_size, id3->path, 2);
319 345
320 case '3': /* Parent of parent of parent */ 346 case '3': /* Parent of parent of parent */
321 return get_dir(buf, buf_size, id3->path, 3); 347 return get_dir(buf, buf_size, id3->path, 3);
322 } 348 }
323 break; 349 break;
324 } 350 }
325 351
326 return NULL; 352 return NULL;
@@ -507,11 +533,7 @@ bool wps_refresh(struct mp3entry* id3, int ffwd_offset, bool refresh_all)
507 533
508 ff_rewind_count = ffwd_offset; 534 ff_rewind_count = ffwd_offset;
509 535
510#ifdef HAVE_LCD_CHARCELL
511 for (i = 0; i < 2; i++)
512#else
513 for (i = 0; i < MAX_LINES; i++) 536 for (i = 0; i < MAX_LINES; i++)
514#endif
515 { 537 {
516 if ( !format_lines[i] ) 538 if ( !format_lines[i] )
517 break; 539 break;
@@ -586,7 +608,7 @@ void wps_display(struct mp3entry* id3)
586 static bool wps_loaded = false; 608 static bool wps_loaded = false;
587 609
588 if (!wps_loaded) { 610 if (!wps_loaded) {
589 load_custom_wps(); 611 wps_load_custom(NULL);
590 wps_loaded = true; 612 wps_loaded = true;
591 613
592 if ( !format_buffer[0] ) { 614 if ( !format_buffer[0] ) {