comparison runner/JAMSFeatureWriter.cpp @ 166:e98b1abeb792 jams

Better track metadata
author Chris Cannam
date Wed, 15 Oct 2014 13:52:25 +0100
parents d0be35a305cc
children e5873fb4ffb3
comparison
equal deleted inserted replaced
165:d0be35a305cc 166:e98b1abeb792
19 using Vamp::Plugin; 19 using Vamp::Plugin;
20 using Vamp::PluginBase; 20 using Vamp::PluginBase;
21 21
22 #include "base/Exceptions.h" 22 #include "base/Exceptions.h"
23 #include "rdf/PluginRDFIndexer.h" 23 #include "rdf/PluginRDFIndexer.h"
24
25 #include <QFileInfo>
24 26
25 #include "version.h" 27 #include "version.h"
26 28
27 JAMSFeatureWriter::JAMSFeatureWriter() : 29 JAMSFeatureWriter::JAMSFeatureWriter() :
28 FileFeatureWriter(SupportOneFilePerTrackTransform | 30 FileFeatureWriter(SupportOneFilePerTrackTransform |
73 } 75 }
74 76
75 void 77 void
76 JAMSFeatureWriter::setTrackMetadata(QString trackId, TrackMetadata metadata) 78 JAMSFeatureWriter::setTrackMetadata(QString trackId, TrackMetadata metadata)
77 { 79 {
78 QString json 80 m_metadata[trackId] = metadata;
79 ("\n\"file_metadata\": {\n"
80 " \"artist\": \"%1\",\n"
81 " \"title\": \"%2\"\n},\n");
82 m_metadata[trackId] = json.arg(metadata.maker).arg(metadata.title);
83 cerr << "setTrackMetadata: metadata is: " << m_metadata[trackId] << endl;
84 } 81 }
85 82
86 static double 83 static double
87 realTime2Sec(const Vamp::RealTime &r) 84 realTime2Sec(const Vamp::RealTime &r)
88 { 85 {
108 TrackTransformPair tt(trackId, transformId); 105 TrackTransformPair tt(trackId, transformId);
109 TrackTransformPair targetKey = getFilenameKey(trackId, transformId); 106 TrackTransformPair targetKey = getFilenameKey(trackId, transformId);
110 107
111 if (m_startedTargets.find(targetKey) == m_startedTargets.end()) { 108 if (m_startedTargets.find(targetKey) == m_startedTargets.end()) {
112 // Need to write track-level preamble 109 // Need to write track-level preamble
113 stream << "{" << m_metadata[trackId] << endl; 110 stream << "{\n";
111 stream << QString("\"file_metadata\": {\n"
112 " \"filename\": \"%1\"")
113 .arg(QFileInfo(trackId).fileName());
114
115 if (m_metadata.find(trackId) != m_metadata.end()) {
116 if (m_metadata[trackId].maker != "") {
117 stream << QString(",\n \"artist\": \"%1\"")
118 .arg(m_metadata[trackId].maker);
119 }
120 if (m_metadata[trackId].title != "") {
121 stream << QString(",\n \"title\": \"%1\"")
122 .arg(m_metadata[trackId].title);
123 }
124 }
125
126 stream << "\n},\n";
127
114 m_startedTargets.insert(targetKey); 128 m_startedTargets.insert(targetKey);
115 } 129 }
116 130
117 bool justBegun = false; 131 bool justBegun = false;
118 132