comparison data/model/Labeller.h @ 383:94fc0591ea43 1.2-stable

* merge from trunk (1.2 ended up being tracked from trunk, but we may want this branch for fixes later)
author Chris Cannam
date Wed, 27 Feb 2008 10:32:45 +0000
parents b1a3f7bc035d
children
comparison
equal deleted inserted replaced
349:f39d33b0b265 383:94fc0591ea43
34 ValueFromSimpleCounter, 34 ValueFromSimpleCounter,
35 ValueFromCyclicalCounter, 35 ValueFromCyclicalCounter,
36 ValueFromTwoLevelCounter, 36 ValueFromTwoLevelCounter,
37 ValueFromFrameNumber, 37 ValueFromFrameNumber,
38 ValueFromRealTime, 38 ValueFromRealTime,
39 ValueFromRealTimeDifference, 39 ValueFromDurationFromPrevious,
40 ValueFromTempo, 40 ValueFromDurationToNext,
41 ValueFromTempoFromPrevious,
42 ValueFromTempoToNext,
41 ValueFromExistingNeighbour, 43 ValueFromExistingNeighbour,
42 ValueFromLabel 44 ValueFromLabel
43 }; 45 };
44 46
45 // uses: 47 // uses:
57 // point, not the previous one) 59 // point, not the previous one)
58 // 60 //
59 // 4. re-label a set of points that have already been added to a 61 // 4. re-label a set of points that have already been added to a
60 // model 62 // model
61 63
62 Labeller(ValueType type) : 64 Labeller(ValueType type = ValueNone) :
63 m_type(type), 65 m_type(type),
64 m_counter(1), 66 m_counter(1),
65 m_counter2(1), 67 m_counter2(1),
66 m_cycle(4), 68 m_cycle(4),
67 m_dp(10), 69 m_dp(10),
68 m_rate(0) { } 70 m_rate(0) { }
69 71
70 Labeller(const Labeller &l) : 72 Labeller(const Labeller &l) :
71 QObject(), 73 QObject(),
72 m_type(l.m_type), 74 m_type(l.m_type),
73 m_counter(1), 75 m_counter(l.m_counter),
74 m_counter2(1), 76 m_counter2(l.m_counter2),
75 m_cycle(l.m_cycle), 77 m_cycle(l.m_cycle),
76 m_dp(l.m_dp), 78 m_dp(l.m_dp),
77 m_rate(l.m_rate) { } 79 m_rate(l.m_rate) { }
78 80
79 virtual ~Labeller() { } 81 virtual ~Labeller() { }
80 82
81 typedef std::map<ValueType, QString> TypeNameMap; 83 typedef std::map<ValueType, QString> TypeNameMap;
82 TypeNameMap getTypeNames() const { 84 TypeNameMap getTypeNames() const {
83 TypeNameMap m; 85 TypeNameMap m;
84 m[ValueNone] = tr("No numbering"); 86 m[ValueNone]
85 m[ValueFromSimpleCounter] = tr("Simple counter"); 87 = tr("No numbering");
86 m[ValueFromCyclicalCounter] = tr("Cyclical counter"); 88 m[ValueFromSimpleCounter]
87 m[ValueFromTwoLevelCounter] = tr("Cyclical two-level counter (bar/beat)"); 89 = tr("Simple counter");
88 m[ValueFromFrameNumber] = tr("Audio sample frame number"); 90 m[ValueFromCyclicalCounter]
89 m[ValueFromRealTime] = tr("Time in seconds"); 91 = tr("Cyclical counter");
90 m[ValueFromRealTimeDifference] = tr("Duration to the following item"); 92 m[ValueFromTwoLevelCounter]
91 m[ValueFromTempo] = tr("Tempo (bpm) based on duration to following item"); 93 = tr("Cyclical two-level counter (bar/beat)");
92 m[ValueFromExistingNeighbour] = tr("Same as the nearest previous item"); 94 m[ValueFromFrameNumber]
93 m[ValueFromLabel] = tr("Value extracted from the item's label (where possible)"); 95 = tr("Audio sample frame number");
96 m[ValueFromRealTime]
97 = tr("Time in seconds");
98 m[ValueFromDurationToNext]
99 = tr("Duration to the following item");
100 m[ValueFromTempoToNext]
101 = tr("Tempo (bpm) based on duration to following item");
102 m[ValueFromDurationFromPrevious]
103 = tr("Duration since the previous item");
104 m[ValueFromTempoFromPrevious]
105 = tr("Tempo (bpm) based on duration since previous item");
106 m[ValueFromExistingNeighbour]
107 = tr("Same as the nearest previous item");
108 m[ValueFromLabel]
109 = tr("Value extracted from the item's label (where possible)");
94 return m; 110 return m;
95 } 111 }
96 112
97 ValueType getType() const { return m_type; } 113 ValueType getType() const { return m_type; }
98 void setType(ValueType type) { m_type = type; } 114 void setType(ValueType type) { m_type = type; }
210 newPoint.value = value; 226 newPoint.value = value;
211 } 227 }
212 } 228 }
213 } 229 }
214 230
231 bool requiresPrevPoint() const {
232 return (m_type == ValueFromDurationFromPrevious ||
233 m_type == ValueFromDurationToNext ||
234 m_type == ValueFromTempoFromPrevious ||
235 m_type == ValueFromDurationToNext);
236 }
237
215 bool actingOnPrevPoint() const { 238 bool actingOnPrevPoint() const {
216 return (m_type == ValueFromRealTimeDifference || 239 return (m_type == ValueFromDurationToNext ||
217 m_type == ValueFromTempo); 240 m_type == ValueFromTempoToNext);
218 } 241 }
219 242
220 protected: 243 protected:
221 template <typename PointType> 244 template <typename PointType>
222 float getValueFor(PointType &newPoint, PointType *prevPoint) 245 float getValueFor(PointType &newPoint, PointType *prevPoint)
250 } else { 273 } else {
251 value = float(newPoint.frame) / float(m_rate); 274 value = float(newPoint.frame) / float(m_rate);
252 } 275 }
253 break; 276 break;
254 277
255 case ValueFromRealTimeDifference: 278 case ValueFromDurationToNext:
256 case ValueFromTempo: 279 case ValueFromTempoToNext:
280 case ValueFromDurationFromPrevious:
281 case ValueFromTempoFromPrevious:
257 if (m_rate == 0.f) { 282 if (m_rate == 0.f) {
258 std::cerr << "ERROR: Labeller::getValueFor: Real-time conversion required, but no sample rate set" << std::endl; 283 std::cerr << "ERROR: Labeller::getValueFor: Real-time conversion required, but no sample rate set" << std::endl;
259 } else if (!prevPoint) { 284 } else if (!prevPoint) {
260 std::cerr << "ERROR: Labeller::getValueFor: Time difference required, but only one point provided" << std::endl; 285 std::cerr << "ERROR: Labeller::getValueFor: Time difference required, but only one point provided" << std::endl;
261 } else { 286 } else {
262 size_t f0 = prevPoint->frame, f1 = newPoint.frame; 287 size_t f0 = prevPoint->frame, f1 = newPoint.frame;
263 if (m_type == ValueFromRealTimeDifference) { 288 if (m_type == ValueFromDurationToNext ||
289 m_type == ValueFromDurationFromPrevious) {
264 value = float(f1 - f0) / m_rate; 290 value = float(f1 - f0) / m_rate;
265 } else { 291 } else {
266 if (f1 > f0) { 292 if (f1 > f0) {
267 value = (60.f * m_rate) / (f1 - f0); 293 value = (60.f * m_rate) / (f1 - f0);
268 } 294 }