diff --git a/src/Menus.cpp b/src/Menus.cpp index 658afe94b..cb548d5e1 100644 --- a/src/Menus.cpp +++ b/src/Menus.cpp @@ -6246,7 +6246,10 @@ void AudacityProject::OnScoreAlign() // that it can be delted by CloseScoreAlignDialog() either here or // if the program is quit by the user while the dialog is up. ScoreAlignParams params; - ScoreAlignDialog *dlog = new ScoreAlignDialog(NULL, params); + + // safe because the class maintains a global resource pointer + safenew ScoreAlignDialog(params); + CloseScoreAlignDialog(); if (params.mStatus != wxID_OK) return; diff --git a/src/effects/AutoDuck.cpp b/src/effects/AutoDuck.cpp index efe9e9f82..96dfc26d1 100644 --- a/src/effects/AutoDuck.cpp +++ b/src/effects/AutoDuck.cpp @@ -629,8 +629,6 @@ EffectAutoDuckPanel::EffectAutoDuckPanel(wxWindow *parent, EffectAutoDuck *effec EffectAutoDuckPanel::~EffectAutoDuckPanel() { - if (mBackgroundBitmap) - delete mBackgroundBitmap; if(HasCapture()) ReleaseMouse(); } @@ -652,9 +650,7 @@ void EffectAutoDuckPanel::OnPaint(wxPaintEvent & WXUNUSED(evt)) if (!mBackgroundBitmap || mBackgroundBitmap->GetWidth() != clientWidth || mBackgroundBitmap->GetHeight() != clientHeight) { - if (mBackgroundBitmap) - delete mBackgroundBitmap; - mBackgroundBitmap = new wxBitmap(clientWidth, clientHeight); + mBackgroundBitmap = std::make_unique(clientWidth, clientHeight); } wxMemoryDC dc; diff --git a/src/effects/AutoDuck.h b/src/effects/AutoDuck.h index ba53752b7..eedec53cc 100644 --- a/src/effects/AutoDuck.h +++ b/src/effects/AutoDuck.h @@ -125,7 +125,7 @@ private: private: wxWindow *mParent; EffectAutoDuck *mEffect; - wxBitmap *mBackgroundBitmap; + std::unique_ptr mBackgroundBitmap; EControlPoint mCurrentControlPoint; wxPoint mControlPoints[AUTO_DUCK_PANEL_NUM_CONTROL_POINTS]; wxPoint mMoveStartControlPoints[AUTO_DUCK_PANEL_NUM_CONTROL_POINTS]; diff --git a/src/effects/ChangePitch.cpp b/src/effects/ChangePitch.cpp index 31bd496be..f29272001 100644 --- a/src/effects/ChangePitch.cpp +++ b/src/effects/ChangePitch.cpp @@ -154,14 +154,14 @@ bool EffectChangePitch::LoadFactoryDefaults() bool EffectChangePitch::Init() { - mSoundTouch = NULL; + mSoundTouch.reset(); return true; } bool EffectChangePitch::Process() { - mSoundTouch = new SoundTouch(); - SetTimeWarper(new IdentityTimeWarper()); + mSoundTouch = std::make_unique(); + SetTimeWarper(std::make_unique()); mSoundTouch->setPitchSemiTones((float)(m_dSemitonesChange)); #ifdef USE_MIDI // Note: m_dSemitonesChange is private to ChangePitch because it only diff --git a/src/effects/ChangeSpeed.cpp b/src/effects/ChangeSpeed.cpp index 87db245c8..8c1cf8c25 100644 --- a/src/effects/ChangeSpeed.cpp +++ b/src/effects/ChangeSpeed.cpp @@ -455,8 +455,8 @@ bool EffectChangeSpeed::TransferDataFromWindow() // the region are shifted along according to how the region size changed. bool EffectChangeSpeed::ProcessLabelTrack(Track *t) { - SetTimeWarper(new RegionTimeWarper(mT0, mT1, - new LinearTimeWarper(mT0, mT0, + SetTimeWarper(std::make_unique(mT0, mT1, + std::make_unique(mT0, mT0, mT1, mT0 + (mT1-mT0)*mFactor))); LabelTrack *lt = (LabelTrack*)t; if (lt == NULL) return false; @@ -551,7 +551,7 @@ bool EffectChangeSpeed::ProcessOne(WaveTrack * track, double newLength = outputTrack->GetEndTime(); if (bResult) { - SetTimeWarper(new LinearTimeWarper(mCurT0, mCurT0, mCurT1, mCurT0 + newLength)); + SetTimeWarper(std::make_unique(mCurT0, mCurT0, mCurT1, mCurT0 + newLength)); bResult = track->ClearAndPaste(mCurT0, mCurT1, outputTrack.get(), true, false, GetTimeWarper()); } diff --git a/src/effects/ChangeTempo.cpp b/src/effects/ChangeTempo.cpp index 9caa05a03..b47903dc6 100644 --- a/src/effects/ChangeTempo.cpp +++ b/src/effects/ChangeTempo.cpp @@ -139,18 +139,18 @@ bool EffectChangeTempo::Init() m_FromLength = mT1 - mT0; m_ToLength = (m_FromLength * 100.0) / (100.0 + m_PercentChange); - mSoundTouch = NULL; + mSoundTouch.reset(); return true; } bool EffectChangeTempo::Process() { - mSoundTouch = new SoundTouch(); + mSoundTouch = std::make_unique(); mSoundTouch->setTempoChange(m_PercentChange); double mT1Dashed = mT0 + (mT1 - mT0)/(m_PercentChange/100.0 + 1.0); - SetTimeWarper(new RegionTimeWarper(mT0, mT1, - new LinearTimeWarper(mT0, mT0, mT1, mT1Dashed ))); + SetTimeWarper(std::make_unique(mT0, mT1, + std::make_unique(mT0, mT0, mT1, mT1Dashed ))); bool success = EffectSoundTouch::Process(); if( success ) mT1 = mT0 + (mT1 - mT0)/(m_PercentChange/100 + 1.); diff --git a/src/effects/Effect.cpp b/src/effects/Effect.cpp index 4a459493b..fbb1eda28 100644 --- a/src/effects/Effect.cpp +++ b/src/effects/Effect.cpp @@ -141,11 +141,6 @@ Effect::~Effect() delete mOutputTracks; } - if (mWarper != NULL) - { - delete mWarper; - } - if (mUIDialog) { mUIDialog->Close(); @@ -2055,22 +2050,16 @@ void Effect::GetSamples(WaveTrack *track, sampleCount *start, sampleCount *len) } } -void Effect::SetTimeWarper(TimeWarper *warper) +void Effect::SetTimeWarper(std::unique_ptr &&warper) { - if (mWarper != NULL) - { - delete mWarper; - mWarper = NULL; - } - - wxASSERT(warper != NULL); - mWarper = warper; + wxASSERT(warper); + mWarper = std::move(warper); } TimeWarper *Effect::GetTimeWarper() { - wxASSERT(mWarper != NULL); - return mWarper; + wxASSERT(mWarper); + return mWarper.get(); } // diff --git a/src/effects/Effect.h b/src/effects/Effect.h index a24c90966..bf350d5da 100644 --- a/src/effects/Effect.h +++ b/src/effects/Effect.h @@ -330,7 +330,7 @@ protected: // Calculates the start time and selection length in samples void GetSamples(WaveTrack *track, sampleCount *start, sampleCount *len); - void SetTimeWarper(TimeWarper *warper); + void SetTimeWarper(std::unique_ptr &&warper); TimeWarper *GetTimeWarper(); // Previewing linear effect can be optimised by pre-mixing. However this @@ -446,7 +446,7 @@ protected: double mF0; double mF1; #endif - TimeWarper *mWarper; + std::unique_ptr mWarper; wxArrayString mPresetNames; wxArrayString mPresetValues; int mPass; diff --git a/src/effects/EffectRack.cpp b/src/effects/EffectRack.cpp index 70adf8f0a..96f7aced6 100644 --- a/src/effects/EffectRack.cpp +++ b/src/effects/EffectRack.cpp @@ -423,9 +423,8 @@ void EffectRack::OnRemove(wxCommandEvent & evt) for (int i = 0; i < NUMCOLS; i++) { - wxWindow *w = mMainSizer->GetItem(index)->GetWindow(); + std::unique_ptr w {mMainSizer->GetItem(index)->GetWindow()}; mMainSizer->Detach(index); - delete w; } mMainSizer->Layout(); diff --git a/src/effects/Equalization.cpp b/src/effects/Equalization.cpp index ddaf0370d..3267eff88 100644 --- a/src/effects/Equalization.cpp +++ b/src/effects/Equalization.cpp @@ -224,10 +224,6 @@ EffectEqualization::EffectEqualization() SetLinearEffectFlag(true); -#ifdef EXPERIMENTAL_EQ_SSE_THREADED - mEffectEqualization48x=NULL; -#endif - mM = DEF_FilterLength; mLin = DEF_InterpLin; mInterp = DEF_InterpMeth; @@ -243,17 +239,17 @@ EffectEqualization::EffectEqualization() mInterpolations.Add(wxGetTranslation(kInterpStrings[i])); } - mLogEnvelope = new Envelope(); + mLogEnvelope = std::make_unique(); mLogEnvelope->SetInterpolateDB(false); mLogEnvelope->Mirror(false); mLogEnvelope->SetRange(MIN_dBMin, MAX_dBMax); // MB: this is the highest possible range - mLinEnvelope = new Envelope(); + mLinEnvelope = std::make_unique(); mLinEnvelope->SetInterpolateDB(false); mLinEnvelope->Mirror(false); mLinEnvelope->SetRange(MIN_dBMin, MAX_dBMax); // MB: this is the highest possible range - mEnvelope = (mLin ? mLinEnvelope : mLogEnvelope); + mEnvelope = (mLin ? mLinEnvelope : mLogEnvelope).get(); mWindowSize = windowSize; @@ -278,12 +274,9 @@ EffectEqualization::EffectEqualization() bool useSSE; GetPrivateConfig(GetCurrentSettingsGroup(), wxT("/SSE/GUI"), useSSE, false); if(useSSE && !mEffectEqualization48x) - mEffectEqualization48x=new EffectEqualization48x; - else - if(!useSSE && mEffectEqualization48x) { - delete mEffectEqualization48x; - mEffectEqualization48x=NULL; - } + mEffectEqualization48x = std::make_unique(); + else if(!useSSE) + mEffectEqualization48x.reset(); mBench=false; #endif } @@ -291,13 +284,6 @@ EffectEqualization::EffectEqualization() EffectEqualization::~EffectEqualization() { - if(mLogEnvelope) - delete mLogEnvelope; - mLogEnvelope = NULL; - if(mLinEnvelope) - delete mLinEnvelope; - mLinEnvelope = NULL; - if(hFFT) EndFFT(hFFT); hFFT = NULL; @@ -310,10 +296,6 @@ EffectEqualization::~EffectEqualization() delete[] mFilterFuncI; mFilterFuncR = NULL; mFilterFuncI = NULL; -#ifdef EXPERIMENTAL_EQ_SSE_THREADED - if(mEffectEqualization48x) - delete mEffectEqualization48x; -#endif } // IdentInterface implementation @@ -372,7 +354,7 @@ bool EffectEqualization::SetAutomationParameters(EffectAutomationParameters & pa InterpMeth -= kNumInterpolations; } - mEnvelope = (mLin ? mLinEnvelope : mLogEnvelope); + mEnvelope = (mLin ? mLinEnvelope : mLogEnvelope).get(); return true; } @@ -534,7 +516,7 @@ bool EffectEqualization::Init() break; } - mEnvelope = (mLin ? mLinEnvelope : mLogEnvelope); + mEnvelope = (mLin ? mLinEnvelope : mLogEnvelope).get(); setCurve(mCurveName); @@ -1669,10 +1651,10 @@ void EffectEqualization::setCurve(int currentCurve) int numPoints = (int) mCurves[currentCurve].points.GetCount(); if (mLin) { // linear freq mode - env = mLinEnvelope; + env = mLinEnvelope.get(); } else { // log freq mode - env = mLogEnvelope; + env = mLogEnvelope.get(); } env->Flatten(0.); env->SetTrackLen(1.0); @@ -1856,11 +1838,11 @@ void EffectEqualization::EnvelopeUpdated() { if (IsLinear()) { - EnvelopeUpdated(mLinEnvelope, true); + EnvelopeUpdated(mLinEnvelope.get(), true); } else { - EnvelopeUpdated(mLogEnvelope, false); + EnvelopeUpdated(mLogEnvelope.get(), false); } } @@ -2205,7 +2187,7 @@ void EffectEqualization::UpdateDraw() if(mLin) // do not use IsLinear() here { EnvLogToLin(); - mEnvelope = mLinEnvelope; + mEnvelope = mLinEnvelope.get(); mFreqRuler->ruler.SetLog(false); mFreqRuler->ruler.SetRange(0, mHiFreq); } @@ -2237,7 +2219,7 @@ void EffectEqualization::UpdateGraphic() } EnvLinToLog(); - mEnvelope = mLogEnvelope; + mEnvelope = mLogEnvelope.get(); mFreqRuler->ruler.SetLog(true); mFreqRuler->ruler.SetRange(mLoFreq, mHiFreq); } @@ -2287,7 +2269,7 @@ void EffectEqualization::UpdateGraphic() mUIParent->Fit(); } #endif - GraphicEQ(mLogEnvelope); + GraphicEQ(mLogEnvelope.get()); mDrawMode = false; } @@ -2360,7 +2342,7 @@ void EffectEqualization::EnvLinToLog(void) delete [] value; if(changed) - EnvelopeUpdated(mLogEnvelope, false); + EnvelopeUpdated(mLogEnvelope.get(), false); } void EffectEqualization::ErrMin(void) @@ -2379,7 +2361,7 @@ void EffectEqualization::ErrMin(void) testEnvelope.SetRange(-120.0, 60.0); testEnvelope.Flatten(0.); testEnvelope.SetTrackLen(1.0); - testEnvelope.CopyFrom(mLogEnvelope, 0.0, 1.0); + testEnvelope.CopyFrom(mLogEnvelope.get(), 0.0, 1.0); for(i=0; i < NUM_PTS; i++) vals[i] = testEnvelope.GetValue(mWhens[i]); @@ -2675,7 +2657,7 @@ void EffectEqualization::OnSlider(wxCommandEvent & event) break; } } - GraphicEQ(mLogEnvelope); + GraphicEQ(mLogEnvelope.get()); EnvelopeUpdated(); } @@ -2683,7 +2665,7 @@ void EffectEqualization::OnInterp(wxCommandEvent & WXUNUSED(event)) { if (mGraphic->GetValue()) { - GraphicEQ(mLogEnvelope); + GraphicEQ(mLogEnvelope.get()); EnvelopeUpdated(); } mInterp = mInterpChoice->GetSelection(); @@ -2768,7 +2750,7 @@ void EffectEqualization::OnInvert(wxCommandEvent & WXUNUSED(event)) // Inverts a tip.Printf( wxT("%gkHz\n%.1fdB"), kThirdOct[i]/1000., mEQVals[i] ); mSliders[i]->SetToolTip(tip); } - GraphicEQ(mLogEnvelope); + GraphicEQ(mLogEnvelope.get()); } else // Draw mode. Invert the points. { @@ -2835,7 +2817,7 @@ void EffectEqualization::OnLinFreq(wxCommandEvent & WXUNUSED(event)) mFreqRuler->ruler.SetLog(false); mFreqRuler->ruler.SetRange(0, mHiFreq); EnvLogToLin(); - mEnvelope = mLinEnvelope; + mEnvelope = mLinEnvelope.get(); mLin = true; } else //going from lin to log freq scale @@ -2843,7 +2825,7 @@ void EffectEqualization::OnLinFreq(wxCommandEvent & WXUNUSED(event)) mFreqRuler->ruler.SetLog(true); mFreqRuler->ruler.SetRange(mLoFreq, mHiFreq); EnvLinToLog(); - mEnvelope = mLogEnvelope; + mEnvelope = mLogEnvelope.get(); mLin = false; } mFreqRuler->Refresh(false); @@ -2912,8 +2894,6 @@ EqualizationPanel::EqualizationPanel(EffectEqualization *effect, wxWindow *paren EqualizationPanel::~EqualizationPanel() { - if (mBitmap) - delete mBitmap; if (mOuti) delete [] mOuti; if (mOutr) @@ -2960,12 +2940,9 @@ void EqualizationPanel::OnPaint(wxPaintEvent & WXUNUSED(event)) if (!mBitmap || mWidth!=width || mHeight!=height) { - if (mBitmap) - delete mBitmap; - mWidth = width; mHeight = height; - mBitmap = new wxBitmap(mWidth, mHeight); + mBitmap = std::make_unique(mWidth, mHeight); } wxBrush bkgndBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)); diff --git a/src/effects/Equalization.h b/src/effects/Equalization.h index 7ef0471c9..896e904b8 100644 --- a/src/effects/Equalization.h +++ b/src/effects/Equalization.h @@ -219,13 +219,12 @@ private: EQCurveArray mCurves; - Envelope *mLogEnvelope; - Envelope *mLinEnvelope; + std::unique_ptr mLogEnvelope, mLinEnvelope; Envelope *mEnvelope; #ifdef EXPERIMENTAL_EQ_SSE_THREADED bool mBench; - EffectEqualization48x *mEffectEqualization48x; + std::unique_ptr mEffectEqualization48x; friend class EffectEqualization48x; #endif @@ -312,7 +311,7 @@ private: bool mRecalcRequired; - wxBitmap *mBitmap; + std::unique_ptr mBitmap; wxRect mEnvRect; int mWidth; int mHeight; diff --git a/src/effects/Generator.cpp b/src/effects/Generator.cpp index 29b271d65..d36f131cb 100644 --- a/src/effects/Generator.cpp +++ b/src/effects/Generator.cpp @@ -78,7 +78,7 @@ bool Generator::Process() else { // Transfer the data from the temporary track to the actual one tmp->Flush(); - SetTimeWarper(new StepTimeWarper(mT0+GetDuration(), GetDuration()-(mT1-mT0))); + SetTimeWarper(std::make_unique(mT0+GetDuration(), GetDuration()-(mT1-mT0))); bGoodResult = track->ClearAndPaste(p->GetSel0(), p->GetSel1(), &*tmp, true, false, GetTimeWarper()); } diff --git a/src/effects/NoiseReduction.cpp b/src/effects/NoiseReduction.cpp index 7e266c1d8..c8ab7734d 100644 --- a/src/effects/NoiseReduction.cpp +++ b/src/effects/NoiseReduction.cpp @@ -338,7 +338,7 @@ private: FloatVector mRealFFTs; FloatVector mImagFFTs; }; - std::vector mQueue; + std::vector> mQueue; }; /****************************************************************//** @@ -641,8 +641,6 @@ bool EffectNoiseReduction::Process() EffectNoiseReduction::Worker::~Worker() { EndFFT(hFFT); - for(int ii = 0, nn = mQueue.size(); ii < nn; ++ii) - delete mQueue[ii]; } bool EffectNoiseReduction::Worker::Process @@ -797,7 +795,7 @@ EffectNoiseReduction::Worker::Worker mQueue.resize(mHistoryLen); for (int ii = 0; ii < mHistoryLen; ++ii) - mQueue[ii] = new Record(mSpectrumSize); + mQueue[ii] = make_movable(mSpectrumSize); // Create windows @@ -986,9 +984,7 @@ void EffectNoiseReduction::Worker::FillFirstHistoryWindow() void EffectNoiseReduction::Worker::RotateHistoryWindows() { - Record *save = mQueue[mHistoryLen - 1]; - mQueue.pop_back(); - mQueue.insert(mQueue.begin(), save); + std::rotate(mQueue.begin(), mQueue.end() - 1, mQueue.end()); } void EffectNoiseReduction::Worker::FinishTrackStatistics(Statistics &statistics) diff --git a/src/effects/SBSMSEffect.cpp b/src/effects/SBSMSEffect.cpp index 49fb0dc6f..0cd4e72bf 100644 --- a/src/effects/SBSMSEffect.cpp +++ b/src/effects/SBSMSEffect.cpp @@ -36,11 +36,7 @@ public: buf = NULL; leftBuffer = NULL; rightBuffer = NULL; - quality = NULL; - iface = NULL; - sbsms = NULL; - resampler = NULL; SBSMSBuf = NULL; outputLeftTrack = NULL; outputRightTrack = NULL; @@ -52,10 +48,6 @@ public: if(leftBuffer) free(leftBuffer); if(rightBuffer) free(rightBuffer); if(SBSMSBuf) free(SBSMSBuf); - if(quality) delete quality; - if(sbsms) delete sbsms; - if(iface) delete iface; - if(resampler) delete resampler; } bool bPitch; @@ -70,13 +62,13 @@ public: float *rightBuffer; WaveTrack *leftTrack; WaveTrack *rightTrack; - SBSMS *sbsms; - SBSMSInterface *iface; + std::unique_ptr sbsms; + std::unique_ptr iface; audio *SBSMSBuf; // Not required by callbacks, but makes for easier cleanup - Resampler *resampler; - SBSMSQuality *quality; + std::unique_ptr resampler; + std::unique_ptr quality; std::unique_ptr outputLeftTrack; std::unique_ptr outputRightTrack; }; @@ -141,7 +133,7 @@ long resampleCB(void *cb_data, SBSMSFrame *data) long postResampleCB(void *cb_data, SBSMSFrame *data) { ResampleBuf *r = (ResampleBuf*) cb_data; - long sampleCount = r->sbsms->read(r->iface, r->SBSMSBuf, r->SBSMSBlockSize); + long sampleCount = r->sbsms->read(r->iface.get(), r->SBSMSBuf, r->SBSMSBlockSize); data->buf = r->SBSMSBuf; data->size = sampleCount; data->ratio0 = 1.0 / r->ratio; @@ -164,24 +156,24 @@ void EffectSBSMS :: setParameters(double rateStart, double rateEnd, double pitch this->bPitchReferenceInput = bPitchReferenceInput; } -TimeWarper *createTimeWarper(double t0, double t1, double duration, +std::unique_ptr createTimeWarper(double t0, double t1, double duration, double rateStart, double rateEnd, SlideType rateSlideType) { - TimeWarper *warper = NULL; + std::unique_ptr warper; if (rateStart == rateEnd || rateSlideType == SlideConstant) { - warper = new LinearTimeWarper(t0, t0, t1, t0+duration); + warper = std::make_unique(t0, t0, t1, t0+duration); } else if(rateSlideType == SlideLinearInputRate) { - warper = new LinearInputRateTimeWarper(t0, t1, rateStart, rateEnd); + warper = std::make_unique(t0, t1, rateStart, rateEnd); } else if(rateSlideType == SlideLinearOutputRate) { - warper = new LinearOutputRateTimeWarper(t0, t1, rateStart, rateEnd); + warper = std::make_unique(t0, t1, rateStart, rateEnd); } else if(rateSlideType == SlideLinearInputStretch) { - warper = new LinearInputStretchTimeWarper(t0, t1, rateStart, rateEnd); + warper = std::make_unique(t0, t1, rateStart, rateEnd); } else if(rateSlideType == SlideLinearOutputStretch) { - warper = new LinearOutputStretchTimeWarper(t0, t1, rateStart, rateEnd); + warper = std::make_unique(t0, t1, rateStart, rateEnd); } else if(rateSlideType == SlideGeometricInput) { - warper = new GeometricInputTimeWarper(t0, t1, rateStart, rateEnd); + warper = std::make_unique(t0, t1, rateStart, rateEnd); } else if(rateSlideType == SlideGeometricOutput) { - warper = new GeometricOutputTimeWarper(t0, t1, rateStart, rateEnd); + warper = std::make_unique(t0, t1, rateStart, rateEnd); } return warper; } @@ -190,8 +182,8 @@ TimeWarper *createTimeWarper(double t0, double t1, double duration, // it are shifted along appropriately. bool EffectSBSMS::ProcessLabelTrack(Track *t) { - TimeWarper *warper = createTimeWarper(mT0,mT1,(mT1-mT0)*mTotalStretch,rateStart,rateEnd,rateSlideType); - SetTimeWarper(new RegionTimeWarper(mT0, mT1, warper)); + auto warper = createTimeWarper(mT0,mT1,(mT1-mT0)*mTotalStretch,rateStart,rateEnd,rateSlideType); + SetTimeWarper(std::make_unique(mT0, mT1, std::move(warper))); LabelTrack *lt = (LabelTrack*)t; if (lt == NULL) return false; lt->WarpLabels(*GetTimeWarper()); @@ -313,10 +305,10 @@ bool EffectSBSMS::Process() outResampleCB = resampleCB; rb.offset = start; rb.end = end; - rb.iface = new SBSMSInterfaceSliding(&rateSlide,&pitchSlide, + rb.iface = std::make_unique(&rateSlide,&pitchSlide, bPitchReferenceInput, samplesToProcess,0, - NULL); + nullptr); } else { @@ -324,9 +316,9 @@ bool EffectSBSMS::Process() outSlideType = (srProcess==srTrack?SlideIdentity:SlideConstant); outResampleCB = postResampleCB; rb.ratio = srProcess/srTrack; - rb.quality = new SBSMSQuality(&SBSMSQualityStandard); - rb.resampler = new Resampler(resampleCB, &rb, srProcess==srTrack?SlideIdentity:SlideConstant); - rb.sbsms = new SBSMS(rightTrack?2:1,rb.quality,true); + rb.quality = std::make_unique(&SBSMSQualityStandard); + rb.resampler = std::make_unique(resampleCB, &rb, srProcess==srTrack?SlideIdentity:SlideConstant); + rb.sbsms = std::make_unique(rightTrack ? 2 : 1, rb.quality.get(), true); rb.SBSMSBlockSize = rb.sbsms->getInputFrameSize(); rb.SBSMSBuf = (audio*)calloc(rb.SBSMSBlockSize,sizeof(audio)); @@ -336,11 +328,11 @@ bool EffectSBSMS::Process() (long)((float)(processPresamples)*(srTrack/srProcess))); rb.offset = start - trackPresamples; rb.end = trackEnd; - rb.iface = new SBSMSEffectInterface(rb.resampler, + rb.iface = std::make_unique(rb.resampler.get(), &rateSlide,&pitchSlide, bPitchReferenceInput, samplesToProcess,processPresamples, - rb.quality); + rb.quality.get()); } Resampler resampler(outResampleCB,&rb,outSlideType); @@ -361,8 +353,8 @@ bool EffectSBSMS::Process() if(duration > maxDuration) maxDuration = duration; - TimeWarper *warper = createTimeWarper(mCurT0,mCurT1,maxDuration,rateStart,rateEnd,rateSlideType); - SetTimeWarper(warper); + auto warper = createTimeWarper(mCurT0,mCurT1,maxDuration,rateStart,rateEnd,rateSlideType); + SetTimeWarper(std::move(warper)); rb.outputLeftTrack = mFactory->NewWaveTrack(leftTrack->GetSampleFormat(), leftTrack->GetRate()); diff --git a/src/effects/ScienFilter.cpp b/src/effects/ScienFilter.cpp index 3acaff38d..85db0fb1b 100644 --- a/src/effects/ScienFilter.cpp +++ b/src/effects/ScienFilter.cpp @@ -1030,10 +1030,6 @@ EffectScienFilterPanel::EffectScienFilterPanel(EffectScienFilter *effect, wxWind EffectScienFilterPanel::~EffectScienFilterPanel() { - if (mBitmap) - { - delete mBitmap; - } } void EffectScienFilterPanel::SetFreqRange(double lo, double hi) @@ -1073,14 +1069,9 @@ void EffectScienFilterPanel::OnPaint(wxPaintEvent & WXUNUSED(evt)) if (!mBitmap || mWidth != width || mHeight != height) { - if (mBitmap) - { - delete mBitmap; - } - mWidth = width; mHeight = height; - mBitmap = new wxBitmap(mWidth, mHeight); + mBitmap = std::make_unique(mWidth, mHeight); } wxBrush bkgndBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)); diff --git a/src/effects/ScienFilter.h b/src/effects/ScienFilter.h index 75b02d879..44c5fc28a 100644 --- a/src/effects/ScienFilter.h +++ b/src/effects/ScienFilter.h @@ -163,7 +163,7 @@ private: double mDbMin; double mDbMax; - wxBitmap *mBitmap; + std::unique_ptr mBitmap; wxRect mEnvRect; int mWidth; int mHeight; diff --git a/src/effects/ScoreAlignDialog.cpp b/src/effects/ScoreAlignDialog.cpp index f49957172..e5d443c59 100644 --- a/src/effects/ScoreAlignDialog.cpp +++ b/src/effects/ScoreAlignDialog.cpp @@ -53,16 +53,16 @@ It \TODO: description #include "scorealign-glue.h" #include "ScoreAlignDialog.h" -static ScoreAlignDialog *gScoreAlignDialog = NULL; +static std::unique_ptr gScoreAlignDialog{}; //IMPLEMENT_CLASS(ScoreAlignDialog, wxDialogWrapper) -ScoreAlignDialog::ScoreAlignDialog(wxWindow *parent, ScoreAlignParams ¶ms) - : wxDialogWrapper(parent, -1, _("Align MIDI to Audio"), +ScoreAlignDialog::ScoreAlignDialog(ScoreAlignParams ¶ms) + : wxDialogWrapper(NULL, -1, _("Align MIDI to Audio"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE) { - gScoreAlignDialog = this; // Allows anyone to close dialog by calling + gScoreAlignDialog.reset(this); // Allows anyone to close dialog by calling // CloseScoreAlignDialog() gPrefs->Read(wxT("/Tracks/Synchronize/FramePeriod"), &p.mFramePeriod, float(SA_DFT_FRAME_PERIOD)); @@ -277,10 +277,7 @@ bool ScoreAlignDialog::TransferDataFromWindow() void CloseScoreAlignDialog() { - if (gScoreAlignDialog) { - delete gScoreAlignDialog; - gScoreAlignDialog = NULL; - } + gScoreAlignDialog.reset(); } diff --git a/src/effects/ScoreAlignDialog.h b/src/effects/ScoreAlignDialog.h index d297e0aec..dd579181c 100644 --- a/src/effects/ScoreAlignDialog.h +++ b/src/effects/ScoreAlignDialog.h @@ -61,7 +61,7 @@ public: wxButton *mDefaultButton; // constructors and destructors - ScoreAlignDialog(wxWindow * parent, ScoreAlignParams ¶ms); + ScoreAlignDialog(ScoreAlignParams ¶ms); ~ScoreAlignDialog(); bool TransferDataFromWindow(); diff --git a/src/effects/SoundTouchEffect.cpp b/src/effects/SoundTouchEffect.cpp index d064fddb1..505cc9ac1 100644 --- a/src/effects/SoundTouchEffect.cpp +++ b/src/effects/SoundTouchEffect.cpp @@ -28,7 +28,7 @@ effect that uses SoundTouch to do its processing (ChangeTempo bool EffectSoundTouch::ProcessLabelTrack(Track *track) { // SetTimeWarper(new RegionTimeWarper(mCurT0, mCurT1, - // new LinearTimeWarper(mCurT0, mCurT0, + // std::make_unique(mCurT0, mCurT0, // mCurT1, mCurT0 + (mCurT1-mCurT0)*mFactor))); LabelTrack *lt = (LabelTrack*)track; if (lt == NULL) return false; @@ -162,8 +162,7 @@ bool EffectSoundTouch::Process() if (bGoodResult) ReplaceProcessedTracks(bGoodResult); - delete mSoundTouch; - mSoundTouch = NULL; + mSoundTouch.reset(); // mT0 = mCurT0; // mT1 = mCurT0 + m_maxNewLength; // Update selection. diff --git a/src/effects/SoundTouchEffect.h b/src/effects/SoundTouchEffect.h index 1671196ec..cda75d01f 100644 --- a/src/effects/SoundTouchEffect.h +++ b/src/effects/SoundTouchEffect.h @@ -50,7 +50,7 @@ public: #endif protected: - SoundTouch *mSoundTouch; + std::unique_ptr mSoundTouch; double mCurT0; double mCurT1; diff --git a/src/effects/TimeWarper.cpp b/src/effects/TimeWarper.cpp index 5200161a0..da16a4c5c 100644 --- a/src/effects/TimeWarper.cpp +++ b/src/effects/TimeWarper.cpp @@ -15,8 +15,10 @@ Geometric TimeWarper classes *//*******************************************************************/ -#include +#include "../Audacity.h" #include "TimeWarper.h" + +#include #include double IdentityTimeWarper::Warp(double originalTime) const diff --git a/src/effects/TimeWarper.h b/src/effects/TimeWarper.h index b65561513..274b8eabb 100644 --- a/src/effects/TimeWarper.h +++ b/src/effects/TimeWarper.h @@ -56,6 +56,8 @@ of the warped region. #ifndef __TIMEWARPER__ #define __TIMEWARPER__ +#include "../MemoryX.h" + class TimeWarper /* not final */ { public: @@ -72,13 +74,12 @@ public: class ShiftTimeWarper final : public TimeWarper { private: - TimeWarper *mWarper; + std::unique_ptr mWarper; double mShift; public: - ShiftTimeWarper(TimeWarper *warper, double shiftAmount) - : mWarper(warper), mShift(shiftAmount) { } - virtual ~ShiftTimeWarper() - { delete mWarper; } + ShiftTimeWarper(std::unique_ptr &&warper, double shiftAmount) + : mWarper(std::move(warper)), mShift(shiftAmount) { } + virtual ~ShiftTimeWarper() {} double Warp(double originalTime) const override; }; @@ -191,17 +192,16 @@ public: class RegionTimeWarper final : public TimeWarper { private: - TimeWarper *mWarper; + std::unique_ptr mWarper; double mTStart; double mTEnd; double mOffset; public: - RegionTimeWarper(double tStart, double tEnd, TimeWarper *warper) - : mWarper(warper), mTStart(tStart), mTEnd(tEnd), + RegionTimeWarper(double tStart, double tEnd, std::unique_ptr &&warper) + : mWarper(std::move(warper)), mTStart(tStart), mTEnd(tEnd), mOffset(mWarper->Warp(mTEnd)-mTEnd) { } - virtual ~RegionTimeWarper() - { delete mWarper; } + virtual ~RegionTimeWarper() {} double Warp(double originalTime) const override { if (originalTime < mTStart)