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