Audacity  2.2.2
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)
 

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

Constructor & Destructor Documentation

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

Definition at line 195 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.

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

Definition at line 536 of file FreqWindow.cpp.

537 {
538 }

Member Function Documentation

void FreqWindow::DrawBackground ( wxMemoryDC &  dc)
private

Definition at line 642 of file FreqWindow.cpp.

References mBitmap, mFreqFont, mFreqPlot, and mPlotRect.

Referenced by DrawPlot().

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

Definition at line 664 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().

665 {
666  if (!mData || mDataLen < mWindowSize || mAnalyst->GetProcessedSize() == 0) {
667  wxMemoryDC memDC;
668 
669  vRuler->ruler.SetLog(false);
670  vRuler->ruler.SetRange(0.0, -dBRange);
671 
672  hRuler->ruler.SetLog(false);
673  hRuler->ruler.SetRange(0, 1);
674 
675  DrawBackground(memDC);
676 
677  if (mDataLen < mWindowSize) {
678  wxString msg = _("Not enough data selected.");
679  wxSize sz = memDC.GetTextExtent(msg);
680  memDC.DrawText(msg,
681  (mPlotRect.GetWidth() - sz.GetWidth()) / 2,
682  (mPlotRect.GetHeight() - sz.GetHeight()) / 2);
683  }
684 
685  memDC.SelectObject(wxNullBitmap);
686 
687  mFreqPlot->Refresh();
688 
689  Refresh();
690 
691  return;
692  }
693 
694  float yRange = mYMax - mYMin;
695  float yTotal = yRange * ((float) mZoomSlider->GetValue() / 100.0f);
696 
697  int sTotal = yTotal * 100;
698  int sRange = yRange * 100;
699  int sPos = mPanScroller->GetThumbPosition() + ((mPanScroller->GetThumbSize() - sTotal) / 2);
700  mPanScroller->SetScrollbar(sPos, sTotal, sRange, sTotal);
701 
702  float yMax = mYMax - ((float)sPos / 100);
703  float yMin = yMax - yTotal;
704 
705  // Set up y axis ruler
706 
708  vRuler->ruler.SetUnits(_("dB"));
710  } else {
711  vRuler->ruler.SetUnits(wxT(""));
713  }
714  int w1, w2, h;
715  vRuler->ruler.GetMaxSize(&w1, &h);
716  vRuler->ruler.SetRange(yMax, yMin); // Note inversion for vertical.
717  vRuler->ruler.GetMaxSize(&w2, &h);
718  if( w1 != w2 ) // Reduces flicker
719  {
720  vRuler->SetMinSize(wxSize(w2,h));
721  Layout();
722  }
723  vRuler->Refresh(false);
724 
725  wxMemoryDC memDC;
726  DrawBackground(memDC);
727 
728  // Get the plot dimensions
729  //
730  // Must be done after setting the vertical ruler above since the
731  // the width could change.
732  wxRect r = mPlotRect;
733 
734  // Set up x axis ruler
735 
736  int width = r.width - 2;
737 
738  float xMin, xMax, xRatio, xStep;
739 
741  xMin = mRate / mWindowSize;
742  xMax = mRate / 2;
743  xRatio = xMax / xMin;
744  if (mLogAxis)
745  {
746  xStep = pow(2.0f, (log(xRatio) / log(2.0f)) / width);
747  hRuler->ruler.SetLog(true);
748  }
749  else
750  {
751  xStep = (xMax - xMin) / width;
752  hRuler->ruler.SetLog(false);
753  }
754  hRuler->ruler.SetUnits(_("Hz"));
755  } else {
756  xMin = 0;
757  xMax = mAnalyst->GetProcessedSize() / mRate;
758  xStep = (xMax - xMin) / width;
759  hRuler->ruler.SetLog(false);
760  hRuler->ruler.SetUnits(_("s"));
761  }
762  hRuler->ruler.SetRange(xMin, xMax-xStep);
763  hRuler->Refresh(false);
764 
765  // Draw the plot
767  memDC.SetPen(wxPen(theTheme.Colour( clrHzPlot ), 1, wxSOLID));
768  else
769  memDC.SetPen(wxPen(theTheme.Colour( clrWavelengthPlot), 1, wxSOLID));
770 
771  float xPos = xMin;
772 
773  for (int i = 0; i < width; i++) {
774  float y;
775 
776  if (mLogAxis)
777  y = mAnalyst->GetProcessedValue(xPos, xPos * xStep);
778  else
779  y = mAnalyst->GetProcessedValue(xPos, xPos + xStep);
780 
781  float ynorm = (y - yMin) / yTotal;
782 
783  int lineheight = (int)(ynorm * (r.height - 1));
784 
785  if (lineheight > r.height - 2)
786  lineheight = r.height - 2;
787 
788  if (ynorm > 0.0)
789  AColor::Line(memDC, r.x + 1 + i, r.y + r.height - 1 - lineheight,
790  r.x + 1 + i, r.y + r.height - 1);
791 
792  if (mLogAxis)
793  xPos *= xStep;
794  else
795  xPos += xStep;
796  }
797 
798  // Outline the graph
799  memDC.SetPen(*wxBLACK_PEN);
800  memDC.SetBrush(*wxTRANSPARENT_BRUSH);
801  memDC.DrawRectangle(r);
802 
803  if(mDrawGrid)
804  {
805  hRuler->ruler.DrawGrid(memDC, r.height, true, true, 1, 1);
806  vRuler->ruler.DrawGrid(memDC, r.width, true, true, 1, 1);
807  }
808 
809  memDC.SelectObject( wxNullBitmap );
810 
811  mFreqPlot->Refresh();
812 }
float mYMin
Definition: FreqWindow.h:207
void SetLog(bool log)
Definition: Ruler.cpp:199
double mRate
Definition: FreqWindow.h:201
AUDACITY_DLL_API Theme theTheme
Definition: Theme.cpp:209
wxRect mPlotRect
Definition: FreqWindow.h:180
std::unique_ptr< SpectrumAnalyst > mAnalyst
Definition: FreqWindow.h:216
void GetMaxSize(wxCoord *width, wxCoord *height)
Definition: Ruler.cpp:1549
bool mDrawGrid
Definition: FreqWindow.h:161
Floats mData
Definition: FreqWindow.h:203
RulerPanel * hRuler
Definition: FreqWindow.h:176
bool mLogAxis
Definition: FreqWindow.h:206
size_t mWindowSize
Definition: FreqWindow.h:204
wxScrollBar * mPanScroller
Definition: FreqWindow.h:195
void DrawBackground(wxMemoryDC &dc)
Definition: FreqWindow.cpp:642
float mYMax
Definition: FreqWindow.h:208
void SetUnits(const wxString &units)
Definition: Ruler.cpp:210
FreqPlot * mFreqPlot
Definition: FreqWindow.h:177
SpectrumAnalyst::Algorithm mAlg
Definition: FreqWindow.h:163
static void Line(wxDC &dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
Definition: AColor.cpp:122
wxSlider * mZoomSlider
Definition: FreqWindow.h:196
_("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:1465
void SetFormat(RulerFormat format)
Definition: Ruler.cpp:188
void SetRange(double min, double max)
Definition: Ruler.cpp:236
wxColour & Colour(int iIndex)
Definition: Theme.cpp:1225
size_t mDataLen
Definition: FreqWindow.h:202
RulerPanel * vRuler
Definition: FreqWindow.h:175
Ruler ruler
Definition: Ruler.h:306
void FreqWindow::GetAudio ( )
private

Definition at line 573 of file FreqWindow.cpp.

References _(), AudacityMessageBox(), fillZero, floatSample, WaveTrack::Get(), WaveTrack::GetRate(), AudacityProject::GetTracks(), mData, mDataLen, mRate, AudacityProject::mViewInfo, p, ViewInfo::selectedRegion, SelectedRegion::t0(), SelectedRegion::t1(), WaveTrack::TimeToLongSamples(), and Track::Wave.

Referenced by OnReplot(), and Show().

574 {
575  mData.reset();
576  mDataLen = 0;
577 
578  int selcount = 0;
579  bool warning = false;
580  TrackListIterator iter(p->GetTracks());
581  Track *t = iter.First();
582  while (t) {
583  if (t->GetSelected() && t->GetKind() == Track::Wave) {
584  WaveTrack *track = (WaveTrack *)t;
585  if (selcount==0) {
586  mRate = track->GetRate();
587  auto start = track->TimeToLongSamples(p->mViewInfo.selectedRegion.t0());
588  auto end = track->TimeToLongSamples(p->mViewInfo.selectedRegion.t1());
589  auto dataLen = end - start;
590  if (dataLen > 10485760) {
591  warning = true;
592  mDataLen = 10485760;
593  }
594  else
595  // dataLen is not more than 10 * 2 ^ 20
596  mDataLen = dataLen.as_size_t();
597  mData = Floats{ mDataLen };
598  // Don't allow throw for bad reads
599  track->Get((samplePtr)mData.get(), floatSample, start, mDataLen,
600  fillZero, false);
601  }
602  else {
603  if (track->GetRate() != mRate) {
604  AudacityMessageBox(_("To plot the spectrum, all selected tracks must be the same sample rate."));
605  mData.reset();
606  mDataLen = 0;
607  return;
608  }
609  auto start = track->TimeToLongSamples(p->mViewInfo.selectedRegion.t0());
610  Floats buffer2{ mDataLen };
611  // Again, stop exceptions
612  track->Get((samplePtr)buffer2.get(), floatSample, start, mDataLen,
613  fillZero, false);
614  for (size_t i = 0; i < mDataLen; i++)
615  mData[i] += buffer2[i];
616  }
617  selcount++;
618  }
619  t = iter.Next();
620  }
621 
622  if (selcount == 0)
623  return;
624 
625  if (warning) {
626  wxString msg;
627  msg.Printf(_("Too much audio was selected. Only the first %.1f seconds of audio will be analyzed."),
628  (mDataLen / mRate));
629  AudacityMessageBox(msg);
630  }
631 }
double mRate
Definition: FreqWindow.h:201
double t0() const
SelectedRegion selectedRegion
Definition: ViewInfo.h:160
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:203
char * samplePtr
Definition: Types.h:203
A Track that contains audio waveform data.
Definition: WaveTrack.h:60
Fundamental data object of Audacity, placed in the TrackPanel. Classes derived form it include the Wa...
Definition: Track.h:102
ViewInfo mViewInfo
Definition: Project.h:558
An iterator for a TrackList.
Definition: Track.h:402
_("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:167
sampleCount TimeToLongSamples(double t0) const
Convert correctly between an (absolute) time in seconds and a number of samples.
Definition: WaveTrack.cpp:1843
size_t mDataLen
Definition: FreqWindow.h:202
double GetRate() const
Definition: WaveTrack.cpp:398
bool Get(samplePtr buffer, sampleFormat format, sampleCount start, size_t len, fillFormat fill=fillZero, bool mayThrow=true, sampleCount *pNumCopied=nullptr) const
Definition: WaveTrack.cpp:1971
TrackList * GetTracks()
Definition: Project.h:192
void FreqWindow::OnAlgChoice ( wxCommandEvent &  event)
private

Definition at line 840 of file FreqWindow.cpp.

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

841 {
842  mAlg = SpectrumAnalyst::Algorithm(mAlgChoice->GetSelection());
843 
844  // Log-frequency axis works for spectrum plots only.
846  mAxisChoice->Enable(true);
847  mLogAxis = mAxisChoice->GetSelection() ? true : false;
848  }
849  else {
850  mAxisChoice->Disable();
851  mLogAxis = false;
852  }
853 
854  SendRecalcEvent();
855 }
wxChoice * mAlgChoice
Definition: FreqWindow.h:191
bool mLogAxis
Definition: FreqWindow.h:206
SpectrumAnalyst::Algorithm mAlg
Definition: FreqWindow.h:163
void SendRecalcEvent()
Definition: FreqWindow.cpp:999
wxChoice * mAxisChoice
Definition: FreqWindow.h:194
void FreqWindow::OnAxisChoice ( wxCommandEvent &  event)
private

Definition at line 871 of file FreqWindow.cpp.

References DrawPlot(), mAxisChoice, and mLogAxis.

872 {
873  mLogAxis = mAxisChoice->GetSelection() ? true : false;
874  DrawPlot();
875 }
bool mLogAxis
Definition: FreqWindow.h:206
wxChoice * mAxisChoice
Definition: FreqWindow.h:194
void DrawPlot()
Definition: FreqWindow.cpp:664
void FreqWindow::OnCloseButton ( wxCommandEvent &  event)
private

Definition at line 988 of file FreqWindow.cpp.

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

989 {
990  gPrefs->Write(wxT("/FreqWindow/DrawGrid"), mDrawGrid);
991  gPrefs->Write(wxT("/FreqWindow/SizeChoice"), mSizeChoice->GetSelection());
992  gPrefs->Write(wxT("/FreqWindow/AlgChoice"), mAlgChoice->GetSelection());
993  gPrefs->Write(wxT("/FreqWindow/FuncChoice"), mFuncChoice->GetSelection());
994  gPrefs->Write(wxT("/FreqWindow/AxisChoice"), mAxisChoice->GetSelection());
995  gPrefs->Flush();
996  Show(false);
997 }
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73
bool mDrawGrid
Definition: FreqWindow.h:161
wxChoice * mAlgChoice
Definition: FreqWindow.h:191
wxChoice * mAxisChoice
Definition: FreqWindow.h:194
wxChoice * mSizeChoice
Definition: FreqWindow.h:192
bool Show(bool show=true) override
Definition: FreqWindow.cpp:547
wxChoice * mFuncChoice
Definition: FreqWindow.h:193
void FreqWindow::OnCloseWindow ( wxCloseEvent &  event)
private

Definition at line 983 of file FreqWindow.cpp.

References Show().

984 {
985  Show(false);
986 }
bool Show(bool show=true) override
Definition: FreqWindow.cpp:547
void FreqWindow::OnExport ( wxCommandEvent &  event)
private

Definition at line 1050 of file FreqWindow.cpp.

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

1051 {
1052  wxString fName = _("spectrum.txt");
1053 
1055  _("Export Spectral Data As:"),
1056  wxEmptyString, fName, wxT("txt"), wxT("*.txt"), wxFD_SAVE | wxRESIZE_BORDER, this);
1057 
1058  if (fName == wxT(""))
1059  return;
1060 
1061  wxTextFile f(fName);
1062 #ifdef __WXMAC__
1063  wxFile{}.Create(fName);
1064 #else
1065  f.Create();
1066 #endif
1067  f.Open();
1068  if (!f.IsOpened()) {
1069  AudacityMessageBox( wxString::Format(
1070  _("Couldn't write to file: %s"), fName ) );
1071  return;
1072  }
1073 
1074  const int processedSize = mAnalyst->GetProcessedSize();
1075  const float *const processed = mAnalyst->GetProcessed();
1076  if (mAlgChoice->GetSelection() == 0) {
1077  f.AddLine(_("Frequency (Hz)\tLevel (dB)"));
1078  for (int i = 1; i < processedSize; i++)
1079  f.AddLine(wxString::
1080  Format(wxT("%f\t%f"), i * mRate / mWindowSize,
1081  processed[i]));
1082  } else {
1083  f.AddLine(_("Lag (seconds)\tFrequency (Hz)\tLevel"));
1084  for (int i = 1; i < processedSize; i++)
1085  f.AddLine(wxString::Format(wxT("%f\t%f\t%f"),
1086  i / mRate, mRate / i, processed[i]));
1087  }
1088 
1089 #ifdef __WXMAC__
1090  f.Write(wxTextFileType_Mac);
1091 #else
1092  f.Write();
1093 #endif
1094  f.Close();
1095 }
double mRate
Definition: FreqWindow.h:201
Abstract base class used in importing a file.
Definition: Import.h:32
std::unique_ptr< SpectrumAnalyst > mAnalyst
Definition: FreqWindow.h:216
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:191
size_t mWindowSize
Definition: FreqWindow.h:204
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:411
_("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 866 of file FreqWindow.cpp.

References SendRecalcEvent().

867 {
868  SendRecalcEvent();
869 }
void SendRecalcEvent()
Definition: FreqWindow.cpp:999
void FreqWindow::OnGetURL ( wxCommandEvent &  event)
private

Definition at line 540 of file FreqWindow.cpp.

References HelpSystem::ShowHelp().

541 {
542  // Original help page is back on-line (March 2016), but the manual should be more reliable.
543  // http://www.eramp.com/WCAG_2_audio_contrast_tool_help.htm
544  HelpSystem::ShowHelp(this, wxT("Plot Spectrum"));
545 }
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 1106 of file FreqWindow.cpp.

References DrawPlot(), mDrawGrid, and mGridOnOff.

1107 {
1108  mDrawGrid = mGridOnOff->IsChecked();
1109 
1110  DrawPlot();
1111 }
wxCheckBox * mGridOnOff
Definition: FreqWindow.h:190
bool mDrawGrid
Definition: FreqWindow.h:161
void DrawPlot()
Definition: FreqWindow.cpp:664
void FreqWindow::OnPanScroller ( wxScrollEvent &  event)
private

Definition at line 830 of file FreqWindow.cpp.

References DrawPlot().

831 {
832  DrawPlot();
833 }
void DrawPlot()
Definition: FreqWindow.cpp:664
void FreqWindow::OnRecalc ( wxCommandEvent &  event)
private

Definition at line 1113 of file FreqWindow.cpp.

References Recalc().

1114 {
1115  Recalc();
1116 }
void Recalc()
void FreqWindow::OnReplot ( wxCommandEvent &  event)
private

Definition at line 1097 of file FreqWindow.cpp.

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

1098 {
1100  if(dBRange < 90.)
1101  dBRange = 90.;
1102  GetAudio();
1103  SendRecalcEvent();
1104 }
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:573
void SendRecalcEvent()
Definition: FreqWindow.cpp:999
void FreqWindow::OnSize ( wxSizeEvent &  event)
private

Definition at line 633 of file FreqWindow.cpp.

References DrawPlot().

634 {
635  Layout();
636 
637  DrawPlot();
638 
639  Refresh(true);
640 }
void DrawPlot()
Definition: FreqWindow.cpp:664
void FreqWindow::OnSizeChoice ( wxCommandEvent &  event)
private

Definition at line 857 of file FreqWindow.cpp.

References mSizeChoice, mWindowSize, and SendRecalcEvent().

858 {
859  long windowSize = 0;
860  mSizeChoice->GetStringSelection().ToLong(&windowSize);
861  mWindowSize = windowSize;
862 
863  SendRecalcEvent();
864 }
size_t mWindowSize
Definition: FreqWindow.h:204
void SendRecalcEvent()
Definition: FreqWindow.cpp:999
wxChoice * mSizeChoice
Definition: FreqWindow.h:192
void FreqWindow::OnZoomSlider ( wxCommandEvent &  event)
private

Definition at line 835 of file FreqWindow.cpp.

References DrawPlot().

836 {
837  DrawPlot();
838 }
void DrawPlot()
Definition: FreqWindow.cpp:664
void FreqWindow::PlotMouseEvent ( wxMouseEvent &  event)
private

Definition at line 815 of file FreqWindow.cpp.

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

Referenced by FreqPlot::OnMouseEvent().

816 {
817  if (event.Moving() && (event.m_x != mMouseX || event.m_y != mMouseY)) {
818  mMouseX = event.m_x;
819  mMouseY = event.m_y;
820 
821  if (mPlotRect.Contains(mMouseX, mMouseY))
822  mFreqPlot->SetCursor(*mCrossCursor);
823  else
824  mFreqPlot->SetCursor(*mArrowCursor);
825 
826  mFreqPlot->Refresh(false);
827  }
828 }
wxRect mPlotRect
Definition: FreqWindow.h:180
std::unique_ptr< wxCursor > mArrowCursor
Definition: FreqWindow.h:184
FreqPlot * mFreqPlot
Definition: FreqWindow.h:177
std::unique_ptr< wxCursor > mCrossCursor
Definition: FreqWindow.h:185
void FreqWindow::PlotPaint ( wxPaintEvent &  event)
private

Definition at line 877 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().

878 {
879  wxPaintDC dc( (wxWindow *) event.GetEventObject() );
880 
881  dc.DrawBitmap( *mBitmap, 0, 0, true );
882  // Fix for Bug 1226 "Plot Spectrum freezes... if insufficient samples selected"
883  if (!mData || mDataLen < mWindowSize)
884  return;
885 
886  dc.SetFont(mFreqFont);
887 
888  wxRect r = mPlotRect;
889 
890  int width = r.width - 2;
891 
892  float xMin, xMax, xRatio, xStep;
893 
895  xMin = mRate / mWindowSize;
896  xMax = mRate / 2;
897  xRatio = xMax / xMin;
898  if (mLogAxis)
899  xStep = pow(2.0f, (log(xRatio) / log(2.0f)) / width);
900  else
901  xStep = (xMax - xMin) / width;
902  } else {
903  xMin = 0;
904  xMax = mAnalyst->GetProcessedSize() / mRate;
905  xStep = (xMax - xMin) / width;
906  }
907 
908  float xPos = xMin;
909 
910  // Find the peak nearest the cursor and plot it
911  if ( r.Contains(mMouseX, mMouseY) & (mMouseX!=0) & (mMouseX!=r.width-1) ) {
912  if (mLogAxis)
913  xPos = xMin * pow(xStep, mMouseX - (r.x + 1));
914  else
915  xPos = xMin + xStep * (mMouseX - (r.x + 1));
916 
917  float bestValue = 0;
918  float bestpeak = mAnalyst->FindPeak(xPos, &bestValue);
919 
920  int px;
921  if (mLogAxis)
922  px = (int)(log(bestpeak / xMin) / log(xStep));
923  else
924  px = (int)((bestpeak - xMin) * width / (xMax - xMin));
925 
926  dc.SetPen(wxPen(wxColour(160,160,160), 1, wxSOLID));
927  AColor::Line(dc, r.x + 1 + px, r.y, r.x + 1 + px, r.y + r.height);
928 
929  // print out info about the cursor location
930 
931  float value;
932 
933  if (mLogAxis) {
934  xPos = xMin * pow(xStep, mMouseX - (r.x + 1));
935  value = mAnalyst->GetProcessedValue(xPos, xPos * xStep);
936  } else {
937  xPos = xMin + xStep * (mMouseX - (r.x + 1));
938  value = mAnalyst->GetProcessedValue(xPos, xPos + xStep);
939  }
940 
941  wxString cursor;
942  wxString peak;
943  wxString xpitch;
944  wxString peakpitch;
945  const wxChar *xp;
946  const wxChar *pp;
947 
949  xpitch = PitchName_Absolute(FreqToMIDInote(xPos));
950  peakpitch = PitchName_Absolute(FreqToMIDInote(bestpeak));
951  xp = xpitch;
952  pp = peakpitch;
953  /* i18n-hint: The %d's are replaced by numbers, the %s by musical notes, e.g. A#*/
954  cursor.Printf(_("%d Hz (%s) = %d dB"), (int)(xPos + 0.5), xp, (int)(value + 0.5));
955  peak.Printf(_("%d Hz (%s) = %.1f dB"), (int)(bestpeak + 0.5), pp, bestValue);
956  } else if (xPos > 0.0 && bestpeak > 0.0) {
957  xpitch = PitchName_Absolute(FreqToMIDInote(1.0 / xPos));
958  peakpitch = PitchName_Absolute(FreqToMIDInote(1.0 / bestpeak));
959  xp = xpitch;
960  pp = peakpitch;
961  /* i18n-hint: The %d's are replaced by numbers, the %s by musical notes, e.g. A#
962  * the %.4f are numbers, and 'sec' should be an abbreviation for seconds */
963  cursor.Printf(_("%.4f sec (%d Hz) (%s) = %f"),
964  xPos, (int)(1.0 / xPos + 0.5), xp, value);
965  peak.Printf(_("%.4f sec (%d Hz) (%s) = %.3f"),
966  bestpeak, (int)(1.0 / bestpeak + 0.5), pp, bestValue);
967  }
968  mCursorText->SetValue(cursor);
969  mPeakText->SetValue(peak);
970  }
971  else {
972  mCursorText->SetValue(wxT(""));
973  mPeakText->SetValue(wxT(""));
974  }
975 
976 
977  // Outline the graph
978  dc.SetPen(*wxBLACK_PEN);
979  dc.SetBrush(*wxTRANSPARENT_BRUSH);
980  dc.DrawRectangle(r);
981 }
double mRate
Definition: FreqWindow.h:201
wxRect mPlotRect
Definition: FreqWindow.h:180
std::unique_ptr< SpectrumAnalyst > mAnalyst
Definition: FreqWindow.h:216
std::unique_ptr< wxBitmap > mBitmap
Definition: FreqWindow.h:211
Floats mData
Definition: FreqWindow.h:203
double FreqToMIDInote(const double freq)
Definition: PitchName.cpp:28
bool mLogAxis
Definition: FreqWindow.h:206
wxTextCtrl * mCursorText
Definition: FreqWindow.h:197
size_t mWindowSize
Definition: FreqWindow.h:204
wxString PitchName_Absolute(const double dMIDInote, const PitchNameChoice choice)
Definition: PitchName.cpp:153
SpectrumAnalyst::Algorithm mAlg
Definition: FreqWindow.h:163
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:182
wxTextCtrl * mPeakText
Definition: FreqWindow.h:198
size_t mDataLen
Definition: FreqWindow.h:202
void FreqWindow::Recalc ( )
private

Definition at line 1005 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().

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

Definition at line 999 of file FreqWindow.cpp.

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

1000 {
1001  wxCommandEvent e(EVT_FREQWINDOW_RECALC, wxID_ANY);
1002  GetEventHandler()->AddPendingEvent(e);
1003 }
bool FreqWindow::Show ( bool  show = true)
override

Definition at line 547 of file FreqWindow.cpp.

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

Referenced by OnCloseButton(), and OnCloseWindow().

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

Friends And Related Function Documentation

friend class FreqPlot
friend

Definition at line 220 of file FreqWindow.h.

Referenced by FreqWindow().

Member Data Documentation

int FreqWindow::dBRange
private

Definition at line 166 of file FreqWindow.h.

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

const int FreqWindow::fontSize = 10
staticprivate

Definition at line 172 of file FreqWindow.h.

Referenced by FreqWindow().

RulerPanel* FreqWindow::hRuler
private

Definition at line 176 of file FreqWindow.h.

Referenced by DrawPlot(), and FreqWindow().

SpectrumAnalyst::Algorithm FreqWindow::mAlg
private

Definition at line 163 of file FreqWindow.h.

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

wxChoice* FreqWindow::mAlgChoice
private

Definition at line 191 of file FreqWindow.h.

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

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

Definition at line 216 of file FreqWindow.h.

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

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

Definition at line 184 of file FreqWindow.h.

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

int FreqWindow::mAxis
private

Definition at line 165 of file FreqWindow.h.

Referenced by FreqWindow().

wxChoice* FreqWindow::mAxisChoice
private

Definition at line 194 of file FreqWindow.h.

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

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

Definition at line 211 of file FreqWindow.h.

Referenced by DrawBackground(), and PlotPaint().

wxButton* FreqWindow::mCloseButton
private

Definition at line 187 of file FreqWindow.h.

Referenced by FreqWindow().

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

Definition at line 185 of file FreqWindow.h.

Referenced by FreqWindow(), and PlotMouseEvent().

wxTextCtrl* FreqWindow::mCursorText
private

Definition at line 197 of file FreqWindow.h.

Referenced by FreqWindow(), and PlotPaint().

Floats FreqWindow::mData
private

Definition at line 203 of file FreqWindow.h.

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

size_t FreqWindow::mDataLen
private

Definition at line 202 of file FreqWindow.h.

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

bool FreqWindow::mDrawGrid
private

Definition at line 161 of file FreqWindow.h.

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

wxButton* FreqWindow::mExportButton
private

Definition at line 188 of file FreqWindow.h.

Referenced by FreqWindow().

wxFont FreqWindow::mFreqFont
private

Definition at line 182 of file FreqWindow.h.

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

FreqPlot* FreqWindow::mFreqPlot
private

Definition at line 177 of file FreqWindow.h.

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

int FreqWindow::mFunc
private

Definition at line 164 of file FreqWindow.h.

Referenced by FreqWindow().

wxChoice* FreqWindow::mFuncChoice
private

Definition at line 193 of file FreqWindow.h.

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

wxCheckBox* FreqWindow::mGridOnOff
private

Definition at line 190 of file FreqWindow.h.

Referenced by FreqWindow(), and OnGridOnOff().

bool FreqWindow::mLogAxis
private

Definition at line 206 of file FreqWindow.h.

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

int FreqWindow::mMouseX
private

Definition at line 213 of file FreqWindow.h.

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

int FreqWindow::mMouseY
private

Definition at line 214 of file FreqWindow.h.

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

wxScrollBar* FreqWindow::mPanScroller
private

Definition at line 195 of file FreqWindow.h.

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

wxTextCtrl* FreqWindow::mPeakText
private

Definition at line 198 of file FreqWindow.h.

Referenced by FreqWindow(), and PlotPaint().

wxRect FreqWindow::mPlotRect
private

Definition at line 180 of file FreqWindow.h.

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

FreqGauge* FreqWindow::mProgress
private

Definition at line 178 of file FreqWindow.h.

Referenced by FreqWindow(), and Recalc().

double FreqWindow::mRate
private

Definition at line 201 of file FreqWindow.h.

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

wxButton* FreqWindow::mReplotButton
private

Definition at line 189 of file FreqWindow.h.

Referenced by FreqWindow().

int FreqWindow::mSize
private

Definition at line 162 of file FreqWindow.h.

Referenced by FreqWindow().

wxChoice* FreqWindow::mSizeChoice
private

Definition at line 192 of file FreqWindow.h.

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

size_t FreqWindow::mWindowSize
private

Definition at line 204 of file FreqWindow.h.

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

float FreqWindow::mYMax
private

Definition at line 208 of file FreqWindow.h.

Referenced by DrawPlot(), and Recalc().

float FreqWindow::mYMin
private

Definition at line 207 of file FreqWindow.h.

Referenced by DrawPlot(), and Recalc().

float FreqWindow::mYStep
private

Definition at line 209 of file FreqWindow.h.

wxSlider* FreqWindow::mZoomSlider
private

Definition at line 196 of file FreqWindow.h.

Referenced by DrawPlot(), and FreqWindow().

AudacityProject* FreqWindow::p
private

Definition at line 167 of file FreqWindow.h.

Referenced by FreqWindow(), and GetAudio().

RulerPanel* FreqWindow::vRuler
private

Definition at line 175 of file FreqWindow.h.

Referenced by DrawPlot(), and FreqWindow().


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