Skip to content

Instantly share code, notes, and snippets.

@benyanke
Last active May 9, 2017 21:36
Show Gist options
  • Save benyanke/8fbb9543e55ec82390d198ce7197596f to your computer and use it in GitHub Desktop.
Save benyanke/8fbb9543e55ec82390d198ce7197596f to your computer and use it in GitHub Desktop.
# Render all GABC files in current directory into PDF scores
function rendergabc() {
dir="`pwd`"
# Clean PDFs from folder
mkdir -p $dir/old >/dev/null 2>&1
rm $dir/old/* -f >/dev/null 2>&1
mv $dir/*.pdf $dir/old/ >/dev/null 2>&1
# Loop through each file in directory
for file in $dir/*.gabc; do
# Output filename to console
printf "Processing \"$gabcFilename\"\n"
# Parse filenames for easier use later
filename=$(basename "$file")
extension="${filename##*.}"
rootFilename="${filename%.*}"
pdfFilename="$rootFilename.pdf"
gabcFilename="$rootFilename.gabc"
# Parse data from file
height=$(cat $file | grep "%height: " | tail -n 1 | awk -F ":" '{print $2}' | awk -F ";" '{print $1}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//');
width=$(cat $file | grep "%width: " | tail -n 1 | awk -F ":" '{print $2}' | awk -F ";" '{print $1}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//');
spacing=$(cat $file | grep "%spacing: " | tail -n 1 | awk -F ":" '{print $2}' | awk -F ";" '{print $1}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//');
font=$(cat $file | grep "%font: " | tail -n 1 | awk -F ":" '{print $2}' | awk -F ";" '{print $1}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//');
score="$(cat $file)"
# Make request, store result locally
curl \
-s \
-G \
--location \
--data-urlencode "fmt=pdf" \
--data-urlencode "width=$width" \
--data-urlencode "height=$height" \
--data-urlencode "spacing=$spacing" \
--data-urlencode "croppdf=true" \
--data-urlencode "font=$font" \
--data-urlencode "gabc=$score" \
-o $pdfFilename \
"http://dev.illuminarepublications.com/gregorio/process.php" 2> /dev/null
done
# FORMAT:
#
# http://dev.illuminarepublications.com/gregorio/process.php?gabc=
# name%3A+Advent+I%2C+Friday%2C+Introit%3B%0D%0Auser-notes%3A+Dóminus+illuminátio+mea%3B%0D%0Acommentary%3A+Ps+27+%2826%29%3A+1%2C+2%3B%0D%0Aannotation%3A+II%3B%0D%0Acentering-scheme%3A+english%3B%0D%0A%25%25%0D%0A%28f3%29THE%28c%29+Lord%28ef%29+is%28f%29+my%28f%29+light%28f%29$
# font=OFLSortsMillGoudy&
# fmt=pdf&
# width=7.5&
# height=11&
# spacing=vichi&
# croppdf=true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment