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 106 of file AutoDuck.h.

Member Enumeration Documentation

◆ EControlPoint

Enumerator
innerFadeDown 
outerFadeDown 
innerFadeUp 
outerFadeUp 
duckAmount 
none 

Definition at line 114 of file AutoDuck.h.

Constructor & Destructor Documentation

◆ Panel()

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

Definition at line 543 of file AutoDuck.cpp.

545: wxPanelWrapper(parent, winid, wxDefaultPosition, wxSize(600, 300))
546{
547 mParent = parent;
548 mEffect = effect;
550 mBackgroundBitmap = NULL;
551
553}
std::unique_ptr< wxBitmap > mBackgroundBitmap
Definition: AutoDuck.h:142
wxWindow * mParent
Definition: AutoDuck.h:140
EControlPoint mCurrentControlPoint
Definition: AutoDuck.h:143
EffectAutoDuck * mEffect
Definition: AutoDuck.h:141

References none.

◆ ~Panel()

EffectAutoDuck::Panel::~Panel ( )
virtual

Definition at line 555 of file AutoDuck.cpp.

556{
557 if(HasCapture())
558 ReleaseMouse();
559}

Member Function Documentation

◆ AcceptsFocus()

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

Definition at line 124 of file AutoDuck.h.

124{ return false; }

◆ AcceptsFocusFromKeyboard()

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

Definition at line 126 of file AutoDuck.h.

126{ return false; }

◆ GetNearestControlPoint()

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

Definition at line 752 of file AutoDuck.cpp.

753{
755 int i;
756
757 for (i = 0; i < AUTO_DUCK_PANEL_NUM_CONTROL_POINTS; i++)
758 dist[i] = GetDistance(pt, mControlPoints[i]);
759
760 int curMinimum = 0;
761 for (i = 0; i < AUTO_DUCK_PANEL_NUM_CONTROL_POINTS; i++)
762 if (dist[i] < dist[curMinimum])
763 curMinimum = i;
764
765 if (dist[curMinimum] <= CONTROL_POINT_REGION)
766 return (EControlPoint)curMinimum;
767 else
768 return none;
769}
#define CONTROL_POINT_REGION
Definition: AutoDuck.cpp:512
static int GetDistance(const wxPoint &first, const wxPoint &second)
Definition: AutoDuck.cpp:524
#define AUTO_DUCK_PANEL_NUM_CONTROL_POINTS
Definition: AutoDuck.h:23
wxPoint mControlPoints[AUTO_DUCK_PANEL_NUM_CONTROL_POINTS]
Definition: AutoDuck.h:144

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 771 of file AutoDuck.cpp.

772{
773 EControlPoint nearest = GetNearestControlPoint(evt.GetPosition());
774
775 if (nearest != none)
776 {
777 // this control point has been clicked
778 mMouseDownPoint = evt.GetPosition();
779
780 mCurrentControlPoint = nearest;
782
783 for (int i = 0; i < AUTO_DUCK_PANEL_NUM_CONTROL_POINTS; i++)
785
786 if( !HasCapture() )
787 CaptureMouse();
788 }
789}
EControlPoint GetNearestControlPoint(const wxPoint &pt)
Definition: AutoDuck.cpp:752
bool mControlPointMoveActivated
Definition: AutoDuck.h:147
wxPoint mMouseDownPoint
Definition: AutoDuck.h:146
wxPoint mMoveStartControlPoints[AUTO_DUCK_PANEL_NUM_CONTROL_POINTS]
Definition: AutoDuck.h:145

References AUTO_DUCK_PANEL_NUM_CONTROL_POINTS, and none.

◆ OnLeftUp()

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

Definition at line 791 of file AutoDuck.cpp.

792{
794 {
796 ReleaseMouse();
797 }
798}

References none.

◆ OnMotion()

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

Definition at line 800 of file AutoDuck.cpp.

801{
802 switch (GetNearestControlPoint(evt.GetPosition()))
803 {
804 case none:
805 SetCursor(wxNullCursor);
806 break;
807 case innerFadeDown:
808 case innerFadeUp:
809 case outerFadeDown:
810 case outerFadeUp:
811 SetCursor(wxCursor(wxCURSOR_SIZEWE));
812 break;
813 case duckAmount:
814 SetCursor(wxCursor(wxCURSOR_SIZENS));
815 break;
816 }
817
819 {
821 {
822 int dist;
823
825 dist = abs(evt.GetY() - mMouseDownPoint.y);
826 else
827 dist = abs(evt.GetX() - mMouseDownPoint.x);
828
829 if (dist >= CONTROL_POINT_MIN_MOVE)
831 }
832
834 {
835 float newValue;
836
837 switch (mCurrentControlPoint)
838 {
839 case outerFadeDown:
840 newValue = ((double)(FADE_DOWN_START - evt.GetX())) / FADE_SCALE;
841 mEffect->mOuterFadeDownLen = std::clamp<double>(newValue, OuterFadeDownLen.min, OuterFadeDownLen.max);
842 break;
843 case outerFadeUp:
844 newValue = ((double)(evt.GetX() - FADE_UP_START)) / FADE_SCALE;
845 mEffect->mOuterFadeUpLen = std::clamp<double>(newValue, OuterFadeUpLen.min, OuterFadeUpLen.max);
846 break;
847 case innerFadeDown:
848 newValue = ((double)(evt.GetX() - FADE_DOWN_START)) / FADE_SCALE;
849 mEffect->mInnerFadeDownLen = std::clamp<double>(newValue, InnerFadeDownLen.min, InnerFadeDownLen.max);
850 break;
851 case innerFadeUp:
852 newValue = ((double)(FADE_UP_START - evt.GetX())) / FADE_SCALE;
853 mEffect->mInnerFadeUpLen = std::clamp<double>(newValue, InnerFadeUpLen.min, InnerFadeUpLen.max);
854 break;
855 case duckAmount:
856 newValue = ((double)(DUCK_AMOUNT_START - evt.GetY())) / DUCK_AMOUNT_SCALE;
857 mEffect->mDuckAmountDb = std::clamp<double>(newValue, DuckAmountDb.min, DuckAmountDb.max);
858 break;
859 case none:
860 wxASSERT(false); // should not happen
861 }
863 Refresh(false);
864 }
865 }
866}
#define FADE_DOWN_START
Definition: AutoDuck.cpp:517
#define FADE_UP_START
Definition: AutoDuck.cpp:518
#define FADE_SCALE
Definition: AutoDuck.cpp:521
#define DUCK_AMOUNT_SCALE
Definition: AutoDuck.cpp:522
#define DUCK_AMOUNT_START
Definition: AutoDuck.cpp:519
#define CONTROL_POINT_MIN_MOVE
Definition: AutoDuck.cpp:513
static constexpr EffectParameter InnerFadeDownLen
Definition: AutoDuck.h:92
double mInnerFadeDownLen
Definition: AutoDuck.h:67
static constexpr EffectParameter InnerFadeUpLen
Definition: AutoDuck.h:94
static constexpr EffectParameter OuterFadeDownLen
Definition: AutoDuck.h:96
bool DoTransferDataToWindow()
Definition: AutoDuck.cpp:415
double mDuckAmountDb
Definition: AutoDuck.h:66
double mInnerFadeUpLen
Definition: AutoDuck.h:68
static constexpr EffectParameter DuckAmountDb
Definition: AutoDuck.h:90
double mOuterFadeDownLen
Definition: AutoDuck.h:69
static constexpr EffectParameter OuterFadeUpLen
Definition: AutoDuck.h:98
double mOuterFadeUpLen
Definition: AutoDuck.h:70
const Type min
Minimum value.
Definition: Shuttle.h:30
const Type max
Maximum value.
Definition: Shuttle.h:31

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

◆ OnMouseCaptureChanged()

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

Definition at line 733 of file AutoDuck.cpp.

735{
736 SetCursor(wxNullCursor);
738}

References none.

◆ OnMouseCaptureLost()

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

Definition at line 740 of file AutoDuck.cpp.

742{
744
745 if (HasCapture())
746 {
747 ReleaseMouse();
748 }
749}

References none.

◆ OnPaint()

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

Definition at line 570 of file AutoDuck.cpp.

571{
572 int clientWidth, clientHeight;
573 GetSize(&clientWidth, &clientHeight);
574
575 if (!mBackgroundBitmap || mBackgroundBitmap->GetWidth() != clientWidth ||
576 mBackgroundBitmap->GetHeight() != clientHeight)
577 {
578 mBackgroundBitmap = std::make_unique<wxBitmap>(clientWidth, clientHeight,24);
579 }
580
581 wxMemoryDC dc;
582 dc.SelectObject(*mBackgroundBitmap);
583
584 dc.SetBrush(*wxWHITE_BRUSH);
585 dc.SetPen(*wxBLACK_PEN);
586 dc.DrawRectangle(0, 0, clientWidth, clientHeight);
587
588 dc.SetFont(wxFont(10, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL,
589 wxFONTWEIGHT_NORMAL));
590 dc.SetTextForeground(*wxBLACK);
591 dc.SetTextBackground(*wxWHITE);
592
593 double duckAmountDb = 0;
594 double innerFadeDownLen = 0;
595 double innerFadeUpLen = 0;
596 double outerFadeDownLen = 0;
597 double outerFadeUpLen = 0;
598 mEffect->mDuckAmountDbBox->GetValue().ToDouble(&duckAmountDb);
599 mEffect->mInnerFadeDownLenBox->GetValue().ToDouble(&innerFadeDownLen);
600 mEffect->mInnerFadeUpLenBox->GetValue().ToDouble(&innerFadeUpLen);
601 mEffect->mOuterFadeDownLenBox->GetValue().ToDouble(&outerFadeDownLen);
602 mEffect->mOuterFadeUpLenBox->GetValue().ToDouble(&outerFadeUpLen);
603
604 if (innerFadeDownLen < InnerFadeDownLen.min || innerFadeDownLen > InnerFadeDownLen.max ||
605 innerFadeUpLen < InnerFadeUpLen.min || innerFadeUpLen > InnerFadeUpLen.max ||
606 outerFadeDownLen < OuterFadeDownLen.min || outerFadeDownLen > OuterFadeDownLen.max ||
607 outerFadeUpLen < OuterFadeUpLen.min || outerFadeUpLen > OuterFadeUpLen.max ||
608 duckAmountDb < DuckAmountDb.min || duckAmountDb > DuckAmountDb.max)
609 {
610 // values are out of range, no preview available
611 wxString message = _("Preview not available");
612 int textWidth = 0, textHeight = 0;
613 dc.GetTextExtent(message, &textWidth, &textHeight);
614 dc.DrawText(message, (clientWidth - textWidth) / 2,
615 (clientHeight - textHeight) / 2);
616
618 } else
619 {
620 // draw preview
621 dc.SetBrush(*wxTRANSPARENT_BRUSH);
622 dc.SetPen(wxPen(theTheme.Colour(clrGraphLines), 3, wxPENSTYLE_SOLID));
623
624 wxPoint points[6];
625
626 points[0].x = 10;
627 points[0].y = DUCK_AMOUNT_START;
628
629 points[1].x = FADE_DOWN_START - (int)(outerFadeDownLen * FADE_SCALE);
630 points[1].y = DUCK_AMOUNT_START;
631
632 points[2].x = FADE_DOWN_START + (int)(innerFadeDownLen * FADE_SCALE);
633 points[2].y = DUCK_AMOUNT_START -
634 (int)(duckAmountDb * DUCK_AMOUNT_SCALE);
635
636 points[3].x = FADE_UP_START - (int)(innerFadeUpLen * FADE_SCALE);
637 points[3].y = DUCK_AMOUNT_START -
638 (int)(duckAmountDb * DUCK_AMOUNT_SCALE);
639
640 points[4].x = FADE_UP_START + (int)(outerFadeUpLen * FADE_SCALE);
641 points[4].y = DUCK_AMOUNT_START;
642
643 points[5].x = clientWidth - 10;
644 points[5].y = DUCK_AMOUNT_START;
645
646 AColor::Lines(dc, 6, points);
647
648 dc.SetPen(wxPen(*wxBLACK, 1, wxPENSTYLE_DOT));
649
650 AColor::Line(dc, FADE_DOWN_START, 10, FADE_DOWN_START, clientHeight - 10);
651 AColor::Line(dc, FADE_UP_START, 10, FADE_UP_START, clientHeight - 10);
652
653 dc.SetPen(AColor::envelopePen);
654 dc.SetBrush(*wxWHITE_BRUSH);
655
656 mControlPoints[outerFadeDown] = points[1];
657 mControlPoints[innerFadeDown] = points[2];
658 mControlPoints[innerFadeUp] = points[3];
659 mControlPoints[outerFadeUp] = points[4];
660 mControlPoints[duckAmount] = wxPoint(
661 (points[2].x + points[3].x) / 2, points[2].y);
662
663 for (int i = 0; i < AUTO_DUCK_PANEL_NUM_CONTROL_POINTS; i++)
664 {
666 int digits;
667 float value;
668
669 if (cp == innerFadeDown)
670 {
671 value = innerFadeDownLen;
672 digits = 2;
673 }
674 else if (cp == innerFadeUp)
675 {
676 value = innerFadeUpLen;
677 digits = 2;
678 }
679 else if (cp == outerFadeDown)
680 {
681 value = outerFadeDownLen;
682 digits = 2;
683 } else if (cp == outerFadeUp)
684 {
685 value = outerFadeUpLen;
686 digits = 2;
687 }
688 else
689 {
690 value = duckAmountDb;
691 digits = 1;
692 }
693
694 wxString valueStr = Internat::ToDisplayString(value, digits);
695 valueStr += wxT(" ");
696
697 if (cp == duckAmount)
698 /* i18n-hint: short form of 'decibels'.*/
699 valueStr += _("dB");
700 else
701 /* i18n-hint: short form of 'seconds'.*/
702 valueStr += _("s");
703
704 int textWidth = 0, textHeight = 0;
705 GetTextExtent(valueStr, &textWidth, &textHeight);
706
707 int textPosX = mControlPoints[i].x - textWidth / 2;
708 int textPosY = mControlPoints[i].y;
709
710 if (cp == duckAmount || cp == outerFadeDown || cp == outerFadeUp)
711 textPosY -= TEXT_DISTANCE + textHeight;
712 else
713 textPosY += TEXT_DISTANCE;
714
715 dc.DrawText(valueStr, textPosX, textPosY);
716
717 dc.DrawEllipse(mControlPoints[i].x - 3,
718 mControlPoints[i].y - 3, 6, 6);
719 }
720 }
721
722 // copy background buffer to paint dc
723 wxPaintDC paintDC(this);
724 paintDC.Blit(0, 0, clientWidth, clientHeight, &dc, 0, 0);
725
726 // clean up: necessary to free resources on Windows
727 dc.SetPen(wxNullPen);
728 dc.SetBrush(wxNullBrush);
729 dc.SetFont(wxNullFont);
730 dc.SelectObject(wxNullBitmap);
731}
wxT("CloseDown"))
#define TEXT_DISTANCE
Definition: AutoDuck.cpp:515
#define _(s)
Definition: Internat.h:75
THEME_API Theme theTheme
Definition: Theme.cpp:82
static void Line(wxDC &dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
Definition: AColor.cpp:187
static void Lines(wxDC &dc, size_t nPoints, const wxPoint points[])
Definition: AColor.cpp:194
static wxPen envelopePen
Definition: AColor.h:115
wxTextCtrl * mInnerFadeUpLenBox
Definition: AutoDuck.h:78
wxTextCtrl * mInnerFadeDownLenBox
Definition: AutoDuck.h:77
wxTextCtrl * mOuterFadeDownLenBox
Definition: AutoDuck.h:79
wxTextCtrl * mOuterFadeUpLenBox
Definition: AutoDuck.h:80
wxTextCtrl * mDuckAmountDbBox
Definition: AutoDuck.h:76
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:161
wxColour & Colour(int iIndex)

References _, AUTO_DUCK_PANEL_NUM_CONTROL_POINTS, ThemeBase::Colour(), DUCK_AMOUNT_SCALE, DUCK_AMOUNT_START, EffectAutoDuck::DuckAmountDb, AColor::envelopePen, FADE_DOWN_START, FADE_SCALE, FADE_UP_START, EffectAutoDuck::InnerFadeDownLen, EffectAutoDuck::InnerFadeUpLen, AColor::Line(), AColor::Lines(), EffectParameter< Structure, Member, Type, Value >::max, EffectAutoDuck::OuterFadeDownLen, EffectAutoDuck::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 561 of file AutoDuck.cpp.

562{
563 mControlPoints[innerFadeDown] = wxPoint(-100,-100);
564 mControlPoints[innerFadeUp] = wxPoint(-100,-100);
565 mControlPoints[outerFadeDown] = wxPoint(-100,-100);
566 mControlPoints[outerFadeUp] = wxPoint(-100,-100);
567 mControlPoints[duckAmount] = wxPoint(-100,-100);
568}

Member Data Documentation

◆ mBackgroundBitmap

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

Definition at line 142 of file AutoDuck.h.

◆ mControlPointMoveActivated

bool EffectAutoDuck::Panel::mControlPointMoveActivated
private

Definition at line 147 of file AutoDuck.h.

◆ mControlPoints

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

Definition at line 144 of file AutoDuck.h.

◆ mCurrentControlPoint

EControlPoint EffectAutoDuck::Panel::mCurrentControlPoint
private

Definition at line 143 of file AutoDuck.h.

◆ mEffect

EffectAutoDuck* EffectAutoDuck::Panel::mEffect
private

Definition at line 141 of file AutoDuck.h.

◆ mMouseDownPoint

wxPoint EffectAutoDuck::Panel::mMouseDownPoint
private

Definition at line 146 of file AutoDuck.h.

◆ mMoveStartControlPoints

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

Definition at line 145 of file AutoDuck.h.

◆ mParent

wxWindow* EffectAutoDuck::Panel::mParent
private

Definition at line 140 of file AutoDuck.h.


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