diff options
| author | Max Horn | 2011-03-23 16:14:39 +0100 |
|---|---|---|
| committer | Max Horn | 2011-03-23 16:49:41 +0100 |
| commit | e70fd59b3505619cccb6f3280a4cf0fb57aefa97 (patch) | |
| tree | 055c9719a41c4706baa4e5c4837e5fd31da95486 /engines/draci | |
| parent | 29847ea42da3e597d3496972c80ce49bea76da20 (diff) | |
| download | scummvm-rg350-e70fd59b3505619cccb6f3280a4cf0fb57aefa97.tar.gz scummvm-rg350-e70fd59b3505619cccb6f3280a4cf0fb57aefa97.tar.bz2 scummvm-rg350-e70fd59b3505619cccb6f3280a4cf0fb57aefa97.zip | |
ENGINES: Further simplify pseudo MidiDrivers; fix some regressions
The regression affected AGOS and maybe some others; specifically,
the real MidiDriver would have been deleted twice -- I previously
missed that the Engine instances takes care of freeing the real
MidiDriver, not the MidiPlayer wrapping it.
This commit should clarify the ownership of the real MidiDriver for
most pseudo MidiDrivers.
Diffstat (limited to 'engines/draci')
| -rw-r--r-- | engines/draci/draci.cpp | 14 | ||||
| -rw-r--r-- | engines/draci/draci.h | 1 | ||||
| -rw-r--r-- | engines/draci/music.cpp | 63 | ||||
| -rw-r--r-- | engines/draci/music.h | 18 |
4 files changed, 38 insertions, 58 deletions
diff --git a/engines/draci/draci.cpp b/engines/draci/draci.cpp index 0bf2d5d34a..45d17ea24f 100644 --- a/engines/draci/draci.cpp +++ b/engines/draci/draci.cpp @@ -162,18 +162,7 @@ int DraciEngine::init() { _dubbingArchive = openAnyPossibleDubbing(); _sound = new Sound(_mixer); - MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI | MDT_ADLIB | MDT_PREFER_GM); - bool native_mt32 = ((MidiDriver::getMusicType(dev) == MT_MT32) || ConfMan.getBool("native_mt32")); - //bool adlib = (MidiDriver::getMusicType(dev) == MT_ADLIB); - - _midiDriver = MidiDriver::createMidi(dev); - if (native_mt32) - _midiDriver->property(MidiDriver::PROP_CHANNEL_MASK, 0x03FE); - - _music = new MusicPlayer(_midiDriver, musicPathMask); - _music->setNativeMT32(native_mt32); - _music->open(); - //_music->setAdLib(adlib); + _music = new MusicPlayer(musicPathMask); // Setup mixer syncSoundSettings(); @@ -404,7 +393,6 @@ DraciEngine::~DraciEngine() { delete _sound; delete _music; - delete _midiDriver; delete _soundsArchive; delete _dubbingArchive; diff --git a/engines/draci/draci.h b/engines/draci/draci.h index aa6080ca05..6a597e123e 100644 --- a/engines/draci/draci.h +++ b/engines/draci/draci.h @@ -85,7 +85,6 @@ public: AnimationManager *_anims; Sound *_sound; MusicPlayer *_music; - MidiDriver *_midiDriver; Font *_smallFont; Font *_bigFont; diff --git a/engines/draci/music.cpp b/engines/draci/music.cpp index b56e10518b..210e925389 100644 --- a/engines/draci/music.cpp +++ b/engines/draci/music.cpp @@ -36,18 +36,46 @@ namespace Draci { -MusicPlayer::MusicPlayer(MidiDriver *driver, const char *pathMask) : _parser(0), _driver(driver), _pathMask(pathMask), _looping(false), _isPlaying(false), _passThrough(false), _isGM(false), _track(-1) { +MusicPlayer::MusicPlayer(const char *pathMask) : _parser(0), _driver(0), _pathMask(pathMask), _looping(false), _isPlaying(false), _passThrough(false), _isGM(false), _track(-1) { + + MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI | MDT_ADLIB | MDT_PREFER_GM); + _nativeMT32 = ((MidiDriver::getMusicType(dev) == MT_MT32) || ConfMan.getBool("native_mt32")); + //bool adlib = (MidiDriver::getMusicType(dev) == MT_ADLIB); + + _driver = MidiDriver::createMidi(dev); + assert(_driver); + if (_nativeMT32) + _driver->property(MidiDriver::PROP_CHANNEL_MASK, 0x03FE); + memset(_channel, 0, sizeof(_channel)); memset(_channelVolume, 127, sizeof(_channelVolume)); _masterVolume = 0; _smfParser = MidiParser::createParser_SMF(); _midiMusicData = NULL; + + int ret = _driver->open(); + if (ret == 0) { + if (_nativeMT32) + _driver->sendMT32Reset(); + else + _driver->sendGMReset(); + + // TODO: Load cmf.ins with the instrument table. It seems that an + // interface for such an operation is supported for AdLib. Maybe for + // this card, setting instruments is necessary. + + _driver->setTimerCallback(this, &onTimer); + } } MusicPlayer::~MusicPlayer() { _driver->setTimerCallback(NULL, NULL); stop(); - this->close(); + if (_driver) { + _driver->close(); + delete _driver; + _driver = 0; + } _smfParser->setMidiDriver(NULL); delete _smfParser; delete[] _midiMusicData; @@ -75,37 +103,6 @@ void MusicPlayer::setVolume(int volume) { } } -int MusicPlayer::open() { - // Don't ever call open without first setting the output driver! - if (!_driver) - return 255; - - int ret = _driver->open(); - if (ret) - return ret; - - if (_nativeMT32) - _driver->sendMT32Reset(); - else - _driver->sendGMReset(); - - // TODO: Load cmf.ins with the instrument table. It seems that an - // interface for such an operation is supported for AdLib. Maybe for - // this card, setting instruments is necessary. - - _driver->setTimerCallback(this, &onTimer); - return 0; -} - -void MusicPlayer::close() { - stop(); - if (_driver) { - _driver->close(); - delete _driver; - } - _driver = 0; -} - void MusicPlayer::send(uint32 b) { if (_passThrough) { _driver->send(b); diff --git a/engines/draci/music.h b/engines/draci/music.h index 80d25016dc..e46901424d 100644 --- a/engines/draci/music.h +++ b/engines/draci/music.h @@ -38,7 +38,7 @@ namespace Draci { class MusicPlayer : public MidiDriver_BASE { public: - MusicPlayer(MidiDriver *driver, const char *pathMask); + MusicPlayer(const char *pathMask); ~MusicPlayer(); bool isPlaying() { return _isPlaying; } @@ -48,7 +48,6 @@ public: int getVolume() { return _masterVolume; } void syncVolume(); - void setNativeMT32(bool b) { _nativeMT32 = b; } bool hasNativeMT32() { return _nativeMT32; } void playSMF(int track, bool loop); void stop(); @@ -59,21 +58,18 @@ public: void setGM(bool isGM) { _isGM = isGM; } - // MidiDriver interface implementation - int open(); - void close(); - void send(uint32 b); - - void metaEvent(byte type, byte *data, uint16 length); - - MidiParser *_parser; - Common::Mutex _mutex; + // MidiDriver_BASE interface implementation + virtual void send(uint32 b); + virtual void metaEvent(byte type, byte *data, uint16 length); protected: static void onTimer(void *data); void setChannelVolume(int channel); + MidiParser *_parser; + Common::Mutex _mutex; + MidiChannel *_channel[16]; MidiDriver *_driver; MidiParser *_smfParser; |
