annotate base/MatrixFileCache.h @ 90:c4e163f911dd

* Switch spectrogram layer over to using the new rudimentary disk-backed FFT cache
author Chris Cannam
date Wed, 03 May 2006 14:26:26 +0000
parents 7de62a884810
children 4988de098b25
rev   line source
Chris@87 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@87 2
Chris@87 3 /*
Chris@87 4 Sonic Visualiser
Chris@87 5 An audio file viewer and annotation editor.
Chris@87 6 Centre for Digital Music, Queen Mary, University of London.
Chris@87 7 This file copyright 2006 Chris Cannam.
Chris@87 8
Chris@87 9 This program is free software; you can redistribute it and/or
Chris@87 10 modify it under the terms of the GNU General Public License as
Chris@87 11 published by the Free Software Foundation; either version 2 of the
Chris@87 12 License, or (at your option) any later version. See the file
Chris@87 13 COPYING included with this distribution for more information.
Chris@87 14 */
Chris@87 15
Chris@87 16 #ifndef _MATRIX_FILE_CACHE_H_
Chris@87 17 #define _MATRIX_FILE_CACHE_H_
Chris@87 18
Chris@87 19 #include <sys/types.h>
Chris@87 20 #include <QString>
Chris@87 21
Chris@87 22 // This class is _not_ thread safe. Each instance must only be used
Chris@87 23 // within a single thread. You may however have as many instances as
Chris@87 24 // you like referring to the same file in separate threads.
Chris@87 25
Chris@87 26 class MatrixFileCache
Chris@87 27 {
Chris@87 28 public:
Chris@87 29 enum Mode { ReadOnly, ReadWrite };
Chris@87 30
Chris@87 31 MatrixFileCache(QString fileBase, Mode mode);
Chris@87 32 virtual ~MatrixFileCache();
Chris@87 33
Chris@87 34 size_t getWidth() const;
Chris@87 35 size_t getHeight() const;
Chris@87 36
Chris@87 37 void resize(size_t width, size_t height);
Chris@87 38 void reset();
Chris@87 39
Chris@90 40 void setRegionOfInterest(size_t x, size_t width);
Chris@90 41 void clearRegionOfInterest();
Chris@87 42
Chris@87 43 float getValueAt(size_t x, size_t y) const;
Chris@87 44 void getColumnAt(size_t x, float *values) const;
Chris@87 45
Chris@87 46 void setValueAt(size_t x, size_t y, float value);
Chris@87 47 void setColumnAt(size_t x, float *values);
Chris@87 48
Chris@87 49 protected:
Chris@87 50 int m_fd;
Chris@87 51 Mode m_mode;
Chris@87 52 size_t m_width;
Chris@87 53 size_t m_height;
Chris@87 54 size_t m_headerSize;
Chris@90 55 size_t m_autoRegionWidth;
Chris@87 56
Chris@90 57 mutable off_t m_off;
Chris@90 58 mutable size_t m_rx;
Chris@90 59 mutable size_t m_rw;
Chris@90 60 mutable bool m_userRegion;
Chris@90 61 mutable float *m_region;
Chris@90 62 mutable bool m_mmapped;
Chris@90 63 mutable size_t m_mmapSize;
Chris@90 64 mutable size_t m_mmapOff;
Chris@90 65 mutable bool m_preferMmap;
Chris@90 66 float *getRegionPtr(size_t x, size_t y) const;
Chris@90 67
Chris@90 68 bool autoSetRegion(size_t x) const;
Chris@90 69 bool setRegion(size_t x, size_t width, bool user) const;
Chris@87 70
Chris@87 71 bool seekTo(size_t x, size_t y) const;
Chris@87 72 };
Chris@87 73
Chris@87 74 #endif
Chris@87 75