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

191: wxDialogWrapper(parent, id, title, pos, wxDefaultSize,
192 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxMAXIMIZE_BOX),
193 mProject{ &project }
194, mAnalyst(std::make_unique<SpectrumAnalyst>())
195{
196 SetName();
197
198 mMouseX = 0;
199 mMouseY = 0;
200 mRate = 0;
201 mDataLen = 0;
202
203 gPrefs->Read(wxT("/FrequencyPlotDialog/DrawGrid"), &mDrawGrid, true);
204 gPrefs->Read(wxT("/FrequencyPlotDialog/SizeChoice"), &mSize, 3);
205
206 int alg;
207 gPrefs->Read(wxT("/FrequencyPlotDialog/AlgChoice"), &alg, 0);
208 mAlg = static_cast<SpectrumAnalyst::Algorithm>(alg);
209
210 gPrefs->Read(wxT("/FrequencyPlotDialog/FuncChoice"), &mFunc, 3);
211 gPrefs->Read(wxT("/FrequencyPlotDialog/AxisChoice"), &mAxis, 1);
212
213 Populate();
214}
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 216 of file FreqWindow.cpp.

217{
218}

Member Function Documentation

◆ DrawBackground()

void FrequencyPlotDialog::DrawBackground ( wxMemoryDC &  dc)
private

Definition at line 675 of file FreqWindow.cpp.

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

698{
699 if (!mData || mDataLen < mWindowSize || mAnalyst->GetProcessedSize() == 0) {
700 wxMemoryDC memDC;
701
704
706 hRuler->ruler.SetRange(0, 1);
707
708 DrawBackground(memDC);
709
710 if (mDataLen < mWindowSize) {
711 wxString msg = _("Not enough data selected.");
712 wxSize sz = memDC.GetTextExtent(msg);
713 memDC.DrawText(msg,
714 (mPlotRect.GetWidth() - sz.GetWidth()) / 2,
715 (mPlotRect.GetHeight() - sz.GetHeight()) / 2);
716 }
717
718 memDC.SelectObject(wxNullBitmap);
719
720 mFreqPlot->Refresh();
721
722 Refresh();
723
724 return;
725 }
726
727 float yRange = mYMax - mYMin;
728 float yTotal = yRange * ((float) mZoomSlider->GetValue() / 100.0f);
729
730 int sTotal = yTotal * 100;
731 int sRange = yRange * 100;
732 int sPos = mPanScroller->GetThumbPosition() + ((mPanScroller->GetThumbSize() - sTotal) / 2);
733 mPanScroller->SetScrollbar(sPos, sTotal, sRange, sTotal);
734
735 float yMax = mYMax - ((float)sPos / 100);
736 float yMin = yMax - yTotal;
737
738 // Set up y axis ruler
739
741 vRuler->ruler.SetUnits(XO("dB"));
743 } else {
744 vRuler->ruler.SetUnits({});
746 }
747 int w1, w2, h;
748 vRuler->ruler.GetMaxSize(&w1, &h);
749 vRuler->ruler.SetRange(yMax, yMin); // Note inversion for vertical.
750 vRuler->ruler.GetMaxSize(&w2, &h);
751 if( w1 != w2 ) // Reduces flicker
752 {
753 vRuler->SetMinSize(wxSize(w2,h));
754 Layout();
755 }
756 vRuler->Refresh(false);
757
758 wxMemoryDC memDC;
759 DrawBackground(memDC);
760
761 // Get the plot dimensions
762 //
763 // Must be done after setting the vertical ruler above since the
764 // the width could change.
765 wxRect r = mPlotRect;
766
767 // Set up x axis ruler
768
769 int width = r.width - 2;
770
771 float xMin, xMax, xRatio, xStep;
772
774 xMin = mRate / mWindowSize;
775 xMax = mRate / 2;
776 xRatio = xMax / xMin;
777 if (mLogAxis)
778 {
779 xStep = pow(2.0f, (log(xRatio) / log(2.0f)) / width);
781 }
782 else
783 {
784 xStep = (xMax - xMin) / width;
786 }
787 hRuler->ruler.SetUnits(XO("Hz"));
788 } else {
789 xMin = 0;
790 xMax = mAnalyst->GetProcessedSize() / mRate;
791 xStep = (xMax - xMin) / width;
793 /* i18n-hint: short form of 'seconds'.*/
794 hRuler->ruler.SetUnits(XO("s"));
795 }
796 hRuler->ruler.SetRange(xMin, xMax-xStep);
797 hRuler->Refresh(false);
798
799 // Draw the plot
801 memDC.SetPen(wxPen(theTheme.Colour( clrHzPlot ), 1, wxPENSTYLE_SOLID));
802 else
803 memDC.SetPen(wxPen(theTheme.Colour( clrWavelengthPlot), 1, wxPENSTYLE_SOLID));
804
805 float xPos = xMin;
806
807 for (int i = 0; i < width; i++) {
808 float y;
809
810 if (mLogAxis)
811 y = mAnalyst->GetProcessedValue(xPos, xPos * xStep);
812 else
813 y = mAnalyst->GetProcessedValue(xPos, xPos + xStep);
814
815 float ynorm = (y - yMin) / yTotal;
816
817 int lineheight = (int)(ynorm * (r.height - 1));
818
819 if (lineheight > r.height - 2)
820 lineheight = r.height - 2;
821
822 if (ynorm > 0.0)
823 AColor::Line(memDC, r.x + 1 + i, r.y + r.height - 1 - lineheight,
824 r.x + 1 + i, r.y + r.height - 1);
825
826 if (mLogAxis)
827 xPos *= xStep;
828 else
829 xPos += xStep;
830 }
831
832 // Outline the graph
833 memDC.SetPen(*wxBLACK_PEN);
834 memDC.SetBrush(*wxTRANSPARENT_BRUSH);
835 memDC.DrawRectangle(r);
836
837 if(mDrawGrid)
838 {
839 hRuler->ruler.DrawGrid(memDC, r.height, true, true, 1, 1);
840 vRuler->ruler.DrawGrid(memDC, r.width, true, true, 1, 1);
841 }
842
843 memDC.SelectObject( wxNullBitmap );
844
845 mFreqPlot->Refresh();
846}
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:675
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:534
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:616
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 585 of file FreqWindow.cpp.

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

References AudacityMessageBox(), BasicUI::MessageBoxOptions::Caption(), PackedArray::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 874 of file FreqWindow.cpp.

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

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

References DrawPlot(), mAxisChoice, and mLogAxis.

Here is the call graph for this function:

◆ OnCloseButton()

void FrequencyPlotDialog::OnCloseButton ( wxCommandEvent &  event)
private

Definition at line 1019 of file FreqWindow.cpp.

1020{
1021 gPrefs->Write(wxT("/FrequencyPlotDialog/DrawGrid"), mDrawGrid);
1022 gPrefs->Write(wxT("/FrequencyPlotDialog/SizeChoice"), mSizeChoice->GetSelection());
1023 gPrefs->Write(wxT("/FrequencyPlotDialog/AlgChoice"), mAlgChoice->GetSelection());
1024 gPrefs->Write(wxT("/FrequencyPlotDialog/FuncChoice"), mFuncChoice->GetSelection());
1025 gPrefs->Write(wxT("/FrequencyPlotDialog/AxisChoice"), mAxisChoice->GetSelection());
1026 gPrefs->Flush();
1027 mData.reset();
1028 Show(false);
1029}
wxChoice * mSizeChoice
Definition: FreqWindow.h:130
wxChoice * mFuncChoice
Definition: FreqWindow.h:131
bool Show(bool show=true) override
Definition: FreqWindow.cpp:558
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 1014 of file FreqWindow.cpp.

1015{
1016 Show(false);
1017}

References Show().

Here is the call graph for this function:

◆ OnExport()

void FrequencyPlotDialog::OnExport ( wxCommandEvent &  event)
private

Definition at line 1082 of file FreqWindow.cpp.

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

901{
903}

References SendRecalcEvent().

Here is the call graph for this function:

◆ OnGetURL()

void FrequencyPlotDialog::OnGetURL ( wxCommandEvent &  event)
private

Definition at line 551 of file FreqWindow.cpp.

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

References HelpSystem::ShowHelp().

Here is the call graph for this function:

◆ OnGridOnOff()

void FrequencyPlotDialog::OnGridOnOff ( wxCommandEvent &  event)
private

Definition at line 1135 of file FreqWindow.cpp.

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

865{
866 DrawPlot();
867}

References DrawPlot().

Here is the call graph for this function:

◆ OnRecalc()

void FrequencyPlotDialog::OnRecalc ( wxCommandEvent &  event)
private

Definition at line 1142 of file FreqWindow.cpp.

1143{
1144 Recalc();
1145}

References Recalc().

Here is the call graph for this function:

◆ OnReplot()

void FrequencyPlotDialog::OnReplot ( wxCommandEvent &  event)
private

Definition at line 1126 of file FreqWindow.cpp.

1127{
1129 if(dBRange < 90.)
1130 dBRange = 90.;
1131 GetAudio();
1133}
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:205

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

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

References DrawPlot().

Here is the call graph for this function:

◆ OnSizeChoice()

void FrequencyPlotDialog::OnSizeChoice ( wxCommandEvent &  event)
private

Definition at line 891 of file FreqWindow.cpp.

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

References mSizeChoice, mWindowSize, and SendRecalcEvent().

Here is the call graph for this function:

◆ OnZoomSlider()

void FrequencyPlotDialog::OnZoomSlider ( wxCommandEvent &  event)
private

Definition at line 869 of file FreqWindow.cpp.

870{
871 DrawPlot();
872}

References DrawPlot().

Here is the call graph for this function:

◆ PlotMouseEvent()

void FrequencyPlotDialog::PlotMouseEvent ( wxMouseEvent &  event)
private

Definition at line 849 of file FreqWindow.cpp.

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

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

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

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

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

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

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

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

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

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: