Mercurial > hg > svcore
comparison data/model/NoteModel.h @ 874:862fe7b20df7 tony_integration
Merge from tonioni branch
| author | Chris Cannam |
|---|---|
| date | Tue, 28 Jan 2014 15:01:54 +0000 |
| parents | 3a3541b357fe |
| children | c48b07b34cb3 |
comparison
equal
deleted
inserted
replaced
| 862:786ee8d1f30e | 874:862fe7b20df7 |
|---|---|
| 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, |
| 125 | 127 |
| 126 QString getTypeName() const { return tr("Note"); } | 128 QString getTypeName() const { return tr("Note"); } |
| 127 | 129 |
| 128 virtual bool canPlay() const { return true; } | 130 virtual bool canPlay() const { return true; } |
| 129 | 131 |
| 130 virtual QString getDefaultPlayPluginId() const | 132 virtual QString getDefaultPlayClipId() const |
| 131 { | 133 { |
| 132 return "dssi:_builtin:sample_player"; | 134 return "piano"; |
| 133 } | |
| 134 | |
| 135 virtual QString getDefaultPlayPluginConfiguration() const | |
| 136 { | |
| 137 return "<plugin program=\"piano\"/>"; | |
| 138 } | 135 } |
| 139 | 136 |
| 140 virtual void toXml(QTextStream &out, | 137 virtual void toXml(QTextStream &out, |
| 141 QString indent = "", | 138 QString indent = "", |
| 142 QString extraAttributes = "") const | 139 QString extraAttributes = "") const |
| 217 { | 214 { |
| 218 if (column == 5) return SortAlphabetical; | 215 if (column == 5) return SortAlphabetical; |
| 219 return SortNumeric; | 216 return SortNumeric; |
| 220 } | 217 } |
| 221 | 218 |
| 219 /** | |
| 220 * NoteExportable methods. | |
| 221 */ | |
| 222 | |
| 223 NoteList getNotes() const { | |
| 224 return getNotes(getStartFrame(), getEndFrame()); | |
| 225 } | |
| 226 | |
| 227 NoteList getNotes(size_t startFrame, size_t endFrame) const { | |
| 228 | |
| 229 PointList points = getPoints(startFrame, endFrame); | |
| 230 NoteList notes; | |
| 231 | |
| 232 for (PointList::iterator pli = | |
| 233 points.begin(); pli != points.end(); ++pli) { | |
| 234 | |
| 235 size_t duration = pli->duration; | |
| 236 if (duration == 0 || duration == 1) { | |
| 237 duration = getSampleRate() / 20; | |
| 238 } | |
| 239 | |
| 240 int pitch = lrintf(pli->value); | |
| 241 | |
| 242 int velocity = 100; | |
| 243 if (pli->level > 0.f && pli->level <= 1.f) { | |
| 244 velocity = lrintf(pli->level * 127); | |
| 245 } | |
| 246 | |
| 247 NoteData note(pli->frame, duration, pitch, velocity); | |
| 248 | |
| 249 if (getScaleUnits() == "Hz") { | |
| 250 note.frequency = pli->value; | |
| 251 note.midiPitch = Pitch::getPitchForFrequency(note.frequency); | |
| 252 note.isMidiPitchQuantized = false; | |
| 253 } | |
| 254 | |
| 255 notes.push_back(note); | |
| 256 } | |
| 257 | |
| 258 return notes; | |
| 259 } | |
| 260 | |
| 222 protected: | 261 protected: |
| 223 float m_valueQuantization; | 262 float m_valueQuantization; |
| 224 }; | 263 }; |
| 225 | 264 |
| 226 #endif | 265 #endif |
