comparison data/model/TextModel.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 7b96b3bd4bae
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 _TEXT_MODEL_H_
17 #define _TEXT_MODEL_H_
18
19 #include "SparseModel.h"
20 #include "base/RealTime.h"
21
22 /**
23 * Text point type for use in a SparseModel. This represents a piece
24 * of text at a given time and y-value in the [0,1) range (indicative
25 * of height on the window). Intended for casual textual annotations.
26 */
27
28 struct TextPoint
29 {
30 public:
31 TextPoint(long _frame) : frame(_frame), height(0.0f) { }
32 TextPoint(long _frame, float _height, QString _label) :
33 frame(_frame), height(_height), label(_label) { }
34
35 int getDimensions() const { return 2; }
36
37 long frame;
38 float height;
39 QString label;
40
41 QString toXmlString(QString indent = "",
42 QString extraAttributes = "") const
43 {
44 return QString("%1<point frame=\"%2\" height=\"%3\" label=\"%4\" %5/>\n")
45 .arg(indent).arg(frame).arg(height).arg(label).arg(extraAttributes);
46 }
47
48 QString toDelimitedDataString(QString delimiter, size_t sampleRate) const
49 {
50 QStringList list;
51 list << RealTime::frame2RealTime(frame, sampleRate).toString().c_str();
52 list << QString("%1").arg(height);
53 list << label;
54 return list.join(delimiter);
55 }
56
57 struct Comparator {
58 bool operator()(const TextPoint &p1,
59 const TextPoint &p2) const {
60 if (p1.frame != p2.frame) return p1.frame < p2.frame;
61 if (p1.height != p2.height) return p1.height < p2.height;
62 return p1.label < p2.label;
63 }
64 };
65
66 struct OrderComparator {
67 bool operator()(const TextPoint &p1,
68 const TextPoint &p2) const {
69 return p1.frame < p2.frame;
70 }
71 };
72 };
73
74
75 // Make this a class rather than a typedef so it can be predeclared.
76
77 class TextModel : public SparseModel<TextPoint>
78 {
79 public:
80 TextModel(size_t sampleRate, size_t resolution, bool notifyOnAdd = true) :
81 SparseModel<TextPoint>(sampleRate, resolution, notifyOnAdd)
82 { }
83
84 virtual QString toXmlString(QString indent = "",
85 QString extraAttributes = "") const
86 {
87 return SparseModel<TextPoint>::toXmlString
88 (indent,
89 QString("%1 subtype=\"text\"")
90 .arg(extraAttributes));
91 }
92 };
93
94
95 #endif
96
97
98