From 4780eb7393cc8cc30dd822966eb82507bb61f6eb Mon Sep 17 00:00:00 2001 From: Max Horn Date: Thu, 24 Mar 2011 16:38:31 +0100 Subject: DRACI: Change MusicPlayer to derive from Audio::MidiPlayer --- engines/draci/music.cpp | 107 +++++------------------------------------------- 1 file changed, 10 insertions(+), 97 deletions(-) (limited to 'engines/draci/music.cpp') diff --git a/engines/draci/music.cpp b/engines/draci/music.cpp index 7c31cc320a..77f51544d5 100644 --- a/engines/draci/music.cpp +++ b/engines/draci/music.cpp @@ -36,7 +36,7 @@ namespace Draci { -MusicPlayer::MusicPlayer(const char *pathMask) : _parser(0), _driver(0), _pathMask(pathMask), _looping(false), _isPlaying(false), _isGM(false), _track(-1) { +MusicPlayer::MusicPlayer(const char *pathMask) : _pathMask(pathMask), _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")); @@ -47,9 +47,6 @@ MusicPlayer::MusicPlayer(const char *pathMask) : _parser(0), _driver(0), _pathMa 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; @@ -81,71 +78,17 @@ MusicPlayer::~MusicPlayer() { delete[] _midiMusicData; } -void MusicPlayer::setChannelVolume(int channel) { - int newVolume = _channelVolume[channel] * _masterVolume / 255; - debugC(3, kDraciSoundDebugLevel, "Music channel %d: volume %d->%d", - channel, _channelVolume[channel], newVolume); - _channel[channel]->volume(newVolume); -} - -void MusicPlayer::setVolume(int volume) { - Common::StackLock lock(_mutex); - - volume = CLIP(volume, 0, 255); - if (_masterVolume == volume) - return; - _masterVolume = volume; - - for (int i = 0; i < 16; ++i) { - if (_channel[i]) { - setChannelVolume(i); - } - } -} - -void MusicPlayer::send(uint32 b) { - byte channel = (byte)(b & 0x0F); - if ((b & 0xFFF0) == 0x07B0) { - // Adjust volume changes by master volume - byte volume = (byte)((b >> 16) & 0x7F); - _channelVolume[channel] = volume; - volume = volume * _masterVolume / 255; - b = (b & 0xFF00FFFF) | (volume << 16); - } else if ((b & 0xF0) == 0xC0 && !_isGM && !_nativeMT32) { - b = (b & 0xFFFF00FF) | MidiDriver::_mt32ToGm[(b >> 8) & 0xFF] << 8; - } - else if ((b & 0xFFF0) == 0x007BB0) { - //Only respond to All Notes Off if this channel - //has currently been allocated - if (!_channel[b & 0x0F]) - return; - } - - if (!_channel[channel]) { - _channel[channel] = (channel == 9) ? _driver->getPercussionChannel() : _driver->allocateChannel(); +void MusicPlayer::sendToChannel(byte channel, uint32 b) { + if (!_channelsTable[channel]) { + _channelsTable[channel] = (channel == 9) ? _driver->getPercussionChannel() : _driver->allocateChannel(); // If a new channel is allocated during the playback, make sure // its volume is correctly initialized. - if (_channel[channel]) - setChannelVolume(channel); + if (_channelsTable[channel]) + _channelsTable[channel]->volume(_channelsVolume[channel] * _masterVolume / 255); } - if (_channel[channel]) - _channel[channel]->send(b); -} - -void MusicPlayer::metaEvent(byte type, byte *data, uint16 length) { - - switch (type) { - case 0x2F: // End of Track - if (_looping) - _parser->jumpToTick(0); - else - stop(); - break; - default: - //warning("Unhandled meta event: %02x", type); - break; - } + if (_channelsTable[channel]) + _channelsTable[channel]->send(b); } void MusicPlayer::onTimer(void *refCon) { @@ -193,7 +136,7 @@ void MusicPlayer::playSMF(int track, bool loop) { syncVolume(); - _looping = loop; + _isLooping = loop; _isPlaying = true; _track = track; debugC(2, kDraciSoundDebugLevel, "Playing track %d", track); @@ -203,39 +146,9 @@ void MusicPlayer::playSMF(int track, bool loop) { } void MusicPlayer::stop() { - Common::StackLock lock(_mutex); - - if (!_isPlaying) - return; - + Audio::MidiPlayer::stop(); debugC(2, kDraciSoundDebugLevel, "Stopping track %d", _track); _track = -1; - _isPlaying = false; - if (_parser) { - _parser->unloadMusic(); - _parser = NULL; - } -} - -void MusicPlayer::pause() { - debugC(2, kDraciSoundDebugLevel, "Pausing track %d", _track); - setVolume(-1); - _isPlaying = false; -} - -void MusicPlayer::resume() { - debugC(2, kDraciSoundDebugLevel, "Resuming track %d", _track); - syncVolume(); - _isPlaying = true; -} - -void MusicPlayer::syncVolume() { - int volume = ConfMan.getInt("music_volume"); - if (ConfMan.getBool("mute")) { - volume = -1; - } - debugC(2, kDraciSoundDebugLevel, "Syncing music volume to %d", volume); - setVolume(volume); } } // End of namespace Draci -- cgit v1.2.3