Mercurial > hg > svgui
comparison layer/SpectrogramLayer.cpp @ 1117:64709d4d09ef spectrogram-minor-refactor
Fix translucent mode for spectrogram
author | Chris Cannam |
---|---|
date | Tue, 19 Jul 2016 17:28:03 +0100 |
parents | ee8e73dc5c8b |
children | d930ff725f64 |
comparison
equal
deleted
inserted
replaced
1116:e7a07cd63d21 | 1117:64709d4d09ef |
---|---|
1015 { | 1015 { |
1016 #ifdef DEBUG_SPECTROGRAM_REPAINT | 1016 #ifdef DEBUG_SPECTROGRAM_REPAINT |
1017 cerr << "SpectrogramLayer::cacheInvalid(" << from << ", " << to << ")" << endl; | 1017 cerr << "SpectrogramLayer::cacheInvalid(" << from << ", " << to << ")" << endl; |
1018 #endif | 1018 #endif |
1019 | 1019 |
1020 //!!! now in common with Colour3DPlotLayer: | |
1020 // We used to call invalidateMagnitudes(from, to) to invalidate | 1021 // We used to call invalidateMagnitudes(from, to) to invalidate |
1021 // only those caches whose views contained some of the (from, to) | 1022 // only those caches whose views contained some of the (from, to) |
1022 // range. That's the right thing to do; it has been lost in | 1023 // range. That's the right thing to do; it has been lost in |
1023 // pulling out the image cache code, but it might not matter very | 1024 // pulling out the image cache code, but it might not matter very |
1024 // much, since the underlying models for spectrogram layers don't | 1025 // much, since the underlying models for spectrogram layers don't |
1065 | 1066 |
1066 bool | 1067 bool |
1067 SpectrogramLayer::getYBinRange(LayerGeometryProvider *v, int y, double &q0, double &q1) const | 1068 SpectrogramLayer::getYBinRange(LayerGeometryProvider *v, int y, double &q0, double &q1) const |
1068 { | 1069 { |
1069 Profiler profiler("SpectrogramLayer::getYBinRange"); | 1070 Profiler profiler("SpectrogramLayer::getYBinRange"); |
1070 | |
1071 int h = v->getPaintHeight(); | 1071 int h = v->getPaintHeight(); |
1072 if (y < 0 || y >= h) return false; | 1072 if (y < 0 || y >= h) return false; |
1073 | 1073 q0 = getBinForY(v, y); |
1074 q1 = getBinForY(v, y-1); | |
1075 return true; | |
1076 } | |
1077 | |
1078 double | |
1079 SpectrogramLayer::getYForBin(const LayerGeometryProvider *v, double bin) const | |
1080 { | |
1081 double minf = getEffectiveMinFrequency(); | |
1082 double maxf = getEffectiveMaxFrequency(); | |
1083 bool logarithmic = (m_binScale == BinScale::Log); | |
1084 sv_samplerate_t sr = m_model->getSampleRate(); | |
1085 | |
1086 double freq = (bin * sr) / getFFTSize(); | |
1087 | |
1088 double y = v->getYForFrequency(freq, minf, maxf, logarithmic); | |
1089 | |
1090 return y; | |
1091 } | |
1092 | |
1093 double | |
1094 SpectrogramLayer::getBinForY(const LayerGeometryProvider *v, double y) const | |
1095 { | |
1074 sv_samplerate_t sr = m_model->getSampleRate(); | 1096 sv_samplerate_t sr = m_model->getSampleRate(); |
1075 double minf = getEffectiveMinFrequency(); | 1097 double minf = getEffectiveMinFrequency(); |
1076 double maxf = getEffectiveMaxFrequency(); | 1098 double maxf = getEffectiveMaxFrequency(); |
1077 | 1099 |
1078 bool logarithmic = (m_binScale == BinScale::Log); | 1100 bool logarithmic = (m_binScale == BinScale::Log); |
1079 | 1101 |
1080 q0 = v->getFrequencyForY(y, minf, maxf, logarithmic); | 1102 double freq = v->getFrequencyForY(y, minf, maxf, logarithmic); |
1081 q1 = v->getFrequencyForY(y - 1, minf, maxf, logarithmic); | 1103 |
1082 | 1104 // Now map on to ("proportion of") actual bins |
1083 // Now map these on to ("proportions of") actual bins | 1105 double bin = (freq * getFFTSize()) / sr; |
1084 | 1106 |
1085 q0 = (q0 * getFFTSize()) / sr; | 1107 return bin; |
1086 q1 = (q1 * getFFTSize()) / sr; | |
1087 | |
1088 return true; | |
1089 } | |
1090 | |
1091 double | |
1092 SpectrogramLayer::getYForBin(const LayerGeometryProvider *, double) const { | |
1093 //!!! not implemented -- needed for non-opaque render | |
1094 | |
1095 //!!! this will crash, as it stands, when a spectrogram without | |
1096 //!!! smoothing is zoomed in | |
1097 | |
1098 //!!! overlap with range methods | |
1099 throw std::logic_error("not implemented"); | |
1100 } | |
1101 | |
1102 double | |
1103 SpectrogramLayer::getBinForY(const LayerGeometryProvider *v, double y) const | |
1104 { | |
1105 //!!! overlap with range methods above (but using double arg) | |
1106 //!!! tidy this | |
1107 | |
1108 int h = v->getPaintHeight(); | |
1109 if (y < 0 || y >= h) return false; | |
1110 | |
1111 sv_samplerate_t sr = m_model->getSampleRate(); | |
1112 double minf = getEffectiveMinFrequency(); | |
1113 double maxf = getEffectiveMaxFrequency(); | |
1114 | |
1115 bool logarithmic = (m_binScale == BinScale::Log); | |
1116 | |
1117 double q = v->getFrequencyForY(y, minf, maxf, logarithmic); | |
1118 | |
1119 // Now map on to ("proportions of") actual bins | |
1120 | |
1121 q = (q * getFFTSize()) / sr; | |
1122 | |
1123 return q; | |
1124 } | 1108 } |
1125 | 1109 |
1126 bool | 1110 bool |
1127 SpectrogramLayer::getXBinRange(LayerGeometryProvider *v, int x, double &s0, double &s1) const | 1111 SpectrogramLayer::getXBinRange(LayerGeometryProvider *v, int x, double &s0, double &s1) const |
1128 { | 1112 { |