aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2011-03-25 10:58:40 +0100
committerMax Horn2011-03-25 14:14:13 +0100
commit00ad039b4cb0959b602592579d16adfac89bffc1 (patch)
tree40c6104dfc598b5667153cccbbc72934f958a602
parent10d1a58cb295993ddf4dbe4ab0869a01a6cbfa3b (diff)
downloadscummvm-rg350-00ad039b4cb0959b602592579d16adfac89bffc1.tar.gz
scummvm-rg350-00ad039b4cb0959b602592579d16adfac89bffc1.tar.bz2
scummvm-rg350-00ad039b4cb0959b602592579d16adfac89bffc1.zip
TOUCHE: Change MidiPlayer to derive from Audio::MidiPlayer
-rw-r--r--engines/touche/midi.cpp68
-rw-r--r--engines/touche/midi.h21
2 files changed, 20 insertions, 69 deletions
diff --git a/engines/touche/midi.cpp b/engines/touche/midi.cpp
index 4349a29bf5..9450f04b4d 100644
--- a/engines/touche/midi.cpp
+++ b/engines/touche/midi.cpp
@@ -33,8 +33,9 @@
namespace Touche {
MidiPlayer::MidiPlayer()
- : _driver(0), _parser(0), _midiData(0), _isLooping(false), _isPlaying(false), _masterVolume(0) {
- memset(_channelsTable, 0, sizeof(_channelsTable));
+ : _midiData(0) {
+
+ // FIXME: Necessary?
memset(_channelsVolume, 0, sizeof(_channelsVolume));
MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI | MDT_ADLIB | MDT_PREFER_GM);
@@ -81,13 +82,9 @@ void MidiPlayer::play(Common::ReadStream &stream, int size, bool loop) {
}
void MidiPlayer::stop() {
- Common::StackLock lock(_mutex);
- if (_isPlaying) {
- _isPlaying = false;
- _parser->unloadMusic();
- free(_midiData);
- _midiData = 0;
- }
+ Audio::MidiPlayer::stop();
+ free(_midiData);
+ _midiData = 0;
}
void MidiPlayer::updateTimer() {
@@ -102,9 +99,17 @@ void MidiPlayer::adjustVolume(int diff) {
}
void MidiPlayer::setVolume(int volume) {
+ // FIXME: This is almost identical to Audio::MidiPlayer::setVolume,
+ // the only difference is that this implementation will always
+ // transmit the volume change, even if the current _masterVolume
+ // equals the new master volume. This *could* make a difference in
+ // some situations.
+ // So, we should determine whether Touche requires this behavioral
+ // difference; and maybe also if other engines could benefit from it
+ // (as hypothetically, it might fix some subtle bugs?)
_masterVolume = CLIP(volume, 0, 255);
Common::StackLock lock(_mutex);
- for (int i = 0; i < NUM_CHANNELS; ++i) {
+ for (int i = 0; i < kNumChannels; ++i) {
if (_channelsTable[i]) {
_channelsTable[i]->volume(_channelsVolume[i] * _masterVolume / 255);
}
@@ -112,47 +117,10 @@ void MidiPlayer::setVolume(int volume) {
}
void MidiPlayer::send(uint32 b) {
- byte volume, ch = (byte)(b & 0xF);
- switch (b & 0xFFF0) {
- case 0x07B0: // volume change
- volume = (byte)((b >> 16) & 0x7F);
- _channelsVolume[ch] = volume;
- volume = volume * _masterVolume / 255;
- b = (b & 0xFF00FFFF) | (volume << 16);
- break;
- case 0x7BB0: // all notes off
- if (!_channelsTable[ch]) {
- // channel not yet allocated, no need to send the event
- return;
- }
- break;
- default:
- if ((b & 0xF0) == 0xC0 && _nativeMT32) { // program change
- b = (b & 0xFFFF00FF) | (_gmToRol[(b >> 8) & 0x7F] << 8);
- }
- break;
- }
- if (!_channelsTable[ch]) {
- _channelsTable[ch] = (ch == 9) ? _driver->getPercussionChannel() : _driver->allocateChannel();
- }
- if (_channelsTable[ch]) {
- _channelsTable[ch]->send(b);
- }
-}
-
-void MidiPlayer::metaEvent(byte type, byte *data, uint16 length) {
- switch (type) {
- case 0x2F: // end of Track
- if (_isLooping) {
- _parser->jumpToTick(0);
- } else {
- stop();
- }
- break;
- default:
-// warning("Unhandled meta event: %02x", type);
- break;
+ if ((b & 0xF0) == 0xC0 && _nativeMT32) { // program change
+ b = (b & 0xFFFF00FF) | (_gmToRol[(b >> 8) & 0x7F] << 8);
}
+ Audio::MidiPlayer::send(b);
}
void MidiPlayer::timerCallback(void *p) {
diff --git a/engines/touche/midi.h b/engines/touche/midi.h
index bc5adc6b5f..091deab220 100644
--- a/engines/touche/midi.h
+++ b/engines/touche/midi.h
@@ -29,7 +29,7 @@
#include "common/util.h"
#include "common/mutex.h"
-#include "audio/mididrv.h"
+#include "audio/midiplayer.h"
class MidiParser;
@@ -39,13 +39,8 @@ namespace Common {
namespace Touche {
-class MidiPlayer : public MidiDriver_BASE {
+class MidiPlayer : public Audio::MidiPlayer {
public:
-
- enum {
- NUM_CHANNELS = 16
- };
-
MidiPlayer();
~MidiPlayer();
@@ -54,27 +49,15 @@ public:
void updateTimer();
void adjustVolume(int diff);
void setVolume(int volume);
- int getVolume() const { return _masterVolume; }
- void setLooping(bool loop) { _isLooping = loop; }
// MidiDriver_BASE interface
virtual void send(uint32 b);
- virtual void metaEvent(byte type, byte *data, uint16 length);
private:
static void timerCallback(void *p);
- MidiDriver *_driver;
- MidiParser *_parser;
uint8 *_midiData;
- bool _isLooping;
- bool _isPlaying;
- int _masterVolume;
- bool _nativeMT32;
- MidiChannel *_channelsTable[NUM_CHANNELS];
- uint8 _channelsVolume[NUM_CHANNELS];
- Common::Mutex _mutex;
static const uint8 _gmToRol[];
};