From bf62205c737fe3904577d5e314b58cadba0c2789 Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Thu, 27 Dec 2012 16:34:23 +0200 Subject: MT32: Move the ROM file deletion code to the ScummVM MT32 driver This removes the custom ScummVM file deletion code in the munt code --- audio/softsynth/mt32.cpp | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) (limited to 'audio/softsynth/mt32.cpp') diff --git a/audio/softsynth/mt32.cpp b/audio/softsynth/mt32.cpp index 3e87963113..e2f1f36f2c 100644 --- a/audio/softsynth/mt32.cpp +++ b/audio/softsynth/mt32.cpp @@ -110,8 +110,9 @@ private: uint16 _channelMask; MT32Emu::Synth *_synth; MT32Emu::ReportHandlerScummVM *_reportHandler; - const MT32Emu::ROMImage *_controlROM; - const MT32Emu::ROMImage *_pcmROM; + const MT32Emu::ROMImage *_controlROM, *_pcmROM; + Common::File *_controlFile, *_pcmFile; + void deleteMuntStructures(); int _outputRate; @@ -198,10 +199,26 @@ MidiDriver_MT32::MidiDriver_MT32(Audio::Mixer *mixer) : MidiDriver_Emulated(mixe } MidiDriver_MT32::~MidiDriver_MT32() { + deleteMuntStructures(); +} + +void MidiDriver_MT32::deleteMuntStructures() { delete _synth; + _synth = NULL; delete _reportHandler; - MT32Emu::ROMImage::freeROMImage(_controlROM); - MT32Emu::ROMImage::freeROMImage(_pcmROM); + _reportHandler = NULL; + + if (_controlROM) + MT32Emu::ROMImage::freeROMImage(_controlROM); + _controlROM = NULL; + if (_pcmROM) + MT32Emu::ROMImage::freeROMImage(_pcmROM); + _pcmROM = NULL; + + delete _controlFile; + _controlFile = NULL; + delete _pcmFile; + _pcmFile = NULL; } int MidiDriver_MT32::open() { @@ -226,14 +243,14 @@ int MidiDriver_MT32::open() { _initializing = true; drawMessage(-1, _s("Initializing MT-32 Emulator")); - Common::File *controlFile = new Common::File(); - if (!controlFile->open("MT32_CONTROL.ROM")) + _controlFile = new Common::File(); + if (!_controlFile->open("MT32_CONTROL.ROM")) error("Error opening MT32_CONTROL.ROM"); - Common::File *pcmFile = new Common::File(); - if (!pcmFile->open("MT32_PCM.ROM")) + _pcmFile = new Common::File(); + if (!_pcmFile->open("MT32_PCM.ROM")) error("Error opening MT32_PCM.ROM"); - _controlROM = MT32Emu::ROMImage::makeROMImage(controlFile); - _pcmROM = MT32Emu::ROMImage::makeROMImage(pcmFile); + _controlROM = MT32Emu::ROMImage::makeROMImage(_controlFile); + _pcmROM = MT32Emu::ROMImage::makeROMImage(_pcmFile); if (!_synth->open(*_controlROM, *_pcmROM)) return MERR_DEVICE_NOT_AVAILABLE; @@ -295,12 +312,7 @@ void MidiDriver_MT32::close() { _mixer->stopHandle(_mixerSoundHandle); _synth->close(); - delete _synth; - _synth = NULL; - delete _reportHandler; - _reportHandler = NULL; - MT32Emu::ROMImage::freeROMImage(_controlROM); - MT32Emu::ROMImage::freeROMImage(_pcmROM); + deleteMuntStructures(); } void MidiDriver_MT32::generateSamples(int16 *data, int len) { -- cgit v1.2.3