ZVISION: Add ActionMusic

This commit is contained in:
richiesams 2013-08-05 00:14:20 -05:00
parent 20c8920929
commit 6515e2d31b
3 changed files with 78 additions and 3 deletions

View File

@ -22,11 +22,16 @@
#include "common/scummsys.h"
#include "common/file.h"
#include "audio/decoders/wave.h"
#include "zvision/actions.h"
#include "zvision/zvision.h"
#include "zvision/script_manager.h"
#include "zvision/render_manager.h"
#include "zvision/action_node.h"
#include "zvision/zork_raw.h"
namespace ZVision {
@ -102,6 +107,60 @@ bool ActionCrossfade::execute(ZVision *engine) {
}
//////////////////////////////////////////////////////////////////////////////
// ActionMusic
//////////////////////////////////////////////////////////////////////////////
ActionMusic::ActionMusic(const Common::String &line) : _volume(255) {
uint type;
char fileNameBuffer[25];
uint loop;
uint volume = 255;
sscanf(line.c_str(), "%*[^:]:%*[^:]:%u(%u %25s %u %u)", &_key, &type, fileNameBuffer, &loop, &volume);
// type 4 are midi sound effect files
if (type == 4) {
_soundType = Audio::Mixer::kSFXSoundType;
_fileName = Common::String::format("midi/%s/%u.wav", fileNameBuffer, loop);
_loop = false;
} else {
// TODO: See what the other types are so we can specify the correct Mixer::SoundType. In the meantime use kPlainSoundType
_soundType = Audio::Mixer::kPlainSoundType;
_fileName = Common::String(fileNameBuffer);
_loop = loop == 1 ? true : false;
}
// Volume is optional. If it doesn't appear, assume full volume
if (volume != 255) {
// Volume in the script files is mapped to [0, 100], but the ScummVM mixer uses [0, 255]
_volume = volume * 255 / 100;
}
}
bool ActionMusic::execute(ZVision *engine) {
Audio::RewindableAudioStream *audioStream;
if (_fileName.contains(".wav")) {
Common::File file;
if (file.open(_fileName)) {
audioStream = Audio::makeWAVStream(&file, DisposeAfterUse::NO);
}
} else {
audioStream = makeRawZorkStream(_fileName, engine);
}
if (_loop) {
Audio::LoopingAudioStream *loopingAudioStream = new Audio::LoopingAudioStream(audioStream, 0, DisposeAfterUse::YES);
engine->_mixer->playStream(_soundType, 0, loopingAudioStream, -1, _volume);
} else {
engine->_mixer->playStream(_soundType, 0, audioStream, -1, _volume);
}
return true;
}
//////////////////////////////////////////////////////////////////////////////
// ActionPreloadAnimation
//////////////////////////////////////////////////////////////////////////////

View File

@ -25,7 +25,11 @@
#include "common/scummsys.h"
#include "common/str.h"
#include "audio/mixer.h"
namespace Common {
class String;
}
namespace ZVision {
@ -194,6 +198,19 @@ public:
private:
};
class ActionMusic : public ResultAction {
public:
ActionMusic(const Common::String &line);
bool execute(ZVision *engine);
private:
uint32 _key;
Audio::Mixer::SoundType _soundType;
Common::String _fileName;
bool _loop;
byte _volume;
};
class ActionPlayAnimation : public ResultAction {
public:
ActionPlayAnimation(const Common::String &line);

View File

@ -200,8 +200,7 @@ void ScriptManager::parseResults(Common::SeekableReadStream &stream, Common::Lis
} else if (line.matchString("*:music*", true)) {
actionList.push_back(Common::SharedPtr<ResultAction>(new ActionMusic(line)));
} else if (line.matchString("*:pan_track*", true)) {