Help with SDL_Mixer

So I have found myself in a bit of trouble here. Essentially what I want to do
is automatically play the next chunk in a “play list” by utilizing the
Mix_ChannelFinished callback register to let me know when a sound has finished
playing. This I can do, not a problem. I also want to set the position for
that sound, here is where the issue lies.

Apparantly the Mix_SetPosition uses the same system as the Mix_RegisterEffect
hook system. Mix_RegisterEffect is documented as clearing the effects for a
channel upon that channel completing. So I’m within the completing callback
where we detect that the sound has finished playing. I queue up the next sound
and call Mix_SetPosition and it absolutely does not work. I can set the
position on the channel outside of the Mix_ChannelFinished registered callback
without trouble, swap it around, do whatever. As soon as one sound chunk stops
playing though it resets the position and I have no way of setting it again when
I resume playback.

So my question is, where is it safe for me to call a Mix_RegisterEffect (and
therefore Mix_SetPosition) when using the Mix_ChannelFinished registered
callback to detect a song completing? Any functions I call from
Mix_ChannelFinished obviously also have this limitation of being unable to set
the position.

Here is a code snippet (slightly modified to remove some of the extra features):

Mix_ChannelFinished(AudioSoundHook);

void AudioSoundHook(int channel){
static AudioPlayer *player = AudioPlayer::instance();
AudioPlayList *activePlayList = player->getSoundPlayList(channel);
if(activePlayList!=0){
if(activePlayList->advancePlayList()){ //move the playhead
activePlayList->beginPlaying(); //play the next song
}
}
}

void AudioPlayList::beginPlaying(){
AudioPlayer::instance()->playSound(getCurrentSound(), -1, 0, -1, this);
currentChannel = AudioPlayer::instance()->getMostRecentlyUsedChannel();
Mix_SetPosition(currentChannel, currentAngle, currentDistance);
}

Michael Hamilton <maxmike gmail.com> writes:


So my question is, where is it safe for me to call a Mix_RegisterEffect (and
therefore Mix_SetPosition) when using the Mix_ChannelFinished registered
callback to detect a song completing? Any functions I call from
Mix_ChannelFinished obviously also have this limitation of being unable to set
the position.

CODE SNIPPET SHOWING DESIRED FUNCTIONALITY REMOVED, SEE PREVIOUS POST

So, I’ve taken a look at the code that calls ye callback:

static void _Mix_channel_done_playing(int channel)
{
if (channel_done_callback) {
channel_done_callback(channel);
}

/*
 * Call internal function directly, to avoid locking audio from
 *   inside audio callback.
 */
_Mix_remove_all_effects(channel, &mix_channel[channel].effects);

}

Basically it calls the callback, removes all effects and goes on its way.
I’m going to switch these and rebuild so I can add effects in the callback
unless someone else has a better solution that does not involve altering
SDL_Mixer code…

Really not sure what other options I have. I don’t see any. Can anyone tell
me if I’m blundering into some sort of fatal mistake here? It seems like a
harmless change but I can’t be totally sure having just skimmed it.