comparison test/test-layer-exports.sh @ 2439:882848f168e8 spectrogram-export

Add tests for exporting selected region only
author Chris Cannam
date Wed, 08 Jan 2020 15:36:12 +0000
parents a5ec35798c9e
children 935107f64e5f
comparison
equal deleted inserted replaced
2438:a5ec35798c9e 2439:882848f168e8
51 echo "Session file $session not found" 1>&2 51 echo "Session file $session not found" 1>&2
52 exit 1 52 exit 1
53 fi 53 fi
54 54
55 tmpdir=$(mktemp -d) 55 tmpdir=$(mktemp -d)
56 trap "rm -rf $tmpdir" 0 56 #trap "rm -rf $tmpdir" 0
57 57
58 input="$tmpdir/input.sv" 58 input="$tmpdir/input.sv"
59 59
60 cp "$session" "$input" 60 cp "$session" "$input"
61 61
62 cat > "$tmpdir/script" <<EOF 62 cat > "$tmpdir/script" <<EOF
63 # Load the session file
63 /open "$input" 64 /open "$input"
65
66 # Select each exportable layer in turn and export to a CSV file
64 /setcurrent 1 3 67 /setcurrent 1 3
65 /exportlayer "$tmpdir/instants.csv" 68 /exportlayer "$tmpdir/instants.csv"
66 /setcurrent 2 3 69 /setcurrent 2 3
67 /exportlayer "$tmpdir/values.csv" 70 /exportlayer "$tmpdir/values.csv"
68 /setcurrent 3 2 71 /setcurrent 3 2
79 /exportlayer "$tmpdir/spectrogram.csv" 82 /exportlayer "$tmpdir/spectrogram.csv"
80 /setcurrent 6 3 83 /setcurrent 6 3
81 /exportlayer "$tmpdir/boxes.csv" 84 /exportlayer "$tmpdir/boxes.csv"
82 /setcurrent 7 2 85 /setcurrent 7 2
83 /exportlayer "$tmpdir/peakfreq.csv" 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 # Now test exporting only the contents of a (multiple) selection.
93 # First set waveform layer as current, to avoid snapping the selection
94 # to the contents of an annotation layer.
95 /setcurrent 1 2
96
97 # Make a selection
98 /select 8 10
99 /addselect 14 16
100
101 # And repeat all the previous exports
102 /setcurrent 1 3
103 /exportlayer "$tmpdir/selected-instants.csv"
104 /setcurrent 2 3
105 /exportlayer "$tmpdir/selected-values.csv"
106 /setcurrent 3 2
107 /exportlayer "$tmpdir/selected-image.csv"
108 /setcurrent 3 3
109 /exportlayer "$tmpdir/selected-regions.csv"
110 /setcurrent 4 2
111 /exportlayer "$tmpdir/selected-text.csv"
112 /setcurrent 4 3
113 /exportlayer "$tmpdir/selected-notes.csv"
114 /setcurrent 5 2
115 /exportlayer "$tmpdir/selected-3dplot.csv"
116 /setcurrent 6 2
117 /exportlayer "$tmpdir/selected-spectrogram.csv"
118 /setcurrent 6 3
119 /exportlayer "$tmpdir/selected-boxes.csv"
120 /setcurrent 7 2
121 /exportlayer "$tmpdir/selected-peakfreq.csv"
122
123 /setcurrent 4 3
124 /exportlayer "$tmpdir/selected-notes.mid"
125
84 /quit 126 /quit
85 EOF 127 EOF
86 128
87 "$sv" --no-splash --osc-script "$tmpdir/script" 129 "$sv" --no-splash --osc-script "$tmpdir/script"
88 130
89 for type in instants values image regions text notes 3dplot spectrogram boxes peakfreq ; do 131 for type in instants values image regions text notes 3dplot spectrogram boxes peakfreq ; do
90 actual="$tmpdir/$type.csv" 132 for pfx in "" "selected-"; do
91 expected="layers-expected/$type.csv" 133 actual="$tmpdir/$pfx$type.csv"
134 expected="layers-expected/$pfx$type.csv"
135 if ! cmp -s "$actual" "$expected" ; then
136 echo
137 if [ -z "$pfx" ]; then
138 echo "Test failed for layer type \"$type\"!"
139 else
140 echo "Test failed for selected regions in layer type \"$type\"!"
141 fi
142 echo
143 echo "Actual:"
144 ls -l "$actual"
145 echo "Expected:"
146 ls -l "$expected"
147 echo
148 echo "Diff begins:"
149 diff -u1 "$actual" "$expected" | head
150 echo
151 fi
152 done
153 done
154
155 for other in notes.mid selected-notes.mid ; do
156 actual="$tmpdir/$other"
157 expected="layers-expected/$other"
92 if ! cmp -s "$actual" "$expected" ; then 158 if ! cmp -s "$actual" "$expected" ; then
93 echo 159 echo
94 echo "Test failed for layer type \"$type\"!" 160 if [ -z "$pfx" ]; then
161 echo "Test failed for \"$other\"!"
162 fi
95 echo 163 echo
96 echo "Actual:" 164 echo "Actual:"
97 ls -l "$actual" 165 ls -l "$actual"
98 echo "Expected" 166 echo "Expected:"
99 ls -l "$expected" 167 ls -l "$expected"
100 echo 168 echo
101 echo "Diff begins:" 169 od -c "$actual" > "$actual".txt
102 diff -u1 "$actual" "$expected" | head 170 od -c "$expected" > "$tmpdir/expected-$other".txt
171 echo
172 echo "Diff:"
173 diff -u1 "$actual".txt "$tmpdir/expected-$other".txt
103 echo 174 echo
104 fi 175 fi
105 done 176 done
106 177
107