00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef _NOTE_MODEL_H_
00017 #define _NOTE_MODEL_H_
00018
00019 #include "SparseValueModel.h"
00020 #include "base/PlayParameterRepository.h"
00021 #include "base/RealTime.h"
00022
00032 struct Note
00033 {
00034 public:
00035 Note(long _frame) : frame(_frame), value(0.0f), duration(0), level(1.f) { }
00036 Note(long _frame, float _value, size_t _duration, float _level, QString _label) :
00037 frame(_frame), value(_value), duration(_duration), level(_level), label(_label) { }
00038
00039 int getDimensions() const { return 3; }
00040
00041 long frame;
00042 float value;
00043 size_t duration;
00044 float level;
00045 QString label;
00046
00047 QString getLabel() const { return label; }
00048
00049 void toXml(QTextStream &stream,
00050 QString indent = "",
00051 QString extraAttributes = "") const
00052 {
00053 stream <<
00054 QString("%1<point frame=\"%2\" value=\"%3\" duration=\"%4\" level=\"%5\" label=\"%6\" %7/>\n")
00055 .arg(indent).arg(frame).arg(value).arg(duration).arg(level).arg(label).arg(extraAttributes);
00056 }
00057
00058 QString toDelimitedDataString(QString delimiter, size_t sampleRate) const
00059 {
00060 QStringList list;
00061 list << RealTime::frame2RealTime(frame, sampleRate).toString().c_str();
00062 list << QString("%1").arg(value);
00063 list << RealTime::frame2RealTime(duration, sampleRate).toString().c_str();
00064 list << QString("%1").arg(level);
00065 if (label != "") list << label;
00066 return list.join(delimiter);
00067 }
00068
00069 struct Comparator {
00070 bool operator()(const Note &p1,
00071 const Note &p2) const {
00072 if (p1.frame != p2.frame) return p1.frame < p2.frame;
00073 if (p1.value != p2.value) return p1.value < p2.value;
00074 if (p1.duration != p2.duration) return p1.duration < p2.duration;
00075 if (p1.level != p2.level) return p1.level < p2.level;
00076 return p1.label < p2.label;
00077 }
00078 };
00079
00080 struct OrderComparator {
00081 bool operator()(const Note &p1,
00082 const Note &p2) const {
00083 return p1.frame < p2.frame;
00084 }
00085 };
00086 };
00087
00088
00089 class NoteModel : public SparseValueModel<Note>
00090 {
00091 public:
00092 NoteModel(size_t sampleRate, size_t resolution,
00093 bool notifyOnAdd = true) :
00094 SparseValueModel<Note>(sampleRate, resolution,
00095 notifyOnAdd),
00096 m_valueQuantization(0)
00097 {
00098 PlayParameterRepository::getInstance()->addModel(this);
00099 }
00100
00101 NoteModel(size_t sampleRate, size_t resolution,
00102 float valueMinimum, float valueMaximum,
00103 bool notifyOnAdd = true) :
00104 SparseValueModel<Note>(sampleRate, resolution,
00105 valueMinimum, valueMaximum,
00106 notifyOnAdd),
00107 m_valueQuantization(0)
00108 {
00109 PlayParameterRepository::getInstance()->addModel(this);
00110 }
00111
00112 float getValueQuantization() const { return m_valueQuantization; }
00113 void setValueQuantization(float q) { m_valueQuantization = q; }
00114
00121 virtual PointList getPoints(long start, long end) const;
00122
00128 virtual PointList getPoints(long frame) const;
00129
00130 QString getTypeName() const { return tr("Note"); }
00131
00132 virtual void toXml(QTextStream &out,
00133 QString indent = "",
00134 QString extraAttributes = "") const
00135 {
00136 std::cerr << "NoteModel::toXml: extraAttributes = \""
00137 << extraAttributes.toStdString() << std::endl;
00138
00139 SparseValueModel<Note>::toXml
00140 (out,
00141 indent,
00142 QString("%1 valueQuantization=\"%2\"")
00143 .arg(extraAttributes).arg(m_valueQuantization));
00144 }
00145
00146 protected:
00147 float m_valueQuantization;
00148 };
00149
00150 #endif