|
From: | Jacques Menu |
Subject: | A tool to substract a constant from bar numbers in LP code |
Date: | Thu, 5 Jun 2014 23:12:53 +0200 |
Hello folks, When scanning scores, I often end up with several movements in a single MusicXML file, with bar numbered sequentially, i.e. not restarting at 1 for each movement. In order to help having correct bars numbers, quite needed when proof-reading/compiling the code, I use the following bash/awk script. Hope this helps! — jmenu@castor:~/bin > cat too.txt e8 [ f8 e8 ] | % 29 f8 [ g8 g,8 ] | \barNumberCheck #30 jmenu@castor:~/bin > ./SubstractNFromLPEndOfLineBarNumbers 24 < too.txt e8 [ f8 e8 ] | % 5 f8 [ g8 g,8 ] | \barNumberCheck # 6 — jmenu@castor:~/bin > cat SubstractNFromLPEndOfLineBarNumbers #!/bin/bash # Jacques Menu - 05/06/2014 # Use awk twice in a pipe to handle "% nnn" and "\barnumber nnn" specs # as may occur in Lilypond code obtained from MusicXML with music2xml # if several scores were scanned at once. # Input comes from a file, and output goes to the standard output, # making it available to copy and paste somewhere. # The pattern specified for \barNumberCheck is special # because awk on Mac OS X is not gawk (and older) # The comparison between barNumber and delta is useful # in case some number have already been adjusted by hand, # otherwise negative bar numbers would be obtained # Tested on Mac OS X 10.9.3 and RedHat 6.5 # "-------------------------------------------------------------------------" # "--> Check usage and arguments" # "-------------------------------------------------------------------------" USAGE="--> Usage: $0 deltaInBarNumbers" if [ $# -ne 1 ]; then echo "" echo ${USAGE} echo exit fi DELTA=$1 # "-------------------------------------------------------------------------" # "--> Go for it" # "-------------------------------------------------------------------------" awk -F '%' -v delta=${DELTA} \ ' \ $2 ~ "[ ]*[0-9]+[ ]*" { \ barNumber = int($2); \ if (barNumber > delta) \ printf ("%s%% %d\n", $1, barNumber - delta); \ else \ printf ("%s\n", $0); \ } \ $2 !~ "[ ]*[0-9]+[ ]*" { \ printf ("%s\n", $0); \ }' \ | \ awk -F 'barNumberCheck #' -v delta=${DELTA} \ ' \ $2 ~ "[ ]*[0-9]+[ ]*" { \ # printf ("--> $1 = %s\n", $1); \ # printf ("--> $2 = %s\n", $2); \ barNumber = int($2); \ # printf ("--> barNumber = %d\n", barNumber); \ if (barNumber > delta) \ printf ("%sbarNumberCheck # %d\n", $1, barNumber - delta); \ else \ printf ("%s\n", $0); \ } \ $2 !~ "[ ]*[0-9]+[ ]*" { \ printf ("%s\n", $0); \ }' |
[Prev in Thread] | Current Thread | [Next in Thread] |