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@92
|
21 #include <QMutex>
|
Chris@92
|
22 #include <map>
|
Chris@87
|
23
|
Chris@95
|
24 #include "FileReadThread.h"
|
Chris@87
|
25
|
Chris@96
|
26 class MatrixFile : public QObject
|
Chris@87
|
27 {
|
Chris@95
|
28 Q_OBJECT
|
Chris@95
|
29
|
Chris@87
|
30 public:
|
Chris@87
|
31 enum Mode { ReadOnly, ReadWrite };
|
Chris@87
|
32
|
Chris@96
|
33 MatrixFile(QString fileBase, Mode mode);
|
Chris@96
|
34 virtual ~MatrixFile();
|
Chris@87
|
35
|
Chris@87
|
36 size_t getWidth() const;
|
Chris@87
|
37 size_t getHeight() const;
|
Chris@87
|
38
|
Chris@87
|
39 void resize(size_t width, size_t height);
|
Chris@87
|
40 void reset();
|
Chris@87
|
41
|
Chris@95
|
42 float getValueAt(size_t x, size_t y);
|
Chris@95
|
43 void getColumnAt(size_t x, float *values);
|
Chris@87
|
44
|
Chris@87
|
45 void setValueAt(size_t x, size_t y, float value);
|
Chris@87
|
46 void setColumnAt(size_t x, float *values);
|
Chris@95
|
47
|
Chris@95
|
48 protected slots:
|
Chris@95
|
49 void requestCancelled(int token);
|
Chris@95
|
50
|
Chris@87
|
51 protected:
|
Chris@87
|
52 int m_fd;
|
Chris@87
|
53 Mode m_mode;
|
Chris@87
|
54 size_t m_width;
|
Chris@87
|
55 size_t m_height;
|
Chris@87
|
56 size_t m_headerSize;
|
Chris@92
|
57 QString m_fileName;
|
Chris@95
|
58 size_t m_defaultCacheWidth;
|
Chris@95
|
59 size_t m_prevX;
|
Chris@87
|
60
|
Chris@95
|
61 struct Cache {
|
Chris@95
|
62 size_t x;
|
Chris@95
|
63 size_t width;
|
Chris@95
|
64 float *data;
|
Chris@95
|
65 };
|
Chris@90
|
66
|
Chris@95
|
67 Cache m_cache;
|
Chris@87
|
68
|
Chris@95
|
69 bool getValuesFromCache(size_t x, size_t ystart, size_t ycount,
|
Chris@95
|
70 float *values);
|
Chris@95
|
71
|
Chris@95
|
72 void primeCache(size_t x, bool left);
|
Chris@95
|
73
|
Chris@95
|
74 bool seekTo(size_t x, size_t y);
|
Chris@95
|
75
|
Chris@95
|
76 FileReadThread m_readThread;
|
Chris@95
|
77 int m_requestToken;
|
Chris@95
|
78 size_t m_requestingX;
|
Chris@95
|
79 size_t m_requestingWidth;
|
Chris@92
|
80
|
Chris@92
|
81 static std::map<QString, int> m_refcount;
|
Chris@92
|
82 static QMutex m_refcountMutex;
|
Chris@95
|
83 QMutex m_fdMutex;
|
Chris@95
|
84 QMutex m_cacheMutex;
|
Chris@87
|
85 };
|
Chris@87
|
86
|
Chris@87
|
87 #endif
|
Chris@87
|
88
|