mirror of
https://github.com/cookiengineer/audacity
synced 2026-03-03 05:04:24 +01:00
Improved Note Track vertical ruler zooming...
... Make consistent zoom in and out limits for mouse picks and for scrollwheel Make scrollwheel do in or out by a constant multiplier, analogously with wave track The Note track remembers a continuously varying key height, but rounds it off whenever it draws
This commit is contained in:
@@ -122,27 +122,38 @@ class AUDACITY_DLL_API NoteTrack final
|
||||
( QuantizedTimeAndBeat t0, QuantizedTimeAndBeat t1, double newDur );
|
||||
|
||||
int GetBottomNote() const { return mBottomNote; }
|
||||
int GetPitchHeight() const { return mPitchHeight; }
|
||||
void SetPitchHeight(int h) { mPitchHeight = h; }
|
||||
/// 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); }
|
||||
int GetPitchHeight() const { return std::max(1, (int)mPitchHeight); }
|
||||
void SetPitchHeight(int rectHeight, float h)
|
||||
{
|
||||
// Impose certain zoom limits
|
||||
auto octavePadding = 2 * 10; // 10 octaves times 2 single-pixel seperations per pixel
|
||||
auto availableHeight = rectHeight - octavePadding;
|
||||
auto numNotes = 128.f;
|
||||
auto minSpacePerNote =
|
||||
std::max((float)MinPitchHeight, availableHeight / numNotes);
|
||||
mPitchHeight =
|
||||
std::max(minSpacePerNote,
|
||||
std::min((float)MaxPitchHeight, h));
|
||||
}
|
||||
/// Zooms out a constant factor (subject to zoom limits)
|
||||
void ZoomOut(const wxRect &rect, int y) { Zoom(rect, y, 1.0f / ZoomStep, true); }
|
||||
/// Zooms in a contant factor (subject to zoom limits)
|
||||
void ZoomIn(const wxRect &rect, int y) { Zoom(rect, y, ZoomStep, 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 Zoom(const wxRect &rect, int y, float multiplier, bool center);
|
||||
void ZoomTo(const wxRect &rect, int start, int end);
|
||||
int GetNoteMargin(int height) const
|
||||
{ return std::min(height / 4, (mPitchHeight + 1) / 2); }
|
||||
int GetOctaveHeight() const { return mPitchHeight * 12 + 2; }
|
||||
{ return std::min(height / 4, (GetPitchHeight() + 1) / 2); }
|
||||
int GetOctaveHeight() const { return GetPitchHeight() * 12 + 2; }
|
||||
// call this once before a series of calls to IPitchToY(). It
|
||||
// sets mBottom to offset of octave 0 so that mBottomNote
|
||||
// is located at r.y + r.height - (GetNoteMargin() + 1 + mPitchHeight)
|
||||
// is located at r.y + r.height - (GetNoteMargin() + 1 + GetPitchHeight())
|
||||
void PrepareIPitchToY(const wxRect &r) const {
|
||||
mBottom = r.y + r.height - GetNoteMargin(r.height) - 1 - mPitchHeight +
|
||||
(mBottomNote / 12) * GetOctaveHeight() +
|
||||
GetNotePos(mBottomNote % 12);
|
||||
mBottom =
|
||||
r.y + r.height - GetNoteMargin(r.height) - 1 - GetPitchHeight() +
|
||||
(mBottomNote / 12) * GetOctaveHeight() +
|
||||
GetNotePos(mBottomNote % 12);
|
||||
}
|
||||
// IPitchToY returns Y coordinate of top of pitch p
|
||||
int IPitchToY(int p) const {
|
||||
@@ -151,7 +162,7 @@ class AUDACITY_DLL_API NoteTrack final
|
||||
// compute the window coordinate of the bottom of an octave: This is
|
||||
// the bottom of the line separating B and C.
|
||||
int GetOctaveBottom(int oct) const {
|
||||
return IPitchToY(oct * 12) + mPitchHeight + 1;
|
||||
return IPitchToY(oct * 12) + GetPitchHeight() + 1;
|
||||
}
|
||||
// Y coordinate for given floating point pitch (rounded to int)
|
||||
int PitchToY(double p) const {
|
||||
@@ -162,7 +173,8 @@ class AUDACITY_DLL_API NoteTrack final
|
||||
// map pitch class number (0-11) to pixel offset from bottom of octave
|
||||
// (the bottom of the black line between B and C) to the top of the
|
||||
// note. Note extra pixel separates B(11)/C(0) and E(4)/F(5).
|
||||
int GetNotePos(int p) const { return 1 + mPitchHeight * (p + 1) + (p > 4); }
|
||||
int GetNotePos(int p) const
|
||||
{ return 1 + GetPitchHeight() * (p + 1) + (p > 4); }
|
||||
// get pixel offset to top of ith black key note
|
||||
int GetBlackPos(int i) const { return GetNotePos(i * 2 + 1 + (i > 1)); }
|
||||
// GetWhitePos tells where to draw lines between keys as an offset from
|
||||
@@ -178,6 +190,8 @@ class AUDACITY_DLL_API NoteTrack final
|
||||
|
||||
mBottomNote = note;
|
||||
}
|
||||
|
||||
#if 0
|
||||
// Vertical scrolling is performed by dragging the keyboard at
|
||||
// left of track. Protocol is call StartVScroll, then update by
|
||||
// calling VScroll with original and final mouse position.
|
||||
@@ -186,6 +200,7 @@ class AUDACITY_DLL_API NoteTrack final
|
||||
// so I left these functions here for possible use in the future.
|
||||
void StartVScroll();
|
||||
void VScroll(int start, int end);
|
||||
#endif
|
||||
|
||||
bool HandleXMLTag(const wxChar *tag, const wxChar **attrs) override;
|
||||
XMLTagHandler *HandleXMLChild(const wxChar *tag) override;
|
||||
@@ -238,7 +253,14 @@ class AUDACITY_DLL_API NoteTrack final
|
||||
mutable int mBottom;
|
||||
int mBottomNote;
|
||||
int mStartBottomNote;
|
||||
int mPitchHeight;
|
||||
|
||||
// Remember continuous variation for zooming,
|
||||
// but it is rounded off whenever drawing:
|
||||
float mPitchHeight;
|
||||
|
||||
enum { MinPitchHeight = 1, MaxPitchHeight = 25 };
|
||||
static const float ZoomStep;
|
||||
|
||||
int mVisibleChannels; // bit set of visible channels
|
||||
|
||||
std::weak_ptr<StretchHandle> mStretchHandle;
|
||||
|
||||
Reference in New Issue
Block a user