Audacity 3.2.0
MeterPanel.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 MeterPanel.h
6
7 Dominic Mazzoni
8
9 VU Meter, for displaying recording/playback level
10
11 This is a bunch of common code that can display many different
12 forms of VU meters and other displays.
13
14**********************************************************************/
15
16#ifndef __AUDACITY_METER_PANEL__
17#define __AUDACITY_METER_PANEL__
18
19#include <atomic>
20#include <wx/setup.h> // for wxUSE_* macros
21#include <wx/brush.h> // member variable
22#include <wx/defs.h>
23#include <wx/timer.h> // member variable
24
25#include "ASlider.h"
26#include "SampleFormat.h"
27#include "Prefs.h"
28#include "MeterPanelBase.h" // to inherit
29#include "Observer.h"
30#include "Ruler.h" // member variable
31
32class AudacityProject;
33struct AudioIOEvent;
34
35// Increase this when we add support for multichannel meters
36// (most of the code is already there)
37const int kMaxMeterBars = 2;
38
39struct MeterBar {
40 bool vert;
41 wxRect b; // Bevel around bar
42 wxRect r; // True bar drawing area
43 float peak;
44 float rms;
45 float peakHold;
47 wxRect rClip;
49 bool isclipping; //ANSWER-ME: What's the diff between these bools?! "clipping" vs "isclipping" is not clear.
52};
53
55{
56 public:
63
64 /* neither constructor nor destructor do anything */
67 /* for debugging purposes, printing the values out is really handy */
69 wxString toString();
71 wxString toStringIfClipped();
72};
73
74// Thread-safe queue of update messages
76{
77 public:
78 explicit MeterUpdateQueue(size_t maxLen);
80
81 bool Put(MeterUpdateMsg &msg);
82 bool Get(MeterUpdateMsg &msg);
83
84 void Clear();
85
86 private:
87 // Align the two atomics to avoid false sharing
88 // mStart is written only by the reader, mEnd by the writer
90
91 const size_t mBufferSize;
93};
94
95class MeterAx;
96
97/********************************************************************/
101class AUDACITY_DLL_API MeterPanel final
102 : public MeterPanelBase, private PrefsListener
103 , public NonInterferingBase
104{
105 DECLARE_DYNAMIC_CLASS(MeterPanel)
106
107 public:
108 // These should be kept in the same order as they appear
109 // in the menu
110 enum Style {
114 MixerTrackCluster, // Doesn't show menu, icon, or L/R labels, but otherwise like VerticalStereo.
117 };
118
119
121 wxWindow* parent, wxWindowID id,
122 bool isInput,
123 const wxPoint& pos = wxDefaultPosition,
124 const wxSize& size = wxDefaultSize,
125 Style style = HorizontalStereo,
126 float fDecayRate = 60.0f);
127
128 void SetFocusFromKbd() override;
129
130 void Clear() override;
131
132 Style GetStyle() const { return mStyle; }
133 Style GetDesiredStyle() const { return mDesiredStyle; }
134 void SetStyle(Style newStyle);
135
141 void Reset(double sampleRate, bool resetClipping) override;
142
165 void UpdateDisplay(unsigned numChannels,
166 int numFrames, const float *sampleData) override;
167
168 // Vaughan, 2010-11-29: This not currently used. See comments in MixerTrackCluster::UpdateMeter().
169 //void UpdateDisplay(int numChannels, int numFrames,
170 // // Need to make these double-indexed max and min arrays if we handle more than 2 channels.
171 // float* maxLeft, float* rmsLeft,
172 // float* maxRight, float* rmsRight,
173 // const size_t kSampleCount);
174
180 bool IsMeterDisabled() const override;
181
182 float GetMaxPeak() const override;
183 float GetPeakHold() const;
184
185 bool IsMonitoring() const;
186 bool IsActive() const;
187
188 bool IsClipping() const override;
189
190 void StartMonitoring();
191 void StopMonitoring();
192
193 // These exist solely for the purpose of resetting the toolbars
194 struct State{ bool mSaved, mMonitoring, mActive; };
195 State SaveState();
196 void RestoreState(const State &state);
197 void SetMixer(wxCommandEvent& event);
198
199 int GetDBRange() const override { return mDB ? mDBRange : -1; }
200
201 bool ShowDialog();
202 void Increase(float steps);
203 void Decrease(float steps);
204 void UpdateSliderControl();
205
206 void ShowMenu(const wxPoint & pos);
207
208 void SetName(const TranslatableString& name);
209
210 private:
211 void UpdatePrefs() override;
212 void UpdateSelectedPrefs( int ) override;
213
214 private:
215 //
216 // Event handlers
217 //
218 void OnErase(wxEraseEvent &evt);
219 void OnPaint(wxPaintEvent &evt);
220 void OnSize(wxSizeEvent &evt);
221 void OnMouse(wxMouseEvent &evt);
222 void OnKeyDown(wxKeyEvent &evt);
223 void OnCharHook(wxKeyEvent &evt);
224 void OnContext(wxContextMenuEvent &evt);
225 void OnSetFocus(wxFocusEvent &evt);
226 void OnKillFocus(wxFocusEvent &evt);
227
228 void OnAudioIOStatus(AudioIOEvent);
229 void OnAudioCapture(AudioIOEvent);
230
231 void OnMeterUpdate(wxTimerEvent &evt);
232 void OnTipTimeout(wxTimerEvent& evt);
233
234 void HandleLayout(wxDC &dc);
235 void SetActiveStyle(Style style);
236 void SetBarAndClip(int iBar, bool vert);
237 void DrawMeterBar(wxDC &dc, MeterBar *meterBar);
238 void ResetBar(MeterBar *bar, bool resetClipping);
239 void RepaintBarsNow();
240 wxFont GetFont() const;
241
242 //
243 // Pop-up menu
244 //
245 void OnMonitor(wxCommandEvent &evt);
246 void OnPreferences(wxCommandEvent &evt);
247
248 wxString Key(const wxString & key) const;
249
252
255 wxTimer mTimer;
256 wxTimer mTipTimer;
257
260
263
265
269 bool mDB;
271 bool mDecay;
272 float mDecayRate; // dB/sec
273 bool mClip;
276 double mT;
277 double mRate;
279 long mMeterDisabled; //is used as a bool, needs long for easy gPrefs...
280
282
284
285 unsigned mNumBars;
287
289
290 std::unique_ptr<wxBitmap> mBitmap;
293 wxSize mLeftSize;
295 wxPen mPen;
298 wxBrush mBrush;
299 wxBrush mRMSBrush;
300 wxBrush mClipBrush;
301 wxBrush mBkgndBrush;
304 wxString mLeftText;
305 wxString mRightText;
306
307 std::unique_ptr<LWSlider> mSlider;
308 wxPoint mSliderPos;
310
311 bool mEnabled{ true };
312
315
316 friend class MeterAx;
317
318 DECLARE_EVENT_TABLE()
319};
320
321#endif // __AUDACITY_METER_PANEL__
static const AudacityProject::AttachedObjects::RegisteredFactory key
const TranslatableString name
Definition: Distortion.cpp:74
const int kMaxMeterBars
Definition: MeterPanel.h:37
static void OnSize(wxSizeEvent &evt)
Definition: VSTEffect.cpp:2537
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
Inherits wxPanel and has a Meter; exposes shared_ptr to the Meter.
virtual bool IsClipping() const =0
virtual bool IsMeterDisabled() const =0
virtual void UpdateDisplay(unsigned numChannels, int numFrames, const float *sampleData)=0
virtual void Clear()=0
virtual float GetMaxPeak() const =0
virtual void Reset(double sampleRate, bool resetClipping)=0
MeterPanel is a panel that paints the meter used for monitoring or playback.
Definition: MeterPanel.h:104
long mMeterRefreshRate
Definition: MeterPanel.h:278
wxString mRightText
Definition: MeterPanel.h:305
bool mLayoutValid
Definition: MeterPanel.h:288
wxSize mRightSize
Definition: MeterPanel.h:294
Style mStyle
Definition: MeterPanel.h:266
wxPoint mSliderPos
Definition: MeterPanel.h:308
int mRulerHeight
Definition: MeterPanel.h:262
double mRate
Definition: MeterPanel.h:277
Style mDesiredStyle
Definition: MeterPanel.h:267
bool mClip
Definition: MeterPanel.h:273
int mDBRange
Definition: MeterPanel.h:270
Style GetStyle() const
Definition: MeterPanel.h:132
bool mIsInput
Definition: MeterPanel.h:264
int mRulerWidth
Definition: MeterPanel.h:261
Ruler mRuler
Definition: MeterPanel.h:303
Observer::Subscription mAudioCaptureSubscription
Definition: MeterPanel.h:251
wxTimer mTimer
Definition: MeterPanel.h:255
float mDecayRate
Definition: MeterPanel.h:272
wxBrush mDisabledBkgndBrush
Definition: MeterPanel.h:302
bool mDecay
Definition: MeterPanel.h:271
double mPeakHoldDuration
Definition: MeterPanel.h:275
std::unique_ptr< LWSlider > mSlider
Definition: MeterPanel.h:307
double mT
Definition: MeterPanel.h:276
wxString mLeftText
Definition: MeterPanel.h:304
AudacityProject * mProject
Definition: MeterPanel.h:253
unsigned mNumBars
Definition: MeterPanel.h:285
wxBrush mBkgndBrush
Definition: MeterPanel.h:301
bool mMonitoring
Definition: MeterPanel.h:281
bool mGradient
Definition: MeterPanel.h:268
bool mActive
Definition: MeterPanel.h:283
Style GetDesiredStyle() const
Definition: MeterPanel.h:133
wxBrush mBrush
Definition: MeterPanel.h:298
Observer::Subscription mAudioIOStatusSubscription
Definition: MeterPanel.h:250
std::unique_ptr< wxBitmap > mBitmap
Definition: MeterPanel.h:290
wxPoint mLeftTextPos
Definition: MeterPanel.h:291
wxTimer mTipTimer
Definition: MeterPanel.h:256
wxSize mLeftSize
Definition: MeterPanel.h:293
wxPen mPeakPeakPen
Definition: MeterPanel.h:297
wxPoint mRightTextPos
Definition: MeterPanel.h:292
wxRect mFocusRect
Definition: MeterPanel.h:314
int mNumPeakSamplesToClip
Definition: MeterPanel.h:274
@ HorizontalStereoCompact
Definition: MeterPanel.h:115
@ AutomaticStereo
Definition: MeterPanel.h:111
@ HorizontalStereo
Definition: MeterPanel.h:112
@ VerticalStereo
Definition: MeterPanel.h:113
@ VerticalStereoCompact
Definition: MeterPanel.h:116
@ MixerTrackCluster
Definition: MeterPanel.h:114
wxSize mSliderSize
Definition: MeterPanel.h:309
int GetDBRange() const override
Definition: MeterPanel.h:199
wxBrush mClipBrush
Definition: MeterPanel.h:300
wxPen mPen
Definition: MeterPanel.h:295
bool mIsFocused
Definition: MeterPanel.h:313
MeterUpdateQueue mQueue
Definition: MeterPanel.h:254
long mMeterDisabled
Definition: MeterPanel.h:279
wxBrush mRMSBrush
Definition: MeterPanel.h:299
wxPen mDisabledPen
Definition: MeterPanel.h:296
Message used to update the MeterPanel.
Definition: MeterPanel.h:55
bool clipping[kMaxMeterBars]
Definition: MeterPanel.h:60
float peak[kMaxMeterBars]
Definition: MeterPanel.h:58
int tailPeakCount[kMaxMeterBars]
Definition: MeterPanel.h:62
int headPeakCount[kMaxMeterBars]
Definition: MeterPanel.h:61
wxString toStringIfClipped()
Only print meter updates if clipping may be happening.
Definition: MeterPanel.cpp:172
wxString toString()
Print out all the values in the meter update message.
Definition: MeterPanel.cpp:155
float rms[kMaxMeterBars]
Definition: MeterPanel.h:59
Queue of MeterUpdateMsg used to feed the MeterPanel.
Definition: MeterPanel.h:76
bool Put(MeterUpdateMsg &msg)
Definition: MeterPanel.cpp:207
ArrayOf< MeterUpdateMsg > mBuffer
Definition: MeterPanel.h:92
NonInterfering< std::atomic< size_t > > mEnd
Definition: MeterPanel.h:89
NonInterfering< std::atomic< size_t > > mStart
Definition: MeterPanel.h:89
MeterUpdateQueue(size_t maxLen)
Definition: MeterPanel.cpp:188
const size_t mBufferSize
Definition: MeterPanel.h:91
bool Get(MeterUpdateMsg &msg)
Definition: MeterPanel.cpp:230
A move-only handle representing a connection to a Publisher.
Definition: Observer.h:70
A listener notified of changes in preferences.
Definition: Prefs.h:556
virtual void UpdateSelectedPrefs(int id)
Definition: Prefs.cpp:127
Used to display a Ruler.
Definition: Ruler.h:26
Holds a msgid for the translation catalog; may also bind format arguments.
AUDACITY_DLL_API void UpdatePrefs(wxWindow *pParent)
void OnPreferences(const CommandContext &context)
Definition: EditMenus.cpp:958
A struct used by MeterPanel to hold the position of one bar.
Definition: MeterPanel.h:39
wxRect rClip
Definition: MeterPanel.h:47
bool isclipping
Definition: MeterPanel.h:49
float peakPeakHold
Definition: MeterPanel.h:51
float peak
Definition: MeterPanel.h:43
int tailPeakCount
Definition: MeterPanel.h:50
float rms
Definition: MeterPanel.h:44
bool vert
Definition: MeterPanel.h:40
wxRect b
Definition: MeterPanel.h:41
bool clipping
Definition: MeterPanel.h:48
double peakHoldTime
Definition: MeterPanel.h:46
wxRect r
Definition: MeterPanel.h:42
float peakHold
Definition: MeterPanel.h:45