42#include <wx/checkbox.h>
44#include <wx/dcclient.h>
45#include <wx/dcmemory.h>
50#include <wx/scrolbar.h>
53#include <wx/statbmp.h>
54#include <wx/stattext.h>
55#include <wx/statusbr.h>
57#include <wx/textctrl.h>
58#include <wx/textfile.h>
60#include <wx/wfstream.h>
61#include <wx/txtstrm.h>
88#if wxUSE_ACCESSIBILITY
92#define FrequencyAnalysisTitle XO("Frequency Analysis")
112#define FREQ_WINDOW_WIDTH 480
113#define FREQ_WINDOW_HEIGHT 330
189 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxMAXIMIZE_BOX),
191, mAnalyst(std::make_unique<SpectrumAnalyst>())
200 gPrefs->Read(wxT(
"/FrequencyPlotDialog/DrawGrid"), &mDrawGrid,
true);
201 gPrefs->Read(wxT(
"/FrequencyPlotDialog/SizeChoice"), &mSize, 3);
204 gPrefs->Read(wxT(
"/FrequencyPlotDialog/AlgChoice"), &alg, 0);
207 gPrefs->Read(wxT(
"/FrequencyPlotDialog/FuncChoice"), &mFunc, 3);
208 gPrefs->Read(wxT(
"/FrequencyPlotDialog/AxisChoice"), &mAxis, 1);
223 XO(
"Standard Autocorrelation") ,
224 XO(
"Cuberoot Autocorrelation") ,
225 XO(
"Enhanced Autocorrelation") ,
249 funcChoices.push_back(
257 XO(
"Linear frequency") ,
258 XO(
"Log frequency") ,
261 mFreqFont = wxFont(
fontSize, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
262 mArrowCursor = std::make_unique<wxCursor>(wxCURSOR_ARROW);
263 mCrossCursor = std::make_unique<wxCursor>(wxCURSOR_CROSS);
267 sizeChoices[
mSize].MSGID().GET().ToLong(&
size);
280 S.SetSizerProportion(1);
281 S.StartMultiColumn(3, wxEXPAND);
290 S.StartVerticalLay(2);
293 S.GetParent(), wxID_ANY, wxVERTICAL,
303 S.AddSpace(wxDefaultCoord, 1);
305 .Position(wxALIGN_RIGHT | wxALIGN_TOP)
307 S.AddSpace(wxDefaultCoord, 1);
317 S.StartHorizontalLay(wxEXPAND, 0);
319 S.StartVerticalLay();
322 wxDefaultPosition, wxDefaultSize, wxSB_VERTICAL);
323#if wxUSE_ACCESSIBILITY
330 .Position( wxALIGN_LEFT | wxTOP)
335 S.StartVerticalLay();
337 wxStaticBitmap *zi =
safenew wxStaticBitmap(
S.GetParent(), wxID_ANY, wxBitmap(
ZoomIn));
338 S.Position(wxALIGN_CENTER)
344 wxDefaultPosition, wxDefaultSize, wxSL_VERTICAL);
348 .Position(wxALIGN_CENTER_HORIZONTAL)
350#if wxUSE_ACCESSIBILITY
357 wxStaticBitmap *zo =
safenew wxStaticBitmap(
S.GetParent(), wxID_ANY, wxBitmap(
ZoomOut));
358 S.Position(wxALIGN_CENTER)
363 S.AddSpace(5, wxDefaultCoord);
365 S.EndHorizontalLay();
373 S.StartHorizontalLay(wxEXPAND, 0);
376 S.GetParent(), wxID_ANY, wxHORIZONTAL,
388 S.AddSpace(1, wxDefaultCoord);
390 .Position(wxALIGN_LEFT | wxALIGN_TOP)
392 S.AddSpace(1, wxDefaultCoord);
394 S.EndHorizontalLay();
412 S.StartHorizontalLay(wxEXPAND);
414 S.SetSizerProportion(1);
415 S.StartMultiColumn(6);
419 S.AddPrompt(
XXO(
"Cursor:"));
422 .AddTextBox( {}, wxT(
""), 10);
424 S.AddPrompt(
XXO(
"Peak:"));
427 .AddTextBox( {}, wxT(
""), 10);
434 S.EndHorizontalLay();
447 S.SetSizerProportion(0);
448 S.StartMultiColumn(9, wxALIGN_CENTER);
457 .MinSize( { wxDefaultCoord, wxDefaultCoord } )
458 .AddChoice(
XXO(
"&Algorithm:"), algChoices,
mAlg);
463 .MinSize( { wxDefaultCoord, wxDefaultCoord } )
464 .AddChoice(
XXO(
"&Size:"), sizeChoices,
mSize);
479 .MinSize( { wxDefaultCoord, wxDefaultCoord } )
480 .AddChoice(
XXO(
"&Function:"), funcChoices,
mFunc);
486 .MinSize( { wxDefaultCoord, wxDefaultCoord } )
487 .AddChoice(
XXO(
"&Axis:"), axisChoices,
mAxis);
521 mCloseButton =
static_cast<wxButton*
>(FindWindowById( wxID_CANCEL ));
529 SetMinSize(GetSize());
531#if defined(__WXGTK__)
562 bool shown = IsShown();
576 bool res = wxDialogWrapper::Show(show);
587 bool warning =
false;
591 mRate = track->GetRate();
592 auto start = track->TimeToLongSamples(selectedRegion.t0());
593 auto end = track->TimeToLongSamples(selectedRegion.t1());
594 auto dataLen =
end - start;
597 auto maxDataLen = size_t(2) << 26;
598 if (dataLen > maxDataLen) {
611 if (track->GetRate() !=
mRate) {
614"To plot the spectrum, all selected tracks must be the same sample rate.") );
619 auto start = track->TimeToLongSamples(selectedRegion.t0());
622 track->GetFloats(buffer2.get(), start,
mDataLen,
624 for (
size_t i = 0; i <
mDataLen; i++)
625 mData[i] += buffer2[i];
635"Too much audio was selected. Only the first %.1f seconds of audio will be analyzed.")
662 dc.SetBackground(wxBrush(wxColour(254, 254, 254)));
665 dc.SetPen(*wxBLACK_PEN);
666 dc.SetBrush(*wxWHITE_BRUSH);
674 if (!
mData || mDataLen < mWindowSize || mAnalyst->GetProcessedSize() == 0) {
686 wxString msg =
_(
"Not enough data selected.");
687 wxSize sz = memDC.GetTextExtent(msg);
689 (
mPlotRect.GetWidth() - sz.GetWidth()) / 2,
690 (
mPlotRect.GetHeight() - sz.GetHeight()) / 2);
693 memDC.SelectObject(wxNullBitmap);
703 float yTotal = yRange * ((float)
mZoomSlider->GetValue() / 100.0f);
705 int sTotal = yTotal * 100;
706 int sRange = yRange * 100;
708 mPanScroller->SetScrollbar(sPos, sTotal, sRange, sTotal);
710 float yMax =
mYMax - ((float)sPos / 100);
711 float yMin = yMax - yTotal;
728 vRuler->SetMinSize(wxSize(w2,h));
744 int width = r.width - 2;
746 float xMin, xMax, xRatio, xStep;
751 xRatio = xMax / xMin;
754 xStep = pow(2.0f, (log(xRatio) / log(2.0f)) / width);
759 xStep = (xMax - xMin) / width;
766 xStep = (xMax - xMin) / width;
776 memDC.SetPen(wxPen(
theTheme.
Colour( clrHzPlot ), 1, wxPENSTYLE_SOLID));
778 memDC.SetPen(wxPen(
theTheme.
Colour( clrWavelengthPlot), 1, wxPENSTYLE_SOLID));
782 for (
int i = 0; i < width; i++) {
786 y =
mAnalyst->GetProcessedValue(xPos, xPos * xStep);
788 y =
mAnalyst->GetProcessedValue(xPos, xPos + xStep);
790 float ynorm = (y - yMin) / yTotal;
792 int lineheight = (int)(ynorm * (r.height - 1));
794 if (lineheight > r.height - 2)
795 lineheight = r.height - 2;
798 AColor::Line(memDC, r.x + 1 + i, r.y + r.height - 1 - lineheight,
799 r.x + 1 + i, r.y + r.height - 1);
808 memDC.SetPen(*wxBLACK_PEN);
809 memDC.SetBrush(*wxTRANSPARENT_BRUSH);
810 memDC.DrawRectangle(r);
818 memDC.SelectObject( wxNullBitmap );
826 if (event.Moving() && (event.m_x !=
mMouseX || event.m_y !=
mMouseY)) {
869 mSizeChoice->GetStringSelection().ToLong(&windowSize);
888 wxPaintDC dc( (wxWindow *) event.GetEventObject() );
890 dc.DrawBitmap( *
mBitmap, 0, 0,
true );
899 int width = r.width - 2;
901 float xMin, xMax, xRatio, xStep;
906 xRatio = xMax / xMin;
908 xStep = pow(2.0f, (log(xRatio) / log(2.0f)) / width);
910 xStep = (xMax - xMin) / width;
914 xStep = (xMax - xMin) / width;
922 xPos = xMin * pow(xStep,
mMouseX - (r.x + 1));
924 xPos = xMin + xStep * (
mMouseX - (r.x + 1));
927 float bestpeak =
mAnalyst->FindPeak(xPos, &bestValue);
931 px = (int)(log(bestpeak / xMin) / log(xStep));
933 px = (int)((bestpeak - xMin) * width / (xMax - xMin));
935 dc.SetPen(wxPen(wxColour(255, 32, 32), 1, wxPENSTYLE_SOLID));
936 AColor::Line(dc, r.x + 1 + px, r.y, r.x + 1 + px, r.y + r.height);
943 xPos = xMin * pow(xStep,
mMouseX - (r.x + 1));
944 value =
mAnalyst->GetProcessedValue(xPos, xPos * xStep);
946 xPos = xMin + xStep * (
mMouseX - (r.x + 1));
947 value =
mAnalyst->GetProcessedValue(xPos, xPos + xStep);
957 cursor =
XO(
"%d Hz (%s) = %d dB")
958 .Format( (
int)(xPos + 0.5), xp, (
int)(value + 0.5));
960 peak =
XO(
"%d Hz (%s) = %.1f dB")
961 .Format( (
int)(bestpeak + 0.5), pp, bestValue );
962 }
else if (xPos > 0.0 && bestpeak > 0.0) {
967 cursor =
XO(
"%.4f sec (%d Hz) (%s) = %f")
968 .Format( xPos, (
int)(1.0 / xPos + 0.5), xp, value );
971 peak =
XO(
"%.4f sec (%d Hz) (%s) = %.3f")
972 .Format( bestpeak, (
int)(1.0 / bestpeak + 0.5), pp, bestValue );
984 dc.SetPen(*wxBLACK_PEN);
985 dc.SetBrush(*wxTRANSPARENT_BRUSH);
997 gPrefs->Write(wxT(
"/FrequencyPlotDialog/SizeChoice"),
mSizeChoice->GetSelection());
998 gPrefs->Write(wxT(
"/FrequencyPlotDialog/AlgChoice"),
mAlgChoice->GetSelection());
999 gPrefs->Write(wxT(
"/FrequencyPlotDialog/FuncChoice"),
mFuncChoice->GetSelection());
1000 gPrefs->Write(wxT(
"/FrequencyPlotDialog/AxisChoice"),
mAxisChoice->GetSelection());
1008 wxCommandEvent e(EVT_FREQWINDOW_RECALC, wxID_ANY);
1009 GetEventHandler()->AddPendingEvent(e);
1023 wxWindow *hadFocus = FindFocus();
1029 std::optional<wxWindowDisabler> blocker;
1031 blocker.emplace(
this);
1039 hadFocus->SetFocus();
1059 wxString fName =
_(
"spectrum.txt");
1061 fName =
SelectFile(FileNames::Operation::Export,
1062 XO(
"Export Spectral Data As:"),
1067 wxFD_SAVE | wxRESIZE_BORDER,
1073 wxFFileOutputStream ffStream{ fName };
1074 if (!ffStream.IsOk()) {
1079 wxTextOutputStream ss(ffStream);
1081 const int processedSize =
mAnalyst->GetProcessedSize();
1082 const float *
const processed =
mAnalyst->GetProcessed();
1085 <<
XO(
"Frequency (Hz)\tLevel (dB)") <<
'\n';
1086 for (
int i = 1; i < processedSize; i++)
1088 << wxString::Format(wxT(
"%f\t%f\n"),
1093 <<
XO(
"Lag (seconds)\tFrequency (Hz)\tLevel") <<
'\n';
1094 for (
int i = 1; i < processedSize; i++)
1096 << wxString::Format(wxT(
"%f\t%f\t%f\n"),
1124 bool shown = IsShown();
1131 auto sizeChoice =
mSizeChoice->GetStringSelection();
1146 long windowSize = 0;
1147 sizeChoice.ToLong(&windowSize);
1165BEGIN_EVENT_TABLE(
FreqPlot, wxWindow)
1172: wxWindow(parent, winid)
1218 auto &project = context.
project;
1225 freqWindow->
Show(
true);
1226 freqWindow->Raise();
1227 freqWindow->SetFocus();
1243 Command( wxT(
"PlotSpectrum"),
XXO(
"Plot Spectrum..."),
1244 &Handler::OnPlotSpectrum,
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
wxEvtHandler CommandHandlerObject
const ReservedCommandFlag & AudioIONotBusyFlag()
const ReservedCommandFlag & TimeSelectedFlag()
const ReservedCommandFlag & WaveTracksSelectedFlag()
IntSetting DecibelScaleCutoff
Negation of this value is the lowest dB level that should be shown in dB scales.
EVT_BUTTON(wxID_NO, DependencyDialog::OnNo) EVT_BUTTON(wxID_YES
const TranslatableString WindowFuncName(int whichFunction)
#define FrequencyAnalysisTitle
static const char * ZoomOut[]
#define FREQ_WINDOW_HEIGHT
DEFINE_EVENT_TYPE(EVT_FREQWINDOW_RECALC)
static const char * ZoomIn[]
EVT_COMMAND(wxID_ANY, EVT_FREQUENCYTEXTCTRL_UPDATED, LabelDialog::OnFreqUpdate) LabelDialog
TranslatableString PitchName_Absolute(const double dMIDInote, const PitchNameChoice choice)
double FreqToMIDInote(const double freq)
AUDACITY_DLL_API AttachedWindows & GetAttachedWindows(AudacityProject &project)
accessors for certain important windows associated with each project
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)
TranslatableString Verbatim(wxString str)
Require calls to the one-argument constructor to go through this distinct global function name.
std::vector< TranslatableString > TranslatableStrings
static void Line(wxDC &dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Subclass & Get(const RegisteredFactory &key)
Get reference to an attachment, creating on demand if not present, down-cast it to Subclass.
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
AudacityProject & project
void RegisterLastAnalyzer(const CommandContext &context)
static CommandManager & Get(AudacityProject &project)
virtual bool Flush(bool bCurrentOnly=false) wxOVERRIDE
FILES_API const FileType AllFiles
FILES_API const FileType TextFiles
Works with FrequencyPlotDialog to display a spectrum plot of the waveform. This class actually does t...
void OnErase(wxEraseEvent &event)
bool AcceptsFocus() const
void OnMouseEvent(wxMouseEvent &event)
void OnPaint(wxPaintEvent &event)
FrequencyPlotDialog * freqWindow
Displays a spectrum plot of the waveform. Has options for selecting parameters of the plot.
std::unique_ptr< wxCursor > mArrowCursor
std::unique_ptr< wxBitmap > mBitmap
void OnGetURL(wxCommandEvent &event)
void OnAlgChoice(wxCommandEvent &event)
void OnPanScroller(wxScrollEvent &event)
void OnZoomSlider(wxCommandEvent &event)
void OnAxisChoice(wxCommandEvent &event)
std::unique_ptr< wxCursor > mCrossCursor
void OnRecalc(wxCommandEvent &event)
SpectrumAnalyst::Algorithm mAlg
virtual ~FrequencyPlotDialog()
std::unique_ptr< SpectrumAnalyst > mAnalyst
void OnFuncChoice(wxCommandEvent &event)
void OnCloseButton(wxCommandEvent &event)
void UpdatePrefs() override
static const int fontSize
void OnReplot(wxCommandEvent &event)
void OnCloseWindow(wxCloseEvent &event)
void OnExport(wxCommandEvent &event)
void PlotPaint(wxPaintEvent &event)
void OnSize(wxSizeEvent &event)
void OnGridOnOff(wxCommandEvent &event)
bool Show(bool show=true) override
void OnSizeChoice(wxCommandEvent &event)
void DrawBackground(wxMemoryDC &dc)
wxScrollBar * mPanScroller
void PlotMouseEvent(wxMouseEvent &event)
static result_type Call(Arguments &&...arguments)
Null check of the installed function is done for you.
static void ShowHelp(wxWindow *parent, const FilePath &localFileName, const URLString &remoteURL, bool bModal=false, bool alwaysDefaultBrowser=false)
static ProjectWindow & Get(AudacityProject &project)
void DrawGrid(wxDC &dc, int length, bool minor=true, bool major=true, int xOffset=0, int yOffset=0) const
void GetMaxSize(wxCoord *width, wxCoord *height)
void SetUnits(const TranslatableString &units)
void SetRange(double min, double max)
void SetFormat(RulerFormat format)
RulerPanel class allows you to work with a Ruler like any other wxWindow.
std::pair< double, double > Range
bool Read(T *pVar) const
overload of Read returning a boolean that is true if the value was previously defined */
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
wxColour & Colour(int iIndex)
static TrackList & Get(AudacityProject &project)
auto Selected() -> TrackIterRange< TrackType >
Holds a msgid for the translation catalog; may also bind format arguments.
wxString Translation() const
NotifyingSelectedRegion selectedRegion
static ViewInfo & Get(AudacityProject &project)
A Track that contains audio waveform data.
An alternative to using wxWindowAccessible, which in wxWidgets 3.1.1 contained GetParent() which was ...
void SetTitle(const TranslatableString &title)
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
CommandHandlerObject & findCommandHandler(AudacityProject &)
AttachedWindows::RegisteredFactory sFrequencyWindowKey
Options & LabelEdges(bool l)
void OnPlotSpectrum(const CommandContext &context)