changeset 196:082c3f21f49e

Simple MIDI writer test
author Chris Cannam
date Tue, 01 Sep 2015 15:51:07 +0100
parents 3f7c65f26559
children 3b7ec45abd1c
files .hgsubstate runner/MIDIFeatureWriter.cpp tests/include.sh tests/test-midi-writer/expected/curve-vsr.mid tests/test-midi-writer/expected/notes-regions.mid tests/test-midi-writer/test-midi-writer.sh tests/test.sh
diffstat 7 files changed, 68 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/.hgsubstate	Wed Aug 26 21:46:52 2015 +0100
+++ b/.hgsubstate	Tue Sep 01 15:51:07 2015 +0100
@@ -1,4 +1,4 @@
 d16f0fd6db6104d87882bc43788a3bb1b0f8c528 dataquay
 55ece8862b6d3a54aad271a53f9c1615e5d3bcf8 sv-dependency-builds
-067b60ae4861b8fdcdbf55f08f267074c268e0df svcore
+50210da3997c9e7e1832823d7e3a8e1188d98fc3 svcore
 632d90c185ecc8655f7a85ba58dc568351449dfd vamp-plugin-sdk
--- a/runner/MIDIFeatureWriter.cpp	Wed Aug 26 21:46:52 2015 +0100
+++ b/runner/MIDIFeatureWriter.cpp	Tue Sep 01 15:51:07 2015 +0100
@@ -22,6 +22,8 @@
 #include "base/Exceptions.h"
 #include "data/fileio/MIDIFileWriter.h"
 
+//#define DEBUG_MIDI_FEATURE_WRITER 1
+
 MIDIFeatureWriter::MIDIFeatureWriter() :
     FileFeatureWriter(SupportOneFilePerTrackTransform |
                       SupportOneFilePerTrack |
@@ -37,7 +39,7 @@
 string
 MIDIFeatureWriter::getDescription() const
 {
-    return "Write features to MIDI files. All features are written as MIDI notes. If a feature has at least one value, its first value will be used as the note pitch, the second value (if present) for velocity. If a feature has units of Hz, then its pitch will be converted from frequency to an integer value in MIDI range, otherwise it will be written directly. Multiple (up to 16) transforms can be written to a single MIDI file, where they will be given separate MIDI channel numbers.";
+    return "Write features to MIDI files. All features are written as MIDI notes. If a feature has at least one value, its first value will be used as the note pitch, the second value (if present) for velocity. If a feature has units of Hz, then its pitch will be converted from frequency to an integer value in MIDI range, otherwise it will simply be rounded to the nearest integer and written directly. Multiple (up to 16) transforms can be written to a single MIDI file, where they will be given separate MIDI channel numbers.";
 }
 
 MIDIFeatureWriter::ParameterList
@@ -108,6 +110,11 @@
         if (feature.hasDuration) {
             duration = Vamp::RealTime::realTime2Frame(feature.duration, sampleRate);
         }
+
+#ifdef DEBUG_MIDI_FEATURE_WRITER
+        cerr << "feature timestamp = " << feature.timestamp << ", sampleRate = " << sampleRate << ", frame = " << frame << endl;
+        cerr << "feature duration = " << feature.duration << ", sampleRate = " << sampleRate << ", duration = " << duration << endl;
+#endif
         
         int pitch = 60;
         if (feature.values.size() > 0) {
--- a/tests/include.sh	Wed Aug 26 21:46:52 2015 +0100
+++ b/tests/include.sh	Tue Sep 01 15:51:07 2015 +0100
@@ -48,20 +48,52 @@
     return `[ -z "$out" ]`
 }
 
+midicompare() {
+    a="$1"
+    b="$2"
+    od -c "$a" > "${a}__"
+    od -c "$b" > "${b}__"
+    cmp -s "${a}__" "${b}__"
+    rv=$?
+    rm "${a}__" "${b}__"
+    return $rv
+}
+
 faildiff() {
     echo "Test failed: $1"
     if [ -n "$2" -a -n "$3" ]; then
 	echo "Output follows:"
 	echo "--"
-	cat $2
+	cat "$2"
 	echo "--"
 	echo "Expected output follows:"
 	echo "--"
-	cat $3
+	cat "$3"
 	echo "--"
 	echo "Diff:"
 	echo "--"
-	sdiff -w78 $2 $3
+	sdiff -w78 "$2" "$3"
+	echo "--"
+    fi
+    exit 1
+}
+
+faildiff_od() {
+    echo "Test failed: $1"
+    if [ -n "$2" -a -n "$3" ]; then
+	echo "Output follows:"
+	echo "--"
+	od -c "$2"
+	echo "--"
+	echo "Expected output follows:"
+	echo "--"
+	od -c "$3"
+	echo "--"
+	echo "Diff:"
+	echo "--"
+	od -w8 -c "$3" > "${3}__"
+	od -w8 -c "$2" | sdiff -w78 - "${3}__"
+	rm "${3}__"
 	echo "--"
     fi
     exit 1
Binary file tests/test-midi-writer/expected/curve-vsr.mid has changed
Binary file tests/test-midi-writer/expected/notes-regions.mid has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-midi-writer/test-midi-writer.sh	Tue Sep 01 15:51:07 2015 +0100
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+. ../include.sh
+
+infile=$audiopath/20sec-silence.wav
+tmpmidi=$mypath/tmp_1_$$.mid
+
+trap "rm -f $tmpmidi" 0
+
+for output in notes-regions curve-vsr; do
+
+    flag=""
+
+    $r -d "$testplug:$output" -w midi --midi-one-file "$tmpmidi" --midi-force "$infile" 2>/dev/null || \
+	fail "Failed to run for plugin $testplug with output $output and no additional flags"
+
+    midicompare "$tmpmidi" "$mypath/expected/$output.mid" || \
+	faildiff_od "Output differs from expected for output $output" "$tmpmidi" "$mypath/expected/$output.mid"
+
+done
+
+exit 0
+
--- a/tests/test.sh	Wed Aug 26 21:46:52 2015 +0100
+++ b/tests/test.sh	Tue Sep 01 15:51:07 2015 +0100
@@ -16,6 +16,7 @@
     lab-writer \
     lab-destinations \
     midi-destinations \
+    midi-writer \
     json-destinations \
     json-writer \
     summaries \