comparison data/model/PathModel.h @ 407:88ad01799040

* Save alignments to session file. Needs much testing.
author Chris Cannam
date Tue, 29 Apr 2008 15:34:17 +0000
parents
children f5e8f12d2e58
comparison
equal deleted inserted replaced
406:d095214ffbaf 407:88ad01799040
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 _PATH_MODEL_H_
17 #define _PATH_MODEL_H_
18
19 #include "Model.h"
20 #include "SparseModel.h"
21 #include "base/RealTime.h"
22
23 #include <QStringList>
24
25
26 struct PathPoint
27 {
28 PathPoint(long _frame) : frame(_frame), mapframe(_frame) { }
29 PathPoint(long _frame, long _mapframe) :
30 frame(_frame), mapframe(_mapframe) { }
31
32 int getDimensions() const { return 2; }
33
34 long frame;
35 long mapframe;
36
37 QString getLabel() const { return ""; }
38
39 void toXml(QTextStream &stream, QString indent = "",
40 QString extraAttributes = "") const {
41 stream << QString("%1<point frame=\"%2\" mapframe=\"%3\" %4/>\n")
42 .arg(indent).arg(frame).arg(mapframe).arg(extraAttributes);
43 }
44
45 QString toDelimitedDataString(QString delimiter,
46 size_t sampleRate) const {
47 QStringList list;
48 list << RealTime::frame2RealTime(frame, sampleRate).toString().c_str();
49 list << QString("%1").arg(mapframe);
50 return list.join(delimiter);
51 }
52
53 struct Comparator {
54 bool operator()(const PathPoint &p1, const PathPoint &p2) const {
55 if (p1.frame != p2.frame) return p1.frame < p2.frame;
56 return p1.mapframe < p2.mapframe;
57 }
58 };
59
60 struct OrderComparator {
61 bool operator()(const PathPoint &p1, const PathPoint &p2) const {
62 return p1.frame < p2.frame;
63 }
64 };
65 };
66
67 class PathModel : public SparseModel<PathPoint>
68 {
69 public:
70 PathModel(size_t sampleRate, size_t resolution, bool notify = true) :
71 SparseModel<PathPoint>(sampleRate, resolution, notify) { }
72
73 virtual void toXml(QTextStream &out,
74 QString indent = "",
75 QString extraAttributes = "") const
76 {
77 SparseModel<PathPoint>::toXml
78 (out,
79 indent,
80 QString("%1 subtype=\"path\"")
81 .arg(extraAttributes));
82 }
83 };
84
85
86 #endif