AlignmentModel.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  Sonic Visualiser
5  An audio file viewer and annotation editor.
6  Centre for Digital Music, Queen Mary, University of London.
7  This file copyright 2007 QMUL.
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version. See the file
13  COPYING included with this distribution for more information.
14 */
15 
16 #ifndef SV_ALIGNMENT_MODEL_H
17 #define SV_ALIGNMENT_MODEL_H
18 
19 #include "Model.h"
20 #include "Path.h"
21 #include "base/RealTime.h"
22 
23 #include <QString>
24 #include <QStringList>
25 
27 
28 class AlignmentModel : public Model
29 {
30  Q_OBJECT
31 
32 public:
33  AlignmentModel(ModelId reference /* any model */,
34  ModelId aligned /* any model */,
35  ModelId path /* a SparseTimeValueModel */);
37 
38  bool isOK() const override;
39 
40  void setError(QString error) { m_error = error; }
41  QString getError() const { return m_error; }
42 
43  sv_frame_t getStartFrame() const override;
44  sv_frame_t getTrueEndFrame() const override;
45  sv_samplerate_t getSampleRate() const override;
46  bool isReady(int *completion = 0) const override;
47  int getCompletion() const override {
48  int c = 0;
49  (void)isReady(&c);
50  return c;
51  }
52  const ZoomConstraint *getZoomConstraint() const override;
53 
54  QString getTypeName() const override { return tr("Alignment"); }
55 
56  ModelId getReferenceModel() const;
57  ModelId getAlignedModel() const;
58 
59  void setCompletion(int completion);
60 
61  sv_frame_t toReference(sv_frame_t frame) const;
62  sv_frame_t fromReference(sv_frame_t frame) const;
63 
64  void setPathFrom(ModelId pathSource); // a SparseTimeValueModel
65  void setPath(const Path &path);
66 
71  void setRelativePitch(int cents) { m_relativePitch = cents; }
72 
76  int getRelativePitch() const { return m_relativePitch; }
77 
78  void toXml(QTextStream &stream,
79  QString indent = "",
80  QString extraAttributes = "") const override;
81 
82  QVector<QString>
84  return {};
85  }
86 
87  QVector<QVector<QString>>
89  return {};
90  }
91 
92 signals:
94 
95 protected slots:
96  void pathSourceChangedWithin(ModelId, sv_frame_t startFrame, sv_frame_t endFrame);
98 
99 protected:
102 
103  ModelId m_pathSource; // a SparseTimeValueModel, which we need a
104  // handle on only while it's still being generated
105 
106  mutable std::unique_ptr<Path> m_path;
107  mutable std::unique_ptr<Path> m_reversePath;
110  QString m_error;
113 
114  void constructPath() const;
115  void constructReversePath() const;
116 
117  sv_frame_t performAlignment(const Path &path, sv_frame_t frame) const;
118 };
119 
120 #endif
double sv_samplerate_t
Sample rate.
Definition: BaseTypes.h:51
bool isOK() const override
Return true if the model was constructed successfully.
int getRelativePitch() const
Get the value set with setRelativePitch.
void constructPath() const
bool isReady(int *completion=0) const override
Return true if the model has finished loading or calculating all its data, for a model that is capabl...
void setPathFrom(ModelId pathSource)
int64_t sv_frame_t
Frame index, the unit of our time axis.
Definition: BaseTypes.h:31
void setPath(const Path &path)
int getCompletion() const override
Return an estimated percentage value showing how far through any background operation used to calcula...
sv_frame_t toReference(sv_frame_t frame) const
void pathSourceCompletionChanged(ModelId)
ModelId m_pathSource
void setCompletion(int completion)
sv_frame_t fromReference(sv_frame_t frame) const
void pathSourceChangedWithin(ModelId, sv_frame_t startFrame, sv_frame_t endFrame)
AlignmentModel(ModelId reference, ModelId aligned, ModelId path)
void toXml(QTextStream &stream, QString indent="", QString extraAttributes="") const override
Stream this exportable object out to XML on a text stream.
sv_frame_t getTrueEndFrame() const override
Return the audio frame at the end of the model.
sv_samplerate_t getSampleRate() const override
Return the frame rate in frames per second.
std::unique_ptr< Path > m_reversePath
Definition: Path.h:60
sv_frame_t performAlignment(const Path &path, sv_frame_t frame) const
QVector< QVector< QString > > toStringExportRows(DataExportOptions, sv_frame_t, sv_frame_t) const override
Emit events starting within the given range as string rows ready for conversion to an e...
Model is the base class for all data models that represent any sort of data on a time scale based on ...
Definition: Model.h:51
const ZoomConstraint * getZoomConstraint() const override
If this model imposes a zoom constraint, i.e.
std::unique_ptr< Path > m_path
sv_frame_t getStartFrame() const override
Return the first audio frame spanned by the model.
void setRelativePitch(int cents)
Set the calculated pitch relative to a reference.
A model representing a wiggly-line plot with points at arbitrary intervals of the model resolution...
QString getError() const
QVector< QString > getStringExportHeaders(DataExportOptions) const override
Return a label for each column that would be written by toStringExportRows.
ZoomConstraint is a simple interface that describes a limitation on the available zoom sizes for a vi...
ModelId getReferenceModel() const
void setError(QString error)
int m_explicitlySetCompletion
ModelId getAlignedModel() const
void constructReversePath() const
QString getTypeName() const override
Return the type of the model.
void completionChanged(ModelId)
Definition: ById.h:115
int DataExportOptions