00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef _ALIGNMENT_MODEL_H_
00017 #define _ALIGNMENT_MODEL_H_
00018
00019 #include "Model.h"
00020 #include "SparseModel.h"
00021 #include "base/RealTime.h"
00022
00023 #include <QString>
00024 #include <QStringList>
00025
00026 class SparseTimeValueModel;
00027
00028 class AlignmentModel : public Model
00029 {
00030 Q_OBJECT
00031
00032 public:
00033 AlignmentModel(Model *reference,
00034 Model *aligned,
00035 Model *inputModel,
00036 SparseTimeValueModel *path);
00037 ~AlignmentModel();
00038
00039 virtual bool isOK() const;
00040 virtual size_t getStartFrame() const;
00041 virtual size_t getEndFrame() const;
00042 virtual size_t getSampleRate() const;
00043 virtual Model *clone() const;
00044 virtual bool isReady(int *completion = 0) const;
00045 virtual const ZoomConstraint *getZoomConstraint() const;
00046
00047 QString getTypeName() const { return tr("Alignment"); }
00048
00049 const Model *getReferenceModel() const;
00050 const Model *getAlignedModel() const;
00051
00052 size_t toReference(size_t frame) const;
00053 size_t fromReference(size_t frame) const;
00054
00055 signals:
00056 void modelChanged();
00057 void modelChanged(size_t startFrame, size_t endFrame);
00058 void completionChanged();
00059
00060 protected slots:
00061 void pathChanged();
00062 void pathChanged(size_t startFrame, size_t endFrame);
00063 void pathCompletionChanged();
00064
00065 protected:
00066 Model *m_reference;
00067 Model *m_aligned;
00068
00069 Model *m_inputModel;
00070
00071 struct PathPoint
00072 {
00073 PathPoint(long _frame) : frame(_frame), mapframe(_frame) { }
00074 PathPoint(long _frame, long _mapframe) :
00075 frame(_frame), mapframe(_mapframe) { }
00076
00077 int getDimensions() const { return 2; }
00078
00079 long frame;
00080 long mapframe;
00081
00082 QString getLabel() const { return ""; }
00083
00084 void toXml(QTextStream &stream, QString indent = "",
00085 QString extraAttributes = "") const {
00086 stream << QString("%1<point frame=\"%2\" mapframe=\"%3\" %4/>\n")
00087 .arg(indent).arg(frame).arg(mapframe).arg(extraAttributes);
00088 }
00089
00090 QString toDelimitedDataString(QString delimiter,
00091 size_t sampleRate) const {
00092 QStringList list;
00093 list << RealTime::frame2RealTime(frame, sampleRate).toString().c_str();
00094 list << QString("%1").arg(mapframe);
00095 return list.join(delimiter);
00096 }
00097
00098 struct Comparator {
00099 bool operator()(const PathPoint &p1, const PathPoint &p2) const {
00100 if (p1.frame != p2.frame) return p1.frame < p2.frame;
00101 return p1.mapframe < p2.mapframe;
00102 }
00103 };
00104
00105 struct OrderComparator {
00106 bool operator()(const PathPoint &p1, const PathPoint &p2) const {
00107 return p1.frame < p2.frame;
00108 }
00109 };
00110 };
00111
00112 class PathModel : public SparseModel<PathPoint>
00113 {
00114 public:
00115 PathModel(size_t sampleRate, size_t resolution, bool notify = true) :
00116 SparseModel<PathPoint>(sampleRate, resolution, notify) { }
00117 };
00118
00119 SparseTimeValueModel *m_rawPath;
00120 mutable PathModel *m_path;
00121 mutable PathModel *m_reversePath;
00122 bool m_pathBegun;
00123 bool m_pathComplete;
00124
00125 void constructPath() const;
00126 void constructReversePath() const;
00127
00128 size_t align(PathModel *path, size_t frame) const;
00129 };
00130
00131 #endif