#!/bin/mksh # -*- mode: sh -*- #- # Copyright © 2007, 2008, 2012, 2013, 2014, 2018, 2019, 2021, 2022, # 2023 # mirabilos # # Provided that these terms and disclaimer and all copyright notices # are retained or reproduced in an accompanying document, permission # is granted to deal in this work without restriction, including un‐ # limited rights to use, publicly perform, distribute, sell, modify, # merge, give away, or sublicence. # # This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to # the utmost extent permitted by applicable law, neither express nor # implied; without malicious intent or gross negligence. In no event # may a licensor, author or contributor be held liable for indirect, # direct, other damage, loss, or other issues arising in any way out # of dealing in the work, even if advised of the possibility of such # damage or existence of a defect, except proven that it results out # of said person’s immediate fault when using the work as intended. #- # Prepare files for uploading to musescore.com # # Takes the .mscx; replaces fonts with those they have; indicates mu͒ # flavour in the header; applies per-file hacks as necessary; stores # as .mscz to t-export for uploading via GUI browser. set -x set -e set -o inherit-xtrace set -o pipefail unset LANGUAGE export LC_ALL=C.UTF-8 export TZ=UTC unset UNZIP ZIPOPT me=$(realpath "$0") function xhtml_fesc { REPLY=${1//'&'/'&'} REPLY=${REPLY//'<'/'<'} REPLY=${REPLY//'>'/'>'} REPLY=${REPLY//'"'/'"'} } if [[ -f $1 && -s $1 ]]; then set -A files for x in "$@"; do files+=("$(realpath "$x")") done usefiles=1 elif [[ -n $1 ]]; then print -ru2 "E: passed file does not exist" exit 1 else usefiles=0 fi owd=$PWD cd "$(realpath "$0/../../..")" wd=$(realpath .) rm -rf .git/t-export mkdir -p .git/t-export/.tmp/META-INF if (( usefiles )); then i=-1 while (( ++i < ${#files[*]} )); do files[i]=${files[i]#"$wd/"} done printf '%s\0' "${files[@]}" |& else git find music -name \*.mscx -o -name \*.mscz -print0 |& fi while IFS= read -r -p -d '' name; do bn=${name%.*} bn=${bn##*/} if [[ $name = *.mscz ]]; then ln -s ../../../"$name" .git/t-export/.tmp/"$bn".mscz "${me%/*}"/mscz x .git/t-export/.tmp/"$bn".mscz else cp "$name" .git/t-export/.tmp/"$bn".mscx fi done cd .git/t-export/.tmp IFS=$'\n' set -A kapitaelchen -- $(grep -l -F 'Gentium Basic Plus mbk' *.mscx) IFS=$' \t\n' rm -f *.mscz perl -pi -e ' s/Gentium/Gentium Basic/g; s/Gentium Basic Plus mbp/Gentium Plus/g; s/Gentium Basic Plus mbg/Gentium Basic/g; s/Gentium Basic Plus mbk/Gentium Basic/g; #XXX see ../2-fontmetrics s/Gentium Basic Plus/Gentium Plus/g; s/Inconsolatazi4varl_qu/Inconsolata/g; s!\$:daystamp: p\$P/\$n/' "$name" ;; ('Bortnjanski -- Tebe poem.mscx'|'Dowland -- Come again.mscx') perl -ni -e 'print unless /^ /../^ <\/Score>/' "$name" ;; } "${me%/*}"/mscz c "$name" mv "${name%x}z" ../ done cd .. rm -rf .tmp if (( ${#kapitaelchen[*]} )); then print -ru2 'W: won’t display correctly due to use of Kapitälchen font:' printf 'W: - %s\n' "${kapitaelchen[@]}" print -ru2 'N: refer to music/2-fontmetrics for details' fi