Audacity 3.2.0
LinearDBFormat.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 LinearDBFormat.cpp
6
7 Dominic Mazzoni
8 Michael Papadopoulos split from Ruler.h
9
10**********************************************************************/
11
12#include "LinearDBFormat.h"
13
15{
16 static LinearDBFormat instance;
17 return instance;
18}
19
21 double units, double& major, double& minor, double& minorMinor,
22 int& mDigits
23) const
24{
25 if (units < 0.001) {
26 minor = 0.001;
27 major = 0.005;
28 return;
29 }
30 if (units < 0.01) {
31 minor = 0.01;
32 major = 0.05;
33 return;
34 }
35 if (units < 0.1) {
36 minor = 0.1;
37 major = 0.5;
38 return;
39 }
40 if (units < 1.0) {
41 minor = 1.0;
42 major = 6.0;
43 return;
44 }
45 if (units < 3.0) {
46 minor = 3.0;
47 major = 12.0;
48 return;
49 }
50 if (units < 6.0) {
51 minor = 6.0;
52 major = 24.0;
53 return;
54 }
55 if (units < 12.0) {
56 minor = 12.0;
57 major = 48.0;
58 return;
59 }
60 if (units < 24.0) {
61 minor = 24.0;
62 major = 96.0;
63 return;
64 }
65 double d = 20.0;
66 for (;;) {
67 if (units < d) {
68 minor = d;
69 major = d * 5.0;
70 return;
71 }
72 d *= 5.0;
73 if (units < d) {
74 minor = d;
75 major = d * 5.0;
76 return;
77 }
78 d *= 2.0;
79 }
80}
81
83 wxString& s, double d, double, double mMinor, int mDigits, TickType tickType
84) const
85{
86 // Replace -0 with 0
87 if (d < 0.0 && (d + mMinor > 0.0))
88 d = 0.0;
89 if (mMinor >= 1.0)
90 s.Printf(wxT("%d"), (int)floor(d + 0.5));
91 else {
92 int precision = -log10(mMinor);
93 s.Printf(wxT("%.*f"), precision, d);
94 }
95}
96
wxT("CloseDown"))
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
~LinearDBFormat() override
static const LinearDBFormat & Instance()