comparison data/model/Labeller.h @ 355:d02f71281639

* Fix #1841095 tapping time instant gives wrong time in aligned track * Fix #1815654 source tidying: Labeller * Fix (I hope) #1849999 Time value graphs one instant out
author Chris Cannam
date Thu, 13 Dec 2007 17:14:33 +0000
parents b1a3f7bc035d
children bc4712c7d269
comparison
equal deleted inserted replaced
354:048b21bc9891 355:d02f71281639
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),
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 }