1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-31 16:09:28 +02:00

fixed bug/enh 266

This commit is contained in:
binarywisdom 2020-08-28 15:07:04 -04:00 committed by Paul Licameli
parent d66ffaa4ce
commit a10a1b81aa
7 changed files with 66 additions and 12 deletions

View File

@ -133,7 +133,8 @@ namespace {
}
/*! @excsafety{Strong} */
bool Sequence::ConvertToSampleFormat(sampleFormat format)
bool Sequence::ConvertToSampleFormat(sampleFormat format,
const std::function<void(size_t)> & progressReport)
{
if (format == mSampleFormat)
// no change
@ -199,6 +200,9 @@ bool Sequence::ConvertToSampleFormat(sampleFormat format)
const auto blockstart = oldSeqBlock.start;
Blockify(*mpFactory, mMaxSamples, mSampleFormat,
newBlockArray, blockstart, bufferNew.ptr(), len);
if (progressReport)
progressReport(len);
}
}

View File

@ -12,6 +12,7 @@
#define __AUDACITY_SEQUENCE__
#include <vector>
#include <functional>
#include "SampleFormat.h"
#include "xml/XMLTagHandler.h"
@ -140,7 +141,8 @@ class PROFILE_DLL_API Sequence final : public XMLTagHandler{
sampleFormat GetSampleFormat() const;
// Return true iff there is a change
bool ConvertToSampleFormat(sampleFormat format);
bool ConvertToSampleFormat(sampleFormat format,
const std::function<void(size_t)> & progressReport = {});
//
// Retrieving summary info

View File

@ -24,7 +24,6 @@
#include "Experimental.h"
#include <math.h>
#include <functional>
#include <vector>
#include <wx/log.h>
@ -1159,12 +1158,13 @@ float WaveClip::GetRMS(double t0, double t1, bool mayThrow) const
return mSequence->GetRMS(s0, s1-s0, mayThrow);
}
void WaveClip::ConvertToSampleFormat(sampleFormat format)
void WaveClip::ConvertToSampleFormat(sampleFormat format,
const std::function<void(size_t)> & progressReport)
{
// Note: it is not necessary to do this recursively to cutlines.
// They get converted as needed when they are expanded.
auto bChanged = mSequence->ConvertToSampleFormat(format);
auto bChanged = mSequence->ConvertToSampleFormat(format, progressReport);
if (bChanged)
MarkChanged();
}

View File

@ -22,6 +22,7 @@
#include <wx/longlong.h>
#include <vector>
#include <functional>
class BlockArray;
class Envelope;
@ -198,7 +199,8 @@ public:
virtual ~WaveClip();
void ConvertToSampleFormat(sampleFormat format);
void ConvertToSampleFormat(sampleFormat format,
const std::function<void(size_t)> & progressReport = {});
// Always gives non-negative answer, not more than sample sequence length
// even if t0 really falls outside that range

View File

@ -412,15 +412,26 @@ void WaveTrack::SetWaveColorIndex(int colorIndex)
mWaveColorIndex = colorIndex;
}
sampleCount WaveTrack::GetNumSamples() const
{
sampleCount result{ 0 };
for (const auto& clip : mClips)
result += clip->GetNumSamples();
return result;
}
/*! @excsafety{Weak} -- Might complete on only some clips */
void WaveTrack::ConvertToSampleFormat(sampleFormat format)
void WaveTrack::ConvertToSampleFormat(sampleFormat format,
const std::function<void(size_t)> & progressReport)
{
for (const auto &clip : mClips)
clip->ConvertToSampleFormat(format);
for (const auto& clip : mClips)
clip->ConvertToSampleFormat(format, progressReport);
mFormat = format;
}
bool WaveTrack::IsEmpty(double t0, double t1) const
{
if (t0 > t1)

View File

@ -14,6 +14,7 @@
#include "Track.h"
#include <vector>
#include <functional>
#include <wx/longlong.h>
#include "WaveTrackLocation.h"
@ -142,8 +143,11 @@ private:
int GetWaveColorIndex() const { return mWaveColorIndex; };
void SetWaveColorIndex(int colorIndex);
sampleCount GetNumSamples() const;
sampleFormat GetSampleFormat() const { return mFormat; }
void ConvertToSampleFormat(sampleFormat format);
void ConvertToSampleFormat(sampleFormat format,
const std::function<void(size_t)> & progressReport = {});
const SpectrogramSettings &GetSpectrogramSettings() const;
SpectrogramSettings &GetSpectrogramSettings();

View File

@ -34,6 +34,9 @@ Paul Licameli split from TrackPanel.cpp
#include "../../../../prefs/PrefsDialog.h"
#include "../../../../prefs/ThemePrefs.h"
#include "../../../../widgets/AudacityMessageBox.h"
#include "widgets/ProgressDialog.h"
#include "UserException.h"
#include "audacity/Types.h"
#include <wx/combobox.h>
#include <wx/frame.h>
@ -252,9 +255,37 @@ void FormatMenuTable::OnFormatChange(wxCommandEvent & event)
AudacityProject *const project = &mpData->project;
for (auto channel : TrackList::Channels(pTrack))
channel->ConvertToSampleFormat(newFormat);
ProgressDialog progress{ XO("Changing sample format"),
XO("Processing... 0%%"),
pdlgHideStopButton };
sampleCount totalSamples{ 0 };
for (const auto& channel : TrackList::Channels(pTrack))
totalSamples += channel->GetNumSamples();
sampleCount processedSamples{ 0 };
// Below is the lambda function that is passed along the call chain to
// the Sequence::ConvertToSampleFormat. This callback function is used
// to report the convertion progress and update the progress dialog.
auto progressUpdate = [&progress, &totalSamples, &processedSamples]
(size_t newlyProcessedCount)->void
{
processedSamples += newlyProcessedCount;
double d_processed = processedSamples.as_double();
double d_total = totalSamples.as_double();
int percentage{ static_cast<int>((d_processed / d_total) * 100) };
auto progressStatus = progress.Update(d_processed, d_total,
XO("Processing... %i%%").Format(percentage));
if (progressStatus != ProgressResult::Success)
throw UserException{};
};
for (auto channel : TrackList::Channels(pTrack))
channel->ConvertToSampleFormat(
newFormat, progressUpdate);
ProjectHistory::Get( *project )
/* i18n-hint: The strings name a track and a format */
.PushState(XO("Changed '%s' to %s")