Audacity 3.2.0
Classes | Public Member Functions | Private Attributes | List of all members
BeatsFormat Class Referencefinal

#include <BeatsFormat.h>

Inheritance diagram for BeatsFormat:
[legend]
Collaboration diagram for BeatsFormat:
[legend]

Classes

struct  Tick
 
struct  Ticks
 

Public Member Functions

 BeatsFormat (const ProjectTimeSignature &timeSignature)
 
 BeatsFormat ()=delete
 
 ~BeatsFormat () override
 
void SetTickSizes (double units, double &major, double &minor, double &minorMinor, int &mDigits) const override
 
void SetLabelString (wxString &s, double d, double units, double minor, int mDigits, TickType tickType) const override
 
void SetData (double bpm, int timeSigUpper, int timeSigLower)
 
void UpdateSubdivision (double units)
 
const TicksGetSubdivision () const
 
 RulerFormat ()
 
- Public Member Functions inherited from RulerFormat
 RulerFormat ()
 
virtual ~RulerFormat ()
 
virtual void SetTickSizes (double units, double &major, double &minor, double &minorMinor, int &mDigits) const =0
 
virtual void SetLabelString (wxString &s, double d, double units, double minor, int mDigits, TickType tickType) const =0
 

Private Attributes

double mBpm { 60.0 }
 
int mTimeSigUpper { 4 }
 
int mTimeSigLower { 4 }
 
Ticks mTicks
 

Additional Inherited Members

- Public Types inherited from RulerFormat
enum  TickType { t_major , t_minor , t_minorMinor }
 

Detailed Description

Definition at line 18 of file BeatsFormat.h.

Constructor & Destructor Documentation

◆ BeatsFormat() [1/2]

BeatsFormat::BeatsFormat ( const ProjectTimeSignature timeSignature)

Definition at line 182 of file BeatsFormat.cpp.

183{
184 SetData(
185 sig.GetTempo(), sig.GetUpperTimeSignature(), sig.GetLowerTimeSignature());
186}
void SetData(double bpm, int timeSigUpper, int timeSigLower)
Definition: BeatsFormat.cpp:70

References ProjectTimeSignature::GetLowerTimeSignature(), ProjectTimeSignature::GetTempo(), ProjectTimeSignature::GetUpperTimeSignature(), and SetData().

Here is the call graph for this function:

◆ BeatsFormat() [2/2]

BeatsFormat::BeatsFormat ( )
delete

◆ ~BeatsFormat()

BeatsFormat::~BeatsFormat ( )
overridedefault

Member Function Documentation

◆ GetSubdivision()

const BeatsFormat::Ticks & BeatsFormat::GetSubdivision ( ) const

Definition at line 177 of file BeatsFormat.cpp.

178{
179 return mTicks;
180}
Ticks mTicks
Definition: BeatsFormat.h:67

References mTicks.

Referenced by anonymous_namespace{TrackArt.cpp}::BeatsGridlinePainter::GetMinorTick().

Here is the caller graph for this function:

◆ RulerFormat()

RulerFormat::RulerFormat ( )
inlineexplicit

Definition at line 22 of file RulerFormat.h.

22{}

◆ SetData()

void BeatsFormat::SetData ( double  bpm,
int  timeSigUpper,
int  timeSigLower 
)
Precondition
bpm > 0
timeSigUpper > 0
timeSigLower > 1
(timeSigLower & (timeSigLower - 1)) == 0

Definition at line 70 of file BeatsFormat.cpp.

71{
72 // Check preconditions
73 assert(bpm > 0);
74 assert(timeSigUpper > 0);
75 assert(timeSigLower > 1);
76 assert((timeSigLower & (timeSigLower - 1)) == 0);
77
78 if (!(mBpm > 0 && mTimeSigUpper > 1 && mTimeSigLower > 1))
79 return;
80
81 if (mTimeSigLower & (mTimeSigLower - 1))
82 return;
83
84 mBpm = bpm;
85 mTimeSigUpper = timeSigUpper;
86 mTimeSigLower = timeSigLower;
87}
double mBpm
Definition: BeatsFormat.h:63
int mTimeSigLower
Definition: BeatsFormat.h:65
int mTimeSigUpper
Definition: BeatsFormat.h:64

References mBpm, mTimeSigLower, and mTimeSigUpper.

Referenced by BeatsFormat(), and ProjectTimeRuler::Impl::Impl().

Here is the caller graph for this function:

◆ SetLabelString()

void BeatsFormat::SetLabelString ( wxString &  s,
double  d,
double  units,
double  minor,
int  mDigits,
TickType  tickType 
) const
overridevirtual

Implements RulerFormat.

Definition at line 30 of file BeatsFormat.cpp.

33{
34 if (d < 0) {
35 return;
36 }
37
38 const auto lower = static_cast<double>(mTimeSigLower);
39 double val = (mBpm * (lower / 4) * d) / (60 * mTimeSigUpper);
40 double beatApprox = (val - floor(val)) * mTimeSigUpper + 1;
41 int beat = round(beatApprox);
42
43 // Don't add decimal if it's a major tick or is on the beat
44 // Segment by distance with units
45 if (units < .4 * (60 / mBpm)* (4 / lower))
46 {
47 if (tickType == RulerFormat::t_major) {
48 s.Printf(wxT("%d"), (int)round(val + 1));
49 }
50 else if (tickType == RulerFormat::t_minor && abs(beat - beatApprox) < 1.0e-5f) {
51 s.Printf(wxT("%d.%d"), (int)floor(val + 1), (int)beat);
52 }
53 }
54 else if (units < .8 * (60 / mBpm) * (4 / lower))
55 {
56 if (tickType == RulerFormat::t_major) {
57 s.Printf(wxT("%d"), (int)round(val + 1));
58 }
59 else if (tickType == RulerFormat::t_minor && beat != 1) {
60 s.Printf(wxT("%d.%d"), (int)floor(val + 1), (int)beat);
61 }
62 }
63 else {
64 if (tickType == RulerFormat::t_major) {
65 s.Printf(wxT("%d"), (int)round(val + 1));
66 }
67 }
68}
wxT("CloseDown"))
fastfloat_really_inline void round(adjusted_mantissa &am, callback cb) noexcept
Definition: fast_float.h:2512

References mBpm, mTimeSigLower, mTimeSigUpper, fast_float::round(), RulerFormat::t_major, RulerFormat::t_minor, and wxT().

Here is the call graph for this function:

◆ SetTickSizes()

void BeatsFormat::SetTickSizes ( double  units,
double &  major,
double &  minor,
double &  minorMinor,
int &  mDigits 
) const
overridevirtual

Implements RulerFormat.

Definition at line 16 of file BeatsFormat.cpp.

20{
21 const_cast<BeatsFormat*>(this)->UpdateSubdivision(units);
22
23 major = mTicks.major.duration;
24 minor = mTicks.minor.duration;
25 minorMinor = mTicks.minorMinor.duration;
26
27 mDigits = 0;
28}
void UpdateSubdivision(double units)
Definition: BeatsFormat.cpp:89

References BeatsFormat::Tick::duration, BeatsFormat::Ticks::major, BeatsFormat::Ticks::minor, BeatsFormat::Ticks::minorMinor, mTicks, and UpdateSubdivision().

Here is the call graph for this function:

◆ UpdateSubdivision()

void BeatsFormat::UpdateSubdivision ( double  units)

Definition at line 89 of file BeatsFormat.cpp.

90{
91 Ticks ticks;
92
93 const auto lower = static_cast<double>(mTimeSigLower);
94 if (units < .025 * (60 / mBpm) * (4 / lower))
95 {
96 // measures
97 ticks.major = { mTimeSigUpper, mTimeSigLower,
98 (60 * mTimeSigUpper) / (mBpm * (lower / 4)) };
99 // thirtysecondth notes (label every quarter note)
100 ticks.minor = { 1, 32, 60 / (mBpm * (lower * 2)) };
101 // hundredtwentyeighth notes
102 ticks.minorMinor = { 1, 128, 60 / (mBpm * (lower * 8)) };
103 }
104 else if (units < .05 * (60 / mBpm) * (4 / lower))
105 {
106 // measures
107 ticks.major = { mTimeSigUpper, mTimeSigLower,
108 (60 * mTimeSigUpper) / (mBpm * (lower / 4)) };
109 // sixteenth notes (label every quarter note)
110 ticks.minor = { 1, 16, 60 / (mBpm * (lower)) };
111 // sixtyfourth notes
112 ticks.minorMinor = { 1, 64, 60 / (mBpm * (lower * 4)) };
113 }
114 else if (units < .1 * (60 / mBpm) * (4 / lower))
115 {
116 // measures
117 ticks.major = { mTimeSigUpper, mTimeSigLower,
118 (60 * mTimeSigUpper) / (mBpm * (lower / 4)) };
119 // eigth notes (label every quarter note)
120 ticks.minor = { 1, 8, 60 / (mBpm * (lower / 2)) };
121 // thirtysecondth notes
122 ticks.minorMinor = { 1, 32, 60 / (mBpm * (lower * 2)) };
123 }
124 else if (units < .4 * (60 / mBpm) * (4 / lower))
125 {
126 // measures
127 ticks.major = { mTimeSigUpper, mTimeSigLower,
128 (60 * mTimeSigUpper) / (mBpm * (lower / 4)) };
129 // eigth notes (label every quarter note)
130 ticks.minor = { 1, 8, 60 / (mBpm * (lower / 2)) };
131 // sixteenth notes
132 ticks.minorMinor = { 1, 16, 60 / (mBpm * (lower)) };
133 }
134 else if (units < .8 * (60 / mBpm) * (4 / lower))
135 {
136 // measures
137 ticks.major = { mTimeSigUpper, mTimeSigLower,
138 (60 * mTimeSigUpper) / (mBpm * (lower / 4)) };
139 // quarter notes
140 ticks.minor = { 1, 4, 60 / (mBpm * (lower / 4)) };
141 // sixteenth notes
142 ticks.minorMinor = { 1, 16, 60 / (mBpm * (lower)) };
143 }
144 else if (units < 4 * (60 / mBpm) * (4 / lower))
145 {
146 // measures
147 ticks.major = { mTimeSigUpper, mTimeSigLower,
148 (60 * mTimeSigUpper) / (mBpm * (lower / 4)) };
149 // quarter notes
150 ticks.minorMinor = { 1, 4, 60 / (mBpm * (lower / 4)) };
151 }
152 else if (units < 8 * (60 / mBpm) * (4 / lower))
153 {
154 // four-measures
155 ticks.major = { 4 * mTimeSigUpper, mTimeSigLower,
156 (60 * mTimeSigUpper) / (mBpm * (lower / 16)) };
157 // measures
158 ticks.minor = { 4, mTimeSigLower, 60 / (mBpm * (lower / 16)) };
159 // half measures
160 ticks.minorMinor = { 2, mTimeSigLower, 60 / (mBpm * (lower / 8)) };
161 }
162 else
163 {
164 int factor = pow(
165 2, std::floor(
166 log2(std::ceil(units) * (mBpm / 60) * (mTimeSigLower / 4))) -
167 2);
168 ticks.major = { factor * 4 * mTimeSigUpper, mTimeSigLower,
169 (60 * mTimeSigUpper) / (mBpm * (lower / (16 * factor))) };
170 ticks.minorMinor = { factor * 2, mTimeSigLower,
171 60 / (mBpm * (lower / (8 * factor))) };
172 }
173
174 mTicks = ticks;
175}

References BeatsFormat::Ticks::major, mBpm, BeatsFormat::Ticks::minor, BeatsFormat::Ticks::minorMinor, mTicks, mTimeSigLower, and mTimeSigUpper.

Referenced by SetTickSizes().

Here is the caller graph for this function:

Member Data Documentation

◆ mBpm

double BeatsFormat::mBpm { 60.0 }
private

Definition at line 63 of file BeatsFormat.h.

Referenced by SetData(), SetLabelString(), and UpdateSubdivision().

◆ mTicks

Ticks BeatsFormat::mTicks
private

Definition at line 67 of file BeatsFormat.h.

Referenced by GetSubdivision(), SetTickSizes(), and UpdateSubdivision().

◆ mTimeSigLower

int BeatsFormat::mTimeSigLower { 4 }
private

Definition at line 65 of file BeatsFormat.h.

Referenced by SetData(), SetLabelString(), and UpdateSubdivision().

◆ mTimeSigUpper

int BeatsFormat::mTimeSigUpper { 4 }
private

Definition at line 64 of file BeatsFormat.h.

Referenced by SetData(), SetLabelString(), and UpdateSubdivision().


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