changeset 1565:a6a31908bd13 spectrogram-export

Add support for a header line on delimited data output
author Chris Cannam
date Fri, 10 Jan 2020 14:30:26 +0000
parents 62b7699e5bfe
children 1f80a514ce29
files layer/Colour3DPlotExporter.cpp layer/Colour3DPlotExporter.h
diffstat 2 files changed, 82 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/layer/Colour3DPlotExporter.cpp	Fri Jan 10 11:12:33 2020 +0000
+++ b/layer/Colour3DPlotExporter.cpp	Fri Jan 10 14:30:26 2020 +0000
@@ -46,8 +46,84 @@
 }
 
 QString
+Colour3DPlotExporter::getDelimitedDataHeaderLine(QString delimiter,
+                                                 DataExportOptions) const
+{
+    auto model =
+        ModelById::getAs<DenseThreeDimensionalModel>(m_sources.source);
+    
+    auto layer = m_sources.verticalBinLayer;
+    auto provider = m_sources.provider;
+    
+    if (!model || !layer) {
+        SVCERR << "ERROR: Colour3DPlotExporter::getDelimitedDataHeaderLine: Source model and layer required" << endl;
+        return {};
+    }
+
+    int minbin = 0;
+    int sh = model->getHeight();
+    int nbins = sh;
+    
+    if (provider) {
+
+        minbin = layer->getIBinForY(provider, provider->getPaintHeight());
+        if (minbin >= sh) minbin = sh - 1;
+        if (minbin < 0) minbin = 0;
+    
+        nbins = layer->getIBinForY(provider, 0) - minbin + 1;
+        if (minbin + nbins > sh) nbins = sh - minbin;
+    }
+
+    QStringList list;
+
+    switch (m_params.timestampFormat) {
+    case TimestampFormat::None:
+        break;
+    case TimestampFormat::Frames:
+        list << "FRAME";
+        break;
+    case TimestampFormat::Seconds:
+        list << "TIME";
+        break;
+    }
+    
+    if (m_params.binDisplay == BinDisplay::PeakFrequencies) {
+        for (int i = 0; i < nbins/4; ++i) {
+            list << QString("FREQ %1").arg(i+1)
+                 << QString("MAG %1").arg(i+1);
+        }
+    } else {
+        bool hasValues = model->hasBinValues();
+        QString unit = (hasValues ? model->getBinValueUnit() : "");
+        for (int i = minbin; i < minbin + nbins; ++i) {
+            QString name = model->getBinName(i);
+            if (name == "") {
+                if (hasValues) {
+                    if (unit != "") {
+                        name = QString("BIN %1: %2 %3")
+                            .arg(i+1)
+                            .arg(model->getBinValue(i))
+                            .arg(unit);
+                    } else {
+                        name = QString("BIN %1: %2")
+                            .arg(i+1)
+                            .arg(model->getBinValue(i));
+                    }
+                } else {
+                    name = QString("BIN %1")
+                        .arg(i+1);
+                }
+            }
+            list << name;
+        }
+    }
+
+    return list.join(delimiter);
+}
+
+QString
 Colour3DPlotExporter::toDelimitedDataString(QString delimiter,
-                                            DataExportOptions options,
+                                            DataExportOptions,
                                             sv_frame_t startFrame,
                                             sv_frame_t duration) const
 {
@@ -55,8 +131,6 @@
 
     BinDisplay binDisplay = m_params.binDisplay;
 
-    (void)options; //!!!
-
     auto model =
         ModelById::getAs<DenseThreeDimensionalModel>(m_sources.source);
     auto fftModel =
@@ -77,23 +151,6 @@
     int minbin = 0;
     int sh = model->getHeight();
     int nbins = sh;
-
-    //!!! todo: consider what to do about the actual Colour 3D Plot
-    //!!! Layer. In the existing application, this is exported full
-    //!!! height. If we switch to using this code, we will be
-    //!!! exporting only the displayed height. This is backward
-    //!!! incompatible, but also not directly interpretable without
-    //!!! any guide in the exported file as to what the bin indices
-    //!!! are. Perhaps we should have a flag to export full height,
-    //!!! and default to using it.
-
-    //!!! todo: what about the other export types besides
-    //!!! delimited-data-string ?
-
-    //!!! todo: export selections only (we have the necessaries here,
-    //!!! but it needs support higher up)
-
-    //!!! todo: option to include timestamps for columns
     
     if (provider) {
 
@@ -134,8 +191,8 @@
             list << QString("%1").arg(fr);
             break;
         case TimestampFormat::Seconds:
-            list << QString("%1").arg(RealTime::frame2RealTime
-                                      (fr, model->getSampleRate()).toDouble());
+            list << RealTime::frame2RealTime(fr, model->getSampleRate())
+                .toString().c_str();
             break;
         }
         
--- a/layer/Colour3DPlotExporter.h	Fri Jan 10 11:12:33 2020 +0000
+++ b/layer/Colour3DPlotExporter.h	Fri Jan 10 14:30:26 2020 +0000
@@ -80,7 +80,9 @@
     ~Colour3DPlotExporter();
 
     void discardSources();
-
+    
+    QString getDelimitedDataHeaderLine(QString, DataExportOptions) const override;
+    
     QString toDelimitedDataString(QString, DataExportOptions,
                                   sv_frame_t, sv_frame_t) const override;