1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-01 08:09:41 +02:00

Merge some more drawing-related code reorganization

This commit is contained in:
Paul Licameli 2015-06-02 19:19:38 -04:00
commit 6c69fe3c67
5 changed files with 37 additions and 25 deletions

View File

@ -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

View File

@ -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();

View File

@ -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

View File

@ -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__

View File

@ -58,8 +58,9 @@ class WaveClip;
WX_DECLARE_USER_EXPORTED_LIST(WaveClip, WaveClipList, AUDACITY_DLL_API);
WX_DEFINE_USER_EXPORTED_ARRAY_PTR(WaveClip*, WaveClipArray, class AUDACITY_DLL_API);
struct WaveDisplay
class WaveDisplay
{
public:
int width;
sampleCount *where;
float *min, *max, *rms;