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 ()
 
bool 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 186 of file FreqWindow.cpp.

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

References project.

◆ ~FrequencyPlotDialog()

FrequencyPlotDialog::~FrequencyPlotDialog ( )
virtual

Definition at line 215 of file FreqWindow.cpp.

216{
217}

Member Function Documentation

◆ DrawBackground()

void FrequencyPlotDialog::DrawBackground ( wxMemoryDC &  dc)
private

Definition at line 674 of file FreqWindow.cpp.

675{
676 Layout();
677
678 mBitmap.reset();
679
680 mPlotRect = mFreqPlot->GetClientRect();
681
682 mBitmap = std::make_unique<wxBitmap>(mPlotRect.width, mPlotRect.height,24);
683
684 dc.SelectObject(*mBitmap);
685
686 dc.SetBackground(wxBrush(wxColour(254, 254, 254)));// DONT-THEME Mask colour.
687 dc.Clear();
688
689 dc.SetPen(*wxBLACK_PEN);
690 dc.SetBrush(*wxWHITE_BRUSH);
691 dc.DrawRectangle(mPlotRect);
692
693 dc.SetFont(mFreqFont);
694}
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 696 of file FreqWindow.cpp.

697{
698 if (!mData || mDataLen < mWindowSize || mAnalyst->GetProcessedSize() == 0) {
699 wxMemoryDC memDC;
700
703
705 hRuler->ruler.SetRange(0, 1);
706
707 DrawBackground(memDC);
708
709 if (mDataLen < mWindowSize) {
710 wxString msg = _("Not enough data selected.");
711 wxSize sz = memDC.GetTextExtent(msg);
712 memDC.DrawText(msg,
713 (mPlotRect.GetWidth() - sz.GetWidth()) / 2,
714 (mPlotRect.GetHeight() - sz.GetHeight()) / 2);
715 }
716
717 memDC.SelectObject(wxNullBitmap);
718
719 mFreqPlot->Refresh();
720
721 Refresh();
722
723 return;
724 }
725
726 float yRange = mYMax - mYMin;
727 float yTotal = yRange * ((float) mZoomSlider->GetValue() / 100.0f);
728
729 int sTotal = yTotal * 100;
730 int sRange = yRange * 100;
731 int sPos = mPanScroller->GetThumbPosition() + ((mPanScroller->GetThumbSize() - sTotal) / 2);
732 mPanScroller->SetScrollbar(sPos, sTotal, sRange, sTotal);
733
734 float yMax = mYMax - ((float)sPos / 100);
735 float yMin = yMax - yTotal;
736
737 // Set up y axis ruler
738
740 vRuler->ruler.SetUnits(XO("dB"));
742 } else {
743 vRuler->ruler.SetUnits({});
745 }
746 int w1, w2, h;
747 vRuler->ruler.GetMaxSize(&w1, &h);
748 vRuler->ruler.SetRange(yMax, yMin); // Note inversion for vertical.
749 vRuler->ruler.GetMaxSize(&w2, &h);
750 if( w1 != w2 ) // Reduces flicker
751 {
752 vRuler->SetMinSize(wxSize(w2,h));
753 Layout();
754 }
755 vRuler->Refresh(false);
756
757 wxMemoryDC memDC;
758 DrawBackground(memDC);
759
760 // Get the plot dimensions
761 //
762 // Must be done after setting the vertical ruler above since the
763 // the width could change.
764 wxRect r = mPlotRect;
765
766 // Set up x axis ruler
767
768 int width = r.width - 2;
769
770 float xMin, xMax, xRatio, xStep;
771
773 xMin = mRate / mWindowSize;
774 xMax = mRate / 2;
775 xRatio = xMax / xMin;
776 if (mLogAxis)
777 {
778 xStep = pow(2.0f, (log(xRatio) / log(2.0f)) / width);
780 }
781 else
782 {
783 xStep = (xMax - xMin) / width;
785 }
786 hRuler->ruler.SetUnits(XO("Hz"));
787 } else {
788 xMin = 0;
789 xMax = mAnalyst->GetProcessedSize() / mRate;
790 xStep = (xMax - xMin) / width;
792 /* i18n-hint: short form of 'seconds'.*/
793 hRuler->ruler.SetUnits(XO("s"));
794 }
795 hRuler->ruler.SetRange(xMin, xMax-xStep);
796 hRuler->Refresh(false);
797
798 // Draw the plot
800 memDC.SetPen(wxPen(theTheme.Colour( clrHzPlot ), 1, wxPENSTYLE_SOLID));
801 else
802 memDC.SetPen(wxPen(theTheme.Colour( clrWavelengthPlot), 1, wxPENSTYLE_SOLID));
803
804 float xPos = xMin;
805
806 for (int i = 0; i < width; i++) {
807 float y;
808
809 if (mLogAxis)
810 y = mAnalyst->GetProcessedValue(xPos, xPos * xStep);
811 else
812 y = mAnalyst->GetProcessedValue(xPos, xPos + xStep);
813
814 float ynorm = (y - yMin) / yTotal;
815
816 int lineheight = (int)(ynorm * (r.height - 1));
817
818 if (lineheight > r.height - 2)
819 lineheight = r.height - 2;
820
821 if (ynorm > 0.0)
822 AColor::Line(memDC, r.x + 1 + i, r.y + r.height - 1 - lineheight,
823 r.x + 1 + i, r.y + r.height - 1);
824
825 if (mLogAxis)
826 xPos *= xStep;
827 else
828 xPos += xStep;
829 }
830
831 // Outline the graph
832 memDC.SetPen(*wxBLACK_PEN);
833 memDC.SetBrush(*wxTRANSPARENT_BRUSH);
834 memDC.DrawRectangle(r);
835
836 if(mDrawGrid)
837 {
838 hRuler->ruler.DrawGrid(memDC, r.height, true, true, 1, 1);
839 vRuler->ruler.DrawGrid(memDC, r.width, true, true, 1, 1);
840 }
841
842 memDC.SelectObject( wxNullBitmap );
843
844 mFreqPlot->Refresh();
845}
XO("Cut/Copy/Paste")
#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: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:674
wxScrollBar * mPanScroller
Definition: FreqWindow.h:133
static const LinearDBFormat & Instance()
static const LinearUpdater & Instance()
static const LogarithmicUpdater & Instance()
static const RealFormat & LinearInstance()
Definition: RealFormat.cpp:14
void DrawGrid(wxDC &dc, int length, bool minor=true, bool major=true, int xOffset=0, int yOffset=0) const
Definition: Ruler.cpp:530
void SetUpdater(const RulerUpdater *pUpdater)
Definition: Ruler.cpp:112
void SetFormat(const RulerFormat *pFormat)
Definition: Ruler.cpp:104
void GetMaxSize(wxCoord *width, wxCoord *height)
Definition: Ruler.cpp:612
void SetUnits(const TranslatableString &units)
Definition: Ruler.cpp:120
void SetRange(double min, double max)
Definition: Ruler.cpp:152
Ruler ruler
Definition: RulerPanel.h:79
wxColour & Colour(int iIndex)

References _, ThemeBase::Colour(), dBRange, DrawBackground(), Ruler::DrawGrid(), Ruler::GetMaxSize(), hRuler, LinearDBFormat::Instance(), LinearUpdater::Instance(), LogarithmicUpdater::Instance(), AColor::Line(), RealFormat::LinearInstance(), mAlg, mAnalyst, mData, mDataLen, mDrawGrid, mFreqPlot, mLogAxis, mPanScroller, mPlotRect, mRate, mWindowSize, mYMax, mYMin, mZoomSlider, RulerPanel::ruler, Ruler::SetFormat(), Ruler::SetRange(), Ruler::SetUnits(), Ruler::SetUpdater(), 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()

bool FrequencyPlotDialog::GetAudio ( )
private

Definition at line 584 of file FreqWindow.cpp.

585{
586 mData.reset();
587 mDataLen = 0;
588
589 int selcount = 0;
590 bool warning = false;
591 for (auto track :
592 TrackList::Get(*mProject).Selected<const WaveTrack>()
593 ) {
594 auto &selectedRegion = ViewInfo::Get(*mProject).selectedRegion;
595 auto start = track->TimeToLongSamples(selectedRegion.t0());
596 if (selcount == 0) {
597 mRate = track->GetRate();
598 auto end = track->TimeToLongSamples(selectedRegion.t1());
599 auto dataLen = end - start;
600 // Permit approximately 46.60 minutes of selected samples at
601 // a sampling frequency of 48 kHz (11.65 minutes at 192 kHz).
602 auto maxDataLen = size_t(2) << 26;
603 if (dataLen > maxDataLen) {
604 warning = true;
605 mDataLen = maxDataLen;
606 }
607 else
608 mDataLen = dataLen.as_size_t();
609 mData = Floats{ mDataLen };
610 }
611 const auto nChannels = track->NChannels();
612 if (track->GetRate() != mRate) {
613 using namespace BasicUI;
615 XO("To plot the spectrum, all selected tracks must have the same sample rate."),
616 MessageBoxOptions {}.Caption(XO("Error")).IconStyle(Icon::Error));
617 mData.reset();
618 mDataLen = 0;
619 return false;
620 }
621 Floats buffer1{ mDataLen };
622 Floats buffer2{ mDataLen };
623 float *const buffers[]{ buffer1.get(), buffer2.get() };
624 // Don't allow throw for bad reads
625 if (!track->GetFloats(
626 0, nChannels, buffers, start, mDataLen, false,
627 FillFormat::fillZero, false))
628 {
629 using namespace BasicUI;
631 XO("Audio could not be analyzed. This may be due to a stretched or pitch-shifted clip.\nTry resetting any stretched clips, or mixing and rendering the tracks before analyzing"),
632 MessageBoxOptions {}.Caption(XO("Error")).IconStyle(Icon::Error));
633 mData.reset();
634 mDataLen = 0;
635 return false;
636 }
637 size_t iChannel = 0;
638 if (selcount == 0) {
639 // First channel -- assign into mData
640 for (size_t i = 0; i < mDataLen; i++)
641 mData[i] = buffers[0][i];
642 ++iChannel;
643 }
644 // Later channels -- accumulate
645 for (; iChannel < nChannels; ++iChannel) {
646 const auto buffer = buffers[iChannel];
647 for (size_t i = 0; i < mDataLen; i++)
648 mData[i] += buffer[i];
649 }
650 ++selcount;
651 }
652
653 if (selcount == 0)
654 return false;
655
656 if (warning) {
657 auto msg = XO(
658"Too much audio was selected. Only the first %.1f seconds of audio will be analyzed.")
659 .Format(mDataLen / mRate);
660 AudacityMessageBox( msg );
661 }
662 return true;
663}
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:314
auto Selected() -> TrackIterRange< TrackType >
Definition: Track.h:967
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:215
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
A Track that contains audio waveform data.
Definition: WaveTrack.h:203
MessageBoxResult ShowMessageBox(const TranslatableString &message, MessageBoxOptions options={})
Show a modal message box with either Ok or Yes and No, and optionally Cancel.
Definition: BasicUI.h:279
const char * end(const char *str) noexcept
Definition: StringUtils.h:106
MessageBoxOptions && Caption(TranslatableString caption_) &&
Definition: BasicUI.h:101

References AudacityMessageBox(), BasicUI::MessageBoxOptions::Caption(), details::end(), fillZero, ViewInfo::Get(), TrackList::Get(), anonymous_namespace{StretchingSequenceIntegrationTest.cpp}::iChannel, mData, mDataLen, mRate, TrackList::Selected(), ViewInfo::selectedRegion, BasicUI::ShowMessageBox(), 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 873 of file FreqWindow.cpp.

874{
875 mAlg = SpectrumAnalyst::Algorithm(mAlgChoice->GetSelection());
876
877 // Log-frequency axis works for spectrum plots only.
879 mAxisChoice->Enable(true);
880 mLogAxis = mAxisChoice->GetSelection() ? true : false;
881 }
882 else {
883 mAxisChoice->Disable();
884 mLogAxis = false;
885 }
886
888}
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 904 of file FreqWindow.cpp.

905{
906 mLogAxis = mAxisChoice->GetSelection() ? true : false;
907 DrawPlot();
908}

References DrawPlot(), mAxisChoice, and mLogAxis.

Here is the call graph for this function:

◆ OnCloseButton()

void FrequencyPlotDialog::OnCloseButton ( wxCommandEvent &  event)
private

Definition at line 1018 of file FreqWindow.cpp.

1019{
1020 gPrefs->Write(wxT("/FrequencyPlotDialog/DrawGrid"), mDrawGrid);
1021 gPrefs->Write(wxT("/FrequencyPlotDialog/SizeChoice"), mSizeChoice->GetSelection());
1022 gPrefs->Write(wxT("/FrequencyPlotDialog/AlgChoice"), mAlgChoice->GetSelection());
1023 gPrefs->Write(wxT("/FrequencyPlotDialog/FuncChoice"), mFuncChoice->GetSelection());
1024 gPrefs->Write(wxT("/FrequencyPlotDialog/AxisChoice"), mAxisChoice->GetSelection());
1025 gPrefs->Flush();
1026 mData.reset();
1027 Show(false);
1028}
wxChoice * mSizeChoice
Definition: FreqWindow.h:130
wxChoice * mFuncChoice
Definition: FreqWindow.h:131
bool Show(bool show=true) override
Definition: FreqWindow.cpp:557
virtual bool Flush() noexcept=0
virtual bool Write(const wxString &key, bool value)=0

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

Here is the call graph for this function:

◆ OnCloseWindow()

void FrequencyPlotDialog::OnCloseWindow ( wxCloseEvent &  event)
private

Definition at line 1013 of file FreqWindow.cpp.

1014{
1015 Show(false);
1016}

References Show().

Here is the call graph for this function:

◆ OnExport()

void FrequencyPlotDialog::OnExport ( wxCommandEvent &  event)
private

Definition at line 1081 of file FreqWindow.cpp.

1082{
1083 wxString fName = _("spectrum.txt");
1084
1085 fName = SelectFile(FileNames::Operation::Export,
1086 XO("Export Spectral Data As:"),
1087 wxEmptyString,
1088 fName,
1089 wxT("txt"),
1091 wxFD_SAVE | wxRESIZE_BORDER,
1092 this);
1093
1094 if (fName.empty())
1095 return;
1096
1097 wxFFileOutputStream ffStream{ fName };
1098 if (!ffStream.IsOk()) {
1099 AudacityMessageBox( XO("Couldn't write to file: %s").Format( fName ) );
1100 return;
1101 }
1102
1103 wxTextOutputStream ss(ffStream);
1104
1105 const int processedSize = mAnalyst->GetProcessedSize();
1106 const float *const processed = mAnalyst->GetProcessed();
1107 if (mAlgChoice->GetSelection() == 0) {
1108 ss
1109 << XO("Frequency (Hz)\tLevel (dB)") << '\n';
1110 for (int i = 1; i < processedSize; i++)
1111 ss
1112 << wxString::Format(wxT("%f\t%f\n"),
1113 i * mRate / mWindowSize, processed[i] );
1114 }
1115 else {
1116 ss
1117 << XO("Lag (seconds)\tFrequency (Hz)\tLevel") << '\n';
1118 for (int i = 1; i < processedSize; i++)
1119 ss
1120 << wxString::Format(wxT("%f\t%f\t%f\n"),
1121 i / mRate, mRate / i, processed[i] );
1122 }
1123}
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 899 of file FreqWindow.cpp.

900{
902}

References SendRecalcEvent().

Here is the call graph for this function:

◆ OnGetURL()

void FrequencyPlotDialog::OnGetURL ( wxCommandEvent &  event)
private

Definition at line 550 of file FreqWindow.cpp.

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

References HelpSystem::ShowHelp().

Here is the call graph for this function:

◆ OnGridOnOff()

void FrequencyPlotDialog::OnGridOnOff ( wxCommandEvent &  event)
private

Definition at line 1134 of file FreqWindow.cpp.

1135{
1136 mDrawGrid = mGridOnOff->IsChecked();
1137
1138 DrawPlot();
1139}
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 863 of file FreqWindow.cpp.

864{
865 DrawPlot();
866}

References DrawPlot().

Here is the call graph for this function:

◆ OnRecalc()

void FrequencyPlotDialog::OnRecalc ( wxCommandEvent &  event)
private

Definition at line 1141 of file FreqWindow.cpp.

1142{
1143 Recalc();
1144}

References Recalc().

Here is the call graph for this function:

◆ OnReplot()

void FrequencyPlotDialog::OnReplot ( wxCommandEvent &  event)
private

Definition at line 1125 of file FreqWindow.cpp.

1126{
1128 if(dBRange < 90.)
1129 dBRange = 90.;
1130 GetAudio();
1132}
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:207

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 665 of file FreqWindow.cpp.

666{
667 Layout();
668
669 DrawPlot();
670
671 Refresh(true);
672}

References DrawPlot().

Here is the call graph for this function:

◆ OnSizeChoice()

void FrequencyPlotDialog::OnSizeChoice ( wxCommandEvent &  event)
private

Definition at line 890 of file FreqWindow.cpp.

891{
892 long windowSize = 0;
893 mSizeChoice->GetStringSelection().ToLong(&windowSize);
894 mWindowSize = windowSize;
895
897}

References mSizeChoice, mWindowSize, and SendRecalcEvent().

Here is the call graph for this function:

◆ OnZoomSlider()

void FrequencyPlotDialog::OnZoomSlider ( wxCommandEvent &  event)
private

Definition at line 868 of file FreqWindow.cpp.

869{
870 DrawPlot();
871}

References DrawPlot().

Here is the call graph for this function:

◆ PlotMouseEvent()

void FrequencyPlotDialog::PlotMouseEvent ( wxMouseEvent &  event)
private

Definition at line 848 of file FreqWindow.cpp.

849{
850 if (event.Moving() && (event.m_x != mMouseX || event.m_y != mMouseY)) {
851 mMouseX = event.m_x;
852 mMouseY = event.m_y;
853
854 if (mPlotRect.Contains(mMouseX, mMouseY))
855 mFreqPlot->SetCursor(*mCrossCursor);
856 else
857 mFreqPlot->SetCursor(*mArrowCursor);
858
859 mFreqPlot->Refresh(false);
860 }
861}
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 910 of file FreqWindow.cpp.

911{
912 wxPaintDC dc( (wxWindow *) event.GetEventObject() );
913
914 dc.DrawBitmap( *mBitmap, 0, 0, true );
915 // Fix for Bug 1226 "Plot Spectrum freezes... if insufficient samples selected"
916 if (!mData || mDataLen < mWindowSize)
917 return;
918
919 dc.SetFont(mFreqFont);
920
921 wxRect r = mPlotRect;
922
923 int width = r.width - 2;
924
925 float xMin, xMax, xRatio, xStep;
926
928 xMin = mRate / mWindowSize;
929 xMax = mRate / 2;
930 xRatio = xMax / xMin;
931 if (mLogAxis)
932 xStep = pow(2.0f, (log(xRatio) / log(2.0f)) / width);
933 else
934 xStep = (xMax - xMin) / width;
935 } else {
936 xMin = 0;
937 xMax = mAnalyst->GetProcessedSize() / mRate;
938 xStep = (xMax - xMin) / width;
939 }
940
941 float xPos = xMin;
942
943 // Find the peak nearest the cursor and plot it
944 if ( r.Contains(mMouseX, mMouseY) && (mMouseX!=0) && (mMouseX!=r.width-1) ) {
945 if (mLogAxis)
946 xPos = xMin * pow(xStep, mMouseX - (r.x + 1));
947 else
948 xPos = xMin + xStep * (mMouseX - (r.x + 1));
949
950 float bestValue = 0;
951 float bestpeak = mAnalyst->FindPeak(xPos, &bestValue);
952
953 int px;
954 if (mLogAxis)
955 px = (int)(log(bestpeak / xMin) / log(xStep));
956 else
957 px = (int)((bestpeak - xMin) * width / (xMax - xMin));
958
959 dc.SetPen(wxPen(wxColour(255, 32, 32), 1, wxPENSTYLE_SOLID));
960 AColor::Line(dc, r.x + 1 + px, r.y, r.x + 1 + px, r.y + r.height);
961
962 // print out info about the cursor location
963
964 float value;
965
966 if (mLogAxis) {
967 xPos = xMin * pow(xStep, mMouseX - (r.x + 1));
968 value = mAnalyst->GetProcessedValue(xPos, xPos * xStep);
969 } else {
970 xPos = xMin + xStep * (mMouseX - (r.x + 1));
971 value = mAnalyst->GetProcessedValue(xPos, xPos + xStep);
972 }
973
974 TranslatableString cursor;
976
978 auto xp = PitchName_Absolute(FreqToMIDInote(xPos));
979 auto pp = PitchName_Absolute(FreqToMIDInote(bestpeak));
980 /* i18n-hint: The %d's are replaced by numbers, the %s by musical notes, e.g. A#*/
981 cursor = XO("%d Hz (%s) = %d dB")
982 .Format( (int)(xPos + 0.5), xp, (int)(value + 0.5));
983 /* i18n-hint: The %d's are replaced by numbers, the %s by musical notes, e.g. A#*/
984 peak = XO("%d Hz (%s) = %.1f dB")
985 .Format( (int)(bestpeak + 0.5), pp, bestValue );
986 } else if (xPos > 0.0 && bestpeak > 0.0) {
987 auto xp = PitchName_Absolute(FreqToMIDInote(1.0 / xPos));
988 auto pp = PitchName_Absolute(FreqToMIDInote(1.0 / bestpeak));
989 /* i18n-hint: The %d's are replaced by numbers, the %s by musical notes, e.g. A#
990 * the %.4f are numbers, and 'sec' should be an abbreviation for seconds */
991 cursor = XO("%.4f sec (%d Hz) (%s) = %f")
992 .Format( xPos, (int)(1.0 / xPos + 0.5), xp, value );
993 /* i18n-hint: The %d's are replaced by numbers, the %s by musical notes, e.g. A#
994 * the %.4f are numbers, and 'sec' should be an abbreviation for seconds */
995 peak = XO("%.4f sec (%d Hz) (%s) = %.3f")
996 .Format( bestpeak, (int)(1.0 / bestpeak + 0.5), pp, bestValue );
997 }
998 mCursorText->SetValue( cursor.Translation() );
999 mPeakText->SetValue( peak.Translation() );
1000 }
1001 else {
1002 mCursorText->SetValue(wxT(""));
1003 mPeakText->SetValue(wxT(""));
1004 }
1005
1006
1007 // Outline the graph
1008 dc.SetPen(*wxBLACK_PEN);
1009 dc.SetBrush(*wxTRANSPARENT_BRUSH);
1010 dc.DrawRectangle(r);
1011}
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 219 of file FreqWindow.cpp.

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

References ThemeBase::Colour(), dBRange, DecibelScaleCutoff, eCloseButton, eHelpButton, eIsCreating, fontSize, FREQ_WINDOW_HEIGHT, FreqAlgChoiceID, FreqAxisChoiceID, FreqExportButtonID, FreqFuncChoiceID, FreqPanScrollerID, FreqPlot, FreqSizeChoiceID, FrequencyAnalysisTitle, FreqZoomSliderID, GridOnOffID, hRuler, LinearDBFormat::Instance(), RulerPanel::Options::LabelEdges(), RealFormat::LinearInstance(), 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(), 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 1036 of file FreqWindow.cpp.

1037{
1038 if (!mData || mDataLen < mWindowSize) {
1039 DrawPlot();
1040 return;
1041 }
1042
1044 SpectrumAnalyst::Algorithm(mAlgChoice->GetSelection());
1045 int windowFunc = mFuncChoice->GetSelection();
1046
1047 wxWindow *hadFocus = FindFocus();
1048 // In wxMac, the skipped window MUST be a top level window. I'd originally made it
1049 // just the mProgress window with the idea of preventing user interaction with the
1050 // controls while the plot was being recalculated. This doesn't appear to be necessary
1051 // so just use the top level window instead.
1052 {
1053 std::optional<wxWindowDisabler> blocker;
1054 if (IsShown())
1055 blocker.emplace(this);
1056 wxYieldIfNeeded();
1057
1058 mAnalyst->Calculate(alg, windowFunc, mWindowSize, mRate,
1059 mData.get(), mDataLen,
1060 &mYMin, &mYMax, mProgress);
1061 }
1062 if (hadFocus) {
1063 hadFocus->SetFocus();
1064 }
1065
1066 if (alg == SpectrumAnalyst::Spectrum) {
1067 if(mYMin < -dBRange)
1068 mYMin = -dBRange;
1069 if(mYMax <= -dBRange)
1070 mYMax = -dBRange + 10.; // it's all out of range, but show a scale.
1071 else
1072 mYMax += .5;
1073 }
1074
1075 // Prime the scrollbar
1076 mPanScroller->SetScrollbar(0, (mYMax - mYMin) * 100, (mYMax - mYMin) * 100, 1);
1077
1078 DrawPlot();
1079}
std::unique_ptr< WindowPlacement > FindFocus()
Find the window that is accepting keyboard input, if any.
Definition: BasicUI.h:375

References dBRange, DrawPlot(), BasicUI::FindFocus(), 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 1030 of file FreqWindow.cpp.

1031{
1032 wxCommandEvent e(EVT_FREQWINDOW_RECALC, wxID_ANY);
1033 GetEventHandler()->AddPendingEvent(e);
1034}

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 557 of file FreqWindow.cpp.

558{
559 if (!show)
560 {
561 mFreqPlot->SetCursor(*mArrowCursor);
562 }
563
564 bool shown = IsShown();
565
566 if (show && !shown)
567 {
569 if(dBRange < 90.)
570 dBRange = 90.;
571 if (!GetAudio())
572 return false;
573 // Don't send an event. We need the recalc right away.
574 // so that mAnalyst is valid when we paint.
575 //SendRecalcEvent();
576 Recalc();
577 }
578
579 bool res = wxDialogWrapper::Show(show);
580
581 return res;
582}
IMPORT_EXPORT_API ExportResult Show(ExportTask exportTask)

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

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 1146 of file FreqWindow.cpp.

1147{
1148 bool shown = IsShown();
1149 if (shown) {
1150 Show(false);
1151 }
1152
1153 auto zoomSlider = mZoomSlider->GetValue();
1154 auto drawGrid = mGridOnOff->GetValue();
1155 auto sizeChoice = mSizeChoice->GetStringSelection();
1156 auto algChoice = mAlgChoice->GetSelection();
1157 auto funcChoice = mFuncChoice->GetSelection();
1158 auto axisChoice = mAxisChoice->GetSelection();
1159
1160 SetSizer(nullptr);
1161 DestroyChildren();
1162
1163 Populate();
1164
1165 mZoomSlider->SetValue(zoomSlider);
1166
1167 mDrawGrid = drawGrid;
1168 mGridOnOff->SetValue(drawGrid);
1169
1170 long windowSize = 0;
1171 sizeChoice.ToLong(&windowSize);
1172 mWindowSize = windowSize;
1173 mSizeChoice->SetStringSelection(sizeChoice);
1174
1175 mAlg = static_cast<SpectrumAnalyst::Algorithm>(algChoice);
1176 mAlgChoice->SetSelection(algChoice);
1177
1178 mFunc = funcChoice;
1179 mFuncChoice->SetSelection(funcChoice);
1180
1181 mAxis = axisChoice;
1182 mAxisChoice->SetSelection(axisChoice);
1183
1184 if (shown) {
1185 Show(true);
1186 }
1187}

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: