comparison transform/CSVFeatureWriter.cpp @ 1000:ec6e69373997

Implement end-times option for CSV writer (not yet tested)
author Chris Cannam
date Tue, 14 Oct 2014 17:30:37 +0100
parents e25dc8d57565
children 51bf067de517
comparison
equal deleted inserted replaced
999:694301cc71cc 1000:ec6e69373997
31 FileFeatureWriter(SupportOneFilePerTrackTransform | 31 FileFeatureWriter(SupportOneFilePerTrackTransform |
32 SupportOneFileTotal | 32 SupportOneFileTotal |
33 SupportStdOut, 33 SupportStdOut,
34 "csv"), 34 "csv"),
35 m_separator(","), 35 m_separator(","),
36 m_sampleTiming(false) 36 m_sampleTiming(false),
37 m_endTimes(false)
37 { 38 {
38 } 39 }
39 40
40 CSVFeatureWriter::~CSVFeatureWriter() 41 CSVFeatureWriter::~CSVFeatureWriter()
41 { 42 {
60 61
61 p.name = "sample-timing"; 62 p.name = "sample-timing";
62 p.description = "Show timings as sample frame counts instead of in seconds."; 63 p.description = "Show timings as sample frame counts instead of in seconds.";
63 p.hasArg = false; 64 p.hasArg = false;
64 pl.push_back(p); 65 pl.push_back(p);
66
67 p.name = "end-times";
68 p.description = "Show start and end time instead of start and duration, for features with duration.";
69 p.hasArg = false;
70 pl.push_back(p);
65 71
66 return pl; 72 return pl;
67 } 73 }
68 74
69 void 75 void
77 cerr << i->first << " -> " << i->second << endl; 83 cerr << i->first << " -> " << i->second << endl;
78 if (i->first == "separator") { 84 if (i->first == "separator") {
79 m_separator = i->second.c_str(); 85 m_separator = i->second.c_str();
80 } else if (i->first == "sample-timing") { 86 } else if (i->first == "sample-timing") {
81 m_sampleTiming = true; 87 m_sampleTiming = true;
88 } else if (i->first == "end-times") {
89 m_endTimes = true;
82 } 90 }
83 } 91 }
84 } 92 }
85 93
86 void 94 void
116 stream << Vamp::RealTime::realTime2Frame 124 stream << Vamp::RealTime::realTime2Frame
117 (features[i].timestamp, transform.getSampleRate()); 125 (features[i].timestamp, transform.getSampleRate());
118 126
119 if (features[i].hasDuration) { 127 if (features[i].hasDuration) {
120 stream << m_separator; 128 stream << m_separator;
121 stream << Vamp::RealTime::realTime2Frame 129 if (m_endTimes) {
122 (features[i].duration, transform.getSampleRate()); 130 stream << Vamp::RealTime::realTime2Frame
131 (features[i].timestamp + features[i].duration,
132 transform.getSampleRate());
133 } else {
134 stream << Vamp::RealTime::realTime2Frame
135 (features[i].duration, transform.getSampleRate());
136 }
123 } 137 }
124 138
125 } else { 139 } else {
126 140
127 QString timestamp = features[i].timestamp.toString().c_str(); 141 QString timestamp = features[i].timestamp.toString().c_str();
128 timestamp.replace(QRegExp("^ +"), ""); 142 timestamp.replace(QRegExp("^ +"), "");
129 stream << timestamp; 143 stream << timestamp;
130 144
131 if (features[i].hasDuration) { 145 if (features[i].hasDuration) {
132 QString duration = features[i].duration.toString().c_str(); 146 if (m_endTimes) {
133 duration.replace(QRegExp("^ +"), ""); 147 QString endtime =
134 stream << m_separator << duration; 148 (features[i].timestamp + features[i].duration)
149 .toString().c_str();
150 endtime.replace(QRegExp("^ +"), "");
151 stream << m_separator << endtime;
152 } else {
153 QString duration = features[i].duration.toString().c_str();
154 duration.replace(QRegExp("^ +"), "");
155 stream << m_separator << duration;
156 }
135 } 157 }
136 } 158 }
137 159
138 if (summaryType != "") { 160 if (summaryType != "") {
139 stream << m_separator << summaryType.c_str(); 161 stream << m_separator << summaryType.c_str();