comparison layer/SpectrogramLayer.cpp @ 1136:9ff838a64461 spectrogram-minor-refactor

Re-enable (little-used) normalise-visible-range option in spectrogram layer
author Chris Cannam
date Wed, 03 Aug 2016 16:16:23 +0100
parents 199049012fc6
children 4e7ed3252d80
comparison
equal deleted inserted replaced
1135:628cd329c241 1136:9ff838a64461
1394 } 1394 }
1395 1395
1396 Colour3DPlotRenderer * 1396 Colour3DPlotRenderer *
1397 SpectrogramLayer::getRenderer(LayerGeometryProvider *v) const 1397 SpectrogramLayer::getRenderer(LayerGeometryProvider *v) const
1398 { 1398 {
1399 if (m_renderers.find(v->getId()) == m_renderers.end()) { 1399 int viewId = v->getId();
1400
1401 if (m_renderers.find(viewId) == m_renderers.end()) {
1400 1402
1401 Colour3DPlotRenderer::Sources sources; 1403 Colour3DPlotRenderer::Sources sources;
1402 sources.verticalBinLayer = this; 1404 sources.verticalBinLayer = this;
1403 sources.fft = getFFTModel(); 1405 sources.fft = getFFTModel();
1404 sources.source = sources.fft; 1406 sources.source = sources.fft;
1411 if (m_colourScale != ColourScaleType::Phase) { 1413 if (m_colourScale != ColourScaleType::Phase) {
1412 cparams.gain = m_gain; 1414 cparams.gain = m_gain;
1413 cparams.threshold = m_threshold; 1415 cparams.threshold = m_threshold;
1414 } 1416 }
1415 1417
1416 if (m_colourScale == ColourScaleType::Linear && 1418 float minValue = 0.0f;
1417 m_normalization == ColumnNormalization::None) { 1419 float maxValue = 1.0f;
1420
1421 if (m_normalizeVisibleArea && m_viewMags[viewId].isSet()) {
1422 minValue = m_viewMags[viewId].getMin();
1423 maxValue = m_viewMags[viewId].getMax();
1424 } else if (m_colourScale == ColourScaleType::Linear &&
1425 m_normalization == ColumnNormalization::None) {
1418 //!!! This should not be necessary -- what is the actual range 1426 //!!! This should not be necessary -- what is the actual range
1419 cparams.maxValue = 0.1; 1427 maxValue = 0.1f;
1420 if (cparams.maxValue <= m_threshold) {
1421 cparams.maxValue = m_threshold + 0.1;
1422 }
1423 } 1428 }
1429
1430 if (maxValue <= minValue) {
1431 maxValue = minValue + 0.1f;
1432 }
1433 if (maxValue <= m_threshold) {
1434 maxValue = m_threshold + 0.1f;
1435 }
1436
1437 cparams.minValue = minValue;
1438 cparams.maxValue = maxValue;
1439
1440 m_lastRenderedMags[viewId] = MagnitudeRange(minValue, maxValue);
1424 1441
1425 Colour3DPlotRenderer::Parameters params; 1442 Colour3DPlotRenderer::Parameters params;
1426 params.colourScale = ColourScale(cparams); 1443 params.colourScale = ColourScale(cparams);
1427 params.normalization = m_normalization; 1444 params.normalization = m_normalization;
1428 params.binDisplay = m_binDisplay; 1445 params.binDisplay = m_binDisplay;
1455 1472
1456 Colour3DPlotRenderer::RenderResult result; 1473 Colour3DPlotRenderer::RenderResult result;
1457 MagnitudeRange magRange; 1474 MagnitudeRange magRange;
1458 int viewId = v->getId(); 1475 int viewId = v->getId();
1459 1476
1460 if (!renderer->geometryChanged(v)) { 1477 bool continuingPaint = !renderer->geometryChanged(v);
1478
1479 if (continuingPaint) {
1461 magRange = m_viewMags[viewId]; 1480 magRange = m_viewMags[viewId];
1462 } 1481 }
1463 1482
1464 if (m_synchronous) { 1483 if (m_synchronous) {
1465 1484
1480 } 1499 }
1481 1500
1482 magRange.sample(result.range); 1501 magRange.sample(result.range);
1483 1502
1484 if (magRange.isSet()) { 1503 if (magRange.isSet()) {
1485 if (!(m_viewMags[viewId] == magRange)) { 1504 if (m_viewMags[viewId] != magRange) {
1486 m_viewMags[viewId] = magRange; 1505 m_viewMags[viewId] = magRange;
1487 //!!! now need to do the normalise-visible thing 1506 cerr << "mag range in this view has changed: "
1507 << magRange.getMin() << " -> " << magRange.getMax() << endl;
1488 } 1508 }
1489 } 1509 }
1490 1510
1491 cerr << "mag range in this view: " 1511 if (!continuingPaint && m_normalizeVisibleArea &&
1492 << m_viewMags[viewId].getMin() 1512 m_viewMags[viewId] != m_lastRenderedMags[viewId]) {
1493 << " -> " 1513 cerr << "mag range has changed from last rendered range: re-rendering"
1494 << m_viewMags[viewId].getMax() 1514 << endl;
1495 << endl; 1515 delete m_renderers[viewId];
1516 m_renderers.erase(viewId);
1517 v->updatePaintRect(v->getPaintRect());
1518 }
1496 } 1519 }
1497 1520
1498 void 1521 void
1499 SpectrogramLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const 1522 SpectrogramLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const
1500 { 1523 {