1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-09-17 16:50:26 +02:00

dB range is now in Waveforms preferences and view settings

This commit is contained in:
Paul Licameli 2015-08-15 18:14:08 -04:00
commit 33b573685f
14 changed files with 232 additions and 121 deletions

View File

@ -184,11 +184,10 @@ static void DrawPoint(wxDC & dc, const wxRect & r, int x, int y, bool top)
}
/// TODO: This should probably move to track artist.
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, double dBRange,
float zoomMin, float zoomMax)
{
double dBRange = zoomInfo.dBr;
dc.SetPen(AColor::envelopePen);
dc.SetBrush(*wxWHITE_BRUSH);
@ -312,13 +311,9 @@ inline int SQR(int x) { return x * x; }
/// @zoomMin - vertical scale, typically -1.0
/// @zoomMax - vertical scale, typically +1.0
float Envelope::ValueOfPixel( int y, int height, bool upper,
const ZoomInfo &zoomInfo, bool dB,
bool dB, double dBRange,
float zoomMin, float zoomMax)
{
double dBRange = 0;
if (dB)
dBRange = zoomInfo.dBr;
float v = ::ValueOfPixel(y, height, 0 != mContourOffset, dB, dBRange, zoomMin, zoomMax);
// MB: this is mostly equivalent to what the old code did, I'm not sure
@ -336,7 +331,8 @@ float Envelope::ValueOfPixel( int y, int height, bool upper,
/// We have an upper and lower envelope line.
/// Also we may be showing an inner envelope (at 0.5 the range).
bool Envelope::HandleMouseButtonDown(wxMouseEvent & event, wxRect & r,
const ZoomInfo &zoomInfo, bool dB,
const ZoomInfo &zoomInfo,
bool dB, double dBRange,
float zoomMin, float zoomMax)
{
int ctr = (int)(r.height * zoomMax / (zoomMax - zoomMin));
@ -349,8 +345,6 @@ bool Envelope::HandleMouseButtonDown(wxMouseEvent & event, wxRect & r,
int bestNum = -1;
int bestDistSqr = 100; // Must be within 10 pixel radius.
double dBr = zoomInfo.dBr;
// Member variables hold state that will be needed in dragging.
mButton = event.GetButton();
mIsDeleting = false;
@ -373,15 +367,15 @@ bool Envelope::HandleMouseButtonDown(wxMouseEvent & event, wxRect & r,
// Outer control points
double value = mEnv[i]->GetVal();
y[0] = GetWaveYPos(value, zoomMin, zoomMax, r.height,
dB, true, dBr, false);
dB, true, dBRange, false);
y[1] = GetWaveYPos(-value, zoomMin, zoomMax, r.height,
dB, true, dBr, false);
dB, true, dBRange, false);
// Inner control points(contour)
y[2] = GetWaveYPos(value, zoomMin, zoomMax, r.height,
dB, false, dBr, false);
dB, false, dBRange, false);
y[3] = GetWaveYPos(-value -.00000001, zoomMin, zoomMax,
r.height, dB, false, dBr, false);
r.height, dB, false, dBRange, false);
numControlPoints = 4;
@ -417,14 +411,14 @@ bool Envelope::HandleMouseButtonDown(wxMouseEvent & event, wxRect & r,
const double v = GetValue( when );
int ct = GetWaveYPos( v, zoomMin, zoomMax, r.height, dB,
false, dBr, false) ;
false, dBRange, false) ;
int cb = GetWaveYPos( -v-.000000001, zoomMin, zoomMax, r.height, dB,
false, dBr, false) ;
false, dBRange, false) ;
if( ct <= cb || !mMirror ){
int t = GetWaveYPos( v, zoomMin, zoomMax, r.height, dB,
true, dBr, false) ;
true, dBRange, false) ;
int b = GetWaveYPos( -v, zoomMin, zoomMax, r.height, dB,
true, dBr, false) ;
true, dBRange, false) ;
ct = (t + ct) / 2;
cb = (b + cb) / 2;
@ -437,7 +431,7 @@ bool Envelope::HandleMouseButtonDown(wxMouseEvent & event, wxRect & r,
mContourOffset = false;
}
double newVal = ValueOfPixel(clip_y, r.height, upper, zoomInfo, dB,
double newVal = ValueOfPixel(clip_y, r.height, upper, dB, dBRange,
zoomMin, zoomMax);
mDragPoint = Insert(when - mOffset, newVal);
@ -482,13 +476,13 @@ void Envelope::MarkDragPointForDeletion()
}
void Envelope::MoveDraggedPoint( wxMouseEvent & event, wxRect & r,
const ZoomInfo &zoomInfo, bool dB,
const ZoomInfo &zoomInfo, bool dB, double dBRange,
float zoomMin, float zoomMax)
{
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, zoomInfo, dB,
double newVal = ValueOfPixel(clip_y, r.height, mUpper, dB, dBRange,
zoomMin, zoomMax);
// We no longer tolerate multiple envelope points at the same t.
@ -517,9 +511,8 @@ void Envelope::MoveDraggedPoint( wxMouseEvent & event, wxRect & r,
}
bool Envelope::HandleDragging( wxMouseEvent & event, wxRect & r,
const ZoomInfo &zoomInfo, bool dB,
float zoomMin, float zoomMax,
float WXUNUSED(eMin), float WXUNUSED(eMax))
const ZoomInfo &zoomInfo, bool dB, double dBRange,
float zoomMin, float zoomMax)
{
mDirty = true;
@ -531,7 +524,7 @@ bool Envelope::HandleDragging( wxMouseEvent & event, wxRect & r,
// IF we're in the rect THEN we're not deleting this point (anymore).
mIsDeleting = false;
// ...we're dragging it.
MoveDraggedPoint( event, r, zoomInfo, dB, zoomMin, zoomMax);
MoveDraggedPoint( event, r, zoomInfo, dB, dBRange, zoomMin, zoomMax);
return true;
}
@ -563,14 +556,14 @@ void Envelope::Delete( int point )
// Returns true if parent needs to be redrawn
bool Envelope::MouseEvent(wxMouseEvent & event, wxRect & r,
const ZoomInfo &zoomInfo, bool dB,
const ZoomInfo &zoomInfo, bool dB, double dBRange,
float zoomMin, float zoomMax)
{
if (event.ButtonDown() && mButton == wxMOUSE_BTN_NONE)
return HandleMouseButtonDown( event, r, zoomInfo,dB,
return HandleMouseButtonDown( event, r, zoomInfo, dB, dBRange,
zoomMin, zoomMax);
if (event.Dragging() && mDragPoint >= 0)
return HandleDragging( event, r, zoomInfo,dB,
return HandleDragging( event, r, zoomInfo, dB, dBRange,
zoomMin, zoomMax);
if (event.ButtonUp() && event.GetButton() == mButton)
return HandleMouseButtonUp();

View File

@ -116,24 +116,22 @@ class Envelope : public XMLTagHandler {
virtual XMLTagHandler *HandleXMLChild(const wxChar *tag);
virtual void WriteXML(XMLWriter &xmlFile);
void DrawPoints(wxDC & dc, const wxRect & r, const ZoomInfo &zoomInfo, bool dB,
float zoomMin=-1.0, float zoomMax=1.0);
void DrawPoints(wxDC & dc, const wxRect & r, const ZoomInfo &zoomInfo,
bool dB, double dBRange,
float zoomMin, float zoomMax);
// Event Handlers
// Each ofthese returns true if parents needs to be redrawn
bool MouseEvent(wxMouseEvent & event, wxRect & r,
const ZoomInfo &zoomInfo, bool dB,
float zoomMin=-1.0, float zoomMax=1.0);
const ZoomInfo &zoomInfo, bool dB, double dBRange,
float zoomMin, float zoomMax);
bool HandleMouseButtonDown( wxMouseEvent & event, wxRect & r,
const ZoomInfo &zoomInfo, bool dB,
float zoomMin=-1.0, float zoomMax=1.0);
const ZoomInfo &zoomInfo, bool dB, double dBRange,
float zoomMin, float zoomMax);
bool HandleDragging( wxMouseEvent & event, wxRect & r,
const ZoomInfo &zoomInfo, bool dB,
float zoomMin=-1.0, float zoomMax=1.0, float eMin=0., float eMax=2.);
const ZoomInfo &zoomInfo, bool dB, double dBRange,
float zoomMin, float zoomMax);
bool HandleMouseButtonUp();
void GetEventParams( int &height, bool &upper, bool dB,
wxMouseEvent & event, wxRect & r,
float &zoomMin, float &zoomMax);
// Handling Cut/Copy/Paste events
void CollapseRegion(double t0, double t1);
@ -198,12 +196,12 @@ private:
EnvPoint * AddPointAtEnd( double t, double val );
void MarkDragPointForDeletion();
float ValueOfPixel( int y, int height, bool upper,
const ZoomInfo &zoomInfo, bool dB,
bool dB, double dBRange,
float zoomMin, float zoomMax);
void BinarySearchForTime( int &Lo, int &Hi, double t ) const;
double GetInterpolationStartValueAtPoint( int iPoint ) const;
void MoveDraggedPoint( wxMouseEvent & event, wxRect & r,
const ZoomInfo &zoomInfo, bool dB,
const ZoomInfo &zoomInfo, bool dB, double dBRange,
float zoomMin, float zoomMax);
// Possibly inline functions:

View File

@ -684,6 +684,8 @@ void TrackArtist::UpdateVRuler(Track *t, wxRect & rect)
// The ruler needs a bevelled surround.
if (t->GetKind() == Track::Wave) {
WaveTrack *wt = static_cast<WaveTrack*>(t);
const float dBRange =
static_cast<WaveTrack*>(wt)->GetWaveformSettings().dBRange;
const int display = wt->GetDisplay();
@ -702,7 +704,7 @@ void TrackArtist::UpdateVRuler(Track *t, wxRect & rect)
wt->SetLastScaleType(scaleType);
float sign = (min >= 0 ? 1 : -1);
if (min != 0.) {
min = DB_TO_LINEAR(fabs(min)*mdBrange - mdBrange);
min = DB_TO_LINEAR(fabs(min) * dBRange - dBRange);
if (min < 0.0)
min = 0.0;
min *= sign;
@ -710,7 +712,7 @@ void TrackArtist::UpdateVRuler(Track *t, wxRect & rect)
sign = (max >= 0 ? 1 : -1);
if (max != 0.) {
max = DB_TO_LINEAR(fabs(max)*mdBrange - mdBrange);
max = DB_TO_LINEAR(fabs(max) * dBRange - dBRange);
if (max < 0.0)
max = 0.0;
max *= sign;
@ -741,7 +743,7 @@ void TrackArtist::UpdateVRuler(Track *t, wxRect & rect)
wt->SetLastScaleType(scaleType);
float sign = (min >= 0 ? 1 : -1);
if (min != 0.) {
min = (LINEAR_TO_DB(fabs(min)) + mdBrange) / mdBrange;
min = (LINEAR_TO_DB(fabs(min)) + dBRange) / dBRange;
if (min < 0.0)
min = 0.0;
min *= sign;
@ -749,7 +751,7 @@ void TrackArtist::UpdateVRuler(Track *t, wxRect & rect)
sign = (max >= 0 ? 1 : -1);
if (max != 0.) {
max = (LINEAR_TO_DB(fabs(max)) + mdBrange) / mdBrange;
max = (LINEAR_TO_DB(fabs(max)) + dBRange) / dBRange;
if (max < 0.0)
max = 0.0;
max *= sign;
@ -761,7 +763,7 @@ void TrackArtist::UpdateVRuler(Track *t, wxRect & rect)
int top = 0;
float topval = 0;
int bot = rect.height;
float botval = -mdBrange;
float botval = -dBRange;
if (min < 0) {
bot = top + (int)((max / (max - min))*(bot - top));
@ -774,10 +776,10 @@ void TrackArtist::UpdateVRuler(Track *t, wxRect & rect)
}
if (max < 1 && max > 0)
topval = -((1 - max)*mdBrange);
topval = -((1 - max) * dBRange);
if (min > 0) {
botval = -((1 - min)*mdBrange);
botval = -((1 - min) * dBRange);
}
vruler->SetBounds(rect.x, rect.y + top + 1, rect.x + rect.width, rect.y + bot - 1);
@ -987,7 +989,8 @@ void TrackArtist::DrawNegativeOffsetTrackArrows(wxDC &dc, const wxRect &rect)
void TrackArtist::DrawWaveformBackground(wxDC &dc, int leftOffset, const wxRect &rect,
const double env[],
float zoomMin, float zoomMax, bool dB,
float zoomMin, float zoomMax,
bool dB, float dBRange,
double t0, double t1,
const ZoomInfo &zoomInfo,
bool drawEnvelope, bool bIsSyncLockSelected)
@ -1024,14 +1027,14 @@ void TrackArtist::DrawWaveformBackground(wxDC &dc, int leftOffset, const wxRect
// envelope.
maxtop = GetWaveYPos(env[xx], zoomMin, zoomMax,
h, dB, true, mdBrange, true);
h, dB, true, dBRange, true);
maxbot = GetWaveYPos(env[xx], zoomMin, zoomMax,
h, dB, false, mdBrange, true);
h, dB, false, dBRange, true);
mintop = GetWaveYPos(-env[xx], zoomMin, zoomMax,
h, dB, false, mdBrange, true);
h, dB, false, dBRange, true);
minbot = GetWaveYPos(-env[xx], zoomMin, zoomMax,
h, dB, true, mdBrange, true);
h, dB, true, dBRange, true);
// Make sure it's odd so that a that max and min mirror each other
mintop +=1;
@ -1103,7 +1106,8 @@ void TrackArtist::DrawWaveformBackground(wxDC &dc, int leftOffset, const wxRect
void TrackArtist::DrawMinMaxRMS(wxDC &dc, const wxRect & rect, const double env[],
float zoomMin, float zoomMax, bool dB,
float zoomMin, float zoomMax,
bool dB, float dBRange,
const float *min, const float *max, const float *rms, const int *bl,
bool /* showProgress */, bool muted
#ifdef EXPERIMENTAL_OUTPUT_DISPLAY
@ -1149,7 +1153,7 @@ void TrackArtist::DrawMinMaxRMS(wxDC &dc, const wxRect & rect, const double env[
}
}
h1 = GetWaveYPos(v, zoomMin, zoomMax,
rect.height, dB, true, mdBrange, true);
rect.height, dB, true, dBRange, true);
#ifdef EXPERIMENTAL_OUTPUT_DISPLAY
v = max[x0] * env[x0] * gain;
@ -1163,7 +1167,7 @@ void TrackArtist::DrawMinMaxRMS(wxDC &dc, const wxRect & rect, const double env[
}
}
h2 = GetWaveYPos(v, zoomMin, zoomMax,
rect.height, dB, true, mdBrange, true);
rect.height, dB, true, dBRange, true);
// JKC: This adjustment to h1 and h2 ensures that the drawn
// waveform is continuous.
@ -1180,14 +1184,14 @@ void TrackArtist::DrawMinMaxRMS(wxDC &dc, const wxRect & rect, const double env[
#ifdef EXPERIMENTAL_OUTPUT_DISPLAY
r1[x0] = GetWaveYPos(-rms[x0] * env[x0]*gain, zoomMin, zoomMax,
rect.height, dB, true, mdBrange, true);
rect.height, dB, true, dBRange, true);
r2[x0] = GetWaveYPos(rms[xx0 * env[x0]*gain, zoomMin, zoomMax,
rect.height, dB, true, mdBrange, true);
rect.height, dB, true, dBRange, true);
#else
r1[x0] = GetWaveYPos(-rms[x0] * env[x0], zoomMin, zoomMax,
rect.height, dB, true, mdBrange, true);
rect.height, dB, true, dBRange, true);
r2[x0] = GetWaveYPos(rms[x0] * env[x0], zoomMin, zoomMax,
rect.height, dB, true, mdBrange, true);
rect.height, dB, true, dBRange, true);
#endif
// Make sure the rms isn't larger than the waveform min/max
if (r1[x0] > h1 - 1) {
@ -1264,7 +1268,8 @@ void TrackArtist::DrawMinMaxRMS(wxDC &dc, const wxRect & rect, const double env[
}
void TrackArtist::DrawIndividualSamples(wxDC &dc, int leftOffset, const wxRect &rect,
float zoomMin, float zoomMax, bool dB,
float zoomMin, float zoomMax,
bool dB, float dBRange,
WaveClip *clip,
const ZoomInfo &zoomInfo,
bool bigPoints, bool showPoints, bool muted)
@ -1312,7 +1317,7 @@ void TrackArtist::DrawIndividualSamples(wxDC &dc, int leftOffset, const wxRect &
std::max(-1,
std::min(rect.height,
GetWaveYPos(tt, zoomMin, zoomMax,
rect.height, dB, true, mdBrange, false)));
rect.height, dB, true, dBRange, false)));
}
// Draw lines
@ -1359,7 +1364,8 @@ void TrackArtist::DrawIndividualSamples(wxDC &dc, int leftOffset, const wxRect &
}
void TrackArtist::DrawEnvelope(wxDC &dc, const wxRect &rect, const double env[],
float zoomMin, float zoomMax, bool dB)
float zoomMin, float zoomMax,
bool dB, float dBRange)
{
int h = rect.height;
@ -1367,16 +1373,16 @@ void TrackArtist::DrawEnvelope(wxDC &dc, const wxRect &rect, const double env[],
for (int x0 = 0; x0 < rect.width; ++x0) {
int cenvTop = GetWaveYPos(env[x0], zoomMin, zoomMax,
h, dB, true, mdBrange, true);
h, dB, true, dBRange, true);
int cenvBot = GetWaveYPos(-env[x0], zoomMin, zoomMax,
h, dB, true, mdBrange, true);
h, dB, true, dBRange, true);
int envTop = GetWaveYPos(env[x0], zoomMin, zoomMax,
h, dB, true, mdBrange, false);
h, dB, true, dBRange, false);
int envBot = GetWaveYPos(-env[x0], zoomMin, zoomMax,
h, dB, true, mdBrange, false);
h, dB, true, dBRange, false);
// Make the collision at zero actually look solid
if (cenvBot - cenvTop < 9) {
@ -1711,6 +1717,7 @@ void TrackArtist::DrawClipWaveform(WaveTrack *track,
double leftOffset = params.leftOffset;
const wxRect &mid = params.mid;
const float dBRange = track->GetWaveformSettings().dBRange;
dc.SetPen(*wxTRANSPARENT_PEN);
@ -1740,7 +1747,8 @@ void TrackArtist::DrawClipWaveform(WaveTrack *track,
t0 = t1 = 0.0;
DrawWaveformBackground(dc, leftOffset, mid,
env,
zoomMin, zoomMax, dB,
zoomMin, zoomMax,
dB, dBRange,
t0, t1, zoomInfo, drawEnvelope,
!track->GetSelected());
}
@ -1845,7 +1853,8 @@ void TrackArtist::DrawClipWaveform(WaveTrack *track,
double *const env2 = &vEnv2[0];
clip->GetEnvelope()->GetValues(env2, rect.width, leftOffset, zoomInfo);
DrawMinMaxRMS(dc, rect, env2,
zoomMin, zoomMax, dB,
zoomMin, zoomMax,
dB, dBRange,
useMin, useMax, useRms, useBl,
isLoadingOD, muted
#ifdef EXPERIMENTAL_OUTPUT_DISPLAY
@ -1854,17 +1863,18 @@ void TrackArtist::DrawClipWaveform(WaveTrack *track,
);
}
else
DrawIndividualSamples(dc, leftOffset, rect, zoomMin, zoomMax, dB,
clip, zoomInfo,
bigPoints, showPoints, muted);
DrawIndividualSamples(dc, leftOffset, rect, zoomMin, zoomMax,
dB, dBRange,
clip, zoomInfo,
bigPoints, showPoints, muted);
}
leftOffset += rect.width + skippedRight;
}
if (drawEnvelope) {
DrawEnvelope(dc, mid, env, zoomMin, zoomMax, dB);
clip->GetEnvelope()->DrawPoints(dc, rect, zoomInfo, dB, zoomMin, zoomMax);
DrawEnvelope(dc, mid, env, zoomMin, zoomMax, dB, dBRange);
clip->GetEnvelope()->DrawPoints(dc, rect, zoomInfo, dB, dBRange, zoomMin, zoomMax);
}
// Draw arrows on the left side if the track extends to the left of the
@ -3108,12 +3118,11 @@ void TrackArtist::DrawTimeTrack(TimeTrack *track,
double lower = track->GetRangeLower(), upper = track->GetRangeUpper();
if(track->GetDisplayLog()) {
// MB: silly way to undo the work of GetWaveYPos while still getting a logarithmic scale
double dBRange = gPrefs->Read(ENV_DB_KEY, ENV_DB_RANGE);
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;
lower = LINEAR_TO_DB(std::max(1.0e-7, lower)) / mdBrange + 1.0;
upper = LINEAR_TO_DB(std::max(1.0e-7, upper)) / mdBrange + 1.0;
}
track->GetEnvelope()->DrawPoints(dc, envRect, zoomInfo,
track->GetDisplayLog(), lower, upper);
track->GetDisplayLog(), mdBrange, lower, upper);
}
void TrackArtist::UpdatePrefs()

View File

@ -140,11 +140,13 @@ class AUDACITY_DLL_API TrackArtist {
void DrawWaveformBackground(wxDC & dc, int leftOffset, const wxRect &rect,
const double env[],
float zoomMin, float zoomMax, bool dB,
float zoomMin, float zoomMax,
bool dB, float dBRange,
double t0, double t1, const ZoomInfo &zoomInfo,
bool drawEnvelope, bool bIsSyncLockSelected);
void DrawMinMaxRMS(wxDC &dc, const wxRect & rect, const double env[],
float zoomMin, float zoomMax, bool dB,
float zoomMin, float zoomMax,
bool dB, float dBRange,
const float *min, const float *max, const float *rms, const int *bl,
bool /* showProgress */, bool muted
#ifdef EXPERIMENTAL_OUTPUT_DISPLAY
@ -152,7 +154,8 @@ class AUDACITY_DLL_API TrackArtist {
#endif
);
void DrawIndividualSamples(wxDC & dc, int leftOffset, const wxRect & rect,
float zoomMin, float zoomMax, bool dB,
float zoomMin, float zoomMax,
bool dB, float dBRange,
WaveClip *clip,
const ZoomInfo &zoomInfo,
bool bigPoints, bool showPoints, bool muted);
@ -160,7 +163,8 @@ class AUDACITY_DLL_API TrackArtist {
void DrawNegativeOffsetTrackArrows(wxDC & dc, const wxRect & rect);
void DrawEnvelope(wxDC & dc, const wxRect & rect, const double env[],
float zoomMin, float zoomMax, bool dB);
float zoomMin, float zoomMax,
bool dB, float dBRange);
void DrawEnvLine(wxDC & dc, const wxRect & rect, int x0, int y0, int cy, bool top);
// Preference values

View File

@ -3660,9 +3660,9 @@ void TrackPanel::ForwardEventToTimeTrackEnvelope(wxMouseEvent & event)
envRect.y++;
envRect.height -= 2;
double lower = ptimetrack->GetRangeLower(), upper = ptimetrack->GetRangeUpper();
if(ptimetrack->GetDisplayLog()) {
const double dBRange = mViewInfo->dBr;
if (ptimetrack->GetDisplayLog()) {
// MB: silly way to undo the work of GetWaveYPos while still getting a logarithmic scale
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;
}
@ -3670,7 +3670,7 @@ void TrackPanel::ForwardEventToTimeTrackEnvelope(wxMouseEvent & event)
pspeedenvelope->MouseEvent(
event, envRect,
*mViewInfo,
ptimetrack->GetDisplayLog(), lower, upper);
ptimetrack->GetDisplayLog(), dBRange, lower, upper);
if (needUpdate) {
RefreshTrack(mCapturedTrack);
}
@ -3694,6 +3694,7 @@ void TrackPanel::ForwardEventToWaveTrackEnvelope(wxMouseEvent & event)
if (display == WaveTrack::Waveform) {
const bool dB = !pwavetrack->GetWaveformSettings().isLinear();
const double dBRange = pwavetrack->GetWaveformSettings().dBRange;
bool needUpdate;
// AS: Then forward our mouse event to the envelope.
@ -3706,7 +3707,7 @@ void TrackPanel::ForwardEventToWaveTrackEnvelope(wxMouseEvent & event)
needUpdate = penvelope->MouseEvent(
event, envRect,
*mViewInfo,
dB, zoomMin, zoomMax);
dB, dBRange, zoomMin, zoomMax);
// If this track is linked to another track, make the identical
// change to the linked envelope:
@ -3723,7 +3724,7 @@ void TrackPanel::ForwardEventToWaveTrackEnvelope(wxMouseEvent & event)
float zoomMin, zoomMax;
pwavetrack->GetDisplayBounds(&zoomMin, &zoomMax);
updateNeeded = e2->MouseEvent(event, envRect,
*mViewInfo, dB,
*mViewInfo, dB, dBRange,
zoomMin, zoomMax);
needUpdate |= updateNeeded;
}
@ -3737,7 +3738,7 @@ void TrackPanel::ForwardEventToWaveTrackEnvelope(wxMouseEvent & event)
float zoomMin, zoomMax;
pwavetrack->GetDisplayBounds(&zoomMin, &zoomMax);
needUpdate |= e2->MouseEvent(event, envRect,
*mViewInfo, dB,
*mViewInfo, dB, dBRange,
zoomMin, zoomMax);
}
}
@ -4864,7 +4865,7 @@ bool TrackPanel::IsSampleEditingPossible( wxMouseEvent &event, Track * t )
return true;
}
float TrackPanel::FindSampleEditingLevel(wxMouseEvent &event, double t0)
float TrackPanel::FindSampleEditingLevel(wxMouseEvent &event, double dBRange, double t0)
{
// Calculate where the mouse is located vertically (between +/- 1)
float zoomMin, zoomMax;
@ -4874,7 +4875,7 @@ float TrackPanel::FindSampleEditingLevel(wxMouseEvent &event, double t0)
const int height = mDrawingTrack->GetHeight();
const bool dB = !mDrawingTrack->GetWaveformSettings().isLinear();
float newLevel =
::ValueOfPixel(y, height, false, dB, mViewInfo->dBr, zoomMin, zoomMax);
::ValueOfPixel(y, height, false, dB, dBRange, zoomMin, zoomMax);
//Take the envelope into account
Envelope *const env = mDrawingTrack->GetEnvelopeAtX(event.m_x);
@ -5004,7 +5005,8 @@ void TrackPanel::HandleSampleEditingClick( wxMouseEvent & event )
SetCapturedTrack(t, IsAdjustingSample);
//Otherwise (e.g., the alt button is not down) do normal redrawing, based on the mouse position.
const float newLevel = FindSampleEditingLevel(event, t0);
const float newLevel = FindSampleEditingLevel
(event, mDrawingTrack->GetWaveformSettings().dBRange, t0);
//Set the sample to the point of the mouse event
mDrawingTrack->Set((samplePtr)&newLevel, floatSample, mDrawingStartSample, 1);
@ -5064,7 +5066,8 @@ void TrackPanel::HandleSampleEditingDrag( wxMouseEvent & event )
//Otherwise, do normal redrawing, based on the mouse position.
// Calculate where the mouse is located vertically (between +/- 1)
const float newLevel = FindSampleEditingLevel(event, t0);
const float newLevel = FindSampleEditingLevel
(event, mDrawingTrack->GetWaveformSettings().dBRange, t0);
//Now, redraw all samples between current and last redrawn sample, inclusive
//Go from the smaller to larger sample.
@ -6997,15 +7000,17 @@ bool TrackPanel::HitTestEnvelope(Track *track, wxRect &rect, wxMouseEvent & even
float zoomMin, zoomMax;
wavetrack->GetDisplayBounds(&zoomMin, &zoomMax);
const double dBRange = wavetrack->GetWaveformSettings().dBRange;
// Get y position of envelope point.
int yValue = GetWaveYPos( envValue,
zoomMin, zoomMax,
rect.height, dB, true, mViewInfo->dBr, false) + rect.y;
rect.height, dB, true, dBRange, false) + rect.y;
// Get y position of center line
int ctr = GetWaveYPos( 0.0,
zoomMin, zoomMax,
rect.height, dB, true, mViewInfo->dBr, false) + rect.y;
rect.height, dB, true, dBRange, false) + rect.y;
// Get y distance of mouse from center line (in pixels).
int yMouse = abs(ctr - event.m_y);
@ -7047,6 +7052,7 @@ bool TrackPanel::HitTestSamples(Track *track, wxRect &rect, wxMouseEvent & event
WaveTrack *wavetrack = (WaveTrack *)track;
//Get rate in order to calculate the critical zoom threshold
double rate = wavetrack->GetRate();
const double dBRange = wavetrack->GetWaveformSettings().dBRange;
const int displayType = wavetrack->GetDisplay();
if (WaveTrack::Waveform != displayType)
@ -7074,7 +7080,7 @@ bool TrackPanel::HitTestSamples(Track *track, wxRect &rect, wxMouseEvent & event
int yValue = GetWaveYPos( oneSample * envValue,
zoomMin, zoomMax,
rect.height, dB, true, mViewInfo->dBr, false) + rect.y;
rect.height, dB, true, dBRange, false) + rect.y;
// Get y position of mouse (in pixels)
int yMouse = event.m_y;

View File

@ -423,7 +423,7 @@ protected:
// Handle sample editing using the 'draw' tool.
virtual bool IsSampleEditingPossible( wxMouseEvent & event, Track * t );
virtual void HandleSampleEditing(wxMouseEvent & event);
float FindSampleEditingLevel(wxMouseEvent &event, double t0);
float FindSampleEditingLevel(wxMouseEvent &event, double dBRange, double t0);
virtual void HandleSampleEditingClick( wxMouseEvent & event );
virtual void HandleSampleEditingDrag( wxMouseEvent & event );
virtual void HandleSampleEditingButtonUp( wxMouseEvent & event );

View File

@ -2909,7 +2909,7 @@ void EqualizationPanel::OnPaint(wxPaintEvent & WXUNUSED(event))
memDC.SetPen(*wxBLACK_PEN);
if( mEffect->mDraw->GetValue() )
{
mEffect->mEnvelope->DrawPoints(memDC, mEnvRect, ZoomInfo(0.0, 1.0, mEnvRect.width-1), false,
mEffect->mEnvelope->DrawPoints(memDC, mEnvRect, ZoomInfo(0.0, 1.0, mEnvRect.width-1), false, 0.0,
mEffect->mdBMin, mEffect->mdBMax);
}
@ -2928,7 +2928,8 @@ void EqualizationPanel::OnMouseEvent(wxMouseEvent & event)
CaptureMouse();
}
if (mEffect->mEnvelope->MouseEvent(event, mEnvRect, ZoomInfo(0.0, 1.0, mEnvRect.width), false,
if (mEffect->mEnvelope->MouseEvent(event, mEnvRect, ZoomInfo(0.0, 1.0, mEnvRect.width),
false, 0.0,
mEffect->mdBMin, mEffect->mdBMax))
{
mEffect->EnvelopeUpdated();

View File

@ -39,6 +39,35 @@ GUIPrefs::~GUIPrefs()
{
}
void GUIPrefs::GetRangeChoices(wxArrayString *pChoices, wxArrayString *pCodes)
{
if (pCodes) {
wxArrayString &codes = *pCodes;
codes.Clear();
codes.Add(wxT("36"));
codes.Add(wxT("48"));
codes.Add(wxT("60"));
codes.Add(wxT("72"));
codes.Add(wxT("84"));
codes.Add(wxT("96"));
codes.Add(wxT("120"));
codes.Add(wxT("145"));
}
if (pChoices) {
wxArrayString &choices = *pChoices;
choices.Clear();
choices.Add(_("-36 dB (shallow range for high-amplitude editing)"));
choices.Add(_("-48 dB (PCM range of 8 bit samples)"));
choices.Add(_("-60 dB (PCM range of 10 bit samples)"));
choices.Add(_("-72 dB (PCM range of 12 bit samples)"));
choices.Add(_("-84 dB (PCM range of 14 bit samples)"));
choices.Add(_("-96 dB (PCM range of 16 bit samples)"));
choices.Add(_("-120 dB (approximate limit of human hearing)"));
choices.Add(_("-145 dB (PCM range of 24 bit samples)"));
}
}
void GUIPrefs::Populate()
{
// First any pre-processing for constructing the GUI.
@ -50,23 +79,7 @@ void GUIPrefs::Populate()
mHtmlHelpChoices.Add(_("Local"));
mHtmlHelpChoices.Add(_("From Internet"));
mRangeCodes.Add(wxT("36"));
mRangeCodes.Add(wxT("48"));
mRangeCodes.Add(wxT("60"));
mRangeCodes.Add(wxT("72"));
mRangeCodes.Add(wxT("84"));
mRangeCodes.Add(wxT("96"));
mRangeCodes.Add(wxT("120"));
mRangeCodes.Add(wxT("145"));
mRangeChoices.Add(_("-36 dB (shallow range for high-amplitude editing)"));
mRangeChoices.Add(_("-48 dB (PCM range of 8 bit samples)"));
mRangeChoices.Add(_("-60 dB (PCM range of 10 bit samples)"));
mRangeChoices.Add(_("-72 dB (PCM range of 12 bit samples)"));
mRangeChoices.Add(_("-84 dB (PCM range of 14 bit samples)"));
mRangeChoices.Add(_("-96 dB (PCM range of 16 bit samples)"));
mRangeChoices.Add(_("-120 dB (approximate limit of human hearing)"));
mRangeChoices.Add(_("-145 dB (PCM range of 24 bit samples)"));
GetRangeChoices(&mRangeChoices, &mRangeCodes);
#if 0
// only for testing...
@ -101,7 +114,7 @@ void GUIPrefs::PopulateOrExchange(ShuttleGui & S)
S.StartMultiColumn(2);
{
const wxString defaultRange = wxString::Format(wxT("%d"), ENV_DB_RANGE);
S.TieChoice(_("Meter/Waveform dB &range:"),
S.TieChoice(_("Meter dB &range:"),
ENV_DB_KEY,
defaultRange,
mRangeChoices,

View File

@ -29,6 +29,8 @@ class GUIPrefs :public PrefsPanel
~GUIPrefs();
virtual bool Apply();
static void GetRangeChoices(wxArrayString *pChoices, wxArrayString *pCodes);
private:
void Populate();
void PopulateOrExchange(ShuttleGui & S);

View File

@ -376,6 +376,8 @@ void PrefsDialog::OnOK(wxCommandEvent & WXUNUSED(event))
gAudacityProjects[i]->UpdatePrefs();
}
WaveformSettings::defaults().LoadPrefs();
gPrefs->Flush();
EndModal(true);
}

View File

@ -15,6 +15,8 @@ Paul Licameli
#include "../Audacity.h"
#include "WaveformPrefs.h"
#include "GUIPrefs.h"
#include "GUISettings.h"
#include <wx/checkbox.h>
@ -38,6 +40,7 @@ WaveformPrefs::WaveformPrefs(wxWindow * parent, WaveTrack *wt)
mDefaulted = false;
}
mTempSettings.ConvertToEnumeratedDBRange();
Populate();
}
@ -50,12 +53,16 @@ enum {
ID_APPLY,
ID_SCALE,
ID_RANGE,
};
void WaveformPrefs::Populate()
{
mScaleChoices = WaveformSettings::GetScaleNames();
// Reuse the same choices and codes as for Interface prefs
GUIPrefs::GetRangeChoices(&mRangeChoices, &mRangeCodes);
//------------------------- Main section --------------------
// Now construct the GUI itself.
ShuttleGui S(this, eIsCreating);
@ -81,9 +88,16 @@ void WaveformPrefs::PopulateOrExchange(ShuttleGui & S)
{
S.StartTwoColumn();
{
S.Id(ID_SCALE).TieChoice(_("S&cale") + wxString(wxT(":")),
*(int*)&mTempSettings.scaleType,
&mScaleChoices);
mScaleChoice =
S.Id(ID_SCALE).TieChoice(_("S&cale") + wxString(wxT(":")),
*(int*)&mTempSettings.scaleType,
&mScaleChoices);
mRangeChoice =
S.Id(ID_RANGE).TieChoice(_("Waveform dB &range") + wxString(wxT(":")),
*(int*)&mTempSettings.dBRange,
&mRangeChoices);
S.SetSizeHints(mRangeChoices);
}
S.EndTwoColumn();
}
@ -104,6 +118,8 @@ void WaveformPrefs::PopulateOrExchange(ShuttleGui & S)
}
S.EndMultiColumn();
EnableDisableRange();
mPopulating = false;
}
@ -117,7 +133,9 @@ bool WaveformPrefs::Validate()
PopulateOrExchange(S);
// Delegate range checking to WaveformSettings class
mTempSettings.ConvertToActualDBRange();
const bool result = mTempSettings.Validate(false);
mTempSettings.ConvertToEnumeratedDBRange();
return result;
}
@ -131,6 +149,7 @@ bool WaveformPrefs::Apply()
ShuttleGui S(this, eIsGettingFromDialog);
PopulateOrExchange(S);
mTempSettings.ConvertToActualDBRange();
WaveformSettings::Globals::Get().SavePrefs();
if (mWt) {
@ -157,6 +176,8 @@ bool WaveformPrefs::Apply()
pSettings->SavePrefs();
}
mTempSettings.ConvertToEnumeratedDBRange();
if (mWt && isOpenPage) {
mWt->SetDisplay(WaveTrack::Waveform);
if (partner)
@ -179,10 +200,19 @@ void WaveformPrefs::OnControl(wxCommandEvent&)
}
}
void WaveformPrefs::OnScale(wxCommandEvent &e)
{
EnableDisableRange();
// do the common part
OnControl(e);
}
void WaveformPrefs::OnDefaults(wxCommandEvent &)
{
if (mDefaultsCheckbox->IsChecked()) {
mTempSettings = WaveformSettings::defaults();
mTempSettings.ConvertToEnumeratedDBRange();
mDefaulted = true;
ShuttleGui S(this, eIsSettingToDialog);
PopulateOrExchange(S);
@ -197,9 +227,15 @@ void WaveformPrefs::OnApply(wxCommandEvent &)
}
}
void WaveformPrefs::EnableDisableRange()
{
mRangeChoice->Enable(mScaleChoice->GetSelection() == 1);
}
BEGIN_EVENT_TABLE(WaveformPrefs, PrefsPanel)
EVT_CHOICE(ID_SCALE, WaveformPrefs::OnControl)
EVT_CHOICE(ID_SCALE, WaveformPrefs::OnScale)
EVT_CHOICE(ID_RANGE, WaveformPrefs::OnControl)
EVT_CHECKBOX(ID_DEFAULTS, WaveformPrefs::OnDefaults)
EVT_BUTTON(ID_APPLY, WaveformPrefs::OnApply)

View File

@ -18,6 +18,7 @@ Paul Licameli
class ShuttleGui;
class WaveTrack;
class wxCheckBox;
class wxChoice;
class WaveformPrefs :public PrefsPanel
{
@ -32,16 +33,23 @@ private:
void PopulateOrExchange(ShuttleGui & S);
void OnControl(wxCommandEvent&);
void OnScale(wxCommandEvent&);
void OnDefaults(wxCommandEvent&);
void OnApply(wxCommandEvent &);
DECLARE_EVENT_TABLE()
void EnableDisableRange();
WaveTrack *const mWt;
bool mDefaulted;
wxCheckBox *mDefaultsCheckbox;
wxChoice *mScaleChoice;
wxChoice *mRangeChoice;
wxArrayString mScaleChoices;
wxArrayString mRangeCodes;
wxArrayString mRangeChoices;
WaveformSettings mTempSettings;

View File

@ -15,6 +15,8 @@ Paul Licameli
#include "../Audacity.h"
#include "WaveformSettings.h"
#include "GUISettings.h"
#include "GUIPrefs.h"
#include <algorithm>
#include <wx/intl.h>
@ -48,6 +50,7 @@ WaveformSettings::WaveformSettings()
WaveformSettings::WaveformSettings(const WaveformSettings &other)
: scaleType(other.scaleType)
, dBRange(other.dBRange)
{
}
@ -55,6 +58,7 @@ WaveformSettings &WaveformSettings::operator= (const WaveformSettings &other)
{
if (this != &other) {
scaleType = other.scaleType;
dBRange = other.dBRange;
}
return *this;
}
@ -73,12 +77,18 @@ bool WaveformSettings::Validate(bool quiet)
std::max(0, std::min(int(stNumScaleTypes) - 1, int(scaleType)))
);
ConvertToEnumeratedDBRange();
ConvertToActualDBRange();
return true;
}
void WaveformSettings::LoadPrefs()
{
scaleType = ScaleType(gPrefs->Read(wxT("/Waveform/ScaleType"), 0L));
bool newPrefFound = gPrefs->Read(wxT("/Waveform/dBRange"), &dBRange);
if (!newPrefFound)
dBRange = gPrefs->Read(ENV_DB_KEY, ENV_DB_RANGE);
// Enforce legal values
Validate(true);
@ -89,12 +99,37 @@ void WaveformSettings::LoadPrefs()
void WaveformSettings::SavePrefs()
{
gPrefs->Write(wxT("/Waveform/ScaleType"), long(scaleType));
gPrefs->Write(wxT("/Waveform/dBRange"), long(dBRange));
}
void WaveformSettings::Update()
{
}
void WaveformSettings::ConvertToEnumeratedDBRange()
{
// Assumes the codes are in ascending sequence.
wxArrayString codes;
GUIPrefs::GetRangeChoices(NULL, &codes);
int ii = 0;
for (int nn = codes.size(); ii < nn; ++ii) {
long value = 0;
codes[ii].ToLong(&value);
if (dBRange < value)
break;
}
dBRange = std::max(0, ii - 1);
}
void WaveformSettings::ConvertToActualDBRange()
{
wxArrayString codes;
GUIPrefs::GetRangeChoices(NULL, &codes);
long value = 0;
codes[dBRange].ToLong(&value);
dBRange = int(value);
}
namespace
{
wxArrayString &scaleNamesArray()

View File

@ -45,6 +45,9 @@ public:
void SavePrefs();
void Update();
void ConvertToEnumeratedDBRange();
void ConvertToActualDBRange();
enum ScaleType {
stLinear,
stLogarithmic,
@ -56,6 +59,7 @@ public:
static const wxArrayString &GetScaleNames();
ScaleType scaleType;
int dBRange;
// Convenience
bool isLinear() const { return stLinear == scaleType; }