From 75eff7af5e23bb86b376746c1216b553d1efbc35 Mon Sep 17 00:00:00 2001 From: Jonathan Gordon Date: Mon, 29 Oct 2007 14:10:24 +0000 Subject: [PATCH] rework my previous commit (FS#8008) to be able to work for any of the strings in the id3 info struct, new ones need to be added to tagtree.c and tagnavi.config *currently available tags are* #title# #artist# #album# #genre# #composer# #albumartist# and #directory# git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15358 a1c6a512-1295-4272-9138-f99709370657 --- apps/tagcache.h | 10 ++++--- apps/tagnavi.config | 1 + apps/tagtree.c | 70 ++++++++++++++++++++++++++++++++------------- 3 files changed, 57 insertions(+), 24 deletions(-) diff --git a/apps/tagcache.h b/apps/tagcache.h index 16dac0b41f..a33e79b56d 100644 --- a/apps/tagcache.h +++ b/apps/tagcache.h @@ -110,10 +110,12 @@ struct tagcache_stat { }; enum source_type {source_constant, source_input, - source_current_artist, source_current_album}; - -#define SOURCE_CURRENT_ARTIST "#artist#" -#define SOURCE_CURRENT_ALBUM "#album#" + source_current_path, /* has different handling to _id3 + so it has to be seperate */ + source_current_id3 /* dont add items after this. + it is used as an index + into id3_to_search_mapping */ + }; struct tagcache_search_clause { diff --git a/apps/tagnavi.config b/apps/tagnavi.config index 30fd371b3e..4facdd25b9 100644 --- a/apps/tagnavi.config +++ b/apps/tagnavi.config @@ -143,6 +143,7 @@ %menu_start "same" "Same as current" "Artist" -> album ? artist = "#artist#" -> title = "fmt_title" "Album" -> title = "fmt_title" ? album = "#album#" +"Directory" -> filename ? filename ~ "#directory#" # Define the runtime sub menu %menu_start "runtime" "Play history" diff --git a/apps/tagtree.c b/apps/tagtree.c index bac74cf443..94bf726caa 100644 --- a/apps/tagtree.c +++ b/apps/tagtree.c @@ -53,7 +53,17 @@ static int tagtree_play_folder(struct tree_context* c); #define SEARCHSTR_SIZE 128 static char searchstring[SEARCHSTR_SIZE]; - +static const struct id3_to_search_mapping { + char *string; + size_t id3_offset; +} id3_to_search_mapping[] = { + { "#title#", offsetof(struct mp3entry, title) }, + { "#artist#", offsetof(struct mp3entry, artist) }, + { "#album#", offsetof(struct mp3entry, album) }, + { "#genre#", offsetof(struct mp3entry, genre_string) }, + { "#composer#", offsetof(struct mp3entry, composer) }, + { "#albumartist#", offsetof(struct mp3entry, albumartist) }, +}; enum variables { var_sorttype = 100, var_limit, @@ -296,12 +306,25 @@ static bool read_clause(struct tagcache_search_clause *clause) if (*(clause->str) == '\0') clause->source = source_input; - else if (!strcasecmp(clause->str, SOURCE_CURRENT_ALBUM)) - clause->source = source_current_album; - else if (!strcasecmp(clause->str, SOURCE_CURRENT_ARTIST)) - clause->source = source_current_artist; - else - clause->source = source_constant; + else if (!strcasecmp(clause->str, "#directory#")) + clause->source = source_current_path; + else + { + unsigned int i; + bool found = false; + for (i=0; !found && istr, id3_to_search_mapping[i].string)) + { + found = true; + break; + } + } + if (found) + clause->source = source_current_id3+i; + else + clause->source = source_constant; + } if (tagcache_is_numeric_tag(clause->tag)) { @@ -1403,21 +1426,28 @@ int tagtree_enter(struct tree_context* c) continue; id3 = audio_current_track(); - - if ((source == source_current_artist) && - (id3) && (id3->artist)) + + if (source == source_current_path && id3) { - strncpy(searchstring, id3->artist, SEARCHSTR_SIZE); - searchstring[SEARCHSTR_SIZE-1] = '\0'; - } - - if ((source == source_current_album) && - (id3) && (id3->album)) + char *e; + strncpy(searchstring, id3->path, SEARCHSTR_SIZE); + e = strrchr(searchstring, '/'); + if (e) + *e = '\0'; + } + + if (source >= source_current_id3 && id3) { - strncpy(searchstring, id3->album, SEARCHSTR_SIZE); - searchstring[SEARCHSTR_SIZE-1] = '\0'; - } - + int i = source-source_current_id3; + int offset = id3_to_search_mapping[i].id3_offset; + char **src = (char**)((char*)id3 + offset); + if (*src) + { + strncpy(searchstring, *src, SEARCHSTR_SIZE); + searchstring[SEARCHSTR_SIZE-1] = '\0'; + } + } + if((source == source_input) || (*searchstring=='\0')) { rc = kbd_input(searchstring, SEARCHSTR_SIZE);