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@2438
|
126 /quit
|
Chris@2438
|
127 EOF
|
Chris@2438
|
128
|
Chris@2438
|
129 "$sv" --no-splash --osc-script "$tmpdir/script"
|
Chris@2438
|
130
|
Chris@2438
|
131 for type in instants values image regions text notes 3dplot spectrogram boxes peakfreq ; do
|
Chris@2439
|
132 for pfx in "" "selected-"; do
|
Chris@2439
|
133 actual="$tmpdir/$pfx$type.csv"
|
Chris@2439
|
134 expected="layers-expected/$pfx$type.csv"
|
Chris@2439
|
135 if ! cmp -s "$actual" "$expected" ; then
|
Chris@2439
|
136 echo
|
Chris@2439
|
137 if [ -z "$pfx" ]; then
|
Chris@2439
|
138 echo "Test failed for layer type \"$type\"!"
|
Chris@2439
|
139 else
|
Chris@2439
|
140 echo "Test failed for selected regions in layer type \"$type\"!"
|
Chris@2439
|
141 fi
|
Chris@2439
|
142 echo
|
Chris@2439
|
143 echo "Actual:"
|
Chris@2439
|
144 ls -l "$actual"
|
Chris@2439
|
145 echo "Expected:"
|
Chris@2439
|
146 ls -l "$expected"
|
Chris@2439
|
147 echo
|
Chris@2439
|
148 echo "Diff begins:"
|
Chris@2439
|
149 diff -u1 "$actual" "$expected" | head
|
Chris@2439
|
150 echo
|
Chris@2439
|
151 fi
|
Chris@2439
|
152 done
|
Chris@2439
|
153 done
|
Chris@2439
|
154
|
Chris@2439
|
155 for other in notes.mid selected-notes.mid ; do
|
Chris@2439
|
156 actual="$tmpdir/$other"
|
Chris@2439
|
157 expected="layers-expected/$other"
|
Chris@2438
|
158 if ! cmp -s "$actual" "$expected" ; then
|
Chris@2438
|
159 echo
|
Chris@2439
|
160 if [ -z "$pfx" ]; then
|
Chris@2439
|
161 echo "Test failed for \"$other\"!"
|
Chris@2439
|
162 fi
|
Chris@2438
|
163 echo
|
Chris@2438
|
164 echo "Actual:"
|
Chris@2438
|
165 ls -l "$actual"
|
Chris@2439
|
166 echo "Expected:"
|
Chris@2438
|
167 ls -l "$expected"
|
Chris@2438
|
168 echo
|
Chris@2439
|
169 od -c "$actual" > "$actual".txt
|
Chris@2439
|
170 od -c "$expected" > "$tmpdir/expected-$other".txt
|
Chris@2439
|
171 echo
|
Chris@2439
|
172 echo "Diff:"
|
Chris@2439
|
173 diff -u1 "$actual".txt "$tmpdir/expected-$other".txt
|
Chris@2438
|
174 echo
|
Chris@2438
|
175 fi
|
Chris@2438
|
176 done
|
Chris@2438
|
177
|