Audacity  3.0.3
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 <wx/setup.h> // for wxUSE_* macros
20 #include <wx/brush.h> // member variable
21 #include <wx/defs.h>
22 #include <wx/timer.h> // member variable
23 
24 #include "SampleFormat.h"
25 #include "Prefs.h"
26 #include "MeterPanelBase.h" // to inherit
27 #include "Ruler.h" // member variable
28 
29 class AudacityProject;
30 
31 // Increase this when we add support for multichannel meters
32 // (most of the code is already there)
33 const int kMaxMeterBars = 2;
34 
35 struct MeterBar {
36  bool vert;
37  wxRect b; // Bevel around bar
38  wxRect r; // True bar drawing area
39  float peak;
40  float rms;
41  float peakHold;
42  double peakHoldTime;
43  wxRect rClip;
44  bool clipping;
45  bool isclipping; //ANSWER-ME: What's the diff between these bools?! "clipping" vs "isclipping" is not clear.
47  float peakPeakHold;
48 };
49 
51 {
52  public:
53  int numFrames;
59 
60  /* neither constructor nor destructor do anything */
63  /* for debugging purposes, printing the values out is really handy */
65  wxString toString();
67  wxString toStringIfClipped();
68 };
69 
70 // Thread-safe queue of update messages
72 {
73  public:
74  explicit MeterUpdateQueue(size_t maxLen);
76 
77  bool Put(MeterUpdateMsg &msg);
78  bool Get(MeterUpdateMsg &msg);
79 
80  void Clear();
81 
82  private:
83  int mStart;
84  int mEnd;
85  size_t mBufferSize;
87 };
88 
89 class MeterAx;
90 
91 /********************************************************************/
95 class AUDACITY_DLL_API MeterPanel final
96  : public MeterPanelBase, private PrefsListener
97 {
98  DECLARE_DYNAMIC_CLASS(MeterPanel)
99 
100  public:
101  // These should be kept in the same order as they appear
102  // in the menu
103  enum Style {
107  MixerTrackCluster, // Doesn't show menu, icon, or L/R labels, but otherwise like VerticalStereo.
109  VerticalStereoCompact, // Narrower.
110  };
111 
112 
114  wxWindow* parent, wxWindowID id,
115  bool isInput,
116  const wxPoint& pos = wxDefaultPosition,
117  const wxSize& size = wxDefaultSize,
118  Style style = HorizontalStereo,
119  float fDecayRate = 60.0f);
120 
121  void SetFocusFromKbd() override;
122 
123  void Clear() override;
124 
125  Style GetStyle() const { return mStyle; }
126  Style GetDesiredStyle() const { return mDesiredStyle; }
127  void SetStyle(Style newStyle);
128 
134  void Reset(double sampleRate, bool resetClipping) override;
135 
158  void UpdateDisplay(unsigned numChannels,
159  int numFrames, const float *sampleData) override;
160 
161  // Vaughan, 2010-11-29: This not currently used. See comments in MixerTrackCluster::UpdateMeter().
162  //void UpdateDisplay(int numChannels, int numFrames,
163  // // Need to make these double-indexed max and min arrays if we handle more than 2 channels.
164  // float* maxLeft, float* rmsLeft,
165  // float* maxRight, float* rmsRight,
166  // const size_t kSampleCount);
167 
173  bool IsMeterDisabled() const override;
174 
175  float GetMaxPeak() const override;
176 
177  bool IsClipping() const override;
178 
179  void StartMonitoring();
180  void StopMonitoring();
181 
182  // These exist solely for the purpose of resetting the toolbars
183  struct State{ bool mSaved, mMonitoring, mActive; };
184  State SaveState();
185  void RestoreState(const State &state);
186 
187  int GetDBRange() const override { return mDB ? mDBRange : -1; }
188 
189  private:
190  void UpdatePrefs() override;
191  void UpdateSelectedPrefs( int ) override;
192 
193  private:
194  //
195  // Event handlers
196  //
197  void OnErase(wxEraseEvent &evt);
198  void OnPaint(wxPaintEvent &evt);
199  void OnSize(wxSizeEvent &evt);
200  bool InIcon(wxMouseEvent *pEvent = nullptr) const;
201  void OnMouse(wxMouseEvent &evt);
202  void OnKeyDown(wxKeyEvent &evt);
203  void OnKeyUp(wxKeyEvent &evt);
204  void OnContext(wxContextMenuEvent &evt);
205  void OnSetFocus(wxFocusEvent &evt);
206  void OnKillFocus(wxFocusEvent &evt);
207 
208  void OnAudioIOStatus(wxCommandEvent &evt);
209 
210  void OnMeterUpdate(wxTimerEvent &evt);
211 
212  void HandleLayout(wxDC &dc);
213  void SetActiveStyle(Style style);
214  void SetBarAndClip(int iBar, bool vert);
215  void DrawMeterBar(wxDC &dc, MeterBar *meterBar);
216  void ResetBar(MeterBar *bar, bool resetClipping);
217  void RepaintBarsNow();
218  wxFont GetFont() const;
219 
220  //
221  // Pop-up menu
222  //
223  void ShowMenu(const wxPoint & pos);
224  void OnMonitor(wxCommandEvent &evt);
225  void OnPreferences(wxCommandEvent &evt);
226 
227  wxString Key(const wxString & key) const;
228 
231  wxTimer mTimer;
232 
233  int mWidth;
234  int mHeight;
235 
238 
239  bool mIsInput;
240 
243  bool mGradient;
244  bool mDB;
245  int mDBRange;
246  bool mDecay;
247  float mDecayRate; // dB/sec
248  bool mClip;
251  double mT;
252  double mRate;
254  long mMeterDisabled; //is used as a bool, needs long for easy gPrefs...
255 
257 
258  bool mActive;
259 
260  unsigned mNumBars;
262 
264 
265  std::unique_ptr<wxBitmap> mBitmap;
266  wxRect mIconRect;
267  wxPoint mLeftTextPos;
268  wxPoint mRightTextPos;
269  wxSize mLeftSize;
270  wxSize mRightSize;
271  std::unique_ptr<wxBitmap> mIcon;
272  wxPen mPen;
275  wxBrush mBrush;
276  wxBrush mRMSBrush;
277  wxBrush mClipBrush;
278  wxBrush mBkgndBrush;
281  wxString mLeftText;
282  wxString mRightText;
283 
285  wxRect mFocusRect;
286 #if defined(__WXMSW__)
287  bool mHadKeyDown;
288 #endif
289 
291 
292  friend class MeterAx;
293 
294  bool mHighlighted {};
295 
296  DECLARE_EVENT_TABLE()
297 };
298 
299 #endif // __AUDACITY_METER_PANEL__
MeterUpdateMsg::rms
float rms[kMaxMeterBars]
Definition: MeterPanel.h:55
size
size_t size
Definition: ffmpeg-2.3.6-single-header.h:412
MeterPanel::mDecayRate
float mDecayRate
Definition: MeterPanel.h:247
MeterPanel::mT
double mT
Definition: MeterPanel.h:251
MeterPanelBase::UpdateDisplay
virtual void UpdateDisplay(unsigned numChannels, int numFrames, const float *sampleData)=0
MeterPanel::GetDesiredStyle
Style GetDesiredStyle() const
Definition: MeterPanel.h:126
MeterPanelBase::IsClipping
virtual bool IsClipping() const =0
MeterPanel::mRightTextPos
wxPoint mRightTextPos
Definition: MeterPanel.h:268
MeterPanel::mDB
bool mDB
Definition: MeterPanel.h:244
MeterPanel::Style
Style
Definition: MeterPanel.h:103
MeterUpdateQueue::mStart
int mStart
Definition: MeterPanel.h:83
MeterPanel::mNumBars
unsigned mNumBars
Definition: MeterPanel.h:260
MeterPanel::mProject
AudacityProject * mProject
Definition: MeterPanel.h:229
MeterPanel::mHeight
int mHeight
Definition: MeterPanel.h:234
MeterBar::r
wxRect r
Definition: MeterPanel.h:38
MeterPanel::State
Definition: MeterPanel.h:183
MeterPanel::mDecay
bool mDecay
Definition: MeterPanel.h:246
MeterPanel::mActive
bool mActive
Definition: MeterPanel.h:258
MeterPanel::State::mSaved
bool mSaved
Definition: MeterPanel.h:183
MeterPanel::HorizontalStereo
@ HorizontalStereo
Definition: MeterPanel.h:105
MeterPanelBase
Inherits wxPanel and has a Meter; exposes shared_ptr to the Meter.
Definition: MeterPanelBase.h:27
MeterPanel::mFocusRect
wxRect mFocusRect
Definition: MeterPanel.h:285
MeterBar::rms
float rms
Definition: MeterPanel.h:40
TrackInfo::UpdatePrefs
AUDACITY_DLL_API void UpdatePrefs(wxWindow *pParent)
MeterPanel::mLeftSize
wxSize mLeftSize
Definition: MeterPanel.h:269
MeterPanel::mPeakHoldDuration
double mPeakHoldDuration
Definition: MeterPanel.h:250
MeterPanel::mBkgndBrush
wxBrush mBkgndBrush
Definition: MeterPanel.h:278
MeterPanel::mRMSBrush
wxBrush mRMSBrush
Definition: MeterPanel.h:276
MeterPanel::mDisabledBkgndBrush
wxBrush mDisabledBkgndBrush
Definition: MeterPanel.h:279
OnSize
static void OnSize(wxSizeEvent &evt)
Definition: VSTEffect.cpp:2784
MeterUpdateMsg::tailPeakCount
int tailPeakCount[kMaxMeterBars]
Definition: MeterPanel.h:58
MeterBar::b
wxRect b
Definition: MeterPanel.h:37
MeterBar::tailPeakCount
int tailPeakCount
Definition: MeterPanel.h:46
MeterPanel::mRulerHeight
int mRulerHeight
Definition: MeterPanel.h:237
MeterPanel::mRate
double mRate
Definition: MeterPanel.h:252
MeterUpdateMsg::clipping
bool clipping[kMaxMeterBars]
Definition: MeterPanel.h:56
MeterPanel::mLeftText
wxString mLeftText
Definition: MeterPanel.h:281
PrefsListener
A listener notified of changes in preferences.
Definition: Prefs.h:392
MeterPanel::mQueue
MeterUpdateQueue mQueue
Definition: MeterPanel.h:230
MeterPanel::mLeftTextPos
wxPoint mLeftTextPos
Definition: MeterPanel.h:267
MeterBar::isclipping
bool isclipping
Definition: MeterPanel.h:45
PrefsListener::UpdateSelectedPrefs
virtual void UpdateSelectedPrefs(int id)
Definition: Prefs.cpp:127
MeterUpdateQueue::~MeterUpdateQueue
~MeterUpdateQueue()
Definition: MeterPanel.cpp:203
MeterPanel::mMeterDisabled
long mMeterDisabled
Definition: MeterPanel.h:254
MeterBar::vert
bool vert
Definition: MeterPanel.h:36
MeterPanel::MixerTrackCluster
@ MixerTrackCluster
Definition: MeterPanel.h:107
MeterBar::rClip
wxRect rClip
Definition: MeterPanel.h:43
MeterPanel::mIsFocused
bool mIsFocused
Definition: MeterPanel.h:284
MeterPanelBase::GetMaxPeak
virtual float GetMaxPeak() const =0
Ruler
Used to display a Ruler.
Definition: Ruler.h:26
MeterBar::peakPeakHold
float peakPeakHold
Definition: MeterPanel.h:47
MeterPanel::mMeterRefreshRate
long mMeterRefreshRate
Definition: MeterPanel.h:253
MeterPanel::mGradient
bool mGradient
Definition: MeterPanel.h:243
MeterUpdateQueue
Queue of MeterUpdateMsg used to feed the MeterPanel.
Definition: MeterPanel.h:72
MeterPanel::mPeakPeakPen
wxPen mPeakPeakPen
Definition: MeterPanel.h:274
MeterUpdateMsg::toStringIfClipped
wxString toStringIfClipped()
Only print meter updates if clipping may be happening.
Definition: MeterPanel.cpp:179
MeterUpdateQueue::MeterUpdateQueue
MeterUpdateQueue(size_t maxLen)
Definition: MeterPanel.cpp:196
MeterPanel::mRightText
wxString mRightText
Definition: MeterPanel.h:282
MeterPanel::mDBRange
int mDBRange
Definition: MeterPanel.h:245
MeterPanel::mNumPeakSamplesToClip
int mNumPeakSamplesToClip
Definition: MeterPanel.h:249
MeterPanel::mIsInput
bool mIsInput
Definition: MeterPanel.h:239
MeterUpdateMsg::peak
float peak[kMaxMeterBars]
Definition: MeterPanel.h:54
MeterPanel::mTimer
wxTimer mTimer
Definition: MeterPanel.h:231
MeterBar::peakHold
float peakHold
Definition: MeterPanel.h:41
Ruler.h
MeterBar::peakHoldTime
double peakHoldTime
Definition: MeterPanel.h:42
MeterPanel::GetStyle
Style GetStyle() const
Definition: MeterPanel.h:125
MeterUpdateQueue::Get
bool Get(MeterUpdateMsg &msg)
Definition: MeterPanel.cpp:236
MeterUpdateQueue::mEnd
int mEnd
Definition: MeterPanel.h:84
MeterPanel::AutomaticStereo
@ AutomaticStereo
Definition: MeterPanel.h:104
MeterPanel::mAccSilent
bool mAccSilent
Definition: MeterPanel.h:290
MeterPanel::mRuler
Ruler mRuler
Definition: MeterPanel.h:280
MeterPanelBase::Clear
virtual void Clear()=0
MeterPanel::mClipBrush
wxBrush mClipBrush
Definition: MeterPanel.h:277
MeterPanel::GetDBRange
int GetDBRange() const override
Definition: MeterPanel.h:187
key
static const AudacityProject::AttachedObjects::RegisteredFactory key
Definition: CommandManager.cpp:201
MeterPanel::mClip
bool mClip
Definition: MeterPanel.h:248
MeterUpdateMsg::toString
wxString toString()
Print out all the values in the meter update message.
Definition: MeterPanel.cpp:162
MeterUpdateMsg::MeterUpdateMsg
MeterUpdateMsg()
Definition: MeterPanel.h:61
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:92
MeterPanelBase.h
MeterUpdateMsg::numFrames
int numFrames
Definition: MeterPanel.h:53
kMaxMeterBars
const int kMaxMeterBars
Definition: MeterPanel.h:33
MeterPanel::HorizontalStereoCompact
@ HorizontalStereoCompact
Definition: MeterPanel.h:108
MeterPanel::mIcon
std::unique_ptr< wxBitmap > mIcon
Definition: MeterPanel.h:271
MeterPanel
MeterPanel is a panel that paints the meter used for monitoring or playback.
Definition: MeterPanel.h:97
MeterPanel::mRightSize
wxSize mRightSize
Definition: MeterPanel.h:270
MeterUpdateMsg::headPeakCount
int headPeakCount[kMaxMeterBars]
Definition: MeterPanel.h:57
MeterUpdateQueue::Put
bool Put(MeterUpdateMsg &msg)
Definition: MeterPanel.cpp:215
MeterUpdateQueue::mBuffer
ArrayOf< MeterUpdateMsg > mBuffer
Definition: MeterPanel.h:86
MeterPanel::mMonitoring
bool mMonitoring
Definition: MeterPanel.h:256
MeterPanel::VerticalStereo
@ VerticalStereo
Definition: MeterPanel.h:106
MeterPanel::mIconRect
wxRect mIconRect
Definition: MeterPanel.h:266
MeterUpdateQueue::mBufferSize
size_t mBufferSize
Definition: MeterPanel.h:85
MeterPanel::mDisabledPen
wxPen mDisabledPen
Definition: MeterPanel.h:273
Prefs.h
MeterPanel::mStyle
Style mStyle
Definition: MeterPanel.h:241
MeterPanel::mBitmap
std::unique_ptr< wxBitmap > mBitmap
Definition: MeterPanel.h:265
MeterPanel::mRulerWidth
int mRulerWidth
Definition: MeterPanel.h:236
MeterPanelBase::IsMeterDisabled
virtual bool IsMeterDisabled() const =0
MeterBar
A struct used by MeterPanel to hold the position of one bar.
Definition: MeterPanel.h:35
MeterPanel::mLayoutValid
bool mLayoutValid
Definition: MeterPanel.h:263
MeterPanel::mPen
wxPen mPen
Definition: MeterPanel.h:272
MeterPanel::VerticalStereoCompact
@ VerticalStereoCompact
Definition: MeterPanel.h:109
MeterPanel::mWidth
int mWidth
Definition: MeterPanel.h:233
MeterBar::clipping
bool clipping
Definition: MeterPanel.h:44
MeterUpdateMsg
Message used to update the MeterPanel.
Definition: MeterPanel.h:51
SampleFormat.h
ArrayOf< MeterUpdateMsg >
MeterPanelBase::Reset
virtual void Reset(double sampleRate, bool resetClipping)=0
MeterBar::peak
float peak
Definition: MeterPanel.h:39
MeterUpdateMsg::~MeterUpdateMsg
~MeterUpdateMsg()
Definition: MeterPanel.h:62
MeterUpdateQueue::Clear
void Clear()
Definition: MeterPanel.cpp:207
MeterPanel::mBrush
wxBrush mBrush
Definition: MeterPanel.h:275
MeterPanel::mDesiredStyle
Style mDesiredStyle
Definition: MeterPanel.h:242