AlignmentModel.h

Go to the documentation of this file.
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
00002 
00003 /*
00004     Sonic Visualiser
00005     An audio file viewer and annotation editor.
00006     Centre for Digital Music, Queen Mary, University of London.
00007     This file copyright 2007 QMUL.
00008     
00009     This program is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU General Public License as
00011     published by the Free Software Foundation; either version 2 of the
00012     License, or (at your option) any later version.  See the file
00013     COPYING included with this distribution for more information.
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, // probably an AggregateWaveModel; I take ownership
00036                    SparseTimeValueModel *path); // I take ownership
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; // I don't own this
00067     Model *m_aligned; // I don't own this
00068 
00069     Model *m_inputModel; // I own this
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; // I own this
00120     mutable PathModel *m_path; // I own this
00121     mutable PathModel *m_reversePath; // I own this
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

Generated on Wed Feb 20 15:45:24 2008 for SonicVisualiser by  doxygen 1.5.1