Rockbox.org home
release
dev builds
extras
themes manual
wiki
device status forums
mailing lists
IRC bugs
patches
dev guide



Rockbox mail archive

Subject: [PATCH] WPS tweak
From: Brian King (brking_at_charter.net)
Date: 2002-08-06


Here is a small WPS patch. It takes the excellent patch Magnus submitted
and adds a couple tweaks.

If id3 mode is selected and no id3 tag is found, it falls back to
parsing the path.

The path can be either .../Artist/Album/Title.mp3 or /Artist/Title.mp3

When parsing the path, all '_' chars are replaced with spaces.

I often have filenames that look like: 01-track.mp3 or "01 track.mp3" so
I strip off any leading track number to display the track name.

The mods to the path parsing code should affect all display modes.

Works great on my Jukebox, should also work fine on a Recorder...

The patch is against the current CVS.

-bk

-- 
Some days it's just not worth chewing through the restraints...

Index: settings_menu.c
===================================================================
RCS file: /cvsroot/rockbox/apps/settings_menu.c,v
retrieving revision 1.8
diff -u -r1.8 settings_menu.c
--- settings_menu.c 2 Aug 2002 13:20:03 -0000 1.8
+++ settings_menu.c 6 Aug 2002 01:14:32 -0000
@@ -63,8 +63,8 @@
 
 static void wps_set(void)
 {
- char* names[] = { "Id3 ", "File ", "Parse" };
- set_option("[WPS display]", &global_settings.wps_display, names, 3 );
+ char* names[] = { "Id3 ", "File ", "Parse ", "Verbose" };
+ set_option("[WPS display]", &global_settings.wps_display, names, 4 );
 }
 
 void settings_menu(void)
Index: wps.c
===================================================================
RCS file: /cvsroot/rockbox/apps/wps.c,v
retrieving revision 1.45
diff -u -r1.45 wps.c
--- wps.c 1 Aug 2002 13:29:59 -0000 1.45
+++ wps.c 6 Aug 2002 01:14:34 -0000
@@ -40,6 +40,10 @@
 #define PLAY_DISPLAY_DEFAULT 0
 #define PLAY_DISPLAY_FILENAME_SCROLL 1
 #define PLAY_DISPLAY_TRACK_TITLE 2
+#define PLAY_DISPLAY_COMPACT_VERBOSE 3
+
+#define BUTTON_POLL_FREQUENCY 10 /* Number of ticks between each button poll */
+#define BUTTON_POLLS_PER_UPDATE 2 /* Number of polls between display update */
 
 #ifdef HAVE_RECORDER_KEYPAD
 #define RELEASE_MASK (BUTTON_F1 | BUTTON_DOWN)
@@ -47,8 +51,104 @@
 #define RELEASE_MASK (BUTTON_MENU | BUTTON_STOP)
 #endif
 
+/* Tokenize a string from the end. An empty string contains no tokens.
+ *
+ * buffer - pointer to buffer to parse. Always pass it unchanged.
+ * separator - chars that limits a token.
+ * end - tracks current scan position; initialize to NULL before the
+ * first call.
+ * returns the current token, or NULL if there are no more tokens.
+ */
+static char* strrtok_r(char* buffer, char* separator, char** end)
+{
+ if (*end == NULL)
+ {
+ /* First call, init to last char */
+ *end = buffer + strlen(buffer) - 1;
+ }
+
+ /* No more to search? */
+ if (*end < buffer)
+ {
+ return NULL;
+ }
+
+ /* Locate previous separator */
+ while ((*end > buffer) && !strchr(separator, **end))
+ {
+ --*end;
+ }
+
+ /* On a separator? */
+ if (strchr(separator, **end))
+ {
+ **end = 0; /* Terminate preceeding token */
+ }
+
+ --*end; /* Prepare for next round */
+ return *end + 2; /* Return char after sparator */
+}
+
+/* strncat and snprintf rolled into one, with a twist. The string in buffer
+ * will not be made longer than buffer_len.
+ */
+static int strfmt(char* buffer, int buffer_len, char* format, ...)
+{
+ int len;
+ va_list args;
+
+ va_start (args, format);
+ len = strlen(buffer);
+ len = vsnprintf(buffer + len, buffer_len - len, format, args);
+ va_end (args);
+
+ return len;
+}
+
+/* Assume path format of: .../Artist/Album/Title.mp3 or /Artist/Title.mp3 */
+static void id3_from_path(char* path, char** artist, char** album, char** title)
+{
+ char* end = NULL;
+ char* space = NULL;
+
+ *title = strrtok_r(path, "/", &end);
+ *album = strrtok_r(path, "/", &end);
+ *artist = strrtok_r(path, "/", &end);
+
+ if (*artist == NULL) *artist = *album;
+
+ if (*title != NULL)
+ {
+ /* Remove any .mp3 suffix */
+ int length = strlen(*title) - 4;
+
+ if ((length > 0) && !strcasecmp(*title + length, ".mp3"))
+ {
+ *(*title + length) = 0;
+ }
+
+ /* Remove any leading track number */
+ while((**title >= '0' && **title <= '9') || **title == ' ' || **title == '-')
+ (*title)++;
+
+ /* Replace '_' with ' ' */
+ for (space = *title; *space != '\0'; space++)
+ if (*space == '_') *space = ' ';
+ for (space = *album; space && *space != '\0'; space++)
+ if (*space == '_') *space = ' ';
+ for (space = *artist; space && *space != '\0'; space++)
+ if (*space == '_') *space = ' ';
+ }
+}
+
 static void draw_screen(struct mp3entry* id3)
 {
+ char* artist;
+ char* album;
+ char* title;
+ static char id3buffer[MAX_PATH];
+ static char buffer[MAX_PATH];
+
     lcd_clear_display();
     if(!id3)
     {
@@ -65,32 +165,13 @@
         switch ( global_settings.wps_display ) {
             case PLAY_DISPLAY_TRACK_TITLE:
             {
- char ch = '/';
- char* end;
- char* szTok;
- char* szDelimit;
- char* szPeriod;
- char szArtist[26];
- char szBuff[257];
- szBuff[sizeof(szBuff)-1] = 0;
-
- strncpy(szBuff, id3->path, sizeof(szBuff));
-
- szTok = strtok_r(szBuff, "/", &end);
- szTok = strtok_r(NULL, "/", &end);
-
- // Assume path format of: Genre/Artist/Album/Mp3_file
- strncpy(szArtist,szTok,sizeof(szArtist));
- szArtist[sizeof(szArtist)-1] = 0;
- szDelimit = strrchr(id3->path, ch);
- lcd_puts(0,0, szArtist?szArtist:"<nothing>");
-
- // removes the .mp3 from the end of the display buffer
- szPeriod = strrchr(szDelimit, '.');
- if (szPeriod != NULL)
- *szPeriod = 0;
+ strncpy(id3buffer, id3->path, sizeof(id3buffer));
+ id3buffer[sizeof(id3buffer) - 1] = '\0';
+ id3_from_path(id3buffer, &artist, &album, &title);
+
+ lcd_puts(0,0, artist?artist:"<nothing>");
 
- lcd_puts_scroll(0,LINE_Y,(++szDelimit));
+ lcd_puts_scroll(0,LINE_Y,title);
                 break;
             }
             case PLAY_DISPLAY_FILENAME_SCROLL:
@@ -107,13 +188,24 @@
             case PLAY_DISPLAY_DEFAULT:
             {
                 int l = 0;
+
+ if (id3->title && id3->artist){
+ artist = id3->artist;
+ album = id3->album;
+ title = id3->title;
+ }
+ else {
+ strncpy(id3buffer, id3->path, sizeof(id3buffer));
+ id3buffer[sizeof(id3buffer) - 1] = '\0';
+ id3_from_path(id3buffer, &artist, &album, &title);
+ }
 #ifdef HAVE_LCD_BITMAP
                 char buffer[64];
 
                 lcd_puts_scroll(0, l++, id3->path);
- lcd_puts(0, l++, id3->title?id3->title:"");
- lcd_puts(0, l++, id3->album?id3->album:"");
- lcd_puts(0, l++, id3->artist?id3->artist:"");
+ lcd_puts(0, l++, title?title:"");
+ lcd_puts(0, l++, album?album:"");
+ lcd_puts(0, l++, artist?artist:"");
 
                 if(id3->vbr)
                     snprintf(buffer, sizeof(buffer), "%d kbit (avg)",
@@ -126,12 +218,52 @@
                 snprintf(buffer,sizeof(buffer), "%d Hz", id3->frequency);
                 lcd_puts(0, l++, buffer);
 #else
-
- lcd_puts(0, l++, id3->artist?id3->artist:"<no artist>");
- lcd_puts_scroll(0, l++, id3->title?id3->title:"<no title>");
+ lcd_puts(0, l++, artist?artist:"<no artist>");
+ lcd_puts_scroll(0, l++, title?title:"<no title>");
 #endif
                 break;
             }
+ case PLAY_DISPLAY_COMPACT_VERBOSE:
+ {
+ int tracknum;
+
+ if (id3->title && id3->artist)
+ {
+ artist = id3->artist;
+ album = id3->album;
+ title = id3->title;
+ /* Doesn't seem to get set... */
+ tracknum = id3->tracknum;
+ }
+ else
+ {
+ strncpy(id3buffer, id3->path, sizeof(id3buffer));
+ id3buffer[sizeof(id3buffer) - 1] = 0;
+ id3_from_path(id3buffer, &artist, &album, &title);
+ tracknum = 0;
+ }
+
+ buffer[0] = 0;
+
+ if (tracknum)
+ {
+ strfmt(buffer, sizeof(buffer), "%d - ", tracknum);
+ }
+
+ strfmt(buffer, sizeof(buffer), "%s", title ? title : "<N/A>");
+
+ if (artist || album)
+ {
+ strfmt(buffer, sizeof(buffer), " (%s, %s)",
+ artist ? artist : "<N/A>",
+ album ? album : "<N/A>");
+ }
+
+ buffer[sizeof(buffer) - 1] = 0;
+ lcd_puts_scroll(0, 0, buffer);
+
+ break;
+ }
         }
     }
     status_draw();
@@ -222,6 +354,38 @@
                 lcd_puts(0, 1, buffer);
                 lcd_update();
            }
+ else if (global_settings.wps_display == PLAY_DISPLAY_COMPACT_VERBOSE)
+ {
+ /* Change display every 5 seconds */
+ #define PDCV_CHANGE_FREQUENCY (5 * BUTTON_POLL_FREQUENCY / BUTTON_POLLS_PER_UPDATE)
+ static int count = 0;
+
+ if (count++ < PDCV_CHANGE_FREQUENCY)
+ {
+ snprintf(buffer, sizeof(buffer), "%02d:%02d%s%s%04d",
+ id3->elapsed / 60000,
+ id3->elapsed % 60000 / 1000,
+ global_settings.playlist_shuffle ? "s" : " ",
+ playlist.amount ? "p" : " ",
+ playlist.index + 1);
+ }
+ else
+ {
+ snprintf(buffer, sizeof(buffer), "-%02d:%02d %3d%s",
+ (id3->length - id3->elapsed) / 60000,
+ (id3->length - id3->elapsed) % 60000 / 1000,
+ id3->bitrate,
+ id3->vbr ? "*" : " ");
+ }
+
+ if (count > (PDCV_CHANGE_FREQUENCY * 2))
+ {
+ count = 0;
+ }
+
+ lcd_puts(0, 1, buffer);
+ lcd_update();
+ }
 #endif
         }
 
@@ -233,7 +397,7 @@
         lcd_drawline(0,LCD_HEIGHT-1,battery_level() * (LCD_WIDTH-1) / 100, LCD_HEIGHT-1);
 #endif
 
- for ( i=0;i<5;i++ ) {
+ for ( i=0;i<BUTTON_POLLS_PER_UPDATE;i++ ) {
             int button = button_get(false);
 
             switch ( button )
@@ -452,7 +616,7 @@
                     break;
 #endif
             }
- sleep(HZ/10);
+ sleep(HZ / BUTTON_POLL_FREQUENCY);
         }
     }
 }



Page was last modified "Jan 10 2012" The Rockbox Crew
aaa