1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-16 16:10:06 +02:00

Bug1156, fix inconsistencies in mapping pixel heights to track vertical scales

This commit is contained in:
Paul Licameli 2015-08-21 11:04:30 -04:00
parent 49ff3ae78f
commit bc5aed7465
3 changed files with 38 additions and 35 deletions

View File

@ -241,10 +241,14 @@ public:
case nstErb: case nstErb:
case nstUndertone: case nstUndertone:
return Iterator return Iterator
(mType, (mValue1 - mValue0) / nPositions, mValue0, mUnit); (mType,
nPositions == 1 ? 0 : (mValue1 - mValue0) / (nPositions - 1),
mValue0, mUnit);
case nstLogarithmic: case nstLogarithmic:
return Iterator return Iterator
(mType, exp((mValue1 - mValue0) / nPositions), exp(mValue0), mUnit); (mType,
nPositions == 1 ? 1 : exp((mValue1 - mValue0) / (nPositions - 1)),
exp(mValue0), mUnit);
} }
} }

View File

@ -571,8 +571,8 @@ void TrackArtist::DrawVRuler(Track *t, wxDC * dc, wxRect & rect)
bev.height--; bev.height--;
dc->DrawRectangle(bev); dc->DrawRectangle(bev);
rect.y += 2; rect.y += 1;
rect.height -= 2; rect.height -= 1;
//int bottom = GetBottom((NoteTrack *) t, rect); //int bottom = GetBottom((NoteTrack *) t, rect);
NoteTrack *track = (NoteTrack *) t; NoteTrack *track = (NoteTrack *) t;
@ -671,7 +671,7 @@ void TrackArtist::UpdateVRuler(Track *t, wxRect & rect)
min = tt->GetRangeLower() * 100.0; min = tt->GetRangeLower() * 100.0;
max = tt->GetRangeUpper() * 100.0; max = tt->GetRangeUpper() * 100.0;
vruler->SetBounds(rect.x, rect.y+1, rect.x + rect.width, rect.y + rect.height-1); vruler->SetBounds(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height-1);
vruler->SetOrientation(wxVERTICAL); vruler->SetOrientation(wxVERTICAL);
vruler->SetRange(max, min); vruler->SetRange(max, min);
vruler->SetFormat((tt->GetDisplayLog()) ? Ruler::RealLogFormat : Ruler::RealFormat); vruler->SetFormat((tt->GetDisplayLog()) ? Ruler::RealLogFormat : Ruler::RealFormat);
@ -720,7 +720,7 @@ void TrackArtist::UpdateVRuler(Track *t, wxRect & rect)
wt->SetDisplayBounds(min, max); wt->SetDisplayBounds(min, max);
} }
vruler->SetBounds(rect.x, rect.y + 1, rect.x + rect.width, rect.y + rect.height - 1); vruler->SetBounds(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height - 1);
vruler->SetOrientation(wxVERTICAL); vruler->SetOrientation(wxVERTICAL);
vruler->SetRange(max, min); vruler->SetRange(max, min);
vruler->SetFormat(Ruler::RealFormat); vruler->SetFormat(Ruler::RealFormat);
@ -782,7 +782,7 @@ void TrackArtist::UpdateVRuler(Track *t, wxRect & rect)
botval = -((1 - min) * dBRange); botval = -((1 - min) * dBRange);
} }
vruler->SetBounds(rect.x, rect.y + top + 1, rect.x + rect.width, rect.y + bot - 1); vruler->SetBounds(rect.x, rect.y + top, rect.x + rect.width, rect.y + bot - 1);
vruler->SetOrientation(wxVERTICAL); vruler->SetOrientation(wxVERTICAL);
vruler->SetRange(topval, botval); vruler->SetRange(topval, botval);
} }
@ -815,7 +815,7 @@ void TrackArtist::UpdateVRuler(Track *t, wxRect & rect)
we will use Hz if maxFreq is < 2000, otherwise we represent kHz, we will use Hz if maxFreq is < 2000, otherwise we represent kHz,
and append to the numbers a "k" and append to the numbers a "k"
*/ */
vruler->SetBounds(rect.x, rect.y + 1, rect.x + rect.width, rect.y + rect.height - 1); vruler->SetBounds(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height - 1);
vruler->SetOrientation(wxVERTICAL); vruler->SetOrientation(wxVERTICAL);
vruler->SetFormat(Ruler::RealFormat); vruler->SetFormat(Ruler::RealFormat);
vruler->SetLabelEdges(true); vruler->SetLabelEdges(true);
@ -853,7 +853,7 @@ void TrackArtist::UpdateVRuler(Track *t, wxRect & rect)
we will use Hz if maxFreq is < 2000, otherwise we represent kHz, we will use Hz if maxFreq is < 2000, otherwise we represent kHz,
and append to the numbers a "k" and append to the numbers a "k"
*/ */
vruler->SetBounds(rect.x, rect.y + 1, rect.x + rect.width, rect.y + rect.height - 1); vruler->SetBounds(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height - 1);
vruler->SetOrientation(wxVERTICAL); vruler->SetOrientation(wxVERTICAL);
vruler->SetFormat(Ruler::IntFormat); vruler->SetFormat(Ruler::IntFormat);
vruler->SetLabelEdges(true); vruler->SetLabelEdges(true);
@ -873,7 +873,7 @@ void TrackArtist::UpdateVRuler(Track *t, wxRect & rect)
// The note track isn't drawing a ruler at all! // The note track isn't drawing a ruler at all!
// But it needs to! // But it needs to!
else if (t->GetKind() == Track::Note) { else if (t->GetKind() == Track::Note) {
vruler->SetBounds(rect.x, rect.y+1, rect.x + 1, rect.y + rect.height-1); vruler->SetBounds(rect.x, rect.y, rect.x + 1, rect.y + rect.height-1);
vruler->SetOrientation(wxVERTICAL); vruler->SetOrientation(wxVERTICAL);
} }
#endif // USE_MIDI #endif // USE_MIDI
@ -946,7 +946,10 @@ float ValueOfPixel(int yy, int height, bool offset,
bool dB, double dBRange, float zoomMin, float zoomMax) bool dB, double dBRange, float zoomMin, float zoomMax)
{ {
wxASSERT(height > 0); wxASSERT(height > 0);
float v = zoomMax - (yy / (float)height) * (zoomMax - zoomMin); // Map 0 to max and height - 1 (not height) to min
float v =
height == 1 ? (zoomMin + zoomMax) / 2 :
zoomMax - (yy / (float)(height - 1)) * (zoomMax - zoomMin);
if (offset) { if (offset) {
if (v > 0.0) if (v > 0.0)
v += .5; v += .5;

View File

@ -2540,6 +2540,8 @@ void TrackPanel::SelectionHandleClick(wxMouseEvent & event,
{ {
Track *rightTrack = NULL; Track *rightTrack = NULL;
mCapturedTrack = pTrack; mCapturedTrack = pTrack;
rect.y += kTopMargin;
rect.height -= kTopMargin + kBottomMargin;
mCapturedRect = rect; mCapturedRect = rect;
mMouseCapture=IsSelecting; mMouseCapture=IsSelecting;
@ -3414,9 +3416,11 @@ void TrackPanel::SelectionHandleDrag(wxMouseEvent & event, Track *clickedTrack)
wxRect rect = mCapturedRect; wxRect rect = mCapturedRect;
Track *pTrack = mCapturedTrack; Track *pTrack = mCapturedTrack;
// AS: Note that FindTrack will replace rect's value. if (!pTrack) {
if (!pTrack)
pTrack = FindTrack(event.m_x, event.m_y, false, false, &rect); pTrack = FindTrack(event.m_x, event.m_y, false, false, &rect);
rect.y += kTopMargin;
rect.height -= kTopMargin + kBottomMargin;
}
// Also fuhggeddaboudit if not in a track. // Also fuhggeddaboudit if not in a track.
if (!pTrack) if (!pTrack)
@ -3705,8 +3709,8 @@ void TrackPanel::HandleEnvelope(wxMouseEvent & event)
} }
mCapturedRect = rect; mCapturedRect = rect;
mCapturedRect.y += kTopInset; mCapturedRect.y += kTopMargin;
mCapturedRect.height -= kTopInset; mCapturedRect.height -= kTopMargin + kBottomMargin;
} }
// AS: if there's actually a selected track, then forward all of the // AS: if there's actually a selected track, then forward all of the
// mouse events to its envelope. // mouse events to its envelope.
@ -3732,8 +3736,6 @@ void TrackPanel::ForwardEventToTimeTrackEnvelope(wxMouseEvent & event)
Envelope *pspeedenvelope = ptimetrack->GetEnvelope(); Envelope *pspeedenvelope = ptimetrack->GetEnvelope();
wxRect envRect = mCapturedRect; wxRect envRect = mCapturedRect;
envRect.y++;
envRect.height -= 2;
double lower = ptimetrack->GetRangeLower(), upper = ptimetrack->GetRangeUpper(); double lower = ptimetrack->GetRangeLower(), upper = ptimetrack->GetRangeUpper();
const double dBRange = mViewInfo->dBr; const double dBRange = mViewInfo->dBr;
if (ptimetrack->GetDisplayLog()) { if (ptimetrack->GetDisplayLog()) {
@ -3775,8 +3777,6 @@ void TrackPanel::ForwardEventToWaveTrackEnvelope(wxMouseEvent & event)
// AS: Then forward our mouse event to the envelope. // AS: Then forward our mouse event to the envelope.
// It'll recalculate and then tell us whether or not to redraw. // It'll recalculate and then tell us whether or not to redraw.
wxRect envRect = mCapturedRect; wxRect envRect = mCapturedRect;
envRect.y++;
envRect.height -= 2;
float zoomMin, zoomMax; float zoomMin, zoomMax;
pwavetrack->GetDisplayBounds(&zoomMin, &zoomMax); pwavetrack->GetDisplayBounds(&zoomMin, &zoomMax);
needUpdate = penvelope->MouseEvent( needUpdate = penvelope->MouseEvent(
@ -3794,8 +3794,6 @@ void TrackPanel::ForwardEventToWaveTrackEnvelope(wxMouseEvent & event)
bool updateNeeded = false; bool updateNeeded = false;
if (e2) { if (e2) {
wxRect envRect = mCapturedRect; wxRect envRect = mCapturedRect;
envRect.y++;
envRect.height -= 2;
float zoomMin, zoomMax; float zoomMin, zoomMax;
pwavetrack->GetDisplayBounds(&zoomMin, &zoomMax); pwavetrack->GetDisplayBounds(&zoomMin, &zoomMax);
updateNeeded = e2->MouseEvent(event, envRect, updateNeeded = e2->MouseEvent(event, envRect,
@ -3808,8 +3806,6 @@ void TrackPanel::ForwardEventToWaveTrackEnvelope(wxMouseEvent & event)
if( (e2 = link->GetActiveEnvelope()) != 0 ) // search for any active DragPoint if( (e2 = link->GetActiveEnvelope()) != 0 ) // search for any active DragPoint
{ {
wxRect envRect = mCapturedRect; wxRect envRect = mCapturedRect;
envRect.y++;
envRect.height -= 2;
float zoomMin, zoomMax; float zoomMin, zoomMax;
pwavetrack->GetDisplayBounds(&zoomMin, &zoomMax); pwavetrack->GetDisplayBounds(&zoomMin, &zoomMax);
needUpdate |= e2->MouseEvent(event, envRect, needUpdate |= e2->MouseEvent(event, envRect,
@ -4663,8 +4659,8 @@ void TrackPanel::HandleWaveTrackVZoom
bool fixedMousePoint) bool fixedMousePoint)
{ {
WaveTrack *const partner = static_cast<WaveTrack *>(tracks->GetLink(track)); WaveTrack *const partner = static_cast<WaveTrack *>(tracks->GetLink(track));
int height = track->GetHeight(); int height = track->GetHeight() - (kTopMargin + kBottomMargin);
int ypos = rect.y; int ypos = rect.y + kBorderThickness;
// Ensure start and end are in order (swap if not). // Ensure start and end are in order (swap if not).
if (zoomEnd < zoomStart) if (zoomEnd < zoomStart)
@ -4955,7 +4951,7 @@ float TrackPanel::FindSampleEditingLevel(wxMouseEvent &event, double dBRange, do
mDrawingTrack->GetDisplayBounds(&zoomMin, &zoomMax); mDrawingTrack->GetDisplayBounds(&zoomMin, &zoomMax);
const int y = event.m_y - mDrawingTrackTop; const int y = event.m_y - mDrawingTrackTop;
const int height = mDrawingTrack->GetHeight(); const int height = mDrawingTrack->GetHeight() - (kTopMargin + kBottomMargin);
const bool dB = !mDrawingTrack->GetWaveformSettings().isLinear(); const bool dB = !mDrawingTrack->GetWaveformSettings().isLinear();
float newLevel = float newLevel =
::ValueOfPixel(y, height, false, dB, dBRange, zoomMin, zoomMax); ::ValueOfPixel(y, height, false, dB, dBRange, zoomMin, zoomMax);
@ -4996,7 +4992,7 @@ void TrackPanel::HandleSampleEditingClick( wxMouseEvent & event )
/// \todo Should mCapturedTrack take the place of mDrawingTrack?? /// \todo Should mCapturedTrack take the place of mDrawingTrack??
mDrawingTrack = static_cast<WaveTrack*>(t); mDrawingTrack = static_cast<WaveTrack*>(t);
mDrawingTrackTop=rect.y; mDrawingTrackTop=rect.y + kTopMargin;
//If we are still around, we are drawing in earnest. Set some member data structures up: //If we are still around, we are drawing in earnest. Set some member data structures up:
//First, calculate the starting sample. To get this, we need the time //First, calculate the starting sample. To get this, we need the time
@ -7395,9 +7391,9 @@ void TrackPanel::DrawEverythingElse(wxDC * dc,
if (region.Contains(0, trackRect.y, GetLeftOffset(), trackRect.height)) { if (region.Contains(0, trackRect.y, GetLeftOffset(), trackRect.height)) {
wxRect rect = trackRect; wxRect rect = trackRect;
rect.x += GetVRulerOffset(); rect.x += GetVRulerOffset();
rect.y += kTopInset; rect.y += kTopMargin;
rect.width = GetVRulerWidth(); rect.width = GetVRulerWidth();
rect.height -= (kTopInset + 2); rect.height -= (kTopMargin + kBottomMargin);
mTrackArtist->DrawVRuler(t, dc, rect); mTrackArtist->DrawVRuler(t, dc, rect);
} }
@ -7408,9 +7404,9 @@ void TrackPanel::DrawEverythingElse(wxDC * dc,
if (region.Contains(0, trackRect.y, GetLeftOffset(), trackRect.height)) { if (region.Contains(0, trackRect.y, GetLeftOffset(), trackRect.height)) {
wxRect rect = trackRect; wxRect rect = trackRect;
rect.x += GetVRulerOffset(); rect.x += GetVRulerOffset();
rect.y += kTopInset; rect.y += kTopMargin;
rect.width = GetVRulerWidth(); rect.width = GetVRulerWidth();
rect.height -= (kTopInset + 2); rect.height -= (kTopMargin + kBottomMargin);
mTrackArtist->DrawVRuler(t, dc, rect); mTrackArtist->DrawVRuler(t, dc, rect);
} }
} }
@ -7953,20 +7949,20 @@ void TrackPanel::UpdateTrackVRuler(Track *t)
return; return;
wxRect rect(GetVRulerOffset(), wxRect rect(GetVRulerOffset(),
kTopInset, kTopMargin,
GetVRulerWidth(), GetVRulerWidth(),
t->GetHeight() - (kTopInset + 2)); t->GetHeight() - (kTopMargin + kBottomMargin));
mTrackArtist->UpdateVRuler(t, rect); mTrackArtist->UpdateVRuler(t, rect);
Track *l = t->GetLink(); Track *l = t->GetLink();
if (l) if (l)
{ {
rect.height = l->GetHeight() - (kTopInset + 2); rect.height = l->GetHeight() - (kTopMargin + kBottomMargin);
mTrackArtist->UpdateVRuler(l, rect); mTrackArtist->UpdateVRuler(l, rect);
} }
#ifdef EXPERIMENTAL_OUTPUT_DISPLAY #ifdef EXPERIMENTAL_OUTPUT_DISPLAY
else if(MONO_WAVE_PAN(t)){ else if(MONO_WAVE_PAN(t)){
rect.height = t->GetHeight(true) - (kTopInset + 2); rect.height = t->GetHeight(true) - (kTopMargin + kBottomMargin);
mTrackArtist->UpdateVRuler(t, rect); mTrackArtist->UpdateVRuler(t, rect);
} }
#endif #endif