aboutsummaryrefslogtreecommitdiff
path: root/engines/agi/sound_midi.cpp
diff options
context:
space:
mode:
authorMax Horn2011-03-24 16:35:07 +0100
committerMax Horn2011-03-24 16:46:46 +0100
commitf4b30ecf6ebb8095eddfc62bb1e832b83b9d6527 (patch)
treebe299c8ab853ccfb056d19e5c106b73788482cc8 /engines/agi/sound_midi.cpp
parente9570c3a4b18984669bd17ba4c80c98c77f3f6f1 (diff)
downloadscummvm-rg350-f4b30ecf6ebb8095eddfc62bb1e832b83b9d6527.tar.gz
scummvm-rg350-f4b30ecf6ebb8095eddfc62bb1e832b83b9d6527.tar.bz2
scummvm-rg350-f4b30ecf6ebb8095eddfc62bb1e832b83b9d6527.zip
AGI: Change SoundGenMIDI to derive from Audio::MidiPlayer
As a side effect, this fixes the incorrect handling of 'All Note Off' in SoundGenMIDI::send.
Diffstat (limited to 'engines/agi/sound_midi.cpp')
-rw-r--r--engines/agi/sound_midi.cpp102
1 files changed, 15 insertions, 87 deletions
diff --git a/engines/agi/sound_midi.cpp b/engines/agi/sound_midi.cpp
index b58e1e50ab..2c6a189fbd 100644
--- a/engines/agi/sound_midi.cpp
+++ b/engines/agi/sound_midi.cpp
@@ -71,7 +71,7 @@ MIDISound::MIDISound(uint8 *data, uint32 len, int resnum, SoundMgr &manager) : A
warning("Error creating MIDI sound from resource %d (Type %d, length %d)", resnum, _type, len);
}
-SoundGenMIDI::SoundGenMIDI(AgiEngine *vm, Audio::Mixer *pMixer) : SoundGen(vm, pMixer), _parser(0), _isPlaying(false), _isGM(false) {
+SoundGenMIDI::SoundGenMIDI(AgiEngine *vm, Audio::Mixer *pMixer) : SoundGen(vm, pMixer), _isGM(false) {
MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI | MDT_ADLIB);
_driver = MidiDriver::createMidi(dev);
assert(_driver);
@@ -83,10 +83,6 @@ SoundGenMIDI::SoundGenMIDI(AgiEngine *vm, Audio::Mixer *pMixer) : SoundGen(vm, p
_nativeMT32 = false;
}
- memset(_channel, 0, sizeof(_channel));
- memset(_channelVolume, 127, sizeof(_channelVolume));
- _masterVolume = 0;
-
int ret = _driver->open();
if (ret == 0) {
if (_nativeMT32)
@@ -114,67 +110,30 @@ SoundGenMIDI::~SoundGenMIDI() {
delete[] _midiMusicData;
}
-void SoundGenMIDI::setChannelVolume(int channel) {
- int newVolume = _channelVolume[channel] * _masterVolume / 255;
- _channel[channel]->volume(newVolume);
-}
-
-void SoundGenMIDI::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 SoundGenMIDI::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) {
+ 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();
+ Audio::MidiPlayer::send(b);
+}
+
+void SoundGenMIDI::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);
+ if (_channelsTable[channel])
+ _channelsTable[channel]->send(b);
}
-void SoundGenMIDI::metaEvent(byte type, byte *data, uint16 length) {
-
- switch (type) {
- case 0x2F: // End of Track
- stop();
- _vm->_sound->soundIsFinished();
- break;
- default:
- //warning("Unhandled meta event: %02x", type);
- break;
- }
+void SoundGenMIDI::endOfTrack() {
+ stop();
+ _vm->_sound->soundIsFinished();
}
void SoundGenMIDI::onTimer(void *refCon) {
@@ -212,37 +171,6 @@ void SoundGenMIDI::play(int resnum) {
}
}
-void SoundGenMIDI::stop() {
- Common::StackLock lock(_mutex);
-
- if (!_isPlaying)
- return;
-
- _isPlaying = false;
- if (_parser) {
- _parser->unloadMusic();
- _parser = NULL;
- }
-}
-
-void SoundGenMIDI::pause() {
- setVolume(-1);
- _isPlaying = false;
-}
-
-void SoundGenMIDI::resume() {
- syncVolume();
- _isPlaying = true;
-}
-
-void SoundGenMIDI::syncVolume() {
- int volume = ConfMan.getInt("music_volume");
- if (ConfMan.getBool("mute")) {
- volume = -1;
- }
- setVolume(volume);
-}
-
/* channel / intrument setup: */
/* most songs are good with this: */