faster but quite buggy; no disc state storage

This commit is contained in:
2025-09-04 15:10:16 +02:00
parent b15848887b
commit 8c37cb2fea
7 changed files with 368 additions and 81 deletions

View File

@@ -1,3 +1,54 @@
# Print the command that sets the header.
# @argument $1: view
# @argument $2: mbid
fzf_command_set_header() {
view=$1
mbid=$2
case "$view" in
"$VIEW_SEARCH_ARTIST") header="Search artist on MusicBrainz" ;;
"$VIEW_SEARCH_ALBUM") header="Search album on MusicBrainz" ;;
"$VIEW_LIST_ARTISTS") header="Search locally available artist" ;;
"$VIEW_LIST_ALBUMS") header="Search locally available album" ;;
"$VIEW_ARTIST")
name="$(mb_artist "$mbid" | $JQ -r '.name')"
header=$(printf "$ARTIST_PROMPT" "$name")
;;
"$VIEW_RELEASEGROUP")
title="$(mb_releasegroup "$mbid" |
$JQ -r '.title')"
artist="$(mb_releasegroup "$mbid" |
$JQ -r '."artist-credit" | map(([.name, .joinphrase]|join(""))) | join("")')"
header=$(printf "$FULL_PROMPT" "$artist" "$title")
;;
"$VIEW_RELEASE")
title="$(mb_release "$mbid" |
$JQ -r '.title')"
artist="$(mb_release "$mbid" |
$JQ -r '."artist-credit" | map(([.name, .joinphrase]|join(""))) | join("")')"
header=$(printf "$FULL_PROMPT" "$artist" "$title")
;;
esac
printf "+change-header(%s)" "${header:-"???"}"
}
# Print the command that tells fzf to load the data
# @argument $1: view
# @argument $2: mbid
fzf_command_load_data() {
view=$1
mbid=${2:-}
case "$view" in
"$VIEW_SEARCH_ARTIST") ;;
"$VIEW_SEARCH_ALBUM") ;;
"$VIEW_LIST_ARTISTS") ;;
"$VIEW_LIST_ALBUMS") ;;
"$VIEW_ARTIST") ;;
"$VIEW_RELEASEGROUP") ;;
"$VIEW_RELEASE") ;;
esac
printf "+reload($0 --lines %s %s)" "$VIEW_LIST_ARTISTS" ""
}
# Set prompt of input field
# @argument $1: view
# @argument $2: mode
@@ -25,7 +76,7 @@ __set_prompt() {
;;
esac
[ "$mode" = "$MODE_INSERT" ] && PT="$PROMPT_INSERT" || PT="$PROMPT_NORMAL"
printf "+change-prompt(%s %s)" "$PT" "${PROMPT:-"$SEARCH_PROMPT"}"
printf "+change-header(%s %s)" "$PT" "${PROMPT:-"$SEARCH_PROMPT"}"
}
# Reload data for FZF

View File

@@ -1,37 +1,60 @@
# Key bindings
# See comment in `src/main.sh` on key bindings.
#
# Some key-bindings are used exclusively in the normal mode, others exclusively
# in the insert mode, others in both modes.
# Some key-bindings are universal in the sense that they do not depend on the
# state of the player (view, mode, arguments), others are not universal.
# Mode selection:
# - $KEYS_I_NORMAL: Switch to normal mode (insert mode)
# - $KEYS_N_INSERT: Switch to insert mode (normal mode)
#
# For fast processing, we propose the following.
# The mode (normal or insert) is stored in the FZF_INPUT_STATE variable. All
# key-bindings that are independent of the `view` and of the `arguments` are
# directly processed using a `--bind` with inline transform element. Keys that
# depend on `view` or `arguments` are processed through `$0 --fzf-key`. In a
# future step, we may also store the `view` part of the state as hidden fields
# in the list (the list generator makes that). Then, it may be possible to
# completely get rid of the state files. Even beter, we may store the view part
# in FZF_HEADER_LABEL.
# Vertical navigation:
# - $KEYS_DOWN: Move cursor to the next line
# - $KEYS_UP: Move cursor to the previous line
# - $KEYS_HALFPAGE_UP: Move cursor half a page up
# - $KEYS_HALFPAGE_DOWN: Move cursor half a page up
# - $KEYS_N_DOWN: Move cursor to the next line (normal mode)
# - $KEYS_N_UP: Move cursor to the previous line (normal mode)
# - $KEYS_N_BOT: Move cursor to the last line (normal mode)
# - $KEYS_N_TOP: Move cursor to the first line (normal mode)
#
# Switching between the modes (normal <-> insert) is done using two fzf `--bind`
# arguments. We make sure that only one is active.
# Horizontal navigation:
# - $KEYS_IN: Enter into selected item, down the hierarchy
# - $KEYS_OUT: Leave current item, up the hierarchy
#
# Filtering:
#
# Playback:
#
# Extras:
# - $KEYS_BROWSE: Open MusicBrainz webpage of the selected item
# - $KEYS_OPEN: Open file manager in the directory of the selected item
# Mode selection:
KEYS_I_NORMAL="${KEYS_I_NORMAL:-"esc"}"
KEYS_N_INSERT="${KEYS_N_INSERT:-"a,i,/"}"
# Vertical navigation:
KEYS_DOWN="${KEYS_DOWN:-"ctrl-j,down"}"
KEYS_UP="${KEYS_UP:-"ctrl-k,up"}"
KEYS_HALFPAGE_DOWN="${KEYS_HALFPAGE_DOWN:-"ctrl-d"}"
KEYS_HALFPAGE_UP="${KEYS_HALFPAGE_UP:-"ctrl-u"}"
KEYS_N_DOWN="${KEYS_N_DOWN:-"j"}"
KEYS_N_UP="${KEYS_N_UP:-"k"}"
KEYS_N_BOT="${KEYS_N_BOT:-"G"}"
KEYS_N_TOP="${KEYS_N_TOP:-"1"}"
# Horizontal navigation:
KEYS_IN="${KEYS_IN:-"ctrl-l"}"
KEYS_OUT="${KEYS_OUT:-"ctrl-h"}"
## Not yet characterized
KEYS_N_QUIT="${KEYS_N_QUIT:-"q"}"
KEYS_INPUT_SINGLE='0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,!,",#,$,%,&,\,(,),*,+,,,-,.,/,:,;,<,=,>,?,@,[,\,\,],^,_,`,{,|,},~'
KEYS_INPUT_SINGLE="$KEYS_INPUT_SINGLE,'"
KEYS_INPUT_SPECIAL="space,backspace,delete,left,right"
export KEYS_INPUT_SINGLE KEYS_INPUT_SPECIAL
# Normal and insert mode
KEYS_HALFPAGE_DOWN="${KEYS_HALFPAGE_DOWN:-"ctrl-d"}"
KEYS_HALFPAGE_UP="${KEYS_HALFPAGE_UP:-"ctrl-u"}"
KEYS_BROWSE="${KEYS_BROWSE:-"alt-b"}"
KEYS_OPEN="${KEYS_OPEN:-"alt-o"}"
KEYS_OUT="${KEYS_OUT:-"ctrl-h"}"
KEYS_IN="${KEYS_IN:-"ctrl-l"}"
KEYS_SELECT_ARTIST="${KEYS_SELECT_ARTIST:-"ctrl-a"}"
KEYS_FILTER_LOCAL="${KEYS_FILTER_LOCAL:-"alt-l"}"
KEYS_FILTER_1="${KEYS_FILTER_1:-"alt-1"}"
@@ -47,13 +70,8 @@ KEYS_NI="$KEYS_HALFPAGE_DOWN,$KEYS_HALFPAGE_UP,$KEYS_BROWSE,$KEYS_OPEN,$KEYS_OUT
export KEYS_NI
# Keys in normal mode only
KEYS_N_DOWN="${KEYS_N_DOWN:-"j"}"
KEYS_N_UP="${KEYS_N_UP:-"k"}"
KEYS_N_OUT="${KEYS_N_OUT:-"h"}"
KEYS_N_IN="${KEYS_N_IN:-"l"}"
KEYS_N_TOP="${KEYS_N_TOP:-"1"}"
KEYS_N_BOT="${KEYS_N_BOT:-"G"}"
KEYS_N_QUIT="${KEYS_N_QUIT:-"q"}"
KEYS_N_INSERT="${KEYS_N_INSERT:-"a,i,/"}"
KEYS_N_TOGGLE_PLAY_PAUSE="${KEYS_N_TOGGLE_PLAY_PAUSE:-"space"}"
KEYS_N_PLAY_NEXT="${KEYS_N_PLAY_NEXT:-"right"}"

View File

@@ -14,6 +14,7 @@ list_releasegroups() {
awk \
-F "\t" \
-v artist="$name" \
-v artistid="$1" \
-v file_local_releasegroups="${LOCALDATA_RELEASEGROUPS:-}" \
-v format_release="$RGV_RELEASE" \
-v format_release_w_artist="$RGV_RELEASE_W_ARTIST" \
@@ -41,7 +42,7 @@ list_releasegroups() {
"$AWK_RELEASEGROUPS" |
sort -n -r |
cut -d "$(printf '\t')" -f 2- |
column -t -s "$(printf '\t')" -E 0 |
column -t -s "$(printf '\t')" |
sed 's| \+\([0-9a-f-]\+\) \+\([0-9a-f-]\+\)$|\t\1\t\2|'
}
@@ -53,8 +54,7 @@ list_releases() {
artist="$(mb_releasegroup "$1" |
$JQ -r '."artist-credit" | map(([.name, .joinphrase]|join(""))) | join("")')"
mb_releasegroup_releases "$1" |
$JQ -r --arg rid "$1" '."releases"[] | [
$rid,
$JQ -r '."releases"[] | [
.id,
.status,
.date,
@@ -82,11 +82,12 @@ list_releases() {
-v release_format_artist="$RV_ARTIST" \
-v rg_artist="$artist" \
-v rg_title="$title" \
-v rgid="$1" \
-v format_local="$FORMAT_LOCAL" \
"$AWK_RELEASES" |
sort -n -r |
cut -d "$(printf '\t')" -f 2- |
column -t -s "$(printf '\t')" -E 0 |
column -t -s "$(printf '\t')" |
sed 's| \+\([0-9a-f-]\+\) \+\([0-9a-f-]\+\):\(.*$\)$|\t\1\t\2\t\3|'
}
@@ -123,7 +124,7 @@ list_recordings() {
"$AWK_RECORDINGS" |
sort -k1,1n -k2,2g |
cut -d "$(printf '\t')" -f 2- |
column -t -s "$(printf '\t')" -R 3,4,7 -E 0 |
column -t -s "$(printf '\t')" -R 3,4,7 |
sed 's| \+\([0-9a-f-]\+\) \+\([0-9a-f-]\+\):\(.*$\)$|\t\1\t\2\t\3|'
if [ "${rectmp:-}" ] && [ -f "$rectmp" ]; then
rm -f "$rectmp"
@@ -198,7 +199,7 @@ list_artists_from_json() {
-v format_disambiguation="$AV_DISAMBIGUATION" \
-v format_local="$FORMAT_LOCAL" \
"$AWK_ARTISTS" |
column -t -s "$(printf '\t')" -E 0 |
column -t -s "$(printf '\t')" |
sed 's| \+\([0-9a-f-]\+\) \+\([0-9a-f-]\+\)$|\t\1\t\2|'
}
@@ -228,7 +229,7 @@ list_playlist() {
-v current_id="$current_id" \
"$AWK_RECORDINGS" |
cut -d "$(printf '\t')" -f 2- |
column -t -s "$(printf '\t')" -R 5 -E 0 |
column -t -s "$(printf '\t')" -R 5 |
sed 's| \+\([0-9a-f-]\+\) \+\([0-9a-f-]\+\):\(.*$\)$|\t\1\t\2\t\3|'
rm -f "$rectmp" "$mpvtmp"
}

View File

@@ -173,7 +173,6 @@ precompute_view() {
cut -d "$(printf '\t')" -f 1 "$LOCALDATA_RELEASES" |
while IFS= read -r rid; do
mb_release "$rid" | $JQ -r '[
"0",
.id,
.status,
.date,