Skip to content

Commit

Permalink
feat(translate.sh): --no-bar-numbers cmdline switch and other enhance…
Browse files Browse the repository at this point in the history
…ments

Signed-off-by: Davide Madrisan <[email protected]>
  • Loading branch information
madrisan committed Mar 4, 2024
1 parent 91ce782 commit 7283c61
Showing 1 changed file with 59 additions and 10 deletions.
69 changes: 59 additions & 10 deletions lyinit/addons/translate.sh
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" ] \
Expand All @@ -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@%.*@@;
Expand All @@ -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;"
Expand Down

0 comments on commit 7283c61

Please sign in to comment.