Audacity 3.2.0
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
CompressionMeterPanel Class Referencefinal

#include <CompressionMeterPanel.h>

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

Public Member Functions

 CompressionMeterPanel (wxWindow *parent, int id, CompressorInstance &instance, float dbRange, std::function< void()> onClipped)
 
void SetDbRange (float dbRange)
 
void Reset ()
 
void ResetClipped ()
 
- Public Member Functions inherited from wxPanelWrapper
 wxPanelWrapper ()
 
 wxPanelWrapper (wxWindow *parent, wxWindowID winid=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL|wxNO_BORDER, const TranslatableString &name=XO("Panel"))
 
bool Create (wxWindow *parent, wxWindowID winid=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL|wxNO_BORDER, const TranslatableString &name=XO("Panel"))
 
void SetLabel (const TranslatableString &label)
 
void SetName (const TranslatableString &name)
 
void SetToolTip (const TranslatableString &toolTip)
 
void SetName ()
 
- Public Member Functions inherited from wxTabTraversalWrapper< wxPanel >
 wxTabTraversalWrapper (Args &&... args)
 
 wxTabTraversalWrapper (const wxTabTraversalWrapper &)=delete
 
 wxTabTraversalWrapper (wxTabTraversalWrapper &&)=delete
 
wxTabTraversalWrapperoperator= (const wxTabTraversalWrapper &)=delete
 
wxTabTraversalWrapperoperator= (wxTabTraversalWrapper &&)=delete
 

Protected Member Functions

 DECLARE_EVENT_TABLE ()
 

Private Member Functions

void PaintMeter (wxPaintDC &dc, const wxColor &color, const wxRect &rect, const MeterValueProvider &provider)
 
void OnPaint (wxPaintEvent &evt)
 
void OnTimer (wxTimerEvent &evt)
 
bool AcceptsFocus () const override
 
bool AcceptsFocusFromKeyboard () const override
 

Private Attributes

const std::shared_ptr< DynamicRangeProcessorMeterValuesQueuemMeterValuesQueue
 
const Observer::Subscription mPlaybackStartStopSubscription
 
const Observer::Subscription mPlaybackPausedSubscription
 
const std::function< void()> mOnClipped
 
std::unique_ptr< MeterValueProvidermCompressionMeter
 
std::unique_ptr< MeterValueProvidermOutputMeter
 
float mDbBottomEdgeValue
 
wxTimer mTimer
 
bool mStopWhenZero = false
 
bool mClipped = false
 

Detailed Description

Definition at line 25 of file CompressionMeterPanel.h.

Constructor & Destructor Documentation

◆ CompressionMeterPanel()

CompressionMeterPanel::CompressionMeterPanel ( wxWindow *  parent,
int  id,
CompressorInstance instance,
float  dbRange,
std::function< void()>  onClipped 
)

Definition at line 38 of file CompressionMeterPanel.cpp.

41 : wxPanelWrapper { parent, id }
42 , mMeterValuesQueue { std::make_unique<
44 , mPlaybackStartStopSubscription { static_cast<
46 instance)
47 .Subscribe(
48 [&](const std::optional<
50 evt) {
51 if (evt)
52 Reset();
53 else
54 mStopWhenZero = true;
55 }) }
57 [this](const AudioIOEvent& evt) {
58 if (evt.type != AudioIOEvent::PAUSE)
59 return;
60 if (evt.on)
61 mTimer.Stop();
62 else
64 }) }
65 , mOnClipped { onClipped }
66 , mDbBottomEdgeValue { -dbRange }
71{
72 if (instance.GetSampleRate().has_value())
73 // Playback is ongoing, and so the `InitializeProcessingSettings` event
74 // was already fired.
75 Reset();
77 mTimer.SetOwner(this, timerId);
78 SetDoubleBuffered(true);
79}
static constexpr auto compressorMeterUpdatePeriodMs
static AudioIO * Get()
Definition: AudioIO.cpp:126
const std::function< void()> mOnClipped
std::unique_ptr< MeterValueProvider > mCompressionMeter
std::unique_ptr< MeterValueProvider > mOutputMeter
const Observer::Subscription mPlaybackStartStopSubscription
const Observer::Subscription mPlaybackPausedSubscription
const std::shared_ptr< DynamicRangeProcessorMeterValuesQueue > mMeterValuesQueue
void SetMeterValuesQueue(std::weak_ptr< DynamicRangeProcessorMeterValuesQueue > queue)
const std::optional< double > & GetSampleRate() const
static std::unique_ptr< MeterValueProvider > Create(Direction direction)
An object that sends messages to an open-ended list of subscribed callbacks.
Definition: Observer.h:108
Subscription Subscribe(Callback callback)
Connect a callback to the Publisher; later-connected are called earlier.
Definition: Observer.h:199
bool on
Definition: AudioIO.h:68
enum AudioIOEvent::Type type

Member Function Documentation

◆ AcceptsFocus()

bool CompressionMeterPanel::AcceptsFocus ( ) const
overrideprivate

Definition at line 218 of file CompressionMeterPanel.cpp.

219{
220 return false;
221}

◆ AcceptsFocusFromKeyboard()

bool CompressionMeterPanel::AcceptsFocusFromKeyboard ( ) const
overrideprivate

Definition at line 223 of file CompressionMeterPanel.cpp.

224{
225 return false;
226}

◆ DECLARE_EVENT_TABLE()

CompressionMeterPanel::DECLARE_EVENT_TABLE ( )
protected

◆ OnPaint()

void CompressionMeterPanel::OnPaint ( wxPaintEvent &  evt)
private

Definition at line 103 of file CompressionMeterPanel.cpp.

104{
105 using namespace DynamicRangeProcessorPanel;
106
107 wxPaintDC dc(this);
108
109 const auto rect = DynamicRangeProcessorPanel::GetPanelRect(*this);
110 const auto gc = MakeGraphicsContext(dc);
111 const auto left = rect.GetLeft();
112 const auto top = rect.GetTop();
113 const auto width = rect.GetWidth();
114 const auto height = rect.GetHeight();
115
116 gc->SetPen(*wxTRANSPARENT_PEN);
117 gc->SetBrush(GetGraphBackgroundBrush(*gc, height));
118 gc->DrawRectangle(left, top, width, height);
119
120 auto leftRect = rect;
121 leftRect.SetWidth(rect.GetWidth() / 2 - 2);
122 leftRect.Offset(1, 0);
124
125 auto rightRect = leftRect;
126 rightRect.Offset(leftRect.GetWidth(), 0);
127 PaintMeter(dc, outputColor, rightRect, *mOutputMeter);
128
129 gc->SetPen(lineColor);
130 gc->SetBrush(wxNullBrush);
131 gc->DrawRectangle(left, top, width, height);
132}
void PaintMeter(wxPaintDC &dc, const wxColor &color, const wxRect &rect, const MeterValueProvider &provider)
std::unique_ptr< wxGraphicsContext > MakeGraphicsContext(const wxPaintDC &dc)
wxRect GetPanelRect(const wxPanelWrapper &panel)
wxGraphicsBrush GetGraphBackgroundBrush(wxGraphicsContext &gc, int height)

References DynamicRangeProcessorPanel::actualCompressionColor, DynamicRangeProcessorPanel::GetGraphBackgroundBrush(), DynamicRangeProcessorPanel::GetPanelRect(), DynamicRangeProcessorPanel::lineColor, DynamicRangeProcessorPanel::MakeGraphicsContext(), mCompressionMeter, mOutputMeter, DynamicRangeProcessorPanel::outputColor, and PaintMeter().

Here is the call graph for this function:

◆ OnTimer()

void CompressionMeterPanel::OnTimer ( wxTimerEvent &  evt)
private

Definition at line 181 of file CompressionMeterPanel.cpp.

182{
183 // Take the max of all values newly pushed by the audio frames - make sure we
184 // don't miss a peak.
186 auto lowestCompressionGain = 0.f;
187 auto highestOutputGain = std::numeric_limits<float>::lowest();
188 while (mMeterValuesQueue->Get(values))
189 {
190 lowestCompressionGain =
191 std::min(values.compressionGainDb, lowestCompressionGain);
192 highestOutputGain = std::max(values.outputDb, highestOutputGain);
193 }
194
195 const auto updateFiveSecondMax = !mStopWhenZero;
196 mCompressionMeter->Update(lowestCompressionGain, updateFiveSecondMax);
197 mOutputMeter->Update(highestOutputGain, updateFiveSecondMax);
198 const auto clipped = mOutputMeter->GetCurrentMax() > 0;
199 if (clipped && !mClipped)
200 {
201 mOnClipped();
202 mClipped = true;
203 }
204
205 Refresh(false);
206
207 if (
208 mCompressionMeter->IsInvisible() && mOutputMeter->IsInvisible() &&
210 {
211 // Decay is complete. Until playback starts again, no need for
212 // timer-triggered updates.
213 mTimer.Stop();
214 mStopWhenZero = false;
215 }
216}
int min(int a, int b)
const wxChar * values

References mClipped, mCompressionMeter, min(), mMeterValuesQueue, mOnClipped, mOutputMeter, mStopWhenZero, mTimer, and values.

Here is the call graph for this function:

◆ PaintMeter()

void CompressionMeterPanel::PaintMeter ( wxPaintDC &  dc,
const wxColor &  color,
const wxRect &  rect,
const MeterValueProvider provider 
)
private

Definition at line 134 of file CompressionMeterPanel.cpp.

137{
138 const auto dB = provider.GetCurrentMax();
139 const auto maxDb = provider.GetGlobalMax();
140 const auto fiveSecMaxDb = provider.GetFiveSecMax();
141 const auto downwards =
143
144 const auto gc = MakeGraphicsContext(dc);
145
146 const double left = rect.GetLeft();
147 const double top = rect.GetTop();
148 const double width = rect.GetWidth();
149 const double height = rect.GetHeight();
150
151 constexpr auto lineWidth = 6.;
152
153 const double dbFrac = std::clamp<double>(dB / mDbBottomEdgeValue, 0., 1.);
154 // So that the top of the cap is aligned with the dB value.
155 const auto yAdjust = lineWidth / 2 * (downwards ? -1 : 1);
156 const double dbY = height * dbFrac + yAdjust;
157 const double maxDbY = maxDb / mDbBottomEdgeValue * height + yAdjust;
158 const double fiveSecMaxDbY =
159 fiveSecMaxDb / mDbBottomEdgeValue * height + yAdjust;
160
161 const auto levelTop = downwards ? top : dbY;
162 const auto levelHeight = downwards ? dbY : height - dbY;
163 const auto maxLevelTop = downwards ? levelHeight - top : maxDbY;
164 const auto maxLevelHeight = std::abs(maxDbY - dbY);
165
166 const auto rectLeft = left + 3;
167 const auto rectWidth = width - 4;
168 const auto opaqueColor = wxColor { color.GetRGB() };
169 gc->SetBrush(GetColorMix(opaqueColor, wxTransparentColor, 0.8));
170 gc->DrawRectangle(rectLeft, levelTop, rectWidth, levelHeight);
171 gc->SetBrush(GetColorMix(opaqueColor, wxTransparentColor, 0.6));
172 gc->DrawRectangle(rectLeft, maxLevelTop, rectWidth, maxLevelHeight);
173 gc->SetBrush(opaqueColor);
174 gc->DrawRectangle(rectLeft, dbY - 2, rectWidth, lineWidth);
175 gc->DrawRectangle(rectLeft, maxDbY - 2, rectWidth, lineWidth);
176 gc->SetPen({ opaqueColor, static_cast<int>(lineWidth / 2) });
177 gc->StrokeLine(
178 left + rectWidth / 2, fiveSecMaxDbY, left + rectWidth, fiveSecMaxDbY);
179}
virtual float GetCurrentMax() const =0
virtual float GetGlobalMax() const =0
virtual float GetFiveSecMax() const =0
virtual Direction GetDirection() const =0
wxColor GetColorMix(const wxColor &a, const wxColor &b, double aWeight)

References MeterValueProvider::Downwards, DynamicRangeProcessorPanel::GetColorMix(), MeterValueProvider::GetCurrentMax(), MeterValueProvider::GetDirection(), MeterValueProvider::GetFiveSecMax(), MeterValueProvider::GetGlobalMax(), DynamicRangeProcessorPanel::MakeGraphicsContext(), and mDbBottomEdgeValue.

Referenced by OnPaint().

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

◆ Reset()

void CompressionMeterPanel::Reset ( )

Definition at line 87 of file CompressionMeterPanel.cpp.

References compressorMeterUpdatePeriodMs, MeterValueProvider::Create(), MeterValueProvider::Downwards, mClipped, mCompressionMeter, mOutputMeter, mStopWhenZero, mTimer, and MeterValueProvider::Upwards.

Here is the call graph for this function:

◆ ResetClipped()

void CompressionMeterPanel::ResetClipped ( )

Definition at line 98 of file CompressionMeterPanel.cpp.

99{
100 mClipped = false;
101}

References mClipped.

◆ SetDbRange()

void CompressionMeterPanel::SetDbRange ( float  dbRange)

Definition at line 81 of file CompressionMeterPanel.cpp.

82{
83 mDbBottomEdgeValue = -dbRange;
84 Refresh(true);
85}

References mDbBottomEdgeValue.

Member Data Documentation

◆ mClipped

bool CompressionMeterPanel::mClipped = false
private

Definition at line 62 of file CompressionMeterPanel.h.

Referenced by OnTimer(), Reset(), and ResetClipped().

◆ mCompressionMeter

std::unique_ptr<MeterValueProvider> CompressionMeterPanel::mCompressionMeter
private

Definition at line 56 of file CompressionMeterPanel.h.

Referenced by OnPaint(), OnTimer(), and Reset().

◆ mDbBottomEdgeValue

float CompressionMeterPanel::mDbBottomEdgeValue
private

Definition at line 58 of file CompressionMeterPanel.h.

Referenced by PaintMeter(), and SetDbRange().

◆ mMeterValuesQueue

const std::shared_ptr<DynamicRangeProcessorMeterValuesQueue> CompressionMeterPanel::mMeterValuesQueue
private

Definition at line 52 of file CompressionMeterPanel.h.

Referenced by OnTimer().

◆ mOnClipped

const std::function<void()> CompressionMeterPanel::mOnClipped
private

Definition at line 55 of file CompressionMeterPanel.h.

Referenced by OnTimer().

◆ mOutputMeter

std::unique_ptr<MeterValueProvider> CompressionMeterPanel::mOutputMeter
private

Definition at line 57 of file CompressionMeterPanel.h.

Referenced by OnPaint(), OnTimer(), and Reset().

◆ mPlaybackPausedSubscription

const Observer::Subscription CompressionMeterPanel::mPlaybackPausedSubscription
private

Definition at line 54 of file CompressionMeterPanel.h.

◆ mPlaybackStartStopSubscription

const Observer::Subscription CompressionMeterPanel::mPlaybackStartStopSubscription
private

Definition at line 53 of file CompressionMeterPanel.h.

◆ mStopWhenZero

bool CompressionMeterPanel::mStopWhenZero = false
private

Definition at line 61 of file CompressionMeterPanel.h.

Referenced by OnTimer(), and Reset().

◆ mTimer

wxTimer CompressionMeterPanel::mTimer
private

Definition at line 60 of file CompressionMeterPanel.h.

Referenced by OnTimer(), and Reset().


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