comparison data/model/AlignmentModel.h @ 384:6f6ab834449d spectrogram-cache-rejig

* Merge from trunk
author Chris Cannam
date Wed, 27 Feb 2008 11:59:42 +0000
parents a71dec01c4d3
children
comparison
equal deleted inserted replaced
337:a6fab10ff9e6 384:6f6ab834449d
15 15
16 #ifndef _ALIGNMENT_MODEL_H_ 16 #ifndef _ALIGNMENT_MODEL_H_
17 #define _ALIGNMENT_MODEL_H_ 17 #define _ALIGNMENT_MODEL_H_
18 18
19 #include "Model.h" 19 #include "Model.h"
20 #include "SparseModel.h"
21 #include "base/RealTime.h"
22
23 #include <QString>
24 #include <QStringList>
20 25
21 class SparseTimeValueModel; 26 class SparseTimeValueModel;
22 27
23 class AlignmentModel : public Model 28 class AlignmentModel : public Model
24 { 29 {
37 virtual size_t getSampleRate() const; 42 virtual size_t getSampleRate() const;
38 virtual Model *clone() const; 43 virtual Model *clone() const;
39 virtual bool isReady(int *completion = 0) const; 44 virtual bool isReady(int *completion = 0) const;
40 virtual const ZoomConstraint *getZoomConstraint() const; 45 virtual const ZoomConstraint *getZoomConstraint() const;
41 46
47 QString getTypeName() const { return tr("Alignment"); }
48
42 const Model *getReferenceModel() const; 49 const Model *getReferenceModel() const;
43 const Model *getAlignedModel() const; 50 const Model *getAlignedModel() const;
44 51
45 size_t toReference(size_t frame) const; 52 size_t toReference(size_t frame) const;
46 size_t fromReference(size_t frame) const; 53 size_t fromReference(size_t frame) const;
58 protected: 65 protected:
59 Model *m_reference; // I don't own this 66 Model *m_reference; // I don't own this
60 Model *m_aligned; // I don't own this 67 Model *m_aligned; // I don't own this
61 68
62 Model *m_inputModel; // I own this 69 Model *m_inputModel; // I own this
63 SparseTimeValueModel *m_path; // I own this 70
64 mutable SparseTimeValueModel *m_reversePath; // I own this 71 struct PathPoint
72 {
73 PathPoint(long _frame) : frame(_frame), mapframe(_frame) { }
74 PathPoint(long _frame, long _mapframe) :
75 frame(_frame), mapframe(_mapframe) { }
76
77 int getDimensions() const { return 2; }
78
79 long frame;
80 long mapframe;
81
82 QString getLabel() const { return ""; }
83
84 void toXml(QTextStream &stream, QString indent = "",
85 QString extraAttributes = "") const {
86 stream << QString("%1<point frame=\"%2\" mapframe=\"%3\" %4/>\n")
87 .arg(indent).arg(frame).arg(mapframe).arg(extraAttributes);
88 }
89
90 QString toDelimitedDataString(QString delimiter,
91 size_t sampleRate) const {
92 QStringList list;
93 list << RealTime::frame2RealTime(frame, sampleRate).toString().c_str();
94 list << QString("%1").arg(mapframe);
95 return list.join(delimiter);
96 }
97
98 struct Comparator {
99 bool operator()(const PathPoint &p1, const PathPoint &p2) const {
100 if (p1.frame != p2.frame) return p1.frame < p2.frame;
101 return p1.mapframe < p2.mapframe;
102 }
103 };
104
105 struct OrderComparator {
106 bool operator()(const PathPoint &p1, const PathPoint &p2) const {
107 return p1.frame < p2.frame;
108 }
109 };
110 };
111
112 class PathModel : public SparseModel<PathPoint>
113 {
114 public:
115 PathModel(size_t sampleRate, size_t resolution, bool notify = true) :
116 SparseModel<PathPoint>(sampleRate, resolution, notify) { }
117 };
118
119 SparseTimeValueModel *m_rawPath; // I own this
120 mutable PathModel *m_path; // I own this
121 mutable PathModel *m_reversePath; // I own this
65 bool m_pathBegun; 122 bool m_pathBegun;
66 bool m_pathComplete; 123 bool m_pathComplete;
67 124
125 void constructPath() const;
68 void constructReversePath() const; 126 void constructReversePath() const;
69 127
70 size_t align(SparseTimeValueModel *path, size_t frame) const; 128 size_t align(PathModel *path, size_t frame) const;
71 }; 129 };
72 130
73 #endif 131 #endif