mirror of
https://github.com/cookiengineer/audacity
synced 2025-10-13 14:13:32 +02:00
Remove some naked new amd delete in: import and export
This commit is contained in:
committed by
Paul Licameli
parent
b47bcb548e
commit
f82ff73578
@@ -79,7 +79,7 @@ FormatClassifier::FormatClassifier(const char* filename) :
|
||||
// Build a debug writer
|
||||
char dfile [1024];
|
||||
sprintf(dfile, "%s.sig", filename);
|
||||
mpWriter = new DebugWriter(dfile);
|
||||
mpWriter = std::make_unique<DebugWriter>(dfile);
|
||||
#endif
|
||||
|
||||
// Run it
|
||||
@@ -102,10 +102,6 @@ FormatClassifier::~FormatClassifier()
|
||||
|
||||
delete[] mMonoFeat;
|
||||
delete[] mStereoFeat;
|
||||
|
||||
#ifdef FORMATCLASSIFIER_SIGNAL_DEBUG
|
||||
delete mpWriter;
|
||||
#endif
|
||||
}
|
||||
|
||||
FormatClassifier::FormatClassT FormatClassifier::GetResultFormat()
|
||||
|
@@ -72,7 +72,7 @@ private:
|
||||
SpecPowerMeter mMeter;
|
||||
|
||||
#ifdef FORMATCLASSIFIER_SIGNAL_DEBUG
|
||||
DebugWriter* mpWriter;
|
||||
std::unique_ptr<DebugWriter> mpWriter;
|
||||
#endif
|
||||
|
||||
float* mSigBuffer;
|
||||
|
@@ -168,7 +168,7 @@ public:
|
||||
|
||||
private:
|
||||
sampleFormat mFormat;
|
||||
MyFLACFile *mFile;
|
||||
std::unique_ptr<MyFLACFile> mFile;
|
||||
wxFFile mHandle;
|
||||
unsigned long mSampleRate;
|
||||
unsigned long mNumChannels;
|
||||
@@ -343,7 +343,7 @@ FLACImportFileHandle::FLACImportFileHandle(const wxString & name)
|
||||
{
|
||||
mFormat = (sampleFormat)
|
||||
gPrefs->Read(wxT("/SamplingRate/DefaultProjectSampleFormat"), floatSample);
|
||||
mFile = new MyFLACFile(this);
|
||||
mFile = std::make_unique<MyFLACFile>(this);
|
||||
}
|
||||
|
||||
bool FLACImportFileHandle::Init()
|
||||
@@ -554,7 +554,6 @@ FLACImportFileHandle::~FLACImportFileHandle()
|
||||
//don't DELETE mFile if we are using OD.
|
||||
#ifndef EXPERIMENTAL_OD_FLAC
|
||||
mFile->finish();
|
||||
delete mFile;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@@ -293,17 +293,14 @@ GetGStreamerImportPlugin(ImportPluginList *importPluginList,
|
||||
nano);
|
||||
|
||||
// Instantiate plugin
|
||||
GStreamerImportPlugin *plug = new GStreamerImportPlugin();
|
||||
auto plug = make_movable<GStreamerImportPlugin>();
|
||||
|
||||
// No supported extensions...no gstreamer plugins installed
|
||||
if (plug->GetSupportedExtensions().GetCount() == 0)
|
||||
{
|
||||
delete plug;
|
||||
return;
|
||||
}
|
||||
|
||||
// Add to list of importers
|
||||
importPluginList->Append(plug);
|
||||
importPluginList->push_back(std::move(plug));
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
|
@@ -120,7 +120,7 @@ public:
|
||||
class LOFImportFileHandle final : public ImportFileHandle
|
||||
{
|
||||
public:
|
||||
LOFImportFileHandle(const wxString & name, wxTextFile *file);
|
||||
LOFImportFileHandle(const wxString & name, std::unique_ptr<wxTextFile> &&file);
|
||||
~LOFImportFileHandle();
|
||||
|
||||
wxString GetFileDescription();
|
||||
@@ -144,7 +144,7 @@ private:
|
||||
void doDuration();
|
||||
void doScrollOffset();
|
||||
|
||||
wxTextFile *mTextFile;
|
||||
std::unique_ptr<wxTextFile> mTextFile;
|
||||
wxFileName mLOFFileName; /**< The name of the LOF file, which is used to
|
||||
interpret relative paths in it */
|
||||
AudacityProject *mProject;
|
||||
@@ -161,9 +161,10 @@ private:
|
||||
double scrollOffset;
|
||||
};
|
||||
|
||||
LOFImportFileHandle::LOFImportFileHandle(const wxString & name, wxTextFile *file)
|
||||
LOFImportFileHandle::LOFImportFileHandle
|
||||
(const wxString & name, std::unique_ptr<wxTextFile> &&file)
|
||||
: ImportFileHandle(name),
|
||||
mTextFile(file)
|
||||
mTextFile(std::move(file))
|
||||
, mLOFFileName{name}
|
||||
{
|
||||
mProject = GetActiveProject();
|
||||
@@ -211,16 +212,13 @@ std::unique_ptr<ImportFileHandle> LOFImportPlugin::Open(const wxString &filename
|
||||
binaryFile.Close();
|
||||
|
||||
// Now open the file again as text file
|
||||
wxTextFile *file = new wxTextFile(filename);
|
||||
auto file = std::make_unique<wxTextFile>(filename);
|
||||
file->Open();
|
||||
|
||||
if (!file->IsOpened())
|
||||
{
|
||||
delete file;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return std::make_unique<LOFImportFileHandle>(filename, file);
|
||||
return std::make_unique<LOFImportFileHandle>(filename, std::move(file));
|
||||
}
|
||||
|
||||
wxString LOFImportFileHandle::GetFileDescription()
|
||||
@@ -501,10 +499,4 @@ void LOFImportFileHandle::doScrollOffset()
|
||||
|
||||
LOFImportFileHandle::~LOFImportFileHandle()
|
||||
{
|
||||
if(mTextFile)
|
||||
{
|
||||
if (mTextFile->IsOpened())
|
||||
mTextFile->Close();
|
||||
delete mTextFile;
|
||||
}
|
||||
}
|
||||
|
@@ -120,9 +120,9 @@ public:
|
||||
class MP3ImportFileHandle final : public ImportFileHandle
|
||||
{
|
||||
public:
|
||||
MP3ImportFileHandle(wxFile *file, wxString filename):
|
||||
MP3ImportFileHandle(std::unique_ptr<wxFile> &&file, wxString filename):
|
||||
ImportFileHandle(filename),
|
||||
mFile(file)
|
||||
mFile(std::move(file))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ public:
|
||||
private:
|
||||
void ImportID3(Tags *tags);
|
||||
|
||||
wxFile *mFile;
|
||||
std::unique_ptr<wxFile> mFile;
|
||||
void *mUserData;
|
||||
struct private_data mPrivateData;
|
||||
mad_decoder mDecoder;
|
||||
@@ -182,17 +182,15 @@ wxString MP3ImportPlugin::GetPluginFormatDescription()
|
||||
|
||||
std::unique_ptr<ImportFileHandle> MP3ImportPlugin::Open(const wxString &Filename)
|
||||
{
|
||||
wxFile *file = new wxFile(Filename);
|
||||
auto file = std::make_unique<wxFile>(Filename);
|
||||
|
||||
if (!file->IsOpened()) {
|
||||
delete file;
|
||||
if (!file->IsOpened())
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/* There's no way to tell if this is a valid mp3 file before actually
|
||||
* decoding, so we return a valid FileHandle. */
|
||||
|
||||
return std::make_unique<MP3ImportFileHandle>(file, Filename);
|
||||
return std::make_unique<MP3ImportFileHandle>(std::move(file), Filename);
|
||||
}
|
||||
|
||||
wxString MP3ImportFileHandle::GetFileDescription()
|
||||
@@ -215,7 +213,7 @@ int MP3ImportFileHandle::Import(TrackFactory *trackFactory, TrackHolders &outTra
|
||||
|
||||
/* Prepare decoder data, initialize decoder */
|
||||
|
||||
mPrivateData.file = mFile;
|
||||
mPrivateData.file = mFile.get();
|
||||
mPrivateData.inputBuffer = new unsigned char [INPUT_BUFFER_SIZE];
|
||||
mPrivateData.progress = mProgress.get();
|
||||
mPrivateData.updateResult= eProgressSuccess;
|
||||
@@ -260,12 +258,6 @@ int MP3ImportFileHandle::Import(TrackFactory *trackFactory, TrackHolders &outTra
|
||||
|
||||
MP3ImportFileHandle::~MP3ImportFileHandle()
|
||||
{
|
||||
if(mFile) {
|
||||
if (mFile->IsOpened()) {
|
||||
mFile->Close();
|
||||
}
|
||||
delete mFile;
|
||||
}
|
||||
}
|
||||
|
||||
void MP3ImportFileHandle::ImportID3(Tags *tags)
|
||||
|
@@ -100,20 +100,20 @@ class OggImportFileHandle final : public ImportFileHandle
|
||||
{
|
||||
public:
|
||||
OggImportFileHandle(const wxString & filename,
|
||||
wxFFile *file,
|
||||
OggVorbis_File *vorbisFile)
|
||||
std::unique_ptr<wxFFile> &&file,
|
||||
std::unique_ptr<OggVorbis_File> &&vorbisFile)
|
||||
: ImportFileHandle(filename),
|
||||
mFile(file),
|
||||
mVorbisFile(vorbisFile)
|
||||
mFile(std::move(file)),
|
||||
mVorbisFile(std::move(vorbisFile))
|
||||
{
|
||||
mFormat = (sampleFormat)
|
||||
gPrefs->Read(wxT("/SamplingRate/DefaultProjectSampleFormat"), floatSample);
|
||||
|
||||
mStreamUsage = new int[vorbisFile->links];
|
||||
for (int i = 0; i < vorbisFile->links; i++)
|
||||
mStreamUsage = new int[mVorbisFile->links];
|
||||
for (int i = 0; i < mVorbisFile->links; i++)
|
||||
{
|
||||
wxString strinfo;
|
||||
strinfo.Printf(wxT("Index[%02x] Version[%d], Channels[%d], Rate[%ld]"), (unsigned int) i,vorbisFile->vi[i].version,vorbisFile->vi[i].channels,vorbisFile->vi[i].rate);
|
||||
strinfo.Printf(wxT("Index[%02x] Version[%d], Channels[%d], Rate[%ld]"), (unsigned int) i,mVorbisFile->vi[i].version,mVorbisFile->vi[i].channels,mVorbisFile->vi[i].rate);
|
||||
mStreamInfo.Add(strinfo);
|
||||
mStreamUsage[i] = 0;
|
||||
}
|
||||
@@ -149,8 +149,8 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
wxFFile *mFile;
|
||||
OggVorbis_File *mVorbisFile;
|
||||
std::unique_ptr<wxFFile> mFile;
|
||||
std::unique_ptr<OggVorbis_File> mVorbisFile;
|
||||
|
||||
int *mStreamUsage;
|
||||
wxArrayString mStreamInfo;
|
||||
@@ -178,17 +178,15 @@ std::unique_ptr<ImportFileHandle> OggImportPlugin::Open(const wxString &filename
|
||||
wxUnusedVar(OV_CALLBACKS_STREAMONLY);
|
||||
wxUnusedVar(OV_CALLBACKS_STREAMONLY_NOCLOSE);
|
||||
|
||||
OggVorbis_File *vorbisFile = new OggVorbis_File;
|
||||
wxFFile *file = new wxFFile(filename, wxT("rb"));
|
||||
auto vorbisFile = std::make_unique<OggVorbis_File>();
|
||||
auto file = std::make_unique<wxFFile>(filename, wxT("rb"));
|
||||
|
||||
if (!file->IsOpened()) {
|
||||
// No need for a message box, it's done automatically (but how?)
|
||||
delete vorbisFile;
|
||||
delete file;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int err = ov_open(file->fp(), vorbisFile, NULL, 0);
|
||||
int err = ov_open(file->fp(), vorbisFile.get(), NULL, 0);
|
||||
|
||||
if (err < 0) {
|
||||
wxString message;
|
||||
@@ -213,12 +211,10 @@ std::unique_ptr<ImportFileHandle> OggImportPlugin::Open(const wxString &filename
|
||||
|
||||
// what to do with message?
|
||||
file->Close();
|
||||
delete vorbisFile;
|
||||
delete file;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return std::make_unique<OggImportFileHandle>(filename, file, vorbisFile);
|
||||
return std::make_unique<OggImportFileHandle>(filename, std::move(file), std::move(vorbisFile));
|
||||
}
|
||||
|
||||
wxString OggImportFileHandle::GetFileDescription()
|
||||
@@ -258,7 +254,7 @@ int OggImportFileHandle::Import(TrackFactory *trackFactory, TrackHolders &outTra
|
||||
continue;
|
||||
}
|
||||
|
||||
vorbis_info *vi = ov_info(mVorbisFile, i);
|
||||
vorbis_info *vi = ov_info(mVorbisFile.get(), i);
|
||||
|
||||
link.resize(vi->channels);
|
||||
|
||||
@@ -314,11 +310,11 @@ int OggImportFileHandle::Import(TrackFactory *trackFactory, TrackHolders &outTra
|
||||
// my hard drive that have malformed headers, and this added call
|
||||
// causes them to be read correctly. Otherwise they have lots of
|
||||
// zeros inserted at the beginning
|
||||
ov_pcm_seek(mVorbisFile, 0);
|
||||
ov_pcm_seek(mVorbisFile.get(), 0);
|
||||
|
||||
do {
|
||||
/* get data from the decoder */
|
||||
bytesRead = ov_read(mVorbisFile, (char *) mainBuffer,
|
||||
bytesRead = ov_read(mVorbisFile.get(), (char *) mainBuffer,
|
||||
CODEC_TRANSFER_SIZE,
|
||||
endian,
|
||||
2, // word length (2 for 16 bit samples)
|
||||
@@ -359,8 +355,8 @@ int OggImportFileHandle::Import(TrackFactory *trackFactory, TrackHolders &outTra
|
||||
|
||||
samplesSinceLastCallback += samplesRead;
|
||||
if (samplesSinceLastCallback > SAMPLES_PER_CALLBACK) {
|
||||
updateResult = mProgress->Update(ov_time_tell(mVorbisFile),
|
||||
ov_time_total(mVorbisFile, bitstream));
|
||||
updateResult = mProgress->Update(ov_time_tell(mVorbisFile.get()),
|
||||
ov_time_total(mVorbisFile.get(), bitstream));
|
||||
samplesSinceLastCallback -= SAMPLES_PER_CALLBACK;
|
||||
|
||||
}
|
||||
@@ -406,12 +402,10 @@ int OggImportFileHandle::Import(TrackFactory *trackFactory, TrackHolders &outTra
|
||||
|
||||
OggImportFileHandle::~OggImportFileHandle()
|
||||
{
|
||||
ov_clear(mVorbisFile);
|
||||
ov_clear(mVorbisFile.get());
|
||||
mFile->Detach(); // so that it doesn't try to close the file (ov_clear()
|
||||
// did that already)
|
||||
delete[] mStreamUsage;
|
||||
delete mVorbisFile;
|
||||
delete mFile;
|
||||
}
|
||||
|
||||
#endif /* USE_LIBVORBIS */
|
||||
|
Reference in New Issue
Block a user