Mercurial > hg > svgui
comparison layer/Colour3DPlotExporter.cpp @ 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 | 77ffd5421627 3943553b95b0 |
comparison
equal
deleted
inserted
replaced
1564:62b7699e5bfe | 1565:a6a31908bd13 |
---|---|
44 m_sources.fft = {}; | 44 m_sources.fft = {}; |
45 m_sources.provider = nullptr; | 45 m_sources.provider = nullptr; |
46 } | 46 } |
47 | 47 |
48 QString | 48 QString |
49 Colour3DPlotExporter::getDelimitedDataHeaderLine(QString delimiter, | |
50 DataExportOptions) const | |
51 { | |
52 auto model = | |
53 ModelById::getAs<DenseThreeDimensionalModel>(m_sources.source); | |
54 | |
55 auto layer = m_sources.verticalBinLayer; | |
56 auto provider = m_sources.provider; | |
57 | |
58 if (!model || !layer) { | |
59 SVCERR << "ERROR: Colour3DPlotExporter::getDelimitedDataHeaderLine: Source model and layer required" << endl; | |
60 return {}; | |
61 } | |
62 | |
63 int minbin = 0; | |
64 int sh = model->getHeight(); | |
65 int nbins = sh; | |
66 | |
67 if (provider) { | |
68 | |
69 minbin = layer->getIBinForY(provider, provider->getPaintHeight()); | |
70 if (minbin >= sh) minbin = sh - 1; | |
71 if (minbin < 0) minbin = 0; | |
72 | |
73 nbins = layer->getIBinForY(provider, 0) - minbin + 1; | |
74 if (minbin + nbins > sh) nbins = sh - minbin; | |
75 } | |
76 | |
77 QStringList list; | |
78 | |
79 switch (m_params.timestampFormat) { | |
80 case TimestampFormat::None: | |
81 break; | |
82 case TimestampFormat::Frames: | |
83 list << "FRAME"; | |
84 break; | |
85 case TimestampFormat::Seconds: | |
86 list << "TIME"; | |
87 break; | |
88 } | |
89 | |
90 if (m_params.binDisplay == BinDisplay::PeakFrequencies) { | |
91 for (int i = 0; i < nbins/4; ++i) { | |
92 list << QString("FREQ %1").arg(i+1) | |
93 << QString("MAG %1").arg(i+1); | |
94 } | |
95 } else { | |
96 bool hasValues = model->hasBinValues(); | |
97 QString unit = (hasValues ? model->getBinValueUnit() : ""); | |
98 for (int i = minbin; i < minbin + nbins; ++i) { | |
99 QString name = model->getBinName(i); | |
100 if (name == "") { | |
101 if (hasValues) { | |
102 if (unit != "") { | |
103 name = QString("BIN %1: %2 %3") | |
104 .arg(i+1) | |
105 .arg(model->getBinValue(i)) | |
106 .arg(unit); | |
107 } else { | |
108 name = QString("BIN %1: %2") | |
109 .arg(i+1) | |
110 .arg(model->getBinValue(i)); | |
111 } | |
112 } else { | |
113 name = QString("BIN %1") | |
114 .arg(i+1); | |
115 } | |
116 } | |
117 list << name; | |
118 } | |
119 } | |
120 | |
121 return list.join(delimiter); | |
122 } | |
123 | |
124 QString | |
49 Colour3DPlotExporter::toDelimitedDataString(QString delimiter, | 125 Colour3DPlotExporter::toDelimitedDataString(QString delimiter, |
50 DataExportOptions options, | 126 DataExportOptions, |
51 sv_frame_t startFrame, | 127 sv_frame_t startFrame, |
52 sv_frame_t duration) const | 128 sv_frame_t duration) const |
53 { | 129 { |
54 QMutexLocker locker(&m_mutex); | 130 QMutexLocker locker(&m_mutex); |
55 | 131 |
56 BinDisplay binDisplay = m_params.binDisplay; | 132 BinDisplay binDisplay = m_params.binDisplay; |
57 | |
58 (void)options; //!!! | |
59 | 133 |
60 auto model = | 134 auto model = |
61 ModelById::getAs<DenseThreeDimensionalModel>(m_sources.source); | 135 ModelById::getAs<DenseThreeDimensionalModel>(m_sources.source); |
62 auto fftModel = | 136 auto fftModel = |
63 ModelById::getAs<FFTModel>(m_sources.fft); | 137 ModelById::getAs<FFTModel>(m_sources.fft); |
75 } | 149 } |
76 | 150 |
77 int minbin = 0; | 151 int minbin = 0; |
78 int sh = model->getHeight(); | 152 int sh = model->getHeight(); |
79 int nbins = sh; | 153 int nbins = sh; |
80 | |
81 //!!! todo: consider what to do about the actual Colour 3D Plot | |
82 //!!! Layer. In the existing application, this is exported full | |
83 //!!! height. If we switch to using this code, we will be | |
84 //!!! exporting only the displayed height. This is backward | |
85 //!!! incompatible, but also not directly interpretable without | |
86 //!!! any guide in the exported file as to what the bin indices | |
87 //!!! are. Perhaps we should have a flag to export full height, | |
88 //!!! and default to using it. | |
89 | |
90 //!!! todo: what about the other export types besides | |
91 //!!! delimited-data-string ? | |
92 | |
93 //!!! todo: export selections only (we have the necessaries here, | |
94 //!!! but it needs support higher up) | |
95 | |
96 //!!! todo: option to include timestamps for columns | |
97 | 154 |
98 if (provider) { | 155 if (provider) { |
99 | 156 |
100 minbin = layer->getIBinForY(provider, provider->getPaintHeight()); | 157 minbin = layer->getIBinForY(provider, provider->getPaintHeight()); |
101 if (minbin >= sh) minbin = sh - 1; | 158 if (minbin >= sh) minbin = sh - 1; |
132 break; | 189 break; |
133 case TimestampFormat::Frames: | 190 case TimestampFormat::Frames: |
134 list << QString("%1").arg(fr); | 191 list << QString("%1").arg(fr); |
135 break; | 192 break; |
136 case TimestampFormat::Seconds: | 193 case TimestampFormat::Seconds: |
137 list << QString("%1").arg(RealTime::frame2RealTime | 194 list << RealTime::frame2RealTime(fr, model->getSampleRate()) |
138 (fr, model->getSampleRate()).toDouble()); | 195 .toString().c_str(); |
139 break; | 196 break; |
140 } | 197 } |
141 | 198 |
142 if (binDisplay == BinDisplay::PeakFrequencies) { | 199 if (binDisplay == BinDisplay::PeakFrequencies) { |
143 | 200 |