From a2445749777bcb8d3f11f26d956089db0eefcbe6 Mon Sep 17 00:00:00 2001 From: Gustav Eek Date: Thu, 22 Aug 2024 23:35:06 +0200 Subject: [PATCH] [tools] Adopt a2cho for CordPro 6 Alter order of replacements for environments: introduce '-- Start of ...' instead of '{start_of...'. ChordPro recognize '^--' as comment, and that is left untouched. Conversion is a multi step process: a-txt --> inter-txt --> inter-cho --> cho. Chordpro converts between the intermediary representations from ascii text to chordpro format. --- tools/a2cho | 72 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 56 insertions(+), 16 deletions(-) diff --git a/tools/a2cho b/tools/a2cho index 1b8ddfe..34af309 100644 --- a/tools/a2cho +++ b/tools/a2cho @@ -2,38 +2,78 @@ SCRIPT=a2cho +# Conversion is a multi step process: a-txt --> inter-txt --> +# inter-cho --> cho. Chordpro converts between the intermediary +# representations from ascii text to chordpro format. +# +# The purpose of the intermediary representaitons is to capture +# environments. +# +# ChordPro recognize '^--' as comment, and that is left untouched +# during conversion txt --> cho. + START_OF=' /^\[.*\]/,$ { - /^\[.*\]/ i{end_of_x}\n - $ a {end_of_x} + /^\[.*\]/ i -- End of x\n + $ a -- End of x } - s/^\[\(Chorus\|Pre-chorus\|Post-chorus\)[,.: ]*\(.*\)\].*/\{start_of_chorus: \2\}/ - s/^\[\(Verse\)[,.: ]*\(.*\)\].*/\{start_of_verse: \2\}/ - s/^\[\(Bridge\|Intro\|Outro\|Break\)[,.: ]*\(.*\)\].*/\{start_of_bridge: \2\}/ - s/^\[\(.*\)\].*/{comment: \1}/ + s/^\[\(Chorus\|Pre-chorus\|Post-chorus\)[,.: ]*\(.*\)\].*/\-- Start of chorus: \2/ + s/^\[\(Verse\)[,.: ]*\(.*\)\].*/\-- Start of verse: \2/ + s/^\[\(Bridge\|Intro\|Outro\|Break\)[,.: ]*\(.*\)\].*/\-- Start of bridge: \2/ + s/^\[\(.*\)\].*/-- Comment: \1/ ' END_OF=' - 1,/^{end_of_x/ { - /^{end_of_x/ {N; d} + 1,/^-- End of x/ { + /^-- End of x/ {N; d} } - /^{start_of_chorus/,/^{end_of_x/ { s/{end_of_x/{end_of_chorus/} - /^{start_of_verse/,/^{end_of_x/ { s/{end_of_x/{end_of_verse/} - /^{start_of_bridge/,/^{end_of_x/ { s/{end_of_x/{end_of_bridge/} - /^{comment/,/^{end_of_x/ {/^{end_of_x/ {N; d}} + /^-- Start of chorus/,/^-- End of x/ { s/-- End of x/-- End of chorus/} + /^-- Start of verse/,/^-- End of x/ { s/-- End of x/-- End of verse/} + /^-- Start of bridge/,/^-- End of x/ { s/-- End of x/-- End of bridge/} + /^-- Comment/,/^-- End of x/ {/^-- End of x/ {N; d}} s/:}/}/ ' VSPC=' /^$/ { N - /{start/ {N; s/\n$//} - /{end/ {s/^\n//} + /-- Start/ {N; s/\n$//} + /-- End/ {s/^\n//} + } +' +SNPT_ON=' + 1 { + i -- Title: snippet\n } ' +SNPT_OFF=' + 1 {N; d} +' +ENVS=' + s/^.*-- Start of \(\w*\)\([: ]*\)\([^{}]*\).*/{start_of_\1\2\3}/ + s/^.*-- End of \(\w*\)/{end_of_\1}/ + s/^.*-- Comment\([: ]*\)\([^{}]*\).*/{comment\1\2}/ + s/:}$/}/ +' +DUPL=' + /{start_of/ { + N; s/{start_of_\(\w*\)\([: ]*\)\([^{}]*\).*{end_of_.*}/{\1\2\3}/ + } +' +VSPC2=' + /^{.*}/ {N; s/} *\n{/}\n\n{/ } +' + +run=$(test -n "$XDG_RUNTIME_DIR" && echo "$XDG_RUNTIME_DIR" || echo "/tmp") function a2cho { cat - |\ - sed -e "$START_OF" | sed -e "$END_OF" | sed -e "$VSPC" |\ - a2crd + sed -e "$SNPT_ON" -e "$START_OF" | sed -e "$END_OF" | sed -e "$VSPC" \ + > $run/$SCRIPT.txt + chordpro \ + --no-strict --diagrams=none \ + -X --nosongconfig --nosysconfig --nouserconfig --noconfig \ + --output $run/$SCRIPT.cho $run/$SCRIPT.txt + cat $run/$SCRIPT.cho |\ + sed -e "$ENVS" | sed -e "$DUPL" | sed -e "$SNPT_OFF" -e "$VSPC2" } if [ ${0##*/} == $SCRIPT ]; then -- 2.39.2