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