Chris@297: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@297: Chris@297: /* Chris@297: Sonic Visualiser Chris@297: An audio file viewer and annotation editor. Chris@297: Centre for Digital Music, Queen Mary, University of London. Chris@297: This file copyright 2007 QMUL. Chris@297: Chris@297: This program is free software; you can redistribute it and/or Chris@297: modify it under the terms of the GNU General Public License as Chris@297: published by the Free Software Foundation; either version 2 of the Chris@297: License, or (at your option) any later version. See the file Chris@297: COPYING included with this distribution for more information. Chris@297: */ Chris@297: Chris@297: #ifndef _ALIGNMENT_MODEL_H_ Chris@297: #define _ALIGNMENT_MODEL_H_ Chris@297: Chris@297: #include "Model.h" Chris@338: #include "SparseModel.h" Chris@338: #include "base/RealTime.h" Chris@338: Chris@338: #include Chris@338: #include Chris@297: Chris@297: class SparseTimeValueModel; Chris@297: Chris@297: class AlignmentModel : public Model Chris@297: { Chris@297: Q_OBJECT Chris@297: Chris@297: public: Chris@297: AlignmentModel(Model *reference, Chris@297: Model *aligned, Chris@297: Model *inputModel, // probably an AggregateWaveModel; I take ownership Chris@297: SparseTimeValueModel *path); // I take ownership Chris@297: ~AlignmentModel(); Chris@297: Chris@297: virtual bool isOK() const; Chris@297: virtual size_t getStartFrame() const; Chris@297: virtual size_t getEndFrame() const; Chris@297: virtual size_t getSampleRate() const; Chris@297: virtual Model *clone() const; Chris@297: virtual bool isReady(int *completion = 0) const; Chris@297: virtual const ZoomConstraint *getZoomConstraint() const; Chris@297: Chris@297: const Model *getReferenceModel() const; Chris@297: const Model *getAlignedModel() const; Chris@297: Chris@297: size_t toReference(size_t frame) const; Chris@297: size_t fromReference(size_t frame) const; Chris@297: Chris@297: signals: Chris@297: void modelChanged(); Chris@297: void modelChanged(size_t startFrame, size_t endFrame); Chris@297: void completionChanged(); Chris@297: Chris@297: protected slots: Chris@297: void pathChanged(); Chris@297: void pathChanged(size_t startFrame, size_t endFrame); Chris@297: void pathCompletionChanged(); Chris@297: Chris@297: protected: Chris@297: Model *m_reference; // I don't own this Chris@297: Model *m_aligned; // I don't own this Chris@297: Chris@297: Model *m_inputModel; // I own this Chris@338: Chris@338: struct PathPoint Chris@338: { Chris@338: PathPoint(long _frame) : frame(_frame), mapframe(_frame) { } Chris@338: PathPoint(long _frame, long _mapframe) : Chris@338: frame(_frame), mapframe(_mapframe) { } Chris@338: Chris@338: int getDimensions() const { return 2; } Chris@338: Chris@338: long frame; Chris@338: long mapframe; Chris@338: Chris@338: QString getLabel() const { return ""; } Chris@338: Chris@338: void toXml(QTextStream &stream, QString indent = "", Chris@338: QString extraAttributes = "") const { Chris@338: stream << QString("%1\n") Chris@338: .arg(indent).arg(frame).arg(mapframe).arg(extraAttributes); Chris@338: } Chris@338: Chris@338: QString toDelimitedDataString(QString delimiter, Chris@338: size_t sampleRate) const { Chris@338: QStringList list; Chris@338: list << RealTime::frame2RealTime(frame, sampleRate).toString().c_str(); Chris@338: list << QString("%1").arg(mapframe); Chris@338: return list.join(delimiter); Chris@338: } Chris@338: Chris@338: struct Comparator { Chris@338: bool operator()(const PathPoint &p1, const PathPoint &p2) const { Chris@338: if (p1.frame != p2.frame) return p1.frame < p2.frame; Chris@338: return p1.mapframe < p2.mapframe; Chris@338: } Chris@338: }; Chris@338: Chris@338: struct OrderComparator { Chris@338: bool operator()(const PathPoint &p1, const PathPoint &p2) const { Chris@338: return p1.frame < p2.frame; Chris@338: } Chris@338: }; Chris@338: }; Chris@338: Chris@338: class PathModel : public SparseModel Chris@338: { Chris@338: public: Chris@338: PathModel(size_t sampleRate, size_t resolution, bool notify = true) : Chris@338: SparseModel(sampleRate, resolution, notify) { } Chris@338: }; Chris@338: Chris@338: SparseTimeValueModel *m_rawPath; // I own this Chris@338: mutable PathModel *m_path; // I own this Chris@338: mutable PathModel *m_reversePath; // I own this Chris@323: bool m_pathBegun; Chris@297: bool m_pathComplete; Chris@297: Chris@338: void constructPath() const; Chris@297: void constructReversePath() const; Chris@297: Chris@338: size_t align(PathModel *path, size_t frame) const; Chris@297: }; Chris@297: Chris@297: #endif