Audacity 3.2.0
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
EffectAutoDuck::Panel Class Referencefinal

#include <AutoDuck.h>

Inheritance diagram for EffectAutoDuck::Panel:
[legend]
Collaboration diagram for EffectAutoDuck::Panel:
[legend]

Public Member Functions

 Panel (wxWindow *parent, wxWindowID winid, EffectAutoDuck *effect)
 
virtual ~Panel ()
 
- Public Member Functions inherited from wxPanelWrapper
 wxPanelWrapper ()
 
 wxPanelWrapper (wxWindow *parent, wxWindowID winid=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL|wxNO_BORDER, const TranslatableString &name=XO("Panel"))
 
bool Create (wxWindow *parent, wxWindowID winid=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL|wxNO_BORDER, const TranslatableString &name=XO("Panel"))
 
void SetLabel (const TranslatableString &label)
 
void SetName (const TranslatableString &name)
 
void SetToolTip (const TranslatableString &toolTip)
 
void SetName ()
 
- Public Member Functions inherited from wxTabTraversalWrapper< wxPanel >
 wxTabTraversalWrapper (Args &&... args)
 
 wxTabTraversalWrapper (const wxTabTraversalWrapper &)=delete
 
 wxTabTraversalWrapper (wxTabTraversalWrapper &&)=delete
 
wxTabTraversalWrapperoperator= (const wxTabTraversalWrapper &)=delete
 
wxTabTraversalWrapperoperator= (wxTabTraversalWrapper &&)=delete
 

Private Types

enum  EControlPoint {
  innerFadeDown = 0 , outerFadeDown , innerFadeUp , outerFadeUp ,
  duckAmount , none = 99
}
 

Private Member Functions

bool AcceptsFocus () const override
 
bool AcceptsFocusFromKeyboard () const override
 
void OnPaint (wxPaintEvent &evt)
 
void OnMouseCaptureChanged (wxMouseCaptureChangedEvent &evt)
 
void OnMouseCaptureLost (wxMouseCaptureLostEvent &evt)
 
void OnLeftDown (wxMouseEvent &evt)
 
void OnLeftUp (wxMouseEvent &evt)
 
void OnMotion (wxMouseEvent &evt)
 
void ResetControlPoints ()
 
EControlPoint GetNearestControlPoint (const wxPoint &pt)
 

Private Attributes

wxWindow * mParent
 
EffectAutoDuckmEffect
 
std::unique_ptr< wxBitmap > mBackgroundBitmap
 
EControlPoint mCurrentControlPoint
 
wxPoint mControlPoints [AUTO_DUCK_PANEL_NUM_CONTROL_POINTS]
 
wxPoint mMoveStartControlPoints [AUTO_DUCK_PANEL_NUM_CONTROL_POINTS]
 
wxPoint mMouseDownPoint
 
bool mControlPointMoveActivated
 

Detailed Description

Definition at line 57 of file AutoDuck.h.

Member Enumeration Documentation

◆ EControlPoint

Enumerator
innerFadeDown 
outerFadeDown 
innerFadeUp 
outerFadeUp 
duckAmount 
none 

Definition at line 65 of file AutoDuck.h.

Constructor & Destructor Documentation

◆ Panel()

EffectAutoDuck::Panel::Panel ( wxWindow *  parent,
wxWindowID  winid,
EffectAutoDuck effect 
)

Definition at line 178 of file AutoDuck.cpp.

180: wxPanelWrapper(parent, winid, wxDefaultPosition, wxSize(600, 300))
181{
182 mParent = parent;
183 mEffect = effect;
185 mBackgroundBitmap = NULL;
186
188}
std::unique_ptr< wxBitmap > mBackgroundBitmap
Definition: AutoDuck.h:93
wxWindow * mParent
Definition: AutoDuck.h:91
EControlPoint mCurrentControlPoint
Definition: AutoDuck.h:94
EffectAutoDuck * mEffect
Definition: AutoDuck.h:92

References none.

◆ ~Panel()

EffectAutoDuck::Panel::~Panel ( )
virtual

Definition at line 190 of file AutoDuck.cpp.

191{
192 if(HasCapture())
193 ReleaseMouse();
194}

Member Function Documentation

◆ AcceptsFocus()

bool EffectAutoDuck::Panel::AcceptsFocus ( ) const
inlineoverrideprivate

Definition at line 75 of file AutoDuck.h.

75{ return false; }

◆ AcceptsFocusFromKeyboard()

bool EffectAutoDuck::Panel::AcceptsFocusFromKeyboard ( ) const
inlineoverrideprivate

Definition at line 77 of file AutoDuck.h.

77{ return false; }

◆ GetNearestControlPoint()

EffectAutoDuck::Panel::EControlPoint EffectAutoDuck::Panel::GetNearestControlPoint ( const wxPoint &  pt)
private

Definition at line 387 of file AutoDuck.cpp.

388{
390 int i;
391
392 for (i = 0; i < AUTO_DUCK_PANEL_NUM_CONTROL_POINTS; i++)
393 dist[i] = GetDistance(pt, mControlPoints[i]);
394
395 int curMinimum = 0;
396 for (i = 0; i < AUTO_DUCK_PANEL_NUM_CONTROL_POINTS; i++)
397 if (dist[i] < dist[curMinimum])
398 curMinimum = i;
399
400 if (dist[curMinimum] <= CONTROL_POINT_REGION)
401 return (EControlPoint)curMinimum;
402 else
403 return none;
404}
#define CONTROL_POINT_REGION
Definition: AutoDuck.cpp:147
static int GetDistance(const wxPoint &first, const wxPoint &second)
Definition: AutoDuck.cpp:159
#define AUTO_DUCK_PANEL_NUM_CONTROL_POINTS
Definition: AutoDuck.h:24
wxPoint mControlPoints[AUTO_DUCK_PANEL_NUM_CONTROL_POINTS]
Definition: AutoDuck.h:95

References AUTO_DUCK_PANEL_NUM_CONTROL_POINTS, CONTROL_POINT_REGION, GetDistance(), and none.

Here is the call graph for this function:

◆ OnLeftDown()

void EffectAutoDuck::Panel::OnLeftDown ( wxMouseEvent &  evt)
private

Definition at line 406 of file AutoDuck.cpp.

407{
408 EControlPoint nearest = GetNearestControlPoint(evt.GetPosition());
409
410 if (nearest != none)
411 {
412 // this control point has been clicked
413 mMouseDownPoint = evt.GetPosition();
414
415 mCurrentControlPoint = nearest;
417
418 for (int i = 0; i < AUTO_DUCK_PANEL_NUM_CONTROL_POINTS; i++)
420
421 if( !HasCapture() )
422 CaptureMouse();
423 }
424}
EControlPoint GetNearestControlPoint(const wxPoint &pt)
Definition: AutoDuck.cpp:387
bool mControlPointMoveActivated
Definition: AutoDuck.h:98
wxPoint mMouseDownPoint
Definition: AutoDuck.h:97
wxPoint mMoveStartControlPoints[AUTO_DUCK_PANEL_NUM_CONTROL_POINTS]
Definition: AutoDuck.h:96

References AUTO_DUCK_PANEL_NUM_CONTROL_POINTS, and none.

◆ OnLeftUp()

void EffectAutoDuck::Panel::OnLeftUp ( wxMouseEvent &  evt)
private

Definition at line 426 of file AutoDuck.cpp.

427{
429 {
431 ReleaseMouse();
432 }
433}

References none.

◆ OnMotion()

void EffectAutoDuck::Panel::OnMotion ( wxMouseEvent &  evt)
private

Definition at line 435 of file AutoDuck.cpp.

436{
437 switch (GetNearestControlPoint(evt.GetPosition()))
438 {
439 case none:
440 SetCursor(wxNullCursor);
441 break;
442 case innerFadeDown:
443 case innerFadeUp:
444 case outerFadeDown:
445 case outerFadeUp:
446 SetCursor(wxCursor(wxCURSOR_SIZEWE));
447 break;
448 case duckAmount:
449 SetCursor(wxCursor(wxCURSOR_SIZENS));
450 break;
451 }
452
454 {
456 {
457 int dist;
458
460 dist = abs(evt.GetY() - mMouseDownPoint.y);
461 else
462 dist = abs(evt.GetX() - mMouseDownPoint.x);
463
464 if (dist >= CONTROL_POINT_MIN_MOVE)
466 }
467
469 {
470 float newValue;
471
472 switch (mCurrentControlPoint)
473 {
474 case outerFadeDown:
475 newValue = ((double)(FADE_DOWN_START - evt.GetX())) / FADE_SCALE;
476 mEffect->mOuterFadeDownLen = std::clamp<double>(newValue, OuterFadeDownLen.min, OuterFadeDownLen.max);
477 break;
478 case outerFadeUp:
479 newValue = ((double)(evt.GetX() - FADE_UP_START)) / FADE_SCALE;
480 mEffect->mOuterFadeUpLen = std::clamp<double>(newValue, OuterFadeUpLen.min, OuterFadeUpLen.max);
481 break;
482 case innerFadeDown:
483 newValue = ((double)(evt.GetX() - FADE_DOWN_START)) / FADE_SCALE;
484 mEffect->mInnerFadeDownLen = std::clamp<double>(newValue, InnerFadeDownLen.min, InnerFadeDownLen.max);
485 break;
486 case innerFadeUp:
487 newValue = ((double)(FADE_UP_START - evt.GetX())) / FADE_SCALE;
488 mEffect->mInnerFadeUpLen = std::clamp<double>(newValue, InnerFadeUpLen.min, InnerFadeUpLen.max);
489 break;
490 case duckAmount:
491 newValue = ((double)(DUCK_AMOUNT_START - evt.GetY())) / DUCK_AMOUNT_SCALE;
492 mEffect->mDuckAmountDb = std::clamp<double>(newValue, DuckAmountDb.min, DuckAmountDb.max);
493 break;
494 case none:
495 wxASSERT(false); // should not happen
496 }
498 Refresh(false);
499 }
500 }
501}
#define FADE_DOWN_START
Definition: AutoDuck.cpp:152
#define FADE_UP_START
Definition: AutoDuck.cpp:153
#define FADE_SCALE
Definition: AutoDuck.cpp:156
#define DUCK_AMOUNT_SCALE
Definition: AutoDuck.cpp:157
#define DUCK_AMOUNT_START
Definition: AutoDuck.cpp:154
#define CONTROL_POINT_MIN_MOVE
Definition: AutoDuck.cpp:148
static constexpr EffectParameter OuterFadeUpLen
Definition: AutoDuckBase.h:75
double mOuterFadeUpLen
Definition: AutoDuckBase.h:55
double mInnerFadeDownLen
Definition: AutoDuckBase.h:52
static constexpr EffectParameter InnerFadeDownLen
Definition: AutoDuckBase.h:66
static constexpr EffectParameter InnerFadeUpLen
Definition: AutoDuckBase.h:69
static constexpr EffectParameter DuckAmountDb
Definition: AutoDuckBase.h:63
static constexpr EffectParameter OuterFadeDownLen
Definition: AutoDuckBase.h:72
double mOuterFadeDownLen
Definition: AutoDuckBase.h:54
double mDuckAmountDb
Definition: AutoDuckBase.h:51
double mInnerFadeUpLen
Definition: AutoDuckBase.h:53
bool DoTransferDataToWindow()
Definition: AutoDuck.cpp:117
const Type min
Minimum value.
const Type max
Maximum value.

References CONTROL_POINT_MIN_MOVE, DUCK_AMOUNT_SCALE, DUCK_AMOUNT_START, AutoDuckBase::DuckAmountDb, FADE_DOWN_START, FADE_SCALE, FADE_UP_START, AutoDuckBase::InnerFadeDownLen, AutoDuckBase::InnerFadeUpLen, EffectParameter< Structure, Member, Type, Value >::max, EffectParameter< Structure, Member, Type, Value >::min, none, AutoDuckBase::OuterFadeDownLen, and AutoDuckBase::OuterFadeUpLen.

◆ OnMouseCaptureChanged()

void EffectAutoDuck::Panel::OnMouseCaptureChanged ( wxMouseCaptureChangedEvent &  evt)
private

Definition at line 368 of file AutoDuck.cpp.

370{
371 SetCursor(wxNullCursor);
373}

References none.

◆ OnMouseCaptureLost()

void EffectAutoDuck::Panel::OnMouseCaptureLost ( wxMouseCaptureLostEvent &  evt)
private

Definition at line 375 of file AutoDuck.cpp.

377{
379
380 if (HasCapture())
381 {
382 ReleaseMouse();
383 }
384}

References none.

◆ OnPaint()

void EffectAutoDuck::Panel::OnPaint ( wxPaintEvent &  evt)
private

Definition at line 205 of file AutoDuck.cpp.

206{
207 int clientWidth, clientHeight;
208 GetSize(&clientWidth, &clientHeight);
209
210 if (!mBackgroundBitmap || mBackgroundBitmap->GetWidth() != clientWidth ||
211 mBackgroundBitmap->GetHeight() != clientHeight)
212 {
213 mBackgroundBitmap = std::make_unique<wxBitmap>(clientWidth, clientHeight,24);
214 }
215
216 wxMemoryDC dc;
217 dc.SelectObject(*mBackgroundBitmap);
218
219 dc.SetBrush(*wxWHITE_BRUSH);
220 dc.SetPen(*wxBLACK_PEN);
221 dc.DrawRectangle(0, 0, clientWidth, clientHeight);
222
223 dc.SetFont(wxFont(10, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL,
224 wxFONTWEIGHT_NORMAL));
225 dc.SetTextForeground(*wxBLACK);
226 dc.SetTextBackground(*wxWHITE);
227
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);
238
239 if (innerFadeDownLen < InnerFadeDownLen.min || innerFadeDownLen > InnerFadeDownLen.max ||
240 innerFadeUpLen < InnerFadeUpLen.min || innerFadeUpLen > InnerFadeUpLen.max ||
241 outerFadeDownLen < OuterFadeDownLen.min || outerFadeDownLen > OuterFadeDownLen.max ||
242 outerFadeUpLen < OuterFadeUpLen.min || outerFadeUpLen > OuterFadeUpLen.max ||
243 duckAmountDb < DuckAmountDb.min || duckAmountDb > DuckAmountDb.max)
244 {
245 // values are out of range, no preview available
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);
251
253 } else
254 {
255 // draw preview
256 dc.SetBrush(*wxTRANSPARENT_BRUSH);
257 dc.SetPen(wxPen(theTheme.Colour(clrGraphLines), 3, wxPENSTYLE_SOLID));
258
259 wxPoint points[6];
260
261 points[0].x = 10;
262 points[0].y = DUCK_AMOUNT_START;
263
264 points[1].x = FADE_DOWN_START - (int)(outerFadeDownLen * FADE_SCALE);
265 points[1].y = DUCK_AMOUNT_START;
266
267 points[2].x = FADE_DOWN_START + (int)(innerFadeDownLen * FADE_SCALE);
268 points[2].y = DUCK_AMOUNT_START -
269 (int)(duckAmountDb * DUCK_AMOUNT_SCALE);
270
271 points[3].x = FADE_UP_START - (int)(innerFadeUpLen * FADE_SCALE);
272 points[3].y = DUCK_AMOUNT_START -
273 (int)(duckAmountDb * DUCK_AMOUNT_SCALE);
274
275 points[4].x = FADE_UP_START + (int)(outerFadeUpLen * FADE_SCALE);
276 points[4].y = DUCK_AMOUNT_START;
277
278 points[5].x = clientWidth - 10;
279 points[5].y = DUCK_AMOUNT_START;
280
281 AColor::Lines(dc, 6, points);
282
283 dc.SetPen(wxPen(*wxBLACK, 1, wxPENSTYLE_DOT));
284
285 AColor::Line(dc, FADE_DOWN_START, 10, FADE_DOWN_START, clientHeight - 10);
286 AColor::Line(dc, FADE_UP_START, 10, FADE_UP_START, clientHeight - 10);
287
288 dc.SetPen(AColor::envelopePen);
289 dc.SetBrush(*wxWHITE_BRUSH);
290
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);
297
298 for (int i = 0; i < AUTO_DUCK_PANEL_NUM_CONTROL_POINTS; i++)
299 {
301 int digits;
302 float value;
303
304 if (cp == innerFadeDown)
305 {
306 value = innerFadeDownLen;
307 digits = 2;
308 }
309 else if (cp == innerFadeUp)
310 {
311 value = innerFadeUpLen;
312 digits = 2;
313 }
314 else if (cp == outerFadeDown)
315 {
316 value = outerFadeDownLen;
317 digits = 2;
318 } else if (cp == outerFadeUp)
319 {
320 value = outerFadeUpLen;
321 digits = 2;
322 }
323 else
324 {
325 value = duckAmountDb;
326 digits = 1;
327 }
328
329 wxString valueStr = Internat::ToDisplayString(value, digits);
330 valueStr += wxT(" ");
331
332 if (cp == duckAmount)
333 /* i18n-hint: short form of 'decibels'.*/
334 valueStr += _("dB");
335 else
336 /* i18n-hint: short form of 'seconds'.*/
337 valueStr += _("s");
338
339 int textWidth = 0, textHeight = 0;
340 GetTextExtent(valueStr, &textWidth, &textHeight);
341
342 int textPosX = mControlPoints[i].x - textWidth / 2;
343 int textPosY = mControlPoints[i].y;
344
345 if (cp == duckAmount || cp == outerFadeDown || cp == outerFadeUp)
346 textPosY -= TEXT_DISTANCE + textHeight;
347 else
348 textPosY += TEXT_DISTANCE;
349
350 dc.DrawText(valueStr, textPosX, textPosY);
351
352 dc.DrawEllipse(mControlPoints[i].x - 3,
353 mControlPoints[i].y - 3, 6, 6);
354 }
355 }
356
357 // copy background buffer to paint dc
358 wxPaintDC paintDC(this);
359 paintDC.Blit(0, 0, clientWidth, clientHeight, &dc, 0, 0);
360
361 // clean up: necessary to free resources on Windows
362 dc.SetPen(wxNullPen);
363 dc.SetBrush(wxNullBrush);
364 dc.SetFont(wxNullFont);
365 dc.SelectObject(wxNullBitmap);
366}
wxT("CloseDown"))
#define TEXT_DISTANCE
Definition: AutoDuck.cpp:150
#define _(s)
Definition: Internat.h:73
THEME_API Theme theTheme
Definition: Theme.cpp:82
static void Line(wxDC &dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
Definition: AColor.cpp:194
static void Lines(wxDC &dc, size_t nPoints, const wxPoint points[])
Definition: AColor.cpp:206
static wxPen envelopePen
Definition: AColor.h:116
wxTextCtrl * mInnerFadeUpLenBox
Definition: AutoDuck.h:47
wxTextCtrl * mInnerFadeDownLenBox
Definition: AutoDuck.h:46
wxTextCtrl * mOuterFadeDownLenBox
Definition: AutoDuck.h:48
wxTextCtrl * mOuterFadeUpLenBox
Definition: AutoDuck.h:49
wxTextCtrl * mDuckAmountDbBox
Definition: AutoDuck.h:45
static wxString ToDisplayString(double numberToConvert, int digitsAfterDecimalPoint=-1)
Convert a number to a string, uses the user's locale's decimal separator.
Definition: Internat.cpp:137
wxColour & Colour(int iIndex)

References _, AUTO_DUCK_PANEL_NUM_CONTROL_POINTS, ThemeBase::Colour(), DUCK_AMOUNT_SCALE, DUCK_AMOUNT_START, AutoDuckBase::DuckAmountDb, AColor::envelopePen, FADE_DOWN_START, FADE_SCALE, FADE_UP_START, AutoDuckBase::InnerFadeDownLen, AutoDuckBase::InnerFadeUpLen, AColor::Line(), AColor::Lines(), EffectParameter< Structure, Member, Type, Value >::max, AutoDuckBase::OuterFadeDownLen, AutoDuckBase::OuterFadeUpLen, TEXT_DISTANCE, theTheme, Internat::ToDisplayString(), and wxT().

Here is the call graph for this function:

◆ ResetControlPoints()

void EffectAutoDuck::Panel::ResetControlPoints ( )
private

Definition at line 196 of file AutoDuck.cpp.

197{
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);
203}

Member Data Documentation

◆ mBackgroundBitmap

std::unique_ptr<wxBitmap> EffectAutoDuck::Panel::mBackgroundBitmap
private

Definition at line 93 of file AutoDuck.h.

◆ mControlPointMoveActivated

bool EffectAutoDuck::Panel::mControlPointMoveActivated
private

Definition at line 98 of file AutoDuck.h.

◆ mControlPoints

wxPoint EffectAutoDuck::Panel::mControlPoints[AUTO_DUCK_PANEL_NUM_CONTROL_POINTS]
private

Definition at line 95 of file AutoDuck.h.

◆ mCurrentControlPoint

EControlPoint EffectAutoDuck::Panel::mCurrentControlPoint
private

Definition at line 94 of file AutoDuck.h.

◆ mEffect

EffectAutoDuck* EffectAutoDuck::Panel::mEffect
private

Definition at line 92 of file AutoDuck.h.

◆ mMouseDownPoint

wxPoint EffectAutoDuck::Panel::mMouseDownPoint
private

Definition at line 97 of file AutoDuck.h.

◆ mMoveStartControlPoints

wxPoint EffectAutoDuck::Panel::mMoveStartControlPoints[AUTO_DUCK_PANEL_NUM_CONTROL_POINTS]
private

Definition at line 96 of file AutoDuck.h.

◆ mParent

wxWindow* EffectAutoDuck::Panel::mParent
private

Definition at line 91 of file AutoDuck.h.


The documentation for this class was generated from the following files: