Mercurial > hg > svcore
comparison base/MatrixFile.h @ 96:1aebdc68ec6d
* Introduce simple non-RT thread base class
* Rename MatrixFileCache to MatrixFile
* some fixes & tidying
author | Chris Cannam |
---|---|
date | Thu, 04 May 2006 16:03:02 +0000 |
parents | base/MatrixFileCache.h@040a151d0897 |
children | 22494cc28c9f |
comparison
equal
deleted
inserted
replaced
95:040a151d0897 | 96:1aebdc68ec6d |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 Sonic Visualiser | |
5 An audio file viewer and annotation editor. | |
6 Centre for Digital Music, Queen Mary, University of London. | |
7 This file copyright 2006 Chris Cannam. | |
8 | |
9 This program is free software; you can redistribute it and/or | |
10 modify it under the terms of the GNU General Public License as | |
11 published by the Free Software Foundation; either version 2 of the | |
12 License, or (at your option) any later version. See the file | |
13 COPYING included with this distribution for more information. | |
14 */ | |
15 | |
16 #ifndef _MATRIX_FILE_CACHE_H_ | |
17 #define _MATRIX_FILE_CACHE_H_ | |
18 | |
19 #include <sys/types.h> | |
20 #include <QString> | |
21 #include <QMutex> | |
22 #include <map> | |
23 | |
24 #include "FileReadThread.h" | |
25 | |
26 class MatrixFile : public QObject | |
27 { | |
28 Q_OBJECT | |
29 | |
30 public: | |
31 enum Mode { ReadOnly, ReadWrite }; | |
32 | |
33 MatrixFile(QString fileBase, Mode mode); | |
34 virtual ~MatrixFile(); | |
35 | |
36 size_t getWidth() const; | |
37 size_t getHeight() const; | |
38 | |
39 void resize(size_t width, size_t height); | |
40 void reset(); | |
41 | |
42 float getValueAt(size_t x, size_t y); | |
43 void getColumnAt(size_t x, float *values); | |
44 | |
45 void setValueAt(size_t x, size_t y, float value); | |
46 void setColumnAt(size_t x, float *values); | |
47 | |
48 protected slots: | |
49 void requestCancelled(int token); | |
50 | |
51 protected: | |
52 int m_fd; | |
53 Mode m_mode; | |
54 size_t m_width; | |
55 size_t m_height; | |
56 size_t m_headerSize; | |
57 QString m_fileName; | |
58 size_t m_defaultCacheWidth; | |
59 size_t m_prevX; | |
60 | |
61 struct Cache { | |
62 size_t x; | |
63 size_t width; | |
64 float *data; | |
65 }; | |
66 | |
67 Cache m_cache; | |
68 | |
69 bool getValuesFromCache(size_t x, size_t ystart, size_t ycount, | |
70 float *values); | |
71 | |
72 void primeCache(size_t x, bool left); | |
73 | |
74 bool seekTo(size_t x, size_t y); | |
75 | |
76 FileReadThread m_readThread; | |
77 int m_requestToken; | |
78 size_t m_requestingX; | |
79 size_t m_requestingWidth; | |
80 | |
81 static std::map<QString, int> m_refcount; | |
82 static QMutex m_refcountMutex; | |
83 QMutex m_fdMutex; | |
84 QMutex m_cacheMutex; | |
85 }; | |
86 | |
87 #endif | |
88 |