1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-23 16:08:07 +02:00

Move mdBr from TrackPanel to ViewInfo, no more lookup of prefs in Envelope.cpp

This commit is contained in:
Paul Licameli 2015-07-07 00:51:14 -04:00
parent edba89d704
commit 7bba4500c4
7 changed files with 30 additions and 36 deletions

View File

@ -39,7 +39,6 @@ a draggable point type.
#include <wx/log.h> #include <wx/log.h>
#include "AColor.h" #include "AColor.h"
#include "Prefs.h"
#include "DirManager.h" #include "DirManager.h"
#include "TrackArtist.h" #include "TrackArtist.h"
@ -175,23 +174,6 @@ static double Limit( double Lo, double Value, double Hi )
return Value; return Value;
} }
double Envelope::toDB(double value)
{
if (value == 0)
return 0;
// TODO: Cache the gPrefs value. Reading it every time is inefficient.
double dBRange = gPrefs->Read(wxT("/GUI/EnvdBRange"), ENV_DB_RANGE);
double sign = (value >= 0 ? 1 : -1);
wxASSERT( dBRange > 0 );
double db = LINEAR_TO_DB(fabs(value));
double val = (db + dBRange) / dBRange;
val = Limit( 0.0, val, 1.0 );
return sign * val;
}
/// 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)
{ {
@ -205,8 +187,7 @@ static void DrawPoint(wxDC & dc, const wxRect & r, int x, int y, bool top)
void Envelope::DrawPoints(wxDC & dc, const wxRect & r, const ZoomInfo &zoomInfo, bool dB, void Envelope::DrawPoints(wxDC & dc, const wxRect & r, const ZoomInfo &zoomInfo, bool dB,
float zoomMin, float zoomMax) float zoomMin, float zoomMax)
{ {
// TODO: Cache the gPrefs value. Reading it every time is inefficient. double dBRange = zoomInfo.dBr;
double dBRange = gPrefs->Read(wxT("/GUI/EnvdBRange"), ENV_DB_RANGE);
dc.SetPen(AColor::envelopePen); dc.SetPen(AColor::envelopePen);
dc.SetBrush(*wxWHITE_BRUSH); dc.SetBrush(*wxWHITE_BRUSH);
@ -330,13 +311,13 @@ inline int SQR(int x) { return x * x; }
/// @dB - display mode either linear or log. /// @dB - display mode either linear or log.
/// @zoomMin - vertical scale, typically -1.0 /// @zoomMin - vertical scale, typically -1.0
/// @zoomMax - vertical scale, typically +1.0 /// @zoomMax - vertical scale, typically +1.0
float Envelope::ValueOfPixel( int y, int height, bool upper, bool dB, float Envelope::ValueOfPixel( int y, int height, bool upper,
const ZoomInfo &zoomInfo, bool dB,
float zoomMin, float zoomMax) float zoomMin, float zoomMax)
{ {
double dBRange = 0; double dBRange = 0;
if (dB) if (dB)
// TODO: Cache the gPrefs value. Reading it every time is inefficient. dBRange = zoomInfo.dBr;
dBRange = gPrefs->Read(wxT("/GUI/EnvdBRange"), ENV_DB_RANGE);
float v = ::ValueOfPixel(y, height, 0 != mContourOffset, dB, dBRange, zoomMin, zoomMax); float v = ::ValueOfPixel(y, height, 0 != mContourOffset, dB, dBRange, zoomMin, zoomMax);
@ -368,8 +349,7 @@ bool Envelope::HandleMouseButtonDown(wxMouseEvent & event, wxRect & r,
int bestNum = -1; int bestNum = -1;
int bestDistSqr = 100; // Must be within 10 pixel radius. int bestDistSqr = 100; // Must be within 10 pixel radius.
// TODO: Cache the gPrefs value. Reading it every time is inefficient. double dBr = zoomInfo.dBr;
double dBr = gPrefs->Read(wxT("/GUI/EnvdBRange"), ENV_DB_RANGE);
// Member variables hold state that will be needed in dragging. // Member variables hold state that will be needed in dragging.
mButton = event.GetButton(); mButton = event.GetButton();
@ -457,7 +437,7 @@ bool Envelope::HandleMouseButtonDown(wxMouseEvent & event, wxRect & r,
mContourOffset = false; mContourOffset = false;
} }
double newVal = ValueOfPixel(clip_y, r.height, upper, dB, double newVal = ValueOfPixel(clip_y, r.height, upper, zoomInfo, dB,
zoomMin, zoomMax); zoomMin, zoomMax);
mDragPoint = Insert(when - mOffset, newVal); mDragPoint = Insert(when - mOffset, newVal);
@ -508,7 +488,7 @@ void Envelope::MoveDraggedPoint( wxMouseEvent & event, wxRect & r,
int clip_y = event.m_y - r.y; int clip_y = event.m_y - r.y;
if(clip_y < 0) clip_y = 0; if(clip_y < 0) clip_y = 0;
if(clip_y > r.height) clip_y = r.height; if(clip_y > r.height) clip_y = r.height;
double newVal = ValueOfPixel(clip_y, r.height, mUpper, dB, double newVal = ValueOfPixel(clip_y, r.height, mUpper, zoomInfo, dB,
zoomMin, zoomMax); zoomMin, zoomMax);
// We no longer tolerate multiple envelope points at the same t. // We no longer tolerate multiple envelope points at the same t.

View File

@ -197,10 +197,10 @@ class Envelope : public XMLTagHandler {
int bufferLen) const; int bufferLen) const;
private: private:
double toDB(double x);
EnvPoint * AddPointAtEnd( double t, double val ); EnvPoint * AddPointAtEnd( double t, double val );
void MarkDragPointForDeletion(); void MarkDragPointForDeletion();
float ValueOfPixel( int y, int height, bool upper, bool dB, float ValueOfPixel( int y, int height, bool upper,
const ZoomInfo &zoomInfo, bool dB,
float zoomMin, float zoomMax); float zoomMin, float zoomMax);
void BinarySearchForTime( int &Lo, int &Hi, double t ) const; void BinarySearchForTime( int &Lo, int &Hi, double t ) const;
double GetInterpolationStartValueAtPoint( int iPoint ) const; double GetInterpolationStartValueAtPoint( int iPoint ) const;

View File

@ -3017,6 +3017,8 @@ bool AudacityProject::HandleXMLTag(const wxChar *tag, const wxChar **attrs)
SetBandwidthSelectionFormatName(value); SetBandwidthSelectionFormatName(value);
} // while } // while
mViewInfo.UpdatePrefs();
if (longVpos != 0) { if (longVpos != 0) {
// PRL: It seems this must happen after SetSnapTo // PRL: It seems this must happen after SetSnapTo
mViewInfo.track = NULL; mViewInfo.track = NULL;

View File

@ -882,7 +882,6 @@ void TrackPanel::UpdatePrefs()
#ifdef EXPERIMENTAL_SCROLLING_LIMITS #ifdef EXPERIMENTAL_SCROLLING_LIMITS
gPrefs->Read(wxT("/GUI/ScrollBeyondZero"), &mScrollBeyondZero, false); gPrefs->Read(wxT("/GUI/ScrollBeyondZero"), &mScrollBeyondZero, false);
#endif #endif
mdBr = gPrefs->Read(wxT("/GUI/EnvdBRange"), ENV_DB_RANGE);
gPrefs->Read(wxT("/GUI/AutoScroll"), &mViewInfo->bUpdateTrackIndicator, gPrefs->Read(wxT("/GUI/AutoScroll"), &mViewInfo->bUpdateTrackIndicator,
true); true);
gPrefs->Read(wxT("/GUI/AdjustSelectionEdges"), &mAdjustSelectionEdges, gPrefs->Read(wxT("/GUI/AdjustSelectionEdges"), &mAdjustSelectionEdges,
@ -904,6 +903,8 @@ void TrackPanel::UpdatePrefs()
UpdateVirtualStereoOrder(); UpdateVirtualStereoOrder();
#endif #endif
mViewInfo->UpdatePrefs();
if (mTrackArtist) { if (mTrackArtist) {
mTrackArtist->UpdatePrefs(); mTrackArtist->UpdatePrefs();
} }
@ -3753,7 +3754,7 @@ void TrackPanel::ForwardEventToTimeTrackEnvelope(wxMouseEvent & event)
double lower = ptimetrack->GetRangeLower(), upper = ptimetrack->GetRangeUpper(); double lower = ptimetrack->GetRangeLower(), upper = ptimetrack->GetRangeUpper();
if(ptimetrack->GetDisplayLog()) { if(ptimetrack->GetDisplayLog()) {
// MB: silly way to undo the work of GetWaveYPos while still getting a logarithmic scale // MB: silly way to undo the work of GetWaveYPos while still getting a logarithmic scale
double dBRange = gPrefs->Read(wxT("/GUI/EnvdBRange"), ENV_DB_RANGE); double dBRange = mViewInfo->dBr;
lower = LINEAR_TO_DB(std::max(1.0e-7, lower)) / dBRange + 1.0; lower = LINEAR_TO_DB(std::max(1.0e-7, lower)) / dBRange + 1.0;
upper = LINEAR_TO_DB(std::max(1.0e-7, upper)) / dBRange + 1.0; upper = LINEAR_TO_DB(std::max(1.0e-7, upper)) / dBRange + 1.0;
} }
@ -4911,7 +4912,8 @@ float TrackPanel::FindSampleEditingLevel(wxMouseEvent &event, double t0)
const int y = event.m_y - mDrawingTrackTop; const int y = event.m_y - mDrawingTrackTop;
const int height = mDrawingTrack->GetHeight(); const int height = mDrawingTrack->GetHeight();
const bool dB = !mDrawingTrack->GetWaveformSettings().isLinear(); const bool dB = !mDrawingTrack->GetWaveformSettings().isLinear();
float newLevel = ::ValueOfPixel(y, height, false, dB, mdBr, zoomMin, zoomMax); float newLevel =
::ValueOfPixel(y, height, false, dB, mViewInfo->dBr, zoomMin, zoomMax);
//Take the envelope into account //Take the envelope into account
Envelope *const env = mDrawingTrack->GetEnvelopeAtX(event.m_x); Envelope *const env = mDrawingTrack->GetEnvelopeAtX(event.m_x);
@ -6928,12 +6930,12 @@ bool TrackPanel::HitTestEnvelope(Track *track, wxRect &r, wxMouseEvent & event)
// Get y position of envelope point. // Get y position of envelope point.
int yValue = GetWaveYPos( envValue, int yValue = GetWaveYPos( envValue,
zoomMin, zoomMax, zoomMin, zoomMax,
r.height, dB, true, mdBr, false ) + r.y; r.height, dB, true, mViewInfo->dBr, false) + r.y;
// Get y position of center line // Get y position of center line
int ctr = GetWaveYPos( 0.0, int ctr = GetWaveYPos( 0.0,
zoomMin, zoomMax, zoomMin, zoomMax,
r.height, dB, true, mdBr, false ) + r.y; r.height, dB, true, mViewInfo->dBr, false) + r.y;
// Get y distance of mouse from center line (in pixels). // Get y distance of mouse from center line (in pixels).
int yMouse = abs(ctr - event.m_y); int yMouse = abs(ctr - event.m_y);
@ -7002,7 +7004,7 @@ bool TrackPanel::HitTestSamples(Track *track, wxRect &r, wxMouseEvent & event)
int yValue = GetWaveYPos( oneSample * envValue, int yValue = GetWaveYPos( oneSample * envValue,
zoomMin, zoomMax, zoomMin, zoomMax,
r.height, dB, true, mdBr, false) + r.y; r.height, dB, true, mViewInfo->dBr, false) + r.y;
// Get y position of mouse (in pixels) // Get y position of mouse (in pixels)
int yMouse = event.m_y; int yMouse = event.m_y;

View File

@ -769,7 +769,6 @@ protected:
bool mAdjustSelectionEdges; bool mAdjustSelectionEdges;
bool mSlideUpDownOnly; bool mSlideUpDownOnly;
bool mCircularTrackNavigation; bool mCircularTrackNavigation;
float mdBr;
// JH: if the user is dragging a track, at what y // JH: if the user is dragging a track, at what y
// coordinate should the dragging track move up or down? // coordinate should the dragging track move up or down?

View File

@ -12,7 +12,9 @@ Paul Licameli
#include <algorithm> #include <algorithm>
#include "Envelope.h"
#include "Internat.h" #include "Internat.h"
#include "Prefs.h"
#include "xml/XMLWriter.h" #include "xml/XMLWriter.h"
namespace { namespace {
@ -26,12 +28,18 @@ ZoomInfo::ZoomInfo(double start, double screenDuration, double pixelsPerSecond)
, screen(screenDuration) , screen(screenDuration)
, zoom(pixelsPerSecond) , zoom(pixelsPerSecond)
{ {
UpdatePrefs();
} }
ZoomInfo::~ZoomInfo() ZoomInfo::~ZoomInfo()
{ {
} }
void ZoomInfo::UpdatePrefs()
{
dBr = gPrefs->Read(wxT("/GUI/EnvdBRange"), ENV_DB_RANGE);
}
/// Converts a position (mouse X coordinate) to /// Converts a position (mouse X coordinate) to
/// project time, in seconds. Needs the left edge of /// project time, in seconds. Needs the left edge of
/// the track as an additional parameter. /// the track as an additional parameter.

View File

@ -32,6 +32,8 @@ public:
ZoomInfo(double start, double duration, double pixelsPerSecond); ZoomInfo(double start, double duration, double pixelsPerSecond);
~ZoomInfo(); ~ZoomInfo();
void UpdatePrefs();
int vpos; // vertical scroll pos int vpos; // vertical scroll pos
double h; // h pos in secs double h; // h pos in secs
@ -42,6 +44,7 @@ protected:
double zoom; // pixels per second double zoom; // pixels per second
public: public:
float dBr; // decibel scale range
// do NOT use this once to convert a pixel width to a duration! // do NOT use this once to convert a pixel width to a duration!
// Instead, call twice to convert start and end times, // Instead, call twice to convert start and end times,