comparison layer/Colour3DPlotExporter.cpp @ 1593:32171776fcc9 sensible-delimited-data-strings

Switch to the StringExport api now found in svcore
author Chris Cannam
date Fri, 03 Apr 2020 17:12:37 +0100
parents b33b0b06133e
children
comparison
equal deleted inserted replaced
1592:1da52d5e6700 1593:32171776fcc9
43 m_sources.source = {}; 43 m_sources.source = {};
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 QVector<QString>
49 Colour3DPlotExporter::getDelimitedDataHeaderLine(QString delimiter, 49 Colour3DPlotExporter::getStringExportHeaders(DataExportOptions opts) const
50 DataExportOptions opts) const
51 { 50 {
52 auto model = 51 auto model =
53 ModelById::getAs<DenseThreeDimensionalModel>(m_sources.source); 52 ModelById::getAs<DenseThreeDimensionalModel>(m_sources.source);
54 53
55 auto layer = m_sources.verticalBinLayer; 54 auto layer = m_sources.verticalBinLayer;
72 71
73 nbins = layer->getIBinForY(provider, 0) - minbin + 1; 72 nbins = layer->getIBinForY(provider, 0) - minbin + 1;
74 if (minbin + nbins > sh) nbins = sh - minbin; 73 if (minbin + nbins > sh) nbins = sh - minbin;
75 } 74 }
76 75
77 QStringList list; 76 QVector<QString> headers;
78 77
79 if (opts & DataExportAlwaysIncludeTimestamp) { 78 if (opts & DataExportAlwaysIncludeTimestamp) {
80 if (opts & DataExportWriteTimeInFrames) { 79 if (opts & DataExportWriteTimeInFrames) {
81 list << "FRAME"; 80 headers << "FRAME";
82 } else { 81 } else {
83 list << "TIME"; 82 headers << "TIME";
84 } 83 }
85 } 84 }
86 85
87 if (m_params.binDisplay == BinDisplay::PeakFrequencies) { 86 if (m_params.binDisplay == BinDisplay::PeakFrequencies) {
88 for (int i = 0; i < nbins/4; ++i) { 87 for (int i = 0; i < nbins/4; ++i) {
89 list << QString("FREQ %1").arg(i+1) 88 headers << QString("FREQ %1").arg(i+1)
90 << QString("MAG %1").arg(i+1); 89 << QString("MAG %1").arg(i+1);
91 } 90 }
92 } else { 91 } else {
93 bool hasValues = model->hasBinValues(); 92 bool hasValues = model->hasBinValues();
94 QString unit = (hasValues ? model->getBinValueUnit() : ""); 93 QString unit = (hasValues ? model->getBinValueUnit() : "");
109 } else { 108 } else {
110 name = QString("BIN %1") 109 name = QString("BIN %1")
111 .arg(i+1); 110 .arg(i+1);
112 } 111 }
113 } 112 }
114 list << name; 113 headers << name;
115 } 114 }
116 } 115 }
117 116
118 return list.join(delimiter); 117 return headers;
119 } 118 }
120 119
121 QString 120 QVector<QVector<QString>>
122 Colour3DPlotExporter::toDelimitedDataString(QString delimiter, 121 Colour3DPlotExporter::toStringExportRows(DataExportOptions opts,
123 DataExportOptions opts, 122 sv_frame_t startFrame,
124 sv_frame_t startFrame, 123 sv_frame_t duration) const
125 sv_frame_t duration) const
126 { 124 {
127 QMutexLocker locker(&m_mutex); 125 QMutexLocker locker(&m_mutex);
128 126
129 BinDisplay binDisplay = m_params.binDisplay; 127 BinDisplay binDisplay = m_params.binDisplay;
130 128
159 if (minbin + nbins > sh) nbins = sh - minbin; 157 if (minbin + nbins > sh) nbins = sh - minbin;
160 } 158 }
161 159
162 int w = model->getWidth(); 160 int w = model->getWidth();
163 161
164 QString s; 162 QVector<QVector<QString>> rows;
165 163
166 for (int i = 0; i < w; ++i) { 164 for (int i = 0; i < w; ++i) {
167 165
168 sv_frame_t fr = model->getStartFrame() + i * model->getResolution(); 166 sv_frame_t fr = model->getStartFrame() + i * model->getResolution();
169 if (fr < startFrame || fr >= startFrame + duration) { 167 if (fr < startFrame || fr >= startFrame + duration) {
177 column.data() + minbin + nbins); 175 column.data() + minbin + nbins);
178 176
179 // The scale factor is always applied 177 // The scale factor is always applied
180 column = ColumnOp::applyGain(column, m_params.scaleFactor); 178 column = ColumnOp::applyGain(column, m_params.scaleFactor);
181 179
182 QStringList list; 180 QVector<QString> row;
183 181
184 if (opts & DataExportAlwaysIncludeTimestamp) { 182 if (opts & DataExportAlwaysIncludeTimestamp) {
185 if (opts & DataExportWriteTimeInFrames) { 183 if (opts & DataExportWriteTimeInFrames) {
186 list << QString("%1").arg(fr); 184 row << QString("%1").arg(fr);
187 } else { 185 } else {
188 list << RealTime::frame2RealTime(fr, model->getSampleRate()) 186 row << RealTime::frame2RealTime(fr, model->getSampleRate())
189 .toString().c_str(); 187 .toString().c_str();
190 } 188 }
191 } 189 }
192 190
193 if (binDisplay == BinDisplay::PeakFrequencies) { 191 if (binDisplay == BinDisplay::PeakFrequencies) {
214 } 212 }
215 213
216 double freq = p.second; 214 double freq = p.second;
217 double value = column[bin - minbin]; 215 double value = column[bin - minbin];
218 216
219 list << QString("%1").arg(freq) << QString("%1").arg(value); 217 row << QString("%1").arg(freq) << QString("%1").arg(value);
220 } 218 }
221 219
222 } else { 220 } else {
223 221
224 if (binDisplay == BinDisplay::PeakBins) { 222 if (binDisplay == BinDisplay::PeakBins) {
225 column = ColumnOp::peakPick(column); 223 column = ColumnOp::peakPick(column);
226 } 224 }
227 225
228 for (auto value: column) { 226 for (auto value: column) {
229 list << QString("%1").arg(value); 227 row << QString("%1").arg(value);
230 } 228 }
231 } 229 }
232 230
233 if (!list.empty()) { 231 if (!row.empty()) {
234 s += list.join(delimiter) + "\n"; 232 rows.push_back(row);
235 } 233 }
236 } 234 }
237 235
238 return s; 236 return rows;
239 } 237 }
240 238