From 989074b79fa4d30c3b9dc420f3080c19a9092213 Mon Sep 17 00:00:00 2001 From: Gustav Eek Date: Tue, 20 Aug 2024 09:11:13 +0200 Subject: [PATCH] [tools] Initially commit the first versions of the conversion tools --- tools/a2cho | 41 +++++++++++++++++++++++++++++++++++++++++ tools/cho2tex | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 tools/a2cho create mode 100644 tools/cho2tex diff --git a/tools/a2cho b/tools/a2cho new file mode 100644 index 0000000..1b8ddfe --- /dev/null +++ b/tools/a2cho @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +SCRIPT=a2cho + +START_OF=' + /^\[.*\]/,$ { + /^\[.*\]/ 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}/ +' +END_OF=' + 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}} + s/:}/}/ +' +VSPC=' + /^$/ { + N + /{start/ {N; s/\n$//} + /{end/ {s/^\n//} + } +' + +function a2cho { + cat - |\ + sed -e "$START_OF" | sed -e "$END_OF" | sed -e "$VSPC" |\ + a2crd +} + +if [ ${0##*/} == $SCRIPT ]; then + cat - | a2cho +fi diff --git a/tools/cho2tex b/tools/cho2tex new file mode 100644 index 0000000..cbfff4a --- /dev/null +++ b/tools/cho2tex @@ -0,0 +1,45 @@ +#!/usr/bin/env bash + +SCRIPT=cho2tex + +SYMBOLS=' + s/\/\/:/\\leftrepeat/g + s/:\/\//\\rightrepeat/g +' +FIXES=' + s/\]$/\]\{\}/ + s/\]\[/\]\\quad[/g +' + +DIRECTIVES=' + s/{start_of_\([a-z]*\): \(.*\)}/\\begin{\1}[\2]/ + s/{start_of_\([a-z]*\)}/\\begin{\1}/ + s/{end_of_\([a-z]*\)}/\\end{\1}/ +' + +other=' + s/comment:/\\em / + s/title:/\\em / + 1 i \\\\begin\{guitar\} + $ a \\\\end\{guitar\} +' + +function cho2tex { + cat - |\ + sed -e "$SYMBOLS" -e "$FIXES" -e "$DIRECTIVES" +} + +if [ ${0##*/} == $SCRIPT ]; then + cat - | cho2tex +fi + +SED_1=' + s/\][ ~]*\[/] ~ [/g + s/\]$/]\n/ + /^{/ d +' + +SED_2=' + s/\]\(rivig\|katt,*\)/|]{\1}/g + s/\]\([rs]p*e-\)/|]{\1}/g +' -- 2.39.2