mirror of
https://github.com/cookiengineer/audacity
synced 2025-08-01 08:29:27 +02:00
fixed bug/enh 266
This commit is contained in:
parent
d66ffaa4ce
commit
a10a1b81aa
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
clip->ConvertToSampleFormat(format, progressReport);
|
||||
mFormat = format;
|
||||
}
|
||||
|
||||
|
||||
bool WaveTrack::IsEmpty(double t0, double t1) const
|
||||
{
|
||||
if (t0 > t1)
|
||||
|
@ -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();
|
||||
|
@ -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,8 +255,36 @@ void FormatMenuTable::OnFormatChange(wxCommandEvent & event)
|
||||
|
||||
AudacityProject *const project = &mpData->project;
|
||||
|
||||
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);
|
||||
channel->ConvertToSampleFormat(
|
||||
newFormat, progressUpdate);
|
||||
|
||||
ProjectHistory::Get( *project )
|
||||
/* i18n-hint: The strings name a track and a format */
|
||||
|
Loading…
x
Reference in New Issue
Block a user