some cleanup; clarified isSoundInUse semantics and the difference between IMuse::get_sound_active and IMuse::getSoundStatus; added lots of const qualifiers to IMuse; rewrote IMuseInternal::getSoundStatus (hopefully not breaking it); added MusicEngine::getSoundStatus
svn-id: r10069
This commit is contained in:
parent
38402315d5
commit
361c3b95d5
15 changed files with 97 additions and 100 deletions
|
@ -424,25 +424,23 @@ Part *IMuseInternal::allocate_part(byte pri, MidiDriver *midi) {
|
|||
return best;
|
||||
}
|
||||
|
||||
int IMuseInternal::getSoundStatus(int sound, bool ignoreFadeouts) {
|
||||
Player *player;
|
||||
if (sound == -1) {
|
||||
player = _players;
|
||||
for (int i = ARRAYSIZE(_players); i; --i, ++player) {
|
||||
if (player->isActive() &&(!ignoreFadeouts || !player->isFadingOut()))
|
||||
return player->getID();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int IMuseInternal::getSoundStatus(int sound, bool ignoreFadeouts) const {
|
||||
int i;
|
||||
const Player *player = _players;
|
||||
|
||||
player = findActivePlayer(sound);
|
||||
if (player &&(!ignoreFadeouts || !player->isFadingOut()))
|
||||
return 1;
|
||||
return get_queue_sound_status(sound);
|
||||
for (i = ARRAYSIZE(_players); i != 0; i--, player++) {
|
||||
if (player->isActive() && (!ignoreFadeouts || !player->isFadingOut())) {
|
||||
if (sound == -1)
|
||||
return player->getID();
|
||||
else if (player->getID() == (uint16)sound)
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return (sound == -1) ? 0 : get_queue_sound_status(sound);
|
||||
}
|
||||
|
||||
int IMuseInternal::get_queue_sound_status(int sound) {
|
||||
uint16 *a;
|
||||
int IMuseInternal::get_queue_sound_status(int sound) const {
|
||||
const uint16 *a;
|
||||
int i, j;
|
||||
|
||||
j = _queue_pos;
|
||||
|
@ -1049,9 +1047,9 @@ int HookDatas::set(byte cls, byte value, byte chan) {
|
|||
|
||||
Player *IMuseInternal::findActivePlayer(int id) {
|
||||
int i;
|
||||
Player *player;
|
||||
Player *player = _players;
|
||||
|
||||
for (i = ARRAYSIZE(_players), player = _players; i != 0; i--, player++) {
|
||||
for (i = ARRAYSIZE(_players); i != 0; i--, player++) {
|
||||
if (player->isActive() && player->getID() == (uint16)id)
|
||||
return player;
|
||||
}
|
||||
|
@ -1746,8 +1744,8 @@ void IMuseInternal::copyGlobalAdlibInstrument(byte slot, Instrument *dest) {
|
|||
|
||||
IMuse::IMuse(OSystem *system, IMuseInternal *target) : _system(system), _target(target) { _mutex = system->create_mutex(); }
|
||||
IMuse::~IMuse() { if (_mutex) _system->delete_mutex(_mutex); if (_target) delete _target; }
|
||||
inline void IMuse::in() { _system->lock_mutex(_mutex); }
|
||||
inline void IMuse::out() { _system->unlock_mutex(_mutex); }
|
||||
inline void IMuse::in() const { _system->lock_mutex(_mutex); }
|
||||
inline void IMuse::out() const { _system->unlock_mutex(_mutex); }
|
||||
|
||||
void IMuse::on_timer(MidiDriver *midi) { in(); _target->on_timer(midi); out(); }
|
||||
void IMuse::pause(bool paused) { in(); _target->pause(paused); out(); }
|
||||
|
@ -1759,8 +1757,8 @@ int IMuse::get_master_volume() { in(); int ret = _target->get_master_volume(); o
|
|||
void IMuse::startSound(int sound) { in(); _target->startSound(sound); out(); }
|
||||
void IMuse::stopSound(int sound) { in(); _target->stopSound(sound); out(); }
|
||||
int IMuse::stopAllSounds() { in(); int ret = _target->stopAllSounds(); out(); return ret; }
|
||||
int IMuse::getSoundStatus(int sound) { in(); int ret = _target->getSoundStatus(sound, true); out(); return ret; }
|
||||
bool IMuse::get_sound_active(int sound) { in(); bool ret = _target->getSoundStatus(sound, false) ? 1 : 0; out(); return ret; }
|
||||
int IMuse::getSoundStatus(int sound) const { in(); int ret = _target->getSoundStatus(sound, true); out(); return ret; }
|
||||
bool IMuse::get_sound_active(int sound) const { in(); bool ret = _target->getSoundStatus(sound, false) ? 1 : 0; out(); return ret; }
|
||||
int IMuse::getMusicTimer() { in(); int ret = _target->getMusicTimer(); out(); return ret; }
|
||||
int32 IMuse::doCommand (int a, int b, int c, int d, int e, int f, int g, int h) { in(); int32 ret = _target->doCommand(a,b,c,d,e,f,g,h); out(); return ret; }
|
||||
int32 IMuse::doCommand (int numargs, int args[]) { in(); int32 ret = _target->doCommand (numargs, args); out(); return ret; }
|
||||
|
|
|
@ -38,11 +38,11 @@ class IMuse : public MusicEngine {
|
|||
private:
|
||||
OSystem *_system;
|
||||
IMuseInternal *_target;
|
||||
OSystem::MutexRef _mutex;
|
||||
mutable OSystem::MutexRef _mutex;
|
||||
|
||||
IMuse(OSystem *system, IMuseInternal *target);
|
||||
void in();
|
||||
void out();
|
||||
void in() const;
|
||||
void out() const;
|
||||
|
||||
public:
|
||||
~IMuse();
|
||||
|
@ -66,8 +66,8 @@ public:
|
|||
void startSound(int sound);
|
||||
void stopSound(int sound);
|
||||
int stopAllSounds();
|
||||
int getSoundStatus(int sound);
|
||||
bool get_sound_active(int sound);
|
||||
int getSoundStatus(int sound) const;
|
||||
bool get_sound_active(int sound) const;
|
||||
int getMusicTimer();
|
||||
int32 doCommand (int a, int b, int c, int d, int e, int f, int g, int h);
|
||||
int32 doCommand (int numargs, int args[]);
|
||||
|
|
|
@ -1164,15 +1164,15 @@ int32 IMuseDigital::doCommand(int a, int b, int c, int d, int e, int f, int g, i
|
|||
}
|
||||
}
|
||||
|
||||
bool IMuseDigital::getSoundStatus(int sound) {
|
||||
int IMuseDigital::getSoundStatus(int sound) const {
|
||||
debug(5, "IMuseDigital::getSoundStatus(%d)", sound);
|
||||
for (int l = 0; l < MAX_DIGITAL_CHANNELS; l++) {
|
||||
if ((_channel[l]._idSound == sound) && _channel[l]._used) {
|
||||
return true;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -72,7 +72,7 @@ public:
|
|||
void stopAll();
|
||||
void pause(bool pause);
|
||||
int32 doCommand(int a, int b, int c, int d, int e, int f, int g, int h);
|
||||
bool getSoundStatus(int sound);
|
||||
int getSoundStatus(int sound) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -232,21 +232,21 @@ public:
|
|||
void fixAfterLoad();
|
||||
Part * getActivePart(uint8 part);
|
||||
uint getBeatIndex();
|
||||
int8 getDetune() { return _detune; }
|
||||
byte getEffectiveVolume() { return _vol_eff; }
|
||||
int getID() { return _id; }
|
||||
MidiDriver *getMidiDriver() { return _midi; }
|
||||
int8 getDetune() const { return _detune; }
|
||||
byte getEffectiveVolume() const { return _vol_eff; }
|
||||
int getID() const { return _id; }
|
||||
MidiDriver *getMidiDriver() const { return _midi; }
|
||||
int getParam(int param, byte chan);
|
||||
int8 getPan() { return _pan; }
|
||||
int8 getPan() const { return _pan; }
|
||||
Part * getPart(uint8 part);
|
||||
byte getPriority() { return _priority; }
|
||||
uint getTicksPerBeat() { return TICKS_PER_BEAT; }
|
||||
int8 getTranspose() { return _transpose; }
|
||||
byte getVolume() { return _volume; }
|
||||
bool isActive() { return _active; }
|
||||
bool isFadingOut();
|
||||
bool isGM() { return _isGM; }
|
||||
bool isMT32() { return _isMT32; }
|
||||
byte getPriority() const { return _priority; }
|
||||
uint getTicksPerBeat() const { return TICKS_PER_BEAT; }
|
||||
int8 getTranspose() const { return _transpose; }
|
||||
byte getVolume() const { return _volume; }
|
||||
bool isActive() const { return _active; }
|
||||
bool isFadingOut() const;
|
||||
bool isGM() const { return _isGM; }
|
||||
bool isMT32() const { return _isMT32; }
|
||||
bool jump(uint track, uint beat, uint tick);
|
||||
void onTimer();
|
||||
void removePart(Part *part);
|
||||
|
@ -397,7 +397,7 @@ protected:
|
|||
byte *findStartOfSound(int sound);
|
||||
bool isMT32(int sound);
|
||||
bool isGM(int sound);
|
||||
int get_queue_sound_status(int sound);
|
||||
int get_queue_sound_status(int sound) const;
|
||||
void handle_marker(uint id, byte data);
|
||||
int get_channel_volume(uint a);
|
||||
void initMidiDriver(MidiDriver *midi);
|
||||
|
@ -462,7 +462,7 @@ public:
|
|||
bool startSound(int sound);
|
||||
int stopSound(int sound);
|
||||
int stopAllSounds();
|
||||
int getSoundStatus(int sound, bool ignoreFadeouts = true);
|
||||
int getSoundStatus(int sound, bool ignoreFadeouts = true) const;
|
||||
int getMusicTimer();
|
||||
int32 doCommand (int a, int b, int c, int d, int e, int f, int g, int h);
|
||||
int32 doCommand (int numargs, int args[]);
|
||||
|
|
|
@ -132,7 +132,7 @@ int Player::getMusicTimer() {
|
|||
return _parser ? (_parser->getTick() * 2 / _parser->getPPQN()) : 0;
|
||||
}
|
||||
|
||||
bool Player::isFadingOut() {
|
||||
bool Player::isFadingOut() const {
|
||||
int i;
|
||||
for (i = 0; i < ARRAYSIZE(_parameterFaders); ++i) {
|
||||
if (_parameterFaders[i].param == ParameterFader::pfVolume &&
|
||||
|
|
|
@ -33,7 +33,7 @@ public:
|
|||
virtual void startSound(int sound) = 0;
|
||||
virtual void stopSound(int sound) = 0;
|
||||
// virtual void stopAllSounds() = 0;
|
||||
// virtual bool getSoundStatus(int sound) const = 0;
|
||||
virtual int getSoundStatus(int sound) const = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -58,7 +58,7 @@ protected:
|
|||
void clear_channel(int i);
|
||||
void chainSound(int nr, byte *data);
|
||||
|
||||
void do_mix (int16 *buf, uint len);
|
||||
void do_mix(int16 *buf, uint len);
|
||||
|
||||
void set_mplex(uint mplex);
|
||||
void parseSpeakerChunk();
|
||||
|
|
|
@ -522,7 +522,7 @@ void Player_V2::startSound(int nr) {
|
|||
mutex_down();
|
||||
}
|
||||
|
||||
bool Player_V2::getSoundStatus(int nr) const {
|
||||
int Player_V2::getSoundStatus(int nr) const {
|
||||
return _current_nr == nr || _next_nr == nr;
|
||||
}
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ public:
|
|||
virtual void startSound(int nr);
|
||||
virtual void stopSound(int nr);
|
||||
virtual void stopAllSounds();
|
||||
virtual bool getSoundStatus(int nr) const;
|
||||
virtual int getSoundStatus(int nr) const;
|
||||
virtual int getMusicTimer() const;
|
||||
|
||||
protected:
|
||||
|
|
|
@ -294,11 +294,11 @@ int Player_V3A::getMusicTimer() const {
|
|||
return _music_timer / 30;
|
||||
}
|
||||
|
||||
bool Player_V3A::getSoundStatus(int nr) const {
|
||||
int Player_V3A::getSoundStatus(int nr) const {
|
||||
if (nr == _curSong)
|
||||
return true;
|
||||
return 1;
|
||||
for (int i = 0; i < V3A_MAXCHANS; i++)
|
||||
if (_soundID[i] == nr)
|
||||
return true;
|
||||
return false;
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ public:
|
|||
virtual int getMusicTimer() const;
|
||||
|
||||
virtual void playMusic();
|
||||
virtual bool getSoundStatus(int nr) const;
|
||||
virtual int getSoundStatus(int nr) const;
|
||||
|
||||
protected:
|
||||
SoundMixer *_mixer;
|
||||
|
|
|
@ -1760,7 +1760,7 @@ bool Scumm::isResourceInUse(int type, int i) const {
|
|||
case rtCostume:
|
||||
return isCostumeInUse(i);
|
||||
case rtSound:
|
||||
return _sound->isSoundActive(i);
|
||||
return _sound->isSoundInUse(i);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -179,20 +179,30 @@ void Sound::playSound(int soundID) {
|
|||
debug(3, "playSound #%d (room %d)", soundID, _scumm->getResourceRoomNr(rtSound, soundID));
|
||||
ptr = _scumm->getResourceAddress(rtSound, soundID);
|
||||
if (!ptr) {
|
||||
// FIXME: Should we replace this by an assert, and/or print an error message?
|
||||
return;
|
||||
}
|
||||
|
||||
if (READ_UINT32(ptr) == MKID('iMUS')){
|
||||
assert(_scumm->_imuseDigital);
|
||||
_scumm->_imuseDigital->startSound(soundID);
|
||||
assert(_scumm->_musicEngine);
|
||||
_scumm->_musicEngine->startSound(soundID);
|
||||
return;
|
||||
}
|
||||
else if (READ_UINT32(ptr) == MKID('Crea')) {
|
||||
assert(_scumm->_imuseDigital);
|
||||
_scumm->_imuseDigital->startSound(soundID);
|
||||
assert(_scumm->_musicEngine);
|
||||
_scumm->_musicEngine->startSound(soundID);
|
||||
return;
|
||||
}
|
||||
/*
|
||||
// XMIDI
|
||||
else if ((READ_UINT32(ptr) == MKID('MIDI')) && (_scumm->_features & GF_HUMONGOUS)) {
|
||||
// Pass XMIDI on to IMuse unprocessed.
|
||||
// IMuse can handle XMIDI resources now.
|
||||
}
|
||||
else if (READ_UINT32(ptr) == MKID('ADL ')) {
|
||||
// played as MIDI, just to make perhaps the later use
|
||||
// of WA possible (see "else if" with GF_OLD256 below)
|
||||
}
|
||||
*/
|
||||
else if (READ_UINT32(ptr) == MKID('SOUN')) {
|
||||
ptr += 24;
|
||||
int track = ptr[0];
|
||||
|
@ -258,17 +268,6 @@ void Sound::playSound(int soundID) {
|
|||
|
||||
return;
|
||||
}
|
||||
/*
|
||||
// XMIDI
|
||||
else if ((READ_UINT32(ptr) == MKID('MIDI')) && (_scumm->_features & GF_HUMONGOUS)) {
|
||||
// Pass XMIDI on to IMuse unprocessed.
|
||||
// IMuse can handle XMIDI resources now.
|
||||
}
|
||||
else if (READ_UINT32(ptr) == MKID('ADL ')) {
|
||||
// played as MIDI, just to make perhaps the later use
|
||||
// of WA possible (see "else if" with GF_OLD256 below)
|
||||
}
|
||||
*/
|
||||
// Support for sampled sound effects in Monkey Island 1 and 2
|
||||
else if (READ_UINT32(ptr) == MKID('SBL ')) {
|
||||
debug(2, "Using SBL sound effect");
|
||||
|
@ -645,7 +644,6 @@ bool Sound::isMouthSyncOff(uint pos) {
|
|||
|
||||
|
||||
int Sound::isSoundRunning(int sound) const {
|
||||
int i;
|
||||
|
||||
if (sound == _currentCDSound)
|
||||
return pollCD();
|
||||
|
@ -661,12 +659,6 @@ int Sound::isSoundRunning(int sound) const {
|
|||
}
|
||||
}
|
||||
|
||||
i = _soundQue2Pos;
|
||||
while (i--) {
|
||||
if (_soundQue2[i] == sound)
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (isSoundInQueue(sound))
|
||||
return 1;
|
||||
|
||||
|
@ -688,41 +680,48 @@ int Sound::isSoundRunning(int sound) const {
|
|||
return 0;
|
||||
}
|
||||
|
||||
// This is exactly the same as isSoundRunning except that it
|
||||
// calls IMuse::get_sound_active() instead of IMuse::getSoundStatus().
|
||||
// This is necessary when determining what resources to
|
||||
// expire from memory.
|
||||
bool Sound::isSoundActive(int sound) const {
|
||||
int i;
|
||||
/**
|
||||
* Check whether the sound resource with the specified ID is still
|
||||
* used. This is invoked by Scumm::isResourceInUse, to determine
|
||||
* which resources can be expired from memory.
|
||||
* Technically, this works very similar to isSoundRunning, however it
|
||||
* calls IMuse::get_sound_active() instead of IMuse::getSoundStatus().
|
||||
* The difference between those two is in how they treat sounds which
|
||||
* are being faded out: get_sound_active() returns true even when the
|
||||
* sound is being faded out, while getSoundStatus() returns false in
|
||||
* that case.
|
||||
*/
|
||||
bool Sound::isSoundInUse(int sound) const {
|
||||
|
||||
if (sound == _currentCDSound)
|
||||
return pollCD() != 0;
|
||||
|
||||
i = _soundQue2Pos;
|
||||
while (i--) {
|
||||
if (_soundQue2[i] == sound)
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isSoundInQueue(sound))
|
||||
return true;
|
||||
|
||||
if (!_scumm->isResourceLoaded(rtSound, sound))
|
||||
return false;
|
||||
|
||||
if (_scumm->_imuseDigital) {
|
||||
return _scumm->_imuseDigital->getSoundStatus(sound) != 0;
|
||||
}
|
||||
if (_scumm->_imuseDigital)
|
||||
return _scumm->_imuseDigital->getSoundStatus(sound);
|
||||
|
||||
if (!_scumm->_imuse)
|
||||
return false;
|
||||
return _scumm->_imuse->get_sound_active(sound);
|
||||
if (_scumm->_imuse)
|
||||
return _scumm->_imuse->get_sound_active(sound);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Sound::isSoundInQueue(int sound) const {
|
||||
int i = 0, j, num;
|
||||
int i, j, num;
|
||||
int16 table[16];
|
||||
|
||||
i = _soundQue2Pos;
|
||||
while (i--) {
|
||||
if (_soundQue2[i] == sound)
|
||||
return 1;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while (i < _soundQuePos) {
|
||||
num = _soundQue[i++];
|
||||
|
||||
|
|
|
@ -125,7 +125,7 @@ public:
|
|||
void stopTalkSound();
|
||||
bool isMouthSyncOff(uint pos);
|
||||
int isSoundRunning(int sound) const;
|
||||
bool isSoundActive(int sound) const;
|
||||
bool isSoundInUse(int sound) const;
|
||||
bool isSoundInQueue(int sound) const;
|
||||
void stopSound(int a);
|
||||
void stopAllSounds();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue