# HG changeset patch # User Chris Cannam # Date 1446558131 0 # Node ID 704a8b27f3ed8478ce0013d962942530f1c4e082 # Parent 7a287e5d5df61741181f682db4c5e9879bc51bd9 Add & test the digits option in the Lab file writer diff -r 7a287e5d5df6 -r 704a8b27f3ed runner/LabFeatureWriter.cpp --- a/runner/LabFeatureWriter.cpp Tue Nov 03 12:41:21 2015 +0000 +++ b/runner/LabFeatureWriter.cpp Tue Nov 03 13:42:11 2015 +0000 @@ -32,7 +32,8 @@ FileFeatureWriter(SupportOneFilePerTrackTransform | SupportStdOut, "lab"), - m_forceEnd(false) + m_forceEnd(false), + m_digits(6) { } @@ -58,6 +59,11 @@ p.hasArg = false; pl.push_back(p); + p.name = "digits"; + p.description = "Specify the number of significant digits to use when printing transform outputs. Outputs are represented internally using single-precision floating-point, so digits beyond the 8th or 9th place are usually meaningless. The default is 6."; + p.hasArg = true; + pl.push_back(p); + return pl; } @@ -70,6 +76,14 @@ i != params.end(); ++i) { if (i->first == "fill-ends") { m_forceEnd = true; + } else if (i->first == "digits") { + int digits = atoi(i->second.c_str()); + if (digits <= 0 || digits > 100) { + cerr << "LabFeatureWriter: ERROR: Invalid or out-of-range value for number of significant digits: " << i->second << endl; + cerr << "LabFeatureWriter: NOTE: Continuing with default settings" << endl; + } else { + m_digits = digits; + } } } } @@ -169,7 +183,7 @@ } for (unsigned int j = 0; j < f.values.size(); ++j) { - stream << sep << f.values[j]; + stream << sep << QString("%1").arg(f.values[j], 0, 'g', m_digits); } if (f.label != "") { diff -r 7a287e5d5df6 -r 704a8b27f3ed runner/LabFeatureWriter.h --- a/runner/LabFeatureWriter.h Tue Nov 03 12:41:21 2015 +0000 +++ b/runner/LabFeatureWriter.h Tue Nov 03 13:42:11 2015 +0000 @@ -17,8 +17,8 @@ COPYING included with this distribution for more information. */ -#ifndef _LAB_FEATURE_WRITER_H_ -#define _LAB_FEATURE_WRITER_H_ +#ifndef LAB_FEATURE_WRITER_H +#define LAB_FEATURE_WRITER_H #include #include @@ -65,6 +65,8 @@ void writeFeature(QTextStream &, const Vamp::Plugin::Feature &f, const Vamp::Plugin::Feature *optionalNextFeature); + + int m_digits; }; #endif diff -r 7a287e5d5df6 -r 704a8b27f3ed tests/test-lab-writer/expected/grid-oss-0.lab --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-lab-writer/expected/grid-oss-0.lab Tue Nov 03 13:42:11 2015 +0000 @@ -0,0 +1,20 @@ +0.000000000 0.0666667 0.1 0.133333 0.166667 0.2 0.233333 0.266667 0.3 0.333333 0.366667 "1 of 20 at 0" +0.023219954 0.1 0.133333 0.166667 0.2 0.233333 0.266667 0.3 0.333333 0.366667 0.4 "2 of 20 at 0.023" +0.046439909 0.133333 0.166667 0.2 0.233333 0.266667 0.3 0.333333 0.366667 0.4 0.433333 "3 of 20 at 0.046" +0.069659863 0.166667 0.2 0.233333 0.266667 0.3 0.333333 0.366667 0.4 0.433333 0.466667 "4 of 20 at 0.069" +0.092879818 0.2 0.233333 0.266667 0.3 0.333333 0.366667 0.4 0.433333 0.466667 0.5 "5 of 20 at 0.092" +0.116099773 0.233333 0.266667 0.3 0.333333 0.366667 0.4 0.433333 0.466667 0.5 0.533333 "6 of 20 at 0.116" +0.139319727 0.266667 0.3 0.333333 0.366667 0.4 0.433333 0.466667 0.5 0.533333 0.566667 "7 of 20 at 0.139" +0.162539682 0.3 0.333333 0.366667 0.4 0.433333 0.466667 0.5 0.533333 0.566667 0.6 "8 of 20 at 0.162" +0.185759637 0.333333 0.366667 0.4 0.433333 0.466667 0.5 0.533333 0.566667 0.6 0.633333 "9 of 20 at 0.185" +0.208979591 0.366667 0.4 0.433333 0.466667 0.5 0.533333 0.566667 0.6 0.633333 0.666667 "10 of 20 at 0.208" +0.232199546 0.4 0.433333 0.466667 0.5 0.533333 0.566667 0.6 0.633333 0.666667 0.7 "11 of 20 at 0.232" +0.255419501 0.433333 0.466667 0.5 0.533333 0.566667 0.6 0.633333 0.666667 0.7 0.733333 "12 of 20 at 0.255" +0.278639455 0.466667 0.5 0.533333 0.566667 0.6 0.633333 0.666667 0.7 0.733333 0.766667 "13 of 20 at 0.278" +0.301859410 0.5 0.533333 0.566667 0.6 0.633333 0.666667 0.7 0.733333 0.766667 0.8 "14 of 20 at 0.301" +0.325079365 0.533333 0.566667 0.6 0.633333 0.666667 0.7 0.733333 0.766667 0.8 0.833333 "15 of 20 at 0.325" +0.348299319 0.566667 0.6 0.633333 0.666667 0.7 0.733333 0.766667 0.8 0.833333 0.866667 "16 of 20 at 0.348" +0.371519274 0.6 0.633333 0.666667 0.7 0.733333 0.766667 0.8 0.833333 0.866667 0.9 "17 of 20 at 0.371" +0.394739229 0.633333 0.666667 0.7 0.733333 0.766667 0.8 0.833333 0.866667 0.9 0.933333 "18 of 20 at 0.394" +0.417959183 0.666667 0.7 0.733333 0.766667 0.8 0.833333 0.866667 0.9 0.933333 0.966667 "19 of 20 at 0.417" +0.441179138 0.7 0.733333 0.766667 0.8 0.833333 0.866667 0.9 0.933333 0.966667 1 "20 of 20 at 0.441" diff -r 7a287e5d5df6 -r 704a8b27f3ed tests/test-lab-writer/expected/grid-oss-2.lab --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-lab-writer/expected/grid-oss-2.lab Tue Nov 03 13:42:11 2015 +0000 @@ -0,0 +1,20 @@ +0.000000000 0.067 0.1 0.13 0.17 0.2 0.23 0.27 0.3 0.33 0.37 "1 of 20 at 0" +0.023219954 0.1 0.13 0.17 0.2 0.23 0.27 0.3 0.33 0.37 0.4 "2 of 20 at 0.023" +0.046439909 0.13 0.17 0.2 0.23 0.27 0.3 0.33 0.37 0.4 0.43 "3 of 20 at 0.046" +0.069659863 0.17 0.2 0.23 0.27 0.3 0.33 0.37 0.4 0.43 0.47 "4 of 20 at 0.069" +0.092879818 0.2 0.23 0.27 0.3 0.33 0.37 0.4 0.43 0.47 0.5 "5 of 20 at 0.092" +0.116099773 0.23 0.27 0.3 0.33 0.37 0.4 0.43 0.47 0.5 0.53 "6 of 20 at 0.116" +0.139319727 0.27 0.3 0.33 0.37 0.4 0.43 0.47 0.5 0.53 0.57 "7 of 20 at 0.139" +0.162539682 0.3 0.33 0.37 0.4 0.43 0.47 0.5 0.53 0.57 0.6 "8 of 20 at 0.162" +0.185759637 0.33 0.37 0.4 0.43 0.47 0.5 0.53 0.57 0.6 0.63 "9 of 20 at 0.185" +0.208979591 0.37 0.4 0.43 0.47 0.5 0.53 0.57 0.6 0.63 0.67 "10 of 20 at 0.208" +0.232199546 0.4 0.43 0.47 0.5 0.53 0.57 0.6 0.63 0.67 0.7 "11 of 20 at 0.232" +0.255419501 0.43 0.47 0.5 0.53 0.57 0.6 0.63 0.67 0.7 0.73 "12 of 20 at 0.255" +0.278639455 0.47 0.5 0.53 0.57 0.6 0.63 0.67 0.7 0.73 0.77 "13 of 20 at 0.278" +0.301859410 0.5 0.53 0.57 0.6 0.63 0.67 0.7 0.73 0.77 0.8 "14 of 20 at 0.301" +0.325079365 0.53 0.57 0.6 0.63 0.67 0.7 0.73 0.77 0.8 0.83 "15 of 20 at 0.325" +0.348299319 0.57 0.6 0.63 0.67 0.7 0.73 0.77 0.8 0.83 0.87 "16 of 20 at 0.348" +0.371519274 0.6 0.63 0.67 0.7 0.73 0.77 0.8 0.83 0.87 0.9 "17 of 20 at 0.371" +0.394739229 0.63 0.67 0.7 0.73 0.77 0.8 0.83 0.87 0.9 0.93 "18 of 20 at 0.394" +0.417959183 0.67 0.7 0.73 0.77 0.8 0.83 0.87 0.9 0.93 0.97 "19 of 20 at 0.417" +0.441179138 0.7 0.73 0.77 0.8 0.83 0.87 0.9 0.93 0.97 1 "20 of 20 at 0.441" diff -r 7a287e5d5df6 -r 704a8b27f3ed tests/test-lab-writer/expected/grid-oss-6.lab --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-lab-writer/expected/grid-oss-6.lab Tue Nov 03 13:42:11 2015 +0000 @@ -0,0 +1,20 @@ +0.000000000 0.0666667 0.1 0.133333 0.166667 0.2 0.233333 0.266667 0.3 0.333333 0.366667 "1 of 20 at 0" +0.023219954 0.1 0.133333 0.166667 0.2 0.233333 0.266667 0.3 0.333333 0.366667 0.4 "2 of 20 at 0.023" +0.046439909 0.133333 0.166667 0.2 0.233333 0.266667 0.3 0.333333 0.366667 0.4 0.433333 "3 of 20 at 0.046" +0.069659863 0.166667 0.2 0.233333 0.266667 0.3 0.333333 0.366667 0.4 0.433333 0.466667 "4 of 20 at 0.069" +0.092879818 0.2 0.233333 0.266667 0.3 0.333333 0.366667 0.4 0.433333 0.466667 0.5 "5 of 20 at 0.092" +0.116099773 0.233333 0.266667 0.3 0.333333 0.366667 0.4 0.433333 0.466667 0.5 0.533333 "6 of 20 at 0.116" +0.139319727 0.266667 0.3 0.333333 0.366667 0.4 0.433333 0.466667 0.5 0.533333 0.566667 "7 of 20 at 0.139" +0.162539682 0.3 0.333333 0.366667 0.4 0.433333 0.466667 0.5 0.533333 0.566667 0.6 "8 of 20 at 0.162" +0.185759637 0.333333 0.366667 0.4 0.433333 0.466667 0.5 0.533333 0.566667 0.6 0.633333 "9 of 20 at 0.185" +0.208979591 0.366667 0.4 0.433333 0.466667 0.5 0.533333 0.566667 0.6 0.633333 0.666667 "10 of 20 at 0.208" +0.232199546 0.4 0.433333 0.466667 0.5 0.533333 0.566667 0.6 0.633333 0.666667 0.7 "11 of 20 at 0.232" +0.255419501 0.433333 0.466667 0.5 0.533333 0.566667 0.6 0.633333 0.666667 0.7 0.733333 "12 of 20 at 0.255" +0.278639455 0.466667 0.5 0.533333 0.566667 0.6 0.633333 0.666667 0.7 0.733333 0.766667 "13 of 20 at 0.278" +0.301859410 0.5 0.533333 0.566667 0.6 0.633333 0.666667 0.7 0.733333 0.766667 0.8 "14 of 20 at 0.301" +0.325079365 0.533333 0.566667 0.6 0.633333 0.666667 0.7 0.733333 0.766667 0.8 0.833333 "15 of 20 at 0.325" +0.348299319 0.566667 0.6 0.633333 0.666667 0.7 0.733333 0.766667 0.8 0.833333 0.866667 "16 of 20 at 0.348" +0.371519274 0.6 0.633333 0.666667 0.7 0.733333 0.766667 0.8 0.833333 0.866667 0.9 "17 of 20 at 0.371" +0.394739229 0.633333 0.666667 0.7 0.733333 0.766667 0.8 0.833333 0.866667 0.9 0.933333 "18 of 20 at 0.394" +0.417959183 0.666667 0.7 0.733333 0.766667 0.8 0.833333 0.866667 0.9 0.933333 0.966667 "19 of 20 at 0.417" +0.441179138 0.7 0.733333 0.766667 0.8 0.833333 0.866667 0.9 0.933333 0.966667 1 "20 of 20 at 0.441" diff -r 7a287e5d5df6 -r 704a8b27f3ed tests/test-lab-writer/expected/grid-oss-fill-ends.lab --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-lab-writer/expected/grid-oss-fill-ends.lab Tue Nov 03 13:42:11 2015 +0000 @@ -0,0 +1,20 @@ +0.000000000 0.023219954 0.0666667 0.1 0.133333 0.166667 0.2 0.233333 0.266667 0.3 0.333333 0.366667 "1 of 20 at 0" +0.023219954 0.046439909 0.1 0.133333 0.166667 0.2 0.233333 0.266667 0.3 0.333333 0.366667 0.4 "2 of 20 at 0.023" +0.046439909 0.069659863 0.133333 0.166667 0.2 0.233333 0.266667 0.3 0.333333 0.366667 0.4 0.433333 "3 of 20 at 0.046" +0.069659863 0.092879818 0.166667 0.2 0.233333 0.266667 0.3 0.333333 0.366667 0.4 0.433333 0.466667 "4 of 20 at 0.069" +0.092879818 0.116099773 0.2 0.233333 0.266667 0.3 0.333333 0.366667 0.4 0.433333 0.466667 0.5 "5 of 20 at 0.092" +0.116099773 0.139319727 0.233333 0.266667 0.3 0.333333 0.366667 0.4 0.433333 0.466667 0.5 0.533333 "6 of 20 at 0.116" +0.139319727 0.162539682 0.266667 0.3 0.333333 0.366667 0.4 0.433333 0.466667 0.5 0.533333 0.566667 "7 of 20 at 0.139" +0.162539682 0.185759637 0.3 0.333333 0.366667 0.4 0.433333 0.466667 0.5 0.533333 0.566667 0.6 "8 of 20 at 0.162" +0.185759637 0.208979591 0.333333 0.366667 0.4 0.433333 0.466667 0.5 0.533333 0.566667 0.6 0.633333 "9 of 20 at 0.185" +0.208979591 0.232199546 0.366667 0.4 0.433333 0.466667 0.5 0.533333 0.566667 0.6 0.633333 0.666667 "10 of 20 at 0.208" +0.232199546 0.255419501 0.4 0.433333 0.466667 0.5 0.533333 0.566667 0.6 0.633333 0.666667 0.7 "11 of 20 at 0.232" +0.255419501 0.278639455 0.433333 0.466667 0.5 0.533333 0.566667 0.6 0.633333 0.666667 0.7 0.733333 "12 of 20 at 0.255" +0.278639455 0.301859410 0.466667 0.5 0.533333 0.566667 0.6 0.633333 0.666667 0.7 0.733333 0.766667 "13 of 20 at 0.278" +0.301859410 0.325079365 0.5 0.533333 0.566667 0.6 0.633333 0.666667 0.7 0.733333 0.766667 0.8 "14 of 20 at 0.301" +0.325079365 0.348299319 0.533333 0.566667 0.6 0.633333 0.666667 0.7 0.733333 0.766667 0.8 0.833333 "15 of 20 at 0.325" +0.348299319 0.371519274 0.566667 0.6 0.633333 0.666667 0.7 0.733333 0.766667 0.8 0.833333 0.866667 "16 of 20 at 0.348" +0.371519274 0.394739229 0.6 0.633333 0.666667 0.7 0.733333 0.766667 0.8 0.833333 0.866667 0.9 "17 of 20 at 0.371" +0.394739229 0.417959183 0.633333 0.666667 0.7 0.733333 0.766667 0.8 0.833333 0.866667 0.9 0.933333 "18 of 20 at 0.394" +0.417959183 0.441179138 0.666667 0.7 0.733333 0.766667 0.8 0.833333 0.866667 0.9 0.933333 0.966667 "19 of 20 at 0.417" +0.441179138 0.441179138 0.7 0.733333 0.766667 0.8 0.833333 0.866667 0.9 0.933333 0.966667 1 "20 of 20 at 0.441" diff -r 7a287e5d5df6 -r 704a8b27f3ed tests/test-lab-writer/expected/grid-oss-no-flags.lab --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-lab-writer/expected/grid-oss-no-flags.lab Tue Nov 03 13:42:11 2015 +0000 @@ -0,0 +1,20 @@ +0.000000000 0.0666667 0.1 0.133333 0.166667 0.2 0.233333 0.266667 0.3 0.333333 0.366667 "1 of 20 at 0" +0.023219954 0.1 0.133333 0.166667 0.2 0.233333 0.266667 0.3 0.333333 0.366667 0.4 "2 of 20 at 0.023" +0.046439909 0.133333 0.166667 0.2 0.233333 0.266667 0.3 0.333333 0.366667 0.4 0.433333 "3 of 20 at 0.046" +0.069659863 0.166667 0.2 0.233333 0.266667 0.3 0.333333 0.366667 0.4 0.433333 0.466667 "4 of 20 at 0.069" +0.092879818 0.2 0.233333 0.266667 0.3 0.333333 0.366667 0.4 0.433333 0.466667 0.5 "5 of 20 at 0.092" +0.116099773 0.233333 0.266667 0.3 0.333333 0.366667 0.4 0.433333 0.466667 0.5 0.533333 "6 of 20 at 0.116" +0.139319727 0.266667 0.3 0.333333 0.366667 0.4 0.433333 0.466667 0.5 0.533333 0.566667 "7 of 20 at 0.139" +0.162539682 0.3 0.333333 0.366667 0.4 0.433333 0.466667 0.5 0.533333 0.566667 0.6 "8 of 20 at 0.162" +0.185759637 0.333333 0.366667 0.4 0.433333 0.466667 0.5 0.533333 0.566667 0.6 0.633333 "9 of 20 at 0.185" +0.208979591 0.366667 0.4 0.433333 0.466667 0.5 0.533333 0.566667 0.6 0.633333 0.666667 "10 of 20 at 0.208" +0.232199546 0.4 0.433333 0.466667 0.5 0.533333 0.566667 0.6 0.633333 0.666667 0.7 "11 of 20 at 0.232" +0.255419501 0.433333 0.466667 0.5 0.533333 0.566667 0.6 0.633333 0.666667 0.7 0.733333 "12 of 20 at 0.255" +0.278639455 0.466667 0.5 0.533333 0.566667 0.6 0.633333 0.666667 0.7 0.733333 0.766667 "13 of 20 at 0.278" +0.301859410 0.5 0.533333 0.566667 0.6 0.633333 0.666667 0.7 0.733333 0.766667 0.8 "14 of 20 at 0.301" +0.325079365 0.533333 0.566667 0.6 0.633333 0.666667 0.7 0.733333 0.766667 0.8 0.833333 "15 of 20 at 0.325" +0.348299319 0.566667 0.6 0.633333 0.666667 0.7 0.733333 0.766667 0.8 0.833333 0.866667 "16 of 20 at 0.348" +0.371519274 0.6 0.633333 0.666667 0.7 0.733333 0.766667 0.8 0.833333 0.866667 0.9 "17 of 20 at 0.371" +0.394739229 0.633333 0.666667 0.7 0.733333 0.766667 0.8 0.833333 0.866667 0.9 0.933333 "18 of 20 at 0.394" +0.417959183 0.666667 0.7 0.733333 0.766667 0.8 0.833333 0.866667 0.9 0.933333 0.966667 "19 of 20 at 0.417" +0.441179138 0.7 0.733333 0.766667 0.8 0.833333 0.866667 0.9 0.933333 0.966667 1 "20 of 20 at 0.441" diff -r 7a287e5d5df6 -r 704a8b27f3ed tests/test-lab-writer/test-lab-writer.sh --- a/tests/test-lab-writer/test-lab-writer.sh Tue Nov 03 12:41:21 2015 +0000 +++ b/tests/test-lab-writer/test-lab-writer.sh Tue Nov 03 13:42:11 2015 +0000 @@ -7,7 +7,7 @@ trap "rm -f $tmplab" 0 -for output in notes-regions curve-vsr; do +for output in notes-regions curve-vsr grid-oss; do flag="" @@ -30,7 +30,7 @@ # actually redundant, it's equivalent to -w csv --csv-separator '\t' # --csv-end-times --csv-omit-filename -for output in notes-regions curve-vsr; do +for output in notes-regions curve-vsr grid-oss; do flag="" @@ -49,5 +49,17 @@ faildiff "Output differs from expected for CSV writer with output $output and $flag flag" "$tmplab" "$mypath/expected/$output-$flag.lab" done +for output in grid-oss; do + for digits in 0 6 2; do + + $r -d "$testplug:$output" -w lab --lab-stdout --lab-digits "$digits" "$infile" 2>/dev/null > "$tmplab" || \ + fail "Failed to run for plugin $testplug with output $output and digits $digits" + + csvcompare "$tmplab" "$mypath/expected/$output-$digits.lab" || \ + faildiff "Output differs from expected for CSV writer with output $output and digits $digits" "$tmplab" "$mypath/expected/$output-$digits.lab" + + done +done + exit 0