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@2509
|
92 # And everything as SVL
|
Chris@2509
|
93 /setcurrent 1 3
|
Chris@2509
|
94 /exportlayer "$tmpdir/instants.svl"
|
Chris@2509
|
95 /setcurrent 2 3
|
Chris@2509
|
96 /exportlayer "$tmpdir/values.svl"
|
Chris@2509
|
97 /setcurrent 3 2
|
Chris@2509
|
98 /exportlayer "$tmpdir/image.svl"
|
Chris@2509
|
99 /setcurrent 3 3
|
Chris@2509
|
100 /exportlayer "$tmpdir/regions.svl"
|
Chris@2509
|
101 /setcurrent 4 2
|
Chris@2509
|
102 /exportlayer "$tmpdir/text.svl"
|
Chris@2509
|
103 /setcurrent 4 3
|
Chris@2509
|
104 /exportlayer "$tmpdir/notes.svl"
|
Chris@2509
|
105 /setcurrent 5 2
|
Chris@2509
|
106 /exportlayer "$tmpdir/3dplot.svl"
|
Chris@2509
|
107 /setcurrent 6 2
|
Chris@2509
|
108 /exportlayer "$tmpdir/spectrogram.svl"
|
Chris@2509
|
109 /setcurrent 6 3
|
Chris@2509
|
110 /exportlayer "$tmpdir/boxes.svl"
|
Chris@2509
|
111 /setcurrent 7 2
|
Chris@2509
|
112 /exportlayer "$tmpdir/peakfreq.svl"
|
Chris@2509
|
113
|
Chris@2509
|
114 # Now test exporting only the contents of a (multiple) selection. This
|
Chris@2509
|
115 # is only supported for CSV files.
|
Chris@2439
|
116 # First set waveform layer as current, to avoid snapping the selection
|
Chris@2439
|
117 # to the contents of an annotation layer.
|
Chris@2439
|
118 /setcurrent 1 2
|
Chris@2439
|
119
|
Chris@2439
|
120 # Make a selection
|
Chris@2439
|
121 /select 8 10
|
Chris@2439
|
122 /addselect 14 16
|
Chris@2439
|
123
|
Chris@2439
|
124 # And repeat all the previous exports
|
Chris@2439
|
125 /setcurrent 1 3
|
Chris@2439
|
126 /exportlayer "$tmpdir/selected-instants.csv"
|
Chris@2439
|
127 /setcurrent 2 3
|
Chris@2439
|
128 /exportlayer "$tmpdir/selected-values.csv"
|
Chris@2439
|
129 /setcurrent 3 2
|
Chris@2439
|
130 /exportlayer "$tmpdir/selected-image.csv"
|
Chris@2439
|
131 /setcurrent 3 3
|
Chris@2439
|
132 /exportlayer "$tmpdir/selected-regions.csv"
|
Chris@2439
|
133 /setcurrent 4 2
|
Chris@2439
|
134 /exportlayer "$tmpdir/selected-text.csv"
|
Chris@2439
|
135 /setcurrent 4 3
|
Chris@2439
|
136 /exportlayer "$tmpdir/selected-notes.csv"
|
Chris@2439
|
137 /setcurrent 5 2
|
Chris@2439
|
138 /exportlayer "$tmpdir/selected-3dplot.csv"
|
Chris@2439
|
139 /setcurrent 6 2
|
Chris@2439
|
140 /exportlayer "$tmpdir/selected-spectrogram.csv"
|
Chris@2439
|
141 /setcurrent 6 3
|
Chris@2439
|
142 /exportlayer "$tmpdir/selected-boxes.csv"
|
Chris@2439
|
143 /setcurrent 7 2
|
Chris@2439
|
144 /exportlayer "$tmpdir/selected-peakfreq.csv"
|
Chris@2439
|
145
|
Chris@2439
|
146 /setcurrent 4 3
|
Chris@2439
|
147 /exportlayer "$tmpdir/selected-notes.mid"
|
Chris@2439
|
148
|
Chris@2444
|
149 # If we also zoom in vertically in the 3d plot, our export should
|
Chris@2444
|
150 # include only the zoomed area - check this
|
Chris@2444
|
151 /setcurrent 5 2
|
Chris@2444
|
152 /zoomvertical 0 12
|
Chris@2444
|
153 /exportlayer "$tmpdir/selected-zoomed-3dplot.csv"
|
Chris@2444
|
154
|
Chris@2438
|
155 /quit
|
Chris@2438
|
156 EOF
|
Chris@2438
|
157
|
Chris@2438
|
158 "$sv" --no-splash --osc-script "$tmpdir/script"
|
Chris@2438
|
159
|
Chris@2438
|
160 for type in instants values image regions text notes 3dplot spectrogram boxes peakfreq ; do
|
Chris@2509
|
161 for format in csv svl ; do
|
Chris@2509
|
162 for pfx in "" "selected-"; do
|
Chris@2509
|
163 if [ "$format" = "svl" ] && [ -n "$pfx" ]; then
|
Chris@2509
|
164 continue
|
Chris@2499
|
165 fi
|
Chris@2509
|
166 actual="$tmpdir/$pfx$type.$format"
|
Chris@2509
|
167 expected="layers-expected/$pfx$type.$format"
|
Chris@2509
|
168 if ! cmp -s "$actual" "$expected" ; then
|
Chris@2509
|
169 echo
|
Chris@2509
|
170 if [ -z "$pfx" ]; then
|
Chris@2509
|
171 echo "Test failed for file type $format, layer type \"$type\"!"
|
Chris@2509
|
172 else
|
Chris@2509
|
173 echo "Test failed for selected regions in layer type \"$type\"!"
|
Chris@2509
|
174 fi
|
Chris@2509
|
175 echo
|
Chris@2509
|
176 echo "Actual:"
|
Chris@2509
|
177 ls -l "$actual"
|
Chris@2509
|
178 echo "Expected:"
|
Chris@2509
|
179 ls -l "$expected"
|
Chris@2509
|
180 echo
|
Chris@2509
|
181 echo "Diff begins:"
|
Chris@2509
|
182 git diff --no-index --word-diff=color --word-diff-regex=. "$actual" "$expected" | head
|
Chris@2509
|
183 echo
|
Chris@2509
|
184 fi
|
Chris@2509
|
185 done
|
Chris@2439
|
186 done
|
Chris@2439
|
187 done
|
Chris@2439
|
188
|
Chris@2444
|
189 for csv in selected-zoomed-3dplot.csv ; do
|
Chris@2444
|
190 actual="$tmpdir/$csv"
|
Chris@2444
|
191 expected="layers-expected/$csv"
|
Chris@2444
|
192 if ! cmp -s "$actual" "$expected" ; then
|
Chris@2444
|
193 echo
|
Chris@2444
|
194 echo "Test failed for \"$csv\"!"
|
Chris@2444
|
195 echo
|
Chris@2444
|
196 echo "Actual:"
|
Chris@2444
|
197 ls -l "$actual"
|
Chris@2444
|
198 echo "Expected:"
|
Chris@2444
|
199 ls -l "$expected"
|
Chris@2444
|
200 echo
|
Chris@2444
|
201 echo "Diff begins:"
|
Chris@2499
|
202 git diff --no-index --word-diff=color --word-diff-regex=. "$actual" "$expected" | head
|
Chris@2444
|
203 echo
|
Chris@2444
|
204 fi
|
Chris@2444
|
205 done
|
Chris@2444
|
206
|
Chris@2439
|
207 for other in notes.mid selected-notes.mid ; do
|
Chris@2439
|
208 actual="$tmpdir/$other"
|
Chris@2439
|
209 expected="layers-expected/$other"
|
Chris@2438
|
210 if ! cmp -s "$actual" "$expected" ; then
|
Chris@2438
|
211 echo
|
Chris@2439
|
212 if [ -z "$pfx" ]; then
|
Chris@2439
|
213 echo "Test failed for \"$other\"!"
|
Chris@2439
|
214 fi
|
Chris@2438
|
215 echo
|
Chris@2438
|
216 echo "Actual:"
|
Chris@2438
|
217 ls -l "$actual"
|
Chris@2439
|
218 echo "Expected:"
|
Chris@2438
|
219 ls -l "$expected"
|
Chris@2438
|
220 echo
|
Chris@2439
|
221 od -c "$actual" > "$actual".txt
|
Chris@2439
|
222 od -c "$expected" > "$tmpdir/expected-$other".txt
|
Chris@2439
|
223 echo
|
Chris@2439
|
224 echo "Diff:"
|
Chris@2499
|
225 git diff --no-index --word-diff=color --word-diff-regex=. "$actual".txt "expected-$other".txt | head
|
Chris@2438
|
226 echo
|
Chris@2438
|
227 fi
|
Chris@2438
|
228 done
|
Chris@2438
|
229
|