Mercurial > hg > svgui
comparison layer/SpectrogramLayer.cpp @ 10:8f5b812baaee
* Hook up SV file i/o. You can now save and load sessions.
Some problems -- gain is not reloaded correctly for waveforms,
reloaded panes are not properly reconnected to the panner, and
no doubt plenty of others.
author | Chris Cannam |
---|---|
date | Tue, 17 Jan 2006 17:45:55 +0000 |
parents | 561be41ad083 |
children | 2d5005f2b3d9 |
comparison
equal
deleted
inserted
replaced
9:561be41ad083 | 10:8f5b812baaee |
---|---|
140 SpectrogramLayer::getPropertyRangeAndValue(const PropertyName &name, | 140 SpectrogramLayer::getPropertyRangeAndValue(const PropertyName &name, |
141 int *min, int *max) const | 141 int *min, int *max) const |
142 { | 142 { |
143 int deft = 0; | 143 int deft = 0; |
144 | 144 |
145 int throwaway; | |
146 if (!min) min = &throwaway; | |
147 if (!max) max = &throwaway; | |
148 | |
145 if (name == tr("Gain")) { | 149 if (name == tr("Gain")) { |
146 | 150 |
147 *min = -50; | 151 *min = -50; |
148 *max = 50; | 152 *max = 50; |
149 | 153 |
550 | 554 |
551 m_mutex.lock(); | 555 m_mutex.lock(); |
552 // don't need to invalidate main cache here | 556 // don't need to invalidate main cache here |
553 m_pixmapCacheInvalid = true; | 557 m_pixmapCacheInvalid = true; |
554 | 558 |
555 int formerColourRotation = m_colourRotation; | |
556 | |
557 m_colourScheme = scheme; | 559 m_colourScheme = scheme; |
558 setCacheColourmap(); | 560 setCacheColourmap(); |
559 | |
560 int distance = formerColourRotation - m_colourRotation; | |
561 | |
562 if (distance != 0) { | |
563 rotateCacheColourmap(-distance); | |
564 m_colourRotation = formerColourRotation; | |
565 } | |
566 | 561 |
567 m_mutex.unlock(); | 562 m_mutex.unlock(); |
568 | 563 |
569 emit layerParametersChanged(); | 564 emit layerParametersChanged(); |
570 } | 565 } |
683 void | 678 void |
684 SpectrogramLayer::setCacheColourmap() | 679 SpectrogramLayer::setCacheColourmap() |
685 { | 680 { |
686 if (m_cacheInvalid || !m_cache) return; | 681 if (m_cacheInvalid || !m_cache) return; |
687 | 682 |
683 int formerRotation = m_colourRotation; | |
684 | |
688 m_cache->setNumColors(256); | 685 m_cache->setNumColors(256); |
689 | 686 |
690 m_cache->setColor(0, qRgb(255, 255, 255)); | 687 m_cache->setColor(0, qRgb(255, 255, 255)); |
691 | 688 |
692 for (int pixel = 1; pixel < 256; ++pixel) { | 689 for (int pixel = 1; pixel < 256; ++pixel) { |
733 m_cache->setColor | 730 m_cache->setColor |
734 (pixel, qRgb(colour.red(), colour.green(), colour.blue())); | 731 (pixel, qRgb(colour.red(), colour.green(), colour.blue())); |
735 } | 732 } |
736 | 733 |
737 m_colourRotation = 0; | 734 m_colourRotation = 0; |
735 rotateCacheColourmap(m_colourRotation - formerRotation); | |
736 m_colourRotation = formerRotation; | |
738 } | 737 } |
739 | 738 |
740 void | 739 void |
741 SpectrogramLayer::rotateCacheColourmap(int distance) | 740 SpectrogramLayer::rotateCacheColourmap(int distance) |
742 { | 741 { |
742 if (!m_cache) return; | |
743 | |
743 QRgb newPixels[256]; | 744 QRgb newPixels[256]; |
744 | 745 |
745 newPixels[0] = m_cache->color(0); | 746 newPixels[0] = m_cache->color(0); |
746 | 747 |
747 for (int pixel = 1; pixel < 256; ++pixel) { | 748 for (int pixel = 1; pixel < 256; ++pixel) { |
912 // unlocked in the first place. | 913 // unlocked in the first place. |
913 //!!! hm, I don't think this is working. | 914 //!!! hm, I don't think this is working. |
914 MUNLOCK((void *)m_layer.m_cache, width * height); | 915 MUNLOCK((void *)m_layer.m_cache, width * height); |
915 | 916 |
916 m_layer.setCacheColourmap(); | 917 m_layer.setCacheColourmap(); |
917 | 918 |
918 m_layer.m_cache->fill(0); | 919 m_layer.m_cache->fill(0); |
919 m_layer.m_mutex.unlock(); | 920 m_layer.m_mutex.unlock(); |
920 | 921 |
921 double *input = (double *) | 922 double *input = (double *) |
922 fftw_malloc(windowSize * sizeof(double)); | 923 fftw_malloc(windowSize * sizeof(double)); |
1439 } | 1440 } |
1440 } | 1441 } |
1441 } | 1442 } |
1442 | 1443 |
1443 if (divisor > 0.0) { | 1444 if (divisor > 0.0) { |
1444 | 1445 /* |
1445 int pixel = int(total / divisor); | 1446 int pixel = int(total / divisor); |
1446 if (pixel > 255) pixel = 255; | 1447 if (pixel > 255) pixel = 255; |
1447 if (pixel < 1) pixel = 1; | 1448 if (pixel < 1) pixel = 1; |
1448 assert(x <= scaled.width()); | 1449 assert(x <= scaled.width()); |
1449 scaled.setPixel(x, y, m_cache->color(pixel)); | 1450 scaled.setPixel(x, y, m_cache->color(pixel)); |
1450 /* | 1451 */ |
1451 float pixel = total / divisor; | 1452 float pixel = total / divisor; |
1452 float lq = pixel - int(pixel); | 1453 float lq = pixel - int(pixel); |
1453 float hq = int(pixel) + 1 - pixel; | 1454 float hq = int(pixel) + 1 - pixel; |
1454 int pixNum = int(pixel); | 1455 int pixNum = int(pixel); |
1455 QRgb low = m_cache->color(pixNum > 255 ? 255 : pixNum); | 1456 QRgb low = m_cache->color(pixNum > 255 ? 255 : pixNum); |
1457 QRgb mixed = qRgb | 1458 QRgb mixed = qRgb |
1458 (qRed(low) * lq + qRed(high) * hq + 0.01, | 1459 (qRed(low) * lq + qRed(high) * hq + 0.01, |
1459 qGreen(low) * lq + qGreen(high) * hq + 0.01, | 1460 qGreen(low) * lq + qGreen(high) * hq + 0.01, |
1460 qBlue(low) * lq + qBlue(high) * hq + 0.01); | 1461 qBlue(low) * lq + qBlue(high) * hq + 0.01); |
1461 scaled.setPixel(x, y, mixed); | 1462 scaled.setPixel(x, y, mixed); |
1462 */ | 1463 |
1463 } else { | 1464 } else { |
1464 assert(x <= scaled.width()); | 1465 assert(x <= scaled.width()); |
1465 scaled.setPixel(x, y, qRgb(0, 0, 0)); | 1466 scaled.setPixel(x, y, qRgb(0, 0, 0)); |
1466 } | 1467 } |
1467 } | 1468 } |