mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-21 06:40:08 +02:00
Keep the current note centered when holding control to zoom
This commit is contained in:
parent
776e4dfdab
commit
b46abbec62
@ -911,22 +911,26 @@ void NoteTrack::VScroll(int start, int end)
|
||||
SetBottomNote(mStartBottomNote + delta);
|
||||
}
|
||||
|
||||
// Zoom the note track, centering the pitch at centerY,
|
||||
// positive amounts zoom in; negative amounts zoom out
|
||||
void NoteTrack::Zoom(const wxRect &rect, int centerY, int amount)
|
||||
void NoteTrack::Zoom(const wxRect &rect, int y, int amount, bool center)
|
||||
{
|
||||
// Construct track rectangle to map pitch to screen coordinates
|
||||
// Only y and height are needed:
|
||||
wxRect trackRect(0, rect.GetY(), 1, rect.GetHeight());
|
||||
PrepareIPitchToY(trackRect);
|
||||
int centerPitch = YToIPitch(centerY);
|
||||
int clickedPitch = YToIPitch(y);
|
||||
// zoom out by changing the pitch height -- a small integer
|
||||
mPitchHeight += amount;
|
||||
if (mPitchHeight <= 0) mPitchHeight = 1;
|
||||
PrepareIPitchToY(trackRect); // update because mPitchHeight changed
|
||||
int newCenterPitch = YToIPitch(rect.GetY() + rect.GetHeight() / 2);
|
||||
// center the pitch that the user clicked on
|
||||
SetBottomNote(mBottomNote + (centerPitch - newCenterPitch));
|
||||
if (center) {
|
||||
int newCenterPitch = YToIPitch(rect.GetY() + rect.GetHeight() / 2);
|
||||
// center the pitch that the user clicked on
|
||||
SetBottomNote(mBottomNote + (clickedPitch - newCenterPitch));
|
||||
} else {
|
||||
int newClickedPitch = YToIPitch(y);
|
||||
// align to keep the pitch that the user clicked on in the same place
|
||||
SetBottomNote(mBottomNote + (clickedPitch - newClickedPitch));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -940,7 +944,7 @@ void NoteTrack::ZoomTo(const wxRect &rect, int start, int end)
|
||||
int temp = topPitch; topPitch = botPitch; botPitch = temp;
|
||||
}
|
||||
if (topPitch == botPitch) { // can't divide by zero, do something else
|
||||
Zoom(rect, start, 1);
|
||||
Zoom(rect, start, 1, true);
|
||||
return;
|
||||
}
|
||||
int trialPitchHeight = trackRect.height / (topPitch - botPitch);
|
||||
@ -949,7 +953,7 @@ void NoteTrack::ZoomTo(const wxRect &rect, int start, int end)
|
||||
} else if (trialPitchHeight == 0) {
|
||||
trialPitchHeight = 1;
|
||||
}
|
||||
Zoom(rect, (start + end) / 2, trialPitchHeight - mPitchHeight);
|
||||
Zoom(rect, (start + end) / 2, trialPitchHeight - mPitchHeight, true);
|
||||
}
|
||||
|
||||
int NoteTrack::YToIPitch(int y)
|
||||
|
@ -127,9 +127,14 @@ class AUDACITY_DLL_API NoteTrack final
|
||||
int GetBottomNote() const { return mBottomNote; }
|
||||
int GetPitchHeight() const { return mPitchHeight; }
|
||||
void SetPitchHeight(int h) { mPitchHeight = h; }
|
||||
void ZoomOut(const wxRect &rect, int y) { Zoom(rect, y, -1); }
|
||||
void ZoomIn(const wxRect &rect, int y) { Zoom(rect, y, 1); }
|
||||
void Zoom(const wxRect &rect, int centerY, int amount);
|
||||
/// Zooms out by one unit
|
||||
void ZoomOut(const wxRect &rect, int y) { Zoom(rect, y, -1, true); }
|
||||
/// Zooms in by one unit
|
||||
void ZoomIn(const wxRect &rect, int y) { Zoom(rect, y, 1, true); }
|
||||
/// Zoom the note track around y.
|
||||
/// Positive amounts zoom in; negative amounts zoom out.
|
||||
/// If center is true, the result will be centered at y.
|
||||
void Zoom(const wxRect &rect, int y, int amount, bool center);
|
||||
void ZoomTo(const wxRect &rect, int start, int end);
|
||||
int GetNoteMargin() const { return (mPitchHeight + 1) / 2; }
|
||||
int GetOctaveHeight() const { return mPitchHeight * 12 + 2; }
|
||||
|
@ -236,7 +236,7 @@ unsigned NoteTrackVRulerControls::HandleWheelRotation
|
||||
|
||||
const auto nt = static_cast<NoteTrack*>(pTrack.get());
|
||||
if (event.CmdDown() && !event.ShiftDown()) {
|
||||
nt->Zoom(evt.rect, evt.event.m_y, (int) (steps));
|
||||
nt->Zoom(evt.rect, evt.event.m_y, (int) (steps), false);
|
||||
} else if (!event.CmdDown() && event.ShiftDown()) {
|
||||
// Scroll some fixed number of notes, independent of zoom level or track height:
|
||||
static const int movement = 6; // 6 semitones is half an octave
|
||||
|
Loading…
x
Reference in New Issue
Block a user