14#include <wx/dcclient.h>
15#include <wx/dcmemory.h>
22#include "../widgets/valnum.h"
38 mUIParent =
S.GetParent();
40 S.StartVerticalLay(
true);
49 S.StartMultiColumn(6, wxCENTER);
51 mDuckAmountDbBox =
S.Validator<FloatingPointValidator<double>>(
52 1, &mDuckAmountDb, NumValidatorStyle::NO_TRAILING_ZEROES,
53 DuckAmountDb.min, DuckAmountDb.max )
55 .AddTextBox(
XXO(
"Duck &amount:"),
wxT(
""), 10);
58 mMaximumPauseBox =
S.Validator<FloatingPointValidator<double>>(
59 2, &mMaximumPause, NumValidatorStyle::NO_TRAILING_ZEROES,
60 MaximumPause.min, MaximumPause.max )
61 .NameSuffix(
XO(
"seconds"))
62 .AddTextBox(
XXO(
"Ma&ximum pause:"),
wxT(
""), 10);
63 S.AddUnits(
XO(
"seconds"));
65 mOuterFadeDownLenBox =
S.Validator<FloatingPointValidator<double>>(
66 2, &mOuterFadeDownLen, NumValidatorStyle::NO_TRAILING_ZEROES,
67 OuterFadeDownLen.min, OuterFadeDownLen.max )
68 .NameSuffix(
XO(
"seconds"))
69 .AddTextBox(
XXO(
"Outer fade &down length:"),
wxT(
""), 10);
70 S.AddUnits(
XO(
"seconds"));
72 mOuterFadeUpLenBox =
S.Validator<FloatingPointValidator<double>>(
73 2, &mOuterFadeUpLen, NumValidatorStyle::NO_TRAILING_ZEROES,
74 OuterFadeUpLen.min, OuterFadeUpLen.max )
75 .NameSuffix(
XO(
"seconds"))
76 .AddTextBox(
XXO(
"Outer fade &up length:"),
wxT(
""), 10);
77 S.AddUnits(
XO(
"seconds"));
79 mInnerFadeDownLenBox =
S.Validator<FloatingPointValidator<double>>(
80 2, &mInnerFadeDownLen, NumValidatorStyle::NO_TRAILING_ZEROES,
81 InnerFadeDownLen.min, InnerFadeDownLen.max )
82 .NameSuffix(
XO(
"seconds"))
83 .AddTextBox(
XXO(
"Inner fade d&own length:"),
wxT(
""), 10);
84 S.AddUnits(
XO(
"seconds"));
86 mInnerFadeUpLenBox =
S.Validator<FloatingPointValidator<double>>(
87 2, &mInnerFadeUpLen, NumValidatorStyle::NO_TRAILING_ZEROES,
88 InnerFadeUpLen.min, InnerFadeUpLen.max )
89 .NameSuffix(
XO(
"seconds"))
90 .AddTextBox(
XXO(
"Inner &fade up length:"),
wxT(
""), 10);
91 S.AddUnits(
XO(
"seconds"));
95 S.StartMultiColumn(3, wxCENTER);
97 mThresholdDbBox =
S.Validator<FloatingPointValidator<double>>(
98 2, &mThresholdDb, NumValidatorStyle::NO_TRAILING_ZEROES,
99 ThresholdDb.min, ThresholdDb.max )
100 .NameSuffix(
XO(
"db"))
101 .AddTextBox(
XXO(
"&Threshold:"),
wxT(
""), 10);
102 S.AddUnits(
XO(
"dB"));
147#define CONTROL_POINT_REGION 10
148#define CONTROL_POINT_MIN_MOVE 5
150#define TEXT_DISTANCE 15
152#define FADE_DOWN_START 150
153#define FADE_UP_START 450
154#define DUCK_AMOUNT_START 50
157#define DUCK_AMOUNT_SCALE 8
159static int GetDistance(
const wxPoint& first,
const wxPoint& second)
161 int distanceX = abs(first.x - second.x);
162 int distanceY = abs(first.y - second.y);
163 if (distanceX > distanceY)
180:
wxPanelWrapper(parent, winid, wxDefaultPosition, wxSize(600, 300))
184 mCurrentControlPoint =
none;
185 mBackgroundBitmap = NULL;
187 ResetControlPoints();
198 mControlPoints[innerFadeDown] = wxPoint(-100,-100);
199 mControlPoints[innerFadeUp] = wxPoint(-100,-100);
200 mControlPoints[outerFadeDown] = wxPoint(-100,-100);
201 mControlPoints[outerFadeUp] = wxPoint(-100,-100);
202 mControlPoints[duckAmount] = wxPoint(-100,-100);
207 int clientWidth, clientHeight;
208 GetSize(&clientWidth, &clientHeight);
210 if (!mBackgroundBitmap || mBackgroundBitmap->GetWidth() != clientWidth ||
211 mBackgroundBitmap->GetHeight() != clientHeight)
213 mBackgroundBitmap = std::make_unique<wxBitmap>(clientWidth, clientHeight,24);
217 dc.SelectObject(*mBackgroundBitmap);
219 dc.SetBrush(*wxWHITE_BRUSH);
220 dc.SetPen(*wxBLACK_PEN);
221 dc.DrawRectangle(0, 0, clientWidth, clientHeight);
223 dc.SetFont(wxFont(10, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL,
224 wxFONTWEIGHT_NORMAL));
225 dc.SetTextForeground(*wxBLACK);
226 dc.SetTextBackground(*wxWHITE);
228 double duckAmountDb = 0;
229 double innerFadeDownLen = 0;
230 double innerFadeUpLen = 0;
231 double outerFadeDownLen = 0;
232 double outerFadeUpLen = 0;
233 mEffect->mDuckAmountDbBox->GetValue().ToDouble(&duckAmountDb);
234 mEffect->mInnerFadeDownLenBox->GetValue().ToDouble(&innerFadeDownLen);
235 mEffect->mInnerFadeUpLenBox->GetValue().ToDouble(&innerFadeUpLen);
236 mEffect->mOuterFadeDownLenBox->GetValue().ToDouble(&outerFadeDownLen);
237 mEffect->mOuterFadeUpLenBox->GetValue().ToDouble(&outerFadeUpLen);
246 wxString message =
_(
"Preview not available");
247 int textWidth = 0, textHeight = 0;
248 dc.GetTextExtent(message, &textWidth, &textHeight);
249 dc.DrawText(message, (clientWidth - textWidth) / 2,
250 (clientHeight - textHeight) / 2);
252 ResetControlPoints();
256 dc.SetBrush(*wxTRANSPARENT_BRUSH);
257 dc.SetPen(wxPen(
theTheme.
Colour(clrGraphLines), 3, wxPENSTYLE_SOLID));
278 points[5].x = clientWidth - 10;
283 dc.SetPen(wxPen(*wxBLACK, 1, wxPENSTYLE_DOT));
289 dc.SetBrush(*wxWHITE_BRUSH);
291 mControlPoints[outerFadeDown] = points[1];
292 mControlPoints[innerFadeDown] = points[2];
293 mControlPoints[innerFadeUp] = points[3];
294 mControlPoints[outerFadeUp] = points[4];
295 mControlPoints[duckAmount] = wxPoint(
296 (points[2].x + points[3].x) / 2, points[2].y);
304 if (cp == innerFadeDown)
306 value = innerFadeDownLen;
309 else if (cp == innerFadeUp)
311 value = innerFadeUpLen;
314 else if (cp == outerFadeDown)
316 value = outerFadeDownLen;
318 }
else if (cp == outerFadeUp)
320 value = outerFadeUpLen;
325 value = duckAmountDb;
330 valueStr +=
wxT(
" ");
332 if (cp == duckAmount)
339 int textWidth = 0, textHeight = 0;
340 GetTextExtent(valueStr, &textWidth, &textHeight);
342 int textPosX = mControlPoints[i].x - textWidth / 2;
343 int textPosY = mControlPoints[i].y;
345 if (cp == duckAmount || cp == outerFadeDown || cp == outerFadeUp)
350 dc.DrawText(valueStr, textPosX, textPosY);
352 dc.DrawEllipse(mControlPoints[i].x - 3,
353 mControlPoints[i].y - 3, 6, 6);
358 wxPaintDC paintDC(
this);
359 paintDC.Blit(0, 0, clientWidth, clientHeight, &dc, 0, 0);
362 dc.SetPen(wxNullPen);
363 dc.SetBrush(wxNullBrush);
364 dc.SetFont(wxNullFont);
365 dc.SelectObject(wxNullBitmap);
369 wxMouseCaptureChangedEvent & WXUNUSED(evt))
371 SetCursor(wxNullCursor);
372 mCurrentControlPoint =
none;
376 wxMouseCaptureLostEvent & WXUNUSED(evt))
378 mCurrentControlPoint =
none;
397 if (dist[i] < dist[curMinimum])
408 EControlPoint nearest = GetNearestControlPoint(evt.GetPosition());
413 mMouseDownPoint = evt.GetPosition();
415 mCurrentControlPoint = nearest;
416 mControlPointMoveActivated =
false;
419 mMoveStartControlPoints[i] = mControlPoints[i];
428 if (mCurrentControlPoint !=
none)
430 mCurrentControlPoint =
none;
437 switch (GetNearestControlPoint(evt.GetPosition()))
440 SetCursor(wxNullCursor);
446 SetCursor(wxCursor(wxCURSOR_SIZEWE));
449 SetCursor(wxCursor(wxCURSOR_SIZENS));
453 if (mCurrentControlPoint !=
none)
455 if (!mControlPointMoveActivated)
459 if (mCurrentControlPoint == duckAmount)
460 dist = abs(evt.GetY() - mMouseDownPoint.y);
462 dist = abs(evt.GetX() - mMouseDownPoint.x);
465 mControlPointMoveActivated =
true;
468 if (mControlPointMoveActivated)
472 switch (mCurrentControlPoint)
497 mEffect->DoTransferDataToWindow();
#define CONTROL_POINT_REGION
static int GetDistance(const wxPoint &first, const wxPoint &second)
#define DUCK_AMOUNT_SCALE
#define DUCK_AMOUNT_START
#define CONTROL_POINT_MIN_MOVE
#define AUTO_DUCK_PANEL_NUM_CONTROL_POINTS
XXO("&Cut/Copy/Paste Toolbar")
static void Line(wxDC &dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
static void Lines(wxDC &dc, size_t nPoints, const wxPoint points[])
static constexpr EffectParameter OuterFadeUpLen
static constexpr EffectParameter InnerFadeDownLen
static constexpr EffectParameter InnerFadeUpLen
static constexpr EffectParameter DuckAmountDb
static constexpr EffectParameter OuterFadeDownLen
EControlPoint GetNearestControlPoint(const wxPoint &pt)
void OnMotion(wxMouseEvent &evt)
void OnLeftDown(wxMouseEvent &evt)
void OnMouseCaptureChanged(wxMouseCaptureChangedEvent &evt)
void OnLeftUp(wxMouseEvent &evt)
void ResetControlPoints()
void OnPaint(wxPaintEvent &evt)
void OnMouseCaptureLost(wxMouseCaptureLostEvent &evt)
bool DoTransferDataToWindow()
wxWeakRef< wxWindow > mUIParent
bool TransferDataToWindow(const EffectSettings &settings) override
void OnValueChanged(wxCommandEvent &evt)
bool TransferDataFromWindow(EffectSettings &settings) override
Performs effect computation.
Hold values to send to effect output meters.
static wxString ToDisplayString(double numberToConvert, int digitsAfterDecimalPoint=-1)
Convert a number to a string, uses the user's locale's decimal separator.
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
wxColour & Colour(int iIndex)
BuiltinEffectsModule::Registration< EffectAutoDuck > reg
const Type min
Minimum value.
const Type max
Maximum value.
Externalized state of a plug-in.