[Scummvm-git-logs] scummvm master -> cc4f30790f1f714024da570ae16e4829c0e0a775
dreammaster
paulfgilbert at gmail.com
Sat Apr 11 02:48:27 UTC 2020
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
cc4f30790f ULTIMA4: Fleshing out music class
Commit: cc4f30790f1f714024da570ae16e4829c0e0a775
https://github.com/scummvm/scummvm/commit/cc4f30790f1f714024da570ae16e4829c0e0a775
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2020-04-10T19:48:14-07:00
Commit Message:
ULTIMA4: Fleshing out music class
Changed paths:
R engines/ultima/ultima4/sound/music_scummvm.cpp
engines/ultima/module.mk
engines/ultima/ultima4/filesys/u4file.cpp
engines/ultima/ultima4/game/cheat.cpp
engines/ultima/ultima4/game/codex.cpp
engines/ultima/ultima4/game/death.cpp
engines/ultima/ultima4/game/game.cpp
engines/ultima/ultima4/game/intro.cpp
engines/ultima/ultima4/game/person.cpp
engines/ultima/ultima4/game/portal.cpp
engines/ultima/ultima4/game/script.cpp
engines/ultima/ultima4/game/spell.cpp
engines/ultima/ultima4/map/camp.cpp
engines/ultima/ultima4/map/combat.cpp
engines/ultima/ultima4/map/shrine.cpp
engines/ultima/ultima4/sound/music.cpp
engines/ultima/ultima4/sound/music.h
engines/ultima/ultima4/sound/sound.cpp
engines/ultima/ultima4/sound/sound_scummvm.cpp
engines/ultima/ultima4/ultima4.cpp
engines/ultima/ultima4/ultima4.h
diff --git a/engines/ultima/module.mk b/engines/ultima/module.mk
index 78963dea4f..96b0c0f29c 100644
--- a/engines/ultima/module.mk
+++ b/engines/ultima/module.mk
@@ -207,7 +207,6 @@ MODULE_OBJS := \
ultima4/map/tileset.o \
ultima4/map/tileview.o \
ultima4/sound/music.o \
- ultima4/sound/music_scummvm.o \
ultima4/sound/sound.o \
ultima4/sound/sound_scummvm.o \
ultima4/ultima4.o \
diff --git a/engines/ultima/ultima4/filesys/u4file.cpp b/engines/ultima/ultima4/filesys/u4file.cpp
index 24a704ad79..d561c8f9cf 100644
--- a/engines/ultima/ultima4/filesys/u4file.cpp
+++ b/engines/ultima/ultima4/filesys/u4file.cpp
@@ -695,7 +695,7 @@ Common::String u4find_path(const Common::String &fname, Common::List<Common::Str
}
Common::String u4find_music(const Common::String &fname) {
- return "data/music/" + fname;
+ return "data/mid/" + fname;
}
Common::String u4find_sound(const Common::String &fname) {
diff --git a/engines/ultima/ultima4/game/cheat.cpp b/engines/ultima/ultima4/game/cheat.cpp
index 7136c3c948..284390af55 100644
--- a/engines/ultima/ultima4/game/cheat.cpp
+++ b/engines/ultima/ultima4/game/cheat.cpp
@@ -21,19 +21,20 @@
*/
#include "ultima/ultima4/game/cheat.h"
-#include "ultima/ultima4/map/location.h"
-#include "ultima/ultima4/map/map.h"
#include "ultima/ultima4/game/context.h"
#include "ultima/ultima4/game/game.h"
-#include "ultima/ultima4/map/mapmgr.h"
#include "ultima/ultima4/game/moongate.h"
#include "ultima/ultima4/game/portal.h"
#include "ultima/ultima4/game/player.h"
-#include "ultima/ultima4/gfx/screen.h"
#include "ultima/ultima4/game/stats.h"
+#include "ultima/ultima4/game/weapon.h"
+#include "ultima/ultima4/gfx/screen.h"
+#include "ultima/ultima4/map/location.h"
+#include "ultima/ultima4/map/map.h"
+#include "ultima/ultima4/map/mapmgr.h"
#include "ultima/ultima4/map/tileset.h"
#include "ultima/ultima4/core/utils.h"
-#include "ultima/ultima4/game/weapon.h"
+#include "ultima/ultima4/sound/music.h"
#include "common/debug.h"
#include "common/events.h"
@@ -350,7 +351,7 @@ bool CheatMenuController::keyPressed(int key) {
screenMessage("\nX-it!\n");
if (!g_game->exitToParentMap())
screenMessage("Not Here!\n");
- musicMgr->play();
+ g_music->play();
break;
case 'y':
@@ -360,7 +361,7 @@ bool CheatMenuController::keyPressed(int key) {
else {
screenMessage("Leaving...\n");
g_game->exitToParentMap();
- musicMgr->play();
+ g_music->play();
}
break;
diff --git a/engines/ultima/ultima4/game/codex.cpp b/engines/ultima/ultima4/game/codex.cpp
index ada85dd488..d2a9dca12e 100644
--- a/engines/ultima/ultima4/game/codex.cpp
+++ b/engines/ultima/ultima4/game/codex.cpp
@@ -205,7 +205,7 @@ void codexEject(CodexEjectCode code) {
/* return view to normal and exit the Abyss */
gameSetViewMode(VIEW_NORMAL);
g_game->exitToParentMap();
- musicMgr->play();
+ g_music->play();
/**
* if being ejected because of a missed virtue question,
diff --git a/engines/ultima/ultima4/game/death.cpp b/engines/ultima/ultima4/game/death.cpp
index db20cadde3..f6b7651640 100644
--- a/engines/ultima/ultima4/game/death.cpp
+++ b/engines/ultima/ultima4/game/death.cpp
@@ -74,7 +74,7 @@ void deathStart(int delay) {
return;
// stop playing music
- musicMgr->fadeOut(1000);
+ g_music->fadeOut(1000);
deathSequenceRunning = 1;
timerCount = 0;
@@ -133,7 +133,7 @@ void deathRevive() {
g_context->_aura->set();
g_context->_horseSpeed = 0;
g_context->_lastCommandTime = g_system->getMillis();
- musicMgr->play();
+ g_music->play();
g_context->_party->reviveParty();
diff --git a/engines/ultima/ultima4/game/game.cpp b/engines/ultima/ultima4/game/game.cpp
index 137680c6ce..eaa80a2565 100644
--- a/engines/ultima/ultima4/game/game.cpp
+++ b/engines/ultima/ultima4/game/game.cpp
@@ -196,7 +196,7 @@ void GameController::initScreen() {
}
void GameController::initScreenWithoutReloadingState() {
- musicMgr->play();
+ g_music->play();
imageMgr->get(BKGD_BORDERS)->_image->draw(0, 0);
g_context->_stats->update(); /* draw the party stats */
@@ -767,25 +767,25 @@ bool GameController::keyPressed(int key) {
/* handle music volume adjustments */
case ',':
// decrease the volume if possible
- screenMessage("Music: %d%s\n", musicMgr->decreaseMusicVolume(), "%");
+ screenMessage("Music: %d%s\n", g_music->decreaseMusicVolume(), "%");
endTurn = false;
break;
case '.':
// increase the volume if possible
- screenMessage("Music: %d%s\n", musicMgr->increaseMusicVolume(), "%");
+ screenMessage("Music: %d%s\n", g_music->increaseMusicVolume(), "%");
endTurn = false;
break;
/* handle sound volume adjustments */
case '<':
// decrease the volume if possible
- screenMessage("Sound: %d%s\n", musicMgr->decreaseSoundVolume(), "%");
+ screenMessage("Sound: %d%s\n", g_music->decreaseSoundVolume(), "%");
soundPlay(SOUND_FLEE);
endTurn = false;
break;
case '>':
// increase the volume if possible
- screenMessage("Sound: %d%s\n", musicMgr->increaseSoundVolume(), "%");
+ screenMessage("Sound: %d%s\n", g_music->increaseSoundVolume(), "%");
soundPlay(SOUND_FLEE);
endTurn = false;
break;
@@ -956,7 +956,7 @@ bool GameController::keyPressed(int key) {
}
case 'v':
- if (musicMgr->toggle())
+ if (g_music->toggle())
screenMessage("Volume On!\n");
else
screenMessage("Volume Off!\n");
@@ -1106,7 +1106,7 @@ bool GameController::keyPressed(int key) {
// Fade out the music and hide the cursor
//before returning to the menu.
- musicMgr->fadeOut(1000);
+ g_music->fadeOut(1000);
screenHideCursor();
intro->init();
@@ -1967,7 +1967,7 @@ void GameController::avatarMoved(MoveEvent &event) {
if (event._result & MOVE_EXIT_TO_PARENT) {
screenMessage("%cLeaving...%c\n", FG_GREY, FG_WHITE);
exitToParentMap();
- musicMgr->play();
+ g_music->play();
}
/* things that happen while not on board the balloon */
@@ -2004,7 +2004,7 @@ void GameController::avatarMovedInDungeon(MoveEvent &event) {
if (event._result & MOVE_EXIT_TO_PARENT) {
screenMessage("%cLeaving...%c\n", FG_GREY, FG_WHITE);
exitToParentMap();
- musicMgr->play();
+ g_music->play();
}
/* check to see if we're entering a dungeon room */
@@ -2796,7 +2796,7 @@ bool GameController::checkMoongates() {
return true;
setMap(shrine_spirituality, 1, NULL);
- musicMgr->play();
+ g_music->play();
shrine_spirituality->enter();
}
diff --git a/engines/ultima/ultima4/game/intro.cpp b/engines/ultima/ultima4/game/intro.cpp
index c49c56d922..db805ee5d2 100644
--- a/engines/ultima/ultima4/game/intro.cpp
+++ b/engines/ultima/ultima4/game/intro.cpp
@@ -320,7 +320,7 @@ bool IntroController::init() {
#endif
_beastiesVisible = true;
_beastieOffset = 0;
- musicMgr->intro();
+ g_music->intro();
} else {
// initialize the titles
initTitles();
@@ -424,7 +424,7 @@ bool IntroController::keyPressed(int key) {
case '7':
case '8':
case '9':
- musicMgr->introSwitch(key - '0');
+ g_music->introSwitch(key - '0');
break;
default:
valid = false;
@@ -938,7 +938,7 @@ void IntroController::timerFired() {
// setup the map screen
_mode = INTRO_MAP;
_beastiesVisible = true;
- musicMgr->intro();
+ g_music->intro();
updateScreen();
}
@@ -1088,21 +1088,21 @@ void IntroController::updateSoundMenu(MenuEvent &event) {
switch (event.getMenuItem()->getId()) {
case MI_SOUND_01:
- musicMgr->setMusicVolume(settingsChanged._musicVol);
+ g_music->setMusicVolume(settingsChanged._musicVol);
break;
case MI_SOUND_02:
- musicMgr->setSoundVolume(settingsChanged._soundVol);
+ g_music->setSoundVolume(settingsChanged._soundVol);
soundPlay(SOUND_FLEE);
break;
case USE_SETTINGS:
// save settings
settings.setData(settingsChanged);
settings.write();
- musicMgr->intro();
+ g_music->intro();
break;
case CANCEL:
- musicMgr->setMusicVolume(settings._musicVol);
- musicMgr->setSoundVolume(settings._soundVol);
+ g_music->setMusicVolume(settings._musicVol);
+ g_music->setSoundVolume(settings._soundVol);
// discard settings
settingsChanged = settings;
break;
@@ -1942,7 +1942,7 @@ void IntroController::skipTitles() {
#ifdef IOS
void IntroController::tryTriggerIntroMusic() {
if (mode == INTRO_MAP)
- musicMgr->intro();
+ g_music->intro();
}
#endif
diff --git a/engines/ultima/ultima4/game/person.cpp b/engines/ultima/ultima4/game/person.cpp
index 6447267b71..070b9ed556 100644
--- a/engines/ultima/ultima4/game/person.cpp
+++ b/engines/ultima/ultima4/game/person.cpp
@@ -384,11 +384,11 @@ void Person::runCommand(Conversation *cnv, const ResponsePart &command) {
} else if (command == ResponsePart::HEALCONFIRM) {
cnv->_state = Conversation::CONFIRMATION;
} else if (command == ResponsePart::STARTMUSIC_LB) {
- musicMgr->lordBritish();
+ g_music->lordBritish();
} else if (command == ResponsePart::STARTMUSIC_HW) {
- musicMgr->hawkwind();
+ g_music->hawkwind();
} else if (command == ResponsePart::STOPMUSIC) {
- musicMgr->play();
+ g_music->play();
} else if (command == ResponsePart::HAWKWIND) {
g_context->_party->adjustKarma(KA_HAWKWIND);
} else {
diff --git a/engines/ultima/ultima4/game/portal.cpp b/engines/ultima/ultima4/game/portal.cpp
index cef6daa09c..1ca6a87787 100644
--- a/engines/ultima/ultima4/game/portal.cpp
+++ b/engines/ultima/ultima4/game/portal.cpp
@@ -136,14 +136,14 @@ int usePortalAt(Location *location, MapCoords coords, PortalTriggerAction action
/* portal just exits to parent map */
if (portal->_exitPortal) {
g_game->exitToParentMap();
- musicMgr->play();
+ g_music->play();
return 1;
} else if (portal->_destid == location->_map->_id)
location->_coords = portal->_start;
else {
g_game->setMap(destination, portal->_saveLocation, portal);
- musicMgr->play();
+ g_music->play();
}
/* if the portal changes the map retroactively, do it here */
diff --git a/engines/ultima/ultima4/game/script.cpp b/engines/ultima/ultima4/game/script.cpp
index 8ed9c039c7..765bcdb055 100644
--- a/engines/ultima/ultima4/game/script.cpp
+++ b/engines/ultima/ultima4/game/script.cpp
@@ -1279,18 +1279,18 @@ Script::ReturnCode Script::karma(Shared::XMLNode *script, Shared::XMLNode *curre
Script::ReturnCode Script::music(Shared::XMLNode *script, Shared::XMLNode *current) {
if (current->getPropertyBool("reset"))
- musicMgr->play();
+ g_music->play();
else {
Common::String type = getPropAsStr(current, "type");
if (current->getPropertyBool("play"))
- musicMgr->play();
+ g_music->play();
if (current->getPropertyBool("stop"))
- musicMgr->stop();
+ g_music->stop();
else if (type == "shopping")
- musicMgr->shopping();
+ g_music->shopping();
else if (type == "camp")
- musicMgr->camp();
+ g_music->camp();
}
return RET_OK;
diff --git a/engines/ultima/ultima4/game/spell.cpp b/engines/ultima/ultima4/game/spell.cpp
index 4db4eacd14..381adaebe2 100644
--- a/engines/ultima/ultima4/game/spell.cpp
+++ b/engines/ultima/ultima4/game/spell.cpp
@@ -767,7 +767,7 @@ static int spellXit(int unused) {
if (!g_context->_location->_map->isWorldMap()) {
screenMessage("Leaving...\n");
g_game->exitToParentMap();
- musicMgr->play();
+ g_music->play();
return 1;
}
return 0;
@@ -793,7 +793,7 @@ static int spellYup(int unused) {
} else {
screenMessage("Leaving...\n");
g_game->exitToParentMap();
- musicMgr->play();
+ g_music->play();
return 1;
}
diff --git a/engines/ultima/ultima4/map/camp.cpp b/engines/ultima/ultima4/map/camp.cpp
index 1eab985820..3982c4e293 100644
--- a/engines/ultima/ultima4/map/camp.cpp
+++ b/engines/ultima/ultima4/map/camp.cpp
@@ -77,7 +77,7 @@ void CampController::begin() {
CombatController::begin();
- musicMgr->camp();
+ g_music->camp();
screenMessage("Resting...\n");
screenDisableCursor();
@@ -90,7 +90,7 @@ void CampController::begin() {
if (settings._campingAlwaysCombat || (xu4_random(8) == 0)) {
const Creature *m = creatureMgr->randomAmbushing();
- musicMgr->play();
+ g_music->play();
screenMessage("Ambushed!\n");
/* create an ambushing creature (so it leaves a chest) */
@@ -118,7 +118,7 @@ void CampController::begin() {
eventHandler->popController();
g_game->exitToParentMap();
- musicMgr->fadeIn(CAMP_FADE_IN_TIME, true);
+ g_music->fadeIn(CAMP_FADE_IN_TIME, true);
delete this;
}
}
@@ -158,7 +158,7 @@ void InnController::begin() {
/* in the original, the vendor music plays straight through sleeping */
if (settings._enhancements)
- musicMgr->fadeOut(INN_FADE_OUT_TIME); /* Fade volume out to ease into rest */
+ g_music->fadeOut(INN_FADE_OUT_TIME); /* Fade volume out to ease into rest */
EventHandler::wait_msecs(INN_FADE_OUT_TIME);
@@ -194,7 +194,7 @@ void InnController::begin() {
screenMessage("\nMorning!\n");
screenPrompt();
- musicMgr->fadeIn(INN_FADE_IN_TIME, true);
+ g_music->fadeIn(INN_FADE_IN_TIME, true);
}
bool InnController::heal() {
diff --git a/engines/ultima/ultima4/map/combat.cpp b/engines/ultima/ultima4/map/combat.cpp
index 18c75528ff..49d8f4be34 100644
--- a/engines/ultima/ultima4/map/combat.cpp
+++ b/engines/ultima/ultima4/map/combat.cpp
@@ -265,7 +265,7 @@ void CombatController::begin() {
/* FIXME: there should be a better way to accomplish this */
if (!_camping) {
- musicMgr->play();
+ g_music->play();
}
/* Set focus to the first active party member, if there is one */
@@ -300,7 +300,7 @@ void CombatController::end(bool adjustKarma) {
bool won = isWon();
g_game->exitToParentMap();
- musicMgr->play();
+ g_music->play();
if (_winOrLose) {
if (won) {
@@ -886,25 +886,25 @@ bool CombatController::keyPressed(int key) {
/* handle music volume adjustments */
case ',':
// decrease the volume if possible
- screenMessage("Music: %d%s\n", musicMgr->decreaseMusicVolume(), "%");
+ screenMessage("Music: %d%s\n", g_music->decreaseMusicVolume(), "%");
endTurn = false;
break;
case '.':
// increase the volume if possible
- screenMessage("Music: %d%s\n", musicMgr->increaseMusicVolume(), "%");
+ screenMessage("Music: %d%s\n", g_music->increaseMusicVolume(), "%");
endTurn = false;
break;
/* handle sound volume adjustments */
case '<':
// decrease the volume if possible
- screenMessage("Sound: %d%s\n", musicMgr->decreaseSoundVolume(), "%");
+ screenMessage("Sound: %d%s\n", g_music->decreaseSoundVolume(), "%");
soundPlay(SOUND_FLEE);
endTurn = false;
break;
case '>':
// increase the volume if possible
- screenMessage("Sound: %d%s\n", musicMgr->increaseSoundVolume(), "%");
+ screenMessage("Sound: %d%s\n", g_music->increaseSoundVolume(), "%");
soundPlay(SOUND_FLEE);
endTurn = false;
break;
@@ -973,7 +973,7 @@ bool CombatController::keyPressed(int key) {
break;
case 'v':
- if (musicMgr->toggle())
+ if (g_music->toggle())
screenMessage("Volume On!\n");
else
screenMessage("Volume Off!\n");
diff --git a/engines/ultima/ultima4/map/shrine.cpp b/engines/ultima/ultima4/map/shrine.cpp
index 3c8b1daaac..34278c383f 100644
--- a/engines/ultima/ultima4/map/shrine.cpp
+++ b/engines/ultima/ultima4/map/shrine.cpp
@@ -287,7 +287,7 @@ void Shrine::showVision(bool elevated) {
void Shrine::eject() {
g_game->exitToParentMap();
- musicMgr->play();
+ g_music->play();
g_context->_location->_turnCompleter->finishTurn();
}
diff --git a/engines/ultima/ultima4/sound/music.cpp b/engines/ultima/ultima4/sound/music.cpp
index 3614bb62b9..1ad616e0ef 100644
--- a/engines/ultima/ultima4/sound/music.cpp
+++ b/engines/ultima/ultima4/sound/music.cpp
@@ -31,26 +31,32 @@
#include "ultima/ultima4/game/context.h"
#include "ultima/ultima4/map/location.h"
#include "ultima/ultima4/ultima4.h"
+#include "ultima/shared/core/file.h"
+#include "audio/decoders/mp3.h"
+#include "audio/mods/mod_xm_s3m.h"
namespace Ultima {
namespace Ultima4 {
-using Common::String;
-using Std::vector;
-
/*
* Static variables
*/
-Music *Music::instance = NULL;
-bool Music::fading = false;
-bool Music::on = false;
-bool Music::functional = true;
+Music *g_music;
+
+bool Music::_fading;
+bool Music::_on;
+bool Music::_functional;
/*
* Constructors/Destructors
*/
-Music::Music() : _introMid(TOWNS), _current(NONE), _playing(NULL) {
+Music::Music() : _introMid(TOWNS), _current(NONE), _playing(nullptr) {
+ g_music = this;
+ _fading = false;
+ _on = false;
+ _functional = true;
+
_filenames.reserve(MAX);
_filenames.push_back(""); // filename for MUSIC_NONE;
@@ -59,7 +65,7 @@ Music::Music() : _introMid(TOWNS), _current(NONE), _playing(NULL) {
*/
const Config *config = Config::getInstance();
- vector<ConfigElement> musicConfs = config->getElement("music").getChildren();
+ Std::vector<ConfigElement> musicConfs = config->getElement("music").getChildren();
Std::vector<ConfigElement>::const_iterator i = musicConfs.begin();
Std::vector<ConfigElement>::const_iterator theEnd = musicConfs.end();
for (; i != theEnd; ++i) {
@@ -72,16 +78,19 @@ Music::Music() : _introMid(TOWNS), _current(NONE), _playing(NULL) {
create_sys(); // Call the Sound System specific creation file.
// Set up the volume.
- on = settings._musicVol;
- setMusicVolume(settings._musicVol);
- setSoundVolume(settings._soundVol);
+ _on = settings._musicVol;
}
Music::~Music() {
+ g_music = nullptr;
eventHandler->getTimer()->remove(&Music::callback);
destroy_sys(); // Call the Sound System specific destruction file.
}
+bool Music::isPlaying() {
+ return g_music->isPlaying_sys();
+}
+
bool Music::load(Type music) {
ASSERT(music < MAX, "Attempted to load an invalid piece of music in Music::load()");
@@ -96,9 +105,9 @@ bool Music::load(Type music) {
return true;
}
- Common::String pathname(u4find_music(_filenames[music]));
- if (!pathname.empty()) {
- bool status = load_sys(pathname);
+ Common::String pathName(u4find_music(_filenames[music]));
+ if (!pathName.empty()) {
+ bool status = load_sys(pathName);
if (status)
_current = music;
return status;
@@ -109,10 +118,10 @@ bool Music::load(Type music) {
void Music::callback(void *data) {
eventHandler->getTimer()->remove(&Music::callback);
- if (musicMgr->on && !isPlaying())
- musicMgr->play();
- else if (!musicMgr->on && isPlaying())
- musicMgr->stop();
+ if (g_music->_on && !isPlaying())
+ g_music->play();
+ else if (!g_music->_on && isPlaying())
+ g_music->stop();
}
void Music::play() {
@@ -129,19 +138,19 @@ void Music::introSwitch(int n) {
bool Music::toggle() {
eventHandler->getTimer()->remove(&Music::callback);
- on = !on;
- if (!on)
+ _on = !_on;
+ if (!_on)
fadeOut(1000);
else
fadeIn(1000, true);
eventHandler->getTimer()->add(&Music::callback, settings._gameCyclesPerSecond);
- return on;
+ return _on;
}
void Music::fadeOut(int msecs) {
- // fade the music out even if 'on' is false
- if (!functional)
+ // fade the music out even if '_on' is false
+ if (!_functional)
return;
if (isPlaying()) {
@@ -154,11 +163,11 @@ void Music::fadeOut(int msecs) {
}
void Music::fadeIn(int msecs, bool loadFromMap) {
- if (!functional || !on)
+ if (!_functional || !_on)
return;
if (!isPlaying()) {
- /* make sure we've got something loaded to play */
+ // make sure we've got something loaded to play
if (loadFromMap || !_playing)
load(g_context->_location->_map->_music);
@@ -202,5 +211,83 @@ int Music::decreaseSoundVolume() {
return (settings._soundVol * 100 / MAX_VOLUME); // percentage
}
+
+void Music::create_sys() {
+ _functional = true;
+}
+
+void Music::destroy_sys() {
+}
+
+bool Music::load_sys(const Common::String &pathName) {
+ delete _playing;
+ _playing = NULL;
+
+ if (pathName.hasSuffixIgnoreCase(".it")) {
+ warning("TODO: Play music file - %s", pathName.c_str());
+ return true;
+ }
+
+ Shared::File f;
+ if (!f.open(pathName)) {
+ warning("unable to load music file %s", pathName.c_str());
+ return false;
+ }
+
+ Common::SeekableReadStream *s = f.readStream(f.size());
+ if (pathName.hasSuffixIgnoreCase(".mp3"))
+ _playing = Audio::makeMP3Stream(s, DisposeAfterUse::YES);
+ else if (pathName.hasSuffixIgnoreCase(".it"))
+ _playing = nullptr;
+ else
+ error("Unknown sound file");
+
+ return true;
+}
+
+void Music::playMid(Type music) {
+ if (!_functional || !_on)
+ return;
+
+ // loaded a new piece of music
+ if (load(music)) {
+ stopMid();
+ g_ultima->_mixer->playStream(Audio::Mixer::kMusicSoundType, &_soundHandle, _playing,
+ -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::YES);
+ }
+}
+
+void Music::stopMid() {
+ g_ultima->_mixer->stopHandle(_soundHandle);
+}
+
+void Music::setSoundVolume_sys(int volume) {
+ uint vol = 255 * volume / MAX_VOLUME;
+ g_ultima->_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, vol);
+}
+
+bool Music::isPlaying_sys() {
+ return g_ultima->_mixer->isSoundHandleActive(_soundHandle);
+}
+
+void Music::setMusicVolume_sys(int volume) {
+ uint vol = 255 * volume / MAX_VOLUME;
+ g_ultima->_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, vol);
+}
+
+void Music::fadeIn_sys(int msecs, bool loadFromMap) {
+#ifdef TODO
+ if (Mix_FadeInMusic(playing, NLOOPS, msecs) == -1)
+ errorWarning("Mix_FadeInMusic: %s\n", Mix_GetError());
+#endif
+}
+
+void Music::fadeOut_sys(int msecs) {
+#ifdef TODO
+ if (Mix_FadeOutMusic(msecs) == -1)
+ errorWarning("Mix_FadeOutMusic: %s\n", Mix_GetError());
+#endif
+}
+
} // End of namespace Ultima4
} // End of namespace Ultima
diff --git a/engines/ultima/ultima4/sound/music.h b/engines/ultima/ultima4/sound/music.h
index 7403a4aa4b..cd4a2ade3c 100644
--- a/engines/ultima/ultima4/sound/music.h
+++ b/engines/ultima/ultima4/sound/music.h
@@ -24,12 +24,12 @@
#define ULTIMA4_MUSIC_H
#include "ultima/shared/std/containers.h"
+#include "audio/audiostream.h"
+#include "audio/mixer.h"
namespace Ultima {
namespace Ultima4 {
-#define musicMgr (Music::getInstance())
-
#define CAMP_FADE_OUT_TIME 1000
#define CAMP_FADE_IN_TIME 0
#define INN_FADE_OUT_TIME 1000
@@ -41,6 +41,8 @@ typedef _Mix_Music OSMusicMixer;
class Music {
public:
+ static bool _functional;
+
enum Type {
NONE,
OUTSIDE,
@@ -55,6 +57,15 @@ public:
MAX
};
+ /*
+ * Properties
+ */
+ Std::vector<Common::String> _filenames;
+ Type _introMid;
+ Type _current;
+ Audio::AudioStream *_playing;
+ Audio::SoundHandle _soundHandle;
+public:
/**
* Initiliaze the music
*/
@@ -65,18 +76,10 @@ public:
*/
~Music();
-
- /** Returns an instance of the Music class */
- static Music *getInstance() {
- if (!instance)
- instance = new Music();
- return instance;
- }
-
- /** Returns true if the mixer is playing any audio. */
- static bool isPlaying() {
- return getInstance()->isPlaying_sys();
- }
+ /**
+ * Returns true if the mixer is playing any audio
+ */
+ static bool isPlaying();
/**
* Ensures that the music is playing if it is supposed to be, or off
@@ -84,14 +87,16 @@ public:
*/
static void callback(void *);
- void init() {}
-
/**
* Main music loop
*/
void play();
+
+ /**
+ * Stop playing music
+ */
void stop() {
- on = false; /**< Stop playing music */
+ _on = false;
stopMid();
}
@@ -104,21 +109,37 @@ public:
* Fade in the music
*/
void fadeIn(int msecs, bool loadFromMap);
+
+ /**
+ * Music when you talk to Lord British
+ */
void lordBritish() {
- playMid(RULEBRIT); /**< Music when you talk to Lord British */
+ playMid(RULEBRIT);
}
+
+ /**
+ * Music when you talk to Hawkwind
+ */
void hawkwind() {
- playMid(SHOPPING); /**< Music when you talk to Hawkwind */
+ playMid(SHOPPING);
}
+
+ /**
+ * Music that plays while camping
+ */
void camp() {
- fadeOut(1000); /**< Music that plays while camping */
+ fadeOut(1000);
}
+
+ /**
+ * Music when talking to a vendor
+ */
void shopping() {
- playMid(SHOPPING); /**< Music when talking to a vendor */
+ playMid(SHOPPING);
}
void intro() {
#ifdef IOS
- on = true; // Force iOS to turn this back on from going in the background.
+ _on = true; // Force iOS to turn this back on from going in the background.
#endif
playMid(_introMid);
}
@@ -144,10 +165,6 @@ public:
setSoundVolume_sys(volume);
}
-
- /*
- * Static variables
- */
private:
void create_sys();
void destroy_sys();
@@ -169,12 +186,12 @@ private:
*/
bool isPlaying_sys();
- static Music *instance;
- static bool fading;
- static bool on;
+ static Music *_instance;
+ static bool _fading;
+ static bool _on;
- bool load_sys(const Common::String &pathname);
+ bool load_sys(const Common::String &pathName);
/**
* Play a midi file
@@ -187,19 +204,10 @@ private:
void stopMid();
bool load(Type music);
-
-public:
- static bool functional;
-
- /*
- * Properties
- */
- Std::vector<Common::String> _filenames;
- Type _introMid;
- Type _current;
- OSMusicMixer *_playing;
};
+extern Music *g_music;
+
} // End of namespace Ultima4
} // End of namespace Ultima
diff --git a/engines/ultima/ultima4/sound/music_scummvm.cpp b/engines/ultima/ultima4/sound/music_scummvm.cpp
deleted file mode 100644
index a8447200db..0000000000
--- a/engines/ultima/ultima4/sound/music_scummvm.cpp
+++ /dev/null
@@ -1,162 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#include "ultima/ultima4/sound/music.h"
-#include "ultima/ultima4/sound/sound.h"
-#include "ultima/ultima4/core/error.h"
-#include "ultima/ultima4/core/config.h"
-#include "ultima/ultima4/game/context.h"
-#include "ultima/ultima4/core/error.h"
-#include "ultima/ultima4/events/event.h"
-#include "ultima/ultima4/map/location.h"
-#include "ultima/ultima4/core/settings.h"
-#include "ultima/ultima4/ultima4.h"
-#include "ultima/ultima4/filesys/u4file.h"
-
-namespace Ultima {
-namespace Ultima4 {
-
-void Music::create_sys() {
-#ifdef TODO
- /*
- * initialize sound subsystem
- */
- TRACE_LOCAL(*logger, "Initializing SDL sound subsystem");
-
- int audio_rate = 22050;
- Uint16 audio_format = AUDIO_S16LSB; /* 16-bit stereo */
- int audio_channels = 2;
- int audio_buffers = 1024;
-
- if (u4_SDL_InitSubSystem(SDL_INIT_AUDIO) == -1) {
- errorWarning("unable to init SDL audio subsystem: %s",
- SDL_GetError());
- this->functional = false;
- return;
- }
-
- TRACE_LOCAL(*logger, "Opening audio");
-
- if (Mix_OpenAudio(audio_rate, audio_format, audio_channels,
- audio_buffers)) {
- fprintf(stderr, "Unable to open audio!\n");
- this->functional = false;
- return;
- }
- this->functional = true;
- TRACE_LOCAL(*logger, "Allocating channels");
-
- Mix_AllocateChannels(16);
-#endif
-}
-
-void Music::destroy_sys() {
-#ifdef TODO
- if (playing) {
- TRACE_LOCAL(*logger, "Stopping currently playing music");
- Mix_FreeMusic(playing);
- playing = NULL;
- }
-
- TRACE_LOCAL(*logger, "Closing audio");
- Mix_CloseAudio();
-
- TRACE_LOCAL(*logger, "Quitting SDL audio subsystem");
- u4_SDL_QuitSubSystem(SDL_INIT_AUDIO);
-#endif
-}
-
-bool Music::load_sys(const Common::String &pathname) {
-#ifdef TODO
- if (playing) {
- Mix_FreeMusic(playing);
- playing = NULL;
- }
-
- playing = Mix_LoadMUS(pathname.c_str());
- if (!playing) {
- errorWarning("unable to load music file %s: %s", pathname.c_str(),
- Mix_GetError());
- return false;
- }
-#endif
- return true;
-}
-
-void Music::playMid(Type music) {
-#ifdef TODO
- if (!functional || !on)
- return;
-
- /* loaded a new piece of music */
- if (load(music)) {
- Mix_PlayMusic(playing, NLOOPS);
- //Mix_SetMusicPosition(0.0); //Could be useful if music was stored on different 'it/mod' patterns
- }
-#endif
-}
-
-void Music::stopMid() {
-#ifdef TODO
- Mix_HaltMusic();
-#endif
-}
-
-void Music::setSoundVolume_sys(int volume) {
-#ifdef TODO
- /**
- * Use Channel 1 for sound effects
- */
- Mix_Volume(1, int((float)MIX_MAX_VOLUME / MAX_VOLUME * volume));
-#endif
-}
-
-bool Music::isPlaying_sys() {
-#ifdef TODO
- return Mix_PlayingMusic();
-#else
- return false;
-#endif
-} /**< Returns true if the mixer is playing any audio */
-
-void Music::setMusicVolume_sys(int volume) {
-#ifdef TODO
- Mix_VolumeMusic(int((float)MIX_MAX_VOLUME / MAX_VOLUME * volume));
-#endif
-}
-
-void Music::fadeIn_sys(int msecs, bool loadFromMap) {
-#ifdef TODO
- if (Mix_FadeInMusic(playing, NLOOPS, msecs) == -1)
- errorWarning("Mix_FadeInMusic: %s\n", Mix_GetError());
-#endif
-}
-
-void Music::fadeOut_sys(int msecs) {
-#ifdef TODO
- if (Mix_FadeOutMusic(msecs) == -1)
- errorWarning("Mix_FadeOutMusic: %s\n", Mix_GetError());
-#endif
-}
-
-} // End of namespace Ultima4
-} // End of namespace Ultima
diff --git a/engines/ultima/ultima4/sound/sound.cpp b/engines/ultima/ultima4/sound/sound.cpp
index d7eee91af8..091be475b4 100644
--- a/engines/ultima/ultima4/sound/sound.cpp
+++ b/engines/ultima/ultima4/sound/sound.cpp
@@ -91,7 +91,7 @@ bool SoundManager::load(Sound sound) {
ASSERT(sound < SOUND_MAX, "Attempted to load an invalid sound in soundLoad()");
// If music didn't initialize correctly, then we can't play it anyway
- if (!Music::functional || !settings._soundVol)
+ if (!Music::_functional || !settings._soundVol)
return false;
if (_soundChunk[sound] == NULL) {
@@ -108,7 +108,7 @@ void SoundManager::play(Sound sound, bool onlyOnce, int specificDurationInTicks)
ASSERT(sound < SOUND_MAX, "Attempted to play an invalid sound in soundPlay()");
// If music didn't initialize correctly, then we can't play it anyway
- if (!Music::functional || !settings._soundVol)
+ if (!Music::_functional || !settings._soundVol)
return;
if (_soundChunk[sound] == NULL) {
diff --git a/engines/ultima/ultima4/sound/sound_scummvm.cpp b/engines/ultima/ultima4/sound/sound_scummvm.cpp
index 9ab1160ee8..37ccf1f07d 100644
--- a/engines/ultima/ultima4/sound/sound_scummvm.cpp
+++ b/engines/ultima/ultima4/sound/sound_scummvm.cpp
@@ -57,7 +57,7 @@ void SoundManager::play_sys(Sound sound, bool onlyOnce, int specificDurationInTi
void SoundManager::stop_sys(int channel) {
#ifdef TODO
// If music didn't initialize correctly, then we shouldn't try to stop it
- if (!musicMgr->functional || !settings.soundVol)
+ if (!g_music->functional || !settings.soundVol)
return;
if (Mix_Playing(channel))
diff --git a/engines/ultima/ultima4/ultima4.cpp b/engines/ultima/ultima4/ultima4.cpp
index b1025bc6b1..0169e85114 100644
--- a/engines/ultima/ultima4/ultima4.cpp
+++ b/engines/ultima/ultima4/ultima4.cpp
@@ -48,8 +48,8 @@ Ultima4Engine *g_ultima;
Ultima4Engine::Ultima4Engine(OSystem *syst, const Ultima::UltimaGameDescription *gameDesc) :
Shared::UltimaEngine(syst, gameDesc), _saveSlotToLoad(-1), _config(nullptr),
- _context(nullptr), _dialogueLoaders(nullptr), _game(nullptr), _imageLoaders(nullptr),
- _saveGame(nullptr), _screen(nullptr) {
+ _context(nullptr), _dialogueLoaders(nullptr), _game(nullptr), _music(nullptr),
+ _imageLoaders(nullptr), _saveGame(nullptr), _screen(nullptr) {
g_ultima = this;
g_context = nullptr;
g_game = nullptr;
@@ -62,13 +62,14 @@ Ultima4Engine::~Ultima4Engine() {
delete _dialogueLoaders;
delete _game;
delete _imageLoaders;
+ delete _music;
delete _saveGame;
delete _screen;
Tileset::unloadAll();
ImageMgr::destroy();
- //delete musicMgr;
+ //delete g_music;
soundDelete();
}
@@ -83,6 +84,7 @@ bool Ultima4Engine::initialize() {
_screen = new Screen();
_game = new GameController();
_imageLoaders = new ImageLoaders();
+ _music = new Music();
_saveGame = new SaveGame();
_screen->init();
@@ -105,8 +107,6 @@ void Ultima4Engine::startup() {
intro->init();
intro->preloadMap();
- musicMgr->init();
-
eventHandler->pushController(intro);
eventHandler->run();
eventHandler->popController();
diff --git a/engines/ultima/ultima4/ultima4.h b/engines/ultima/ultima4/ultima4.h
index 74f33619d3..7595737a90 100644
--- a/engines/ultima/ultima4/ultima4.h
+++ b/engines/ultima/ultima4/ultima4.h
@@ -33,6 +33,7 @@ class Context;
class DialogueLoaders;
class ImageLoaders;
class GameController;
+class Music;
struct SaveGame;
class Screen;
@@ -57,6 +58,7 @@ public:
DialogueLoaders *_dialogueLoaders;
ImageLoaders *_imageLoaders;
GameController *_game;
+ Music *_music;
SaveGame *_saveGame;
Screen *_screen;
public:
More information about the Scummvm-git-logs
mailing list