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 "LockFreeQueue.h"
27#include "MeterPanelBase.h" // to inherit
28#include "Observer.h"
29#include "Prefs.h"
30#include "Ruler.h" // member variable
31#include "SampleFormat.h"
32
33class AudacityProject;
34struct AudioIOEvent;
35
36// Increase this when we add support for multichannel meters
37// (most of the code is already there)
38const int kMaxMeterBars = 2;
39
40struct MeterBar {
41 bool vert;
42 wxRect b; // Bevel around bar
43 wxRect r; // True bar drawing area
44 float peak;
45 float rms;
46 float peakHold;
48 wxRect rClip;
50 bool isclipping; //ANSWER-ME: What's the diff between these bools?! "clipping" vs "isclipping" is not clear.
53};
54
56{
57 public:
64
65 /* neither constructor nor destructor do anything */
68 /* for debugging purposes, printing the values out is really handy */
70 wxString toString();
72 wxString toStringIfClipped();
73};
74
75//
76// The MeterPanel passes itself messages via this queue so that it can
77// communicate between the audio thread and the GUI thread.
78// This class uses lock-free synchronization with atomics.
79//
81
82class MeterAx;
83
84/********************************************************************/
88class AUDACITY_DLL_API MeterPanel final
89 : public MeterPanelBase, private PrefsListener
90 , public NonInterferingBase
91{
92 DECLARE_DYNAMIC_CLASS(MeterPanel)
93
94 public:
95 // These should be kept in the same order as they appear
96 // in the menu
97 enum Style {
101 MixerTrackCluster, // Doesn't show menu, icon, or L/R labels, but otherwise like VerticalStereo.
104 };
105
106
108 wxWindow* parent, wxWindowID id,
109 bool isInput,
110 const wxPoint& pos = wxDefaultPosition,
111 const wxSize& size = wxDefaultSize,
112 Style style = HorizontalStereo,
113 float fDecayRate = 60.0f);
114
115 void SetFocusFromKbd() override;
116
117 void Clear() override;
118
119 Style GetStyle() const { return mStyle; }
120 Style GetDesiredStyle() const { return mDesiredStyle; }
121 void SetStyle(Style newStyle);
122
128 void Reset(double sampleRate, bool resetClipping) override;
129
152 void UpdateDisplay(unsigned numChannels,
153 int numFrames, const float *sampleData) override;
154
155 // Vaughan, 2010-11-29: This not currently used. See comments in MixerTrackCluster::UpdateMeter().
156 //void UpdateDisplay(int numChannels, int numFrames,
157 // // Need to make these double-indexed max and min arrays if we handle more than 2 channels.
158 // float* maxLeft, float* rmsLeft,
159 // float* maxRight, float* rmsRight,
160 // const size_t kSampleCount);
161
167 bool IsMeterDisabled() const override;
168
169 float GetMaxPeak() const override;
170 float GetPeakHold() const;
171
172 bool IsMonitoring() const;
173 bool IsActive() const;
174
175 bool IsClipping() const override;
176
177 void StartMonitoring();
178 void StopMonitoring();
179
180 // These exist solely for the purpose of resetting the toolbars
181 struct State{ bool mSaved, mMonitoring, mActive; };
182 State SaveState();
183 void RestoreState(const State &state);
184 void SetMixer(wxCommandEvent& event);
185
186 int GetDBRange() const override { return mDB ? mDBRange : -1; }
187
188 bool ShowDialog();
189 void Increase(float steps);
190 void Decrease(float steps);
191 void UpdateSliderControl();
192
193 void ShowMenu(const wxPoint & pos);
194
195 void SetName(const TranslatableString& name);
196
197 private:
198 void UpdatePrefs() override;
199 void UpdateSelectedPrefs( int ) override;
200
201 private:
202 //
203 // Event handlers
204 //
205 void OnErase(wxEraseEvent &evt);
206 void OnPaint(wxPaintEvent &evt);
207 void OnSize(wxSizeEvent &evt);
208 void OnMouse(wxMouseEvent &evt);
209 void OnKeyDown(wxKeyEvent &evt);
210 void OnCharHook(wxKeyEvent &evt);
211 void OnContext(wxContextMenuEvent &evt);
212 void OnSetFocus(wxFocusEvent &evt);
213 void OnKillFocus(wxFocusEvent &evt);
214
215 void OnAudioIOStatus(AudioIOEvent);
216 void OnAudioCapture(AudioIOEvent);
217
218 void OnMeterUpdate(wxTimerEvent &evt);
219 void OnTipTimeout(wxTimerEvent& evt);
220
221 void HandleLayout(wxDC &dc);
222 void SetActiveStyle(Style style);
223 void SetBarAndClip(int iBar, bool vert);
224 void DrawMeterBar(wxDC &dc, MeterBar *meterBar);
225 void ResetBar(MeterBar *bar, bool resetClipping);
226 void RepaintBarsNow();
227 wxFont GetFont() const;
228
229 //
230 // Pop-up menu
231 //
232 void OnMonitor(wxCommandEvent &evt);
233 void OnPreferences(wxCommandEvent &evt);
234
235 wxString Key(const wxString & key) const;
236
239
242 wxTimer mTimer;
243 wxTimer mTipTimer;
244
247
248 int mRulerWidth{};
249 int mRulerHeight{};
250
252
253 Style mStyle{};
256 bool mDB;
258 bool mDecay;
259 float mDecayRate{}; // dB/sec
260 bool mClip;
263 double mT;
264 double mRate;
265 long mMeterRefreshRate{};
266 long mMeterDisabled{}; //is used as a bool, needs long for easy gPrefs...
267
269
271
272 unsigned mNumBars;
274
276
277 std::unique_ptr<wxBitmap> mBitmap;
280 wxSize mLeftSize;
282 wxPen mPen;
284 wxBrush mBrush;
285 wxBrush mRMSBrush;
286 wxBrush mClipBrush;
287 wxBrush mBkgndBrush;
291 wxString mLeftText;
292 wxString mRightText;
293
294 std::unique_ptr<LWSlider> mSlider;
295 wxPoint mSliderPos;
297
298 bool mEnabled{ true };
299
300 bool mIsFocused{};
302
303 friend class MeterAx;
304
305 DECLARE_EVENT_TABLE()
306};
307
308#endif // __AUDACITY_METER_PANEL__
const int kMaxMeterBars
Definition: MeterPanel.h:38
static const AudacityProject::AttachedObjects::RegisteredFactory key
wxString name
Definition: TagsEditor.cpp:166
static void OnSize(wxSizeEvent &evt)
Definition: VSTEditor.cpp:224
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:91
wxString mRightText
Definition: MeterPanel.h:292
bool mLayoutValid
Definition: MeterPanel.h:275
wxSize mRightSize
Definition: MeterPanel.h:281
wxPoint mSliderPos
Definition: MeterPanel.h:295
wxBrush mMeterBkgndBrush
Definition: MeterPanel.h:289
double mRate
Definition: MeterPanel.h:264
Style mDesiredStyle
Definition: MeterPanel.h:254
bool mClip
Definition: MeterPanel.h:260
int mDBRange
Definition: MeterPanel.h:257
Style GetStyle() const
Definition: MeterPanel.h:119
bool mIsInput
Definition: MeterPanel.h:251
Ruler mRuler
Definition: MeterPanel.h:290
Observer::Subscription mAudioCaptureSubscription
Definition: MeterPanel.h:238
wxTimer mTimer
Definition: MeterPanel.h:242
wxBrush mDisabledBkgndBrush
Definition: MeterPanel.h:288
bool mDecay
Definition: MeterPanel.h:258
double mPeakHoldDuration
Definition: MeterPanel.h:262
std::unique_ptr< LWSlider > mSlider
Definition: MeterPanel.h:294
double mT
Definition: MeterPanel.h:263
wxString mLeftText
Definition: MeterPanel.h:291
AudacityProject * mProject
Definition: MeterPanel.h:240
unsigned mNumBars
Definition: MeterPanel.h:272
wxBrush mBkgndBrush
Definition: MeterPanel.h:287
bool mMonitoring
Definition: MeterPanel.h:268
bool mGradient
Definition: MeterPanel.h:255
bool mActive
Definition: MeterPanel.h:270
Style GetDesiredStyle() const
Definition: MeterPanel.h:120
wxBrush mBrush
Definition: MeterPanel.h:284
Observer::Subscription mAudioIOStatusSubscription
Definition: MeterPanel.h:237
std::unique_ptr< wxBitmap > mBitmap
Definition: MeterPanel.h:277
wxPoint mLeftTextPos
Definition: MeterPanel.h:278
wxTimer mTipTimer
Definition: MeterPanel.h:243
wxSize mLeftSize
Definition: MeterPanel.h:280
wxPen mPeakPeakPen
Definition: MeterPanel.h:283
wxPoint mRightTextPos
Definition: MeterPanel.h:279
wxRect mFocusRect
Definition: MeterPanel.h:301
int mNumPeakSamplesToClip
Definition: MeterPanel.h:261
@ HorizontalStereoCompact
Definition: MeterPanel.h:102
@ AutomaticStereo
Definition: MeterPanel.h:98
@ HorizontalStereo
Definition: MeterPanel.h:99
@ VerticalStereo
Definition: MeterPanel.h:100
@ VerticalStereoCompact
Definition: MeterPanel.h:103
@ MixerTrackCluster
Definition: MeterPanel.h:101
wxSize mSliderSize
Definition: MeterPanel.h:296
int GetDBRange() const override
Definition: MeterPanel.h:186
wxBrush mClipBrush
Definition: MeterPanel.h:286
wxPen mPen
Definition: MeterPanel.h:282
MeterUpdateQueue mQueue
Definition: MeterPanel.h:241
wxBrush mRMSBrush
Definition: MeterPanel.h:285
Message used to update the MeterPanel.
Definition: MeterPanel.h:56
bool clipping[kMaxMeterBars]
Definition: MeterPanel.h:61
float peak[kMaxMeterBars]
Definition: MeterPanel.h:59
int tailPeakCount[kMaxMeterBars]
Definition: MeterPanel.h:63
int headPeakCount[kMaxMeterBars]
Definition: MeterPanel.h:62
wxString toStringIfClipped()
Only print meter updates if clipping may be happening.
Definition: MeterPanel.cpp:176
wxString toString()
Print out all the values in the meter update message.
Definition: MeterPanel.cpp:159
float rms[kMaxMeterBars]
Definition: MeterPanel.h:60
Queue of MeterUpdateMsg used to feed the MeterPanel.
A move-only handle representing a connection to a Publisher.
Definition: Observer.h:70
A listener notified of changes in preferences.
Definition: Prefs.h:652
virtual void UpdateSelectedPrefs(int id)
Definition: Prefs.cpp:158
virtual void UpdatePrefs()=0
Definition: Prefs.cpp:154
Used to display a Ruler.
Definition: Ruler.h:34
Holds a msgid for the translation catalog; may also bind format arguments.
void OnPreferences(const CommandContext &context)
Definition: EditMenus.cpp:1015
A struct used by MeterPanel to hold the position of one bar.
Definition: MeterPanel.h:40
wxRect rClip
Definition: MeterPanel.h:48
bool isclipping
Definition: MeterPanel.h:50
float peakPeakHold
Definition: MeterPanel.h:52
float peak
Definition: MeterPanel.h:44
int tailPeakCount
Definition: MeterPanel.h:51
float rms
Definition: MeterPanel.h:45
bool vert
Definition: MeterPanel.h:41
wxRect b
Definition: MeterPanel.h:42
bool clipping
Definition: MeterPanel.h:49
double peakHoldTime
Definition: MeterPanel.h:47
wxRect r
Definition: MeterPanel.h:43
float peakHold
Definition: MeterPanel.h:46