[Scummvm-cvs-logs] scummvm master -> 47c7e39bca80a5249288fac5c5da4a44d552e763

dreammaster dreammaster at scummvm.org
Thu Aug 11 05:10:54 CEST 2016


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:
47c7e39bca TITANIC: Add music handler stopping code


Commit: 47c7e39bca80a5249288fac5c5da4a44d552e763
    https://github.com/scummvm/scummvm/commit/47c7e39bca80a5249288fac5c5da4a44d552e763
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2016-08-10T23:10:46-04:00

Commit Message:
TITANIC: Add music handler stopping code

Changed paths:
    engines/titanic/sound/music_handler.cpp
    engines/titanic/sound/music_handler.h
    engines/titanic/sound/music_player.cpp
    engines/titanic/sound/music_player.h
    engines/titanic/sound/music_room.cpp
    engines/titanic/sound/music_wave.cpp
    engines/titanic/sound/music_wave.h



diff --git a/engines/titanic/sound/music_handler.cpp b/engines/titanic/sound/music_handler.cpp
index 9ef5ffa..037c340 100644
--- a/engines/titanic/sound/music_handler.cpp
+++ b/engines/titanic/sound/music_handler.cpp
@@ -27,11 +27,15 @@
 namespace Titanic {
 
 CMusicHandler::CMusicHandler(CProjectItem *project, CSoundManager *soundManager) :
-		_project(project), _soundManager(soundManager),
-		_field124(0) {
+		_project(project), _soundManager(soundManager), _stopWaves(false),
+		_soundHandle(-1), _waveFile(nullptr) {
 	Common::fill(&_musicWaves[0], &_musicWaves[4], (CMusicWave *)nullptr);
 }
 
+CMusicHandler::~CMusicHandler() {
+	stop();
+}
+
 CMusicWave *CMusicHandler::createMusicWave(int waveIndex, int count) {
 	switch (waveIndex) {
 	case 0:
@@ -59,4 +63,18 @@ bool CMusicHandler::isBusy() {
 	return false;
 }
 
+void CMusicHandler::stop() {
+	if (_waveFile) {
+		_soundManager->stopSound(_soundHandle);
+		delete _waveFile;
+		_waveFile = nullptr;
+		_soundHandle = -1;
+	}
+
+	for (int idx = 0; idx < 4; ++idx) {
+		if (_stopWaves && _musicWaves[idx])
+			_musicWaves[idx]->stop();
+	}
+}
+
 } // End of namespace Titanic
diff --git a/engines/titanic/sound/music_handler.h b/engines/titanic/sound/music_handler.h
index 7b8ee03..17ffea9 100644
--- a/engines/titanic/sound/music_handler.h
+++ b/engines/titanic/sound/music_handler.h
@@ -24,6 +24,7 @@
 #define TITANIC_MUSIC_HANDLER_H
 
 #include "titanic/sound/music_wave.h"
+#include "titanic/sound/wave_file.h"
 
 namespace Titanic {
 
@@ -35,9 +36,12 @@ private:
 	CProjectItem *_project;
 	CSoundManager *_soundManager;
 	CMusicWave *_musicWaves[4];
-	int _field124;
+	bool _stopWaves;
+	CWaveFile *_waveFile;
+	int _soundHandle;
 public:
 	CMusicHandler(CProjectItem *project, CSoundManager *soundManager);
+	~CMusicHandler();
 
 	/**
 	 * Creates a new music wave class instance, and assigns it to a slot
@@ -49,7 +53,16 @@ public:
 
 	bool isBusy();
 
-	void set124(int val) { _field124 = val; }
+	/**
+	 * Flags whether the loaded music waves will be stopped when the
+	 * music handler is stopped
+	 */
+	void setStopWaves(bool flag) { _stopWaves = flag; }
+
+	/**
+	 * Stop playing the music
+	 */
+	void stop();
 };
 
 } // End of namespace Titanic
diff --git a/engines/titanic/sound/music_player.cpp b/engines/titanic/sound/music_player.cpp
index fb5a596..cd764c7 100644
--- a/engines/titanic/sound/music_player.cpp
+++ b/engines/titanic/sound/music_player.cpp
@@ -39,7 +39,7 @@ void CMusicPlayer::save(SimpleFile *file, int indent) {
 	file->writeNumberLine(1, indent);
 	file->writeNumberLine(_isActive, indent);
 	file->writeQuotedLine(_stopTarget, indent);
-	file->writeNumberLine(_fieldCC, indent);
+	file->writeNumberLine(_stopWaves, indent);
 	file->writeNumberLine(_musicId, indent);
 
 	CGameObject::save(file, indent);
@@ -49,7 +49,7 @@ void CMusicPlayer::load(SimpleFile *file) {
 	file->readNumber();
 	_isActive = file->readNumber();
 	_stopTarget = file->readString();
-	_fieldCC = file->readNumber();
+	_stopWaves = file->readNumber();
 	_musicId = file->readNumber();
 
 	CGameObject::load(file);
@@ -120,7 +120,7 @@ bool CMusicPlayer::LeaveRoomMsg(CLeaveRoomMsg *msg) {
 
 bool CMusicPlayer::CreateMusicPlayerMsg(CCreateMusicPlayerMsg *msg) {
 	if (CMusicRoom::_musicHandler) {
-		CMusicRoom::_musicHandler->set124(_fieldCC);
+		CMusicRoom::_musicHandler->setStopWaves(_stopWaves);
 		return true;
 	}
 
@@ -156,7 +156,7 @@ bool CMusicPlayer::CreateMusicPlayerMsg(CCreateMusicPlayerMsg *msg) {
 		wave->load(5, "z#505.wav", 53);
 		wave->load(6, "z#501.wav", 58);
 
-		CMusicRoom::_musicHandler->set124(_fieldCC);
+		CMusicRoom::_musicHandler->setStopWaves(_stopWaves);
 	}
 
 	return true;
diff --git a/engines/titanic/sound/music_player.h b/engines/titanic/sound/music_player.h
index 3ed1bff..7b82d4d 100644
--- a/engines/titanic/sound/music_player.h
+++ b/engines/titanic/sound/music_player.h
@@ -41,12 +41,12 @@ class CMusicPlayer : public CGameObject {
 protected:
 	bool _isActive;
 	CString _stopTarget;
-	int _fieldCC;
+	bool _stopWaves;
 	int _musicId;
 public:
 	CLASSDEF;
 	CMusicPlayer() : CGameObject(),
-		_isActive(false), _fieldCC(0), _musicId(100) {}
+		_isActive(false), _stopWaves(false), _musicId(100) {}
 
 	/**
 	 * Save the data for the class to file
diff --git a/engines/titanic/sound/music_room.cpp b/engines/titanic/sound/music_room.cpp
index 06cf866..34217de 100644
--- a/engines/titanic/sound/music_room.cpp
+++ b/engines/titanic/sound/music_room.cpp
@@ -58,7 +58,8 @@ void CMusicRoom::startMusic(int musicId) {
 }
 
 void CMusicRoom::stopMusic() {
-	// TODO
+	if (_musicHandler)
+		_musicHandler->stop();
 }
 
 } // End of namespace Titanic
diff --git a/engines/titanic/sound/music_wave.cpp b/engines/titanic/sound/music_wave.cpp
index 753098e..6b5b187 100644
--- a/engines/titanic/sound/music_wave.cpp
+++ b/engines/titanic/sound/music_wave.cpp
@@ -47,4 +47,8 @@ CWaveFile *CMusicWave::createWaveFile(const CString &name) {
 	return _soundManager->loadSound(name);
 }
 
+void CMusicWave::stop() {
+
+}
+
 } // End of namespace Titanic
diff --git a/engines/titanic/sound/music_wave.h b/engines/titanic/sound/music_wave.h
index dcdd361..b240f4a 100644
--- a/engines/titanic/sound/music_wave.h
+++ b/engines/titanic/sound/music_wave.h
@@ -59,6 +59,11 @@ public:
 	 * Loads a new file into the list of available entries
 	 */
 	void load(int index, const CString &filename, int v3);
+
+	/**
+	 * Stops the music
+	 */
+	void stop();
 };
 
 } // End of namespace Titanic






More information about the Scummvm-git-logs mailing list