comparison layer/SpectrogramLayer.cpp @ 77:fd348f36c0d3

* Implement harmonic cursor in spectrogram * Implement layer export. This doesn't quite do the right thing for the SV XML layer export yet -- it doesn't include layer display information, so when imported, it only creates an invisible model. Could also do with fixing CSV file import so as to work correctly for note and text layers.
author Chris Cannam
date Mon, 10 Apr 2006 17:22:59 +0000
parents dfdbf336bb37
children 19bf27e4fb29
comparison
equal deleted inserted replaced
76:45ba0b381c5d 77:fd348f36c0d3
946 946
947 default: 947 default:
948 case DefaultColours: 948 case DefaultColours:
949 hue = 256 - pixel; 949 hue = 256 - pixel;
950 colour = QColor::fromHsv(hue, pixel/2 + 128, pixel); 950 colour = QColor::fromHsv(hue, pixel/2 + 128, pixel);
951 m_crosshairColour = QColor(255, 150, 50);
952 // m_crosshairColour = QColor::fromHsv(240, 160, 255);
951 break; 953 break;
952 954
953 case WhiteOnBlack: 955 case WhiteOnBlack:
954 colour = QColor(pixel, pixel, pixel); 956 colour = QColor(pixel, pixel, pixel);
957 m_crosshairColour = Qt::red;
955 break; 958 break;
956 959
957 case BlackOnWhite: 960 case BlackOnWhite:
958 colour = QColor(256-pixel, 256-pixel, 256-pixel); 961 colour = QColor(256-pixel, 256-pixel, 256-pixel);
962 m_crosshairColour = Qt::darkGreen;
959 break; 963 break;
960 964
961 case RedOnBlue: 965 case RedOnBlue:
962 colour = QColor(pixel > 128 ? (pixel - 128) * 2 : 0, 0, 966 colour = QColor(pixel > 128 ? (pixel - 128) * 2 : 0, 0,
963 pixel < 128 ? pixel : (256 - pixel)); 967 pixel < 128 ? pixel : (256 - pixel));
968 m_crosshairColour = Qt::green;
964 break; 969 break;
965 970
966 case YellowOnBlack: 971 case YellowOnBlack:
967 px = 256 - pixel; 972 px = 256 - pixel;
968 colour = QColor(px < 64 ? 255 - px/2 : 973 colour = QColor(px < 64 ? 255 - px/2 :
969 px < 128 ? 224 - (px - 64) : 974 px < 128 ? 224 - (px - 64) :
970 px < 192 ? 160 - (px - 128) * 3 / 2 : 975 px < 192 ? 160 - (px - 128) * 3 / 2 :
971 256 - px, 976 256 - px,
972 pixel, 977 pixel,
973 pixel / 4); 978 pixel / 4);
979 m_crosshairColour = QColor::fromHsv(240, 255, 255);
974 break; 980 break;
975 981
976 case BlueOnBlack: 982 case BlueOnBlack:
977 colour = QColor::fromHsv 983 colour = QColor::fromHsv
978 (240, pixel > 226 ? 256 - (pixel - 226) * 8 : 255, 984 (240, pixel > 226 ? 256 - (pixel - 226) * 8 : 255,
979 (pixel * pixel) / 255); 985 (pixel * pixel) / 255);
986 m_crosshairColour = Qt::red;
980 break; 987 break;
981 988
982 case Rainbow: 989 case Rainbow:
983 hue = 250 - pixel; 990 hue = 250 - pixel;
984 if (hue < 0) hue += 256; 991 if (hue < 0) hue += 256;
985 colour = QColor::fromHsv(pixel, 255, 255); 992 colour = QColor::fromHsv(pixel, 255, 255);
993 m_crosshairColour = Qt::white;
986 break; 994 break;
987 } 995 }
988 996
989 m_cache->setColour(pixel, colour); 997 m_cache->setColour(pixel, colour);
990 } 998 }
2103 } 2111 }
2104 2112
2105 return true; 2113 return true;
2106 } 2114 }
2107 2115
2116 bool
2117 SpectrogramLayer::getCrosshairExtents(View *v, QPainter &paint,
2118 QPoint cursorPos,
2119 std::vector<QRect> &extents) const
2120 {
2121 QRect vertical(cursorPos.x() - 12, 0, 12, v->height());
2122 extents.push_back(vertical);
2123
2124 QRect horizontal(0, cursorPos.y(), cursorPos.x(), 1);
2125 extents.push_back(horizontal);
2126
2127 return true;
2128 }
2129
2130 void
2131 SpectrogramLayer::paintCrosshairs(View *v, QPainter &paint,
2132 QPoint cursorPos) const
2133 {
2134 paint.save();
2135 paint.setPen(m_crosshairColour);
2136
2137 paint.drawLine(0, cursorPos.y(), cursorPos.x() - 1, cursorPos.y());
2138 paint.drawLine(cursorPos.x(), 0, cursorPos.x(), v->height());
2139
2140 float fundamental = getFrequencyForY(v, cursorPos.y());
2141
2142 int harmonic = 2;
2143
2144 while (harmonic < 100) {
2145
2146 float hy = lrintf(getYForFrequency(v, fundamental * harmonic));
2147 if (hy < 0 || hy > v->height()) break;
2148
2149 int len = 7;
2150
2151 if (harmonic % 2 == 0) {
2152 if (harmonic % 4 == 0) {
2153 len = 12;
2154 } else {
2155 len = 10;
2156 }
2157 }
2158
2159 paint.drawLine(cursorPos.x() - len,
2160 hy,
2161 cursorPos.x(),
2162 hy);
2163
2164 ++harmonic;
2165 }
2166
2167 paint.restore();
2168 }
2169
2108 QString 2170 QString
2109 SpectrogramLayer::getFeatureDescription(View *v, QPoint &pos) const 2171 SpectrogramLayer::getFeatureDescription(View *v, QPoint &pos) const
2110 { 2172 {
2111 int x = pos.x(); 2173 int x = pos.x();
2112 int y = pos.y(); 2174 int y = pos.y();