1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-18 17:10:05 +02:00

Remove some naked new amd delete in: tracks and clips

This commit is contained in:
Paul Licameli 2016-04-08 01:56:06 -04:00 committed by Paul Licameli
parent 8392a57d34
commit 20bee00115
12 changed files with 103 additions and 134 deletions

View File

@ -129,10 +129,6 @@ NoteTrack::~NoteTrack()
if (mSerializationBuffer) {
delete [] mSerializationBuffer;
}
if (mSeq) {
delete mSeq;
}
}
Track::Holder NoteTrack::Duplicate() const
@ -154,10 +150,10 @@ Track::Holder NoteTrack::Duplicate() const
} else if (mSerializationBuffer) {
SonifyBeginUnserialize();
assert(!mSeq);
Alg_track_ptr alg_track = Alg_seq::unserialize(mSerializationBuffer,
mSerializationLength);
std::unique_ptr<Alg_track> alg_track{ Alg_seq::unserialize(mSerializationBuffer,
mSerializationLength) };
assert(alg_track->get_type() == 's');
duplicate->mSeq = (Alg_seq_ptr) alg_track;
duplicate->mSeq.reset(static_cast<Alg_seq*>(alg_track.release()));
SonifyEndUnserialize();
} else assert(false); // bug if neither mSeq nor mSerializationBuffer
// copy some other fields here
@ -206,8 +202,7 @@ void NoteTrack::WarpAndTransposeNotes(double t0, double t1,
nt->mSerializationLength = mSerializationLength;
mSerializationBuffer = NULL;
mSerializationLength = 0;
mSeq = nt->mSeq;
nt->mSeq = NULL;
mSeq = std::move(nt->mSeq);
}
mSeq->convert_to_seconds(); // make sure time units are right
t1 -= offset; // adjust time range to compensate for track offset
@ -216,7 +211,7 @@ void NoteTrack::WarpAndTransposeNotes(double t0, double t1,
t1 = mSeq->get_dur();
if (t0 >= t1) return;
}
Alg_iterator iter(mSeq, false);
Alg_iterator iter(mSeq.get(), false);
iter.begin();
Alg_event_ptr event;
while (0 != (event = iter.next()) && event->time < t1) {
@ -368,17 +363,14 @@ bool NoteTrack::LabelClick(wxRect & r, int mx, int my, bool right)
return true;
}
void NoteTrack::SetSequence(Alg_seq_ptr seq)
void NoteTrack::SetSequence(std::unique_ptr<Alg_seq> &&seq)
{
if (mSeq)
delete mSeq;
mSeq = seq;
mSeq = std::move(seq);
}
Alg_seq* NoteTrack::GetSequence()
{
return mSeq;
return mSeq.get();
}
void NoteTrack::PrintSequence()
@ -454,7 +446,7 @@ Track::Holder NoteTrack::Cut(double t0, double t1)
newTrack->Init(*this);
mSeq->convert_to_seconds();
newTrack->mSeq = mSeq->cut(t0 - GetOffset(), len, false);
newTrack->mSeq.reset(mSeq->cut(t0 - GetOffset(), len, false));
newTrack->SetOffset(GetOffset());
// What should be done with the rest of newTrack's members?
@ -475,7 +467,7 @@ Track::Holder NoteTrack::Copy(double t0, double t1) const
newTrack->Init(*this);
mSeq->convert_to_seconds();
newTrack->mSeq = mSeq->copy(t0 - GetOffset(), len, false);
newTrack->mSeq.reset(mSeq->copy(t0 - GetOffset(), len, false));
newTrack->SetOffset(GetOffset());
// What should be done with the rest of newTrack's members?
@ -530,14 +522,14 @@ bool NoteTrack::Paste(double t, const Track *src)
return false;
if(!mSeq)
mSeq = new Alg_seq();
mSeq = std::make_unique<Alg_seq>();
if (other->GetOffset() > 0) {
mSeq->convert_to_seconds();
mSeq->insert_silence(t - GetOffset(), other->GetOffset());
t += other->GetOffset();
}
mSeq->paste(t - GetOffset(), other->mSeq);
mSeq->paste(t - GetOffset(), other->mSeq.get());
return true;
}
@ -596,24 +588,34 @@ bool NoteTrack::StretchRegion(double t0, double t1, double dur)
return result;
}
Alg_seq_ptr NoteTrack::MakeExportableSeq()
namespace
{
void swap(std::unique_ptr<Alg_seq> &a, std::unique_ptr<Alg_seq> &b)
{
std::unique_ptr<Alg_seq> tmp = std::move(a);
a = std::move(b);
b = std::move(tmp);
}
}
Alg_seq *NoteTrack::MakeExportableSeq(std::unique_ptr<Alg_seq> &cleanup)
{
cleanup.reset();
double offset = GetOffset();
if (offset == 0)
return mSeq;
return mSeq.get();
// make a copy, deleting events that are shifted before time 0
double start = -offset;
if (start < 0) start = 0;
// notes that begin before "start" are not included even if they
// extend past "start" (because "all" parameter is set to false)
Alg_seq_ptr seq = mSeq->copy(start, mSeq->get_dur() - start, false);
cleanup.reset( mSeq->copy(start, mSeq->get_dur() - start, false) );
auto seq = cleanup.get();
if (offset > 0) {
// swap seq and mSeq so that Shift operates on the NEW copy
Alg_seq_ptr old_seq = mSeq;
mSeq = seq;
// swap cleanup and mSeq so that Shift operates on the NEW copy
swap(mSeq, cleanup);
Shift(offset);
seq = mSeq; // undo the swap
mSeq = old_seq;
swap(mSeq, cleanup); // undo the swap
#ifdef OLD_CODE
// now shift events by offset. This must be done with an integer
// number of measures, so first, find the beats-per-measure
@ -717,9 +719,9 @@ Alg_seq_ptr NoteTrack::MakeExportableSeq()
bool NoteTrack::ExportMIDI(const wxString &f)
{
Alg_seq_ptr seq = MakeExportableSeq();
std::unique_ptr<Alg_seq> cleanup;
auto seq = MakeExportableSeq(cleanup);
bool rslt = seq->smf_write(f.mb_str());
if (seq != mSeq) delete seq;
return rslt;
}
@ -782,7 +784,7 @@ bool NoteTrack::HandleXMLTag(const wxChar *tag, const wxChar **attrs)
else if (!wxStrcmp(attr, wxT("data"))) {
std::string s(strValue.mb_str(wxConvUTF8));
std::istringstream data(s);
mSeq = new Alg_seq(data, false);
mSeq = std::make_unique<Alg_seq>(data, false);
}
} // while
return true;

View File

@ -72,13 +72,13 @@ class AUDACITY_DLL_API NoteTrack final : public Track {
int DrawLabelControls(wxDC & dc, wxRect & r);
bool LabelClick(wxRect & r, int x, int y, bool right);
void SetSequence(Alg_seq *seq);
void SetSequence(std::unique_ptr<Alg_seq> &&seq);
Alg_seq* GetSequence();
void PrintSequence();
int GetVisibleChannels();
Alg_seq_ptr MakeExportableSeq();
Alg_seq *MakeExportableSeq(std::unique_ptr<Alg_seq> &cleanup);
bool ExportMIDI(const wxString &f);
bool ExportAllegro(const wxString &f);
@ -186,7 +186,7 @@ class AUDACITY_DLL_API NoteTrack final : public Track {
void ClearVisibleChan(int c) { mVisibleChannels &= ~CHANNEL_BIT(c); }
void ToggleVisibleChan(int c) { mVisibleChannels ^= CHANNEL_BIT(c); }
private:
Alg_seq *mSeq; // NULL means no sequence
std::unique_ptr<Alg_seq> mSeq; // NULL means no sequence
// when Duplicate() is called, assume that it is to put a copy
// of the track into the undo stack or to redo/copy from the
// stack to the project object. We want copies to the stack

View File

@ -44,7 +44,7 @@ TimeTrack::TimeTrack(DirManager *projDirManager, const ZoomInfo *zoomInfo):
mRangeUpper = 1.1;
mDisplayLog = false;
mEnvelope = new Envelope();
mEnvelope = std::make_unique<Envelope>();
mEnvelope->SetTrackLen(1000000000.0);
mEnvelope->SetInterpolateDB(true);
mEnvelope->Flatten(1.0);
@ -55,7 +55,7 @@ TimeTrack::TimeTrack(DirManager *projDirManager, const ZoomInfo *zoomInfo):
SetDefaultName(_("Time Track"));
SetName(GetDefaultName());
mRuler = new Ruler;
mRuler = std::make_unique<Ruler>();
mRuler->SetUseZoomInfo(0, mZoomInfo);
mRuler->SetLabelEdges(false);
mRuler->SetFormat(Ruler::TimeFormat);
@ -71,17 +71,17 @@ TimeTrack::TimeTrack(const TimeTrack &orig):
Init(orig); // this copies the TimeTrack metadata (name, range, etc)
///@TODO: Give Envelope:: a copy-constructor instead of this?
mEnvelope = new Envelope();
mEnvelope = std::make_unique<Envelope>();
mEnvelope->SetTrackLen(1000000000.0);
SetInterpolateLog(orig.GetInterpolateLog()); // this calls Envelope::SetInterpolateDB
mEnvelope->Flatten(1.0);
mEnvelope->Mirror(false);
mEnvelope->SetOffset(0);
mEnvelope->SetRange(orig.mEnvelope->GetMinValue(), orig.mEnvelope->GetMaxValue());
mEnvelope->Paste(0.0, orig.mEnvelope);
mEnvelope->Paste(0.0, orig.mEnvelope.get());
///@TODO: Give Ruler:: a copy-constructor instead of this?
mRuler = new Ruler;
mRuler = std::make_unique<Ruler>();
mRuler->SetUseZoomInfo(0, mZoomInfo);
mRuler->SetLabelEdges(false);
mRuler->SetFormat(Ruler::TimeFormat);
@ -103,10 +103,6 @@ void TimeTrack::Init(const TimeTrack &orig)
TimeTrack::~TimeTrack()
{
delete mEnvelope;
mEnvelope = NULL;
delete mRuler;
}
Track::Holder TimeTrack::Duplicate() const
@ -205,7 +201,7 @@ void TimeTrack::HandleXMLEndTag(const wxChar * WXUNUSED(tag))
XMLTagHandler *TimeTrack::HandleXMLChild(const wxChar *tag)
{
if (!wxStrcmp(tag, wxT("envelope")))
return mEnvelope;
return mEnvelope.get();
return NULL;
}

View File

@ -67,8 +67,8 @@ class TimeTrack final : public Track {
// Access the track's speed envelope
Envelope *GetEnvelope() { return mEnvelope; }
const Envelope *GetEnvelope() const { return mEnvelope; }
Envelope *GetEnvelope() { return mEnvelope.get(); }
const Envelope *GetEnvelope() const { return mEnvelope.get(); }
//Note: The meaning of this function has changed (December 2012)
//Previously this function did something that was close to the opposite (but not entirely accurate).
@ -119,8 +119,8 @@ class TimeTrack final : public Track {
private:
const ZoomInfo *const mZoomInfo;
Envelope *mEnvelope;
Ruler *mRuler;
std::unique_ptr<Envelope> mEnvelope;
std::unique_ptr<Ruler> mRuler;
double mRangeLower;
double mRangeUpper;
bool mDisplayLog;

View File

@ -2232,8 +2232,7 @@ void TrackArtist::DrawClipSpectrum(WaveTrackCache &waveTrackCache,
}
else {
// Update the spectrum pixel cache
delete clip->mSpecPxCache;
clip->mSpecPxCache = new SpecPxCache(hiddenMid.width * hiddenMid.height);
clip->mSpecPxCache = std::make_unique<SpecPxCache>(hiddenMid.width * hiddenMid.height);
clip->mSpecPxCache->valid = true;
clip->mSpecPxCache->scaleType = scaleType;
clip->mSpecPxCache->gain = gain;
@ -2727,7 +2726,7 @@ void TrackArtist::DrawNoteBackground(const NoteTrack *track, wxDC &dc,
}
// draw bar lines
Alg_seq_ptr seq = track->mSeq;
Alg_seq_ptr seq = track->mSeq.get();
// We assume that sliding a NoteTrack around slides the barlines
// along with the notes. This means that when we write out a track
// as Allegro or MIDI without the offset, we'll need to insert an
@ -2779,16 +2778,16 @@ void TrackArtist::DrawNoteTrack(const NoteTrack *track,
const double h = X_TO_TIME(rect.x);
const double h1 = X_TO_TIME(rect.x + rect.width);
Alg_seq_ptr seq = track->mSeq;
Alg_seq_ptr seq = track->mSeq.get();
if (!seq) {
assert(track->mSerializationBuffer);
// JKC: Previously this indirected via seq->, a NULL pointer.
// This was actually OK, since unserialize is a static function.
// Alg_seq:: is clearer.
Alg_track_ptr alg_track = Alg_seq::unserialize(track->mSerializationBuffer,
track->mSerializationLength);
std::unique_ptr<Alg_track> alg_track{ Alg_seq::unserialize(track->mSerializationBuffer,
track->mSerializationLength) };
assert(alg_track->get_type() == 's');
const_cast<NoteTrack*>(track)->mSeq = seq = (Alg_seq_ptr) alg_track;
const_cast<NoteTrack*>(track)->mSeq.reset(seq = static_cast<Alg_seq*>(alg_track.release()));
free(track->mSerializationBuffer);
track->mSerializationBuffer = NULL;
}

View File

@ -293,10 +293,10 @@ WaveClip::WaveClip(DirManager *projDirManager, sampleFormat format, int rate)
mOffset = 0;
mRate = rate;
mSequence = std::make_unique<Sequence>(projDirManager, format);
mEnvelope = new Envelope();
mWaveCache = new WaveCache();
mSpecCache = new SpecCache();
mSpecPxCache = new SpecPxCache(1);
mEnvelope = std::make_unique<Envelope>();
mWaveCache = std::make_unique<WaveCache>();
mSpecCache = std::make_unique<SpecCache>();
mSpecPxCache = std::make_unique<SpecPxCache>(1);
mAppendBufferLen = 0;
mDirty = 0;
mIsPlaceholder = false;
@ -311,13 +311,13 @@ WaveClip::WaveClip(const WaveClip& orig, DirManager *projDirManager)
mOffset = orig.mOffset;
mRate = orig.mRate;
mSequence = std::make_unique<Sequence>(*orig.mSequence, projDirManager);
mEnvelope = new Envelope();
mEnvelope->Paste(0.0, orig.mEnvelope);
mEnvelope = std::make_unique<Envelope>();
mEnvelope->Paste(0.0, orig.mEnvelope.get());
mEnvelope->SetOffset(orig.GetOffset());
mEnvelope->SetTrackLen(((double)orig.mSequence->GetNumSamples()) / orig.mRate);
mWaveCache = new WaveCache();
mSpecCache = new SpecCache();
mSpecPxCache = new SpecPxCache(1);
mWaveCache = std::make_unique<WaveCache>();
mSpecCache = std::make_unique<SpecCache>();
mSpecPxCache = std::make_unique<SpecPxCache>(1);
for (WaveClipList::compatibility_iterator it=orig.mCutLines.GetFirst(); it; it=it->GetNext())
mCutLines.Append(new WaveClip(*it->GetData(), projDirManager));
@ -329,13 +329,6 @@ WaveClip::WaveClip(const WaveClip& orig, DirManager *projDirManager)
WaveClip::~WaveClip()
{
delete mEnvelope;
mEnvelope = NULL;
delete mWaveCache;
delete mSpecCache;
delete mSpecPxCache;
mCutLines.DeleteContents(true);
mCutLines.Clear();
}
@ -416,12 +409,10 @@ bool WaveClip::AfterClip(double t) const
}
///Delete the wave cache - force redraw. Thread-safe
void WaveClip::DeleteWaveCache()
void WaveClip::ClearWaveCache()
{
ODLocker locker(&mWaveCacheMutex);
if(mWaveCache!=NULL)
delete mWaveCache;
mWaveCache = new WaveCache();
mWaveCache = std::make_unique<WaveCache>();
}
///Adds an invalid region to the wavecache so it redraws that portion only.
@ -556,8 +547,7 @@ bool WaveClip::GetWaveDisplay(WaveDisplay &display, double t0,
return true;
}
std::unique_ptr<WaveCache> oldCache(mWaveCache);
mWaveCache = 0;
std::unique_ptr<WaveCache> oldCache(std::move(mWaveCache));
int oldX0 = 0;
double correction = 0.0;
@ -577,7 +567,7 @@ bool WaveClip::GetWaveDisplay(WaveDisplay &display, double t0,
if (!(copyEnd > copyBegin))
oldCache.reset(0);
mWaveCache = new WaveCache(numPixels, pixelsPerSecond, mRate, t0, mDirty);
mWaveCache = std::make_unique<WaveCache>(numPixels, pixelsPerSecond, mRate, t0, mDirty);
min = &mWaveCache->min[0];
max = &mWaveCache->max[0];
rms = &mWaveCache->rms[0];
@ -1098,8 +1088,7 @@ bool WaveClip::GetSpectrogram(WaveTrackCache &waveTrackCache,
// a complete hit, because of the complications of time reassignment
match = false;
std::unique_ptr<SpecCache> oldCache(mSpecCache);
mSpecCache = 0;
std::unique_ptr<SpecCache> oldCache(std::move(mSpecCache));
const double tstep = 1.0 / pixelsPerSecond;
const double samplesPerPixel = mRate * tstep;
@ -1124,7 +1113,7 @@ bool WaveClip::GetSpectrogram(WaveTrackCache &waveTrackCache,
if (!(copyEnd > copyBegin))
oldCache.reset(0);
mSpecCache = new SpecCache(
mSpecCache = std::make_unique<SpecCache>(
numPixels, settings.algorithm, pixelsPerSecond, t0,
windowType, windowSize, zeroPaddingFactor, frequencyGain);
@ -1368,7 +1357,7 @@ XMLTagHandler *WaveClip::HandleXMLChild(const wxChar *tag)
if (!wxStrcmp(tag, wxT("sequence")))
return mSequence.get();
else if (!wxStrcmp(tag, wxT("envelope")))
return mEnvelope;
return mEnvelope.get();
else if (!wxStrcmp(tag, wxT("waveclip")))
{
// Nested wave clips are cut lines
@ -1402,16 +1391,14 @@ bool WaveClip::CreateFromCopy(double t0, double t1, const WaveClip* other)
other->TimeToSamplesClip(t1, &s1);
std::unique_ptr<Sequence> oldSequence = std::move(mSequence);
mSequence = NULL;
if (!other->mSequence->Copy(s0, s1, mSequence))
{
mSequence = std::move(oldSequence);
return false;
}
delete mEnvelope;
mEnvelope = new Envelope();
mEnvelope->CopyFrom(other->mEnvelope, (double)s0/mRate, (double)s1/mRate);
mEnvelope = std::make_unique<Envelope>();
mEnvelope->CopyFrom(other->mEnvelope.get(), (double)s0/mRate, (double)s1/mRate);
MarkChanged();
@ -1450,7 +1437,7 @@ bool WaveClip::Paste(double t0, const WaveClip* other)
if (mSequence->Paste(s0, pastedClip->mSequence.get()))
{
MarkChanged();
mEnvelope->Paste((double)s0/mRate + mOffset, pastedClip->mEnvelope);
mEnvelope->Paste((double)s0/mRate + mOffset, pastedClip->mEnvelope.get());
mEnvelope->RemoveUnneededPoints();
OffsetCutLines(t0, pastedClip->GetEndTime() - pastedClip->GetStartTime());
@ -1788,16 +1775,9 @@ bool WaveClip::Resample(int rate, ProgressDialog *progress)
mRate = rate;
// Invalidate wave display cache
if (mWaveCache)
{
delete mWaveCache;
mWaveCache = NULL;
}
mWaveCache = new WaveCache();
mWaveCache = std::make_unique<WaveCache>();
// Invalidate the spectrum display cache
if (mSpecCache)
delete mSpecCache;
mSpecCache = new SpecCache();
mSpecCache = std::make_unique<SpecCache>();
}
return !error;

View File

@ -251,8 +251,8 @@ public:
bool SetSamples(samplePtr buffer, sampleFormat format,
sampleCount start, sampleCount len);
Envelope* GetEnvelope() { return mEnvelope; }
const Envelope* GetEnvelope() const { return mEnvelope; }
Envelope* GetEnvelope() { return mEnvelope.get(); }
const Envelope* GetEnvelope() const { return mEnvelope.get(); }
BlockArray* GetSequenceBlockArray();
// Get low-level access to the sequence. Whenever possible, don't use this,
@ -348,7 +348,7 @@ public:
// not balanced by unlocking calls.
///Delete the wave cache - force redraw. Thread-safe
void DeleteWaveCache();
void ClearWaveCache();
///Adds an invalid region to the wavecache so it redraws that portion only.
void AddInvalidRegion(long startSample, long endSample);
@ -363,7 +363,7 @@ public:
void WriteXML(XMLWriter &xmlFile) /* not override */;
// Cache of values to colour pixels of Spectrogram - used by TrackArtist
mutable SpecPxCache *mSpecPxCache;
mutable std::unique_ptr<SpecPxCache> mSpecPxCache;
// AWD, Oct 2009: for pasting whitespace at the end of selection
bool GetIsPlaceholder() const { return mIsPlaceholder; }
@ -377,11 +377,11 @@ protected:
int mDirty;
bool mIsCutLine;
std::unique_ptr<Sequence> mSequence;
Envelope *mEnvelope;
std::unique_ptr<Envelope> mEnvelope;
mutable WaveCache *mWaveCache;
mutable std::unique_ptr<WaveCache> mWaveCache;
mutable ODLock mWaveCacheMutex;
mutable SpecCache *mSpecCache;
mutable std::unique_ptr<SpecCache> mSpecCache;
SampleBuffer mAppendBuffer;
sampleCount mAppendBufferLen;

View File

@ -78,8 +78,6 @@ WaveTrack::Holder TrackFactory::NewWaveTrack(sampleFormat format, double rate)
WaveTrack::WaveTrack(DirManager *projDirManager, sampleFormat format, double rate) :
Track(projDirManager)
, mpSpectrumSettings(0)
, mpWaveformSettings(0)
{
if (format == (sampleFormat)0)
{
@ -163,9 +161,9 @@ void WaveTrack::Merge(const Track &orig)
mDisplayMin = wt.mDisplayMin;
mDisplayMax = wt.mDisplayMax;
SetSpectrogramSettings(wt.mpSpectrumSettings
? new SpectrogramSettings(*wt.mpSpectrumSettings) : 0);
? std::make_unique<SpectrogramSettings>(*wt.mpSpectrumSettings) : nullptr);
SetWaveformSettings
(wt.mpWaveformSettings ? new WaveformSettings(*wt.mpWaveformSettings) : 0);
(wt.mpWaveformSettings ? std::make_unique<WaveformSettings>(*wt.mpWaveformSettings) : nullptr);
}
Track::Merge(orig);
}
@ -180,9 +178,6 @@ WaveTrack::~WaveTrack()
for (WaveClipList::compatibility_iterator it=GetClipIterator(); it; it=it->GetNext())
delete it->GetData();
mClips.Clear();
delete mpSpectrumSettings;
delete mpWaveformSettings;
}
double WaveTrack::GetOffset() const
@ -763,15 +758,14 @@ SpectrogramSettings &WaveTrack::GetIndependentSpectrogramSettings()
{
if (!mpSpectrumSettings)
mpSpectrumSettings =
new SpectrogramSettings(SpectrogramSettings::defaults());
std::make_unique<SpectrogramSettings>(SpectrogramSettings::defaults());
return *mpSpectrumSettings;
}
void WaveTrack::SetSpectrogramSettings(SpectrogramSettings *pSettings)
void WaveTrack::SetSpectrogramSettings(std::unique_ptr<SpectrogramSettings> &&pSettings)
{
if (mpSpectrumSettings != pSettings) {
delete mpSpectrumSettings;
mpSpectrumSettings = pSettings;
mpSpectrumSettings = std::move(pSettings);
}
}
@ -794,15 +788,14 @@ WaveformSettings &WaveTrack::GetWaveformSettings()
WaveformSettings &WaveTrack::GetIndependentWaveformSettings()
{
if (!mpWaveformSettings)
mpWaveformSettings = new WaveformSettings(WaveformSettings::defaults());
mpWaveformSettings = std::make_unique<WaveformSettings>(WaveformSettings::defaults());
return *mpWaveformSettings;
}
void WaveTrack::SetWaveformSettings(WaveformSettings *pSettings)
void WaveTrack::SetWaveformSettings(std::unique_ptr<WaveformSettings> &&pSettings)
{
if (mpWaveformSettings != pSettings) {
delete mpWaveformSettings;
mpWaveformSettings = pSettings;
mpWaveformSettings = std::move(pSettings);
}
}
@ -2643,10 +2636,10 @@ void WaveTrack::FillSortedClipArray(WaveClipArray& clips) const
}
///Deletes all clips' wavecaches. Careful, This may not be threadsafe.
void WaveTrack::DeleteWaveCaches()
void WaveTrack::ClearWaveCaches()
{
for (WaveClipList::compatibility_iterator it=GetClipIterator(); it; it=it->GetNext())
it->GetData()->DeleteWaveCache();
it->GetData()->ClearWaveCache();
}
///Adds an invalid region to the wavecache so it redraws that portion only.

View File

@ -145,12 +145,12 @@ class AUDACITY_DLL_API WaveTrack final : public Track {
const SpectrogramSettings &GetSpectrogramSettings() const;
SpectrogramSettings &GetSpectrogramSettings();
SpectrogramSettings &GetIndependentSpectrogramSettings();
void SetSpectrogramSettings(SpectrogramSettings *pSettings);
void SetSpectrogramSettings(std::unique_ptr<SpectrogramSettings> &&pSettings);
const WaveformSettings &GetWaveformSettings() const;
WaveformSettings &GetWaveformSettings();
WaveformSettings &GetIndependentWaveformSettings();
void SetWaveformSettings(WaveformSettings *pSettings);
void SetWaveformSettings(std::unique_ptr<WaveformSettings> &&pSettings);
//
// High-level editing
@ -219,8 +219,8 @@ class AUDACITY_DLL_API WaveTrack final : public Track {
///gets an int with OD flags so that we can determine which ODTasks should be run on this track after save/open, etc.
unsigned int GetODFlags();
///Deletes all clips' wavecaches. Careful, This may not be threadsafe.
void DeleteWaveCaches();
///Invalidates all clips' wavecaches. Careful, This may not be threadsafe.
void ClearWaveCaches();
///Adds an invalid region to the wavecache so it redraws that portion only.
void AddInvalidRegion(sampleCount startSample, sampleCount endSample);
@ -520,8 +520,8 @@ class AUDACITY_DLL_API WaveTrack final : public Track {
double mLegacyProjectFileOffset;
int mAutoSaveIdent;
SpectrogramSettings *mpSpectrumSettings;
WaveformSettings *mpWaveformSettings;
std::unique_ptr<SpectrogramSettings> mpSpectrumSettings;
std::unique_ptr<WaveformSettings> mpWaveformSettings;
};
// This is meant to be a short-lived object, during whose lifetime,

View File

@ -47,23 +47,22 @@ bool ImportMIDI(const wxString &fName, NoteTrack * dest)
}
double offset = 0.0;
Alg_seq_ptr new_seq = new Alg_seq(fName.mb_str(), is_midi, &offset);
auto new_seq = std::make_unique<Alg_seq>(fName.mb_str(), is_midi, &offset);
//Should we also check if(seq->tracks() == 0) ?
if(new_seq->get_read_error() == alg_error_open){
wxMessageBox( _("Could not open file ") + fName + wxT("."));
mf.Close();
delete new_seq;
return false;
}
dest->SetSequence(new_seq);
dest->SetSequence(std::move(new_seq));
dest->SetOffset(offset);
wxString trackNameBase = fName.AfterLast(wxFILE_SEP_PATH).BeforeLast('.');
dest->SetName(trackNameBase);
mf.Close();
// the mean pitch should be somewhere in the middle of the display
Alg_iterator iterator(new_seq, false);
Alg_iterator iterator(dest->GetSequence(), false);
iterator.begin();
// for every event
Alg_event_ptr evt;

View File

@ -382,11 +382,11 @@ bool SpectrumPrefs::Apply()
if (mWt) {
if (mDefaulted) {
mWt->SetSpectrogramSettings(NULL);
mWt->SetSpectrogramSettings({});
// ... and so that the vertical scale also defaults:
mWt->SetSpectrumBounds(-1, -1);
if (partner) {
partner->SetSpectrogramSettings(NULL);
partner->SetSpectrogramSettings({});
partner->SetSpectrumBounds(-1, -1);
}
}

View File

@ -147,9 +147,9 @@ bool WaveformPrefs::Apply()
if (mWt) {
if (mDefaulted) {
mWt->SetWaveformSettings(NULL);
mWt->SetWaveformSettings({});
if (partner)
partner->SetWaveformSettings(NULL);
partner->SetWaveformSettings({});
}
else {
WaveformSettings *pSettings =