--***************************** Music/sound functions ***************************-- ----------------------------------------------------------------------------------- -- MusicIdle -- -- Updates the playing of looped or queued sound files by checking the status of -- the current file and starting any queued files as needed. (Call from onŠidle.) -- on MusicIdle global gMusicFile global gMusicFileLooping -- if (soundBusy(1) = FALSE) and (gMusicFile <> []) then if GetAt(gMusicFileLooping, 1) = FALSE then -- if not in a sound loop, pop to the next sound file in queue deleteAt gMusicFile, 1 deleteAt gMusicFileLooping, 1 end if if gMusicFile <> [] then put "MusicIdle(): Starting to play '" & getAt(gMusicFile, 1) & "'" sound playFile 1, getAt(gMusicFile, 1) end if end if end MusicIdle ----------------------------------------------------------------------------------- -- MusicFade fadeTo, nTicks -- -- Fades the sound volume from the current volume to the volume specified in -- fadeTo over the time period specified by nTicks -- on MusicFade fadeTo, nTicks -- local fadeFrom, nSteps, ticksPerStep, stepsPerTick, direction -- if soundBusy(1) = TRUE then set fadeFrom = the volume of sound 1 set nSteps = Abs(fadeTo - fadeFrom) if nSteps > nTicks then set stepsPerTick = nSteps / nTicks set ticksPerStep = 1 else set stepsPerTick = 1 set ticksPerStep = nTicks / nSteps end if if fadeFrom > fadeTo then set direction = -1 else set direction = 1 end if put " fadeFrom: " & fadeFrom & ", fadeTo: " & fadeTo & ", nSteps: " & nSteps ¬ & ", stepsPerTick: " & stepsPerTick & ", ticksPerStep: " & ticksPerStep repeat with i = 1 to (nSteps / stepsPerTick) set the volume of sound 1 = (fadeFrom + i * stepsPerTick * direction) Delay ticksPerStep end repeat end if set the volume of sound 1 = fadeTo end MusicFade ----------------------------------------------------------------------------------- -- MusicFadeOut nTicks -- -- Fades the volume of any currently playing sounds to zero over the time period -- specified by nTicks, and clears the music queue. -- on MusicFadeOut nTicks global gMusicFile global gMusicFileLooping -- local oldSoundVolume -- set gMusicFile = [] set gMusicFileLooping = [] set oldSoundVolume = the volume of sound 1 MusicFade 0, nTicks sound stop 1 set the volume of sound 1 to oldSoundVolume end MusicFadeOut ----------------------------------------------------------------------------------- -- MusicPlayFile musicFile, loop -- -- Fades the current volume to zero and clears the music queue before immediately -- beginning to play the sound file specified in musicFile. If loop is set -- to true, the audio will be looped as needed by MusicIdle. -- on MusicPlayFile musicFile, loop global gMusicFile global gMusicFileLooping -- MusicFadeOut 30 add gMusicFile, musicFile add gMusicFileLooping, (loop = TRUE) sound playFile 1, musicFile end MusicPlayFile