comparison data/model/FlexiNoteModel.h @ 774:d3df9f50b188 tonioni

changed names in FlexiNoteModel to reflect new name (was copied from NoteModel)
author matthiasm
date Tue, 26 Mar 2013 14:20:19 +0000
parents 2079abf4f0c1
children 9aa3f343a6ea
comparison
equal deleted inserted replaced
773:2079abf4f0c1 774:d3df9f50b188
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 _FLEXINOTE_MODEL_H_
17 #define _NOTE_MODEL_H_ 17 #define _FLEXINOTE_MODEL_H_
18 18
19 #include "IntervalModel.h" 19 #include "IntervalModel.h"
20 #include "base/RealTime.h" 20 #include "base/RealTime.h"
21 #include "base/PlayParameterRepository.h" 21 #include "base/PlayParameterRepository.h"
22 22
23 /** 23 /**
24 * NoteModel -- a concrete IntervalModel for notes. 24 * FlexiNoteModel -- a concrete IntervalModel for notes.
25 */ 25 */
26 26
27 /** 27 /**
28 * Extension of the NoteModel for more flexible note interaction.
29 * The original NoteModel rationale is given below, will need to be
30 * updated for FlexiNoteModel:
31 *
28 * Note type for use in a sparse model. All we mean by a "note" is 32 * Note type for use in a sparse model. All we mean by a "note" is
29 * something that has an onset time, a single value, a duration, and a 33 * something that has an onset time, a single value, a duration, and a
30 * level. Like other points, it can also have a label. With this 34 * level. Like other points, it can also have a label. With this
31 * point type, the model can be thought of as representing a simple 35 * point type, the model can be thought of as representing a simple
32 * MIDI-type piano roll, except that the y coordinates (values) do not 36 * MIDI-type piano roll, except that the y coordinates (values) do not
33 * have to be discrete integers. 37 * have to be discrete integers.
34 */ 38 */
35 39
36 struct Note 40 struct FlexiNote
37 { 41 {
38 public: 42 public:
39 Note(long _frame) : frame(_frame), value(0.0f), duration(0), level(1.f) { } 43 FlexiNote(long _frame) : frame(_frame), value(0.0f), duration(0), level(1.f) { }
40 Note(long _frame, float _value, size_t _duration, float _level, QString _label) : 44 FlexiNote(long _frame, float _value, size_t _duration, float _level, QString _label) :
41 frame(_frame), value(_value), duration(_duration), level(_level), label(_label) { } 45 frame(_frame), value(_value), duration(_duration), level(_level), label(_label) { }
42 46
43 int getDimensions() const { return 3; } 47 int getDimensions() const { return 3; }
44 48
45 long frame; 49 long frame;
70 if (label != "") list << label; 74 if (label != "") list << label;
71 return list.join(delimiter); 75 return list.join(delimiter);
72 } 76 }
73 77
74 struct Comparator { 78 struct Comparator {
75 bool operator()(const Note &p1, 79 bool operator()(const FlexiNote &p1,
76 const Note &p2) const { 80 const FlexiNote &p2) const {
77 if (p1.frame != p2.frame) return p1.frame < p2.frame; 81 if (p1.frame != p2.frame) return p1.frame < p2.frame;
78 if (p1.value != p2.value) return p1.value < p2.value; 82 if (p1.value != p2.value) return p1.value < p2.value;
79 if (p1.duration != p2.duration) return p1.duration < p2.duration; 83 if (p1.duration != p2.duration) return p1.duration < p2.duration;
80 if (p1.level != p2.level) return p1.level < p2.level; 84 if (p1.level != p2.level) return p1.level < p2.level;
81 return p1.label < p2.label; 85 return p1.label < p2.label;
82 } 86 }
83 }; 87 };
84 88
85 struct OrderComparator { 89 struct OrderComparator {
86 bool operator()(const Note &p1, 90 bool operator()(const FlexiNote &p1,
87 const Note &p2) const { 91 const FlexiNote &p2) const {
88 return p1.frame < p2.frame; 92 return p1.frame < p2.frame;
89 } 93 }
90 }; 94 };
91 }; 95 };
92 96
93 97
94 class NoteModel : public IntervalModel<Note> 98 class FlexiNoteModel : public IntervalModel<FlexiNote>
95 { 99 {
96 Q_OBJECT 100 Q_OBJECT
97 101
98 public: 102 public:
99 NoteModel(size_t sampleRate, size_t resolution, 103 FlexiNoteModel(size_t sampleRate, size_t resolution,
100 bool notifyOnAdd = true) : 104 bool notifyOnAdd = true) :
101 IntervalModel<Note>(sampleRate, resolution, notifyOnAdd), 105 IntervalModel<FlexiNote>(sampleRate, resolution, notifyOnAdd),
102 m_valueQuantization(0) 106 m_valueQuantization(0)
103 { 107 {
104 PlayParameterRepository::getInstance()->addPlayable(this); 108 PlayParameterRepository::getInstance()->addPlayable(this);
105 } 109 }
106 110
107 NoteModel(size_t sampleRate, size_t resolution, 111 FlexiNoteModel(size_t sampleRate, size_t resolution,
108 float valueMinimum, float valueMaximum, 112 float valueMinimum, float valueMaximum,
109 bool notifyOnAdd = true) : 113 bool notifyOnAdd = true) :
110 IntervalModel<Note>(sampleRate, resolution, 114 IntervalModel<FlexiNote>(sampleRate, resolution,
111 valueMinimum, valueMaximum, 115 valueMinimum, valueMaximum,
112 notifyOnAdd), 116 notifyOnAdd),
113 m_valueQuantization(0) 117 m_valueQuantization(0)
114 { 118 {
115 PlayParameterRepository::getInstance()->addPlayable(this); 119 PlayParameterRepository::getInstance()->addPlayable(this);
116 } 120 }
117 121
118 virtual ~NoteModel() 122 virtual ~FlexiNoteModel()
119 { 123 {
120 PlayParameterRepository::getInstance()->removePlayable(this); 124 PlayParameterRepository::getInstance()->removePlayable(this);
121 } 125 }
122 126
123 float getValueQuantization() const { return m_valueQuantization; } 127 float getValueQuantization() const { return m_valueQuantization; }
124 void setValueQuantization(float q) { m_valueQuantization = q; } 128 void setValueQuantization(float q) { m_valueQuantization = q; }
125 129
126 QString getTypeName() const { return tr("Note"); } 130 QString getTypeName() const { return tr("FlexiNote"); }
127 131
128 virtual bool canPlay() const { return true; } 132 virtual bool canPlay() const { return true; }
129 133
130 virtual QString getDefaultPlayPluginId() const 134 virtual QString getDefaultPlayPluginId() const
131 { 135 {
139 143
140 virtual void toXml(QTextStream &out, 144 virtual void toXml(QTextStream &out,
141 QString indent = "", 145 QString indent = "",
142 QString extraAttributes = "") const 146 QString extraAttributes = "") const
143 { 147 {
144 std::cerr << "NoteModel::toXml: extraAttributes = \"" 148 std::cerr << "FlexiNoteModel::toXml: extraAttributes = \""
145 << extraAttributes.toStdString() << std::endl; 149 << extraAttributes.toStdString() << std::endl;
146 150
147 IntervalModel<Note>::toXml 151 IntervalModel<FlexiNote>::toXml
148 (out, 152 (out,
149 indent, 153 indent,
150 QString("%1 subtype=\"note\" valueQuantization=\"%2\"") 154 QString("%1 subtype=\"note\" valueQuantization=\"%2\"")
151 .arg(extraAttributes).arg(m_valueQuantization)); 155 .arg(extraAttributes).arg(m_valueQuantization));
152 } 156 }
174 } 178 }
175 179
176 virtual QVariant getData(int row, int column, int role) const 180 virtual QVariant getData(int row, int column, int role) const
177 { 181 {
178 if (column < 4) { 182 if (column < 4) {
179 return IntervalModel<Note>::getData(row, column, role); 183 return IntervalModel<FlexiNote>::getData(row, column, role);
180 } 184 }
181 185
182 PointListConstIterator i = getPointListIteratorForRow(row); 186 PointListConstIterator i = getPointListIteratorForRow(row);
183 if (i == m_points.end()) return QVariant(); 187 if (i == m_points.end()) return QVariant();
184 188
190 } 194 }
191 195
192 virtual Command *getSetDataCommand(int row, int column, const QVariant &value, int role) 196 virtual Command *getSetDataCommand(int row, int column, const QVariant &value, int role)
193 { 197 {
194 if (column < 4) { 198 if (column < 4) {
195 return IntervalModel<Note>::getSetDataCommand 199 return IntervalModel<FlexiNote>::getSetDataCommand
196 (row, column, value, role); 200 (row, column, value, role);
197 } 201 }
198 202
199 if (role != Qt::EditRole) return 0; 203 if (role != Qt::EditRole) return 0;
200 PointListConstIterator i = getPointListIteratorForRow(row); 204 PointListConstIterator i = getPointListIteratorForRow(row);