MCPcopy Create free account
hub / github.com/audacity/audacity / Update

Method Update

src/widgets/LogarithmicUpdater.cpp:21–130  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19}
20
21void LogarithmicUpdater::Update(
22 wxDC& dc, const Envelope* envelope,
23 UpdateOutputs& allOutputs, const RulerStruct& context) const
24{
25 TickOutputs majorOutputs{
26 allOutputs.majorLabels, allOutputs.bits, allOutputs.box };
27
28 const int mLength = context.mLength;
29
30 const int mOrientation = context.mOrientation;
31
32 const double mMin = context.mMin;
33 const double mMax = context.mMax;
34 const double mHiddenMin = context.mHiddenMin;
35 const double mHiddenMax = context.mHiddenMax;
36
37 const RulerStruct::Fonts& mFonts = *context.mpFonts;
38 const NumberScale mNumberScale = context.mNumberScale;
39
40 auto numberScale = (mNumberScale == NumberScale{})
41 ? NumberScale(nstLogarithmic, mMin, mMax)
42 : mNumberScale;
43
44 double UPP = (mHiddenMax - mHiddenMin) / mLength; // Units per pixel
45 TickSizes tickSizes{ UPP, mOrientation, context.mpRulerFormat, true };
46
47 tickSizes.mDigits = 2; //TODO: implement dynamic digit computation
48
49 double loLog = log10(mMin);
50 double hiLog = log10(mMax);
51 int loDecade = (int)floor(loLog);
52
53 double val;
54 double startDecade = pow(10., (double)loDecade);
55
56 // Major ticks are the decades
57 double decade = startDecade;
58 double delta = hiLog - loLog, steps = fabs(delta);
59 double step = delta >= 0 ? 10 : 0.1;
60 double rMin = std::min(mMin, mMax), rMax = std::max(mMin, mMax);
61 for (int i = 0; i <= steps; i++)
62 { // if(i!=0)
63 { val = decade;
64 if (val >= rMin && val < rMax) {
65 const int pos(0.5 + mLength * numberScale.ValueToPosition(val));
66 Tick(dc, pos, val, tickSizes, mFonts.major, majorOutputs, context);
67 }
68 }
69 decade *= step;
70 }
71
72 // Minor ticks are multiples of decades
73 decade = startDecade;
74 float start, end, mstep;
75 if (delta > 0)
76 {
77 start = 2; end = 10; mstep = 1;
78 }

Callers

nothing calls this directly

Calls 6

maxFunction · 0.85
TickClass · 0.85
NumberScaleClass · 0.50
minFunction · 0.50
InstanceClass · 0.50
ValueToPositionMethod · 0.45

Tested by

no test coverage detected