Audacity 3.2.0
Public Member Functions | Static Public Attributes | Private Types | Private Attributes | List of all members
NoteTrackDisplayData Class Reference

Temporary data used to display a note track. More...

#include <NoteTrackDisplayData.h>

Collaboration diagram for NoteTrackDisplayData:
[legend]

Public Member Functions

 NoteTrackDisplayData (const NoteTrack &track, const wxRect &r)
 
void Zoom (int y, float multiplier, bool center)
 
void ZoomTo (int start, int end)
 
void ZoomOut (int y)
 Zooms out a constant factor (subject to zoom limits) More...
 
void ZoomIn (int y)
 Zooms in a constant factor (subject to zoom limits) More...
 
int GetPitchHeight (int factor) const
 
int GetNoteMargin () const
 
int GetOctaveHeight () const
 
int IPitchToY (int p) const
 
int GetOctaveBottom (int oct) const
 
int PitchToY (double p) const
 
int YToIPitch (int y) const
 
int GetNotePos (int p) const
 
int GetBlackPos (int i) const
 
int GetWhitePos (int i) const
 

Static Public Attributes

static const float ZoomStep = powf( 2.0f, 0.25f )
 

Private Types

enum  { MinPitchHeight = 1 , MaxPitchHeight = 25 }
 

Private Attributes

const NoteTrackmTrack
 
wxRect mRect
 
float mPitchHeight
 
int mBottom
 
int mMargin
 

Detailed Description

Temporary data used to display a note track.

Definition at line 77 of file NoteTrackDisplayData.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private
Enumerator
MinPitchHeight 
MaxPitchHeight 

Definition at line 89 of file NoteTrackDisplayData.h.

Constructor & Destructor Documentation

◆ NoteTrackDisplayData()

NoteTrackDisplayData::NoteTrackDisplayData ( const NoteTrack track,
const wxRect &  r 
)

Definition at line 151 of file NoteTrackDisplayData.cpp.

153 : mTrack{ track }
154 , mRect{ rect }
155{
156 auto &data = NoteTrackRange::Get(mTrack);
157 auto span = data.GetTopNote() - data.GetBottomNote() + 1; // + 1 to make sure it includes both
158
159 mMargin = std::min((int) (rect.height / (float)(span)) / 2, rect.height / 4);
160
161 // Count the number of dividers between B/C and E/F
162 int numC = 0, numF = 0;
163 auto botOctave = data.GetBottomNote() / 12, botNote = data.GetBottomNote() % 12;
164 auto topOctave = data.GetTopNote() / 12, topNote = data.GetTopNote() % 12;
165 if (topOctave == botOctave)
166 {
167 if (botNote == 0) numC = 1;
168 if (topNote <= 5) numF = 1;
169 }
170 else
171 {
172 numC = topOctave - botOctave;
173 numF = topOctave - botOctave - 1;
174 if (botNote == 0) numC++;
175 if (botNote <= 5) numF++;
176 if (topOctave <= 5) numF++;
177 }
178 // Effective space, excluding the margins and the lines between some notes
179 auto effectiveHeight = rect.height - (2 * (mMargin + 1)) - numC - numF;
180 // Guaranteed that both the bottom and top notes will be visible
181 // (assuming that the clamping below does not happen)
182 mPitchHeight = effectiveHeight / ((float) span);
183
188
189 mBottom = rect.y + rect.height - GetNoteMargin() - 1 - GetPitchHeight(1) +
190 botOctave * GetOctaveHeight() + GetNotePos(botNote);
191}
int min(int a, int b)
int GetPitchHeight(int factor) const
int GetNotePos(int p) const
const NoteTrack & mTrack
static NoteTrackRange & Get(const NoteTrack &track)
Allow mutative access to attached data of a const track.

References NoteTrackRange::Get(), GetNoteMargin(), GetNotePos(), GetOctaveHeight(), GetPitchHeight(), MaxPitchHeight, mBottom, min(), MinPitchHeight, mMargin, mPitchHeight, and mTrack.

Here is the call graph for this function:

Member Function Documentation

◆ GetBlackPos()

int NoteTrackDisplayData::GetBlackPos ( int  i) const
inline

Definition at line 124 of file NoteTrackDisplayData.h.

124{ return GetNotePos(i * 2 + 1 + (i > 1)); }

References GetNotePos().

Here is the call graph for this function:

◆ GetNoteMargin()

int NoteTrackDisplayData::GetNoteMargin ( ) const
inline

Definition at line 103 of file NoteTrackDisplayData.h.

103{ return mMargin; };

References mMargin.

Referenced by NoteTrackDisplayData().

Here is the caller graph for this function:

◆ GetNotePos()

int NoteTrackDisplayData::GetNotePos ( int  p) const
inline

Definition at line 121 of file NoteTrackDisplayData.h.

122 { return 1 + GetPitchHeight(p + 1) + (p > 4); }

References GetPitchHeight().

Referenced by GetBlackPos(), IPitchToY(), and NoteTrackDisplayData().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetOctaveBottom()

int NoteTrackDisplayData::GetOctaveBottom ( int  oct) const
inline

Definition at line 109 of file NoteTrackDisplayData.h.

109 {
110 return IPitchToY(oct * 12) + GetPitchHeight(1) + 1;
111 }

References GetPitchHeight(), and IPitchToY().

Here is the call graph for this function:

◆ GetOctaveHeight()

int NoteTrackDisplayData::GetOctaveHeight ( ) const
inline

Definition at line 104 of file NoteTrackDisplayData.h.

104{ return GetPitchHeight(12) + 2; }

References GetPitchHeight().

Referenced by GetWhitePos(), IPitchToY(), NoteTrackDisplayData(), and YToIPitch().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetPitchHeight()

int NoteTrackDisplayData::GetPitchHeight ( int  factor) const

Definition at line 241 of file NoteTrackDisplayData.cpp.

242{
243 return std::max(1, (int)(factor * mPitchHeight));
244
245}

References mPitchHeight.

Referenced by GetNotePos(), GetOctaveBottom(), GetOctaveHeight(), and NoteTrackDisplayData().

Here is the caller graph for this function:

◆ GetWhitePos()

int NoteTrackDisplayData::GetWhitePos ( int  i) const
inline

Definition at line 128 of file NoteTrackDisplayData.h.

128{ return 1 + (i * GetOctaveHeight()) / 7; }

References GetOctaveHeight().

Here is the call graph for this function:

◆ IPitchToY()

int NoteTrackDisplayData::IPitchToY ( int  p) const

Definition at line 193 of file NoteTrackDisplayData.cpp.

194{ return mBottom - (p / 12) * GetOctaveHeight() - GetNotePos(p % 12); }

References GetNotePos(), GetOctaveHeight(), and mBottom.

Referenced by GetOctaveBottom(), and PitchToY().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PitchToY()

int NoteTrackDisplayData::PitchToY ( double  p) const
inline

Definition at line 113 of file NoteTrackDisplayData.h.

113 {
114 return IPitchToY((int) (p + 0.5));
115 }

References IPitchToY().

Here is the call graph for this function:

◆ YToIPitch()

int NoteTrackDisplayData::YToIPitch ( int  y) const

Definition at line 196 of file NoteTrackDisplayData.cpp.

197{
198 y = mBottom - y; // pixels above pitch 0
199 int octave = (y / GetOctaveHeight());
200 y -= octave * GetOctaveHeight();
201 // result is approximate because C and G are one pixel taller than
202 // mPitchHeight.
203 // Poke 1-13-18: However in practice this seems not to be an issue,
204 // as long as we use mPitchHeight and not the rounded version
205 return (y / mPitchHeight) + octave * 12;
206}

References GetOctaveHeight(), mBottom, and mPitchHeight.

Referenced by Zoom(), and ZoomTo().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Zoom()

void NoteTrackDisplayData::Zoom ( int  y,
float  multiplier,
bool  center 
)

Zoom the note track around y. If center is true, the result will be centered at y.

Definition at line 208 of file NoteTrackDisplayData.cpp.

209{
210 auto &data = NoteTrackRange::Get(mTrack);
211 int clickedPitch = YToIPitch(y);
212 int extent = data.GetTopNote() - data.GetBottomNote() + 1;
213 int newExtent = (int) (extent / multiplier);
214 float position;
215 if (center) {
216 // center the pitch that the user clicked on
217 position = .5;
218 } else {
219 // align to keep the pitch that the user clicked on in the same place
220 position = extent / (clickedPitch - data.GetBottomNote());
221 }
222 int newBottomNote = clickedPitch - (newExtent * position);
223 int newTopNote = clickedPitch + (newExtent * (1 - position));
224 data.SetNoteRange(newBottomNote, newTopNote);
225}

References NoteTrackRange::Get(), mTrack, and YToIPitch().

Referenced by ZoomIn(), ZoomOut(), and ZoomTo().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ZoomIn()

void NoteTrackDisplayData::ZoomIn ( int  y)
inline

Zooms in a constant factor (subject to zoom limits)

Definition at line 100 of file NoteTrackDisplayData.h.

100{ Zoom(y, ZoomStep, true); }
void Zoom(int y, float multiplier, bool center)
static const float ZoomStep

References Zoom(), and ZoomStep.

Here is the call graph for this function:

◆ ZoomOut()

void NoteTrackDisplayData::ZoomOut ( int  y)
inline

Zooms out a constant factor (subject to zoom limits)

Definition at line 98 of file NoteTrackDisplayData.h.

98{ Zoom(y, 1.0f / ZoomStep, true); }

References Zoom(), and ZoomStep.

Here is the call graph for this function:

◆ ZoomTo()

void NoteTrackDisplayData::ZoomTo ( int  start,
int  end 
)

Definition at line 227 of file NoteTrackDisplayData.cpp.

228{
229 wxRect trackRect(0, mRect.GetY(), 1, mRect.GetHeight());
230 int pitch1 = YToIPitch(start);
231 int pitch2 = YToIPitch(end);
232 if (pitch1 == pitch2) {
233 // Just zoom in instead of zooming to show only one note
234 Zoom(start, 1, true);
235 return;
236 }
237 // It's fine for this to be in either order
238 NoteTrackRange::Get(mTrack).SetNoteRange(pitch1, pitch2);
239}
void SetNoteRange(int note1, int note2)
Sets the top and bottom note (both pitches) automatically, swapping them if needed.
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159

References PackedArray::end(), NoteTrackRange::Get(), mRect, mTrack, NoteTrackRange::SetNoteRange(), YToIPitch(), and Zoom().

Referenced by NoteTrackVZoomHandle::Release().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ mBottom

int NoteTrackDisplayData::mBottom
private

Definition at line 86 of file NoteTrackDisplayData.h.

Referenced by IPitchToY(), NoteTrackDisplayData(), and YToIPitch().

◆ mMargin

int NoteTrackDisplayData::mMargin
private

Definition at line 87 of file NoteTrackDisplayData.h.

Referenced by GetNoteMargin(), and NoteTrackDisplayData().

◆ mPitchHeight

float NoteTrackDisplayData::mPitchHeight
private

Definition at line 82 of file NoteTrackDisplayData.h.

Referenced by GetPitchHeight(), NoteTrackDisplayData(), and YToIPitch().

◆ mRect

wxRect NoteTrackDisplayData::mRect
private

Definition at line 80 of file NoteTrackDisplayData.h.

Referenced by ZoomTo().

◆ mTrack

const NoteTrack& NoteTrackDisplayData::mTrack
private

Definition at line 79 of file NoteTrackDisplayData.h.

Referenced by NoteTrackDisplayData(), Zoom(), and ZoomTo().

◆ ZoomStep

const float NoteTrackDisplayData::ZoomStep = powf( 2.0f, 0.25f )
static

Definition at line 130 of file NoteTrackDisplayData.h.

Referenced by ZoomIn(), and ZoomOut().


The documentation for this class was generated from the following files: