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

Reviewed use of Track::GetY; don't use in NoteTrack; fix off-by-1's

This commit is contained in:
Paul Licameli 2017-06-03 23:20:37 -04:00
parent acd55e95db
commit 5395f253bf
5 changed files with 34 additions and 22 deletions

View File

@ -907,26 +907,26 @@ void NoteTrack::VScroll(int start, int end)
// Zoom the note track, centering the pitch at centerY, // Zoom the note track, centering the pitch at centerY,
// amount is 1 for zoom in, and -1 for zoom out // amount is 1 for zoom in, and -1 for zoom out
void NoteTrack::Zoom(int centerY, int amount) void NoteTrack::Zoom(const wxRect &rect, int centerY, int amount)
{ {
// Construct track rectangle to map pitch to screen coordinates // Construct track rectangle to map pitch to screen coordinates
// Only y and height are needed: // Only y and height are needed:
wxRect trackRect(0, GetY(), 1, GetHeight()); wxRect trackRect(0, rect.GetY(), 1, rect.GetHeight());
PrepareIPitchToY(trackRect); PrepareIPitchToY(trackRect);
int centerPitch = YToIPitch(centerY); int centerPitch = YToIPitch(centerY);
// zoom out by changing the pitch height -- a small integer // zoom out by changing the pitch height -- a small integer
mPitchHeight += amount; mPitchHeight += amount;
if (mPitchHeight <= 0) mPitchHeight = 1; if (mPitchHeight <= 0) mPitchHeight = 1;
PrepareIPitchToY(trackRect); // update because mPitchHeight changed PrepareIPitchToY(trackRect); // update because mPitchHeight changed
int newCenterPitch = YToIPitch(GetY() + GetHeight() / 2); int newCenterPitch = YToIPitch(rect.GetY() + rect.GetHeight() / 2);
// center the pitch that the user clicked on // center the pitch that the user clicked on
SetBottomNote(mBottomNote + (centerPitch - newCenterPitch)); SetBottomNote(mBottomNote + (centerPitch - newCenterPitch));
} }
void NoteTrack::ZoomTo(int start, int end) void NoteTrack::ZoomTo(const wxRect &rect, int start, int end)
{ {
wxRect trackRect(0, GetY(), 1, GetHeight()); wxRect trackRect(0, rect.GetY(), 1, rect.GetHeight());
PrepareIPitchToY(trackRect); PrepareIPitchToY(trackRect);
int topPitch = YToIPitch(start); int topPitch = YToIPitch(start);
int botPitch = YToIPitch(end); int botPitch = YToIPitch(end);
@ -934,7 +934,7 @@ void NoteTrack::ZoomTo(int start, int end)
int temp = topPitch; topPitch = botPitch; botPitch = temp; int temp = topPitch; topPitch = botPitch; botPitch = temp;
} }
if (topPitch == botPitch) { // can't divide by zero, do something else if (topPitch == botPitch) { // can't divide by zero, do something else
Zoom(start, 1); Zoom(rect, start, 1);
return; return;
} }
int trialPitchHeight = trackRect.height / (topPitch - botPitch); int trialPitchHeight = trackRect.height / (topPitch - botPitch);
@ -943,7 +943,7 @@ void NoteTrack::ZoomTo(int start, int end)
} else if (trialPitchHeight == 0) { } else if (trialPitchHeight == 0) {
trialPitchHeight = 1; trialPitchHeight = 1;
} }
Zoom((start + end) / 2, trialPitchHeight - mPitchHeight); Zoom(rect, (start + end) / 2, trialPitchHeight - mPitchHeight);
} }
int NoteTrack::YToIPitch(int y) int NoteTrack::YToIPitch(int y)

View File

@ -121,10 +121,10 @@ class AUDACITY_DLL_API NoteTrack final
int GetBottomNote() const { return mBottomNote; } int GetBottomNote() const { return mBottomNote; }
int GetPitchHeight() const { return mPitchHeight; } int GetPitchHeight() const { return mPitchHeight; }
void SetPitchHeight(int h) { mPitchHeight = h; } void SetPitchHeight(int h) { mPitchHeight = h; }
void ZoomOut(int y) { Zoom(y, -1); } void ZoomOut(const wxRect &rect, int y) { Zoom(rect, y, -1); }
void ZoomIn(int y) { Zoom(y, 1); } void ZoomIn(const wxRect &rect, int y) { Zoom(rect, y, 1); }
void Zoom(int centerY, int amount); void Zoom(const wxRect &rect, int centerY, int amount);
void ZoomTo(int start, int end); void ZoomTo(const wxRect &rect, int start, int end);
int GetNoteMargin() const { return (mPitchHeight + 1) / 2; } int GetNoteMargin() const { return (mPitchHeight + 1) / 2; }
int GetOctaveHeight() const { return mPitchHeight * 12 + 2; } int GetOctaveHeight() const { return mPitchHeight * 12 + 2; }
// call this once before a series of calls to IPitchToY(). It // call this once before a series of calls to IPitchToY(). It

View File

@ -2009,7 +2009,8 @@ Track *AudacityProject::GetFirstVisible()
for (Track *t = iter.First(); t; t = iter.Next()) { for (Track *t = iter.First(); t; t = iter.Next()) {
int y = t->GetY(); int y = t->GetY();
int h = t->GetHeight(); int h = t->GetHeight();
if (y >= mViewInfo.vpos || y + h >= mViewInfo.vpos) { if (y + h - 1 >= mViewInfo.vpos) {
// At least the bottom row of pixels is not scrolled away above
mViewInfo.track = t; mViewInfo.track = t;
break; break;
} }
@ -2028,8 +2029,8 @@ void AudacityProject::UpdateFirstVisible()
Track *t = mViewInfo.track; Track *t = mViewInfo.track;
mViewInfo.track = NULL; mViewInfo.track = NULL;
if (t->GetY() > mViewInfo.vpos) { if (t->GetY() >= mViewInfo.vpos) {
while (t && t->GetY() > mViewInfo.vpos) { while (t && t->GetY() >= mViewInfo.vpos) {
t = mTracks->GetPrev(t); t = mTracks->GetPrev(t);
} }
} }
@ -2037,7 +2038,8 @@ void AudacityProject::UpdateFirstVisible()
while (t) { while (t) {
int y = t->GetY(); int y = t->GetY();
int h = t->GetHeight(); int h = t->GetHeight();
if (y >= mViewInfo.vpos || y + h >= mViewInfo.vpos) { if (y + h - 1 >= mViewInfo.vpos) {
// At least the bottom row of pixels is not scrolled away above
mViewInfo.track = t; mViewInfo.track = t;
return; return;
} }

View File

@ -4289,12 +4289,18 @@ void TrackPanel::HandleVZoomButtonUp( wxMouseEvent & event )
// which we then return // which we then return
if (mCapturedTrack->GetKind() == Track::Note) { if (mCapturedTrack->GetKind() == Track::Note) {
NoteTrack *nt = (NoteTrack *) mCapturedTrack; NoteTrack *nt = (NoteTrack *) mCapturedTrack;
const wxRect rect{
GetLeftOffset(),
mCapturedTrack->GetY() + kTopMargin,
GetSize().GetWidth() - GetLeftOffset(),
mCapturedTrack->GetHeight() - (kTopMargin + kBottomMargin)
};
if (IsDragZooming()) { if (IsDragZooming()) {
nt->ZoomTo(mZoomStart, mZoomEnd); nt->ZoomTo(rect, mZoomStart, mZoomEnd);
} else if (event.ShiftDown() || event.RightUp()) { } else if (event.ShiftDown() || event.RightUp()) {
nt->ZoomOut(mZoomEnd); nt->ZoomOut(rect, mZoomEnd);
} else { } else {
nt->ZoomIn(mZoomEnd); nt->ZoomIn(rect, mZoomEnd);
} }
mZoomEnd = mZoomStart = 0; mZoomEnd = mZoomStart = 0;
Refresh(false); Refresh(false);
@ -9611,6 +9617,7 @@ void TrackInfo::DrawVelocitySlider(wxDC *dc, NoteTrack *t, wxRect rect, bool cap
LWSlider * TrackInfo::GainSlider(WaveTrack *t, bool captured) const LWSlider * TrackInfo::GainSlider(WaveTrack *t, bool captured) const
{ {
// PRL: Add the inset, but why not also the border?
wxRect rect(kLeftInset, t->GetY() - pParent->GetViewInfo()->vpos + kTopInset, 1, t->GetHeight()); wxRect rect(kLeftInset, t->GetY() - pParent->GetViewInfo()->vpos + kTopInset, 1, t->GetHeight());
wxRect sliderRect; wxRect sliderRect;
GetGainRect(rect, sliderRect); GetGainRect(rect, sliderRect);
@ -9628,6 +9635,7 @@ LWSlider * TrackInfo::GainSlider(WaveTrack *t, bool captured) const
LWSlider * TrackInfo::PanSlider(WaveTrack *t, bool captured) const LWSlider * TrackInfo::PanSlider(WaveTrack *t, bool captured) const
{ {
// PRL: Add the inset, but why not also the border?
wxRect rect(kLeftInset, t->GetY() - pParent->GetViewInfo()->vpos + kTopInset, 1, t->GetHeight()); wxRect rect(kLeftInset, t->GetY() - pParent->GetViewInfo()->vpos + kTopInset, 1, t->GetHeight());
wxRect sliderRect; wxRect sliderRect;
GetPanRect(rect, sliderRect); GetPanRect(rect, sliderRect);
@ -9646,6 +9654,7 @@ LWSlider * TrackInfo::PanSlider(WaveTrack *t, bool captured) const
#ifdef EXPERIMENTAL_MIDI_OUT #ifdef EXPERIMENTAL_MIDI_OUT
LWSlider * TrackInfo::VelocitySlider(NoteTrack *t, bool captured) const LWSlider * TrackInfo::VelocitySlider(NoteTrack *t, bool captured) const
{ {
// PRL: Add the inset, but why not also the border?
wxRect rect(kLeftInset, t->GetY() - pParent->GetViewInfo()->vpos + kTopInset, 1, t->GetHeight()); wxRect rect(kLeftInset, t->GetY() - pParent->GetViewInfo()->vpos + kTopInset, 1, t->GetHeight());
wxRect sliderRect; wxRect sliderRect;
GetVelocityRect(rect, sliderRect); GetVelocityRect(rect, sliderRect);

View File

@ -122,10 +122,11 @@ void EditCursorOverlay::Draw(OverlayPanel &panel, wxDC &dc)
#ifdef EXPERIMENTAL_OUTPUT_DISPLAY #ifdef EXPERIMENTAL_OUTPUT_DISPLAY
if (MONO_WAVE_PAN(pTrack)){ if (MONO_WAVE_PAN(pTrack)){
auto y = pTrack->GetY(true) - viewInfo.vpos + 1; auto y = pTrack->GetY(true) - viewInfo.vpos;
auto top = y + kTopInset; auto top = y + kTopMargin;
auto bottom = y + pTrack->GetHeight(true) - kTopInset; auto height = pTrack->GetHeight(true) - (kTopMargin + kBottomMargin);
AColor::Line(dc, mLastCursorX, top, mLastCursorX, bottom); // - 1 because AColor::Line is inclusive of endpoint
AColor::Line(dc, mLastCursorX, top, mLastCursorX, top + height - 1);
} }
#endif #endif