Audacity  2.2.2
Public Member Functions | 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:
AudacityCommand CommandDefinitionInterface IdentInterface ParamsInterface

Public Member Functions

IdentInterfaceSymbol GetSymbol () override
 
wxString GetDescription () override
 
bool DefineParams (ShuttleParams &S) override
 
void PopulateOrExchange (ShuttleGui &S) override
 
bool Apply () override
 
wxString ManualPage () override
 
bool Apply (const CommandContext &context) override
 
- Public Member Functions inherited from AudacityCommand
 AudacityCommand ()
 
virtual ~AudacityCommand ()
 
wxString GetPath () override
 
IdentInterfaceSymbol GetVendor () override
 
wxString GetVersion () override
 
virtual bool IsBatchProcessing ()
 
virtual void SetBatchProcessing (bool start)
 
virtual bool Apply (const CommandContext &WXUNUSED(context))
 
bool ShowInterface (wxWindow *parent, bool forceModal=false)
 
virtual void SetHostUI (EffectUIHostInterface *WXUNUSED(host))
 
bool PopulateUI (wxWindow *parent)
 
wxDialog * CreateUI (wxWindow *parent, AudacityCommand *client)
 
virtual bool GetAutomationParameters (wxString &parms)
 
virtual bool SetAutomationParameters (const wxString &parms)
 
bool DoAudacityCommand (wxWindow *parent, const CommandContext &context, bool shouldPrompt=true)
 
int MessageBox (const wxString &message, long style=DefaultMessageBoxStyle, const wxString &titleStr=wxString{})
 
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 ()
 
- Public Member Functions inherited from CommandDefinitionInterface
virtual ~CommandDefinitionInterface ()
 
- Public Member Functions inherited from IdentInterface
virtual ~IdentInterface ()
 
const wxString & GetTranslatedName ()
 
- Public Member Functions inherited from ParamsInterface
virtual ~ParamsInterface ()
 
virtual bool DefineParams (ShuttleParams &WXUNUSED(S))
 

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
 
int mUIResultID
 

Detailed Description

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

Definition at line 28 of file CompareAudioCommand.h.

Member Function Documentation

bool CompareAudioCommand::Apply ( )
overridevirtual

Reimplemented from AudacityCommand.

Definition at line 50 of file CompareAudioCommand.cpp.

50  {
51  return true;
52 }
bool CompareAudioCommand::Apply ( const CommandContext context)
override

Definition at line 109 of file CompareAudioCommand.cpp.

References CompareSample(), errorThreshold, floatSample, WaveTrack::Get(), WaveTrack::GetBestBlockSize(), WaveTrack::GetMaxBlockSize(), Track::GetName(), CommandContext::GetProject(), GetSelection(), limitSampleBufferSize(), WaveTrack::LongSamplesToTime(), min(), mT0, mT1, mTrack0, mTrack1, CommandContext::Progress(), CommandContext::Status(), and WaveTrack::TimeToLongSamples().

110 {
111  if (!GetSelection(context, *context.GetProject()))
112  {
113  return false;
114  }
115 
116  wxString msg = wxT("Comparing tracks '");
117  msg += mTrack0->GetName() + wxT("' and '")
118  + mTrack1->GetName() + wxT("'.");
119  context.Status(msg);
120 
121  long errorCount = 0;
122  // Initialize buffers for track data to be analyzed
123  auto buffSize = std::min(mTrack0->GetMaxBlockSize(), mTrack1->GetMaxBlockSize());
124 
125  Floats buff0{ buffSize };
126  Floats buff1{ buffSize };
127 
128  // Compare tracks block by block
129  auto s0 = mTrack0->TimeToLongSamples(mT0);
130  auto s1 = mTrack0->TimeToLongSamples(mT1);
131  auto position = s0;
132  auto length = s1 - s0;
133  while (position < s1)
134  {
135  // Get a block of data into the buffers
136  auto block = limitSampleBufferSize(
137  mTrack0->GetBestBlockSize(position), s1 - position
138  );
139  mTrack0->Get((samplePtr)buff0.get(), floatSample, position, block);
140  mTrack1->Get((samplePtr)buff1.get(), floatSample, position, block);
141 
142  for (decltype(block) buffPos = 0; buffPos < block; ++buffPos)
143  {
144  if (CompareSample(buff0[buffPos], buff1[buffPos]) > errorThreshold)
145  {
146  ++errorCount;
147  }
148  }
149 
150  position += block;
151  context.Progress(
152  (position - s0).as_double() /
153  length.as_double()
154  );
155  }
156 
157  // Output the results
158  double errorSeconds = mTrack0->LongSamplesToTime(errorCount);
159  context.Status(wxString::Format(wxT("%li"), errorCount));
160  context.Status(wxString::Format(wxT("%.4f"), errorSeconds));
161  context.Status(wxString::Format(wxT("Finished comparison: %li samples (%.3f seconds) exceeded the error threshold of %f."), errorCount, errorSeconds, errorThreshold));
162  return true;
163 }
AudacityProject * GetProject() const
const WaveTrack * mTrack1
double CompareSample(double value1, double value2)
virtual void Status(const wxString &message, bool bFlush=false) const
virtual void Progress(double d) const
size_t GetBestBlockSize(sampleCount t) const
Definition: WaveTrack.cpp:1607
size_t limitSampleBufferSize(size_t bufferSize, sampleCount limit)
Definition: Types.h:178
const WaveTrack * mTrack0
char * samplePtr
Definition: Types.h:203
int min(int a, int b)
wxString GetName() const
Definition: Track.h:271
size_t GetMaxBlockSize() const
Definition: WaveTrack.cpp:1625
sampleCount TimeToLongSamples(double t0) const
Convert correctly between an (absolute) time in seconds and a number of samples.
Definition: WaveTrack.cpp:1843
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
double LongSamplesToTime(sampleCount pos) const
Convert correctly between an number of samples and an (absolute) time in seconds. ...
Definition: WaveTrack.cpp:1848
bool GetSelection(const CommandContext &context, AudacityProject &proj)
double CompareAudioCommand::CompareSample ( double  value1,
double  value2 
)
protected

Definition at line 99 of file CompareAudioCommand.cpp.

Referenced by Apply().

100 {
101  return fabs(value1 - value2);
102 }
bool CompareAudioCommand::DefineParams ( ShuttleParams S)
override

Definition at line 45 of file CompareAudioCommand.cpp.

References ShuttleParams::Define(), and errorThreshold.

45  {
46  S.Define( errorThreshold, wxT("Threshold"), 0.0f, 0.0f, 0.01f, 1.0f );
47  return true;
48 }
virtual void Define(bool &var, const wxChar *key, const bool vdefault, const bool vmin=false, const bool vmax=false, const bool vscl=false)
Definition: Shuttle.cpp:339
wxString CompareAudioCommand::GetDescription ( )
inlineoverridevirtual

Reimplemented from AudacityCommand.

Definition at line 33 of file CompareAudioCommand.h.

References _().

33 {return _("Compares a range on two tracks.");};
_("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
bool CompareAudioCommand::GetSelection ( const CommandContext context,
AudacityProject proj 
)
private

Definition at line 66 of file CompareAudioCommand.cpp.

References CommandContext::Error(), AudacityProject::GetTracks(), mT0, mT1, mTrack0, mTrack1, AudacityProject::mViewInfo, ViewInfo::selectedRegion, CommandContext::Status(), SelectedRegion::t0(), SelectedRegion::t1(), and Track::Wave.

Referenced by Apply().

67 {
68  // Get the selected time interval
69  mT0 = proj.mViewInfo.selectedRegion.t0();
70  mT1 = proj.mViewInfo.selectedRegion.t1();
71  if (mT0 >= mT1)
72  {
73  context.Error(wxT("There is no selection!"));
74  return false;
75  }
76 
77  // Get the selected tracks and check that there are at least two to
78  // compare
80  mTrack0 = (WaveTrack*)(iter.First());
81  if (mTrack0 == NULL)
82  {
83  context.Error(wxT("No tracks selected! Select two tracks to compare."));
84  return false;
85  }
86  mTrack1 = (WaveTrack*)(iter.Next());
87  if (mTrack1 == NULL)
88  {
89  context.Error(wxT("Only one track selected! Select two tracks to compare."));
90  return false;
91  }
92  if (iter.Next() != NULL)
93  {
94  context.Status(wxT("More than two tracks selected - only the first two will be compared."));
95  }
96  return true;
97 }
double t0() const
const WaveTrack * mTrack1
SelectedRegion selectedRegion
Definition: ViewInfo.h:160
virtual void Status(const wxString &message, bool bFlush=false) const
double t1() const
const WaveTrack * mTrack0
A Track that contains audio waveform data.
Definition: WaveTrack.h:60
ViewInfo mViewInfo
Definition: Project.h:558
virtual void Error(const wxString &message) const
TrackList * GetTracks()
Definition: Project.h:192
IdentInterfaceSymbol CompareAudioCommand::GetSymbol ( )
inlineoverridevirtual

Implements AudacityCommand.

Definition at line 32 of file CompareAudioCommand.h.

References XO.

32 {return XO("Compare Audio");}
#define XO(s)
Definition: Internat.h:33
wxString CompareAudioCommand::ManualPage ( )
inlineoverridevirtual

Reimplemented from AudacityCommand.

Definition at line 39 of file CompareAudioCommand.h.

39 {return wxT("Compare_Audio");};
void CompareAudioCommand::PopulateOrExchange ( ShuttleGui S)
override

Definition at line 54 of file CompareAudioCommand.cpp.

References _(), ShuttleGui::AddSpace(), ShuttleGuiBase::EndMultiColumn(), errorThreshold, ShuttleGuiBase::StartMultiColumn(), and ShuttleGuiBase::TieTextBox().

55 {
56  S.AddSpace(0, 5);
57 
58  S.StartMultiColumn(2, wxALIGN_CENTER);
59  {
60  S.TieTextBox(_("Threshold:"),errorThreshold);
61  }
62  S.EndMultiColumn();
63 }
void EndMultiColumn()
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
_("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
wxSizerItem * AddSpace(int width, int height)
wxTextCtrl * TieTextBox(const wxString &Prompt, WrappedType &WrappedRef, const int nChars)

Member Data Documentation

double CompareAudioCommand::errorThreshold
private

Definition at line 44 of file CompareAudioCommand.h.

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

double CompareAudioCommand::mT0
private

Definition at line 45 of file CompareAudioCommand.h.

Referenced by Apply(), and GetSelection().

double CompareAudioCommand::mT1
private

Definition at line 45 of file CompareAudioCommand.h.

Referenced by Apply(), and GetSelection().

const WaveTrack* CompareAudioCommand::mTrack0
private

Definition at line 46 of file CompareAudioCommand.h.

Referenced by Apply(), and GetSelection().

const WaveTrack* CompareAudioCommand::mTrack1
private

Definition at line 47 of file CompareAudioCommand.h.

Referenced by Apply(), and GetSelection().


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