Skip to content

Commit eb0fec4

Browse files
committed
kv488: assert that marks are consistent over parts
Summary: We can add this script only now, because the first movement has been completed. Similarly, we will only be able to add checking for each later movement once it has also been completed. Test Plan: Running `./assert_consistent_marks.sh` or `make quickcheck` passes as is, but if a `\barNumberCheck #1` is changed to `\barNumberCheck #2`, then these invocations fail with one “missing” message and one “superfluous” message, as desired.
1 parent 178c919 commit eb0fec4

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

ftp/MozartWA/KV488/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ midi: \
2626
kv488-3-presto.midi
2727
quicktest quickcheck:
2828
./assert_barchecks.sh
29+
./assert_consistent_marks.sh
2930
test check: quicktest
3031
! $(MAKE) all -B PAPERSIZE=a4 2>&1 | grep -F -e err -e warn >&2
3132
! $(MAKE) all -B PAPERSIZE=letter 2>&1 | grep -F -e err -e warn >&2
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/sh
2+
# We require that the ``\solo'' and ``\tutti'' marks be applied to
3+
# exactly the same measures for each instrument (within a given
4+
# movement). This script verifies that invariant.
5+
#
6+
# Originally written by William Chargin <[email protected]>. Released
7+
# under the MIT License.
8+
set -eu
9+
10+
cd "$(dirname "$0")"
11+
12+
failed=0
13+
14+
# Find bar numbers on which a ``\solo'' or ``\tutti'' mark appears in
15+
# the LilyPond file given on standard input. Output is a
16+
# newline-delimited list of numbers.
17+
bar_numbers() {
18+
grep -h -B 1 '\\solo\|\\tutti' \
19+
| grep -F '\barNumberCheck' \
20+
| sed -e 's/.*#\([0-9]\+\).*/\1/' \
21+
| sort \
22+
| uniq
23+
}
24+
25+
# Check that ``\solo'' and ``\tutti'' marks are consistent within the
26+
# movement given by $1. If they are not, set the global `failed` to 1.
27+
check_movement() {
28+
movement="$1"
29+
canonical="${movement}"/piano.ily
30+
expected="$(mktemp)"
31+
actual="$(mktemp)"
32+
bar_numbers <"${canonical}" >"${expected}"
33+
for file in "${movement}"/*.ily; do
34+
if ! grep -qF '\relative' "${file}"; then
35+
# Not a piece of music.
36+
continue
37+
fi
38+
bar_numbers <"${file}" >"${actual}"
39+
if diff -q "${expected}" "${actual}" >/dev/null 2>/dev/null; then
40+
continue
41+
fi
42+
# We add fake line numbers to be compatible with tools that
43+
# expect "file:line: error" entries, such as Vim's quickfix
44+
# list. It's not possible to get an accurate line number for
45+
# missing marks, and it would be a bunch of extra work to get it
46+
# for superfluous marks, so we just put everything on line 1.
47+
comm -23 "${expected}" "${actual}" | sort -n | awk -v file="${file}" \
48+
'{ printf("%s:1: missing %s\n", file, $1) }' >&2
49+
comm -13 "${expected}" "${actual}" | sort -n | awk -v file="${file}" \
50+
'{ printf("%s:1: superfluous %s\n", file, $1) }' >&2
51+
failed=1
52+
done
53+
rm "${expected}" "${actual}"
54+
}
55+
56+
main() {
57+
check_movement 01_allegro
58+
exit "${failed}"
59+
}
60+
61+
main

ftp/MozartWA/KV488/create_makefile.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ makefile() {
118118
printf '\n'
119119
printf 'quicktest quickcheck:\n'
120120
printf '\t%s\n' ./assert_barchecks.sh
121+
printf '\t%s\n' ./assert_consistent_marks.sh
121122
printf 'test check: quicktest\n'
122123
# shellcheck disable=SC2016
123124
printf \

0 commit comments

Comments
 (0)