comparison data/model/NoteModel.h @ 1527:710e6250a401 zoom

Merge from default branch
author Chris Cannam
date Mon, 17 Sep 2018 13:51:14 +0100
parents 6965c83c8fa7
children c01cbe41aeb5
comparison
equal deleted inserted replaced
1324:d4a28d1479a8 1527:710e6250a401
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 _NOTE_MODEL_H_ 16 #ifndef SV_NOTE_MODEL_H
17 #define _NOTE_MODEL_H_ 17 #define SV_NOTE_MODEL_H
18 18
19 #include "IntervalModel.h" 19 #include "IntervalModel.h"
20 #include "NoteData.h" 20 #include "NoteData.h"
21 #include "base/RealTime.h" 21 #include "base/RealTime.h"
22 #include "base/PlayParameterRepository.h" 22 #include "base/PlayParameterRepository.h"
38 struct Note 38 struct Note
39 { 39 {
40 public: 40 public:
41 Note(sv_frame_t _frame) : frame(_frame), value(0.0f), duration(0), level(1.f) { } 41 Note(sv_frame_t _frame) : frame(_frame), value(0.0f), duration(0), level(1.f) { }
42 Note(sv_frame_t _frame, float _value, sv_frame_t _duration, float _level, QString _label) : 42 Note(sv_frame_t _frame, float _value, sv_frame_t _duration, float _level, QString _label) :
43 frame(_frame), value(_value), duration(_duration), level(_level), label(_label) { } 43 frame(_frame), value(_value), duration(_duration), level(_level), label(_label) { }
44 44
45 int getDimensions() const { return 3; } 45 int getDimensions() const { return 3; }
46 46
47 sv_frame_t frame; 47 sv_frame_t frame;
48 float value; 48 float value;
54 54
55 void toXml(QTextStream &stream, 55 void toXml(QTextStream &stream,
56 QString indent = "", 56 QString indent = "",
57 QString extraAttributes = "") const 57 QString extraAttributes = "") const
58 { 58 {
59 stream << 59 stream <<
60 QString("%1<point frame=\"%2\" value=\"%3\" duration=\"%4\" level=\"%5\" label=\"%6\" %7/>\n") 60 QString("%1<point frame=\"%2\" value=\"%3\" duration=\"%4\" level=\"%5\" label=\"%6\" %7/>\n")
61 .arg(indent).arg(frame).arg(value).arg(duration).arg(level) 61 .arg(indent).arg(frame).arg(value).arg(duration).arg(level)
62 .arg(XmlExportable::encodeEntities(label)).arg(extraAttributes); 62 .arg(XmlExportable::encodeEntities(label)).arg(extraAttributes);
63 } 63 }
64 64
65 QString toDelimitedDataString(QString delimiter, DataExportOptions opts, sv_samplerate_t sampleRate) const { 65 QString toDelimitedDataString(QString delimiter, DataExportOptions opts, sv_samplerate_t sampleRate) const {
66 QStringList list; 66 QStringList list;
73 if (label != "") list << label; 73 if (label != "") list << label;
74 return list.join(delimiter); 74 return list.join(delimiter);
75 } 75 }
76 76
77 struct Comparator { 77 struct Comparator {
78 bool operator()(const Note &p1, 78 bool operator()(const Note &p1,
79 const Note &p2) const { 79 const Note &p2) const {
80 if (p1.frame != p2.frame) return p1.frame < p2.frame; 80 if (p1.frame != p2.frame) return p1.frame < p2.frame;
81 if (p1.value != p2.value) return p1.value < p2.value; 81 if (p1.value != p2.value) return p1.value < p2.value;
82 if (p1.duration != p2.duration) return p1.duration < p2.duration; 82 if (p1.duration != p2.duration) return p1.duration < p2.duration;
83 if (p1.level != p2.level) return p1.level < p2.level; 83 if (p1.level != p2.level) return p1.level < p2.level;
84 return p1.label < p2.label; 84 return p1.label < p2.label;
85 } 85 }
86 }; 86 };
87 87
88 struct OrderComparator { 88 struct OrderComparator {
89 bool operator()(const Note &p1, 89 bool operator()(const Note &p1,
90 const Note &p2) const { 90 const Note &p2) const {
91 return p1.frame < p2.frame; 91 return p1.frame < p2.frame;
92 } 92 }
93 }; 93 };
94 }; 94 };
95 95
96 96
97 class NoteModel : public IntervalModel<Note>, public NoteExportable 97 class NoteModel : public IntervalModel<Note>, public NoteExportable
98 { 98 {
99 Q_OBJECT 99 Q_OBJECT
100 100
101 public: 101 public:
102 NoteModel(sv_samplerate_t sampleRate, int resolution, 102 NoteModel(sv_samplerate_t sampleRate, int resolution,
103 bool notifyOnAdd = true) : 103 bool notifyOnAdd = true) :
104 IntervalModel<Note>(sampleRate, resolution, notifyOnAdd), 104 IntervalModel<Note>(sampleRate, resolution, notifyOnAdd),
105 m_valueQuantization(0) 105 m_valueQuantization(0)
106 { 106 {
107 PlayParameterRepository::getInstance()->addPlayable(this); 107 PlayParameterRepository::getInstance()->addPlayable(this);
108 } 108 }
109 109
110 NoteModel(sv_samplerate_t sampleRate, int resolution, 110 NoteModel(sv_samplerate_t sampleRate, int resolution,
111 float valueMinimum, float valueMaximum, 111 float valueMinimum, float valueMaximum,
112 bool notifyOnAdd = true) : 112 bool notifyOnAdd = true) :
113 IntervalModel<Note>(sampleRate, resolution, 113 IntervalModel<Note>(sampleRate, resolution,
114 valueMinimum, valueMaximum, 114 valueMinimum, valueMaximum,
115 notifyOnAdd), 115 notifyOnAdd),
116 m_valueQuantization(0) 116 m_valueQuantization(0)
117 { 117 {
118 PlayParameterRepository::getInstance()->addPlayable(this); 118 PlayParameterRepository::getInstance()->addPlayable(this);
119 } 119 }
120 120
121 virtual ~NoteModel() 121 virtual ~NoteModel()
122 { 122 {
123 PlayParameterRepository::getInstance()->removePlayable(this); 123 PlayParameterRepository::getInstance()->removePlayable(this);
141 { 141 {
142 std::cerr << "NoteModel::toXml: extraAttributes = \"" 142 std::cerr << "NoteModel::toXml: extraAttributes = \""
143 << extraAttributes.toStdString() << std::endl; 143 << extraAttributes.toStdString() << std::endl;
144 144
145 IntervalModel<Note>::toXml 145 IntervalModel<Note>::toXml
146 (out, 146 (out,
147 indent, 147 indent,
148 QString("%1 subtype=\"note\" valueQuantization=\"%2\"") 148 QString("%1 subtype=\"note\" valueQuantization=\"%2\"")
149 .arg(extraAttributes).arg(m_valueQuantization)); 149 .arg(extraAttributes).arg(m_valueQuantization));
150 } 150 }
151 151
152 /** 152 /**
153 * TabularModel methods. 153 * TabularModel methods.
154 */ 154 */
225 return getNotesWithin(getStartFrame(), getEndFrame()); 225 return getNotesWithin(getStartFrame(), getEndFrame());
226 } 226 }
227 227
228 NoteList getNotesWithin(sv_frame_t startFrame, sv_frame_t endFrame) const { 228 NoteList getNotesWithin(sv_frame_t startFrame, sv_frame_t endFrame) const {
229 229
230 PointList points = getPoints(startFrame, endFrame); 230 PointList points = getPoints(startFrame, endFrame);
231 NoteList notes; 231 NoteList notes;
232 232
233 for (PointList::iterator pli = 233 for (PointList::iterator pli =
234 points.begin(); pli != points.end(); ++pli) { 234 points.begin(); pli != points.end(); ++pli) {
235 235
236 sv_frame_t duration = pli->duration; 236 sv_frame_t duration = pli->duration;
237 if (duration == 0 || duration == 1) { 237 if (duration == 0 || duration == 1) {
238 duration = sv_frame_t(getSampleRate() / 20); 238 duration = sv_frame_t(getSampleRate() / 20);
239 } 239 }
240 240
241 int pitch = int(lrintf(pli->value)); 241 int pitch = int(lrintf(pli->value));