Mercurial > hg > svcore
comparison data/model/SparseTimeValueModel.h @ 1429:48e9f538e6e9
Untabify
author | Chris Cannam |
---|---|
date | Thu, 01 Mar 2018 18:02:22 +0000 |
parents | 1517d4c60e88 |
children | c01cbe41aeb5 |
comparison
equal
deleted
inserted
replaced
1428:87ae75da6527 | 1429:48e9f538e6e9 |
---|---|
29 struct TimeValuePoint | 29 struct TimeValuePoint |
30 { | 30 { |
31 public: | 31 public: |
32 TimeValuePoint(sv_frame_t _frame) : frame(_frame), value(0.0f) { } | 32 TimeValuePoint(sv_frame_t _frame) : frame(_frame), value(0.0f) { } |
33 TimeValuePoint(sv_frame_t _frame, float _value, QString _label) : | 33 TimeValuePoint(sv_frame_t _frame, float _value, QString _label) : |
34 frame(_frame), value(_value), label(_label) { } | 34 frame(_frame), value(_value), label(_label) { } |
35 | 35 |
36 int getDimensions() const { return 2; } | 36 int getDimensions() const { return 2; } |
37 | 37 |
38 sv_frame_t frame; | 38 sv_frame_t frame; |
39 float value; | 39 float value; |
43 | 43 |
44 void toXml(QTextStream &stream, QString indent = "", | 44 void toXml(QTextStream &stream, QString indent = "", |
45 QString extraAttributes = "") const | 45 QString extraAttributes = "") const |
46 { | 46 { |
47 stream << QString("%1<point frame=\"%2\" value=\"%3\" label=\"%4\" %5/>\n") | 47 stream << QString("%1<point frame=\"%2\" value=\"%3\" label=\"%4\" %5/>\n") |
48 .arg(indent).arg(frame).arg(value).arg(XmlExportable::encodeEntities(label)) | 48 .arg(indent).arg(frame).arg(value).arg(XmlExportable::encodeEntities(label)) |
49 .arg(extraAttributes); | 49 .arg(extraAttributes); |
50 } | 50 } |
51 | 51 |
52 QString toDelimitedDataString(QString delimiter, DataExportOptions, sv_samplerate_t sampleRate) const | 52 QString toDelimitedDataString(QString delimiter, DataExportOptions, sv_samplerate_t sampleRate) const |
53 { | 53 { |
57 if (label != "") list << label; | 57 if (label != "") list << label; |
58 return list.join(delimiter); | 58 return list.join(delimiter); |
59 } | 59 } |
60 | 60 |
61 struct Comparator { | 61 struct Comparator { |
62 bool operator()(const TimeValuePoint &p1, | 62 bool operator()(const TimeValuePoint &p1, |
63 const TimeValuePoint &p2) const { | 63 const TimeValuePoint &p2) const { |
64 if (p1.frame != p2.frame) return p1.frame < p2.frame; | 64 if (p1.frame != p2.frame) return p1.frame < p2.frame; |
65 if (p1.value != p2.value) return p1.value < p2.value; | 65 if (p1.value != p2.value) return p1.value < p2.value; |
66 return p1.label < p2.label; | 66 return p1.label < p2.label; |
67 } | 67 } |
68 }; | 68 }; |
69 | 69 |
70 struct OrderComparator { | 70 struct OrderComparator { |
71 bool operator()(const TimeValuePoint &p1, | 71 bool operator()(const TimeValuePoint &p1, |
72 const TimeValuePoint &p2) const { | 72 const TimeValuePoint &p2) const { |
73 return p1.frame < p2.frame; | 73 return p1.frame < p2.frame; |
74 } | 74 } |
75 }; | 75 }; |
76 }; | 76 }; |
77 | 77 |
78 | 78 |
79 class SparseTimeValueModel : public SparseValueModel<TimeValuePoint> | 79 class SparseTimeValueModel : public SparseValueModel<TimeValuePoint> |
80 { | 80 { |
81 Q_OBJECT | 81 Q_OBJECT |
82 | 82 |
83 public: | 83 public: |
84 SparseTimeValueModel(sv_samplerate_t sampleRate, int resolution, | 84 SparseTimeValueModel(sv_samplerate_t sampleRate, int resolution, |
85 bool notifyOnAdd = true) : | 85 bool notifyOnAdd = true) : |
86 SparseValueModel<TimeValuePoint>(sampleRate, resolution, | 86 SparseValueModel<TimeValuePoint>(sampleRate, resolution, |
87 notifyOnAdd) | 87 notifyOnAdd) |
88 { | 88 { |
89 // Model is playable, but may not sound (if units not Hz or | 89 // Model is playable, but may not sound (if units not Hz or |
90 // range unsuitable) | 90 // range unsuitable) |
91 PlayParameterRepository::getInstance()->addPlayable(this); | 91 PlayParameterRepository::getInstance()->addPlayable(this); |
92 } | 92 } |
93 | 93 |
94 SparseTimeValueModel(sv_samplerate_t sampleRate, int resolution, | 94 SparseTimeValueModel(sv_samplerate_t sampleRate, int resolution, |
95 float valueMinimum, float valueMaximum, | 95 float valueMinimum, float valueMaximum, |
96 bool notifyOnAdd = true) : | 96 bool notifyOnAdd = true) : |
97 SparseValueModel<TimeValuePoint>(sampleRate, resolution, | 97 SparseValueModel<TimeValuePoint>(sampleRate, resolution, |
98 valueMinimum, valueMaximum, | 98 valueMinimum, valueMaximum, |
99 notifyOnAdd) | 99 notifyOnAdd) |
100 { | 100 { |
101 // Model is playable, but may not sound (if units not Hz or | 101 // Model is playable, but may not sound (if units not Hz or |
102 // range unsuitable) | 102 // range unsuitable) |
103 PlayParameterRepository::getInstance()->addPlayable(this); | 103 PlayParameterRepository::getInstance()->addPlayable(this); |
104 } | 104 } |
105 | 105 |
106 virtual ~SparseTimeValueModel() | 106 virtual ~SparseTimeValueModel() |
107 { | 107 { |
108 PlayParameterRepository::getInstance()->removePlayable(this); | 108 PlayParameterRepository::getInstance()->removePlayable(this); |
109 } | 109 } |
110 | 110 |
111 QString getTypeName() const { return tr("Sparse Time-Value"); } | 111 QString getTypeName() const { return tr("Sparse Time-Value"); } |
112 | 112 |
113 virtual bool canPlay() const { return true; } | 113 virtual bool canPlay() const { return true; } |