comparison data/model/NoteModel.h @ 852:d6bd5751b8f6 tonioni_multi_transform

Add NoteExportable base class, use it in MIDI export (and also elsewhere in playback)
author Chris Cannam
date Mon, 02 Dec 2013 17:11:20 +0000
parents e22b6e89a7f7
children 6d07bcc844a1
comparison
equal deleted inserted replaced
850:dba8a02b0413 852:d6bd5751b8f6
15 15
16 #ifndef _NOTE_MODEL_H_ 16 #ifndef _NOTE_MODEL_H_
17 #define _NOTE_MODEL_H_ 17 #define _NOTE_MODEL_H_
18 18
19 #include "IntervalModel.h" 19 #include "IntervalModel.h"
20 #include "NoteData.h"
20 #include "base/RealTime.h" 21 #include "base/RealTime.h"
21 #include "base/PlayParameterRepository.h" 22 #include "base/PlayParameterRepository.h"
23 #include "base/Pitch.h"
22 24
23 /** 25 /**
24 * NoteModel -- a concrete IntervalModel for notes. 26 * NoteModel -- a concrete IntervalModel for notes.
25 */ 27 */
26 28
89 } 91 }
90 }; 92 };
91 }; 93 };
92 94
93 95
94 class NoteModel : public IntervalModel<Note> 96 class NoteModel : public IntervalModel<Note>, public NoteExportable
95 { 97 {
96 Q_OBJECT 98 Q_OBJECT
97 99
98 public: 100 public:
99 NoteModel(size_t sampleRate, size_t resolution, 101 NoteModel(size_t sampleRate, size_t resolution,
217 { 219 {
218 if (column == 5) return SortAlphabetical; 220 if (column == 5) return SortAlphabetical;
219 return SortNumeric; 221 return SortNumeric;
220 } 222 }
221 223
224 /**
225 * NoteExportable methods.
226 */
227
228 NoteList getNotes() const {
229 return getNotes(getStartFrame(), getEndFrame());
230 }
231
232 NoteList getNotes(size_t startFrame, size_t endFrame) const {
233
234 PointList points = getPoints(startFrame, endFrame);
235 NoteList notes;
236
237 for (PointList::iterator pli =
238 points.begin(); pli != points.end(); ++pli) {
239
240 size_t duration = pli->duration;
241 if (duration == 0 || duration == 1) {
242 duration = getSampleRate() / 20;
243 }
244
245 int pitch = lrintf(pli->value);
246
247 int velocity = 100;
248 if (pli->level > 0.f && pli->level <= 1.f) {
249 velocity = lrintf(pli->level * 127);
250 }
251
252 NoteData note(pli->frame, duration, pitch, velocity);
253
254 if (getScaleUnits() == "Hz") {
255 note.frequency = pli->value;
256 note.midiPitch = Pitch::getPitchForFrequency(note.frequency);
257 note.isMidiPitchQuantized = false;
258 }
259
260 notes.push_back(note);
261 }
262
263 return notes;
264 }
265
222 protected: 266 protected:
223 float m_valueQuantization; 267 float m_valueQuantization;
224 }; 268 };
225 269
226 #endif 270 #endif