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:
parent
edba89d704
commit
7bba4500c4
@ -39,7 +39,6 @@ a draggable point type.
|
||||
#include <wx/log.h>
|
||||
|
||||
#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.
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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?
|
||||
|
@ -12,7 +12,9 @@ Paul Licameli
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#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.
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user