comparison data/model/AlignmentModel.cpp @ 1038:cc27f35aa75c cxx11

Introducing the signed 64-bit frame index type, and fixing build failures from inclusion of -Wconversion with -Werror. Not finished yet.
author Chris Cannam
date Tue, 03 Mar 2015 15:18:24 +0000
parents 13f53ecc8bb5
children a1cd5abcb38b
comparison
equal deleted inserted replaced
1037:bf0e5944289b 1038:cc27f35aa75c
35 if (m_rawPath) { 35 if (m_rawPath) {
36 36
37 connect(m_rawPath, SIGNAL(modelChanged()), 37 connect(m_rawPath, SIGNAL(modelChanged()),
38 this, SLOT(pathChanged())); 38 this, SLOT(pathChanged()));
39 39
40 connect(m_rawPath, SIGNAL(modelChangedWithin(int, int)), 40 connect(m_rawPath, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)),
41 this, SLOT(pathChangedWithin(int, int))); 41 this, SLOT(pathChangedWithin(sv_frame_t, sv_frame_t)));
42 42
43 connect(m_rawPath, SIGNAL(completionChanged()), 43 connect(m_rawPath, SIGNAL(completionChanged()),
44 this, SLOT(pathCompletionChanged())); 44 this, SLOT(pathCompletionChanged()));
45 45
46 constructPath(); 46 constructPath();
72 { 72 {
73 if (m_rawPath) return m_rawPath->isOK(); 73 if (m_rawPath) return m_rawPath->isOK();
74 else return true; 74 else return true;
75 } 75 }
76 76
77 int 77 sv_frame_t
78 AlignmentModel::getStartFrame() const 78 AlignmentModel::getStartFrame() const
79 { 79 {
80 int a = m_reference->getStartFrame(); 80 sv_frame_t a = m_reference->getStartFrame();
81 int b = m_aligned->getStartFrame(); 81 sv_frame_t b = m_aligned->getStartFrame();
82 return std::min(a, b); 82 return std::min(a, b);
83 } 83 }
84 84
85 int 85 sv_frame_t
86 AlignmentModel::getEndFrame() const 86 AlignmentModel::getEndFrame() const
87 { 87 {
88 int a = m_reference->getEndFrame(); 88 sv_frame_t a = m_reference->getEndFrame();
89 int b = m_aligned->getEndFrame(); 89 sv_frame_t b = m_aligned->getEndFrame();
90 return std::max(a, b); 90 return std::max(a, b);
91 } 91 }
92 92
93 int 93 int
94 AlignmentModel::getSampleRate() const 94 AlignmentModel::getSampleRate() const
142 AlignmentModel::getAlignedModel() const 142 AlignmentModel::getAlignedModel() const
143 { 143 {
144 return m_aligned; 144 return m_aligned;
145 } 145 }
146 146
147 int 147 sv_frame_t
148 AlignmentModel::toReference(int frame) const 148 AlignmentModel::toReference(sv_frame_t frame) const
149 { 149 {
150 #ifdef DEBUG_ALIGNMENT_MODEL 150 #ifdef DEBUG_ALIGNMENT_MODEL
151 SVDEBUG << "AlignmentModel::toReference(" << frame << ")" << endl; 151 SVDEBUG << "AlignmentModel::toReference(" << frame << ")" << endl;
152 #endif 152 #endif
153 if (!m_path) { 153 if (!m_path) {
155 constructPath(); 155 constructPath();
156 } 156 }
157 return align(m_path, frame); 157 return align(m_path, frame);
158 } 158 }
159 159
160 int 160 sv_frame_t
161 AlignmentModel::fromReference(int frame) const 161 AlignmentModel::fromReference(sv_frame_t frame) const
162 { 162 {
163 #ifdef DEBUG_ALIGNMENT_MODEL 163 #ifdef DEBUG_ALIGNMENT_MODEL
164 SVDEBUG << "AlignmentModel::fromReference(" << frame << ")" << endl; 164 SVDEBUG << "AlignmentModel::fromReference(" << frame << ")" << endl;
165 #endif 165 #endif
166 if (!m_reversePath) { 166 if (!m_reversePath) {
180 m_rawPath = 0; 180 m_rawPath = 0;
181 } 181 }
182 } 182 }
183 183
184 void 184 void
185 AlignmentModel::pathChangedWithin(int, int) 185 AlignmentModel::pathChangedWithin(sv_frame_t, sv_frame_t)
186 { 186 {
187 if (!m_pathComplete) return; 187 if (!m_pathComplete) return;
188 constructPath(); 188 constructPath();
189 constructReversePath(); 189 constructReversePath();
190 } 190 }
240 240
241 SparseTimeValueModel::PointList points = m_rawPath->getPoints(); 241 SparseTimeValueModel::PointList points = m_rawPath->getPoints();
242 242
243 for (SparseTimeValueModel::PointList::const_iterator i = points.begin(); 243 for (SparseTimeValueModel::PointList::const_iterator i = points.begin();
244 i != points.end(); ++i) { 244 i != points.end(); ++i) {
245 long frame = i->frame; 245 sv_frame_t frame = i->frame;
246 float value = i->value; 246 double value = i->value;
247 long rframe = lrintf(value * m_aligned->getSampleRate()); 247 sv_frame_t rframe = lrint(value * m_aligned->getSampleRate());
248 m_path->addPoint(PathPoint(frame, rframe)); 248 m_path->addPoint(PathPoint(frame, rframe));
249 } 249 }
250 250
251 #ifdef DEBUG_ALIGNMENT_MODEL 251 #ifdef DEBUG_ALIGNMENT_MODEL
252 SVDEBUG << "AlignmentModel::constructPath: " << m_path->getPointCount() << " points, at least " << (2 * m_path->getPointCount() * (3 * sizeof(void *) + sizeof(int) + sizeof(PathPoint))) << " bytes" << endl; 252 SVDEBUG << "AlignmentModel::constructPath: " << m_path->getPointCount() << " points, at least " << (2 * m_path->getPointCount() * (3 * sizeof(void *) + sizeof(int) + sizeof(PathPoint))) << " bytes" << endl;
272 272
273 PathModel::PointList points = m_path->getPoints(); 273 PathModel::PointList points = m_path->getPoints();
274 274
275 for (PathModel::PointList::const_iterator i = points.begin(); 275 for (PathModel::PointList::const_iterator i = points.begin();
276 i != points.end(); ++i) { 276 i != points.end(); ++i) {
277 long frame = i->frame; 277 sv_frame_t frame = i->frame;
278 long rframe = i->mapframe; 278 sv_frame_t rframe = i->mapframe;
279 m_reversePath->addPoint(PathPoint(rframe, frame)); 279 m_reversePath->addPoint(PathPoint(rframe, frame));
280 } 280 }
281 281
282 #ifdef DEBUG_ALIGNMENT_MODEL 282 #ifdef DEBUG_ALIGNMENT_MODEL
283 SVDEBUG << "AlignmentModel::constructReversePath: " << m_reversePath->getPointCount() << " points, at least " << (2 * m_reversePath->getPointCount() * (3 * sizeof(void *) + sizeof(int) + sizeof(PathPoint))) << " bytes" << endl; 283 SVDEBUG << "AlignmentModel::constructReversePath: " << m_reversePath->getPointCount() << " points, at least " << (2 * m_reversePath->getPointCount() * (3 * sizeof(void *) + sizeof(int) + sizeof(PathPoint))) << " bytes" << endl;
284 #endif 284 #endif
285 } 285 }
286 286
287 int 287 sv_frame_t
288 AlignmentModel::align(PathModel *path, int frame) const 288 AlignmentModel::align(PathModel *path, sv_frame_t frame) const
289 { 289 {
290 if (!path) return frame; 290 if (!path) return frame;
291 291
292 // The path consists of a series of points, each with frame equal 292 // The path consists of a series of points, each with frame equal
293 // to the frame on the source model and mapframe equal to the 293 // to the frame on the source model and mapframe equal to the
313 #ifdef DEBUG_ALIGNMENT_MODEL 313 #ifdef DEBUG_ALIGNMENT_MODEL
314 cerr << "Note: i == points.end()" << endl; 314 cerr << "Note: i == points.end()" << endl;
315 #endif 315 #endif
316 --i; 316 --i;
317 } 317 }
318 while (i != points.begin() && i->frame > long(frame)) --i; 318 while (i != points.begin() && i->frame > frame) --i;
319 319
320 long foundFrame = i->frame; 320 sv_frame_t foundFrame = i->frame;
321 long foundMapFrame = i->mapframe; 321 sv_frame_t foundMapFrame = i->mapframe;
322 322
323 long followingFrame = foundFrame; 323 sv_frame_t followingFrame = foundFrame;
324 long followingMapFrame = foundMapFrame; 324 sv_frame_t followingMapFrame = foundMapFrame;
325 325
326 if (++i != points.end()) { 326 if (++i != points.end()) {
327 #ifdef DEBUG_ALIGNMENT_MODEL 327 #ifdef DEBUG_ALIGNMENT_MODEL
328 cerr << "another point available" << endl; 328 cerr << "another point available" << endl;
329 #endif 329 #endif
335 #endif 335 #endif
336 } 336 }
337 337
338 if (foundMapFrame < 0) return 0; 338 if (foundMapFrame < 0) return 0;
339 339
340 int resultFrame = foundMapFrame; 340 sv_frame_t resultFrame = foundMapFrame;
341 341
342 if (followingFrame != foundFrame && long(frame) > foundFrame) { 342 if (followingFrame != foundFrame && frame > foundFrame) {
343 float interp = 343 double interp =
344 float(frame - foundFrame) / 344 double(frame - foundFrame) /
345 float(followingFrame - foundFrame); 345 double(followingFrame - foundFrame);
346 resultFrame += lrintf((followingMapFrame - foundMapFrame) * interp); 346 resultFrame += lrint(double(followingMapFrame - foundMapFrame) * interp);
347 } 347 }
348 348
349 #ifdef DEBUG_ALIGNMENT_MODEL 349 #ifdef DEBUG_ALIGNMENT_MODEL
350 SVDEBUG << "AlignmentModel::align: resultFrame = " << resultFrame << endl; 350 SVDEBUG << "AlignmentModel::align: resultFrame = " << resultFrame << endl;
351 #endif 351 #endif