42#include <wx/checkbox.h>
44#include <wx/dcclient.h>
45#include <wx/dcmemory.h>
49#include <wx/scrolbar.h>
51#include <wx/statbmp.h>
52#include <wx/stattext.h>
53#include <wx/statusbr.h>
55#include <wx/textctrl.h>
56#include <wx/textfile.h>
58#include <wx/wfstream.h>
59#include <wx/txtstrm.h>
91#if wxUSE_ACCESSIBILITY
95#define FrequencyAnalysisTitle XO("Frequency Analysis")
115#define FREQ_WINDOW_WIDTH 480
116#define FREQ_WINDOW_HEIGHT 330
192 parent,
id,
title, pos, wxDefaultSize,
193 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxMAXIMIZE_BOX)
213 XO(
"Standard Autocorrelation") ,
214 XO(
"Cuberoot Autocorrelation") ,
215 XO(
"Enhanced Autocorrelation") ,
239 funcChoices.push_back(
247 XO(
"Linear frequency") ,
248 XO(
"Log frequency") ,
251 mFreqFont = wxFont(
fontSize, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
252 mArrowCursor = std::make_unique<wxCursor>(wxCURSOR_ARROW);
253 mCrossCursor = std::make_unique<wxCursor>(wxCURSOR_CROSS);
257 sizeChoices[
mSize].MSGID().GET().ToLong(&
size);
270 S.SetSizerProportion(1);
271 S.StartMultiColumn(3, wxEXPAND);
280 S.StartVerticalLay(2);
283 S.GetParent(), wxID_ANY, wxVERTICAL,
293 S.AddSpace(wxDefaultCoord, 1);
295 .Position(wxALIGN_RIGHT | wxALIGN_TOP)
297 S.AddSpace(wxDefaultCoord, 1);
307 S.StartHorizontalLay(wxEXPAND, 0);
309 S.StartVerticalLay();
312 wxDefaultPosition, wxDefaultSize, wxSB_VERTICAL);
313#if wxUSE_ACCESSIBILITY
320 .Position( wxALIGN_LEFT | wxTOP)
325 S.StartVerticalLay();
327 wxStaticBitmap *zi =
safenew wxStaticBitmap(
S.GetParent(), wxID_ANY, wxBitmap(
ZoomIn));
328 S.Position(wxALIGN_CENTER)
334 wxDefaultPosition, wxDefaultSize, wxSL_VERTICAL);
338 .Position(wxALIGN_CENTER_HORIZONTAL)
340#if wxUSE_ACCESSIBILITY
347 wxStaticBitmap *zo =
safenew wxStaticBitmap(
S.GetParent(), wxID_ANY, wxBitmap(
ZoomOut));
348 S.Position(wxALIGN_CENTER)
353 S.AddSpace(5, wxDefaultCoord);
355 S.EndHorizontalLay();
363 S.StartHorizontalLay(wxEXPAND, 0);
366 S.GetParent(), wxID_ANY, wxHORIZONTAL,
378 S.AddSpace(1, wxDefaultCoord);
380 .Position(wxALIGN_LEFT | wxALIGN_TOP)
382 S.AddSpace(1, wxDefaultCoord);
384 S.EndHorizontalLay();
402 S.StartHorizontalLay(wxEXPAND);
404 S.SetSizerProportion(1);
405 S.StartMultiColumn(6);
409 S.AddPrompt(
XXO(
"Cursor:"));
412 .AddTextBox( {},
wxT(
""), 10);
414 S.AddPrompt(
XXO(
"Peak:"));
417 .AddTextBox( {},
wxT(
""), 10);
424 S.EndHorizontalLay();
437 S.SetSizerProportion(0);
438 S.StartMultiColumn(9, wxALIGN_CENTER);
447 .MinSize( { wxDefaultCoord, wxDefaultCoord } )
448 .AddChoice(
XXO(
"&Algorithm:"), algChoices,
mAlg);
453 .MinSize( { wxDefaultCoord, wxDefaultCoord } )
454 .AddChoice(
XXO(
"&Size:"), sizeChoices,
mSize);
469 .MinSize( { wxDefaultCoord, wxDefaultCoord } )
470 .AddChoice(
XXO(
"&Function:"), funcChoices,
mFunc);
476 .MinSize( { wxDefaultCoord, wxDefaultCoord } )
477 .AddChoice(
XXO(
"&Axis:"), axisChoices,
mAxis);
511 mCloseButton =
static_cast<wxButton*
>(FindWindowById( wxID_CANCEL ));
519 SetMinSize(GetSize());
521#if defined(__WXGTK__)
552 bool shown = IsShown();
593 dc.SetBackground(wxBrush(wxColour(254, 254, 254)));
596 dc.SetPen(*wxBLACK_PEN);
597 dc.SetBrush(*wxWHITE_BRUSH);
605 if (!
mData || mDataLen < mWindowSize || mAnalyst->GetProcessedSize() == 0) {
617 wxString msg =
_(
"Not enough data selected.");
618 wxSize sz = memDC.GetTextExtent(msg);
620 (
mPlotRect.GetWidth() - sz.GetWidth()) / 2,
621 (
mPlotRect.GetHeight() - sz.GetHeight()) / 2);
624 memDC.SelectObject(wxNullBitmap);
634 float yTotal = yRange * ((float)
mZoomSlider->GetValue() / 100.0f);
636 int sTotal = yTotal * 100;
637 int sRange = yRange * 100;
639 mPanScroller->SetScrollbar(sPos, sTotal, sRange, sTotal);
641 float yMax =
mYMax - ((float)sPos / 100);
642 float yMin = yMax - yTotal;
659 vRuler->SetMinSize(wxSize(w2,h));
675 int width = r.width - 2;
677 float xMin, xMax, xRatio, xStep;
682 xRatio = xMax / xMin;
685 xStep = pow(2.0f, (log(xRatio) / log(2.0f)) / width);
690 xStep = (xMax - xMin) / width;
697 xStep = (xMax - xMin) / width;
707 memDC.SetPen(wxPen(
theTheme.
Colour( clrHzPlot ), 1, wxPENSTYLE_SOLID));
709 memDC.SetPen(wxPen(
theTheme.
Colour( clrWavelengthPlot), 1, wxPENSTYLE_SOLID));
713 for (
int i = 0; i < width; i++) {
717 y =
mAnalyst->GetProcessedValue(xPos, xPos * xStep);
719 y =
mAnalyst->GetProcessedValue(xPos, xPos + xStep);
721 float ynorm = (y - yMin) / yTotal;
723 int lineheight = (int)(ynorm * (r.height - 1));
725 if (lineheight > r.height - 2)
726 lineheight = r.height - 2;
729 AColor::Line(memDC, r.x + 1 + i, r.y + r.height - 1 - lineheight,
730 r.x + 1 + i, r.y + r.height - 1);
739 memDC.SetPen(*wxBLACK_PEN);
740 memDC.SetBrush(*wxTRANSPARENT_BRUSH);
741 memDC.DrawRectangle(r);
749 memDC.SelectObject( wxNullBitmap );
757 if (event.Moving() && (event.m_x !=
mMouseX || event.m_y !=
mMouseY)) {
800 mSizeChoice->GetStringSelection().ToLong(&windowSize);
819 wxPaintDC dc( (wxWindow *) event.GetEventObject() );
821 dc.DrawBitmap( *
mBitmap, 0, 0,
true );
830 int width = r.width - 2;
832 float xMin, xMax, xRatio, xStep;
837 xRatio = xMax / xMin;
839 xStep = pow(2.0f, (log(xRatio) / log(2.0f)) / width);
841 xStep = (xMax - xMin) / width;
845 xStep = (xMax - xMin) / width;
853 xPos = xMin * pow(xStep,
mMouseX - (r.x + 1));
855 xPos = xMin + xStep * (
mMouseX - (r.x + 1));
858 float bestpeak =
mAnalyst->FindPeak(xPos, &bestValue);
862 px = (int)(log(bestpeak / xMin) / log(xStep));
864 px = (int)((bestpeak - xMin) * width / (xMax - xMin));
866 dc.SetPen(wxPen(wxColour(255, 32, 32), 1, wxPENSTYLE_SOLID));
867 AColor::Line(dc, r.x + 1 + px, r.y, r.x + 1 + px, r.y + r.height);
874 xPos = xMin * pow(xStep,
mMouseX - (r.x + 1));
875 value =
mAnalyst->GetProcessedValue(xPos, xPos * xStep);
877 xPos = xMin + xStep * (
mMouseX - (r.x + 1));
878 value =
mAnalyst->GetProcessedValue(xPos, xPos + xStep);
888 cursor =
XO(
"%d Hz (%s) = %d dB")
889 .Format( (
int)(xPos + 0.5), xp, (
int)(value + 0.5));
891 peak =
XO(
"%d Hz (%s) = %.1f dB")
892 .Format( (
int)(bestpeak + 0.5), pp, bestValue );
893 }
else if (xPos > 0.0 && bestpeak > 0.0) {
898 cursor =
XO(
"%.4f sec (%d Hz) (%s) = %f")
899 .Format( xPos, (
int)(1.0 / xPos + 0.5), xp, value );
902 peak =
XO(
"%.4f sec (%d Hz) (%s) = %.3f")
903 .Format( bestpeak, (
int)(1.0 / bestpeak + 0.5), pp, bestValue );
915 dc.SetPen(*wxBLACK_PEN);
916 dc.SetBrush(*wxTRANSPARENT_BRUSH);
939 wxCommandEvent e(EVT_FREQWINDOW_RECALC, wxID_ANY);
940 GetEventHandler()->AddPendingEvent(e);
960 std::optional<wxWindowDisabler> blocker;
962 blocker.emplace(
this);
966 auto progress = [&](
long long num,
long long den) {
981 hadFocus->SetFocus();
1001 wxString fName =
_(
"spectrum.txt");
1003 fName =
SelectFile(FileNames::Operation::Export,
1004 XO(
"Export Spectral Data As:"),
1009 wxFD_SAVE | wxRESIZE_BORDER,
1015 wxFFileOutputStream ffStream{ fName };
1016 if (!ffStream.IsOk()) {
1021 wxTextOutputStream ss(ffStream);
1023 const int processedSize =
mAnalyst->GetProcessedSize();
1024 const float *
const processed =
mAnalyst->GetProcessed();
1027 <<
XO(
"Frequency (Hz)\tLevel (dB)") <<
'\n';
1028 for (
int i = 1; i < processedSize; i++)
1030 << wxString::Format(
wxT(
"%f\t%f\n"),
1035 <<
XO(
"Lag (seconds)\tFrequency (Hz)\tLevel") <<
'\n';
1036 for (
int i = 1; i < processedSize; i++)
1038 << wxString::Format(
wxT(
"%f\t%f\t%f\n"),
1066 bool shown = IsShown();
1073 auto sizeChoice =
mSizeChoice->GetStringSelection();
1088 long windowSize = 0;
1089 sizeChoice.ToLong(&windowSize);
1107BEGIN_EVENT_TABLE(
FreqPlot, wxWindow)
1114: wxWindow(parent, winid)
1164 freqWindow->
Show(
true);
1165 freqWindow->Raise();
1166 freqWindow->SetFocus();
1176 wxT(
"Analyze/Analyzers/Windows")
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
Toolkit-neutral facade for basic user interface services.
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[]
XXO("&Cut/Copy/Paste Toolbar")
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::BasicSettings * gPrefs
AUDACITY_DLL_API wxFrame & GetProjectFrame(AudacityProject &project)
Get the top-level window associated with the project (as a wxFrame only, when you do not need to use ...
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)
FILES_API const FileType AllFiles
FILES_API const FileType TextFiles
void SetRange(int range, int bar=12, int gap=3)
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)
virtual ~FrequencyPlotDialog()
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 void ShowHelp(wxWindow *parent, const FilePath &localFileName, const URLString &remoteURL, bool bModal=false, bool alwaysDefaultBrowser=false)
static const LinearUpdater & Instance()
static const LogarithmicUpdater & Instance()
std::unique_ptr< SpectrumAnalyst > mAnalyst
SpectrumAnalyst::Algorithm mAlg
Generates classes whose instances register items at construction.
void DrawGrid(wxDC &dc, int length, bool minor=true, bool major=true, int xOffset=0, int yOffset=0) const
void SetUpdater(const RulerUpdater *pUpdater)
void SetFormat(const RulerFormat *pFormat)
void GetMaxSize(wxCoord *width, wxCoord *height)
void SetUnits(const TranslatableString &units)
void SetRange(double min, double max)
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)
Holds a msgid for the translation catalog; may also bind format arguments.
wxString Translation() const
An alternative to using wxWindowAccessible, which in wxWidgets 3.1.1 contained GetParent() which was ...
virtual bool Flush() noexcept=0
virtual bool Write(const wxString &key, bool value)=0
void SetTitle(const TranslatableString &title)
std::unique_ptr< WindowPlacement > FindFocus()
Find the window that is accepting keyboard input, if any.
IMPORT_EXPORT_API ExportResult Show(ExportTask exportTask)
void OnPlotSpectrum(const CommandContext &context)
AttachedWindows::RegisteredFactory sFrequencyWindowKey
Options & LabelEdges(bool l)