Mercurial > hg > svcore
comparison data/model/SparseModel.h @ 1453:4b496a258782
Merge from branch streaming-csv-writer
author | Chris Cannam |
---|---|
date | Tue, 17 Apr 2018 10:52:06 +0100 |
parents | 6e9615bde1f9 |
children | 904e031c9c76 |
comparison
equal
deleted
inserted
replaced
1429:48e9f538e6e9 | 1453:4b496a258782 |
---|---|
11 published by the Free Software Foundation; either version 2 of the | 11 published by the Free Software Foundation; either version 2 of the |
12 License, or (at your option) any later version. See the file | 12 License, or (at your option) any later version. See the file |
13 COPYING included with this distribution for more information. | 13 COPYING included with this distribution for more information. |
14 */ | 14 */ |
15 | 15 |
16 #ifndef _SPARSE_MODEL_H_ | 16 #ifndef SV_SPARSE_MODEL_H |
17 #define _SPARSE_MODEL_H_ | 17 #define SV_SPARSE_MODEL_H |
18 | 18 |
19 #include "Model.h" | 19 #include "Model.h" |
20 #include "TabularModel.h" | 20 #include "TabularModel.h" |
21 #include "base/Command.h" | 21 #include "base/Command.h" |
22 #include "base/RealTime.h" | 22 #include "base/RealTime.h" |
60 // 10 sample frames later. | 60 // 10 sample frames later. |
61 virtual int getResolution() const { | 61 virtual int getResolution() const { |
62 return m_resolution ? m_resolution : 1; | 62 return m_resolution ? m_resolution : 1; |
63 } | 63 } |
64 virtual void setResolution(int resolution); | 64 virtual void setResolution(int resolution); |
65 | |
66 // Extend the end of the model. If this is set to something beyond | |
67 // the end of the final point in the model, then getEndFrame() | |
68 // will return this value. Otherwise getEndFrame() will return the | |
69 // end of the final point. | |
70 virtual void extendEndFrame(sv_frame_t to) { m_extendTo = to; } | |
71 | 65 |
72 typedef PointType Point; | 66 typedef PointType Point; |
73 typedef std::multiset<PointType, | 67 typedef std::multiset<PointType, |
74 typename PointType::OrderComparator> PointList; | 68 typename PointType::OrderComparator> PointList; |
75 typedef typename PointList::iterator PointListIterator; | 69 typedef typename PointList::iterator PointListIterator; |
149 virtual void setCompletion(int completion, bool update = true); | 143 virtual void setCompletion(int completion, bool update = true); |
150 virtual int getCompletion() const { return m_completion; } | 144 virtual int getCompletion() const { return m_completion; } |
151 | 145 |
152 virtual bool hasTextLabels() const { return m_hasTextLabels; } | 146 virtual bool hasTextLabels() const { return m_hasTextLabels; } |
153 | 147 |
148 virtual bool isSparse() const { return true; } | |
149 | |
154 QString getTypeName() const { return tr("Sparse"); } | 150 QString getTypeName() const { return tr("Sparse"); } |
155 | 151 |
156 virtual QString getXmlOutputType() const { return "sparse"; } | 152 virtual QString getXmlOutputType() const { return "sparse"; } |
157 | 153 |
158 virtual void toXml(QTextStream &out, | 154 virtual void toXml(QTextStream &out, |
166 | 162 |
167 virtual QString toDelimitedDataStringWithOptions(QString delimiter, | 163 virtual QString toDelimitedDataStringWithOptions(QString delimiter, |
168 DataExportOptions opts) const { | 164 DataExportOptions opts) const { |
169 return toDelimitedDataStringSubsetWithOptions | 165 return toDelimitedDataStringSubsetWithOptions |
170 (delimiter, opts, | 166 (delimiter, opts, |
171 std::min(getStartFrame(), sv_frame_t(0)), getEndFrame() + 1); | 167 std::min(getStartFrame(), sv_frame_t(0)), getEndFrame()); |
172 } | 168 } |
173 | 169 |
174 virtual QString toDelimitedDataStringSubset(QString delimiter, sv_frame_t f0, sv_frame_t f1) const { | 170 virtual QString toDelimitedDataStringSubset(QString delimiter, sv_frame_t f0, sv_frame_t f1) const { |
175 return toDelimitedDataStringSubsetWithOptions | 171 return toDelimitedDataStringSubsetWithOptions |
176 (delimiter, DataExportDefaults, f0, f1); | 172 (delimiter, DataExportDefaults, f0, f1); |
393 } | 389 } |
394 | 390 |
395 protected: | 391 protected: |
396 sv_samplerate_t m_sampleRate; | 392 sv_samplerate_t m_sampleRate; |
397 int m_resolution; | 393 int m_resolution; |
398 sv_frame_t m_extendTo; | |
399 bool m_notifyOnAdd; | 394 bool m_notifyOnAdd; |
400 sv_frame_t m_sinceLastNotifyMin; | 395 sv_frame_t m_sinceLastNotifyMin; |
401 sv_frame_t m_sinceLastNotifyMax; | 396 sv_frame_t m_sinceLastNotifyMax; |
402 bool m_hasTextLabels; | 397 bool m_hasTextLabels; |
403 | 398 |
539 SparseModel<PointType>::SparseModel(sv_samplerate_t sampleRate, | 534 SparseModel<PointType>::SparseModel(sv_samplerate_t sampleRate, |
540 int resolution, | 535 int resolution, |
541 bool notifyOnAdd) : | 536 bool notifyOnAdd) : |
542 m_sampleRate(sampleRate), | 537 m_sampleRate(sampleRate), |
543 m_resolution(resolution), | 538 m_resolution(resolution), |
544 m_extendTo(0), | |
545 m_notifyOnAdd(notifyOnAdd), | 539 m_notifyOnAdd(notifyOnAdd), |
546 m_sinceLastNotifyMin(-1), | 540 m_sinceLastNotifyMin(-1), |
547 m_sinceLastNotifyMax(-1), | 541 m_sinceLastNotifyMax(-1), |
548 m_hasTextLabels(false), | 542 m_hasTextLabels(false), |
549 m_pointCount(0), | 543 m_pointCount(0), |
569 { | 563 { |
570 QMutexLocker locker(&m_mutex); | 564 QMutexLocker locker(&m_mutex); |
571 sv_frame_t f = 0; | 565 sv_frame_t f = 0; |
572 if (!m_points.empty()) { | 566 if (!m_points.empty()) { |
573 PointListConstIterator i(m_points.end()); | 567 PointListConstIterator i(m_points.end()); |
574 f = (--i)->frame; | 568 f = (--i)->frame + 1; |
575 } | 569 } |
576 if (m_extendTo > f) return m_extendTo; | 570 return f; |
577 else return f; | |
578 } | 571 } |
579 | 572 |
580 template <typename PointType> | 573 template <typename PointType> |
581 bool | 574 bool |
582 SparseModel<PointType>::isEmpty() const | 575 SparseModel<PointType>::isEmpty() const |