annotate data/model/AlignmentModel.h @ 345:700cd3350391

* Improvements to layer summary dialog (LayerTree, LayerTreeDialog), & rename. It's still rather unstable though.
author Chris Cannam
date Wed, 28 Nov 2007 17:45:37 +0000
parents f14e2f7b24f7
children 88ad01799040
rev   line source
Chris@297 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@297 2
Chris@297 3 /*
Chris@297 4 Sonic Visualiser
Chris@297 5 An audio file viewer and annotation editor.
Chris@297 6 Centre for Digital Music, Queen Mary, University of London.
Chris@297 7 This file copyright 2007 QMUL.
Chris@297 8
Chris@297 9 This program is free software; you can redistribute it and/or
Chris@297 10 modify it under the terms of the GNU General Public License as
Chris@297 11 published by the Free Software Foundation; either version 2 of the
Chris@297 12 License, or (at your option) any later version. See the file
Chris@297 13 COPYING included with this distribution for more information.
Chris@297 14 */
Chris@297 15
Chris@297 16 #ifndef _ALIGNMENT_MODEL_H_
Chris@297 17 #define _ALIGNMENT_MODEL_H_
Chris@297 18
Chris@297 19 #include "Model.h"
Chris@338 20 #include "SparseModel.h"
Chris@338 21 #include "base/RealTime.h"
Chris@338 22
Chris@338 23 #include <QString>
Chris@338 24 #include <QStringList>
Chris@297 25
Chris@297 26 class SparseTimeValueModel;
Chris@297 27
Chris@297 28 class AlignmentModel : public Model
Chris@297 29 {
Chris@297 30 Q_OBJECT
Chris@297 31
Chris@297 32 public:
Chris@297 33 AlignmentModel(Model *reference,
Chris@297 34 Model *aligned,
Chris@297 35 Model *inputModel, // probably an AggregateWaveModel; I take ownership
Chris@297 36 SparseTimeValueModel *path); // I take ownership
Chris@297 37 ~AlignmentModel();
Chris@297 38
Chris@297 39 virtual bool isOK() const;
Chris@297 40 virtual size_t getStartFrame() const;
Chris@297 41 virtual size_t getEndFrame() const;
Chris@297 42 virtual size_t getSampleRate() const;
Chris@297 43 virtual Model *clone() const;
Chris@297 44 virtual bool isReady(int *completion = 0) const;
Chris@297 45 virtual const ZoomConstraint *getZoomConstraint() const;
Chris@297 46
Chris@345 47 QString getTypeName() const { return tr("Alignment"); }
Chris@345 48
Chris@297 49 const Model *getReferenceModel() const;
Chris@297 50 const Model *getAlignedModel() const;
Chris@297 51
Chris@297 52 size_t toReference(size_t frame) const;
Chris@297 53 size_t fromReference(size_t frame) const;
Chris@297 54
Chris@297 55 signals:
Chris@297 56 void modelChanged();
Chris@297 57 void modelChanged(size_t startFrame, size_t endFrame);
Chris@297 58 void completionChanged();
Chris@297 59
Chris@297 60 protected slots:
Chris@297 61 void pathChanged();
Chris@297 62 void pathChanged(size_t startFrame, size_t endFrame);
Chris@297 63 void pathCompletionChanged();
Chris@297 64
Chris@297 65 protected:
Chris@297 66 Model *m_reference; // I don't own this
Chris@297 67 Model *m_aligned; // I don't own this
Chris@297 68
Chris@297 69 Model *m_inputModel; // I own this
Chris@338 70
Chris@338 71 struct PathPoint
Chris@338 72 {
Chris@338 73 PathPoint(long _frame) : frame(_frame), mapframe(_frame) { }
Chris@338 74 PathPoint(long _frame, long _mapframe) :
Chris@338 75 frame(_frame), mapframe(_mapframe) { }
Chris@338 76
Chris@338 77 int getDimensions() const { return 2; }
Chris@338 78
Chris@338 79 long frame;
Chris@338 80 long mapframe;
Chris@338 81
Chris@338 82 QString getLabel() const { return ""; }
Chris@338 83
Chris@338 84 void toXml(QTextStream &stream, QString indent = "",
Chris@338 85 QString extraAttributes = "") const {
Chris@338 86 stream << QString("%1<point frame=\"%2\" mapframe=\"%3\" %4/>\n")
Chris@338 87 .arg(indent).arg(frame).arg(mapframe).arg(extraAttributes);
Chris@338 88 }
Chris@338 89
Chris@338 90 QString toDelimitedDataString(QString delimiter,
Chris@338 91 size_t sampleRate) const {
Chris@338 92 QStringList list;
Chris@338 93 list << RealTime::frame2RealTime(frame, sampleRate).toString().c_str();
Chris@338 94 list << QString("%1").arg(mapframe);
Chris@338 95 return list.join(delimiter);
Chris@338 96 }
Chris@338 97
Chris@338 98 struct Comparator {
Chris@338 99 bool operator()(const PathPoint &p1, const PathPoint &p2) const {
Chris@338 100 if (p1.frame != p2.frame) return p1.frame < p2.frame;
Chris@338 101 return p1.mapframe < p2.mapframe;
Chris@338 102 }
Chris@338 103 };
Chris@338 104
Chris@338 105 struct OrderComparator {
Chris@338 106 bool operator()(const PathPoint &p1, const PathPoint &p2) const {
Chris@338 107 return p1.frame < p2.frame;
Chris@338 108 }
Chris@338 109 };
Chris@338 110 };
Chris@338 111
Chris@338 112 class PathModel : public SparseModel<PathPoint>
Chris@338 113 {
Chris@338 114 public:
Chris@338 115 PathModel(size_t sampleRate, size_t resolution, bool notify = true) :
Chris@338 116 SparseModel<PathPoint>(sampleRate, resolution, notify) { }
Chris@338 117 };
Chris@338 118
Chris@338 119 SparseTimeValueModel *m_rawPath; // I own this
Chris@338 120 mutable PathModel *m_path; // I own this
Chris@338 121 mutable PathModel *m_reversePath; // I own this
Chris@323 122 bool m_pathBegun;
Chris@297 123 bool m_pathComplete;
Chris@297 124
Chris@338 125 void constructPath() const;
Chris@297 126 void constructReversePath() const;
Chris@297 127
Chris@338 128 size_t align(PathModel *path, size_t frame) const;
Chris@297 129 };
Chris@297 130
Chris@297 131 #endif