comparison data/model/SparseModel.h @ 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 9f526ddc6165
children a1cd5abcb38b
comparison
equal deleted inserted replaced
1037:bf0e5944289b 1038:cc27f35aa75c
46 SparseModel(int sampleRate, int resolution, 46 SparseModel(int sampleRate, int resolution,
47 bool notifyOnAdd = true); 47 bool notifyOnAdd = true);
48 virtual ~SparseModel() { } 48 virtual ~SparseModel() { }
49 49
50 virtual bool isOK() const { return true; } 50 virtual bool isOK() const { return true; }
51 virtual int getStartFrame() const; 51 virtual sv_frame_t getStartFrame() const;
52 virtual int getEndFrame() const; 52 virtual sv_frame_t getEndFrame() const;
53 virtual int getSampleRate() const { return m_sampleRate; } 53 virtual int getSampleRate() const { return m_sampleRate; }
54 54
55 virtual Model *clone() const; 55 virtual Model *clone() const;
56 56
57 // Number of frames of the underlying sample rate that this model 57 // Number of frames of the underlying sample rate that this model
89 * Get all of the points in this model between the given 89 * Get all of the points in this model between the given
90 * boundaries (in frames), as well as up to two points before and 90 * boundaries (in frames), as well as up to two points before and
91 * after the boundaries. If you need exact boundaries, check the 91 * after the boundaries. If you need exact boundaries, check the
92 * point coordinates in the returned list. 92 * point coordinates in the returned list.
93 */ 93 */
94 virtual PointList getPoints(long start, long end) const; 94 virtual PointList getPoints(sv_frame_t start, sv_frame_t end) const;
95 95
96 /** 96 /**
97 * Get all points that cover the given frame number, taking the 97 * Get all points that cover the given frame number, taking the
98 * resolution of the model into account. 98 * resolution of the model into account.
99 */ 99 */
100 virtual PointList getPoints(long frame) const; 100 virtual PointList getPoints(sv_frame_t frame) const;
101 101
102 /** 102 /**
103 * Return all points that share the nearest frame number prior to 103 * Return all points that share the nearest frame number prior to
104 * the given one at which there are any points. 104 * the given one at which there are any points.
105 */ 105 */
106 virtual PointList getPreviousPoints(long frame) const; 106 virtual PointList getPreviousPoints(sv_frame_t frame) const;
107 107
108 /** 108 /**
109 * Return all points that share the nearest frame number 109 * Return all points that share the nearest frame number
110 * subsequent to the given one at which there are any points. 110 * subsequent to the given one at which there are any points.
111 */ 111 */
112 virtual PointList getNextPoints(long frame) const; 112 virtual PointList getNextPoints(sv_frame_t frame) const;
113 113
114 /** 114 /**
115 * Remove all points. 115 * Remove all points.
116 */ 116 */
117 virtual void clear(); 117 virtual void clear();
155 s += i->toDelimitedDataString(delimiter, m_sampleRate) + "\n"; 155 s += i->toDelimitedDataString(delimiter, m_sampleRate) + "\n";
156 } 156 }
157 return s; 157 return s;
158 } 158 }
159 159
160 virtual QString toDelimitedDataStringSubset(QString delimiter, int f0, int f1) const 160 virtual QString toDelimitedDataStringSubset(QString delimiter, sv_frame_t f0, sv_frame_t f1) const
161 { 161 {
162 QString s; 162 QString s;
163 for (PointListConstIterator i = m_points.begin(); i != m_points.end(); ++i) { 163 for (PointListConstIterator i = m_points.begin(); i != m_points.end(); ++i) {
164 if (i->frame >= (long)f0 && i->frame < (long)f1) { 164 if (i->frame >= f0 && i->frame < f1) {
165 s += i->toDelimitedDataString(delimiter, m_sampleRate) + "\n"; 165 s += i->toDelimitedDataString(delimiter, m_sampleRate) + "\n";
166 } 166 }
167 } 167 }
168 return s; 168 return s;
169 } 169 }
282 * TabularModel methods. 282 * TabularModel methods.
283 */ 283 */
284 284
285 virtual int getRowCount() const 285 virtual int getRowCount() const
286 { 286 {
287 return m_points.size(); 287 return int(m_points.size());
288 } 288 }
289 289
290 virtual long getFrameForRow(int row) const 290 virtual sv_frame_t getFrameForRow(int row) const
291 { 291 {
292 PointListConstIterator i = getPointListIteratorForRow(row); 292 PointListConstIterator i = getPointListIteratorForRow(row);
293 if (i == m_points.end()) return 0; 293 if (i == m_points.end()) return 0;
294 return i->frame; 294 return i->frame;
295 } 295 }
296 296
297 virtual int getRowForFrame(long frame) const 297 virtual int getRowForFrame(sv_frame_t frame) const
298 { 298 {
299 if (m_rows.empty()) rebuildRowVector(); 299 if (m_rows.empty()) rebuildRowVector();
300 std::vector<long>::iterator i = 300 std::vector<sv_frame_t>::iterator i =
301 std::lower_bound(m_rows.begin(), m_rows.end(), frame); 301 std::lower_bound(m_rows.begin(), m_rows.end(), frame);
302 #if defined(__SUNPRO_CC) && defined(__STD_RW_ITERATOR__) 302 ssize_t row = std::distance(m_rows.begin(), i);
303 int row = 0;
304 std::distance(m_rows.begin(), i, row);
305 #else
306 int row = std::distance(m_rows.begin(), i);
307 #endif
308 if (i != m_rows.begin() && (i == m_rows.end() || *i != frame)) { 303 if (i != m_rows.begin() && (i == m_rows.end() || *i != frame)) {
309 --row; 304 --row;
310 } 305 }
311 return row; 306 return int(row);
312 } 307 }
313 308
314 virtual int getColumnCount() const { return 1; } 309 virtual int getColumnCount() const { return 1; }
315 virtual QVariant getData(int row, int column, int role) const 310 virtual QVariant getData(int row, int column, int role) const
316 { 311 {
372 367
373 protected: 368 protected:
374 int m_sampleRate; 369 int m_sampleRate;
375 int m_resolution; 370 int m_resolution;
376 bool m_notifyOnAdd; 371 bool m_notifyOnAdd;
377 long m_sinceLastNotifyMin; 372 sv_frame_t m_sinceLastNotifyMin;
378 long m_sinceLastNotifyMax; 373 sv_frame_t m_sinceLastNotifyMax;
379 bool m_hasTextLabels; 374 bool m_hasTextLabels;
380 375
381 PointList m_points; 376 PointList m_points;
382 int m_pointCount; 377 int m_pointCount;
383 mutable QMutex m_mutex; 378 mutable QMutex m_mutex;
384 int m_completion; 379 int m_completion;
385 380
386 void getPointIterators(long frame, 381 void getPointIterators(sv_frame_t frame,
387 PointListIterator &startItr, 382 PointListIterator &startItr,
388 PointListIterator &endItr); 383 PointListIterator &endItr);
389 void getPointIterators(long frame, 384 void getPointIterators(sv_frame_t frame,
390 PointListConstIterator &startItr, 385 PointListConstIterator &startItr,
391 PointListConstIterator &endItr) const; 386 PointListConstIterator &endItr) const;
392 387
393 // This is only used if the model is called on to act in 388 // This is only used if the model is called on to act in
394 // TabularModel mode 389 // TabularModel mode
395 mutable std::vector<long> m_rows; // map from row number to frame 390 mutable std::vector<sv_frame_t> m_rows; // map from row number to frame
396 void rebuildRowVector() const 391 void rebuildRowVector() const
397 { 392 {
398 m_rows.clear(); 393 m_rows.clear();
399 for (PointListConstIterator i = m_points.begin(); i != m_points.end(); ++i) { 394 for (PointListConstIterator i = m_points.begin(); i != m_points.end(); ++i) {
400 // std::cerr << "rebuildRowVector: row " << m_rows.size() << " -> " << i->frame << std::endl; 395 // std::cerr << "rebuildRowVector: row " << m_rows.size() << " -> " << i->frame << std::endl;
405 PointListIterator getPointListIteratorForRow(int row) 400 PointListIterator getPointListIteratorForRow(int row)
406 { 401 {
407 if (m_rows.empty()) rebuildRowVector(); 402 if (m_rows.empty()) rebuildRowVector();
408 if (row < 0 || row + 1 > int(m_rows.size())) return m_points.end(); 403 if (row < 0 || row + 1 > int(m_rows.size())) return m_points.end();
409 404
410 int frame = m_rows[row]; 405 sv_frame_t frame = m_rows[row];
411 int indexAtFrame = 0; 406 int indexAtFrame = 0;
412 int ri = row; 407 int ri = row;
413 while (ri > 0 && m_rows[ri-1] == m_rows[row]) { --ri; ++indexAtFrame; } 408 while (ri > 0 && m_rows[ri-1] == m_rows[row]) { --ri; ++indexAtFrame; }
414 int initialIndexAtFrame = indexAtFrame; 409 int initialIndexAtFrame = indexAtFrame;
415 410
432 PointListConstIterator getPointListIteratorForRow(int row) const 427 PointListConstIterator getPointListIteratorForRow(int row) const
433 { 428 {
434 if (m_rows.empty()) rebuildRowVector(); 429 if (m_rows.empty()) rebuildRowVector();
435 if (row < 0 || row + 1 > int(m_rows.size())) return m_points.end(); 430 if (row < 0 || row + 1 > int(m_rows.size())) return m_points.end();
436 431
437 int frame = m_rows[row]; 432 sv_frame_t frame = m_rows[row];
438 int indexAtFrame = 0; 433 int indexAtFrame = 0;
439 int ri = row; 434 int ri = row;
440 while (ri > 0 && m_rows[ri-1] == m_rows[row]) { --ri; ++indexAtFrame; } 435 while (ri > 0 && m_rows[ri-1] == m_rows[row]) { --ri; ++indexAtFrame; }
441 int initialIndexAtFrame = indexAtFrame; 436 int initialIndexAtFrame = indexAtFrame;
442 437
478 m_completion(100) 473 m_completion(100)
479 { 474 {
480 } 475 }
481 476
482 template <typename PointType> 477 template <typename PointType>
483 int 478 sv_frame_t
484 SparseModel<PointType>::getStartFrame() const 479 SparseModel<PointType>::getStartFrame() const
485 { 480 {
486 QMutexLocker locker(&m_mutex); 481 QMutexLocker locker(&m_mutex);
487 int f = 0; 482 sv_frame_t f = 0;
488 if (!m_points.empty()) { 483 if (!m_points.empty()) {
489 f = m_points.begin()->frame; 484 f = m_points.begin()->frame;
490 } 485 }
491 return f; 486 return f;
492 } 487 }
493 488
494 template <typename PointType> 489 template <typename PointType>
495 int 490 sv_frame_t
496 SparseModel<PointType>::getEndFrame() const 491 SparseModel<PointType>::getEndFrame() const
497 { 492 {
498 QMutexLocker locker(&m_mutex); 493 QMutexLocker locker(&m_mutex);
499 int f = 0; 494 sv_frame_t f = 0;
500 if (!m_points.empty()) { 495 if (!m_points.empty()) {
501 PointListConstIterator i(m_points.end()); 496 PointListConstIterator i(m_points.end());
502 f = (--i)->frame; 497 f = (--i)->frame;
503 } 498 }
504 return f; 499 return f;
539 return m_points; 534 return m_points;
540 } 535 }
541 536
542 template <typename PointType> 537 template <typename PointType>
543 typename SparseModel<PointType>::PointList 538 typename SparseModel<PointType>::PointList
544 SparseModel<PointType>::getPoints(long start, long end) const 539 SparseModel<PointType>::getPoints(sv_frame_t start, sv_frame_t end) const
545 { 540 {
546 if (start > end) return PointList(); 541 if (start > end) return PointList();
547 QMutexLocker locker(&m_mutex); 542 QMutexLocker locker(&m_mutex);
548 543
549 PointType startPoint(start), endPoint(end); 544 PointType startPoint(start), endPoint(end);
565 return rv; 560 return rv;
566 } 561 }
567 562
568 template <typename PointType> 563 template <typename PointType>
569 typename SparseModel<PointType>::PointList 564 typename SparseModel<PointType>::PointList
570 SparseModel<PointType>::getPoints(long frame) const 565 SparseModel<PointType>::getPoints(sv_frame_t frame) const
571 { 566 {
572 PointListConstIterator startItr, endItr; 567 PointListConstIterator startItr, endItr;
573 getPointIterators(frame, startItr, endItr); 568 getPointIterators(frame, startItr, endItr);
574 569
575 PointList rv; 570 PointList rv;
581 return rv; 576 return rv;
582 } 577 }
583 578
584 template <typename PointType> 579 template <typename PointType>
585 void 580 void
586 SparseModel<PointType>::getPointIterators(long frame, 581 SparseModel<PointType>::getPointIterators(sv_frame_t frame,
587 PointListIterator &startItr, 582 PointListIterator &startItr,
588 PointListIterator &endItr) 583 PointListIterator &endItr)
589 { 584 {
590 QMutexLocker locker(&m_mutex); 585 QMutexLocker locker(&m_mutex);
591 586
593 startItr = m_points.end(); 588 startItr = m_points.end();
594 endItr = m_points.end(); 589 endItr = m_points.end();
595 return; 590 return;
596 } 591 }
597 592
598 long start = (frame / m_resolution) * m_resolution; 593 sv_frame_t start = (frame / m_resolution) * m_resolution;
599 long end = start + m_resolution; 594 sv_frame_t end = start + m_resolution;
600 595
601 PointType startPoint(start), endPoint(end); 596 PointType startPoint(start), endPoint(end);
602 597
603 startItr = m_points.lower_bound(startPoint); 598 startItr = m_points.lower_bound(startPoint);
604 endItr = m_points.upper_bound(endPoint); 599 endItr = m_points.upper_bound(endPoint);
605 } 600 }
606 601
607 template <typename PointType> 602 template <typename PointType>
608 void 603 void
609 SparseModel<PointType>::getPointIterators(long frame, 604 SparseModel<PointType>::getPointIterators(sv_frame_t frame,
610 PointListConstIterator &startItr, 605 PointListConstIterator &startItr,
611 PointListConstIterator &endItr) const 606 PointListConstIterator &endItr) const
612 { 607 {
613 QMutexLocker locker(&m_mutex); 608 QMutexLocker locker(&m_mutex);
614 609
617 startItr = m_points.end(); 612 startItr = m_points.end();
618 endItr = m_points.end(); 613 endItr = m_points.end();
619 return; 614 return;
620 } 615 }
621 616
622 long start = (frame / m_resolution) * m_resolution; 617 sv_frame_t start = (frame / m_resolution) * m_resolution;
623 long end = start + m_resolution; 618 sv_frame_t end = start + m_resolution;
624 619
625 PointType startPoint(start), endPoint(end); 620 PointType startPoint(start), endPoint(end);
626 621
627 // std::cerr << "getPointIterators: start frame " << start << ", end frame " << end << ", m_resolution " << m_resolution << std::endl; 622 // std::cerr << "getPointIterators: start frame " << start << ", end frame " << end << ", m_resolution " << m_resolution << std::endl;
628 623
630 endItr = m_points.upper_bound(endPoint); 625 endItr = m_points.upper_bound(endPoint);
631 } 626 }
632 627
633 template <typename PointType> 628 template <typename PointType>
634 typename SparseModel<PointType>::PointList 629 typename SparseModel<PointType>::PointList
635 SparseModel<PointType>::getPreviousPoints(long originFrame) const 630 SparseModel<PointType>::getPreviousPoints(sv_frame_t originFrame) const
636 { 631 {
637 QMutexLocker locker(&m_mutex); 632 QMutexLocker locker(&m_mutex);
638 633
639 PointType lookupPoint(originFrame); 634 PointType lookupPoint(originFrame);
640 PointList rv; 635 PointList rv;
641 636
642 PointListConstIterator i = m_points.lower_bound(lookupPoint); 637 PointListConstIterator i = m_points.lower_bound(lookupPoint);
643 if (i == m_points.begin()) return rv; 638 if (i == m_points.begin()) return rv;
644 639
645 --i; 640 --i;
646 long frame = i->frame; 641 sv_frame_t frame = i->frame;
647 while (i->frame == frame) { 642 while (i->frame == frame) {
648 rv.insert(*i); 643 rv.insert(*i);
649 if (i == m_points.begin()) break; 644 if (i == m_points.begin()) break;
650 --i; 645 --i;
651 } 646 }
653 return rv; 648 return rv;
654 } 649 }
655 650
656 template <typename PointType> 651 template <typename PointType>
657 typename SparseModel<PointType>::PointList 652 typename SparseModel<PointType>::PointList
658 SparseModel<PointType>::getNextPoints(long originFrame) const 653 SparseModel<PointType>::getNextPoints(sv_frame_t originFrame) const
659 { 654 {
660 QMutexLocker locker(&m_mutex); 655 QMutexLocker locker(&m_mutex);
661 656
662 PointType lookupPoint(originFrame); 657 PointType lookupPoint(originFrame);
663 PointList rv; 658 PointList rv;
664 659
665 PointListConstIterator i = m_points.upper_bound(lookupPoint); 660 PointListConstIterator i = m_points.upper_bound(lookupPoint);
666 if (i == m_points.end()) return rv; 661 if (i == m_points.end()) return rv;
667 662
668 long frame = i->frame; 663 sv_frame_t frame = i->frame;
669 while (i != m_points.end() && i->frame == frame) { 664 while (i != m_points.end() && i->frame == frame) {
670 rv.insert(*i); 665 rv.insert(*i);
671 ++i; 666 ++i;
672 } 667 }
673 668