Debian Codegraph @

src/tracks/playabletrack/notetrack/ui/NoteTrackDisplayData.h

raw
1 /**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 @file NoteTrackDisplayData.h
6 @brief Calculations supporting Note track display
7
8 Paul Licameli split from NoteTrack.h
9
10 **********************************************************************/
11
12 #ifndef __AUDACITY_NOTE_TRACK_DISPLAY_DATA
13 #define __AUDACITY_NOTE_TRACK_DISPLAY_DATA
14
15 #include <wx/gdicmn.h>
16 #include "NoteTrack.h"
17
18 class Alg_seq;
19 class NoteTrack;
20
21 /// Persistent data for display of a note track
22 class AUDACITY_DLL_API NoteTrackRange final : public NoteTrackAttachment
23 {
24 public:
25 //! Allow mutative access to attached data of a const track
26 static NoteTrackRange &Get(const NoteTrack &track);
27
28 ~NoteTrackRange() override;
29 std::unique_ptr<NoteTrackAttachment> Clone() const override;
30
31 void WriteXML(XMLWriter &xmlFile) const override;
32 bool HandleAttribute(const Attribute &attribute) override;
33
34 enum { MinPitch = 0, MaxPitch = 127 };
35
36 /// Gets the current bottom note (a pitch)
37 int GetBottomNote() const { return mBottomNote; }
38 /// Gets the current top note (a pitch)
39 int GetTopNote() const { return mTopNote; }
40
41 /// Sets the bottom note (a pitch), making sure that it is never greater than the top note.
42 void SetBottomNote(int note);
43 /// Sets the top note (a pitch), making sure that it is never less than the bottom note.
44 void SetTopNote(int note);
45
46 /// Sets the top and bottom note (both pitches) automatically, swapping them if needed.
47 void SetNoteRange(int note1, int note2);
48 /// Shifts all notes vertically by the given pitch
49 void ShiftNoteRange(int offset);
50
51 /// Zooms so that all notes are visible
52 void ZoomAllNotes(Alg_seq *pSeq);
53 /// Zooms so that the entire track is visible
54 void ZoomMaxExtent() { SetNoteRange(MinPitch, MaxPitch); }
55
56 #if 0
57 // Vertical scrolling is performed by dragging the keyboard at
58 // left of track. Protocol is call StartVScroll, then update by
59 // calling VScroll with original and final mouse position.
60 // These functions are not used -- instead, zooming/dragging works like
61 // audio track zooming/dragging. The vertical scrolling is nice however,
62 // so I left these functions here for possible use in the future.
63 void StartVScroll();
64 void VScroll(int start, int end);
65 #endif
66
67 private:
68 int mBottomNote{ MinPitch };
69 int mTopNote{ MaxPitch };
70 #if 0
71 // Also unused from vertical scrolling
72 int mStartBottomNote;
73 #endif
74 };
75
76 /// Temporary data used to display a note track
77 class NoteTrackDisplayData {
78 private:
79 const NoteTrack &mTrack;
80 wxRect mRect;
81
82 float mPitchHeight;
83 // mBottom is the Y offset of pitch 0 (normally off screen)
84 // Used so that mBottomNote is located at
85 // mY + mHeight - (GetNoteMargin() + 1 + GetPitchHeight())
86 int mBottom;
87 int mMargin;
88
89 enum { MinPitchHeight = 1, MaxPitchHeight = 25 };
90 public:
91 NoteTrackDisplayData(const NoteTrack &track, const wxRect &r);
92
93 /// Zoom the note track around y.
94 /// If center is true, the result will be centered at y.
95 void Zoom(int y, float multiplier, bool center);
96 void ZoomTo(int start, int end);
97 /// Zooms out a constant factor (subject to zoom limits)
98 void ZoomOut(int y) { Zoom(y, 1.0f / ZoomStep, true); }
99 /// Zooms in a constant factor (subject to zoom limits)
100 void ZoomIn(int y) { Zoom(y, ZoomStep, true); }
101
102 int GetPitchHeight(int factor) const;
103 int GetNoteMargin() const { return mMargin; };
104 int GetOctaveHeight() const { return GetPitchHeight(12) + 2; }
105 // IPitchToY returns Y coordinate of top of pitch p
106 int IPitchToY(int p) const;
107 // compute the window coordinate of the bottom of an octave: This is
108 // the bottom of the line separating B and C.
109 int GetOctaveBottom(int oct) const {
110 return IPitchToY(oct * 12) + GetPitchHeight(1) + 1;
111 }
112 // Y coordinate for given floating point pitch (rounded to int)
113 int PitchToY(double p) const {
114 return IPitchToY((int) (p + 0.5));
115 }
116 // Integer pitch corresponding to a Y coordinate
117 int YToIPitch(int y) const;
118 // map pitch class number (0-11) to pixel offset from bottom of octave
119 // (the bottom of the black line between B and C) to the top of the
120 // note. Note extra pixel separates B(11)/C(0) and E(4)/F(5).
121 int GetNotePos(int p) const
122 { return 1 + GetPitchHeight(p + 1) + (p > 4); }
123 // get pixel offset to top of ith black key note
124 int GetBlackPos(int i) const { return GetNotePos(i * 2 + 1 + (i > 1)); }
125 // GetWhitePos tells where to draw lines between keys as an offset from
126 // GetOctaveBottom. GetWhitePos(0) returns 1, which matches the location
127 // of the line separating B and C
128 int GetWhitePos(int i) const { return 1 + (i * GetOctaveHeight()) / 7; }
129
130 static const float ZoomStep;
131 };
132
133 #endif