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 tweaks

[PATCH] WPS tweaks

From: Brian King <brking_at_charter.net>
Date: Sat, 17 Aug 2002 00:44:11 -0500

Here are a couple tweaks to the WPS code once again - hopefully this
makes it into cvs so I can stop patching my rockbox firmware;)

Here is what it does:

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.

Also, this time I put strrtok_r in its rightful place - hopefully;)

The patch is against the current CVS.

-bk



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


diff -u -r1.76 wps.c
--- apps/wps.c 17 Aug 2002 00:41:36 -0000 1.76
+++ apps/wps.c 17 Aug 2002 05:20:27 -0000
_at__at_ -64,8 +64,55 _at__at_
 bool device_muted = false;
 static bool ff_rewind = false;
 
+/* 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];
     int font_height;
 #ifdef LOADABLE_FONTS
     unsigned char *font = lcd_getcurrentldfont();
_at__at_ -91,32 +138,12 _at__at_
         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,LINE_Y, 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_scroll(0,LINE_Y+1,(++szDelimit));
+ lcd_puts(0,LINE_Y, artist?artist:"<nothing>");
+ lcd_puts_scroll(0,LINE_Y+1,title);
                 break;
             }
             case PLAY_DISPLAY_FILENAME_SCROLL:
_at__at_ -133,13 +160,23 _at__at_
             case PLAY_DISPLAY_DEFAULT:
             {
                 int l = LINE_Y;
+ 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(LINE_Y==0&&font_height<=8) {
                     if(id3->vbr)
_at__at_ -163,8 +200,8 _at__at_
                     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;
             }
diff -u -r1.76 firmware/common/strrtok.c
--- firmware/common/strrtok.c Wed Dec 31 18:00:00 1969 1.76
+++ firmware/common/strrtok.c Fri Aug 16 23:37:16 2002
_at__at_ -0,0 +1,70 _at__at_
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id: strtok.c,v 1.1 2002/05/07 07:42:30 bagder Exp $
+ *
+ * Copyright (C) 2002 by Daniel Stenberg
+ *
+ * All files in this archive are subject to the GNU General Public License.
+ * See the file COPYING in the source tree root for full license agreement.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied. *
+ ****************************************************************************/
+
+#include "config.h"
+
+#ifndef HAVE_STRRTOK_R
+#include <stddef.h>
+#include <string.h>
+
+/* 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.
+ */
+char*
+strrtok_r(char* buffer, const 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 */
+}
+
+#endif /* this was only compiled if strrtok_r wasn't present */
+
+/*
+ * local variables:
+ * eval: (load-file "../rockbox-mode.el")
+ * end:
+ */
diff -u -r1.2 firmware/include/string.h
--- firmware/include/string.h 17 Jun 2002 13:34:04 -0000 1.2
+++ firmware/include/string.h 17 Aug 2002 05:05:58 -0000
_at__at_ -49,6 +49,7 _at__at_
 
 #ifndef __STRICT_ANSI__
 char *_EXFUN(strtok_r,(char *, const char *, char **));
+char *_EXFUN(strrtok_r,(char *, const char *, char **));
 
 _PTR _EXFUN(memccpy,(_PTR, const _PTR, int, size_t));
 int _EXFUN(strcasecmp,(const char *, const char *));
Received on 2002-08-17

Page template was last modified "Tue Sep 7 00:00:02 2021" The Rockbox Crew -- Privacy Policy