Mercurial > hg > svgui
comparison layer/WaveformLayer.cpp @ 682:1a0dfcbffaf1
Drop std:: from cout, cerr, endl -- pull these in through Debug.h
author | Chris Cannam |
---|---|
date | Tue, 26 Nov 2013 14:06:40 +0000 |
parents | b5d3dea6d869 |
children | 97ea68f62c1f def489f5ce92 |
comparison
equal
deleted
inserted
replaced
681:eaf4446a1bef | 682:1a0dfcbffaf1 |
---|---|
28 #include <iostream> | 28 #include <iostream> |
29 #include <cmath> | 29 #include <cmath> |
30 | 30 |
31 //#define DEBUG_WAVEFORM_PAINT 1 | 31 //#define DEBUG_WAVEFORM_PAINT 1 |
32 | 32 |
33 using std::cerr; | 33 |
34 using std::endl; | 34 |
35 | 35 |
36 WaveformLayer::WaveformLayer() : | 36 WaveformLayer::WaveformLayer() : |
37 SingleColourLayer(), | 37 SingleColourLayer(), |
38 m_model(0), | 38 m_model(0), |
39 m_gain(1.0f), | 39 m_gain(1.0f), |
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 std::cerr << "WaveformLayer::paint (" << rect.x() << "," << rect.y() | 477 cerr << "WaveformLayer::paint (" << rect.x() << "," << rect.y() |
478 << ") [" << rect.width() << "x" << rect.height() << "]: zoom " << zoomLevel << 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; |
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 std::cerr << "WaveformLayer::paint: aggressive is true" << endl; | 497 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 std::cerr << "WaveformLayer::paint: cache size " << m_cache->width() << "x" << m_cache->height() << " differs from view size " << w << "x" << h << ": regenerating aggressive cache" << endl; | 507 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 std::cerr << "Painting waveform from " << frame0 << " to " << frame1 << " (" << (x1-x0+1) << " pixels at zoom " << zoomLevel << " and model zoom " << modelZoomLevel << ")" << std::endl; | 565 cerr << "Painting waveform from " << frame0 << " to " << frame1 << " (" << (x1-x0+1) << " pixels at zoom " << zoomLevel << " and model zoom " << modelZoomLevel << ")" << 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 |
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 #ifdef DEBUG_WAVEFORM_PAINT | 606 #ifdef DEBUG_WAVEFORM_PAINT |
607 std::cerr << "ch = " << ch << ", channels = " << channels << ", m = " << m << ", my = " << my << ", h = " << h << std::endl; | 607 cerr << "ch = " << ch << ", channels = " << channels << ", m = " << m << ", my = " << my << ", h = " << h << endl; |
608 #endif | 608 #endif |
609 | 609 |
610 if (my - m > y1 || my + m < y0) continue; | 610 if (my - m > y1 || my + m < y0) continue; |
611 | 611 |
612 if ((m_scale == dBScale || m_scale == MeterScale) && | 612 if ((m_scale == dBScale || m_scale == MeterScale) && |
668 | 668 |
669 m_model->getSummaries(ch, frame0, frame1 - frame0, | 669 m_model->getSummaries(ch, frame0, frame1 - frame0, |
670 *ranges, modelZoomLevel); | 670 *ranges, modelZoomLevel); |
671 | 671 |
672 #ifdef DEBUG_WAVEFORM_PAINT | 672 #ifdef DEBUG_WAVEFORM_PAINT |
673 std::cerr << "channel " << ch << ": " << ranges->size() << " ranges from " << frame0 << " to " << frame1 << " at zoom level " << modelZoomLevel << std::endl; | 673 cerr << "channel " << ch << ": " << ranges->size() << " ranges from " << frame0 << " to " << frame1 << " at zoom level " << modelZoomLevel << endl; |
674 #endif | 674 #endif |
675 | 675 |
676 if (mergingChannels || mixingChannels) { | 676 if (mergingChannels || mixingChannels) { |
677 if (m_model->getChannelCount() > 1) { | 677 if (m_model->getChannelCount() > 1) { |
678 if (!otherChannelRanges) { | 678 if (!otherChannelRanges) { |
695 size_t f0, f1; | 695 size_t f0, f1; |
696 if (!getSourceFramesForX(v, x, modelZoomLevel, f0, f1)) continue; | 696 if (!getSourceFramesForX(v, x, modelZoomLevel, f0, f1)) continue; |
697 f1 = f1 - 1; | 697 f1 = f1 - 1; |
698 | 698 |
699 if (f0 < frame0) { | 699 if (f0 < frame0) { |
700 std::cerr << "ERROR: WaveformLayer::paint: pixel " << x << " has f0 = " << f0 << " which is less than range frame0 " << frame0 << " for x0 = " << x0 << std::endl; | 700 cerr << "ERROR: WaveformLayer::paint: pixel " << x << " has f0 = " << f0 << " which is less than range frame0 " << frame0 << " for x0 = " << x0 << endl; |
701 continue; | 701 continue; |
702 } | 702 } |
703 | 703 |
704 size_t i0 = (f0 - frame0) / modelZoomLevel; | 704 size_t i0 = (f0 - frame0) / modelZoomLevel; |
705 size_t i1 = (f1 - frame0) / modelZoomLevel; | 705 size_t i1 = (f1 - frame0) / modelZoomLevel; |
706 | 706 |
707 #ifdef DEBUG_WAVEFORM_PAINT | 707 #ifdef DEBUG_WAVEFORM_PAINT |
708 std::cerr << "WaveformLayer::paint: pixel " << x << ": i0 " << i0 << " (f " << f0 << "), i1 " << i1 << " (f " << f1 << ")" << std::endl; | 708 cerr << "WaveformLayer::paint: pixel " << x << ": i0 " << i0 << " (f " << f0 << "), i1 " << i1 << " (f " << f1 << ")" << endl; |
709 #endif | 709 #endif |
710 | 710 |
711 if (i1 > i0 + 1) { | 711 if (i1 > i0 + 1) { |
712 std::cerr << "WaveformLayer::paint: ERROR: i1 " << i1 << " > i0 " << i0 << " plus one (zoom = " << zoomLevel << ", model zoom = " << modelZoomLevel << ")" << std::endl; | 712 cerr << "WaveformLayer::paint: ERROR: i1 " << i1 << " > i0 " << i0 << " plus one (zoom = " << zoomLevel << ", model zoom = " << modelZoomLevel << ")" << endl; |
713 } | 713 } |
714 | 714 |
715 if (ranges && i0 < ranges->size()) { | 715 if (ranges && i0 < ranges->size()) { |
716 | 716 |
717 range = (*ranges)[i0]; | 717 range = (*ranges)[i0]; |
722 range.setAbsmean((range.absmean() + (*ranges)[i1].absmean()) / 2); | 722 range.setAbsmean((range.absmean() + (*ranges)[i1].absmean()) / 2); |
723 } | 723 } |
724 | 724 |
725 } else { | 725 } else { |
726 #ifdef DEBUG_WAVEFORM_PAINT | 726 #ifdef DEBUG_WAVEFORM_PAINT |
727 std::cerr << "No (or not enough) ranges for i0 = " << i0 << std::endl; | 727 cerr << "No (or not enough) ranges for i0 = " << i0 << endl; |
728 #endif | 728 #endif |
729 continue; | 729 continue; |
730 } | 730 } |
731 | 731 |
732 int rangeBottom = 0, rangeTop = 0, meanBottom = 0, meanTop = 0; | 732 int rangeBottom = 0, rangeTop = 0, meanBottom = 0, meanTop = 0; |
872 } else { | 872 } else { |
873 paint->setPen(midColour); | 873 paint->setPen(midColour); |
874 } | 874 } |
875 | 875 |
876 #ifdef DEBUG_WAVEFORM_PAINT | 876 #ifdef DEBUG_WAVEFORM_PAINT |
877 std::cerr << "range " << rangeBottom << " -> " << rangeTop << ", means " << meanBottom << " -> " << meanTop << ", raw range " << range.min() << " -> " << range.max() << std::endl; | 877 cerr << "range " << rangeBottom << " -> " << rangeTop << ", means " << meanBottom << " -> " << meanTop << ", raw range " << range.min() << " -> " << range.max() << endl; |
878 #endif | 878 #endif |
879 | 879 |
880 if (rangeTop == rangeBottom) { | 880 if (rangeTop == rangeBottom) { |
881 paint->drawPoint(x, rangeTop); | 881 paint->drawPoint(x, rangeTop); |
882 } else { | 882 } else { |
1049 case dBScale: | 1049 case dBScale: |
1050 vy = dBscale(value, m); | 1050 vy = dBscale(value, m); |
1051 break; | 1051 break; |
1052 } | 1052 } |
1053 | 1053 |
1054 // std::cerr << "mergingChannels= " << mergingChannels << ", channel = " << channel << ", value = " << value << ", vy = " << vy << std::endl; | 1054 // cerr << "mergingChannels= " << mergingChannels << ", channel = " << channel << ", value = " << value << ", vy = " << vy << endl; |
1055 | 1055 |
1056 return my - vy; | 1056 return my - vy; |
1057 } | 1057 } |
1058 | 1058 |
1059 float | 1059 float |