annotate runner/DefaultFeatureWriter.cpp @ 399:a3912193ce69 tip

Default branch is now named default on git as well as hg, in case we ever want to switch to mirroring in the other direction
author Chris Cannam
date Thu, 27 Aug 2020 15:57:37 +0100
parents 0a56cf975768
children
rev   line source
Chris@0 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@0 2
Chris@0 3 /*
Chris@0 4 Sonic Annotator
Chris@0 5 A utility for batch feature extraction from audio files.
Chris@0 6 Mark Levy, Chris Sutton and Chris Cannam, Queen Mary, University of London.
Chris@0 7 Copyright 2007-2008 QMUL.
Chris@0 8
Chris@0 9 This program is free software; you can redistribute it and/or
Chris@0 10 modify it under the terms of the GNU General Public License as
Chris@0 11 published by the Free Software Foundation; either version 2 of the
Chris@0 12 License, or (at your option) any later version. See the file
Chris@0 13 COPYING included with this distribution for more information.
Chris@0 14 */
Chris@0 15
Chris@0 16 #include <iostream>
Chris@0 17 #include <map>
Chris@0 18
Chris@0 19 #include "DefaultFeatureWriter.h"
Chris@0 20
Chris@144 21 string
Chris@144 22 DefaultFeatureWriter::getDescription() const
Chris@144 23 {
Chris@144 24 return "Write features in a generic XML format, with <feature> or <summary> elements containing output name and some or all of timestamp, duration, values, and label.";
Chris@144 25 }
Chris@144 26
Chris@138 27 void DefaultFeatureWriter::write(QString,
Chris@138 28 const Transform &,
Chris@0 29 const Vamp::Plugin::OutputDescriptor& output,
Chris@0 30 const Vamp::Plugin::FeatureList& featureList,
Chris@0 31 std::string summaryType)
Chris@0 32 {
Chris@0 33 // generic XML output
Chris@0 34
Chris@0 35 /*
Chris@0 36
Chris@0 37 <feature>
Chris@0 38 <name>output.name</name>
Chris@0 39 <timestamp>feature.timestamp</timestamp>
Chris@0 40 <values>output.binName[0]:feature.value[0]...</values>
Chris@0 41 <label>feature.label</label>
Chris@0 42 </feature>
Chris@0 43
Chris@0 44 */
Chris@0 45
Chris@138 46 for (int i = 0; i < (int)featureList.size(); ++i) {
Chris@138 47
Chris@0 48 if (summaryType == "") {
Chris@326 49 std::cout << "<feature>" << std::endl;
Chris@0 50 } else {
Chris@326 51 std::cout << "<summary type=\"" << summaryType << "\">" << std::endl;
Chris@0 52 }
Chris@326 53 std::cout << "\t<name>" << output.name << "</name>" << std::endl;
Chris@0 54 if (featureList[i].hasTimestamp) {
Chris@326 55 std::cout << "\t<timestamp>" << featureList[i].timestamp << "</timestamp>" << std::endl;
Chris@0 56 }
Chris@0 57 if (featureList[i].hasDuration) {
Chris@326 58 std::cout << "\t<duration>" << featureList[i].duration << "</duration>" << std::endl;
Chris@0 59 }
Chris@0 60 if (featureList[i].values.size() > 0)
Chris@0 61 {
Chris@326 62 std::cout << "\t<values>";
Chris@138 63 for (int j = 0; j < (int)featureList[i].values.size(); ++j) {
Chris@0 64 if (j > 0)
Chris@326 65 std::cout << " ";
Chris@0 66 if (output.binNames.size() > 0)
Chris@326 67 std::cout << output.binNames[j] << ":";
Chris@326 68 std::cout << featureList[i].values[j];
Chris@0 69 }
Chris@326 70 std::cout << "</values>" << std::endl;
Chris@0 71 }
Chris@0 72 if (featureList[i].label.length() > 0)
Chris@326 73 std::cout << "\t<label>" << featureList[i].label << "</label>" << std::endl;
Chris@0 74 if (summaryType == "") {
Chris@326 75 std::cout << "</feature>" << std::endl;
Chris@0 76 } else {
Chris@326 77 std::cout << "</summary>" << std::endl;
Chris@0 78 }
Chris@0 79 }
Chris@0 80 }