Chris@87: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@87: Chris@87: /* Chris@87: Sonic Visualiser Chris@87: An audio file viewer and annotation editor. Chris@87: Centre for Digital Music, Queen Mary, University of London. Chris@87: This file copyright 2006 Chris Cannam. Chris@87: Chris@87: This program is free software; you can redistribute it and/or Chris@87: modify it under the terms of the GNU General Public License as Chris@87: published by the Free Software Foundation; either version 2 of the Chris@87: License, or (at your option) any later version. See the file Chris@87: COPYING included with this distribution for more information. Chris@87: */ Chris@87: Chris@87: #ifndef _MATRIX_FILE_CACHE_H_ Chris@87: #define _MATRIX_FILE_CACHE_H_ Chris@87: Chris@87: #include Chris@87: #include Chris@92: #include Chris@92: #include Chris@87: Chris@95: #include "FileReadThread.h" Chris@87: Chris@96: class MatrixFile : public QObject Chris@87: { Chris@95: Q_OBJECT Chris@95: Chris@87: public: Chris@87: enum Mode { ReadOnly, ReadWrite }; Chris@87: Chris@96: MatrixFile(QString fileBase, Mode mode); Chris@96: virtual ~MatrixFile(); Chris@87: Chris@87: size_t getWidth() const; Chris@87: size_t getHeight() const; Chris@87: Chris@87: void resize(size_t width, size_t height); Chris@87: void reset(); Chris@87: Chris@95: float getValueAt(size_t x, size_t y); Chris@95: void getColumnAt(size_t x, float *values); Chris@87: Chris@87: void setValueAt(size_t x, size_t y, float value); Chris@87: void setColumnAt(size_t x, float *values); Chris@95: Chris@87: protected: Chris@87: int m_fd; Chris@87: Mode m_mode; Chris@87: size_t m_width; Chris@87: size_t m_height; Chris@87: size_t m_headerSize; Chris@92: QString m_fileName; Chris@95: size_t m_defaultCacheWidth; Chris@95: size_t m_prevX; Chris@87: Chris@95: struct Cache { Chris@95: size_t x; Chris@95: size_t width; Chris@95: float *data; Chris@95: }; Chris@90: Chris@95: Cache m_cache; Chris@87: Chris@95: bool getValuesFromCache(size_t x, size_t ystart, size_t ycount, Chris@95: float *values); Chris@95: Chris@95: void primeCache(size_t x, bool left); Chris@95: Chris@95: bool seekTo(size_t x, size_t y); Chris@95: Chris@95: FileReadThread m_readThread; Chris@95: int m_requestToken; Chris@97: Chris@95: size_t m_requestingX; Chris@95: size_t m_requestingWidth; Chris@97: char *m_spareData; Chris@92: Chris@92: static std::map m_refcount; Chris@92: static QMutex m_refcountMutex; Chris@95: QMutex m_fdMutex; Chris@95: QMutex m_cacheMutex; Chris@87: }; Chris@87: Chris@87: #endif Chris@87: