comparison data/model/FlexiNoteModel.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
42 struct FlexiNote 42 struct FlexiNote
43 { 43 {
44 public: 44 public:
45 FlexiNote(sv_frame_t _frame) : frame(_frame), value(0.0f), duration(0), level(1.f) { } 45 FlexiNote(sv_frame_t _frame) : frame(_frame), value(0.0f), duration(0), level(1.f) { }
46 FlexiNote(sv_frame_t _frame, float _value, sv_frame_t _duration, float _level, QString _label) : 46 FlexiNote(sv_frame_t _frame, float _value, sv_frame_t _duration, float _level, QString _label) :
47 frame(_frame), value(_value), duration(_duration), level(_level), label(_label) { } 47 frame(_frame), value(_value), duration(_duration), level(_level), label(_label) { }
48 48
49 int getDimensions() const { return 3; } 49 int getDimensions() const { return 3; }
50 50
51 sv_frame_t frame; 51 sv_frame_t frame;
52 float value; 52 float value;
58 58
59 void toXml(QTextStream &stream, 59 void toXml(QTextStream &stream,
60 QString indent = "", 60 QString indent = "",
61 QString extraAttributes = "") const 61 QString extraAttributes = "") const
62 { 62 {
63 stream << 63 stream <<
64 QString("%1<point frame=\"%2\" value=\"%3\" duration=\"%4\" level=\"%5\" label=\"%6\" %7/>\n") 64 QString("%1<point frame=\"%2\" value=\"%3\" duration=\"%4\" level=\"%5\" label=\"%6\" %7/>\n")
65 .arg(indent).arg(frame).arg(value).arg(duration).arg(level) 65 .arg(indent).arg(frame).arg(value).arg(duration).arg(level)
66 .arg(XmlExportable::encodeEntities(label)).arg(extraAttributes); 66 .arg(XmlExportable::encodeEntities(label)).arg(extraAttributes);
67 } 67 }
68 68
69 QString toDelimitedDataString(QString delimiter, DataExportOptions opts, sv_samplerate_t sampleRate) const 69 QString toDelimitedDataString(QString delimiter, DataExportOptions opts, sv_samplerate_t sampleRate) const
70 { 70 {
78 if (label != "") list << label; 78 if (label != "") list << label;
79 return list.join(delimiter); 79 return list.join(delimiter);
80 } 80 }
81 81
82 struct Comparator { 82 struct Comparator {
83 bool operator()(const FlexiNote &p1, 83 bool operator()(const FlexiNote &p1,
84 const FlexiNote &p2) const { 84 const FlexiNote &p2) const {
85 if (p1.frame != p2.frame) return p1.frame < p2.frame; 85 if (p1.frame != p2.frame) return p1.frame < p2.frame;
86 if (p1.value != p2.value) return p1.value < p2.value; 86 if (p1.value != p2.value) return p1.value < p2.value;
87 if (p1.duration != p2.duration) return p1.duration < p2.duration; 87 if (p1.duration != p2.duration) return p1.duration < p2.duration;
88 if (p1.level != p2.level) return p1.level < p2.level; 88 if (p1.level != p2.level) return p1.level < p2.level;
89 return p1.label < p2.label; 89 return p1.label < p2.label;
90 } 90 }
91 }; 91 };
92 92
93 struct OrderComparator { 93 struct OrderComparator {
94 bool operator()(const FlexiNote &p1, 94 bool operator()(const FlexiNote &p1,
95 const FlexiNote &p2) const { 95 const FlexiNote &p2) const {
96 return p1.frame < p2.frame; 96 return p1.frame < p2.frame;
97 } 97 }
98 }; 98 };
99 }; 99 };
100 100
101 101
102 class FlexiNoteModel : public IntervalModel<FlexiNote>, public NoteExportable 102 class FlexiNoteModel : public IntervalModel<FlexiNote>, public NoteExportable
104 Q_OBJECT 104 Q_OBJECT
105 105
106 public: 106 public:
107 FlexiNoteModel(sv_samplerate_t sampleRate, int resolution, 107 FlexiNoteModel(sv_samplerate_t sampleRate, int resolution,
108 bool notifyOnAdd = true) : 108 bool notifyOnAdd = true) :
109 IntervalModel<FlexiNote>(sampleRate, resolution, notifyOnAdd), 109 IntervalModel<FlexiNote>(sampleRate, resolution, notifyOnAdd),
110 m_valueQuantization(0) 110 m_valueQuantization(0)
111 { 111 {
112 PlayParameterRepository::getInstance()->addPlayable(this); 112 PlayParameterRepository::getInstance()->addPlayable(this);
113 } 113 }
114 114
115 FlexiNoteModel(sv_samplerate_t sampleRate, int resolution, 115 FlexiNoteModel(sv_samplerate_t sampleRate, int resolution,
116 float valueMinimum, float valueMaximum, 116 float valueMinimum, float valueMaximum,
117 bool notifyOnAdd = true) : 117 bool notifyOnAdd = true) :
118 IntervalModel<FlexiNote>(sampleRate, resolution, 118 IntervalModel<FlexiNote>(sampleRate, resolution,
119 valueMinimum, valueMaximum, 119 valueMinimum, valueMaximum,
120 notifyOnAdd), 120 notifyOnAdd),
121 m_valueQuantization(0) 121 m_valueQuantization(0)
122 { 122 {
123 PlayParameterRepository::getInstance()->addPlayable(this); 123 PlayParameterRepository::getInstance()->addPlayable(this);
124 } 124 }
125 125
126 virtual ~FlexiNoteModel() 126 virtual ~FlexiNoteModel()
127 { 127 {
128 PlayParameterRepository::getInstance()->removePlayable(this); 128 PlayParameterRepository::getInstance()->removePlayable(this);
148 { 148 {
149 std::cerr << "FlexiNoteModel::toXml: extraAttributes = \"" 149 std::cerr << "FlexiNoteModel::toXml: extraAttributes = \""
150 << extraAttributes.toStdString() << std::endl; 150 << extraAttributes.toStdString() << std::endl;
151 151
152 IntervalModel<FlexiNote>::toXml 152 IntervalModel<FlexiNote>::toXml
153 (out, 153 (out,
154 indent, 154 indent,
155 QString("%1 subtype=\"flexinote\" valueQuantization=\"%2\"") 155 QString("%1 subtype=\"flexinote\" valueQuantization=\"%2\"")
156 .arg(extraAttributes).arg(m_valueQuantization)); 156 .arg(extraAttributes).arg(m_valueQuantization));
157 } 157 }
158 158
159 /** 159 /**
160 * TabularModel methods. 160 * TabularModel methods.
161 */ 161 */
233 return getNotesWithin(getStartFrame(), getEndFrame()); 233 return getNotesWithin(getStartFrame(), getEndFrame());
234 } 234 }
235 235
236 NoteList getNotesWithin(sv_frame_t startFrame, sv_frame_t endFrame) const 236 NoteList getNotesWithin(sv_frame_t startFrame, sv_frame_t endFrame) const
237 { 237 {
238 PointList points = getPoints(startFrame, endFrame); 238 PointList points = getPoints(startFrame, endFrame);
239 NoteList notes; 239 NoteList notes;
240 for (PointList::iterator pli = points.begin(); pli != points.end(); ++pli) { 240 for (PointList::iterator pli = points.begin(); pli != points.end(); ++pli) {
241 sv_frame_t duration = pli->duration; 241 sv_frame_t duration = pli->duration;
242 if (duration == 0 || duration == 1) { 242 if (duration == 0 || duration == 1) {
243 duration = sv_frame_t(getSampleRate() / 20); 243 duration = sv_frame_t(getSampleRate() / 20);
244 } 244 }
245 int pitch = int(lrintf(pli->value)); 245 int pitch = int(lrintf(pli->value));
246 246