Mercurial > hg > sonic-annotator
diff runner/LabFeatureWriter.cpp @ 206:704a8b27f3ed
Add & test the digits option in the Lab file writer
author | Chris Cannam |
---|---|
date | Tue, 03 Nov 2015 13:42:11 +0000 |
parents | 089f1a13963d |
children | ef03350baec7 |
line wrap: on
line diff
--- 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 != "") {