annotate layer/Colour3DPlotExporter.cpp @ 1555:745be36202aa spectrogram-export

Provide export model
author Chris Cannam
date Tue, 07 Jan 2020 11:18:43 +0000
parents a0b2f3b4dd2f
children ac8da42674ff
rev   line source
Chris@1554 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@1554 2
Chris@1554 3 /*
Chris@1554 4 Sonic Visualiser
Chris@1554 5 An audio file viewer and annotation editor.
Chris@1554 6 Centre for Digital Music, Queen Mary, University of London.
Chris@1554 7
Chris@1554 8 This program is free software; you can redistribute it and/or
Chris@1554 9 modify it under the terms of the GNU General Public License as
Chris@1554 10 published by the Free Software Foundation; either version 2 of the
Chris@1554 11 License, or (at your option) any later version. See the file
Chris@1554 12 COPYING included with this distribution for more information.
Chris@1554 13 */
Chris@1554 14
Chris@1554 15 #include "Colour3DPlotExporter.h"
Chris@1554 16
Chris@1554 17 #include "data/model/EditableDenseThreeDimensionalModel.h"
Chris@1554 18 #include "data/model/FFTModel.h"
Chris@1554 19
Chris@1554 20 #include "VerticalBinLayer.h"
Chris@1554 21
Chris@1554 22 QString
Chris@1554 23 Colour3DPlotExporter::toDelimitedDataString(QString delimiter,
Chris@1554 24 DataExportOptions options,
Chris@1554 25 sv_frame_t startFrame,
Chris@1554 26 sv_frame_t duration) const
Chris@1554 27 {
Chris@1554 28 QMutexLocker locker(&m_mutex);
Chris@1554 29
Chris@1554 30 BinDisplay binDisplay = m_params.binDisplay;
Chris@1554 31
Chris@1554 32 auto model =
Chris@1554 33 ModelById::getAs<DenseThreeDimensionalModel>(m_sources.source);
Chris@1554 34 auto fftModel =
Chris@1554 35 ModelById::getAs<FFTModel>(m_sources.fft);
Chris@1554 36
Chris@1554 37 auto layer = m_sources.verticalBinLayer;
Chris@1554 38 auto provider = m_sources.provider;
Chris@1554 39
Chris@1554 40 if (!model || !layer) {
Chris@1554 41 SVCERR << "ERROR: Colour3DPlotExporter::toDelimitedDataString: Source model and layer required" << endl;
Chris@1554 42 return {};
Chris@1554 43 }
Chris@1554 44
Chris@1554 45 int minbin = 0;
Chris@1554 46 int sh = model->getHeight();
Chris@1554 47 int nbins = sh;
Chris@1554 48
Chris@1554 49 //!!! todo: consider what to do about the actual Colour 3D Plot
Chris@1554 50 //!!! Layer. In the existing application, this is exported full
Chris@1554 51 //!!! height. If we switch to using this code, we will be
Chris@1554 52 //!!! exporting only the displayed height. This is backward
Chris@1554 53 //!!! incompatible, but also not directly interpretable without
Chris@1554 54 //!!! any guide in the exported file as to what the bin indices
Chris@1554 55 //!!! are. Perhaps we should have a flag to export full height,
Chris@1554 56 //!!! and default to using it.
Chris@1554 57
Chris@1554 58 //!!! todo: what about the other export types besides
Chris@1554 59 //!!! delimited-data-string ?
Chris@1554 60
Chris@1554 61 if (provider) {
Chris@1554 62
Chris@1554 63 minbin = layer->getIBinForY(provider, provider->getPaintHeight());
Chris@1554 64 if (minbin >= sh) minbin = sh - 1;
Chris@1554 65 if (minbin < 0) minbin = 0;
Chris@1554 66
Chris@1554 67 nbins = layer->getIBinForY(provider, 0) - minbin + 1;
Chris@1554 68 if (minbin + nbins > sh) nbins = sh - minbin;
Chris@1554 69 }
Chris@1554 70
Chris@1554 71 int w = model->getWidth();
Chris@1554 72
Chris@1554 73 QString s;
Chris@1554 74
Chris@1554 75 for (int i = 0; i < w; ++i) {
Chris@1554 76 sv_frame_t fr = model->getStartFrame() + i * model->getResolution();
Chris@1554 77 if (fr < startFrame || fr >= startFrame + duration) {
Chris@1554 78 continue;
Chris@1554 79 }
Chris@1554 80 QStringList list;
Chris@1554 81
Chris@1554 82 //...
Chris@1554 83
Chris@1554 84 s += list.join(delimiter) + "\n";
Chris@1554 85 }
Chris@1554 86
Chris@1554 87 return s;
Chris@1554 88
Chris@1554 89
Chris@1554 90 //!!! For reference, this is the body of
Chris@1554 91 //!!! EditableDenseThreeDimensionalModel::toDelimitedDataString
Chris@1554 92 /*
Chris@1554 93 QString s;
Chris@1554 94 for (int i = 0; in_range_for(m_data, i); ++i) {
Chris@1554 95 sv_frame_t fr = m_startFrame + i * m_resolution;
Chris@1554 96 if (fr >= startFrame && fr < startFrame + duration) {
Chris@1554 97 QStringList list;
Chris@1554 98 for (int j = 0; in_range_for(m_data.at(i), j); ++j) {
Chris@1554 99 list << QString("%1").arg(m_data.at(i).at(j));
Chris@1554 100 }
Chris@1554 101 s += list.join(delimiter) + "\n";
Chris@1554 102 }
Chris@1554 103 }
Chris@1554 104 return s;
Chris@1554 105 */
Chris@1554 106 }
Chris@1554 107