annotate test/test-layer-exports.sh @ 2508:c68b431ca101

Pull out Provider structure for plugin source metadata
author Chris Cannam
date Mon, 20 Apr 2020 18:47:23 +0100
parents 048d9eed0a1f
children 03b12584af5b
rev   line source
Chris@2438 1 #!/bin/bash
Chris@2438 2 #
Chris@2438 3 # Regression tests for layer export to CSV
Chris@2438 4 # Must be run from directory that contains this script
Chris@2438 5
Chris@2438 6 # NB hardcoded assumptions here about the contents of the session
Chris@2438 7 # file, so the session file (all.sv) is also hardcoded. The session is
Chris@2438 8 # expected to consist of:
Chris@2438 9 #
Chris@2438 10 # - pane 1 with 3 layers (ruler, waveform, instants)
Chris@2438 11 # - pane 2 with 3 layers (ruler, waveform, values)
Chris@2438 12 # - pane 3 with 3 layers (ruler, image, regions)
Chris@2438 13 # - pane 4 with 3 layers (ruler, text, notes)
Chris@2438 14 # - pane 5 with 2 layers (ruler, 3d plot)
Chris@2438 15 # - pane 6 with 3 layers (ruler, spectrogram, boxes)
Chris@2438 16 # - pane 7 with 2 layers (ruler, peak frequency spectrogram)
Chris@2438 17
Chris@2438 18 set -e
Chris@2438 19
Chris@2438 20 if [ -n "$1" ]; then
Chris@2438 21 echo "Usage: $0" 1>&2
Chris@2438 22 exit 2
Chris@2438 23 fi
Chris@2438 24
Chris@2438 25 set -u
Chris@2438 26
Chris@2438 27 sv="../sonic-visualiser"
Chris@2438 28 if [ ! -f "$sv" -o ! -x "$sv" ]; then
Chris@2438 29 echo "This script must be run from the sonic-visualiser/test directory" 1>&2
Chris@2438 30 exit 1
Chris@2438 31 fi
Chris@2438 32
Chris@2438 33 version=$("$sv" -v 2>&1)
Chris@2438 34 adequate=no
Chris@2438 35 case "$version" in
Chris@2438 36 [012].*) ;;
Chris@2438 37 3.[012]) ;;
Chris@2438 38 3.[012].*) ;;
Chris@2438 39 [1-9]*) adequate=yes ;;
Chris@2438 40 *) echo "Failed to query Sonic Visualiser version" 1>&2
Chris@2438 41 exit 1 ;;
Chris@2438 42 esac
Chris@2438 43 if [ "$adequate" = "no" ]; then
Chris@2438 44 echo "Sonic Visualiser version must be at least 3.3 (supporting --osc-script option)" 1>&2
Chris@2438 45 exit 1
Chris@2438 46 fi
Chris@2438 47
Chris@2438 48 session="all.sv"
Chris@2438 49
Chris@2438 50 if [ ! -f "$session" ]; then
Chris@2438 51 echo "Session file $session not found" 1>&2
Chris@2438 52 exit 1
Chris@2438 53 fi
Chris@2438 54
Chris@2438 55 tmpdir=$(mktemp -d)
Chris@2443 56 trap "rm -rf $tmpdir" 0
Chris@2438 57
Chris@2438 58 input="$tmpdir/input.sv"
Chris@2438 59
Chris@2438 60 cp "$session" "$input"
Chris@2438 61
Chris@2438 62 cat > "$tmpdir/script" <<EOF
Chris@2439 63 # Load the session file
Chris@2438 64 /open "$input"
Chris@2439 65
Chris@2439 66 # Select each exportable layer in turn and export to a CSV file
Chris@2438 67 /setcurrent 1 3
Chris@2438 68 /exportlayer "$tmpdir/instants.csv"
Chris@2438 69 /setcurrent 2 3
Chris@2438 70 /exportlayer "$tmpdir/values.csv"
Chris@2438 71 /setcurrent 3 2
Chris@2438 72 /exportlayer "$tmpdir/image.csv"
Chris@2438 73 /setcurrent 3 3
Chris@2438 74 /exportlayer "$tmpdir/regions.csv"
Chris@2438 75 /setcurrent 4 2
Chris@2438 76 /exportlayer "$tmpdir/text.csv"
Chris@2438 77 /setcurrent 4 3
Chris@2438 78 /exportlayer "$tmpdir/notes.csv"
Chris@2438 79 /setcurrent 5 2
Chris@2438 80 /exportlayer "$tmpdir/3dplot.csv"
Chris@2438 81 /setcurrent 6 2
Chris@2438 82 /exportlayer "$tmpdir/spectrogram.csv"
Chris@2438 83 /setcurrent 6 3
Chris@2438 84 /exportlayer "$tmpdir/boxes.csv"
Chris@2438 85 /setcurrent 7 2
Chris@2438 86 /exportlayer "$tmpdir/peakfreq.csv"
Chris@2439 87
Chris@2439 88 # Note layer can also be exported as MIDI
Chris@2439 89 /setcurrent 4 3
Chris@2439 90 /exportlayer "$tmpdir/notes.mid"
Chris@2439 91
Chris@2439 92 # Now test exporting only the contents of a (multiple) selection.
Chris@2439 93 # First set waveform layer as current, to avoid snapping the selection
Chris@2439 94 # to the contents of an annotation layer.
Chris@2439 95 /setcurrent 1 2
Chris@2439 96
Chris@2439 97 # Make a selection
Chris@2439 98 /select 8 10
Chris@2439 99 /addselect 14 16
Chris@2439 100
Chris@2439 101 # And repeat all the previous exports
Chris@2439 102 /setcurrent 1 3
Chris@2439 103 /exportlayer "$tmpdir/selected-instants.csv"
Chris@2439 104 /setcurrent 2 3
Chris@2439 105 /exportlayer "$tmpdir/selected-values.csv"
Chris@2439 106 /setcurrent 3 2
Chris@2439 107 /exportlayer "$tmpdir/selected-image.csv"
Chris@2439 108 /setcurrent 3 3
Chris@2439 109 /exportlayer "$tmpdir/selected-regions.csv"
Chris@2439 110 /setcurrent 4 2
Chris@2439 111 /exportlayer "$tmpdir/selected-text.csv"
Chris@2439 112 /setcurrent 4 3
Chris@2439 113 /exportlayer "$tmpdir/selected-notes.csv"
Chris@2439 114 /setcurrent 5 2
Chris@2439 115 /exportlayer "$tmpdir/selected-3dplot.csv"
Chris@2439 116 /setcurrent 6 2
Chris@2439 117 /exportlayer "$tmpdir/selected-spectrogram.csv"
Chris@2439 118 /setcurrent 6 3
Chris@2439 119 /exportlayer "$tmpdir/selected-boxes.csv"
Chris@2439 120 /setcurrent 7 2
Chris@2439 121 /exportlayer "$tmpdir/selected-peakfreq.csv"
Chris@2439 122
Chris@2439 123 /setcurrent 4 3
Chris@2439 124 /exportlayer "$tmpdir/selected-notes.mid"
Chris@2439 125
Chris@2444 126 # If we also zoom in vertically in the 3d plot, our export should
Chris@2444 127 # include only the zoomed area - check this
Chris@2444 128 /setcurrent 5 2
Chris@2444 129 /zoomvertical 0 12
Chris@2444 130 /exportlayer "$tmpdir/selected-zoomed-3dplot.csv"
Chris@2444 131
Chris@2438 132 /quit
Chris@2438 133 EOF
Chris@2438 134
Chris@2438 135 "$sv" --no-splash --osc-script "$tmpdir/script"
Chris@2438 136
Chris@2438 137 for type in instants values image regions text notes 3dplot spectrogram boxes peakfreq ; do
Chris@2439 138 for pfx in "" "selected-"; do
Chris@2439 139 actual="$tmpdir/$pfx$type.csv"
Chris@2439 140 expected="layers-expected/$pfx$type.csv"
Chris@2439 141 if ! cmp -s "$actual" "$expected" ; then
Chris@2439 142 echo
Chris@2439 143 if [ -z "$pfx" ]; then
Chris@2439 144 echo "Test failed for layer type \"$type\"!"
Chris@2439 145 else
Chris@2439 146 echo "Test failed for selected regions in layer type \"$type\"!"
Chris@2499 147 fi
Chris@2439 148 echo
Chris@2439 149 echo "Actual:"
Chris@2439 150 ls -l "$actual"
Chris@2439 151 echo "Expected:"
Chris@2439 152 ls -l "$expected"
Chris@2439 153 echo
Chris@2439 154 echo "Diff begins:"
Chris@2499 155 git diff --no-index --word-diff=color --word-diff-regex=. "$actual" "$expected" | head
Chris@2439 156 echo
Chris@2439 157 fi
Chris@2439 158 done
Chris@2439 159 done
Chris@2439 160
Chris@2444 161 for csv in selected-zoomed-3dplot.csv ; do
Chris@2444 162 actual="$tmpdir/$csv"
Chris@2444 163 expected="layers-expected/$csv"
Chris@2444 164 if ! cmp -s "$actual" "$expected" ; then
Chris@2444 165 echo
Chris@2444 166 echo "Test failed for \"$csv\"!"
Chris@2444 167 echo
Chris@2444 168 echo "Actual:"
Chris@2444 169 ls -l "$actual"
Chris@2444 170 echo "Expected:"
Chris@2444 171 ls -l "$expected"
Chris@2444 172 echo
Chris@2444 173 echo "Diff begins:"
Chris@2499 174 git diff --no-index --word-diff=color --word-diff-regex=. "$actual" "$expected" | head
Chris@2444 175 echo
Chris@2444 176 fi
Chris@2444 177 done
Chris@2444 178
Chris@2439 179 for other in notes.mid selected-notes.mid ; do
Chris@2439 180 actual="$tmpdir/$other"
Chris@2439 181 expected="layers-expected/$other"
Chris@2438 182 if ! cmp -s "$actual" "$expected" ; then
Chris@2438 183 echo
Chris@2439 184 if [ -z "$pfx" ]; then
Chris@2439 185 echo "Test failed for \"$other\"!"
Chris@2439 186 fi
Chris@2438 187 echo
Chris@2438 188 echo "Actual:"
Chris@2438 189 ls -l "$actual"
Chris@2439 190 echo "Expected:"
Chris@2438 191 ls -l "$expected"
Chris@2438 192 echo
Chris@2439 193 od -c "$actual" > "$actual".txt
Chris@2439 194 od -c "$expected" > "$tmpdir/expected-$other".txt
Chris@2439 195 echo
Chris@2439 196 echo "Diff:"
Chris@2499 197 git diff --no-index --word-diff=color --word-diff-regex=. "$actual".txt "expected-$other".txt | head
Chris@2438 198 echo
Chris@2438 199 fi
Chris@2438 200 done
Chris@2438 201