From cb05476c459f78062feed68160bc743741bcf232 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Thu, 14 Apr 2016 12:33:59 -0400 Subject: [PATCH] Remove naked new[] in: effects plug-ins --- src/effects/VST/VSTEffect.cpp | 190 +++------- src/effects/VST/VSTEffect.h | 18 +- src/effects/audiounits/AudioUnitEffect.cpp | 137 ++----- src/effects/audiounits/AudioUnitEffect.h | 11 +- src/effects/ladspa/LadspaEffect.cpp | 95 +---- src/effects/ladspa/LadspaEffect.h | 21 +- src/effects/lv2/LV2Effect.cpp | 399 +++++++++------------ src/effects/lv2/LV2Effect.h | 17 +- src/effects/vamp/VampEffect.cpp | 69 +--- src/effects/vamp/VampEffect.h | 13 +- 10 files changed, 341 insertions(+), 629 deletions(-) diff --git a/src/effects/VST/VSTEffect.cpp b/src/effects/VST/VSTEffect.cpp index 597940ced..3c871c643 100644 --- a/src/effects/VST/VSTEffect.cpp +++ b/src/effects/VST/VSTEffect.cpp @@ -1108,10 +1108,6 @@ VSTEffect::VSTEffect(const wxString & path, VSTEffect *master) // UI mGui = false; - mNames = NULL; - mSliders = NULL; - mDisplays = NULL; - mLabels = NULL; mContainer = NULL; // If we're a slave then go ahead a load immediately @@ -1128,26 +1124,6 @@ VSTEffect::~VSTEffect() mDialog->Close(); } - if (mNames) - { - delete [] mNames; - } - - if (mSliders) - { - delete [] mSliders; - } - - if (mDisplays) - { - delete [] mDisplays; - } - - if (mLabels) - { - delete [] mLabels; - } - Unload(); } @@ -1289,7 +1265,9 @@ bool VSTEffect::SetHost(EffectHostInterface *host) if (mHost) { - mHost->GetSharedConfig(wxT("Options"), wxT("BufferSize"), mUserBlockSize, 8192); + int userBlockSize; + mHost->GetSharedConfig(wxT("Options"), wxT("BufferSize"), userBlockSize, 8192); + mUserBlockSize = std::max( 1, userBlockSize ); mHost->GetSharedConfig(wxT("Options"), wxT("UseLatency"), mUseLatency, true); mBlockSize = mUserBlockSize; @@ -1330,7 +1308,7 @@ int VSTEffect::GetMidiOutCount() size_t VSTEffect::SetBlockSize(size_t maxBlockSize) { - mBlockSize = std::min((int)maxBlockSize, mUserBlockSize); + mBlockSize = std::min( maxBlockSize, mUserBlockSize ); return mBlockSize; } @@ -1424,26 +1402,16 @@ void VSTEffect::SetChannelCount(unsigned numChannels) bool VSTEffect::RealtimeInitialize() { - mMasterIn = new float *[mAudioIns]; - for (int i = 0; i < mAudioIns; i++) - { - mMasterIn[i] = new float[mBlockSize]; - memset(mMasterIn[i], 0, mBlockSize * sizeof(float)); - } - - mMasterOut = new float *[mAudioOuts]; - for (int i = 0; i < mAudioOuts; i++) - { - mMasterOut[i] = new float[mBlockSize]; - } + mMasterIn.reinit( mAudioIns, mBlockSize, true ); + mMasterOut.reinit( mAudioOuts, mBlockSize ); return ProcessInitialize(0, NULL); } bool VSTEffect::RealtimeAddProcessor(unsigned numChannels, float sampleRate) { - VSTEffect *slave = new VSTEffect(mPath, this); - mSlaves.Add(slave); + mSlaves.push_back(make_movable(mPath, this)); + VSTEffect *const slave = mSlaves.back().get(); slave->SetBlockSize(mBlockSize); slave->SetChannelCount(numChannels); @@ -1478,24 +1446,13 @@ bool VSTEffect::RealtimeAddProcessor(unsigned numChannels, float sampleRate) bool VSTEffect::RealtimeFinalize() { - for (size_t i = 0, cnt = mSlaves.GetCount(); i < cnt; i++) - { - mSlaves[i]->ProcessFinalize(); - delete mSlaves[i]; - } - mSlaves.Clear(); + for (const auto &slave : mSlaves) + slave->ProcessFinalize(); + mSlaves.clear(); - for (int i = 0; i < mAudioIns; i++) - { - delete [] mMasterIn[i]; - } - delete [] mMasterIn; + mMasterIn.reset(); - for (int i = 0; i < mAudioOuts; i++) - { - delete [] mMasterOut[i]; - } - delete [] mMasterOut; + mMasterOut.reset(); return ProcessFinalize(); } @@ -1504,10 +1461,8 @@ bool VSTEffect::RealtimeSuspend() { PowerOff(); - for (size_t i = 0, cnt = mSlaves.GetCount(); i < cnt; i++) - { - mSlaves[i]->PowerOff(); - } + for (const auto &slave : mSlaves) + slave->PowerOff(); return true; } @@ -1516,10 +1471,8 @@ bool VSTEffect::RealtimeResume() { PowerOn(); - for (size_t i = 0, cnt = mSlaves.GetCount(); i < cnt; i++) - { - mSlaves[i]->PowerOn(); - } + for (const auto &slave : mSlaves) + slave->PowerOn(); return true; } @@ -1527,9 +1480,7 @@ bool VSTEffect::RealtimeResume() bool VSTEffect::RealtimeProcessStart() { for (int i = 0; i < mAudioIns; i++) - { - memset(mMasterIn[i], 0, mBlockSize * sizeof(float)); - } + memset(mMasterIn[i].get(), 0, mBlockSize * sizeof(float)); mNumSamples = 0; @@ -1554,7 +1505,11 @@ size_t VSTEffect::RealtimeProcess(int group, float **inbuf, float **outbuf, size bool VSTEffect::RealtimeProcessEnd() { - ProcessBlock(mMasterIn, mMasterOut, mNumSamples); + // These casts to float** should be safe... + ProcessBlock( + reinterpret_cast (mMasterIn.get()), + reinterpret_cast (mMasterOut.get()), + mNumSamples); return true; } @@ -1646,8 +1601,6 @@ bool VSTEffect::GetAutomationParameters(EffectAutomationParameters & parms) bool VSTEffect::SetAutomationParameters(EffectAutomationParameters & parms) { - size_t slaveCnt = mSlaves.GetCount(); - callDispatcher(effBeginSetProgram, 0, 0, NULL, 0.0); for (int i = 0; i < mAEffect->numParams; i++) { @@ -1666,10 +1619,8 @@ bool VSTEffect::SetAutomationParameters(EffectAutomationParameters & parms) if (d >= -1.0 && d <= 1.0) { callSetParameter(i, d); - for (size_t i = 0; i < slaveCnt; i++) - { - mSlaves[i]->callSetParameter(i, d); - } + for (const auto &slave : mSlaves) + slave->callSetParameter(i, d); } } callDispatcher(effEndSetProgram, 0, 0, NULL, 0.0); @@ -1817,29 +1768,10 @@ bool VSTEffect::CloseUI() RemoveHandler(); - if (mNames) - { - delete [] mNames; - mNames = NULL; - } - - if (mSliders) - { - delete [] mSliders; - mSliders = NULL; - } - - if (mDisplays) - { - delete [] mDisplays; - mDisplays = NULL; - } - - if (mLabels) - { - delete [] mLabels; - mLabels = NULL; - } + mNames.reset(); + mSliders.reset(); + mDisplays.reset(); + mLabels.reset(); mUIHost = NULL; mParent = NULL; @@ -1978,7 +1910,9 @@ void VSTEffect::ShowOptions() if (dlg.ShowModal()) { // Reinitialize configuration settings - mHost->GetSharedConfig(wxT("Options"), wxT("BufferSize"), mUserBlockSize, 8192); + int userBlockSize; + mHost->GetSharedConfig(wxT("Options"), wxT("BufferSize"), userBlockSize, 8192); + mUserBlockSize = std::max( 1, userBlockSize ); mHost->GetSharedConfig(wxT("Options"), wxT("UseLatency"), mUseLatency, true); } } @@ -2328,14 +2262,13 @@ bool VSTEffect::LoadParameters(const wxString & group) if (mHost->GetPrivateConfig(group, wxT("Chunk"), value, wxEmptyString)) { - char *buf = new char[value.length() / 4 * 3]; + ArrayOf buf{ value.length() / 4 * 3 }; - int len = VSTEffect::b64decode(value, buf); + int len = VSTEffect::b64decode(value, buf.get()); if (len) { - callSetChunk(true, len, buf, &info); + callSetChunk(true, len, buf.get(), &info); } - delete [] buf; return true; } @@ -2513,10 +2446,8 @@ void VSTEffect::Automate(int index, float value) return; } - for (size_t i = 0, cnt = mSlaves.GetCount(); i < cnt; i++) - { - mSlaves[i]->callSetParameter(index, value); - } + for (const auto &slave : mSlaves) + slave->callSetParameter(index, value); return; } @@ -2587,10 +2518,8 @@ void VSTEffect::callSetParameter(int index, float value) { mAEffect->setParameter(mAEffect, index, value); - for (size_t i = 0, cnt = mSlaves.GetCount(); i < cnt; i++) - { - mSlaves[i]->callSetParameter(index, value); - } + for (const auto &slave : mSlaves) + slave->callSetParameter(index, value); } } @@ -2599,10 +2528,8 @@ void VSTEffect::callSetProgram(int index) callDispatcher(effBeginSetProgram, 0, 0, NULL, 0.0); callDispatcher(effSetProgram, 0, index, NULL, 0.0); - for (size_t i = 0, cnt = mSlaves.GetCount(); i < cnt; i++) - { - mSlaves[i]->callSetProgram(index); - } + for (const auto &slave : mSlaves) + slave->callSetProgram(index); callDispatcher(effEndSetProgram, 0, 0, NULL, 0.0); } @@ -2643,10 +2570,8 @@ void VSTEffect::callSetChunk(bool isPgm, int len, void *buf, VstPatchChunkInfo * callDispatcher(effSetChunk, isPgm ? 1 : 0, len, buf, 0.0); callDispatcher(effEndSetProgram, 0, 0, NULL, 0.0); - for (size_t i = 0, cnt = mSlaves.GetCount(); i < cnt; i++) - { - mSlaves[i]->callSetChunk(isPgm, len, buf, info); - } + for (const auto &slave : mSlaves) + slave->callSetChunk(isPgm, len, buf, info); } //////////////////////////////////////////////////////////////////////////////// @@ -2847,10 +2772,10 @@ void VSTEffect::BuildPlain() mParent->SetSizer(mainSizer.release()); } - mNames = new wxStaticText *[mAEffect->numParams]; - mSliders = new wxSlider *[mAEffect->numParams]; - mDisplays = new wxStaticText *[mAEffect->numParams]; - mLabels = new wxStaticText *[mAEffect->numParams]; + mNames.reinit(static_cast(mAEffect->numParams)); + mSliders.reinit(static_cast(mAEffect->numParams)); + mDisplays.reinit(static_cast(mAEffect->numParams)); + mLabels.reinit(static_cast(mAEffect->numParams)); { auto paramSizer = std::make_unique(wxVERTICAL, scroller, _("Effect Settings")); @@ -3062,7 +2987,7 @@ bool VSTEffect::LoadFXB(const wxFileName & fn) } // Allocate memory for the contents - unsigned char *data = new unsigned char[f.Length()]; + ArrayOf data{ size_t(f.Length()) }; if (!data) { wxMessageBox(_("Unable to allocate memory when loading presets file."), @@ -3071,7 +2996,7 @@ bool VSTEffect::LoadFXB(const wxFileName & fn) mParent); return false; } - unsigned char *bptr = data; + unsigned char *bptr = data.get(); do { @@ -3218,9 +3143,6 @@ bool VSTEffect::LoadFXB(const wxFileName & fn) } } while (false); - // Get rid of the data - delete [] data; - return ret; } @@ -3236,7 +3158,7 @@ bool VSTEffect::LoadFXP(const wxFileName & fn) } // Allocate memory for the contents - unsigned char *data = new unsigned char[f.Length()]; + ArrayOf data{ size_t(f.Length()) }; if (!data) { wxMessageBox(_("Unable to allocate memory when loading presets file."), @@ -3245,7 +3167,7 @@ bool VSTEffect::LoadFXP(const wxFileName & fn) mParent); return false; } - unsigned char *bptr = data; + unsigned char *bptr = data.get(); do { @@ -3271,9 +3193,6 @@ bool VSTEffect::LoadFXP(const wxFileName & fn) ret = LoadFXProgram(&bptr, len, i, false); } while (false); - // Get rid of the data - delete [] data; - return ret; } @@ -3947,15 +3866,14 @@ void VSTEffect::HandleXMLEndTag(const wxChar *tag) { if (mChunk.length()) { - char *buf = new char[mChunk.length() / 4 * 3]; + ArrayOf buf{ mChunk.length() / 4 * 3 }; - int len = VSTEffect::b64decode(mChunk, buf); + int len = VSTEffect::b64decode(mChunk, buf.get()); if (len) { - callSetChunk(true, len, buf, &mXMLInfo); + callSetChunk(true, len, buf.get(), &mXMLInfo); } - delete [] buf; mChunk.clear(); } mInChunk = false; diff --git a/src/effects/VST/VSTEffect.h b/src/effects/VST/VSTEffect.h index 0a8d0d171..18e34b8ad 100644 --- a/src/effects/VST/VSTEffect.h +++ b/src/effects/VST/VSTEffect.h @@ -16,6 +16,7 @@ #include "audacity/ModuleInterface.h" #include "audacity/PluginInterface.h" +#include "../../SampleFormat.h" #include "../../widgets/NumericTextCtrl.h" #include "VSTControl.h" @@ -61,7 +62,7 @@ struct __CFBundle; // /////////////////////////////////////////////////////////////////////////////// -WX_DEFINE_ARRAY_PTR(VSTEffect *, VSTEffectArray); +using VSTEffectArray = std::vector < movable_ptr > ; DECLARE_LOCAL_EVENT_TYPE(EVT_SIZEWINDOW, -1); DECLARE_LOCAL_EVENT_TYPE(EVT_UPDATEDISPLAY, -1); @@ -268,7 +269,7 @@ private: int mMidiOuts; bool mAutomatable; float mSampleRate; - int mUserBlockSize; + size_t mUserBlockSize; wxString mName; wxString mVendor; wxString mDescription; @@ -313,7 +314,7 @@ private: bool mUseLatency; int mBufferDelay; - int mBlockSize; + unsigned mBlockSize; int mProcessLevel; bool mHasPower; @@ -329,8 +330,7 @@ private: VSTEffect *mMaster; // non-NULL if a slave VSTEffectArray mSlaves; unsigned mNumChannels; - float **mMasterIn; - float **mMasterOut; + FloatBuffers mMasterIn, mMasterOut; size_t mNumSamples; // UI @@ -343,10 +343,10 @@ private: VSTControl *mControl; NumericTextCtrl *mDuration; - wxStaticText **mNames; - wxSlider **mSliders; - wxStaticText **mDisplays; - wxStaticText **mLabels; + ArrayOf mNames; + ArrayOf mSliders; + ArrayOf mDisplays; + ArrayOf mLabels; bool mInSet; bool mInChunk; diff --git a/src/effects/audiounits/AudioUnitEffect.cpp b/src/effects/audiounits/AudioUnitEffect.cpp index 152ee8e89..35a425878 100644 --- a/src/effects/audiounits/AudioUnitEffect.cpp +++ b/src/effects/audiounits/AudioUnitEffect.cpp @@ -831,9 +831,6 @@ AudioUnitEffect::AudioUnitEffect(const wxString & path, mDialog = NULL; mParent = NULL; - mInputList = NULL; - mOutputList = NULL; - mUnitInitialized = false; mEventListenerRef = NULL; @@ -965,17 +962,16 @@ bool AudioUnitEffect::SupportsAutomation() } UInt32 cnt = dataSize / sizeof(AudioUnitParameterID); - AudioUnitParameterID *array = new AudioUnitParameterID[cnt]; + ArrayOf < AudioUnitParameterID > array{cnt}; result = AudioUnitGetProperty(mUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global, 0, - array, + array.get(), &dataSize); if (result != noErr) { - delete [] array; return false; } @@ -991,20 +987,16 @@ bool AudioUnitEffect::SupportsAutomation() &dataSize); if (result != noErr) { - delete [] array; return false; } if (info.flags & kAudioUnitParameterFlag_IsWritable) { // All we need is one - delete [] array; return true; } } - delete [] array; - return false; } @@ -1096,17 +1088,16 @@ bool AudioUnitEffect::SetHost(EffectHostInterface *host) // And get them UInt32 cnt = dataSize / sizeof(AudioUnitParameterID); - AudioUnitParameterID *array = new AudioUnitParameterID[cnt]; + ArrayOf array {cnt}; result = AudioUnitGetProperty(mUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global, 0, - array, + array.get(), &dataSize); if (result != noErr) { - delete [] array; return false; } @@ -1119,13 +1110,10 @@ bool AudioUnitEffect::SetHost(EffectHostInterface *host) &event); if (result != noErr) { - delete [] array; return false; } } - delete [] array; - event.mEventType = kAudioUnitEvent_PropertyChange; event.mArgument.mProperty.mAudioUnit = mUnit; event.mArgument.mProperty.mPropertyID = kAudioUnitProperty_Latency; @@ -1246,11 +1234,11 @@ bool AudioUnitEffect::ProcessInitialize(sampleCount WXUNUSED(totalLen), ChannelN { OSStatus result; - mInputList = new AudioBufferList[mAudioIns]; - mInputList->mNumberBuffers = mAudioIns; + mInputList.reinit( mAudioIns ); + mInputList[0].mNumberBuffers = mAudioIns; - mOutputList = new AudioBufferList[mAudioOuts]; - mOutputList->mNumberBuffers = mAudioOuts; + mOutputList.reinit( mAudioOuts ); + mOutputList[0].mNumberBuffers = mAudioOuts; memset(&mTimeStamp, 0, sizeof(AudioTimeStamp)); mTimeStamp.mSampleTime = 0; // This is a double-precision number that should @@ -1294,35 +1282,26 @@ bool AudioUnitEffect::ProcessFinalize() { mReady = false; - if (mOutputList) - { - delete [] mOutputList; - mOutputList = NULL; - } - - if (mInputList) - { - delete [] mInputList; - mInputList = NULL; - } + mOutputList.reset(); + mInputList.reset(); return true; } size_t AudioUnitEffect::ProcessBlock(float **inBlock, float **outBlock, size_t blockLen) { - for (int i = 0; i < mAudioIns; i++) + for (size_t i = 0; i < mAudioIns; i++) { - mInputList->mBuffers[i].mNumberChannels = 1; - mInputList->mBuffers[i].mData = inBlock[i]; - mInputList->mBuffers[i].mDataByteSize = sizeof(float) * blockLen; + mInputList[0].mBuffers[i].mNumberChannels = 1; + mInputList[0].mBuffers[i].mData = inBlock[i]; + mInputList[0].mBuffers[i].mDataByteSize = sizeof(float) * blockLen; } - for (int i = 0; i < mAudioOuts; i++) + for (size_t i = 0; i < mAudioOuts; i++) { - mOutputList->mBuffers[i].mNumberChannels = 1; - mOutputList->mBuffers[i].mData = outBlock[i]; - mOutputList->mBuffers[i].mDataByteSize = sizeof(float) * blockLen; + mOutputList[0].mBuffers[i].mNumberChannels = 1; + mOutputList[0].mBuffers[i].mData = outBlock[i]; + mOutputList[0].mBuffers[i].mDataByteSize = sizeof(float) * blockLen; } AudioUnitRenderActionFlags flags = 0; @@ -1333,7 +1312,7 @@ size_t AudioUnitEffect::ProcessBlock(float **inBlock, float **outBlock, size_t b &mTimeStamp, 0, blockLen, - mOutputList); + mOutputList.get()); if (result != noErr) { printf("Render failed: %d %4.4s\n", (int)result, (char *)&result); @@ -1347,20 +1326,8 @@ size_t AudioUnitEffect::ProcessBlock(float **inBlock, float **outBlock, size_t b bool AudioUnitEffect::RealtimeInitialize() { - mMasterIn = new float *[mAudioIns]; - - for (int i = 0; i < mAudioIns; i++) - { - mMasterIn[i] = new float[mBlockSize]; - memset(mMasterIn[i], 0, mBlockSize * sizeof(float)); - } - - mMasterOut = new float *[mAudioOuts]; - for (int i = 0; i < mAudioOuts; i++) - { - mMasterOut[i] = new float[mBlockSize]; - } - + mMasterIn.reinit(mAudioIns, mBlockSize, true); + mMasterOut.reinit( mAudioOuts, mBlockSize ); return ProcessInitialize(0); } @@ -1389,17 +1356,8 @@ bool AudioUnitEffect::RealtimeFinalize() mSlaves[i]->ProcessFinalize(); mSlaves.clear(); - for (int i = 0; i < mAudioIns; i++) - { - delete [] mMasterIn[i]; - } - delete [] mMasterIn; - - for (int i = 0; i < mAudioOuts; i++) - { - delete [] mMasterOut[i]; - } - delete [] mMasterOut; + mMasterIn.reset(); + mMasterOut.reset(); return ProcessFinalize(); } @@ -1424,10 +1382,8 @@ bool AudioUnitEffect::RealtimeResume() bool AudioUnitEffect::RealtimeProcessStart() { - for (int i = 0; i < mAudioIns; i++) - { - memset(mMasterIn[i], 0, mBlockSize * sizeof(float)); - } + for (size_t i = 0; i < mAudioIns; i++) + memset(mMasterIn[i].get(), 0, mBlockSize * sizeof(float)); mNumSamples = 0; @@ -1441,7 +1397,7 @@ size_t AudioUnitEffect::RealtimeProcess(int group, { wxASSERT(numSamples <= mBlockSize); - for (int c = 0; c < mAudioIns; c++) + for (size_t c = 0; c < mAudioIns; c++) { for (decltype(numSamples) s = 0; s < numSamples; s++) { @@ -1455,7 +1411,10 @@ size_t AudioUnitEffect::RealtimeProcess(int group, bool AudioUnitEffect::RealtimeProcessEnd() { - ProcessBlock(mMasterIn, mMasterOut, mNumSamples); + ProcessBlock( + reinterpret_cast(mMasterIn.get()), + reinterpret_cast(mMasterOut.get()), + mNumSamples); return true; } @@ -1505,17 +1464,16 @@ bool AudioUnitEffect::GetAutomationParameters(EffectAutomationParameters & parms } UInt32 cnt = dataSize / sizeof(AudioUnitParameterID); - AudioUnitParameterID *array = new AudioUnitParameterID[cnt]; + ArrayOf array {cnt}; result = AudioUnitGetProperty(mUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global, 0, - array, + array.get(), &dataSize); if (result != noErr) { - delete [] array; return false; } @@ -1531,7 +1489,6 @@ bool AudioUnitEffect::GetAutomationParameters(EffectAutomationParameters & parms &dataSize); if (result != noErr) { - delete [] array; return false; } @@ -1554,14 +1511,11 @@ bool AudioUnitEffect::GetAutomationParameters(EffectAutomationParameters & parms &value); if (result != noErr) { - delete [] array; return false; } parms.Write(name, value); } - delete [] array; - return true; } @@ -1583,17 +1537,16 @@ bool AudioUnitEffect::SetAutomationParameters(EffectAutomationParameters & parms } UInt32 cnt = dataSize / sizeof(AudioUnitParameterID); - AudioUnitParameterID *array = new AudioUnitParameterID[cnt]; + ArrayOf array {cnt}; result = AudioUnitGetProperty(mUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global, 0, - array, + array.get(), &dataSize); if (result != noErr) { - delete [] array; return false; } @@ -1609,7 +1562,6 @@ bool AudioUnitEffect::SetAutomationParameters(EffectAutomationParameters & parms &dataSize); if (result != noErr) { - delete [] array; return false; } @@ -1628,7 +1580,6 @@ bool AudioUnitEffect::SetAutomationParameters(EffectAutomationParameters & parms double d = 0.0; if (!parms.Read(name, &d)) { - delete [] array; return false; } @@ -1641,13 +1592,10 @@ bool AudioUnitEffect::SetAutomationParameters(EffectAutomationParameters & parms 0); if (result != noErr) { - delete [] array; return false; } } - delete [] array; - AudioUnitParameter aup; aup.mAudioUnit = mUnit; aup.mParameterID = kAUParameterListener_AnyParameter; @@ -2064,8 +2012,6 @@ bool AudioUnitEffect::SetRateAndChannels() bool AudioUnitEffect::CopyParameters(AudioUnit srcUnit, AudioUnit dstUnit) { OSStatus result; - int numParameters, i; - AudioUnitParameterID *parameters; Float32 parameterValue; UInt32 size; @@ -2087,25 +2033,24 @@ bool AudioUnitEffect::CopyParameters(AudioUnit srcUnit, AudioUnit dstUnit) // Now get the list of all parameter IDs - numParameters = size / sizeof(AudioUnitParameterID); - parameters = new AudioUnitParameterID[numParameters]; + auto numParameters = size / sizeof(AudioUnitParameterID); + ArrayOf parameters{ numParameters }; result = AudioUnitGetProperty(srcUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global, 0, - parameters, + parameters.get(), &size); if (result != 0) { printf("Couldn't get parameter list\n"); - delete[] parameters; return false; } // Copy the parameters from the main unit to the unit specific to // this track - for (i = 0; i < numParameters; i++) + for (unsigned i = 0; i < numParameters; i++) { result = AudioUnitGetParameter(srcUnit, parameters[i], @@ -2130,8 +2075,6 @@ bool AudioUnitEffect::CopyParameters(AudioUnit srcUnit, AudioUnit dstUnit) } } - delete[] parameters; - return true; } @@ -2152,9 +2095,7 @@ OSStatus AudioUnitEffect::Render(AudioUnitRenderActionFlags *inActionFlags, AudioBufferList *ioData) { for (int i = 0; i < ioData->mNumberBuffers; i++) - { - ioData->mBuffers[i].mData = mInputList->mBuffers[i].mData; - } + ioData->mBuffers[i].mData = mInputList[0].mBuffers[i].mData; return 0; } diff --git a/src/effects/audiounits/AudioUnitEffect.h b/src/effects/audiounits/AudioUnitEffect.h index 516624a8e..b1a67f780 100644 --- a/src/effects/audiounits/AudioUnitEffect.h +++ b/src/effects/audiounits/AudioUnitEffect.h @@ -182,7 +182,7 @@ private: EffectHostInterface *mHost; unsigned mAudioIns; - int mAudioOuts; + unsigned mAudioOuts; bool mInteractive; bool mLatencyDone; UInt32 mBlockSize; @@ -194,8 +194,8 @@ private: AudioTimeStamp mTimeStamp; bool mReady; - AudioBufferList *mInputList; - AudioBufferList *mOutputList; + ArrayOf mInputList; + ArrayOf mOutputList; EffectUIHostInterface *mUIHost; wxWindow *mParent; @@ -206,10 +206,9 @@ private: AudioUnitEffect *mMaster; // non-NULL if a slave AudioUnitEffectArray mSlaves; unsigned mNumChannels; - float **mMasterIn; - float **mMasterOut; + ArraysOf mMasterIn, mMasterOut; size_t mNumSamples; - + AUEventListenerRef mEventListenerRef; friend class AudioUnitEffectExportDialog; diff --git a/src/effects/ladspa/LadspaEffect.cpp b/src/effects/ladspa/LadspaEffect.cpp index 77ac643d8..fe77cc4d0 100644 --- a/src/effects/ladspa/LadspaEffect.cpp +++ b/src/effects/ladspa/LadspaEffect.cpp @@ -556,62 +556,14 @@ LadspaEffect::LadspaEffect(const wxString & path, int index) mSampleRate = 44100; mBlockSize = 0; - mInputPorts = NULL; - mOutputPorts = NULL; - mInputControls = NULL; - mOutputControls = NULL; - mLatencyPort = -1; mDialog = NULL; mParent = NULL; - mSliders = NULL; - mFields = NULL; - mLabels = NULL; - mToggles = NULL; } LadspaEffect::~LadspaEffect() { - if (mInputPorts) - { - delete [] mInputPorts; - } - - if (mOutputPorts) - { - delete [] mOutputPorts; - } - - if (mInputControls) - { - delete [] mInputControls; - } - - if (mOutputControls) - { - delete [] mOutputControls; - } - - if (mToggles) - { - delete [] mToggles; - } - - if (mSliders) - { - delete [] mSliders; - } - - if (mFields) - { - delete [] mFields; - } - - if (mLabels) - { - delete [] mLabels; - } } // ============================================================================ @@ -715,10 +667,10 @@ bool LadspaEffect::SetHost(EffectHostInterface *host) return false; } - mInputPorts = new unsigned long [mData->PortCount]; - mOutputPorts = new unsigned long [mData->PortCount]; - mInputControls = new float [mData->PortCount]; - mOutputControls = new float [mData->PortCount]; + mInputPorts.reinit( mData->PortCount ); + mOutputPorts.reinit( mData->PortCount ); + mInputControls.reinit( mData->PortCount ); + mOutputControls.reinit( mData->PortCount ); for (unsigned long p = 0; p < mData->PortCount; p++) { @@ -1165,13 +1117,11 @@ bool LadspaEffect::PopulateUI(wxWindow *parent) mParent->PushEventHandler(this); - mToggles = new wxCheckBox *[mData->PortCount]; - mSliders = new wxSlider *[mData->PortCount]; - mFields = new wxTextCtrl *[mData->PortCount]; - mLabels = new wxStaticText *[mData->PortCount]; - mMeters = new LadspaEffectMeter *[mData->PortCount]; - - memset(mFields, 0, mData->PortCount * sizeof(wxTextCtrl *)); + mToggles.reinit( mData->PortCount ); + mSliders.reinit( mData->PortCount ); + mFields.reinit( mData->PortCount, true); + mLabels.reinit( mData->PortCount ); + mMeters.reinit( mData->PortCount ); wxASSERT(mParent); // To justify safenew wxScrolledWindow *const w = safenew wxScrolledWindow(mParent, @@ -1505,29 +1455,10 @@ bool LadspaEffect::CloseUI() { mParent->RemoveEventHandler(this); - if (mToggles) - { - delete [] mToggles; - mToggles = NULL; - } - - if (mSliders) - { - delete [] mSliders; - mSliders = NULL; - } - - if (mFields) - { - delete [] mFields; - mFields = NULL; - } - - if (mLabels) - { - delete [] mLabels; - mLabels = NULL; - } + mToggles.reset(); + mSliders.reset(); + mFields.reset(); + mLabels.reset(); mUIHost = NULL; mParent = NULL; diff --git a/src/effects/ladspa/LadspaEffect.h b/src/effects/ladspa/LadspaEffect.h index f6f4c1d86..3a284694f 100644 --- a/src/effects/ladspa/LadspaEffect.h +++ b/src/effects/ladspa/LadspaEffect.h @@ -13,6 +13,7 @@ class wxStaticText; class wxTextCtrl; class wxCheckBox; +#include "../../MemoryX.h" #include #include "audacity/EffectInterface.h" @@ -22,6 +23,7 @@ class wxCheckBox; #include "../../widgets/NumericTextCtrl.h" #include "ladspa.h" +#include "../../SampleFormat.h" #define LADSPAEFFECTS_VERSION wxT("1.0.0.0") #define LADSPAEFFECTS_FAMILY wxT("LADSPA") @@ -158,20 +160,19 @@ private: double mSampleRate; size_t mBlockSize; - int mUserBlockSize; bool mInteractive; unsigned mAudioIns; - unsigned long *mInputPorts; + ArrayOf mInputPorts; unsigned mAudioOuts; - unsigned long *mOutputPorts; + ArrayOf mOutputPorts; int mNumInputControls; - float *mInputControls; + Floats mInputControls; int mNumOutputControls; - float *mOutputControls; + Floats mOutputControls; bool mUseLatency; int mLatencyPort; @@ -185,11 +186,11 @@ private: NumericTextCtrl *mDuration; wxDialog *mDialog; wxWindow *mParent; - wxSlider **mSliders; - wxTextCtrl **mFields; - wxStaticText **mLabels; - wxCheckBox **mToggles; - LadspaEffectMeter **mMeters; + ArrayOf mSliders; + ArrayOf mFields; + ArrayOf mLabels; + ArrayOf mToggles; + ArrayOf mMeters; DECLARE_EVENT_TABLE() diff --git a/src/effects/lv2/LV2Effect.cpp b/src/effects/lv2/LV2Effect.cpp index 4aa39347d..070a2e02a 100644 --- a/src/effects/lv2/LV2Effect.cpp +++ b/src/effects/lv2/LV2Effect.cpp @@ -315,15 +315,11 @@ LV2Effect::LV2Effect(const LilvPlugin *plug) mLatency = 0.0; mDialog = NULL; - mSliders = NULL; - mFields = NULL; mURIMap = NULL; mNumURIMap = 0; mOptions = NULL; mNumOptions = 0; - mFeatures = NULL; - mNumFeatures = 0; mIdleFeature = NULL; mOptionsInterface = NULL; @@ -342,15 +338,6 @@ LV2Effect::~LV2Effect() free(mURIMap); } - if (mFeatures) - { - for (int i = 0; mFeatures[i] != NULL; i++) - { - delete mFeatures[i]; - } - free(mFeatures); - } - if (mOptions) { free(mOptions); @@ -460,10 +447,10 @@ bool LV2Effect::SetHost(EffectHostInterface *host) { mHost = host; - int numPorts = lilv_plugin_get_num_ports(mPlug); + auto numPorts = lilv_plugin_get_num_ports(mPlug); // Fail if we don't grok the port types - for (int i = 0; i < numPorts; i++) + for (size_t i = 0; i < numPorts; i++) { const LilvPort *port = lilv_plugin_get_port_by_index(mPlug, i); @@ -474,176 +461,174 @@ bool LV2Effect::SetHost(EffectHostInterface *host) } } - // Allocate buffers for the port indices and the default control values - float *minimumVals = new float [numPorts]; - float *maximumVals = new float [numPorts]; - float *defaultValues = new float [numPorts]; - - // Retrieve the port ranges for all ports (some values may be NaN) - lilv_plugin_get_port_ranges_float(mPlug, - minimumVals, - maximumVals, - defaultValues); - - // Get info about all ports - for (int i = 0; i < numPorts; i++) { - const LilvPort *port = lilv_plugin_get_port_by_index(mPlug, i); - int index = lilv_port_get_index(mPlug, port); + // Allocate buffers for the port indices and the default control values + Floats minimumVals{ numPorts }; + Floats maximumVals{ numPorts }; + Floats defaultValues{ numPorts }; - // Quick check for audio ports - if (lilv_port_is_a(mPlug, port, gAudio)) + // Retrieve the port ranges for all ports (some values may be NaN) + lilv_plugin_get_port_ranges_float(mPlug, + minimumVals.get(), + maximumVals.get(), + defaultValues.get()); + + // Get info about all ports + for (size_t i = 0; i < numPorts; i++) { + const LilvPort *port = lilv_plugin_get_port_by_index(mPlug, i); + int index = lilv_port_get_index(mPlug, port); + + // Quick check for audio ports + if (lilv_port_is_a(mPlug, port, gAudio)) + { + if (lilv_port_is_a(mPlug, port, gInput)) + { + mAudioInputs.Add(index); + } + else if (lilv_port_is_a(mPlug, port, gOutput)) + { + mAudioOutputs.Add(index); + } + continue; + } + + // Only control ports from this point + if (!lilv_port_is_a(mPlug, port, gControl)) + { + continue; + } + + LV2Port ctrl; + ctrl.mIndex = index; + + // Get the port name + ctrl.mSymbol = LilvString(lilv_port_get_symbol(mPlug, port)); + LilvNode *tmpName = lilv_port_get_name(mPlug, port); + ctrl.mName = LilvString(tmpName); + lilv_node_free(tmpName); + + // Get any unit descriptor + LilvNode *unit = lilv_port_get(mPlug, port, gUnit); + if (unit) + { + ctrl.mUnits = LilvString(lilv_world_get(gWorld, unit, gUnitSymbol, NULL)); + } + + // Get the group to which this port belongs or default to the main group + ctrl.mGroup = wxEmptyString; + LilvNode *group = lilv_port_get(mPlug, port, gGroup); + if (group) + { + ctrl.mGroup = LilvString(lilv_world_get(gWorld, group, gLabel, NULL)); + if (ctrl.mGroup.IsEmpty()) + { + ctrl.mGroup = LilvString(lilv_world_get(gWorld, group, gName, NULL)); + } + + if (ctrl.mGroup.IsEmpty()) + { + ctrl.mGroup = LilvString(group); + } + } + + // Add it if not previously done + if (mGroups.Index(ctrl.mGroup) == wxNOT_FOUND) + { + mGroups.Add(ctrl.mGroup); + } + + // Get the scale points + LilvScalePoints *points = lilv_port_get_scale_points(mPlug, port); + LILV_FOREACH(scale_points, j, points) + { + const LilvScalePoint *point = lilv_scale_points_get(points, j); + + ctrl.mScaleValues.Add(lilv_node_as_float(lilv_scale_point_get_value(point))); + ctrl.mScaleLabels.Add(LilvString(lilv_scale_point_get_label(point))); + } + lilv_scale_points_free(points); + + // Collect the value and range info + ctrl.mHasLo = !std::isnan(minimumVals[i]); + ctrl.mHasHi = !std::isnan(maximumVals[i]); + ctrl.mMin = ctrl.mHasLo ? minimumVals[i] : 0.0; + ctrl.mMax = ctrl.mHasHi ? maximumVals[i] : 1.0; + ctrl.mLo = ctrl.mMin; + ctrl.mHi = ctrl.mMax; + ctrl.mDef = !std::isnan(defaultValues[i]) ? + defaultValues[i] : + ctrl.mHasLo ? + ctrl.mLo : + ctrl.mHasHi ? + ctrl.mHi : + 0.0; + ctrl.mVal = ctrl.mDef; + + // Figure out the type of port we have if (lilv_port_is_a(mPlug, port, gInput)) { - mAudioInputs.Add(index); - } - else if (lilv_port_is_a(mPlug, port, gOutput)) - { - mAudioOutputs.Add(index); - } - continue; - } + ctrl.mInput = true; + if (lilv_port_has_property(mPlug, port, gToggled)) + { + ctrl.mToggle = true; + } + else if (lilv_port_has_property(mPlug, port, gEnumeration)) + { + ctrl.mEnumeration = true; + } + else if (lilv_port_has_property(mPlug, port, gInteger)) + { + ctrl.mInteger = true; + } + else if (lilv_port_has_property(mPlug, port, gSampleRate)) + { + ctrl.mSampleRate = true; + } - // Only control ports from this point - if (!lilv_port_is_a(mPlug, port, gControl)) - { - continue; - } + // Trigger properties can be combined with other types, but it + // seems mostly to be combined with toggle. So, we turn the + // checkbox into a button. + if (lilv_port_has_property(mPlug, port, gTrigger)) + { + ctrl.mTrigger = true; + } - LV2Port ctrl; - ctrl.mIndex = index; + // We'll make the slider logarithmic + if (lilv_port_has_property(mPlug, port, gLogarithmic)) + { + ctrl.mLogarithmic = true; + } - // Get the port name - ctrl.mSymbol = LilvString(lilv_port_get_symbol(mPlug, port)); - LilvNode *tmpName = lilv_port_get_name(mPlug, port); - ctrl.mName = LilvString(tmpName); - lilv_node_free(tmpName); + if (lilv_port_has_property(mPlug, port, gEnumeration)) + { + ctrl.mEnumeration = true; + } - // Get any unit descriptor - LilvNode *unit = lilv_port_get(mPlug, port, gUnit); - if (unit) - { - ctrl.mUnits = LilvString(lilv_world_get(gWorld, unit, gUnitSymbol, NULL)); - } - - // Get the group to which this port belongs or default to the main group - ctrl.mGroup = wxEmptyString; - LilvNode *group = lilv_port_get(mPlug, port, gGroup); - if (group) - { - ctrl.mGroup = LilvString(lilv_world_get(gWorld, group, gLabel, NULL)); - if (ctrl.mGroup.IsEmpty()) - { - ctrl.mGroup = LilvString(lilv_world_get(gWorld, group, gName, NULL)); - } - - if (ctrl.mGroup.IsEmpty()) - { - ctrl.mGroup = LilvString(group); - } - } - - // Add it if not previously done - if (mGroups.Index(ctrl.mGroup) == wxNOT_FOUND) - { - mGroups.Add(ctrl.mGroup); - } - - // Get the scale points - LilvScalePoints *points = lilv_port_get_scale_points(mPlug, port); - LILV_FOREACH(scale_points, j, points) - { - const LilvScalePoint *point = lilv_scale_points_get(points, j); - - ctrl.mScaleValues.Add(lilv_node_as_float(lilv_scale_point_get_value(point))); - ctrl.mScaleLabels.Add(LilvString(lilv_scale_point_get_label(point))); - } - lilv_scale_points_free(points); - - // Collect the value and range info - ctrl.mHasLo = !std::isnan(minimumVals[i]); - ctrl.mHasHi = !std::isnan(maximumVals[i]); - ctrl.mMin = ctrl.mHasLo ? minimumVals[i] : 0.0; - ctrl.mMax = ctrl.mHasHi ? maximumVals[i] : 1.0; - ctrl.mLo = ctrl.mMin; - ctrl.mHi = ctrl.mMax; - ctrl.mDef = !std::isnan(defaultValues[i]) ? - defaultValues[i] : - ctrl.mHasLo ? - ctrl.mLo : - ctrl.mHasHi ? - ctrl.mHi : - 0.0; - ctrl.mVal = ctrl.mDef; - - // Figure out the type of port we have - if (lilv_port_is_a(mPlug, port, gInput)) - { - ctrl.mInput = true; - if (lilv_port_has_property(mPlug, port, gToggled)) - { - ctrl.mToggle = true; - } - else if (lilv_port_has_property(mPlug, port, gEnumeration)) - { - ctrl.mEnumeration = true; - } - else if (lilv_port_has_property(mPlug, port, gInteger)) - { - ctrl.mInteger = true; - } - else if (lilv_port_has_property(mPlug, port, gSampleRate)) - { - ctrl.mSampleRate = true; - } - - // Trigger properties can be combined with other types, but it - // seems mostly to be combined with toggle. So, we turn the - // checkbox into a button. - if (lilv_port_has_property(mPlug, port, gTrigger)) - { - ctrl.mTrigger = true; - } - - // We'll make the slider logarithmic - if (lilv_port_has_property(mPlug, port, gLogarithmic)) - { - ctrl.mLogarithmic = true; - } - - if (lilv_port_has_property(mPlug, port, gEnumeration)) - { - ctrl.mEnumeration = true; - } - - mControlsMap[ctrl.mIndex] = mControls.GetCount(); - mGroupMap[ctrl.mGroup].Add(mControls.GetCount()); - mControls.Add(ctrl); - } - else if (lilv_port_is_a(mPlug, port, gOutput)) - { - ctrl.mInput = false; - if (lilv_port_has_property(mPlug, port, gLatency)) - { - mLatencyPort = i; - } - else - { + mControlsMap[ctrl.mIndex] = mControls.GetCount(); mGroupMap[ctrl.mGroup].Add(mControls.GetCount()); mControls.Add(ctrl); } - } - else - { - // Just ignore it for now + else if (lilv_port_is_a(mPlug, port, gOutput)) + { + ctrl.mInput = false; + if (lilv_port_has_property(mPlug, port, gLatency)) + { + mLatencyPort = i; + } + else + { + mGroupMap[ctrl.mGroup].Add(mControls.GetCount()); + mControls.Add(ctrl); + } + } + else + { + // Just ignore it for now + } } } - delete [] minimumVals; - delete [] maximumVals; - delete [] defaultValues; - // mHost will be null during registration if (mHost) { @@ -747,7 +732,7 @@ void LV2Effect::SetSampleRate(double rate) size_t LV2Effect::SetBlockSize(size_t maxBlockSize) { - mBlockSize = (int) maxBlockSize; + mBlockSize = maxBlockSize; if (mOptionsInterface && mOptionsInterface->set) { @@ -837,19 +822,13 @@ size_t LV2Effect::ProcessBlock(float **inbuf, float **outbuf, size_t size) bool LV2Effect::RealtimeInitialize() { - mMasterIn = new float *[mAudioInputs.GetCount()]; + mMasterIn.reinit( mAudioInputs.GetCount(), mBlockSize ); for (size_t p = 0, cnt = mAudioInputs.GetCount(); p < cnt; p++) - { - mMasterIn[p] = new float[mBlockSize]; - lilv_instance_connect_port(mMaster, mAudioInputs[p], mMasterIn[p]); - } + lilv_instance_connect_port(mMaster, mAudioInputs[p], mMasterIn[p].get()); - mMasterOut = new float *[mAudioOutputs.GetCount()]; + mMasterOut.reinit( mAudioOutputs.GetCount(), mBlockSize ); for (size_t p = 0, cnt = mAudioOutputs.GetCount(); p < cnt; p++) - { - mMasterOut[p] = new float[mBlockSize]; - lilv_instance_connect_port(mMaster, mAudioOutputs[p], mMasterOut[p]); - } + lilv_instance_connect_port(mMaster, mAudioOutputs[p], mMasterOut[p].get()); lilv_instance_activate(mMaster); @@ -868,17 +847,9 @@ bool LV2Effect::RealtimeFinalize() lilv_instance_deactivate(mMaster); - for (size_t p = 0, cnt = mAudioInputs.GetCount(); p < cnt; p++) - { - delete [] mMasterIn[p]; - } - delete [] mMasterIn; - - for (size_t p = 0, cnt = mAudioOutputs.GetCount(); p < cnt; p++) - { - delete [] mMasterOut[p]; - } - delete [] mMasterOut; + mMasterIn.reset(); + + mMasterOut.reset(); return true; } @@ -896,9 +867,7 @@ bool LV2Effect::RealtimeResume() bool LV2Effect::RealtimeProcessStart() { for (size_t p = 0, cnt = mAudioInputs.GetCount(); p < cnt; p++) - { - memset(mMasterIn[p], 0, mBlockSize * sizeof(float)); - } + memset(mMasterIn[p].get(), 0, mBlockSize * sizeof(float)); mNumSamples = 0; @@ -1072,8 +1041,6 @@ bool LV2Effect::PopulateUI(wxWindow *parent) mParent->PushEventHandler(this); - mSliders = NULL; - mFields = NULL; mSuilHost = NULL; mSuilInstance = NULL; @@ -1145,17 +1112,8 @@ bool LV2Effect::CloseUI() mParent->RemoveEventHandler(this); - if (mSliders) - { - delete [] mSliders; - mSliders = NULL; - } - - if (mFields) - { - delete [] mFields; - mFields = NULL; - } + mSliders.reset(); + mFields.reset(); if (mSuilInstance) { @@ -1365,27 +1323,26 @@ size_t LV2Effect::AddOption(const char *key, uint32_t size, const char *type, vo LV2_Feature *LV2Effect::AddFeature(const char *uri, void *data) { - int ndx = mNumFeatures; + mFeatures.resize(mFeatures.size() + 1); - mNumFeatures += 1; - mFeatures = (LV2_Feature **) realloc(mFeatures, mNumFeatures * sizeof(LV2_Feature *)); - mFeatures[ndx] = NULL; + auto &pFeature = mFeatures.back(); if (uri != NULL) { - mFeatures[ndx] = new LV2_Feature; - mFeatures[ndx]->URI = uri; - mFeatures[ndx]->data = data; + pFeature = make_movable(); + pFeature->URI = uri; + pFeature->data = data; } - return mFeatures[ndx]; + mFeaturePtrs.push_back(pFeature.get()); + return pFeature.get(); } LilvInstance *LV2Effect::InitInstance(float sampleRate) { LilvInstance *handle = lilv_plugin_instantiate(mPlug, sampleRate, - mFeatures); + mFeaturePtrs.data()); if (!handle) { return NULL; @@ -1521,7 +1478,7 @@ bool LV2Effect::BuildFancy() lilv_node_as_uri(uiType), lilv_uri_to_path(lilv_node_as_uri(lilv_ui_get_bundle_uri(ui))), lilv_uri_to_path(lilv_node_as_uri(lilv_ui_get_binary_uri(ui))), - mFeatures); + mFeaturePtrs.data()); lilv_uis_free(uis); @@ -1586,9 +1543,9 @@ bool LV2Effect::BuildPlain() int numCols = 5; // Allocate memory for the user parameter controls - int ctrlcnt = (int) mControls.GetCount(); - mSliders = new wxSlider *[ctrlcnt]; - mFields = new wxTextCtrl *[ctrlcnt]; + auto ctrlcnt = mControls.GetCount(); + mSliders.reinit(ctrlcnt); + mFields.reinit(ctrlcnt); wxSizer *innerSizer; diff --git a/src/effects/lv2/LV2Effect.h b/src/effects/lv2/LV2Effect.h index 8cd6814a6..17a233b5f 100644 --- a/src/effects/lv2/LV2Effect.h +++ b/src/effects/lv2/LV2Effect.h @@ -13,6 +13,9 @@ #if USE_LV2 +#include "../../MemoryX.h" +#include + #include #include #include @@ -32,6 +35,7 @@ #include #include +#include "../../SampleFormat.h" #include "../../widgets/NumericTextCtrl.h" #include "LoadLV2.h" @@ -254,7 +258,7 @@ private: EffectHostInterface *mHost; - int mBlockSize; + size_t mBlockSize; double mSampleRate; wxLongToLongHashMap mControlsMap; @@ -274,8 +278,7 @@ private: LilvInstance *mProcess; LV2SlaveArray mSlaves; - float **mMasterIn; - float **mMasterOut; + FloatBuffers mMasterIn, mMasterOut; size_t mNumSamples; double mLength; @@ -302,8 +305,8 @@ private: LV2_Options_Option *mOptions; int mNumOptions; - LV2_Feature **mFeatures; - int mNumFeatures; + std::vector> mFeatures; + std::vector mFeaturePtrs; LV2_Feature *mInstanceAccessFeature; LV2_Feature *mParentFeature; @@ -314,8 +317,8 @@ private: SuilInstance *mSuilInstance; NumericTextCtrl *mDuration; - wxSlider **mSliders; - wxTextCtrl **mFields; + ArrayOf mSliders; + ArrayOf mFields; bool mFactoryPresetsLoaded; wxArrayString mFactoryPresetNames; diff --git a/src/effects/vamp/VampEffect.cpp b/src/effects/vamp/VampEffect.cpp index 403a676ed..b403f9388 100644 --- a/src/effects/vamp/VampEffect.cpp +++ b/src/effects/vamp/VampEffect.cpp @@ -81,46 +81,10 @@ VampEffect::VampEffect(std::unique_ptr &&plugin, { mKey = mPath.BeforeLast(wxT('/')).ToUTF8(); mName = mPath.AfterLast(wxT('/')); - - mSliders = NULL; - mFields = NULL; - mLabels = NULL; - mToggles = NULL; - mChoices = NULL; - mValues = NULL; } VampEffect::~VampEffect() { - if (mValues) - { - delete [] mValues; - } - - if (mSliders) - { - delete [] mSliders; - } - - if (mFields) - { - delete [] mFields; - } - - if (mLabels) - { - delete [] mLabels; - } - - if (mToggles) - { - delete [] mToggles; - } - - if (mChoices) - { - delete [] mChoices; - } } // ============================================================================ @@ -486,11 +450,7 @@ bool VampEffect::Process() )); LabelTrack *ltrack = addedTracks.back()->get(); - float **data = new float *[channels]; // ANSWER-ME: Vigilant Sentry marks this as memory leak, var "data" not deleted. - for (int c = 0; c < channels; ++c) - { - data[c] = new float[block]; - } + FloatBuffers data{ channels, block }; auto originalLen = len; auto ls = lstart; @@ -502,12 +462,12 @@ bool VampEffect::Process() if (left) { - left->Get((samplePtr)data[0], floatSample, ls, request); + left->Get((samplePtr)data[0].get(), floatSample, ls, request); } if (right) { - right->Get((samplePtr)data[1], floatSample, rs, request); + right->Get((samplePtr)data[1].get(), floatSample, rs, request); } if (request < block) @@ -528,7 +488,8 @@ bool VampEffect::Process() (int)(mRate + 0.5) ); - Vamp::Plugin::FeatureSet features = mPlugin->process(data, timestamp); + Vamp::Plugin::FeatureSet features = mPlugin->process( + reinterpret_cast< float** >( data.get() ), timestamp); AddFeatures(ltrack, features); if (len > (int)step) @@ -589,14 +550,14 @@ void VampEffect::PopulateOrExchange(ShuttleGui & S) mParameters = mPlugin->getParameterDescriptors(); - int count = mParameters.size(); + auto count = mParameters.size(); - mToggles = new wxCheckBox *[count]; - mSliders = new wxSlider *[count]; - mFields = new wxTextCtrl *[count]; - mLabels = new wxStaticText *[count]; - mChoices = new wxChoice *[count]; - mValues = new float[count]; + mToggles.reinit( count ); + mSliders.reinit( count ); + mFields.reinit( count ); + mLabels.reinit( count ); + mChoices.reinit( count ); + mValues.reinit( count ); S.SetStyle(wxVSCROLL | wxTAB_TRAVERSAL); wxScrolledWindow *scroller = S.StartScroller(2); @@ -631,10 +592,10 @@ void VampEffect::PopulateOrExchange(ShuttleGui & S) S.AddSpace(1, 1); } - for (int p = 0; p < count; p++) + for (size_t p = 0; p < count; p++) { - wxString tip = wxString::FromUTF8(mParameters[p].description.c_str()); - wxString unit = wxString::FromUTF8(mParameters[p].unit.c_str()); + wxString tip = wxString::FromUTF8(mParameters[p].description.c_str()); + wxString unit = wxString::FromUTF8(mParameters[p].unit.c_str()); float value = mPlugin->getParameter(mParameters[p].identifier); diff --git a/src/effects/vamp/VampEffect.h b/src/effects/vamp/VampEffect.h index 69b1a3c53..7ce5b0ece 100644 --- a/src/effects/vamp/VampEffect.h +++ b/src/effects/vamp/VampEffect.h @@ -25,6 +25,7 @@ #include +#include "../../SampleFormat.h" #include "../Effect.h" class LabelTrack; @@ -99,13 +100,13 @@ private: Vamp::Plugin::ParameterList mParameters; - float *mValues; + Floats mValues; - wxSlider **mSliders; - wxTextCtrl **mFields; - wxStaticText **mLabels; - wxCheckBox **mToggles; - wxChoice **mChoices; + ArrayOf mSliders; + ArrayOf mFields; + ArrayOf mLabels; + ArrayOf mToggles; + ArrayOf mChoices; wxChoice *mProgram; DECLARE_EVENT_TABLE()