comparison layer/Colour3DPlotExporter.h @ 1566:1f80a514ce29

Merge from branch spectrogram-export
author Chris Cannam
date Fri, 10 Jan 2020 14:54:27 +0000
parents a6a31908bd13
children 3943553b95b0
comparison
equal deleted inserted replaced
1553:76e4302a3fc2 1566:1f80a514ce29
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 #ifndef COLOUR_3D_PLOT_EXPORTER_H
16 #define COLOUR_3D_PLOT_EXPORTER_H
17
18 #include "Colour3DPlotRenderer.h"
19
20 class Colour3DPlotExporter : public Model
21 {
22 Q_OBJECT
23
24 public:
25 struct Sources {
26 // These must all outlive this class, or else discardSources()
27 // must be called
28 const VerticalBinLayer *verticalBinLayer; // always
29 ModelId source; // always; a DenseThreeDimensionalModel
30 ModelId fft; // optionally; an FFTModel; used for phase/peak-freq modes
31 const LayerGeometryProvider *provider; // optionally
32 };
33
34 enum class TimestampFormat {
35 None,
36 Seconds,
37 Frames
38 };
39
40 struct Parameters {
41 Parameters() :
42 binDisplay(BinDisplay::AllBins),
43 scaleFactor(1.0),
44 threshold(0.0),
45 gain(1.0),
46 normalization(ColumnNormalization::None),
47 timestampFormat(TimestampFormat::None) { }
48
49 /** Selection of bins to include in the export. */
50 BinDisplay binDisplay;
51
52 /** Initial scale factor (e.g. for FFT scaling). This factor
53 * is actually applied to exported values, in contrast to the
54 * gain value below based on the ColourScale parameter. */
55 double scaleFactor;
56
57 /** Threshold below which every value is mapped to background
58 * pixel 0 in the display, matching the ColourScale object
59 * parameters. This is used for thresholding in
60 * peak-frequency output only. */
61 double threshold;
62
63 /** Gain that is applied before thresholding, in the display,
64 * matching the ColourScale object parameters. This is used
65 * only to determined the thresholding level. The exported
66 * values have the scaleFactor applied, but not this gain. */
67 double gain;
68
69 /** Type of column normalization. Again, this is only used to
70 * calculate thresholding level. The exported values are
71 * un-normalized. */
72 ColumnNormalization normalization;
73
74 /** Format to use for the timestamp column. If None, no
75 * timestamp column will be included. */
76 TimestampFormat timestampFormat;
77 };
78
79 Colour3DPlotExporter(Sources sources, Parameters parameters);
80 ~Colour3DPlotExporter();
81
82 void discardSources();
83
84 QString getDelimitedDataHeaderLine(QString, DataExportOptions) const override;
85
86 QString toDelimitedDataString(QString, DataExportOptions,
87 sv_frame_t, sv_frame_t) const override;
88
89
90 // Further Model methods that we just delegate
91
92 bool isOK() const override {
93 if (auto model = ModelById::get(m_sources.source)) {
94 return model->isOK();
95 }
96 return false;
97 }
98
99 sv_frame_t getStartFrame() const override {
100 if (auto model = ModelById::get(m_sources.source)) {
101 return model->getStartFrame();
102 }
103 return 0;
104 }
105
106 sv_frame_t getTrueEndFrame() const override {
107 if (auto model = ModelById::get(m_sources.source)) {
108 return model->getTrueEndFrame();
109 }
110 return 0;
111 }
112
113 sv_samplerate_t getSampleRate() const override {
114 if (auto model = ModelById::get(m_sources.source)) {
115 return model->getSampleRate();
116 }
117 return 0;
118 }
119
120 QString getTypeName() const override {
121 if (auto model = ModelById::get(m_sources.source)) {
122 return model->getTypeName();
123 }
124 return "(exporter)"; // internal fallback, no translation needed
125 }
126
127 int getCompletion() const override {
128 if (auto model = ModelById::get(m_sources.source)) {
129 return model->getCompletion();
130 }
131 return 0;
132 }
133
134 private:
135 Sources m_sources;
136 Parameters m_params;
137 };
138
139 #endif