Mercurial > hg > svcore
comparison data/model/SparseOneDimensionalModel.h @ 147:3a13b0d4934e
* Reorganising code base. This revision will not compile.
author | Chris Cannam |
---|---|
date | Mon, 31 Jul 2006 11:44:37 +0000 |
parents | |
children | 4b2ea82fd0ed |
comparison
equal
deleted
inserted
replaced
146:f90fad823cea | 147:3a13b0d4934e |
---|---|
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 2006 Chris Cannam. | |
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 _SPARSE_ONE_DIMENSIONAL_MODEL_H_ | |
17 #define _SPARSE_ONE_DIMENSIONAL_MODEL_H_ | |
18 | |
19 #include "SparseModel.h" | |
20 #include "PlayParameterRepository.h" | |
21 #include "base/RealTime.h" | |
22 | |
23 struct OneDimensionalPoint | |
24 { | |
25 public: | |
26 OneDimensionalPoint(long _frame) : frame(_frame) { } | |
27 OneDimensionalPoint(long _frame, QString _label) : frame(_frame), label(_label) { } | |
28 | |
29 int getDimensions() const { return 1; } | |
30 | |
31 long frame; | |
32 QString label; | |
33 | |
34 QString toXmlString(QString indent = "", | |
35 QString extraAttributes = "") const | |
36 { | |
37 return QString("%1<point frame=\"%2\" label=\"%3\" %4/>\n") | |
38 .arg(indent).arg(frame).arg(label).arg(extraAttributes); | |
39 } | |
40 | |
41 QString toDelimitedDataString(QString delimiter, size_t sampleRate) const | |
42 { | |
43 QStringList list; | |
44 list << RealTime::frame2RealTime(frame, sampleRate).toString().c_str(); | |
45 list << label; | |
46 return list.join(delimiter); | |
47 } | |
48 | |
49 struct Comparator { | |
50 bool operator()(const OneDimensionalPoint &p1, | |
51 const OneDimensionalPoint &p2) const { | |
52 if (p1.frame != p2.frame) return p1.frame < p2.frame; | |
53 return p1.label < p2.label; | |
54 } | |
55 }; | |
56 | |
57 struct OrderComparator { | |
58 bool operator()(const OneDimensionalPoint &p1, | |
59 const OneDimensionalPoint &p2) const { | |
60 return p1.frame < p2.frame; | |
61 } | |
62 }; | |
63 }; | |
64 | |
65 | |
66 class SparseOneDimensionalModel : public SparseModel<OneDimensionalPoint> | |
67 { | |
68 public: | |
69 SparseOneDimensionalModel(size_t sampleRate, size_t resolution, | |
70 bool notifyOnAdd = true) : | |
71 SparseModel<OneDimensionalPoint>(sampleRate, resolution, notifyOnAdd) | |
72 { | |
73 PlayParameterRepository::getInstance()->addModel(this); | |
74 } | |
75 | |
76 int getIndexOf(const Point &point) { | |
77 // slow | |
78 int i = 0; | |
79 Point::Comparator comparator; | |
80 for (PointList::const_iterator j = m_points.begin(); | |
81 j != m_points.end(); ++j, ++i) { | |
82 if (!comparator(*j, point) && !comparator(point, *j)) return i; | |
83 } | |
84 return -1; | |
85 } | |
86 }; | |
87 | |
88 #endif | |
89 | |
90 | |
91 |