15#include "../CommonCommandFlags.h"
19#include "../ProjectWindowBase.h"
25#include "../widgets/NumericTextCtrl.h"
31#if defined(__WXMSW__) && !defined(__CYGWIN__)
33#define finite(x) _finite(x)
37#include <wx/valtext.h>
39#include <wx/wfstream.h>
40#include <wx/txtstrm.h>
41#include <wx/textctrl.h>
47#define DB_MAX_LIMIT 0.0
48#define WCAG2_PASS 20.0
87 if (event.GetKeyCode() == WXK_TAB) {
100 const wxPoint & pos):
102 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxMAXIMIZE_BOX )
131 S.StartHorizontalLay(wxCENTER,
false);
135 XO(
"Contrast Analyzer, for measuring RMS volume differences between two selections of audio."));
137 S.EndHorizontalLay();
138 S.StartStatic(
XO(
"Parameters") );
140 S.StartMultiColumn(5, wxEXPAND);
144 S.AddFixedText( {} );
145 S.AddFixedText(
XO(
"Start"));
146 S.AddFixedText(
XO(
"End"));
147 S.AddFixedText( {} );
148 S.AddFixedText(
XO(
"Volume "));
151 S.AddFixedText(
XO(
"&Foreground:"),
false);
162 S.Name(
XO(
"Foreground start time"))
175 S.Name(
XO(
"Foreground end time"))
180 .ConnectRoot(wxEVT_KEY_DOWN,
182 .AddTextBox( {},
wxT(
""), 17);
185 S.AddFixedText(
XO(
"&Background:"));
196 S.Name(
XO(
"Background start time"))
209 S.Name(
XO(
"Background end time"))
214 .ConnectRoot(wxEVT_KEY_DOWN,
216 .AddTextBox( {},
wxT(
""), 17);
223 S.StartStatic(
XO(
"Result") );
225 S.StartMultiColumn(3, wxCENTER);
227 auto label =
XO(
"Co&ntrast Result:");
231 .ConnectRoot(wxEVT_KEY_DOWN,
233 .AddTextBox( {},
wxT(
""), 50);
240 .ConnectRoot(wxEVT_KEY_DOWN,
242 .AddTextBox( {},
wxT(
""), 50);
250 S.StartMultiColumn(3, wxEXPAND);
261 SetMinSize(GetSize());
274 wxCommandEvent dummyEvent;
322 auto format0 =
XO(
"RMS = %s.");
325 auto format1 =
XO(
"%s dB");
330 if( fabs( *pValue ) != std::numeric_limits<float>::infinity() ) {
331 auto number = wxString::Format(
wxT(
"%.2f"), *pValue );
332 value = format1.
Format( number );
338 value = format1.
Format(
"" );
340 return format0.
Format( value );
345 if( diffdB != diffdB )
346 return XO(
"indeterminate");
348 if( diffdB != std::numeric_limits<float>::infinity() )
351 return XO(
"%.2f dB RMS").Format( diffdB );
354 return XO(
"Infinite dB difference");
360 if( diffdB != diffdB )
361 return XO(
"Difference is indeterminate.");
363 if( fabs(diffdB) != std::numeric_limits<float>::infinity() )
366 return XO(
"Difference = %.2f RMS dB.").Format( diffdB );
370 return XO(
"Difference = infinite RMS dB.");
390 mPassFailText->ChangeValue(
_(
"Background higher than foreground"));
438 wxString fName =
wxT(
"contrast.txt");
440 fName =
SelectFile(FileNames::Operation::Export,
441 XO(
"Export Contrast Result As:"),
446 wxFD_SAVE | wxRESIZE_BORDER,
452 wxFFileOutputStream ffStream{ fName };
454 if (!ffStream.IsOk()) {
459 wxTextOutputStream ss(ffStream);
462 <<
wxT(
"===================================") <<
'\n'
464 <<
XO(
"WCAG 2.0 Success Criteria 1.4.7 Contrast Results") <<
'\n'
468 <<
XO(
"Foreground") <<
'\n';
471 int h = (int)(t/3600);
472 int m = (int)((t - h*3600)/60);
473 float s = t - h*3600.0 - m*60.0;
476 <<
XO(
"Time started = %2d hour(s), %2d minute(s), %.2f seconds.")
477 .Format( h, m, s ) <<
'\n';
481 m = (int)((t - h*3600)/60);
482 s = t - h*3600.0 - m*60.0;
485 <<
XO(
"Time ended = %2d hour(s), %2d minute(s), %.2f seconds.")
486 .Format( h, m, s ) <<
'\n'
489 <<
XO(
"Background") <<
'\n';
493 m = (int)((t - h*3600)/60);
494 s = t - h*3600.0 - m*60.0;
497 <<
XO(
"Time started = %2d hour(s), %2d minute(s), %.2f seconds.")
498 .Format( h, m, s ) <<
'\n';
502 m = (int)((t - h*3600)/60);
503 s = t - h*3600.0 - m*60.0;
506 <<
XO(
"Time ended = %2d hour(s), %2d minute(s), %.2f seconds.")
507 .Format( h, m, s ) <<
'\n'
510 <<
XO(
"Results") <<
'\n';
517 ?
XO(
"Success Criteria 1.4.7 of WCAG 2.0: Pass")
518 :
XO(
"Success Criteria 1.4.7 of WCAG 2.0: Fail")) <<
'\n'
520 <<
XO(
"Data gathered") <<
'\n';
522 wxDateTime now = wxDateTime::Now();
523 int year = now.GetYear();
524 wxDateTime::Month month = now.GetMonth();
525 wxString monthName = now.GetMonthName(month);
526 int dom = now.GetDay();
527 int hour = now.GetHour();
528 int minute = now.GetMinute();
529 int second = now.GetSecond();
531 auto sNow =
XO(
"%d %s %02d %02dh %02dm %02ds")
532 .Format( dom, monthName, year, hour, minute, second );
536 <<
wxT(
"===================================") <<
'\n'
574 &window, -1,
XO(
"Contrast Analysis (WCAG 2 compliance)"),
589 contrastDialog->CentreOnParent();
590 contrastDialog->Show();
601 wxT(
"Ctrl+Shift+T") ),
602 wxT(
"Analyze/Analyzers/Windows")
@ Internal
Indicates internal failure from Audacity.
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
const ReservedCommandFlag & AudioIONotBusyFlag()
const ReservedCommandFlag & TimeSelectedFlag()
const ReservedCommandFlag & WaveTracksSelectedFlag()
EVT_BUTTON(wxID_NO, DependencyDialog::OnNo) EVT_BUTTON(wxID_YES
XXO("&Cut/Copy/Paste Toolbar")
const NumericConverterType & NumericConverterType_TIME()
an object holding per-project preferred sample rate
AudacityProject * FindProjectFromWindow(wxWindow *pWindow)
AUDACITY_DLL_API wxFrame & GetProjectFrame(AudacityProject &project)
Get the top-level window associated with the project (as a wxFrame only, when you do not need to use ...
AUDACITY_DLL_API AttachedWindows & GetAttachedWindows(AudacityProject &project)
accessors for certain important windows associated with each project
FilePath SelectFile(FileNames::Operation op, const TranslatableString &message, const FilePath &default_path, const FilePath &default_filename, const FileExtension &default_extension, const FileTypes &fileTypes, int flags, wxWindow *parent)
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Subclass & Get(const RegisteredFactory &key)
Get reference to an attachment, creating on demand if not present, down-cast it to Subclass.
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
AudacityProject & project
void RegisterLastAnalyzer(const CommandContext &context)
static CommandManager & Get(AudacityProject &project)
bool mForegroundIsDefined
bool mBackgroundIsDefined
void SetStartAndEndTime()
NumericTextCtrl * mBackgroundStartT
wxButton * m_pButton_Close
AudacityProject & GetProject() override
void OnClose(wxCommandEvent &event)
void OnChar(wxKeyEvent &event)
NumericTextCtrl * mBackgroundEndT
wxTextCtrl * mBackgroundRMSText
wxButton * m_pButton_UseCurrentB
void OnExport(wxCommandEvent &event)
void OnGetBackground(wxCommandEvent &event)
ContrastDialog(wxWindow *parent, wxWindowID id, const TranslatableString &title, const wxPoint &pos)
NumericTextCtrl * mForegroundStartT
void OnReset(wxCommandEvent &event)
wxButton * m_pButton_Export
void OnGetURL(wxCommandEvent &event)
wxTextCtrl * mForegroundRMSText
wxButton * m_pButton_Reset
wxButton * m_pButton_UseCurrentF
NumericTextCtrl * mForegroundEndT
void OnGetForeground(wxCommandEvent &event)
wxTextCtrl * mPassFailText
wxButton * m_pButton_GetURL
FILES_API const FileType AllFiles
FILES_API const FileType TextFiles
static FormatterContext SampleRateContext(double sampleRate)
static void ShowHelp(wxWindow *parent, const FilePath &localFileName, const URLString &remoteURL, bool bModal=false, bool alwaysDefaultBrowser=false)
void SetValue(double newValue)
static ProjectFileIO & Get(AudacityProject &project)
const FilePath & GetFileName() const
static ProjectRate & Get(AudacityProject &project)
Generates classes whose instances register items at construction.
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
static TrackList & Get(AudacityProject &project)
auto Selected() -> TrackIterRange< TrackType >
Holds a msgid for the translation catalog; may also bind format arguments.
TranslatableString & Format(Args &&...args) &
Capture variadic format arguments (by copy) when there is no plural.
NotifyingSelectedRegion selectedRegion
static ViewInfo & Get(AudacityProject &project)
A Track that contains audio waveform data.
IMPORT_EXPORT_API ExportResult Show(ExportTask exportTask)
void OnContrast(const CommandContext &context)
TranslatableString FormatRMSMessage(float *pValue)
AttachedWindows::RegisteredFactory sContrastDialogKey
TranslatableString FormatDifferenceForExport(float diffdB)
TranslatableString FormatDifference(float diffdB)
Options & MenuEnabled(bool enable)
Options & AutoPos(bool enable)
Options & ReadOnly(bool enable)