comparison layer/WaveformLayer.cpp @ 612:ea786e8bd931 sv_v2.0

Use drawPoint when drawing a single point, rather than drawLine. Otherwise the line seems to go missing some of the time, though I can't see any mistake in the code here. Fixes SV bug #485
author Chris Cannam
date Thu, 21 Jun 2012 14:37:43 +0100
parents 5b72899d692b
children b5d3dea6d869 3437e0fad7ae
comparison
equal deleted inserted replaced
611:0c5330bbe313 612:ea786e8bd931
472 472
473 int zoomLevel = v->getZoomLevel(); 473 int zoomLevel = v->getZoomLevel();
474 474
475 #ifdef DEBUG_WAVEFORM_PAINT 475 #ifdef DEBUG_WAVEFORM_PAINT
476 Profiler profiler("WaveformLayer::paint", true); 476 Profiler profiler("WaveformLayer::paint", true);
477 SVDEBUG << "WaveformLayer::paint (" << rect.x() << "," << rect.y() 477 std::cerr << "WaveformLayer::paint (" << rect.x() << "," << rect.y()
478 << ") [" << rect.width() << "x" << rect.height() << "]: zoom " << zoomLevel << ", start " << startFrame << endl; 478 << ") [" << rect.width() << "x" << rect.height() << "]: zoom " << zoomLevel << endl;
479 #endif 479 #endif
480 480
481 size_t channels = 0, minChannel = 0, maxChannel = 0; 481 size_t channels = 0, minChannel = 0, maxChannel = 0;
482 bool mergingChannels = false, mixingChannels = false; 482 bool mergingChannels = false, mixingChannels = false;
483 483
492 QPainter *paint; 492 QPainter *paint;
493 493
494 if (m_aggressive) { 494 if (m_aggressive) {
495 495
496 #ifdef DEBUG_WAVEFORM_PAINT 496 #ifdef DEBUG_WAVEFORM_PAINT
497 SVDEBUG << "WaveformLayer::paint: aggressive is true" << endl; 497 std::cerr << "WaveformLayer::paint: aggressive is true" << endl;
498 #endif 498 #endif
499 499
500 if (m_cacheValid && (zoomLevel != m_cacheZoomLevel)) { 500 if (m_cacheValid && (zoomLevel != m_cacheZoomLevel)) {
501 m_cacheValid = false; 501 m_cacheValid = false;
502 } 502 }
503 503
504 if (!m_cache || m_cache->width() != w || m_cache->height() != h) { 504 if (!m_cache || m_cache->width() != w || m_cache->height() != h) {
505 #ifdef DEBUG_WAVEFORM_PAINT 505 #ifdef DEBUG_WAVEFORM_PAINT
506 if (m_cache) { 506 if (m_cache) {
507 SVDEBUG << "WaveformLayer::paint: cache size " << m_cache->width() << "x" << m_cache->height() << " differs from view size " << w << "x" << h << ": regenerating aggressive cache" << endl; 507 std::cerr << "WaveformLayer::paint: cache size " << m_cache->width() << "x" << m_cache->height() << " differs from view size " << w << "x" << h << ": regenerating aggressive cache" << endl;
508 } 508 }
509 #endif 509 #endif
510 delete m_cache; 510 delete m_cache;
511 m_cache = new QPixmap(w, h); 511 m_cache = new QPixmap(w, h);
512 m_cacheValid = false; 512 m_cacheValid = false;
560 560
561 getSourceFramesForX(v, x0, modelZoomLevel, frame0, spare); 561 getSourceFramesForX(v, x0, modelZoomLevel, frame0, spare);
562 getSourceFramesForX(v, x1, modelZoomLevel, spare, frame1); 562 getSourceFramesForX(v, x1, modelZoomLevel, spare, frame1);
563 563
564 #ifdef DEBUG_WAVEFORM_PAINT 564 #ifdef DEBUG_WAVEFORM_PAINT
565 SVDEBUG << "Painting waveform from " << frame0 << " to " << frame1 << " (" << (x1-x0+1) << " pixels at zoom " << zoomLevel << " and model zoom " << modelZoomLevel << ")" << endl; 565 std::cerr << "Painting waveform from " << frame0 << " to " << frame1 << " (" << (x1-x0+1) << " pixels at zoom " << zoomLevel << " and model zoom " << modelZoomLevel << ")" << std::endl;
566 #endif 566 #endif
567 567
568 RangeSummarisableTimeValueModel::RangeBlock *ranges = 568 RangeSummarisableTimeValueModel::RangeBlock *ranges =
569 new RangeSummarisableTimeValueModel::RangeBlock; 569 new RangeSummarisableTimeValueModel::RangeBlock;
570 570
600 600
601 float gain = m_effectiveGains[ch]; 601 float gain = m_effectiveGains[ch];
602 602
603 int m = (h / channels) / 2; 603 int m = (h / channels) / 2;
604 int my = m + (((ch - minChannel) * h) / channels); 604 int my = m + (((ch - minChannel) * h) / channels);
605 605
606 // std::cerr << "ch = " << ch << ", channels = " << channels << ", m = " << m << ", my = " << my << ", h = " << h << std::endl; 606 #ifdef DEBUG_WAVEFORM_PAINT
607 std::cerr << "ch = " << ch << ", channels = " << channels << ", m = " << m << ", my = " << my << ", h = " << h << std::endl;
608 #endif
607 609
608 if (my - m > y1 || my + m < y0) continue; 610 if (my - m > y1 || my + m < y0) continue;
609 611
610 if ((m_scale == dBScale || m_scale == MeterScale) && 612 if ((m_scale == dBScale || m_scale == MeterScale) &&
611 m_channelMode != MergeChannels) { 613 m_channelMode != MergeChannels) {
701 703
702 size_t i0 = (f0 - frame0) / modelZoomLevel; 704 size_t i0 = (f0 - frame0) / modelZoomLevel;
703 size_t i1 = (f1 - frame0) / modelZoomLevel; 705 size_t i1 = (f1 - frame0) / modelZoomLevel;
704 706
705 #ifdef DEBUG_WAVEFORM_PAINT 707 #ifdef DEBUG_WAVEFORM_PAINT
706 SVDEBUG << "WaveformLayer::paint: pixel " << x << ": i0 " << i0 << " (f " << f0 << "), i1 " << i1 << " (f " << f1 << ")" << endl; 708 std::cerr << "WaveformLayer::paint: pixel " << x << ": i0 " << i0 << " (f " << f0 << "), i1 " << i1 << " (f " << f1 << ")" << std::endl;
707 #endif 709 #endif
708 710
709 if (i1 > i0 + 1) { 711 if (i1 > i0 + 1) {
710 SVDEBUG << "WaveformLayer::paint: ERROR: i1 " << i1 << " > i0 " << i0 << " plus one (zoom = " << zoomLevel << ", model zoom = " << modelZoomLevel << ")" << endl; 712 std::cerr << "WaveformLayer::paint: ERROR: i1 " << i1 << " > i0 " << i0 << " plus one (zoom = " << zoomLevel << ", model zoom = " << modelZoomLevel << ")" << std::endl;
711 } 713 }
712 714
713 if (ranges && i0 < ranges->size()) { 715 if (ranges && i0 < ranges->size()) {
714 716
715 range = (*ranges)[i0]; 717 range = (*ranges)[i0];
719 range.setMin(std::min(range.min(), (*ranges)[i1].min())); 721 range.setMin(std::min(range.min(), (*ranges)[i1].min()));
720 range.setAbsmean((range.absmean() + (*ranges)[i1].absmean()) / 2); 722 range.setAbsmean((range.absmean() + (*ranges)[i1].absmean()) / 2);
721 } 723 }
722 724
723 } else { 725 } else {
726 #ifdef DEBUG_WAVEFORM_PAINT
727 std::cerr << "No (or not enough) ranges for i0 = " << i0 << std::endl;
728 #endif
724 continue; 729 continue;
725 } 730 }
726 731
727 int rangeBottom = 0, rangeTop = 0, meanBottom = 0, meanTop = 0; 732 int rangeBottom = 0, rangeTop = 0, meanBottom = 0, meanTop = 0;
728 733
866 } 871 }
867 } else { 872 } else {
868 paint->setPen(midColour); 873 paint->setPen(midColour);
869 } 874 }
870 875
871 paint->drawLine(x, rangeBottom, x, rangeTop); 876 #ifdef DEBUG_WAVEFORM_PAINT
877 std::cerr << "range " << rangeBottom << " -> " << rangeTop << std::endl;
878 #endif
879
880 if (rangeTop == rangeBottom) {
881 paint->drawPoint(x, rangeTop);
882 } else {
883 paint->drawLine(x, rangeBottom, x, rangeTop);
884 }
872 885
873 prevRangeTopColour = baseColour; 886 prevRangeTopColour = baseColour;
874 prevRangeBottomColour = baseColour; 887 prevRangeBottomColour = baseColour;
875 888
876 if (m_greyscale && (m_scale == LinearScale) && ready) { 889 if (m_greyscale && (m_scale == LinearScale) && ready) {