Mercurial > hg > sonic-annotator
comparison runner/JAMSFeatureWriter.cpp @ 165:d0be35a305cc jams
Add transform metadata to output
author | Chris Cannam |
---|---|
date | Wed, 15 Oct 2014 13:30:25 +0100 |
parents | 447230267c0d |
children | e98b1abeb792 |
comparison
equal
deleted
inserted
replaced
164:ddc47a055434 | 165:d0be35a305cc |
---|---|
123 QString json | 123 QString json |
124 ("\"%1\": [ { \n" | 124 ("\"%1\": [ { \n" |
125 " \"annotation_metadata\": {\n" | 125 " \"annotation_metadata\": {\n" |
126 " \"annotation_tools\": \"Sonic Annotator v%2\",\n" | 126 " \"annotation_tools\": \"Sonic Annotator v%2\",\n" |
127 " \"data_source\": \"Automatic feature extraction\",\n" | 127 " \"data_source\": \"Automatic feature extraction\",\n" |
128 " \"annotator\": { \"transform_id\": \"%3\" }\n" | 128 " \"annotator\": {\n" |
129 "%3" | |
130 " },\n" | |
129 " },\n" | 131 " },\n" |
130 " \"data\": ["); | 132 " \"data\": ["); |
131 m_data[tt] = json | 133 m_data[tt] = json |
132 .arg(getTaskKey(m_tasks[transformId])) | 134 .arg(getTaskKey(m_tasks[transformId])) |
133 .arg(RUNNER_VERSION) | 135 .arg(RUNNER_VERSION) |
134 .arg(transformId); | 136 .arg(writeTransformToObjectContents(transform)); |
135 justBegun = true; | 137 justBegun = true; |
136 } | 138 } |
137 | 139 |
138 QString d = m_data[tt]; | 140 QString d = m_data[tt]; |
139 | 141 |
335 case MelodyTask: return "melody"; | 337 case MelodyTask: return "melody"; |
336 case PitchTask: return "pitch"; | 338 case PitchTask: return "pitch"; |
337 } | 339 } |
338 return "unknown"; | 340 return "unknown"; |
339 } | 341 } |
342 | |
343 QString | |
344 JAMSFeatureWriter::writeTransformToObjectContents(const Transform &t) | |
345 { | |
346 QString json; | |
347 QString stpl(" \"%1\": \"%2\",\n"); | |
348 QString ntpl(" \"%1\": %2,\n"); | |
349 | |
350 json += stpl.arg("plugin_id").arg(t.getPluginIdentifier()); | |
351 json += stpl.arg("output_id").arg(t.getOutput()); | |
352 | |
353 if (t.getSummaryType() != Transform::NoSummary) { | |
354 json += stpl.arg("summary_type") | |
355 .arg(Transform::summaryTypeToString(t.getSummaryType())); | |
356 } | |
357 | |
358 if (t.getPluginVersion() != QString()) { | |
359 json += stpl.arg("plugin_version").arg(t.getPluginVersion()); | |
360 } | |
361 | |
362 if (t.getProgram() != QString()) { | |
363 json += stpl.arg("program").arg(t.getProgram()); | |
364 } | |
365 | |
366 if (t.getStepSize() != 0) { | |
367 json += ntpl.arg("step_size").arg(t.getStepSize()); | |
368 } | |
369 | |
370 if (t.getBlockSize() != 0) { | |
371 json += ntpl.arg("block_size").arg(t.getBlockSize()); | |
372 } | |
373 | |
374 if (t.getWindowType() != HanningWindow) { | |
375 json += stpl.arg("window_type") | |
376 .arg(Window<float>::getNameForType(t.getWindowType()).c_str()); | |
377 } | |
378 | |
379 if (t.getStartTime() != RealTime::zeroTime) { | |
380 json += ntpl.arg("start").arg(t.getStartTime().toDouble()); | |
381 } | |
382 | |
383 if (t.getDuration() != RealTime::zeroTime) { | |
384 json += ntpl.arg("duration").arg(t.getDuration().toDouble()); | |
385 } | |
386 | |
387 if (t.getSampleRate() != 0) { | |
388 json += ntpl.arg("sample_rate").arg(t.getSampleRate()); | |
389 } | |
390 | |
391 if (!t.getParameters().empty()) { | |
392 json += QString(" \"parameters\": {\n"); | |
393 Transform::ParameterMap parameters = t.getParameters(); | |
394 for (Transform::ParameterMap::const_iterator i = parameters.begin(); | |
395 i != parameters.end(); ++i) { | |
396 QString name = i->first; | |
397 float value = i->second; | |
398 json += QString(" \"%1\": %2\n").arg(name).arg(value); | |
399 } | |
400 json += QString(" },\n"); | |
401 } | |
402 | |
403 // no trailing comma on final property: | |
404 json += QString(" \"transform_id\": \"%1\"\n").arg(t.getIdentifier()); | |
405 | |
406 return json; | |
407 } | |
408 |