Mercurial > hg > svcore
comparison data/model/FlexiNoteModel.h @ 855:42bbc538d983 tonioni_multi_transform
Merge from tonioni branch
author | Chris Cannam |
---|---|
date | Wed, 04 Dec 2013 18:29:15 +0000 |
parents | d6bd5751b8f6 |
children | 6d07bcc844a1 |
comparison
equal
deleted
inserted
replaced
849:418cd2064769 | 855:42bbc538d983 |
---|---|
14 */ | 14 */ |
15 | 15 |
16 #ifndef _FLEXINOTE_MODEL_H_ | 16 #ifndef _FLEXINOTE_MODEL_H_ |
17 #define _FLEXINOTE_MODEL_H_ | 17 #define _FLEXINOTE_MODEL_H_ |
18 | 18 |
19 // #include "NotelikeModel.h" // GF: reomved as this is an uncommitted experiment for now | |
20 | |
21 #include "IntervalModel.h" | 19 #include "IntervalModel.h" |
20 #include "NoteData.h" | |
22 #include "base/RealTime.h" | 21 #include "base/RealTime.h" |
22 #include "base/Pitch.h" | |
23 #include "base/PlayParameterRepository.h" | 23 #include "base/PlayParameterRepository.h" |
24 | 24 |
25 /** | 25 /** |
26 * FlexiNoteModel -- a concrete IntervalModel for notes. | 26 * FlexiNoteModel -- a concrete IntervalModel for notes. |
27 */ | 27 */ |
95 } | 95 } |
96 }; | 96 }; |
97 }; | 97 }; |
98 | 98 |
99 | 99 |
100 class FlexiNoteModel : public IntervalModel<FlexiNote> | 100 class FlexiNoteModel : public IntervalModel<FlexiNote>, public NoteExportable |
101 { | 101 { |
102 Q_OBJECT | 102 Q_OBJECT |
103 | 103 |
104 public: | 104 public: |
105 FlexiNoteModel(size_t sampleRate, size_t resolution, | 105 FlexiNoteModel(size_t sampleRate, size_t resolution, |
225 { | 225 { |
226 if (column == 5) return SortAlphabetical; | 226 if (column == 5) return SortAlphabetical; |
227 return SortNumeric; | 227 return SortNumeric; |
228 } | 228 } |
229 | 229 |
230 /** | |
231 * NoteExportable methods. | |
232 */ | |
233 | |
234 NoteList getNotes() const { | |
235 return getNotes(getStartFrame(), getEndFrame()); | |
236 } | |
237 | |
238 NoteList getNotes(size_t startFrame, size_t endFrame) const { | |
239 | |
240 PointList points = getPoints(startFrame, endFrame); | |
241 NoteList notes; | |
242 | |
243 for (PointList::iterator pli = | |
244 points.begin(); pli != points.end(); ++pli) { | |
245 | |
246 size_t duration = pli->duration; | |
247 if (duration == 0 || duration == 1) { | |
248 duration = getSampleRate() / 20; | |
249 } | |
250 | |
251 int pitch = lrintf(pli->value); | |
252 | |
253 int velocity = 100; | |
254 if (pli->level > 0.f && pli->level <= 1.f) { | |
255 velocity = lrintf(pli->level * 127); | |
256 } | |
257 | |
258 NoteData note(pli->frame, duration, pitch, velocity); | |
259 | |
260 if (getScaleUnits() == "Hz") { | |
261 note.frequency = pli->value; | |
262 note.midiPitch = Pitch::getPitchForFrequency(note.frequency); | |
263 note.isMidiPitchQuantized = false; | |
264 } | |
265 | |
266 notes.push_back(note); | |
267 } | |
268 | |
269 return notes; | |
270 } | |
271 | |
230 protected: | 272 protected: |
231 float m_valueQuantization; | 273 float m_valueQuantization; |
232 }; | 274 }; |
233 | 275 |
234 #endif | 276 #endif |