|
|
|
@ -32,8 +32,8 @@ class Jukebox : Object;
|
|
|
|
|
float fadeLevel = 0.0;
|
|
|
|
|
|
|
|
|
|
// How much to fade in and out each second
|
|
|
|
|
float fadeInRate = 0.10;
|
|
|
|
|
float fadeOutRate = 0.25;
|
|
|
|
|
float fadeInRate = 0.14;
|
|
|
|
|
float fadeOutRate = 0.30;
|
|
|
|
|
|
|
|
|
|
// Time between each fade step
|
|
|
|
|
float fadeInterval = 0.2;
|
|
|
|
@ -50,12 +50,7 @@ int index;
|
|
|
|
|
float musVolume;
|
|
|
|
|
|
|
|
|
|
bool isPlaying; // Is a song currently playing?
|
|
|
|
|
|
|
|
|
|
// TODO: Make "isPaused" instead, makes more sense
|
|
|
|
|
bool hasSong; // Is a song currently selected (playing or paused)
|
|
|
|
|
|
|
|
|
|
// TODO: Move to Object for now
|
|
|
|
|
native int randInt(int a, int b);
|
|
|
|
|
bool isPaused; // Is the song currently paused?
|
|
|
|
|
|
|
|
|
|
// Native functions to control music
|
|
|
|
|
native setSound(char[] filename);
|
|
|
|
@ -66,12 +61,18 @@ idle waitUntilFinished();
|
|
|
|
|
|
|
|
|
|
// Fade out and then stop the music. TODO: Rename these to resume()
|
|
|
|
|
// etc and use super.resume, when this is possible.
|
|
|
|
|
pause() { state = fadeOut; }
|
|
|
|
|
pause()
|
|
|
|
|
{
|
|
|
|
|
isPaused = true;
|
|
|
|
|
state = fadeOut;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resume()
|
|
|
|
|
{
|
|
|
|
|
if(!hasSong) next();
|
|
|
|
|
else playSound();
|
|
|
|
|
if(isPaused) playSound();
|
|
|
|
|
else next();
|
|
|
|
|
|
|
|
|
|
isPaused = false;
|
|
|
|
|
state = fadeIn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -81,7 +82,6 @@ stop()
|
|
|
|
|
{
|
|
|
|
|
stopSound();
|
|
|
|
|
|
|
|
|
|
hasSong = false;
|
|
|
|
|
isPlaying = false;
|
|
|
|
|
fadeLevel = 0.0;
|
|
|
|
|
state = null;
|
|
|
|
@ -96,7 +96,9 @@ play()
|
|
|
|
|
playSound();
|
|
|
|
|
|
|
|
|
|
isPlaying = true;
|
|
|
|
|
hasSong = true;
|
|
|
|
|
isPaused = false;
|
|
|
|
|
|
|
|
|
|
state = playing;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Play the next song in the playlist
|
|
|
|
@ -159,7 +161,6 @@ randomize()
|
|
|
|
|
state fadeIn
|
|
|
|
|
{
|
|
|
|
|
begin:
|
|
|
|
|
|
|
|
|
|
setVolume(musVolume*fadeLevel);
|
|
|
|
|
|
|
|
|
|
sleep(fadeInterval);
|
|
|
|
@ -179,7 +180,6 @@ state fadeIn
|
|
|
|
|
state fadeOut
|
|
|
|
|
{
|
|
|
|
|
begin:
|
|
|
|
|
|
|
|
|
|
sleep(fadeInterval);
|
|
|
|
|
|
|
|
|
|
fadeLevel -= fadeInterval*fadeOutRate;
|
|
|
|
@ -187,7 +187,6 @@ state fadeOut
|
|
|
|
|
if(fadeLevel <= 0.0)
|
|
|
|
|
{
|
|
|
|
|
fadeLevel = 0.0;
|
|
|
|
|
|
|
|
|
|
stopSound();
|
|
|
|
|
isPlaying = false;
|
|
|
|
|
|
|
|
|
@ -201,12 +200,16 @@ state fadeOut
|
|
|
|
|
state playing
|
|
|
|
|
{
|
|
|
|
|
begin:
|
|
|
|
|
// Wait for the song to play. Will return imediately if the song has
|
|
|
|
|
// already stopped or if no song is playing
|
|
|
|
|
waitUntilFinished();
|
|
|
|
|
setVolume(musVolume);
|
|
|
|
|
fadeLevel = 1.0;
|
|
|
|
|
|
|
|
|
|
// Start playing the next song
|
|
|
|
|
next();
|
|
|
|
|
while(true)
|
|
|
|
|
{
|
|
|
|
|
// Wait for the song to play. Will return imediately if the song has
|
|
|
|
|
// already stopped or if no song is playing
|
|
|
|
|
waitUntilFinished();
|
|
|
|
|
|
|
|
|
|
goto begin;
|
|
|
|
|
// Start playing the next song
|
|
|
|
|
next();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|