From 7bba4500c45b373fecfe688cbed52af4471abe50 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Tue, 7 Jul 2015 00:51:14 -0400 Subject: [PATCH] Move mdBr from TrackPanel to ViewInfo, no more lookup of prefs in Envelope.cpp --- src/Envelope.cpp | 34 +++++++--------------------------- src/Envelope.h | 4 ++-- src/Project.cpp | 2 ++ src/TrackPanel.cpp | 14 ++++++++------ src/TrackPanel.h | 1 - src/ViewInfo.cpp | 8 ++++++++ src/ViewInfo.h | 3 +++ 7 files changed, 30 insertions(+), 36 deletions(-) diff --git a/src/Envelope.cpp b/src/Envelope.cpp index 3b62da9c1..d12fcb3a7 100644 --- a/src/Envelope.cpp +++ b/src/Envelope.cpp @@ -39,7 +39,6 @@ a draggable point type. #include #include "AColor.h" -#include "Prefs.h" #include "DirManager.h" #include "TrackArtist.h" @@ -175,23 +174,6 @@ static double Limit( double Lo, double Value, double Hi ) 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. 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, float zoomMin, float zoomMax) { - // TODO: Cache the gPrefs value. Reading it every time is inefficient. - double dBRange = gPrefs->Read(wxT("/GUI/EnvdBRange"), ENV_DB_RANGE); + double dBRange = zoomInfo.dBr; dc.SetPen(AColor::envelopePen); dc.SetBrush(*wxWHITE_BRUSH); @@ -330,13 +311,13 @@ inline int SQR(int x) { return x * x; } /// @dB - display mode either linear or log. /// @zoomMin - 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) { double dBRange = 0; if (dB) - // TODO: Cache the gPrefs value. Reading it every time is inefficient. - dBRange = gPrefs->Read(wxT("/GUI/EnvdBRange"), ENV_DB_RANGE); + dBRange = zoomInfo.dBr; 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 bestDistSqr = 100; // Must be within 10 pixel radius. - // TODO: Cache the gPrefs value. Reading it every time is inefficient. - double dBr = gPrefs->Read(wxT("/GUI/EnvdBRange"), ENV_DB_RANGE); + double dBr = zoomInfo.dBr; // Member variables hold state that will be needed in dragging. mButton = event.GetButton(); @@ -457,7 +437,7 @@ bool Envelope::HandleMouseButtonDown(wxMouseEvent & event, wxRect & r, mContourOffset = false; } - double newVal = ValueOfPixel(clip_y, r.height, upper, dB, + double newVal = ValueOfPixel(clip_y, r.height, upper, zoomInfo, dB, zoomMin, zoomMax); mDragPoint = Insert(when - mOffset, newVal); @@ -508,7 +488,7 @@ void Envelope::MoveDraggedPoint( wxMouseEvent & event, wxRect & r, int clip_y = event.m_y - r.y; if(clip_y < 0) clip_y = 0; 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); // We no longer tolerate multiple envelope points at the same t. diff --git a/src/Envelope.h b/src/Envelope.h index 508c5c76d..7f359438a 100644 --- a/src/Envelope.h +++ b/src/Envelope.h @@ -197,10 +197,10 @@ class Envelope : public XMLTagHandler { int bufferLen) const; private: - double toDB(double x); EnvPoint * AddPointAtEnd( double t, double val ); 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); void BinarySearchForTime( int &Lo, int &Hi, double t ) const; double GetInterpolationStartValueAtPoint( int iPoint ) const; diff --git a/src/Project.cpp b/src/Project.cpp index 3cc1e4274..4ac064861 100644 --- a/src/Project.cpp +++ b/src/Project.cpp @@ -3017,6 +3017,8 @@ bool AudacityProject::HandleXMLTag(const wxChar *tag, const wxChar **attrs) SetBandwidthSelectionFormatName(value); } // while + mViewInfo.UpdatePrefs(); + if (longVpos != 0) { // PRL: It seems this must happen after SetSnapTo mViewInfo.track = NULL; diff --git a/src/TrackPanel.cpp b/src/TrackPanel.cpp index edaa256a0..fde42b8a6 100644 --- a/src/TrackPanel.cpp +++ b/src/TrackPanel.cpp @@ -882,7 +882,6 @@ void TrackPanel::UpdatePrefs() #ifdef EXPERIMENTAL_SCROLLING_LIMITS gPrefs->Read(wxT("/GUI/ScrollBeyondZero"), &mScrollBeyondZero, false); #endif - mdBr = gPrefs->Read(wxT("/GUI/EnvdBRange"), ENV_DB_RANGE); gPrefs->Read(wxT("/GUI/AutoScroll"), &mViewInfo->bUpdateTrackIndicator, true); gPrefs->Read(wxT("/GUI/AdjustSelectionEdges"), &mAdjustSelectionEdges, @@ -904,6 +903,8 @@ void TrackPanel::UpdatePrefs() UpdateVirtualStereoOrder(); #endif + mViewInfo->UpdatePrefs(); + if (mTrackArtist) { mTrackArtist->UpdatePrefs(); } @@ -3753,7 +3754,7 @@ void TrackPanel::ForwardEventToTimeTrackEnvelope(wxMouseEvent & event) double lower = ptimetrack->GetRangeLower(), upper = ptimetrack->GetRangeUpper(); if(ptimetrack->GetDisplayLog()) { // 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; 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 height = mDrawingTrack->GetHeight(); 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 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. int yValue = GetWaveYPos( envValue, 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 int ctr = GetWaveYPos( 0.0, 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). 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, 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) int yMouse = event.m_y; diff --git a/src/TrackPanel.h b/src/TrackPanel.h index 061071d10..24c63adad 100644 --- a/src/TrackPanel.h +++ b/src/TrackPanel.h @@ -769,7 +769,6 @@ protected: bool mAdjustSelectionEdges; bool mSlideUpDownOnly; bool mCircularTrackNavigation; - float mdBr; // JH: if the user is dragging a track, at what y // coordinate should the dragging track move up or down? diff --git a/src/ViewInfo.cpp b/src/ViewInfo.cpp index f0f439a42..fabe7d8df 100644 --- a/src/ViewInfo.cpp +++ b/src/ViewInfo.cpp @@ -12,7 +12,9 @@ Paul Licameli #include +#include "Envelope.h" #include "Internat.h" +#include "Prefs.h" #include "xml/XMLWriter.h" namespace { @@ -26,12 +28,18 @@ ZoomInfo::ZoomInfo(double start, double screenDuration, double pixelsPerSecond) , screen(screenDuration) , zoom(pixelsPerSecond) { + UpdatePrefs(); } ZoomInfo::~ZoomInfo() { } +void ZoomInfo::UpdatePrefs() +{ + dBr = gPrefs->Read(wxT("/GUI/EnvdBRange"), ENV_DB_RANGE); +} + /// Converts a position (mouse X coordinate) to /// project time, in seconds. Needs the left edge of /// the track as an additional parameter. diff --git a/src/ViewInfo.h b/src/ViewInfo.h index 8775b9a28..5d1313b5c 100644 --- a/src/ViewInfo.h +++ b/src/ViewInfo.h @@ -32,6 +32,8 @@ public: ZoomInfo(double start, double duration, double pixelsPerSecond); ~ZoomInfo(); + void UpdatePrefs(); + int vpos; // vertical scroll pos double h; // h pos in secs @@ -42,6 +44,7 @@ protected: double zoom; // pixels per second public: + float dBr; // decibel scale range // do NOT use this once to convert a pixel width to a duration! // Instead, call twice to convert start and end times,