Audacity 3.2.0
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
FrequencyPlotDialog Class Referencefinal

Displays a spectrum plot of the waveform. Has options for selecting parameters of the plot. More...

#include <FreqWindow.h>

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

Public Member Functions

 FrequencyPlotDialog (wxWindow *parent, wxWindowID id, AudacityProject &project, const TranslatableString &title, const wxPoint &pos)
 
virtual ~FrequencyPlotDialog ()
 
bool Show (bool show=true) override
 
- Public Member Functions inherited from wxDialogWrapper
 wxDialogWrapper ()
 
 wxDialogWrapper (wxWindow *parent, wxWindowID id, const TranslatableString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE, const TranslatableString &name=XO("Dialog"))
 
bool Create (wxWindow *parent, wxWindowID id, const TranslatableString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE, const TranslatableString &name=XO("Dialog"))
 
void SetTitle (const TranslatableString &title)
 
void SetLabel (const TranslatableString &title)
 
void SetName (const TranslatableString &title)
 
void SetName ()
 
- Public Member Functions inherited from wxTabTraversalWrapper< wxDialog >
 wxTabTraversalWrapper (Args &&... args)
 
 wxTabTraversalWrapper (const wxTabTraversalWrapper &)=delete
 
 wxTabTraversalWrapper (wxTabTraversalWrapper &&)=delete
 
wxTabTraversalWrapperoperator= (const wxTabTraversalWrapper &)=delete
 
wxTabTraversalWrapperoperator= (wxTabTraversalWrapper &&)=delete
 
- Public Member Functions inherited from PrefsListener
 PrefsListener ()
 
virtual ~PrefsListener ()
 
virtual void UpdatePrefs ()=0
 

Private Member Functions

void Populate ()
 
void GetAudio ()
 
void PlotMouseEvent (wxMouseEvent &event)
 
void PlotPaint (wxPaintEvent &event)
 
void OnCloseWindow (wxCloseEvent &event)
 
void OnCloseButton (wxCommandEvent &event)
 
void OnGetURL (wxCommandEvent &event)
 
void OnSize (wxSizeEvent &event)
 
void OnPanScroller (wxScrollEvent &event)
 
void OnZoomSlider (wxCommandEvent &event)
 
void OnAlgChoice (wxCommandEvent &event)
 
void OnSizeChoice (wxCommandEvent &event)
 
void OnFuncChoice (wxCommandEvent &event)
 
void OnAxisChoice (wxCommandEvent &event)
 
void OnExport (wxCommandEvent &event)
 
void OnReplot (wxCommandEvent &event)
 
void OnGridOnOff (wxCommandEvent &event)
 
void OnRecalc (wxCommandEvent &event)
 
void SendRecalcEvent ()
 
void Recalc ()
 
void DrawPlot ()
 
void DrawBackground (wxMemoryDC &dc)
 
void UpdatePrefs () override
 

Private Attributes

bool mDrawGrid
 
int mSize
 
SpectrumAnalyst::Algorithm mAlg
 
int mFunc
 
int mAxis
 
int dBRange
 
AudacityProjectmProject
 
RulerPanelvRuler
 
RulerPanelhRuler
 
FreqPlotmFreqPlot
 
FreqGaugemProgress
 
wxRect mPlotRect
 
wxFont mFreqFont
 
std::unique_ptr< wxCursor > mArrowCursor
 
std::unique_ptr< wxCursor > mCrossCursor
 
wxButton * mCloseButton
 
wxButton * mExportButton
 
wxButton * mReplotButton
 
wxCheckBox * mGridOnOff
 
wxChoice * mAlgChoice
 
wxChoice * mSizeChoice
 
wxChoice * mFuncChoice
 
wxChoice * mAxisChoice
 
wxScrollBar * mPanScroller
 
wxSlider * mZoomSlider
 
wxTextCtrl * mCursorText
 
wxTextCtrl * mPeakText
 
double mRate
 
size_t mDataLen
 
Floats mData
 
size_t mWindowSize
 
bool mLogAxis
 
float mYMin
 
float mYMax
 
float mYStep
 
std::unique_ptr< wxBitmap > mBitmap
 
int mMouseX
 
int mMouseY
 
std::unique_ptr< SpectrumAnalystmAnalyst
 

Static Private Attributes

static const int fontSize = 8
 

Friends

class FreqPlot
 

Additional Inherited Members

- Static Public Member Functions inherited from PrefsListener
static void Broadcast (int id=0)
 Call this static function to notify all PrefsListener objects. More...
 
- Protected Member Functions inherited from PrefsListener
virtual void UpdateSelectedPrefs (int id)
 

Detailed Description

Displays a spectrum plot of the waveform. Has options for selecting parameters of the plot.

Has a feature that finds peaks and reports their value as you move the mouse around.

Definition at line 56 of file FreqWindow.h.

Constructor & Destructor Documentation

◆ FrequencyPlotDialog()

FrequencyPlotDialog::FrequencyPlotDialog ( wxWindow *  parent,
wxWindowID  id,
AudacityProject project,
const TranslatableString title,
const wxPoint &  pos 
)

Definition at line 181 of file FreqWindow.cpp.

185: wxDialogWrapper(parent, id, title, pos, wxDefaultSize,
186 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxMAXIMIZE_BOX),
187 mProject{ &project }
188, mAnalyst(std::make_unique<SpectrumAnalyst>())
189{
190 SetName();
191
192 mMouseX = 0;
193 mMouseY = 0;
194 mRate = 0;
195 mDataLen = 0;
196
197 gPrefs->Read(wxT("/FrequencyPlotDialog/DrawGrid"), &mDrawGrid, true);
198 gPrefs->Read(wxT("/FrequencyPlotDialog/SizeChoice"), &mSize, 3);
199
200 int alg;
201 gPrefs->Read(wxT("/FrequencyPlotDialog/AlgChoice"), &alg, 0);
202 mAlg = static_cast<SpectrumAnalyst::Algorithm>(alg);
203
204 gPrefs->Read(wxT("/FrequencyPlotDialog/FuncChoice"), &mFunc, 3);
205 gPrefs->Read(wxT("/FrequencyPlotDialog/AxisChoice"), &mAxis, 1);
206
207 Populate();
208}
wxT("CloseDown"))
static const auto title
FileConfig * gPrefs
Definition: Prefs.cpp:70
SpectrumAnalyst::Algorithm mAlg
Definition: FreqWindow.h:101
std::unique_ptr< SpectrumAnalyst > mAnalyst
Definition: FreqWindow.h:154
AudacityProject * mProject
Definition: FreqWindow.h:105

◆ ~FrequencyPlotDialog()

FrequencyPlotDialog::~FrequencyPlotDialog ( )
virtual

Definition at line 210 of file FreqWindow.cpp.

211{
212}

Member Function Documentation

◆ DrawBackground()

void FrequencyPlotDialog::DrawBackground ( wxMemoryDC &  dc)
private

Definition at line 647 of file FreqWindow.cpp.

648{
649 Layout();
650
651 mBitmap.reset();
652
653 mPlotRect = mFreqPlot->GetClientRect();
654
655 mBitmap = std::make_unique<wxBitmap>(mPlotRect.width, mPlotRect.height,24);
656
657 dc.SelectObject(*mBitmap);
658
659 dc.SetBackground(wxBrush(wxColour(254, 254, 254)));// DONT-THEME Mask colour.
660 dc.Clear();
661
662 dc.SetPen(*wxBLACK_PEN);
663 dc.SetBrush(*wxWHITE_BRUSH);
664 dc.DrawRectangle(mPlotRect);
665
666 dc.SetFont(mFreqFont);
667}
std::unique_ptr< wxBitmap > mBitmap
Definition: FreqWindow.h:149
FreqPlot * mFreqPlot
Definition: FreqWindow.h:115

References mBitmap, mFreqFont, mFreqPlot, and mPlotRect.

Referenced by DrawPlot().

Here is the caller graph for this function:

◆ DrawPlot()

void FrequencyPlotDialog::DrawPlot ( )
private

Definition at line 669 of file FreqWindow.cpp.

670{
671 if (!mData || mDataLen < mWindowSize || mAnalyst->GetProcessedSize() == 0) {
672 wxMemoryDC memDC;
673
674 vRuler->ruler.SetLog(false);
676
677 hRuler->ruler.SetLog(false);
678 hRuler->ruler.SetRange(0, 1);
679
680 DrawBackground(memDC);
681
682 if (mDataLen < mWindowSize) {
683 wxString msg = _("Not enough data selected.");
684 wxSize sz = memDC.GetTextExtent(msg);
685 memDC.DrawText(msg,
686 (mPlotRect.GetWidth() - sz.GetWidth()) / 2,
687 (mPlotRect.GetHeight() - sz.GetHeight()) / 2);
688 }
689
690 memDC.SelectObject(wxNullBitmap);
691
692 mFreqPlot->Refresh();
693
694 Refresh();
695
696 return;
697 }
698
699 float yRange = mYMax - mYMin;
700 float yTotal = yRange * ((float) mZoomSlider->GetValue() / 100.0f);
701
702 int sTotal = yTotal * 100;
703 int sRange = yRange * 100;
704 int sPos = mPanScroller->GetThumbPosition() + ((mPanScroller->GetThumbSize() - sTotal) / 2);
705 mPanScroller->SetScrollbar(sPos, sTotal, sRange, sTotal);
706
707 float yMax = mYMax - ((float)sPos / 100);
708 float yMin = yMax - yTotal;
709
710 // Set up y axis ruler
711
713 vRuler->ruler.SetUnits(XO("dB"));
715 } else {
716 vRuler->ruler.SetUnits({});
718 }
719 int w1, w2, h;
720 vRuler->ruler.GetMaxSize(&w1, &h);
721 vRuler->ruler.SetRange(yMax, yMin); // Note inversion for vertical.
722 vRuler->ruler.GetMaxSize(&w2, &h);
723 if( w1 != w2 ) // Reduces flicker
724 {
725 vRuler->SetMinSize(wxSize(w2,h));
726 Layout();
727 }
728 vRuler->Refresh(false);
729
730 wxMemoryDC memDC;
731 DrawBackground(memDC);
732
733 // Get the plot dimensions
734 //
735 // Must be done after setting the vertical ruler above since the
736 // the width could change.
737 wxRect r = mPlotRect;
738
739 // Set up x axis ruler
740
741 int width = r.width - 2;
742
743 float xMin, xMax, xRatio, xStep;
744
746 xMin = mRate / mWindowSize;
747 xMax = mRate / 2;
748 xRatio = xMax / xMin;
749 if (mLogAxis)
750 {
751 xStep = pow(2.0f, (log(xRatio) / log(2.0f)) / width);
752 hRuler->ruler.SetLog(true);
753 }
754 else
755 {
756 xStep = (xMax - xMin) / width;
757 hRuler->ruler.SetLog(false);
758 }
759 hRuler->ruler.SetUnits(XO("Hz"));
760 } else {
761 xMin = 0;
762 xMax = mAnalyst->GetProcessedSize() / mRate;
763 xStep = (xMax - xMin) / width;
764 hRuler->ruler.SetLog(false);
765 /* i18n-hint: short form of 'seconds'.*/
766 hRuler->ruler.SetUnits(XO("s"));
767 }
768 hRuler->ruler.SetRange(xMin, xMax-xStep);
769 hRuler->Refresh(false);
770
771 // Draw the plot
773 memDC.SetPen(wxPen(theTheme.Colour( clrHzPlot ), 1, wxPENSTYLE_SOLID));
774 else
775 memDC.SetPen(wxPen(theTheme.Colour( clrWavelengthPlot), 1, wxPENSTYLE_SOLID));
776
777 float xPos = xMin;
778
779 for (int i = 0; i < width; i++) {
780 float y;
781
782 if (mLogAxis)
783 y = mAnalyst->GetProcessedValue(xPos, xPos * xStep);
784 else
785 y = mAnalyst->GetProcessedValue(xPos, xPos + xStep);
786
787 float ynorm = (y - yMin) / yTotal;
788
789 int lineheight = (int)(ynorm * (r.height - 1));
790
791 if (lineheight > r.height - 2)
792 lineheight = r.height - 2;
793
794 if (ynorm > 0.0)
795 AColor::Line(memDC, r.x + 1 + i, r.y + r.height - 1 - lineheight,
796 r.x + 1 + i, r.y + r.height - 1);
797
798 if (mLogAxis)
799 xPos *= xStep;
800 else
801 xPos += xStep;
802 }
803
804 // Outline the graph
805 memDC.SetPen(*wxBLACK_PEN);
806 memDC.SetBrush(*wxTRANSPARENT_BRUSH);
807 memDC.DrawRectangle(r);
808
809 if(mDrawGrid)
810 {
811 hRuler->ruler.DrawGrid(memDC, r.height, true, true, 1, 1);
812 vRuler->ruler.DrawGrid(memDC, r.width, true, true, 1, 1);
813 }
814
815 memDC.SelectObject( wxNullBitmap );
816
817 mFreqPlot->Refresh();
818}
XO("Cut/Copy/Paste")
#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
RulerPanel * hRuler
Definition: FreqWindow.h:114
wxSlider * mZoomSlider
Definition: FreqWindow.h:134
RulerPanel * vRuler
Definition: FreqWindow.h:113
void DrawBackground(wxMemoryDC &dc)
Definition: FreqWindow.cpp:647
wxScrollBar * mPanScroller
Definition: FreqWindow.h:133
void DrawGrid(wxDC &dc, int length, bool minor=true, bool major=true, int xOffset=0, int yOffset=0) const
Definition: Ruler.cpp:1521
void SetLog(bool log)
Definition: Ruler.cpp:142
void GetMaxSize(wxCoord *width, wxCoord *height)
Definition: Ruler.cpp:1603
void SetUnits(const TranslatableString &units)
Definition: Ruler.cpp:153
void SetRange(double min, double max)
Definition: Ruler.cpp:188
void SetFormat(RulerFormat format)
Definition: Ruler.cpp:131
@ LinearDBFormat
Definition: Ruler.h:34
@ RealFormat
Definition: Ruler.h:31
Ruler ruler
Definition: Ruler.h:288
wxColour & Colour(int iIndex)

References _, ThemeBase::Colour(), dBRange, DrawBackground(), Ruler::DrawGrid(), Ruler::GetMaxSize(), hRuler, AColor::Line(), Ruler::LinearDBFormat, mAlg, mAnalyst, mData, mDataLen, mDrawGrid, mFreqPlot, mLogAxis, mPanScroller, mPlotRect, mRate, mWindowSize, mYMax, mYMin, mZoomSlider, Ruler::RealFormat, RulerPanel::ruler, Ruler::SetFormat(), Ruler::SetLog(), Ruler::SetRange(), Ruler::SetUnits(), SpectrumAnalyst::Spectrum, theTheme, vRuler, and XO().

Referenced by OnAxisChoice(), OnGridOnOff(), OnPanScroller(), OnSize(), OnZoomSlider(), and Recalc().

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

◆ GetAudio()

void FrequencyPlotDialog::GetAudio ( )
private

Definition at line 578 of file FreqWindow.cpp.

579{
580 mData.reset();
581 mDataLen = 0;
582
583 int selcount = 0;
584 bool warning = false;
585 for (auto track : TrackList::Get( *mProject ).Selected< const WaveTrack >()) {
586 auto &selectedRegion = ViewInfo::Get( *mProject ).selectedRegion;
587 if (selcount==0) {
588 mRate = track->GetRate();
589 auto start = track->TimeToLongSamples(selectedRegion.t0());
590 auto end = track->TimeToLongSamples(selectedRegion.t1());
591 auto dataLen = end - start;
592 // Permit approximately 46.60 minutes of selected samples at
593 // a sampling frequency of 48 kHz (11.65 minutes at 192 kHz).
594 auto maxDataLen = size_t(2) << 26;
595 if (dataLen > maxDataLen) {
596 warning = true;
597 mDataLen = maxDataLen;
598 }
599 else {
600 mDataLen = dataLen.as_size_t();
601 }
602 mData = Floats{ mDataLen };
603 // Don't allow throw for bad reads
604 track->GetFloats(mData.get(), start, mDataLen,
605 fillZero, false);
606 }
607 else {
608 if (track->GetRate() != mRate) {
610 XO(
611"To plot the spectrum, all selected tracks must be the same sample rate.") );
612 mData.reset();
613 mDataLen = 0;
614 return;
615 }
616 auto start = track->TimeToLongSamples(selectedRegion.t0());
617 Floats buffer2{ mDataLen };
618 // Again, stop exceptions
619 track->GetFloats(buffer2.get(), start, mDataLen,
620 fillZero, false);
621 for (size_t i = 0; i < mDataLen; i++)
622 mData[i] += buffer2[i];
623 }
624 selcount++;
625 }
626
627 if (selcount == 0)
628 return;
629
630 if (warning) {
631 auto msg = XO(
632"Too much audio was selected. Only the first %.1f seconds of audio will be analyzed.")
633 .Format(mDataLen / mRate);
634 AudacityMessageBox( msg );
635 }
636}
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
@ fillZero
Definition: SampleFormat.h:60
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:486
auto Selected() -> TrackIterRange< TrackType >
Definition: Track.h:1454
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:217
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:234
A Track that contains audio waveform data.
Definition: WaveTrack.h:57
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159

References AudacityMessageBox(), PackedArray::end(), fillZero, ViewInfo::Get(), TrackList::Get(), mData, mDataLen, mRate, TrackList::Selected(), ViewInfo::selectedRegion, and XO().

Referenced by OnReplot(), and Show().

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

◆ OnAlgChoice()

void FrequencyPlotDialog::OnAlgChoice ( wxCommandEvent &  event)
private

Definition at line 846 of file FreqWindow.cpp.

847{
848 mAlg = SpectrumAnalyst::Algorithm(mAlgChoice->GetSelection());
849
850 // Log-frequency axis works for spectrum plots only.
852 mAxisChoice->Enable(true);
853 mLogAxis = mAxisChoice->GetSelection() ? true : false;
854 }
855 else {
856 mAxisChoice->Disable();
857 mLogAxis = false;
858 }
859
861}
wxChoice * mAlgChoice
Definition: FreqWindow.h:129
wxChoice * mAxisChoice
Definition: FreqWindow.h:132

References mAlg, mAlgChoice, mAxisChoice, mLogAxis, SendRecalcEvent(), and SpectrumAnalyst::Spectrum.

Here is the call graph for this function:

◆ OnAxisChoice()

void FrequencyPlotDialog::OnAxisChoice ( wxCommandEvent &  event)
private

Definition at line 877 of file FreqWindow.cpp.

878{
879 mLogAxis = mAxisChoice->GetSelection() ? true : false;
880 DrawPlot();
881}

References DrawPlot(), mAxisChoice, and mLogAxis.

Here is the call graph for this function:

◆ OnCloseButton()

void FrequencyPlotDialog::OnCloseButton ( wxCommandEvent &  event)
private

Definition at line 991 of file FreqWindow.cpp.

992{
993 gPrefs->Write(wxT("/FrequencyPlotDialog/DrawGrid"), mDrawGrid);
994 gPrefs->Write(wxT("/FrequencyPlotDialog/SizeChoice"), mSizeChoice->GetSelection());
995 gPrefs->Write(wxT("/FrequencyPlotDialog/AlgChoice"), mAlgChoice->GetSelection());
996 gPrefs->Write(wxT("/FrequencyPlotDialog/FuncChoice"), mFuncChoice->GetSelection());
997 gPrefs->Write(wxT("/FrequencyPlotDialog/AxisChoice"), mAxisChoice->GetSelection());
998 gPrefs->Flush();
999 mData.reset();
1000 Show(false);
1001}
virtual bool Flush(bool bCurrentOnly=false) wxOVERRIDE
Definition: FileConfig.cpp:143
wxChoice * mSizeChoice
Definition: FreqWindow.h:130
wxChoice * mFuncChoice
Definition: FreqWindow.h:131
bool Show(bool show=true) override
Definition: FreqWindow.cpp:552

References FileConfig::Flush(), gPrefs, mAlgChoice, mAxisChoice, mData, mDrawGrid, mFuncChoice, mSizeChoice, Show(), and wxT().

Here is the call graph for this function:

◆ OnCloseWindow()

void FrequencyPlotDialog::OnCloseWindow ( wxCloseEvent &  event)
private

Definition at line 986 of file FreqWindow.cpp.

987{
988 Show(false);
989}

References Show().

Here is the call graph for this function:

◆ OnExport()

void FrequencyPlotDialog::OnExport ( wxCommandEvent &  event)
private

Definition at line 1054 of file FreqWindow.cpp.

1055{
1056 wxString fName = _("spectrum.txt");
1057
1058 fName = SelectFile(FileNames::Operation::Export,
1059 XO("Export Spectral Data As:"),
1060 wxEmptyString,
1061 fName,
1062 wxT("txt"),
1064 wxFD_SAVE | wxRESIZE_BORDER,
1065 this);
1066
1067 if (fName.empty())
1068 return;
1069
1070 wxFFileOutputStream ffStream{ fName };
1071 if (!ffStream.IsOk()) {
1072 AudacityMessageBox( XO("Couldn't write to file: %s").Format( fName ) );
1073 return;
1074 }
1075
1076 wxTextOutputStream ss(ffStream);
1077
1078 const int processedSize = mAnalyst->GetProcessedSize();
1079 const float *const processed = mAnalyst->GetProcessed();
1080 if (mAlgChoice->GetSelection() == 0) {
1081 ss
1082 << XO("Frequency (Hz)\tLevel (dB)") << '\n';
1083 for (int i = 1; i < processedSize; i++)
1084 ss
1085 << wxString::Format(wxT("%f\t%f\n"),
1086 i * mRate / mWindowSize, processed[i] );
1087 }
1088 else {
1089 ss
1090 << XO("Lag (seconds)\tFrequency (Hz)\tLevel") << '\n';
1091 for (int i = 1; i < processedSize; i++)
1092 ss
1093 << wxString::Format(wxT("%f\t%f\t%f\n"),
1094 i / mRate, mRate / i, processed[i] );
1095 }
1096}
FilePath SelectFile(FileNames::Operation op, const TranslatableString &message, const FilePath &default_path, const FilePath &default_filename, const FileExtension &default_extension, const FileTypes &fileTypes, int flags, wxWindow *parent)
Definition: SelectFile.cpp:17
FILES_API const FileType AllFiles
Definition: FileNames.h:70
FILES_API const FileType TextFiles
Definition: FileNames.h:73
Abstract base class used in importing a file.

References _, FileNames::AllFiles, AudacityMessageBox(), mAlgChoice, mAnalyst, mRate, mWindowSize, SelectFile(), FileNames::TextFiles, wxT(), and XO().

Here is the call graph for this function:

◆ OnFuncChoice()

void FrequencyPlotDialog::OnFuncChoice ( wxCommandEvent &  event)
private

Definition at line 872 of file FreqWindow.cpp.

873{
875}

References SendRecalcEvent().

Here is the call graph for this function:

◆ OnGetURL()

void FrequencyPlotDialog::OnGetURL ( wxCommandEvent &  event)
private

Definition at line 545 of file FreqWindow.cpp.

546{
547 // Original help page is back on-line (March 2016), but the manual should be more reliable.
548 // http://www.eramp.com/WCAG_2_audio_contrast_tool_help.htm
549 HelpSystem::ShowHelp(this, L"Plot_Spectrum");
550}
static void ShowHelp(wxWindow *parent, const FilePath &localFileName, const URLString &remoteURL, bool bModal=false, bool alwaysDefaultBrowser=false)
Definition: HelpSystem.cpp:234

References HelpSystem::ShowHelp().

Here is the call graph for this function:

◆ OnGridOnOff()

void FrequencyPlotDialog::OnGridOnOff ( wxCommandEvent &  event)
private

Definition at line 1107 of file FreqWindow.cpp.

1108{
1109 mDrawGrid = mGridOnOff->IsChecked();
1110
1111 DrawPlot();
1112}
wxCheckBox * mGridOnOff
Definition: FreqWindow.h:128

References DrawPlot(), mDrawGrid, and mGridOnOff.

Here is the call graph for this function:

◆ OnPanScroller()

void FrequencyPlotDialog::OnPanScroller ( wxScrollEvent &  event)
private

Definition at line 836 of file FreqWindow.cpp.

837{
838 DrawPlot();
839}

References DrawPlot().

Here is the call graph for this function:

◆ OnRecalc()

void FrequencyPlotDialog::OnRecalc ( wxCommandEvent &  event)
private

Definition at line 1114 of file FreqWindow.cpp.

1115{
1116 Recalc();
1117}

References Recalc().

Here is the call graph for this function:

◆ OnReplot()

void FrequencyPlotDialog::OnReplot ( wxCommandEvent &  event)
private

Definition at line 1098 of file FreqWindow.cpp.

1099{
1101 if(dBRange < 90.)
1102 dBRange = 90.;
1103 GetAudio();
1105}
IntSetting DecibelScaleCutoff
Negation of this value is the lowest dB level that should be shown in dB scales.
Definition: Decibels.cpp:12
bool Read(T *pVar) const
overload of Read returning a boolean that is true if the value was previously defined *‍/
Definition: Prefs.h:200

References dBRange, DecibelScaleCutoff, GetAudio(), Setting< T >::Read(), and SendRecalcEvent().

Here is the call graph for this function:

◆ OnSize()

void FrequencyPlotDialog::OnSize ( wxSizeEvent &  event)
private

Definition at line 638 of file FreqWindow.cpp.

639{
640 Layout();
641
642 DrawPlot();
643
644 Refresh(true);
645}

References DrawPlot().

Here is the call graph for this function:

◆ OnSizeChoice()

void FrequencyPlotDialog::OnSizeChoice ( wxCommandEvent &  event)
private

Definition at line 863 of file FreqWindow.cpp.

864{
865 long windowSize = 0;
866 mSizeChoice->GetStringSelection().ToLong(&windowSize);
867 mWindowSize = windowSize;
868
870}

References mSizeChoice, mWindowSize, and SendRecalcEvent().

Here is the call graph for this function:

◆ OnZoomSlider()

void FrequencyPlotDialog::OnZoomSlider ( wxCommandEvent &  event)
private

Definition at line 841 of file FreqWindow.cpp.

842{
843 DrawPlot();
844}

References DrawPlot().

Here is the call graph for this function:

◆ PlotMouseEvent()

void FrequencyPlotDialog::PlotMouseEvent ( wxMouseEvent &  event)
private

Definition at line 821 of file FreqWindow.cpp.

822{
823 if (event.Moving() && (event.m_x != mMouseX || event.m_y != mMouseY)) {
824 mMouseX = event.m_x;
825 mMouseY = event.m_y;
826
827 if (mPlotRect.Contains(mMouseX, mMouseY))
828 mFreqPlot->SetCursor(*mCrossCursor);
829 else
830 mFreqPlot->SetCursor(*mArrowCursor);
831
832 mFreqPlot->Refresh(false);
833 }
834}
std::unique_ptr< wxCursor > mArrowCursor
Definition: FreqWindow.h:122
std::unique_ptr< wxCursor > mCrossCursor
Definition: FreqWindow.h:123

References mArrowCursor, mCrossCursor, mFreqPlot, mMouseX, mMouseY, and mPlotRect.

Referenced by FreqPlot::OnMouseEvent().

Here is the caller graph for this function:

◆ PlotPaint()

void FrequencyPlotDialog::PlotPaint ( wxPaintEvent &  event)
private

Definition at line 883 of file FreqWindow.cpp.

884{
885 wxPaintDC dc( (wxWindow *) event.GetEventObject() );
886
887 dc.DrawBitmap( *mBitmap, 0, 0, true );
888 // Fix for Bug 1226 "Plot Spectrum freezes... if insufficient samples selected"
889 if (!mData || mDataLen < mWindowSize)
890 return;
891
892 dc.SetFont(mFreqFont);
893
894 wxRect r = mPlotRect;
895
896 int width = r.width - 2;
897
898 float xMin, xMax, xRatio, xStep;
899
901 xMin = mRate / mWindowSize;
902 xMax = mRate / 2;
903 xRatio = xMax / xMin;
904 if (mLogAxis)
905 xStep = pow(2.0f, (log(xRatio) / log(2.0f)) / width);
906 else
907 xStep = (xMax - xMin) / width;
908 } else {
909 xMin = 0;
910 xMax = mAnalyst->GetProcessedSize() / mRate;
911 xStep = (xMax - xMin) / width;
912 }
913
914 float xPos = xMin;
915
916 // Find the peak nearest the cursor and plot it
917 if ( r.Contains(mMouseX, mMouseY) && (mMouseX!=0) && (mMouseX!=r.width-1) ) {
918 if (mLogAxis)
919 xPos = xMin * pow(xStep, mMouseX - (r.x + 1));
920 else
921 xPos = xMin + xStep * (mMouseX - (r.x + 1));
922
923 float bestValue = 0;
924 float bestpeak = mAnalyst->FindPeak(xPos, &bestValue);
925
926 int px;
927 if (mLogAxis)
928 px = (int)(log(bestpeak / xMin) / log(xStep));
929 else
930 px = (int)((bestpeak - xMin) * width / (xMax - xMin));
931
932 dc.SetPen(wxPen(wxColour(255, 32, 32), 1, wxPENSTYLE_SOLID));
933 AColor::Line(dc, r.x + 1 + px, r.y, r.x + 1 + px, r.y + r.height);
934
935 // print out info about the cursor location
936
937 float value;
938
939 if (mLogAxis) {
940 xPos = xMin * pow(xStep, mMouseX - (r.x + 1));
941 value = mAnalyst->GetProcessedValue(xPos, xPos * xStep);
942 } else {
943 xPos = xMin + xStep * (mMouseX - (r.x + 1));
944 value = mAnalyst->GetProcessedValue(xPos, xPos + xStep);
945 }
946
947 TranslatableString cursor;
949
951 auto xp = PitchName_Absolute(FreqToMIDInote(xPos));
952 auto pp = PitchName_Absolute(FreqToMIDInote(bestpeak));
953 /* i18n-hint: The %d's are replaced by numbers, the %s by musical notes, e.g. A#*/
954 cursor = XO("%d Hz (%s) = %d dB")
955 .Format( (int)(xPos + 0.5), xp, (int)(value + 0.5));
956 /* i18n-hint: The %d's are replaced by numbers, the %s by musical notes, e.g. A#*/
957 peak = XO("%d Hz (%s) = %.1f dB")
958 .Format( (int)(bestpeak + 0.5), pp, bestValue );
959 } else if (xPos > 0.0 && bestpeak > 0.0) {
960 auto xp = PitchName_Absolute(FreqToMIDInote(1.0 / xPos));
961 auto pp = PitchName_Absolute(FreqToMIDInote(1.0 / bestpeak));
962 /* i18n-hint: The %d's are replaced by numbers, the %s by musical notes, e.g. A#
963 * the %.4f are numbers, and 'sec' should be an abbreviation for seconds */
964 cursor = XO("%.4f sec (%d Hz) (%s) = %f")
965 .Format( xPos, (int)(1.0 / xPos + 0.5), xp, value );
966 /* i18n-hint: The %d's are replaced by numbers, the %s by musical notes, e.g. A#
967 * the %.4f are numbers, and 'sec' should be an abbreviation for seconds */
968 peak = XO("%.4f sec (%d Hz) (%s) = %.3f")
969 .Format( bestpeak, (int)(1.0 / bestpeak + 0.5), pp, bestValue );
970 }
971 mCursorText->SetValue( cursor.Translation() );
972 mPeakText->SetValue( peak.Translation() );
973 }
974 else {
975 mCursorText->SetValue(wxT(""));
976 mPeakText->SetValue(wxT(""));
977 }
978
979
980 // Outline the graph
981 dc.SetPen(*wxBLACK_PEN);
982 dc.SetBrush(*wxTRANSPARENT_BRUSH);
983 dc.DrawRectangle(r);
984}
TranslatableString PitchName_Absolute(const double dMIDInote, const PitchNameChoice choice)
Definition: PitchName.cpp:153
double FreqToMIDInote(const double freq)
Definition: PitchName.cpp:28
wxTextCtrl * mCursorText
Definition: FreqWindow.h:135
wxTextCtrl * mPeakText
Definition: FreqWindow.h:136
Holds a msgid for the translation catalog; may also bind format arguments.
wxString Translation() const

References FreqToMIDInote(), AColor::Line(), mAlg, mAnalyst, mBitmap, mCursorText, mData, mDataLen, mFreqFont, mLogAxis, mMouseX, mMouseY, mPeakText, mPlotRect, mRate, mWindowSize, PitchName_Absolute(), SpectrumAnalyst::Spectrum, TranslatableString::Translation(), wxT(), and XO().

Referenced by FreqPlot::OnPaint().

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

◆ Populate()

void FrequencyPlotDialog::Populate ( )
private

Definition at line 214 of file FreqWindow.cpp.

215{
217
218 TranslatableStrings algChoices{
219 XO("Spectrum") ,
220 XO("Standard Autocorrelation") ,
221 XO("Cuberoot Autocorrelation") ,
222 XO("Enhanced Autocorrelation") ,
223 /* i18n-hint: This is a technical term, derived from the word
224 * "spectrum". Do not translate it unless you are sure you
225 * know the correct technical word in your language. */
226 XO("Cepstrum") ,
227 };
228
229 TranslatableStrings sizeChoices{
230 Verbatim( "128" ) ,
231 Verbatim( "256" ) ,
232 Verbatim( "512" ) ,
233 Verbatim( "1024" ) ,
234 Verbatim( "2048" ) ,
235 Verbatim( "4096" ) ,
236 Verbatim( "8192" ) ,
237 Verbatim( "16384" ) ,
238 Verbatim( "32768" ) ,
239 Verbatim( "65536" ) ,
240 Verbatim( "131072" ) ,
241 };
242
243 TranslatableStrings funcChoices;
244 for (int i = 0, cnt = NumWindowFuncs(); i < cnt; i++)
245 {
246 funcChoices.push_back(
247 /* i18n-hint: This refers to a "window function",
248 * such as Hann or Rectangular, used in the
249 * Frequency analyze dialog box. */
250 XO("%s window").Format( WindowFuncName(i) ) );
251 }
252
253 TranslatableStrings axisChoices{
254 XO("Linear frequency") ,
255 XO("Log frequency") ,
256 };
257
258 mFreqFont = wxFont(fontSize, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
259 mArrowCursor = std::make_unique<wxCursor>(wxCURSOR_ARROW);
260 mCrossCursor = std::make_unique<wxCursor>(wxCURSOR_CROSS);
261
262 long size;
263 // reinterpret one of the verbatim strings above as a number
264 sizeChoices[mSize].MSGID().GET().ToLong(&size);
266
268 if(dBRange < 90.)
269 dBRange = 90.;
270
271 ShuttleGui S(this, eIsCreating);
272
273 S.SetBorder(0);
274
275 S.AddSpace(5);
276
277 S.SetSizerProportion(1);
278 S.StartMultiColumn(3, wxEXPAND);
279 {
280 S.SetStretchyCol(1);
281 S.SetStretchyRow(0);
282
283 // -------------------------------------------------------------------
284 // ROW 1: Freq response panel and sliders for vertical scale
285 // -------------------------------------------------------------------
286
287 S.StartVerticalLay(2);
288 {
290 S.GetParent(), wxID_ANY, wxVERTICAL,
291 wxSize{ 100, 100 }, // Ruler can't handle small sizes
292 RulerPanel::Range{ 0.0, -dBRange },
294 XO("dB"),
296 .LabelEdges(true)
297 .TickColour( theTheme.Colour( clrGraphLabels ) )
298 );
299
300 S.AddSpace(wxDefaultCoord, 1);
301 S.Prop(1)
302 .Position(wxALIGN_RIGHT | wxALIGN_TOP)
303 .AddWindow(vRuler);
304 S.AddSpace(wxDefaultCoord, 1);
305 }
306 S.EndVerticalLay();
307
308 mFreqPlot = safenew FreqPlot(S.GetParent(), wxID_ANY);
309 S.Prop(1)
310 .Position(wxEXPAND)
311 .MinSize( { wxDefaultCoord, FREQ_WINDOW_HEIGHT } )
312 .AddWindow(mFreqPlot);
313
314 S.StartHorizontalLay(wxEXPAND, 0);
315 {
316 S.StartVerticalLay();
317 {
318 mPanScroller = safenew wxScrollBar(S.GetParent(), FreqPanScrollerID,
319 wxDefaultPosition, wxDefaultSize, wxSB_VERTICAL);
320#if wxUSE_ACCESSIBILITY
321 // so that name can be set on a standard control
323#endif
324 S.Prop(1);
325 S
326 .Name(XO("Scroll"))
327 .Position( wxALIGN_LEFT | wxTOP)
328 .AddWindow(mPanScroller);
329 }
330 S.EndVerticalLay();
331
332 S.StartVerticalLay();
333 {
334 wxStaticBitmap *zi = safenew wxStaticBitmap(S.GetParent(), wxID_ANY, wxBitmap(ZoomIn));
335 S.Position(wxALIGN_CENTER)
336 .AddWindow(zi);
337
338 S.AddSpace(5);
339
340 mZoomSlider = safenew wxSliderWrapper(S.GetParent(), FreqZoomSliderID, 100, 1, 100,
341 wxDefaultPosition, wxDefaultSize, wxSL_VERTICAL);
342 S.Prop(1);
343 S
344 .Name(XO("Zoom"))
345 .Position(wxALIGN_CENTER_HORIZONTAL)
346 .AddWindow(mZoomSlider);
347#if wxUSE_ACCESSIBILITY
348 // so that name can be set on a standard control
350#endif
351
352 S.AddSpace(5);
353
354 wxStaticBitmap *zo = safenew wxStaticBitmap(S.GetParent(), wxID_ANY, wxBitmap(ZoomOut));
355 S.Position(wxALIGN_CENTER)
356 .AddWindow(zo);
357 }
358 S.EndVerticalLay();
359
360 S.AddSpace(5, wxDefaultCoord);
361 }
362 S.EndHorizontalLay();
363
364 // -------------------------------------------------------------------
365 // ROW 2: Frequency ruler
366 // -------------------------------------------------------------------
367
368 S.AddSpace(1);
369
370 S.StartHorizontalLay(wxEXPAND, 0);
371 {
373 S.GetParent(), wxID_ANY, wxHORIZONTAL,
374 wxSize{ 100, 100 }, // Ruler can't handle small sizes
375 RulerPanel::Range{ 10, 20000 },
377 XO("Hz"),
379 .Log(true)
380 .Flip(true)
381 .LabelEdges(true)
382 .TickColour( theTheme.Colour( clrGraphLabels ) )
383 );
384
385 S.AddSpace(1, wxDefaultCoord);
386 S.Prop(1)
387 .Position(wxALIGN_LEFT | wxALIGN_TOP)
388 .AddWindow(hRuler);
389 S.AddSpace(1, wxDefaultCoord);
390 }
391 S.EndHorizontalLay();
392
393 S.AddSpace(1);
394
395 // -------------------------------------------------------------------
396 // ROW 3: Spacer
397 // -------------------------------------------------------------------
398
399 S.AddSpace(5);
400 S.AddSpace(5);
401 S.AddSpace(5);
402
403 // -------------------------------------------------------------------
404 // ROW 4: Info
405 // -------------------------------------------------------------------
406
407 S.AddSpace(1);
408
409 S.StartHorizontalLay(wxEXPAND);
410 {
411 S.SetSizerProportion(1);
412 S.StartMultiColumn(6);
413 S.SetStretchyCol(1);
414 S.SetStretchyCol(3);
415 {
416 S.AddPrompt(XXO("Cursor:"));
417
418 mCursorText = S.Style(wxTE_READONLY)
419 .AddTextBox( {}, wxT(""), 10);
420
421 S.AddPrompt(XXO("Peak:"));
422
423 mPeakText = S.Style(wxTE_READONLY)
424 .AddTextBox( {}, wxT(""), 10);
425 S.AddSpace(5);
426
427 mGridOnOff = S.Id(GridOnOffID).AddCheckBox(XXO("&Grids"), mDrawGrid);
428 }
429 S.EndMultiColumn();
430 }
431 S.EndHorizontalLay();
432
433 S.AddSpace(1);
434 }
435 S.EndMultiColumn();
436
437 // -------------------------------------------------------------------
438 // ROW 5: Spacer
439 // -------------------------------------------------------------------
440
441 S.AddSpace(5);
442
443 S.SetBorder(2);
444 S.SetSizerProportion(0);
445 S.StartMultiColumn(9, wxALIGN_CENTER);
446 {
447 // ----------------------------------------------------------------
448 // ROW 6: Algorithm, Size, Export, Replot
449 // ----------------------------------------------------------------
450
451 S.AddSpace(5);
452
453 mAlgChoice = S.Id(FreqAlgChoiceID).Focus()
454 .MinSize( { wxDefaultCoord, wxDefaultCoord } )
455 .AddChoice(XXO("&Algorithm:"), algChoices, mAlg);
456
457 S.AddSpace(5);
458
460 .MinSize( { wxDefaultCoord, wxDefaultCoord } )
461 .AddChoice(XXO("&Size:"), sizeChoices, mSize);
462
463 S.AddSpace(5);
464
465 mExportButton = S.Id(FreqExportButtonID).AddButton(XXO("&Export..."));
466
467 S.AddSpace(5);
468
469 // ----------------------------------------------------------------
470 // ROW 7: Function, Axis, Grids, Close
471 // ----------------------------------------------------------------
472
473 S.AddSpace(5);
474
476 .MinSize( { wxDefaultCoord, wxDefaultCoord } )
477 .AddChoice(XXO("&Function:"), funcChoices, mFunc);
478 mFuncChoice->MoveAfterInTabOrder(mSizeChoice);
479
480 S.AddSpace(5);
481
483 .MinSize( { wxDefaultCoord, wxDefaultCoord } )
484 .AddChoice(XXO("&Axis:"), axisChoices, mAxis);
485 mAxisChoice->MoveAfterInTabOrder(mFuncChoice);
486
487 S.AddSpace(5);
488
489 mReplotButton = S.Id(ReplotButtonID).AddButton(XXO("&Replot..."));
490
491 S.AddSpace(5);
492
493 //mCloseButton = S.Id(wxID_CANCEL).AddButton(XO("&Close"));
494
495 //S.AddSpace(5);
496 }
497 S.EndMultiColumn();
498 S.AddStandardButtons( eHelpButton | eCloseButton );
499
500 // -------------------------------------------------------------------
501 // ROW 8: Spacer
502 // -------------------------------------------------------------------
503
504 S.AddSpace(5);
505
506 mProgress = safenew FreqGauge(S.GetParent(), wxID_ANY); //, wxST_SIZEGRIP);
507 S.Position(wxEXPAND)
508 .AddWindow(mProgress);
509
510 // Log-frequency axis works for spectrum plots only.
512 {
513 mAxis = 0;
514 mAxisChoice->Disable();
515 }
516 mLogAxis = mAxis != 0;
517
518 mCloseButton = static_cast<wxButton*>(FindWindowById( wxID_CANCEL ));
519 mCloseButton->SetDefault();
520
521 Layout();
522 Fit();
523 // Bug 1607:
524 Center();
525
526 SetMinSize(GetSize());
527
528#if defined(__WXGTK__)
529 // This should be rechecked with wx3.
530 //
531 // The scrollbar (focus some reason) doesn't allow tabbing past it
532 // because it can't receive focus. So, convince it otherwise.
533 //
534 // Unfortunately, this still doesn't let you adjust the scrollbar
535 // from the keyboard. Near as I can tell, wxWGTK is capturing the
536 // keyboard input, so the GTK widget doesn't see it, preventing
537 // the normal scroll events from being generated.
538 //
539 // I guess the only way round it would be to handle key actions
540 // ourselves, but we'll leave that for a future date.
541// gtk_widget_set_can_focus(mPanScroller->m_widget, true);
542#endif
543}
int NumWindowFuncs()
Definition: FFT.cpp:327
const TranslatableString WindowFuncName(int whichFunction)
Definition: FFT.cpp:332
#define FrequencyAnalysisTitle
Definition: FreqWindow.cpp:89
@ FreqAxisChoiceID
Definition: FreqWindow.cpp:102
@ FreqFuncChoiceID
Definition: FreqWindow.cpp:101
@ FreqPanScrollerID
Definition: FreqWindow.cpp:97
@ FreqExportButtonID
Definition: FreqWindow.cpp:98
@ ReplotButtonID
Definition: FreqWindow.cpp:103
@ FreqAlgChoiceID
Definition: FreqWindow.cpp:99
@ FreqSizeChoiceID
Definition: FreqWindow.cpp:100
@ FreqZoomSliderID
Definition: FreqWindow.cpp:96
@ GridOnOffID
Definition: FreqWindow.cpp:104
static const char * ZoomOut[]
Definition: FreqWindow.cpp:137
#define FREQ_WINDOW_HEIGHT
Definition: FreqWindow.cpp:110
static const char * ZoomIn[]
Definition: FreqWindow.cpp:112
XXO("&Cut/Copy/Paste Toolbar")
#define safenew
Definition: MemoryX.h:10
@ eIsCreating
Definition: ShuttleGui.h:39
@ eCloseButton
Definition: ShuttleGui.h:607
@ eHelpButton
Definition: ShuttleGui.h:601
#define S(N)
Definition: ToChars.cpp:64
TranslatableString Verbatim(wxString str)
Require calls to the one-argument constructor to go through this distinct global function name.
std::vector< TranslatableString > TranslatableStrings
friend class FreqPlot
Definition: FreqWindow.h:158
wxButton * mExportButton
Definition: FreqWindow.h:126
wxButton * mReplotButton
Definition: FreqWindow.h:127
static const int fontSize
Definition: FreqWindow.h:108
FreqGauge * mProgress
Definition: FreqWindow.h:116
wxButton * mCloseButton
Definition: FreqWindow.h:125
RulerPanel class allows you to work with a Ruler like any other wxWindow.
Definition: Ruler.h:228
std::pair< double, double > Range
Definition: Ruler.h:232
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:628
An alternative to using wxWindowAccessible, which in wxWidgets 3.1.1 contained GetParent() which was ...
void SetTitle(const TranslatableString &title)
Options & LabelEdges(bool l)
Definition: Ruler.h:250
Options & Log(bool l)
Definition: Ruler.h:244

References ThemeBase::Colour(), dBRange, DecibelScaleCutoff, eCloseButton, eHelpButton, eIsCreating, fontSize, FREQ_WINDOW_HEIGHT, FreqAlgChoiceID, FreqAxisChoiceID, FreqExportButtonID, FreqFuncChoiceID, FreqPanScrollerID, FreqPlot, FreqSizeChoiceID, FrequencyAnalysisTitle, FreqZoomSliderID, GridOnOffID, hRuler, RulerPanel::Options::LabelEdges(), Ruler::LinearDBFormat, RulerPanel::Options::Log(), mAlg, mAlgChoice, mArrowCursor, mAxis, mAxisChoice, mCloseButton, mCrossCursor, mCursorText, mDrawGrid, mExportButton, mFreqFont, mFreqPlot, mFunc, mFuncChoice, mGridOnOff, mLogAxis, mPanScroller, mPeakText, mProgress, mReplotButton, mSize, mSizeChoice, mWindowSize, mZoomSlider, NumWindowFuncs(), Setting< T >::Read(), Ruler::RealFormat, ReplotButtonID, S, safenew, wxDialogWrapper::SetTitle(), size, SpectrumAnalyst::Spectrum, theTheme, Verbatim(), vRuler, WindowFuncName(), wxT(), XO(), XXO(), ZoomIn, and ZoomOut.

Referenced by UpdatePrefs().

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

◆ Recalc()

void FrequencyPlotDialog::Recalc ( )
private

Definition at line 1009 of file FreqWindow.cpp.

1010{
1011 if (!mData || mDataLen < mWindowSize) {
1012 DrawPlot();
1013 return;
1014 }
1015
1017 SpectrumAnalyst::Algorithm(mAlgChoice->GetSelection());
1018 int windowFunc = mFuncChoice->GetSelection();
1019
1020 wxWindow *hadFocus = FindFocus();
1021 // In wxMac, the skipped window MUST be a top level window. I'd originally made it
1022 // just the mProgress window with the idea of preventing user interaction with the
1023 // controls while the plot was being recalculated. This doesn't appear to be necessary
1024 // so just use the top level window instead.
1025 {
1026 std::optional<wxWindowDisabler> blocker;
1027 if (IsShown())
1028 blocker.emplace(this);
1029 wxYieldIfNeeded();
1030
1031 mAnalyst->Calculate(alg, windowFunc, mWindowSize, mRate,
1032 mData.get(), mDataLen,
1033 &mYMin, &mYMax, mProgress);
1034 }
1035 if (hadFocus) {
1036 hadFocus->SetFocus();
1037 }
1038
1039 if (alg == SpectrumAnalyst::Spectrum) {
1040 if(mYMin < -dBRange)
1041 mYMin = -dBRange;
1042 if(mYMax <= -dBRange)
1043 mYMax = -dBRange + 10.; // it's all out of range, but show a scale.
1044 else
1045 mYMax += .5;
1046 }
1047
1048 // Prime the scrollbar
1049 mPanScroller->SetScrollbar(0, (mYMax - mYMin) * 100, (mYMax - mYMin) * 100, 1);
1050
1051 DrawPlot();
1052}

References dBRange, DrawPlot(), mAlgChoice, mAnalyst, mData, mDataLen, mFuncChoice, mPanScroller, mProgress, mRate, mWindowSize, mYMax, mYMin, and SpectrumAnalyst::Spectrum.

Referenced by OnRecalc(), and Show().

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

◆ SendRecalcEvent()

void FrequencyPlotDialog::SendRecalcEvent ( )
private

Definition at line 1003 of file FreqWindow.cpp.

1004{
1005 wxCommandEvent e(EVT_FREQWINDOW_RECALC, wxID_ANY);
1006 GetEventHandler()->AddPendingEvent(e);
1007}

Referenced by OnAlgChoice(), OnFuncChoice(), OnReplot(), and OnSizeChoice().

Here is the caller graph for this function:

◆ Show()

bool FrequencyPlotDialog::Show ( bool  show = true)
override

Definition at line 552 of file FreqWindow.cpp.

553{
554 if (!show)
555 {
556 mFreqPlot->SetCursor(*mArrowCursor);
557 }
558
559 bool shown = IsShown();
560
561 if (show && !shown)
562 {
564 if(dBRange < 90.)
565 dBRange = 90.;
566 GetAudio();
567 // Don't send an event. We need the recalc right away.
568 // so that mAnalyst is valid when we paint.
569 //SendRecalcEvent();
570 Recalc();
571 }
572
573 bool res = wxDialogWrapper::Show(show);
574
575 return res;
576}

References dBRange, DecibelScaleCutoff, GetAudio(), mArrowCursor, mFreqPlot, Setting< T >::Read(), and Recalc().

Referenced by OnCloseButton(), OnCloseWindow(), anonymous_namespace{FreqWindow.cpp}::OnPlotSpectrum(), and UpdatePrefs().

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

◆ UpdatePrefs()

void FrequencyPlotDialog::UpdatePrefs ( )
overrideprivatevirtual

Implements PrefsListener.

Definition at line 1119 of file FreqWindow.cpp.

1120{
1121 bool shown = IsShown();
1122 if (shown) {
1123 Show(false);
1124 }
1125
1126 auto zoomSlider = mZoomSlider->GetValue();
1127 auto drawGrid = mGridOnOff->GetValue();
1128 auto sizeChoice = mSizeChoice->GetStringSelection();
1129 auto algChoice = mAlgChoice->GetSelection();
1130 auto funcChoice = mFuncChoice->GetSelection();
1131 auto axisChoice = mAxisChoice->GetSelection();
1132
1133 SetSizer(nullptr);
1134 DestroyChildren();
1135
1136 Populate();
1137
1138 mZoomSlider->SetValue(zoomSlider);
1139
1140 mDrawGrid = drawGrid;
1141 mGridOnOff->SetValue(drawGrid);
1142
1143 long windowSize = 0;
1144 sizeChoice.ToLong(&windowSize);
1145 mWindowSize = windowSize;
1146 mSizeChoice->SetStringSelection(sizeChoice);
1147
1148 mAlg = static_cast<SpectrumAnalyst::Algorithm>(algChoice);
1149 mAlgChoice->SetSelection(algChoice);
1150
1151 mFunc = funcChoice;
1152 mFuncChoice->SetSelection(funcChoice);
1153
1154 mAxis = axisChoice;
1155 mAxisChoice->SetSelection(axisChoice);
1156
1157 if (shown) {
1158 Show(true);
1159 }
1160}

References mAlg, mAlgChoice, mAxis, mAxisChoice, mDrawGrid, mFunc, mFuncChoice, mGridOnOff, mSizeChoice, mWindowSize, mZoomSlider, Populate(), and Show().

Here is the call graph for this function:

Friends And Related Function Documentation

◆ FreqPlot

friend class FreqPlot
friend

Definition at line 158 of file FreqWindow.h.

Referenced by Populate().

Member Data Documentation

◆ dBRange

int FrequencyPlotDialog::dBRange
private

Definition at line 104 of file FreqWindow.h.

Referenced by DrawPlot(), OnReplot(), Populate(), Recalc(), and Show().

◆ fontSize

const int FrequencyPlotDialog::fontSize = 8
staticprivate

Definition at line 108 of file FreqWindow.h.

Referenced by Populate().

◆ hRuler

RulerPanel* FrequencyPlotDialog::hRuler
private

Definition at line 114 of file FreqWindow.h.

Referenced by DrawPlot(), and Populate().

◆ mAlg

SpectrumAnalyst::Algorithm FrequencyPlotDialog::mAlg
private

Definition at line 101 of file FreqWindow.h.

Referenced by DrawPlot(), OnAlgChoice(), PlotPaint(), Populate(), and UpdatePrefs().

◆ mAlgChoice

wxChoice* FrequencyPlotDialog::mAlgChoice
private

Definition at line 129 of file FreqWindow.h.

Referenced by OnAlgChoice(), OnCloseButton(), OnExport(), Populate(), Recalc(), and UpdatePrefs().

◆ mAnalyst

std::unique_ptr<SpectrumAnalyst> FrequencyPlotDialog::mAnalyst
private

Definition at line 154 of file FreqWindow.h.

Referenced by DrawPlot(), OnExport(), PlotPaint(), and Recalc().

◆ mArrowCursor

std::unique_ptr<wxCursor> FrequencyPlotDialog::mArrowCursor
private

Definition at line 122 of file FreqWindow.h.

Referenced by PlotMouseEvent(), Populate(), and Show().

◆ mAxis

int FrequencyPlotDialog::mAxis
private

Definition at line 103 of file FreqWindow.h.

Referenced by Populate(), and UpdatePrefs().

◆ mAxisChoice

wxChoice* FrequencyPlotDialog::mAxisChoice
private

Definition at line 132 of file FreqWindow.h.

Referenced by OnAlgChoice(), OnAxisChoice(), OnCloseButton(), Populate(), and UpdatePrefs().

◆ mBitmap

std::unique_ptr<wxBitmap> FrequencyPlotDialog::mBitmap
private

Definition at line 149 of file FreqWindow.h.

Referenced by DrawBackground(), and PlotPaint().

◆ mCloseButton

wxButton* FrequencyPlotDialog::mCloseButton
private

Definition at line 125 of file FreqWindow.h.

Referenced by Populate().

◆ mCrossCursor

std::unique_ptr<wxCursor> FrequencyPlotDialog::mCrossCursor
private

Definition at line 123 of file FreqWindow.h.

Referenced by PlotMouseEvent(), and Populate().

◆ mCursorText

wxTextCtrl* FrequencyPlotDialog::mCursorText
private

Definition at line 135 of file FreqWindow.h.

Referenced by PlotPaint(), and Populate().

◆ mData

Floats FrequencyPlotDialog::mData
private

Definition at line 141 of file FreqWindow.h.

Referenced by DrawPlot(), GetAudio(), OnCloseButton(), PlotPaint(), and Recalc().

◆ mDataLen

size_t FrequencyPlotDialog::mDataLen
private

Definition at line 140 of file FreqWindow.h.

Referenced by DrawPlot(), GetAudio(), PlotPaint(), and Recalc().

◆ mDrawGrid

bool FrequencyPlotDialog::mDrawGrid
private

Definition at line 99 of file FreqWindow.h.

Referenced by DrawPlot(), OnCloseButton(), OnGridOnOff(), Populate(), and UpdatePrefs().

◆ mExportButton

wxButton* FrequencyPlotDialog::mExportButton
private

Definition at line 126 of file FreqWindow.h.

Referenced by Populate().

◆ mFreqFont

wxFont FrequencyPlotDialog::mFreqFont
private

Definition at line 120 of file FreqWindow.h.

Referenced by DrawBackground(), PlotPaint(), and Populate().

◆ mFreqPlot

FreqPlot* FrequencyPlotDialog::mFreqPlot
private

Definition at line 115 of file FreqWindow.h.

Referenced by DrawBackground(), DrawPlot(), PlotMouseEvent(), Populate(), and Show().

◆ mFunc

int FrequencyPlotDialog::mFunc
private

Definition at line 102 of file FreqWindow.h.

Referenced by Populate(), and UpdatePrefs().

◆ mFuncChoice

wxChoice* FrequencyPlotDialog::mFuncChoice
private

Definition at line 131 of file FreqWindow.h.

Referenced by OnCloseButton(), Populate(), Recalc(), and UpdatePrefs().

◆ mGridOnOff

wxCheckBox* FrequencyPlotDialog::mGridOnOff
private

Definition at line 128 of file FreqWindow.h.

Referenced by OnGridOnOff(), Populate(), and UpdatePrefs().

◆ mLogAxis

bool FrequencyPlotDialog::mLogAxis
private

Definition at line 144 of file FreqWindow.h.

Referenced by DrawPlot(), OnAlgChoice(), OnAxisChoice(), PlotPaint(), and Populate().

◆ mMouseX

int FrequencyPlotDialog::mMouseX
private

Definition at line 151 of file FreqWindow.h.

Referenced by PlotMouseEvent(), and PlotPaint().

◆ mMouseY

int FrequencyPlotDialog::mMouseY
private

Definition at line 152 of file FreqWindow.h.

Referenced by PlotMouseEvent(), and PlotPaint().

◆ mPanScroller

wxScrollBar* FrequencyPlotDialog::mPanScroller
private

Definition at line 133 of file FreqWindow.h.

Referenced by DrawPlot(), Populate(), and Recalc().

◆ mPeakText

wxTextCtrl* FrequencyPlotDialog::mPeakText
private

Definition at line 136 of file FreqWindow.h.

Referenced by PlotPaint(), and Populate().

◆ mPlotRect

wxRect FrequencyPlotDialog::mPlotRect
private

Definition at line 118 of file FreqWindow.h.

Referenced by DrawBackground(), DrawPlot(), PlotMouseEvent(), and PlotPaint().

◆ mProgress

FreqGauge* FrequencyPlotDialog::mProgress
private

Definition at line 116 of file FreqWindow.h.

Referenced by Populate(), and Recalc().

◆ mProject

AudacityProject* FrequencyPlotDialog::mProject
private

Definition at line 105 of file FreqWindow.h.

◆ mRate

double FrequencyPlotDialog::mRate
private

Definition at line 139 of file FreqWindow.h.

Referenced by DrawPlot(), GetAudio(), OnExport(), PlotPaint(), and Recalc().

◆ mReplotButton

wxButton* FrequencyPlotDialog::mReplotButton
private

Definition at line 127 of file FreqWindow.h.

Referenced by Populate().

◆ mSize

int FrequencyPlotDialog::mSize
private

Definition at line 100 of file FreqWindow.h.

Referenced by Populate().

◆ mSizeChoice

wxChoice* FrequencyPlotDialog::mSizeChoice
private

Definition at line 130 of file FreqWindow.h.

Referenced by OnCloseButton(), OnSizeChoice(), Populate(), and UpdatePrefs().

◆ mWindowSize

size_t FrequencyPlotDialog::mWindowSize
private

Definition at line 142 of file FreqWindow.h.

Referenced by DrawPlot(), OnExport(), OnSizeChoice(), PlotPaint(), Populate(), Recalc(), and UpdatePrefs().

◆ mYMax

float FrequencyPlotDialog::mYMax
private

Definition at line 146 of file FreqWindow.h.

Referenced by DrawPlot(), and Recalc().

◆ mYMin

float FrequencyPlotDialog::mYMin
private

Definition at line 145 of file FreqWindow.h.

Referenced by DrawPlot(), and Recalc().

◆ mYStep

float FrequencyPlotDialog::mYStep
private

Definition at line 147 of file FreqWindow.h.

◆ mZoomSlider

wxSlider* FrequencyPlotDialog::mZoomSlider
private

Definition at line 134 of file FreqWindow.h.

Referenced by DrawPlot(), Populate(), and UpdatePrefs().

◆ vRuler

RulerPanel* FrequencyPlotDialog::vRuler
private

Definition at line 113 of file FreqWindow.h.

Referenced by DrawPlot(), and Populate().


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