changeset 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 694301cc71cc
children 51bf067de517
files transform/CSVFeatureWriter.cpp transform/CSVFeatureWriter.h
diffstat 2 files changed, 29 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/transform/CSVFeatureWriter.cpp	Tue Oct 14 10:07:02 2014 +0100
+++ b/transform/CSVFeatureWriter.cpp	Tue Oct 14 17:30:37 2014 +0100
@@ -33,7 +33,8 @@
                       SupportStdOut,
                       "csv"),
     m_separator(","),
-    m_sampleTiming(false)
+    m_sampleTiming(false),
+    m_endTimes(false)
 {
 }
 
@@ -62,6 +63,11 @@
     p.description = "Show timings as sample frame counts instead of in seconds.";
     p.hasArg = false;
     pl.push_back(p);
+    
+    p.name = "end-times";
+    p.description = "Show start and end time instead of start and duration, for features with duration.";
+    p.hasArg = false;
+    pl.push_back(p);
 
     return pl;
 }
@@ -79,6 +85,8 @@
             m_separator = i->second.c_str();
         } else if (i->first == "sample-timing") {
             m_sampleTiming = true;
+        } else if (i->first == "end-times") {
+            m_endTimes = true;
         }
     }
 }
@@ -118,8 +126,14 @@
 
             if (features[i].hasDuration) {
                 stream << m_separator;
-                stream << Vamp::RealTime::realTime2Frame
-                    (features[i].duration, transform.getSampleRate());
+                if (m_endTimes) {
+                    stream << Vamp::RealTime::realTime2Frame
+                        (features[i].timestamp + features[i].duration,
+                         transform.getSampleRate());
+                } else {
+                    stream << Vamp::RealTime::realTime2Frame
+                        (features[i].duration, transform.getSampleRate());
+                }
             }
 
         } else {
@@ -129,9 +143,17 @@
             stream << timestamp;
 
             if (features[i].hasDuration) {
-                QString duration = features[i].duration.toString().c_str();
-                duration.replace(QRegExp("^ +"), "");
-                stream << m_separator << duration;
+                if (m_endTimes) {
+                    QString endtime =
+                        (features[i].timestamp + features[i].duration)
+                        .toString().c_str();
+                    endtime.replace(QRegExp("^ +"), "");
+                    stream << m_separator << endtime;
+                } else {
+                    QString duration = features[i].duration.toString().c_str();
+                    duration.replace(QRegExp("^ +"), "");
+                    stream << m_separator << duration;
+                }
             }            
         }
 
--- a/transform/CSVFeatureWriter.h	Tue Oct 14 10:07:02 2014 +0100
+++ b/transform/CSVFeatureWriter.h	Tue Oct 14 17:30:37 2014 +0100
@@ -56,6 +56,7 @@
 private:
     QString m_separator;
     bool m_sampleTiming;
+    bool m_endTimes;
     QString m_prevPrintedTrackId;
 };