1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-20 14:20:06 +02:00

Moved ValueOfPixel into global namespace, it wants to live next to its inverse

This commit is contained in:
Paul Licameli 2015-06-02 19:11:09 -04:00
parent 1df1effb71
commit 437e28db1a
4 changed files with 35 additions and 24 deletions

View File

@ -189,17 +189,6 @@ double Envelope::toDB(double value)
return sign * val; 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. /// TODO: This should probably move to track artist.
static void DrawPoint(wxDC & dc, const wxRect & r, int x, int y, bool top) 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 Envelope::ValueOfPixel( int y, int height, bool upper, bool dB,
float zoomMin, float zoomMax) float zoomMin, float zoomMax)
{ {
float v; double dBRange;
wxASSERT( height > 0 );
v = zoomMax - (y/(float)height) * (zoomMax - zoomMin);
if (mContourOffset) {
if( v > 0.0 )
v += .5;
else
v -= .5;
}
if (dB) 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 // MB: this is mostly equivalent to what the old code did, I'm not sure
// if anything special is needed for asymmetric ranges // if anything special is needed for asymmetric ranges

View File

@ -194,7 +194,6 @@ class Envelope : public XMLTagHandler {
int bufferLen) const; int bufferLen) const;
private: private:
double fromDB(double x) const;
double toDB(double x); double toDB(double x);
EnvPoint * AddPointAtEnd( double t, double val ); EnvPoint * AddPointAtEnd( double t, double val );
void MarkDragPointForDeletion(); void MarkDragPointForDeletion();

View File

@ -959,6 +959,33 @@ int GetWaveYPos(float value, float min, float max,
return (int) (value * (height - 1) + 0.5); 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) void TrackArtist::DrawNegativeOffsetTrackArrows(wxDC &dc, const wxRect &r)
{ {
// Draws two black arrows on the left side of the track to // Draws two black arrows on the left side of the track to

View File

@ -249,5 +249,8 @@ class AUDACITY_DLL_API TrackArtist {
extern int GetWaveYPos(float value, float min, float max, extern int GetWaveYPos(float value, float min, float max,
int height, bool dB, bool outer, float dBr, int height, bool dB, bool outer, float dBr,
bool clip); 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__ #endif // define __AUDACITY_TRACKARTIST__