diff options
author | Max Horn | 2011-03-24 16:41:46 +0100 |
---|---|---|
committer | Max Horn | 2011-03-24 16:46:48 +0100 |
commit | 47e347b9227e4472fdefbfa8f2811dd95d0e7a2f (patch) | |
tree | afe77ebe3034d49527a6738538fd723ccb5b1835 /engines/tinsel | |
parent | 7cc04f25ff614df96a805fb1c64b12c422e7022e (diff) | |
download | scummvm-rg350-47e347b9227e4472fdefbfa8f2811dd95d0e7a2f.tar.gz scummvm-rg350-47e347b9227e4472fdefbfa8f2811dd95d0e7a2f.tar.bz2 scummvm-rg350-47e347b9227e4472fdefbfa8f2811dd95d0e7a2f.zip |
TINSEL: Change MidiMusicPlayer to derive from Audio::MidiPlayer
Diffstat (limited to 'engines/tinsel')
-rw-r--r-- | engines/tinsel/music.cpp | 69 | ||||
-rw-r--r-- | engines/tinsel/music.h | 27 |
2 files changed, 13 insertions, 83 deletions
diff --git a/engines/tinsel/music.cpp b/engines/tinsel/music.cpp index 235f03ada8..943beb474e 100644 --- a/engines/tinsel/music.cpp +++ b/engines/tinsel/music.cpp @@ -386,7 +386,7 @@ void DeleteMidiBuffer() { midiBuffer.pDat = NULL; } -MidiMusicPlayer::MidiMusicPlayer() : _parser(0), _driver(0), _looping(false), _isPlaying(false) { +MidiMusicPlayer::MidiMusicPlayer() { 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); @@ -396,10 +396,6 @@ MidiMusicPlayer::MidiMusicPlayer() : _parser(0), _driver(0), _looping(false), _i if (native_mt32) _driver->property(MidiDriver::PROP_CHANNEL_MASK, 0x03FE); - memset(_channel, 0, sizeof(_channel)); - memset(_channelVolume, 0, sizeof(_channelVolume)); - _masterVolume = 0; - int ret = _driver->open(); if (ret == 0) { if (native_mt32) @@ -428,64 +424,23 @@ MidiMusicPlayer::~MidiMusicPlayer() { void MidiMusicPlayer::setVolume(int volume) { _vm->_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, volume); - if (_masterVolume == volume) - return; - - _masterVolume = volume; - - Common::StackLock lock(_mutex); - - for (int i = 0; i < 16; ++i) { - if (_channel[i]) { - _channel[i]->volume(_channelVolume[i] * _masterVolume / 255); - } - } + Audio::MidiPlayer::setVolume(volume); } void MidiMusicPlayer::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 & 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(); - - if (_channel[channel]) { - _channel[channel]->send(b); + Audio::MidiPlayer::send(b); + byte channel = (byte)(b & 0x0F); + if (_channelsTable[channel]) { if ((b & 0xFFF0) == 0x0079B0) { // We've just Reset All Controllers, so we need to // re-adjust the volume. Otherwise, volume is reset to // default whenever the music changes. - _channel[channel]->send(0x000007B0 | (((_channelVolume[channel] * _masterVolume) / 255) << 16) | channel); + _channelsTable[channel]->send(0x000007B0 | (((_channelsVolume[channel] * _masterVolume) / 255) << 16) | channel); } } } -void MidiMusicPlayer::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; - } -} - void MidiMusicPlayer::onTimer(void *refCon) { MidiMusicPlayer *music = (MidiMusicPlayer *)refCon; Common::StackLock lock(music->_mutex); @@ -522,21 +477,11 @@ void MidiMusicPlayer::playXMIDI(byte *midiData, uint32 size, bool loop) { _parser = parser; - _looping = loop; + _isLooping = loop; _isPlaying = true; } } -void MidiMusicPlayer::stop() { - Common::StackLock lock(_mutex); - - _isPlaying = false; - if (_parser) { - _parser->unloadMusic(); - _parser = NULL; - } -} - void MidiMusicPlayer::pause() { setVolume(-1); _isPlaying = false; diff --git a/engines/tinsel/music.h b/engines/tinsel/music.h index 1857032a6d..9436c02032 100644 --- a/engines/tinsel/music.h +++ b/engines/tinsel/music.h @@ -28,12 +28,13 @@ #ifndef TINSEL_MUSIC_H #define TINSEL_MUSIC_H -#include "audio/mididrv.h" -#include "audio/midiparser.h" +#include "audio/midiplayer.h" #include "audio/audiostream.h" #include "audio/mixer.h" #include "common/mutex.h" +class MidiParser; + namespace Tinsel { bool PlayMidiSequence( // Plays the specified MIDI sequence through the sound driver @@ -60,27 +61,21 @@ SCNHANDLE GetTrackOffset(int trackNumber); void dumpMusic(); -class MidiMusicPlayer : public MidiDriver_BASE { +class MidiMusicPlayer : public Audio::MidiPlayer { public: MidiMusicPlayer(); ~MidiMusicPlayer(); - bool isPlaying() { return _isPlaying; } - void setPlaying(bool playing) { _isPlaying = playing; } - - void setVolume(int volume); - int getVolume() { return _masterVolume; } + virtual void setVolume(int volume); void playXMIDI(byte *midiData, uint32 size, bool loop); - void stop(); +// void stop(); void pause(); void resume(); - void setLoop(bool loop) { _looping = loop; } // MidiDriver_BASE interface implementation virtual void send(uint32 b); - virtual void metaEvent(byte type, byte *data, uint16 length); // The original sets the "sequence timing" to 109 Hz, whatever that // means. The default is 120. @@ -90,17 +85,7 @@ protected: static void onTimer(void *data); - MidiParser *_parser; - Common::Mutex _mutex; - - MidiChannel *_channel[16]; - MidiDriver *_driver; MidiParser *_xmidiParser; - byte _channelVolume[16]; - - bool _isPlaying; - bool _looping; - byte _masterVolume; }; class PCMMusicPlayer : public Audio::AudioStream { |