-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(translate.sh): --no-bar-numbers cmdline switch and other enhance…
…ments Signed-off-by: Davide Madrisan <[email protected]>
- Loading branch information
Showing
1 changed file
with
59 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,49 @@ | ||
#!/bin/bash | ||
# A very simple script for reformatting existing .ly code blocks | ||
# A very simple script for reformatting .ly code blocks | ||
# Copyright (c) 2023-2024 Davide Madrisan <[email protected]> | ||
|
||
# Usage: | ||
# translate.sh score.ly | ||
# translate.sh < score.ly | ||
# translate.sh [--no-bar-numbers] score.ly | ||
# translate.sh [--no-bar-numbers] < score.ly | ||
|
||
PROGNAME="${0##*/}" | ||
PROGPATH="${0%/*}" | ||
REVISION=2 | ||
|
||
usage () { | ||
cat <<__EOF | ||
Usage: $PROGNAME [--no-bar-numbers] score.ly | ||
$PROGNAME [--no-bar-numbers] < score.ly | ||
$PROGNAME --help | ||
Where: | ||
--no-bar-numbers: do not add bar numbers | ||
Example: | ||
$0 --no-bar-numbers score.ly | ||
__EOF | ||
} | ||
|
||
help () { | ||
cat <<__EOF | ||
$PROGNAME v$REVISION - a very simple for reformatting .ly code blocks | ||
Copyright (C) 2024 Davide Madrisan <[email protected]> | ||
__EOF | ||
|
||
usage | ||
} | ||
|
||
ly_bar_numbers=1 | ||
|
||
while test -n "$1"; do | ||
case "$1" in | ||
--help|-h) help; exit 0 ;; | ||
--no-bar-numbers) ly_bar_numbers="0" ;; | ||
esac | ||
shift | ||
done | ||
|
||
infile="$1" | ||
[ -n "$infile" -a ! -r "$infile" ] \ | ||
|
@@ -20,10 +59,12 @@ while read line; do | |
continue ;; | ||
esac | ||
let "linenum+=1" | ||
[ "$linenum" == 1 ] && echo " %1" | ||
(( $linenum % 5 == 0 )) && echo " %$linenum" | ||
#echo "[debug] $linenum \"$line\"" | ||
#echo "[debug] | ${line/|*/}" \ | ||
if [ "$ly_bar_numbers" = "1" ]; then | ||
[ "$linenum" == 1 ] && echo " %1" | ||
(( $linenum % 5 == 0 )) && echo " %$linenum" | ||
#echo "[debug] $linenum \"$line\"" | ||
#echo "[debug] | ${line/|*/}" \ | ||
fi | ||
echo " | $line" \ | ||
| sed "# remove comments | ||
s@%.*@@; | ||
|
@@ -50,13 +91,21 @@ while read line; do | |
s@\\\\tb @\\\\tieNeutral @g; | ||
s@\\\\td @\\\\tieDown @g; | ||
s@\\\\tu @\\\\tieUp @g; | ||
# some notation substs with unfortunately side effects | ||
s@\\\\halsdown @\\\\stemDown @g; | ||
s@\\\\halsneutral @\\\\stemNeutral @g; | ||
s@\\\\halsup @\\\\stemUp @g; | ||
s@\\\\staffdown @\\\\staffLower @g; | ||
s@\\\\staffup @\\\\staffUpper @g; | ||
# some notation substitutes with potential side effects | ||
# (so they must be manually enabled) | ||
#s@\([a-g]\+\)s\([0-9,'=~\.]*\) @\1is\2 @g; | ||
#s@\([a-g]\+\)f\([0-9,'=~\.]*\) @\1es\2 @g; | ||
#s@ h\([0-9,'=~\.\\]*\) @ b\1 @g;s@ h @ b @g;s@ h\$@ b@; | ||
# german notation to nederlands (default) | ||
s@ h\([0-9,'=~\.\(\[]*\) @ b\1 @g; | ||
s@ h\([0-9,'=~\.\(\[]*\)\([\\a-zA-Z]*\) @ b\1\2 @g;s@ h @ b @g;s@ h\$@ b@; | ||
s@ h\([0-9,'=~\.]*\)\([\\a-zA-Z]*\)\$@ b\1\2@g;s@ h\$@ b@; | ||
s@^ @ @; | ||
# remove final | (again) | ||
# remove final pipe char | (again) | ||
s/|[ ]*$//; | ||
# remove empty lines | ||
/^[ \t]*$/d;" | ||
|