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