Audacity 3.2.0
Functions
anonymous_namespace{ClipPitchAndSpeedButtonHandle.cpp} Namespace Reference

Functions

wxString GetPitchShiftText (int clipCentShift)
 
wxString GetPlaybackSpeedText (double clipStretchRatio)
 
void DrawPitchOrSpeedIconIfItFits (wxDC &dc, const wxRect &rect, const wxBitmap &icon, const wxString &text)
 

Detailed Description


Audacity: A Digital Audio Editor

ClipPitchAndSpeedButtonHandle.cpp

Matthieu Hodgkinson

Function Documentation

◆ DrawPitchOrSpeedIconIfItFits()

void anonymous_namespace{ClipPitchAndSpeedButtonHandle.cpp}::DrawPitchOrSpeedIconIfItFits ( wxDC &  dc,
const wxRect &  rect,
const wxBitmap &  icon,
const wxString &  text 
)

Definition at line 87 of file ClipPitchAndSpeedButtonHandle.cpp.

89{
90 const auto textExtent = dc.GetTextExtent(text);
91 const auto textWidth = textExtent.GetWidth();
92 const auto textHeight = textExtent.GetHeight();
93
94 const auto iconHeight = icon.GetHeight();
95 const auto iconWidth = textWidth == 0 ? 0 : icon.GetWidth();
96 const auto contentWidth = iconWidth + textWidth;
97 if (contentWidth == 0 || contentWidth > rect.width)
98 return;
99 const auto height = rect.GetHeight();
100 const auto iconTop = rect.GetTop() + (height - iconHeight) / 2;
101 const auto x = rect.x + (rect.width - contentWidth) / 2;
102 dc.DrawBitmap(icon, x, iconTop);
103 const auto y = rect.GetTop() + (height - textHeight) / 2;
104 dc.DrawText(text, x + iconWidth, y);
105}

Referenced by ClipButtonSpecializations< ClipButtonId::Pitch >::DrawOnClip(), and ClipButtonSpecializations< ClipButtonId::Speed >::DrawOnClip().

Here is the caller graph for this function:

◆ GetPitchShiftText()

wxString anonymous_namespace{ClipPitchAndSpeedButtonHandle.cpp}::GetPitchShiftText ( int  clipCentShift)

Definition at line 32 of file ClipPitchAndSpeedButtonHandle.cpp.

33{
34 wxString pitchShiftText;
35 if (clipCentShift != 0)
36 {
37 pitchShiftText = wxString::Format("%.2f", std::abs(clipCentShift) / 100.);
38 while (pitchShiftText.EndsWith("0"))
39 pitchShiftText.RemoveLast();
40 if (pitchShiftText.EndsWith(".") || pitchShiftText.EndsWith(","))
41 pitchShiftText.RemoveLast();
42 }
43 return pitchShiftText;
44}

Referenced by ClipButtonSpecializations< ClipButtonId::Pitch >::DrawOnClip().

Here is the caller graph for this function:

◆ GetPlaybackSpeedText()

wxString anonymous_namespace{ClipPitchAndSpeedButtonHandle.cpp}::GetPlaybackSpeedText ( double  clipStretchRatio)

Definition at line 46 of file ClipPitchAndSpeedButtonHandle.cpp.

47{
48 if (TimeAndPitchInterface::IsPassThroughMode(clipStretchRatio))
49 return {};
50
51 // clang-format off
52 // We reckon that most of the time, a rounded percentage value is sufficient.
53 // There are two exceptions:
54 // - The clip is only slightly stretched such that the rounded value is 100.
55 // There should be an indicator if and only if the clip is stretched, this
56 // must be reliable. Yet showing "100%" would be confusing. Hence in that
57 // case we constrain the values to [99.1, ..., 99.9, 100.1,
58 // ..., 100.9], i.e., omitting 100.0.
59 // - The clip is stretched so much that the playback speed is less than 1%.
60 // Make sure in that case that we never show 0%, but always at least 0.1%.
61 // clang-format on
62
63 const auto playbackSpeed = 100 / clipStretchRatio;
64 wxString fullText;
65
66 // We compare with .95 rather than 1, since playback speeds within [100.95,
67 // 101) get rounded to 101.0 and (99, 99.05] to 99.0 by `wxString::Format`.
68 // Let these be processed by the integer-display branch of this if statement
69 // instead.
70 if (fabs(playbackSpeed - 100.) < .95)
71 // Never show 100.0%
72 fullText += wxString::Format(
73 "%.1f%%", playbackSpeed > 100 ? std::max(playbackSpeed, 100.1) :
74 std::min(playbackSpeed, 99.9));
75 else if (playbackSpeed < 1)
76 // Never show 0.0%
77 fullText += wxString::Format("%.1f%%", std::max(playbackSpeed, 0.1));
78 else
79 {
80 const auto roundedPlaybackSpeed =
81 static_cast<int>(std::round(playbackSpeed));
82 fullText += wxString::Format("%d%%", roundedPlaybackSpeed);
83 }
84 return fullText;
85}
int min(int a, int b)
static bool IsPassThroughMode(double stretchRatio)
fastfloat_really_inline void round(adjusted_mantissa &am, callback cb) noexcept
Definition: fast_float.h:2512

References TimeAndPitchInterface::IsPassThroughMode(), min(), and fast_float::round().

Referenced by ClipButtonSpecializations< ClipButtonId::Speed >::DrawOnClip().

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