Mercurial > hg > sonic-annotator
changeset 169:859d8ec60e06 jams
Add setNofM logic which the JSON writer can use to write a list when sending multiple files' worth to a single target
author | Chris Cannam |
---|---|
date | Wed, 15 Oct 2014 16:05:15 +0100 (2014-10-15) |
parents | 3e30dbb68ca2 |
children | 3536342ac088 |
files | .hgsubstate runner/JAMSFeatureWriter.cpp runner/JAMSFeatureWriter.h runner/main.cpp tests/test-json-destinations/test-json-destinations.sh |
diffstat | 5 files changed, 60 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgsubstate Wed Oct 15 15:20:16 2014 +0100 +++ b/.hgsubstate Wed Oct 15 16:05:15 2014 +0100 @@ -1,3 +1,3 @@ d16f0fd6db6104d87882bc43788a3bb1b0f8c528 dataquay 879bdc878826bebec67130326f99397c430419b1 sv-dependency-builds -7d003fe48225c0fc4f811de075b4d7f0b9bc599b svcore +6b2a8b34e9d3d9a573af2ae303f33362e4c17784 svcore
--- a/runner/JAMSFeatureWriter.cpp Wed Oct 15 15:20:16 2014 +0100 +++ b/runner/JAMSFeatureWriter.cpp Wed Oct 15 16:05:15 2014 +0100 @@ -33,7 +33,9 @@ SupportStdOut, "json"), m_network(false), - m_networkRetrieved(false) + m_networkRetrieved(false), + m_n(1), + m_m(1) { } @@ -142,7 +144,13 @@ if (f.values.size() > 0) { d += QString(", \"value\": [ "); for (int j = 0; j < int(f.values.size()); ++j) { - d += QString("%1 ").arg(f.values[i]); + if (isnan(f.values[j])) { + d += "\"NaN\" "; + } else if (isinf(f.values[j])) { + d += "\"Inf\" "; + } else { + d += QString("%1 ").arg(f.values[j]); + } } d += "]"; } @@ -154,6 +162,18 @@ } void +JAMSFeatureWriter::setNofM(int n, int m) +{ + if (m_singleFileName != "" || m_stdout) { + m_n = n; + m_m = m; + } else { + m_n = 1; + m_m = 1; + } +} + +void JAMSFeatureWriter::finish() { for (FileStreamMap::const_iterator stri = m_streams.begin(); @@ -162,10 +182,6 @@ QTextStream *sptr = stri->second; QTextStream &stream = *sptr; - if (m_streamTracks[sptr].size() > 1) { - stream << "[\n"; - } - bool firstInStream = true; for (TrackIds::const_iterator tri = m_streamTracks[sptr].begin(); @@ -173,7 +189,13 @@ TrackId trackId = *tri; - if (!firstInStream) { + if (firstInStream) { + if (m_streamTracks[sptr].size() > 1 || (m_m > 1 && m_n == 1)) { + stream << "[\n"; + } + } + + if (!firstInStream || (m_m > 1 && m_n > 1)) { stream << ",\n"; } @@ -253,10 +275,12 @@ firstInStream = false; } - if (m_streamTracks[sptr].size() > 1) { - stream << "\n]"; + if (!firstInStream) { + if (m_streamTracks[sptr].size() > 1 || (m_m > 1 && m_n == m_m)) { + stream << "\n]"; + } + stream << "\n"; } - stream << "\n"; } m_streamTracks.clear();
--- a/runner/JAMSFeatureWriter.h Wed Oct 15 15:20:16 2014 +0100 +++ b/runner/JAMSFeatureWriter.h Wed Oct 15 16:05:15 2014 +0100 @@ -36,6 +36,8 @@ virtual void setTrackMetadata(QString trackid, TrackMetadata metadata); + virtual void setNofM(int, int); + virtual void write(QString trackid, const Transform &transform, const Vamp::Plugin::OutputDescriptor &output, @@ -95,6 +97,8 @@ bool m_network; bool m_networkRetrieved; + int m_n; + int m_m; }; #endif
--- a/runner/main.cpp Wed Oct 15 15:20:16 2014 +0100 +++ b/runner/main.cpp Wed Oct 15 16:05:15 2014 +0100 @@ -939,17 +939,25 @@ } if (multiplex) { try { + for (int i = 0; i < (int)writers.size(); ++i) { + writers[i]->setNofM(1, 1); + } manager.extractFeaturesMultiplexed(goodSources); } catch (const std::exception &e) { cerr << "ERROR: Feature extraction failed: " << e.what() << endl; } } else { + int n = 0; for (QStringList::const_iterator i = goodSources.begin(); i != goodSources.end(); ++i) { std::cerr << "Extracting features for: \"" << i->toStdString() << "\"" << std::endl; + ++n; try { + for (int j = 0; j < (int)writers.size(); ++j) { + writers[j]->setNofM(n, goodSources.size()); + } manager.extractFeatures(*i); } catch (const std::exception &e) { cerr << "ERROR: Feature extraction failed for \""
--- a/tests/test-json-destinations/test-json-destinations.sh Wed Oct 15 15:20:16 2014 +0100 +++ b/tests/test-json-destinations/test-json-destinations.sh Wed Oct 15 16:05:15 2014 +0100 @@ -23,11 +23,22 @@ transformdir=$mypath/transforms +failshow() { + echo "Test failed: $1" + if [ -n "$2" ]; then + echo "Output follows:" + echo "--" + cat $2 + echo "--" + fi + exit 1 +} + check_json() { test -f $1 || \ fail "Fails to write output to expected location $1 for $2" - cat $1 | json_verify || \ - fail "Writes invalid JSON to location $1 for $2" + cat $1 | json_verify -q || \ + failshow "Writes invalid JSON to location $1 for $2" $1 rm -f $1 }