comparison layer/WaveformLayer.cpp @ 27:38fe0ea9e46e

* Some fixes to waveform layer greyscaling * Tidying in panner class
author Chris Cannam
date Fri, 03 Feb 2006 17:30:47 +0000
parents dcdb21b62dbb
children 202d1dca67d2
comparison
equal deleted inserted replaced
26:94381052a6c9 27:38fe0ea9e46e
410 RangeSummarisableTimeValueModel::RangeBlock otherChannelRanges; 410 RangeSummarisableTimeValueModel::RangeBlock otherChannelRanges;
411 RangeSummarisableTimeValueModel::Range range; 411 RangeSummarisableTimeValueModel::Range range;
412 412
413 QColor greys[3]; 413 QColor greys[3];
414 if (m_colour == Qt::black) { 414 if (m_colour == Qt::black) {
415 for (int i = 0; i < 3; ++i) { 415 for (int i = 0; i < 3; ++i) { // 0 lightest, 2 darkest
416 int level = 192 - 64 * i; 416 int level = 192 - 64 * i;
417 greys[i] = QColor(level, level, level); 417 greys[i] = QColor(level, level, level);
418 } 418 }
419 } else { 419 } else {
420 int factor = (m_view->hasLightBackground() ? 120 : 80); 420 int h, s, v;
421 greys[2] = m_colour.light(factor); 421 m_colour.getHsv(&h, &s, &v);
422 greys[1] = greys[2].light(factor); 422 for (int i = 0; i < 3; ++i) { // 0 lightest, 2 darkest
423 greys[0] = greys[1].light(factor); 423 if (m_view->hasLightBackground()) {
424 greys[i] = QColor::fromHsv(h, s * (i + 1) / 4, v);
425 } else {
426 greys[i] = QColor::fromHsv(h, s * (3 - i) / 4, v);
427 }
428 }
424 } 429 }
425 430
426 QColor midColour = m_colour; 431 QColor midColour = m_colour;
427 if (midColour == Qt::black) { 432 if (midColour == Qt::black) {
428 midColour = Qt::gray; 433 midColour = Qt::gray;
547 rangeTop = AudioLevel::multiplier_to_preview(range.max * m_gain, m * greyLevels); 552 rangeTop = AudioLevel::multiplier_to_preview(range.max * m_gain, m * greyLevels);
548 meanBottom = -AudioLevel::multiplier_to_preview(range.absmean * m_gain, m); 553 meanBottom = -AudioLevel::multiplier_to_preview(range.absmean * m_gain, m);
549 meanTop = AudioLevel::multiplier_to_preview(range.absmean * m_gain, m); 554 meanTop = AudioLevel::multiplier_to_preview(range.absmean * m_gain, m);
550 } 555 }
551 556
552 int topFill = (rangeTop < 0 ? -rangeTop : rangeTop) % greyLevels; 557 rangeBottom = my * greyLevels - rangeBottom;
553 int bottomFill = (rangeBottom < 0 ? -rangeBottom : rangeBottom) % greyLevels; 558 rangeTop = my * greyLevels - rangeTop;
559 meanBottom = my - meanBottom;
560 meanTop = my - meanTop;
561
562 int topFill = (rangeTop % greyLevels);
563 if (topFill > 0) topFill = greyLevels - topFill;
564
565 int bottomFill = (rangeBottom % greyLevels);
566
554 rangeTop = rangeTop / greyLevels; 567 rangeTop = rangeTop / greyLevels;
555 rangeBottom = rangeBottom / greyLevels; 568 rangeBottom = rangeBottom / greyLevels;
556 569
557 bool clipped = false; 570 bool clipped = false;
558 if (rangeTop < -m) { rangeTop = -m; clipped = true; } 571
559 if (rangeTop > m) { rangeTop = m; clipped = true; } 572 if (rangeTop < my - m) { rangeTop = my - m; }
560 if (rangeBottom < -m) { rangeBottom = -m; clipped = true; } 573 if (rangeTop > my + m) { rangeTop = my + m; }
561 if (rangeBottom > m) { rangeBottom = m; clipped = true; } 574 if (rangeBottom < my - m) { rangeBottom = my - m; }
575 if (rangeBottom > my + m) { rangeBottom = my + m; }
576
577 if (range.max * m_gain <= -1.0 ||
578 range.max * m_gain >= 1.0) clipped = true;
562 579
563 rangeBottom = my - rangeBottom;
564 rangeTop = my - rangeTop;
565 meanBottom = my - meanBottom;
566 meanTop = my - meanTop;
567
568 if (meanBottom > rangeBottom) meanBottom = rangeBottom; 580 if (meanBottom > rangeBottom) meanBottom = rangeBottom;
569 if (meanTop < rangeTop) meanTop = rangeTop; 581 if (meanTop < rangeTop) meanTop = rangeTop;
570 582
571 bool drawMean = m_showMeans; 583 bool drawMean = m_showMeans;
572 if (meanTop == rangeTop) { 584 if (meanTop == rangeTop) {
612 if (!clipped) { 624 if (!clipped) {
613 if (rangeTop < rangeBottom) { 625 if (rangeTop < rangeBottom) {
614 if (topFill > 0 && 626 if (topFill > 0 &&
615 (!drawMean || (rangeTop < meanTop - 1))) { 627 (!drawMean || (rangeTop < meanTop - 1))) {
616 paint->setPen(greys[topFill - 1]); 628 paint->setPen(greys[topFill - 1]);
617 paint->drawPoint(x, rangeTop - 1); 629 paint->drawPoint(x, rangeTop);
618 } 630 }
619 if (bottomFill > 0 && 631 if (bottomFill > 0 &&
620 (!drawMean || (rangeBottom > meanBottom + 1))) { 632 (!drawMean || (rangeBottom > meanBottom + 1))) {
621 paint->setPen(greys[bottomFill - 1]); 633 paint->setPen(greys[bottomFill - 1]);
622 paint->drawPoint(x, rangeBottom + 1); 634 paint->drawPoint(x, rangeBottom);
623 } 635 }
624 } 636 }
625 } 637 }
626 } 638 }
627 639