Audacity 3.2.0
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
ContrastDialog Class Referencefinal

#include <Contrast.h>

Inheritance diagram for ContrastDialog:
[legend]
Collaboration diagram for ContrastDialog:
[legend]

Public Member Functions

 ContrastDialog (wxWindow *parent, wxWindowID id, const TranslatableString &title, const wxPoint &pos)
 
- Public Member Functions inherited from wxDialogWrapper
 wxDialogWrapper ()
 
 wxDialogWrapper (wxWindow *parent, wxWindowID id, const TranslatableString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE, const TranslatableString &name=XO("Dialog"))
 
bool Create (wxWindow *parent, wxWindowID id, const TranslatableString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE, const TranslatableString &name=XO("Dialog"))
 
void SetTitle (const TranslatableString &title)
 
void SetLabel (const TranslatableString &title)
 
void SetName (const TranslatableString &title)
 
void SetName ()
 
- Public Member Functions inherited from wxTabTraversalWrapper< wxDialog >
 wxTabTraversalWrapper (Args &&... args)
 
 wxTabTraversalWrapper (const wxTabTraversalWrapper &)=delete
 
 wxTabTraversalWrapper (wxTabTraversalWrapper &&)=delete
 
wxTabTraversalWrapperoperator= (const wxTabTraversalWrapper &)=delete
 
wxTabTraversalWrapperoperator= (wxTabTraversalWrapper &&)=delete
 

Public Attributes

wxButton * m_pButton_UseCurrentF
 
wxButton * m_pButton_UseCurrentB
 
wxButton * m_pButton_GetURL
 
wxButton * m_pButton_Export
 
wxButton * m_pButton_Reset
 
wxButton * m_pButton_Close
 
NumericTextCtrlmForegroundStartT
 
NumericTextCtrlmForegroundEndT
 
NumericTextCtrlmBackgroundStartT
 
NumericTextCtrlmBackgroundEndT
 
double mT0
 
double mT1
 
double mProjectRate
 
double mStartTimeF
 
double mEndTimeF
 
double mStartTimeB
 
double mEndTimeB
 

Private Member Functions

void OnChar (wxKeyEvent &event)
 
void OnGetURL (wxCommandEvent &event)
 
void OnExport (wxCommandEvent &event)
 
void OnGetForeground (wxCommandEvent &event)
 
void OnGetBackground (wxCommandEvent &event)
 
void results ()
 
void OnReset (wxCommandEvent &event)
 
void OnClose (wxCommandEvent &event)
 
bool GetDB (float &dB)
 
void SetStartAndEndTime ()
 

Private Attributes

wxTextCtrl * mForegroundRMSText
 
wxTextCtrl * mBackgroundRMSText
 
wxTextCtrl * mPassFailText
 
wxTextCtrl * mDiffText
 
float foregrounddB
 
float backgrounddB
 
bool mForegroundIsDefined
 
bool mBackgroundIsDefined
 
double mT0orig
 
double mT1orig
 
bool mDoBackground
 
double length
 

Detailed Description

Definition at line 27 of file Contrast.h.

Constructor & Destructor Documentation

◆ ContrastDialog()

ContrastDialog::ContrastDialog ( wxWindow *  parent,
wxWindowID  id,
const TranslatableString title,
const wxPoint &  pos 
)

Definition at line 194 of file Contrast.cpp.

196 :
197 wxDialogWrapper(parent, id, title, pos, wxDefaultSize,
198 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxMAXIMIZE_BOX )
199{
200 SetName();
201
202 mT0 = 0.0;
203 mT1 = 0.0;
204 foregrounddB = 0.0;
205 backgrounddB = 0.0;
206 mForegroundIsDefined = false;
207 mBackgroundIsDefined = false;
208
209 // NULL out the control members until the controls are created.
210 mForegroundStartT = NULL;
211 mForegroundEndT = NULL;
212 mBackgroundStartT = NULL;
213 mBackgroundEndT = NULL;
214 wxString number;
215
216 auto p = FindProjectFromWindow( this );
218
219 const auto options = NumericTextCtrl::Options{}
220 .AutoPos(true)
221 .MenuEnabled(false)
222 .ReadOnly(true);
223
224 ShuttleGui S(this, eIsCreating);
225
226 S.SetBorder(5);
227 S.StartHorizontalLay(wxCENTER, false);
228 {
229 S.AddTitle(
230 /* i18n-hint: RMS abbreviates root mean square, a certain averaging method */
231 XO("Contrast Analyzer, for measuring RMS volume differences between two selections of audio."));
232 }
233 S.EndHorizontalLay();
234 S.StartStatic( XO("Parameters") );
235 {
236 S.StartMultiColumn(5, wxEXPAND);
237 {
238
239 // Headings
240 S.AddFixedText( {} ); // spacer
241 S.AddFixedText(XO("Start"));
242 S.AddFixedText(XO("End"));
243 S.AddFixedText( {} ); // spacer
244 S.AddFixedText(XO("Volume "));
245
246 //Foreground
247 S.AddFixedText(XO("&Foreground:"), false);
248 if (S.GetMode() == eIsCreating)
249 {
252 S.GetParent(), ID_FOREGROUNDSTART_T,
255 0.0,
256 options);
257 }
258 S.Name(XO("Foreground start time"))
259 .AddWindow(mForegroundStartT);
260
261 if (S.GetMode() == eIsCreating)
262 {
265 S.GetParent(), ID_FOREGROUNDEND_T,
268 0.0,
269 options);
270 }
271 S.Name(XO("Foreground end time"))
272 .AddWindow(mForegroundEndT);
273
274 m_pButton_UseCurrentF = S.Id(ID_BUTTON_USECURRENTF).AddButton(XXO("&Measure selection"));
276 .ConnectRoot(wxEVT_KEY_DOWN,
278 .AddTextBox( {}, wxT(""), 17);
279
280 //Background
281 S.AddFixedText(XO("&Background:"));
282 if (S.GetMode() == eIsCreating)
283 {
286 S.GetParent(), ID_BACKGROUNDSTART_T,
289 0.0,
290 options);
291 }
292 S.Name(XO("Background start time"))
293 .AddWindow(mBackgroundStartT);
294
295 if (S.GetMode() == eIsCreating)
296 {
299 S.GetParent(), ID_BACKGROUNDEND_T,
302 0.0,
303 options);
304 }
305 S.Name(XO("Background end time"))
306 .AddWindow(mBackgroundEndT);
307
308 m_pButton_UseCurrentB = S.Id(ID_BUTTON_USECURRENTB).AddButton(XXO("Mea&sure selection"));
310 .ConnectRoot(wxEVT_KEY_DOWN,
312 .AddTextBox( {}, wxT(""), 17);
313 }
314 S.EndMultiColumn();
315 }
316 S.EndStatic();
317
318 //Result
319 S.StartStatic( XO("Result") );
320 {
321 S.StartMultiColumn(3, wxCENTER);
322 {
323 auto label = XO("Co&ntrast Result:");
324 S.AddFixedText(label);
326 .Name(label)
327 .ConnectRoot(wxEVT_KEY_DOWN,
329 .AddTextBox( {}, wxT(""), 50);
330 m_pButton_Reset = S.Id(ID_BUTTON_RESET).AddButton(XXO("R&eset"));
331
332 label = XO("&Difference:");
333 S.AddFixedText(label);
335 .Name(label)
336 .ConnectRoot(wxEVT_KEY_DOWN,
338 .AddTextBox( {}, wxT(""), 50);
339 m_pButton_Export = S.Id(ID_BUTTON_EXPORT).AddButton(XXO("E&xport..."));
340 }
341 S.EndMultiColumn();
342 }
343 S.EndStatic();
344 S.AddStandardButtons(eCloseButton |eHelpButton);
345#if 0
346 S.StartMultiColumn(3, wxEXPAND);
347 {
348 S.SetStretchyCol(1);
349 m_pButton_GetURL = S.Id(ID_BUTTON_GETURL).AddButton(XO("&Help"));
350 S.AddFixedText({}); // spacer
351 m_pButton_Close = S.Id(ID_BUTTON_CLOSE).AddButton(XO("&Close"));
352 }
353 S.EndMultiColumn();
354#endif
355 Layout();
356 Fit();
357 SetMinSize(GetSize());
358 Center();
359}
wxT("CloseDown"))
@ Internal
Indicates internal failure from Audacity.
@ ID_BACKGROUNDEND_T
Definition: Contrast.cpp:164
@ ID_FOREGROUNDDB_TEXT
Definition: Contrast.cpp:165
@ ID_BACKGROUNDSTART_T
Definition: Contrast.cpp:163
@ ID_BUTTON_RESET
Definition: Contrast.cpp:159
@ ID_BUTTON_USECURRENTF
Definition: Contrast.cpp:155
@ ID_BACKGROUNDDB_TEXT
Definition: Contrast.cpp:166
@ ID_RESULTSDB_TEXT
Definition: Contrast.cpp:168
@ ID_RESULTS_TEXT
Definition: Contrast.cpp:167
@ ID_BUTTON_USECURRENTB
Definition: Contrast.cpp:156
@ ID_FOREGROUNDSTART_T
Definition: Contrast.cpp:161
@ ID_FOREGROUNDEND_T
Definition: Contrast.cpp:162
@ ID_BUTTON_EXPORT
Definition: Contrast.cpp:158
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
#define safenew
Definition: MemoryX.h:9
static const auto title
const NumericConverterType & NumericConverterType_TIME()
AudacityProject * FindProjectFromWindow(wxWindow *pWindow)
@ eIsCreating
Definition: ShuttleGui.h:37
@ eCloseButton
Definition: ShuttleGui.h:619
@ eHelpButton
Definition: ShuttleGui.h:613
TranslatableString label
Definition: TagsEditor.cpp:165
#define S(N)
Definition: ToChars.cpp:64
NumericTextCtrl * mBackgroundStartT
Definition: Contrast.h:43
wxButton * m_pButton_Close
Definition: Contrast.h:39
bool mBackgroundIsDefined
Definition: Contrast.h:73
double mT0
Definition: Contrast.h:46
void OnChar(wxKeyEvent &event)
Definition: Contrast.cpp:180
NumericTextCtrl * mBackgroundEndT
Definition: Contrast.h:44
wxTextCtrl * mBackgroundRMSText
Definition: Contrast.h:66
wxButton * m_pButton_UseCurrentB
Definition: Contrast.h:35
double mProjectRate
Definition: Contrast.h:48
bool mForegroundIsDefined
Definition: Contrast.h:72
double mT1
Definition: Contrast.h:47
NumericTextCtrl * mForegroundStartT
Definition: Contrast.h:41
wxButton * m_pButton_Export
Definition: Contrast.h:37
float foregrounddB
Definition: Contrast.h:70
wxTextCtrl * mForegroundRMSText
Definition: Contrast.h:65
wxButton * m_pButton_Reset
Definition: Contrast.h:38
wxTextCtrl * mDiffText
Definition: Contrast.h:68
wxButton * m_pButton_UseCurrentF
Definition: Contrast.h:34
NumericTextCtrl * mForegroundEndT
Definition: Contrast.h:42
float backgrounddB
Definition: Contrast.h:71
wxTextCtrl * mPassFailText
Definition: Contrast.h:67
wxButton * m_pButton_GetURL
Definition: Contrast.h:36
static FormatterContext SampleRateContext(double sampleRate)
static ProjectRate & Get(AudacityProject &project)
Definition: ProjectRate.cpp:28
double GetRate() const
Definition: ProjectRate.cpp:53
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:640
NUMERIC_FORMATS_API NumericFormatSymbol HundredthsFormat()
Options & MenuEnabled(bool enable)
Options & AutoPos(bool enable)
Options & ReadOnly(bool enable)

References NumericTextCtrl::Options::AutoPos(), backgrounddB, eCloseButton, eHelpButton, eIsCreating, FindProjectFromWindow(), foregrounddB, ProjectRate::Get(), ProjectRate::GetRate(), NumericConverterFormats::HundredthsFormat(), ID_BACKGROUNDDB_TEXT, ID_BACKGROUNDEND_T, ID_BACKGROUNDSTART_T, ID_BUTTON_EXPORT, ID_BUTTON_RESET, ID_BUTTON_USECURRENTB, ID_BUTTON_USECURRENTF, ID_FOREGROUNDDB_TEXT, ID_FOREGROUNDEND_T, ID_FOREGROUNDSTART_T, ID_RESULTS_TEXT, ID_RESULTSDB_TEXT, Internal, label, m_pButton_Close, m_pButton_Export, m_pButton_GetURL, m_pButton_Reset, m_pButton_UseCurrentB, m_pButton_UseCurrentF, mBackgroundEndT, mBackgroundIsDefined, mBackgroundRMSText, mBackgroundStartT, mDiffText, NumericTextCtrl::Options::MenuEnabled(), mForegroundEndT, mForegroundIsDefined, mForegroundRMSText, mForegroundStartT, mPassFailText, mProjectRate, mT0, mT1, NumericConverterType_TIME(), OnChar(), NumericTextCtrl::Options::ReadOnly(), S, safenew, FormatterContext::SampleRateContext(), wxDialogWrapper::SetName(), wxT(), XO(), and XXO().

Here is the call graph for this function:

Member Function Documentation

◆ GetDB()

bool ContrastDialog::GetDB ( float &  dB)
private

Definition at line 54 of file Contrast.cpp.

55{
56 float rms = float(0.0);
57
58 // For stereo tracks: sqrt((mean(L)+mean(R))/2)
59 double meanSq = 0.0;
60
61 auto p = FindProjectFromWindow( this );
62 auto range =
64 auto numberSelectedTracks = range.size();
65 if (numberSelectedTracks > 1) {
67 nullptr,
68 XO("You can only measure one track at a time."),
69 XO("Error"),
70 wxOK);
71 m.ShowModal();
72 return false;
73 }
74 if(numberSelectedTracks == 0) {
76 nullptr,
77 XO("Please select an audio track."),
78 XO("Error"),
79 wxOK);
80 m.ShowModal();
81 return false;
82 }
83
84 const auto first = *range.begin();
85 const auto channels = first->Channels();
86 assert(mT0 <= mT1);
87 // Ignore whitespace beyond ends of track.
88 mT0 = std::max(mT0, first->GetStartTime());
89 mT1 = std::min(mT1, first->GetEndTime());
90 for (auto t : channels) {
91
92 auto SelT0 = t->TimeToLongSamples(mT0);
93 auto SelT1 = t->TimeToLongSamples(mT1);
94
95 if(SelT0 > SelT1)
96 {
98 nullptr,
99 XO("Invalid audio selection.\nPlease ensure that audio is selected."),
100 XO("Error"),
101 wxOK);
102 m.ShowModal();
103 return false;
104 }
105
106 if(SelT0 == SelT1)
107 {
109 nullptr,
110 XO("Nothing to measure.\nPlease select a section of a track."),
111 XO("Error"),
112 wxOK);
113 m.ShowModal();
114 return false;
115 }
116
117 // Don't throw in this analysis dialog
118 rms = WaveChannelUtilities::GetRMS(*t, mT0, mT1, false);
119 meanSq += rms * rms;
120 }
121 // TODO: This works for stereo, provided the audio clips are in both channels.
122 // We should really count gaps between clips as silence.
123 rms = (meanSq > 0.0)
124 ? sqrt( meanSq/static_cast<double>( channels.size() ) )
125 : 0.0;
126
127 // Gives warning C4056, Overflow in floating-point constant arithmetic
128 // -INFINITY is intentional here.
129 // Looks like we are stuck with this warning, as
130 // #pragma warning( disable : 4056)
131 // even around the whole function does not disable it successfully.
132
133 dB = (rms == 0.0)? -INFINITY : LINEAR_TO_DB(rms);
134 return true;
135}
int min(int a, int b)
#define LINEAR_TO_DB(x)
Definition: MemoryX.h:338
Wrap wxMessageDialog so that caption IS translatable.
size_t size() const
How many attachment pointers are in the Site.
Definition: ClientData.h:260
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:314
auto Selected() -> TrackIterRange< TrackType >
Definition: Track.h:967
A Track that contains audio waveform data.
Definition: WaveTrack.h:203
#define INFINITY
WAVE_TRACK_API float GetRMS(const WaveChannel &channel, double t0, double t1, bool mayThrow=true)
__finl float_x4 __vecc sqrt(const float_x4 &a)

References FindProjectFromWindow(), TrackList::Get(), WaveChannelUtilities::GetRMS(), INFINITY, LINEAR_TO_DB, min(), mT0, mT1, TrackList::Selected(), ClientData::Site< Host, ClientData, ObjectCopyingPolicy, Pointer, ObjectLockingPolicy, RegistryLockingPolicy >::size(), staffpad::audio::simd::sqrt(), and XO().

Referenced by OnGetBackground(), and OnGetForeground().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnChar()

void ContrastDialog::OnChar ( wxKeyEvent &  event)
private

Definition at line 180 of file Contrast.cpp.

181{
182 // Is this still required?
183 if (event.GetKeyCode() == WXK_TAB) {
184 // pass to next handler
185 event.Skip();
186 return;
187 }
188
189 // ignore any other key
190 event.Skip(false);
191 return;
192}

Referenced by ContrastDialog().

Here is the caller graph for this function:

◆ OnClose()

void ContrastDialog::OnClose ( wxCommandEvent &  event)
private

Definition at line 368 of file Contrast.cpp.

369{
370 wxCommandEvent dummyEvent;
371 OnReset(dummyEvent);
372
373 Show(false);
374}
void OnReset(wxCommandEvent &event)
Definition: Contrast.cpp:636
IMPORT_EXPORT_API ExportResult Show(ExportTask exportTask)

References OnReset(), and ExportProgressUI::Show().

Here is the call graph for this function:

◆ OnExport()

void ContrastDialog::OnExport ( wxCommandEvent &  event)
private

Definition at line 530 of file Contrast.cpp.

531{
532 // TODO: Handle silence checks better (-infinity dB)
533 auto project = FindProjectFromWindow( this );
534 wxString fName = wxT("contrast.txt");
535
536 fName = SelectFile(FileNames::Operation::Export,
537 XO("Export Contrast Result As:"),
538 wxEmptyString,
539 fName,
540 wxT("txt"),
542 wxFD_SAVE | wxRESIZE_BORDER,
543 this);
544
545 if (fName.empty())
546 return;
547
548 wxFFileOutputStream ffStream{ fName };
549
550 if (!ffStream.IsOk()) {
551 AudacityMessageBox( XO("Couldn't write to file: %s").Format( fName ) );
552 return;
553 }
554
555 wxTextOutputStream ss(ffStream);
556
557 ss
558 << wxT("===================================") << '\n'
559 /* i18n-hint: WCAG abbreviates Web Content Accessibility Guidelines */
560 << XO("WCAG 2.0 Success Criteria 1.4.7 Contrast Results") << '\n'
561 << '\n'
562 << XO("Filename = %s.").Format( ProjectFileIO::Get(*project).GetFileName() ) << '\n'
563 << '\n'
564 << XO("Foreground") << '\n';
565
566 float t = (float)mForegroundStartT->GetValue();
567 int h = (int)(t/3600); // there must be a standard function for this!
568 int m = (int)((t - h*3600)/60);
569 float s = t - h*3600.0 - m*60.0;
570
571 ss
572 << XO("Time started = %2d hour(s), %2d minute(s), %.2f seconds.")
573 .Format( h, m, s ) << '\n';
574
575 t = (float)mForegroundEndT->GetValue();
576 h = (int)(t/3600);
577 m = (int)((t - h*3600)/60);
578 s = t - h*3600.0 - m*60.0;
579
580 ss
581 << XO("Time ended = %2d hour(s), %2d minute(s), %.2f seconds.")
582 .Format( h, m, s ) << '\n'
583 << FormatRMSMessage( mForegroundIsDefined ? &foregrounddB : nullptr ) << '\n'
584 << '\n'
585 << XO("Background") << '\n';
586
587 t = (float)mBackgroundStartT->GetValue();
588 h = (int)(t/3600);
589 m = (int)((t - h*3600)/60);
590 s = t - h*3600.0 - m*60.0;
591
592 ss
593 << XO("Time started = %2d hour(s), %2d minute(s), %.2f seconds.")
594 .Format( h, m, s ) << '\n';
595
596 t = (float)mBackgroundEndT->GetValue();
597 h = (int)(t/3600);
598 m = (int)((t - h*3600)/60);
599 s = t - h*3600.0 - m*60.0;
600
601 ss
602 << XO("Time ended = %2d hour(s), %2d minute(s), %.2f seconds.")
603 .Format( h, m, s ) << '\n'
604 << FormatRMSMessage( mBackgroundIsDefined ? &backgrounddB : nullptr ) << '\n'
605 << '\n'
606 << XO("Results") << '\n';
607
608 float diffdB = foregrounddB - backgrounddB;
609
610 ss
611 << FormatDifferenceForExport( diffdB ) << '\n'
612 << (( diffdB > 20. )
613 ? XO("Success Criteria 1.4.7 of WCAG 2.0: Pass")
614 : XO("Success Criteria 1.4.7 of WCAG 2.0: Fail")) << '\n'
615 << '\n'
616 << XO("Data gathered") << '\n';
617
618 wxDateTime now = wxDateTime::Now();
619 int year = now.GetYear();
620 wxDateTime::Month month = now.GetMonth();
621 wxString monthName = now.GetMonthName(month);
622 int dom = now.GetDay();
623 int hour = now.GetHour();
624 int minute = now.GetMinute();
625 int second = now.GetSecond();
626 /* i18n-hint: day of month, month, year, hour, minute, second */
627 auto sNow = XO("%d %s %02d %02dh %02dm %02ds")
628 .Format( dom, monthName, year, hour, minute, second );
629
630 ss <<
631 sNow << '\n'
632 << wxT("===================================") << '\n'
633 << '\n';
634}
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
FilePath SelectFile(FileNames::Operation op, const TranslatableString &message, const FilePath &default_path, const FilePath &default_filename, const FileExtension &default_extension, const FileTypes &fileTypes, int flags, wxWindow *parent)
Definition: SelectFile.cpp:17
const auto project
FILES_API const FileType AllFiles
Definition: FileNames.h:70
FILES_API const FileType TextFiles
Definition: FileNames.h:73
Abstract base class used in importing a file.
static ProjectFileIO & Get(AudacityProject &project)
const FilePath & GetFileName() const
TranslatableString FormatRMSMessage(float *pValue)
Definition: Contrast.cpp:414
TranslatableString FormatDifferenceForExport(float diffdB)
Definition: Contrast.cpp:454

References FileNames::AllFiles, AudacityMessageBox(), backgrounddB, FindProjectFromWindow(), foregrounddB, anonymous_namespace{Contrast.cpp}::FormatDifferenceForExport(), anonymous_namespace{Contrast.cpp}::FormatRMSMessage(), ProjectFileIO::Get(), ProjectFileIO::GetFileName(), NumericConverter::GetValue(), mBackgroundEndT, mBackgroundIsDefined, mBackgroundStartT, mForegroundEndT, mForegroundIsDefined, mForegroundStartT, project, SelectFile(), FileNames::TextFiles, wxT(), and XO().

Here is the call graph for this function:

◆ OnGetBackground()

void ContrastDialog::OnGetBackground ( wxCommandEvent &  event)
private

Definition at line 392 of file Contrast.cpp.

393{
394 auto p = FindProjectFromWindow( this );
395 auto &selectedRegion = ViewInfo::Get( *p ).selectedRegion;
396
397 if (TrackList::Get(*p).Selected<const WaveTrack>()) {
398 mBackgroundStartT->SetValue(selectedRegion.t0());
399 mBackgroundEndT->SetValue(selectedRegion.t1());
400 }
401
404 m_pButton_UseCurrentB->SetFocus();
405 results();
406}
void SetStartAndEndTime()
Definition: Contrast.cpp:137
void results()
Definition: Contrast.cpp:470
bool GetDB(float &dB)
Definition: Contrast.cpp:54
void SetValue(double newValue)
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:215
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235

References backgrounddB, FindProjectFromWindow(), ViewInfo::Get(), TrackList::Get(), GetDB(), m_pButton_UseCurrentB, mBackgroundEndT, mBackgroundIsDefined, mBackgroundStartT, results(), TrackList::Selected(), ViewInfo::selectedRegion, SetStartAndEndTime(), and NumericTextCtrl::SetValue().

Here is the call graph for this function:

◆ OnGetForeground()

void ContrastDialog::OnGetForeground ( wxCommandEvent &  event)
private

Definition at line 376 of file Contrast.cpp.

377{
378 auto p = FindProjectFromWindow( this );
379 auto &selectedRegion = ViewInfo::Get( *p ).selectedRegion;
380
381 if (TrackList::Get(*p).Selected<const WaveTrack>()) {
382 mForegroundStartT->SetValue(selectedRegion.t0());
383 mForegroundEndT->SetValue(selectedRegion.t1());
384 }
385
388 m_pButton_UseCurrentF->SetFocus();
389 results();
390}

References FindProjectFromWindow(), foregrounddB, ViewInfo::Get(), TrackList::Get(), GetDB(), m_pButton_UseCurrentF, mForegroundEndT, mForegroundIsDefined, mForegroundStartT, results(), TrackList::Selected(), ViewInfo::selectedRegion, SetStartAndEndTime(), and NumericTextCtrl::SetValue().

Here is the call graph for this function:

◆ OnGetURL()

void ContrastDialog::OnGetURL ( wxCommandEvent &  event)
private

Definition at line 361 of file Contrast.cpp.

362{
363 // Original help page is back on-line (March 2016), but the manual should be more reliable.
364 // http://www.eramp.com/WCAG_2_audio_contrast_tool_help.htm
365 HelpSystem::ShowHelp(this, L"Contrast");
366}
static void ShowHelp(wxWindow *parent, const FilePath &localFileName, const URLString &remoteURL, bool bModal=false, bool alwaysDefaultBrowser=false)
Definition: HelpSystem.cpp:231

References HelpSystem::ShowHelp().

Here is the call graph for this function:

◆ OnReset()

void ContrastDialog::OnReset ( wxCommandEvent &  event)
private

Definition at line 636 of file Contrast.cpp.

637{
642 mForegroundIsDefined = false;
643 mBackgroundIsDefined = false;
644
645 mForegroundRMSText->SetName(_("No foreground measured")); // Read by screen-readers
646 mBackgroundRMSText->SetName(_("No background measured"));
647 mForegroundRMSText->ChangeValue(wxT("")); // Displayed value
648 mBackgroundRMSText->ChangeValue(wxT(""));
649 mPassFailText->ChangeValue(wxT(""));
650 mDiffText->ChangeValue(wxT(""));
651}
#define _(s)
Definition: Internat.h:73

References _, mBackgroundEndT, mBackgroundIsDefined, mBackgroundRMSText, mBackgroundStartT, mDiffText, mForegroundEndT, mForegroundIsDefined, mForegroundRMSText, mForegroundStartT, mPassFailText, NumericTextCtrl::SetValue(), and wxT().

Referenced by OnClose().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ results()

void ContrastDialog::results ( )
private

Definition at line 470 of file Contrast.cpp.

471{
472 mPassFailText->SetName(wxT(""));
473 mPassFailText->ChangeValue(wxT(""));
474 mDiffText->ChangeValue(wxT(""));
475
476 // foreground and background defined.
478 float diffdB = std::fabs(foregrounddB - backgrounddB);
480 mPassFailText->ChangeValue(_("Foreground level too high"));
481 }
482 else if (backgrounddB > DB_MAX_LIMIT) {
483 mPassFailText->ChangeValue(_("Background level too high"));
484 }
485 else if (backgrounddB > foregrounddB) {
486 mPassFailText->ChangeValue(_("Background higher than foreground"));
487 }
488 else if(diffdB > WCAG2_PASS) {
489 /* i18n-hint: WCAG2 is the 'Web Content Accessibility Guidelines (WCAG) 2.0', see http://www.w3.org/TR/WCAG20/ */
490 mPassFailText->ChangeValue(_("WCAG2 Pass"));
491 }
492 else {
493 /* i18n-hint: WCAG abbreviates Web Content Accessibility Guidelines */
494 mPassFailText->ChangeValue(_("WCAG2 Fail"));
495 }
496
497 /* i18n-hint: i.e. difference in loudness at the moment. */
498 mDiffText->SetName(_("Current difference"));
499 mDiffText->ChangeValue( FormatDifference( diffdB ).Translation() );
500 }
501
503 mForegroundRMSText->SetName(_("Measured foreground level")); // Read by screen-readers
504 if(std::isinf(- foregrounddB))
505 mForegroundRMSText->ChangeValue(_("zero"));
506 else
507 // i18n-hint: short form of 'decibels'
508 mForegroundRMSText->ChangeValue(wxString::Format(_("%.2f dB"), foregrounddB));
509 }
510 else {
511 mForegroundRMSText->SetName(_("No foreground measured")); // Read by screen-readers
512 mForegroundRMSText->ChangeValue(wxT(""));
513 mPassFailText->ChangeValue(_("Foreground not yet measured"));
514 }
515
517 mBackgroundRMSText->SetName(_("Measured background level"));
518 if(std::isinf(- backgrounddB))
519 mBackgroundRMSText->ChangeValue(_("zero"));
520 else
521 mBackgroundRMSText->ChangeValue(wxString::Format(_("%.2f dB"), backgrounddB));
522 }
523 else {
524 mBackgroundRMSText->SetName(_("No background measured"));
525 mBackgroundRMSText->ChangeValue(wxT(""));
526 mPassFailText->ChangeValue(_("Background not yet measured"));
527 }
528}
#define WCAG2_PASS
Definition: Contrast.cpp:51
#define DB_MAX_LIMIT
Definition: Contrast.cpp:50
TranslatableString FormatDifference(float diffdB)
Definition: Contrast.cpp:439

References _, backgrounddB, DB_MAX_LIMIT, foregrounddB, anonymous_namespace{Contrast.cpp}::FormatDifference(), mBackgroundIsDefined, mBackgroundRMSText, mDiffText, mForegroundIsDefined, mForegroundRMSText, mPassFailText, WCAG2_PASS, and wxT().

Referenced by OnGetBackground(), and OnGetForeground().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetStartAndEndTime()

void ContrastDialog::SetStartAndEndTime ( )
private

Definition at line 137 of file Contrast.cpp.

138{
139 auto p = FindProjectFromWindow( this );
140 auto &selectedRegion = ViewInfo::Get( *p ).selectedRegion;
141 mT0 = selectedRegion.t0();
142 mT1 = selectedRegion.t1();
143}

References FindProjectFromWindow(), ViewInfo::Get(), mT0, mT1, and ViewInfo::selectedRegion.

Referenced by OnGetBackground(), and OnGetForeground().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ backgrounddB

float ContrastDialog::backgrounddB
private

Definition at line 71 of file Contrast.h.

Referenced by ContrastDialog(), OnExport(), OnGetBackground(), and results().

◆ foregrounddB

float ContrastDialog::foregrounddB
private

Definition at line 70 of file Contrast.h.

Referenced by ContrastDialog(), OnExport(), OnGetForeground(), and results().

◆ length

double ContrastDialog::length
private

Definition at line 81 of file Contrast.h.

◆ m_pButton_Close

wxButton* ContrastDialog::m_pButton_Close

Definition at line 39 of file Contrast.h.

Referenced by ContrastDialog().

◆ m_pButton_Export

wxButton* ContrastDialog::m_pButton_Export

Definition at line 37 of file Contrast.h.

Referenced by ContrastDialog().

◆ m_pButton_GetURL

wxButton* ContrastDialog::m_pButton_GetURL

Definition at line 36 of file Contrast.h.

Referenced by ContrastDialog().

◆ m_pButton_Reset

wxButton* ContrastDialog::m_pButton_Reset

Definition at line 38 of file Contrast.h.

Referenced by ContrastDialog().

◆ m_pButton_UseCurrentB

wxButton* ContrastDialog::m_pButton_UseCurrentB

Definition at line 35 of file Contrast.h.

Referenced by ContrastDialog(), and OnGetBackground().

◆ m_pButton_UseCurrentF

wxButton* ContrastDialog::m_pButton_UseCurrentF

Definition at line 34 of file Contrast.h.

Referenced by ContrastDialog(), and OnGetForeground().

◆ mBackgroundEndT

NumericTextCtrl* ContrastDialog::mBackgroundEndT

Definition at line 44 of file Contrast.h.

Referenced by ContrastDialog(), OnExport(), OnGetBackground(), and OnReset().

◆ mBackgroundIsDefined

bool ContrastDialog::mBackgroundIsDefined
private

Definition at line 73 of file Contrast.h.

Referenced by ContrastDialog(), OnExport(), OnGetBackground(), OnReset(), and results().

◆ mBackgroundRMSText

wxTextCtrl* ContrastDialog::mBackgroundRMSText
private

Definition at line 66 of file Contrast.h.

Referenced by ContrastDialog(), OnReset(), and results().

◆ mBackgroundStartT

NumericTextCtrl* ContrastDialog::mBackgroundStartT

Definition at line 43 of file Contrast.h.

Referenced by ContrastDialog(), OnExport(), OnGetBackground(), and OnReset().

◆ mDiffText

wxTextCtrl* ContrastDialog::mDiffText
private

Definition at line 68 of file Contrast.h.

Referenced by ContrastDialog(), OnReset(), and results().

◆ mDoBackground

bool ContrastDialog::mDoBackground
private

Definition at line 77 of file Contrast.h.

◆ mEndTimeB

double ContrastDialog::mEndTimeB

Definition at line 52 of file Contrast.h.

◆ mEndTimeF

double ContrastDialog::mEndTimeF

Definition at line 50 of file Contrast.h.

◆ mForegroundEndT

NumericTextCtrl* ContrastDialog::mForegroundEndT

Definition at line 42 of file Contrast.h.

Referenced by ContrastDialog(), OnExport(), OnGetForeground(), and OnReset().

◆ mForegroundIsDefined

bool ContrastDialog::mForegroundIsDefined
private

Definition at line 72 of file Contrast.h.

Referenced by ContrastDialog(), OnExport(), OnGetForeground(), OnReset(), and results().

◆ mForegroundRMSText

wxTextCtrl* ContrastDialog::mForegroundRMSText
private

Definition at line 65 of file Contrast.h.

Referenced by ContrastDialog(), OnReset(), and results().

◆ mForegroundStartT

NumericTextCtrl* ContrastDialog::mForegroundStartT

Definition at line 41 of file Contrast.h.

Referenced by ContrastDialog(), OnExport(), OnGetForeground(), and OnReset().

◆ mPassFailText

wxTextCtrl* ContrastDialog::mPassFailText
private

Definition at line 67 of file Contrast.h.

Referenced by ContrastDialog(), OnReset(), and results().

◆ mProjectRate

double ContrastDialog::mProjectRate

Definition at line 48 of file Contrast.h.

Referenced by ContrastDialog().

◆ mStartTimeB

double ContrastDialog::mStartTimeB

Definition at line 51 of file Contrast.h.

◆ mStartTimeF

double ContrastDialog::mStartTimeF

Definition at line 49 of file Contrast.h.

◆ mT0

double ContrastDialog::mT0

Definition at line 46 of file Contrast.h.

Referenced by ContrastDialog(), GetDB(), and SetStartAndEndTime().

◆ mT0orig

double ContrastDialog::mT0orig
private

Definition at line 74 of file Contrast.h.

◆ mT1

double ContrastDialog::mT1

Definition at line 47 of file Contrast.h.

Referenced by ContrastDialog(), GetDB(), and SetStartAndEndTime().

◆ mT1orig

double ContrastDialog::mT1orig
private

Definition at line 75 of file Contrast.h.


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