Audacity 3.2.0
NoteTrackDisplayData.h
Go to the documentation of this file.
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
18class Alg_seq;
19class NoteTrack;
20
22class AUDACITY_DLL_API NoteTrackRange final : public NoteTrackAttachment
23{
24public:
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
37 int GetBottomNote() const { return mBottomNote; }
39 int GetTopNote() const { return mTopNote; }
40
42 void SetBottomNote(int note);
44 void SetTopNote(int note);
45
47 void SetNoteRange(int note1, int note2);
49 void ShiftNoteRange(int offset);
50
52 void ZoomAllNotes(Alg_seq *pSeq);
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
67private:
68 int mBottomNote{ MinPitch };
69 int mTopNote{ MaxPitch };
70#if 0
71 // Also unused from vertical scrolling
72 int mStartBottomNote;
73#endif
74};
75
78private:
80 wxRect mRect;
81
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())
88
89 enum { MinPitchHeight = 1, MaxPitchHeight = 25 };
90public:
91 NoteTrackDisplayData(const NoteTrack &track, const wxRect &r);
92
95 void Zoom(int y, float multiplier, bool center);
96 void ZoomTo(int start, int end);
98 void ZoomOut(int y) { Zoom(y, 1.0f / ZoomStep, true); }
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
std::pair< std::string_view, XMLAttributeValueView > Attribute
Definition: XMLTagHandler.h:39
Temporary data used to display a note track.
void ZoomOut(int y)
Zooms out a constant factor (subject to zoom limits)
int GetPitchHeight(int factor) const
int GetNotePos(int p) const
void Zoom(int y, float multiplier, bool center)
NoteTrackDisplayData(const NoteTrack &track, const wxRect &r)
const NoteTrack & mTrack
void ZoomIn(int y)
Zooms in a constant factor (subject to zoom limits)
int PitchToY(double p) const
static const float ZoomStep
int GetOctaveBottom(int oct) const
void ZoomTo(int start, int end)
int GetWhitePos(int i) const
int GetBlackPos(int i) const
A Track that is used for Midi notes. (Somewhat old code).
Definition: NoteTrack.h:78
Persistent data for display of a note track.
void ZoomMaxExtent()
Zooms so that the entire track is visible.
~NoteTrackRange() override
int GetTopNote() const
Gets the current top note (a pitch)
int GetBottomNote() const
Gets the current bottom note (a pitch)
Base class for XMLFileWriter and XMLStringWriter that provides the general functionality for creating...
Definition: XMLWriter.h:25
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:201
const char * end(const char *str) noexcept
Definition: StringUtils.h:106
virtual void WriteXML(XMLWriter &xmlFile) const
Default implementation does nothing.
Definition: NoteTrack.cpp:124
virtual bool HandleAttribute(const Attribute &attribute)
Return whether the attribute was used; default returns false.
Definition: NoteTrack.cpp:127