summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Wilgus <wilgus.william@gmail.com>2024-07-13 01:33:29 -0400
committerWilliam Wilgus <me.theuser@yahoo.com>2024-07-13 01:39:50 -0400
commit3891bcf3b9df0b320b2ecbd700de9cedceedb342 (patch)
treeacd7f93636ae2708dfd9e3bc678f7b36ed2a9bef
parent8753c41b2e4f5a670fedcd2e06d8375f8c317844 (diff)
downloadrockbox-3891bcf3b9df0b320b2ecbd700de9cedceedb342.tar.gz
rockbox-3891bcf3b9df0b320b2ecbd700de9cedceedb342.zip
[Revert] id3 title display playlist_viewer.c
reading the disk works fine for on disk playlist but trying to read from the disk with the current playlist becomes unbearably slow removes the static playlist_track_info prefering the unused one already on the stack from search_playlist() Change-Id: I01b836b4fe46bb51ef6a28d5db6b3f9cdc7d1e51
-rw-r--r--apps/playlist_viewer.c115
-rw-r--r--apps/settings_list.c6
2 files changed, 26 insertions, 95 deletions
diff --git a/apps/playlist_viewer.c b/apps/playlist_viewer.c
index f0a9a711a2..b0435365e2 100644
--- a/apps/playlist_viewer.c
+++ b/apps/playlist_viewer.c
@@ -51,10 +51,6 @@
51#include "menus/exported_menus.h" 51#include "menus/exported_menus.h"
52#include "yesno.h" 52#include "yesno.h"
53 53
54#if defined(HAVE_TC_RAMCACHE) && defined(HAVE_DIRCACHE)
55#include "tagcache.h"
56#endif
57
58/* Maximum number of tracks we can have loaded at one time */ 54/* Maximum number of tracks we can have loaded at one time */
59#define MAX_PLAYLIST_ENTRIES 200 55#define MAX_PLAYLIST_ENTRIES 200
60 56
@@ -67,8 +63,7 @@ struct playlist_entry {
67 char *name; /* track path */ 63 char *name; /* track path */
68 int index; /* Playlist index */ 64 int index; /* Playlist index */
69 int display_index; /* Display index */ 65 int display_index; /* Display index */
70 uint16_t title_offset; /* where in the buffer the title is located */ 66 int attr; /* Is track queued?; Is track marked as bad?*/
71 uint16_t attr; /* Is track queued?; Is track marked as bad?*/
72}; 67};
73 68
74enum direction 69enum direction
@@ -118,13 +113,15 @@ struct playlist_viewer {
118 or -1 if nothing is currently being moved */ 113 or -1 if nothing is currently being moved */
119 int moving_playlist_index; /* Playlist-relative index (as opposed to 114 int moving_playlist_index; /* Playlist-relative index (as opposed to
120 viewer-relative index) of moving track */ 115 viewer-relative index) of moving track */
121 bool (*track_metadata)(struct mp3entry* id3,
122 int fd,
123 const char* trackname,
124 int flags); /* Title display metadata lookup fn */
125 struct playlist_buffer buffer; 116 struct playlist_buffer buffer;
126}; 117};
127 118
119struct playlist_search_data
120{
121 struct playlist_track_info *track;
122 int *found_indicies;
123};
124
128static struct playlist_viewer viewer; 125static struct playlist_viewer viewer;
129 126
130/* Used when viewing playlists on disk */ 127/* Used when viewing playlists on disk */
@@ -230,36 +227,6 @@ static void playlist_buffer_load_entries_screen(struct playlist_buffer * pb,
230 playlist_buffer_load_entries(pb, start, direction); 227 playlist_buffer_load_entries(pb, start, direction);
231} 228}
232 229
233#if defined(HAVE_TC_RAMCACHE) && defined(HAVE_DIRCACHE)
234static bool try_track_ram_metadata(struct mp3entry* id3, int fd, const char* trackname, int flags)
235{
236 /* used for title display mode */
237 /* try to get the id3 data from the database */
238 if (tagcache_fill_tags(id3, trackname))
239 return true;
240 /* fall back to reading the file from disk */
241 return get_metadata_ex(id3, fd, trackname, flags);
242}
243#endif
244
245static int load_track_title(char* buffer, size_t bufsz, char *filename)
246{
247 size_t len = 0;
248 struct mp3entry id3;
249 if (viewer.track_metadata(&id3, -1, filename, METADATA_EXCLUDE_ID3_PATH)
250 && id3.title && id3.title[0] != '\0')
251 {
252 const char *artist = id3.artist;
253 if (!artist)
254 artist = id3.albumartist;
255 if(!artist)
256 artist = str(LANG_TAGNAVI_UNTAGGED);
257
258 len = snprintf(buffer, bufsz, "%s - %s", artist, id3.title) + 1;
259 }
260 return len;
261}
262
263static int playlist_entry_load(struct playlist_entry *entry, int index, 230static int playlist_entry_load(struct playlist_entry *entry, int index,
264 char* name_buffer, int remaining_size) 231 char* name_buffer, int remaining_size)
265{ 232{
@@ -278,27 +245,9 @@ static int playlist_entry_load(struct playlist_entry *entry, int index,
278 if (len <= remaining_size) 245 if (len <= remaining_size)
279 { 246 {
280 entry->name = name_buffer; 247 entry->name = name_buffer;
281 entry->title_offset = 0; /* offset 0 is the first char of name */
282 entry->index = info.index; 248 entry->index = info.index;
283 entry->display_index = info.display_index; 249 entry->display_index = info.display_index;
284 entry->attr = info.attr & (PLAYLIST_ATTR_SKIPPED | PLAYLIST_ATTR_QUEUED); 250 entry->attr = info.attr & (PLAYLIST_ATTR_SKIPPED | PLAYLIST_ATTR_QUEUED);
285
286 if (global_settings.playlist_viewer_track_display == 2) /* title */
287 {
288 /* advance buffer position past filename, adjust length remaining */
289 name_buffer += len;
290 remaining_size -= len;
291 int tlen = load_track_title(name_buffer, remaining_size, info.filename);
292 if (tlen > remaining_size)
293 return -1; /*Failure */
294 if (tlen > 0)
295 {
296 entry->title_offset = len;
297 /* offset is the first char after terminating zero of name */
298 len += tlen;
299 }
300 }
301
302 return len; 251 return len;
303 } 252 }
304 return -1; 253 return -1;
@@ -443,17 +392,6 @@ static bool playlist_viewer_init(struct playlist_viewer * viewer,
443 file = filename+1; 392 file = filename+1;
444 } 393 }
445 viewer->title = file; 394 viewer->title = file;
446#if defined(HAVE_TC_RAMCACHE) && defined(HAVE_DIRCACHE)
447 if (global_settings.tagcache_ram == TAGCACHE_RAM_ON &&
448 tagcache_is_usable() && tagcache_is_in_ram())
449 {
450 viewer->track_metadata = try_track_ram_metadata;
451 }
452 else
453#endif
454 {
455 viewer->track_metadata = get_metadata_ex;
456 }
457 395
458 if (is_playing) 396 if (is_playing)
459 { 397 {
@@ -512,8 +450,6 @@ static void format_name(char* dest, const char* src, size_t bufsz)
512 strrsplt(dest, '.'); 450 strrsplt(dest, '.');
513 break; 451 break;
514 } 452 }
515 case 2: /* Artist - Title */
516 /*fall-through*/
517 case 1: 453 case 1:
518 /* Full path */ 454 /* Full path */
519 strlcpy(dest, src, bufsz); 455 strlcpy(dest, src, bufsz);
@@ -527,7 +463,7 @@ static void format_line(const struct playlist_entry* track, char* str,
527{ 463{
528 char name[MAX_PATH]; 464 char name[MAX_PATH];
529 char *skipped = ""; 465 char *skipped = "";
530 format_name(name, track->name + track->title_offset, sizeof(name)); 466 format_name(name, track->name, sizeof(name));
531 467
532 if (track->attr & PLAYLIST_ATTR_SKIPPED) 468 if (track->attr & PLAYLIST_ATTR_SKIPPED)
533 skipped = "(ERR) "; 469 skipped = "(ERR) ";
@@ -857,9 +793,6 @@ static int playlist_callback_voice(int selected_item, void *data)
857 case 1: /*full path*/ 793 case 1: /*full path*/
858 talk_fullpath(track->name, true); 794 talk_fullpath(track->name, true);
859 break; 795 break;
860 case 2: /*title*/
861 talk_spell(track->name + track->title_offset, true);
862 break;
863 default: 796 default:
864 case 0: /*filename only*/ 797 case 0: /*filename only*/
865 talk_file_or_spell(NULL, track->name, NULL, true); 798 talk_file_or_spell(NULL, track->name, NULL, true);
@@ -1208,28 +1141,22 @@ static void close_playlist_viewer(void)
1208 } 1141 }
1209} 1142}
1210 1143
1211static struct playlist_track_info* get_static_track_info(int *found_indicies, int selected_item)
1212{
1213 /* playlist_track_info is a large struct keep a static copy to hand out */
1214 static struct playlist_track_info track;
1215 playlist_get_track_info(viewer.playlist, found_indicies[selected_item], &track);
1216 return &track;
1217}
1218
1219static const char* playlist_search_callback_name(int selected_item, void * data, 1144static const char* playlist_search_callback_name(int selected_item, void * data,
1220 char *buffer, size_t buffer_len) 1145 char *buffer, size_t buffer_len)
1221{ 1146{
1222 struct playlist_track_info *track = get_static_track_info(data, selected_item); 1147 struct playlist_search_data *s_data = data;
1223 format_name(buffer, track->filename, buffer_len); 1148 playlist_get_track_info(viewer.playlist, s_data->found_indicies[selected_item], s_data->track);
1149 format_name(buffer, s_data->track->filename, buffer_len);
1224 return buffer; 1150 return buffer;
1225} 1151}
1226 1152
1227static int say_search_item(int selected_item, void *data) 1153static int say_search_item(int selected_item, void *data)
1228{ 1154{
1229 struct playlist_track_info *track = get_static_track_info(data, selected_item); 1155 struct playlist_search_data *s_data = data;
1230 if(global_settings.playlist_viewer_track_display == 1) 1156 playlist_get_track_info(viewer.playlist, s_data->found_indicies[selected_item], s_data->track);
1231 talk_fullpath(track->filename, false); 1157 if(global_settings.playlist_viewer_track_display == 1) /* full path*/
1232 else talk_file_or_spell(NULL, track->filename, NULL, false); 1158 talk_fullpath(s_data->track->filename, false);
1159 else talk_file_or_spell(NULL, s_data->track->filename, NULL, false);
1233 return 0; 1160 return 0;
1234} 1161}
1235 1162
@@ -1241,6 +1168,7 @@ bool search_playlist(void)
1241 int found_indicies[MAX_PLAYLIST_ENTRIES]; 1168 int found_indicies[MAX_PLAYLIST_ENTRIES];
1242 int found_indicies_count = 0, last_found_count = -1; 1169 int found_indicies_count = 0, last_found_count = -1;
1243 int button; 1170 int button;
1171 int track_display = global_settings.playlist_viewer_track_display;
1244 struct gui_synclist playlist_lists; 1172 struct gui_synclist playlist_lists;
1245 struct playlist_track_info track; 1173 struct playlist_track_info track;
1246 1174
@@ -1268,8 +1196,11 @@ bool search_playlist(void)
1268 break; 1196 break;
1269 1197
1270 playlist_get_track_info(viewer.playlist, i, &track); 1198 playlist_get_track_info(viewer.playlist, i, &track);
1199 const char *trackname = track.filename;
1200 if (track_display == 0) /* if we only display filename only search filename */
1201 trackname = strrchr(track.filename, '/');
1271 1202
1272 if (strcasestr(track.filename,search_str)) 1203 if (trackname && strcasestr(trackname, search_str))
1273 found_indicies[found_indicies_count++] = track.index; 1204 found_indicies[found_indicies_count++] = track.index;
1274 1205
1275 yield(); 1206 yield();
@@ -1284,9 +1215,9 @@ bool search_playlist(void)
1284 return ret; 1215 return ret;
1285 } 1216 }
1286 backlight_on(); 1217 backlight_on();
1287 1218 struct playlist_search_data s_data = {.track = &track, .found_indicies = found_indicies};
1288 gui_synclist_init(&playlist_lists, playlist_search_callback_name, 1219 gui_synclist_init(&playlist_lists, playlist_search_callback_name,
1289 found_indicies, false, 1, NULL); 1220 &s_data, false, 1, NULL);
1290 gui_synclist_set_title(&playlist_lists, str(LANG_SEARCH_RESULTS), NOICON); 1221 gui_synclist_set_title(&playlist_lists, str(LANG_SEARCH_RESULTS), NOICON);
1291 gui_synclist_set_icon_callback(&playlist_lists, NULL); 1222 gui_synclist_set_icon_callback(&playlist_lists, NULL);
1292 if(global_settings.talk_file) 1223 if(global_settings.talk_file)
diff --git a/apps/settings_list.c b/apps/settings_list.c
index 60a2735e90..09a45f1faa 100644
--- a/apps/settings_list.c
+++ b/apps/settings_list.c
@@ -1415,9 +1415,9 @@ const struct settings_list settings[] = {
1415 OFFON_SETTING(0,playlist_viewer_indices,LANG_SHOW_INDICES,true, 1415 OFFON_SETTING(0,playlist_viewer_indices,LANG_SHOW_INDICES,true,
1416 "playlist viewer indices",NULL), 1416 "playlist viewer indices",NULL),
1417 CHOICE_SETTING(0, playlist_viewer_track_display, LANG_TRACK_DISPLAY, 0, 1417 CHOICE_SETTING(0, playlist_viewer_track_display, LANG_TRACK_DISPLAY, 0,
1418 "playlist viewer track display","track name,full path,id3 title", 1418 "playlist viewer track display","track name,full path",
1419 NULL, 3, ID2P(LANG_DISPLAY_TRACK_NAME_ONLY), 1419 NULL, 2, ID2P(LANG_DISPLAY_TRACK_NAME_ONLY),
1420 ID2P(LANG_DISPLAY_FULL_PATH), ID2P(LANG_ID3_TITLE)), 1420 ID2P(LANG_DISPLAY_FULL_PATH)),
1421 CHOICE_SETTING(0, recursive_dir_insert, LANG_RECURSE_DIRECTORY , RECURSE_ON, 1421 CHOICE_SETTING(0, recursive_dir_insert, LANG_RECURSE_DIRECTORY , RECURSE_ON,
1422 "recursive directory insert", off_on_ask, NULL , 3 , 1422 "recursive directory insert", off_on_ask, NULL , 3 ,
1423 ID2P(LANG_OFF), ID2P(LANG_ON), ID2P(LANG_ASK)), 1423 ID2P(LANG_OFF), ID2P(LANG_ON), ID2P(LANG_ASK)),