Audacity 3.2.0
LV2EffectMeter.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 @file LV2EffectMeter.cpp
6
7 Paul Licameli split from LV2Effect.cpp
8
9 Audacity(R) is copyright (c) 1999-2008 Audacity Team.
10 License: GPL v2 or later. See License.txt.
11
12**********************************************************************/
13
14#if defined(USE_LV2)
15
16#if defined(__GNUC__)
17#pragma GCC diagnostic ignored "-Wparentheses"
18#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
19#elif defined(__clang__)
20#pragma clang diagnostic ignored "-Wparentheses"
21#pragma clang diagnostic ignored "-Wdeprecated-declarations"
22#endif
23
24#include "LV2EffectMeter.h"
25#include <wx/dcbuffer.h>
26
27BEGIN_EVENT_TABLE(LV2EffectMeter, wxWindow)
29 EVT_ERASE_BACKGROUND(LV2EffectMeter::OnErase)
33
35 wxWindow *parent, const LV2ControlPortPtr port, const float &value
36) : wxWindow{ parent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
37 wxSIMPLE_BORDER }
38 , mControlPort(port)
39 , mValue{ value }
40{
41 mLastValue = -value;
42 SetBackgroundColour(*wxWHITE);
43 SetMinSize({ 20, 20 });
44}
45
47{
48}
49
50void LV2EffectMeter::OnIdle(wxIdleEvent &evt)
51{
52 evt.Skip();
53 if (!mConnected)
54 return;
55 if (mLastValue != mValue)
56 Refresh(false);
57}
58
59void LV2EffectMeter::OnErase(wxEraseEvent &WXUNUSED(evt))
60{
61 // Just ignore it to prevent flashing
62}
63
64void LV2EffectMeter::OnPaint(wxPaintEvent &WXUNUSED(evt))
65{
66 if (!mConnected)
67 return;
68
69 std::unique_ptr<wxDC> dc {wxAutoBufferedPaintDCFactory(this)};
70
71 // Cache some metrics
72 wxRect r = GetClientRect();
73 wxCoord x = r.GetLeft();
74 wxCoord y = r.GetTop();
75 wxCoord w = r.GetWidth();
76 wxCoord h = r.GetHeight();
77
78 // These use unscaled value, min, and max
79 float val = std::clamp(mValue, mControlPort->mMin, mControlPort->mMax)
80 - mControlPort->mMin;
81
82 // Setup for erasing the background
83 dc->SetPen(*wxTRANSPARENT_PEN);
84 dc->SetBrush(wxColour(100, 100, 220));
85
86 dc->Clear();
87 dc->DrawRectangle(x, y, (w * (val / fabs(mControlPort->mMax - mControlPort->mMin))), h);
88
90}
91
92void LV2EffectMeter::OnSize(wxSizeEvent &WXUNUSED(evt))
93{
94 Refresh(false);
95}
96
97#endif
END_EVENT_TABLE()
std::shared_ptr< LV2ControlPort > LV2ControlPortPtr
Definition: LV2Ports.h:202
UI widget that watches a floating point location and then updates a bar.
void OnErase(wxEraseEvent &evt)
const float & mValue
const LV2ControlPortPtr mControlPort
void OnPaint(wxPaintEvent &evt)
void OnSize(wxSizeEvent &evt)
void OnIdle(wxIdleEvent &evt)
virtual ~LV2EffectMeter()