Audacity 3.2.0
Public Member Functions | Static Public Attributes | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
CompareAudioCommand Class Referencefinal

Returns information about the amount of audio that is about a certain threshold of difference in two selected tracks. More...

#include <CompareAudioCommand.h>

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

Public Member Functions

ComponentInterfaceSymbol GetSymbol () const override
 
TranslatableString GetDescription () const override
 
template<bool Const>
bool VisitSettings (SettingsVisitorBase< Const > &S)
 
bool VisitSettings (SettingsVisitor &S) override
 
bool VisitSettings (ConstSettingsVisitor &S) override
 
void PopulateOrExchange (ShuttleGui &S) override
 
ManualPageID ManualPage () override
 
bool Apply (const CommandContext &context) override
 
- Public Member Functions inherited from AudacityCommand
 AudacityCommand ()
 
virtual ~AudacityCommand ()
 
PluginPath GetPath () const override
 
VendorSymbol GetVendor () const override
 
wxString GetVersion () const override
 
ComponentInterfaceSymbol GetSymbol () const override=0
 
virtual TranslatableString GetDescription () const override
 
virtual ManualPageID ManualPage ()
 
virtual bool IsBatchProcessing () const
 
virtual void SetBatchProcessing (bool start)
 
virtual bool Apply (const CommandContext &WXUNUSED(context))
 
bool ShowInterface (wxWindow *parent, bool forceModal=false)
 
wxDialog * CreateUI (wxWindow *parent, AudacityCommand *client)
 
bool SaveSettingsAsString (wxString &parms)
 
bool LoadSettingsFromString (const wxString &parms)
 
bool DoAudacityCommand (wxWindow *parent, const CommandContext &context, bool shouldPrompt=true)
 
int MessageBox (const TranslatableString &message, long style=DefaultMessageBoxStyle, const TranslatableString &titleStr={})
 
virtual bool Init ()
 
virtual bool PromptUser (wxWindow *parent)
 
virtual bool CheckWhetherSkipAudacityCommand ()
 
virtual void End ()
 
virtual void PopulateOrExchange (ShuttleGui &WXUNUSED(S))
 
virtual bool TransferDataToWindow ()
 
virtual bool TransferDataFromWindow ()
 
virtual bool VisitSettings (SettingsVisitor &)
 
virtual bool VisitSettings (ConstSettingsVisitor &)
 
- Public Member Functions inherited from ComponentInterface
virtual ~ComponentInterface ()
 
virtual PluginPath GetPath () const =0
 
virtual ComponentInterfaceSymbol GetSymbol () const =0
 
virtual VendorSymbol GetVendor () const =0
 
virtual wxString GetVersion () const =0
 
virtual TranslatableString GetDescription () const =0
 
TranslatableString GetName () const
 

Static Public Attributes

static const ComponentInterfaceSymbol Symbol { XO("Compare Audio") }
 

Protected Member Functions

double CompareSample (double value1, double value2)
 

Private Member Functions

bool GetSelection (const CommandContext &context, AudacityProject &proj)
 

Private Attributes

double errorThreshold
 
double mT0
 
double mT1
 
const WaveTrackmTrack0
 
const WaveTrackmTrack1
 

Additional Inherited Members

- Public Types inherited from AudacityCommand
enum  : long { DefaultMessageBoxStyle = wxOK | wxCENTRE }
 
- Protected Attributes inherited from AudacityCommand
ProgressDialogmProgress
 
wxDialog * mUIDialog
 
wxWindow * mUIParent
 

Detailed Description

Returns information about the amount of audio that is about a certain threshold of difference in two selected tracks.

Definition at line 26 of file CompareAudioCommand.h.

Member Function Documentation

◆ Apply()

bool CompareAudioCommand::Apply ( const CommandContext context)
override

Definition at line 119 of file CompareAudioCommand.cpp.

120{
121 if (!GetSelection(context, context.project))
122 {
123 return false;
124 }
125
126 wxString msg = wxT("Comparing tracks '");
127 msg += mTrack0->GetName() + wxT("' and '")
128 + mTrack1->GetName() + wxT("'.");
129 context.Status(msg);
130
131 long errorCount = 0;
132 // Initialize buffers for track data to be analyzed
134
135 Floats buff0{ buffSize };
136 Floats buff1{ buffSize };
137
138 // Compare tracks block by block
139 auto s0 = mTrack0->TimeToLongSamples(mT0);
140 auto s1 = mTrack0->TimeToLongSamples(mT1);
141 auto position = s0;
142 auto length = s1 - s0;
143 while (position < s1)
144 {
145 // Get a block of data into the buffers
146 auto block = limitSampleBufferSize(
147 mTrack0->GetBestBlockSize(position), s1 - position
148 );
149 mTrack0->GetFloats(buff0.get(), position, block);
150 mTrack1->GetFloats(buff1.get(), position, block);
151
152 for (decltype(block) buffPos = 0; buffPos < block; ++buffPos)
153 {
154 if (CompareSample(buff0[buffPos], buff1[buffPos]) > errorThreshold)
155 {
156 ++errorCount;
157 }
158 }
159
160 position += block;
161 context.Progress(
162 (position - s0).as_double() /
163 length.as_double()
164 );
165 }
166
167 // Output the results
168 double errorSeconds = mTrack0->LongSamplesToTime(errorCount);
169 context.Status(wxString::Format(wxT("%li"), errorCount));
170 context.Status(wxString::Format(wxT("%.4f"), errorSeconds));
171 context.Status(wxString::Format(wxT("Finished comparison: %li samples (%.3f seconds) exceeded the error threshold of %f."), errorCount, errorSeconds, errorThreshold));
172 return true;
173}
wxT("CloseDown"))
int min(int a, int b)
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: SampleCount.cpp:22
virtual void Progress(double d) const
virtual void Status(const wxString &message, bool bFlush=false) const
AudacityProject & project
double CompareSample(double value1, double value2)
const WaveTrack * mTrack1
bool GetSelection(const CommandContext &context, AudacityProject &proj)
const WaveTrack * mTrack0
bool GetFloats(float *buffer, sampleCount start, size_t len, fillFormat fill=fillZero, bool mayThrow=true, sampleCount *pNumWithinClips=nullptr) const
Retrieve samples from a track in floating-point format, regardless of the storage format.
Definition: SampleTrack.h:82
double LongSamplesToTime(sampleCount pos) const
Convert correctly between a number of samples and an (absolute) time in seconds.
Definition: SampleTrack.cpp:48
sampleCount TimeToLongSamples(double t0) const
Convert correctly between an (absolute) time in seconds and a number of samples.
Definition: SampleTrack.cpp:43
wxString GetName() const
Definition: Track.h:467
size_t GetMaxBlockSize() const override
This returns a nonnegative number of samples meant to size a memory buffer.
Definition: WaveTrack.cpp:1611
size_t GetBestBlockSize(sampleCount t) const override
This returns a nonnegative number of samples meant to size a memory buffer.
Definition: WaveTrack.cpp:1593

References CompareSample(), errorThreshold, WaveTrack::GetBestBlockSize(), SampleTrack::GetFloats(), WaveTrack::GetMaxBlockSize(), Track::GetName(), GetSelection(), limitSampleBufferSize(), SampleTrack::LongSamplesToTime(), min(), mT0, mT1, mTrack0, mTrack1, CommandContext::Progress(), CommandContext::project, CommandContext::Status(), SampleTrack::TimeToLongSamples(), and wxT().

Here is the call graph for this function:

◆ CompareSample()

double CompareAudioCommand::CompareSample ( double  value1,
double  value2 
)
protected

Definition at line 109 of file CompareAudioCommand.cpp.

110{
111 return fabs(value1 - value2);
112}

Referenced by Apply().

Here is the caller graph for this function:

◆ GetDescription()

TranslatableString CompareAudioCommand::GetDescription ( ) const
inlineoverridevirtual

Reimplemented from AudacityCommand.

Definition at line 33 of file CompareAudioCommand.h.

33{return XO("Compares a range on two tracks.");};
XO("Cut/Copy/Paste")

References XO().

Here is the call graph for this function:

◆ GetSelection()

bool CompareAudioCommand::GetSelection ( const CommandContext context,
AudacityProject proj 
)
private

Definition at line 75 of file CompareAudioCommand.cpp.

76{
77 // Get the selected time interval
78 auto &selectedRegion = ViewInfo::Get( proj ).selectedRegion;
79 mT0 = selectedRegion.t0();
80 mT1 = selectedRegion.t1();
81 if (mT0 >= mT1)
82 {
83 context.Error(wxT("There is no selection!"));
84 return false;
85 }
86
87 // Get the selected tracks and check that there are at least two to
88 // compare
89 auto trackRange = TrackList::Get( proj ).Selected< const WaveTrack >();
90 mTrack0 = *trackRange.first;
91 if (mTrack0 == NULL)
92 {
93 context.Error(wxT("No tracks selected! Select two tracks to compare."));
94 return false;
95 }
96 mTrack1 = * ++ trackRange.first;
97 if (mTrack1 == NULL)
98 {
99 context.Error(wxT("Only one track selected! Select two tracks to compare."));
100 return false;
101 }
102 if ( * ++ trackRange.first )
103 {
104 context.Status(wxT("More than two tracks selected - only the first two will be compared."));
105 }
106 return true;
107}
virtual void Error(const wxString &message) const
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:487
auto Selected() -> TrackIterRange< TrackType >
Definition: Track.h:1457
NotifyingSelectedRegion selectedRegion
Definition: ViewInfo.h:219
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
A Track that contains audio waveform data.
Definition: WaveTrack.h:51

References CommandContext::Error(), ViewInfo::Get(), TrackList::Get(), mT0, mT1, mTrack0, mTrack1, TrackList::Selected(), ViewInfo::selectedRegion, CommandContext::Status(), and wxT().

Referenced by Apply().

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

◆ GetSymbol()

ComponentInterfaceSymbol CompareAudioCommand::GetSymbol ( ) const
inlineoverridevirtual

Implements AudacityCommand.

Definition at line 32 of file CompareAudioCommand.h.

32{return Symbol;}
static const ComponentInterfaceSymbol Symbol

References Symbol.

◆ ManualPage()

ManualPageID CompareAudioCommand::ManualPage ( )
inlineoverridevirtual

Reimplemented from AudacityCommand.

Definition at line 40 of file CompareAudioCommand.h.

40{return L"Extra_Menu:_Scriptables_II#compare_Audio";}

◆ PopulateOrExchange()

void CompareAudioCommand::PopulateOrExchange ( ShuttleGui S)
override

Definition at line 63 of file CompareAudioCommand.cpp.

64{
65 S.AddSpace(0, 5);
66
67 S.StartMultiColumn(2, wxALIGN_CENTER);
68 {
69 S.TieTextBox(XXO("Threshold:"),errorThreshold);
70 }
71 S.EndMultiColumn();
72}
XXO("&Cut/Copy/Paste Toolbar")
#define S(N)
Definition: ToChars.cpp:64

References errorThreshold, S, and XXO().

Here is the call graph for this function:

◆ VisitSettings() [1/3]

bool CompareAudioCommand::VisitSettings ( ConstSettingsVisitor )
overridevirtual

Visit settings, if defined. false means no defined settings. Default implementation returns false

Reimplemented from AudacityCommand.

Definition at line 60 of file CompareAudioCommand.cpp.

61 { return VisitSettings<true>(S); }

References S.

◆ VisitSettings() [2/3]

bool CompareAudioCommand::VisitSettings ( SettingsVisitor )
overridevirtual

Visit settings, if defined. false means no defined settings. Default implementation returns false

Reimplemented from AudacityCommand.

Definition at line 57 of file CompareAudioCommand.cpp.

58 { return VisitSettings<false>(S); }

References S.

◆ VisitSettings() [3/3]

template<bool Const>
bool CompareAudioCommand::VisitSettings ( SettingsVisitorBase< Const > &  S)

Definition at line 53 of file CompareAudioCommand.cpp.

53 {
54 S.Define( errorThreshold, wxT("Threshold"), 0.0f, 0.0f, 0.01f, 1.0f );
55 return true;
56}

References errorThreshold, S, and wxT().

Here is the call graph for this function:

Member Data Documentation

◆ errorThreshold

double CompareAudioCommand::errorThreshold
private

Definition at line 45 of file CompareAudioCommand.h.

Referenced by Apply(), PopulateOrExchange(), and VisitSettings().

◆ mT0

double CompareAudioCommand::mT0
private

Definition at line 46 of file CompareAudioCommand.h.

Referenced by Apply(), and GetSelection().

◆ mT1

double CompareAudioCommand::mT1
private

Definition at line 46 of file CompareAudioCommand.h.

Referenced by Apply(), and GetSelection().

◆ mTrack0

const WaveTrack* CompareAudioCommand::mTrack0
private

Definition at line 47 of file CompareAudioCommand.h.

Referenced by Apply(), and GetSelection().

◆ mTrack1

const WaveTrack* CompareAudioCommand::mTrack1
private

Definition at line 48 of file CompareAudioCommand.h.

Referenced by Apply(), and GetSelection().

◆ Symbol

const ComponentInterfaceSymbol CompareAudioCommand::Symbol { XO("Compare Audio") }
static

Definition at line 29 of file CompareAudioCommand.h.

Referenced by GetSymbol().


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