42#include <wx/checkbox.h>
44#include <wx/dcclient.h>
45#include <wx/dcmemory.h>
48#include <wx/scrolbar.h>
50#include <wx/statbmp.h>
51#include <wx/stattext.h>
52#include <wx/statusbr.h>
54#include <wx/textctrl.h>
55#include <wx/textfile.h>
57#include <wx/wfstream.h>
58#include <wx/txtstrm.h>
89#if wxUSE_ACCESSIBILITY
93#define FrequencyAnalysisTitle XO("Frequency Analysis")
113#define FREQ_WINDOW_WIDTH 480
114#define FREQ_WINDOW_HEIGHT 330
190 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxMAXIMIZE_BOX),
192, mAnalyst(std::make_unique<SpectrumAnalyst>())
201 gPrefs->Read(
wxT(
"/FrequencyPlotDialog/DrawGrid"), &mDrawGrid,
true);
202 gPrefs->Read(
wxT(
"/FrequencyPlotDialog/SizeChoice"), &mSize, 3);
205 gPrefs->Read(
wxT(
"/FrequencyPlotDialog/AlgChoice"), &alg, 0);
208 gPrefs->Read(
wxT(
"/FrequencyPlotDialog/FuncChoice"), &mFunc, 3);
209 gPrefs->Read(
wxT(
"/FrequencyPlotDialog/AxisChoice"), &mAxis, 1);
224 XO(
"Standard Autocorrelation") ,
225 XO(
"Cuberoot Autocorrelation") ,
226 XO(
"Enhanced Autocorrelation") ,
250 funcChoices.push_back(
258 XO(
"Linear frequency") ,
259 XO(
"Log frequency") ,
262 mFreqFont = wxFont(
fontSize, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
263 mArrowCursor = std::make_unique<wxCursor>(wxCURSOR_ARROW);
264 mCrossCursor = std::make_unique<wxCursor>(wxCURSOR_CROSS);
268 sizeChoices[
mSize].MSGID().GET().ToLong(&
size);
281 S.SetSizerProportion(1);
282 S.StartMultiColumn(3, wxEXPAND);
291 S.StartVerticalLay(2);
294 S.GetParent(), wxID_ANY, wxVERTICAL,
304 S.AddSpace(wxDefaultCoord, 1);
306 .Position(wxALIGN_RIGHT | wxALIGN_TOP)
308 S.AddSpace(wxDefaultCoord, 1);
318 S.StartHorizontalLay(wxEXPAND, 0);
320 S.StartVerticalLay();
323 wxDefaultPosition, wxDefaultSize, wxSB_VERTICAL);
324#if wxUSE_ACCESSIBILITY
331 .Position( wxALIGN_LEFT | wxTOP)
336 S.StartVerticalLay();
338 wxStaticBitmap *zi =
safenew wxStaticBitmap(
S.GetParent(), wxID_ANY, wxBitmap(
ZoomIn));
339 S.Position(wxALIGN_CENTER)
345 wxDefaultPosition, wxDefaultSize, wxSL_VERTICAL);
349 .Position(wxALIGN_CENTER_HORIZONTAL)
351#if wxUSE_ACCESSIBILITY
358 wxStaticBitmap *zo =
safenew wxStaticBitmap(
S.GetParent(), wxID_ANY, wxBitmap(
ZoomOut));
359 S.Position(wxALIGN_CENTER)
364 S.AddSpace(5, wxDefaultCoord);
366 S.EndHorizontalLay();
374 S.StartHorizontalLay(wxEXPAND, 0);
377 S.GetParent(), wxID_ANY, wxHORIZONTAL,
389 S.AddSpace(1, wxDefaultCoord);
391 .Position(wxALIGN_LEFT | wxALIGN_TOP)
393 S.AddSpace(1, wxDefaultCoord);
395 S.EndHorizontalLay();
413 S.StartHorizontalLay(wxEXPAND);
415 S.SetSizerProportion(1);
416 S.StartMultiColumn(6);
420 S.AddPrompt(
XXO(
"Cursor:"));
423 .AddTextBox( {},
wxT(
""), 10);
425 S.AddPrompt(
XXO(
"Peak:"));
428 .AddTextBox( {},
wxT(
""), 10);
435 S.EndHorizontalLay();
448 S.SetSizerProportion(0);
449 S.StartMultiColumn(9, wxALIGN_CENTER);
458 .MinSize( { wxDefaultCoord, wxDefaultCoord } )
459 .AddChoice(
XXO(
"&Algorithm:"), algChoices,
mAlg);
464 .MinSize( { wxDefaultCoord, wxDefaultCoord } )
465 .AddChoice(
XXO(
"&Size:"), sizeChoices,
mSize);
480 .MinSize( { wxDefaultCoord, wxDefaultCoord } )
481 .AddChoice(
XXO(
"&Function:"), funcChoices,
mFunc);
487 .MinSize( { wxDefaultCoord, wxDefaultCoord } )
488 .AddChoice(
XXO(
"&Axis:"), axisChoices,
mAxis);
522 mCloseButton =
static_cast<wxButton*
>(FindWindowById( wxID_CANCEL ));
530 SetMinSize(GetSize());
532#if defined(__WXGTK__)
563 bool shown = IsShown();
577 bool res = wxDialogWrapper::Show(show);
588 bool warning =
false;
592 mRate = track->GetRate();
593 auto start = track->TimeToLongSamples(selectedRegion.t0());
594 auto end = track->TimeToLongSamples(selectedRegion.t1());
595 auto dataLen =
end - start;
598 auto maxDataLen = size_t(2) << 26;
599 if (dataLen > maxDataLen) {
612 if (track->GetRate() !=
mRate) {
615"To plot the spectrum, all selected tracks must be the same sample rate.") );
620 auto start = track->TimeToLongSamples(selectedRegion.t0());
623 track->GetFloats(buffer2.get(), start,
mDataLen,
625 for (
size_t i = 0; i <
mDataLen; i++)
626 mData[i] += buffer2[i];
636"Too much audio was selected. Only the first %.1f seconds of audio will be analyzed.")
663 dc.SetBackground(wxBrush(wxColour(254, 254, 254)));
666 dc.SetPen(*wxBLACK_PEN);
667 dc.SetBrush(*wxWHITE_BRUSH);
675 if (!
mData || mDataLen < mWindowSize || mAnalyst->GetProcessedSize() == 0) {
687 wxString msg =
_(
"Not enough data selected.");
688 wxSize sz = memDC.GetTextExtent(msg);
690 (
mPlotRect.GetWidth() - sz.GetWidth()) / 2,
691 (
mPlotRect.GetHeight() - sz.GetHeight()) / 2);
694 memDC.SelectObject(wxNullBitmap);
704 float yTotal = yRange * ((float)
mZoomSlider->GetValue() / 100.0f);
706 int sTotal = yTotal * 100;
707 int sRange = yRange * 100;
709 mPanScroller->SetScrollbar(sPos, sTotal, sRange, sTotal);
711 float yMax =
mYMax - ((float)sPos / 100);
712 float yMin = yMax - yTotal;
729 vRuler->SetMinSize(wxSize(w2,h));
745 int width = r.width - 2;
747 float xMin, xMax, xRatio, xStep;
752 xRatio = xMax / xMin;
755 xStep = pow(2.0f, (log(xRatio) / log(2.0f)) / width);
760 xStep = (xMax - xMin) / width;
767 xStep = (xMax - xMin) / width;
777 memDC.SetPen(wxPen(
theTheme.
Colour( clrHzPlot ), 1, wxPENSTYLE_SOLID));
779 memDC.SetPen(wxPen(
theTheme.
Colour( clrWavelengthPlot), 1, wxPENSTYLE_SOLID));
783 for (
int i = 0; i < width; i++) {
787 y =
mAnalyst->GetProcessedValue(xPos, xPos * xStep);
789 y =
mAnalyst->GetProcessedValue(xPos, xPos + xStep);
791 float ynorm = (y - yMin) / yTotal;
793 int lineheight = (int)(ynorm * (r.height - 1));
795 if (lineheight > r.height - 2)
796 lineheight = r.height - 2;
799 AColor::Line(memDC, r.x + 1 + i, r.y + r.height - 1 - lineheight,
800 r.x + 1 + i, r.y + r.height - 1);
809 memDC.SetPen(*wxBLACK_PEN);
810 memDC.SetBrush(*wxTRANSPARENT_BRUSH);
811 memDC.DrawRectangle(r);
819 memDC.SelectObject( wxNullBitmap );
827 if (event.Moving() && (event.m_x !=
mMouseX || event.m_y !=
mMouseY)) {
870 mSizeChoice->GetStringSelection().ToLong(&windowSize);
889 wxPaintDC dc( (wxWindow *) event.GetEventObject() );
891 dc.DrawBitmap( *
mBitmap, 0, 0,
true );
900 int width = r.width - 2;
902 float xMin, xMax, xRatio, xStep;
907 xRatio = xMax / xMin;
909 xStep = pow(2.0f, (log(xRatio) / log(2.0f)) / width);
911 xStep = (xMax - xMin) / width;
915 xStep = (xMax - xMin) / width;
923 xPos = xMin * pow(xStep,
mMouseX - (r.x + 1));
925 xPos = xMin + xStep * (
mMouseX - (r.x + 1));
928 float bestpeak =
mAnalyst->FindPeak(xPos, &bestValue);
932 px = (int)(log(bestpeak / xMin) / log(xStep));
934 px = (int)((bestpeak - xMin) * width / (xMax - xMin));
936 dc.SetPen(wxPen(wxColour(255, 32, 32), 1, wxPENSTYLE_SOLID));
937 AColor::Line(dc, r.x + 1 + px, r.y, r.x + 1 + px, r.y + r.height);
944 xPos = xMin * pow(xStep,
mMouseX - (r.x + 1));
945 value =
mAnalyst->GetProcessedValue(xPos, xPos * xStep);
947 xPos = xMin + xStep * (
mMouseX - (r.x + 1));
948 value =
mAnalyst->GetProcessedValue(xPos, xPos + xStep);
958 cursor =
XO(
"%d Hz (%s) = %d dB")
959 .Format( (
int)(xPos + 0.5), xp, (
int)(value + 0.5));
961 peak =
XO(
"%d Hz (%s) = %.1f dB")
962 .Format( (
int)(bestpeak + 0.5), pp, bestValue );
963 }
else if (xPos > 0.0 && bestpeak > 0.0) {
968 cursor =
XO(
"%.4f sec (%d Hz) (%s) = %f")
969 .Format( xPos, (
int)(1.0 / xPos + 0.5), xp, value );
972 peak =
XO(
"%.4f sec (%d Hz) (%s) = %.3f")
973 .Format( bestpeak, (
int)(1.0 / bestpeak + 0.5), pp, bestValue );
985 dc.SetPen(*wxBLACK_PEN);
986 dc.SetBrush(*wxTRANSPARENT_BRUSH);
1009 wxCommandEvent e(EVT_FREQWINDOW_RECALC, wxID_ANY);
1010 GetEventHandler()->AddPendingEvent(e);
1030 std::optional<wxWindowDisabler> blocker;
1032 blocker.emplace(
this);
1040 hadFocus->SetFocus();
1060 wxString fName =
_(
"spectrum.txt");
1062 fName =
SelectFile(FileNames::Operation::Export,
1063 XO(
"Export Spectral Data As:"),
1068 wxFD_SAVE | wxRESIZE_BORDER,
1074 wxFFileOutputStream ffStream{ fName };
1075 if (!ffStream.IsOk()) {
1080 wxTextOutputStream ss(ffStream);
1082 const int processedSize =
mAnalyst->GetProcessedSize();
1083 const float *
const processed =
mAnalyst->GetProcessed();
1086 <<
XO(
"Frequency (Hz)\tLevel (dB)") <<
'\n';
1087 for (
int i = 1; i < processedSize; i++)
1089 << wxString::Format(
wxT(
"%f\t%f\n"),
1094 <<
XO(
"Lag (seconds)\tFrequency (Hz)\tLevel") <<
'\n';
1095 for (
int i = 1; i < processedSize; i++)
1097 << wxString::Format(
wxT(
"%f\t%f\t%f\n"),
1125 bool shown = IsShown();
1132 auto sizeChoice =
mSizeChoice->GetStringSelection();
1147 long windowSize = 0;
1148 sizeChoice.ToLong(&windowSize);
1166BEGIN_EVENT_TABLE(
FreqPlot, wxWindow)
1173: wxWindow(parent, winid)
1218 auto &project = context.
project;
1225 freqWindow->
Show(
true);
1226 freqWindow->Raise();
1227 freqWindow->SetFocus();
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
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_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 const LinearUpdater & Instance()
static const LogarithmicUpdater & Instance()
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 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)
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)
std::unique_ptr< WindowPlacement > FindFocus()
Find the window that is accepting keyboard input, if any.
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
void OnPlotSpectrum(const CommandContext &context)
AttachedWindows::RegisteredFactory sFrequencyWindowKey
Options & LabelEdges(bool l)