tagnavi make track submenu

add some faster options to the track menu
add a shortcut for basename formatting
sort basename results

filename - by sorted filename
title - just title no formatting untagged items are unsorted as well
title mm:ss - title and duration

Change-Id: I90aea95051f6231580ef7f1fc08cd2d0d69601fb
This commit is contained in:
William Wilgus 2023-02-04 16:39:42 -05:00
parent b5d93a6605
commit 1c26f565bf
4 changed files with 90 additions and 70 deletions

View file

@ -1934,17 +1934,10 @@ static int pf_tcs_retrieve_track_title(int string_index, int disc_num, int track
if (rb->strcmp(UNTAGGED, tcs.result) == 0) if (rb->strcmp(UNTAGGED, tcs.result) == 0)
{ {
/* show filename instead of <untaggged> */ /* show filename instead of <untaggged> */
if (!rb->tagcache_retrieve(&tcs, tcs.idx_id, tag_filename, if (!rb->tagcache_retrieve(&tcs, tcs.idx_id, tag_virt_basename,
file_name, MAX_PATH)) file_name, MAX_PATH))
return 0; return 0;
track_title = file_name; track_title = file_name;
if (track_title)
{
/* if filename remove the '/' */
track_title = rb->strrchr(track_title, PATH_SEPCH);
if (track_title)
track_title++;
}
} }
if (!track_title) if (!track_title)

View file

@ -930,9 +930,17 @@ static bool open_files(struct tagcache_search *tcs, int tag)
static bool retrieve(struct tagcache_search *tcs, IF_DIRCACHE(int idx_id,) static bool retrieve(struct tagcache_search *tcs, IF_DIRCACHE(int idx_id,)
struct index_entry *idx, int tag, char *buf, long bufsz) struct index_entry *idx, int tag, char *buf, long bufsz)
{ {
bool success = false;
bool is_basename = false;
struct tagfile_entry tfe; struct tagfile_entry tfe;
long seek; long seek;
if (tag == tag_virt_basename)
{
tag = tag_filename;
is_basename = true;
}
if (TAGCACHE_IS_NUMERIC(tag)) if (TAGCACHE_IS_NUMERIC(tag))
goto failure; goto failure;
@ -950,7 +958,7 @@ static bool retrieve(struct tagcache_search *tcs, IF_DIRCACHE(int idx_id,)
if (tag == tag_filename && (idx->flag & FLAG_DIRCACHE)) if (tag == tag_filename && (idx->flag & FLAG_DIRCACHE))
{ {
if (dircache_get_fileref_path(&tcrc_dcfrefs[idx_id], buf, bufsz) >= 0) if (dircache_get_fileref_path(&tcrc_dcfrefs[idx_id], buf, bufsz) >= 0)
return true; success = true;
} }
else else
#endif /* HAVE_DIRCACHE */ #endif /* HAVE_DIRCACHE */
@ -959,13 +967,12 @@ static bool retrieve(struct tagcache_search *tcs, IF_DIRCACHE(int idx_id,)
struct tagfile_entry *ep = struct tagfile_entry *ep =
(struct tagfile_entry *)&tcramcache.hdr->tags[tag][seek]; (struct tagfile_entry *)&tcramcache.hdr->tags[tag][seek];
strmemccpy(buf, ep->tag_data, bufsz); strmemccpy(buf, ep->tag_data, bufsz);
success = true;
return true;
} }
} }
#endif /* HAVE_TC_RAMCACHE */ #endif /* HAVE_TC_RAMCACHE */
if (open_files(tcs, tag)) if (!success && open_files(tcs, tag))
{ {
lseek(tcs->idxfd[tag], seek, SEEK_SET); lseek(tcs->idxfd[tag], seek, SEEK_SET);
switch (ecread_tagfile_entry_and_tag(tcs->idxfd[tag], &tfe, buf, bufsz)) switch (ecread_tagfile_entry_and_tag(tcs->idxfd[tag], &tfe, buf, bufsz))
@ -984,10 +991,22 @@ static bool retrieve(struct tagcache_search *tcs, IF_DIRCACHE(int idx_id,)
break; break;
case e_SUCCESS_LEN_ZERO: case e_SUCCESS_LEN_ZERO:
case e_SUCCESS: case e_SUCCESS:
return true; success = true;
break;
} }
} }
if (success)
{
if (is_basename)
{
char* basename = strrchr(buf, '/');
if (basename != NULL)
memmove(buf, basename + 1, strlen(basename)); /* includes NULL */
}
return true;
}
failure: failure:
str_setlen(buf, 0); str_setlen(buf, 0);
return false; return false;
@ -1284,7 +1303,7 @@ static bool check_clauses(struct tagcache_search *tcs,
if (clause->tag == tag_filename if (clause->tag == tag_filename
|| clause->tag == tag_virt_basename) || clause->tag == tag_virt_basename)
{ {
retrieve(tcs, IF_DIRCACHE(tcs->idx_id,) idx, tag_filename, retrieve(tcs, IF_DIRCACHE(tcs->idx_id,) idx, clause->tag,
buf, bufsz); buf, bufsz);
} }
else else
@ -1316,6 +1335,12 @@ static bool check_clauses(struct tagcache_search *tcs,
case e_SUCCESS_LEN_ZERO: /* Check if entry has been deleted. */ case e_SUCCESS_LEN_ZERO: /* Check if entry has been deleted. */
return false; return false;
case e_SUCCESS: case e_SUCCESS:
if (clause->tag == tag_virt_basename)
{
char *basename = strrchr(str, '/');
if (basename)
str = basename + 1;
}
break; break;
case e_ENTRY_SIZEMISMATCH: case e_ENTRY_SIZEMISMATCH:
logf("read error #15"); logf("read error #15");
@ -1333,13 +1358,6 @@ static bool check_clauses(struct tagcache_search *tcs,
} }
} }
if (clause->tag == tag_virt_basename)
{
char *basename = strrchr(str, '/');
if (basename)
str = basename + 1;
}
if (!check_against_clause(seek, str, clause)) if (!check_against_clause(seek, str, clause))
{ {
/* Clause failed -- try finding a logical-or clause */ /* Clause failed -- try finding a logical-or clause */
@ -1709,7 +1727,7 @@ bool tagcache_search_add_clause(struct tagcache_search *tcs,
return true; return true;
} }
static bool get_next(struct tagcache_search *tcs) static bool get_next(struct tagcache_search *tcs, bool is_numeric)
{ {
/* WARNING pointers into buf are used in outside functions */ /* WARNING pointers into buf are used in outside functions */
static char buf[TAGCACHE_BUFSZ]; static char buf[TAGCACHE_BUFSZ];
@ -1719,11 +1737,6 @@ static bool get_next(struct tagcache_search *tcs)
long flag = 0; long flag = 0;
#endif #endif
if (!tcs->valid || !tc_stat.ready)
return false;
bool is_numeric = TAGCACHE_IS_NUMERIC(tcs->type);
if (tcs->idxfd[tcs->type] < 0 && !is_numeric if (tcs->idxfd[tcs->type] < 0 && !is_numeric
#ifdef HAVE_TC_RAMCACHE #ifdef HAVE_TC_RAMCACHE
&& !tcs->ramsearch && !tcs->ramsearch
@ -1849,9 +1862,6 @@ static bool get_next(struct tagcache_search *tcs)
tcs->valid = false; tcs->valid = false;
logf("read error #4"); logf("read error #4");
return false; return false;
default:
logf("unknown_error");
break;;
} }
/** /**
@ -1871,12 +1881,15 @@ static bool get_next(struct tagcache_search *tcs)
bool tagcache_get_next(struct tagcache_search *tcs) bool tagcache_get_next(struct tagcache_search *tcs)
{ {
while (get_next(tcs)) if (tcs->valid && tagcache_is_usable())
{
bool is_numeric = TAGCACHE_IS_NUMERIC(tcs->type);
while (get_next(tcs, is_numeric))
{ {
if (tcs->result_len > 1) if (tcs->result_len > 1)
return true; return true;
} }
}
#ifdef LOGF_ENABLE #ifdef LOGF_ENABLE
if (tcs->unique_list_count > 0) if (tcs->unique_list_count > 0)
logf(" uniqbuf: %d used / %d avail", tcs->unique_list_count, tcs->unique_list_capacity); logf(" uniqbuf: %d used / %d avail", tcs->unique_list_count, tcs->unique_list_capacity);
@ -2817,9 +2830,6 @@ static int build_index(int index_type, struct tagcache_header *h, int tmpfd)
logf("read error #8"); logf("read error #8");
close(fd); close(fd);
return -2; return -2;
default:
logf("unknown_error");
break;;
} }
/** /**
@ -3994,9 +4004,6 @@ static bool delete_entry(long idx_id)
case e_TAG_SIZEMISMATCH: case e_TAG_SIZEMISMATCH:
logf("delete_entry(): read error #3"); logf("delete_entry(): read error #3");
goto cleanup; goto cleanup;
default:
logf("unknown_error");
break;;
} }
myidx.tag_seek[tag] = crc_32(buf, strlen(buf), 0xffffffff); myidx.tag_seek[tag] = crc_32(buf, strlen(buf), 0xffffffff);
@ -4519,10 +4526,6 @@ static bool check_file_refs(bool auto_update)
switch (res) switch (res)
{ {
default:
logf("read error");
ret = false;
goto wend_finished;
case e_ENTRY_SIZEMISMATCH: case e_ENTRY_SIZEMISMATCH:
logf("size mismatch entry EOF?"); /* likely EOF */ logf("size mismatch entry EOF?"); /* likely EOF */
ret = false; ret = false;

View file

@ -14,7 +14,6 @@
%format "fmt_title" "%d.%02d. %s - %02d:%02d" discnum tracknum title Lm Ls ? discnum > "0" %format "fmt_title" "%d.%02d. %s - %02d:%02d" discnum tracknum title Lm Ls ? discnum > "0"
%format "fmt_title" "%02d. %s - %02d:%02d" tracknum title Lm Ls ? tracknum > "0" %format "fmt_title" "%02d. %s - %02d:%02d" tracknum title Lm Ls ? tracknum > "0"
%format "fmt_title" "%s - %02d:%02d" title Lm Ls %format "fmt_title" "%s - %02d:%02d" title Lm Ls
%format "fmt_alphanum_title" "%s - %02d:%02d (%s)" basename Lm Ls filename ? title == "<Untagged>"
%format "fmt_alphanum_title" "%s - %02d:%02d" title Lm Ls %format "fmt_alphanum_title" "%s - %02d:%02d" title Lm Ls
%format "fmt_mostplayed" "%2d|%3d %s (%s)" playcount autoscore title canonicalartist %sort = "inverse" %limit = "100" %format "fmt_mostplayed" "%2d|%3d %s (%s)" playcount autoscore title canonicalartist %sort = "inverse" %limit = "100"
%format "fmt_lastplayed" "%06d%s - %s" lastplayed canonicalartist title %sort = "inverse" %limit = "99" %strip = "6" %format "fmt_lastplayed" "%06d%s - %s" lastplayed canonicalartist title %sort = "inverse" %limit = "99" %strip = "6"
@ -165,6 +164,12 @@
"New favourites" -> canonicalartist ? playcount <= "3" & autoscore > "85" -> album -> title = "fmt_best_tracks" "New favourites" -> canonicalartist ? playcount <= "3" & autoscore > "85" -> album -> title = "fmt_best_tracks"
"Forgotten favourites" -> title = "fmt_forgotten" ? playcount > "3" & autoscore > "85" "Forgotten favourites" -> title = "fmt_forgotten" ? playcount > "3" & autoscore > "85"
# Define track submenu
%menu_start "track" "Tracks by"
"Filename" -> basename
"Title" -> title
"Title mm:ss" -> title = "fmt_alphanum_title"
# #
# === Begin of main menu # === Begin of main menu
# #
@ -176,7 +181,7 @@
"Album" -> album -> title = "fmt_title" "Album" -> album -> title = "fmt_title"
"Genre" -> genre -> canonicalartist -> album -> title = "fmt_title" "Genre" -> genre -> canonicalartist -> album -> title = "fmt_title"
"Composer" -> composer -> album -> title = "fmt_title" "Composer" -> composer -> album -> title = "fmt_title"
"Track" -> title = "fmt_alphanum_title" "Track" ==> "track"
"Year" -> year ? year > "0" -> canonicalartist -> album -> title = "fmt_title" "Year" -> year ? year > "0" -> canonicalartist -> album -> title = "fmt_title"
"User Rating" -> rating -> title = "fmt_title" "User Rating" -> rating -> title = "fmt_title"
"Recently Added" -> album ? entryage < "4" & commitid > "0" -> title = "fmt_title" "Recently Added" -> album ? entryage < "4" & commitid > "0" -> title = "fmt_title"

View file

@ -1328,7 +1328,7 @@ static int format_str(struct tagcache_search *tcs, struct display_format *fmt,
int buf_pos = 0; int buf_pos = 0;
int i; int i;
memset(buf, 0, buf_size); /* memset(buf, 0, buf_size); probably uneeded */
for (i = 0; fmt->formatstr[i] != '\0'; i++) for (i = 0; fmt->formatstr[i] != '\0'; i++)
{ {
if (fmt->formatstr[i] == '%') if (fmt->formatstr[i] == '%')
@ -1375,20 +1375,12 @@ static int format_str(struct tagcache_search *tcs, struct display_format *fmt,
int tag = fmt->tags[parpos]; int tag = fmt->tags[parpos];
if (!tagcache_retrieve(tcs, tcs->idx_id, if (!tagcache_retrieve(tcs, tcs->idx_id,
(tag == tag_virt_basename ? tag, tmpbuf, sizeof tmpbuf))
tag_filename : tag),
tmpbuf, sizeof tmpbuf))
{ {
logf("retrieve failed"); logf("retrieve failed");
return -3; return -3;
} }
if (tag == tag_virt_basename
&& (result = strrchr(tmpbuf, '/')) != NULL)
{
result++;
}
else
result = tmpbuf; result = tmpbuf;
} }
buf_pos += buf_pos +=
@ -1424,6 +1416,19 @@ static struct tagentry* get_entries(struct tree_context *tc)
return core_get_data(tc->cache.entries_handle); return core_get_data(tc->cache.entries_handle);
} }
static void tcs_get_basename(struct tagcache_search *tcs, bool is_basename)
{
if (is_basename)
{
char* basename = strrchr(tcs->result, '/');
if (basename != NULL)
{
tcs->result = basename + 1;
tcs->result_len = strlen(tcs->result) + 1;
}
}
}
static int retrieve_entries(struct tree_context *c, int offset, bool init) static int retrieve_entries(struct tree_context *c, int offset, bool init)
{ {
struct tagcache_search tcs; struct tagcache_search tcs;
@ -1436,6 +1441,7 @@ static int retrieve_entries(struct tree_context *c, int offset, bool init)
int tag; int tag;
bool sort = false; bool sort = false;
bool sort_inverse; bool sort_inverse;
bool is_basename = false;
int sort_limit; int sort_limit;
int strip; int strip;
@ -1463,13 +1469,19 @@ static int retrieve_entries(struct tree_context *c, int offset, bool init)
if (tag == menu_reload) if (tag == menu_reload)
return RELOAD_TAGTREE; return RELOAD_TAGTREE;
if (tag == tag_virt_basename) /* basename shortcut */
{
is_basename = true;
tag = tag_filename;
}
if (!tagcache_search(&tcs, tag)) if (!tagcache_search(&tcs, tag))
return -1; return -1;
/* Prevent duplicate entries in the search list. */ /* Prevent duplicate entries in the search list. */
tagcache_search_set_uniqbuf(&tcs, uniqbuf, UNIQBUF_SIZE); tagcache_search_set_uniqbuf(&tcs, uniqbuf, UNIQBUF_SIZE);
if (level || csi->clause_count[0] || TAGCACHE_IS_NUMERIC(tag)) if (level || is_basename|| csi->clause_count[0] || TAGCACHE_IS_NUMERIC(tag))
sort = true; sort = true;
for (i = 0; i < level; i++) for (i = 0; i < level; i++)
@ -1589,10 +1601,10 @@ static int retrieve_entries(struct tree_context *c, int offset, bool init)
if (strcmp(tcs.result, UNTAGGED) == 0) if (strcmp(tcs.result, UNTAGGED) == 0)
{ {
if (tag == tag_title && tcs.type == tag_title && tcs.filter_count <= 1) if (tag == tag_title && tcs.type == tag_title && tcs.filter_count <= 1)
{ /* Fallback to filename */ { /* Fallback to basename */
char *lastname = dptr->name; char *lastname = dptr->name;
dptr->name = core_get_data(c->cache.name_buffer_handle)+namebufused; dptr->name = core_get_data(c->cache.name_buffer_handle)+namebufused;
if (tagcache_retrieve(&tcs, tcs.idx_id, tag_filename, dptr->name, if (tagcache_retrieve(&tcs, tcs.idx_id, tag_virt_basename, dptr->name,
c->cache.name_buffer_size - namebufused)) c->cache.name_buffer_size - namebufused))
{ {
namebufused += strlen(dptr->name)+1; namebufused += strlen(dptr->name)+1;
@ -1614,6 +1626,13 @@ static int retrieve_entries(struct tree_context *c, int offset, bool init)
{ {
int ret = format_str(&tcs, fmt, dptr->name, int ret = format_str(&tcs, fmt, dptr->name,
c->cache.name_buffer_size - namebufused); c->cache.name_buffer_size - namebufused);
if (ret >= 0)
{
namebufused += strlen(dptr->name)+1; /* include NULL */
}
else
{
dptr->name[0] = '\0';
if (ret == -4) /* buffer full */ if (ret == -4) /* buffer full */
{ {
logf("chunk mode #2: %d", current_entry_count); logf("chunk mode #2: %d", current_entry_count);
@ -1621,19 +1640,17 @@ static int retrieve_entries(struct tree_context *c, int offset, bool init)
sort = false; sort = false;
break ; break ;
} }
else if (ret < 0)
{
logf("format_str() failed"); logf("format_str() failed");
tagcache_search_finish(&tcs); tagcache_search_finish(&tcs);
tree_unlock_cache(c); tree_unlock_cache(c);
core_unpin(tagtree_handle); core_unpin(tagtree_handle);
return 0; return 0;
} }
else
namebufused += strlen(dptr->name)+1;
} }
else else
{ {
tcs_get_basename(&tcs, is_basename);
namebufused += tcs.result_len; namebufused += tcs.result_len;
if (namebufused < c->cache.name_buffer_size) if (namebufused < c->cache.name_buffer_size)
strcpy(dptr->name, tcs.result); strcpy(dptr->name, tcs.result);
@ -1647,8 +1664,10 @@ static int retrieve_entries(struct tree_context *c, int offset, bool init)
} }
} }
else else
{
tcs_get_basename(&tcs, is_basename);
dptr->name = tcs.result; dptr->name = tcs.result;
}
entry_skip_formatter: entry_skip_formatter:
dptr++; dptr++;
current_entry_count++; current_entry_count++;