diff options
Diffstat (limited to 'simon')
-rw-r--r-- | simon/midi.cpp | 45 | ||||
-rw-r--r-- | simon/midi.h | 5 |
2 files changed, 33 insertions, 17 deletions
diff --git a/simon/midi.cpp b/simon/midi.cpp index aca5b72ba4..038e42e471 100644 --- a/simon/midi.cpp +++ b/simon/midi.cpp @@ -61,8 +61,8 @@ MidiPlayer::MidiPlayer (OSystem *system) { _enable_sfx = true; _current = 0; - memset(_volumeTable, 127, sizeof(_volumeTable)); _masterVolume = 255; + resetVolumeTable(); _paused = false; _currentTrack = 255; @@ -104,12 +104,11 @@ void MidiPlayer::send (uint32 b) { if (!_current) return; - byte volume; - + byte channel = (byte) (b & 0x0F); if ((b & 0xFFF0) == 0x07B0) { // Adjust volume changes by master volume. - volume = (byte) ((b >> 16) & 0x7F); - _volumeTable [b & 0xF] = volume; + byte volume = (byte) ((b >> 16) & 0x7F); + _current->volume [channel] = volume; volume = volume * _masterVolume / 255; b = (b & 0xFF00FFFF) | (volume << 16); } else if ((b & 0xF0) == 0xC0 && _map_mt32_to_gm) { @@ -121,7 +120,6 @@ void MidiPlayer::send (uint32 b) { return; } - byte channel = (byte) (b & 0x0F); if (!_current->channel [channel]) _current->channel[channel] = (channel == 9) ? _driver->getPercussionChannel() : _driver->allocateChannel(); if (_current->channel [channel]) @@ -233,8 +231,12 @@ void MidiPlayer::pause (bool b) { _paused = b; _system->lock_mutex (_mutex); - for (int i = ARRAYSIZE (_volumeTable); i; --i) - _driver->send (((_paused ? 0 : (_volumeTable[i-1] * _masterVolume / 255)) << 16) | (7 << 8) | 0xB0 | i); + for (int i = 0; i < 16; ++i) { + if (_music.channel[i]) + _music.channel[i]->volume (_paused ? 0 : (_music.volume[i] * _masterVolume / 255)); + if (_sfx.channel[i]) + _sfx.channel[i]->volume (_paused ? 0 : (_sfx.volume[i] * _masterVolume / 255)); + } _system->unlock_mutex (_mutex); } @@ -246,14 +248,16 @@ void MidiPlayer::set_volume (int volume) { if (_masterVolume == volume) return; - _masterVolume = volume; // Now tell all the channels this. _system->lock_mutex (_mutex); if (_driver && !_paused) { - for (int i = ARRAYSIZE (_volumeTable); i; --i) { - _driver->send (((_volumeTable[i-1] * _masterVolume / 255) << 16) | (7 << 8) | 0xB0 | i); + for (int i = 0; i < 16; ++i) { + if (_music.channel[i]) + _music.channel[i]->volume (_music.volume[i] * _masterVolume / 255); + if (_sfx.channel[i]) + _sfx.channel[i]->volume (_sfx.volume[i] * _masterVolume / 255); } } _system->unlock_mutex (_mutex); @@ -317,7 +321,7 @@ void MidiPlayer::clearConstructs (MusicInfo &info) { if (_driver) { for (i = 0; i < 16; ++i) { if (info.channel[i]) { - _driver->send (0x007BB0 | info.channel[i]->getNumber()); // All Notes Off + info.channel[i]->allNotesOff(); info.channel[i]->release(); } } @@ -325,6 +329,15 @@ void MidiPlayer::clearConstructs (MusicInfo &info) { info.clear(); } +void MidiPlayer::resetVolumeTable() { + int i; + for (i = 0; i < 16; ++i) { + _music.volume[i] = _sfx.volume[i] = 127; + if (_driver) + _driver->send (((_masterVolume >> 1) << 16) | 0x7B0 | i); + } +} + static int simon1_gmf_size[] = { 8900, 12166, 2848, 3442, 4034, 4508, 7064, 9730, 6014, 4742, 3138, 6570, 5384, 8909, 6457, 16321, 2742, 8968, 4804, 8442, 7717, @@ -397,7 +410,7 @@ void MidiPlayer::loadSMF (File *in, int song, bool sfx) { if (!sfx) { _currentTrack = 255; - memset(_volumeTable, 127, sizeof(_volumeTable)); + resetVolumeTable(); } p->parser = parser; // That plugs the power cord into the wall _system->unlock_mutex (_mutex); @@ -456,7 +469,7 @@ void MidiPlayer::loadMultipleSMF (File *in, bool sfx) { if (!sfx) { _currentTrack = 255; - memset(_volumeTable, 127, sizeof(_volumeTable)); + resetVolumeTable(); } _system->unlock_mutex (_mutex); } @@ -505,7 +518,7 @@ void MidiPlayer::loadXMIDI (File *in, bool sfx) { if (!sfx) { _currentTrack = 255; - memset(_volumeTable, 127, sizeof(_volumeTable)); + resetVolumeTable(); } p->parser = parser; // That plugs the power cord into the wall _system->unlock_mutex (_mutex); @@ -537,7 +550,7 @@ void MidiPlayer::loadS1D (File *in, bool sfx) { if (!sfx) { _currentTrack = 255; - memset(_volumeTable, 127, sizeof(_volumeTable)); + resetVolumeTable(); } p->parser = parser; // That plugs the power cord into the wall _system->unlock_mutex (_mutex); diff --git a/simon/midi.h b/simon/midi.h index de80e253c3..331bbce02f 100644 --- a/simon/midi.h +++ b/simon/midi.h @@ -34,7 +34,9 @@ struct MusicInfo { byte num_songs; // For Type 1 SMF resources byte * songs[16]; // For Type 1 SMF resources uint32 song_sizes[16]; // For Type 1 SMF resources + MidiChannel *channel[16]; // Dynamic remapping of channels to resolve conflicts + byte volume[16]; // Current channel volume MusicInfo() { clear(); } void clear() { @@ -57,7 +59,6 @@ protected: MusicInfo *_current; // Allows us to establish current context for operations. // These are maintained for both music and SFX - byte _volumeTable[16]; // 0-127 byte _masterVolume; // 0-255 bool _paused; @@ -67,9 +68,11 @@ protected: byte _queuedTrack; bool _loopQueuedTrack; +protected: static void onTimer (void *data); void clearConstructs(); void clearConstructs (MusicInfo &info); + void resetVolumeTable(); public: bool _enable_sfx; |