Update to the Custom WPS. Now actually works, can be fed any string, uses %xx instead of just %x, and more! It's #define'd out in settings.h - Needs to be enabled to use it. PLAYER ONLY

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1963 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Justin Heiner 2002-08-24 06:57:24 +00:00
parent 11f2c3c225
commit 5301881adc
4 changed files with 167 additions and 101 deletions

View file

@ -23,6 +23,9 @@
#include <stdbool.h> #include <stdbool.h>
#include "file.h" #include "file.h"
/* Custom WPS Parsing - Uncomment to enable - PLAYER ONLY */
/* #define CUSTOM_WPS */
/* data structures */ /* data structures */
#define RESUME_OFF 0 #define RESUME_OFF 0
@ -63,6 +66,10 @@ struct user_settings
bool sort_case; /* dir sort order: 0=case insensitive, 1=sensitive */ bool sort_case; /* dir sort order: 0=case insensitive, 1=sensitive */
int scroll_speed; /* long texts scrolling speed: 1-20 */ int scroll_speed; /* long texts scrolling speed: 1-20 */
bool playlist_shuffle; bool playlist_shuffle;
#ifdef CUSTOM_WPS
char custom_wps[64]; /* custom WPS string */
bool wps_changed; /* to reload Custom WPS if changed to it */
#endif
/* while playing screen settings */ /* while playing screen settings */
int wps_display; /* 0=id3, 1=file, 2=parse */ int wps_display; /* 0=id3, 1=file, 2=parse */

View file

@ -103,6 +103,7 @@ static Menu wps_set(void)
char* names[] = { "1 Line ID3", "2 Line ID3", "File ", char* names[] = { "1 Line ID3", "2 Line ID3", "File ",
"Parse ", "Custom WPS " }; "Parse ", "Custom WPS " };
set_option("[WPS display]", &global_settings.wps_display, names, 5 ); set_option("[WPS display]", &global_settings.wps_display, names, 5 );
global_settings.wps_changed = true;
#else #else
char* names[] = { "1 Line ID3", "2 Line ID3", "File ", char* names[] = { "1 Line ID3", "2 Line ID3", "File ",
"Parse " }; "Parse " };

View file

@ -90,6 +90,13 @@ static void draw_screen(struct mp3entry* id3)
} }
else else
{ {
#ifdef CUSTOM_WPS
if(global_settings.wps_changed) {
if(global_settings.wps_display == PLAY_DISPLAY_CUSTOM_WPS)
load_custom_wps();
global_settings.wps_changed = false;
}
#endif
switch ( global_settings.wps_display ) { switch ( global_settings.wps_display ) {
case PLAY_DISPLAY_TRACK_TITLE: case PLAY_DISPLAY_TRACK_TITLE:
{ {
@ -123,6 +130,9 @@ static void draw_screen(struct mp3entry* id3)
} }
case PLAY_DISPLAY_FILENAME_SCROLL: case PLAY_DISPLAY_FILENAME_SCROLL:
{ {
#ifdef CUSTOM_WPS
display_custom_wps(0, 0, true, "%pp/%pe: %fn");
#else
char buffer[64]; char buffer[64];
char ch = '/'; char ch = '/';
char* szLast = strrchr(id3->path, ch); char* szLast = strrchr(id3->path, ch);
@ -142,6 +152,7 @@ static void draw_screen(struct mp3entry* id3)
id3->path); id3->path);
} }
lcd_puts_scroll(0, 0, buffer); lcd_puts_scroll(0, 0, buffer);
#endif
break; break;
} }
case PLAY_DISPLAY_2LINEID3: case PLAY_DISPLAY_2LINEID3:
@ -177,15 +188,23 @@ static void draw_screen(struct mp3entry* id3)
lcd_puts(0, l++, buffer); lcd_puts(0, l++, buffer);
} }
#else
#ifdef CUSTOM_WPS
display_custom_wps(0, l++, false, "%ia");
display_custom_wps(0, l++, true, "%it");
#else #else
lcd_puts(0, l++, id3->artist?id3->artist:"<no artist>"); lcd_puts(0, l++, id3->artist?id3->artist:"<no artist>");
lcd_puts_scroll(0, l++, id3->title?id3->title:"<no title>"); lcd_puts_scroll(0, l++, id3->title?id3->title:"<no title>");
#endif
#endif #endif
break; break;
} }
#ifdef HAVE_LCD_CHARCELLS #ifdef HAVE_LCD_CHARCELLS
case PLAY_DISPLAY_1LINEID3: case PLAY_DISPLAY_1LINEID3:
{ {
#ifdef CUSTOM_WPS
display_custom_wps(0, 0, true, "%pp/%pe: %fc");
#else
char buffer[64]; char buffer[64];
char ch = '/'; char ch = '/';
char* szLast = strrchr(id3->path, ch); char* szLast = strrchr(id3->path, ch);
@ -200,12 +219,17 @@ static void draw_screen(struct mp3entry* id3)
id3->index + 1, playlist.amount, id3->index + 1, playlist.amount,
szLast?++szLast:id3->path); szLast?++szLast:id3->path);
lcd_puts_scroll(0, 0, buffer); lcd_puts_scroll(0, 0, buffer);
#endif
break; break;
} }
#ifdef CUSTOM_WPS #ifdef CUSTOM_WPS
case PLAY_DISPLAY_CUSTOM_WPS: case PLAY_DISPLAY_CUSTOM_WPS:
{ {
wps_load_custom_config(); if(global_settings.custom_wps[0] == 0)
snprintf(global_settings.custom_wps, sizeof(global_settings.custom_wps),
"Couldn't Load Custom WPS");
display_custom_wps(0, 0, true, global_settings.custom_wps);
break;
} }
#endif #endif
#endif #endif
@ -216,14 +240,31 @@ static void draw_screen(struct mp3entry* id3)
} }
#ifdef CUSTOM_WPS #ifdef CUSTOM_WPS
int wps_load_custom_config(void) bool load_custom_wps(void)
{
int fd;
fd = open("/wps.config", O_RDONLY);
if(-1 == fd)
{
global_settings.custom_wps[0] = 0;
close(fd);
return(false);
}
read(fd, global_settings.custom_wps, sizeof(global_settings.custom_wps));
close(fd);
return(true);
}
bool display_custom_wps(int x_val, int y_val, bool do_scroll, char *wps_string)
{ {
char buffer[128]; char buffer[128];
char tmpbuf[64]; char tmpbuf[64];
char cchr1[0] = ""; char cchr1;
char cchr2[0] = ""; char cchr2;
int i; char cchr3;
int fd; unsigned int seek;
struct mp3entry* id3 = NULL; struct mp3entry* id3 = NULL;
char* szLast; char* szLast;
@ -233,116 +274,128 @@ int wps_load_custom_config(void)
/* point to the first letter in the file name */ /* point to the first letter in the file name */
szLast++; szLast++;
buffer[0]=0; buffer[0] = 0;
lcd_stop_scroll();
fd = open("/wps.config", O_RDONLY); seek = -1;
if(-1 == fd)
{
lcd_puts(0, 0, " *Error* ");
sleep(HZ);
lcd_puts_scroll(0, 1, "--Couldn't Load wps.config--");
sleep(HZ*5);
global_settings.wps_display = 0;
settings_save();
draw_screen(id3);
return(-1);
}
while(1) while(1)
{ {
i = read(fd, cchr1, 1); seek++;
if(i <= 0) cchr1 = wps_string[seek];
{ tmpbuf[0] = 0;
close(fd); switch(cchr1)
lcd_puts_scroll(0, 0, buffer);
return(1);
}
switch(cchr1[0])
{ {
case '%': case '%':
i = read(fd, cchr2, 1); seek++;
if(i <= 0) cchr2 = wps_string[seek];
switch(cchr2)
{ {
close(fd); case 'i': /* ID3 Information */
lcd_puts_scroll(0, 0, buffer); seek++;
return(1); cchr3 = wps_string[seek];
} switch(cchr3)
switch(cchr2[0]) {
{ case 't': /* ID3 Title */
case 't': /* ID3 Title */ snprintf(tmpbuf, sizeof(tmpbuf), "%s",
snprintf(tmpbuf, sizeof(tmpbuf), "%s", id3->title); id3->title?id3->title:"<no title>");
break;
case 'a': /* ID3 Artist */
snprintf(tmpbuf, sizeof(tmpbuf), "%s",
id3->artist?id3->artist:"<no artist>");
break;
case 'n': /* ID3 Track Number */
snprintf(tmpbuf, sizeof(tmpbuf), "%d", id3->tracknum);
break;
case 'd': /* ID3 Album/Disc */
snprintf(tmpbuf, sizeof(tmpbuf), "%s", id3->album);
break;
}
break; break;
case 'a': /* ID3 Artist */ case 'f': /* File Information */
snprintf(tmpbuf, sizeof(tmpbuf), "%s", id3->artist); seek++;
cchr3 = wps_string[seek];
switch(cchr3)
{
case 'c': /* Conditional Filename \ ID3 Artist-Title */
if(id3->artist && id3->title)
snprintf(tmpbuf, sizeof(tmpbuf), "%s - %s",
id3->artist?id3->artist:"<no artist>",
id3->title?id3->title:"<no title>");
else
snprintf(tmpbuf, sizeof(tmpbuf), "%s",
szLast?szLast:id3->path);
break;
case 'd': /* Conditional Filename \ ID3 Title-Artist */
if(id3->artist && id3->title)
snprintf(tmpbuf, sizeof(tmpbuf), "%s - %s",
id3->title?id3->title:"<no title>",
id3->artist?id3->artist:"<no artist>");
else
snprintf(tmpbuf, sizeof(tmpbuf), "%s",
szLast?szLast:id3->path);
break;
case 'b': /* File Bitrate */
snprintf(tmpbuf, sizeof(tmpbuf), "%d", id3->bitrate);
break;
case 'f': /* File Frequency */
snprintf(tmpbuf, sizeof(tmpbuf), "%d", id3->frequency);
break;
case 'p': /* File Path */
snprintf(tmpbuf, sizeof(tmpbuf), "%s", id3->path);
break;
case 'n': /* File Name */
snprintf(tmpbuf, sizeof(tmpbuf), "%s",
szLast?szLast:id3->path);
break;
case 's': /* File Size (In Kilobytes) */
snprintf(tmpbuf, sizeof(tmpbuf), "%d",
id3->filesize / 1024);
break;
}
break; break;
case 'n': /* ID3 Track Number */ case 'p': /* Playlist/Song Information */
snprintf(tmpbuf, sizeof(tmpbuf), "%d", id3->tracknum); seek++;
break; cchr3 = wps_string[seek];
case 'u': /* ID3 Album */ switch(cchr3)
snprintf(tmpbuf, sizeof(tmpbuf), "%s", id3->album); {
break; case 'p': /* Playlist Position */
case 'c': /* Conditional Filename \ ID3 Artist-Title */ snprintf(tmpbuf, sizeof(tmpbuf), "%d", id3->index + 1);
if(id3->artist && id3->title) break;
snprintf(tmpbuf, sizeof(tmpbuf), "%s - %s", case 'e': /* Playlist Total Entries */
id3->artist?id3->artist:"<no artist>", snprintf(tmpbuf, sizeof(tmpbuf), "%d", playlist.amount);
id3->title?id3->title:"<no title>"); break;
else case 'c': /* Current Time in Song */
snprintf(tmpbuf, sizeof(tmpbuf), "%s", snprintf(tmpbuf, sizeof(tmpbuf), "%d:%02d",
szLast?szLast:id3->path); id3->elapsed / 60000,
break; id3->elapsed % 60000 / 1000);
case 'h': /* Conditional Filename \ ID3 Title-Artist */ break;
if(id3->artist && id3->title) case 't': /* Total Time */
snprintf(tmpbuf, sizeof(tmpbuf), "%s - %s", snprintf(tmpbuf, sizeof(tmpbuf), "%d:%02d",
id3->title?id3->title:"<no title>", id3->elapsed / 60000,
id3->artist?id3->artist:"<no artist>"); id3->elapsed % 60000 / 1000);
else break;
snprintf(tmpbuf, sizeof(tmpbuf), "%s", }
szLast?szLast:id3->path);
break;
case 'b': /* File Bitrate */
snprintf(tmpbuf, sizeof(tmpbuf), "%d", id3->bitrate);
break;
case 'f': /* File Frequency */
snprintf(tmpbuf, sizeof(tmpbuf), "%d", id3->frequency);
break;
case 'p': /* File Path */
snprintf(tmpbuf, sizeof(tmpbuf), "%s", id3->path);
break;
case 'm': /* File Name */
snprintf(tmpbuf, sizeof(tmpbuf), "%s",
szLast?szLast:id3->path);
break;
case 's': /* File Size (In Kilobytes) */
snprintf(tmpbuf, sizeof(tmpbuf), "%d",
id3->filesize / 1024);
break;
case 'i': /* Playlist Position */
snprintf(tmpbuf, sizeof(tmpbuf), "%d", id3->index + 1);
break;
case 'l': /* Playlist Total Entries */
snprintf(tmpbuf, sizeof(tmpbuf), "%d", playlist.amount);
break;
case 'e': /* Elapsed Time */
snprintf(tmpbuf, sizeof(tmpbuf), "%d:%02d",
id3->elapsed / 60000,
id3->elapsed % 60000 / 1000);
break;
case 'o': /* Total Time */
snprintf(tmpbuf, sizeof(tmpbuf), "%d:%02d",
id3->elapsed / 60000,
id3->elapsed % 60000 / 1000);
break; break;
case '%': /* Displays % */ case '%': /* Displays % */
snprintf(tmpbuf, sizeof(tmpbuf), "%%"); snprintf(tmpbuf, sizeof(tmpbuf), "%%");
break; break;
} }
snprintf(buffer, sizeof(buffer), "%s%s", buffer, tmpbuf);
break; break;
default: default:
snprintf(tmpbuf, sizeof(tmpbuf), "%s", cchr1); snprintf(buffer, sizeof(buffer), "%s%c", buffer, cchr1);
break; break;
} }
snprintf(buffer, sizeof(buffer), "%s%s", buffer, tmpbuf); if(seek >= strlen(wps_string))
{
lcd_stop_scroll();
if(do_scroll)
lcd_puts_scroll(x_val, y_val, buffer);
else
lcd_puts(x_val, y_val, buffer);
return(true);
}
} }
return(true);
} }
#endif #endif
@ -607,6 +660,10 @@ int wps_show(void)
ff_rewind = false; ff_rewind = false;
#ifdef CUSTOM_WPS
load_custom_wps(); /* Load the Custom WPS file, if there is one */
#endif
if(mpeg_is_playing()) if(mpeg_is_playing())
{ {
id3 = mpeg_current_track(); id3 = mpeg_current_track();

View file

@ -28,7 +28,8 @@ extern bool keys_locked;
int wps_show(void); int wps_show(void);
#ifdef CUSTOM_WPS #ifdef CUSTOM_WPS
int wps_load_custom_config(void); bool load_custom_wps(void);
bool display_custom_wps(int x_val, int y_val, bool do_scroll, char *wps_string);
#endif #endif
#endif #endif