Mercurial > hg > svcore
comparison data/model/SparseOneDimensionalModel.h @ 1429:48e9f538e6e9
Untabify
author | Chris Cannam |
---|---|
date | Thu, 01 Mar 2018 18:02:22 +0000 |
parents | 57633d605547 |
children | c01cbe41aeb5 |
comparison
equal
deleted
inserted
replaced
1428:87ae75da6527 | 1429:48e9f538e6e9 |
---|---|
39 void toXml(QTextStream &stream, | 39 void toXml(QTextStream &stream, |
40 QString indent = "", | 40 QString indent = "", |
41 QString extraAttributes = "") const | 41 QString extraAttributes = "") const |
42 { | 42 { |
43 stream << QString("%1<point frame=\"%2\" label=\"%3\" %4/>\n") | 43 stream << QString("%1<point frame=\"%2\" label=\"%3\" %4/>\n") |
44 .arg(indent).arg(frame).arg(XmlExportable::encodeEntities(label)) | 44 .arg(indent).arg(frame).arg(XmlExportable::encodeEntities(label)) |
45 .arg(extraAttributes); | 45 .arg(extraAttributes); |
46 } | 46 } |
47 | 47 |
48 QString toDelimitedDataString(QString delimiter, DataExportOptions, sv_samplerate_t sampleRate) const | 48 QString toDelimitedDataString(QString delimiter, DataExportOptions, sv_samplerate_t sampleRate) const |
49 { | 49 { |
52 if (label != "") list << label; | 52 if (label != "") list << label; |
53 return list.join(delimiter); | 53 return list.join(delimiter); |
54 } | 54 } |
55 | 55 |
56 struct Comparator { | 56 struct Comparator { |
57 bool operator()(const OneDimensionalPoint &p1, | 57 bool operator()(const OneDimensionalPoint &p1, |
58 const OneDimensionalPoint &p2) const { | 58 const OneDimensionalPoint &p2) const { |
59 if (p1.frame != p2.frame) return p1.frame < p2.frame; | 59 if (p1.frame != p2.frame) return p1.frame < p2.frame; |
60 return p1.label < p2.label; | 60 return p1.label < p2.label; |
61 } | 61 } |
62 }; | 62 }; |
63 | 63 |
64 struct OrderComparator { | 64 struct OrderComparator { |
65 bool operator()(const OneDimensionalPoint &p1, | 65 bool operator()(const OneDimensionalPoint &p1, |
66 const OneDimensionalPoint &p2) const { | 66 const OneDimensionalPoint &p2) const { |
67 return p1.frame < p2.frame; | 67 return p1.frame < p2.frame; |
68 } | 68 } |
69 }; | 69 }; |
70 }; | 70 }; |
71 | 71 |
72 | 72 |
73 class SparseOneDimensionalModel : public SparseModel<OneDimensionalPoint>, | 73 class SparseOneDimensionalModel : public SparseModel<OneDimensionalPoint>, |
75 { | 75 { |
76 Q_OBJECT | 76 Q_OBJECT |
77 | 77 |
78 public: | 78 public: |
79 SparseOneDimensionalModel(sv_samplerate_t sampleRate, int resolution, | 79 SparseOneDimensionalModel(sv_samplerate_t sampleRate, int resolution, |
80 bool notifyOnAdd = true) : | 80 bool notifyOnAdd = true) : |
81 SparseModel<OneDimensionalPoint>(sampleRate, resolution, notifyOnAdd) | 81 SparseModel<OneDimensionalPoint>(sampleRate, resolution, notifyOnAdd) |
82 { | 82 { |
83 PlayParameterRepository::getInstance()->addPlayable(this); | 83 PlayParameterRepository::getInstance()->addPlayable(this); |
84 } | 84 } |
85 | 85 |
86 virtual ~SparseOneDimensionalModel() | 86 virtual ~SparseOneDimensionalModel() |
87 { | 87 { |
88 PlayParameterRepository::getInstance()->removePlayable(this); | 88 PlayParameterRepository::getInstance()->removePlayable(this); |
95 return "tap"; | 95 return "tap"; |
96 } | 96 } |
97 | 97 |
98 int getIndexOf(const Point &point) | 98 int getIndexOf(const Point &point) |
99 { | 99 { |
100 // slow | 100 // slow |
101 int i = 0; | 101 int i = 0; |
102 Point::Comparator comparator; | 102 Point::Comparator comparator; |
103 for (PointList::const_iterator j = m_points.begin(); | 103 for (PointList::const_iterator j = m_points.begin(); |
104 j != m_points.end(); ++j, ++i) { | 104 j != m_points.end(); ++j, ++i) { |
105 if (!comparator(*j, point) && !comparator(point, *j)) return i; | 105 if (!comparator(*j, point) && !comparator(point, *j)) return i; |
106 } | 106 } |
107 return -1; | 107 return -1; |
108 } | 108 } |
109 | 109 |
110 QString getTypeName() const { return tr("Sparse 1-D"); } | 110 QString getTypeName() const { return tr("Sparse 1-D"); } |
111 | 111 |
112 /** | 112 /** |
187 return getNotesWithin(getStartFrame(), getEndFrame()); | 187 return getNotesWithin(getStartFrame(), getEndFrame()); |
188 } | 188 } |
189 | 189 |
190 NoteList getNotesWithin(sv_frame_t startFrame, sv_frame_t endFrame) const { | 190 NoteList getNotesWithin(sv_frame_t startFrame, sv_frame_t endFrame) const { |
191 | 191 |
192 PointList points = getPoints(startFrame, endFrame); | 192 PointList points = getPoints(startFrame, endFrame); |
193 NoteList notes; | 193 NoteList notes; |
194 | 194 |
195 for (PointList::iterator pli = | 195 for (PointList::iterator pli = |
196 points.begin(); pli != points.end(); ++pli) { | 196 points.begin(); pli != points.end(); ++pli) { |
197 | 197 |
198 notes.push_back | 198 notes.push_back |
199 (NoteData(pli->frame, | 199 (NoteData(pli->frame, |
200 sv_frame_t(getSampleRate() / 6), // arbitrary short duration | 200 sv_frame_t(getSampleRate() / 6), // arbitrary short duration |
201 64, // default pitch | 201 64, // default pitch |