SCI: Renamed various song/songlib related structs and members

svn-id: r41342
This commit is contained in:
Max Horn 2009-06-07 17:06:32 +00:00
parent 42555118ba
commit f2ca788004
8 changed files with 294 additions and 287 deletions

View file

@ -37,7 +37,7 @@
#include "sci/gfx/gfx_gui.h" // for sciw_set_status_bar #include "sci/gfx/gfx_gui.h" // for sciw_set_status_bar
#include "sci/gfx/gfx_state_internal.h" #include "sci/gfx/gfx_state_internal.h"
#include "sci/gfx/gfx_widgets.h" // for getPort #include "sci/gfx/gfx_widgets.h" // for getPort
#include "sci/sfx/songlib.h" // for songlib_t #include "sci/sfx/songlib.h" // for SongLibrary
#include "sci/sfx/iterator.h" // for SCI_SONG_ITERATOR_TYPE_SCI0 #include "sci/sfx/iterator.h" // for SCI_SONG_ITERATOR_TYPE_SCI0
#include "sci/sfx/sci_midi.h" #include "sci/sfx/sci_midi.h"
#include "sci/vocabulary.h" #include "sci/vocabulary.h"
@ -1530,14 +1530,14 @@ bool Console::cmdShowMap(int argc, const char **argv) {
bool Console::cmdSongLib(int argc, const char **argv) { bool Console::cmdSongLib(int argc, const char **argv) {
DebugPrintf("Song library:\n"); DebugPrintf("Song library:\n");
song_t *seeker = *(g_EngineState->_sound._songlib.lib); Song *seeker = *(g_EngineState->_sound._songlib._lib);
do { do {
DebugPrintf(" %p", (void *)seeker); DebugPrintf(" %p", (void *)seeker);
if (seeker) { if (seeker) {
DebugPrintf("[%04lx,p=%d,s=%d]->", seeker->handle, seeker->priority, seeker->status); DebugPrintf("[%04lx,p=%d,s=%d]->", seeker->_handle, seeker->_priority, seeker->_status);
seeker = seeker->next; seeker = seeker->_next;
} }
DebugPrintf("\n"); DebugPrintf("\n");
} while (seeker); } while (seeker);

View file

@ -151,7 +151,7 @@ SongIterator *build_iterator(EngineState *s, int song_nr, SongIteratorType type,
void process_sound_events(EngineState *s) { /* Get all sound events, apply their changes to the heap */ void process_sound_events(EngineState *s) { /* Get all sound events, apply their changes to the heap */
int result; int result;
song_handle_t handle; SongHandle handle;
int cue; int cue;
if (s->_version >= SCI_VERSION_01) if (s->_version >= SCI_VERSION_01)
@ -204,7 +204,7 @@ void process_sound_events(EngineState *s) { /* Get all sound events, apply their
reg_t kDoSound_SCI0(EngineState *s, int funct_nr, int argc, reg_t *argv) { reg_t kDoSound_SCI0(EngineState *s, int funct_nr, int argc, reg_t *argv) {
reg_t obj = (argc > 1) ? argv[1] : NULL_REG; reg_t obj = (argc > 1) ? argv[1] : NULL_REG;
uint16 command = argv[0].toUint16(); uint16 command = argv[0].toUint16();
song_handle_t handle = FROBNICATE_HANDLE(obj); SongHandle handle = FROBNICATE_HANDLE(obj);
int number = obj.segment ? int number = obj.segment ?
GET_SEL32V(obj, number) : GET_SEL32V(obj, number) :
-1; /* We were not going to use it anyway */ -1; /* We were not going to use it anyway */
@ -383,7 +383,7 @@ reg_t kDoSound_SCI0(EngineState *s, int funct_nr, int argc, reg_t *argv) {
reg_t kDoSound_SCI01(EngineState *s, int funct_nr, int argc, reg_t *argv) { reg_t kDoSound_SCI01(EngineState *s, int funct_nr, int argc, reg_t *argv) {
uint16 command = argv[0].toUint16(); uint16 command = argv[0].toUint16();
reg_t obj = (argc > 1) ? argv[1] : NULL_REG; reg_t obj = (argc > 1) ? argv[1] : NULL_REG;
song_handle_t handle = FROBNICATE_HANDLE(obj); SongHandle handle = FROBNICATE_HANDLE(obj);
int number = obj.segment ? int number = obj.segment ?
GET_SEL32V(obj, number) : GET_SEL32V(obj, number) :
-1; /* We were not going to use it anyway */ -1; /* We were not going to use it anyway */
@ -673,7 +673,7 @@ reg_t kDoSound_SCI01(EngineState *s, int funct_nr, int argc, reg_t *argv) {
reg_t kDoSound_SCI1(EngineState *s, int funct_nr, int argc, reg_t *argv) { reg_t kDoSound_SCI1(EngineState *s, int funct_nr, int argc, reg_t *argv) {
uint16 command = argv[0].toUint16(); uint16 command = argv[0].toUint16();
reg_t obj = (argc > 1) ? argv[1] : NULL_REG; reg_t obj = (argc > 1) ? argv[1] : NULL_REG;
song_handle_t handle = FROBNICATE_HANDLE(obj); SongHandle handle = FROBNICATE_HANDLE(obj);
int number = obj.segment ? int number = obj.segment ?
GET_SEL32V(obj, number) : GET_SEL32V(obj, number) :
-1; /* We were not going to use it anyway */ -1; /* We were not going to use it anyway */
@ -798,9 +798,9 @@ reg_t kDoSound_SCI1(EngineState *s, int funct_nr, int argc, reg_t *argv) {
int looping = GET_SEL32V(obj, loop); int looping = GET_SEL32V(obj, loop);
//int vol = GET_SEL32V(obj, vol); //int vol = GET_SEL32V(obj, vol);
int pri = GET_SEL32V(obj, pri); int pri = GET_SEL32V(obj, pri);
song_t *song = song_lib_find(s->_sound._songlib, handle); Song *song = song_lib_find(s->_sound._songlib, handle);
if (GET_SEL32V(obj, nodePtr) && (song && number != song->resource_num)) { if (GET_SEL32V(obj, nodePtr) && (song && number != song->_resourceNum)) {
s->_sound.sfx_song_set_status(handle, SOUND_STATUS_STOPPED); s->_sound.sfx_song_set_status(handle, SOUND_STATUS_STOPPED);
s->_sound.sfx_remove_song(handle); s->_sound.sfx_remove_song(handle);
PUT_SEL32(obj, nodePtr, NULL_REG); PUT_SEL32(obj, nodePtr, NULL_REG);

View file

@ -52,7 +52,7 @@ SongIterator *build_iterator(EngineState *s, int song_nr, SongIteratorType type,
// of the classes they are syncing. // of the classes they are syncing.
static void sync_MemObjPtr(Common::Serializer &s, MemObject *&obj); static void sync_MemObjPtr(Common::Serializer &s, MemObject *&obj);
static void sync_songlib_t(Common::Serializer &s, songlib_t &obj); static void sync_songlib_t(Common::Serializer &s, SongLibrary &obj);
static void sync_reg_t(Common::Serializer &s, reg_t &obj) { static void sync_reg_t(Common::Serializer &s, reg_t &obj) {
s.syncAsUint16LE(obj.segment); s.syncAsUint16LE(obj.segment);
@ -73,22 +73,22 @@ static void syncCStr(Common::Serializer &s, char **str) {
} }
static void sync_song_t(Common::Serializer &s, song_t &obj) { static void sync_song_t(Common::Serializer &s, Song &obj) {
s.syncAsSint32LE(obj.handle); s.syncAsSint32LE(obj._handle);
s.syncAsSint32LE(obj.resource_num); s.syncAsSint32LE(obj._resourceNum);
s.syncAsSint32LE(obj.priority); s.syncAsSint32LE(obj._priority);
s.syncAsSint32LE(obj.status); s.syncAsSint32LE(obj._status);
s.syncAsSint32LE(obj.restore_behavior); s.syncAsSint32LE(obj._restoreBehavior);
s.syncAsSint32LE(obj.restore_time); s.syncAsSint32LE(obj._restoreTime);
s.syncAsSint32LE(obj.loops); s.syncAsSint32LE(obj._loops);
s.syncAsSint32LE(obj.hold); s.syncAsSint32LE(obj._hold);
if (s.isLoading()) { if (s.isLoading()) {
obj._it = 0;
obj._delay = 0; obj._delay = 0;
obj.it = 0; obj._next = 0;
obj.next_playing = 0; obj._nextPlaying = 0;
obj.next_stopping = 0; obj._nextStopping = 0;
obj.next = 0;
} }
} }
@ -401,7 +401,7 @@ void StringFrag::saveLoadWithSerializer(Common::Serializer &s) {
#pragma mark - #pragma mark -
static void sync_songlib_t(Common::Serializer &s, songlib_t &obj) { static void sync_songlib_t(Common::Serializer &s, SongLibrary &obj) {
int songcount = 0; int songcount = 0;
if (s.isSaving()) if (s.isSaving())
songcount = song_lib_count(obj); songcount = song_lib_count(obj);
@ -410,16 +410,16 @@ static void sync_songlib_t(Common::Serializer &s, songlib_t &obj) {
if (s.isLoading()) { if (s.isLoading()) {
song_lib_init(&obj); song_lib_init(&obj);
while (songcount--) { while (songcount--) {
song_t *newsong = (song_t *)calloc(1, sizeof(song_t)); Song *newsong = (Song *)calloc(1, sizeof(Song));
sync_song_t(s, *newsong); sync_song_t(s, *newsong);
song_lib_add(obj, newsong); song_lib_add(obj, newsong);
} }
} else { } else {
song_t *seeker = *(obj.lib); Song *seeker = *(obj._lib);
while (seeker) { while (seeker) {
seeker->restore_time = seeker->it->getTimepos(); seeker->_restoreTime = seeker->_it->getTimepos();
sync_song_t(s, *seeker); sync_song_t(s, *seeker);
seeker = seeker->next; seeker = seeker->_next;
} }
} }
} }
@ -692,11 +692,11 @@ static void reconstruct_clones(EngineState *s, SegManager *self) {
int _reset_graphics_input(EngineState *s); int _reset_graphics_input(EngineState *s);
static void reconstruct_sounds(EngineState *s) { static void reconstruct_sounds(EngineState *s) {
song_t *seeker; Song *seeker;
SongIteratorType it_type = s->resmgr->_sciVersion >= SCI_VERSION_01 ? SCI_SONG_ITERATOR_TYPE_SCI1 : SCI_SONG_ITERATOR_TYPE_SCI0; SongIteratorType it_type = s->resmgr->_sciVersion >= SCI_VERSION_01 ? SCI_SONG_ITERATOR_TYPE_SCI1 : SCI_SONG_ITERATOR_TYPE_SCI0;
if (s->_sound._songlib.lib) if (s->_sound._songlib._lib)
seeker = *(s->_sound._songlib.lib); seeker = *(s->_sound._songlib._lib);
else { else {
song_lib_init(&s->_sound._songlib); song_lib_init(&s->_sound._songlib);
seeker = NULL; seeker = NULL;
@ -707,21 +707,21 @@ static void reconstruct_sounds(EngineState *s) {
int oldstatus; int oldstatus;
SongIterator::Message msg; SongIterator::Message msg;
base = ff = build_iterator(s, seeker->resource_num, it_type, seeker->handle); base = ff = build_iterator(s, seeker->_resourceNum, it_type, seeker->_handle);
if (seeker->restore_behavior == RESTORE_BEHAVIOR_CONTINUE) if (seeker->_restoreBehavior == RESTORE_BEHAVIOR_CONTINUE)
ff = new_fast_forward_iterator(base, seeker->restore_time); ff = new_fast_forward_iterator(base, seeker->_restoreTime);
ff->init(); ff->init();
msg = SongIterator::Message(seeker->handle, SIMSG_SET_LOOPS(seeker->loops)); msg = SongIterator::Message(seeker->_handle, SIMSG_SET_LOOPS(seeker->_loops));
songit_handle_message(&ff, msg); songit_handle_message(&ff, msg);
msg = SongIterator::Message(seeker->handle, SIMSG_SET_HOLD(seeker->hold)); msg = SongIterator::Message(seeker->_handle, SIMSG_SET_HOLD(seeker->_hold));
songit_handle_message(&ff, msg); songit_handle_message(&ff, msg);
oldstatus = seeker->status; oldstatus = seeker->_status;
seeker->status = SOUND_STATUS_STOPPED; seeker->_status = SOUND_STATUS_STOPPED;
seeker->it = ff; seeker->_it = ff;
s->_sound.sfx_song_set_status(seeker->handle, oldstatus); s->_sound.sfx_song_set_status(seeker->_handle, oldstatus);
seeker = seeker->next; seeker = seeker->_next;
} }
} }
@ -729,7 +729,7 @@ void internal_stringfrag_strncpy(EngineState *s, reg_t *dest, reg_t *src, int le
EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) { EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
EngineState *retval; EngineState *retval;
songlib_t temp; SongLibrary temp;
/* /*
if (s->sound_server) { if (s->sound_server) {

View file

@ -47,6 +47,15 @@ class SfxPlayer;
SfxPlayer *player = NULL; // FIXME: Avoid non-const global vars SfxPlayer *player = NULL; // FIXME: Avoid non-const global vars
/* Plays a song iterator that found a PCM through a PCM device, if possible
** Parameters: (SongIterator *) it: The iterator to play
** (SongHandle) handle: Debug handle
** Returns : (int) 0 if the effect will not be played, nonzero if it will
** This assumes that the last call to 'it->next()' returned SI_PCM.
*/
static int sfx_play_iterator_pcm(SongIterator *it, SongHandle handle);
#pragma mark - #pragma mark -
@ -351,39 +360,39 @@ SfxState::~SfxState() {
void SfxState::freezeTime() { void SfxState::freezeTime() {
/* Freezes the top song delay time */ /* Freezes the top song delay time */
const Audio::Timestamp ctime = Audio::Timestamp(g_system->getMillis(), SFX_TICKS_PER_SEC); const Audio::Timestamp ctime = Audio::Timestamp(g_system->getMillis(), SFX_TICKS_PER_SEC);
song_t *song = _song; Song *song = _song;
while (song) { while (song) {
song->_delay = song->_wakeupTime.frameDiff(ctime); song->_delay = song->_wakeupTime.frameDiff(ctime);
if (song->_delay < 0) if (song->_delay < 0)
song->_delay = 0; song->_delay = 0;
song = song->next_playing; song = song->_nextPlaying;
} }
} }
void SfxState::thawTime() { void SfxState::thawTime() {
/* inverse of freezeTime() */ /* inverse of freezeTime() */
const Audio::Timestamp ctime = Audio::Timestamp(g_system->getMillis(), SFX_TICKS_PER_SEC); const Audio::Timestamp ctime = Audio::Timestamp(g_system->getMillis(), SFX_TICKS_PER_SEC);
song_t *song = _song; Song *song = _song;
while (song) { while (song) {
song->_wakeupTime = ctime.addFrames(song->_delay); song->_wakeupTime = ctime.addFrames(song->_delay);
song = song->next_playing; song = song->_nextPlaying;
} }
} }
#if 0 #if 0
// Unreferenced - removed // Unreferenced - removed
static void _dump_playing_list(SfxState *self, char *msg) { static void _dump_playing_list(SfxState *self, char *msg) {
song_t *song = self->_song; Song *song = self->_song;
fprintf(stderr, "[] Song list : [ "); fprintf(stderr, "[] Song list : [ ");
song = *(self->_songlib.lib); song = *(self->_songlib.lib);
while (song) { while (song) {
fprintf(stderr, "%08lx:%d ", song->handle, song->status); fprintf(stderr, "%08lx:%d ", song->handle, song->_status);
song = song->next_playing; song = song->_nextPlaying;
} }
fprintf(stderr, "]\n"); fprintf(stderr, "]\n");
@ -391,7 +400,7 @@ static void _dump_playing_list(SfxState *self, char *msg) {
while (song) { while (song) {
fprintf(stderr, "%08lx ", song->handle); fprintf(stderr, "%08lx ", song->handle);
song = song->next_playing; song = song->_nextPlaying;
} }
fprintf(stderr, "]\n"); fprintf(stderr, "]\n");
@ -400,15 +409,15 @@ static void _dump_playing_list(SfxState *self, char *msg) {
#if 0 #if 0
static void _dump_songs(SfxState *self) { static void _dump_songs(SfxState *self) {
song_t *song = self->_song; Song *song = self->_song;
fprintf(stderr, "Cue iterators:\n"); fprintf(stderr, "Cue iterators:\n");
song = *(self->_songlib.lib); song = *(self->_songlib.lib);
while (song) { while (song) {
fprintf(stderr, " **\tHandle %08x (p%d): status %d\n", fprintf(stderr, " **\tHandle %08x (p%d): status %d\n",
song->handle, song->priority, song->status); song->handle, song->_priority, song->_status);
SIMSG_SEND(song->it, SIMSG_PRINT(1)); SIMSG_SEND(song->_it, SIMSG_PRINT(1));
song = song->next; song = song->_next;
} }
if (player) { if (player) {
@ -418,32 +427,32 @@ static void _dump_songs(SfxState *self) {
} }
#endif #endif
bool SfxState::isPlaying(song_t *song) { bool SfxState::isPlaying(Song *song) {
song_t *playing_song = _song; Song *playing_song = _song;
/* _dump_playing_list(this, "is-playing");*/ /* _dump_playing_list(this, "is-playing");*/
while (playing_song) { while (playing_song) {
if (playing_song == song) if (playing_song == song)
return true; return true;
playing_song = playing_song->next_playing; playing_song = playing_song->_nextPlaying;
} }
return false; return false;
} }
void SfxState::setSongStatus(song_t *song, int status) { void SfxState::setSongStatus(Song *song, int status) {
const Audio::Timestamp ctime = Audio::Timestamp(g_system->getMillis(), SFX_TICKS_PER_SEC); const Audio::Timestamp ctime = Audio::Timestamp(g_system->getMillis(), SFX_TICKS_PER_SEC);
switch (status) { switch (status) {
case SOUND_STATUS_STOPPED: case SOUND_STATUS_STOPPED:
// Reset // Reset
song->it->init(); song->_it->init();
break; break;
case SOUND_STATUS_SUSPENDED: case SOUND_STATUS_SUSPENDED:
case SOUND_STATUS_WAITING: case SOUND_STATUS_WAITING:
if (song->status == SOUND_STATUS_PLAYING) { if (song->_status == SOUND_STATUS_PLAYING) {
// Update delay, set wakeup_time // Update delay, set wakeup_time
song->_delay += song->_wakeupTime.frameDiff(ctime); song->_delay += song->_wakeupTime.frameDiff(ctime);
song->_wakeupTime = ctime; song->_wakeupTime = ctime;
@ -454,7 +463,7 @@ void SfxState::setSongStatus(song_t *song, int status) {
/* otherwise... */ /* otherwise... */
case SOUND_STATUS_PLAYING: case SOUND_STATUS_PLAYING:
if (song->status == SOUND_STATUS_STOPPED) { if (song->_status == SOUND_STATUS_STOPPED) {
// Starting anew // Starting anew
song->_wakeupTime = ctime; song->_wakeupTime = ctime;
} }
@ -471,12 +480,12 @@ void SfxState::setSongStatus(song_t *song, int status) {
return; return;
} }
song->status = status; song->_status = status;
} }
/* Update internal state iff only one song may be played */ /* Update internal state iff only one song may be played */
void SfxState::updateSingleSong() { void SfxState::updateSingleSong() {
song_t *newsong = song_lib_find_active(_songlib); Song *newsong = song_lib_find_active(_songlib);
if (newsong != _song) { if (newsong != _song) {
freezeTime(); /* Store song delay time */ freezeTime(); /* Store song delay time */
@ -485,11 +494,11 @@ void SfxState::updateSingleSong() {
player->stop(); player->stop();
if (newsong) { if (newsong) {
if (!newsong->it) if (!newsong->_it)
return; /* Restore in progress and not ready for this yet */ return; /* Restore in progress and not ready for this yet */
/* Change song */ /* Change song */
if (newsong->status == SOUND_STATUS_WAITING) if (newsong->_status == SOUND_STATUS_WAITING)
setSongStatus(newsong, SOUND_STATUS_PLAYING); setSongStatus(newsong, SOUND_STATUS_PLAYING);
/* Change instrument mappings */ /* Change instrument mappings */
@ -497,7 +506,7 @@ void SfxState::updateSingleSong() {
/* Turn off sound */ /* Turn off sound */
} }
if (_song) { if (_song) {
if (_song->status == SOUND_STATUS_PLAYING) if (_song->_status == SOUND_STATUS_PLAYING)
setSongStatus(newsong, SOUND_STATUS_WAITING); setSongStatus(newsong, SOUND_STATUS_WAITING);
} }
@ -506,13 +515,13 @@ void SfxState::updateSingleSong() {
debugMessage += " New song:"; debugMessage += " New song:";
} else { } else {
char tmp[50]; char tmp[50];
sprintf(tmp, " pausing %08lx, now playing ", _song->handle); sprintf(tmp, " pausing %08lx, now playing ", _song->_handle);
debugMessage += tmp; debugMessage += tmp;
} }
if (newsong) { if (newsong) {
char tmp[20]; char tmp[20];
sprintf(tmp, "%08lx\n", newsong->handle); sprintf(tmp, "%08lx\n", newsong->_handle);
debugMessage += tmp; debugMessage += tmp;
} else { } else {
debugMessage += " none\n"; debugMessage += " none\n";
@ -524,7 +533,7 @@ void SfxState::updateSingleSong() {
thawTime(); /* Recover song delay time */ thawTime(); /* Recover song delay time */
if (newsong && player) { if (newsong && player) {
SongIterator *clonesong = newsong->it->clone(newsong->_delay); SongIterator *clonesong = newsong->_it->clone(newsong->_delay);
player->add_iterator(clonesong, newsong->_wakeupTime.msecs()); player->add_iterator(clonesong, newsong->_wakeupTime.msecs());
} }
@ -533,11 +542,11 @@ void SfxState::updateSingleSong() {
void SfxState::updateMultiSong() { void SfxState::updateMultiSong() {
song_t *oldfirst = _song; Song *oldfirst = _song;
song_t *oldseeker; Song *oldseeker;
song_t *newsong = song_lib_find_active(_songlib); Song *newsong = song_lib_find_active(_songlib);
song_t *newseeker; Song *newseeker;
song_t not_playing_anymore; /* Dummy object, referenced by Song not_playing_anymore; /* Dummy object, referenced by
** songs which are no longer ** songs which are no longer
** active. */ ** active. */
@ -548,30 +557,30 @@ void SfxState::updateMultiSong() {
return; return;
for (newseeker = newsong; newseeker; for (newseeker = newsong; newseeker;
newseeker = newseeker->next_playing) { newseeker = newseeker->_nextPlaying) {
if (!newseeker || !newseeker->it) if (!newseeker || !newseeker->_it)
return; /* Restore in progress and not ready for this yet */ return; /* Restore in progress and not ready for this yet */
} }
/* First, put all old songs into the 'stopping' list and /* First, put all old songs into the 'stopping' list and
** mark their 'next-playing' as not_playing_anymore. */ ** mark their 'next-playing' as not_playing_anymore. */
for (oldseeker = oldfirst; oldseeker; for (oldseeker = oldfirst; oldseeker;
oldseeker = oldseeker->next_stopping) { oldseeker = oldseeker->_nextStopping) {
oldseeker->next_stopping = oldseeker->next_playing; oldseeker->_nextStopping = oldseeker->_nextPlaying;
oldseeker->next_playing = &not_playing_anymore; oldseeker->_nextPlaying = &not_playing_anymore;
if (oldseeker == oldseeker->next_playing) { if (oldseeker == oldseeker->_nextPlaying) {
error("updateMultiSong() failed. Breakpoint in %s, line %d", __FILE__, __LINE__); error("updateMultiSong() failed. Breakpoint in %s, line %d", __FILE__, __LINE__);
} }
} }
/* Second, re-generate the new song queue. */ /* Second, re-generate the new song queue. */
for (newseeker = newsong; newseeker; for (newseeker = newsong; newseeker;
newseeker = newseeker->next_playing) { newseeker = newseeker->_nextPlaying) {
newseeker->next_playing newseeker->_nextPlaying
= song_lib_find_next_active(_songlib, newseeker); = song_lib_find_next_active(_songlib, newseeker);
if (newseeker == newseeker->next_playing) { if (newseeker == newseeker->_nextPlaying) {
error("updateMultiSong() failed. Breakpoint in %s, line %d", __FILE__, __LINE__); error("updateMultiSong() failed. Breakpoint in %s, line %d", __FILE__, __LINE__);
} }
} }
@ -582,21 +591,21 @@ void SfxState::updateMultiSong() {
/* Third, stop all old songs */ /* Third, stop all old songs */
for (oldseeker = oldfirst; oldseeker; for (oldseeker = oldfirst; oldseeker;
oldseeker = oldseeker->next_stopping) oldseeker = oldseeker->_nextStopping)
if (oldseeker->next_playing == &not_playing_anymore) { if (oldseeker->_nextPlaying == &not_playing_anymore) {
setSongStatus(oldseeker, SOUND_STATUS_SUSPENDED); setSongStatus(oldseeker, SOUND_STATUS_SUSPENDED);
debugC(2, kDebugLevelSound, "[SFX] Stopping song %lx\n", oldseeker->handle); debugC(2, kDebugLevelSound, "[SFX] Stopping song %lx\n", oldseeker->_handle);
if (player && oldseeker->it) if (player && oldseeker->_it)
player->iterator_message(SongIterator::Message(oldseeker->it->ID, SIMSG_STOP)); player->iterator_message(SongIterator::Message(oldseeker->_it->ID, SIMSG_STOP));
oldseeker->next_playing = NULL; /* Clear this pointer; we don't need the tag anymore */ oldseeker->_nextPlaying = NULL; /* Clear this pointer; we don't need the tag anymore */
} }
for (newseeker = newsong; newseeker; newseeker = newseeker->next_playing) { for (newseeker = newsong; newseeker; newseeker = newseeker->_nextPlaying) {
if (newseeker->status != SOUND_STATUS_PLAYING && player) { if (newseeker->_status != SOUND_STATUS_PLAYING && player) {
debugC(2, kDebugLevelSound, "[SFX] Adding song %lx\n", newseeker->it->ID); debugC(2, kDebugLevelSound, "[SFX] Adding song %lx\n", newseeker->_it->ID);
SongIterator *clonesong = newseeker->it->clone(newseeker->_delay); SongIterator *clonesong = newseeker->_it->clone(newseeker->_delay);
player->add_iterator(clonesong, g_system->getMillis()); player->add_iterator(clonesong, g_system->getMillis());
} }
setSongStatus(newseeker, SOUND_STATUS_PLAYING); setSongStatus(newseeker, SOUND_STATUS_PLAYING);
@ -615,7 +624,7 @@ void SfxState::update() {
updateSingleSong(); updateSingleSong();
} }
int sfx_play_iterator_pcm(SongIterator *it, song_handle_t handle) { static int sfx_play_iterator_pcm(SongIterator *it, SongHandle handle) {
#ifdef DEBUG_SONG_API #ifdef DEBUG_SONG_API
fprintf(stderr, "[sfx-core] Playing PCM: %08lx\n", handle); fprintf(stderr, "[sfx-core] Playing PCM: %08lx\n", handle);
#endif #endif
@ -716,11 +725,11 @@ void SfxState::sfx_suspend(bool suspend) {
_suspended = suspend; _suspended = suspend;
} }
int SfxState::sfx_poll(song_handle_t *handle, int *cue) { int SfxState::sfx_poll(SongHandle *handle, int *cue) {
if (!_song) if (!_song)
return 0; /* No milk today */ return 0; /* No milk today */
*handle = _song->handle; *handle = _song->_handle;
#ifdef DEBUG_SONG_API #ifdef DEBUG_SONG_API
fprintf(stderr, "[sfx-core] Polling any (%08lx)\n", *handle); fprintf(stderr, "[sfx-core] Polling any (%08lx)\n", *handle);
@ -728,12 +737,12 @@ int SfxState::sfx_poll(song_handle_t *handle, int *cue) {
return sfx_poll_specific(*handle, cue); return sfx_poll_specific(*handle, cue);
} }
int SfxState::sfx_poll_specific(song_handle_t handle, int *cue) { int SfxState::sfx_poll_specific(SongHandle handle, int *cue) {
const Audio::Timestamp ctime = Audio::Timestamp(g_system->getMillis(), SFX_TICKS_PER_SEC); const Audio::Timestamp ctime = Audio::Timestamp(g_system->getMillis(), SFX_TICKS_PER_SEC);
song_t *song = _song; Song *song = _song;
while (song && song->handle != handle) while (song && song->_handle != handle)
song = song->next_playing; song = song->_nextPlaying;
if (!song) if (!song)
return 0; /* Song not playing */ return 0; /* Song not playing */
@ -745,7 +754,7 @@ int SfxState::sfx_poll_specific(song_handle_t handle, int *cue) {
return 0; /* Patience, young hacker! */ return 0; /* Patience, young hacker! */
byte buf[8]; byte buf[8];
int result = songit_next(&(song->it), buf, cue, IT_READER_MASK_ALL); int result = songit_next(&(song->_it), buf, cue, IT_READER_MASK_ALL);
switch (result) { switch (result) {
@ -783,8 +792,8 @@ int SfxState::sfx_poll_specific(song_handle_t handle, int *cue) {
/* Song basics */ /* Song basics */
/*****************/ /*****************/
void SfxState::sfx_add_song(SongIterator *it, int priority, song_handle_t handle, int number) { void SfxState::sfx_add_song(SongIterator *it, int priority, SongHandle handle, int number) {
song_t *song = song_lib_find(_songlib, handle); Song *song = song_lib_find(_songlib, handle);
#ifdef DEBUG_SONG_API #ifdef DEBUG_SONG_API
fprintf(stderr, "[sfx-core] Adding song: %08lx at %d, it=%p\n", handle, priority, it); fprintf(stderr, "[sfx-core] Adding song: %08lx at %d, it=%p\n", handle, priority, it);
@ -807,10 +816,10 @@ void SfxState::sfx_add_song(SongIterator *it, int priority, song_handle_t handle
setSongStatus( song, SOUND_STATUS_STOPPED); setSongStatus( song, SOUND_STATUS_STOPPED);
fprintf(stderr, "Overwriting old song (%08lx) ...\n", handle); fprintf(stderr, "Overwriting old song (%08lx) ...\n", handle);
if (song->status == SOUND_STATUS_PLAYING || song->status == SOUND_STATUS_SUSPENDED) { if (song->_status == SOUND_STATUS_PLAYING || song->_status == SOUND_STATUS_SUSPENDED) {
delete it; delete it;
error("Unexpected (error): Song %ld still playing/suspended (%d)", error("Unexpected (error): Song %ld still playing/suspended (%d)",
handle, song->status); handle, song->_status);
return; return;
} else { } else {
song_lib_remove(_songlib, handle); /* No duplicates */ song_lib_remove(_songlib, handle); /* No duplicates */
@ -819,9 +828,9 @@ void SfxState::sfx_add_song(SongIterator *it, int priority, song_handle_t handle
} }
song = song_new(handle, it, priority); song = song_new(handle, it, priority);
song->resource_num = number; song->_resourceNum = number;
song->hold = 0; song->_hold = 0;
song->loops = 0; song->_loops = 0;
song->_wakeupTime = Audio::Timestamp(g_system->getMillis(), SFX_TICKS_PER_SEC); song->_wakeupTime = Audio::Timestamp(g_system->getMillis(), SFX_TICKS_PER_SEC);
song_lib_add(_songlib, song); song_lib_add(_songlib, song);
_song = NULL; /* As above */ _song = NULL; /* As above */
@ -830,11 +839,11 @@ void SfxState::sfx_add_song(SongIterator *it, int priority, song_handle_t handle
return; return;
} }
void SfxState::sfx_remove_song(song_handle_t handle) { void SfxState::sfx_remove_song(SongHandle handle) {
#ifdef DEBUG_SONG_API #ifdef DEBUG_SONG_API
fprintf(stderr, "[sfx-core] Removing song: %08lx\n", handle); fprintf(stderr, "[sfx-core] Removing song: %08lx\n", handle);
#endif #endif
if (_song && _song->handle == handle) if (_song && _song->_handle == handle)
_song = NULL; _song = NULL;
song_lib_remove(_songlib, handle); song_lib_remove(_songlib, handle);
@ -849,8 +858,8 @@ void SfxState::sfx_remove_song(song_handle_t handle) {
#define ASSERT_SONG(s) if (!(s)) { warning("Looking up song handle %08lx failed in %s, L%d", handle, __FILE__, __LINE__); return; } #define ASSERT_SONG(s) if (!(s)) { warning("Looking up song handle %08lx failed in %s, L%d", handle, __FILE__, __LINE__); return; }
void SfxState::sfx_song_set_status(song_handle_t handle, int status) { void SfxState::sfx_song_set_status(SongHandle handle, int status) {
song_t *song = song_lib_find(_songlib, handle); Song *song = song_lib_find(_songlib, handle);
ASSERT_SONG(song); ASSERT_SONG(song);
#ifdef DEBUG_SONG_API #ifdef DEBUG_SONG_API
fprintf(stderr, "[sfx-core] Setting song status to %d" fprintf(stderr, "[sfx-core] Setting song status to %d"
@ -862,11 +871,11 @@ void SfxState::sfx_song_set_status(song_handle_t handle, int status) {
update(); update();
} }
void SfxState::sfx_song_set_fade(song_handle_t handle, fade_params_t *params) { void SfxState::sfx_song_set_fade(SongHandle handle, fade_params_t *params) {
#ifdef DEBUG_SONG_API #ifdef DEBUG_SONG_API
static const char *stopmsg[] = {"??? Should not happen", "Do not stop afterwards", "Stop afterwards"}; static const char *stopmsg[] = {"??? Should not happen", "Do not stop afterwards", "Stop afterwards"};
#endif #endif
song_t *song = song_lib_find(_songlib, handle); Song *song = song_lib_find(_songlib, handle);
ASSERT_SONG(song); ASSERT_SONG(song);
@ -877,52 +886,52 @@ void SfxState::sfx_song_set_fade(song_handle_t handle, fade_params_t *params) {
stopmsg[fade->action]); stopmsg[fade->action]);
#endif #endif
SIMSG_SEND_FADE(song->it, params); SIMSG_SEND_FADE(song->_it, params);
update(); update();
} }
void SfxState::sfx_song_renice(song_handle_t handle, int priority) { void SfxState::sfx_song_renice(SongHandle handle, int priority) {
song_t *song = song_lib_find(_songlib, handle); Song *song = song_lib_find(_songlib, handle);
ASSERT_SONG(song); ASSERT_SONG(song);
#ifdef DEBUG_SONG_API #ifdef DEBUG_SONG_API
fprintf(stderr, "[sfx-core] Renicing song %08lx to %d\n", fprintf(stderr, "[sfx-core] Renicing song %08lx to %d\n",
handle, priority); handle, priority);
#endif #endif
song->priority = priority; song->_priority = priority;
update(); update();
} }
void SfxState::sfx_song_set_loops(song_handle_t handle, int loops) { void SfxState::sfx_song_set_loops(SongHandle handle, int loops) {
song_t *song = song_lib_find(_songlib, handle); Song *song = song_lib_find(_songlib, handle);
SongIterator::Message msg = SongIterator::Message(handle, SIMSG_SET_LOOPS(loops)); SongIterator::Message msg = SongIterator::Message(handle, SIMSG_SET_LOOPS(loops));
ASSERT_SONG(song); ASSERT_SONG(song);
song->loops = loops; song->_loops = loops;
#ifdef DEBUG_SONG_API #ifdef DEBUG_SONG_API
fprintf(stderr, "[sfx-core] Setting loops on %08lx to %d\n", fprintf(stderr, "[sfx-core] Setting loops on %08lx to %d\n",
handle, loops); handle, loops);
#endif #endif
songit_handle_message(&(song->it), msg); songit_handle_message(&(song->_it), msg);
if (player/* && player->send_iterator_message*/) if (player/* && player->send_iterator_message*/)
/* FIXME: The above should be optional! */ /* FIXME: The above should be optional! */
player->iterator_message(msg); player->iterator_message(msg);
} }
void SfxState::sfx_song_set_hold(song_handle_t handle, int hold) { void SfxState::sfx_song_set_hold(SongHandle handle, int hold) {
song_t *song = song_lib_find(_songlib, handle); Song *song = song_lib_find(_songlib, handle);
SongIterator::Message msg = SongIterator::Message(handle, SIMSG_SET_HOLD(hold)); SongIterator::Message msg = SongIterator::Message(handle, SIMSG_SET_HOLD(hold));
ASSERT_SONG(song); ASSERT_SONG(song);
song->hold = hold; song->_hold = hold;
#ifdef DEBUG_SONG_API #ifdef DEBUG_SONG_API
fprintf(stderr, "[sfx-core] Setting hold on %08lx to %d\n", fprintf(stderr, "[sfx-core] Setting hold on %08lx to %d\n",
handle, hold); handle, hold);
#endif #endif
songit_handle_message(&(song->it), msg); songit_handle_message(&(song->_it), msg);
if (player/* && player->send_iterator_message*/) if (player/* && player->send_iterator_message*/)
/* FIXME: The above should be optional! */ /* FIXME: The above should be optional! */
@ -934,9 +943,9 @@ static const int MIDI_cmdlen[16] = {0, 0, 0, 0, 0, 0, 0, 0,
3, 3, 0, 3, 2, 0, 3, 0 3, 3, 0, 3, 2, 0, 3, 0
}; };
static const song_handle_t midi_send_base = 0xffff0000; static const SongHandle midi_send_base = 0xffff0000;
Common::Error SfxState::sfx_send_midi(song_handle_t handle, int channel, Common::Error SfxState::sfx_send_midi(SongHandle handle, int channel,
int command, int arg1, int arg2) { int command, int arg1, int arg2) {
byte buffer[5]; byte buffer[5];

View file

@ -47,8 +47,8 @@ class SfxState {
public: // FIXME, make private public: // FIXME, make private
SongIterator *_it; /**< The song iterator at the heart of things */ SongIterator *_it; /**< The song iterator at the heart of things */
uint _flags; /**< SFX_STATE_FLAG_* */ uint _flags; /**< SFX_STATE_FLAG_* */
songlib_t _songlib; /**< Song library */ SongLibrary _songlib; /**< Song library */
song_t *_song; /**< Active song, or start of active song chain */ Song *_song; /**< Active song, or start of active song chain */
bool _suspended; /**< Whether we are suspended */ bool _suspended; /**< Whether we are suspended */
ResourceSync *_soundSync; /**< Used by kDoSync for speech syncing in CD talkie games */ ResourceSync *_soundSync; /**< Used by kDoSync for speech syncing in CD talkie games */
AudioResource *_audioResource; /**< Used for audio resources in CD talkie games */ AudioResource *_audioResource; /**< Used for audio resources in CD talkie games */
@ -77,17 +77,17 @@ public:
/* Polls the sound server for cues etc. /* Polls the sound server for cues etc.
** Returns : (int) 0 if the cue queue is empty, SI_LOOP, SI_CUE, or SI_FINISHED otherwise ** Returns : (int) 0 if the cue queue is empty, SI_LOOP, SI_CUE, or SI_FINISHED otherwise
** (song_handle_t) *handle: The affected handle ** (SongHandle) *handle: The affected handle
** (int) *cue: The sound cue number (if SI_CUE), or the loop number (if SI_LOOP) ** (int) *cue: The sound cue number (if SI_CUE), or the loop number (if SI_LOOP)
*/ */
int sfx_poll(song_handle_t *handle, int *cue); int sfx_poll(SongHandle *handle, int *cue);
/* Polls the sound server for cues etc. /* Polls the sound server for cues etc.
** Parameters: (song_handle_t) handle: The handle to poll ** Parameters: (SongHandle) handle: The handle to poll
** Returns : (int) 0 if the cue queue is empty, SI_LOOP, SI_CUE, or SI_FINISHED otherwise ** Returns : (int) 0 if the cue queue is empty, SI_LOOP, SI_CUE, or SI_FINISHED otherwise
** (int) *cue: The sound cue number (if SI_CUE), or the loop number (if SI_LOOP) ** (int) *cue: The sound cue number (if SI_CUE), or the loop number (if SI_LOOP)
*/ */
int sfx_poll_specific(song_handle_t handle, int *cue); int sfx_poll_specific(SongHandle handle, int *cue);
/* Determines the current global volume settings /* Determines the current global volume settings
** Returns : (int) The global volume, between 0 (silent) and 127 (max. volume) ** Returns : (int) The global volume, between 0 (silent) and 127 (max. volume)
@ -111,15 +111,15 @@ public:
/* Adds a song to the internal sound library /* Adds a song to the internal sound library
** Parameters: (SongIterator *) it: The iterator describing the song ** Parameters: (SongIterator *) it: The iterator describing the song
** (int) priority: Initial song priority (higher <-> more important) ** (int) priority: Initial song priority (higher <-> more important)
** (song_handle_t) handle: The handle to associate with the song ** (SongHandle) handle: The handle to associate with the song
*/ */
void sfx_add_song(SongIterator *it, int priority, song_handle_t handle, int resnum); void sfx_add_song(SongIterator *it, int priority, SongHandle handle, int resnum);
/* Deletes a song and its associated song iterator from the song queue /* Deletes a song and its associated song iterator from the song queue
** Parameters: (song_handle_t) handle: The song to remove ** Parameters: (SongHandle) handle: The song to remove
*/ */
void sfx_remove_song(song_handle_t handle); void sfx_remove_song(SongHandle handle);
/**********************/ /**********************/
@ -128,48 +128,48 @@ public:
/* Sets the song status, i.e. whether it is playing, suspended, or stopped. /* Sets the song status, i.e. whether it is playing, suspended, or stopped.
** Parameters: (song_handle_t) handle: Handle of the song to modify ** Parameters: (SongHandle) handle: Handle of the song to modify
** (int) status: The song status the song should assume ** (int) status: The song status the song should assume
** WAITING and PLAYING are set implicitly and essentially describe the same state ** WAITING and PLAYING are set implicitly and essentially describe the same state
** as far as this function is concerned. ** as far as this function is concerned.
*/ */
void sfx_song_set_status(song_handle_t handle, int status); void sfx_song_set_status(SongHandle handle, int status);
/* Sets the new song priority /* Sets the new song priority
** Parameters: (song_handle_t) handle: The handle to modify ** Parameters: (SongHandle) handle: The handle to modify
** (int) priority: The priority to set ** (int) priority: The priority to set
*/ */
void sfx_song_renice(song_handle_t handle, int priority); void sfx_song_renice(SongHandle handle, int priority);
/* Sets the number of loops for the specified song /* Sets the number of loops for the specified song
** Parameters: (song_handle_t) handle: The song handle to reference ** Parameters: (SongHandle) handle: The song handle to reference
** (int) loops: Number of loops to set ** (int) loops: Number of loops to set
*/ */
void sfx_song_set_loops(song_handle_t handle, int loops); void sfx_song_set_loops(SongHandle handle, int loops);
/* Sets the number of loops for the specified song /* Sets the number of loops for the specified song
** Parameters: (song_handle_t) handle: The song handle to reference ** Parameters: (SongHandle) handle: The song handle to reference
** (int) hold: Number of loops to setn ** (int) hold: Number of loops to setn
*/ */
void sfx_song_set_hold(song_handle_t handle, int hold); void sfx_song_set_hold(SongHandle handle, int hold);
/* Instructs a song to be faded out /* Instructs a song to be faded out
** Parameters: (song_handle_t) handle: The song handle to reference ** Parameters: (SongHandle) handle: The song handle to reference
** (fade_params_t *) fade_setup: The precise fade-out configuration to use ** (fade_params_t *) fade_setup: The precise fade-out configuration to use
*/ */
void sfx_song_set_fade(song_handle_t handle, fade_params_t *fade_setup); void sfx_song_set_fade(SongHandle handle, fade_params_t *fade_setup);
// Previously undocumented: // Previously undocumented:
Common::Error sfx_send_midi(song_handle_t handle, int channel, Common::Error sfx_send_midi(SongHandle handle, int channel,
int command, int arg1, int arg2); int command, int arg1, int arg2);
protected: protected:
void freezeTime(); void freezeTime();
void thawTime(); void thawTime();
bool isPlaying(song_t *song); bool isPlaying(Song *song);
void setSongStatus(song_t *song, int status); void setSongStatus(Song *song, int status);
void updateSingleSong(); void updateSingleSong();
void updateMultiSong(); void updateMultiSong();
void update(); void update();

View file

@ -253,7 +253,6 @@ enum SongIteratorType {
| IT_READER_MASK_CUE \ | IT_READER_MASK_CUE \
| IT_READER_MASK_PCM ) | IT_READER_MASK_PCM )
int songit_next(SongIterator **it, byte *buf, int *result, int mask);
/* Convenience wrapper around it->next /* Convenience wrapper around it->next
** Parameters: (SongIterator **it) Reference to the iterator to access ** Parameters: (SongIterator **it) Reference to the iterator to access
** (byte *) buf: The buffer to write to (needs to be able to ** (byte *) buf: The buffer to write to (needs to be able to
@ -270,8 +269,8 @@ int songit_next(SongIterator **it, byte *buf, int *result, int mask);
** to the lower layers) for 0, the cue value for SI_CUE, ** to the lower layers) for 0, the cue value for SI_CUE,
** or the number of loops remaining for SI_LOOP. ** or the number of loops remaining for SI_LOOP.
*/ */
int songit_next(SongIterator **it, byte *buf, int *result, int mask);
SongIterator *songit_new(byte *data, uint size, SongIteratorType type, songit_id_t id);
/* Constructs a new song iterator object /* Constructs a new song iterator object
** Parameters: (byte *) data: The song data to iterate over ** Parameters: (byte *) data: The song data to iterate over
** (uint) size: Number of bytes in the song ** (uint) size: Number of bytes in the song
@ -280,26 +279,17 @@ SongIterator *songit_new(byte *data, uint size, SongIteratorType type, songit_id
** Returns : (SongIterator *) A newly allocated but uninitialized song ** Returns : (SongIterator *) A newly allocated but uninitialized song
** iterator, or NULL if 'type' was invalid or unsupported ** iterator, or NULL if 'type' was invalid or unsupported
*/ */
SongIterator *songit_new(byte *data, uint size, SongIteratorType type, songit_id_t id);
int songit_handle_message(SongIterator **it_reg, SongIterator::Message msg);
/* Handles a message to the song iterator /* Handles a message to the song iterator
** Parameters: (SongIterator **): A reference to the variable storing the song iterator ** Parameters: (SongIterator **): A reference to the variable storing the song iterator
** Returns : (int) Non-zero if the message was understood ** Returns : (int) Non-zero if the message was understood
** The song iterator may polymorph as result of msg, so a writeable reference is required. ** The song iterator may polymorph as result of msg, so a writeable reference is required.
*/ */
int songit_handle_message(SongIterator **it_reg, SongIterator::Message msg);
int sfx_play_iterator_pcm(SongIterator *it, unsigned long handle);
/* Plays a song iterator that found a PCM through a PCM device, if possible
** Parameters: (SongIterator *) it: The iterator to play
** (song_handle_t) handle: Debug handle
** Returns : (int) 0 if the effect will not be played, nonzero if it will
** This assumes that the last call to 'it->next()' returned SI_PCM.
*/
SongIterator *new_fast_forward_iterator(SongIterator *it, int delta);
/* Creates a new song iterator which fast-forwards /* Creates a new song iterator which fast-forwards
** Parameters: (SongIterator *) it: The iterator to wrap ** Parameters: (SongIterator *) it: The iterator to wrap
** (int) delta: The number of ticks to skip ** (int) delta: The number of ticks to skip
@ -307,6 +297,7 @@ SongIterator *new_fast_forward_iterator(SongIterator *it, int delta);
** which skips all delta times ** which skips all delta times
** until 'delta' has been used up ** until 'delta' has been used up
*/ */
SongIterator *new_fast_forward_iterator(SongIterator *it, int delta);

View file

@ -31,169 +31,169 @@ namespace Sci {
#define debug_stream stderr #define debug_stream stderr
song_t *song_new(song_handle_t handle, SongIterator *it, int priority) { Song *song_new(SongHandle handle, SongIterator *it, int priority) {
song_t *retval; Song *retval;
retval = (song_t*) malloc(sizeof(song_t)); retval = (Song *)malloc(sizeof(Song));
#ifdef SATISFY_PURIFY #ifdef SATISFY_PURIFY
memset(retval, 0, sizeof(song_t)); memset(retval, 0, sizeof(Song));
#endif #endif
retval->handle = handle; retval->_handle = handle;
retval->priority = priority; retval->_priority = priority;
retval->next = NULL; retval->_next = NULL;
retval->_delay = 0; retval->_delay = 0;
retval->_wakeupTime = Audio::Timestamp(); retval->_wakeupTime = Audio::Timestamp();
retval->it = it; retval->_it = it;
retval->status = SOUND_STATUS_STOPPED; retval->_status = SOUND_STATUS_STOPPED;
retval->next_playing = NULL; retval->_nextPlaying = NULL;
retval->next_stopping = NULL; retval->_nextStopping = NULL;
retval->restore_behavior = RESTORE_BEHAVIOR_CONTINUE; retval->_restoreBehavior = RESTORE_BEHAVIOR_CONTINUE;
retval->restore_time = 0; retval->_restoreTime = 0;
return retval; return retval;
} }
void song_lib_add(const songlib_t &songlib, song_t *song) { void song_lib_add(const SongLibrary &songlib, Song *song) {
song_t **seeker = NULL; Song **seeker = NULL;
int pri = song->priority; int pri = song->_priority;
if (NULL == song) { if (NULL == song) {
sciprintf("song_lib_add(): NULL passed for song\n"); sciprintf("song_lib_add(): NULL passed for song\n");
return; return;
} }
if (*(songlib.lib) == NULL) { if (*(songlib._lib) == NULL) {
*(songlib.lib) = song; *(songlib._lib) = song;
song->next = NULL; song->_next = NULL;
return; return;
} }
seeker = (songlib.lib); seeker = (songlib._lib);
while (*seeker && ((*seeker)->priority > pri)) while (*seeker && ((*seeker)->_priority > pri))
seeker = &((*seeker)->next); seeker = &((*seeker)->_next);
song->next = *seeker; song->_next = *seeker;
*seeker = song; *seeker = song;
} }
static void _songfree_chain(song_t *song) { static void _songfree_chain(Song *song) {
/* Recursively free a chain of songs */ /* Recursively free a chain of songs */
if (song) { if (song) {
_songfree_chain(song->next); _songfree_chain(song->_next);
delete song->it; delete song->_it;
song->it = NULL; song->_it = NULL;
free(song); free(song);
} }
} }
void song_lib_init(songlib_t *songlib) { void song_lib_init(SongLibrary *songlib) {
songlib->lib = &(songlib->_s); songlib->_lib = &(songlib->_s);
songlib->_s = NULL; songlib->_s = NULL;
} }
void song_lib_free(const songlib_t &songlib) { void song_lib_free(const SongLibrary &songlib) {
_songfree_chain(*(songlib.lib)); _songfree_chain(*(songlib._lib));
*(songlib.lib) = NULL; *(songlib._lib) = NULL;
} }
song_t *song_lib_find(const songlib_t &songlib, song_handle_t handle) { Song *song_lib_find(const SongLibrary &songlib, SongHandle handle) {
song_t *seeker = *(songlib.lib); Song *seeker = *(songlib._lib);
while (seeker) { while (seeker) {
if (seeker->handle == handle) if (seeker->_handle == handle)
break; break;
seeker = seeker->next; seeker = seeker->_next;
} }
return seeker; return seeker;
} }
song_t *song_lib_find_next_active(const songlib_t &songlib, song_t *other) { Song *song_lib_find_next_active(const SongLibrary &songlib, Song *other) {
song_t *seeker = other ? other->next : *(songlib.lib); Song *seeker = other ? other->_next : *(songlib._lib);
while (seeker) { while (seeker) {
if ((seeker->status == SOUND_STATUS_WAITING) || if ((seeker->_status == SOUND_STATUS_WAITING) ||
(seeker->status == SOUND_STATUS_PLAYING)) (seeker->_status == SOUND_STATUS_PLAYING))
break; break;
seeker = seeker->next; seeker = seeker->_next;
} }
/* Only return songs that have equal priority */ /* Only return songs that have equal priority */
if (other && seeker && other->priority > seeker->priority) if (other && seeker && other->_priority > seeker->_priority)
return NULL; return NULL;
return seeker; return seeker;
} }
song_t *song_lib_find_active(const songlib_t &songlib) { Song *song_lib_find_active(const SongLibrary &songlib) {
return song_lib_find_next_active(songlib, NULL); return song_lib_find_next_active(songlib, NULL);
} }
int song_lib_remove(const songlib_t &songlib, song_handle_t handle) { int song_lib_remove(const SongLibrary &songlib, SongHandle handle) {
int retval; int retval;
song_t *goner = *(songlib.lib); Song *goner = *(songlib._lib);
if (!goner) if (!goner)
return -1; return -1;
if (goner->handle == handle) if (goner->_handle == handle)
*(songlib.lib) = goner->next; *(songlib._lib) = goner->_next;
else { else {
while ((goner->next) && (goner->next->handle != handle)) while ((goner->_next) && (goner->_next->_handle != handle))
goner = goner->next; goner = goner->_next;
if (goner->next) { /* Found him? */ if (goner->_next) { /* Found him? */
song_t *oldnext = goner->next; Song *oldnext = goner->_next;
goner->next = goner->next->next; goner->_next = goner->_next->_next;
goner = oldnext; goner = oldnext;
} else return -1; /* No. */ } else return -1; /* No. */
} }
retval = goner->status; retval = goner->_status;
delete goner->it; delete goner->_it;
free(goner); free(goner);
return retval; return retval;
} }
void song_lib_resort(const songlib_t &songlib, song_t *song) { void song_lib_resort(const SongLibrary &songlib, Song *song) {
if (*(songlib.lib) == song) if (*(songlib._lib) == song)
*(songlib.lib) = song->next; *(songlib._lib) = song->_next;
else { else {
song_t *seeker = *(songlib.lib); Song *seeker = *(songlib._lib);
while (seeker->next && (seeker->next != song)) while (seeker->_next && (seeker->_next != song))
seeker = seeker->next; seeker = seeker->_next;
if (seeker->next) if (seeker->_next)
seeker->next = seeker->next->next; seeker->_next = seeker->_next->_next;
} }
song_lib_add(songlib, song); song_lib_add(songlib, song);
} }
int song_lib_count(const songlib_t &songlib) { int song_lib_count(const SongLibrary &songlib) {
song_t *seeker = *(songlib.lib); Song *seeker = *(songlib._lib);
int retval = 0; int retval = 0;
while (seeker) { while (seeker) {
retval++; retval++;
seeker = seeker->next; seeker = seeker->_next;
} }
return retval; return retval;
} }
void song_lib_set_restore_behavior(const songlib_t &songlib, song_handle_t handle, RESTORE_BEHAVIOR action) { void song_lib_set_restore_behavior(const SongLibrary &songlib, SongHandle handle, RESTORE_BEHAVIOR action) {
song_t *seeker = song_lib_find(songlib, handle); Song *seeker = song_lib_find(songlib, handle);
seeker->restore_behavior = action; seeker->_restoreBehavior = action;
} }
} // End of namespace Sci } // End of namespace Sci

View file

@ -42,7 +42,7 @@ class SongIterator;
#define SOUND_STATUS_WAITING 3 #define SOUND_STATUS_WAITING 3
/* "waiting" means "tagged for playing, but not active right now" */ /* "waiting" means "tagged for playing, but not active right now" */
typedef unsigned long song_handle_t; typedef unsigned long SongHandle;
enum RESTORE_BEHAVIOR { enum RESTORE_BEHAVIOR {
RESTORE_BEHAVIOR_CONTINUE, /* restart a song when restored from RESTORE_BEHAVIOR_CONTINUE, /* restart a song when restored from
@ -50,123 +50,130 @@ enum RESTORE_BEHAVIOR {
RESTORE_BEHAVIOR_RESTART /* continue it from where it was */ RESTORE_BEHAVIOR_RESTART /* continue it from where it was */
}; };
struct song_t { struct Song {
song_handle_t handle; SongHandle _handle;
int resource_num; /* Resource number */ int _resourceNum; /**<! Resource number */
int priority; /* Song priority (more important if priority is higher) */ int _priority; /**!< Song priority (more important if priority is higher) */
int status; /* See above */ int _status; /* See above */
int restore_behavior; int _restoreBehavior;
int restore_time; int _restoreTime;
/* Grabbed from the sound iterator, for save/restore purposes */ /* Grabbed from the sound iterator, for save/restore purposes */
int loops; int _loops;
int hold; int _hold;
SongIterator *it; SongIterator *_it;
int _delay; /* Delay before accessing the iterator, in ticks */ int _delay; /**!< Delay before accessing the iterator, in ticks */
Audio::Timestamp _wakeupTime; /**< Timestamp indicating the next MIDI event */ Audio::Timestamp _wakeupTime; /**!< Timestamp indicating the next MIDI event */
song_t *next; /* Next song or NULL if this is the last one */ Song *_next; /**!< Next song or NULL if this is the last one */
song_t *next_playing; /* Next playing song; used by the
** core song system */ /**
song_t *next_stopping; /* Next song pending stopping; used exclusively by * Next playing song. Used by the core song system.
** the core song system's _update_multi_song() */ */
Song *_nextPlaying;
/**
* Next song pending stopping. Used exclusively by the core song system's
* _update_multi_song()
*/
Song *_nextStopping;
}; };
struct songlib_t { struct SongLibrary {
song_t **lib; Song **_lib;
song_t *_s; Song *_s;
}; };
/**************************/ /**************************/
/* Song library commands: */ /* Song library commands: */
/**************************/ /**************************/
song_t *song_new(song_handle_t handle, SongIterator *it, int priority);
/* Initializes a new song /* Initializes a new song
** Parameters: (song_handle_t) handle: The sound handle ** Parameters: (SongHandle) handle: The sound handle
** (SongIterator *) it: The song ** (SongIterator *) it: The song
** (int) priority: The song's priority ** (int) priority: The song's priority
** Returns : (song_t *) A freshly allocated song ** Returns : (Song *) A freshly allocated song
** Other values are set to predefined defaults. ** Other values are set to predefined defaults.
*/ */
Song *song_new(SongHandle handle, SongIterator *it, int priority);
void song_lib_init(songlib_t *songlib);
/* Initializes a static song library /* Initializes a static song library
** Parameters: (songlib_t *) songlib: Pointer to the library ** Parameters: (SongLibrary *) songlib: Pointer to the library
** to initialize ** to initialize
** Returns : (void) ** Returns : (void)
*/ */
void song_lib_init(SongLibrary *songlib);
void song_lib_free(const songlib_t &songlib);
/* Frees a song library /* Frees a song library
** Parameters: (songlib_t) songlib: The library to free ** Parameters: (SongLibrary) songlib: The library to free
** Returns : (void) ** Returns : (void)
*/ */
void song_lib_free(const SongLibrary &songlib);
void song_lib_add(const songlib_t &songlib, song_t *song);
/* Adds a song to a song library. /* Adds a song to a song library.
** Parameters: (songlib_t) songlib: An existing sound library, or NULL ** Parameters: (SongLibrary) songlib: An existing sound library, or NULL
** (song_t *) song: The song to add ** (Song *) song: The song to add
** Returns : (void) ** Returns : (void)
*/ */
void song_lib_add(const SongLibrary &songlib, Song *song);
song_t *song_lib_find(const songlib_t &songlib, song_handle_t handle);
/* Looks up the song with the specified handle /* Looks up the song with the specified handle
** Parameters: (songlib_t) songlib: An existing sound library, may point to NULL ** Parameters: (SongLibrary) songlib: An existing sound library, may point to NULL
** (song_handle_t) handle: The sound handle to look for ** (SongHandle) handle: The sound handle to look for
** Returns : (song_t *) The song or NULL if it wasn't found ** Returns : (Song *) The song or NULL if it wasn't found
*/ */
Song *song_lib_find(const SongLibrary &songlib, SongHandle handle);
song_t *song_lib_find_active(const songlib_t &songlib);
/* Finds the first song playing with the highest priority /* Finds the first song playing with the highest priority
** Parameters: (songlib_t) songlib: An existing sound library ** Parameters: (SongLibrary) songlib: An existing sound library
** Returns : (song_t *) The song that should be played next, or NULL if there is none ** Returns : (Song *) The song that should be played next, or NULL if there is none
*/ */
Song *song_lib_find_active(const SongLibrary &songlib);
song_t *song_lib_find_next_active(const songlib_t &songlib, song_t *song);
/* Finds the next song playing with the highest priority /* Finds the next song playing with the highest priority
** Parameters: (songlib_t) songlib: The song library to operate on ** Parameters: (SongLibrary) songlib: The song library to operate on
** (song_t *) song: A song previously returned from the song library ** (Song *) song: A song previously returned from the song library
** Returns : (song_t *) The next song to play relative to 'song', or ** Returns : (Song *) The next song to play relative to 'song', or
** NULL if none are left ** NULL if none are left
** The functions 'song_lib_find_active' and 'song_lib_find_next_active ** The functions 'song_lib_find_active' and 'song_lib_find_next_active
** allow to iterate over all songs that satisfy the requirement of ** allow to iterate over all songs that satisfy the requirement of
** being 'playable'. ** being 'playable'.
*/ */
Song *song_lib_find_next_active(const SongLibrary &songlib, Song *song);
int song_lib_remove(const songlib_t &songlib, song_handle_t handle);
/* Removes a song from the library /* Removes a song from the library
** Parameters: (songlib_t) songlib: An existing sound library ** Parameters: (SongLibrary) songlib: An existing sound library
** (song_handle_t) handle: Handle of the song to remove ** (SongHandle) handle: Handle of the song to remove
** Returns : (int) The status of the song that was removed ** Returns : (int) The status of the song that was removed
*/ */
int song_lib_remove(const SongLibrary &songlib, SongHandle handle);
void song_lib_resort(const songlib_t &songlib, song_t *song);
/* Removes a song from the library and sorts it in again; for use after renicing /* Removes a song from the library and sorts it in again; for use after renicing
** Parameters: (songlib_t) songlib: An existing sound library ** Parameters: (SongLibrary) songlib: An existing sound library
** (song_t *) song: The song to work on ** (Song *) song: The song to work on
** Returns : (void) ** Returns : (void)
*/ */
void song_lib_resort(const SongLibrary &songlib, Song *song);
int song_lib_count(const songlib_t &songlib);
/* Counts the number of songs in a song library /* Counts the number of songs in a song library
** Parameters: (songlib_t) songlib: The library to count ** Parameters: (SongLibrary) songlib: The library to count
** Returns : (int) The number of songs ** Returns : (int) The number of songs
*/ */
int song_lib_count(const SongLibrary &songlib);
void song_lib_set_restore_behavior(const songlib_t &songlib, song_handle_t handle,
RESTORE_BEHAVIOR action);
/* Determines what should be done with the song "handle" when /* Determines what should be done with the song "handle" when
** restoring it from a saved game. ** restoring it from a saved game.
** Parameters: (songlib_t) songlib: The library that contains the song ** Parameters: (SongLibrary) songlib: The library that contains the song
** (song_handle_t) handle: Its handle ** (SongHandle) handle: Its handle
** (RESTORE_BEHAVIOR) action: The desired action ** (RESTORE_BEHAVIOR) action: The desired action
*/ */
void song_lib_set_restore_behavior(const SongLibrary &songlib, SongHandle handle,
RESTORE_BEHAVIOR action);
} // End of namespace Sci } // End of namespace Sci