annotate data/model/Dense3DModelPeakCache.h @ 1761:ee7fd2c01d87 by-id

Work on management of alignment-related models
author Chris Cannam
date Fri, 12 Jul 2019 13:57:42 +0100
parents 6d09d68165a4
children 59d9dcfd67c2
rev   line source
Chris@545 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@545 2
Chris@545 3 /*
Chris@545 4 Sonic Visualiser
Chris@545 5 An audio file viewer and annotation editor.
Chris@545 6 Centre for Digital Music, Queen Mary, University of London.
Chris@545 7 This file copyright 2009 QMUL.
Chris@545 8
Chris@545 9 This program is free software; you can redistribute it and/or
Chris@545 10 modify it under the terms of the GNU General Public License as
Chris@545 11 published by the Free Software Foundation; either version 2 of the
Chris@545 12 License, or (at your option) any later version. See the file
Chris@545 13 COPYING included with this distribution for more information.
Chris@545 14 */
Chris@545 15
Chris@1191 16 #ifndef DENSE_3D_MODEL_PEAK_CACHE_H
Chris@1191 17 #define DENSE_3D_MODEL_PEAK_CACHE_H
Chris@545 18
Chris@545 19 #include "DenseThreeDimensionalModel.h"
Chris@545 20 #include "EditableDenseThreeDimensionalModel.h"
Chris@545 21
Chris@545 22 class Dense3DModelPeakCache : public DenseThreeDimensionalModel
Chris@545 23 {
Chris@546 24 Q_OBJECT
Chris@546 25
Chris@545 26 public:
Chris@1739 27 Dense3DModelPeakCache(ModelId source, // a DenseThreeDimensionalModel
Chris@929 28 int columnsPerPeak);
Chris@545 29 ~Dense3DModelPeakCache();
Chris@545 30
Chris@1580 31 bool isOK() const override {
Chris@1739 32 auto source = ModelById::get(m_source);
Chris@1739 33 return source && source->isOK();
Chris@546 34 }
Chris@546 35
Chris@1580 36 sv_samplerate_t getSampleRate() const override {
Chris@1739 37 auto source = ModelById::get(m_source);
Chris@1739 38 return source ? source->getSampleRate() : 0;
Chris@546 39 }
Chris@546 40
Chris@1580 41 sv_frame_t getStartFrame() const override {
Chris@1739 42 auto source = ModelById::get(m_source);
Chris@1739 43 return source ? source->getStartFrame() : 0;
Chris@546 44 }
Chris@546 45
Chris@1725 46 sv_frame_t getTrueEndFrame() const override {
Chris@1739 47 auto source = ModelById::get(m_source);
Chris@1739 48 return source ? source->getTrueEndFrame() : 0;
Chris@546 49 }
Chris@546 50
Chris@1580 51 int getResolution() const override {
Chris@1739 52 auto source = ModelById::getAs<DenseThreeDimensionalModel>(m_source);
Chris@1739 53 return source ? source->getResolution() * m_columnsPerPeak : 1;
Chris@545 54 }
Chris@545 55
Chris@1190 56 virtual int getColumnsPerPeak() const {
Chris@1190 57 return m_columnsPerPeak;
Chris@1190 58 }
Chris@1190 59
Chris@1580 60 int getWidth() const override {
Chris@1739 61 auto source = ModelById::getAs<DenseThreeDimensionalModel>(m_source);
Chris@1739 62 if (!source) return 0;
Chris@1739 63 int sourceWidth = source->getWidth();
Chris@1192 64 if ((sourceWidth % m_columnsPerPeak) == 0) {
Chris@1192 65 return sourceWidth / m_columnsPerPeak;
Chris@1192 66 } else {
Chris@1192 67 return sourceWidth / m_columnsPerPeak + 1;
Chris@1192 68 }
Chris@545 69 }
Chris@545 70
Chris@1580 71 int getHeight() const override {
Chris@1739 72 auto source = ModelById::getAs<DenseThreeDimensionalModel>(m_source);
Chris@1739 73 return source ? source->getHeight() : 0;
Chris@545 74 }
Chris@545 75
Chris@1580 76 float getMinimumLevel() const override {
Chris@1739 77 auto source = ModelById::getAs<DenseThreeDimensionalModel>(m_source);
Chris@1739 78 return source ? source->getMinimumLevel() : 0.f;
Chris@545 79 }
Chris@545 80
Chris@1580 81 float getMaximumLevel() const override {
Chris@1739 82 auto source = ModelById::getAs<DenseThreeDimensionalModel>(m_source);
Chris@1739 83 return source ? source->getMaximumLevel() : 1.f;
Chris@545 84 }
Chris@545 85
Chris@1339 86 /**
Chris@1339 87 * Retrieve the peaks column at peak-cache column number col. This
Chris@1339 88 * will consist of the peak values in the underlying model from
Chris@1339 89 * columns (col * getColumnsPerPeak()) to ((col+1) *
Chris@1339 90 * getColumnsPerPeak() - 1) inclusive.
Chris@1339 91 */
Chris@1580 92 Column getColumn(int col) const override;
Chris@545 93
Chris@1580 94 float getValueAt(int col, int n) const override;
Chris@545 95
Chris@1580 96 QString getBinName(int n) const override {
Chris@1739 97 auto source = ModelById::getAs<DenseThreeDimensionalModel>(m_source);
Chris@1739 98 return source ? source->getBinName(n) : "";
Chris@545 99 }
Chris@545 100
Chris@1580 101 bool shouldUseLogValueScale() const override {
Chris@1739 102 auto source = ModelById::getAs<DenseThreeDimensionalModel>(m_source);
Chris@1739 103 return source ? source->shouldUseLogValueScale() : false;
Chris@545 104 }
Chris@545 105
Chris@1580 106 QString getTypeName() const override { return tr("Dense 3-D Peak Cache"); }
Chris@545 107
Chris@1580 108 int getCompletion() const override {
Chris@1739 109 auto source = ModelById::get(m_source);
Chris@1739 110 return source ? source->getCompletion() : 100;
Chris@545 111 }
Chris@545 112
Chris@1679 113 QString toDelimitedDataString(QString, DataExportOptions,
Chris@1679 114 sv_frame_t, sv_frame_t) const override {
Chris@1679 115 return "";
Chris@1679 116 }
Chris@1679 117
Chris@545 118 protected slots:
Chris@1752 119 void sourceModelChanged(ModelId);
Chris@545 120
Chris@545 121 private:
Chris@1739 122 ModelId m_source;
Chris@1739 123 mutable std::unique_ptr<EditableDenseThreeDimensionalModel> m_cache;
Chris@1153 124 mutable std::vector<bool> m_coverage; // must be bool, for space efficiency
Chris@1153 125 // (vector of bool uses 1-bit elements)
Chris@1190 126 int m_columnsPerPeak;
Chris@545 127
Chris@929 128 bool haveColumn(int column) const;
Chris@929 129 void fillColumn(int column) const;
Chris@545 130 };
Chris@545 131
Chris@545 132
Chris@545 133 #endif