comparison data/model/SparseTimeValueModel.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_TIME_VALUE_MODEL_H_
17 #define _SPARSE_TIME_VALUE_MODEL_H_
18
19 #include "SparseValueModel.h"
20 #include "PlayParameterRepository.h"
21 #include "base/RealTime.h"
22
23 /**
24 * Time/value point type for use in a SparseModel or SparseValueModel.
25 * With this point type, the model basically represents a wiggly-line
26 * plot with points at arbitrary intervals of the model resolution.
27 */
28
29 struct TimeValuePoint
30 {
31 public:
32 TimeValuePoint(long _frame) : frame(_frame), value(0.0f) { }
33 TimeValuePoint(long _frame, float _value, QString _label) :
34 frame(_frame), value(_value), label(_label) { }
35
36 int getDimensions() const { return 2; }
37
38 long frame;
39 float value;
40 QString label;
41
42 QString toXmlString(QString indent = "",
43 QString extraAttributes = "") const
44 {
45 return QString("%1<point frame=\"%2\" value=\"%3\" label=\"%4\" %5/>\n")
46 .arg(indent).arg(frame).arg(value).arg(label).arg(extraAttributes);
47 }
48
49 QString toDelimitedDataString(QString delimiter, size_t sampleRate) const
50 {
51 QStringList list;
52 list << RealTime::frame2RealTime(frame, sampleRate).toString().c_str();
53 list << QString("%1").arg(value);
54 list << label;
55 return list.join(delimiter);
56 }
57
58 struct Comparator {
59 bool operator()(const TimeValuePoint &p1,
60 const TimeValuePoint &p2) const {
61 if (p1.frame != p2.frame) return p1.frame < p2.frame;
62 if (p1.value != p2.value) return p1.value < p2.value;
63 return p1.label < p2.label;
64 }
65 };
66
67 struct OrderComparator {
68 bool operator()(const TimeValuePoint &p1,
69 const TimeValuePoint &p2) const {
70 return p1.frame < p2.frame;
71 }
72 };
73 };
74
75
76 class SparseTimeValueModel : public SparseValueModel<TimeValuePoint>
77 {
78 public:
79 SparseTimeValueModel(size_t sampleRate, size_t resolution,
80 float valueMinimum, float valueMaximum,
81 bool notifyOnAdd = true) :
82 SparseValueModel<TimeValuePoint>(sampleRate, resolution,
83 valueMinimum, valueMaximum,
84 notifyOnAdd)
85 {
86 PlayParameterRepository::getInstance()->addModel(this);
87 }
88 };
89
90
91 #endif
92
93
94