diff --git a/src/Envelope.cpp b/src/Envelope.cpp index b70f3b15a..44f72ac0d 100644 --- a/src/Envelope.cpp +++ b/src/Envelope.cpp @@ -189,17 +189,6 @@ double Envelope::toDB(double value) return sign * val; } -double Envelope::fromDB(double value) const -{ - if (value == 0) - return 0; - - double sign = (value >= 0 ? 1 : -1); - // TODO: Cache the gPrefs value. Reading it every time is inefficient. - double dBRange = gPrefs->Read(wxT("/GUI/EnvdBRange"), ENV_DB_RANGE); - return pow(10.0, ((fabs(value) * dBRange) - dBRange) / 20.0)*sign;; -} - /// TODO: This should probably move to track artist. static void DrawPoint(wxDC & dc, const wxRect & r, int x, int y, bool top) { @@ -342,19 +331,12 @@ void Envelope::WriteXML(XMLWriter &xmlFile) float Envelope::ValueOfPixel( int y, int height, bool upper, bool dB, float zoomMin, float zoomMax) { - float v; - - wxASSERT( height > 0 ); - v = zoomMax - (y/(float)height) * (zoomMax - zoomMin); - - if (mContourOffset) { - if( v > 0.0 ) - v += .5; - else - v -= .5; - } + double dBRange; if (dB) - v = fromDB(v); + // TODO: Cache the gPrefs value. Reading it every time is inefficient. + dBRange = gPrefs->Read(wxT("/GUI/EnvdBRange"), ENV_DB_RANGE); + + float v = ::ValueOfPixel(y, height, mContourOffset, dB, dBRange, zoomMin, zoomMax); // MB: this is mostly equivalent to what the old code did, I'm not sure // if anything special is needed for asymmetric ranges diff --git a/src/Envelope.h b/src/Envelope.h index 481657bd4..c1e25bc59 100644 --- a/src/Envelope.h +++ b/src/Envelope.h @@ -194,7 +194,6 @@ class Envelope : public XMLTagHandler { int bufferLen) const; private: - double fromDB(double x) const; double toDB(double x); EnvPoint * AddPointAtEnd( double t, double val ); void MarkDragPointForDeletion(); diff --git a/src/TrackArtist.cpp b/src/TrackArtist.cpp index b72181c7d..00fc9b4b2 100644 --- a/src/TrackArtist.cpp +++ b/src/TrackArtist.cpp @@ -959,6 +959,33 @@ int GetWaveYPos(float value, float min, float max, return (int) (value * (height - 1) + 0.5); } +float FromDB(float value, double dBRange) +{ + if (value == 0) + return 0; + + double sign = (value >= 0 ? 1 : -1); + return pow(10.0, ((fabs(value) * dBRange) - dBRange) / 20.0)*sign; +} + +float ValueOfPixel(int y, int height, bool offset, + bool dB, double dBRange, float zoomMin, float zoomMax) +{ + wxASSERT(height > 0); + float v = zoomMax - (y / (float)height) * (zoomMax - zoomMin); + if (offset) { + if (v > 0.0) + v += .5; + else + v -= .5; + } + + if (dB) + v = FromDB(v, dBRange); + + return v; +} + void TrackArtist::DrawNegativeOffsetTrackArrows(wxDC &dc, const wxRect &r) { // Draws two black arrows on the left side of the track to diff --git a/src/TrackArtist.h b/src/TrackArtist.h index b833f2768..c14d5632a 100644 --- a/src/TrackArtist.h +++ b/src/TrackArtist.h @@ -249,5 +249,8 @@ class AUDACITY_DLL_API TrackArtist { extern int GetWaveYPos(float value, float min, float max, int height, bool dB, bool outer, float dBr, bool clip); +extern float FromDB(float value, double dBRange); +extern float ValueOfPixel(int y, int height, bool offset, + bool dB, double dBRange, float zoomMin, float zoomMax); #endif // define __AUDACITY_TRACKARTIST__