diff options
author | Nicola Mettifogo | 2007-04-27 20:06:42 +0000 |
---|---|---|
committer | Nicola Mettifogo | 2007-04-27 20:06:42 +0000 |
commit | 81d6873608d92dccd6192a1050b8fb96fed76956 (patch) | |
tree | db09942de0c00bb7ae7debc1daec84e409db30a7 | |
parent | bead956c8de3eb8548de9b799c12b46b424cc14c (diff) | |
download | scummvm-rg350-81d6873608d92dccd6192a1050b8fb96fed76956.tar.gz scummvm-rg350-81d6873608d92dccd6192a1050b8fb96fed76956.tar.bz2 scummvm-rg350-81d6873608d92dccd6192a1050b8fb96fed76956.zip |
Refactored music code for dos version and added music to Amiga versions.
svn-id: r26619
-rw-r--r-- | engines/parallaction/callables.cpp | 7 | ||||
-rw-r--r-- | engines/parallaction/defs.h | 2 | ||||
-rw-r--r-- | engines/parallaction/disk.cpp | 14 | ||||
-rw-r--r-- | engines/parallaction/disk.h | 4 | ||||
-rw-r--r-- | engines/parallaction/intro.cpp | 17 | ||||
-rw-r--r-- | engines/parallaction/location.cpp | 6 | ||||
-rw-r--r-- | engines/parallaction/menu.cpp | 2 | ||||
-rw-r--r-- | engines/parallaction/music.cpp | 164 | ||||
-rw-r--r-- | engines/parallaction/music.h | 94 | ||||
-rw-r--r-- | engines/parallaction/parallaction.cpp | 66 | ||||
-rw-r--r-- | engines/parallaction/parallaction.h | 12 |
11 files changed, 275 insertions, 113 deletions
diff --git a/engines/parallaction/callables.cpp b/engines/parallaction/callables.cpp index 0f1bc00518..1946737488 100644 --- a/engines/parallaction/callables.cpp +++ b/engines/parallaction/callables.cpp @@ -55,7 +55,8 @@ void _c_play_boogie(void *parm) { return; flag = 0; - _vm->_midiPlayer->play("boogie2"); + _vm->_soundMan->setMusicFile("boogie2"); + _vm->_soundMan->playMusic(); return; } @@ -452,11 +453,11 @@ void _c_offSound(void*) { } void _c_startMusic(void*) { - // TODO: to be implemented + _vm->_soundMan->playMusic(); } void _c_closeMusic(void*) { - // TODO: to be implemented + _vm->_soundMan->stopMusic(); } } // namespace Parallaction diff --git a/engines/parallaction/defs.h b/engines/parallaction/defs.h index 9e877db457..d2b8f049d9 100644 --- a/engines/parallaction/defs.h +++ b/engines/parallaction/defs.h @@ -28,6 +28,8 @@ namespace Parallaction { +#define PATH_LEN 200 + template <class T> class ManagedList : public Common::List<T> { diff --git a/engines/parallaction/disk.cpp b/engines/parallaction/disk.cpp index b91a95c674..cbedb17e85 100644 --- a/engines/parallaction/disk.cpp +++ b/engines/parallaction/disk.cpp @@ -569,6 +569,16 @@ Table* DosDisk::loadTable(const char* name) { return t; } +Common::ReadStream* DosDisk::loadMusic(const char* name) { + char path[PATH_LEN]; + sprintf(path, "%s.mid", name); + + Common::File *stream = new Common::File; + if (!stream->open(path)) + errorFileNotFound(path); + + return stream; +} #pragma mark - @@ -1157,5 +1167,9 @@ Table* AmigaDisk::loadTable(const char* name) { return t; } +Common::ReadStream* AmigaDisk::loadMusic(const char* name) { + return openArchivedFile(name); +} + } // namespace Parallaction diff --git a/engines/parallaction/disk.h b/engines/parallaction/disk.h index b7b6ea4137..ea3ad6523f 100644 --- a/engines/parallaction/disk.h +++ b/engines/parallaction/disk.h @@ -111,7 +111,7 @@ public: virtual void loadSlide(const char *filename) = 0; virtual void loadScenery(const char* background, const char* mask) = 0; virtual Table* loadTable(const char* name) = 0; - + virtual Common::ReadStream* loadMusic(const char* name) = 0; }; class DosDisk : public Disk { @@ -146,6 +146,7 @@ public: void loadSlide(const char *filename); void loadScenery(const char* background, const char* mask); Table* loadTable(const char* name); + Common::ReadStream* loadMusic(const char* name); }; class AmigaDisk : public Disk { @@ -176,6 +177,7 @@ public: void loadSlide(const char *filename); void loadScenery(const char* background, const char* mask); Table* loadTable(const char* name); + Common::ReadStream* loadMusic(const char* name); }; } // namespace Parallaction diff --git a/engines/parallaction/intro.cpp b/engines/parallaction/intro.cpp index 6e1ec7ca47..efb73cf65f 100644 --- a/engines/parallaction/intro.cpp +++ b/engines/parallaction/intro.cpp @@ -126,7 +126,12 @@ extern Credit _credits[]; void _c_startIntro(void *parm) { _rightHandAnim = _vm->findAnimation("righthand"); - _vm->_midiPlayer->play("intro"); + + if (_vm->getPlatform() == Common::kPlatformPC) { + _vm->_soundMan->setMusicFile("intro"); + _vm->_soundMan->playMusic(); + } + _engineFlags |= kEngineMouse; return; @@ -144,6 +149,8 @@ void _c_endIntro(void *parm) { _di = _vm->_gfx->getStringWidth(_credits[_si]._name); _vm->_gfx->displayString((SCREEN_WIDTH - _di)/2, 100, _credits[_si]._name); + _vm->_gfx->updateScreen(); + for (uint16 v2 = 0; v2 < 100; v2++) { _vm->updateInput(); if (_mouseButtons != kMouseLeftUp) @@ -155,8 +162,12 @@ void _c_endIntro(void *parm) { waitUntilLeftClick(); - _engineFlags &= ~kEngineMouse; - _vm->_menu->selectCharacter(); + if (_vm->getFeatures() & GF_DEMO) { + _engineFlags |= kEngineQuit; + } else { + _engineFlags &= ~kEngineMouse; + _vm->_menu->selectCharacter(); + } return; } diff --git a/engines/parallaction/location.cpp b/engines/parallaction/location.cpp index 8de66e5cda..c0c2d8cad5 100644 --- a/engines/parallaction/location.cpp +++ b/engines/parallaction/location.cpp @@ -150,6 +150,10 @@ void Parallaction::parseLocation(const char *filename) { if (!scumm_stricmp(_tokens[0], "SOUND")) { strcpy(_soundFile, _tokens[1]); } + if (!scumm_stricmp(_tokens[0], "MUSIC")) { + if (getPlatform() == Common::kPlatformAmiga) + _soundMan->setMusicFile(_tokens[1]); + } fillBuffers(*_locationScript, true); } @@ -307,7 +311,7 @@ void Parallaction::showSlide(const char *name) { void Parallaction::changeLocation(char *location) { debugC(1, kDebugLocation, "changeLocation to '%s'", location); - pickMusic(location); + _soundMan->playLocationMusic(location); // WORKAROUND: this if-statement has been added to avoid crashes caused by // execution of label jobs after a location switch. The other workaround in diff --git a/engines/parallaction/menu.cpp b/engines/parallaction/menu.cpp index 843d959706..0311f45729 100644 --- a/engines/parallaction/menu.cpp +++ b/engines/parallaction/menu.cpp @@ -289,7 +289,7 @@ void Menu::selectCharacter() { v14._height = BLOCK_HEIGHT; _vm->changeCursor(kCursorArrow); - _vm->_midiPlayer->stop(); + _vm->_soundMan->stopMusic(); _vm->_gfx->setFont(kFontMenu); diff --git a/engines/parallaction/music.cpp b/engines/parallaction/music.cpp index b203b453be..e637e84569 100644 --- a/engines/parallaction/music.cpp +++ b/engines/parallaction/music.cpp @@ -22,17 +22,62 @@ #include "common/stdafx.h" #include "common/file.h" -#include "parallaction/parallaction.h" #include "common/stream.h" +#include "sound/mixer.h" #include "sound/midiparser.h" +#include "sound/mods/protracker.h" #include "parallaction/music.h" +#include "parallaction/parallaction.h" namespace Parallaction { +class MidiPlayer : public MidiDriver { +public: + + enum { + NUM_CHANNELS = 16 + }; + + MidiPlayer(MidiDriver *driver); + ~MidiPlayer(); + + void play(const char *filename); + void stop(); + void updateTimer(); + void adjustVolume(int diff); + void setVolume(int volume); + int getVolume() const { return _masterVolume; } + void setLooping(bool loop) { _isLooping = loop; } + + // MidiDriver interface + int open(); + void close(); + void send(uint32 b); + void metaEvent(byte type, byte *data, uint16 length); + void setTimerCallback(void *timerParam, void (*timerProc)(void *)) { } + uint32 getBaseTempo() { return _driver ? _driver->getBaseTempo() : 0; } + MidiChannel *allocateChannel() { return 0; } + MidiChannel *getPercussionChannel() { return 0; } + +private: + + static void timerCallback(void *p); + + MidiDriver *_driver; + MidiParser *_parser; + uint8 *_midiData; + bool _isLooping; + bool _isPlaying; + int _masterVolume; + MidiChannel *_channelsTable[NUM_CHANNELS]; + uint8 _channelsVolume[NUM_CHANNELS]; + Common::Mutex _mutex; +}; + MidiPlayer::MidiPlayer(MidiDriver *driver) : _driver(driver), _parser(0), _midiData(0), _isLooping(false), _isPlaying(false), _masterVolume(0) { assert(_driver); @@ -180,4 +225,121 @@ void MidiPlayer::timerCallback(void *p) { player->updateTimer(); } + +DosSoundMan::DosSoundMan(Parallaction *vm, MidiDriver *midiDriver) : SoundMan(vm), _musicData1(0) { + _midiPlayer = new MidiPlayer(midiDriver); +} + +DosSoundMan::~DosSoundMan() { + delete _midiPlayer; +} + +void DosSoundMan::playMusic() { + _midiPlayer->play(_musicFile); +} + +void DosSoundMan::stopMusic() { + _midiPlayer->stop(); +} + +void DosSoundMan::playCharacterMusic(const char *character) { + + if (!scumm_stricmp(_vm->_location._name, "night") || + !scumm_stricmp(_vm->_location._name, "intsushi")) { + return; + } + + char *name = const_cast<char*>(character); + + if (IS_MINI_CHARACTER(name)) + name+=4; + + if (!scumm_stricmp(name, _dinoName)) { + setMusicFile("dino"); + } else + if (!scumm_stricmp(name, _donnaName)) { + setMusicFile("dough"); + } else + if (!scumm_stricmp(name, _doughName)) { + setMusicFile("nuts"); + } else { + warning("unknown character '%s' in DosSoundMan::playCharacterMusic", character); + return; + } + + playMusic(); +} + +void DosSoundMan::playLocationMusic(const char *location) { + if (_musicData1 != 0) { + playCharacterMusic(_vm->_characterName); + _musicData1 = 0; + debugC(2, kDebugLocation, "changeLocation: started character specific music"); + } + + if (!scumm_stricmp(location, "night") || !scumm_stricmp(location, "intsushi")) { + setMusicFile("nuts"); + playMusic(); + + debugC(2, kDebugLocation, "changeLocation: started music 'soft'"); + } + + if (!scumm_stricmp(location, "museo") || + !scumm_stricmp(location, "caveau") || + !scumm_strnicmp(location, "plaza1", 6) || + !scumm_stricmp(location, "estgrotta") || + !scumm_stricmp(location, "intgrottadopo") || + !scumm_stricmp(location, "endtgz") || + !scumm_stricmp(location, "common")) { + + stopMusic(); + _musicData1 = 1; + + debugC(2, kDebugLocation, "changeLocation: music stopped"); + } +} + +AmigaSoundMan::AmigaSoundMan(Parallaction *vm) : SoundMan(vm) { + _musicStream = 0; +} + +AmigaSoundMan::~AmigaSoundMan() { + stopMusic(); +} + +void AmigaSoundMan::playMusic() { + stopMusic(); + + Common::ReadStream *stream = _vm->_disk->loadMusic(_musicFile); + _musicStream = Audio::makeProtrackerStream(stream); + delete stream; + + _mixer->playInputStream(Audio::Mixer::kMusicSoundType, &_musicHandle, _musicStream, -1, 255, 0, false, true); +} + +void AmigaSoundMan::stopMusic() { + _mixer->stopHandle(_musicHandle); + delete _musicStream; +} + +void AmigaSoundMan::playCharacterMusic(const char *character) { +} + +void AmigaSoundMan::playLocationMusic(const char *location) { +} + + +SoundMan::SoundMan(Parallaction *vm) : _vm(vm) { + _mixer = _vm->_mixer; +} + +void SoundMan::setMusicVolume(int value) { + _mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, value); +} + +void SoundMan::setMusicFile(const char *filename) { + strcpy(_musicFile, filename); +} + + } // namespace Parallaction diff --git a/engines/parallaction/music.h b/engines/parallaction/music.h index eef249a7d4..2c609f0353 100644 --- a/engines/parallaction/music.h +++ b/engines/parallaction/music.h @@ -26,53 +26,69 @@ #include "common/util.h" #include "common/mutex.h" +#include "sound/audiostream.h" +#include "sound/mixer.h" #include "sound/mididrv.h" +#include "parallaction/defs.h" + class MidiParser; namespace Parallaction { -class MidiPlayer : public MidiDriver { +class Parallaction; +class MidiPlayer; + +class SoundMan { + +protected: + Parallaction *_vm; + Audio::Mixer *_mixer; + char _musicFile[PATH_LEN]; + +public: + SoundMan(Parallaction *vm); + virtual ~SoundMan() {} + + void setMusicFile(const char *filename); + + virtual void playMusic() = 0; + virtual void stopMusic() = 0; + + virtual void playCharacterMusic(const char *character) = 0; + virtual void playLocationMusic(const char *location) = 0; + + void setMusicVolume(int value); +}; + +class DosSoundMan : public SoundMan { + + MidiPlayer *_midiPlayer; + int _musicData1; + +public: + DosSoundMan(Parallaction *vm, MidiDriver *midiDriver); + ~DosSoundMan(); + void playMusic(); + void stopMusic(); + + void playCharacterMusic(const char *character); + void playLocationMusic(const char *location); +}; + +class AmigaSoundMan : public SoundMan { + + Audio::AudioStream *_musicStream; + Audio::SoundHandle _musicHandle; + public: + AmigaSoundMan(Parallaction *vm); + AmigaSoundMan::~AmigaSoundMan(); + void playMusic(); + void stopMusic(); - enum { - NUM_CHANNELS = 16 - }; - - MidiPlayer(MidiDriver *driver); - ~MidiPlayer(); - - void play(const char *filename); - void stop(); - void updateTimer(); - void adjustVolume(int diff); - void setVolume(int volume); - int getVolume() const { return _masterVolume; } - void setLooping(bool loop) { _isLooping = loop; } - - // MidiDriver interface - int open(); - void close(); - void send(uint32 b); - void metaEvent(byte type, byte *data, uint16 length); - void setTimerCallback(void *timerParam, void (*timerProc)(void *)) { } - uint32 getBaseTempo() { return _driver ? _driver->getBaseTempo() : 0; } - MidiChannel *allocateChannel() { return 0; } - MidiChannel *getPercussionChannel() { return 0; } - -private: - - static void timerCallback(void *p); - - MidiDriver *_driver; - MidiParser *_parser; - uint8 *_midiData; - bool _isLooping; - bool _isPlaying; - int _masterVolume; - MidiChannel *_channelsTable[NUM_CHANNELS]; - uint8 _channelsVolume[NUM_CHANNELS]; - Common::Mutex _mutex; + void playCharacterMusic(const char *character); + void playLocationMusic(const char *location); }; } // namespace Parallaction diff --git a/engines/parallaction/parallaction.cpp b/engines/parallaction/parallaction.cpp index ae7320eafe..92495d8401 100644 --- a/engines/parallaction/parallaction.cpp +++ b/engines/parallaction/parallaction.cpp @@ -124,7 +124,7 @@ Parallaction::Parallaction(OSystem *syst) : Parallaction::~Parallaction() { - delete _midiPlayer; + delete _soundMan; delete _disk; delete _globalTable; @@ -165,10 +165,10 @@ int Parallaction::init() { _activeItem._id = 0; _procCurrentHoverItem = -1; - _musicData1 = 0; +// _musicData1 = 0; strcpy(_characterName1, "null"); - _midiPlayer = 0; + _soundMan = 0; _baseTime = 0; @@ -205,11 +205,14 @@ int Parallaction::init() { _animations.push_front(&_vm->_char._ani); _gfx = new Gfx(this); - int midiDriver = MidiDriver::detectMusicDriver(MDT_MIDI | MDT_ADLIB | MDT_PREFER_MIDI); - MidiDriver *driver = MidiDriver::createMidi(midiDriver); - _midiPlayer = new MidiPlayer(driver); - - _mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, ConfMan.getInt("music_volume")); + if (getPlatform() == Common::kPlatformPC) { + int midiDriver = MidiDriver::detectMusicDriver(MDT_MIDI | MDT_ADLIB | MDT_PREFER_MIDI); + MidiDriver *driver = MidiDriver::createMidi(midiDriver); + _soundMan = new DosSoundMan(this, driver); + _soundMan->setMusicVolume(ConfMan.getInt("music_volume")); + } else { + _soundMan = new AmigaSoundMan(this); + } return 0; } @@ -721,50 +724,6 @@ void Parallaction::freeCharacter() { return; } -void Parallaction::selectCharacterMusic(const char *name) { - if (IS_MINI_CHARACTER(name)) - name+=4; - - if (!scumm_stricmp(name, _dinoName)) { - _midiPlayer->play("dino"); - } else if (!scumm_stricmp(name, _donnaName)) { - _midiPlayer->play("donna"); - } else { - _midiPlayer->play("nuts"); - } - - return; -} - -void Parallaction::pickMusic(const char *location) { - if (_musicData1 != 0) { - selectCharacterMusic(_vm->_characterName); - _musicData1 = 0; - debugC(2, kDebugLocation, "changeLocation: started character specific music"); - } - - if (!scumm_stricmp(location, "night") || !scumm_stricmp(location, "intsushi")) { - _vm->_midiPlayer->play("soft"); - - debugC(2, kDebugLocation, "changeLocation: started music 'soft'"); - } - - if (!scumm_stricmp(location, "museo") || - !scumm_stricmp(location, "caveau") || - !scumm_strnicmp(location, "plaza1", 6) || - !scumm_stricmp(location, "estgrotta") || - !scumm_stricmp(location, "intgrottadopo") || - !scumm_stricmp(location, "endtgz") || - !scumm_stricmp(location, "common")) { - - _vm->_midiPlayer->stop(); - _musicData1 = 1; - - debugC(2, kDebugLocation, "changeLocation: music stopped"); - } -} - - void Parallaction::changeCharacter(const char *name) { char baseName[20]; @@ -796,8 +755,7 @@ void Parallaction::changeCharacter(const char *name) { _vm->_char._ani._cnv = _disk->loadFrames(fullName); - if (scumm_stricmp(name, "night") && scumm_stricmp(name, "intsushi")) - selectCharacterMusic(name); + _soundMan->playCharacterMusic(name); } } diff --git a/engines/parallaction/parallaction.h b/engines/parallaction/parallaction.h index 0a63ee9380..e317226e63 100644 --- a/engines/parallaction/parallaction.h +++ b/engines/parallaction/parallaction.h @@ -196,8 +196,6 @@ extern const char *_minidrkiName; #define IS_MINI_CHARACTER(s) (((s)[0] == 'm')) #define IS_DUMMY_CHARACTER(s) (((s)[0] == 'D')) -#define PATH_LEN 200 - void waitUntilLeftClick(); @@ -218,7 +216,7 @@ void jobEraseLabel(void *parm, Job *j); class Gfx; class Menu; -class MidiPlayer; +class SoundMan; @@ -347,8 +345,7 @@ private: const PARALLACTIONGameDescription *_gameDescription; public: - - MidiPlayer *_midiPlayer; + SoundMan *_soundMan; Gfx* _gfx; Menu* _menu; @@ -391,8 +388,6 @@ protected: // data int16 _transCurrentHoverItem; uint32 _baseTime; - - uint16 _musicData1; // only used in changeLocation char _characterName1[50]; // only used in changeCharacter int16 _keyDown; @@ -441,9 +436,6 @@ protected: // members void parseCommands(Script &script, CommandList&); - void pickMusic(const char *location); - void selectCharacterMusic(const char *name); - void freeCharacter(); void initResources(); |