Audacity 3.2.0
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
EffectAutoDuckPanel Class Referencefinal

#include <AutoDuck.h>

Inheritance diagram for EffectAutoDuckPanel:
[legend]
Collaboration diagram for EffectAutoDuckPanel:
[legend]

Public Member Functions

 EffectAutoDuckPanel (wxWindow *parent, wxWindowID winid, EffectAutoDuck *effect)
 
virtual ~EffectAutoDuckPanel ()
 
- 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 89 of file AutoDuck.h.

Member Enumeration Documentation

◆ EControlPoint

Enumerator
innerFadeDown 
outerFadeDown 
innerFadeUp 
outerFadeUp 
duckAmount 
none 

Definition at line 97 of file AutoDuck.h.

Constructor & Destructor Documentation

◆ EffectAutoDuckPanel()

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

Definition at line 595 of file AutoDuck.cpp.

597: wxPanelWrapper(parent, winid, wxDefaultPosition, wxSize(600, 300))
598{
599 mParent = parent;
600 mEffect = effect;
602 mBackgroundBitmap = NULL;
603
605}
void ResetControlPoints()
Definition: AutoDuck.cpp:613
EControlPoint mCurrentControlPoint
Definition: AutoDuck.h:126
wxWindow * mParent
Definition: AutoDuck.h:123
std::unique_ptr< wxBitmap > mBackgroundBitmap
Definition: AutoDuck.h:125
EffectAutoDuck * mEffect
Definition: AutoDuck.h:124

References none.

◆ ~EffectAutoDuckPanel()

EffectAutoDuckPanel::~EffectAutoDuckPanel ( )
virtual

Definition at line 607 of file AutoDuck.cpp.

608{
609 if(HasCapture())
610 ReleaseMouse();
611}

Member Function Documentation

◆ AcceptsFocus()

bool EffectAutoDuckPanel::AcceptsFocus ( ) const
inlineoverrideprivate

Definition at line 107 of file AutoDuck.h.

107{ return false; }

◆ AcceptsFocusFromKeyboard()

bool EffectAutoDuckPanel::AcceptsFocusFromKeyboard ( ) const
inlineoverrideprivate

Definition at line 109 of file AutoDuck.h.

109{ return false; }

◆ GetNearestControlPoint()

EffectAutoDuckPanel::EControlPoint EffectAutoDuckPanel::GetNearestControlPoint ( const wxPoint &  pt)
private

Definition at line 804 of file AutoDuck.cpp.

805{
807 int i;
808
809 for (i = 0; i < AUTO_DUCK_PANEL_NUM_CONTROL_POINTS; i++)
810 dist[i] = GetDistance(pt, mControlPoints[i]);
811
812 int curMinimum = 0;
813 for (i = 0; i < AUTO_DUCK_PANEL_NUM_CONTROL_POINTS; i++)
814 if (dist[i] < dist[curMinimum])
815 curMinimum = i;
816
817 if (dist[curMinimum] <= CONTROL_POINT_REGION)
818 return (EControlPoint)curMinimum;
819 else
820 return none;
821}
#define CONTROL_POINT_REGION
Definition: AutoDuck.cpp:564
static int GetDistance(const wxPoint &first, const wxPoint &second)
Definition: AutoDuck.cpp:576
#define AUTO_DUCK_PANEL_NUM_CONTROL_POINTS
Definition: AutoDuck.h:21
wxPoint mControlPoints[AUTO_DUCK_PANEL_NUM_CONTROL_POINTS]
Definition: AutoDuck.h:127

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

Referenced by OnLeftDown(), and OnMotion().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnLeftDown()

void EffectAutoDuckPanel::OnLeftDown ( wxMouseEvent &  evt)
private

Definition at line 823 of file AutoDuck.cpp.

824{
825 EControlPoint nearest = GetNearestControlPoint(evt.GetPosition());
826
827 if (nearest != none)
828 {
829 // this control point has been clicked
830 mMouseDownPoint = evt.GetPosition();
831
832 mCurrentControlPoint = nearest;
834
835 for (int i = 0; i < AUTO_DUCK_PANEL_NUM_CONTROL_POINTS; i++)
837
838 if( !HasCapture() )
839 CaptureMouse();
840 }
841}
EControlPoint GetNearestControlPoint(const wxPoint &pt)
Definition: AutoDuck.cpp:804
wxPoint mMoveStartControlPoints[AUTO_DUCK_PANEL_NUM_CONTROL_POINTS]
Definition: AutoDuck.h:128
wxPoint mMouseDownPoint
Definition: AutoDuck.h:129
bool mControlPointMoveActivated
Definition: AutoDuck.h:130

References AUTO_DUCK_PANEL_NUM_CONTROL_POINTS, GetNearestControlPoint(), mControlPointMoveActivated, mControlPoints, mCurrentControlPoint, mMouseDownPoint, mMoveStartControlPoints, and none.

Here is the call graph for this function:

◆ OnLeftUp()

void EffectAutoDuckPanel::OnLeftUp ( wxMouseEvent &  evt)
private

Definition at line 843 of file AutoDuck.cpp.

844{
846 {
848 ReleaseMouse();
849 }
850}

References mCurrentControlPoint, and none.

◆ OnMotion()

void EffectAutoDuckPanel::OnMotion ( wxMouseEvent &  evt)
private

Definition at line 852 of file AutoDuck.cpp.

853{
854 switch (GetNearestControlPoint(evt.GetPosition()))
855 {
856 case none:
857 SetCursor(wxNullCursor);
858 break;
859 case innerFadeDown:
860 case innerFadeUp:
861 case outerFadeDown:
862 case outerFadeUp:
863 SetCursor(wxCursor(wxCURSOR_SIZEWE));
864 break;
865 case duckAmount:
866 SetCursor(wxCursor(wxCURSOR_SIZENS));
867 break;
868 }
869
871 {
873 {
874 int dist;
875
877 dist = abs(evt.GetY() - mMouseDownPoint.y);
878 else
879 dist = abs(evt.GetX() - mMouseDownPoint.x);
880
881 if (dist >= CONTROL_POINT_MIN_MOVE)
883 }
884
886 {
887 float newValue;
888
889 switch (mCurrentControlPoint)
890 {
891 case outerFadeDown:
892 newValue = ((double)(FADE_DOWN_START - evt.GetX())) / FADE_SCALE;
894 std::clamp<double>(newValue, MIN_OuterFadeDownLen, MAX_OuterFadeDownLen);
895 break;
896 case outerFadeUp:
897 newValue = ((double)(evt.GetX() - FADE_UP_START)) / FADE_SCALE;
899 std::clamp<double>(newValue, MIN_OuterFadeUpLen, MAX_OuterFadeUpLen);
900 break;
901 case innerFadeDown:
902 newValue = ((double)(evt.GetX() - FADE_DOWN_START)) / FADE_SCALE;
904 std::clamp<double>(newValue, MIN_InnerFadeDownLen, MAX_InnerFadeDownLen);
905 break;
906 case innerFadeUp:
907 newValue = ((double)(FADE_UP_START - evt.GetX())) / FADE_SCALE;
909 std::clamp<double>(newValue, MIN_InnerFadeUpLen, MAX_InnerFadeUpLen);
910 break;
911 case duckAmount:
912 newValue = ((double)(DUCK_AMOUNT_START - evt.GetY())) / DUCK_AMOUNT_SCALE;
914 std::clamp<double>(newValue, MIN_DuckAmountDb, MAX_DuckAmountDb);
915 break;
916 case none:
917 wxASSERT(false); // should not happen
918 }
920 Refresh(false);
921 }
922 }
923}
#define FADE_DOWN_START
Definition: AutoDuck.cpp:569
#define FADE_UP_START
Definition: AutoDuck.cpp:570
#define FADE_SCALE
Definition: AutoDuck.cpp:573
#define DUCK_AMOUNT_SCALE
Definition: AutoDuck.cpp:574
#define DUCK_AMOUNT_START
Definition: AutoDuck.cpp:571
#define CONTROL_POINT_MIN_MOVE
Definition: AutoDuck.cpp:565
double mInnerFadeDownLen
Definition: AutoDuck.h:66
bool DoTransferDataToWindow()
Definition: AutoDuck.cpp:482
double mDuckAmountDb
Definition: AutoDuck.h:65
double mInnerFadeUpLen
Definition: AutoDuck.h:67
double mOuterFadeDownLen
Definition: AutoDuck.h:68
double mOuterFadeUpLen
Definition: AutoDuck.h:69

References CONTROL_POINT_MIN_MOVE, EffectAutoDuck::DoTransferDataToWindow(), DUCK_AMOUNT_SCALE, DUCK_AMOUNT_START, duckAmount, FADE_DOWN_START, FADE_SCALE, FADE_UP_START, GetNearestControlPoint(), innerFadeDown, innerFadeUp, mControlPointMoveActivated, mCurrentControlPoint, EffectAutoDuck::mDuckAmountDb, mEffect, EffectAutoDuck::mInnerFadeDownLen, EffectAutoDuck::mInnerFadeUpLen, mMouseDownPoint, EffectAutoDuck::mOuterFadeDownLen, EffectAutoDuck::mOuterFadeUpLen, none, outerFadeDown, and outerFadeUp.

Here is the call graph for this function:

◆ OnMouseCaptureChanged()

void EffectAutoDuckPanel::OnMouseCaptureChanged ( wxMouseCaptureChangedEvent &  evt)
private

Definition at line 785 of file AutoDuck.cpp.

787{
788 SetCursor(wxNullCursor);
790}

References mCurrentControlPoint, and none.

◆ OnMouseCaptureLost()

void EffectAutoDuckPanel::OnMouseCaptureLost ( wxMouseCaptureLostEvent &  evt)
private

Definition at line 792 of file AutoDuck.cpp.

794{
796
797 if (HasCapture())
798 {
799 ReleaseMouse();
800 }
801}

References mCurrentControlPoint, and none.

◆ OnPaint()

void EffectAutoDuckPanel::OnPaint ( wxPaintEvent &  evt)
private

Definition at line 622 of file AutoDuck.cpp.

623{
624 int clientWidth, clientHeight;
625 GetSize(&clientWidth, &clientHeight);
626
627 if (!mBackgroundBitmap || mBackgroundBitmap->GetWidth() != clientWidth ||
628 mBackgroundBitmap->GetHeight() != clientHeight)
629 {
630 mBackgroundBitmap = std::make_unique<wxBitmap>(clientWidth, clientHeight,24);
631 }
632
633 wxMemoryDC dc;
634 dc.SelectObject(*mBackgroundBitmap);
635
636 dc.SetBrush(*wxWHITE_BRUSH);
637 dc.SetPen(*wxBLACK_PEN);
638 dc.DrawRectangle(0, 0, clientWidth, clientHeight);
639
640 dc.SetFont(wxFont(10, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL,
641 wxFONTWEIGHT_NORMAL));
642 dc.SetTextForeground(*wxBLACK);
643 dc.SetTextBackground(*wxWHITE);
644
645 double duckAmountDb = 0;
646 double innerFadeDownLen = 0;
647 double innerFadeUpLen = 0;
648 double outerFadeDownLen = 0;
649 double outerFadeUpLen = 0;
650 mEffect->mDuckAmountDbBox->GetValue().ToDouble(&duckAmountDb);
651 mEffect->mInnerFadeDownLenBox->GetValue().ToDouble(&innerFadeDownLen);
652 mEffect->mInnerFadeUpLenBox->GetValue().ToDouble(&innerFadeUpLen);
653 mEffect->mOuterFadeDownLenBox->GetValue().ToDouble(&outerFadeDownLen);
654 mEffect->mOuterFadeUpLenBox->GetValue().ToDouble(&outerFadeUpLen);
655
656 if (innerFadeDownLen < MIN_InnerFadeDownLen || innerFadeDownLen > MAX_InnerFadeDownLen ||
657 innerFadeUpLen < MIN_InnerFadeUpLen || innerFadeUpLen > MAX_InnerFadeUpLen ||
658 outerFadeDownLen < MIN_OuterFadeDownLen || outerFadeDownLen > MAX_OuterFadeDownLen ||
659 outerFadeUpLen < MIN_OuterFadeUpLen || outerFadeUpLen > MAX_OuterFadeUpLen ||
660 duckAmountDb < MIN_DuckAmountDb || duckAmountDb > MAX_DuckAmountDb)
661 {
662 // values are out of range, no preview available
663 wxString message = _("Preview not available");
664 int textWidth = 0, textHeight = 0;
665 dc.GetTextExtent(message, &textWidth, &textHeight);
666 dc.DrawText(message, (clientWidth - textWidth) / 2,
667 (clientHeight - textHeight) / 2);
668
670 } else
671 {
672 // draw preview
673 dc.SetBrush(*wxTRANSPARENT_BRUSH);
674 dc.SetPen(wxPen(theTheme.Colour(clrGraphLines), 3, wxPENSTYLE_SOLID));
675
676 wxPoint points[6];
677
678 points[0].x = 10;
679 points[0].y = DUCK_AMOUNT_START;
680
681 points[1].x = FADE_DOWN_START - (int)(outerFadeDownLen * FADE_SCALE);
682 points[1].y = DUCK_AMOUNT_START;
683
684 points[2].x = FADE_DOWN_START + (int)(innerFadeDownLen * FADE_SCALE);
685 points[2].y = DUCK_AMOUNT_START -
686 (int)(duckAmountDb * DUCK_AMOUNT_SCALE);
687
688 points[3].x = FADE_UP_START - (int)(innerFadeUpLen * FADE_SCALE);
689 points[3].y = DUCK_AMOUNT_START -
690 (int)(duckAmountDb * DUCK_AMOUNT_SCALE);
691
692 points[4].x = FADE_UP_START + (int)(outerFadeUpLen * FADE_SCALE);
693 points[4].y = DUCK_AMOUNT_START;
694
695 points[5].x = clientWidth - 10;
696 points[5].y = DUCK_AMOUNT_START;
697
698 AColor::Lines(dc, 6, points);
699
700 dc.SetPen(wxPen(*wxBLACK, 1, wxPENSTYLE_DOT));
701
702 AColor::Line(dc, FADE_DOWN_START, 10, FADE_DOWN_START, clientHeight - 10);
703 AColor::Line(dc, FADE_UP_START, 10, FADE_UP_START, clientHeight - 10);
704
705 dc.SetPen(AColor::envelopePen);
706 dc.SetBrush(*wxWHITE_BRUSH);
707
708 mControlPoints[outerFadeDown] = points[1];
709 mControlPoints[innerFadeDown] = points[2];
710 mControlPoints[innerFadeUp] = points[3];
711 mControlPoints[outerFadeUp] = points[4];
712 mControlPoints[duckAmount] = wxPoint(
713 (points[2].x + points[3].x) / 2, points[2].y);
714
715 for (int i = 0; i < AUTO_DUCK_PANEL_NUM_CONTROL_POINTS; i++)
716 {
718 int digits;
719 float value;
720
721 if (cp == innerFadeDown)
722 {
723 value = innerFadeDownLen;
724 digits = 2;
725 }
726 else if (cp == innerFadeUp)
727 {
728 value = innerFadeUpLen;
729 digits = 2;
730 }
731 else if (cp == outerFadeDown)
732 {
733 value = outerFadeDownLen;
734 digits = 2;
735 } else if (cp == outerFadeUp)
736 {
737 value = outerFadeUpLen;
738 digits = 2;
739 }
740 else
741 {
742 value = duckAmountDb;
743 digits = 1;
744 }
745
746 wxString valueStr = Internat::ToDisplayString(value, digits);
747 valueStr += wxT(" ");
748
749 if (cp == duckAmount)
750 /* i18n-hint: short form of 'decibels'.*/
751 valueStr += _("dB");
752 else
753 /* i18n-hint: short form of 'seconds'.*/
754 valueStr += _("s");
755
756 int textWidth = 0, textHeight = 0;
757 GetTextExtent(valueStr, &textWidth, &textHeight);
758
759 int textPosX = mControlPoints[i].x - textWidth / 2;
760 int textPosY = mControlPoints[i].y;
761
762 if (cp == duckAmount || cp == outerFadeDown || cp == outerFadeUp)
763 textPosY -= TEXT_DISTANCE + textHeight;
764 else
765 textPosY += TEXT_DISTANCE;
766
767 dc.DrawText(valueStr, textPosX, textPosY);
768
769 dc.DrawEllipse(mControlPoints[i].x - 3,
770 mControlPoints[i].y - 3, 6, 6);
771 }
772 }
773
774 // copy background buffer to paint dc
775 wxPaintDC paintDC(this);
776 paintDC.Blit(0, 0, clientWidth, clientHeight, &dc, 0, 0);
777
778 // clean up: necessary to free resources on Windows
779 dc.SetPen(wxNullPen);
780 dc.SetBrush(wxNullBrush);
781 dc.SetFont(wxNullFont);
782 dc.SelectObject(wxNullBitmap);
783}
#define TEXT_DISTANCE
Definition: AutoDuck.cpp:567
#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:108
wxTextCtrl * mInnerFadeUpLenBox
Definition: AutoDuck.h:77
wxTextCtrl * mInnerFadeDownLenBox
Definition: AutoDuck.h:76
wxTextCtrl * mOuterFadeDownLenBox
Definition: AutoDuck.h:78
wxTextCtrl * mOuterFadeUpLenBox
Definition: AutoDuck.h:79
wxTextCtrl * mDuckAmountDbBox
Definition: AutoDuck.h:75
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:162
wxColour & Colour(int iIndex)

References _, AUTO_DUCK_PANEL_NUM_CONTROL_POINTS, ThemeBase::Colour(), DUCK_AMOUNT_SCALE, DUCK_AMOUNT_START, duckAmount, AColor::envelopePen, FADE_DOWN_START, FADE_SCALE, FADE_UP_START, innerFadeDown, innerFadeUp, AColor::Line(), AColor::Lines(), mBackgroundBitmap, mControlPoints, EffectAutoDuck::mDuckAmountDbBox, mEffect, EffectAutoDuck::mInnerFadeDownLenBox, EffectAutoDuck::mInnerFadeUpLenBox, EffectAutoDuck::mOuterFadeDownLenBox, EffectAutoDuck::mOuterFadeUpLenBox, outerFadeDown, outerFadeUp, ResetControlPoints(), TEXT_DISTANCE, theTheme, and Internat::ToDisplayString().

Here is the call graph for this function:

◆ ResetControlPoints()

void EffectAutoDuckPanel::ResetControlPoints ( )
private

Definition at line 613 of file AutoDuck.cpp.

614{
615 mControlPoints[innerFadeDown] = wxPoint(-100,-100);
616 mControlPoints[innerFadeUp] = wxPoint(-100,-100);
617 mControlPoints[outerFadeDown] = wxPoint(-100,-100);
618 mControlPoints[outerFadeUp] = wxPoint(-100,-100);
619 mControlPoints[duckAmount] = wxPoint(-100,-100);
620}

References duckAmount, innerFadeDown, innerFadeUp, mControlPoints, outerFadeDown, and outerFadeUp.

Referenced by OnPaint().

Here is the caller graph for this function:

Member Data Documentation

◆ mBackgroundBitmap

std::unique_ptr<wxBitmap> EffectAutoDuckPanel::mBackgroundBitmap
private

Definition at line 125 of file AutoDuck.h.

Referenced by OnPaint().

◆ mControlPointMoveActivated

bool EffectAutoDuckPanel::mControlPointMoveActivated
private

Definition at line 130 of file AutoDuck.h.

Referenced by OnLeftDown(), and OnMotion().

◆ mControlPoints

wxPoint EffectAutoDuckPanel::mControlPoints[AUTO_DUCK_PANEL_NUM_CONTROL_POINTS]
private

Definition at line 127 of file AutoDuck.h.

Referenced by GetNearestControlPoint(), OnLeftDown(), OnPaint(), and ResetControlPoints().

◆ mCurrentControlPoint

EControlPoint EffectAutoDuckPanel::mCurrentControlPoint
private

Definition at line 126 of file AutoDuck.h.

Referenced by OnLeftDown(), OnLeftUp(), OnMotion(), OnMouseCaptureChanged(), and OnMouseCaptureLost().

◆ mEffect

EffectAutoDuck* EffectAutoDuckPanel::mEffect
private

Definition at line 124 of file AutoDuck.h.

Referenced by OnMotion(), and OnPaint().

◆ mMouseDownPoint

wxPoint EffectAutoDuckPanel::mMouseDownPoint
private

Definition at line 129 of file AutoDuck.h.

Referenced by OnLeftDown(), and OnMotion().

◆ mMoveStartControlPoints

wxPoint EffectAutoDuckPanel::mMoveStartControlPoints[AUTO_DUCK_PANEL_NUM_CONTROL_POINTS]
private

Definition at line 128 of file AutoDuck.h.

Referenced by OnLeftDown().

◆ mParent

wxWindow* EffectAutoDuckPanel::mParent
private

Definition at line 123 of file AutoDuck.h.


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