1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-19 09:30:06 +02:00

Bug819 - Paste should not change clipboard contents when sample formats differ

This commit is contained in:
Paul-Licameli 2015-04-08 12:09:30 -04:00
parent 44fc5b9f4d
commit fe8d3535d8
2 changed files with 24 additions and 29 deletions

View File

@ -26,6 +26,7 @@ drawing). Cache's the Spectrogram frequency samples.
*//*******************************************************************/
#include <math.h>
#include <memory>
#include <vector>
#include <wx/log.h>
@ -311,7 +312,7 @@ WaveClip::WaveClip(DirManager *projDirManager, sampleFormat format, int rate)
mIsPlaceholder = false;
}
WaveClip::WaveClip(WaveClip& orig, DirManager *projDirManager)
WaveClip::WaveClip(const WaveClip& orig, DirManager *projDirManager)
{
// essentially a copy constructor - but you must pass in the
// current project's DirManager, because we might be copying
@ -1221,34 +1222,34 @@ bool WaveClip::CreateFromCopy(double t0, double t1, WaveClip* other)
return true;
}
bool WaveClip::Paste(double t0, WaveClip* other)
bool WaveClip::Paste(double t0, const WaveClip* other)
{
WaveClip* pastedClip;
bool clipNeedsResampling = other->mRate != mRate;
const bool clipNeedsResampling = other->mRate != mRate;
const bool clipNeedsNewFormat =
other->mSequence->GetSampleFormat() != mSequence->GetSampleFormat();
std::auto_ptr<WaveClip> newClip;
const WaveClip* pastedClip;
if (clipNeedsResampling || clipNeedsNewFormat)
{
newClip.reset(new WaveClip(*other, mSequence->GetDirManager()));
if (clipNeedsResampling)
{
// The other clip's rate is different to our's, so resample
pastedClip = new WaveClip(*other, mSequence->GetDirManager());
if (!pastedClip->Resample(mRate))
{
delete pastedClip;
// The other clip's rate is different from ours, so resample
if (!newClip->Resample(mRate))
return false;
}
if (clipNeedsNewFormat)
// Force sample formats to match.
newClip->ConvertToSampleFormat(mSequence->GetSampleFormat());
pastedClip = newClip.get();
} else
{
// No resampling needed, just use original clip without making a copy
// No resampling or format change needed, just use original clip without making a copy
pastedClip = other;
}
sampleCount s0;
TimeToSamplesClip(t0, &s0);
// Force sample formats to match.
if (pastedClip->mSequence->GetSampleFormat() != mSequence->GetSampleFormat())
pastedClip->ConvertToSampleFormat(mSequence->GetSampleFormat());
bool result = false;
if (mSequence->Paste(s0, pastedClip->mSequence))
{
@ -1270,12 +1271,6 @@ bool WaveClip::Paste(double t0, WaveClip* other)
result = true;
}
if (clipNeedsResampling)
{
// Clip was constructed as a copy, so delete it
delete pastedClip;
}
return result;
}

View File

@ -69,7 +69,7 @@ private:
WaveClip(const WaveClip&)
{
wxFAIL_MSG(wxT("It is an error to copy a WaveClip without specifying the DirManager."));
};
}
WaveClip& operator=(const WaveClip& orig)
{
WaveClip bogus(orig);
@ -83,7 +83,7 @@ public:
// essentially a copy constructor - but you must pass in the
// current project's DirManager, because we might be copying
// from one project to another
WaveClip(WaveClip& orig, DirManager *projDirManager);
WaveClip(const WaveClip& orig, DirManager *projDirManager);
virtual ~WaveClip();
@ -179,7 +179,7 @@ public:
bool ClearAndAddCutLine(double t0, double t1);
/// Paste data from other clip, resampling it if not equal rate
bool Paste(double t0, WaveClip* other);
bool Paste(double t0, const WaveClip* other);
/** Insert silence - note that this is an efficient operation for large
* amounts of silence */
@ -232,8 +232,8 @@ public:
SpecPxCache *mSpecPxCache;
// AWD, Oct 2009: for pasting whitespace at the end of selection
bool GetIsPlaceholder() { return mIsPlaceholder; };
void SetIsPlaceholder(bool val) { mIsPlaceholder = val; };
bool GetIsPlaceholder() const { return mIsPlaceholder; }
void SetIsPlaceholder(bool val) { mIsPlaceholder = val; }
protected:
wxRect mDisplayRect;