Audacity  2.3.1
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
FreqWindow Class Referencefinal

Displays a spectrum plot of the waveform. Has options for selecting parameters of the plot. More...

#include <FreqWindow.h>

Inheritance diagram for FreqWindow:
wxDialogWrapper wxTabTraversalWrapper< wxDialog >

Public Member Functions

 FreqWindow (wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &pos)
 
virtual ~FreqWindow ()
 
bool Show (bool show=true) override
 
- Public Member Functions inherited from wxDialogWrapper
 wxDialogWrapper ()
 
 wxDialogWrapper (wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE, const wxString &name=_("Dialog"))
 
bool Create (wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE, const wxString &name=_("Dialog"))
 
- Public Member Functions inherited from wxTabTraversalWrapper< wxDialog >
 wxTabTraversalWrapper (Args &&...args)
 
 wxTabTraversalWrapper (const wxTabTraversalWrapper &)=delete
 
 wxTabTraversalWrapper (wxTabTraversalWrapper &&)=delete
 
wxTabTraversalWrapperoperator= (const wxTabTraversalWrapper &)=delete
 
wxTabTraversalWrapperoperator= (wxTabTraversalWrapper &&)=delete
 

Private Member Functions

void 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)
 

Private Attributes

bool mDrawGrid
 
int mSize
 
SpectrumAnalyst::Algorithm mAlg
 
int mFunc
 
int mAxis
 
int dBRange
 
AudacityProjectp
 
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 = 10
 

Friends

class FreqPlot
 

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 127 of file FreqWindow.h.

Constructor & Destructor Documentation

FreqWindow::FreqWindow ( wxWindow *  parent,
wxWindowID  id,
const wxString &  title,
const wxPoint &  pos 
)

Definition at line 196 of file FreqWindow.cpp.

References _(), ShuttleGuiBase::AddButton(), ShuttleGuiBase::AddCheckBox(), ShuttleGuiBase::AddChoice(), ShuttleGuiBase::AddPrompt(), ShuttleGui::AddSpace(), ShuttleGui::AddStandardButtons(), ShuttleGuiBase::AddTextBox(), ShuttleGuiBase::AddWindow(), ThemeBase::Colour(), dBRange, eCloseButton, eHelpButton, eIsCreating, ShuttleGuiBase::EndHorizontalLay(), ShuttleGuiBase::EndMultiColumn(), ShuttleGuiBase::EndVerticalLay(), ENV_DB_KEY, ENV_DB_RANGE, RulerPanel::Options::Flip(), fontSize, FREQ_WINDOW_HEIGHT, FreqAlgChoiceID, FreqAxisChoiceID, FreqExportButtonID, FreqFuncChoiceID, FreqPanScrollerID, FreqPlot, FreqSizeChoiceID, FreqZoomSliderID, GetActiveProject(), gPrefs, GridOnOffID, hRuler, ShuttleGui::Id(), RulerPanel::Options::LabelEdges(), Ruler::LinearDBFormat, RulerPanel::Options::Log(), mAlg, mAlgChoice, mArrowCursor, mAxis, mAxisChoice, mCloseButton, mCrossCursor, mCursorText, mDataLen, mDrawGrid, mExportButton, mFreqFont, mFreqPlot, mFunc, mFuncChoice, mGridOnOff, mLogAxis, mMouseX, mMouseY, mPanScroller, mPeakText, mProgress, mRate, mReplotButton, mSize, mSizeChoice, mWindowSize, mZoomSlider, NumWindowFuncs(), p, ShuttleGui::Prop(), Ruler::RealFormat, ReplotButtonID, safenew, ShuttleGuiBase::SetBorder(), ShuttleGuiBase::SetSizeHints(), ShuttleGuiBase::SetSizerProportion(), ShuttleGuiBase::SetStretchyCol(), ShuttleGuiBase::SetStretchyRow(), ShuttleGuiBase::SetStyle(), SpectrumAnalyst::Spectrum, ShuttleGuiBase::StartHorizontalLay(), ShuttleGuiBase::StartMultiColumn(), ShuttleGuiBase::StartVerticalLay(), theTheme, RulerPanel::Options::TickColour(), vRuler, WindowFuncName(), ZoomIn, and ZoomOut.

199 : wxDialogWrapper(parent, id, title, pos, wxDefaultSize,
200  wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxMAXIMIZE_BOX),
201  mAnalyst(std::make_unique<SpectrumAnalyst>())
202 {
203  SetName(GetTitle());
204 
205  mMouseX = 0;
206  mMouseY = 0;
207  mRate = 0;
208  mDataLen = 0;
209 
210  p = GetActiveProject();
211  if (!p)
212  return;
213 
214  wxArrayString algChoices;
215  algChoices.Add(_("Spectrum"));
216  algChoices.Add(_("Standard Autocorrelation"));
217  algChoices.Add(_("Cuberoot Autocorrelation"));
218  algChoices.Add(_("Enhanced Autocorrelation"));
219  /* i18n-hint: This is a technical term, derived from the word
220  * "spectrum". Do not translate it unless you are sure you
221  * know the correct technical word in your language. */
222  algChoices.Add(_("Cepstrum"));
223 
224  wxArrayString sizeChoices;
225  sizeChoices.Add(wxT("128"));
226  sizeChoices.Add(wxT("256"));
227  sizeChoices.Add(wxT("512"));
228  sizeChoices.Add(wxT("1024"));
229  sizeChoices.Add(wxT("2048"));
230  sizeChoices.Add(wxT("4096"));
231  sizeChoices.Add(wxT("8192"));
232  sizeChoices.Add(wxT("16384"));
233  sizeChoices.Add(wxT("32768"));
234  sizeChoices.Add(wxT("65536"));
235 
236  wxArrayString funcChoices;
237  for (int i = 0, cnt = NumWindowFuncs(); i < cnt; i++)
238  {
239  /* i18n-hint: This refers to a "window function",
240  * such as Hann or Rectangular, used in the
241  * Frequency analyze dialog box. */
242  funcChoices.Add(wxString::Format("%s window", WindowFuncName(i) ) );
243  }
244 
245  wxArrayString axisChoices;
246  axisChoices.Add(_("Linear frequency"));
247  axisChoices.Add(_("Log frequency"));
248 
249  mFreqFont = wxFont(fontSize, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
250  mArrowCursor = std::make_unique<wxCursor>(wxCURSOR_ARROW);
251  mCrossCursor = std::make_unique<wxCursor>(wxCURSOR_CROSS);
252 
253  gPrefs->Read(wxT("/FreqWindow/DrawGrid"), &mDrawGrid, true);
254 
255  long size;
256  gPrefs->Read(wxT("/FreqWindow/SizeChoice"), &mSize, 3);
257  sizeChoices[mSize].ToLong(&size);
258  mWindowSize = size;
259 
260  int alg;
261  gPrefs->Read(wxT("/FreqWindow/AlgChoice"), &alg, 0);
262  mAlg = static_cast<SpectrumAnalyst::Algorithm>(alg);
263 
264  gPrefs->Read(wxT("/FreqWindow/FuncChoice"), &mFunc, 3);
265  gPrefs->Read(wxT("/FreqWindow/AxisChoice"), &mAxis, 1);
267  if(dBRange < 90.)
268  dBRange = 90.;
269 
270  ShuttleGui S(this, eIsCreating);
271 
272  S.SetBorder(0);
273 
274  S.AddSpace(5);
275 
276  S.SetSizerProportion(1);
277  S.StartMultiColumn(3, wxEXPAND);
278  {
279  S.SetStretchyCol(1);
280  S.SetStretchyRow(0);
281 
282  // -------------------------------------------------------------------
283  // ROW 1: Freq response panel and sliders for vertical scale
284  // -------------------------------------------------------------------
285 
286  S.StartVerticalLay(2);
287  {
289  this, wxID_ANY, wxVERTICAL,
290  wxSize{ 100, 100 }, // Ruler can't handle small sizes
291  RulerPanel::Range{ 0.0, -dBRange },
293  _("dB"),
295  .LabelEdges(true)
296  .TickColour( theTheme.Colour( clrGraphLabels ) )
297  );
298 
299  S.AddSpace(wxDefaultCoord, 1);
300  S.Prop(1);
301  S.AddWindow(vRuler, wxALIGN_RIGHT | wxALIGN_TOP);
302  S.AddSpace(wxDefaultCoord, 1);
303  }
304  S.EndVerticalLay();
305 
306  mFreqPlot = safenew FreqPlot(this, wxID_ANY);
307  mFreqPlot->SetMinSize(wxSize(wxDefaultCoord, FREQ_WINDOW_HEIGHT));
308  S.Prop(1);
309  S.AddWindow(mFreqPlot, wxEXPAND);
310 
311  S.StartHorizontalLay(wxEXPAND, 0);
312  {
313  S.StartVerticalLay();
314  {
315  mPanScroller = safenew wxScrollBar(this, FreqPanScrollerID,
316  wxDefaultPosition, wxDefaultSize, wxSB_VERTICAL);
317 #if wxUSE_ACCESSIBILITY
318  // so that name can be set on a standard control
320 #endif
321  mPanScroller->SetName(_("Scroll"));
322  S.Prop(1);
323  S.AddWindow(mPanScroller, wxALIGN_LEFT | wxTOP);
324  }
325  S.EndVerticalLay();
326 
327  S.StartVerticalLay();
328  {
329  wxStaticBitmap *zi = safenew wxStaticBitmap(this, wxID_ANY, wxBitmap(ZoomIn));
330  S.AddWindow((wxWindow *) zi, wxALIGN_CENTER);
331 
332  S.AddSpace(5);
333 
334  mZoomSlider = safenew wxSlider(this, FreqZoomSliderID, 100, 1, 100,
335  wxDefaultPosition, wxDefaultSize, wxSL_VERTICAL);
336  S.Prop(1);
337  S.AddWindow(mZoomSlider, wxALIGN_CENTER_HORIZONTAL);
338 #if wxUSE_ACCESSIBILITY
339  // so that name can be set on a standard control
341 #endif
342  mZoomSlider->SetName(_("Zoom"));
343 
344  S.AddSpace(5);
345 
346  wxStaticBitmap *zo = safenew wxStaticBitmap(this, wxID_ANY, wxBitmap(ZoomOut));
347  S.AddWindow((wxWindow *) zo, wxALIGN_CENTER);
348  }
349  S.EndVerticalLay();
350 
351  S.AddSpace(5, wxDefaultCoord);
352  }
353  S.EndHorizontalLay();
354 
355  // -------------------------------------------------------------------
356  // ROW 2: Frequency ruler
357  // -------------------------------------------------------------------
358 
359  S.AddSpace(1);
360 
361  S.StartHorizontalLay(wxEXPAND, 0);
362  {
364  this, wxID_ANY, wxHORIZONTAL,
365  wxSize{ 100, 100 }, // Ruler can't handle small sizes
366  RulerPanel::Range{ 10, 20000 },
368  _("Hz"),
370  .Log(true)
371  .Flip(true)
372  .LabelEdges(true)
373  .TickColour( theTheme.Colour( clrGraphLabels ) )
374  );
375 
376  S.AddSpace(1, wxDefaultCoord);
377  S.Prop(1);
378  S.AddWindow(hRuler, wxALIGN_LEFT | wxALIGN_TOP);
379  S.AddSpace(1, wxDefaultCoord);
380  }
381  S.EndHorizontalLay();
382 
383  S.AddSpace(1);
384 
385  // -------------------------------------------------------------------
386  // ROW 3: Spacer
387  // -------------------------------------------------------------------
388  S.AddSpace(5);
389  S.AddSpace(5);
390  S.AddSpace(5);
391 
392  // -------------------------------------------------------------------
393  // ROW 4: Info
394  // -------------------------------------------------------------------
395 
396  S.AddSpace(1);
397 
398  S.StartHorizontalLay(wxEXPAND);
399  {
400  S.SetSizerProportion(1);
401  S.StartMultiColumn(6);
402  S.SetStretchyCol(1);
403  S.SetStretchyCol(3);
404  {
405  S.AddPrompt(_("Cursor:"));
406 
407  S.SetStyle(wxTE_READONLY);
408  mCursorText = S.AddTextBox( {}, wxT(""), 10);
409 
410  S.AddPrompt(_("Peak:"));
411 
412  S.SetStyle(wxTE_READONLY);
413  mPeakText = S.AddTextBox( {}, wxT(""), 10);
414  S.AddSpace(5);
415 
416  mGridOnOff = S.Id(GridOnOffID).AddCheckBox(_("&Grids"), wxT("false"));
417  mGridOnOff->SetValue(mDrawGrid);
418  }
419  S.EndMultiColumn();
420  }
421  S.EndHorizontalLay();
422 
423  S.AddSpace(1);
424  }
425  S.EndMultiColumn();
426 
427  // -------------------------------------------------------------------
428  // ROW 5: Spacer
429  // -------------------------------------------------------------------
430 
431  S.AddSpace(5);
432 
433  S.SetBorder(2);
434  S.SetSizerProportion(0);
435  S.StartMultiColumn(9, wxALIGN_CENTER);
436  {
437  // ----------------------------------------------------------------
438  // ROW 6: Algorithm, Size, Export, Replot
439  // ----------------------------------------------------------------
440 
441  S.AddSpace(5);
442 
443  mAlgChoice = S.Id(FreqAlgChoiceID).AddChoice(_("&Algorithm:"), wxT(""), &algChoices);
444  mAlgChoice->SetSelection(mAlg);
445  S.SetSizeHints(wxDefaultCoord, wxDefaultCoord);
446 
447  S.AddSpace(5);
448 
449  mSizeChoice = S.Id(FreqSizeChoiceID).AddChoice(_("&Size:"), wxT(""), &sizeChoices);
450  mSizeChoice->SetSelection(mSize);
451  S.SetSizeHints(wxDefaultCoord, wxDefaultCoord);
452 
453  S.AddSpace(5);
454 
455  mExportButton = S.Id(FreqExportButtonID).AddButton(_("&Export..."));
456 
457  S.AddSpace(5);
458 
459 
460  // ----------------------------------------------------------------
461  // ROW 7: Function, Axix, Grids, Close
462  // ----------------------------------------------------------------
463 
464  S.AddSpace(5);
465 
466  mFuncChoice = S.Id(FreqFuncChoiceID).AddChoice(_("&Function:"), wxT(""), &funcChoices);
467  mFuncChoice->SetSelection(mFunc);
468  S.SetSizeHints(wxDefaultCoord, wxDefaultCoord);
469  mFuncChoice->MoveAfterInTabOrder(mSizeChoice);
470 
471  S.AddSpace(5);
472 
473  mAxisChoice = S.Id(FreqAxisChoiceID).AddChoice(_("&Axis:"), wxT(""), &axisChoices);
474  mAxisChoice->SetSelection(mAxis);
475  S.SetSizeHints(wxDefaultCoord, wxDefaultCoord);
476  mAxisChoice->MoveAfterInTabOrder(mFuncChoice);
477 
478  S.AddSpace(5);
479 
480  mReplotButton = S.Id(ReplotButtonID).AddButton(_("&Replot..."));
481 
482  S.AddSpace(5);
483 
484  //mCloseButton = S.Id(wxID_CANCEL).AddButton(_("&Close"));
485 
486  //S.AddSpace(5);
487  }
488  S.EndMultiColumn();
489  S.AddStandardButtons( eHelpButton | eCloseButton );
490 
491  // -------------------------------------------------------------------
492  // ROW 8: Spacer
493  // -------------------------------------------------------------------
494 
495  S.AddSpace(5);
496 
497  mProgress = safenew FreqGauge(this, wxID_ANY); //, wxST_SIZEGRIP);
498  S.AddWindow(mProgress, wxEXPAND);
499 
500  // Log-frequency axis works for spectrum plots only.
502  {
503  mAxis = 0;
504  mAxisChoice->Disable();
505  }
506  mLogAxis = mAxis != 0;
507 
508  mCloseButton = static_cast<wxButton*>(FindWindowById( wxID_CANCEL ));
509  mCloseButton->SetDefault();
510  mCloseButton->SetFocus();
511 
512  Layout();
513  Fit();
514  // Bug 1607:
515  Center();
516 
517  SetMinSize(GetSize());
518  mAlgChoice->SetFocus();
519 
520 #if defined(__WXGTK__)
521  // This should be rechecked with wx3.
522  //
523  // The scrollbar (focus some reason) doesn't allow tabbing past it
524  // because it can't receive focus. So, convince it otherwise.
525  //
526  // Unfortunately, this still doesn't let you adjust the scrollbar
527  // from the keyboard. Near as I can tell, wxWGTK is capturing the
528  // keyboard input, so the GTK widget doesn't see it, preventing
529  // the normal scroll events from being generated.
530  //
531  // I guess the only way round it would be to handle key actions
532  // ourselves, but we'll leave that for a future date.
533 // gtk_widget_set_can_focus(mPanScroller->m_widget, true);
534 #endif
535 }
wxCheckBox * mGridOnOff
Definition: FreqWindow.h:192
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73
wxButton * mExportButton
Definition: FreqWindow.h:190
double mRate
Definition: FreqWindow.h:203
AUDACITY_DLL_API Theme theTheme
Definition: Theme.cpp:209
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI...
Definition: ShuttleGui.h:409
wxButton * mCloseButton
Definition: FreqWindow.h:189
#define ENV_DB_KEY
Definition: GUISettings.h:15
std::unique_ptr< SpectrumAnalyst > mAnalyst
Definition: FreqWindow.h:218
Options & LabelEdges(bool l)
Definition: Ruler.h:266
bool mDrawGrid
Definition: FreqWindow.h:163
std::unique_ptr< wxCursor > mArrowCursor
Definition: FreqWindow.h:186
wxChoice * mAlgChoice
Definition: FreqWindow.h:193
RulerPanel class allows you to work with a Ruler like any other wxWindow.
Definition: Ruler.h:244
#define safenew
Definition: Audacity.h:230
RulerPanel * hRuler
Definition: FreqWindow.h:178
const wxChar * WindowFuncName(int whichFunction)
Definition: FFT.cpp:335
An alternative to using wxWindowAccessible, which in wxWidgets 3.1.1 contained GetParent() which was ...
#define ENV_DB_RANGE
Definition: GUISettings.h:16
bool mLogAxis
Definition: FreqWindow.h:208
wxTextCtrl * mCursorText
Definition: FreqWindow.h:199
Options & Flip(bool f)
Definition: Ruler.h:263
wxButton * mReplotButton
Definition: FreqWindow.h:191
size_t mWindowSize
Definition: FreqWindow.h:206
wxScrollBar * mPanScroller
Definition: FreqWindow.h:197
Options & Log(bool l)
Definition: Ruler.h:260
static const int fontSize
Definition: FreqWindow.h:174
FreqPlot * mFreqPlot
Definition: FreqWindow.h:179
SpectrumAnalyst::Algorithm mAlg
Definition: FreqWindow.h:165
int NumWindowFuncs()
Definition: FFT.cpp:330
wxSlider * mZoomSlider
Definition: FreqWindow.h:198
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
wxFont mFreqFont
Definition: FreqWindow.h:184
Options & TickColour(const wxColour c)
Definition: Ruler.h:272
AudacityProject * p
Definition: FreqWindow.h:169
wxChoice * mAxisChoice
Definition: FreqWindow.h:196
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:311
wxChoice * mSizeChoice
Definition: FreqWindow.h:194
std::pair< double, double > Range
Definition: Ruler.h:248
wxTextCtrl * mPeakText
Definition: FreqWindow.h:200
wxColour & Colour(int iIndex)
Definition: Theme.cpp:1225
FreqGauge * mProgress
Definition: FreqWindow.h:180
size_t mDataLen
Definition: FreqWindow.h:204
#define FREQ_WINDOW_HEIGHT
Definition: FreqWindow.cpp:112
static const char * ZoomOut[]
Definition: FreqWindow.cpp:141
friend class FreqPlot
Definition: FreqWindow.h:222
static const char * ZoomIn[]
Definition: FreqWindow.cpp:115
std::unique_ptr< wxCursor > mCrossCursor
Definition: FreqWindow.h:187
wxChoice * mFuncChoice
Definition: FreqWindow.h:195
RulerPanel * vRuler
Definition: FreqWindow.h:177
FreqWindow::~FreqWindow ( )
virtual

Definition at line 537 of file FreqWindow.cpp.

538 {
539 }

Member Function Documentation

void FreqWindow::DrawBackground ( wxMemoryDC &  dc)
private

Definition at line 637 of file FreqWindow.cpp.

References mBitmap, mFreqFont, mFreqPlot, and mPlotRect.

Referenced by DrawPlot().

638 {
639  Layout();
640 
641  mBitmap.reset();
642 
643  mPlotRect = mFreqPlot->GetClientRect();
644 
645  mBitmap = std::make_unique<wxBitmap>(mPlotRect.width, mPlotRect.height,24);
646 
647  dc.SelectObject(*mBitmap);
648 
649  dc.SetBackground(wxBrush(wxColour(254, 254, 254)));// DONT-THEME Mask colour.
650  dc.Clear();
651 
652  dc.SetPen(*wxBLACK_PEN);
653  dc.SetBrush(*wxWHITE_BRUSH);
654  dc.DrawRectangle(mPlotRect);
655 
656  dc.SetFont(mFreqFont);
657 }
wxRect mPlotRect
Definition: FreqWindow.h:182
std::unique_ptr< wxBitmap > mBitmap
Definition: FreqWindow.h:213
FreqPlot * mFreqPlot
Definition: FreqWindow.h:179
wxFont mFreqFont
Definition: FreqWindow.h:184
void FreqWindow::DrawPlot ( )
private

Definition at line 659 of file FreqWindow.cpp.

References _(), ThemeBase::Colour(), dBRange, DrawBackground(), Ruler::DrawGrid(), Ruler::GetMaxSize(), hRuler, AColor::Line(), Ruler::LinearDBFormat, mAlg, mAnalyst, mData, mDataLen, mDrawGrid, mFreqPlot, mLogAxis, mPanScroller, mPlotRect, mRate, mWindowSize, mYMax, mYMin, mZoomSlider, Ruler::RealFormat, RulerPanel::ruler, Ruler::SetFormat(), Ruler::SetLog(), Ruler::SetRange(), Ruler::SetUnits(), SpectrumAnalyst::Spectrum, theTheme, and vRuler.

Referenced by OnAxisChoice(), OnGridOnOff(), OnPanScroller(), OnSize(), OnZoomSlider(), and Recalc().

660 {
661  if (!mData || mDataLen < mWindowSize || mAnalyst->GetProcessedSize() == 0) {
662  wxMemoryDC memDC;
663 
664  vRuler->ruler.SetLog(false);
665  vRuler->ruler.SetRange(0.0, -dBRange);
666 
667  hRuler->ruler.SetLog(false);
668  hRuler->ruler.SetRange(0, 1);
669 
670  DrawBackground(memDC);
671 
672  if (mDataLen < mWindowSize) {
673  wxString msg = _("Not enough data selected.");
674  wxSize sz = memDC.GetTextExtent(msg);
675  memDC.DrawText(msg,
676  (mPlotRect.GetWidth() - sz.GetWidth()) / 2,
677  (mPlotRect.GetHeight() - sz.GetHeight()) / 2);
678  }
679 
680  memDC.SelectObject(wxNullBitmap);
681 
682  mFreqPlot->Refresh();
683 
684  Refresh();
685 
686  return;
687  }
688 
689  float yRange = mYMax - mYMin;
690  float yTotal = yRange * ((float) mZoomSlider->GetValue() / 100.0f);
691 
692  int sTotal = yTotal * 100;
693  int sRange = yRange * 100;
694  int sPos = mPanScroller->GetThumbPosition() + ((mPanScroller->GetThumbSize() - sTotal) / 2);
695  mPanScroller->SetScrollbar(sPos, sTotal, sRange, sTotal);
696 
697  float yMax = mYMax - ((float)sPos / 100);
698  float yMin = yMax - yTotal;
699 
700  // Set up y axis ruler
701 
703  vRuler->ruler.SetUnits(_("dB"));
705  } else {
706  vRuler->ruler.SetUnits(wxT(""));
708  }
709  int w1, w2, h;
710  vRuler->ruler.GetMaxSize(&w1, &h);
711  vRuler->ruler.SetRange(yMax, yMin); // Note inversion for vertical.
712  vRuler->ruler.GetMaxSize(&w2, &h);
713  if( w1 != w2 ) // Reduces flicker
714  {
715  vRuler->SetMinSize(wxSize(w2,h));
716  Layout();
717  }
718  vRuler->Refresh(false);
719 
720  wxMemoryDC memDC;
721  DrawBackground(memDC);
722 
723  // Get the plot dimensions
724  //
725  // Must be done after setting the vertical ruler above since the
726  // the width could change.
727  wxRect r = mPlotRect;
728 
729  // Set up x axis ruler
730 
731  int width = r.width - 2;
732 
733  float xMin, xMax, xRatio, xStep;
734 
736  xMin = mRate / mWindowSize;
737  xMax = mRate / 2;
738  xRatio = xMax / xMin;
739  if (mLogAxis)
740  {
741  xStep = pow(2.0f, (log(xRatio) / log(2.0f)) / width);
742  hRuler->ruler.SetLog(true);
743  }
744  else
745  {
746  xStep = (xMax - xMin) / width;
747  hRuler->ruler.SetLog(false);
748  }
749  hRuler->ruler.SetUnits(_("Hz"));
750  } else {
751  xMin = 0;
752  xMax = mAnalyst->GetProcessedSize() / mRate;
753  xStep = (xMax - xMin) / width;
754  hRuler->ruler.SetLog(false);
755  hRuler->ruler.SetUnits(_("s"));
756  }
757  hRuler->ruler.SetRange(xMin, xMax-xStep);
758  hRuler->Refresh(false);
759 
760  // Draw the plot
762  memDC.SetPen(wxPen(theTheme.Colour( clrHzPlot ), 1, wxPENSTYLE_SOLID));
763  else
764  memDC.SetPen(wxPen(theTheme.Colour( clrWavelengthPlot), 1, wxPENSTYLE_SOLID));
765 
766  float xPos = xMin;
767 
768  for (int i = 0; i < width; i++) {
769  float y;
770 
771  if (mLogAxis)
772  y = mAnalyst->GetProcessedValue(xPos, xPos * xStep);
773  else
774  y = mAnalyst->GetProcessedValue(xPos, xPos + xStep);
775 
776  float ynorm = (y - yMin) / yTotal;
777 
778  int lineheight = (int)(ynorm * (r.height - 1));
779 
780  if (lineheight > r.height - 2)
781  lineheight = r.height - 2;
782 
783  if (ynorm > 0.0)
784  AColor::Line(memDC, r.x + 1 + i, r.y + r.height - 1 - lineheight,
785  r.x + 1 + i, r.y + r.height - 1);
786 
787  if (mLogAxis)
788  xPos *= xStep;
789  else
790  xPos += xStep;
791  }
792 
793  // Outline the graph
794  memDC.SetPen(*wxBLACK_PEN);
795  memDC.SetBrush(*wxTRANSPARENT_BRUSH);
796  memDC.DrawRectangle(r);
797 
798  if(mDrawGrid)
799  {
800  hRuler->ruler.DrawGrid(memDC, r.height, true, true, 1, 1);
801  vRuler->ruler.DrawGrid(memDC, r.width, true, true, 1, 1);
802  }
803 
804  memDC.SelectObject( wxNullBitmap );
805 
806  mFreqPlot->Refresh();
807 }
float mYMin
Definition: FreqWindow.h:209
void SetLog(bool log)
Definition: Ruler.cpp:155
double mRate
Definition: FreqWindow.h:203
AUDACITY_DLL_API Theme theTheme
Definition: Theme.cpp:209
wxRect mPlotRect
Definition: FreqWindow.h:182
std::unique_ptr< SpectrumAnalyst > mAnalyst
Definition: FreqWindow.h:218
void GetMaxSize(wxCoord *width, wxCoord *height)
Definition: Ruler.cpp:1511
bool mDrawGrid
Definition: FreqWindow.h:163
Floats mData
Definition: FreqWindow.h:205
RulerPanel * hRuler
Definition: FreqWindow.h:178
bool mLogAxis
Definition: FreqWindow.h:208
size_t mWindowSize
Definition: FreqWindow.h:206
wxScrollBar * mPanScroller
Definition: FreqWindow.h:197
void DrawBackground(wxMemoryDC &dc)
Definition: FreqWindow.cpp:637
float mYMax
Definition: FreqWindow.h:210
void SetUnits(const wxString &units)
Definition: Ruler.cpp:166
FreqPlot * mFreqPlot
Definition: FreqWindow.h:179
SpectrumAnalyst::Algorithm mAlg
Definition: FreqWindow.h:165
static void Line(wxDC &dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
Definition: AColor.cpp:122
wxSlider * mZoomSlider
Definition: FreqWindow.h:198
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
void DrawGrid(wxDC &dc, int length, bool minor=true, bool major=true, int xOffset=0, int yOffset=0)
Definition: Ruler.cpp:1427
void SetFormat(RulerFormat format)
Definition: Ruler.cpp:144
void SetRange(double min, double max)
Definition: Ruler.cpp:192
wxColour & Colour(int iIndex)
Definition: Theme.cpp:1225
size_t mDataLen
Definition: FreqWindow.h:204
RulerPanel * vRuler
Definition: FreqWindow.h:177
Ruler ruler
Definition: Ruler.h:304
void FreqWindow::GetAudio ( )
private

Definition at line 574 of file FreqWindow.cpp.

References _(), AudacityMessageBox(), fillZero, floatSample, AudacityProject::GetTracks(), mData, mDataLen, mRate, AudacityProject::mViewInfo, p, TrackList::Selected(), ViewInfo::selectedRegion, SelectedRegion::t0(), and SelectedRegion::t1().

Referenced by OnReplot(), and Show().

575 {
576  mData.reset();
577  mDataLen = 0;
578 
579  int selcount = 0;
580  bool warning = false;
581  for (auto track : p->GetTracks()->Selected< const WaveTrack >()) {
582  if (selcount==0) {
583  mRate = track->GetRate();
584  auto start = track->TimeToLongSamples(p->mViewInfo.selectedRegion.t0());
585  auto end = track->TimeToLongSamples(p->mViewInfo.selectedRegion.t1());
586  auto dataLen = end - start;
587  if (dataLen > 10485760) {
588  warning = true;
589  mDataLen = 10485760;
590  }
591  else
592  // dataLen is not more than 10 * 2 ^ 20
593  mDataLen = dataLen.as_size_t();
594  mData = Floats{ mDataLen };
595  // Don't allow throw for bad reads
596  track->Get((samplePtr)mData.get(), floatSample, start, mDataLen,
597  fillZero, false);
598  }
599  else {
600  if (track->GetRate() != mRate) {
601  AudacityMessageBox(_("To plot the spectrum, all selected tracks must be the same sample rate."));
602  mData.reset();
603  mDataLen = 0;
604  return;
605  }
606  auto start = track->TimeToLongSamples(p->mViewInfo.selectedRegion.t0());
607  Floats buffer2{ mDataLen };
608  // Again, stop exceptions
609  track->Get((samplePtr)buffer2.get(), floatSample, start, mDataLen,
610  fillZero, false);
611  for (size_t i = 0; i < mDataLen; i++)
612  mData[i] += buffer2[i];
613  }
614  selcount++;
615  }
616 
617  if (selcount == 0)
618  return;
619 
620  if (warning) {
621  wxString msg;
622  msg.Printf(_("Too much audio was selected. Only the first %.1f seconds of audio will be analyzed."),
623  (mDataLen / mRate));
624  AudacityMessageBox(msg);
625  }
626 }
double mRate
Definition: FreqWindow.h:203
double t0() const
SelectedRegion selectedRegion
Definition: ViewInfo.h:162
int AudacityMessageBox(const wxString &message, const wxString &caption=AudacityMessageBoxCaptionStr(), long style=wxOK|wxCENTRE, wxWindow *parent=NULL, int x=wxDefaultCoord, int y=wxDefaultCoord)
Definition: ErrorDialog.h:92
double t1() const
Floats mData
Definition: FreqWindow.h:205
auto Selected() -> TrackIterRange< TrackType >
Definition: Track.h:1263
char * samplePtr
Definition: Types.h:203
A Track that contains audio waveform data.
Definition: WaveTrack.h:60
ViewInfo mViewInfo
Definition: Project.h:555
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
AudacityProject * p
Definition: FreqWindow.h:169
size_t mDataLen
Definition: FreqWindow.h:204
TrackList * GetTracks()
Definition: Project.h:209
void FreqWindow::OnAlgChoice ( wxCommandEvent &  event)
private

Definition at line 835 of file FreqWindow.cpp.

References mAlg, mAlgChoice, mAxisChoice, mLogAxis, SendRecalcEvent(), and SpectrumAnalyst::Spectrum.

836 {
837  mAlg = SpectrumAnalyst::Algorithm(mAlgChoice->GetSelection());
838 
839  // Log-frequency axis works for spectrum plots only.
841  mAxisChoice->Enable(true);
842  mLogAxis = mAxisChoice->GetSelection() ? true : false;
843  }
844  else {
845  mAxisChoice->Disable();
846  mLogAxis = false;
847  }
848 
849  SendRecalcEvent();
850 }
wxChoice * mAlgChoice
Definition: FreqWindow.h:193
bool mLogAxis
Definition: FreqWindow.h:208
SpectrumAnalyst::Algorithm mAlg
Definition: FreqWindow.h:165
void SendRecalcEvent()
Definition: FreqWindow.cpp:994
wxChoice * mAxisChoice
Definition: FreqWindow.h:196
void FreqWindow::OnAxisChoice ( wxCommandEvent &  event)
private

Definition at line 866 of file FreqWindow.cpp.

References DrawPlot(), mAxisChoice, and mLogAxis.

867 {
868  mLogAxis = mAxisChoice->GetSelection() ? true : false;
869  DrawPlot();
870 }
bool mLogAxis
Definition: FreqWindow.h:208
wxChoice * mAxisChoice
Definition: FreqWindow.h:196
void DrawPlot()
Definition: FreqWindow.cpp:659
void FreqWindow::OnCloseButton ( wxCommandEvent &  event)
private

Definition at line 983 of file FreqWindow.cpp.

References gPrefs, mAlgChoice, mAxisChoice, mDrawGrid, mFuncChoice, mSizeChoice, and Show().

984 {
985  gPrefs->Write(wxT("/FreqWindow/DrawGrid"), mDrawGrid);
986  gPrefs->Write(wxT("/FreqWindow/SizeChoice"), mSizeChoice->GetSelection());
987  gPrefs->Write(wxT("/FreqWindow/AlgChoice"), mAlgChoice->GetSelection());
988  gPrefs->Write(wxT("/FreqWindow/FuncChoice"), mFuncChoice->GetSelection());
989  gPrefs->Write(wxT("/FreqWindow/AxisChoice"), mAxisChoice->GetSelection());
990  gPrefs->Flush();
991  Show(false);
992 }
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73
bool mDrawGrid
Definition: FreqWindow.h:163
wxChoice * mAlgChoice
Definition: FreqWindow.h:193
wxChoice * mAxisChoice
Definition: FreqWindow.h:196
wxChoice * mSizeChoice
Definition: FreqWindow.h:194
bool Show(bool show=true) override
Definition: FreqWindow.cpp:548
wxChoice * mFuncChoice
Definition: FreqWindow.h:195
void FreqWindow::OnCloseWindow ( wxCloseEvent &  event)
private

Definition at line 978 of file FreqWindow.cpp.

References Show().

979 {
980  Show(false);
981 }
bool Show(bool show=true) override
Definition: FreqWindow.cpp:548
void FreqWindow::OnExport ( wxCommandEvent &  event)
private

Definition at line 1045 of file FreqWindow.cpp.

References _(), AudacityMessageBox(), FileNames::Export, mAlgChoice, mAnalyst, mRate, mWindowSize, and FileNames::SelectFile().

1046 {
1047  wxString fName = _("spectrum.txt");
1048 
1050  _("Export Spectral Data As:"),
1051  wxEmptyString, fName, wxT("txt"), wxT("*.txt"), wxFD_SAVE | wxRESIZE_BORDER, this);
1052 
1053  if (fName == wxT(""))
1054  return;
1055 
1056  wxTextFile f(fName);
1057 #ifdef __WXMAC__
1058  wxFile{}.Create(fName);
1059 #else
1060  f.Create();
1061 #endif
1062  f.Open();
1063  if (!f.IsOpened()) {
1064  AudacityMessageBox( wxString::Format(
1065  _("Couldn't write to file: %s"), fName ) );
1066  return;
1067  }
1068 
1069  const int processedSize = mAnalyst->GetProcessedSize();
1070  const float *const processed = mAnalyst->GetProcessed();
1071  if (mAlgChoice->GetSelection() == 0) {
1072  f.AddLine(_("Frequency (Hz)\tLevel (dB)"));
1073  for (int i = 1; i < processedSize; i++)
1074  f.AddLine(wxString::
1075  Format(wxT("%f\t%f"), i * mRate / mWindowSize,
1076  processed[i]));
1077  } else {
1078  f.AddLine(_("Lag (seconds)\tFrequency (Hz)\tLevel"));
1079  for (int i = 1; i < processedSize; i++)
1080  f.AddLine(wxString::Format(wxT("%f\t%f\t%f"),
1081  i / mRate, mRate / i, processed[i]));
1082  }
1083 
1084 #ifdef __WXMAC__
1085  f.Write(wxTextFileType_Mac);
1086 #else
1087  f.Write();
1088 #endif
1089  f.Close();
1090 }
double mRate
Definition: FreqWindow.h:203
Abstract base class used in importing a file.
Definition: Import.h:32
std::unique_ptr< SpectrumAnalyst > mAnalyst
Definition: FreqWindow.h:218
int AudacityMessageBox(const wxString &message, const wxString &caption=AudacityMessageBoxCaptionStr(), long style=wxOK|wxCENTRE, wxWindow *parent=NULL, int x=wxDefaultCoord, int y=wxDefaultCoord)
Definition: ErrorDialog.h:92
wxChoice * mAlgChoice
Definition: FreqWindow.h:193
size_t mWindowSize
Definition: FreqWindow.h:206
static wxString SelectFile(Operation op, const wxString &message, const wxString &default_path, const wxString &default_filename, const wxString &default_extension, const wxString &wildcard, int flags, wxWindow *parent)
Definition: FileNames.cpp:425
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
void FreqWindow::OnFuncChoice ( wxCommandEvent &  event)
private

Definition at line 861 of file FreqWindow.cpp.

References SendRecalcEvent().

862 {
863  SendRecalcEvent();
864 }
void SendRecalcEvent()
Definition: FreqWindow.cpp:994
void FreqWindow::OnGetURL ( wxCommandEvent &  event)
private

Definition at line 541 of file FreqWindow.cpp.

References HelpSystem::ShowHelp().

542 {
543  // Original help page is back on-line (March 2016), but the manual should be more reliable.
544  // http://www.eramp.com/WCAG_2_audio_contrast_tool_help.htm
545  HelpSystem::ShowHelp(this, wxT("Plot Spectrum"));
546 }
static void ShowHelp(wxWindow *parent, const wxString &localFileName, const wxString &remoteURL, bool bModal=false, bool alwaysDefaultBrowser=false)
Definition: HelpSystem.cpp:194
void FreqWindow::OnGridOnOff ( wxCommandEvent &  event)
private

Definition at line 1101 of file FreqWindow.cpp.

References DrawPlot(), mDrawGrid, and mGridOnOff.

1102 {
1103  mDrawGrid = mGridOnOff->IsChecked();
1104 
1105  DrawPlot();
1106 }
wxCheckBox * mGridOnOff
Definition: FreqWindow.h:192
bool mDrawGrid
Definition: FreqWindow.h:163
void DrawPlot()
Definition: FreqWindow.cpp:659
void FreqWindow::OnPanScroller ( wxScrollEvent &  event)
private

Definition at line 825 of file FreqWindow.cpp.

References DrawPlot().

826 {
827  DrawPlot();
828 }
void DrawPlot()
Definition: FreqWindow.cpp:659
void FreqWindow::OnRecalc ( wxCommandEvent &  event)
private

Definition at line 1108 of file FreqWindow.cpp.

References Recalc().

1109 {
1110  Recalc();
1111 }
void Recalc()
void FreqWindow::OnReplot ( wxCommandEvent &  event)
private

Definition at line 1092 of file FreqWindow.cpp.

References dBRange, ENV_DB_KEY, ENV_DB_RANGE, GetAudio(), gPrefs, and SendRecalcEvent().

1093 {
1095  if(dBRange < 90.)
1096  dBRange = 90.;
1097  GetAudio();
1098  SendRecalcEvent();
1099 }
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73
#define ENV_DB_KEY
Definition: GUISettings.h:15
#define ENV_DB_RANGE
Definition: GUISettings.h:16
void GetAudio()
Definition: FreqWindow.cpp:574
void SendRecalcEvent()
Definition: FreqWindow.cpp:994
void FreqWindow::OnSize ( wxSizeEvent &  event)
private

Definition at line 628 of file FreqWindow.cpp.

References DrawPlot().

629 {
630  Layout();
631 
632  DrawPlot();
633 
634  Refresh(true);
635 }
void DrawPlot()
Definition: FreqWindow.cpp:659
void FreqWindow::OnSizeChoice ( wxCommandEvent &  event)
private

Definition at line 852 of file FreqWindow.cpp.

References mSizeChoice, mWindowSize, and SendRecalcEvent().

853 {
854  long windowSize = 0;
855  mSizeChoice->GetStringSelection().ToLong(&windowSize);
856  mWindowSize = windowSize;
857 
858  SendRecalcEvent();
859 }
size_t mWindowSize
Definition: FreqWindow.h:206
void SendRecalcEvent()
Definition: FreqWindow.cpp:994
wxChoice * mSizeChoice
Definition: FreqWindow.h:194
void FreqWindow::OnZoomSlider ( wxCommandEvent &  event)
private

Definition at line 830 of file FreqWindow.cpp.

References DrawPlot().

831 {
832  DrawPlot();
833 }
void DrawPlot()
Definition: FreqWindow.cpp:659
void FreqWindow::PlotMouseEvent ( wxMouseEvent &  event)
private

Definition at line 810 of file FreqWindow.cpp.

References mArrowCursor, mCrossCursor, mFreqPlot, mMouseX, mMouseY, and mPlotRect.

Referenced by FreqPlot::OnMouseEvent().

811 {
812  if (event.Moving() && (event.m_x != mMouseX || event.m_y != mMouseY)) {
813  mMouseX = event.m_x;
814  mMouseY = event.m_y;
815 
816  if (mPlotRect.Contains(mMouseX, mMouseY))
817  mFreqPlot->SetCursor(*mCrossCursor);
818  else
819  mFreqPlot->SetCursor(*mArrowCursor);
820 
821  mFreqPlot->Refresh(false);
822  }
823 }
wxRect mPlotRect
Definition: FreqWindow.h:182
std::unique_ptr< wxCursor > mArrowCursor
Definition: FreqWindow.h:186
FreqPlot * mFreqPlot
Definition: FreqWindow.h:179
std::unique_ptr< wxCursor > mCrossCursor
Definition: FreqWindow.h:187
void FreqWindow::PlotPaint ( wxPaintEvent &  event)
private

Definition at line 872 of file FreqWindow.cpp.

References _(), FreqToMIDInote(), AColor::Line(), mAlg, mAnalyst, mBitmap, mCursorText, mData, mDataLen, mFreqFont, mLogAxis, mMouseX, mMouseY, mPeakText, mPlotRect, mRate, mWindowSize, PitchName_Absolute(), and SpectrumAnalyst::Spectrum.

Referenced by FreqPlot::OnPaint().

873 {
874  wxPaintDC dc( (wxWindow *) event.GetEventObject() );
875 
876  dc.DrawBitmap( *mBitmap, 0, 0, true );
877  // Fix for Bug 1226 "Plot Spectrum freezes... if insufficient samples selected"
878  if (!mData || mDataLen < mWindowSize)
879  return;
880 
881  dc.SetFont(mFreqFont);
882 
883  wxRect r = mPlotRect;
884 
885  int width = r.width - 2;
886 
887  float xMin, xMax, xRatio, xStep;
888 
890  xMin = mRate / mWindowSize;
891  xMax = mRate / 2;
892  xRatio = xMax / xMin;
893  if (mLogAxis)
894  xStep = pow(2.0f, (log(xRatio) / log(2.0f)) / width);
895  else
896  xStep = (xMax - xMin) / width;
897  } else {
898  xMin = 0;
899  xMax = mAnalyst->GetProcessedSize() / mRate;
900  xStep = (xMax - xMin) / width;
901  }
902 
903  float xPos = xMin;
904 
905  // Find the peak nearest the cursor and plot it
906  if ( r.Contains(mMouseX, mMouseY) & (mMouseX!=0) & (mMouseX!=r.width-1) ) {
907  if (mLogAxis)
908  xPos = xMin * pow(xStep, mMouseX - (r.x + 1));
909  else
910  xPos = xMin + xStep * (mMouseX - (r.x + 1));
911 
912  float bestValue = 0;
913  float bestpeak = mAnalyst->FindPeak(xPos, &bestValue);
914 
915  int px;
916  if (mLogAxis)
917  px = (int)(log(bestpeak / xMin) / log(xStep));
918  else
919  px = (int)((bestpeak - xMin) * width / (xMax - xMin));
920 
921  dc.SetPen(wxPen(wxColour(160,160,160), 1, wxPENSTYLE_SOLID));
922  AColor::Line(dc, r.x + 1 + px, r.y, r.x + 1 + px, r.y + r.height);
923 
924  // print out info about the cursor location
925 
926  float value;
927 
928  if (mLogAxis) {
929  xPos = xMin * pow(xStep, mMouseX - (r.x + 1));
930  value = mAnalyst->GetProcessedValue(xPos, xPos * xStep);
931  } else {
932  xPos = xMin + xStep * (mMouseX - (r.x + 1));
933  value = mAnalyst->GetProcessedValue(xPos, xPos + xStep);
934  }
935 
936  wxString cursor;
937  wxString peak;
938  wxString xpitch;
939  wxString peakpitch;
940  const wxChar *xp;
941  const wxChar *pp;
942 
944  xpitch = PitchName_Absolute(FreqToMIDInote(xPos));
945  peakpitch = PitchName_Absolute(FreqToMIDInote(bestpeak));
946  xp = xpitch;
947  pp = peakpitch;
948  /* i18n-hint: The %d's are replaced by numbers, the %s by musical notes, e.g. A#*/
949  cursor.Printf(_("%d Hz (%s) = %d dB"), (int)(xPos + 0.5), xp, (int)(value + 0.5));
950  peak.Printf(_("%d Hz (%s) = %.1f dB"), (int)(bestpeak + 0.5), pp, bestValue);
951  } else if (xPos > 0.0 && bestpeak > 0.0) {
952  xpitch = PitchName_Absolute(FreqToMIDInote(1.0 / xPos));
953  peakpitch = PitchName_Absolute(FreqToMIDInote(1.0 / bestpeak));
954  xp = xpitch;
955  pp = peakpitch;
956  /* i18n-hint: The %d's are replaced by numbers, the %s by musical notes, e.g. A#
957  * the %.4f are numbers, and 'sec' should be an abbreviation for seconds */
958  cursor.Printf(_("%.4f sec (%d Hz) (%s) = %f"),
959  xPos, (int)(1.0 / xPos + 0.5), xp, value);
960  peak.Printf(_("%.4f sec (%d Hz) (%s) = %.3f"),
961  bestpeak, (int)(1.0 / bestpeak + 0.5), pp, bestValue);
962  }
963  mCursorText->SetValue(cursor);
964  mPeakText->SetValue(peak);
965  }
966  else {
967  mCursorText->SetValue(wxT(""));
968  mPeakText->SetValue(wxT(""));
969  }
970 
971 
972  // Outline the graph
973  dc.SetPen(*wxBLACK_PEN);
974  dc.SetBrush(*wxTRANSPARENT_BRUSH);
975  dc.DrawRectangle(r);
976 }
double mRate
Definition: FreqWindow.h:203
wxRect mPlotRect
Definition: FreqWindow.h:182
std::unique_ptr< SpectrumAnalyst > mAnalyst
Definition: FreqWindow.h:218
std::unique_ptr< wxBitmap > mBitmap
Definition: FreqWindow.h:213
Floats mData
Definition: FreqWindow.h:205
double FreqToMIDInote(const double freq)
Definition: PitchName.cpp:28
bool mLogAxis
Definition: FreqWindow.h:208
wxTextCtrl * mCursorText
Definition: FreqWindow.h:199
size_t mWindowSize
Definition: FreqWindow.h:206
wxString PitchName_Absolute(const double dMIDInote, const PitchNameChoice choice)
Definition: PitchName.cpp:153
SpectrumAnalyst::Algorithm mAlg
Definition: FreqWindow.h:165
static void Line(wxDC &dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
Definition: AColor.cpp:122
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
wxFont mFreqFont
Definition: FreqWindow.h:184
wxTextCtrl * mPeakText
Definition: FreqWindow.h:200
size_t mDataLen
Definition: FreqWindow.h:204
void FreqWindow::Recalc ( )
private

Definition at line 1000 of file FreqWindow.cpp.

References Maybe< X >::create(), dBRange, DrawPlot(), mAlgChoice, mAnalyst, mData, mDataLen, mFuncChoice, mPanScroller, mProgress, mRate, mWindowSize, mYMax, mYMin, and SpectrumAnalyst::Spectrum.

Referenced by OnRecalc(), and Show().

1001 {
1002  if (!mData || mDataLen < mWindowSize) {
1003  DrawPlot();
1004  return;
1005  }
1006 
1008  SpectrumAnalyst::Algorithm(mAlgChoice->GetSelection());
1009  int windowFunc = mFuncChoice->GetSelection();
1010 
1011  wxWindow *hadFocus = FindFocus();
1012  // In wxMac, the skipped window MUST be a top level window. I'd originally made it
1013  // just the mProgress window with the idea of preventing user interaction with the
1014  // controls while the plot was being recalculated. This doesn't appear to be necessary
1015  // so just use the the top level window instead.
1016  {
1017  Maybe<wxWindowDisabler> blocker;
1018  if (IsShown())
1019  blocker.create(this);
1020  wxYieldIfNeeded();
1021 
1022  mAnalyst->Calculate(alg, windowFunc, mWindowSize, mRate,
1023  mData.get(), mDataLen,
1024  &mYMin, &mYMax, mProgress);
1025  }
1026  if (hadFocus) {
1027  hadFocus->SetFocus();
1028  }
1029 
1030  if (alg == SpectrumAnalyst::Spectrum) {
1031  if(mYMin < -dBRange)
1032  mYMin = -dBRange;
1033  if(mYMax <= -dBRange)
1034  mYMax = -dBRange + 10.; // it's all out of range, but show a scale.
1035  else
1036  mYMax += .5;
1037  }
1038 
1039  // Prime the scrollbar
1040  mPanScroller->SetScrollbar(0, (mYMax - mYMin) * 100, (mYMax - mYMin) * 100, 1);
1041 
1042  DrawPlot();
1043 }
float mYMin
Definition: FreqWindow.h:209
double mRate
Definition: FreqWindow.h:203
std::unique_ptr< SpectrumAnalyst > mAnalyst
Definition: FreqWindow.h:218
Like a smart pointer, allows for object to not exist (nullptr)
Definition: MemoryX.h:209
wxChoice * mAlgChoice
Definition: FreqWindow.h:193
Floats mData
Definition: FreqWindow.h:205
size_t mWindowSize
Definition: FreqWindow.h:206
wxScrollBar * mPanScroller
Definition: FreqWindow.h:197
float mYMax
Definition: FreqWindow.h:210
FreqGauge * mProgress
Definition: FreqWindow.h:180
size_t mDataLen
Definition: FreqWindow.h:204
void DrawPlot()
Definition: FreqWindow.cpp:659
wxChoice * mFuncChoice
Definition: FreqWindow.h:195
void create(Args &&...args)
Definition: MemoryX.h:256
void FreqWindow::SendRecalcEvent ( )
private

Definition at line 994 of file FreqWindow.cpp.

Referenced by OnAlgChoice(), OnFuncChoice(), OnReplot(), and OnSizeChoice().

995 {
996  wxCommandEvent e(EVT_FREQWINDOW_RECALC, wxID_ANY);
997  GetEventHandler()->AddPendingEvent(e);
998 }
bool FreqWindow::Show ( bool  show = true)
override

Definition at line 548 of file FreqWindow.cpp.

References dBRange, ENV_DB_KEY, ENV_DB_RANGE, GetAudio(), gPrefs, mArrowCursor, mFreqPlot, and Recalc().

Referenced by OnCloseButton(), OnCloseWindow(), and PluginActions::Handler::OnPlotSpectrum().

549 {
550  if (!show)
551  {
552  mFreqPlot->SetCursor(*mArrowCursor);
553  }
554 
555  bool shown = IsShown();
556 
557  if (show && !shown)
558  {
560  if(dBRange < 90.)
561  dBRange = 90.;
562  GetAudio();
563  // Don't send an event. We need the recalc right away.
564  // so that mAnalyst is valid when we paint.
565  //SendRecalcEvent();
566  Recalc();
567  }
568 
569  bool res = wxDialogWrapper::Show(show);
570 
571  return res;
572 }
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73
#define ENV_DB_KEY
Definition: GUISettings.h:15
std::unique_ptr< wxCursor > mArrowCursor
Definition: FreqWindow.h:186
void Recalc()
#define ENV_DB_RANGE
Definition: GUISettings.h:16
void GetAudio()
Definition: FreqWindow.cpp:574
FreqPlot * mFreqPlot
Definition: FreqWindow.h:179

Friends And Related Function Documentation

friend class FreqPlot
friend

Definition at line 222 of file FreqWindow.h.

Referenced by FreqWindow().

Member Data Documentation

int FreqWindow::dBRange
private

Definition at line 168 of file FreqWindow.h.

Referenced by DrawPlot(), FreqWindow(), OnReplot(), Recalc(), and Show().

const int FreqWindow::fontSize = 10
staticprivate

Definition at line 174 of file FreqWindow.h.

Referenced by FreqWindow().

RulerPanel* FreqWindow::hRuler
private

Definition at line 178 of file FreqWindow.h.

Referenced by DrawPlot(), and FreqWindow().

SpectrumAnalyst::Algorithm FreqWindow::mAlg
private

Definition at line 165 of file FreqWindow.h.

Referenced by DrawPlot(), FreqWindow(), OnAlgChoice(), and PlotPaint().

wxChoice* FreqWindow::mAlgChoice
private

Definition at line 193 of file FreqWindow.h.

Referenced by FreqWindow(), OnAlgChoice(), OnCloseButton(), OnExport(), and Recalc().

std::unique_ptr<SpectrumAnalyst> FreqWindow::mAnalyst
private

Definition at line 218 of file FreqWindow.h.

Referenced by DrawPlot(), OnExport(), PlotPaint(), and Recalc().

std::unique_ptr<wxCursor> FreqWindow::mArrowCursor
private

Definition at line 186 of file FreqWindow.h.

Referenced by FreqWindow(), PlotMouseEvent(), and Show().

int FreqWindow::mAxis
private

Definition at line 167 of file FreqWindow.h.

Referenced by FreqWindow().

wxChoice* FreqWindow::mAxisChoice
private

Definition at line 196 of file FreqWindow.h.

Referenced by FreqWindow(), OnAlgChoice(), OnAxisChoice(), and OnCloseButton().

std::unique_ptr<wxBitmap> FreqWindow::mBitmap
private

Definition at line 213 of file FreqWindow.h.

Referenced by DrawBackground(), and PlotPaint().

wxButton* FreqWindow::mCloseButton
private

Definition at line 189 of file FreqWindow.h.

Referenced by FreqWindow().

std::unique_ptr<wxCursor> FreqWindow::mCrossCursor
private

Definition at line 187 of file FreqWindow.h.

Referenced by FreqWindow(), and PlotMouseEvent().

wxTextCtrl* FreqWindow::mCursorText
private

Definition at line 199 of file FreqWindow.h.

Referenced by FreqWindow(), and PlotPaint().

Floats FreqWindow::mData
private

Definition at line 205 of file FreqWindow.h.

Referenced by DrawPlot(), GetAudio(), PlotPaint(), and Recalc().

size_t FreqWindow::mDataLen
private

Definition at line 204 of file FreqWindow.h.

Referenced by DrawPlot(), FreqWindow(), GetAudio(), PlotPaint(), and Recalc().

bool FreqWindow::mDrawGrid
private

Definition at line 163 of file FreqWindow.h.

Referenced by DrawPlot(), FreqWindow(), OnCloseButton(), and OnGridOnOff().

wxButton* FreqWindow::mExportButton
private

Definition at line 190 of file FreqWindow.h.

Referenced by FreqWindow().

wxFont FreqWindow::mFreqFont
private

Definition at line 184 of file FreqWindow.h.

Referenced by DrawBackground(), FreqWindow(), and PlotPaint().

FreqPlot* FreqWindow::mFreqPlot
private

Definition at line 179 of file FreqWindow.h.

Referenced by DrawBackground(), DrawPlot(), FreqWindow(), PlotMouseEvent(), and Show().

int FreqWindow::mFunc
private

Definition at line 166 of file FreqWindow.h.

Referenced by FreqWindow().

wxChoice* FreqWindow::mFuncChoice
private

Definition at line 195 of file FreqWindow.h.

Referenced by FreqWindow(), OnCloseButton(), and Recalc().

wxCheckBox* FreqWindow::mGridOnOff
private

Definition at line 192 of file FreqWindow.h.

Referenced by FreqWindow(), and OnGridOnOff().

bool FreqWindow::mLogAxis
private

Definition at line 208 of file FreqWindow.h.

Referenced by DrawPlot(), FreqWindow(), OnAlgChoice(), OnAxisChoice(), and PlotPaint().

int FreqWindow::mMouseX
private

Definition at line 215 of file FreqWindow.h.

Referenced by FreqWindow(), PlotMouseEvent(), and PlotPaint().

int FreqWindow::mMouseY
private

Definition at line 216 of file FreqWindow.h.

Referenced by FreqWindow(), PlotMouseEvent(), and PlotPaint().

wxScrollBar* FreqWindow::mPanScroller
private

Definition at line 197 of file FreqWindow.h.

Referenced by DrawPlot(), FreqWindow(), and Recalc().

wxTextCtrl* FreqWindow::mPeakText
private

Definition at line 200 of file FreqWindow.h.

Referenced by FreqWindow(), and PlotPaint().

wxRect FreqWindow::mPlotRect
private

Definition at line 182 of file FreqWindow.h.

Referenced by DrawBackground(), DrawPlot(), PlotMouseEvent(), and PlotPaint().

FreqGauge* FreqWindow::mProgress
private

Definition at line 180 of file FreqWindow.h.

Referenced by FreqWindow(), and Recalc().

double FreqWindow::mRate
private

Definition at line 203 of file FreqWindow.h.

Referenced by DrawPlot(), FreqWindow(), GetAudio(), OnExport(), PlotPaint(), and Recalc().

wxButton* FreqWindow::mReplotButton
private

Definition at line 191 of file FreqWindow.h.

Referenced by FreqWindow().

int FreqWindow::mSize
private

Definition at line 164 of file FreqWindow.h.

Referenced by FreqWindow().

wxChoice* FreqWindow::mSizeChoice
private

Definition at line 194 of file FreqWindow.h.

Referenced by FreqWindow(), OnCloseButton(), and OnSizeChoice().

size_t FreqWindow::mWindowSize
private

Definition at line 206 of file FreqWindow.h.

Referenced by DrawPlot(), FreqWindow(), OnExport(), OnSizeChoice(), PlotPaint(), and Recalc().

float FreqWindow::mYMax
private

Definition at line 210 of file FreqWindow.h.

Referenced by DrawPlot(), and Recalc().

float FreqWindow::mYMin
private

Definition at line 209 of file FreqWindow.h.

Referenced by DrawPlot(), and Recalc().

float FreqWindow::mYStep
private

Definition at line 211 of file FreqWindow.h.

wxSlider* FreqWindow::mZoomSlider
private

Definition at line 198 of file FreqWindow.h.

Referenced by DrawPlot(), and FreqWindow().

AudacityProject* FreqWindow::p
private

Definition at line 169 of file FreqWindow.h.

Referenced by FreqWindow(), and GetAudio().

RulerPanel* FreqWindow::vRuler
private

Definition at line 177 of file FreqWindow.h.

Referenced by DrawPlot(), and FreqWindow().


The documentation for this class was generated from the following files: