comparison data/model/SparseValueModel.h @ 1429:48e9f538e6e9

Untabify
author Chris Cannam
date Thu, 01 Mar 2018 18:02:22 +0000
parents a1cd5abcb38b
children c01cbe41aeb5
comparison
equal deleted inserted replaced
1428:87ae75da6527 1429:48e9f538e6e9
30 template <typename PointType> 30 template <typename PointType>
31 class SparseValueModel : public SparseModel<PointType> 31 class SparseValueModel : public SparseModel<PointType>
32 { 32 {
33 public: 33 public:
34 SparseValueModel(sv_samplerate_t sampleRate, int resolution, 34 SparseValueModel(sv_samplerate_t sampleRate, int resolution,
35 bool notifyOnAdd = true) : 35 bool notifyOnAdd = true) :
36 SparseModel<PointType>(sampleRate, resolution, notifyOnAdd), 36 SparseModel<PointType>(sampleRate, resolution, notifyOnAdd),
37 m_valueMinimum(0.f), 37 m_valueMinimum(0.f),
38 m_valueMaximum(0.f), 38 m_valueMaximum(0.f),
39 m_haveExtents(false) 39 m_haveExtents(false)
40 { } 40 { }
41 41
42 SparseValueModel(sv_samplerate_t sampleRate, int resolution, 42 SparseValueModel(sv_samplerate_t sampleRate, int resolution,
43 float valueMinimum, float valueMaximum, 43 float valueMinimum, float valueMaximum,
44 bool notifyOnAdd = true) : 44 bool notifyOnAdd = true) :
45 SparseModel<PointType>(sampleRate, resolution, notifyOnAdd), 45 SparseModel<PointType>(sampleRate, resolution, notifyOnAdd),
46 m_valueMinimum(valueMinimum), 46 m_valueMinimum(valueMinimum),
47 m_valueMaximum(valueMaximum), 47 m_valueMaximum(valueMaximum),
48 m_haveExtents(true) 48 m_haveExtents(true)
49 { } 49 { }
50 50
51 using SparseModel<PointType>::m_points; 51 using SparseModel<PointType>::m_points;
52 using SparseModel<PointType>::modelChanged; 52 using SparseModel<PointType>::modelChanged;
64 UnitDatabase::getInstance()->registerUnit(units); 64 UnitDatabase::getInstance()->registerUnit(units);
65 } 65 }
66 66
67 virtual void addPoint(const PointType &point) 67 virtual void addPoint(const PointType &point)
68 { 68 {
69 bool allChange = false; 69 bool allChange = false;
70 70
71 if (!ISNAN(point.value) && !ISINF(point.value)) { 71 if (!ISNAN(point.value) && !ISINF(point.value)) {
72 if (!m_haveExtents || point.value < m_valueMinimum) { 72 if (!m_haveExtents || point.value < m_valueMinimum) {
73 m_valueMinimum = point.value; allChange = true; 73 m_valueMinimum = point.value; allChange = true;
74 // std::cerr << "addPoint: value min = " << m_valueMinimum << std::endl; 74 // std::cerr << "addPoint: value min = " << m_valueMinimum << std::endl;
78 // std::cerr << "addPoint: value max = " << m_valueMaximum << " (min = " << m_valueMinimum << ")" << std::endl; 78 // std::cerr << "addPoint: value max = " << m_valueMaximum << " (min = " << m_valueMinimum << ")" << std::endl;
79 } 79 }
80 m_haveExtents = true; 80 m_haveExtents = true;
81 } 81 }
82 82
83 SparseModel<PointType>::addPoint(point); 83 SparseModel<PointType>::addPoint(point);
84 if (allChange) emit modelChanged(); 84 if (allChange) emit modelChanged();
85 } 85 }
86 86
87 virtual void deletePoint(const PointType &point) 87 virtual void deletePoint(const PointType &point)
88 { 88 {
89 SparseModel<PointType>::deletePoint(point); 89 SparseModel<PointType>::deletePoint(point);
90 90
91 if (point.value == m_valueMinimum || 91 if (point.value == m_valueMinimum ||
92 point.value == m_valueMaximum) { 92 point.value == m_valueMaximum) {
93 93
94 float formerMin = m_valueMinimum, formerMax = m_valueMaximum; 94 float formerMin = m_valueMinimum, formerMax = m_valueMaximum;
95 95
96 for (typename SparseModel<PointType>::PointList::const_iterator i 96 for (typename SparseModel<PointType>::PointList::const_iterator i
97 = m_points.begin(); 97 = m_points.begin();
98 i != m_points.end(); ++i) { 98 i != m_points.end(); ++i) {
99 99
100 if (i == m_points.begin() || i->value < m_valueMinimum) { 100 if (i == m_points.begin() || i->value < m_valueMinimum) {
101 m_valueMinimum = i->value; 101 m_valueMinimum = i->value;
102 // std::cerr << "deletePoint: value min = " << m_valueMinimum << std::endl; 102 // std::cerr << "deletePoint: value min = " << m_valueMinimum << std::endl;
103 } 103 }
104 if (i == m_points.begin() || i->value > m_valueMaximum) { 104 if (i == m_points.begin() || i->value > m_valueMaximum) {
105 m_valueMaximum = i->value; 105 m_valueMaximum = i->value;
106 // std::cerr << "deletePoint: value max = " << m_valueMaximum << std::endl; 106 // std::cerr << "deletePoint: value max = " << m_valueMaximum << std::endl;
107 } 107 }
108 } 108 }
109 109
110 if (formerMin != m_valueMinimum || formerMax != m_valueMaximum) { 110 if (formerMin != m_valueMinimum || formerMax != m_valueMaximum) {
111 emit modelChanged(); 111 emit modelChanged();
112 } 112 }
113 } 113 }
114 } 114 }
115 115
116 virtual void toXml(QTextStream &stream, 116 virtual void toXml(QTextStream &stream,
117 QString indent = "", 117 QString indent = "",
118 QString extraAttributes = "") const 118 QString extraAttributes = "") const
119 { 119 {
120 std::cerr << "SparseValueModel::toXml: extraAttributes = \"" 120 std::cerr << "SparseValueModel::toXml: extraAttributes = \""
121 << extraAttributes.toStdString() << std::endl; 121 << extraAttributes.toStdString() << std::endl;
122 122
123 SparseModel<PointType>::toXml 123 SparseModel<PointType>::toXml
124 (stream, 124 (stream,
125 indent, 125 indent,
126 QString("%1 minimum=\"%2\" maximum=\"%3\" units=\"%4\"") 126 QString("%1 minimum=\"%2\" maximum=\"%3\" units=\"%4\"")
127 .arg(extraAttributes).arg(m_valueMinimum).arg(m_valueMaximum) 127 .arg(extraAttributes).arg(m_valueMinimum).arg(m_valueMaximum)
128 .arg(this->encodeEntities(m_units))); 128 .arg(this->encodeEntities(m_units)));
129 } 129 }
130 130
131 protected: 131 protected:
132 float m_valueMinimum; 132 float m_valueMinimum;