annotate data/model/ReadOnlyWaveFileModel.h @ 1886:f803d3c33f76 tip

Switch off copious debug in soft synth driving
author Chris Cannam
date Fri, 14 Aug 2020 10:44:44 +0100
parents 14747f24ad04
children
rev   line source
Chris@147 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@147 2
Chris@147 3 /*
Chris@147 4 Sonic Visualiser
Chris@147 5 An audio file viewer and annotation editor.
Chris@147 6 Centre for Digital Music, Queen Mary, University of London.
Chris@202 7 This file copyright 2006 Chris Cannam and QMUL.
Chris@147 8
Chris@147 9 This program is free software; you can redistribute it and/or
Chris@147 10 modify it under the terms of the GNU General Public License as
Chris@147 11 published by the Free Software Foundation; either version 2 of the
Chris@147 12 License, or (at your option) any later version. See the file
Chris@147 13 COPYING included with this distribution for more information.
Chris@147 14 */
Chris@147 15
Chris@1122 16 #ifndef READ_ONLY_WAVE_FILE_MODEL_H
Chris@1122 17 #define READ_ONLY_WAVE_FILE_MODEL_H
Chris@1122 18
Chris@1122 19 #include "WaveFileModel.h"
Chris@147 20
Chris@150 21 #include "base/Thread.h"
Chris@147 22 #include <QMutex>
Chris@147 23 #include <QTimer>
Chris@147 24
Chris@317 25 #include "data/fileio/FileSource.h"
Chris@316 26
Chris@147 27 #include "RangeSummarisableTimeValueModel.h"
Chris@147 28 #include "PowerOfSqrtTwoZoomConstraint.h"
Chris@147 29
Chris@147 30 #include <stdlib.h>
Chris@147 31
Chris@1858 32 #include <atomic>
Chris@1858 33
Chris@147 34 class AudioFileReader;
Chris@147 35
Chris@1122 36 class ReadOnlyWaveFileModel : public WaveFileModel
Chris@147 37 {
Chris@147 38 Q_OBJECT
Chris@147 39
Chris@147 40 public:
Chris@1514 41 /**
Chris@1514 42 * Construct a WaveFileModel from a source path and optional
Chris@1514 43 * resampling target rate
Chris@1514 44 */
Chris@1122 45 ReadOnlyWaveFileModel(FileSource source, sv_samplerate_t targetRate = 0);
Chris@1514 46
Chris@1514 47 /**
Chris@1514 48 * Construct a WaveFileModel from a source path using an existing
Chris@1514 49 * AudioFileReader. The model does not take ownership of the
Chris@1514 50 * AudioFileReader, which remains managed by the caller and must
Chris@1514 51 * outlive the model.
Chris@1514 52 */
Chris@1122 53 ReadOnlyWaveFileModel(FileSource source, AudioFileReader *reader);
Chris@1514 54
Chris@1122 55 ~ReadOnlyWaveFileModel();
Chris@147 56
Chris@1580 57 bool isOK() const override;
Chris@1580 58 bool isReady(int *) const override;
Chris@1671 59 int getCompletion() const override {
Chris@1671 60 int c = 0;
Chris@1671 61 (void)isReady(&c);
Chris@1671 62 return c;
Chris@1671 63 }
Chris@147 64
Chris@1580 65 const ZoomConstraint *getZoomConstraint() const override { return &m_zoomConstraint; }
Chris@179 66
Chris@1580 67 sv_frame_t getFrameCount() const override;
Chris@1580 68 int getChannelCount() const override;
Chris@1580 69 sv_samplerate_t getSampleRate() const override;
Chris@1580 70 sv_samplerate_t getNativeRate() const override;
Chris@147 71
Chris@1580 72 QString getTitle() const override;
Chris@1580 73 QString getMaker() const override;
Chris@1580 74 QString getLocation() const override;
Chris@333 75
Chris@1010 76 QString getLocalFilename() const;
Chris@1010 77
Chris@1580 78 float getValueMinimum() const override { return -1.0f; }
Chris@1580 79 float getValueMaximum() const override { return 1.0f; }
Chris@147 80
Chris@1580 81 sv_frame_t getStartFrame() const override { return m_startFrame; }
Chris@1725 82 sv_frame_t getTrueEndFrame() const override { return m_startFrame + getFrameCount(); }
Chris@147 83
Chris@1580 84 void setStartFrame(sv_frame_t startFrame) override { m_startFrame = startFrame; }
Chris@147 85
Chris@1580 86 floatvec_t getData(int channel, sv_frame_t start, sv_frame_t count) const override;
Chris@147 87
Chris@1580 88 std::vector<floatvec_t> getMultiChannelData(int fromchannel, int tochannel, sv_frame_t start, sv_frame_t count) const override;
Chris@363 89
Chris@1580 90 int getSummaryBlockSize(int desired) const override;
Chris@377 91
Chris@1580 92 void getSummaries(int channel, sv_frame_t start, sv_frame_t count,
Chris@300 93 RangeBlock &ranges,
Chris@1580 94 int &blockSize) const override;
Chris@300 95
Chris@1580 96 Range getSummary(int channel, sv_frame_t start, sv_frame_t count) const override;
Chris@147 97
Chris@1580 98 QString getTypeName() const override { return tr("Wave File"); }
Chris@345 99
Chris@1580 100 void toXml(QTextStream &out,
Chris@163 101 QString indent = "",
Chris@1580 102 QString extraAttributes = "") const override;
Chris@163 103
Chris@147 104 protected slots:
Chris@147 105 void fillTimerTimedOut();
Chris@147 106 void cacheFilled();
Chris@147 107
Chris@147 108 protected:
Chris@147 109 void initialize();
Chris@147 110
Chris@147 111 class RangeCacheFillThread : public Thread
Chris@147 112 {
Chris@147 113 public:
Chris@1122 114 RangeCacheFillThread(ReadOnlyWaveFileModel &model) :
Chris@1406 115 m_model(model), m_fillExtent(0),
Chris@175 116 m_frameCount(model.getFrameCount()) { }
Chris@147 117
Chris@1406 118 sv_frame_t getFillExtent() const { return m_fillExtent; }
Chris@1580 119 void run() override;
Chris@147 120
Chris@147 121 protected:
Chris@1122 122 ReadOnlyWaveFileModel &m_model;
Chris@1406 123 sv_frame_t m_fillExtent;
Chris@1038 124 sv_frame_t m_frameCount;
Chris@147 125 };
Chris@147 126
Chris@147 127 void fillCache();
Chris@316 128
Chris@317 129 FileSource m_source;
Chris@147 130 QString m_path;
Chris@147 131 AudioFileReader *m_reader;
Chris@175 132 bool m_myReader;
Chris@147 133
Chris@1038 134 sv_frame_t m_startFrame;
Chris@300 135
Chris@147 136 RangeBlock m_cache[2]; // interleaved at two base resolutions
Chris@147 137 mutable QMutex m_mutex;
Chris@147 138 RangeCacheFillThread *m_fillThread;
Chris@147 139 QTimer *m_updateTimer;
Chris@1038 140 sv_frame_t m_lastFillExtent;
Chris@1557 141 mutable int m_prevCompletion;
Chris@1858 142 std::atomic<bool> m_exiting;
Chris@179 143 static PowerOfSqrtTwoZoomConstraint m_zoomConstraint;
Chris@377 144
Chris@1326 145 mutable floatvec_t m_directRead;
Chris@1038 146 mutable sv_frame_t m_lastDirectReadStart;
Chris@1038 147 mutable sv_frame_t m_lastDirectReadCount;
Chris@377 148 mutable QMutex m_directReadMutex;
Chris@147 149 };
Chris@147 150
Chris@147 151 #endif