Chris@1554: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@1554: Chris@1554: /* Chris@1554: Sonic Visualiser Chris@1554: An audio file viewer and annotation editor. Chris@1554: Centre for Digital Music, Queen Mary, University of London. Chris@1554: Chris@1554: This program is free software; you can redistribute it and/or Chris@1554: modify it under the terms of the GNU General Public License as Chris@1554: published by the Free Software Foundation; either version 2 of the Chris@1554: License, or (at your option) any later version. See the file Chris@1554: COPYING included with this distribution for more information. Chris@1554: */ Chris@1554: Chris@1554: #include "Colour3DPlotExporter.h" Chris@1554: Chris@1554: #include "data/model/EditableDenseThreeDimensionalModel.h" Chris@1554: #include "data/model/FFTModel.h" Chris@1554: Chris@1554: #include "VerticalBinLayer.h" Chris@1554: Chris@1554: QString Chris@1554: Colour3DPlotExporter::toDelimitedDataString(QString delimiter, Chris@1554: DataExportOptions options, Chris@1554: sv_frame_t startFrame, Chris@1554: sv_frame_t duration) const Chris@1554: { Chris@1554: QMutexLocker locker(&m_mutex); Chris@1554: Chris@1554: BinDisplay binDisplay = m_params.binDisplay; Chris@1554: Chris@1554: auto model = Chris@1554: ModelById::getAs(m_sources.source); Chris@1554: auto fftModel = Chris@1554: ModelById::getAs(m_sources.fft); Chris@1554: Chris@1554: auto layer = m_sources.verticalBinLayer; Chris@1554: auto provider = m_sources.provider; Chris@1554: Chris@1554: if (!model || !layer) { Chris@1554: SVCERR << "ERROR: Colour3DPlotExporter::toDelimitedDataString: Source model and layer required" << endl; Chris@1554: return {}; Chris@1554: } Chris@1554: Chris@1554: int minbin = 0; Chris@1554: int sh = model->getHeight(); Chris@1554: int nbins = sh; Chris@1554: Chris@1554: //!!! todo: consider what to do about the actual Colour 3D Plot Chris@1554: //!!! Layer. In the existing application, this is exported full Chris@1554: //!!! height. If we switch to using this code, we will be Chris@1554: //!!! exporting only the displayed height. This is backward Chris@1554: //!!! incompatible, but also not directly interpretable without Chris@1554: //!!! any guide in the exported file as to what the bin indices Chris@1554: //!!! are. Perhaps we should have a flag to export full height, Chris@1554: //!!! and default to using it. Chris@1554: Chris@1554: //!!! todo: what about the other export types besides Chris@1554: //!!! delimited-data-string ? Chris@1554: Chris@1554: if (provider) { Chris@1554: Chris@1554: minbin = layer->getIBinForY(provider, provider->getPaintHeight()); Chris@1554: if (minbin >= sh) minbin = sh - 1; Chris@1554: if (minbin < 0) minbin = 0; Chris@1554: Chris@1554: nbins = layer->getIBinForY(provider, 0) - minbin + 1; Chris@1554: if (minbin + nbins > sh) nbins = sh - minbin; Chris@1554: } Chris@1554: Chris@1554: int w = model->getWidth(); Chris@1554: Chris@1554: QString s; Chris@1554: Chris@1554: for (int i = 0; i < w; ++i) { Chris@1554: sv_frame_t fr = model->getStartFrame() + i * model->getResolution(); Chris@1554: if (fr < startFrame || fr >= startFrame + duration) { Chris@1554: continue; Chris@1554: } Chris@1554: QStringList list; Chris@1554: Chris@1554: //... Chris@1554: Chris@1554: s += list.join(delimiter) + "\n"; Chris@1554: } Chris@1554: Chris@1554: return s; Chris@1554: Chris@1554: Chris@1554: //!!! For reference, this is the body of Chris@1554: //!!! EditableDenseThreeDimensionalModel::toDelimitedDataString Chris@1554: /* Chris@1554: QString s; Chris@1554: for (int i = 0; in_range_for(m_data, i); ++i) { Chris@1554: sv_frame_t fr = m_startFrame + i * m_resolution; Chris@1554: if (fr >= startFrame && fr < startFrame + duration) { Chris@1554: QStringList list; Chris@1554: for (int j = 0; in_range_for(m_data.at(i), j); ++j) { Chris@1554: list << QString("%1").arg(m_data.at(i).at(j)); Chris@1554: } Chris@1554: s += list.join(delimiter) + "\n"; Chris@1554: } Chris@1554: } Chris@1554: return s; Chris@1554: */ Chris@1554: } Chris@1554: