# HG changeset patch # User Chris Cannam # Date 1181922491 0 # Node ID a3a54632cd4cc571d4980a2927aa3fb6a1607607 # Parent 7e9e533f18632b01d55f273fa183a7416ca43529 * fixes to spectrum harmonic cursor etc diff -r 7e9e533f1863 -r a3a54632cd4c layer/SliceLayer.h --- a/layer/SliceLayer.h Fri Jun 15 12:55:16 2007 +0000 +++ b/layer/SliceLayer.h Fri Jun 15 15:48:11 2007 +0000 @@ -105,8 +105,8 @@ void modelAboutToBeDeleted(Model *); protected: - float getXForBin(int bin, int totalBins, float w) const; - int getBinForX(float x, int totalBins, float w) const; + virtual float getXForBin(int bin, int totalBins, float w) const; + virtual int getBinForX(float x, int totalBins, float w) const; virtual QString getFeatureDescription(View *v, QPoint &, bool includeBinDescription, diff -r 7e9e533f1863 -r a3a54632cd4c layer/SpectrumLayer.cpp --- a/layer/SpectrumLayer.cpp Fri Jun 15 12:55:16 2007 +0000 +++ b/layer/SpectrumLayer.cpp Fri Jun 15 15:48:11 2007 +0000 @@ -256,6 +256,28 @@ } float +SpectrumLayer::getXForBin(int bin, int totalBins, float w) const +{ + if (!m_sliceableModel) return SliceLayer::getXForBin(bin, totalBins, w); + + float sampleRate = m_sliceableModel->getSampleRate(); + float binfreq = (sampleRate * bin) / (totalBins * 2); + + return getXForFrequency(binfreq, w); +} + +int +SpectrumLayer::getBinForX(float x, int totalBins, float w) const +{ + if (!m_sliceableModel) return SliceLayer::getBinForX(x, totalBins, w); + + float sampleRate = m_sliceableModel->getSampleRate(); + float binfreq = getFrequencyForX(x, w); + + return int((binfreq * totalBins * 2) / sampleRate); +} + +float SpectrumLayer::getFrequencyForX(float x, float w) const { float freq = 0; diff -r 7e9e533f1863 -r a3a54632cd4c layer/SpectrumLayer.h --- a/layer/SpectrumLayer.h Fri Jun 15 12:55:16 2007 +0000 +++ b/layer/SpectrumLayer.h Fri Jun 15 15:48:11 2007 +0000 @@ -100,6 +100,9 @@ virtual void getBiasCurve(BiasCurve &) const; BiasCurve m_biasCurve; + virtual float getXForBin(int bin, int totalBins, float w) const; + virtual int getBinForX(float x, int totalBins, float w) const; + float getFrequencyForX(float x, float w) const; float getXForFrequency(float freq, float w) const;