diff options
Diffstat (limited to 'backends/audiocd/default/default-audiocd.cpp')
| -rw-r--r-- | backends/audiocd/default/default-audiocd.cpp | 93 | 
1 files changed, 52 insertions, 41 deletions
diff --git a/backends/audiocd/default/default-audiocd.cpp b/backends/audiocd/default/default-audiocd.cpp index abf80ac4cd..c2ce7cedcc 100644 --- a/backends/audiocd/default/default-audiocd.cpp +++ b/backends/audiocd/default/default-audiocd.cpp @@ -22,6 +22,7 @@  #include "backends/audiocd/default/default-audiocd.h"  #include "audio/audiostream.h" +#include "common/config-manager.h"  #include "common/system.h"  DefaultAudioCDManager::DefaultAudioCDManager() { @@ -37,7 +38,25 @@ DefaultAudioCDManager::DefaultAudioCDManager() {  	assert(_mixer);  } -void DefaultAudioCDManager::play(int track, int numLoops, int startFrame, int duration, bool only_emulate) { +DefaultAudioCDManager::~DefaultAudioCDManager() { +	// Subclasses should call close as well +	close(); +} + +bool DefaultAudioCDManager::open() { +	// For emulation, opening is always valid +	close(); +	return true; +} + +void DefaultAudioCDManager::close() { +	// Only need to stop for emulation +	stop(); +} + +bool DefaultAudioCDManager::play(int track, int numLoops, int startFrame, int duration, bool onlyEmulate) { +	stop(); +  	if (numLoops != 0 || startFrame != 0) {  		_cd.track = track;  		_cd.numLoops = numLoops; @@ -55,9 +74,6 @@ void DefaultAudioCDManager::play(int track, int numLoops, int startFrame, int du  		for (int i = 0; !stream && i < 2; ++i)  			stream = Audio::SeekableAudioStream::openStreamFile(trackName[i]); -		// Stop any currently playing emulated track -		_mixer->stopHandle(_handle); -  		if (stream != 0) {  			Audio::Timestamp start = Audio::Timestamp(0, startFrame, 75);  			Audio::Timestamp end = duration ? Audio::Timestamp(0, startFrame + duration, 75) : stream->getLength(); @@ -70,12 +86,11 @@ void DefaultAudioCDManager::play(int track, int numLoops, int startFrame, int du  			_emulating = true;  			_mixer->playStream(Audio::Mixer::kMusicSoundType, &_handle,  			                        Audio::makeLoopingAudioStream(stream, start, end, (numLoops < 1) ? numLoops + 1 : numLoops), -1, _cd.volume, _cd.balance); -		} else { -			_emulating = false; -			if (!only_emulate) -				playCD(track, numLoops, startFrame, duration); +			return true;  		}  	} + +	return false;  }  void DefaultAudioCDManager::stop() { @@ -83,52 +98,32 @@ void DefaultAudioCDManager::stop() {  		// Audio CD emulation  		_mixer->stopHandle(_handle);  		_emulating = false; -	} else { -		// Real Audio CD -		stopCD();  	}  }  bool DefaultAudioCDManager::isPlaying() const { -	if (_emulating) { -		// Audio CD emulation +	// Audio CD emulation +	if (_emulating)  		return _mixer->isSoundHandleActive(_handle); -	} else { -		// Real Audio CD -		return pollCD(); -	} + +	// The default class only handles emulation +	return false;  }  void DefaultAudioCDManager::setVolume(byte volume) {  	_cd.volume = volume; -	if (_emulating) { -		// Audio CD emulation -		if (_mixer->isSoundHandleActive(_handle)) -			_mixer->setChannelVolume(_handle, _cd.volume); -	} else { -		// Real Audio CD -		// Unfortunately I can't implement this atm -		// since SDL doesn't seem to offer an interface method for this. - -		// g_system->setVolumeCD(_cd.volume); -	} +	// Audio CD emulation +	if (_emulating && isPlaying()) +		_mixer->setChannelVolume(_handle, _cd.volume);  }  void DefaultAudioCDManager::setBalance(int8 balance) {  	_cd.balance = balance; -	if (_emulating) { -		// Audio CD emulation -		if (isPlaying()) -			_mixer->setChannelBalance(_handle, _cd.balance); -	} else { -		// Real Audio CD -		// Unfortunately I can't implement this atm -		// since SDL doesn't seem to offer an interface method for this. - -		// g_system->setBalanceCD(_cd.balance); -	} +	// Audio CD emulation +	if (_emulating && isPlaying()) +		_mixer->setChannelBalance(_handle, _cd.balance);  }  void DefaultAudioCDManager::update() { @@ -142,8 +137,6 @@ void DefaultAudioCDManager::update() {  			// or not.  			_emulating = false;  		} -	} else { -		updateCD();  	}  } @@ -152,3 +145,21 @@ DefaultAudioCDManager::Status DefaultAudioCDManager::getStatus() const {  	info.playing = isPlaying();  	return info;  } + +bool DefaultAudioCDManager::openRealCD() { +	Common::String cdrom = ConfMan.get("cdrom"); + +	// Try to parse it as an int +	char *endPos; +	int drive = strtol(cdrom.c_str(), &endPos, 0); + +	// If not an integer, treat as a drive path +	if (endPos == cdrom.c_str()) +		return openCD(cdrom); + +	if (drive < 0) +		return false; + +	return openCD(drive); +} +  | 
