Mercurial > hg > svgui
comparison layer/SpectrogramLayer.cpp @ 1362:d79e21855aef
Add mechanism for saving/loading colour maps by name/id rather than by numerical index, for future compatibility when adding to or changing the supported colour maps. Add two new colour maps (and one old one). Write out backward-compatible numerical indices for use when reloading in older versions. Also add a mechanism to invert the colour map, though I don't think it turns out useful enough to include in the UI.
author | Chris Cannam |
---|---|
date | Thu, 18 Oct 2018 13:21:56 +0100 |
parents | 6e724c81f18f |
children | b6cca362bbf4 |
comparison
equal
deleted
inserted
replaced
1361:2e3b3fadba27 | 1362:d79e21855aef |
---|---|
71 m_maxFrequency(8000), | 71 m_maxFrequency(8000), |
72 m_initialMaxFrequency(8000), | 72 m_initialMaxFrequency(8000), |
73 m_colourScale(ColourScaleType::Log), | 73 m_colourScale(ColourScaleType::Log), |
74 m_colourScaleMultiple(1.0), | 74 m_colourScaleMultiple(1.0), |
75 m_colourMap(0), | 75 m_colourMap(0), |
76 m_colourInverted(false), | |
76 m_binScale(BinScale::Linear), | 77 m_binScale(BinScale::Linear), |
77 m_binDisplay(BinDisplay::AllBins), | 78 m_binDisplay(BinDisplay::AllBins), |
78 m_normalization(ColumnNormalization::None), | 79 m_normalization(ColumnNormalization::None), |
79 m_normalizeVisibleArea(false), | 80 m_normalizeVisibleArea(false), |
80 m_lastEmittedZoomStep(-1), | 81 m_lastEmittedZoomStep(-1), |
446 QString | 447 QString |
447 SpectrogramLayer::getPropertyValueLabel(const PropertyName &name, | 448 SpectrogramLayer::getPropertyValueLabel(const PropertyName &name, |
448 int value) const | 449 int value) const |
449 { | 450 { |
450 if (name == "Colour") { | 451 if (name == "Colour") { |
451 return ColourMapper::getColourMapName(value); | 452 return ColourMapper::getColourMapLabel(value); |
452 } | 453 } |
453 if (name == "Colour Scale") { | 454 if (name == "Colour Scale") { |
454 switch (value) { | 455 switch (value) { |
455 default: | 456 default: |
456 case 0: return tr("Linear"); | 457 case 0: return tr("Linear"); |
1079 } | 1080 } |
1080 | 1081 |
1081 bool | 1082 bool |
1082 SpectrogramLayer::hasLightBackground() const | 1083 SpectrogramLayer::hasLightBackground() const |
1083 { | 1084 { |
1084 return ColourMapper(m_colourMap, 1.f, 255.f).hasLightBackground(); | 1085 return ColourMapper(m_colourMap, m_colourInverted, 1.f, 255.f) |
1086 .hasLightBackground(); | |
1085 } | 1087 } |
1086 | 1088 |
1087 double | 1089 double |
1088 SpectrogramLayer::getEffectiveMinFrequency() const | 1090 SpectrogramLayer::getEffectiveMinFrequency() const |
1089 { | 1091 { |
1528 smoothing == Preferences::SpectrogramZeroPaddedAndInterpolated); | 1530 smoothing == Preferences::SpectrogramZeroPaddedAndInterpolated); |
1529 | 1531 |
1530 m_renderers[viewId] = new Colour3DPlotRenderer(sources, params); | 1532 m_renderers[viewId] = new Colour3DPlotRenderer(sources, params); |
1531 | 1533 |
1532 m_crosshairColour = | 1534 m_crosshairColour = |
1533 ColourMapper(m_colourMap, 1.f, 255.f).getContrastingColour(); | 1535 ColourMapper(m_colourMap, m_colourInverted, 1.f, 255.f) |
1536 .getContrastingColour(); | |
1534 } | 1537 } |
1535 | 1538 |
1536 return m_renderers[viewId]; | 1539 return m_renderers[viewId]; |
1537 } | 1540 } |
1538 | 1541 |
2506 .arg(m_threshold); | 2509 .arg(m_threshold); |
2507 | 2510 |
2508 s += QString("minFrequency=\"%1\" " | 2511 s += QString("minFrequency=\"%1\" " |
2509 "maxFrequency=\"%2\" " | 2512 "maxFrequency=\"%2\" " |
2510 "colourScale=\"%3\" " | 2513 "colourScale=\"%3\" " |
2511 "colourScheme=\"%4\" " | 2514 "colourRotation=\"%4\" " |
2512 "colourRotation=\"%5\" " | 2515 "frequencyScale=\"%5\" " |
2513 "frequencyScale=\"%6\" " | 2516 "binDisplay=\"%6\" ") |
2514 "binDisplay=\"%7\" ") | |
2515 .arg(m_minFrequency) | 2517 .arg(m_minFrequency) |
2516 .arg(m_maxFrequency) | 2518 .arg(m_maxFrequency) |
2517 .arg(convertFromColourScale(m_colourScale, m_colourScaleMultiple)) | 2519 .arg(convertFromColourScale(m_colourScale, m_colourScaleMultiple)) |
2518 .arg(m_colourMap) | |
2519 .arg(m_colourRotation) | 2520 .arg(m_colourRotation) |
2520 .arg(int(m_binScale)) | 2521 .arg(int(m_binScale)) |
2521 .arg(int(m_binDisplay)); | 2522 .arg(int(m_binDisplay)); |
2522 | 2523 |
2524 // New-style colour map attribute, by string id rather than by | |
2525 // number | |
2526 | |
2527 s += QString("colourMap=\"%1\" ") | |
2528 .arg(ColourMapper::getColourMapId(m_colourMap)); | |
2529 | |
2530 // Old-style colour map attribute | |
2531 | |
2532 s += QString("colourScheme=\"%1\" ") | |
2533 .arg(ColourMapper::getBackwardCompatibilityColourMap(m_colourMap)); | |
2534 | |
2523 // New-style normalization attributes, allowing for more types of | 2535 // New-style normalization attributes, allowing for more types of |
2524 // normalization in future: write out the column normalization | 2536 // normalization in future: write out the column normalization |
2525 // type separately, and then whether we are normalizing visible | 2537 // type separately, and then whether we are normalizing visible |
2526 // area as well afterwards | 2538 // area as well afterwards |
2527 | 2539 |
2594 if (ok) { | 2606 if (ok) { |
2595 setColourScale(colourScale.first); | 2607 setColourScale(colourScale.first); |
2596 setColourScaleMultiple(colourScale.second); | 2608 setColourScaleMultiple(colourScale.second); |
2597 } | 2609 } |
2598 | 2610 |
2599 int colourMap = attributes.value("colourScheme").toInt(&ok); | 2611 QString colourMapId = attributes.value("colourMap"); |
2600 if (ok) setColourMap(colourMap); | 2612 int colourMap = ColourMapper::getColourMapById(colourMapId); |
2613 if (colourMap >= 0) { | |
2614 setColourMap(colourMap); | |
2615 } else { | |
2616 colourMap = attributes.value("colourScheme").toInt(&ok); | |
2617 if (ok && colourMap < ColourMapper::getColourMapCount()) { | |
2618 setColourMap(colourMap); | |
2619 } | |
2620 } | |
2601 | 2621 |
2602 int colourRotation = attributes.value("colourRotation").toInt(&ok); | 2622 int colourRotation = attributes.value("colourRotation").toInt(&ok); |
2603 if (ok) setColourRotation(colourRotation); | 2623 if (ok) setColourRotation(colourRotation); |
2604 | 2624 |
2605 BinScale binScale = (BinScale) | 2625 BinScale binScale = (BinScale) |