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

* Merge from trunk
author Chris Cannam
date Wed, 27 Feb 2008 11:59:42 +0000
parents 7a4bd2c8585c
children
comparison
equal deleted inserted replaced
337:a6fab10ff9e6 384:6f6ab834449d
30 */ 30 */
31 31
32 struct Note 32 struct Note
33 { 33 {
34 public: 34 public:
35 Note(long _frame) : frame(_frame), value(0.0f), duration(0) { } 35 Note(long _frame) : frame(_frame), value(0.0f), duration(0), level(1.f) { }
36 Note(long _frame, float _value, size_t _duration, QString _label) : 36 Note(long _frame, float _value, size_t _duration, float _level, QString _label) :
37 frame(_frame), value(_value), duration(_duration), label(_label) { } 37 frame(_frame), value(_value), duration(_duration), level(_level), label(_label) { }
38 38
39 int getDimensions() const { return 3; } 39 int getDimensions() const { return 3; }
40 40
41 long frame; 41 long frame;
42 float value; 42 float value;
43 size_t duration; 43 size_t duration;
44 float level;
44 QString label; 45 QString label;
45 46
47 QString getLabel() const { return label; }
48
46 void toXml(QTextStream &stream, 49 void toXml(QTextStream &stream,
47 QString indent = "", 50 QString indent = "",
48 QString extraAttributes = "") const 51 QString extraAttributes = "") const
49 { 52 {
50 stream << 53 stream <<
51 QString("%1<point frame=\"%2\" value=\"%3\" duration=\"%4\" label=\"%5\" %6/>\n") 54 QString("%1<point frame=\"%2\" value=\"%3\" duration=\"%4\" level=\"%5\" label=\"%6\" %7/>\n")
52 .arg(indent).arg(frame).arg(value).arg(duration).arg(label).arg(extraAttributes); 55 .arg(indent).arg(frame).arg(value).arg(duration).arg(level).arg(label).arg(extraAttributes);
53 } 56 }
54 57
55 QString toDelimitedDataString(QString delimiter, size_t sampleRate) const 58 QString toDelimitedDataString(QString delimiter, size_t sampleRate) const
56 { 59 {
57 QStringList list; 60 QStringList list;
58 list << RealTime::frame2RealTime(frame, sampleRate).toString().c_str(); 61 list << RealTime::frame2RealTime(frame, sampleRate).toString().c_str();
59 list << QString("%1").arg(value); 62 list << QString("%1").arg(value);
60 list << QString("%1").arg(duration); 63 list << RealTime::frame2RealTime(duration, sampleRate).toString().c_str();
64 list << QString("%1").arg(level);
61 if (label != "") list << label; 65 if (label != "") list << label;
62 return list.join(delimiter); 66 return list.join(delimiter);
63 } 67 }
64 68
65 struct Comparator { 69 struct Comparator {
66 bool operator()(const Note &p1, 70 bool operator()(const Note &p1,
67 const Note &p2) const { 71 const Note &p2) const {
68 if (p1.frame != p2.frame) return p1.frame < p2.frame; 72 if (p1.frame != p2.frame) return p1.frame < p2.frame;
69 if (p1.value != p2.value) return p1.value < p2.value; 73 if (p1.value != p2.value) return p1.value < p2.value;
70 if (p1.duration != p2.duration) return p1.duration < p2.duration; 74 if (p1.duration != p2.duration) return p1.duration < p2.duration;
75 if (p1.level != p2.level) return p1.level < p2.level;
71 return p1.label < p2.label; 76 return p1.label < p2.label;
72 } 77 }
73 }; 78 };
74 79
75 struct OrderComparator { 80 struct OrderComparator {
120 * given frame. Consequently this can be very slow (optimised 125 * given frame. Consequently this can be very slow (optimised
121 * data structures still to be done!). 126 * data structures still to be done!).
122 */ 127 */
123 virtual PointList getPoints(long frame) const; 128 virtual PointList getPoints(long frame) const;
124 129
130 QString getTypeName() const { return tr("Note"); }
131
125 virtual void toXml(QTextStream &out, 132 virtual void toXml(QTextStream &out,
126 QString indent = "", 133 QString indent = "",
127 QString extraAttributes = "") const 134 QString extraAttributes = "") const
128 { 135 {
129 std::cerr << "NoteModel::toXml: extraAttributes = \"" 136 std::cerr << "NoteModel::toXml: extraAttributes = \""