Code cleanup Effect TrackProgress

Building and customizing Audacity from the source code.
Forum rules
If you require help using Audacity, please post on the forum board relevant to your operating system:
Windows
Mac OS X
GNU/Linux and Unix-like
Post Reply
Edgar
Forum Crew
Posts: 2043
Joined: Thu Sep 03, 2009 9:13 pm
Operating System: Windows 10

Code cleanup Effect TrackProgress

Post by Edgar » Sat Oct 25, 2014 6:17 pm

In SVN HEAD srceffectsEffect.h at or near line number 249:

Code: Select all

bool TrackProgress(int whichTrack, double frac, wxString = wxT(""));
Note that the third parameter (wxString) has no name; while currently permissible in C++ I expect this is probably an inadvertent typo. I think it should be:

Code: Select all

bool TrackProgress(int whichTrack, double frac, const wxString & msg = wxEmptyString);
to conform with the source code in Effect.cpp:

Code: Select all

bool Effect::TrackProgress(int whichTrack, double frac, wxString msg)
which should probably be:

Code: Select all

bool Effect::TrackProgress(int whichTrack, double frac, const wxString & msg)
because the the message should be passed as a constant reference not cloned.

Additionally, if you look at Effect.h at or near line number 189:

Code: Select all

bool Effect::TrackGroupProgress(int whichGroup, double frac)
You will see that the almost identical progress indicator for groups is lacking the third "message" parameter; obviously none of the current versions of this function are being passed a message but having the ability in the future to do so might make sense. Clearly it is prepared to do so:

Code: Select all

bool Effect::TrackProgress(int whichTrack, double frac, wxString msg)
{
   int updateResult = mProgress->Update(whichTrack + frac, (double) mNumTracks, msg);
   return (updateResult != eProgressSuccess);
}

bool Effect::TrackGroupProgress(int whichGroup, double frac)
{
   int updateResult = mProgress->Update(whichGroup + frac, (double) mNumGroups);
   return (updateResult != eProgressSuccess);
}
as you can see, both pieces of code use the exact same function (mProgress->Update) regardless of whether it is doing single or group:

Code: Select all

int Update(double current, double total, const wxString & message = wxEmptyString);
(and you can see the proper use of "& message = wxEmptyString" - 3 things: pass by constant reference, rich variable name (message not msg) and the use of wxEmptyString not wxT("").

So, in the header file:

Code: Select all

   bool TrackProgress(int whichTrack, double fraction, const wxString & message = wxEmptyString);
 
   // Pass a fraction between 0.0 and 1.0, for the current track group
   // (when doing stereo groups at a time)
   bool TrackGroupProgress(int whichGroup, double fraction, const wxString & message = wxEmptyString);
The source file:

Code: Select all

bool Effect::TrackProgress(int whichTrack, double fraction, const wxString & message)
{
   int updateResult = mProgress->Update(whichTrack + fraction, (double) mNumTracks, message);
   return (updateResult != eProgressSuccess);
}

bool Effect::TrackGroupProgress(int whichGroup, double fraction, const wxString & message)
{
   int updateResult = mProgress->Update(whichGroup + fraction, (double) mNumGroups, message);
   return (updateResult != eProgressSuccess);
}

Post Reply