diff options
Diffstat (limited to 'apps/wps-display.c')
-rw-r--r-- | apps/wps-display.c | 72 |
1 files changed, 34 insertions, 38 deletions
diff --git a/apps/wps-display.c b/apps/wps-display.c index 6bca8cb40d..b70c1359d1 100644 --- a/apps/wps-display.c +++ b/apps/wps-display.c | |||
@@ -55,17 +55,10 @@ | |||
55 | #endif | 55 | #endif |
56 | 56 | ||
57 | #define FORMAT_BUFFER_SIZE 300 | 57 | #define FORMAT_BUFFER_SIZE 300 |
58 | struct format_flags | ||
59 | { | ||
60 | bool dynamic; | ||
61 | bool scroll; | ||
62 | bool player_progress; | ||
63 | bool peak_meter; | ||
64 | }; | ||
65 | 58 | ||
66 | static char format_buffer[FORMAT_BUFFER_SIZE]; | 59 | static char format_buffer[FORMAT_BUFFER_SIZE]; |
67 | static char* format_lines[MAX_LINES]; | 60 | static char* format_lines[MAX_LINES]; |
68 | static bool dynamic_lines[MAX_LINES]; | 61 | static unsigned char line_type[MAX_LINES]; |
69 | static int ff_rewind_count; | 62 | static int ff_rewind_count; |
70 | bool wps_time_countup = true; | 63 | bool wps_time_countup = true; |
71 | static bool wps_loaded = false; | 64 | static bool wps_loaded = false; |
@@ -218,9 +211,7 @@ static char* get_dir(char* buf, int buf_size, char* path, int level) | |||
218 | * buf - buffer to certain tags, such as track number, play time or | 211 | * buf - buffer to certain tags, such as track number, play time or |
219 | * directory name. | 212 | * directory name. |
220 | * buf_size - size of buffer. | 213 | * buf_size - size of buffer. |
221 | * flags - flags in this struct will be set depending on the tag: | 214 | * flags - returns the type of the line. See constants i wps-display.h |
222 | * dynamic - if the tag data changes over time (like play time); | ||
223 | * player_progress - set if the tag is %pb. | ||
224 | * | 215 | * |
225 | * Returns the tag. NULL indicates the tag wasn't available. | 216 | * Returns the tag. NULL indicates the tag wasn't available. |
226 | */ | 217 | */ |
@@ -228,7 +219,7 @@ static char* get_tag(struct mp3entry* id3, | |||
228 | char* tag, | 219 | char* tag, |
229 | char* buf, | 220 | char* buf, |
230 | int buf_size, | 221 | int buf_size, |
231 | struct format_flags* flags) | 222 | unsigned char* flags) |
232 | { | 223 | { |
233 | if ((0 == tag[0]) || (0 == tag[1])) | 224 | if ((0 == tag[0]) || (0 == tag[1])) |
234 | { | 225 | { |
@@ -238,6 +229,7 @@ static char* get_tag(struct mp3entry* id3, | |||
238 | switch (tag[0]) | 229 | switch (tag[0]) |
239 | { | 230 | { |
240 | case 'i': /* ID3 Information */ | 231 | case 'i': /* ID3 Information */ |
232 | *flags |= WPS_REFRESH_STATIC; | ||
241 | switch (tag[1]) | 233 | switch (tag[1]) |
242 | { | 234 | { |
243 | case 't': /* ID3 Title */ | 235 | case 't': /* ID3 Title */ |
@@ -263,6 +255,7 @@ static char* get_tag(struct mp3entry* id3, | |||
263 | break; | 255 | break; |
264 | 256 | ||
265 | case 'f': /* File Information */ | 257 | case 'f': /* File Information */ |
258 | *flags |= WPS_REFRESH_STATIC; | ||
266 | switch(tag[1]) | 259 | switch(tag[1]) |
267 | { | 260 | { |
268 | case 'v': /* VBR file? */ | 261 | case 'v': /* VBR file? */ |
@@ -310,40 +303,42 @@ static char* get_tag(struct mp3entry* id3, | |||
310 | switch(tag[1]) | 303 | switch(tag[1]) |
311 | { | 304 | { |
312 | case 'b': /* progress bar */ | 305 | case 'b': /* progress bar */ |
313 | flags->player_progress = true; | 306 | *flags |= WPS_REFRESH_PLAYER_PROGRESS; |
314 | flags->dynamic = true; | ||
315 | return "\x01"; | 307 | return "\x01"; |
316 | 308 | ||
317 | case 'p': /* Playlist Position */ | 309 | case 'p': /* Playlist Position */ |
310 | *flags |= WPS_REFRESH_STATIC; | ||
318 | snprintf(buf, buf_size, "%d", id3->index + 1); | 311 | snprintf(buf, buf_size, "%d", id3->index + 1); |
319 | return buf; | 312 | return buf; |
320 | 313 | ||
321 | case 'n': /* Playlist Name (without path) */ | 314 | case 'n': /* Playlist Name (without path) */ |
315 | *flags |= WPS_REFRESH_STATIC; | ||
322 | return playlist_name(buf, buf_size); | 316 | return playlist_name(buf, buf_size); |
323 | 317 | ||
324 | case 'e': /* Playlist Total Entries */ | 318 | case 'e': /* Playlist Total Entries */ |
319 | *flags |= WPS_REFRESH_STATIC; | ||
325 | snprintf(buf, buf_size, "%d", playlist_amount()); | 320 | snprintf(buf, buf_size, "%d", playlist_amount()); |
326 | return buf; | 321 | return buf; |
327 | 322 | ||
328 | case 'c': /* Current Time in Song */ | 323 | case 'c': /* Current Time in Song */ |
329 | flags->dynamic = true; | 324 | *flags |= WPS_REFRESH_DYNAMIC; |
330 | format_time(buf, buf_size, id3->elapsed + ff_rewind_count); | 325 | format_time(buf, buf_size, id3->elapsed + ff_rewind_count); |
331 | return buf; | 326 | return buf; |
332 | 327 | ||
333 | case 'r': /* Remaining Time in Song */ | 328 | case 'r': /* Remaining Time in Song */ |
334 | flags->dynamic = true; | 329 | *flags |= WPS_REFRESH_DYNAMIC; |
335 | format_time(buf, buf_size, | 330 | format_time(buf, buf_size, |
336 | id3->length - id3->elapsed - ff_rewind_count); | 331 | id3->length - id3->elapsed - ff_rewind_count); |
337 | return buf; | 332 | return buf; |
338 | 333 | ||
339 | case 't': /* Total Time */ | 334 | case 't': /* Total Time */ |
335 | *flags |= WPS_REFRESH_STATIC; | ||
340 | format_time(buf, buf_size, id3->length); | 336 | format_time(buf, buf_size, id3->length); |
341 | return buf; | 337 | return buf; |
342 | 338 | ||
343 | #ifdef HAVE_LCD_BITMAP | 339 | #ifdef HAVE_LCD_BITMAP |
344 | case 'm': /* Peak Meter */ | 340 | case 'm': /* Peak Meter */ |
345 | flags->peak_meter = true; | 341 | *flags |= WPS_REFRESH_PEAK_METER; |
346 | flags->dynamic = true; | ||
347 | return "\x01"; | 342 | return "\x01"; |
348 | #endif | 343 | #endif |
349 | } | 344 | } |
@@ -351,6 +346,7 @@ static char* get_tag(struct mp3entry* id3, | |||
351 | 346 | ||
352 | case 'd': /* Directory path information */ | 347 | case 'd': /* Directory path information */ |
353 | { | 348 | { |
349 | *flags |= WPS_REFRESH_STATIC; | ||
354 | int level = tag[1] - '0'; | 350 | int level = tag[1] - '0'; |
355 | /* d1 through d9 */ | 351 | /* d1 through d9 */ |
356 | if ((0 < level) && (9 > level)) | 352 | if ((0 < level) && (9 > level)) |
@@ -437,16 +433,13 @@ static char* skip_conditional(char* fmt, bool to_else) | |||
437 | * buf_size - the size of buffer. | 433 | * buf_size - the size of buffer. |
438 | * id3 - the ID3 data to format with. | 434 | * id3 - the ID3 data to format with. |
439 | * fmt - format description. | 435 | * fmt - format description. |
440 | * flags - flags in this struct will be set depending on the tag: | 436 | * flags - returns the type of the line. See constants i wps-display.h |
441 | * dynamic - if the tag data changes over time (like play time); | ||
442 | * player_progress - set if the tag is %pb. | ||
443 | * scroll - if line scrolling is requested. | ||
444 | */ | 437 | */ |
445 | static void format_display(char* buf, | 438 | static void format_display(char* buf, |
446 | int buf_size, | 439 | int buf_size, |
447 | struct mp3entry* id3, | 440 | struct mp3entry* id3, |
448 | char* fmt, | 441 | char* fmt, |
449 | struct format_flags* flags) | 442 | unsigned char* flags) |
450 | { | 443 | { |
451 | char temp_buf[128]; | 444 | char temp_buf[128]; |
452 | char* buf_end = buf + buf_size - 1; /* Leave room for end null */ | 445 | char* buf_end = buf + buf_size - 1; /* Leave room for end null */ |
@@ -483,7 +476,7 @@ static void format_display(char* buf, | |||
483 | break; | 476 | break; |
484 | 477 | ||
485 | case 's': | 478 | case 's': |
486 | flags->scroll = true; | 479 | *flags |= WPS_REFRESH_SCROLL; |
487 | ++fmt; | 480 | ++fmt; |
488 | break; | 481 | break; |
489 | 482 | ||
@@ -526,10 +519,10 @@ static void format_display(char* buf, | |||
526 | *buf = 0; | 519 | *buf = 0; |
527 | } | 520 | } |
528 | 521 | ||
529 | bool wps_refresh(struct mp3entry* id3, int ffwd_offset, bool refresh_all) | 522 | bool wps_refresh(struct mp3entry* id3, int ffwd_offset, unsigned char refresh_mode) |
530 | { | 523 | { |
531 | char buf[MAX_PATH]; | 524 | char buf[MAX_PATH]; |
532 | struct format_flags flags; | 525 | unsigned char flags; |
533 | int i; | 526 | int i; |
534 | #ifdef HAVE_LCD_BITMAP | 527 | #ifdef HAVE_LCD_BITMAP |
535 | /* to find out wether the peak meter is enabled we | 528 | /* to find out wether the peak meter is enabled we |
@@ -554,16 +547,15 @@ bool wps_refresh(struct mp3entry* id3, int ffwd_offset, bool refresh_all) | |||
554 | if ( !format_lines[i] ) | 547 | if ( !format_lines[i] ) |
555 | break; | 548 | break; |
556 | 549 | ||
557 | if (dynamic_lines[i] || refresh_all) | 550 | if ((line_type[i] & refresh_mode) || |
551 | (refresh_mode == WPS_REFRESH_ALL)) | ||
558 | { | 552 | { |
559 | flags.dynamic = false; | 553 | flags = 0; |
560 | flags.scroll = false; | ||
561 | flags.player_progress = false; | ||
562 | flags.peak_meter = false; | ||
563 | format_display(buf, sizeof(buf), id3, format_lines[i], &flags); | 554 | format_display(buf, sizeof(buf), id3, format_lines[i], &flags); |
564 | dynamic_lines[i] = flags.dynamic; | 555 | line_type[i] = flags; |
565 | 556 | ||
566 | if (flags.player_progress) { | 557 | /* progress */ |
558 | if (flags & refresh_mode & WPS_REFRESH_PLAYER_PROGRESS) { | ||
567 | #ifdef HAVE_LCD_CHARCELLS | 559 | #ifdef HAVE_LCD_CHARCELLS |
568 | draw_player_progress(id3, ff_rewind_count); | 560 | draw_player_progress(id3, ff_rewind_count); |
569 | #else | 561 | #else |
@@ -578,11 +570,12 @@ bool wps_refresh(struct mp3entry* id3, int ffwd_offset, bool refresh_all) | |||
578 | } | 570 | } |
579 | 571 | ||
580 | #ifdef HAVE_LCD_BITMAP | 572 | #ifdef HAVE_LCD_BITMAP |
581 | if (flags.peak_meter) { | 573 | /* peak meter */ |
574 | if (flags & refresh_mode & WPS_REFRESH_PEAK_METER) { | ||
582 | int peak_meter_y; | 575 | int peak_meter_y; |
583 | int w,h; | 576 | struct font *fnt = font_get(FONT_UI); |
577 | int h = fnt->height; | ||
584 | int offset = global_settings.statusbar ? STATUSBAR_HEIGHT : 0; | 578 | int offset = global_settings.statusbar ? STATUSBAR_HEIGHT : 0; |
585 | lcd_getstringsize("M",&w,&h); | ||
586 | 579 | ||
587 | peak_meter_y = i * h + offset; | 580 | peak_meter_y = i * h + offset; |
588 | 581 | ||
@@ -601,10 +594,13 @@ bool wps_refresh(struct mp3entry* id3, int ffwd_offset, bool refresh_all) | |||
601 | } | 594 | } |
602 | #endif | 595 | #endif |
603 | 596 | ||
604 | if (flags.scroll && !flags.dynamic) | 597 | /* static line */ |
598 | if (flags & WPS_REFRESH_SCROLL) | ||
605 | { | 599 | { |
600 | if (refresh_mode & WPS_REFRESH_SCROLL) { | ||
606 | lcd_puts_scroll(0, i, buf); | 601 | lcd_puts_scroll(0, i, buf); |
607 | } | 602 | } |
603 | } | ||
608 | else | 604 | else |
609 | { | 605 | { |
610 | lcd_puts(0, i, buf); | 606 | lcd_puts(0, i, buf); |
@@ -656,7 +652,7 @@ bool wps_display(struct mp3entry* id3) | |||
656 | } | 652 | } |
657 | } | 653 | } |
658 | } | 654 | } |
659 | wps_refresh(id3, 0, true); | 655 | wps_refresh(id3, 0, WPS_REFRESH_ALL); |
660 | status_draw(); | 656 | status_draw(); |
661 | lcd_update(); | 657 | lcd_update(); |
662 | return false; | 658 | return false; |