Mercurial > hg > easaier-soundaccess
comparison data/model/NoteModel.h @ 0:fc9323a41f5a
start base : Sonic Visualiser sv1-1.0rc1
author | lbajardsilogic |
---|---|
date | Fri, 11 May 2007 09:08:14 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:fc9323a41f5a |
---|---|
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 _NOTE_MODEL_H_ | |
17 #define _NOTE_MODEL_H_ | |
18 | |
19 #include "SparseValueModel.h" | |
20 #include "base/PlayParameterRepository.h" | |
21 #include "base/RealTime.h" | |
22 | |
23 /** | |
24 * Note type for use in a SparseModel or SparseValueModel. All we | |
25 * mean by a "note" is something that has an onset time, a single | |
26 * value, and a duration. Like other points, it can also have a | |
27 * label. With this point type, the model can be thought of as | |
28 * representing a simple MIDI-type piano roll, except that the y | |
29 * coordinates (values) do not have to be discrete integers. | |
30 */ | |
31 | |
32 struct Note | |
33 { | |
34 public: | |
35 Note(long _frame) : frame(_frame), value(0.0f), duration(0) { } | |
36 Note(long _frame, float _value, size_t _duration, QString _label) : | |
37 frame(_frame), value(_value), duration(_duration), label(_label) { } | |
38 | |
39 int getDimensions() const { return 3; } | |
40 | |
41 long frame; | |
42 float value; | |
43 size_t duration; | |
44 QString label; | |
45 | |
46 QString toXmlString(QString indent = "", | |
47 QString extraAttributes = "") const | |
48 { | |
49 return QString("%1<point frame=\"%2\" value=\"%3\" duration=\"%4\" label=\"%5\" %6/>\n") | |
50 .arg(indent).arg(frame).arg(value).arg(duration).arg(label).arg(extraAttributes); | |
51 } | |
52 | |
53 QString toDelimitedDataString(QString delimiter, size_t sampleRate) const | |
54 { | |
55 QStringList list; | |
56 list << RealTime::frame2RealTime(frame, sampleRate).toString().c_str(); | |
57 list << QString("%1").arg(value); | |
58 list << QString("%1").arg(duration); | |
59 list << label; | |
60 return list.join(delimiter); | |
61 } | |
62 | |
63 struct Comparator { | |
64 bool operator()(const Note &p1, | |
65 const Note &p2) const { | |
66 if (p1.frame != p2.frame) return p1.frame < p2.frame; | |
67 if (p1.value != p2.value) return p1.value < p2.value; | |
68 if (p1.duration != p2.duration) return p1.duration < p2.duration; | |
69 return p1.label < p2.label; | |
70 } | |
71 }; | |
72 | |
73 struct OrderComparator { | |
74 bool operator()(const Note &p1, | |
75 const Note &p2) const { | |
76 return p1.frame < p2.frame; | |
77 } | |
78 }; | |
79 }; | |
80 | |
81 | |
82 class NoteModel : public SparseValueModel<Note> | |
83 { | |
84 public: | |
85 NoteModel(size_t sampleRate, size_t resolution, | |
86 bool notifyOnAdd = true) : | |
87 SparseValueModel<Note>(sampleRate, resolution, | |
88 notifyOnAdd), | |
89 m_valueQuantization(0) | |
90 { | |
91 PlayParameterRepository::getInstance()->addModel(this); | |
92 } | |
93 | |
94 NoteModel(size_t sampleRate, size_t resolution, | |
95 float valueMinimum, float valueMaximum, | |
96 bool notifyOnAdd = true) : | |
97 SparseValueModel<Note>(sampleRate, resolution, | |
98 valueMinimum, valueMaximum, | |
99 notifyOnAdd), | |
100 m_valueQuantization(0) | |
101 { | |
102 PlayParameterRepository::getInstance()->addModel(this); | |
103 } | |
104 | |
105 float getValueQuantization() const { return m_valueQuantization; } | |
106 void setValueQuantization(float q) { m_valueQuantization = q; } | |
107 | |
108 /** | |
109 * Notes have a duration, so this returns all points that span any | |
110 * of the given range (as well as the usual additional few before | |
111 * and after). Consequently this can be very slow (optimised data | |
112 * structures still to be done!). | |
113 */ | |
114 virtual PointList getPoints(long start, long end) const; | |
115 | |
116 /** | |
117 * Notes have a duration, so this returns all points that span the | |
118 * given frame. Consequently this can be very slow (optimised | |
119 * data structures still to be done!). | |
120 */ | |
121 virtual PointList getPoints(long frame) const; | |
122 | |
123 virtual QString toXmlString(QString indent = "", | |
124 QString extraAttributes = "") const | |
125 { | |
126 return SparseValueModel<Note>::toXmlString | |
127 (indent, | |
128 QString("%1 valueQuantization=\"%2\"") | |
129 .arg(extraAttributes).arg(m_valueQuantization)); | |
130 } | |
131 | |
132 protected: | |
133 float m_valueQuantization; | |
134 }; | |
135 | |
136 #endif |